From fb9991d544063757a52bd96f5ff27ef4d26b77a1 Mon Sep 17 00:00:00 2001 From: Pamela Fox Date: Mon, 23 Jun 2025 11:26:14 -0700 Subject: [PATCH 1/4] Escape brackets correctly --- README.md | 19 ++++++++++++++++++- dist/code-exercise.umd.js | 19 +++++-------------- dist/worker.js | 4 ---- index.html | 38 +++++++++++++++++--------------------- package.json | 2 +- src/code-exercise.js | 18 +++++------------- 6 files changed, 46 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index ae40ee9..98df350 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Add the script to your HTML: ``` Then use the component in your HTML: -```html + def my_function(param): """ A function that does something. @@ -24,6 +24,23 @@ def my_function(param): """ # YOUR CODE HERE + +The component will preserve whitespace and indentation in the code, so you can write the Python code naturally in your HTML. + +I recommend using CSS to style the code elements so that they look like code blocks before they get turned into a CodeMirror editor. That will avoid any layout shifts when the editor is initialized. + +```css +code-exercise-element { + white-space: pre; + font-family: monospace; +} +``` +To style the CodeMirror editor that loads inside the element, include a CSS rule that targets the `.cm-editor` class: + +```css +code-exercise-element .cm-editor { + border: 1px solid #ccc; +} ``` ### Attributes diff --git a/dist/code-exercise.umd.js b/dist/code-exercise.umd.js index 1fe752b..ac17d38 100644 --- a/dist/code-exercise.umd.js +++ b/dist/code-exercise.umd.js @@ -15,7 +15,7 @@ const e=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShad * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ -var $;d.finalized=!0,d.elementProperties=new Map,d.elementStyles=[],d.shadowRootOptions={mode:"open"},null==a||a({ReactiveElement:d}),(null!==(o=globalThis.reactiveElementVersions)&&void 0!==o?o:globalThis.reactiveElementVersions=[]).push("1.3.2");const p=globalThis.trustedTypes,m=p?p.createPolicy("lit-html",{createHTML:t=>t}):void 0,w=`lit$${(Math.random()+"").slice(9)}$`,g="?"+w,b=`<${g}>`,x=document,y=(t="")=>x.createComment(t),Q=t=>null===t||"object"!=typeof t&&"function"!=typeof t,P=Array.isArray,v=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,q=/-->/g,S=/>/g,k=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,I=/'/g,R=/"/g,W=/^(?:script|style|textarea|title)$/i,Y=(t=>(e,...i)=>({_$litType$:t,strings:e,values:i}))(1),X=Symbol.for("lit-noChange"),M=Symbol.for("lit-nothing"),Z=new WeakMap,T=x.createTreeWalker(x,129,null,!1),_=(t,e)=>{const i=t.length-1,s=[];let r,n=2===e?"":"",h=v;for(let e=0;e"===l[0]?(h=null!=r?r:v,u=-1):void 0===l[1]?u=-2:(u=h.lastIndex-l[2].length,o=l[1],h=void 0===l[3]?k:'"'===l[3]?R:I):h===R||h===I?h=k:h===q||h===S?h=v:(h=k,r=void 0);const f=h===k&&t[e+1].startsWith("/>")?" ":"";n+=h===v?i+b:u>=0?(s.push(o),i.slice(0,u)+"$lit$"+i.slice(u)+w+f):i+w+(-2===u?(s.push(void 0),e):f)}const o=n+(t[i]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==m?m.createHTML(o):o,s]};class E{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let r=0,n=0;const h=t.length-1,o=this.parts,[l,u]=_(t,e);if(this.el=E.createElement(l,i),T.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(s=T.nextNode())&&o.length0){s.textContent=p?p.emptyScript:"";for(let i=0;i{var e;return P(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.S(t):this.$(t)}M(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.M(t))}$(t){this._$AH!==M&&Q(this._$AH)?this._$AA.nextSibling.data=t:this.k(x.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:s}=t,r="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=E.createElement(s.h,this.options)),s);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(i);else{const t=new j(r,this),e=t.p(this.options);t.m(i),this.k(e),this._$AH=t}}_$AC(t){let e=Z.get(t.strings);return void 0===e&&Z.set(t.strings,e=new E(t)),e}S(t){P(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const r of t)s===e.length?e.push(i=new U(this.M(y()),this.M(y()),this,this.options)):i=e[s],i._$AI(r),s++;s2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=M}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,s){const r=this.strings;let n=!1;if(void 0===r)t=A(this,t,e,0),n=!Q(t)||t!==this._$AH&&t!==X,n&&(this._$AH=t);else{const s=t;let h,o;for(t=r[0],h=0;ht}):void 0,w=`lit$${(Math.random()+"").slice(9)}$`,g="?"+w,x=`<${g}>`,b=document,y=(t="")=>b.createComment(t),Q=t=>null===t||"object"!=typeof t&&"function"!=typeof t,P=Array.isArray,v=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,q=/-->/g,S=/>/g,k=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,I=/'/g,R=/"/g,W=/^(?:script|style|textarea|title)$/i,Y=(t=>(e,...i)=>({_$litType$:t,strings:e,values:i}))(1),X=Symbol.for("lit-noChange"),M=Symbol.for("lit-nothing"),Z=new WeakMap,T=b.createTreeWalker(b,129,null,!1),_=(t,e)=>{const i=t.length-1,s=[];let r,n=2===e?"":"",h=v;for(let e=0;e"===l[0]?(h=null!=r?r:v,u=-1):void 0===l[1]?u=-2:(u=h.lastIndex-l[2].length,o=l[1],h=void 0===l[3]?k:'"'===l[3]?R:I):h===R||h===I?h=k:h===q||h===S?h=v:(h=k,r=void 0);const f=h===k&&t[e+1].startsWith("/>")?" ":"";n+=h===v?i+x:u>=0?(s.push(o),i.slice(0,u)+"$lit$"+i.slice(u)+w+f):i+w+(-2===u?(s.push(void 0),e):f)}const o=n+(t[i]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==m?m.createHTML(o):o,s]};class E{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let r=0,n=0;const h=t.length-1,o=this.parts,[l,u]=_(t,e);if(this.el=E.createElement(l,i),T.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(s=T.nextNode())&&o.length0){s.textContent=p?p.emptyScript:"";for(let i=0;i{var e;return P(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.S(t):this.$(t)}M(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=this.M(t))}$(t){this._$AH!==M&&Q(this._$AH)?this._$AA.nextSibling.data=t:this.k(b.createTextNode(t)),this._$AH=t}T(t){var e;const{values:i,_$litType$:s}=t,r="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=E.createElement(s.h,this.options)),s);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(i);else{const t=new j(r,this),e=t.p(this.options);t.m(i),this.k(e),this._$AH=t}}_$AC(t){let e=Z.get(t.strings);return void 0===e&&Z.set(t.strings,e=new E(t)),e}S(t){P(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const r of t)s===e.length?e.push(i=new U(this.M(y()),this.M(y()),this,this.options)):i=e[s],i._$AI(r),s++;s2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=M}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,s){const r=this.strings;let n=!1;if(void 0===r)t=A(this,t,e,0),n=!Q(t)||t!==this._$AH&&t!==X,n&&(this._$AH=t);else{const s=t;let h,o;for(t=r[0],h=0;h(...e)=>({_$litDirective$:t,values:e}))(class extends ot{render(t){return M}update(t,[e]){var i;const s=e!==this.U;return s&&void 0!==this.U&&this.ot(void 0),(s||this.rt!==this.lt)&&(this.U=e,this.ht=null===(i=t.options)||void 0===i?void 0:i.host,this.ot(this.lt=t.element)),M}ot(t){var e;if("function"==typeof this.U){const i=null!==(e=this.ht)&&void 0!==e?e:globalThis;let s=ut.get(i);void 0===s&&(s=new WeakMap,ut.set(i,s)),void 0!==s.get(this.U)&&this.U.call(this.ht,void 0),s.set(this.U,t),void 0!==t&&this.U.call(this.ht,t)}else this.U.value=t}get rt(){var t,e,i;return"function"==typeof this.U?null===(e=ut.get(null!==(t=this.ht)&&void 0!==t?t:globalThis))||void 0===e?void 0:e.get(this.U):null===(i=this.U)||void 0===i?void 0:i.value}disconnected(){this.rt===this.lt&&this.ot(void 0)}reconnected(){this.ot(this.lt)}});class ft{constructor(){}lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){let s=[];return this.decompose(0,t,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(e,this.length,s,1),Ot.from(s,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){let i=[];return this.decompose(t,e,i,0),Ot.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),s=new pt(this),r=new pt(t);for(let t=e,n=e;;){if(s.next(t),r.next(t),t=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(n+=s.value.length,s.done||n>=i)return!0}}iter(t=1){return new pt(this,t)}iterRange(t,e=this.length){return new mt(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let s=this.line(t).from;i=this.iterRange(s,Math.max(s,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new wt(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}static of(t){if(0==t.length)throw new RangeError("A document must have at least one line");return 1!=t.length||t[0]?t.length<=32?new ct(t):Ot.from(ct.split(t,[])):ft.empty}}class ct extends ft{constructor(t,e=function(t){let e=-1;for(let i of t)e+=i.length+1;return e}(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,s){for(let r=0;;r++){let n=this.text[r],h=s+n.length;if((e?i:h)>=t)return new gt(s,h,i,n);s=h+1,i++}}decompose(t,e,i,s){let r=t<=0&&e>=this.length?this:new ct($t(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(1&s){let t=i.pop(),e=dt(r.text,t.text.slice(),0,r.length);if(e.length<=32)i.push(new ct(e,t.length+r.length));else{let t=e.length>>1;i.push(new ct(e.slice(0,t)),new ct(e.slice(t)))}}else i.push(r)}replace(t,e,i){if(!(i instanceof ct))return super.replace(t,e,i);let s=dt(this.text,dt(i.text,$t(this.text,0,t)),e),r=this.length+i.length-(e-t);return s.length<=32?new ct(s,r):Ot.from(ct.split(s,[]),r)}sliceString(t,e=this.length,i="\n"){let s="";for(let r=0,n=0;r<=e&&nt&&n&&(s+=i),tr&&(s+=h.slice(Math.max(0,t-r),e-r)),r=o+1}return s}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],s=-1;for(let r of t)i.push(r),s+=r.length+1,32==i.length&&(e.push(new ct(i,s)),i=[],s=-1);return s>-1&&e.push(new ct(i,s)),e}}class Ot extends ft{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let e of t)this.lines+=e.lines}lineInner(t,e,i,s){for(let r=0;;r++){let n=this.children[r],h=s+n.length,o=i+n.lines-1;if((e?o:h)>=t)return n.lineInner(t,e,i,s);s=h+1,i=o+1}}decompose(t,e,i,s){for(let r=0,n=0;n<=e&&r=n){let r=s&((n<=t?1:0)|(o>=e?2:0));n>=t&&o<=e&&!r?i.push(h):h.decompose(t-n,e-n,i,r)}n=o+1}}replace(t,e,i){if(i.lines=r&&e<=h){let o=n.replace(t-r,e-r,i),l=this.lines-n.lines+o.lines;if(o.lines>4&&o.lines>l>>6){let r=this.children.slice();return r[s]=o,new Ot(r,this.length-(e-t)+i.length)}return super.replace(r,h,o)}r=h+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i="\n"){let s="";for(let r=0,n=0;rt&&r&&(s+=i),tn&&(s+=h.sliceString(t-n,e-n,i)),n=o+1}return s}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof Ot))return 0;let i=0,[s,r,n,h]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;s+=e,r+=e){if(s==n||r==h)return i;let o=this.children[s],l=t.children[r];if(o!=l)return i+o.scanIdentical(l,e);i+=o.length+1}}static from(t,e=t.reduce(((t,e)=>t+e.length+1),-1)){let i=0;for(let e of t)i+=e.lines;if(i<32){let i=[];for(let e of t)e.flatten(i);return new ct(i,e)}let s=Math.max(32,i>>5),r=s<<1,n=s>>1,h=[],o=0,l=-1,u=[];function a(t){let e;if(t.lines>r&&t instanceof Ot)for(let e of t.children)a(e);else t.lines>n&&(o>n||!o)?(f(),h.push(t)):t instanceof ct&&o&&(e=u[u.length-1])instanceof ct&&t.lines+e.lines<=32?(o+=t.lines,l+=t.length+1,u[u.length-1]=new ct(e.text.concat(t.text),e.length+1+t.length)):(o+t.lines>s&&f(),o+=t.lines,l+=t.length+1,u.push(t))}function f(){0!=o&&(h.push(1==u.length?u[0]:Ot.from(u,l)),l=-1,o=u.length=0)}for(let e of t)a(e);return f(),1==h.length?h[0]:new Ot(h,e)}}function dt(t,e,i=0,s=1e9){for(let r=0,n=0,h=!0;n=i&&(l>s&&(o=o.slice(0,s-r)),r0?1:(t instanceof ct?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],n=r>>1,h=s instanceof ct?s.text.length:s.children.length;if(n==(e>0?h:0)){if(0==i)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&r)==(e>0?0:1)){if(this.offsets[i]+=e,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(s instanceof ct){let r=s.text[n+(e<0?-1:0)];if(this.offsets[i]+=e,r.length>Math.max(0,t))return this.value=0==t?r:e>0?r.slice(t):r.slice(0,r.length-t),this;t-=r.length}else{let r=s.children[n+(e<0?-1:0)];t>r.length?(t-=r.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(r),this.offsets.push(e>0?1:(r instanceof ct?r.text.length:r.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class mt{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new pt(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:s}=this.cursor.next(t);return this.pos+=(s.length+t)*e,this.value=s.length<=i?s:e<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class wt{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:s}=this.inner.next(t);return e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(ft.prototype[Symbol.iterator]=function(){return this.iter()},pt.prototype[Symbol.iterator]=mt.prototype[Symbol.iterator]=wt.prototype[Symbol.iterator]=function(){return this});class gt{constructor(t,e,i,s){this.from=t,this.to=e,this.number=i,this.text=s}get length(){return this.to-this.from}}let bt="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map((t=>t?parseInt(t,36):1));for(let t=1;tt)return bt[e-1]<=t;return!1}function yt(t){return t>=127462&&t<=127487}function Qt(t,e,i=!0,s=!0){return(i?Pt:vt)(t,e,s)}function Pt(t,e,i){if(e==t.length)return e;e&&qt(t.charCodeAt(e))&&St(t.charCodeAt(e-1))&&e--;let s=kt(t,e);for(e+=Rt(s);e=0&&yt(kt(t,s));)i++,s-=2;if(i%2==0)break;e+=2}}}return e}function vt(t,e,i){for(;e>0;){let s=Pt(t,e-2,i);if(s=56320&&t<57344}function St(t){return t>=55296&&t<56320}function kt(t,e){let i=t.charCodeAt(e);if(!St(i)||e+1==t.length)return i;let s=t.charCodeAt(e+1);return qt(s)?s-56320+(i-55296<<10)+65536:i}function It(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function Rt(t){return t<65536?1:2}const Wt=/\r\n?|\n/;var Yt=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(Yt||(Yt={}));class Xt{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return r+(t-s);r+=h}else{if(i!=Yt.Simple&&l>=t&&(i==Yt.TrackDel&&st||i==Yt.TrackBefore&&st))return null;if(l>t||l==t&&e<0&&!h)return t==s||e<0?r:r+o;r+=o}s=l}if(t>s)throw new RangeError(`Position ${t} is out of range for changeset of length ${s}`);return r}touchesRange(t,e=t){for(let i=0,s=0;i=0&&s<=e&&r>=t)return!(se)||"cover";s=r}return!1}toString(){let t="";for(let e=0;e=0?":"+s:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some((t=>"number"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Xt(t)}static create(t){return new Xt(t)}}class Mt extends Xt{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return _t(this,((e,i,s,r,n)=>t=t.replace(s,s+(i-e),n)),!1),t}mapDesc(t,e=!1){return Et(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let s=0,r=0;s=0){e[s]=h,e[s+1]=n;let o=s>>1;for(;i.length0&&Tt(i,e,r.text),r.forward(t),h+=t}let l=t[n++];for(;h>1].toJSON()))}return t}static of(t,e,i){let s=[],r=[],n=0,h=null;function o(t=!1){if(!t&&!s.length)return;nh||t<0||h>e)throw new RangeError(`Invalid change range ${t} to ${h} (in doc of length ${e})`);let a=u?"string"==typeof u?ft.of(u.split(i||Wt)):u:ft.empty,f=a.length;if(t==h&&0==f)return;tn&&Zt(s,t-n,-1),Zt(s,h-t,f),Tt(r,s,a),n=h}}(t),o(!h),h}static empty(t){return new Mt(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let s=0;se&&"string"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==r.length)e.push(r[0],0);else{for(;i.length=0&&i<=0&&i==t[r+1]?t[r]+=e:0==e&&0==t[r]?t[r+1]+=i:s?(t[r]+=e,t[r+1]+=i):t.push(e,i)}function Tt(t,e,i){if(0==i.length)return;let s=e.length-2>>1;if(s>1])),!(i||h==t.sections.length||t.sections[h+1]<0);)o=t.sections[h++],l=t.sections[h++];e(r,u,n,a,f),r=u,n=a}}}function Et(t,e,i,s=!1){let r=[],n=s?[]:null,h=new jt(t),o=new jt(e);for(let t=0,e=0;;)if(-1==h.ins)t+=h.len,h.next();else if(-1==o.ins&&e=0&&(h.done||ee&&!h.done&&t+h.len=0)){if(h.done&&o.done)return n?Mt.createSet(r,n):Xt.create(r);throw new Error("Mismatched change set lengths")}{let i=0,s=t+h.len;for(;;)if(o.ins>=0&&e>t&&e+o.lene||h.ins>=0&&h.len>e)&&(t||s.length>i),n.forward2(e),h.forward(e)}}else Zt(s,0,h.ins,t),r&&Tt(r,s,h.text),h.next()}}class jt{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return e>=t.length?ft.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?ft.empty:e[i].slice(this.off,null==t?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){-1==this.ins?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class Ut{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return 16&this.flags?this.to:this.from}get head(){return 16&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 4&this.flags?-1:8&this.flags?1:0}get bidiLevel(){let t=3&this.flags;return 3==t?null:t}get goalColumn(){let t=this.flags>>5;return 33554431==t?void 0:t}map(t,e=-1){let i,s;return this.empty?i=s=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),s=t.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new Ut(i,s,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return Vt.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return Vt.range(this.anchor,i)}eq(t){return this.anchor==t.anchor&&this.head==t.head}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||"number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid JSON representation for SelectionRange");return Vt.range(t.anchor,t.head)}static create(t,e,i){return new Ut(t,e,i)}}class Vt{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:Vt.create(this.ranges.map((i=>i.map(t,e))),this.mainIndex)}eq(t){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let e=0;et.toJSON())),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||"number"!=typeof t.main||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new Vt(t.ranges.map((t=>Ut.fromJSON(t))),t.main)}static single(t,e=t){return new Vt([Vt.range(t,e)],0)}static create(t,e=0){if(0==t.length)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;st?4:0))}static normalized(t,e=0){let i=t[e];t.sort(((t,e)=>t.from-e.from)),e=t.indexOf(i);for(let i=1;is.head?Vt.range(h,n):Vt.range(n,h))}}return new Vt(t,e)}}function Ct(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let Gt=0;class Dt{constructor(t,e,i,s,r){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=s,this.extensions=r,this.id=Gt++,this.default=t([])}static define(t={}){return new Dt(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:zt),!!t.static,t.enables)}of(t){return new Ht([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ht(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ht(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],(i=>e(i.field(t))))}}function zt(t,e){return t==e||t.length==e.length&&t.every(((t,i)=>t===e[i]))}class Ht{constructor(t,e,i,s){this.dependencies=t,this.facet=e,this.type=i,this.value=s,this.id=Gt++}dynamicSlot(t){var e;let i=this.value,s=this.facet.compareInput,r=this.id,n=t[r]>>1,h=2==this.type,o=!1,l=!1,u=[];for(let i of this.dependencies)"doc"==i?o=!0:"selection"==i?l=!0:1&(null!==(e=t[i.id])&&void 0!==e?e:1)||u.push(t[i.id]);return{create:t=>(t.values[n]=i(t),1),update(t,e){if(o&&e.docChanged||l&&(e.docChanged||e.selection)||Ft(t,u)){let e=i(t);if(h?!Nt(e,t.values[n],s):!s(e,t.values[n]))return t.values[n]=e,1}return 0},reconfigure:(t,e)=>{let o=i(t),l=e.config.address[r];if(null!=l){let i=ae(e,l);if(this.dependencies.every((i=>i instanceof Dt?e.facet(i)===t.facet(i):!(i instanceof Kt)||e.field(i,!1)==t.field(i,!1)))||(h?Nt(o,i,s):s(o,i)))return t.values[n]=i,0}return t.values[n]=o,1}}}}function Nt(t,e,i){if(t.length!=e.length)return!1;for(let s=0;st[e.id])),r=i.map((t=>t.type)),n=s.filter((t=>!(1&t))),h=t[e.id]>>1;function o(t){let i=[];for(let e=0;et===e),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(Lt).find((t=>t.field==this));return((null==e?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:t=>(t.values[e]=this.create(t),1),update:(t,i)=>{let s=t.values[e],r=this.updateF(s,i);return this.compareF(s,r)?0:(t.values[e]=r,1)},reconfigure:(t,i)=>null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}init(t){return[this,Lt.of({field:this,create:t})]}get extension(){return this}}const Jt=4,te=3,ee=2,ie=1;function se(t){return e=>new ne(e,t)}const re={highest:se(0),high:se(ie),default:se(ee),low:se(te),lowest:se(Jt)};class ne{constructor(t,e){this.inner=t,this.prec=e}}class he{of(t){return new oe(this,t)}reconfigure(t){return he.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class oe{constructor(t,e){this.compartment=t,this.inner=e}}class le{constructor(t,e,i,s,r,n){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=n,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(t,e,i){let s=[],r=Object.create(null),n=new Map;for(let i of function(t,e,i){let s=[[],[],[],[],[]],r=new Map;function n(t,h){let o=r.get(t);if(null!=o){if(o<=h)return;let e=s[o].indexOf(t);e>-1&&s[o].splice(e,1),t instanceof oe&&i.delete(t.compartment)}if(r.set(t,h),Array.isArray(t))for(let e of t)n(e,h);else if(t instanceof oe){if(i.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let s=e.get(t.compartment)||t.inner;i.set(t.compartment,s),n(s,h)}else if(t instanceof ne)n(t.inner,t.prec);else if(t instanceof Kt)s[h].push(t),t.provides&&n(t.provides,h);else if(t instanceof Ht)s[h].push(t),t.facet.extensions&&n(t.facet.extensions,h);else{let e=t.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${t}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);n(e,h)}}return n(t,ee),s.reduce(((t,e)=>t.concat(e)))}(t,e,n))i instanceof Kt?s.push(i):(r[i.facet.id]||(r[i.facet.id]=[])).push(i);let h=Object.create(null),o=[],l=[];for(let t of s)h[t.id]=l.length<<1,l.push((e=>t.slot(e)));let u=null==i?void 0:i.config.facets;for(let t in r){let e=r[t],s=e[0].facet,n=u&&u[t]||[];if(e.every((t=>0==t.type)))if(h[s.id]=o.length<<1|1,zt(n,e))o.push(i.facet(s));else{let t=s.combine(e.map((t=>t.value)));o.push(i&&s.compare(t,i.facet(s))?i.facet(s):t)}else{for(let t of e)0==t.type?(h[t.id]=o.length<<1|1,o.push(t.value)):(h[t.id]=l.length<<1,l.push((e=>t.dynamicSlot(e))));h[s.id]=l.length<<1,l.push((t=>Bt(t,s,e)))}}let a=l.map((t=>t(h)));return new le(t,n,a,h,o,r)}}function ue(t,e){if(1&e)return 2;let i=e>>1,s=t.status[i];if(4==s)throw new Error("Cyclic dependency between fields and/or facets");if(2&s)return s;t.status[i]=4;let r=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|r}function ae(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const fe=Dt.define(),ce=Dt.define({combine:t=>t.some((t=>t)),static:!0}),Oe=Dt.define({combine:t=>t.length?t[0]:void 0,static:!0}),de=Dt.define(),$e=Dt.define(),pe=Dt.define(),me=Dt.define({combine:t=>!!t.length&&t[0]});class we{constructor(t,e){this.type=t,this.value=e}static define(){return new ge}}class ge{of(t){return new we(this,t)}}class be{constructor(t){this.map=t}of(t){return new xe(this,t)}}class xe{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return void 0===e?void 0:e==this.value?this:new xe(this.type,e)}is(t){return this.type==t}static define(t={}){return new be(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let s of t){let t=s.map(e);t&&i.push(t)}return i}}xe.reconfigure=xe.define(),xe.appendConfig=xe.define();class ye{constructor(t,e,i,s,r,n){this.startState=t,this.changes=e,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=n,this._doc=null,this._state=null,i&&Ct(i,e.newLength),r.some((t=>t.type==ye.time))||(this.annotations=r.concat(ye.time.of(Date.now())))}static create(t,e,i,s,r,n){return new ye(t,e,i,s,r,n)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(ye.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function Qe(t,e){let i=[];for(let s=0,r=0;;){let n,h;if(s=t[s]))n=t[s++],h=t[s++];else{if(!(r=0;r--){let n=i[r](t);n&&Object.keys(n).length&&(s=Pe(t,ve(e,n,t.changes.newLength),!0))}return s==t?t:ye.create(e,t.changes,t.selection,s.effects,s.annotations,s.scrollIntoView)}(i?function(t){let e=t.startState,i=!0;for(let s of e.facet(de)){let e=s(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:Qe(i,e))}if(!0!==i){let s,r;if(!1===i)r=t.changes.invertedDesc,s=Mt.empty(e.doc.length);else{let e=t.changes.filter(i);s=e.changes,r=e.filtered.mapDesc(e.changes).invertedDesc}t=ye.create(e,s,t.selection&&t.selection.map(r),xe.mapEffects(t.effects,r),t.annotations,t.scrollIntoView)}let s=e.facet($e);for(let i=s.length-1;i>=0;i--){let r=s[i](t);t=r instanceof ye?r:Array.isArray(r)&&1==r.length&&r[0]instanceof ye?r[0]:qe(e,ke(r),!1)}return t}(r):r)}ye.time=we.define(),ye.userEvent=we.define(),ye.addToHistory=we.define(),ye.remote=we.define();const Se=[];function ke(t){return null==t?Se:Array.isArray(t)?t:[t]}var Ie=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(Ie||(Ie={}));const Re=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let We;try{We=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(I){}function Ye(t){return e=>{if(!/\S/.test(e))return Ie.Space;if(function(t){if(We)return We.test(t);for(let e=0;e"€"&&(i.toUpperCase()!=i.toLowerCase()||Re.test(i)))return!0}return!1}(e))return Ie.Word;for(let i=0;i-1)return Ie.Word;return Ie.Other}}class Xe{constructor(t,e,i,s,r,n){this.config=t,this.doc=e,this.selection=i,this.values=s,this.status=t.statusTemplate.slice(),this.computeSlot=r,n&&(n._state=this);for(let t=0;tr.set(e,t))),i=null),r.set(e.value.compartment,e.value.extension)):e.is(xe.reconfigure)?(i=null,s=e.value):e.is(xe.appendConfig)&&(i=null,s=ke(s).concat(e.value));i?e=t.startState.values.slice():(i=le.resolve(s,r,this),e=new Xe(i,this.doc,this.selection,i.dynamicSlots.map((()=>null)),((t,e)=>e.reconfigure(t,this)),null).values),new Xe(i,t.newDoc,t.newSelection,e,((e,i)=>i.update(e,t)),t)}replaceSelection(t){return"string"==typeof t&&(t=this.toText(t)),this.changeByRange((e=>({changes:{from:e.from,to:e.to,insert:t},range:Vt.cursor(e.from+t.length)})))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),s=this.changes(i.changes),r=[i.range],n=ke(i.effects);for(let i=1;ir.spec.fromJSON(n,t))))}return Xe.create({doc:t.doc,selection:Vt.fromJSON(t.selection),extensions:e.extensions?s.concat([e.extensions]):s})}static create(t={}){let e=le.resolve(t.extensions||[],new Map),i=t.doc instanceof ft?t.doc:ft.of((t.doc||"").split(e.staticFacet(Xe.lineSeparator)||Wt)),s=t.selection?t.selection instanceof Vt?t.selection:Vt.single(t.selection.anchor,t.selection.head):Vt.single(0);return Ct(s,i.length),e.staticFacet(ce)||(s=s.asSingle()),new Xe(e,i,s,e.dynamicSlots.map((()=>null)),((t,e)=>e.create(t)),null)}get tabSize(){return this.facet(Xe.tabSize)}get lineBreak(){return this.facet(Xe.lineSeparator)||"\n"}get readOnly(){return this.facet(me)}phrase(t,...e){for(let e of this.facet(Xe.phrases))if(Object.prototype.hasOwnProperty.call(e,t)){t=e[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,((t,i)=>{if("$"==i)return"$";let s=+(i||1);return!s||s>e.length?t:e[s-1]}))),t}languageDataAt(t,e,i=-1){let s=[];for(let r of this.facet(fe))for(let n of r(this,e,i))Object.prototype.hasOwnProperty.call(n,t)&&s.push(n[t]);return s}charCategorizer(t){return Ye(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:s}=this.doc.lineAt(t),r=this.charCategorizer(t),n=t-i,h=t-i;for(;n>0;){let t=Qt(e,n,!1);if(r(e.slice(t,n))!=Ie.Word)break;n=t}for(;ht.length?t[0]:4}),Xe.lineSeparator=Oe,Xe.readOnly=me,Xe.phrases=Dt.define({compare(t,e){let i=Object.keys(t),s=Object.keys(e);return i.length==s.length&&i.every((i=>t[i]==e[i]))}}),Xe.languageData=fe,Xe.changeFilter=de,Xe.transactionFilter=$e,Xe.transactionExtender=pe,he.reconfigure=xe.define();class Ze{eq(t){return this==t}range(t,e=t){return Te.create(t,e,this)}}Ze.prototype.startSide=Ze.prototype.endSide=0,Ze.prototype.point=!1,Ze.prototype.mapMode=Yt.TrackDel;class Te{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new Te(t,e,i)}}function _e(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Ee{constructor(t,e,i,s){this.from=t,this.to=e,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,s=0){let r=i?this.to:this.from;for(let n=s,h=r.length;;){if(n==h)return n;let s=n+h>>1,o=r[s]-t||(i?this.value[s].endSide:this.value[s].startSide)-e;if(s==n)return o>=0?n:h;o>=0?h=s:n=s+1}}between(t,e,i,s){for(let r=this.findIndex(e,-1e9,!0),n=this.findIndex(i,1e9,!1,r);ru||l==u&&a.startSide>0&&a.endSide<=0)continue;(u-l||a.endSide-a.startSide)<0||(n<0&&(n=l),a.point&&(h=Math.max(h,u-l)),i.push(a),s.push(l-n),r.push(u-n))}return{mapped:i.length?new Ee(s,r,i,h):null,pos:n}}}class Ae{constructor(t,e,i,s){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=s}static create(t,e,i,s){return new Ae(t,e,i,s)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=t,n=t.filter;if(0==e.length&&!n)return this;if(i&&(e=e.slice().sort(_e)),this.isEmpty)return e.length?Ae.of(e):this;let h=new Ve(this,null,-1).goto(0),o=0,l=[],u=new je;for(;h.value||o=0){let t=e[o++];u.addInner(t.from,t.to,t.value)||l.push(t)}else 1==h.rangeIndex&&h.chunkIndexthis.chunkEnd(h.chunkIndex)||rh.to||r=r&&t<=r+n.length&&!1===n.between(r,t-r,e-r,i))return}this.nextLayer.between(t,e,i)}}iter(t=0){return Ce.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Ce.from(t).goto(e)}static compare(t,e,i,s,r=-1){let n=t.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=r)),h=e.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=r)),o=Ue(n,h,i),l=new De(n,o,r),u=new De(h,o,r);i.iterGaps(((t,e,i)=>ze(l,t,u,e,i,s))),i.empty&&0==i.length&&ze(l,0,u,0,0,s)}static eq(t,e,i=0,s){null==s&&(s=1e9);let r=t.filter((t=>!t.isEmpty&&e.indexOf(t)<0)),n=e.filter((e=>!e.isEmpty&&t.indexOf(e)<0));if(r.length!=n.length)return!1;if(!r.length)return!0;let h=Ue(r,n),o=new De(r,h,0).goto(i),l=new De(n,h,0).goto(i);for(;;){if(o.to!=l.to||!He(o.active,l.active)||o.point&&(!l.point||!o.point.eq(l.point)))return!1;if(o.to>s)return!0;o.next(),l.next()}}static spans(t,e,i,s,r=-1){let n=new De(t,null,r).goto(e),h=e,o=n.openStart;for(;;){let t=Math.min(n.to,i);if(n.point?(s.point(h,t,n.point,n.activeForPoint(n.to),o,n.pointRank),o=n.openEnd(t)+(n.to>t?1:0)):t>h&&(s.span(h,t,n.active,o),o=n.openEnd(t)),n.to>i)break;h=n.to,n.next()}return o}static of(t,e=!1){let i=new je;for(let s of t instanceof Te?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i0)return t.slice().sort(_e);e=s}return t}(t):t)i.add(s.from,s.to,s.value);return i.finish()}}Ae.empty=new Ae([],[],null,-1),Ae.empty.nextLayer=Ae.empty;class je{constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}finishChunk(t){this.chunks.push(new Ee(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new je)).add(t,e,i)}addInner(t,e,i){let s=t-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(s<0||(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),0))}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(Ae.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=Ae.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Ue(t,e,i){let s=new Map;for(let e of t)for(let t=0;t=this.minPoint)break}}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=i&&s.push(new Ve(n,e,i,r));return 1==s.length?s[0]:new Ce(s)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let t=this.heap.length>>1;t>=0;t--)Ge(this.heap,t);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let t=this.heap.length>>1;t>=0;t--)Ge(this.heap,t);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),Ge(this.heap,0)}}}function Ge(t,e){for(let i=t[e];;){let s=1+(e<<1);if(s>=t.length)break;let r=t[s];if(s+1=0&&(r=t[s+1],s++),i.compare(r)<0)break;t[s]=i,t[e]=r,e=s}}class De{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Ce.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){Ne(this.active,t),Ne(this.activeTo,t),Ne(this.activeRank,t),this.minActive=Be(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:s,rank:r}=this.cursor;for(;e-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>t){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),i&&Ne(i,r)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let r=this.cursor.value;if(r.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from=0&&!(this.activeRank[i]t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function ze(t,e,i,s,r,n){t.goto(e),i.goto(s);let h=s+r,o=s,l=s-e;for(;;){let e=t.to+l-i.to||t.endSide-i.endSide,s=e<0?t.to+l:i.to,r=Math.min(s,h);if(t.point||i.point?t.point&&i.point&&(t.point==i.point||t.point.eq(i.point))&&He(t.activeForPoint(t.to+l),i.activeForPoint(i.to))||n.comparePoint(o,r,t.point,i.point):r>o&&!He(t.active,i.active)&&n.compareRange(o,r,t.active,i.active),s>h)break;o=s,e<=0&&t.next(),e>=0&&i.next()}}function He(t,e){if(t.length!=e.length)return!1;for(let i=0;i=e;i--)t[i+1]=t[i];t[e]=i}function Be(t,e){let i=-1,s=1e9;for(let r=0;r=e)return s;if(s==t.length)break;r+=9==t.charCodeAt(s)?i-r%i:1,s=Qt(t,s)}return!0===s?-1:t.length}const Je="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),ti="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),ei="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class ii{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function r(t,e,n,h){let o=[],l=/^@(\w+)\b/.exec(t[0]),u=l&&"keyframes"==l[1];if(l&&null==e)return n.push(t[0]+";");for(let i in e){let h=e[i];if(/&/.test(i))r(i.split(/,\s*/).map((e=>t.map((t=>e.replace(/&/,t))))).reduce(((t,e)=>t.concat(e))),h,n);else if(h&&"object"==typeof h){if(!l)throw new RangeError("The value of a property ("+i+") should be a primitive value.");r(s(i),h,o,u)}else null!=h&&o.push(i.replace(/_.*/,"").replace(/[A-Z]/g,(t=>"-"+t.toLowerCase()))+": "+h+";")}(o.length||u)&&n.push((!i||l||h?t:t.map(i)).join(", ")+" {"+o.join(" ")+"}")}for(let e in t)r(s(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=ei[Je]||1;return ei[Je]=t+1,"ͼ"+t.toString(36)}static mount(t,e){(t[ti]||new ri(t)).mount(Array.isArray(e)?e:[e])}}let si=null;class ri{constructor(t){if(!t.head&&t.adoptedStyleSheets&&"undefined"!=typeof CSSStyleSheet){if(si)return t.adoptedStyleSheets=[si.sheet].concat(t.adoptedStyleSheets),t[ti]=si;this.sheet=new CSSStyleSheet,t.adoptedStyleSheets=[this.sheet].concat(t.adoptedStyleSheets),si=this}else{this.styleTag=(t.ownerDocument||t).createElement("style");let e=t.head||t;e.insertBefore(this.styleTag,e.firstChild)}this.modules=[],t[ti]=this}mount(t){let e=this.sheet,i=0,s=0;for(let r=0;r-1&&(this.modules.splice(h,1),s--,h=-1),-1==h){if(this.modules.splice(s++,0,n),e)for(let t=0;t",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"',229:"Q"},oi="undefined"!=typeof navigator&&/Chrome\/(\d+)/.exec(navigator.userAgent),li="undefined"!=typeof navigator&&/Apple Computer/.test(navigator.vendor),ui="undefined"!=typeof navigator&&/Gecko\/\d+/.test(navigator.userAgent),ai="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),fi="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ci=oi&&(ai||+oi[1]<57)||ui&&ai,Oi=0;Oi<10;Oi++)ni[48+Oi]=ni[96+Oi]=String(Oi);for(Oi=1;Oi<=24;Oi++)ni[Oi+111]="F"+Oi;for(Oi=65;Oi<=90;Oi++)ni[Oi]=String.fromCharCode(Oi+32),hi[Oi]=String.fromCharCode(Oi);for(var di in ni)hi.hasOwnProperty(di)||(hi[di]=ni[di]);function $i(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function pi(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function mi(t,e){if(!e.anchorNode)return!1;try{return pi(t,e.anchorNode)}catch(t){return!1}}function wi(t){return 3==t.nodeType?Ri(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function gi(t,e,i,s){return!!i&&(xi(t,e,i,s,-1)||xi(t,e,i,s,1))}function bi(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function xi(t,e,i,s,r){for(;;){if(t==i&&e==s)return!0;if(e==(r<0?0:yi(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=bi(t)+(r<0?0:1),t=i}else{if(1!=t.nodeType)return!1;if(1==(t=t.childNodes[e+(r<0?-1:0)]).nodeType&&"false"==t.contentEditable)return!1;e=r<0?yi(t):0}}}function yi(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}const Qi={left:0,right:0,top:0,bottom:0};function Pi(t,e){let i=e?t.left:t.right;return{left:i,right:i,top:t.top,bottom:t.bottom}}function vi(t){return{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}class qi{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){this.set(t.anchorNode,t.anchorOffset,t.focusNode,t.focusOffset)}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let Si,ki=null;function Ii(t){if(t.setActive)return t.setActive();if(ki)return t.focus(ki);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==ki?{get preventScroll(){return ki={preventScroll:!0},!0}}:void 0),!ki){ki=!1;for(let t=0;te)return i.domBoundsAround(t,e,l);if(a>=t&&-1==s&&(s=o,r=l),l>e&&i.dom.parentNode==this.dom){n=o,h=u;break}u=a,l=a+i.breakAfter}return{from:r,to:h<0?i+this.length:h,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:n=0?this.children[n].dom:null}}markDirty(t=!1){this.dirty|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.dirty|=2),1&e.dirty)return;e.dirty|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.dirty&&this.markParentsDirty(!0))}setDOM(t){this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=Mi){this.markDirty();for(let i=t;ithis.pos||t==this.pos&&(e>0||0==this.i||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Ei(t,e,i,s,r,n,h,o,l){let{children:u}=t,a=u.length?u[e]:null,f=n.length?n[n.length-1]:null,c=f?f.breakAfter:h;if(!(e==s&&a&&!h&&!c&&n.length<2&&a.merge(i,r,n.length?f:null,0==i,o,l))){if(s0&&(!h&&n.length&&a.merge(i,a.length,n[0],!1,o,0)?a.breakAfter=n.shift().breakAfter:(i2);var Li={mac:Bi||/Mac/.test(ji.platform),windows:/Win/.test(ji.platform),linux:/Linux|X11/.test(ji.platform),ie:Di,ie_version:Ci?Ui.documentMode||6:Gi?+Gi[1]:Vi?+Vi[1]:0,gecko:zi,gecko_version:zi?+(/Firefox\/(\d+)/.exec(ji.userAgent)||[0,0])[1]:0,chrome:!!Hi,chrome_version:Hi?+Hi[1]:0,ios:Bi,android:/Android\b/.test(ji.userAgent),webkit:Ni,safari:Fi,webkit_version:Ni?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:null!=Ui.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};class Ki extends Zi{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){3==t.nodeType&&this.createDOM(t)}merge(t,e,i){return(!i||i instanceof Ki&&!(this.length-(e-t)+i.length>256))&&(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Ki(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new Xi(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return ts(this.dom,t,e)}}class Ji extends Zi{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let t of e)t.setParent(this)}setAttrs(t){if(Yi(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.dirty|=6)}sync(t){this.dom?4&this.dirty&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t)}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof Ji&&i.mark.eq(this.mark))||t&&r<=0||et&&e.push(i=t&&(s=r),i=h,r++}let n=this.length-t;return this.length=t,s>-1&&(this.children.length=s,this.markDirty()),new Ji(this.mark,e,n)}domAtPos(t){return hs(this.dom,this.children,t)}coordsAt(t,e){return ls(this,t,e)}}function ts(t,e,i){let s=t.nodeValue.length;e>s&&(e=s);let r=e,n=e,h=0;0==e&&i<0||e==s&&i>=0?Li.chrome||Li.gecko||(e?(r--,h=1):n=0)?0:o.length-1];return Li.safari&&!h&&0==l.width&&(l=Array.prototype.find.call(o,(t=>t.width))||l),h?Pi(l,h<0):l||null}class es extends Zi{constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}static create(t,e,i){return new(t.customView||es)(t,e,i)}split(t){let e=es.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(){this.dom&&this.widget.updateDOM(this.dom)||(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}getSide(){return this.side}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof es&&this.widget.compare(i.widget))||t>0&&r<=0||e0?i.length-1:0;s=i[e],!(t>0?0==e:e==i.length-1||s.top0?-1:1);return 0==t&&e>0||t==this.length&&e<=0?s:Pi(s,0==t)}get isEditable(){return!1}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class is extends es{domAtPos(t){let{topView:e,text:i}=this.widget;return e?ss(t,0,e,i,((t,e)=>t.domAtPos(e)),(t=>new Xi(i,Math.min(t,i.nodeValue.length)))):new Xi(i,Math.min(t,i.nodeValue.length))}sync(){this.setDOM(this.widget.toDOM())}localPosFromDOM(t,e){let{topView:i,text:s}=this.widget;return i?rs(t,e,i,s):Math.min(e,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(t,e){let{topView:i,text:s}=this.widget;return i?ss(t,e,i,s,((t,e,i)=>t.coordsAt(e,i)),((t,e)=>ts(s,t,e))):ts(s,t,e)}destroy(){var t;super.destroy(),null===(t=this.widget.topView)||void 0===t||t.destroy()}get isEditable(){return!0}}function ss(t,e,i,s,r,n){if(i instanceof Ji){for(let h of i.children){let i=pi(h.dom,s),o=i?s.nodeValue.length:h.length;if(t=0;)if(e<0?s>0:s0?-1:1);return i&&i.tope.top?{left:e.left,right:e.right,top:i.top,bottom:i.bottom}:e}get overrideDOMText(){return ft.empty}}function hs(t,e,i){let s=0;for(let r=0;sr&&i0;s--){let i=e[s-1].dom;if(i.parentNode==t)return Xi.after(i)}return new Xi(t,0)}function os(t,e,i){let s,{children:r}=t;i>0&&e instanceof Ji&&r.length&&(s=r[r.length-1])instanceof Ji&&s.mark.eq(e.mark)?os(s,e.children[0],i-1):(r.push(e),e.setParent(t)),t.length+=e.length}function ls(t,e,i){for(let s=0,r=0;r0?o>=e:o>e)&&(e0)){let t=0;if(o==s){if(h.getSide()<=0)continue;t=i=-h.getSide()}let r=h.coordsAt(Math.max(0,e-s),i);return t&&r?Pi(r,i<0):r}s=o}let s=t.dom.lastChild;if(!s)return t.dom.getBoundingClientRect();let r=wi(s);return r[r.length-1]||null}function us(t,e){for(let i in t)"class"==i&&e.class?e.class+=" "+t.class:"style"==i&&e.style?e.style+=";"+t.style:e[i]=t[i];return e}function as(t,e){if(t==e)return!0;if(!t||!e)return!1;let i=Object.keys(t),s=Object.keys(e);if(i.length!=s.length)return!1;for(let r of i)if(-1==s.indexOf(r)||t[r]!==e[r])return!1;return!0}function fs(t,e,i){let s=null;if(e)for(let r in e)i&&r in i||t.removeAttribute(s=r);if(i)for(let r in i)e&&e[r]==i[r]||t.setAttribute(s=r,i[r]);return!!s}Ki.prototype.children=es.prototype.children=ns.prototype.children=Mi;class cs{eq(t){return!1}updateDOM(t){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}ignoreEvent(t){return!0}get customView(){return null}destroy(t){}}var Os=function(t){return t[t.Text=0]="Text",t[t.WidgetBefore=1]="WidgetBefore",t[t.WidgetAfter=2]="WidgetAfter",t[t.WidgetRange=3]="WidgetRange",t}(Os||(Os={}));class ds extends Ze{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new $s(t)}static widget(t){let e=t.side||0,i=!!t.block;return e+=i?e>0?3e8:-4e8:e>0?1e8:-1e8,new ms(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,s=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:r,end:n}=ws(t,s);e=(r?s?-3e8:-1:5e8)-1,i=1+(n?s?2e8:1:-6e8)}return new ms(t,e,i,s,t.widget||null,!0)}static line(t){return new ps(t)}static set(t,e=!1){return Ae.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}ds.none=Ae.empty;class $s extends ds{constructor(t){let{start:e,end:i}=ws(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){return this==t||t instanceof $s&&this.tagName==t.tagName&&this.class==t.class&&as(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)}}$s.prototype.point=!1;class ps extends ds{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof ps&&as(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)}}ps.prototype.mapMode=Yt.TrackBefore,ps.prototype.point=!0;class ms extends ds{constructor(t,e,i,s,r,n){super(e,i,r,t),this.block=s,this.isReplace=n,this.mapMode=s?e<=0?Yt.TrackBefore:Yt.TrackAfter:Yt.TrackDel}get type(){return this.startSide=5}eq(t){return t instanceof ms&&function(t,e){return t==e||!!(t&&e&&t.compare(e))}(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)}}function ws(t,e=!1){let{inclusiveStart:i,inclusiveEnd:s}=t;return null==i&&(i=t.inclusive),null==s&&(s=t.inclusive),{start:null!=i?i:e,end:null!=s?s:e}}function gs(t,e,i,s=0){let r=i.length-1;r>=0&&i[r]+s>=t?i[r]=Math.max(i[r],e):i.push(t,e)}ms.prototype.point=!0;class bs extends Zi{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,s,r,n){if(i){if(!(i instanceof bs))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Ai(this,t,e,i?i.children:[],r,n),!0}split(t){let e=new bs;if(e.breakAfter=this.breakAfter,0==this.length)return e;let{i,off:s}=this.childPos(t);s&&(e.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let t=i;t0&&0==this.children[i-1].length;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=void 0===this.prevAttrs?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){as(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){os(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=us(e,this.attrs||{})),i&&(this.attrs=us({class:i},this.attrs||{}))}domAtPos(t){return hs(this.dom,this.children,t)}reuseDOM(t){"DIV"==t.nodeName&&(this.setDOM(t),this.dirty|=6)}sync(t){var e;this.dom?4&this.dirty&&(Yi(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),void 0!==this.prevAttrs&&(fs(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t);let i=this.dom.lastChild;for(;i&&Zi.get(i)instanceof Ji;)i=i.lastChild;if(!(i&&this.length&&("BR"==i.nodeName||0!=(null===(e=Zi.get(i))||void 0===e?void 0:e.isEditable)||Li.ios&&this.children.some((t=>t instanceof Ki))))){let t=document.createElement("BR");t.cmIgnore=!0,this.dom.appendChild(t)}}measureTextSize(){if(0==this.children.length||this.length>20)return null;let t=0;for(let e of this.children){if(!(e instanceof Ki))return null;let i=wi(e.dom);if(1!=i.length)return null;t+=i[0].width}return{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length}}coordsAt(t,e){return ls(this,t,e)}become(t){return!1}get type(){return Os.Text}static find(t,e){for(let i=0,s=0;i=e){if(r instanceof bs)return r;if(n>e)break}s=n+r.breakAfter}return null}}class xs extends Zi{constructor(t,e,i){super(),this.widget=t,this.length=e,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof xs&&this.widget.compare(i.widget))||t>0&&r<=0||e0;){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:s}=this.cursor.next(this.skip);if(this.skip=0,s)throw new Error("Ran out of text content when drawing inline views");if(i){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer([]),this.curLine=null,t--;continue}this.text=e,this.textOff=0}let s=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(0,i)),this.getLine().append(Qs(new Ki(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=0}}span(t,e,i,s){this.buildText(e-t,i,s),this.pos=e,this.openStart<0&&(this.openStart=s)}point(t,e,i,s,r,n){if(this.disallowBlockEffectsFor[n]&&i instanceof ms){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let h=e-t;if(i instanceof ms)if(i.block){let{type:t}=i;t!=Os.WidgetAfter||this.posCovered()||this.getLine(),this.addBlockWidget(new xs(i.widget||new Ps("div"),h,t))}else{let n=es.create(i.widget||new Ps("span"),h,i.startSide),o=this.atCursorPos&&!n.isEditable&&r<=s.length&&(t0),l=!n.isEditable&&(tt.some((t=>t))});class Ys{constructor(t,e="nearest",i="nearest",s=5,r=5){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r}map(t){return t.empty?this:new Ys(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin)}}const Xs=xe.define({map:(t,e)=>t.map(e)});function Ms(t,e,i){let s=t.facet(ks);s.length?s[0](e):window.onerror?window.onerror(String(e),i,void 0,void 0,e):i?console.error(i+":",e):console.error(e)}const Zs=Dt.define({combine:t=>!t.length||t[0]});let Ts=0;const _s=Dt.define();class Es{constructor(t,e,i,s){this.id=t,this.create=e,this.domEventHandlers=i,this.extension=s(this)}static define(t,e){const{eventHandlers:i,provide:s,decorations:r}=e||{};return new Es(Ts++,t,i,(t=>{let e=[_s.of(t)];return r&&e.push(Vs.of((e=>{let i=e.plugin(t);return i?r(i):ds.none}))),s&&e.push(s(t)),e}))}static fromClass(t,e){return Es.define((e=>new t(e)),e)}}class As{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(Ms(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){Ms(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(null===(e=this.value)||void 0===e?void 0:e.destroy)try{this.value.destroy()}catch(e){Ms(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const js=Dt.define(),Us=Dt.define(),Vs=Dt.define(),Cs=Dt.define(),Gs=Dt.define(),Ds=Dt.define();class zs{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new zs(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toAu)break;r+=2}if(!o)return i;new zs(o.fromA,o.toA,o.fromB,o.toB).addToSet(i),n=o.toA,h=o.toB}}}class Hs{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=Mt.empty(this.startState.doc.length);for(let t of i)this.changes=this.changes.compose(t.changes);let s=[];this.changes.iterChangedRanges(((t,e,i,r)=>s.push(new zs(t,e,i,r)))),this.changedRanges=s;let r=t.hasFocus;r!=t.inputState.notifiedFocused&&(t.inputState.notifiedFocused=r,this.flags|=1)}static create(t,e,i){return new Hs(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(10&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some((t=>t.selection))}get empty(){return 0==this.flags&&0==this.transactions.length}}var Ns=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(Ns||(Ns={}));const Fs=Ns.LTR,Bs=Ns.RTL;function Ls(t){let e=[];for(let i=0;i=e){if(h.level==i)return n;(r<0||(0!=s?s<0?h.frome:t[r].level>h.level))&&(r=n)}}if(r<0)throw new RangeError("Index out of range");return r}}const rr=[];function nr(t){return[new sr(0,t,0)]}let hr="";function or(t,e,i,s,r){var n;let h=s.head-t.from,o=-1;if(0==h){if(!r||!t.length)return null;e[0].level!=i&&(h=e[0].side(!1,i),o=0)}else if(h==t.length){if(r)return null;let t=e[e.length-1];t.level!=i&&(h=t.side(!0,i),o=e.length-1)}o<0&&(o=sr.find(e,h,null!==(n=s.bidiLevel)&&void 0!==n?n:-1,s.assoc));let l=e[o];h==l.side(r,i)&&(l=e[o+=r?1:-1],h=l.side(!r,i));let u=r==(l.dir==i),a=Qt(t.text,h,u);if(hr=t.text.slice(Math.min(h,a),Math.max(h,a)),a!=l.side(r,i))return Vt.cursor(a+t.from,u?-1:1,l.level);let f=o==(r?e.length-1:0)?null:e[o+(r?1:-1)];return f||l.level==i?f&&f.level1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=h-1);i=n+h}}readNode(t){if(t.cmIgnore)return;let e=Zi.get(t),i=e&&e.overrideDOMText;if(null!=i){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;)t.lineBreak?this.lineBreak():this.append(t.value)}else 3==t.nodeType?this.readTextNode(t):"BR"==t.nodeName?t.nextSibling&&this.lineBreak():1==t.nodeType&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(3==t.nodeType?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+Math.min(e,i.offset))}}function ar(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}class fr{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class cr extends Zi{constructor(t){super(),this.view=t,this.compositionDeco=ds.none,this.decorations=[],this.dynamicDecorationMap=[],this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new bs],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new zs(0,0,0,t.state.doc.length)],0)}get root(){return this.view.root}get editorView(){return this.view}get length(){return this.view.state.doc.length}update(t){let e=t.changedRanges;this.minWidth>0&&e.length&&(e.every((({fromA:t,toA:e})=>ethis.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.view.inputState.composing<0?this.compositionDeco=ds.none:(t.transactions.length||this.dirty)&&(this.compositionDeco=function(t,e){let i=dr(t);if(!i)return ds.none;let{from:s,to:r,node:n,text:h}=i,o=e.mapPos(s,1),l=Math.max(o,e.mapPos(r,-1)),{state:u}=t,a=3==n.nodeType?n.nodeValue:new ur([],u).readRange(n.firstChild,null).text;if(l-o{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let t=Li.chrome||Li.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.sync(t),this.dirty=0,t&&(t.written||i.selectionRange.focusNode!=t.node)&&(this.forceSelection=!0),this.dom.style.height=""}));let s=[];if(this.view.viewport.from||this.view.viewport.to=0?t[e]:null;if(!s)break;let{fromA:r,toA:n,fromB:h,toB:o}=s,{content:l,breakAtStart:u,openStart:a,openEnd:f}=ys.build(this.view.state.doc,h,o,this.decorations,this.dynamicDecorationMap),{i:c,off:O}=i.findPos(n,1),{i:d,off:$}=i.findPos(r,-1);Ei(this,d,$,c,O,l,u,a,f)}}updateSelection(t=!1,e=!1){if(!t&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange(),!e&&!this.mayControlSelection()||Li.ios&&this.view.inputState.rapidCompositionStart)return;let i=this.forceSelection;this.forceSelection=!1;let s=this.view.state.selection.main,r=this.domAtPos(s.anchor),n=s.empty?r:this.domAtPos(s.head);if(Li.gecko&&s.empty&&1==(h=r).node.nodeType&&h.node.firstChild&&(0==h.offset||"false"==h.node.childNodes[h.offset-1].contentEditable)&&(h.offset==h.node.childNodes.length||"false"==h.node.childNodes[h.offset].contentEditable)){let t=document.createTextNode("");this.view.observer.ignore((()=>r.node.insertBefore(t,r.node.childNodes[r.offset]||null))),r=n=new Xi(t,0),i=!0}var h;let o=this.view.observer.selectionRange;!i&&o.focusNode&&gi(r.node,r.offset,o.anchorNode,o.anchorOffset)&&gi(n.node,n.offset,o.focusNode,o.focusOffset)||(this.view.observer.ignore((()=>{Li.android&&Li.chrome&&this.dom.contains(o.focusNode)&&function(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(o.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let t=$i(this.root);if(t)if(s.empty){if(Li.gecko){let t=(e=r.node,i=r.offset,1!=e.nodeType?0:(i&&"false"==e.childNodes[i-1].contentEditable?1:0)|(is.head&&([r,n]=[n,r]),e.setEnd(n.node,n.offset),e.setStart(r.node,r.offset),t.removeAllRanges(),t.addRange(e)}var e,i})),this.view.observer.setSelectionRange(r,n)),this.impreciseAnchor=r.precise?null:new Xi(o.anchorNode,o.anchorOffset),this.impreciseHead=n.precise?null:new Xi(o.focusNode,o.focusOffset)}enforceCursorAssoc(){if(this.compositionDeco.size)return;let t=this.view.state.selection.main,e=$i(this.root);if(!(e&&t.empty&&t.assoc&&e.modify))return;let i=bs.find(this,t.head);if(!i)return;let s=i.posAtStart;if(t.head==s||t.head==s+i.length)return;let r=this.coordsAt(t.head,-1),n=this.coordsAt(t.head,1);if(!r||!n||r.bottom>n.top)return;let h=this.domAtPos(t.head+t.assoc);e.collapse(h.node,h.offset),e.modify("move",t.assoc<0?"forward":"backward","lineboundary")}mayControlSelection(){let t=this.root.activeElement;return t==this.dom||mi(this.dom,this.view.observer.selectionRange)&&!(t&&this.dom.contains(t))}nearest(t){for(let e=t;e;){let t=Zi.get(e);if(t&&t.rootView==this)return t;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;en||t==n&&r.type!=Os.WidgetBefore&&r.type!=Os.WidgetAfter&&(!s||2==e||this.children[s-1].breakAfter||this.children[s-1].type==Os.WidgetBefore&&e>-2))return r.coordsAt(t-n,e);i=n}}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,n=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,h=-1,o=this.view.textDirection==Ns.LTR;for(let t=0,l=0;ls)break;if(t>=i){let i=u.dom.getBoundingClientRect();if(e.push(i.height),n){let e=u.dom.lastChild,s=e?wi(e):[];if(s.length){let e=s[s.length-1],n=o?e.right-i.left:i.right-e.left;n>h&&(h=n,this.minWidth=r,this.minWidthFrom=t,this.minWidthTo=a)}}}t=a+u.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return"rtl"==getComputedStyle(this.children[e].dom).direction?Ns.RTL:Ns.LTR}measureTextSize(){for(let t of this.children)if(t instanceof bs){let e=t.measureTextSize();if(e)return e}let t,e,i=document.createElement("div");return i.className="cm-line",i.style.width="99999px",i.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore((()=>{this.dom.appendChild(i);let s=wi(i.firstChild)[0];t=i.getBoundingClientRect().height,e=s?s.width/27:7,i.remove()})),{lineHeight:t,charWidth:e}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new _i(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],n=r?r.from-1:this.length;if(n>i){let s=e.lineBlockAt(n).bottom-e.lineBlockAt(i).top;t.push(ds.replace({widget:new Or(s),block:!0,inclusive:!0,isBlockGap:!0}).range(i,n))}if(!r)break;i=r.to+1}return ds.set(t)}updateDeco(){let t=this.view.state.facet(Vs).map(((t,e)=>(this.dynamicDecorationMap[e]="function"==typeof t)?t(this.view):t));for(let e=t.length;ei.anchor?-1:1);if(!s)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(s={left:Math.min(s.left,e.left),top:Math.min(s.top,e.top),right:Math.max(s.right,e.right),bottom:Math.max(s.bottom,e.bottom)});let r=0,n=0,h=0,o=0;for(let t of this.view.state.facet(Gs).map((t=>t(this.view))))if(t){let{left:e,right:i,top:s,bottom:l}=t;null!=e&&(r=Math.max(r,e)),null!=i&&(n=Math.max(n,i)),null!=s&&(h=Math.max(h,s)),null!=l&&(o=Math.max(o,l))}let l={left:s.left-r,top:s.top-h,right:s.right+n,bottom:s.bottom+o};!function(t,e,i,s,r,n,h,o){let l=t.ownerDocument,u=l.defaultView;for(let a=t;a;)if(1==a.nodeType){let t,f=a==l.body;if(f)t=vi(u);else{if(a.scrollHeight<=a.clientHeight&&a.scrollWidth<=a.clientWidth){a=a.parentNode;continue}let e=a.getBoundingClientRect();t={left:e.left,right:e.left+a.clientWidth,top:e.top,bottom:e.top+a.clientHeight}}let c=0,O=0;if("nearest"==r)e.top0&&e.bottom>t.bottom+O&&(O=e.bottom-t.bottom+O+h)):e.bottom>t.bottom&&(O=e.bottom-t.bottom+h,i<0&&e.top-O0&&e.right>t.right+c&&(c=e.right-t.right+c+n)):e.right>t.right&&(c=e.right-t.right+n,i<0&&e.left0&&i<=0)e=yi(t=t.childNodes[e-1]);else{if(!(1==t.nodeType&&e=0))return null;t=t.childNodes[e],e=0}}}class mr{constructor(){this.changes=[]}compareRange(t,e){gs(t,e,this.changes)}comparePoint(t,e){gs(t,e,this.changes)}}function wr(t,e){return e.left>t?e.left-t:Math.max(0,t-e.right)}function gr(t,e){return e.top>t?e.top-t:Math.max(0,t-e.bottom)}function br(t,e){return t.tope.top+1}function xr(t,e){return et.bottom?{top:t.top,left:t.left,right:t.right,bottom:e}:t}function Qr(t,e,i){let s,r,n,h,o,l,u,a;for(let f=t.firstChild;f;f=f.nextSibling){let t=wi(f);for(let c=0;c$||h==$&&n>d)&&(s=f,r=O,n=d,h=$),0==d?i>O.bottom&&(!u||u.bottomO.top)&&(l=f,a=O):u&&br(u,O)?u=yr(u,O.bottom):a&&br(a,O)&&(a=xr(a,O.top))}}if(u&&u.bottom>=i?(s=o,r=u):a&&a.top<=i&&(s=l,r=a),!s)return{node:t,offset:0};let f=Math.max(r.left,Math.min(r.right,e));return 3==s.nodeType?Pr(s,f,i):n||"true"!=s.contentEditable?{node:t,offset:Array.prototype.indexOf.call(t.childNodes,s)+(e>=(r.left+r.right)/2?1:0)}:Qr(s,f,i)}function Pr(t,e,i){let s=t.nodeValue.length,r=-1,n=1e9,h=0;for(let o=0;oi?u.top-i:i-u.bottom)-1;if(u.left-1<=e&&u.right+1>=e&&a=(u.left+u.right)/2,s=i;if((Li.chrome||Li.gecko)&&Ri(t,o).getBoundingClientRect().left==u.right&&(s=!i),a<=0)return{node:t,offset:o+(s?1:0)};r=o+(s?1:0),n=a}}}return{node:t,offset:r>-1?r:h>0?t.nodeValue.length:0}}function vr(t,{x:e,y:i},s,r=-1){var n;let h,o=t.contentDOM.getBoundingClientRect(),l=o.top+t.viewState.paddingTop,{docHeight:u}=t.viewState,a=i-l;if(a<0)return 0;if(a>u)return t.state.doc.length;for(let e=t.defaultLineHeight/2,i=!1;h=t.elementAtHeight(a),h.type!=Os.Text;)for(;a=r>0?h.bottom+e:h.top-e,!(a>=0&&a<=u);){if(i)return s?null:0;i=!0,r=-r}i=l+a;let f=h.from;if(ft.viewport.to)return t.viewport.to==t.state.doc.length?t.state.doc.length:s?null:qr(t,o,h,e,i);let c=t.dom.ownerDocument,O=t.root.elementFromPoint?t.root:c,d=O.elementFromPoint(e,i);d&&!t.contentDOM.contains(d)&&(d=null),d||(e=Math.max(o.left+1,Math.min(o.right-1,e)),d=O.elementFromPoint(e,i),d&&!t.contentDOM.contains(d)&&(d=null));let $,p=-1;if(d&&0!=(null===(n=t.docView.nearest(d))||void 0===n?void 0:n.isEditable))if(c.caretPositionFromPoint){let t=c.caretPositionFromPoint(e,i);t&&({offsetNode:$,offset:p}=t)}else if(c.caretRangeFromPoint){let t=c.caretRangeFromPoint(e,i);t&&(({startContainer:$,startOffset:p}=t),Li.safari&&function(t,e,i){let s;if(3!=t.nodeType||e!=(s=t.nodeValue.length))return!1;for(let e=t.nextSibling;e;e=e.nextSibling)if(1!=e.nodeType||"BR"!=e.nodeName)return!1;return Ri(t,s-1,s).getBoundingClientRect().left>i}($,p,e)&&($=void 0))}if(!$||!t.docView.dom.contains($)){let s=bs.find(t.docView,f);if(!s)return a>h.top+h.height/2?h.to:h.from;({node:$,offset:p}=Qr(s.dom,e,i))}return t.docView.posFromDOM($,p)}function qr(t,e,i,s,r){let n=Math.round((s-e.left)*t.defaultCharacterWidth);t.lineWrapping&&i.height>1.5*t.defaultLineHeight&&(n+=Math.floor((r-i.top)/t.defaultLineHeight)*t.viewState.heightOracle.lineLength);let h=t.state.sliceDoc(i.from,i.to);return i.from+Ke(h,n,t.state.tabSize)}function Sr(t,e,i,s){let r=t.state.doc.lineAt(e.head),n=t.bidiSpans(r),h=t.textDirectionAt(r.from);for(let o=e,l=null;;){let e=or(r,n,h,o,i),u=hr;if(!e){if(r.number==(i?t.state.doc.lines:1))return o;u="\n",r=t.state.doc.line(r.number+(i?1:-1)),n=t.bidiSpans(r),e=Vt.cursor(i?r.from:r.to)}if(l){if(!l(u))return o}else{if(!s)return e;l=s(u)}o=e}}function kr(t,e,i){let s=t.state.facet(Cs).map((e=>e(t)));for(;;){let t=!1;for(let r of s)r.between(i.from-1,i.from+1,((s,r,n)=>{i.from>s&&i.fromi.from?Vt.cursor(s,1):Vt.cursor(r,-1),t=!0)}));if(!t)return i}}class Ir{constructor(t){this.lastKeyCode=0,this.lastKeyTime=0,this.chromeScrollHack=-1,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.rapidCompositionStart=!1,this.mouseSelection=null;for(let e in Mr){let i=Mr[e];t.contentDOM.addEventListener(e,(s=>{Xr(t,s)&&!this.ignoreDuringComposition(s)&&("keydown"==e&&this.keydown(t,s)||(this.mustFlushObserver(s)&&t.observer.forceFlush(),this.runCustomHandlers(e,t,s)?s.preventDefault():i(t,s)))})),this.registeredEvents.push(e)}Li.chrome&&Li.chrome_version>=102&&t.scrollDOM.addEventListener("wheel",(()=>{this.chromeScrollHack<0?t.contentDOM.style.pointerEvents="none":window.clearTimeout(this.chromeScrollHack),this.chromeScrollHack=setTimeout((()=>{this.chromeScrollHack=-1,t.contentDOM.style.pointerEvents=""}),100)}),{passive:!0}),this.notifiedFocused=t.hasFocus,Li.safari&&t.contentDOM.addEventListener("input",(()=>null))}setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}ensureHandlers(t,e){var i;let s;this.customHandlers=[];for(let r of e)if(s=null===(i=r.update(t).spec)||void 0===i?void 0:i.domEventHandlers){this.customHandlers.push({plugin:r.value,handlers:s});for(let e in s)this.registeredEvents.indexOf(e)<0&&"scroll"!=e&&(this.registeredEvents.push(e),t.contentDOM.addEventListener(e,(i=>{Xr(t,i)&&this.runCustomHandlers(e,t,i)&&i.preventDefault()})))}}runCustomHandlers(t,e,i){for(let s of this.customHandlers){let r=s.handlers[t];if(r)try{if(r.call(s.plugin,i,e)||i.defaultPrevented)return!0}catch(t){Ms(e.state,t)}}return!1}runScrollHandlers(t,e){for(let i of this.customHandlers){let s=i.handlers.scroll;if(s)try{s.call(i.plugin,e,t)}catch(e){Ms(t.state,e)}}}keydown(t,e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),9==e.keyCode&&Date.now()t.keyCode==e.keyCode)))||e.ctrlKey||e.altKey||e.metaKey||e.synthetic||(this.pendingIOSKey=i,setTimeout((()=>this.flushIOSKey(t)),250),0))}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(this.pendingIOSKey=void 0,Wi(t.contentDOM,e.key,e.keyCode))}ignoreDuringComposition(t){return!!/^key/.test(t.type)&&(this.composing>0||!!(Li.safari&&Date.now()-this.compositionEndedAt<100)&&(this.compositionEndedAt=0,!0))}mustFlushObserver(t){return"keydown"==t.type&&229!=t.keyCode||"compositionend"==t.type&&!Li.ios}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.mouseSelection&&this.mouseSelection.update(t),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}const Rr=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Wr=[16,17,18,20,91,92,224,225];class Yr{constructor(t,e,i,s){this.view=t,this.style=i,this.mustSelect=s,this.lastEvent=e;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(Xe.allowMultipleSelections)&&function(t,e){let i=t.state.facet(vs);return i.length?i[0](e):Li.mac?e.metaKey:e.ctrlKey}(t,e),this.dragMove=function(t,e){let i=t.state.facet(qs);return i.length?i[0](e):Li.mac?!e.altKey:!e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let s=$i(t.root);if(!s||0==s.rangeCount)return!0;let r=s.getRangeAt(0).getClientRects();for(let t=0;t=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}(t,e)||1!=Hr(e))&&null,!1===this.dragging&&(e.preventDefault(),this.select(e))}move(t){if(0==t.buttons)return this.destroy();!1===this.dragging&&this.select(this.lastEvent=t)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}select(t){let e=this.style.get(t,this.extend,this.multiple);!this.mustSelect&&e.eq(this.view.state.selection)&&e.main.assoc==this.view.state.selection.main.assoc||this.view.dispatch({selection:e,userEvent:"select.pointer",scrollIntoView:!0}),this.mustSelect=!1}update(t){t.docChanged&&this.dragging&&(this.dragging=this.dragging.map(t.changes)),this.style.update(t)&&setTimeout((()=>this.select(this.lastEvent)),20)}}function Xr(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,s=e.target;s!=t.contentDOM;s=s.parentNode)if(!s||11==s.nodeType||(i=Zi.get(s))&&i.ignoreEvent(e))return!1;return!0}const Mr=Object.create(null),Zr=Li.ie&&Li.ie_version<15||Li.ios&&Li.webkit_version<604;function Tr(t,e){let i,{state:s}=t,r=1,n=s.toText(e),h=n.lines==s.selection.ranges.length,o=null!=Fr&&s.selection.ranges.every((t=>t.empty))&&Fr==n.toString();if(o){let t=-1;i=s.changeByRange((i=>{let o=s.doc.lineAt(i.from);if(o.from==t)return{range:i};t=o.from;let l=s.toText((h?n.line(r++).text:e)+s.lineBreak);return{changes:{from:o.from,insert:l},range:Vt.cursor(i.from+l.length)}}))}else i=h?s.changeByRange((t=>{let e=n.line(r++);return{changes:{from:t.from,to:t.to,insert:e.text},range:Vt.cursor(t.from+e.length)}})):s.replaceSelection(n);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Mr.keydown=(t,e)=>{t.inputState.setSelectionOrigin("select"),27==e.keyCode?t.inputState.lastEscPress=Date.now():Wr.indexOf(e.keyCode)<0&&(t.inputState.lastEscPress=0)};let _r=0;function Er(t,e,i,s){if(1==s)return Vt.cursor(e,i);if(2==s)return function(t,e,i=1){let s=t.charCategorizer(e),r=t.doc.lineAt(e),n=e-r.from;if(0==r.length)return Vt.cursor(e);0==n?i=1:n==r.length&&(i=-1);let h=n,o=n;i<0?h=Qt(r.text,n,!1):o=Qt(r.text,n);let l=s(r.text.slice(h,o));for(;h>0;){let t=Qt(r.text,h,!1);if(s(r.text.slice(t,h))!=l)break;h=t}for(;o{_r=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},Mr.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},Mr.mousedown=(t,e)=>{if(t.observer.flush(),_r>Date.now()-2e3&&1==Hr(e))return;let i=null;for(let s of t.state.facet(Ss))if(i=s(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=Vr(t,e),s=Hr(e),r=t.state.selection,n=i,h=e;return{update(t){t.docChanged&&(i&&(i.pos=t.changes.mapPos(i.pos)),r=r.map(t.changes),h=null)},get(e,o,l){let u;if(h&&e.clientX==h.clientX&&e.clientY==h.clientY?u=n:(u=n=Vr(t,e),h=e),!u||!i)return r;let a=Er(t,u.pos,u.bias,s);if(i.pos!=u.pos&&!o){let e=Er(t,i.pos,i.bias,s),r=Math.min(e.from,a.from),n=Math.max(e.to,a.to);a=rIi(t.contentDOM))),t.inputState.startMouseSelection(new Yr(t,e,i,s))}};let Ar=(t,e)=>t>=e.top&&t<=e.bottom,jr=(t,e,i)=>Ar(e,i)&&t>=i.left&&t<=i.right;function Ur(t,e,i,s){let r=bs.find(t.docView,e);if(!r)return 1;let n=e-r.posAtStart;if(0==n)return 1;if(n==r.length)return-1;let h=r.coordsAt(n,-1);if(h&&jr(i,s,h))return-1;let o=r.coordsAt(n,1);return o&&jr(i,s,o)?1:h&&Ar(s,h)?-1:1}function Vr(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:i,bias:Ur(t,i,e.clientX,e.clientY)}}const Cr=Li.ie&&Li.ie_version<=11;let Gr=null,Dr=0,zr=0;function Hr(t){if(!Cr)return t.detail;let e=Gr,i=zr;return Gr=t,zr=Date.now(),Dr=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Dr+1)%3:1}function Nr(t,e,i,s){if(!i)return;let r=t.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:n}=t.inputState,h=s&&n&&n.dragging&&n.dragMove?{from:n.dragging.from,to:n.dragging.to}:null,o={from:r,insert:i},l=t.state.changes(h?[h,o]:o);t.focus(),t.dispatch({changes:l,selection:{anchor:l.mapPos(r,-1),head:l.mapPos(r,1)},userEvent:h?"move.drop":"input.drop"})}Mr.dragstart=(t,e)=>{let{selection:{main:i}}=t.state,{mouseSelection:s}=t.inputState;s&&(s.dragging=i),e.dataTransfer&&(e.dataTransfer.setData("Text",t.state.sliceDoc(i.from,i.to)),e.dataTransfer.effectAllowed="copyMove")},Mr.drop=(t,e)=>{if(!e.dataTransfer)return;if(t.state.readOnly)return e.preventDefault();let i=e.dataTransfer.files;if(i&&i.length){e.preventDefault();let s=Array(i.length),r=0,n=()=>{++r==i.length&&Nr(t,e,s.filter((t=>null!=t)).join(t.state.lineBreak),!1)};for(let t=0;t{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(s[t]=e.result),n()},e.readAsText(i[t])}}else Nr(t,e,e.dataTransfer.getData("Text"),!0)},Mr.paste=(t,e)=>{if(t.state.readOnly)return e.preventDefault();t.observer.flush();let i=Zr?null:e.clipboardData;i?(Tr(t,i.getData("text/plain")),e.preventDefault()):function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout((()=>{t.focus(),i.remove(),Tr(t,i.value)}),50)}(t)};let Fr=null;function Br(t){setTimeout((()=>{t.hasFocus!=t.inputState.notifiedFocused&&t.update([])}),10)}function Lr(t,e){if(t.docView.compositionDeco.size){t.inputState.rapidCompositionStart=e;try{t.update([])}finally{t.inputState.rapidCompositionStart=!1}}}Mr.copy=Mr.cut=(t,e)=>{let{text:i,ranges:s,linewise:r}=function(t){let e=[],i=[],s=!1;for(let s of t.selection.ranges)s.empty||(e.push(t.sliceDoc(s.from,s.to)),i.push(s));if(!e.length){let r=-1;for(let{from:s}of t.selection.ranges){let n=t.doc.lineAt(s);n.number>r&&(e.push(n.text),i.push({from:n.from,to:Math.min(t.doc.length,n.to+1)})),r=n.number}s=!0}return{text:e.join(t.lineBreak),ranges:i,linewise:s}}(t.state);if(!i&&!r)return;Fr=r?i:null;let n=Zr?null:e.clipboardData;n?(e.preventDefault(),n.clearData(),n.setData("text/plain",i)):function(t,e){let i=t.dom.parentNode;if(!i)return;let s=i.appendChild(document.createElement("textarea"));s.style.cssText="position: fixed; left: -10000px; top: 10px",s.value=e,s.focus(),s.selectionEnd=e.length,s.selectionStart=0,setTimeout((()=>{s.remove(),t.focus()}),50)}(t,i),"cut"!=e.type||t.state.readOnly||t.dispatch({changes:s,scrollIntoView:!0,userEvent:"delete.cut"})},Mr.focus=Br,Mr.blur=t=>{t.observer.clearSelectionRange(),Br(t)},Mr.compositionstart=Mr.compositionupdate=t=>{null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0,t.docView.compositionDeco.size&&(t.observer.flush(),Lr(t,!0)))},Mr.compositionend=t=>{t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionFirstChange=null,setTimeout((()=>{t.inputState.composing<0&&Lr(t,!1)}),50)},Mr.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},Mr.beforeinput=(t,e)=>{var i;let s;if(Li.chrome&&Li.android&&(s=Rr.find((t=>t.inputType==e.inputType)))&&(t.observer.delayAndroidKey(s.key,s.keyCode),"Backspace"==s.key||"Delete"==s.key)){let e=(null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0;setTimeout((()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())}),100)}};const Kr=["pre-wrap","normal","pre-line","break-spaces"];class Jr{constructor(){this.doc=ft.empty,this.lineWrapping=!1,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength)),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Kr.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i-1,h=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=n;if(this.lineWrapping=n,this.lineHeight=e,this.charWidth=i,this.lineLength=s,h){this.heightSamples={};for(let t=0;t0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>rn&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return nn.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let r=this;for(let n=s.length-1;n>=0;n--){let{fromA:h,toA:o,fromB:l,toB:u}=s[n],a=r.lineAt(h,sn.ByPosNoHeight,e,0,0),f=a.to>=o?a:r.lineAt(o,sn.ByPosNoHeight,e,0,0);for(u+=f.to-o,o=f.to;n>0&&a.from<=s[n-1].toA;)h=s[n-1].fromA,l=s[n-1].fromB,n--,h2*r){let r=t[e-1];r.break?t.splice(--e,1,r.left,null,r.right):t.splice(--e,1,r.left,r.right),i+=1+r.break,s-=r.size}else{if(!(r>2*s))break;{let e=t[i];e.break?t.splice(i,1,e.left,null,e.right):t.splice(i,1,e.left,e.right),i+=2+e.break,r-=e.size}}else if(s=r&&n(this.blockAt(0,i,s,r))}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setHeight(t,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class on extends hn{constructor(t,e){super(t,e,Os.Text),this.collapsed=0,this.widgetHeight=0}replace(t,e,i){let s=i[0];return 1==i.length&&(s instanceof on||s instanceof ln&&4&s.flags)&&Math.abs(this.length-s.length)<10?(s instanceof ln?s=new on(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):nn.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setHeight(t,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ln extends nn{constructor(t){super(t,0)}lines(t,e){let i=t.lineAt(e).number,s=t.lineAt(e+this.length).number;return{firstLine:i,lastLine:s,lineHeight:this.height/(s-i+1)}}blockAt(t,e,i,s){let{firstLine:r,lastLine:n,lineHeight:h}=this.lines(e,s),o=Math.max(0,Math.min(n-r,Math.floor((t-i)/h))),{from:l,length:u}=e.line(r+o);return new en(l,u,i+h*o,h,Os.Text)}lineAt(t,e,i,s,r){if(e==sn.ByHeight)return this.blockAt(t,i,s,r);if(e==sn.ByPosNoHeight){let{from:e,to:s}=i.lineAt(t);return new en(e,s-e,0,0,Os.Text)}let{firstLine:n,lineHeight:h}=this.lines(i,r),{from:o,length:l,number:u}=i.lineAt(t);return new en(o,l,s+h*(u-n),h,Os.Text)}forEachLine(t,e,i,s,r,n){let{firstLine:h,lineHeight:o}=this.lines(i,r);for(let l=Math.max(t,r),u=Math.min(r+this.length,e);l<=u;){let e=i.lineAt(l);l==t&&(s+=o*(e.number-h)),n(new en(e.from,e.length,s,o,Os.Text)),s+=o,l=e.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let t=i[i.length-1];t instanceof ln?i[i.length-1]=new ln(t.length+s):i.push(null,new ln(s-1))}if(t>0){let e=i[0];e instanceof ln?i[0]=new ln(t+e.length):i.unshift(new ln(t-1),null)}return nn.of(i)}decomposeLeft(t,e){e.push(new ln(t-1),null)}decomposeRight(t,e){e.push(null,new ln(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let i=[],n=Math.max(e,s.from),h=-1,o=t.heightChanged;for(s.from>e&&i.push(new ln(s.from-e-1).updateHeight(t,e));n<=r&&s.more;){let e=t.doc.lineAt(n).length;i.length&&i.push(null);let r=s.heights[s.index++];-1==h?h=r:Math.abs(r-h)>=rn&&(h=-2);let o=new on(e,r);o.outdated=!1,i.push(o),n+=e+1}n<=r&&i.push(null,new ln(r-n).updateHeight(t,n));let l=nn.of(i);return t.heightChanged=o||h<0||Math.abs(l.height-this.height)>=rn||Math.abs(h-this.lines(t.doc,e).lineHeight)>=rn,l}return(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class un extends nn{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return 1&this.flags}blockAt(t,e,i,s){let r=i+this.left.height;return th))return l;let u=e==sn.ByPosNoHeight?sn.ByPosNoHeight:sn.ByPos;return o?l.join(this.right.lineAt(h,u,i,n,h)):this.left.lineAt(h,u,i,s,r).join(l)}forEachLine(t,e,i,s,r,n){let h=s+this.left.height,o=r+this.left.length+this.break;if(this.break)t=o&&this.right.forEachLine(t,e,i,h,o,n);else{let l=this.lineAt(o,sn.ByPos,i,s,r);t=t&&l.from<=e&&n(l),e>l.to&&this.right.forEachLine(l.to+1,e,i,h,o,n)}}replace(t,e,i){let s=this.left.length+this.break;if(ethis.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let r=[];t>0&&this.decomposeLeft(t,r);let n=r.length;for(let t of i)r.push(t);if(t>0&&an(r,n-1),e=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t2*e.size||e.size>2*t.size?nn.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=t.height+e.height,this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:r,right:n}=this,h=e+r.length+this.break,o=null;return s&&s.from<=e+r.length&&s.more?o=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=h+n.length&&s.more?o=n=n.updateHeight(t,h,i,s):n.updateHeight(t,h,i),o?this.balanced(r,n):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function an(t,e){let i,s;null==t[e]&&(i=t[e-1])instanceof ln&&(s=t[e+1])instanceof ln&&t.splice(e-1,3,new ln(i.length+1+s.length))}class fn{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof on?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new on(t-this.pos,-1)),this.writtenTo=t,e>t&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t=5)&&this.addLineDeco(s,r)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTot&&this.nodes.push(new on(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new ln(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 on)return t;let e=new on(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine(),t.type!=Os.WidgetAfter||this.isCovered||this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,t.type!=Os.WidgetBefore&&(this.covering=t)}addLineDeco(t,e){let i=this.ensureLine();i.length+=e,i.collapsed+=e,i.widgetHeight=Math.max(i.widgetHeight,t),this.writtenTo=this.pos=this.pos+e}finish(t){let e=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof on||this.isCovered?(this.writtenTot.clientHeight||t.scrollWidth>t.clientWidth)&&"visible"!=i.overflow){let e=t.getBoundingClientRect();s=Math.max(s,e.left),r=Math.min(r,e.right),n=Math.max(n,e.top),h=Math.min(h,e.bottom)}e="absolute"==i.position||"fixed"==i.position?t.offsetParent:t.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:s-i.left,right:Math.max(s,r)-i.left,top:n-(i.top+e),bottom:Math.max(n,h)-(i.top+e)}}function dn(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class $n{constructor(t,e,i){this.from=t,this.to=e,this.size=i}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i"function"!=typeof t)),this.heightMap=nn.empty().applyChanges(this.stateDeco,ft.empty,this.heightOracle.setDoc(t.doc),[new zs(0,0,0,t.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ds.set(this.lineGaps.map((t=>t.draw(!1)))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some((({from:t,to:e})=>s>=t&&s<=e))){let{from:e,to:i}=this.lineBlockAt(s);t.push(new wn(e,i))}}this.viewports=t.sort(((t,e)=>t.from-e.from)),this.scaler=this.heightMap.height<=7e6?Pn:new vn(this.heightOracle.doc,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.state.doc,0,0,(t=>{this.viewportLines.push(1==this.scaler.scale?t:qn(t,this.scaler))}))}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Vs).filter((t=>"function"!=typeof t));let s=t.changedRanges,r=zs.extendWithRanges(s,function(t,e,i){let s=new cn;return Ae.compare(t,e,i,s,0),s.changes}(i,this.stateDeco,t?t.changes:Mt.empty(this.state.doc.length))),n=this.heightMap.height;this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=n&&(t.flags|=2);let h=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.headh.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,e));let o=!t.changes.empty||2&t.flags||h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,this.updateForViewport(),o&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?Ns.RTL:Ns.LTR;let n=this.heightOracle.mustRefreshForWrapping(r),h=n||this.mustMeasureContent||this.contentDOMHeight!=e.clientHeight;this.contentDOMHeight=e.clientHeight,this.mustMeasureContent=!1;let o=0,l=0,u=parseInt(i.paddingTop)||0,a=parseInt(i.paddingBottom)||0;this.paddingTop==u&&this.paddingBottom==a||(this.paddingTop=u,this.paddingBottom=a,o|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(h=!0),this.editorWidth=t.scrollDOM.clientWidth,o|=8);let f=(this.printing?dn:On)(e,this.paddingTop),c=f.top-this.pixelViewport.top,O=f.bottom-this.pixelViewport.bottom;this.pixelViewport=f;let d=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(d!=this.inView&&(this.inView=d,d&&(h=!0)),!this.inView)return 0;let $=e.clientWidth;if(this.contentDOMWidth==$&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=$,this.editorHeight=t.scrollDOM.clientHeight,o|=8),h){let e=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(e)&&(n=!0),n||s.lineWrapping&&Math.abs($-this.contentDOMWidth)>s.charWidth){let{lineHeight:i,charWidth:h}=t.docView.measureTextSize();n=s.refresh(r,i,h,$/h,e),n&&(t.docView.minWidth=0,o|=8)}c>0&&O>0?l=Math.max(c,O):c<0&&O<0&&(l=Math.min(c,O)),s.heightChanged=!1;for(let i of this.viewports){let r=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=this.heightMap.updateHeight(s,0,n,new tn(i.from,r))}s.heightChanged&&(o|=2)}let p=!this.viewportIsAppropriate(this.viewport,l)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return p&&(this.viewport=this.getViewport(l,this.scrollTarget)),this.updateForViewport(),(2&o||p)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(n?[]:this.lineGaps)),o|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),o}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,r=this.state.doc,{visibleTop:n,visibleBottom:h}=this,o=new wn(s.lineAt(n-1e3*i,sn.ByHeight,r,0,0).from,s.lineAt(h+1e3*(1-i),sn.ByHeight,r,0,0).to);if(e){let{head:t}=e.range;if(to.to){let i,n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),h=s.lineAt(t,sn.ByPos,r,0,0);i="center"==e.y?(h.top+h.bottom)/2-n/2:"start"==e.y||"nearest"==e.y&&t=h+Math.max(10,Math.min(i,250)))&&s>n-2e3&&ri.from&&h.push({from:i.from,to:s}),r=i.from&&o.from<=i.to&&yn(h,o.from-10,o.from+10),!o.empty&&o.to>=i.from&&o.to<=i.to&&yn(h,o.to-10,o.to+10);for(let{from:s,to:r}of h)r-s>1e3&&e.push(Qn(t,(t=>t.from>=i.from&&t.to<=i.to&&Math.abs(t.from-s)<1e3&&Math.abs(t.to-r)<1e3))||new $n(s,r,this.gapSize(i,s,r,n)))}return e}gapSize(t,e,i,s){let r=xn(s,i)-xn(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){$n.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=ds.set(t.map((t=>t.draw(this.heightOracle.lineWrapping)))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];Ae.spans(t,this.viewport.from,this.viewport.to,{span(t,i){e.push({from:t,to:i})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some(((t,i)=>t.from!=e[i].from||t.to!=e[i].to));return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find((e=>e.from<=t&&e.to>=t))||qn(this.heightMap.lineAt(t,sn.ByPos,this.state.doc,0,0),this.scaler)}lineBlockAtHeight(t){return qn(this.heightMap.lineAt(this.scaler.fromDOM(t),sn.ByHeight,this.state.doc,0,0),this.scaler)}elementAtHeight(t){return qn(this.heightMap.blockAt(this.scaler.fromDOM(t),this.state.doc,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class wn{constructor(t,e){this.from=t,this.to=e}}function gn(t,e,i){let s=[],r=t,n=0;return Ae.spans(i,t,e,{span(){},point(t,e){t>r&&(s.push({from:r,to:t}),n+=t-r),r=e}},20),r=1)return e[e.length-1].to;let s=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:r}=e[t],n=r-i;if(s<=n)return i+s;s-=n}}function xn(t,e){let i=0;for(let{from:s,to:r}of t.ranges){if(e<=r){i+=e-s;break}i+=r-s}return i/t.total}function yn(t,e,i){for(let s=0;se){let n=[];r.fromi&&n.push({from:i,to:r.to}),t.splice(s,1,...n),s+=n.length-1}}}function Qn(t,e){for(let i of t)if(e(i))return i}const Pn={toDOM:t=>t,fromDOM:t=>t,scale:1};class vn{constructor(t,e,i){let s=0,r=0,n=0;this.viewports=i.map((({from:i,to:r})=>{let n=e.lineAt(i,sn.ByPos,t,0,0).top,h=e.lineAt(r,sn.ByPos,t,0,0).bottom;return s+=h-n,{from:i,to:r,top:n,bottom:h,domTop:0,domBottom:0}})),this.scale=(7e6-s)/(e.height-s);for(let t of this.viewports)t.domTop=n+(t.top-r)*this.scale,n=t.domBottom=t.domTop+(t.bottom-t.top),r=t.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let r=eqn(t,e))):t.type)}const Sn=Dt.define({combine:t=>t.join(" ")}),kn=Dt.define({combine:t=>t.indexOf(!0)>-1}),In=ii.newName(),Rn=ii.newName(),Wn=ii.newName(),Yn={"&light":"."+Rn,"&dark":"."+Wn};function Xn(t,e,i){return new ii(e,{finish:e=>/&/.test(e)?e.replace(/&\w*/,(e=>{if("&"==e)return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]})):t+" "+e})}const Mn=Xn("."+In,{"&.cm-editor":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,minHeight:"100%",display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 4px"},".cm-selectionLayer":{zIndex:-1,contain:"size style"},".cm-selectionBackground":{position:"absolute"},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{zIndex:100,contain:"size style",pointerEvents:"none"},"&.cm-focused .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{visibility:"hidden"},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{visibility:"hidden"},"100%":{}},".cm-cursor, .cm-dropCursor":{position:"absolute",borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},"&.cm-focused .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#f3f9ff"},"&dark .cm-activeLine":{backgroundColor:"#223039"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{display:"flex",height:"100%",boxSizing:"border-box",left:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".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"}},Yn),Zn={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Tn=Li.ie&&Li.ie_version<=11;class _n{constructor(t,e,i){this.view=t,this.onChange=e,this.onScrollChanged=i,this.active=!1,this.selectionRange=new qi,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.scrollTargets=[],this.intersection=null,this.resize=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver((e=>{for(let t of e)this.queue.push(t);(Li.ie&&Li.ie_version<=11||Li.ios&&t.composing)&&e.some((t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():this.flush()})),Tn&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),window.addEventListener("resize",this.onResize=this.onResize.bind(this)),"function"==typeof ResizeObserver&&(this.resize=new ResizeObserver((()=>{this.view.docView.lastUpdate{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))}),{}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver((t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))}),{})),this.listenForScroll(),this.readSelectionRange(),this.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}onScroll(t){this.intersecting&&this.flush(!1),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout((()=>{this.resizeTimeout=-1,this.view.requestMeasure()}),50))}onPrint(){this.view.viewState.printing=!0,this.view.measure(),setTimeout((()=>{this.view.viewState.printing=!1,this.view.requestMeasure()}),500)}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some(((e,i)=>e!=t[i])))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:e}=this,i=this.selectionRange;if(e.state.facet(Zs)?e.root.activeElement!=this.dom:!mi(e.dom,i))return;let s=i.anchorNode&&e.docView.nearest(i.anchorNode);s&&s.ignoreEvent(t)||((Li.ie&&Li.ie_version<=11||Li.android&&Li.chrome)&&!e.state.selection.main.empty&&i.focusNode&&gi(i.focusNode,i.focusOffset,i.anchorNode,i.anchorOffset)?this.flushSoon():this.flush(!1))}readSelectionRange(){let{root:t}=this.view,e=Li.safari&&11==t.nodeType&&function(){let t=document.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}()==this.view.contentDOM&&function(t){let e=null;function i(t){t.preventDefault(),t.stopImmediatePropagation(),e=t.getTargetRanges()[0]}if(t.contentDOM.addEventListener("beforeinput",i,!0),document.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",i,!0),!e)return null;let s=e.startContainer,r=e.startOffset,n=e.endContainer,h=e.endOffset,o=t.docView.domAtPos(t.state.selection.main.anchor);return gi(o.node,o.offset,n,h)&&([s,r,n,h]=[n,h,s,r]),{anchorNode:s,anchorOffset:r,focusNode:n,focusOffset:h}}(this.view)||$i(t);return!(!e||this.selectionRange.eq(e))&&(this.selectionRange.setRange(e),this.selectionChanged=!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(1==i.nodeType)!e&&t{let t=this.delayedAndroidKey;this.delayedAndroidKey=null,this.delayedFlush=-1,this.flush()||Wi(this.view.contentDOM,t.key,t.keyCode)})),this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e})}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=window.setTimeout((()=>{this.delayedFlush=-1,this.flush()}),20))}forceFlush(){this.delayedFlush>=0&&(window.clearTimeout(this.delayedFlush),this.delayedFlush=-1,this.flush())}processRecords(){let t=this.queue;for(let e of this.observer.takeRecords())t.push(e);t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let r of t){let t=this.readMutation(r);t&&(t.typeOver&&(s=!0),-1==e?({from:e,to:i}=t):(e=Math.min(t.from,e),i=Math.max(t.to,i)))}return{from:e,to:i,typeOver:s}}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return;t&&this.readSelectionRange();let{from:e,to:i,typeOver:s}=this.processRecords(),r=this.selectionChanged&&mi(this.dom,this.selectionRange);if(e<0&&!r)return;this.selectionChanged=!1;let n=this.view.state,h=this.onChange(e,i,s);return this.view.state==n&&this.view.update([]),h}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty("attributes"==t.type),"attributes"==t.type&&(e.dirty|=4),"childList"==t.type){let i=En(e,t.previousSibling||t.target.previousSibling,-1),s=En(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resize)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);window.removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onResize),window.removeEventListener("beforeprint",this.onPrint),this.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout)}}function En(t,e,i){for(;e;){let s=Zi.get(e);if(s&&s.parent==t)return s;let r=e.parentNode;e=r!=t.dom?r:i>0?e.nextSibling:e.previousSibling}return null}function An(t,e,i,s){let r,n,h=t.state.selection.main;if(e>-1){let s=t.docView.domBoundsAround(e,i,0);if(!s||t.state.readOnly)return!1;let{from:o,to:l}=s,u=t.docView.impreciseHead||t.docView.impreciseAnchor?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}=t.observer.selectionRange;return i&&(e.push(new fr(i,s)),r==i&&n==s||e.push(new fr(r,n))),e}(t),a=new ur(u,t.state);a.readRange(s.startDOM,s.endDOM);let f=h.from,c=null;(8===t.inputState.lastKeyCode&&t.inputState.lastKeyTime>Date.now()-100||Li.android&&a.text.length0&&o>0&&t.charCodeAt(h-1)==e.charCodeAt(o-1);)h--,o--;return"end"==s&&(i-=h+Math.max(0,n-Math.min(h,o))-n),h=h?n-i:0,o=n+(o-h),h=n):o=o?n-i:0,h=n+(h-o),o=n),{from:n,toA:h,toB:o}}(t.state.doc.sliceString(o,l,lr),a.text,f-o,c);O&&(Li.chrome&&13==t.inputState.lastKeyCode&&O.toB==O.from+2&&a.text.slice(O.from,O.toB)==lr+lr&&O.toB--,r={from:o+O.from,to:o+O.toA,insert:ft.of(a.text.slice(O.from,O.toB).split(lr))}),n=function(t,e){if(0==t.length)return null;let i=t[0].pos,s=2==t.length?t[1].pos:i;return i>-1&&s>-1?Vt.single(i+e,s+e):null}(u,o)}else if(t.hasFocus||!t.state.facet(Zs)){let e=t.observer.selectionRange,{impreciseHead:i,impreciseAnchor:s}=t.docView,r=i&&i.node==e.focusNode&&i.offset==e.focusOffset||!pi(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),o=s&&s.node==e.anchorNode&&s.offset==e.anchorOffset||!pi(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset);r==h.head&&o==h.anchor||(n=Vt.single(o,r))}if(!r&&!n)return!1;if(!r&&s&&!h.empty&&n&&n.main.empty?r={from:h.from,to:h.to,insert:t.state.doc.slice(h.from,h.to)}:r&&r.from>=h.from&&r.to<=h.to&&(r.from!=h.from||r.to!=h.to)&&h.to-h.from-(r.to-r.from)<=4?r={from:h.from,to:h.to,insert:t.state.doc.slice(h.from,r.from).append(r.insert).append(t.state.doc.slice(r.to,h.to))}:(Li.mac||Li.android)&&r&&r.from==r.to&&r.from==h.head-1&&"."==r.insert.toString()&&(r={from:h.from,to:h.to,insert:ft.of([" "])}),r){let e=t.state;if(Li.ios&&t.inputState.flushIOSKey(t))return!0;if(Li.android&&(r.from==h.from&&r.to==h.to&&1==r.insert.length&&2==r.insert.lines&&Wi(t.contentDOM,"Enter",13)||r.from==h.from-1&&r.to==h.to&&0==r.insert.length&&Wi(t.contentDOM,"Backspace",8)||r.from==h.from&&r.to==h.to+1&&0==r.insert.length&&Wi(t.contentDOM,"Delete",46)))return!0;let i,s=r.insert.toString();if(t.state.facet(Rs).some((e=>e(t,r.from,r.to,s))))return!0;if(t.inputState.composing>=0&&t.inputState.composing++,r.from>=h.from&&r.to<=h.to&&r.to-r.from>=(h.to-h.from)/3&&(!n||n.main.empty&&n.main.from==r.from+r.insert.length)&&t.inputState.composing<0){let s=h.fromr.to?e.sliceDoc(r.to,h.to):"";i=e.replaceSelection(t.state.toText(s+r.insert.sliceString(0,void 0,t.state.lineBreak)+n))}else{let s=e.changes(r),o=n&&!e.selection.main.eq(n.main)&&n.main.to<=s.newLength?n.main:void 0;if(e.selection.ranges.length>1&&t.inputState.composing>=0&&r.to<=h.to&&r.to>=h.to-10){let n=t.state.sliceDoc(r.from,r.to),l=dr(t)||t.state.doc.lineAt(h.head),u=h.to-r.to,a=h.to-h.from;i=e.changeByRange((i=>{if(i.from==h.from&&i.to==h.to)return{changes:s,range:o||i.map(s)};let f=i.to-u,c=f-n.length;if(i.to-i.from!=a||t.state.sliceDoc(c,f)!=n||l&&i.to>=l.from&&i.from<=l.to)return{range:i};let O=e.changes({from:c,to:f,insert:r.insert}),d=i.to-h.to;return{changes:O,range:o?Vt.range(Math.max(0,o.anchor+d),Math.max(0,o.head+d)):i.map(O)}}))}else i={changes:s,selection:o&&e.selection.replaceRange(o)}}let o="input.type";return t.composing&&(o+=".compose",t.inputState.compositionFirstChange&&(o+=".start",t.inputState.compositionFirstChange=!1)),t.dispatch(i,{scrollIntoView:!0,userEvent:o}),!0}if(n&&!n.main.eq(h)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin),t.dispatch({selection:n,scrollIntoView:e,userEvent:i}),!0}return!1}class jn{constructor(t={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.style.cssText="position: absolute; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),this._dispatch=t.dispatch||(t=>this.update([t])),this.dispatch=this.dispatch.bind(this),this.root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new mn(t.state||Xe.create(t)),this.plugins=this.state.facet(_s).map((t=>new As(t)));for(let t of this.plugins)t.update(this);this.observer=new _n(this,((t,e,i)=>An(this,t,e,i)),(t=>{this.inputState.runScrollHandlers(this,t),this.observer.intersecting&&this.measure()})),this.inputState=new Ir(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new cr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),t.parent&&t.parent.appendChild(this.dom)}get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}dispatch(...t){this._dispatch(1==t.length&&t[0]instanceof ye?t[0]:this.state.update(...t))}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,s=!1,r=this.state;for(let e of t){if(e.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=e.state}if(this.destroyed)return void(this.viewState.state=r);if(this.observer.clear(),r.facet(Xe.phrases)!=this.state.facet(Xe.phrases))return this.setState(r);e=Hs.create(this,r,t);let n=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(n&&(n=n.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection;n=new Ys(t.empty?t:Vt.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(Xs)&&(n=t.value)}this.viewState.update(e,n),this.bidiCache=Cn.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(Ds)!=this.styleModules&&this.mountStyles(),s=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some((t=>t.isUserEvent("select.pointer"))))}finally{this.updateState=0}if(e.startState.facet(Sn)!=e.state.facet(Sn)&&(this.viewState.mustMeasureContent=!0),(i||s||n||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!e.empty)for(let t of this.state.facet(Is))t(e)}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new mn(t),this.plugins=t.facet(_s).map((t=>new As(t))),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView=new cr(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(_s),i=t.state.facet(_s);if(e!=i){let s=[];for(let r of i){let i=e.indexOf(r);if(i<0)s.push(new As(r));else{let e=this.plugins[i];e.mustUpdate=t,s.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=s,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t-1&&cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,t&&this.observer.flush();let e=null;try{for(let t=0;;t++){this.updateState=1;let i=this.viewport,s=this.viewState.measure(this);if(!s&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let r=[];4&s||([this.measureRequests,r]=[r,this.measureRequests]);let n=r.map((t=>{try{return t.read(this)}catch(t){return Ms(this.state,t),Vn}})),h=Hs.create(this,this.state,[]),o=!1,l=!1;h.flags|=s,e?e.flags|=s:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),o=this.docView.update(h));for(let t=0;t{let i=fs(this.contentDOM,this.contentAttrs,e),s=fs(this.dom,this.editorAttrs,t);return i||s}));return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)t.is(jn.announce)&&(e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value)}mountStyles(){this.styleModules=this.state.facet(Ds),ii.mount(this.root,this.styleModules.concat(Mn).reverse())}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=requestAnimationFrame((()=>this.measure()))),t){if(null!=t.key)for(let e=0;ee.spec==t))||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return kr(this,t,Sr(this,t,e,i))}moveByGroup(t,e){return kr(this,t,Sr(this,t,e,(e=>function(t,e,i){let s=t.state.charCategorizer(e),r=s(i);return t=>{let e=s(t);return r==Ie.Space&&(r=e),r==e}}(this,t.head,e))))}moveToLineBoundary(t,e,i=!0){return function(t,e,i,s){let r=t.state.doc.lineAt(e.head),n=s&&t.lineWrapping?t.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head):null;if(n){let e=t.dom.getBoundingClientRect(),s=t.textDirectionAt(r.from),h=t.posAtCoords({x:i==(s==Ns.LTR)?e.right-1:e.left+1,y:(n.top+n.bottom)/2});if(null!=h)return Vt.cursor(h,i?-1:1)}let h=bs.find(t.docView,e.head),o=h?i?h.posAtEnd:h.posAtStart:i?r.to:r.from;return Vt.cursor(o,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return kr(this,t,function(t,e,i,s){let r=e.head,n=i?1:-1;if(r==(i?t.state.doc.length:0))return Vt.cursor(r,e.assoc);let h,o=e.goalColumn,l=t.contentDOM.getBoundingClientRect(),u=t.coordsAtPos(r),a=t.documentTop;if(u)null==o&&(o=u.left-l.left),h=n<0?u.top:u.bottom;else{let e=t.viewState.lineBlockAt(r);null==o&&(o=Math.min(l.right-l.left,t.defaultCharacterWidth*(r-e.from))),h=(n<0?e.top:e.bottom)+a}let f=l.left+o,c=null!=s?s:t.defaultLineHeight>>1;for(let i=0;;i+=10){let s=h+(c+i)*n,u=vr(t,{x:f,y:s},!1,n);if(sl.bottom||(n<0?ur))return Vt.cursor(u,e.assoc,void 0,o)}}(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),vr(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),r=this.bidiSpans(s);return Pi(i,r[sr.find(r,t-s.from,-1,e)].dir==Ns.LTR==e>0)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Ws)||tthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>Un)return nr(t.length);let e=this.textDirectionAt(t.from);for(let i of this.bidiCache)if(i.from==t.from&&i.dir==e)return i.order;let i=function(t,e){let i=t.length,s=e==Fs?1:2,r=e==Fs?2:1;if(!t||1==s&&!ir.test(t))return nr(i);for(let e=0,r=s,h=s;e=0;t-=3)if(er[t+1]==-n){let e=er[t+2],i=2&e?s:4&e?1&e?r:s:0;i&&(rr[o]=rr[er[t]]=i),l=t;break}}else{if(189==er.length)break;er[l++]=o,er[l++]=e,er[l++]=u}else if(2==(h=rr[o])||1==h){let t=h==s;u=t?0:1;for(let e=l-3;e>=0;e-=3){let i=er[e+2];if(2&i)break;if(t)er[e+2]|=2;else{if(4&i)break;er[e+2]|=4}}}for(let t=0;te;){let t=i,s=2!=rr[--i];for(;i>e&&s==(2!=rr[i-1]);)i--;h.push(new sr(i,t,s?2:1))}else h.push(new sr(e,t,0))}else for(let t=0;tDate.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore((()=>{Ii(this.contentDOM),this.docView.updateSelection()}))}destroy(){for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return Xs.of(new Ys("number"==typeof t?Vt.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}static domEventHandlers(t){return Es.define((()=>({})),{eventHandlers:t})}static theme(t,e){let i=ii.newName(),s=[Sn.of(i),Ds.of(Xn(`.${i}`,t))];return e&&e.dark&&s.push(kn.of(!0)),s}static baseTheme(t){return re.lowest(Ds.of(Xn("."+In,t,Yn)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&Zi.get(i)||Zi.get(t);return(null===(e=null==s?void 0:s.rootView)||void 0===e?void 0:e.view)||null}}jn.styleModule=Ds,jn.inputHandler=Rs,jn.perLineTextDirection=Ws,jn.exceptionSink=ks,jn.updateListener=Is,jn.editable=Zs,jn.mouseSelectionStyle=Ss,jn.dragMovesSelection=qs,jn.clickAddsSelectionRange=vs,jn.decorations=Vs,jn.atomicRanges=Cs,jn.scrollMargins=Gs,jn.darkTheme=kn,jn.contentAttributes=Us,jn.editorAttributes=js,jn.lineWrapping=jn.contentAttributes.of({class:"cm-lineWrapping"}),jn.announce=xe.define();const Un=4096,Vn={};class Cn{constructor(t,e,i,s){this.from=t,this.to=e,this.dir=i,this.order=s}static update(t,e){if(e.empty)return t;let i=[],s=t.length?t[t.length-1].dir:Ns.LTR;for(let r=Math.max(0,t.length-10);r=0;r--){let e=s[r],n="function"==typeof e?e(t):e;n&&us(n,i)}return i}const Dn=Li.mac?"mac":Li.windows?"win":Li.linux?"linux":"key";function zn(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),!1!==i&&e.shiftKey&&(t="Shift-"+t),t}const Hn=jn.domEventHandlers({keydown:(t,e)=>Jn(Bn(e.state),t,e,"editor")}),Nn=Dt.define({enables:Hn}),Fn=new WeakMap;function Bn(t){let e=t.facet(Nn),i=Fn.get(e);return i||Fn.set(e,i=function(t,e=Dn){let i=Object.create(null),s=Object.create(null),r=(t,e)=>{let i=s[t];if(null==i)s[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")},n=(t,s,n,h)=>{let o=i[t]||(i[t]=Object.create(null)),l=s.split(/ (?!$)/).map((t=>function(t,e){const i=t.split(/-(?!$)/);let s,r,n,h,o=i[i.length-1];"Space"==o&&(o=" ");for(let t=0;t{let s=Ln={view:e,prefix:i,scope:t};return setTimeout((()=>{Ln==s&&(Ln=null)}),Kn),!0}]})}let u=l.join(" ");r(u,!1);let a=o[u]||(o[u]={preventDefault:!1,commands:[]});a.commands.push(n),h&&(a.preventDefault=!0)};for(let i of t){let t=i[e]||i.key;if(t)for(let e of i.scope?i.scope.split(" "):["editor"])n(e,t,i.run,i.preventDefault),i.shift&&n(e,"Shift-"+t,i.shift,i.preventDefault)}return i}(e.reduce(((t,e)=>t.concat(e)),[]))),i}let Ln=null;const Kn=4e3;function Jn(t,e,i,s){let r=function(t){var e=!(ci&&(t.ctrlKey||t.altKey||t.metaKey)||(li||fi)&&t.shiftKey&&t.key&&1==t.key.length)&&t.key||(t.shiftKey?hi:ni)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(e),n=kt(r,0),h=Rt(n)==r.length&&" "!=r,o="",l=!1;Ln&&Ln.view==i&&Ln.scope==s&&(o=Ln.prefix+" ",(l=Wr.indexOf(e.keyCode)<0)&&(Ln=null));let u,a=t=>{if(t){for(let e of t.commands)if(e(i))return!0;t.preventDefault&&(l=!0)}return!1},f=t[s];if(f){if(a(f[o+zn(r,e,!h)]))return!0;if(h&&(e.shiftKey||e.altKey||e.metaKey||n>127)&&(u=ni[e.keyCode])&&u!=r){if(a(f[o+zn(u,e,!0)]))return!0;if(e.shiftKey&&hi[e.keyCode]!=u&&a(f[o+zn(hi[e.keyCode],e,!1)]))return!0}else if(h&&e.shiftKey&&a(f[o+zn(r,e,!0)]))return!0}return l}const th=!Li.ios,eh=Dt.define({combine:t=>Me(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function ih(t={}){return[eh.of(t),rh,hh]}class sh{constructor(t,e,i,s,r){this.left=t,this.top=e,this.width=i,this.height=s,this.className=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width>=0&&(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}}const rh=Es.fromClass(class{constructor(t){this.view=t,this.rangePieces=[],this.cursors=[],this.measureReq={read:this.readPos.bind(this),write:this.drawSel.bind(this)},this.selectionLayer=t.scrollDOM.appendChild(document.createElement("div")),this.selectionLayer.className="cm-selectionLayer",this.selectionLayer.setAttribute("aria-hidden","true"),this.cursorLayer=t.scrollDOM.appendChild(document.createElement("div")),this.cursorLayer.className="cm-cursorLayer",this.cursorLayer.setAttribute("aria-hidden","true"),t.requestMeasure(this.measureReq),this.setBlinkRate()}setBlinkRate(){this.cursorLayer.style.animationDuration=this.view.state.facet(eh).cursorBlinkRate+"ms"}update(t){let e=t.startState.facet(eh)!=t.state.facet(eh);(e||t.selectionSet||t.geometryChanged||t.viewportChanged)&&this.view.requestMeasure(this.measureReq),t.transactions.some((t=>t.scrollIntoView))&&(this.cursorLayer.style.animationName="cm-blink"==this.cursorLayer.style.animationName?"cm-blink2":"cm-blink"),e&&this.setBlinkRate()}readPos(){let{state:t}=this.view,e=t.facet(eh),i=t.selection.ranges.map((t=>t.empty?[]:function(t,e){if(e.to<=t.viewport.from||e.from>=t.viewport.to)return[];let i=Math.max(e.from,t.viewport.from),s=Math.min(e.to,t.viewport.to),r=t.textDirection==Ns.LTR,n=t.contentDOM,h=n.getBoundingClientRect(),o=oh(t),l=window.getComputedStyle(n.firstChild),u=h.left+parseInt(l.paddingLeft)+Math.min(0,parseInt(l.textIndent)),a=h.right-parseInt(l.paddingRight),f=uh(t,i),c=uh(t,s),O=f.type==Os.Text?f:null,d=c.type==Os.Text?c:null;if(t.lineWrapping&&(O&&(O=lh(t,i,O)),d&&(d=lh(t,s,d))),O&&d&&O.from==d.from)return p(m(e.from,e.to,O));{let i=O?m(e.from,null,O):w(f,!1),s=d?m(null,e.to,d):w(c,!0),r=[];return(O||f).to<(d||c).from-1?r.push($(u,i.bottom,a,s.top)):i.bottomf&&s.from=n)break;o>r&&l(Math.max(t,r),null==e&&t<=f,Math.min(o,n),null==i&&o>=c,h.dir)}if(r=s.to+1,r>=n)break}return 0==o.length&&l(f,null==e,c,null==i,t.textDirection),{top:n,bottom:h,horizontal:o}}function w(t,e){let i=h.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(this.view,t))).reduce(((t,e)=>t.concat(e))),s=[];for(let i of t.selection.ranges){let r=i==t.selection.main;if(i.empty?!r||th:e.drawRangeCursor){let t=ah(this.view,i,r);t&&s.push(t)}}return{rangePieces:i,cursors:s}}drawSel({rangePieces:t,cursors:e}){if(t.length!=this.rangePieces.length||t.some(((t,e)=>!t.eq(this.rangePieces[e])))){this.selectionLayer.textContent="";for(let e of t)this.selectionLayer.appendChild(e.draw());this.rangePieces=t}if(e.length!=this.cursors.length||e.some(((t,e)=>!t.eq(this.cursors[e])))){let t=this.cursorLayer.children;if(t.length!==e.length){this.cursorLayer.textContent="";for(const t of e)this.cursorLayer.appendChild(t.draw())}else e.forEach(((e,i)=>e.adjust(t[i])));this.cursors=e}}destroy(){this.selectionLayer.remove(),this.cursorLayer.remove()}}),nh={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};th&&(nh[".cm-line"].caretColor="transparent !important");const hh=re.highest(jn.theme(nh));function oh(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==Ns.LTR?e.left:e.right-t.scrollDOM.clientWidth)-t.scrollDOM.scrollLeft,top:e.top-t.scrollDOM.scrollTop}}function lh(t,e,i){let s=Vt.cursor(e);return{from:Math.max(i.from,t.moveToLineBoundary(s,!1,!0).from),to:Math.min(i.to,t.moveToLineBoundary(s,!0,!0).from),type:Os.Text}}function uh(t,e){let i=t.lineBlockAt(e);if(Array.isArray(i.type))for(let t of i.type)if(t.to>e||t.to==e&&(t.to==i.to||t.type==Os.Text))return t;return i}function ah(t,e,i){let s=t.coordsAtPos(e.head,e.assoc||1);if(!s)return null;let r=oh(t);return new sh(s.left-r.left,s.top-r.top,-1,s.bottom-s.top,i?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary")}const fh=xe.define({map:(t,e)=>null==t?null:e.mapPos(t)}),ch=Kt.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce(((t,e)=>e.is(fh)?e.value:t),t))}),Oh=Es.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(ch);null==i?null!=this.cursor&&(null===(e=this.cursor)||void 0===e||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(ch)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let t=this.view.state.field(ch),e=null!=t&&this.view.coordsAtPos(t);if(!e)return null;let i=this.view.scrollDOM.getBoundingClientRect();return{left:e.left-i.left+this.view.scrollDOM.scrollLeft,top:e.top-i.top+this.view.scrollDOM.scrollTop,height:e.bottom-e.top}}drawCursor(t){this.cursor&&(t?(this.cursor.style.left=t.left+"px",this.cursor.style.top=t.top+"px",this.cursor.style.height=t.height+"px"):this.cursor.style.left="-100000px")}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(ch)!=t&&this.view.dispatch({effects:fh.of(t)})}},{eventHandlers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function dh(){return[ch,Oh]}function $h(t,e,i,s,r){e.lastIndex=0;for(let n,h=t.iterRange(i,s),o=i;!h.next().done;o+=h.value.length)if(!h.lineBreak)for(;n=e.exec(h.value);)r(o+n.index,o+n.index+n[0].length,n)}class ph{constructor(t){let{regexp:e,decoration:i,boundary:s,maxLength:r=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");this.regexp=e,this.getDeco="function"==typeof i?i:()=>i,this.boundary=s,this.maxLength=r}createDeco(t){let e=new je;for(let{from:i,to:s}of function(t,e){let i=t.visibleRanges;if(1==i.length&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let s=[];for(let{from:r,to:n}of i)r=Math.max(t.state.doc.lineAt(r).from,r-e),n=Math.min(t.state.doc.lineAt(n).to,n+e),s.length&&s[s.length-1].to>=r?s[s.length-1].to=n:s.push({from:r,to:n});return s}(t,this.maxLength))$h(t.state.doc,this.regexp,i,s,((i,s,r)=>e.add(i,s,this.getDeco(r,t,i))));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges(((e,r,n,h)=>{h>t.view.viewport.from&&n1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let r of t.visibleRanges){let n=Math.max(r.from,i),h=Math.min(r.to,s);if(h>n){let i=t.state.doc.lineAt(n),s=i.toi.from;n--)if(this.boundary.test(i.text[n-1-i.from])){o=n;break}for(;ha.push(this.getDeco(s,t,e).range(e,i))));e=e.update({filterFrom:o,filterTo:l,filter:(t,e)=>tl,add:a})}}return e}}const mh=null!=/x/.unicode?"gu":"g",wh=new RegExp("[\0-\b\n--Ÿ­؜​‎‏\u2028\u2029‭‮\ufeff-]",mh),gh={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",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let bh=null;const xh=Dt.define({combine(t){let e=Me(t,{render:null,specialChars:wh,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==bh&&"undefined"!=typeof document&&document.body){let e=document.body.style;bh=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return bh||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,mh)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,mh)),e}});function yh(t={}){return[xh.of(t),Qh||(Qh=Es.fromClass(class{constructor(t){this.view=t,this.decorations=ds.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(xh)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new ph({regexp:t.specialChars,decoration:(e,i,s)=>{let{doc:r}=i.state,n=kt(e[0],0);if(9==n){let t=r.lineAt(s),e=i.state.tabSize,n=Le(t.text,e,s-t.from);return ds.replace({widget:new vh((e-n%e)*this.view.defaultCharacterWidth)})}return this.decorationCache[n]||(this.decorationCache[n]=ds.replace({widget:new Ph(t,n)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(xh);t.startState.facet(xh)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))]}let Qh=null;class Ph extends cs{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=function(t){return t>=32?"•":10==t?"␤":String.fromCharCode(9216+t)}(this.code),i=t.state.phrase("Control character")+" "+(gh[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let r=document.createElement("span");return r.textContent=e,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class vh extends cs{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}function qh(){return kh}const Sh=ds.line({class:"cm-activeLine"}),kh=Es.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let s of t.state.selection.ranges){if(!s.empty)return ds.none;let r=t.lineBlockAt(s.head);r.from>e&&(i.push(Sh.range(r.from)),e=r.from)}return ds.set(i)}},{decorations:t=>t.decorations}),Ih=2e3;function Rh(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),s=t.state.doc.lineAt(i),r=i-s.from,n=r>Ih?-1:r==s.length?function(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}(t,e.clientX):Le(s.text,t.state.tabSize,i-s.from);return{line:s.number,col:n,off:r}}function Wh(t,e){let i=Rh(t,e),s=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),r=t.state.doc.lineAt(e);i={line:r.number,col:i.col,off:Math.min(i.off,r.length)},s=s.map(t.changes)}},get(e,r,n){let h=Rh(t,e);if(!h)return s;let o=function(t,e,i){let s=Math.min(e.line,i.line),r=Math.max(e.line,i.line),n=[];if(e.off>Ih||i.off>Ih||e.col<0||i.col<0){let h=Math.min(e.off,i.off),o=Math.max(e.off,i.off);for(let e=s;e<=r;e++){let i=t.doc.line(e);i.length<=o&&n.push(Vt.range(i.from+h,i.to+o))}}else{let h=Math.min(e.col,i.col),o=Math.max(e.col,i.col);for(let e=s;e<=r;e++){let i=t.doc.line(e),s=Ke(i.text,h,t.tabSize,!0);if(s>-1){let e=Ke(i.text,o,t.tabSize);n.push(Vt.range(i.from+s,i.from+e))}}}return n}(t.state,i,h);return o.length?n?Vt.create(o.concat(s.ranges)):Vt.create(o):s}}:null}function Yh(t){let e=(null==t?void 0:t.eventFilter)||(t=>t.altKey&&0==t.button);return jn.mouseSelectionStyle.of(((t,i)=>e(i)?Wh(t,i):null))}const Xh={Alt:[18,t=>t.altKey],Control:[17,t=>t.ctrlKey],Shift:[16,t=>t.shiftKey],Meta:[91,t=>t.metaKey]},Mh={style:"cursor: crosshair"};function Zh(t={}){let[e,i]=Xh[t.key||"Alt"],s=Es.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventHandlers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)}}});return[s,jn.contentAttributes.of((t=>{var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.isDown)?Mh:null}))]}const Th="-10000px";class _h{constructor(t,e,i){this.facet=e,this.createTooltipView=i,this.input=t.state.facet(e),this.tooltips=this.input.filter((t=>t)),this.tooltipViews=this.tooltips.map(i)}update(t){let e=t.state.facet(this.facet),i=e.filter((t=>t));if(e===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let s=[];for(let e=0;e{var e,i,s;return{position:Li.ios?"absolute":(null===(e=t.find((t=>t.position)))||void 0===e?void 0:e.position)||"fixed",parent:(null===(i=t.find((t=>t.parent)))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(s=t.find((t=>t.tooltipSpace)))||void 0===s?void 0:s.tooltipSpace)||Eh}}}),jh=Es.fromClass(class{constructor(t){var e;this.view=t,this.inView=!0,this.lastTransaction=0,this.measureTimeout=-1;let i=t.state.facet(Ah);this.position=i.position,this.parent=i.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.manager=new _h(t,Ch,(t=>this.createTooltip(t))),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver((t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()}),{threshold:[1]}):null,this.observeIntersection(),null===(e=t.dom.ownerDocument.defaultView)||void 0===e||e.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout((()=>{this.measureTimeout=-1,this.maybeMeasure()}),50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t);e&&this.observeIntersection();let i=e||t.geometryChanged,s=t.state.facet(Ah);if(s.position!=this.position){this.position=s.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(s.parent!=this.parent){this.parent&&this.container.remove(),this.parent=s.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t){let e=t.create(this.view);if(e.dom.classList.add("cm-tooltip"),t.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",e.dom.appendChild(t)}return e.dom.style.position=this.position,e.dom.style.top=Th,this.container.appendChild(e.dom),e.mount&&e.mount(this.view),e}destroy(){var t,e;null===(t=this.view.dom.ownerDocument.defaultView)||void 0===t||t.removeEventListener("resize",this.measureSoon);for(let{dom:t}of this.manager.tooltipViews)t.remove();null===(e=this.intersectionObserver)||void 0===e||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=this.view.dom.getBoundingClientRect();return{editor:t,parent:this.parent?this.container.getBoundingClientRect():t,pos:this.manager.tooltips.map(((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)})),size:this.manager.tooltipViews.map((({dom:t})=>t.getBoundingClientRect())),space:this.view.state.facet(Ah).tooltipSpace(this.view)}}writeMeasure(t){let{editor:e,space:i}=t,s=[];for(let r=0;r=Math.min(e.bottom,i.bottom)||l.rightMath.min(e.right,i.right)+.1){o.style.top=Th;continue}let a=n.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,f=a?7:0,c=u.right-u.left,O=u.bottom-u.top,d=h.offset||Vh,$=this.view.textDirection==Ns.LTR,p=u.width>i.right-i.left?$?i.left:i.right-u.width:$?Math.min(l.left-(a?14:0)+d.x,i.right-c):Math.max(i.left,l.left-c+(a?14:0)-d.x),m=!!n.above;!n.strictSide&&(m?l.top-(u.bottom-u.top)-d.yi.bottom)&&m==i.bottom-l.bottom>l.top-i.top&&(m=!m);let w=m?l.top-O-f-d.y:l.bottom+f+d.y,g=p+c;if(!0!==h.overlap)for(let t of s)t.leftp&&t.topw&&(w=m?t.top-O-2-f:t.bottom+f+2);"absolute"==this.position?(o.style.top=w-t.parent.top+"px",o.style.left=p-t.parent.left+"px"):(o.style.top=w+"px",o.style.left=p+"px"),a&&(a.style.left=l.left+($?d.x:-d.x)-(p+14-7)+"px"),!0!==h.overlap&&s.push({left:p,top:w,right:g,bottom:w+O}),o.classList.toggle("cm-tooltip-above",m),o.classList.toggle("cm-tooltip-below",!m),h.positioned&&h.positioned()}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let t of this.manager.tooltipViews)t.dom.style.top=Th}},{eventHandlers:{scroll(){this.maybeMeasure()}}}),Uh=jn.baseTheme({".cm-tooltip":{zIndex:100},"&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"}}}),Vh={x:0,y:0},Ch=Dt.define({enables:[jh,Uh]}),Gh=Dt.define();class Dh{constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new _h(t,Gh,(t=>this.createHostedView(t)))}static create(t){return new Dh(t)}createHostedView(t){let e=t.create(this.view);return e.dom.classList.add("cm-tooltip-section"),this.dom.appendChild(e.dom),this.mounted&&e.mount&&e.mount(this.view),e}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned()}update(t){this.manager.update(t)}}const zh=Ch.compute([Gh],(t=>{let e=t.facet(Gh).filter((t=>t));return 0===e.length?null:{pos:Math.min(...e.map((t=>t.pos))),end:Math.max(...e.filter((t=>null!=t.end)).map((t=>t.end))),create:Dh.create,above:e[0].above,arrow:e.some((t=>t.arrow))}}));class Hh{constructor(t,e,i,s,r){this.view=t,this.source=e,this.field=i,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout((()=>this.startHover()),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active)return;let t=Date.now()-this.lastMove.time;ti.bottom||t.xi.right+this.view.defaultCharacterWidth)return;let s=this.view.bidiSpans(this.view.state.doc.lineAt(e)).find((t=>t.from<=e&&t.to>=e)),r=s&&s.dir==Ns.RTL?-1:1,n=this.source(this.view,e,t.x{this.pending==t&&(this.pending=null,e&&this.view.dispatch({effects:this.setHover.of(e)}))}),(t=>Ms(this.view.state,t,"hover tooltip")))}else n&&this.view.dispatch({effects:this.setHover.of(n)})}mousemove(t){var e;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let i=this.active;if(i&&!function(t){for(let e=t;e;e=e.parentNode)if(1==e.nodeType&&e.classList.contains("cm-tooltip"))return!0;return!1}(this.lastMove.target)||this.pending){let{pos:s}=i||this.pending,r=null!==(e=null==i?void 0:i.end)&&void 0!==e?e:s;(s==r?this.view.posAtCoords(this.lastMove)==s:function(t,e,i,s,r,n){let h=document.createRange(),o=t.domAtPos(e),l=t.domAtPos(i);h.setEnd(l.node,l.offset),h.setStart(o.node,o.offset);let u=h.getClientRects();h.detach();for(let t=0;tnull,update(t,s){if(t&&(e.hideOnChange&&(s.docChanged||s.selection)||e.hideOn&&e.hideOn(s,t)))return null;if(t&&s.docChanged){let e=s.changes.mapPos(t.pos,-1,Yt.TrackDel);if(null==e)return null;let i=Object.assign(Object.create(null),t);i.pos=e,null!=t.end&&(i.end=s.changes.mapPos(t.end)),t=i}for(let e of s.effects)e.is(i)&&(t=e.value),e.is(Fh)&&(t=null);return t},provide:t=>Gh.from(t)});return[s,Es.define((r=>new Hh(r,t,s,i,e.hoverTime||300))),zh]}const Fh=xe.define(),Bh=Dt.define({combine(t){let e,i;for(let s of t)e=e||s.topContainer,i=i||s.bottomContainer;return{topContainer:e,bottomContainer:i}}});function Lh(t,e){let i=t.plugin(Kh),s=i?i.specs.indexOf(e):-1;return s>-1?i.panels[s]:null}const Kh=Es.fromClass(class{constructor(t){this.input=t.state.facet(eo),this.specs=this.input.filter((t=>t)),this.panels=this.specs.map((e=>e(t)));let e=t.state.facet(Bh);this.top=new Jh(t,!0,e.topContainer),this.bottom=new Jh(t,!1,e.bottomContainer),this.top.sync(this.panels.filter((t=>t.top))),this.bottom.sync(this.panels.filter((t=>!t.top)));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(t){let e=t.state.facet(Bh);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Jh(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Jh(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(eo);if(i!=this.input){let e=i.filter((t=>t)),s=[],r=[],n=[],h=[];for(let i of e){let e,o=this.specs.indexOf(i);o<0?(e=i(t.view),h.push(e)):(e=this.panels[o],e.update&&e.update(t)),s.push(e),(e.top?r:n).push(e)}this.specs=e,this.panels=s,this.top.sync(r),this.bottom.sync(n);for(let t of h)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>jn.scrollMargins.of((e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}}))});class Jh{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=to(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=to(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 to(t){let e=t.nextSibling;return t.remove(),e}const eo=Dt.define({enables:Kh});class io extends Ze{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}io.prototype.elementClass="",io.prototype.toDOM=void 0,io.prototype.mapMode=Yt.TrackBefore,io.prototype.startSide=io.prototype.endSide=-1,io.prototype.point=!0;const so=Dt.define(),ro={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>Ae.empty,lineMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},no=Dt.define();function ho(t){return[lo(),no.of(Object.assign(Object.assign({},ro),t))]}const oo=Dt.define({combine:t=>t.some((t=>t))});function lo(t){let e=[uo];return t&&!1===t.fixed&&e.push(oo.of(!0)),e}const uo=Es.fromClass(class{constructor(t){this.view=t,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight+"px",this.gutters=t.state.facet(no).map((e=>new Oo(t,e)));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!t.state.facet(oo),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,s=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(s<.8*(i.to-i.from))}t.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+"px"),this.view.state.facet(oo)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&this.dom.remove();let i=Ae.iter(this.view.state.facet(so),this.view.viewport.from),s=[],r=this.gutters.map((t=>new co(t,this.view.viewport,-this.view.documentPadding.top)));for(let t of this.view.viewportLineBlocks){let e;if(Array.isArray(t.type)){for(let i of t.type)if(i.type==Os.Text){e=i;break}}else e=t.type==Os.Text?t:void 0;if(e){s.length&&(s=[]),fo(i,s,t.from);for(let t of r)t.line(this.view,e,s)}}for(let t of r)t.finish();t&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(t){let e=t.startState.facet(no),i=t.state.facet(no),s=t.docChanged||t.heightChanged||t.viewportChanged||!Ae.eq(t.startState.facet(so),t.state.facet(so),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(s=!0);else{s=!0;let r=[];for(let s of i){let i=e.indexOf(s);i<0?r.push(new Oo(this.view,s)):(this.gutters[i].update(t),r.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),r.indexOf(t)<0&&t.destroy();for(let t of r)this.dom.appendChild(t.dom);this.gutters=r}return s}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove()}},{provide:t=>jn.scrollMargins.of((e=>{let i=e.plugin(t);return i&&0!=i.gutters.length&&i.fixed?e.textDirection==Ns.LTR?{left:i.dom.offsetWidth}:{right:i.dom.offsetWidth}:null}))});function ao(t){return Array.isArray(t)?t:[t]}function fo(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class co{constructor(t,e,i){this.gutter=t,this.height=i,this.localMarkers=[],this.i=0,this.cursor=Ae.iter(t.markers,e.from)}line(t,e,i){this.localMarkers.length&&(this.localMarkers=[]),fo(this.cursor,this.localMarkers,e.from);let s=i.length?this.localMarkers.concat(i):this.localMarkers,r=this.gutter.config.lineMarker(t,e,s);r&&s.unshift(r);let n=this.gutter;if(0==s.length&&!n.config.renderEmptyElements)return;let h=e.top-this.height;if(this.i==n.elements.length){let i=new $o(t,e.height,h,s);n.elements.push(i),n.dom.appendChild(i.dom)}else n.elements[this.i].update(t,e.height,h,s);this.height=e.bottom,this.i++}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Oo{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,(s=>{let r=t.lineBlockAtHeight(s.clientY-t.documentTop);e.domEventHandlers[i](t,r,s)&&s.preventDefault()}));this.markers=ao(e.markers(t)),e.initialSpacer&&(this.spacer=new $o(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=ao(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let i=t.view.viewport;return!Ae.eq(this.markers,e,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class $o{constructor(t,e,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,s)}update(t,e,i,s){this.height!=e&&(this.dom.style.height=(this.height=e)+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;iMe(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let s=i[t],r=e[t];i[t]=s?(t,e,i)=>s(t,e,i)||r(t,e,i):r}return i}})});class wo extends io{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function go(t,e){return t.state.facet(mo).formatNumber(e,t.state)}const bo=no.compute([mo],(t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(po),lineMarker:(t,e,i)=>i.some((t=>t.toDOM))?null:new wo(go(t,t.state.doc.lineAt(e.from).number)),lineMarkerChange:t=>t.startState.facet(mo)!=t.state.facet(mo),initialSpacer:t=>new wo(go(t,yo(t.state.doc.lines))),updateSpacer(t,e){let i=go(e.view,yo(e.view.state.doc.lines));return i==t.number?t:new wo(i)},domEventHandlers:t.facet(mo).domEventHandlers})));function xo(t={}){return[mo.of(t),lo(),bo]}function yo(t){let e=9;for(;e{let e=[],i=-1;for(let s of t.selection.ranges)if(s.empty){let r=t.doc.lineAt(s.head).from;r>i&&(i=r,e.push(Qo.range(r)))}return Ae.of(e)}));function vo(){return Po}const qo=1024;let So=0;class ko{constructor(t,e){this.from=t,this.to=e}}class Io{constructor(t={}){this.id=So++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof t&&(t=Wo.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}Io.closedBy=new Io({deserialize:t=>t.split(" ")}),Io.openedBy=new Io({deserialize:t=>t.split(" ")}),Io.group=new Io({deserialize:t=>t.split(" ")}),Io.contextHash=new Io({perNode:!0}),Io.lookAhead=new Io({perNode:!0}),Io.mounted=new Io({perNode:!0});const Ro=Object.create(null);class Wo{constructor(t,e,i,s=0){this.name=t,this.props=e,this.id=i,this.flags=s}static define(t){let e=t.props&&t.props.length?Object.create(null):Ro,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),s=new Wo(t.name||"",e,t.id,i);if(t.props)for(let i of t.props)if(Array.isArray(i)||(i=i(s)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[i[0].id]=i[1]}return s}prop(t){return this.props[t.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(Io.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let s of i.split(" "))e[s]=t[i];return t=>{for(let i=t.prop(Io.group),s=-1;s<(i?i.length:0);s++){let r=e[s<0?t.name:i[s]];if(r)return r}}}}Wo.none=new Wo("",Object.create(null),0,8);class Yo{constructor(t){this.types=t;for(let e=0;e=s&&(n.type.isAnonymous||!1!==e(n))){if(n.firstChild())continue;t=!0}for(;t&&i&&!n.type.isAnonymous&&i(n),!n.nextSibling();){if(!n.parent())return;t=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Lo(Wo.none,this.children,this.positions,0,this.children.length,0,this.length,((t,e,i)=>new To(this.type,t,e,i,this.propValues)),t.makeTree||((t,e,i)=>new To(Wo.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:s,maxBufferLength:r=qo,reused:n=[],minRepeatType:h=s.types.length}=t,o=Array.isArray(i)?new _o(i,i.length):i,l=s.types,u=0,a=0;function f(t,e,i,m,w){let{id:g,start:b,end:x,size:y}=o,Q=a;for(;y<0;){if(o.next(),-1==y){let e=n[g];return i.push(e),void m.push(b-t)}if(-3==y)return void(u=g);if(-4==y)return void(a=g);throw new RangeError(`Unrecognized record size: ${y}`)}let P,v,q=l[g],S=b-t;if(x-b<=r&&(v=$(o.pos-e,w))){let e=new Uint16Array(v.size-v.skip),i=o.pos-v.size,r=e.length;for(;o.pos>i;)r=p(v.start,e,r);P=new Eo(e,x-v.start,s),S=v.start-t}else{let t=o.pos-y;o.next();let e=[],i=[],s=g>=h?g:-1,n=0,l=x;for(;o.pos>t;)s>=0&&o.id==s&&o.size>=0?(o.end<=l-r&&(O(e,i,b,n,o.end,l,s,Q),n=e.length,l=o.end),o.next()):f(b,t,e,i,s);if(s>=0&&n>0&&n-1&&n>0){let t=c(q);P=Lo(q,e,i,0,e.length,0,x-b,t,t)}else P=d(q,e,i,x-b,Q-x)}i.push(P),m.push(S)}function c(t){return(e,i,s)=>{let r,n,h=0,o=e.length-1;if(o>=0&&(r=e[o])instanceof To){if(!o&&r.type==t&&r.length==s)return r;(n=r.prop(Io.lookAhead))&&(h=i[o]+r.length+n)}return d(t,e,i,s,h)}}function O(t,e,i,r,n,h,o,l){let u=[],a=[];for(;t.length>r;)u.push(t.pop()),a.push(e.pop()+i-n);t.push(d(s.types[o],u,a,h-n,l-h)),e.push(n-i)}function d(t,e,i,s,r=0,n){if(u){let t=[Io.contextHash,u];n=n?[t].concat(n):[t]}if(r>25){let t=[Io.lookAhead,r];n=n?[t].concat(n):[t]}return new To(t,e,i,s,n)}function $(t,e){let i=o.fork(),s=0,n=0,l=0,u=i.end-r,a={size:0,start:0,skip:0};t:for(let r=i.pos-t;i.pos>r;){let t=i.size;if(i.id==e&&t>=0){a.size=s,a.start=n,a.skip=l,l+=4,s+=4,i.next();continue}let o=i.pos-t;if(t<0||o=h?4:0,c=i.start;for(i.next();i.pos>o;){if(i.size<0){if(-3!=i.size)break t;f+=4}else i.id>=h&&(f+=4);i.next()}n=c,s+=t,l+=f}return(e<0||s==t)&&(a.size=s,a.start=n,a.skip=l),a.size>4?a:void 0}function p(t,e,i){let{id:s,start:r,end:n,size:l}=o;if(o.next(),l>=0&&s4){let s=o.pos-(l-4);for(;o.pos>s;)i=p(t,e,i)}e[--i]=h,e[--i]=n-t,e[--i]=r-t,e[--i]=s}else-3==l?u=s:-4==l&&(a=s);return i}let m=[],w=[];for(;o.pos>0;)f(t.start||0,t.bufferStart||0,m,w,-1);let g=null!==(e=t.length)&&void 0!==e?e:m.length?w[0]+m[0].length:0;return new To(l[t.topID],m.reverse(),w.reverse(),g)}(t)}}To.empty=new To(Wo.none,[],[],0);class _o{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new _o(this.buffer,this.index)}}class Eo{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return Wo.none}toString(){let t=[];for(let e=0;e0));o=n[o+3]);return h}slice(t,e,i,s){let r=this.buffer,n=new Uint16Array(e-t);for(let s=t,h=0;s=e&&ie;case 1:return i<=e&&s>e;case 2:return s>e;case 4:return!0}}function jo(t,e){let i=t.childBefore(e);for(;i;){let e=i.lastChild;if(!e||e.to!=i.to)break;e.type.isError&&e.from==e.to?(t=i,i=e.prevSibling):i=e}return t}function Uo(t,e,i,s){for(var r;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to0?h.length:-1;t!=l;t+=e){let l=h[t],u=o[t]+n.from;if(Ao(s,i,u,u+l.length))if(l instanceof Eo){if(r&Zo.ExcludeBuffers)continue;let h=l.findChild(0,l.buffer.length,e,i-u,s);if(h>-1)return new zo(new Do(n,l,t,u),null,h)}else if(r&Zo.IncludeAnonymous||!l.type.isAnonymous||No(l)){let h;if(!(r&Zo.IgnoreMounts)&&l.props&&(h=l.prop(Io.mounted))&&!h.overlay)return new Vo(h.tree,u,t,n);let o=new Vo(l,u,t,n);return r&Zo.IncludeAnonymous||!o.type.isAnonymous?o:o.nextChild(e<0?l.children.length-1:0,e,i,s)}}if(r&Zo.IncludeAnonymous||!n.type.isAnonymous)return null;if(t=n.index>=0?n.index+e:e<0?-1:n._parent._tree.children.length,n=n._parent,!n)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,i=0){let s;if(!(i&Zo.IgnoreOverlays)&&(s=this._tree.prop(Io.mounted))&&s.overlay){let i=t-this.from;for(let{from:t,to:r}of s.overlay)if((e>0?t<=i:t=i:r>i))return new Vo(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}cursor(t=0){return new Ho(this,t)}get tree(){return this._tree}toTree(){return this._tree}resolve(t,e=0){return Uo(this,t,e,!1)}resolveInner(t,e=0){return Uo(this,t,e,!0)}enterUnfinishedNodesBefore(t){return jo(this,t)}getChild(t,e=null,i=null){let s=Co(this,t,e,i);return s.length?s[0]:null}getChildren(t,e=null,i=null){return Co(this,t,e,i)}toString(){return this._tree.toString()}get node(){return this}matchContext(t){return Go(this,t)}}function Co(t,e,i,s){let r=t.cursor(),n=[];if(!r.firstChild())return n;if(null!=i)for(;!r.type.is(i);)if(!r.nextSibling())return n;for(;;){if(null!=s&&r.type.is(s))return n;if(r.type.is(e)&&n.push(r.node),!r.nextSibling())return null==s?n:[]}}function Go(t,e,i=e.length-1){for(let s=t.parent;i>=0;s=s.parent){if(!s)return!1;if(!s.type.isAnonymous){if(e[i]&&e[i]!=s.name)return!1;i--}}return!0}class Do{constructor(t,e,i,s){this.parent=t,this.buffer=e,this.index=i,this.start=s}}class zo{constructor(t,e,i){this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}child(t,e,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.context.start,i);return r<0?null:new zo(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,i=0){if(i&Zo.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return r<0?null:new zo(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new zo(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new zo(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}cursor(t=0){return new Ho(this,t)}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let n=i.buffer[this.index+1],h=i.buffer[this.index+2];t.push(i.slice(s,r,n,h)),e.push(0)}return new To(this.type,t,e,this.to-this.from)}resolve(t,e=0){return Uo(this,t,e,!1)}resolveInner(t,e=0){return Uo(this,t,e,!0)}enterUnfinishedNodesBefore(t){return jo(this,t)}toString(){return this.context.buffer.childString(this.index)}getChild(t,e=null,i=null){let s=Co(this,t,e,i);return s.length?s[0]:null}getChildren(t,e=null,i=null){return Co(this,t,e,i)}get node(){return this}matchContext(t){return Go(this,t)}}class Ho{constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof Vo)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let e=t._parent;e;e=e._parent)this.stack.unshift(e.index);this.bufferNode=t,this.yieldBuf(t.index)}}get name(){return this.type.name}yieldNode(t){return!!t&&(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0)}yieldBuf(t,e){this.index=t;let{start:i,buffer:s}=this.buffer;return this.type=e||s.set.types[s.buffer[t]],this.from=i+s.buffer[t+1],this.to=i+s.buffer[t+2],!0}yield(t){return!!t&&(t instanceof Vo?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.buffer.start,i);return!(r<0)&&(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,i=this.mode){return this.buffer?!(i&Zo.ExcludeBuffers)&&this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Zo.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&Zo.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return!!this._tree._parent&&this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode));let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let t=i<0?0:this.stack[i]+4;if(this.index!=t)return this.yieldBuf(e.findChild(t,this.index,-1,0,4))}else{let t=e.buffer[this.index+3];if(t<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(t)}return i<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:s}=this;if(s){if(t>0){if(this.index-1)for(let s=e+t,r=t<0?-1:i._tree.children.length;s!=r;s+=t){let t=i._tree.children[s];if(this.mode&Zo.IncludeAnonymous||t instanceof Eo||!t.type.isAnonymous||No(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to=0;){for(let n=t;n;n=n._parent)if(n.index==s){if(s==this.index)return n;e=n,i=r+1;break t}s=this.stack[--r]}for(let t=i;t=0;r--){if(r<0)return Go(this.node,t,s);let n=i[e.buffer[this.stack[r]]];if(!n.isAnonymous){if(t[s]&&t[s]!=n.name)return!1;s--}}return!0}}function No(t){return t.children.some((t=>t instanceof Eo||!t.type.isAnonymous||No(t)))}const Fo=new WeakMap;function Bo(t,e){if(!t.isAnonymous||e instanceof Eo||e.type!=t)return 1;let i=Fo.get(e);if(null==i){i=1;for(let s of e.children){if(s.type!=t||!(s instanceof To)){i=1;break}i+=Bo(t,s)}Fo.set(e,i)}return i}function Lo(t,e,i,s,r,n,h,o,l){let u=0;for(let i=s;i=a)break;d+=e}if(u==r+1){if(d>a){let t=i[r];e(t.children,t.positions,0,t.children.length,s[r]+o);continue}f.push(i[r])}else{let e=s[u-1]+i[u-1].length-O;f.push(Lo(t,i,s,r,u,O,e,null,l))}c.push(O+o-n)}}(e,i,s,r,0),(o||l)(f,c,h)}class Ko{constructor(t,e,i,s,r=!1,n=!1){this.from=t,this.to=e,this.tree=i,this.offset=s,this.open=(r?1:0)|(n?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],i=!1){let s=[new Ko(0,t.length,t,0,!1,i)];for(let i of e)i.to>t.length&&s.push(i);return s}static applyChanges(t,e,i=128){if(!e.length)return t;let s=[],r=1,n=t.length?t[0]:null;for(let h=0,o=0,l=0;;h++){let u=h=i)for(;n&&n.from=e.from||a<=e.to||l){let t=Math.max(e.from,o)-l,i=Math.min(e.to,a)-l;e=t>=i?null:new Ko(t,i,e.tree,e.offset+l,h>0,!!u)}if(e&&s.push(e),n.to>a)break;n=rnew ko(t.from,t.to))):[new ko(0,0)]:[new ko(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let s=this.startParse(t,e,i);for(;;){let t=s.advance();if(t)return t}}}class tl{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new Io({perNode:!0});let el=0;class il{constructor(t,e,i){this.set=t,this.base=e,this.modified=i,this.id=el++}static define(t){if(null==t?void 0:t.base)throw new Error("Can not derive from a modified tag");let e=new il([],null,[]);if(e.set.push(e),t)for(let i of t.set)e.set.push(i);return e}static defineModifier(){let t=new rl;return e=>e.modified.indexOf(t)>-1?e:rl.get(e.base||e,e.modified.concat(t).sort(((t,e)=>t.id-e.id)))}}let sl=0;class rl{constructor(){this.instances=[],this.id=sl++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find((i=>i.base==t&&function(t,e){return t.length==e.length&&t.every(((t,i)=>t==e[i]))}(e,i.modified)));if(i)return i;let s=[],r=new il(s,t,e);for(let t of e)t.instances.push(r);let n=nl(e);for(let e of t.set)for(let t of n)s.push(rl.get(e,t));return r}}function nl(t){let e=[t];for(let i=0;i0&&e+3==t.length){r=1;break}let s=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(n);if(!s)throw new RangeError("Invalid path: "+t);if(i.push("*"==s[0]?"":'"'==s[0][0]?JSON.parse(s[0]):s[0]),e+=s[0].length,e==t.length)break;let h=t[e++];if(e==t.length&&"!"==h){r=0;break}if("/"!=h)throw new RangeError("Invalid path: "+t);n=t.slice(e)}let h=i.length-1,o=i[h];if(!o)throw new RangeError("Invalid path: "+t);let l=new ll(s,r,h>0?i.slice(0,h):null);e[o]=l.sort(e[o])}}return ol.add(e)}const ol=new Io;class ll{constructor(t,e,i,s){this.tags=t,this.mode=e,this.context=i,this.next=s}sort(t){return!t||t.depth{let e=r;for(let s of t)for(let t of s.set){let s=i[t.id];if(s){e=e?e+" "+s:s;break}}return e},scope:s}}function al(t,e){let i=null;for(let s of t){let t=s.style(e);t&&(i=i?i+" "+t:t)}return i}function fl(t,e,i,s=0,r=t.length){let n=new cl(s,Array.isArray(e)?e:[e],i);n.highlightRange(t.cursor(),s,r,"",n.highlighters),n.flush(r)}class cl{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,s,r){let{type:n,from:h,to:o}=t;if(h>=i||o<=e)return;n.isTop&&(r=this.highlighters.filter((t=>!t.scope||t.scope(n))));let l=s,u=n.prop(ol),a=!1;for(;u;){if(!u.context||t.matchContext(u.context)){let t=al(r,u.tags);t&&(l&&(l+=" "),l+=t,1==u.mode?s+=(s?" ":"")+t:0==u.mode&&(a=!0));break}u=u.next}if(this.startSpan(t.from,l),a)return;let f=t.tree&&t.tree.prop(Io.mounted);if(f&&f.overlay){let n=t.node.enter(f.overlay[0].from+h,1),u=this.highlighters.filter((t=>!t.scope||t.scope(f.tree.type))),a=t.firstChild();for(let c=0,O=h;;c++){let d=c=$)&&t.nextSibling()););if(!d||$>i)break;O=d.to+h,O>e&&(this.highlightRange(n.cursor(),Math.max(e,d.from+h),Math.min(i,O),s,u),this.startSpan(O,l))}a&&t.parent()}else if(t.firstChild()){do{if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,s,r),this.startSpan(Math.min(i,t.to),l)}}while(t.nextSibling());t.parent()}}}const Ol=il.define,dl=Ol(),$l=Ol(),pl=Ol($l),ml=Ol($l),wl=Ol(),gl=Ol(wl),bl=Ol(wl),xl=Ol(),yl=Ol(xl),Ql=Ol(),Pl=Ol(),vl=Ol(),ql=Ol(vl),Sl=Ol(),kl={comment:dl,lineComment:Ol(dl),blockComment:Ol(dl),docComment:Ol(dl),name:$l,variableName:Ol($l),typeName:pl,tagName:Ol(pl),propertyName:ml,attributeName:Ol(ml),className:Ol($l),labelName:Ol($l),namespace:Ol($l),macroName:Ol($l),literal:wl,string:gl,docString:Ol(gl),character:Ol(gl),attributeValue:Ol(gl),number:bl,integer:Ol(bl),float:Ol(bl),bool:Ol(wl),regexp:Ol(wl),escape:Ol(wl),color:Ol(wl),url:Ol(wl),keyword:Ql,self:Ol(Ql),null:Ol(Ql),atom:Ol(Ql),unit:Ol(Ql),modifier:Ol(Ql),operatorKeyword:Ol(Ql),controlKeyword:Ol(Ql),definitionKeyword:Ol(Ql),moduleKeyword:Ol(Ql),operator:Pl,derefOperator:Ol(Pl),arithmeticOperator:Ol(Pl),logicOperator:Ol(Pl),bitwiseOperator:Ol(Pl),compareOperator:Ol(Pl),updateOperator:Ol(Pl),definitionOperator:Ol(Pl),typeOperator:Ol(Pl),controlOperator:Ol(Pl),punctuation:vl,separator:Ol(vl),bracket:ql,angleBracket:Ol(ql),squareBracket:Ol(ql),paren:Ol(ql),brace:Ol(ql),content:xl,heading:yl,heading1:Ol(yl),heading2:Ol(yl),heading3:Ol(yl),heading4:Ol(yl),heading5:Ol(yl),heading6:Ol(yl),contentSeparator:Ol(xl),list:Ol(xl),quote:Ol(xl),emphasis:Ol(xl),strong:Ol(xl),link:Ol(xl),monospace:Ol(xl),strikethrough:Ol(xl),inserted:Ol(),deleted:Ol(),changed:Ol(),invalid:Ol(),meta:Sl,documentMeta:Ol(Sl),annotation:Ol(Sl),processingInstruction:Ol(Sl),definition:il.defineModifier(),constant:il.defineModifier(),function:il.defineModifier(),standard:il.defineModifier(),local:il.defineModifier(),special:il.defineModifier()};var Il;ul([{tag:kl.link,class:"tok-link"},{tag:kl.heading,class:"tok-heading"},{tag:kl.emphasis,class:"tok-emphasis"},{tag:kl.strong,class:"tok-strong"},{tag:kl.keyword,class:"tok-keyword"},{tag:kl.atom,class:"tok-atom"},{tag:kl.bool,class:"tok-bool"},{tag:kl.url,class:"tok-url"},{tag:kl.labelName,class:"tok-labelName"},{tag:kl.inserted,class:"tok-inserted"},{tag:kl.deleted,class:"tok-deleted"},{tag:kl.literal,class:"tok-literal"},{tag:kl.string,class:"tok-string"},{tag:kl.number,class:"tok-number"},{tag:[kl.regexp,kl.escape,kl.special(kl.string)],class:"tok-string2"},{tag:kl.variableName,class:"tok-variableName"},{tag:kl.local(kl.variableName),class:"tok-variableName tok-local"},{tag:kl.definition(kl.variableName),class:"tok-variableName tok-definition"},{tag:kl.special(kl.variableName),class:"tok-variableName2"},{tag:kl.definition(kl.propertyName),class:"tok-propertyName tok-definition"},{tag:kl.typeName,class:"tok-typeName"},{tag:kl.namespace,class:"tok-namespace"},{tag:kl.className,class:"tok-className"},{tag:kl.macroName,class:"tok-macroName"},{tag:kl.propertyName,class:"tok-propertyName"},{tag:kl.operator,class:"tok-operator"},{tag:kl.comment,class:"tok-comment"},{tag:kl.meta,class:"tok-meta"},{tag:kl.invalid,class:"tok-invalid"},{tag:kl.punctuation,class:"tok-punctuation"}]);const Rl=new Io;class Wl{constructor(t,e,i=[]){this.data=t,Xe.prototype.hasOwnProperty("tree")||Object.defineProperty(Xe.prototype,"tree",{get(){return Ml(this)}}),this.parser=e,this.extension=[Cl.of(this),Xe.languageData.of(((t,e,i)=>t.facet(Yl(t,e,i))))].concat(i)}isActiveAt(t,e,i=-1){return Yl(t,e,i)==this.data}findRegions(t){let e=t.facet(Cl);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],s=(t,e)=>{if(t.prop(Rl)==this.data)return void i.push({from:e,to:e+t.length});let r=t.prop(Io.mounted);if(r){if(r.tree.prop(Rl)==this.data){if(r.overlay)for(let t of r.overlay)i.push({from:t.from+e,to:t.to+e});else i.push({from:e,to:e+t.length});return}if(r.overlay){let t=i.length;if(s(r.tree,r.overlay[0].from+e),i.length>t)return}}for(let i=0;it.concat(i):void 0}));var i;return new Xl(e,t.parser.configure({props:[Rl.add((t=>t.isTop?e:void 0))]}))}configure(t){return new Xl(this.data,this.parser.configure(t))}get allowsNesting(){return this.parser.hasWrappers()}}function Ml(t){let e=t.field(Wl.state,!1);return e?e.tree:To.empty}class Zl{constructor(t,e=t.length){this.doc=t,this.length=e,this.cursorPos=0,this.string="",this.cursor=t.iter()}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let Tl=null;class _l{constructor(t,e,i=[],s,r,n,h,o){this.parser=t,this.state=e,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=n,this.skipped=h,this.scheduleOn=o,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new _l(t,e,[],To.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Zl(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=To.empty&&this.isDone(null!=e?e:this.state.doc.length)?(this.takeTree(),!0):this.withContext((()=>{var i;if("number"==typeof t){let e=Date.now()+t;t=()=>Date.now()>e}for(this.parse||(this.parse=this.startParse()),null!=e&&(null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&e=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext((()=>{for(;!(e=this.parse.advance()););})),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(Ko.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Tl;Tl=this;try{return t()}finally{Tl=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=El(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:s,treeLen:r,viewport:n,skipped:h}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges(((t,i,s,r)=>e.push({fromA:t,toA:i,fromB:s,toB:r}))),i=Ko.applyChanges(i,e),s=To.empty,r=0,n={from:t.mapPos(n.from,-1),to:t.mapPos(n.to,1)},this.skipped.length){h=[];for(let e of this.skipped){let i=t.mapPos(e.from,1),s=t.mapPos(e.to,-1);it.from&&(this.fragments=El(this.fragments,i,s),this.skipped.splice(e--,1))}return!(this.skipped.length>=e||(this.reset(),0))}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Jo{createParse(e,i,s){let r=s[0].from,n=s[s.length-1].to,h={parsedPos:r,advance(){let e=Tl;if(e){for(let t of s)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=n,new To(Wo.none,[],[],n-r)},stoppedAt:null,stopAt(){}};return h}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&0==e[0].from&&e[0].to>=t}static get(){return Tl}}function El(t,e,i){return Ko.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class Al{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Al(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=_l.create(t.facet(Cl).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Al(i)}}Wl.state=Kt.define({create:Al.init,update(t,e){for(let t of e.effects)if(t.is(Wl.setState))return t.value;return e.startState.facet(Cl)!=e.state.facet(Cl)?Al.init(e.state):t.apply(e)}});let jl=t=>{let e=setTimeout((()=>t()),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(jl=t=>{let e=-1,i=setTimeout((()=>{e=requestIdleCallback(t,{timeout:400})}),100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const Ul="undefined"!=typeof navigator&&(null===(Il=navigator.scheduling)||void 0===Il?void 0:Il.isInputPending)?()=>navigator.scheduling.isInputPending():null,Vl=Es.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(Wl.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),t.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(Wl.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=jl(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnds+1e3,o=r.context.work((()=>Ul&&Ul()||Date.now()>n),s+(h?0:1e5));this.chunkBudget-=Date.now()-e,(o||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Wl.setState.of(new Al(r.context))})),this.chunkBudget>0&&(!o||h)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then((()=>this.scheduleWork())).catch((t=>Ms(this.view.state,t))).then((()=>this.workScheduled--)),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Cl=Dt.define({combine:t=>t.length?t[0]:null,enables:[Wl.state,Vl]});class Gl{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const Dl=Dt.define(),zl=Dt.define({combine:t=>{if(!t.length)return" ";if(!/^(?: +|\t+)$/.test(t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return t[0]}});function Hl(t){let e=t.facet(zl);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function Nl(t,e){let i="",s=t.tabSize;if(9==t.facet(zl).charCodeAt(0))for(;e>=s;)i+="\t",e-=s;for(let t=0;t=i.from&&s<=i.to?r&&s==t?{text:"",from:t}:(e<0?s-1&&(r+=n-this.countColumn(i,i.search(/\S|$/))),r}countColumn(t,e=t.length){return Le(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:s}=this.lineAt(t,e),r=this.options.overrideIndentation;if(r){let t=r(s);if(t>-1)return t}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Ll=new Io;function Kl(t){let e=t.type.prop(Ll);if(e)return e;let i,s=t.firstChild;if(s&&(i=s.type.prop(Io.closedBy))){let e=t.lastChild,s=e&&i.indexOf(e.name)>-1;return t=>ru(t,!0,1,void 0,s&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?tu:null}function Jl(t,e,i){for(;t;t=t.parent){let s=Kl(t);if(s)return s(eu.create(i,e,t))}return null}function tu(){return 0}class eu extends Bl{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.node=i}static create(t,e,i){return new eu(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){let t=this.state.doc.lineAt(this.node.from);for(;;){let e=this.node.resolve(t.from);for(;e.parent&&e.parent.from==e.from;)e=e.parent;if(iu(e,this.node))break;t=this.state.doc.lineAt(e.from)}return this.lineIndent(t.from)}continue(){let t=this.node.parent;return t?Jl(t,this.pos,this.base):0}}function iu(t,e){for(let i=e;i;i=i.parent)if(t==i)return!0;return!1}function su({closing:t,align:e=!0,units:i=1}){return s=>ru(s,e,i,t)}function ru(t,e,i,s,r){let n=t.textAfter,h=n.match(/^\s*/)[0].length,o=s&&n.slice(h,h+s.length)==s||r==t.pos+h,l=e?function(t){let e=t.node,i=e.childAfter(e.from),s=e.lastChild;if(!i)return null;let r=t.options.simulateBreak,n=t.state.doc.lineAt(i.from),h=null==r||r<=n.from?n.to:Math.min(n.to,r);for(let t=i.to;;){let r=e.childAfter(t);if(!r||r==s)return null;if(!r.type.isSkipped)return r.from{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let i=t.newDoc,{head:s}=t.newSelection.main,r=i.lineAt(s);if(s>r.from+200)return t;let n=i.sliceString(r.from,s);if(!e.some((t=>t.test(n))))return t;let{state:h}=t,o=-1,l=[];for(let{head:t}of h.selection.ranges){let e=h.doc.lineAt(t);if(e.from==o)continue;o=e.from;let i=Fl(h,e.from);if(null==i)continue;let s=/^\s*/.exec(e.text)[0],r=Nl(h,i);s!=r&&l.push({from:e.from,to:e.from+s.length,insert:r})}return l.length?[t,{changes:l,sequential:!0}]:t}))}const hu=Dt.define(),ou=new Io;function lu(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function uu(t,e,i){for(let s of t.facet(hu)){let r=s(t,e,i);if(r)return r}return function(t,e,i){let s=Ml(t);if(s.lengthi)continue;if(r&&n.from=e&&s.to>i&&(r=s)}}return r}(t,e,i)}function au(t,e){let i=e.mapPos(t.from,1),s=e.mapPos(t.to,-1);return i>=s?void 0:{from:i,to:s}}const fu=xe.define({map:au}),cu=xe.define({map:au});function Ou(t){let e=[];for(let{head:i}of t.state.selection.ranges)e.some((t=>t.from<=i&&t.to>=i))||e.push(t.lineBlockAt(i));return e}const du=Kt.define({create:()=>ds.none,update(t,e){t=t.map(e.changes);for(let i of e.effects)i.is(fu)&&!pu(t,i.value.from,i.value.to)?t=t.update({add:[Qu.range(i.value.from,i.value.to)]}):i.is(cu)&&(t=t.update({filter:(t,e)=>i.value.from!=t||i.value.to!=e,filterFrom:i.value.from,filterTo:i.value.to}));if(e.selection){let i=!1,{head:s}=e.selection.main;t.between(s,s,((t,e)=>{ts&&(i=!0)})),i&&(t=t.update({filterFrom:s,filterTo:s,filter:(t,e)=>e<=s||t>=s}))}return t},provide:t=>jn.decorations.from(t),toJSON(t,e){let i=[];return t.between(0,e.doc.length,((t,e)=>{i.push(t,e)})),i},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let i=0;i{(!r||r.from>t)&&(r={from:t,to:e})})),r}function pu(t,e,i){let s=!1;return t.between(e,e,((t,r)=>{t==e&&r==i&&(s=!0)})),s}function mu(t,e){return t.field(du,!1)?e:e.concat(xe.appendConfig.of(yu()))}function wu(t,e,i=!0){let s=t.state.doc.lineAt(e.from).number,r=t.state.doc.lineAt(e.to).number;return jn.announce.of(`${t.state.phrase(i?"Folded lines":"Unfolded lines")} ${s} ${t.state.phrase("to")} ${r}.`)}const gu=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of Ou(t)){let i=uu(t.state,e.from,e.to);if(i)return t.dispatch({effects:mu(t.state,[fu.of(i),wu(t,i)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(du,!1))return!1;let e=[];for(let i of Ou(t)){let s=$u(t.state,i.from,i.to);s&&e.push(cu.of(s),wu(t,s,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,i=[];for(let s=0;s{let e=t.state.field(du,!1);if(!e||!e.size)return!1;let i=[];return e.between(0,t.state.doc.length,((t,e)=>{i.push(cu.of({from:t,to:e}))})),t.dispatch({effects:i}),!0}}],bu={placeholderDOM:null,placeholderText:"…"},xu=Dt.define({combine:t=>Me(t,bu)});function yu(t){let e=[du,Su];return t&&e.push(xu.of(t)),e}const Qu=ds.replace({widget:new class extends cs{toDOM(t){let{state:e}=t,i=e.facet(xu),s=e=>{let i=t.lineBlockAt(t.posAtDOM(e.target)),s=$u(t.state,i.from,i.to);s&&t.dispatch({effects:cu.of(s)}),e.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(t,s);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",e.phrase("folded code")),r.title=e.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}}}),Pu={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class vu extends io{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}function qu(t={}){let e=Object.assign(Object.assign({},Pu),t),i=new vu(e,!0),s=new vu(e,!1),r=Es.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(Cl)!=t.state.facet(Cl)||t.startState.field(du,!1)!=t.state.field(du,!1)||Ml(t.startState)!=Ml(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new je;for(let r of t.viewportLineBlocks){let n=$u(t.state,r.from,r.to)?s:uu(t.state,r.from,r.to)?i:null;n&&e.add(r.from,r.from,n)}return e.finish()}}),{domEventHandlers:n}=e;return[r,ho({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(r))||void 0===e?void 0:e.markers)||Ae.empty},initialSpacer:()=>new vu(e,!1),domEventHandlers:Object.assign(Object.assign({},n),{click:(t,e,i)=>{if(n.click&&n.click(t,e,i))return!0;let s=$u(t.state,e.from,e.to);if(s)return t.dispatch({effects:cu.of(s)}),!0;let r=uu(t.state,e.from,e.to);return!!r&&(t.dispatch({effects:fu.of(r)}),!0)}})}),yu()]}const Su=jn.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class ku{constructor(t,e){let i;function s(t){let e=ii.newName();return(i||(i=Object.create(null)))["."+e]=t,e}const r="string"==typeof e.all?e.all:e.all?s(e.all):void 0,n=e.scope;this.scope=n instanceof Wl?t=>t.prop(Rl)==n.data:n?t=>t==n:void 0,this.style=ul(t.map((t=>({tag:t.tag,class:t.class||s(Object.assign({},t,{tag:null}))}))),{all:r}).style,this.module=i?new ii(i):null,this.themeType=e.themeType}static define(t,e){return new ku(t,e||{})}}const Iu=Dt.define(),Ru=Dt.define({combine:t=>t.length?[t[0]]:null});function Wu(t){let e=t.facet(Iu);return e.length?e:t.facet(Ru)}function Yu(t,e){let i,s=[Mu];return t instanceof ku&&(t.module&&s.push(jn.styleModule.of(t.module)),i=t.themeType),(null==e?void 0:e.fallback)?s.push(Ru.of(t)):i?s.push(Iu.computeN([jn.darkTheme],(e=>e.facet(jn.darkTheme)==("dark"==i)?[t]:[]))):s.push(Iu.of(t)),s}class Xu{constructor(t){this.markCache=Object.create(null),this.tree=Ml(t.state),this.decorations=this.buildDeco(t,Wu(t.state))}update(t){let e=Ml(t.state),i=Wu(t.state),s=i!=Wu(t.startState);e.length{i.add(t,e,this.markCache[s]||(this.markCache[s]=ds.mark({class:s})))}),s,r);return i.finish()}}const Mu=re.high(Es.fromClass(Xu,{decorations:t=>t.decorations})),Zu=ku.define([{tag:kl.meta,color:"#7a757a"},{tag:kl.link,textDecoration:"underline"},{tag:kl.heading,textDecoration:"underline",fontWeight:"bold"},{tag:kl.emphasis,fontStyle:"italic"},{tag:kl.strong,fontWeight:"bold"},{tag:kl.strikethrough,textDecoration:"line-through"},{tag:kl.keyword,color:"#708"},{tag:[kl.atom,kl.bool,kl.url,kl.contentSeparator,kl.labelName],color:"#219"},{tag:[kl.literal,kl.inserted],color:"#164"},{tag:[kl.string,kl.deleted],color:"#a11"},{tag:[kl.regexp,kl.escape,kl.special(kl.string)],color:"#e40"},{tag:kl.definition(kl.variableName),color:"#00f"},{tag:kl.local(kl.variableName),color:"#30a"},{tag:[kl.typeName,kl.namespace],color:"#085"},{tag:kl.className,color:"#167"},{tag:[kl.special(kl.variableName),kl.macroName],color:"#256"},{tag:kl.definition(kl.propertyName),color:"#00c"},{tag:kl.comment,color:"#940"},{tag:kl.invalid,color:"#f00"}]),Tu=jn.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),_u="()[]{}",Eu=Dt.define({combine:t=>Me(t,{afterCursor:!0,brackets:_u,maxScanDistance:1e4,renderMatch:Uu})}),Au=ds.mark({class:"cm-matchingBracket"}),ju=ds.mark({class:"cm-nonmatchingBracket"});function Uu(t){let e=[],i=t.matched?Au:ju;return e.push(i.range(t.start.from,t.start.to)),t.end&&e.push(i.range(t.end.from,t.end.to)),e}const Vu=Kt.define({create:()=>ds.none,update(t,e){if(!e.docChanged&&!e.selection)return t;let i=[],s=e.state.facet(Eu);for(let t of e.state.selection.ranges){if(!t.empty)continue;let r=zu(e.state,t.head,-1,s)||t.head>0&&zu(e.state,t.head-1,1,s)||s.afterCursor&&(zu(e.state,t.head,1,s)||t.headjn.decorations.from(t)}),Cu=[Vu,Tu];function Gu(t={}){return[Eu.of(t),Cu]}function Du(t,e,i){let s=t.prop(e<0?Io.openedBy:Io.closedBy);if(s)return s;if(1==t.name.length){let s=i.indexOf(t.name);if(s>-1&&s%2==(e<0?1:0))return[i[s+e]]}return null}function zu(t,e,i,s={}){let r=s.maxScanDistance||1e4,n=s.brackets||_u,h=Ml(t),o=h.resolveInner(e,i);for(let t=o;t;t=t.parent){let e=Du(t.type,i,n);if(e&&t.from0)return null;let u={from:i<0?e-1:e,to:i>0?e+1:e},a=t.doc.iterRange(e,i>0?t.doc.length:0),f=0;for(let t=0;!a.next().done&&t<=n;){let n=a.value;i<0&&(t+=n.length);let o=e+t*i;for(let t=i>0?0:n.length-1,e=i>0?n.length:-1;t!=e;t+=i){let e=h.indexOf(n[t]);if(!(e<0||s.resolve(o+t,1).type!=r))if(e%2==0==i>0)f++;else{if(1==f)return{start:u,end:{from:o+t,to:o+t+1},matched:e>>1==l>>1};f--}}i>0&&(t+=n.length)}return a.done?{start:u,matched:!1}:null}(t,e,i,h,o.type,r,n)}function Hu(t,e,i,s,r,n){let h=s.parent,o={from:s.from,to:s.to},l=0,u=null==h?void 0:h.cursor();if(u&&(i<0?u.childBefore(s.from):u.childAfter(s.to)))do{if(i<0?u.to<=s.from:u.from>=s.to){if(0==l&&r.indexOf(u.type.name)>-1&&u.from-1||(Bu.push(t),console.warn(e))}function Ju(t,e){let i=null;for(let s of e.split(".")){let e=t[s]||kl[s];e?"function"==typeof e?i?i=e(i):Ku(s,`Modifier ${s} used at start of tag`):i?Ku(s,`Tag ${s} used as modifier`):i=e:Ku(s,`Unknown highlighting tag ${s}`)}if(!i)return 0;let s=e.replace(/ /g,"_"),r=Wo.define({id:Fu.length,name:s,props:[hl({[s]:i})]});return Fu.push(r),r.id}function ta(t,e){return({state:i,dispatch:s})=>{if(i.readOnly)return!1;let r=t(e,i);return!!r&&(s(i.update(r)),!0)}}const ea=ta(oa,0),ia=ta(ha,0),sa=ta(((t,e)=>ha(t,e,function(t){let e=[];for(let i of t.selection.ranges){let s=t.doc.lineAt(i.from),r=i.to<=s.to?s:t.doc.lineAt(i.to),n=e.length-1;n>=0&&e[n].to>s.from?e[n].to=r.to:e.push({from:s.from,to:r.to})}return e}(e))),0);function ra(t,e=t.selection.main.head){let i=t.languageDataAt("commentTokens",e);return i.length?i[0]:{}}const na=50;function ha(t,e,i=e.selection.ranges){let s=i.map((t=>ra(e,t.from).block));if(!s.every((t=>t)))return null;let r=i.map(((t,i)=>function(t,{open:e,close:i},s,r){let n,h,o=t.sliceDoc(s-na,s),l=t.sliceDoc(r,r+na),u=/\s*$/.exec(o)[0].length,a=/^\s*/.exec(l)[0].length,f=o.length-u;if(o.slice(f-e.length,f)==e&&l.slice(a,a+i.length)==i)return{open:{pos:s-u,margin:u&&1},close:{pos:r+a,margin:a&&1}};r-s<=2*na?n=h=t.sliceDoc(s,r):(n=t.sliceDoc(s,s+na),h=t.sliceDoc(r-na,r));let c=/^\s*/.exec(n)[0].length,O=/\s*$/.exec(h)[0].length,d=h.length-O-i.length;return n.slice(c,c+e.length)==e&&h.slice(d,d+i.length)==i?{open:{pos:s+c+e.length,margin:/\s/.test(n.charAt(c+e.length))?1:0},close:{pos:r-O-i.length,margin:/\s/.test(h.charAt(d-1))?1:0}}:null}(e,s[i],t.from,t.to)));if(2!=t&&!r.every((t=>t)))return{changes:e.changes(i.map(((t,e)=>r[e]?[]:[{from:t.from,insert:s[e].open+" "},{from:t.to,insert:" "+s[e].close}])))};if(1!=t&&r.some((t=>t))){let t=[];for(let e,i=0;ir&&(t==n||n>o.from)){r=o.from;let t=ra(e,i).line;if(!t)continue;let n=/^\s*/.exec(o.text)[0].length,l=n==o.length,u=o.text.slice(n,n+t.length)==t?n:-1;nt.comment<0&&(!t.empty||t.single)))){let t=[];for(let{line:e,token:i,indent:r,empty:n,single:h}of s)!h&&n||t.push({from:e.from+r,insert:i+" "});let i=e.changes(t);return{changes:i,selection:e.selection.map(i,1)}}if(1!=t&&s.some((t=>t.comment>=0))){let t=[];for(let{line:e,comment:i,token:r}of s)if(i>=0){let s=e.from+i,n=s+r.length;" "==e.text[n-e.from]&&n++,t.push({from:s,to:n})}return{changes:t}}return null}const la=we.define(),ua=we.define(),aa=Dt.define(),fa=Dt.define({combine:t=>Me(t,{minDepth:100,newGroupDelay:500},{minDepth:Math.max,newGroupDelay:Math.min})}),ca=Kt.define({create:()=>Ia.empty,update(t,e){let i=e.state.facet(fa),s=e.annotation(la);if(s){let r=e.docChanged?Vt.single(function(t){let e=0;return t.iterChangedRanges(((t,i)=>e=i)),e}(e.changes)):void 0,n=ga.fromTransaction(e,r),h=s.side,o=0==h?t.undone:t.done;return o=n?ba(o,o.length,i.minDepth,n):Pa(o,e.startState.selection),new Ia(0==h?s.rest:o,0==h?o:s.rest)}let r=e.annotation(ua);if("full"!=r&&"before"!=r||(t=t.isolate()),!1===e.annotation(ye.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let n=ga.fromTransaction(e),h=e.annotation(ye.time),o=e.annotation(ye.userEvent);return n?t=t.addChanges(n,h,o,i.newGroupDelay,i.minDepth):e.selection&&(t=t.addSelection(e.startState.selection,h,o,i.newGroupDelay)),"full"!=r&&"after"!=r||(t=t.isolate()),t},toJSON:t=>({done:t.done.map((t=>t.toJSON())),undone:t.undone.map((t=>t.toJSON()))}),fromJSON:t=>new Ia(t.done.map(ga.fromJSON),t.undone.map(ga.fromJSON))});function Oa(t={}){return[ca,fa.of(t),jn.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?$a:"historyRedo"==t.inputType?pa:null;return!!i&&(t.preventDefault(),i(e))}})]}function da(t,e){return function({state:i,dispatch:s}){if(!e&&i.readOnly)return!1;let r=i.field(ca,!1);if(!r)return!1;let n=r.pop(t,i,e);return!!n&&(s(n),!0)}}const $a=da(0,!1),pa=da(1,!1),ma=da(0,!0),wa=da(1,!0);class ga{constructor(t,e,i,s,r){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(t){return new ga(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:null===(t=this.changes)||void 0===t?void 0:t.toJSON(),mapped:null===(e=this.mapped)||void 0===e?void 0:e.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map((t=>t.toJSON()))}}static fromJSON(t){return new ga(t.changes&&Mt.fromJSON(t.changes),[],t.mapped&&Xt.fromJSON(t.mapped),t.startSelection&&Vt.fromJSON(t.startSelection),t.selectionsAfter.map(Vt.fromJSON))}static fromTransaction(t,e){let i=ya;for(let e of t.startState.facet(aa)){let s=e(t);s.length&&(i=i.concat(s))}return!i.length&&t.changes.empty?null:new ga(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,ya)}static selection(t){return new ga(void 0,ya,void 0,void 0,t)}}function ba(t,e,i,s){let r=e+1>i+20?e-i-1:0,n=t.slice(r,e);return n.push(s),n}function xa(t,e){return t.length?e.length?t.concat(e):t:e}const ya=[],Qa=200;function Pa(t,e){if(t.length){let i=t[t.length-1],s=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-Qa));return s.length&&s[s.length-1].eq(e)?t:(s.push(e),ba(t,t.length-1,1e9,i.setSelAfter(s)))}return[ga.selection([e])]}function va(t){let e=t[t.length-1],i=t.slice();return i[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),i}function qa(t,e){if(!t.length)return t;let i=t.length,s=ya;for(;i;){let r=Sa(t[i-1],e,s);if(r.changes&&!r.changes.empty||r.effects.length){let e=t.slice(0,i);return e[i-1]=r,e}e=r.mapped,i--,s=r.selectionsAfter}return s.length?[ga.selection(s)]:ya}function Sa(t,e,i){let s=xa(t.selectionsAfter.length?t.selectionsAfter.map((t=>t.map(e))):ya,i);if(!t.changes)return ga.selection(s);let r=t.changes.map(e),n=e.mapDesc(t.changes,!0),h=t.mapped?t.mapped.composeDesc(n):n;return new ga(r,xe.mapEffects(t.effects,e),h,t.startSelection.map(n),s)}const ka=/^(input\.type|delete)($|\.)/;class Ia{constructor(t,e,i=0,s=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new Ia(this.done,this.undone):this}addChanges(t,e,i,s,r){let n=this.done,h=n[n.length-1];return n=h&&h.changes&&!h.changes.empty&&t.changes&&(!i||ka.test(i))&&(!h.selectionsAfter.length&&e-this.prevTimei.push(t,e))),e.iterChangedRanges(((t,e,r,n)=>{for(let t=0;t=e&&r<=h&&(s=!0)}})),s}(h.changes,t.changes)||"input.type.compose"==i)?ba(n,n.length-1,r,new ga(t.changes.compose(h.changes),xa(t.effects,h.effects),h.mapped,h.startSelection,ya)):ba(n,n.length,r,t),new Ia(n,ya,e,i)}addSelection(t,e,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:ya;return r.length>0&&e-this.prevTimet.empty!=e.ranges[i].empty)).length}(r[r.length-1],t)?this:new Ia(Pa(this.done,t),this.undone,e,i)}addMapping(t){return new Ia(qa(this.done,t),qa(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let s=0==t?this.done:this.undone;if(0==s.length)return null;let r=s[s.length-1];if(i&&r.selectionsAfter.length)return e.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:la.of({side:t,rest:va(s)}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let i=1==s.length?ya:s.slice(0,s.length-1);return r.mapped&&(i=qa(i,r.mapped)),e.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:la.of({side:t,rest:i}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}Ia.empty=new Ia(ya,ya);const Ra=[{key:"Mod-z",run:$a,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:pa,preventDefault:!0},{key:"Mod-u",run:ma,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:wa,preventDefault:!0}];function Wa(t,e){return Vt.create(t.ranges.map(e),t.mainIndex)}function Ya(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Xa({state:t,dispatch:e},i){let s=Wa(t.selection,i);return!s.eq(t.selection)&&(e(Ya(t,s)),!0)}function Ma(t,e){return Vt.cursor(e?t.to:t.from)}function Za(t,e){return Xa(t,(i=>i.empty?t.moveByChar(i,e):Ma(i,e)))}function Ta(t){return t.textDirectionAt(t.state.selection.main.head)==Ns.LTR}const _a=t=>Za(t,!Ta(t)),Ea=t=>Za(t,Ta(t));function Aa(t,e){return Xa(t,(i=>i.empty?t.moveByGroup(i,e):Ma(i,e)))}function ja(t,e,i){if(e.type.prop(i))return!0;let s=e.to-e.from;return s&&(s>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function Ua(t,e,i){let s,r,n=Ml(t).resolveInner(e.head),h=i?Io.closedBy:Io.openedBy;for(let s=e.head;;){let e=i?n.childAfter(s):n.childBefore(s);if(!e)break;ja(t,e,h)?n=e:s=i?e.to:e.from}return r=n.type.prop(h)&&(s=i?zu(t,n.from,1):zu(t,n.to,-1))&&s.matched?i?s.end.to:s.end.from:i?n.to:n.from,Vt.cursor(r,i?-1:1)}function Va(t,e){return Xa(t,(i=>{if(!i.empty)return Ma(i,e);let s=t.moveVertically(i,e);return s.head!=i.head?s:t.moveToLineBoundary(i,e)}))}const Ca=t=>Va(t,!1),Ga=t=>Va(t,!0);function Da(t){return Math.max(t.defaultLineHeight,Math.min(t.dom.clientHeight,innerHeight)-5)}function za(t,e){let{state:i}=t,s=Wa(i.selection,(i=>i.empty?t.moveVertically(i,e,Da(t)):Ma(i,e)));if(s.eq(i.selection))return!1;let r,n=t.coordsAtPos(i.selection.main.head),h=t.scrollDOM.getBoundingClientRect();return n&&n.top>h.top&&n.bottomza(t,!1),Na=t=>za(t,!0);function Fa(t,e,i){let s=t.lineBlockAt(e.head),r=t.moveToLineBoundary(e,i);if(r.head==e.head&&r.head!=(i?s.to:s.from)&&(r=t.moveToLineBoundary(e,i,!1)),!i&&r.head==s.from&&s.length){let i=/^\s*/.exec(t.state.sliceDoc(s.from,Math.min(s.from+100,s.to)))[0].length;i&&e.head!=s.from+i&&(r=Vt.cursor(s.from+i))}return r}const Ba=t=>Xa(t,(e=>Fa(t,e,!0))),La=t=>Xa(t,(e=>Fa(t,e,!1)));function Ka(t,e){let i=Wa(t.state.selection,(t=>{let i=e(t);return Vt.range(t.anchor,i.head,i.goalColumn)}));return!i.eq(t.state.selection)&&(t.dispatch(Ya(t.state,i)),!0)}function Ja(t,e){return Ka(t,(i=>t.moveByChar(i,e)))}const tf=t=>Ja(t,!Ta(t)),ef=t=>Ja(t,Ta(t));function sf(t,e){return Ka(t,(i=>t.moveByGroup(i,e)))}function rf(t,e){return Ka(t,(i=>t.moveVertically(i,e)))}const nf=t=>rf(t,!1),hf=t=>rf(t,!0);function of(t,e){return Ka(t,(i=>t.moveVertically(i,e,Da(t))))}const lf=t=>of(t,!1),uf=t=>of(t,!0),af=t=>Ka(t,(e=>Fa(t,e,!0))),ff=t=>Ka(t,(e=>Fa(t,e,!1))),cf=({state:t,dispatch:e})=>(e(Ya(t,{anchor:0})),!0),Of=({state:t,dispatch:e})=>(e(Ya(t,{anchor:t.doc.length})),!0),df=({state:t,dispatch:e})=>(e(Ya(t,{anchor:t.selection.main.anchor,head:0})),!0),$f=({state:t,dispatch:e})=>(e(Ya(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function pf({state:t,dispatch:e},i){if(t.readOnly)return!1;let s="delete.selection",r=t.changeByRange((t=>{let{from:e,to:r}=t;if(e==r){let t=i(e);te&&(s="delete.forward"),e=Math.min(e,t),r=Math.max(r,t)}return e==r?{range:t}:{changes:{from:e,to:r},range:Vt.cursor(e)}}));return!r.changes.empty&&(e(t.update(r,{scrollIntoView:!0,userEvent:s})),!0)}function mf(t,e,i){if(t instanceof jn)for(let s of t.state.facet(jn.atomicRanges).map((e=>e(t))))s.between(e,e,((t,s)=>{te&&(e=i?s:t)}));return e}const wf=(t,e)=>pf(t,(i=>{let s,r,{state:n}=t,h=n.doc.lineAt(i);if(!e&&i>h.from&&iwf(t,!1),bf=t=>wf(t,!0),xf=(t,e)=>pf(t,(i=>{let s=i,{state:r}=t,n=r.doc.lineAt(s),h=r.charCategorizer(s);for(let t=null;;){if(s==(e?n.to:n.from)){s==i&&n.number!=(e?r.doc.lines:1)&&(s+=e?1:-1);break}let o=Qt(n.text,s-n.from,e)+n.from,l=n.text.slice(Math.min(s,o)-n.from,Math.max(s,o)-n.from),u=h(l);if(null!=t&&u!=t)break;" "==l&&s==i||(t=u),s=o}return mf(t,s,e)})),yf=t=>xf(t,!1),Qf=t=>pf(t,(e=>{let i=t.lineBlockAt(e).to;return mf(t,e=r.number){let t=e[e.length-1];t.to=n.to,t.ranges.push(s)}else e.push({from:r.from,to:n.to,ranges:[s]});i=n.number+1}return e}function vf(t,e,i){if(t.readOnly)return!1;let s=[],r=[];for(let e of Pf(t)){if(i?e.to==t.doc.length:0==e.from)continue;let n=t.doc.lineAt(i?e.to+1:e.from-1),h=n.length+1;if(i){s.push({from:e.to,to:n.to},{from:e.from,insert:n.text+t.lineBreak});for(let i of e.ranges)r.push(Vt.range(Math.min(t.doc.length,i.anchor+h),Math.min(t.doc.length,i.head+h)))}else{s.push({from:n.from,to:e.from},{from:e.to,insert:t.lineBreak+n.text});for(let t of e.ranges)r.push(Vt.range(t.anchor-h,t.head-h))}}return!!s.length&&(e(t.update({changes:s,scrollIntoView:!0,selection:Vt.create(r,t.selection.mainIndex),userEvent:"move.line"})),!0)}function qf(t,e,i){if(t.readOnly)return!1;let s=[];for(let e of Pf(t))i?s.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):s.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});return e(t.update({changes:s,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Sf=If(!1),kf=If(!0);function If(t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let s=e.changeByRange((i=>{let{from:s,to:r}=i,n=e.doc.lineAt(s),h=!t&&s==r&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,s=Ml(t).resolveInner(e),r=s.childBefore(e),n=s.childAfter(e);return r&&n&&r.to<=e&&n.from>=e&&(i=r.type.prop(Io.closedBy))&&i.indexOf(n.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(n.from).from?{from:r.to,to:n.from}:null}(e,s);t&&(s=r=(r<=n.to?n:e.doc.lineAt(r)).to);let o=new Bl(e,{simulateBreak:s,simulateDoubleBreak:!!h}),l=Fl(o,s);for(null==l&&(l=/^\s*/.exec(e.doc.lineAt(s).text)[0].length);rn.from&&s{let r=[];for(let n=s.from;n<=s.to;){let h=t.doc.lineAt(n);h.number>i&&(s.empty||s.to>h.from)&&(e(h,r,s),i=h.number),n=h.to+1}let n=t.changes(r);return{changes:r,range:Vt.range(n.mapPos(s.anchor,1),n.mapPos(s.head,1))}}))}const Wf=({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Rf(t,((e,i)=>{i.push({from:e.from,insert:t.facet(zl)})})),{userEvent:"input.indent"})),!0),Yf=({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Rf(t,((e,i)=>{let s=/^\s*/.exec(e.text)[0];if(!s)return;let r=Le(s,t.tabSize),n=0,h=Nl(t,Math.max(0,r-Hl(t)));for(;nAa(t,!Ta(t)),shift:t=>sf(t,!Ta(t))},{mac:"Cmd-ArrowLeft",run:La,shift:ff},{key:"ArrowRight",run:Ea,shift:ef,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>Aa(t,Ta(t)),shift:t=>sf(t,Ta(t))},{mac:"Cmd-ArrowRight",run:Ba,shift:af},{key:"ArrowUp",run:Ca,shift:nf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:cf,shift:df},{mac:"Ctrl-ArrowUp",run:Ha,shift:lf},{key:"ArrowDown",run:Ga,shift:hf,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Of,shift:$f},{mac:"Ctrl-ArrowDown",run:Na,shift:uf},{key:"PageUp",run:Ha,shift:lf},{key:"PageDown",run:Na,shift:uf},{key:"Home",run:La,shift:ff,preventDefault:!0},{key:"Mod-Home",run:cf,shift:df},{key:"End",run:Ba,shift:af,preventDefault:!0},{key:"Mod-End",run:Of,shift:$f},{key:"Enter",run:Sf},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:gf,shift:gf},{key:"Delete",run:bf},{key:"Mod-Backspace",mac:"Alt-Backspace",run:yf},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>xf(t,!0)},{mac:"Mod-Backspace",run:t=>pf(t,(e=>{let i=t.lineBlockAt(e).from;return mf(t,e>i?i:Math.max(0,e-1),!1)}))},{mac:"Mod-Delete",run:Qf}].concat([{key:"Ctrl-b",run:_a,shift:tf,preventDefault:!0},{key:"Ctrl-f",run:Ea,shift:ef},{key:"Ctrl-p",run:Ca,shift:nf},{key:"Ctrl-n",run:Ga,shift:hf},{key:"Ctrl-a",run:t=>Xa(t,(e=>Vt.cursor(t.lineBlockAt(e.head).from,1))),shift:t=>Ka(t,(e=>Vt.cursor(t.lineBlockAt(e.head).from)))},{key:"Ctrl-e",run:t=>Xa(t,(e=>Vt.cursor(t.lineBlockAt(e.head).to,-1))),shift:t=>Ka(t,(e=>Vt.cursor(t.lineBlockAt(e.head).to)))},{key:"Ctrl-d",run:bf},{key:"Ctrl-h",run:gf},{key:"Ctrl-k",run:Qf},{key:"Ctrl-Alt-h",run:yf},{key:"Ctrl-o",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange((t=>({changes:{from:t.from,to:t.to,insert:ft.of(["",""])},range:Vt.cursor(t.from)})));return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange((e=>{if(!e.empty||0==e.from||e.from==t.doc.length)return{range:e};let i=e.from,s=t.doc.lineAt(i),r=i==s.from?i-1:Qt(s.text,i-s.from,!1)+s.from,n=i==s.to?i+1:Qt(s.text,i-s.from,!0)+s.from;return{changes:{from:r,to:n,insert:t.doc.slice(i,n).append(t.doc.slice(r,i))},range:Vt.cursor(n)}}));return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:Na}].map((t=>({mac:t.key,run:t.run,shift:t.shift})))),Mf=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:t=>Xa(t,(e=>Ua(t.state,e,!Ta(t)))),shift:t=>Ka(t,(e=>Ua(t.state,e,!Ta(t))))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>Xa(t,(e=>Ua(t.state,e,Ta(t)))),shift:t=>Ka(t,(e=>Ua(t.state,e,Ta(t))))},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>vf(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>qf(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>vf(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>qf(t,e,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,s=null;return i.ranges.length>1?s=Vt.create([i.main]):i.main.empty||(s=Vt.create([Vt.cursor(i.main.head)])),!!s&&(e(Ya(t,s)),!0)}},{key:"Mod-Enter",run:kf},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=Pf(t).map((({from:e,to:i})=>Vt.range(e,Math.min(i+1,t.doc.length))));return e(t.update({selection:Vt.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=Wa(t.selection,(e=>{var i;let s=Ml(t).resolveInner(e.head,1);for(;!(s.from=e.to||s.to>e.to&&s.from<=e.from)&&(null===(i=s.parent)||void 0===i?void 0:i.parent);)s=s.parent;return Vt.range(s.to,s.from)}));return e(Ya(t,i)),!0},preventDefault:!0},{key:"Mod-[",run:Yf},{key:"Mod-]",run:Wf},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),s=new Bl(t,{overrideIndentation:t=>{let e=i[t];return e??-1}}),r=Rf(t,((e,r,n)=>{let h=Fl(s,e.from);if(null==h)return;/\S/.test(e.text)||(h=0);let o=/^\s*/.exec(e.text)[0],l=Nl(t,h);(o!=l||n.from{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes(Pf(e).map((({from:t,to:i})=>(t>0?t--:it.moveVertically(e,!0))).map(i);return t.dispatch({changes:i,selection:s,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>function(t,e,i){let s=!1,r=Wa(t.selection,(e=>{let r=zu(t,e.head,-1)||zu(t,e.head,1)||e.head>0&&zu(t,e.head-1,1)||e.head{let e=ra(t.state);return e.line?ea(t):!!e.block&&sa(t)}},{key:"Alt-A",run:ia}].concat(Xf),Zf={key:"Tab",run:Wf,shift:Yf};function Tf(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var s in i)if(Object.prototype.hasOwnProperty.call(i,s)){var r=i[s];"string"==typeof r?t.setAttribute(s,r):null!=r&&(t[s]=r)}e++}for(;et.normalize("NFKD"):t=>t;class Af{constructor(t,e,i=0,s=t.length,r){this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,s),this.bufferStart=i,this.normalize=r?t=>r(Ef(t)):Ef,this.query=this.normalize(e)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return kt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=It(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=Rt(t);let s=this.normalize(e);for(let t=0,r=i;;t++){let n=s.charCodeAt(t),h=this.match(n,r);if(h)return this.value=h,this;if(t==s.length-1)break;r==i&&tthis.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,s=i+e[0].length;if(this.matchPos=s+(i==s?1:0),i==this.curLine.length&&this.nextLine(),ithis.value.to)return this.value={from:i,to:s,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length=i||s.to<=e){let s=new Gf(e,t.sliceString(e,i));return Cf.set(t,s),s}if(s.from==e&&s.to==i)return s;let{text:r,from:n}=s;return n>e&&(r=t.sliceString(e,n)+r,n=e),s.to=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e&&this.flat.tothis.flat.text.length-10&&(e=null),e){let t=this.flat.from+e.index,i=t+e[0].length;return this.value={from:t,to:i,match:e},this.matchPos=i+(t==i?1:0),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Gf.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function zf(t){let e=Tf("input",{class:"cm-textfield",name:"line"});function i(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!i)return;let{state:s}=t,r=s.doc.lineAt(s.selection.main.head),[,n,h,o,l]=i,u=o?+o.slice(1):0,a=h?+h:r.number;if(h&&l){let t=a/100;n&&(t=t*("-"==n?-1:1)+r.number/s.doc.lines),a=Math.round(s.doc.lines*t)}else h&&n&&(a=a*("-"==n?-1:1)+r.number);let f=s.doc.line(Math.max(1,Math.min(s.doc.lines,a)));t.dispatch({effects:Hf.of(!1),selection:Vt.cursor(f.from+Math.max(0,Math.min(u,f.length))),scrollIntoView:!0}),t.focus()}return{dom:Tf("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:Hf.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),i())},onsubmit:t=>{t.preventDefault(),i()}},Tf("label",t.state.phrase("Go to line"),": ",e)," ",Tf("button",{class:"cm-button",type:"submit"},t.state.phrase("go")))}}"undefined"!=typeof Symbol&&(Vf.prototype[Symbol.iterator]=Df.prototype[Symbol.iterator]=function(){return this});const Hf=xe.define(),Nf=Kt.define({create:()=>!0,update(t,e){for(let i of e.effects)i.is(Hf)&&(t=i.value);return t},provide:t=>eo.from(t,(t=>t?zf:null))}),Ff=jn.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Bf={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Lf=Dt.define({combine:t=>Me(t,Bf,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});function Kf(t){let e=[sc,ic];return t&&e.push(Lf.of(t)),e}const Jf=ds.mark({class:"cm-selectionMatch"}),tc=ds.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ec(t,e,i,s){return!(0!=i&&t(e.sliceDoc(i-1,i))==Ie.Word||s!=e.doc.length&&t(e.sliceDoc(s,s+1))==Ie.Word)}const ic=Es.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(Lf),{state:i}=t,s=i.selection;if(s.ranges.length>1)return ds.none;let r,n=s.main,h=null;if(n.empty){if(!e.highlightWordAroundCursor)return ds.none;let t=i.wordAt(n.head);if(!t)return ds.none;h=i.charCategorizer(n.head),r=i.sliceDoc(t.from,t.to)}else{let t=n.to-n.from;if(t200)return ds.none;if(e.wholeWords){if(r=i.sliceDoc(n.from,n.to),h=i.charCategorizer(n.head),!ec(h,i,n.from,n.to)||!function(t,e,i,s){return t(e.sliceDoc(i,i+1))==Ie.Word&&t(e.sliceDoc(s-1,s))==Ie.Word}(h,i,n.from,n.to))return ds.none}else if(r=i.sliceDoc(n.from,n.to).trim(),!r)return ds.none}let o=[];for(let s of t.visibleRanges){let t=new Af(i.doc,r,s.from,s.to);for(;!t.next().done;){let{from:s,to:r}=t.value;if((!h||ec(h,i,s,r))&&(n.empty&&s<=n.from&&r>=n.to?o.push(tc.range(s,r)):(s>=n.to||r<=n.from)&&o.push(Jf.range(s,r)),o.length>e.maxMatches))return ds.none}}return ds.set(o)}},{decorations:t=>t.decorations}),sc=jn.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),rc=Dt.define({combine(t){var e;return{top:t.reduce(((t,e)=>null!=t?t:e.top),void 0)||!1,caseSensitive:t.reduce(((t,e)=>null!=t?t:e.caseSensitive),void 0)||!1,createPanel:(null===(e=t.find((t=>t.createPanel)))||void 0===e?void 0:e.createPanel)||(t=>new Ic(t))}}});class nc{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,Uf),!0}catch(t){return!1}}(this.search)),this.unquoted=t.literal?this.search:this.search.replace(/\\([nrt\\])/g,((t,e)=>"n"==e?"\n":"r"==e?"\r":"t"==e?"\t":"\\"))}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp}create(){return this.regexp?new ac(this):new lc(this)}getCursor(t,e=0,i=t.length){return this.regexp?uc(this,t,e,i):oc(this,t,e,i)}}class hc{constructor(t){this.spec=t}}function oc(t,e,i,s){return new Af(e,t.unquoted,i,s,t.caseSensitive?void 0:t=>t.toLowerCase())}class lc extends hc{constructor(t){super(t)}nextMatch(t,e,i){let s=oc(this.spec,t,i,t.length).nextOverlapping();return s.done&&(s=oc(this.spec,t,0,e).nextOverlapping()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=i;;){let i=Math.max(e,s-1e4-this.spec.unquoted.length),r=oc(this.spec,t,i,s),n=null;for(;!r.nextOverlapping().done;)n=r.value;if(n)return n;if(i==e)return null;s-=1e4}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.length)}getReplacement(t){return this.spec.replace}matchAll(t,e){let i=oc(this.spec,t,0,t.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=oc(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function uc(t,e,i,s){return new Vf(e,t.search,t.caseSensitive?void 0:{ignoreCase:!0},i,s)}class ac extends hc{nextMatch(t,e,i){let s=uc(this.spec,t,i,t.length).next();return s.done&&(s=uc(this.spec,t,0,e).next()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=1;;s++){let r=Math.max(e,i-1e4*s),n=uc(this.spec,t,r,i),h=null;for(;!n.next().done;)h=n.value;if(h&&(r==e||h.from>r+10))return h;if(r==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.length)}getReplacement(t){return this.spec.replace.replace(/\$([$&\d+])/g,((e,i)=>"$"==i?"$":"&"==i?t.match[0]:"0"!=i&&+i=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=uc(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const fc=xe.define(),cc=xe.define(),Oc=Kt.define({create:t=>new dc(vc(t).create(),null),update(t,e){for(let i of e.effects)i.is(fc)?t=new dc(i.value.create(),t.panel):i.is(cc)&&(t=new dc(t.query,i.value?Pc:null));return t},provide:t=>eo.from(t,(t=>t.panel))});class dc{constructor(t,e){this.query=t,this.panel=e}}const $c=ds.mark({class:"cm-searchMatch"}),pc=ds.mark({class:"cm-searchMatch cm-searchMatch-selected"}),mc=Es.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Oc))}update(t){let e=t.state.field(Oc);(e!=t.startState.field(Oc)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return ds.none;let{view:i}=this,s=new je;for(let e=0,r=i.visibleRanges,n=r.length;er[e+1].from-500;)o=r[++e].to;t.highlight(i.state.doc,h,o,((t,e)=>{let r=i.state.selection.ranges.some((i=>i.from==t&&i.to==e));s.add(t,e,r?pc:$c)}))}return s.finish()}},{decorations:t=>t.decorations});function wc(t){return e=>{let i=e.state.field(Oc,!1);return i&&i.query.spec.valid?t(e,i):qc(e)}}const gc=wc(((t,{query:e})=>{let{from:i,to:s}=t.state.selection.main,r=e.nextMatch(t.state.doc,i,s);return!(!r||r.from==i&&r.to==s||(t.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:Xc(t,r),userEvent:"select.search"}),0))})),bc=wc(((t,{query:e})=>{let{state:i}=t,{from:s,to:r}=i.selection.main,n=e.prevMatch(i.doc,s,r);return!!n&&(t.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0,effects:Xc(t,n),userEvent:"select.search"}),!0)})),xc=wc(((t,{query:e})=>{let i=e.matchAll(t.state.doc,1e3);return!(!i||!i.length||(t.dispatch({selection:Vt.create(i.map((t=>Vt.range(t.from,t.to)))),userEvent:"select.search.matches"}),0))})),yc=wc(((t,{query:e})=>{let{state:i}=t,{from:s,to:r}=i.selection.main;if(i.readOnly)return!1;let n=e.nextMatch(i.doc,s,s);if(!n)return!1;let h,o,l=[],u=[];if(n.from==s&&n.to==r&&(o=i.toText(e.getReplacement(n)),l.push({from:n.from,to:n.to,insert:o}),n=e.nextMatch(i.doc,n.from,n.to),u.push(jn.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(s).number)+"."))),n){let e=0==l.length||l[0].from>=n.to?0:n.to-n.from-o.length;h={anchor:n.from-e,head:n.to-e},u.push(Xc(t,n))}return t.dispatch({changes:l,selection:h,scrollIntoView:!!h,effects:u,userEvent:"input.replace"}),!0})),Qc=wc(((t,{query:e})=>{if(t.state.readOnly)return!1;let i=e.matchAll(t.state.doc,1e9).map((t=>{let{from:i,to:s}=t;return{from:i,to:s,insert:e.getReplacement(t)}}));if(!i.length)return!1;let s=t.state.phrase("replaced $ matches",i.length)+".";return t.dispatch({changes:i,effects:jn.announce.of(s),userEvent:"input.replace.all"}),!0}));function Pc(t){return t.state.facet(rc).createPanel(t)}function vc(t,e){var i;let s=t.selection.main,r=s.empty||s.to>s.from+100?"":t.sliceDoc(s.from,s.to),n=null!==(i=null==e?void 0:e.caseSensitive)&&void 0!==i?i:t.facet(rc).caseSensitive;return e&&!r?e:new nc({search:r.replace(/\n/g,"\\n"),caseSensitive:n})}const qc=t=>{let e=t.state.field(Oc,!1);if(e&&e.panel){let i=Lh(t,Pc);if(!i)return!1;let s=i.dom.querySelector("[main-field]");if(s&&s!=t.root.activeElement){let i=vc(t.state,e.query.spec);i.valid&&t.dispatch({effects:fc.of(i)}),s.focus(),s.select()}}else t.dispatch({effects:[cc.of(!0),e?fc.of(vc(t.state,e.query.spec)):xe.appendConfig.of(Zc)]});return!0},Sc=t=>{let e=t.state.field(Oc,!1);if(!e||!e.panel)return!1;let i=Lh(t,Pc);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:cc.of(!1)}),!0},kc=[{key:"Mod-f",run:qc,scope:"editor search-panel"},{key:"F3",run:gc,shift:bc,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:gc,shift:bc,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Sc,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:t,dispatch:e})=>{let i=t.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:s,to:r}=i.main,n=[],h=0;for(let e=new Af(t.doc,t.sliceDoc(s,r));!e.next().done;){if(n.length>1e3)return!1;e.value.from==s&&(h=n.length),n.push(Vt.range(e.value.from,e.value.to))}return e(t.update({selection:Vt.create(n,h),userEvent:"select.search.matches"})),!0}},{key:"Alt-g",run:t=>{let e=Lh(t,zf);if(!e){let i=[Hf.of(!0)];null==t.state.field(Nf,!1)&&i.push(xe.appendConfig.of([Nf,Ff])),t.dispatch({effects:i}),e=Lh(t,zf)}return e&&e.dom.querySelector("input").focus(),!0}},{key:"Mod-d",run:({state:t,dispatch:e})=>{let{ranges:i}=t.selection;if(i.some((t=>t.from===t.to)))return(({state:t,dispatch:e})=>{let{selection:i}=t,s=Vt.create(i.ranges.map((e=>t.wordAt(e.head)||Vt.cursor(e.head))),i.mainIndex);return!s.eq(i)&&(e(t.update({selection:s})),!0)})({state:t,dispatch:e});let s=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some((e=>t.sliceDoc(e.from,e.to)!=s)))return!1;let r=function(t,e){let{main:i,ranges:s}=t.selection,r=t.wordAt(i.head),n=r&&r.from==i.from&&r.to==i.to;for(let i=!1,r=new Af(t.doc,e,s[s.length-1].to);;){if(r.next(),!r.done){if(i&&s.some((t=>t.from==r.value.from)))continue;if(n){let e=t.wordAt(r.value.from);if(!e||e.from!=r.value.from||e.to!=r.value.to)continue}return r.value}if(i)return null;r=new Af(t.doc,e,0,Math.max(0,s[s.length-1].from-1)),i=!0}}(t,s);return!!r&&(e(t.update({selection:t.selection.addRange(Vt.range(r.from,r.to),!1),effects:jn.scrollIntoView(r.to)})),!0)},preventDefault:!0}];class Ic{constructor(t){this.view=t;let e=this.query=t.state.field(Oc).query.spec;function i(t,e,i){return Tf("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=Tf("input",{value:e.search,placeholder:Rc(t,"Find"),"aria-label":Rc(t,"Find"),class:"cm-textfield",name:"search","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Tf("input",{value:e.replace,placeholder:Rc(t,"Replace"),"aria-label":Rc(t,"Replace"),class:"cm-textfield",name:"replace",onchange:this.commit,onkeyup:this.commit}),this.caseField=Tf("input",{type:"checkbox",name:"case",checked:e.caseSensitive,onchange:this.commit}),this.reField=Tf("input",{type:"checkbox",name:"re",checked:e.regexp,onchange:this.commit}),this.dom=Tf("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",(()=>gc(t)),[Rc(t,"next")]),i("prev",(()=>bc(t)),[Rc(t,"previous")]),i("select",(()=>xc(t)),[Rc(t,"all")]),Tf("label",null,[this.caseField,Rc(t,"match case")]),Tf("label",null,[this.reField,Rc(t,"regexp")]),...t.state.readOnly?[]:[Tf("br"),this.replaceField,i("replace",(()=>yc(t)),[Rc(t,"replace")]),i("replaceAll",(()=>Qc(t)),[Rc(t,"replace all")]),Tf("button",{name:"close",onclick:()=>Sc(t),"aria-label":Rc(t,"close"),type:"button"},["×"])]])}commit(){let t=new nc({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:fc.of(t)}))}keydown(t){var e,i,s;e=this.view,i=t,s="search-panel",Jn(Bn(e.state),i,e,s)?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?bc:gc)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),yc(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(fc)&&!t.value.eq(this.query)&&this.setQuery(t.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(rc).top}}function Rc(t,e){return t.state.phrase(e)}const Wc=30,Yc=/[\s\.,:;?!]/;function Xc(t,{from:e,to:i}){let s=t.state.doc.lineAt(e),r=t.state.doc.lineAt(i).to,n=Math.max(s.from,e-Wc),h=Math.min(r,i+Wc),o=t.state.sliceDoc(n,h);if(n!=s.from)for(let t=0;to.length-Wc;t--)if(!Yc.test(o[t-1])&&Yc.test(o[t])){o=o.slice(0,t);break}return jn.announce.of(`${t.state.phrase("current match")}. ${o} ${t.state.phrase("on line")} ${s.number}.`)}const Mc=jn.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Zc=[Oc,re.lowest(mc),Mc];class Tc{constructor(t,e,i){this.state=t,this.pos=e,this.explicit=i,this.abortListeners=[]}tokenBefore(t){let e=Ml(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),s=e.text.slice(i-e.from,this.pos-e.from),r=s.search(Uc(t,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return null==this.abortListeners}addEventListener(t,e){"abort"==t&&this.abortListeners&&this.abortListeners.push(e)}}function _c(t){let e=Object.keys(t).join(""),i=/\w/.test(e);return i&&(e=e.replace(/\w/g,"")),`[${i?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function Ec(t){let e=t.map((t=>"string"==typeof t?{label:t}:t)),[i,s]=e.every((t=>/^\w+$/.test(t.label)))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),i=Object.create(null);for(let{label:s}of t){e[s[0]]=!0;for(let t=1;t{let r=t.matchBefore(s);return r||t.explicit?{from:r?r.from:t.pos,options:e,validFor:i}:null}}class Ac{constructor(t,e,i){this.completion=t,this.source=e,this.match=i}}function jc(t){return t.selection.main.head}function Uc(t,e){var i;let{source:s}=t,r=e&&"^"!=s[0],n="$"!=s[s.length-1];return r||n?new RegExp(`${r?"^":""}(?:${s})${n?"$":""}`,null!==(i=t.flags)&&void 0!==i?i:t.ignoreCase?"i":""):t}function Vc(t,e){const i=e.completion.apply||e.completion.label;let s=e.source;var r,n,h,o;"string"==typeof i?t.dispatch((r=t.state,n=i,h=s.from,o=s.to,Object.assign(Object.assign({},r.changeByRange((t=>{if(t==r.selection.main)return{changes:{from:h,to:o,insert:n},range:Vt.cursor(h+n.length)};let e=o-h;return!t.empty||e&&r.sliceDoc(t.from-e,t.from)!=r.sliceDoc(h,o)?{range:t}:{changes:{from:t.from-e,to:t.from,insert:n},range:Vt.cursor(t.from-e+n.length)}}))),{userEvent:"input.complete"}))):i(t,e.completion,s.from,s.to)}const Cc=new WeakMap;function Gc(t){if(!Array.isArray(t))return t;let e=Cc.get(t);return e||Cc.set(t,e=Ec(t)),e}class Dc{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[];for(let e=0;e=48&&l<=57||l>=97&&l<=122?2:l>=65&&l<=90?1:0:(w=It(l))!=w.toLowerCase()?1:w!=w.toUpperCase()?2:0;(!s||1==g&&$||0==m&&0!=g)&&(e[a]==l||i[a]==l&&(f=!0)?n[a++]=s:n.length&&(p=!1)),m=g,s+=Rt(l)}return a==o&&0==n[0]&&p?this.result((f?-200:0)-100,n,t):c==o&&0==O?[-200-t.length,0,d]:h>-1?[-700-t.length,h,h+this.pattern.length]:c==o?[-900-t.length,O,d]:a==o?this.result((f?-200:0)-100-700+(p?0:-1100),n,t):2==e.length?null:this.result((s[0]?-700:0)-200-1100,s,t)}result(t,e,i){let s=[t-i.length],r=1;for(let t of e){let e=t+(this.astral?Rt(kt(i,t)):1);r>1&&s[r-1]==t?s[r-1]=e:(s[r++]=t,s[r++]=e)}return s}}const zc=Dt.define({combine:t=>Me(t,{activateOnTyping:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[]},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,optionClass:(t,e)=>i=>function(t,e){return t?e?t+" "+e:t:e}(t(i),e(i)),addToOptions:(t,e)=>t.concat(e)})});function Hc(t,e,i){if(t<=i)return{from:0,to:t};if(e<=t>>1){let t=Math.floor(e/i);return{from:t*i,to:(t+1)*i}}let s=Math.floor((t-e)/i);return{from:t-(s+1)*i,to:t-s*i}}class Nc{constructor(t,e){this.view=t,this.stateField=e,this.info=null,this.placeInfo={read:()=>this.measureInfo(),write:t=>this.positionInfo(t),key:this};let i=t.state.field(e),{options:s,selected:r}=i.open,n=t.state.facet(zc);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map((t=>"cm-completionIcon-"+t))),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,i){let s=document.createElement("span");s.className="cm-completionLabel";let{label:r}=t,n=0;for(let t=1;tn&&s.appendChild(document.createTextNode(r.slice(n,e)));let o=s.appendChild(document.createElement("span"));o.appendChild(document.createTextNode(r.slice(e,h))),o.className="cm-completionMatchedText",n=h}return nt.position-e.position)).map((t=>t.render))}(n),this.optionClass=n.optionClass,this.range=Hc(s.length,r,n.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.dom.addEventListener("mousedown",(e=>{for(let i,r=e.target;r&&r!=this.dom;r=r.parentNode)if("LI"==r.nodeName&&(i=/-(\d+)$/.exec(r.id))&&+i[1]{this.info&&this.view.requestMeasure(this.placeInfo)}))}mount(){this.updateSel()}update(t){t.state.field(this.stateField)!=t.startState.field(this.stateField)&&this.updateSel()}positioned(){this.info&&this.view.requestMeasure(this.placeInfo)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected=this.range.to)&&(this.range=Hc(e.options.length,e.selected,this.view.state.facet(zc).maxRenderedOptions),this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e.options,t.id,this.range)),this.list.addEventListener("scroll",(()=>{this.info&&this.view.requestMeasure(this.placeInfo)}))),this.updateSelectedOption(e.selected)){this.info&&(this.info.remove(),this.info=null);let{completion:i}=e.options[e.selected],{info:s}=i;if(!s)return;let r="string"==typeof s?document.createTextNode(s):s(i);if(!r)return;"then"in r?r.then((e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e)})).catch((t=>Ms(this.view.state,t,"completion info"))):this.addInfoPane(r)}}addInfoPane(t){let e=this.info=document.createElement("div");e.className="cm-tooltip cm-completionInfo",e.appendChild(t),this.dom.appendChild(e),this.view.requestMeasure(this.placeInfo)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)s==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return e&&function(t,e){let i=t.getBoundingClientRect(),s=e.getBoundingClientRect();s.topi.bottom&&(t.scrollTop+=s.bottom-i.bottom)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=t.getBoundingClientRect();if(s.top>Math.min(innerHeight,e.bottom)-10||s.bottom=this.options.length?this:new Bc(this.options,Jc(e,t),this.tooltip,this.timestamp,t)}static build(t,e,i,s,r){let n=function(t,e){let i=[],s=0;for(let r of t)if(r.hasResult())if(!1===r.result.filter){let t=r.result.getMatch;for(let e of r.result.options){let n=[1e9-s++];if(t)for(let i of t(e))n.push(i);i.push(new Ac(e,r,n))}}else{let t,s=new Dc(e.sliceDoc(r.from,r.to));for(let e of r.result.options)(t=s.match(e.label))&&(null!=e.boost&&(t[0]+=e.boost),i.push(new Ac(e,r,t)))}let r=[],n=null;for(let t of i.sort(eO))!n||n.label!=t.completion.label||n.detail!=t.completion.detail||null!=n.type&&null!=t.completion.type&&n.type!=t.completion.type||n.apply!=t.completion.apply?r.push(t):Fc(t.completion)>Fc(n)&&(r[r.length-1]=t),n=t.completion;return r}(t,e);if(!n.length)return null;let h=0;if(s&&s.selected){let t=s.options[s.selected].completion;for(let e=0;ee.hasResult()?Math.min(t,e.from):t),1e8),create:(o=uO,t=>new Nc(t,o)),above:r.aboveCursor},s?s.timestamp:Date.now(),h);var o}map(t){return new Bc(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected)}}class Lc{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new Lc(tO,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,i=e.facet(zc),s=(i.override||e.languageDataAt("autocomplete",jc(e)).map(Gc)).map((e=>{let s=this.active.find((t=>t.source==e))||new sO(e,this.active.some((t=>0!=t.state))?1:0);return s.update(t,i)}));s.length==this.active.length&&s.every(((t,e)=>t==this.active[e]))&&(s=this.active);let r=t.selection||s.some((e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to)))||!function(t,e){if(t==e)return!0;for(let i=0,s=0;;){for(;i1!=t.state))&&s.some((t=>t.hasResult()))&&(s=s.map((t=>t.hasResult()?new sO(t.source,0):t)));for(let e of t.effects)e.is(lO)&&(r=r&&r.setSelected(e.value,this.id));return s==this.active&&r==this.open?this:new Lc(s,this.id,r)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:Kc}}const Kc={"aria-autocomplete":"list"};function Jc(t,e){return{"aria-autocomplete":"list","aria-haspopup":"listbox","aria-activedescendant":t+"-"+e,"aria-controls":t}}const tO=[];function eO(t,e){let i=e.match[0]-t.match[0];return i||t.completion.label.localeCompare(e.completion.label)}function iO(t){return t.isUserEvent("input.type")?"input":t.isUserEvent("delete.backward")?"delete":null}class sO{constructor(t,e,i=-1){this.source=t,this.state=e,this.explicitPos=i}hasResult(){return!1}update(t,e){let i=iO(t),s=this;i?s=s.handleUserEvent(t,i,e):t.docChanged?s=s.handleChange(t):t.selection&&0!=s.state&&(s=new sO(s.source,0));for(let e of t.effects)if(e.is(nO))s=new sO(s.source,1,e.value?jc(t.state):-1);else if(e.is(hO))s=new sO(s.source,0);else if(e.is(oO))for(let t of e.value)t.source==s.source&&(s=t);return s}handleUserEvent(t,e,i){return"delete"!=e&&i.activateOnTyping?new sO(this.source,1):this.map(t.changes)}handleChange(t){return t.changes.touchesRange(jc(t.startState))?new sO(this.source,0):this.map(t.changes)}map(t){return t.empty||this.explicitPos<0?this:new sO(this.source,this.state,t.mapPos(this.explicitPos))}}class rO extends sO{constructor(t,e,i,s,r){super(t,2,e),this.result=i,this.from=s,this.to=r}hasResult(){return!0}handleUserEvent(t,e,i){var s;let r=t.changes.mapPos(this.from),n=t.changes.mapPos(this.to,1),h=jc(t.state);if((this.explicitPos<0?h<=r:hn||"delete"==e&&jc(t.startState)==this.from)return new sO(this.source,"input"==e&&i.activateOnTyping?1:0);let o,l=this.explicitPos<0?-1:t.changes.mapPos(this.explicitPos);return function(t,e,i,s){if(!t)return!1;let r=e.sliceDoc(i,s);return"function"==typeof t?t(r,i,s,e):Uc(t,!0).test(r)}(this.result.validFor,t.state,r,n)?new rO(this.source,l,this.result,r,n):this.result.update&&(o=this.result.update(this.result,r,n,new Tc(t.state,h,l>=0)))?new rO(this.source,l,o,o.from,null!==(s=o.to)&&void 0!==s?s:jc(t.state)):new sO(this.source,1,l)}handleChange(t){return t.changes.touchesRange(this.from,this.to)?new sO(this.source,0):this.map(t.changes)}map(t){return t.empty?this:new rO(this.source,this.explicitPos<0?-1:t.mapPos(this.explicitPos),this.result,t.mapPos(this.from),t.mapPos(this.to,1))}}const nO=xe.define(),hO=xe.define(),oO=xe.define({map:(t,e)=>t.map((t=>t.map(e)))}),lO=xe.define(),uO=Kt.define({create:()=>Lc.start(),update:(t,e)=>t.update(e),provide:t=>[Ch.from(t,(t=>t.tooltip)),jn.contentAttributes.from(t,(t=>t.attrs))]});function aO(t,e="option"){return i=>{let s=i.state.field(uO,!1);if(!s||!s.open||Date.now()-s.open.timestamp<75)return!1;let r,n=1;"page"==e&&(r=function(t,e){let i=t.plugin(jh);if(!i)return null;let s=i.manager.tooltips.indexOf(e);return s<0?null:i.manager.tooltipViews[s]}(i,s.open.tooltip))&&(n=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let h=s.open.selected+n*(t?1:-1),{length:o}=s.open.options;return h<0?h="page"==e?0:o-1:h>=o&&(h="page"==e?o-1:0),i.dispatch({effects:lO.of(h)}),!0}}class fO{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const cO=Es.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.composing=0;for(let e of t.state.field(uO).active)1==e.state&&this.startQuery(e)}update(t){let e=t.state.field(uO);if(!t.selectionSet&&!t.docChanged&&t.startState.field(uO)==e)return;let i=t.transactions.some((t=>(t.selection||t.docChanged)&&!iO(t)));for(let e=0;e50&&Date.now()-s.time>1e3){for(let t of s.context.abortListeners)try{t()}catch(t){Ms(this.view.state,t)}s.context.abortListeners=null,this.running.splice(e--,1)}else s.updates.push(...t.transactions)}if(this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),this.debounceUpdate=e.active.some((t=>1==t.state&&!this.running.some((e=>e.active.source==t.source))))?setTimeout((()=>this.startUpdate()),50):-1,0!=this.composing)for(let e of t.transactions)"input"==iO(e)?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1;let{state:t}=this.view,e=t.field(uO);for(let t of e.active)1!=t.state||this.running.some((e=>e.active.source==t.source))||this.startQuery(t)}startQuery(t){let{state:e}=this.view,i=jc(e),s=new Tc(e,i,t.explicitPos==i),r=new fO(t,s);this.running.push(r),Promise.resolve(t.source(s)).then((t=>{r.context.aborted||(r.done=t||null,this.scheduleAccept())}),(t=>{this.view.dispatch({effects:hO.of(null)}),Ms(this.view.state,t)}))}scheduleAccept(){this.running.every((t=>void 0!==t.done))?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout((()=>this.accept()),50))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],i=this.view.state.facet(zc);for(let s=0;st.source==r.active.source));if(n&&1==n.state)if(null==r.done){let t=new sO(r.active.source,0);for(let e of r.updates)t=t.update(e,i);1!=t.state&&e.push(t)}else this.startQuery(n)}e.length&&this.view.dispatch({effects:oO.of(e)})}},{eventHandlers:{blur(){let t=this.view.state.field(uO,!1);t&&t.tooltip&&this.view.state.facet(zc).closeOnBlur&&this.view.dispatch({effects:hO.of(null)})},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout((()=>this.view.dispatch({effects:nO.of(!1)})),20),this.composing=0}}}),OO=jn.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",listStyle:"none",margin:0,padding:0,"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer",padding:"1px 3px",lineHeight:1.2}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"300px"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),dO={brackets:["(","[","{","'",'"'],before:")]}:;>"},$O=xe.define({map(t,e){let i=e.mapPos(t,-1,Yt.TrackAfter);return i??void 0}}),pO=xe.define({map:(t,e)=>e.mapPos(t)}),mO=new class extends Ze{};mO.startSide=1,mO.endSide=-1;const wO=Kt.define({create:()=>Ae.empty,update(t,e){if(e.selection){let i=e.state.doc.lineAt(e.selection.main.head).from,s=e.startState.doc.lineAt(e.startState.selection.main.head).from;i!=e.changes.mapPos(s,-1)&&(t=Ae.empty)}t=t.map(e.changes);for(let i of e.effects)i.is($O)?t=t.update({add:[mO.range(i.value,i.value+1)]}):i.is(pO)&&(t=t.update({filter:t=>t!=i.value}));return t}});function gO(){return[PO,wO]}const bO="()[]{}<>";function xO(t){for(let e=0;e<8;e+=2)if(bO.charCodeAt(e)==t)return bO.charAt(e+1);return It(t<128?t:t+1)}function yO(t,e){return t.languageDataAt("closeBrackets",e)[0]||dO}const QO="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),PO=jn.inputHandler.of(((t,e,i,s)=>{if((QO?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let r=t.state.selection.main;if(s.length>2||2==s.length&&1==Rt(kt(s,0))||e!=r.from||i!=r.to)return!1;let n=function(t,e){let i=yO(t,t.selection.main.head),s=i.brackets||dO.brackets;for(let r of s){let n=xO(kt(r,0));if(e==r)return n==r?RO(t,r,s.indexOf(r+r+r)>-1):kO(t,r,n,i.before||dO.before);if(e==n&&qO(t,t.selection.main.from))return IO(t,0,n)}return null}(t.state,s);return!!n&&(t.dispatch(n),!0)})),vO=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=yO(t,t.selection.main.head).brackets||dO.brackets,s=null,r=t.changeByRange((e=>{if(e.empty){let s=function(t,e){let i=t.sliceString(e-2,e);return Rt(kt(i,0))==i.length?i:i.slice(1)}(t.doc,e.head);for(let r of i)if(r==s&&SO(t.doc,e.head)==xO(kt(r,0)))return{changes:{from:e.head-r.length,to:e.head+r.length},range:Vt.cursor(e.head-r.length),userEvent:"delete.backward"}}return{range:s=e}}));return s||e(t.update(r,{scrollIntoView:!0})),!s}}];function qO(t,e){let i=!1;return t.field(wO).between(0,t.doc.length,(t=>{t==e&&(i=!0)})),i}function SO(t,e){let i=t.sliceString(e,e+2);return i.slice(0,Rt(kt(i,0)))}function kO(t,e,i,s){let r=null,n=t.changeByRange((n=>{if(!n.empty)return{changes:[{insert:e,from:n.from},{insert:i,from:n.to}],effects:$O.of(n.to+e.length),range:Vt.range(n.anchor+e.length,n.head+e.length)};let h=SO(t.doc,n.head);return!h||/\s/.test(h)||s.indexOf(h)>-1?{changes:{insert:e+i,from:n.head},effects:$O.of(n.head+e.length),range:Vt.cursor(n.head+e.length)}:{range:r=n}}));return r?null:t.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function IO(t,e,i){let s=null,r=t.selection.ranges.map((e=>e.empty&&SO(t.doc,e.head)==i?Vt.cursor(e.head+i.length):s=e));return s?null:t.update({selection:Vt.create(r,t.selection.mainIndex),scrollIntoView:!0,effects:t.selection.ranges.map((({from:t})=>pO.of(t)))})}function RO(t,e,i){let s=null,r=t.changeByRange((r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:e,from:r.to}],effects:$O.of(r.to+e.length),range:Vt.range(r.anchor+e.length,r.head+e.length)};let n=r.head,h=SO(t.doc,n);if(h==e){if(WO(t,n))return{changes:{insert:e+e,from:n},effects:$O.of(n+e.length),range:Vt.cursor(n+e.length)};if(qO(t,n)){let s=i&&t.sliceDoc(n,n+3*e.length)==e+e+e;return{range:Vt.cursor(n+e.length*(s?3:1)),effects:pO.of(n)}}}else{if(i&&t.sliceDoc(n-2*e.length,n)==e+e&&WO(t,n-2*e.length))return{changes:{insert:e+e+e+e,from:n},effects:$O.of(n+e.length),range:Vt.cursor(n+e.length)};if(t.charCategorizer(n)(h)!=Ie.Word){let i=t.sliceDoc(n-1,n);if(i!=e&&t.charCategorizer(n)(i)!=Ie.Word&&!function(t,e,i){let s=Ml(t).resolveInner(e,-1);for(let r=0;r<5;r++){if(t.sliceDoc(s.from,s.from+i.length)==i)return!0;let r=s.to==e&&s.parent;if(!r)break;s=r}return!1}(t,n,e))return{changes:{insert:e+e,from:n},effects:$O.of(n+e.length),range:Vt.cursor(n+e.length)}}}return{range:s=r}}));return s?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function WO(t,e){let i=Ml(t).resolveInner(e+1);return i.parent&&i.from==e}function YO(t={}){return[uO,zc.of(t),cO,MO,OO]}const XO=[{key:"Ctrl-Space",run:t=>!!t.state.field(uO,!1)&&(t.dispatch({effects:nO.of(!0)}),!0)},{key:"Escape",run:t=>{let e=t.state.field(uO,!1);return!(!e||!e.active.some((t=>0!=t.state))||(t.dispatch({effects:hO.of(null)}),0))}},{key:"ArrowDown",run:aO(!0)},{key:"ArrowUp",run:aO(!1)},{key:"PageDown",run:aO(!0,"page")},{key:"PageUp",run:aO(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field(uO,!1);return!(t.state.readOnly||!e||!e.open||Date.now()-e.open.timestamp<75||(Vc(t,e.open.options[e.open.selected]),0))}}],MO=re.highest(Nn.computeN([zc],(t=>t.facet(zc).defaultKeymap?[XO]:[])));class ZO{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class TO{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let s=t,r=i.facet(BO).markerFilter;r&&(s=r(s));let n=ds.set(s.map((t=>t.from==t.to||t.from==t.to-1&&i.doc.lineAt(t.from).to==t.from?ds.widget({widget:new JO(t),diagnostic:t}).range(t.from):ds.mark({attributes:{class:"cm-lintRange cm-lintRange-"+t.severity},diagnostic:t}).range(t.from,t.to))),!0);return new TO(n,e,_O(n))}}function _O(t,e=null,i=0){let s=null;return t.between(i,1e9,((t,i,{spec:r})=>{if(!e||r.diagnostic==e)return s=new ZO(t,i,r.diagnostic),!1})),s}function EO(t,e){return!(!t.effects.some((t=>t.is(jO)))&&!t.changes.touchesRange(e.pos))}function AO(t,e){return t.field(CO,!1)?e:e.concat(xe.appendConfig.of([CO,jn.decorations.compute([CO],(t=>{let{selected:e,panel:i}=t.field(CO);return e&&i&&e.from!=e.to?ds.set([GO.range(e.from,e.to)]):ds.none})),Nh(DO,{hideOn:EO}),sd]))}const jO=xe.define(),UO=xe.define(),VO=xe.define(),CO=Kt.define({create:()=>new TO(ds.none,null,null),update(t,e){if(e.docChanged){let i=t.diagnostics.map(e.changes),s=null;if(t.selected){let r=e.changes.mapPos(t.selected.from,1);s=_O(i,t.selected.diagnostic,r)||_O(i,null,r)}t=new TO(i,t.panel,s)}for(let i of e.effects)i.is(jO)?t=TO.init(i.value,t.panel,e.state):i.is(UO)?t=new TO(t.diagnostics,i.value?ed.open:null,t.selected):i.is(VO)&&(t=new TO(t.diagnostics,t.panel,i.value));return t},provide:t=>[eo.from(t,(t=>t.panel)),jn.decorations.from(t,(t=>t.diagnostics))]}),GO=ds.mark({class:"cm-lintRange cm-lintRange-active"});function DO(t,e,i){let{diagnostics:s}=t.state.field(CO),r=[],n=2e8,h=0;s.between(e-(i<0?1:0),e+(i>0?1:0),((t,s,{spec:o})=>{e>=t&&e<=s&&(t==s||(e>t||i>0)&&(e({dom:zO(t,r)})}:null}function zO(t,e){return Tf("ul",{class:"cm-tooltip-lint"},e.map((e=>KO(t,e,!1))))}const HO=t=>{let e=t.state.field(CO,!1);return!(!e||!e.panel||(t.dispatch({effects:UO.of(!1)}),0))},NO=[{key:"Mod-Shift-m",run:t=>{let e=t.state.field(CO,!1);e&&e.panel||t.dispatch({effects:AO(t.state,[UO.of(!0)])});let i=Lh(t,ed.open);return i&&i.dom.querySelector(".cm-panel-lint ul").focus(),!0}},{key:"F8",run:t=>{let e=t.state.field(CO,!1);if(!e)return!1;let i=t.state.selection.main,s=e.diagnostics.iter(i.to+1);return!(!s.value&&(s=e.diagnostics.iter(0),!s.value||s.from==i.from&&s.to==i.to)||(t.dispatch({selection:{anchor:s.from,head:s.to},scrollIntoView:!0}),0))}}],FO=Es.fromClass(class{constructor(t){this.view=t,this.timeout=-1,this.set=!0;let{delay:e}=t.state.facet(BO);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){let t=Date.now();if(tPromise.resolve(t(this.view))))).then((e=>{let i=e.reduce(((t,e)=>t.concat(e)));this.view.state.doc==t.doc&&this.view.dispatch(function(t,e){return{effects:AO(t,[jO.of(e)])}}(this.view.state,i))}),(t=>{Ms(this.view.state,t)}))}}update(t){let e=t.state.facet(BO);(t.docChanged||e!=t.startState.facet(BO))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}}),BO=Dt.define({combine:t=>Object.assign({sources:t.map((t=>t.source))},Me(t.map((t=>t.config)),{delay:750,markerFilter:null,tooltipFilter:null})),enables:FO});function LO(t){let e=[];if(t)t:for(let{name:i}of t){for(let t=0;tt.toLowerCase()==s.toLowerCase()))){e.push(s);continue t}}e.push("")}return e}function KO(t,e,i){var s;let r=i?LO(e.actions):[];return Tf("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Tf("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage():e.message),null===(s=e.actions)||void 0===s?void 0:s.map(((i,s)=>{let n=s=>{s.preventDefault();let r=_O(t.state.field(CO).diagnostics,e);r&&i.apply(t,r.from,r.to)},{name:h}=i,o=r[s]?h.indexOf(r[s]):-1,l=o<0?h:[h.slice(0,o),Tf("u",h.slice(o,o+1)),h.slice(o+1)];return Tf("button",{type:"button",class:"cm-diagnosticAction",onclick:n,onmousedown:n,"aria-label":` Action: ${h}${o<0?"":` (access key "${r[s]})"`}.`},l)})),e.source&&Tf("div",{class:"cm-diagnosticSource"},e.source))}class JO extends cs{constructor(t){super(),this.diagnostic=t}eq(t){return t.diagnostic==this.diagnostic}toDOM(){return Tf("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class td{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=KO(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class ed{constructor(t){this.view=t,this.items=[],this.list=Tf("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(27==e.keyCode)HO(this.view),this.view.focus();else if(38==e.keyCode||33==e.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==e.keyCode||34==e.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==e.keyCode)this.moveSelection(0);else if(35==e.keyCode)this.moveSelection(this.items.length-1);else if(13==e.keyCode)this.view.focus();else{if(!(e.keyCode>=65&&e.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],s=LO(i.actions);for(let r=0;r{for(let e=0;eHO(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(CO).selected;if(!t)return-1;for(let e=0;e{let o,l=-1;for(let t=i;ti&&(this.items.splice(i,l-i),s=!0)),e&&o.diagnostic==e.diagnostic?o.dom.hasAttribute("aria-selected")||(o.dom.setAttribute("aria-selected","true"),r=o):o.dom.hasAttribute("aria-selected")&&o.dom.removeAttribute("aria-selected"),i++}));i({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:t,panel:e})=>{t.tope.bottom&&(this.list.scrollTop+=t.bottom-e.bottom)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let t=this.list.firstChild;function e(){let e=t;t=e.nextSibling,e.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=_O(this.view.state.field(CO).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:VO.of(e)})}static open(t){return new ed(t)}}function id(t){return function(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,${encodeURIComponent(t)}')`}(``,'width="6" height="3"')}const sd=jn.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:id("#d11")},".cm-lintRange-warning":{backgroundImage:id("orange")},".cm-lintRange-info":{backgroundImage:id("#999")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}}),rd=[xo(),vo(),yh(),Oa(),qu(),ih(),dh(),Xe.allowMultipleSelections.of(!0),nu(),Yu(Zu,{fallback:!0}),Gu(),gO(),YO(),Yh(),Zh(),qh(),Kf(),Nn.of([...vO,...Mf,...kc,...Ra,...gu,...XO,...NO])];class nd{constructor(t,e,i,s,r,n,h,o,l,u=0,a){this.p=t,this.stack=e,this.state=i,this.reducePos=s,this.pos=r,this.score=n,this.buffer=h,this.bufferBase=o,this.curContext=l,this.lookAhead=u,this.parent=a}toString(){return`[${this.stack.filter(((t,e)=>e%3==0)).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let s=t.parser.context;return new nd(t,[],e,i,i,0,[],0,s?new hd(s,s.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){let e=t>>19,i=65535&t,{parser:s}=this.p,r=s.dynamicPrecedence(i);if(r&&(this.score+=r),0==e)return this.pushState(s.getGoto(this.state,i,!0),this.reducePos),in;)this.stack.pop();this.reduceContext(i,h)}storeNode(t,e,i,s=4,r=!1){if(0==t&&(!this.stack.length||this.stack[this.stack.length-1]0&&0==t.buffer[s-4]&&t.buffer[s-1]>-1){if(e==i)return;if(t.buffer[s-2]>=e)return void(t.buffer[s-2]=i)}}if(r&&this.pos!=i){let r=this.buffer.length;if(r>0&&0!=this.buffer[r-4])for(;r>0&&this.buffer[r-2]>i;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,s>4&&(s-=4);this.buffer[r]=t,this.buffer[r+1]=e,this.buffer[r+2]=i,this.buffer[r+3]=s}else this.buffer.push(t,e,i,s)}shift(t,e,i){let s=this.pos;if(131072&t)this.pushState(65535&t,this.pos);else if(262144&t)this.pos=i,this.shiftContext(e,s),e<=this.p.parser.maxNode&&this.buffer.push(e,s,i,4);else{let r=t,{parser:n}=this.p;(i>this.pos||e<=n.maxNode)&&(this.pos=i,n.stateFlag(r,1)||(this.reducePos=i)),this.pushState(r,s),this.shiftContext(e,s),e<=n.maxNode&&this.buffer.push(e,s,i,4)}}apply(t,e,i){65536&t?this.reduce(t):this.shift(t,e,i)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let s=this.pos;this.reducePos=this.pos=s+t.length,this.pushState(e,s),this.buffer.push(i,s,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(;e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),s=t.bufferBase+e;for(;t&&s==t.bufferBase;)t=t.parent;return new nd(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,s,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new ld(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(!(65536&i))return!0;if(0==i)return!1;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let i=[];for(let s,r=0;r1&e&&t==s))||i.push(e[t],s)}e=i}let i=[];for(let t=0;t>19,s=65535&t,r=this.stack.length-3*i;if(r<0||e.getGoto(this.stack[r],s,!1)<0)return!1;this.storeNode(0,this.reducePos,this.reducePos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(3!=this.stack.length)return!1;let{parser:t}=this.p;return 65535==t.data[t.stateSlot(this.state,1)]&&!t.stateSlot(this.state,4)}restart(){this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;ethis.lookAhead&&(this.emitLookAhead(),this.lookAhead=t)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class hd{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}var od;!function(t){t[t.Insert=200]="Insert",t[t.Delete=190]="Delete",t[t.Reduce=100]="Reduce",t[t.MaxNext=4]="MaxNext",t[t.MaxInsertStackDepth=300]="MaxInsertStackDepth",t[t.DampenInsertStackDepth=120]="DampenInsertStackDepth"}(od||(od={}));class ld{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=65535&t,i=t>>19;0==i?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=3*(i-1);let s=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=s}}class ud{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,0==this.index&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new ud(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;null!=t&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,0==this.index&&this.maybeNext()}fork(){return new ud(this.stack,this.pos,this.index)}}class ad{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const fd=new ad;class cd{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=fd,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,s=this.rangeIndex,r=this.pos+t;for(;ri.to:r>=i.to;){if(s==this.ranges.length-1)return null;let t=this.ranges[++s];r+=t.from-i.to,i=t}return r}peek(t){let e,i,s=this.chunkOff+t;if(s>=0&&s=this.chunk2Pos&&es.to&&(this.chunk2=this.chunk2.slice(0,s.to-e)),i=this.chunk2.charCodeAt(0)}}return e>=this.token.lookAhead&&(this.token.lookAhead=e+1),i}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(null==i||i=this.chunk2Pos&&this.posthis.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=fd,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let s of this.ranges){if(s.from>=e)break;s.to>t&&(i+=this.input.read(Math.max(s.from,t),Math.min(s.to,e)))}return i}}class Od{constructor(t,e){this.data=t,this.id=e}token(t,e){!function(t,e,i,s){let r=0,n=1<0){let i=t[s];if(o.allows(i)&&(-1==e.token.value||e.token.value==i||h.overrides(i,e.token.value))){e.acceptToken(i);break}}let s=e.next,l=0,u=t[r+2];if(!(e.next<0&&u>l&&65535==t[i+3*u-3])){for(;l>1,h=i+n+(n<<1),o=t[h],a=t[h+1];if(s=a)){r=t[h+2],e.advance();continue t}l=n+1}}break}r=t[i+3*u-1]}}(this.data,t,e,this.id)}}Od.prototype.contextual=Od.prototype.fallback=Od.prototype.extend=!1;class dd{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}}function $d(t,e=Uint16Array){if("string"!=typeof t)return t;let i=null;for(let s=0,r=0;s=92&&e--,e>=34&&e--;let r=e-32;if(r>=46&&(r-=46,i=!0),n+=r,i)break;n*=46}i?i[r++]=n:i=new e(n)}return i}const pd="undefined"!=typeof process&&process.env&&/\bparse\b/.test(process.env.LOG);let md=null;var wd,gd;function bd(t,e,i){let s=t.cursor(Zo.IncludeAnonymous);for(s.moveTo(e);;)if(!(i<0?s.childBefore(e):s.childAfter(e)))for(;;){if((i<0?s.toe)&&!s.type.isError)return i<0?Math.max(0,Math.min(s.to-1,e-25)):Math.min(t.length,Math.max(s.from+1,e+25));if(i<0?s.prevSibling():s.nextSibling())break;if(!s.parent())return i<0?0:t.length}}!function(t){t[t.Margin=25]="Margin"}(wd||(wd={}));class xd{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?bd(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?bd(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(tt)return this.nextStart=n,null;if(r instanceof To){if(n==t){if(n=Math.max(this.safeFrom,t)&&(this.trees.push(r),this.start.push(n),this.index.push(0))}else this.index[e]++,this.nextStart=n+r.length}}}class yd{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map((t=>new ad))}getActions(t){let e=0,i=null,{parser:s}=t.p,{tokenizers:r}=s,n=s.stateSlot(t.state,3),h=t.curContext?t.curContext.hash:0,o=0;for(let s=0;su.end+25&&(o=Math.max(u.lookAhead,o)),0!=u.value)){let s=e;if(u.extended>-1&&(e=this.addActions(t,u.extended,u.end,e)),e=this.addActions(t,u.value,u.end,e),!l.extend&&(i=u,e>s))break}}for(;this.actions.length>e;)this.actions.pop();return o&&t.setLookAhead(o),i||t.pos!=this.stream.end||(i=new ad,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new ad,{pos:i,p:s}=t;return e.start=i,e.end=Math.min(i+1,s.stream.end),e.value=i==s.stream.end?s.parser.eofTerm:0,e}updateCachedToken(t,e,i){if(e.token(this.stream.reset(i.pos,t),i),t.value>-1){let{parser:e}=i.p;for(let s=0;s=0&&i.p.parser.dialect.allows(r>>1)){1&r?t.extended=r>>1:t.value=r>>1;break}}}else t.value=0,t.end=Math.min(i.p.stream.end,i.pos+1)}putAction(t,e,i,s){for(let e=0;e4*t.bufferLength?new xd(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t,e,i=this.stacks,s=this.minStackPos,r=this.stacks=[];for(let n=0;ns)r.push(h);else{if(this.advanceStack(h,r,i))continue;{t||(t=[],e=[]),t.push(h);let i=this.tokens.getMainToken(h);e.push(i.value,i.end)}}break}}if(!r.length){let e=t&&function(t){let e=null;for(let i of t){let t=i.p.stoppedAt;(i.pos==i.p.stream.end||null!=t&&i.pos>t)&&i.p.parser.stateFlag(i.state,2)&&(!e||e.scorethis.stoppedAt?t[0]:this.runRecovery(t,e,r);if(i)return this.stackToTree(i.forceAll())}if(this.recovering){let t=1==this.recovering?1:3*this.recovering;if(r.length>t)for(r.sort(((t,e)=>e.score-t.score));r.length>t;)r.pop();r.some((t=>t.reducePos>s))&&this.recovering--}else if(r.length>1)t:for(let t=0;t500&&s.buffer.length>500){if(!((e.score-s.score||e.buffer.length-s.buffer.length)>0)){r.splice(t--,1);continue t}r.splice(i--,1)}}}this.minStackPos=r[0].pos;for(let t=1;t ":"";if(null!=this.stoppedAt&&s>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let e=t.curContext&&t.curContext.tracker.strict,i=e?t.curContext.hash:0;for(let h=this.fragments.nodeAt(s);h;){let s=this.parser.nodeSet.types[h.type.id]==h.type?r.getGoto(t.state,h.type.id):-1;if(s>-1&&h.length&&(!e||(h.prop(Io.contextHash)||0)==i))return t.useNode(h,s),pd&&console.log(n+this.stackID(t)+` (via reuse of ${r.getName(h.type.id)})`),!0;if(!(h instanceof To)||0==h.children.length||h.positions[0]>0)break;let o=h.children[0];if(!(o instanceof To&&0==h.positions[0]))break;h=o}}let h=r.stateSlot(t.state,4);if(h>0)return t.reduce(h),pd&&console.log(n+this.stackID(t)+` (via always-reduce ${r.getName(65535&h)})`),!0;if(t.stack.length>=15e3)for(;t.stack.length>9e3&&t.forceReduce(););let o=this.tokens.getActions(t);for(let h=0;hs?e.push(c):i.push(c)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return Pd(t,e),!0}}runRecovery(t,e,i){let s=null,r=!1;for(let n=0;n ":"";if(h.deadEnd){if(r)continue;if(r=!0,h.restart(),pd&&console.log(u+this.stackID(h)+" (restarted)"),this.advanceFully(h,i))continue}let a=h.split(),f=u;for(let t=0;a.forceReduce()&&t<10&&(pd&&console.log(f+this.stackID(a)+" (via force-reduce)"),!this.advanceFully(a,i));t++)pd&&(f=this.stackID(a)+" -> ");for(let t of h.recoverByInsert(o))pd&&console.log(u+this.stackID(t)+" (via recover-insert)"),this.advanceFully(t,i);this.stream.end>h.pos?(l==h.pos&&(l++,o=0),h.recoverByDelete(o,l),pd&&console.log(u+this.stackID(h)+` (via recover-delete ${this.parser.getName(o)})`),Pd(h,i)):(!s||s.scoret;class Sd extends Jo{constructor(t){if(super(),this.wrappers=[],14!=t.version)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let i=0;it.topRules[e][1])),s=[];for(let t=0;t=0)r(s,t,e[i++]);else{let n=e[i+-s];for(let h=-s;h>0;h--)r(e[i++],t,n);i++}}}this.nodeSet=new Yo(e.map(((e,r)=>Wo.define({name:r>=this.minRepeatTerm?void 0:e,id:r,props:s[r],top:i.indexOf(r)>-1,error:0==r,skipped:t.skippedNodes&&t.skippedNodes.indexOf(r)>-1})))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=qo;let n=$d(t.tokenData);if(this.context=t.context,this.specialized=new Uint16Array(t.specialized?t.specialized.length:0),this.specializers=[],t.specialized)for(let e=0;e"number"==typeof t?new Od(n,t):t)),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let s=new Qd(this,t,e,i);for(let r of this.wrappers)s=r(s,t,e,i);return s}getGoto(t,e,i=!1){let s=this.goto;if(e>=s[0])return-1;for(let r=s[e+1];;){let e=s[r++],n=1&e,h=s[r++];if(n&&i)return h;for(let i=r+(e>>1);r0}validAction(t,e){if(e==this.stateSlot(t,4))return!0;for(let i=this.stateSlot(t,1);;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])return!1;i=kd(this.data,i+2)}if(e==kd(this.data,i+1))return!0}}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])break;i=kd(this.data,i+2)}if(!(1&this.data[i+2])){let t=this.data[i+1];e.some(((e,i)=>1&i&&e==t))||e.push(this.data[i],t)}}return e}overrides(t,e){let i=Id(this.data,this.tokenPrecTable,e);return i<0||Id(this.data,this.tokenPrecTable,t){let i=t.tokenizers.find((t=>t.from==e));return i?i.to:e}))),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),null!=t.strict&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),null!=t.bufferLength&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return null==e?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map((()=>!1));if(t)for(let s of t.split(" ")){let t=e.indexOf(s);t>=0&&(i[t]=!0)}let s=null;for(let t=0;t{if(t.next<0)t.acceptToken(167);else if(10!=t.next&&13!=t.next);else if(e.context.depth<0)t.acceptToken(165,1);else{t.advance();let e=0;for(;32==t.next||9==t.next;)t.advance(),e++;let i=10==t.next||13==t.next||35==t.next;t.acceptToken(i?166:164,-e)}}),{contextual:!0,fallback:!0}),Yd=new dd(((t,e)=>{let i=e.context.depth;if(i<0)return;let s=t.peek(-1);if((10==s||13==s)&&e.context.depth>=0){let e=0,s=0;for(;;){if(32==t.next)e++;else{if(9!=t.next)break;e+=8-e%8}t.advance(),s++}e!=i&&10!=t.next&&13!=t.next&&35!=t.next&&(e0),this.strict=!1!==t.strict}}({start:Md,reduce:(t,e)=>t.depth<0&&Rd.indexOf(e)>-1?t.parent:t,shift:(t,e,i,s)=>162==e?new Xd(t,function(t){let e=0;for(let i=0;it.hash}),Td=new dd((t=>{for(let e=0;e<5;e++){if(t.next!="print".charCodeAt(e))return;t.advance()}if(!/\w/.test(String.fromCharCode(t.next)))for(let e=0;;e++){let i=t.peek(e);if(32!=i&&9!=i)return void(40!=i&&46!=i&&10!=i&&13!=i&&35!=i&&t.acceptToken(1))}})),_d=hl({'async "*" "**" FormatConversion FormatSpec':kl.modifier,"for while if elif else try except finally return raise break continue with pass assert await yield":kl.controlKeyword,"in not and or is del":kl.operatorKeyword,"from def class global nonlocal lambda":kl.definitionKeyword,import:kl.moduleKeyword,"with as print":kl.keyword,Boolean:kl.bool,None:kl.null,VariableName:kl.variableName,"CallExpression/VariableName":kl.function(kl.variableName),"FunctionDefinition/VariableName":kl.function(kl.definition(kl.variableName)),"ClassDefinition/VariableName":kl.definition(kl.className),PropertyName:kl.propertyName,"CallExpression/MemberExpression/PropertyName":kl.function(kl.propertyName),Comment:kl.lineComment,Number:kl.number,String:kl.string,FormatString:kl.special(kl.string),UpdateOp:kl.updateOperator,ArithOp:kl.arithmeticOperator,BitOp:kl.bitwiseOperator,CompareOp:kl.compareOperator,AssignOp:kl.definitionOperator,Ellipsis:kl.punctuation,At:kl.meta,"( )":kl.paren,"[ ]":kl.squareBracket,"{ }":kl.brace,".":kl.derefOperator,", ;":kl.separator}),Ed={__proto__:null,await:40,or:50,and:52,in:56,not:58,is:60,if:66,else:68,lambda:72,yield:90,from:92,async:98,for:100,None:152,True:154,False:154,del:168,pass:172,break:176,continue:180,return:184,raise:192,import:196,as:198,global:202,nonlocal:204,assert:208,elif:218,while:222,try:228,except:230,finally:232,with:236,def:240,class:250},Ad=Sd.deserialize({version:14,states:"!?pO`Q$IXOOO%cQ$I[O'#GaOOQ$IS'#Cm'#CmOOQ$IS'#Cn'#CnO'RQ$IWO'#ClO(tQ$I[O'#G`OOQ$IS'#Ga'#GaOOQ$IS'#DS'#DSOOQ$IS'#G`'#G`O)bQ$IWO'#CsO)rQ$IWO'#DdO*SQ$IWO'#DhOOQ$IS'#Ds'#DsO*gO`O'#DsO*oOpO'#DsO*wO!bO'#DtO+SO#tO'#DtO+_O&jO'#DtO+jO,UO'#DtO-lQ$I[O'#GQOOQ$IS'#GQ'#GQO'RQ$IWO'#GPO/OQ$I[O'#GPOOQ$IS'#E]'#E]O/gQ$IWO'#E^OOQ$IS'#GO'#GOO/qQ$IWO'#F}OOQ$IV'#F}'#F}O/|Q$IWO'#FPOOQ$IS'#Fr'#FrO0RQ$IWO'#FOOOQ$IV'#H]'#H]OOQ$IV'#F|'#F|OOQ$IT'#FR'#FRQ`Q$IXOOO'RQ$IWO'#CoO0aQ$IWO'#C{O0hQ$IWO'#DPO0vQ$IWO'#GeO1WQ$I[O'#EQO'RQ$IWO'#EROOQ$IS'#ET'#ETOOQ$IS'#EV'#EVOOQ$IS'#EX'#EXO1lQ$IWO'#EZO2SQ$IWO'#E_O/|Q$IWO'#EaO2gQ$I[O'#EaO/|Q$IWO'#EdO/gQ$IWO'#EgO/gQ$IWO'#EkO/gQ$IWO'#EnO2rQ$IWO'#EpO2yQ$IWO'#EuO3UQ$IWO'#EqO/gQ$IWO'#EuO/|Q$IWO'#EwO/|Q$IWO'#E|OOQ$IS'#Cc'#CcOOQ$IS'#Cd'#CdOOQ$IS'#Ce'#CeOOQ$IS'#Cf'#CfOOQ$IS'#Cg'#CgOOQ$IS'#Ch'#ChOOQ$IS'#Cj'#CjO'RQ$IWO,58|O'RQ$IWO,58|O'RQ$IWO,58|O'RQ$IWO,58|O'RQ$IWO,58|O'RQ$IWO,58|O3ZQ$IWO'#DmOOQ$IS,5:W,5:WO3nQ$IWO'#GoOOQ$IS,5:Z,5:ZO3{Q%1`O,5:ZO4QQ$I[O,59WO0aQ$IWO,59`O0aQ$IWO,59`O0aQ$IWO,59`O6pQ$IWO,59`O6uQ$IWO,59`O6|Q$IWO,59hO7TQ$IWO'#G`O8ZQ$IWO'#G_OOQ$IS'#G_'#G_OOQ$IS'#DY'#DYO8rQ$IWO,59_O'RQ$IWO,59_O9QQ$IWO,59_O9VQ$IWO,5:PO'RQ$IWO,5:POOQ$IS,5:O,5:OO9eQ$IWO,5:OO9jQ$IWO,5:VO'RQ$IWO,5:VO'RQ$IWO,5:TOOQ$IS,5:S,5:SO9{Q$IWO,5:SO:QQ$IWO,5:UOOOO'#FZ'#FZO:VO`O,5:_OOQ$IS,5:_,5:_OOOO'#F['#F[O:_OpO,5:_O:gQ$IWO'#DuOOOO'#F]'#F]O:wO!bO,5:`OOQ$IS,5:`,5:`OOOO'#F`'#F`O;SO#tO,5:`OOOO'#Fa'#FaO;_O&jO,5:`OOOO'#Fb'#FbO;jO,UO,5:`OOQ$IS'#Fc'#FcO;uQ$I[O,5:dO>gQ$I[O,5hQ$IZO<TAN>TO#FQQ$IWO<aAN>aO/gQ$IWO1G1^O#FbQ$I[O1G1^P#FlQ$IWO'#FWOOQ$IS1G1d1G1dP#FyQ$IWO'#F^O#GWQ$IWO7+(mOOOO-E9]-E9]O#GnQ$IWO7+'qOOQ$ISAN?VAN?VO#HXQ$IWO,5UZ%q7[%kW%y#tOr(}rs)}sw(}wx>wx#O(}#O#P2]#P#o(}#o#p:X#p#q(}#q#r2q#r~(}:Y?QX%q7[%kW%y#tOr>wrs?ms#O>w#O#PAP#P#o>w#o#p8Y#p#q>w#q#r6g#r~>w:Y?rX%q7[Or>wrs@_s#O>w#O#PAP#P#o>w#o#p8Y#p#q>w#q#r6g#r~>w:Y@dX%q7[Or>wrs-}s#O>w#O#PAP#P#o>w#o#p8Y#p#q>w#q#r6g#r~>w:YAUT%q7[O#o>w#o#p6g#p#q>w#q#r6g#r~>w`x#O!`x#O!gZ%kW%f,XOY!wZ]!Ad]^>w^r!Adrs!Bhs#O!Ad#O#P!C[#P#o!Ad#o#p!9f#p#q!Ad#q#r!7x#r~!AdEc!BoX%q7[%f,XOr>wrs@_s#O>w#O#PAP#P#o>w#o#p8Y#p#q>w#q#r6g#r~>wEc!CaT%q7[O#o!Ad#o#p!7x#p#q!Ad#q#r!7x#r~!AdGZ!CuT%q7[O#o!-l#o#p!DU#p#q!-l#q#r!DU#r~!-l0}!De]%hS%kW%f,X%n`%w!b%y#tOY!DUYZAyZ]!DU]^Ay^r!DUrs!E^sw!DUwx!5tx#O!DU#O#P!FU#P#o!DU#o#p!F[#p~!DU0}!EiX%hS%f,X%n`%w!bOrAyrsCiswAywx5Px#OAy#O#PEo#P#oAy#o#pEu#p~Ay0}!FXPO~!DU0}!Fe]%hS%kW%f,XOY!`x#O!`sw#=dwx#@Sx#O#=d#O#P#Av#P#o#=d#o#p#0Y#p~#=d2P#=mZQ1s%hS%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@Sx#O#=d#O#P#Av#P~#=d2P#>gZQ1s%hSOY#=dYZ:{Z]#=d]^:{^r#=drs#?Ysw#=dwx#@Sx#O#=d#O#P#Av#P~#=d2P#?aZQ1s%hSOY#=dYZ:{Z]#=d]^:{^r#=drs#,zsw#=dwx#@Sx#O#=d#O#P#Av#P~#=d2P#@ZZQ1s%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@|x#O#=d#O#P#Av#P~#=d2P#ATZQ1s%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#9bx#O#=d#O#P#Av#P~#=d2P#A{TQ1sOY#=dYZ:{Z]#=d]^:{^~#=dLe#Bg_Q1s%q7[%kW%y#tOY!NdYZ(}Z]!Nd]^(}^r!Ndrs# rsw!Ndwx#Cfx#O!Nd#O#P#/f#P#o!Nd#o#p#wZ]#Cf]^>w^r#Cfrs#Djs#O#Cf#O#P#Fj#P#o#Cf#o#p#8h#p#q#Cf#q#r#5h#r~#CfJ}#Dq]Q1s%q7[OY#CfYZ>wZ]#Cf]^>w^r#Cfrs#Ejs#O#Cf#O#P#Fj#P#o#Cf#o#p#8h#p#q#Cf#q#r#5h#r~#CfJ}#Eq]Q1s%q7[OY#CfYZ>wZ]#Cf]^>w^r#Cfrs#'[s#O#Cf#O#P#Fj#P#o#Cf#o#p#8h#p#q#Cf#q#r#5h#r~#CfJ}#FqXQ1s%q7[OY#CfYZ>wZ]#Cf]^>w^#o#Cf#o#p#5h#p#q#Cf#q#r#5h#r~#CfLu#GeXQ1s%q7[OY!KxYZ'PZ]!Kx]^'P^#o!Kx#o#p#HQ#p#q!Kx#q#r#HQ#r~!Kx6i#Ha]Q1s%hS%kW%n`%w!b%y#tOY#HQYZAyZ]#HQ]^Ay^r#HQrs#IYsw#HQwx#3dx#O#HQ#O#P#Mn#P#o#HQ#o#p#NS#p~#HQ6i#Ie]Q1s%hS%n`%w!bOY#HQYZAyZ]#HQ]^Ay^r#HQrs#J^sw#HQwx#3dx#O#HQ#O#P#Mn#P#o#HQ#o#p#NS#p~#HQ6i#Ji]Q1s%hS%n`%w!bOY#HQYZAyZ]#HQ]^Ay^r#HQrs#Kbsw#HQwx#3dx#O#HQ#O#P#Mn#P#o#HQ#o#p#NS#p~#HQ3k#KmZQ1s%hS%n`%w!bOY#KbYZD_Z]#Kb]^D_^w#Kbwx#)|x#O#Kb#O#P#L`#P#o#Kb#o#p#Lt#p~#Kb3k#LeTQ1sOY#KbYZD_Z]#Kb]^D_^~#Kb3k#L{ZQ1s%hSOY#,zYZ1OZ]#,z]^1O^w#,zwx#-nx#O#,z#O#P#/Q#P#o#,z#o#p#Kb#p~#,z6i#MsTQ1sOY#HQYZAyZ]#HQ]^Ay^~#HQ6i#N]]Q1s%hS%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@Sx#O#=d#O#P#Av#P#o#=d#o#p#HQ#p~#=dLu$ c_Q1s%q7[%hS%n`%w!bOY!KxYZ'PZ]!Kx]^'P^r!Kxrs$!bsw!Kxwx!MYx#O!Kx#O#P#G^#P#o!Kx#o#p#NS#p#q!Kx#q#r#HQ#r~!KxIw$!o]Q1s%q7[%hS%n`%w!bOY$!bYZGgZ]$!b]^Gg^w$!bwx#%[x#O$!b#O#P$#h#P#o$!b#o#p#Lt#p#q$!b#q#r#Kb#r~$!bIw$#oXQ1s%q7[OY$!bYZGgZ]$!b]^Gg^#o$!b#o#p#Kb#p#q$!b#q#r#Kb#r~$!bMV$$i_Q1s%q7[%kW%tp%y#tOY$%hYZIqZ]$%h]^Iq^r$%hrs# rsw$%hwx$.px#O$%h#O#P$&x#P#o$%h#o#p$-n#p#q$%h#q#r$'l#r~$%hMV$%y_Q1s%q7[%hS%kW%tp%w!b%y#tOY$%hYZIqZ]$%h]^Iq^r$%hrs# rsw$%hwx$$[x#O$%h#O#P$&x#P#o$%h#o#p$-n#p#q$%h#q#r$'l#r~$%hMV$'PXQ1s%q7[OY$%hYZIqZ]$%h]^Iq^#o$%h#o#p$'l#p#q$%h#q#r$'l#r~$%h6y$'{]Q1s%hS%kW%tp%w!b%y#tOY$'lYZKXZ]$'l]^KX^r$'lrs#1`sw$'lwx$(tx#O$'l#O#P$-Y#P#o$'l#o#p$-n#p~$'l6y$)P]Q1s%kW%tp%y#tOY$'lYZKXZ]$'l]^KX^r$'lrs#1`sw$'lwx$)xx#O$'l#O#P$-Y#P#o$'l#o#p$-n#p~$'l6y$*T]Q1s%kW%tp%y#tOY$'lYZKXZ]$'l]^KX^r$'lrs#1`sw$'lwx$*|x#O$'l#O#P$-Y#P#o$'l#o#p$-n#p~$'l5c$+XZQ1s%kW%tp%y#tOY$*|YZMmZ]$*|]^Mm^r$*|rs#6ds#O$*|#O#P$+z#P#o$*|#o#p$,`#p~$*|5c$,PTQ1sOY$*|YZMmZ]$*|]^Mm^~$*|5c$,gZQ1s%kWOY#9bYZ8tZ]#9b]^8t^r#9brs#:Us#O#9b#O#P#;h#P#o#9b#o#p$*|#p~#9b6y$-_TQ1sOY$'lYZKXZ]$'l]^KX^~$'l6y$-w]Q1s%hS%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@Sx#O#=d#O#P#Av#P#o#=d#o#p$'l#p~#=dMV$.}_Q1s%q7[%kW%tp%y#tOY$%hYZIqZ]$%h]^Iq^r$%hrs# rsw$%hwx$/|x#O$%h#O#P$&x#P#o$%h#o#p$-n#p#q$%h#q#r$'l#r~$%hKo$0Z]Q1s%q7[%kW%tp%y#tOY$/|YZ!!uZ]$/|]^!!u^r$/|rs#Djs#O$/|#O#P$1S#P#o$/|#o#p$,`#p#q$/|#q#r$*|#r~$/|Ko$1ZXQ1s%q7[OY$/|YZ!!uZ]$/|]^!!u^#o$/|#o#p$*|#p#q$/|#q#r$*|#r~$/|Mg$1}XQ1s%q7[OY!IYYZ$}Z]!IY]^$}^#o!IY#o#p$2j#p#q!IY#q#r$2j#r~!IY7Z$2{]Q1s%hS%kW%n`%tp%w!b%y#tOY$2jYZ!$gZ]$2j]^!$g^r$2jrs#IYsw$2jwx$(tx#O$2j#O#P$3t#P#o$2j#o#p$4Y#p~$2j7Z$3yTQ1sOY$2jYZ!$gZ]$2j]^!$g^~$2j7Z$4c]Q1s%hS%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@Sx#O#=d#O#P#Av#P#o#=d#o#p$2j#p~#=dGz$5o]$}Q%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!_$}!_!`$6h!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gz$6{Z!s,W%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gz$8R]$wQ%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!_$}!_!`$6h!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}G{$9Z_%r`%q7[%kW%f,X%tp%y#tOY$:YYZIqZ]$:Y]^Iq^r$:Yrs$;jsw$:Ywx%%zx#O$:Y#O#P%!^#P#o$:Y#o#p%$x#p#q$:Y#q#r%!r#r~$:YGk$:k_%q7[%hS%kW%f,X%tp%w!b%y#tOY$:YYZIqZ]$:Y]^Iq^r$:Yrs$;jsw$:Ywx% ^x#O$:Y#O#P%!^#P#o$:Y#o#p%$x#p#q$:Y#q#r%!r#r~$:YFy$;u_%q7[%hS%f,X%w!bOY$Sx#O$Sx#O$_Z%q7[%kW%f,X%y#tOr(}rs)}sw(}wx={x#O(}#O#P2]#P#o(}#o#p:X#p#q(}#q#r2q#r~(}Fy$?VT%q7[O#o$Sx#O$T!Q!_$}!_!`$6h!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gz%>h]%OQ%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!_$}!_!`$6h!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%?tu!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!O$}!O!P%BX!P!Q$}!Q![%Cc![!d$}!d!e%Ee!e!g$}!g!h%7Z!h!l$}!l!m%;k!m!q$}!q!r%H_!r!z$}!z!{%KR!{#O$}#O#P!$R#P#R$}#R#S%Cc#S#U$}#U#V%Ee#V#X$}#X#Y%7Z#Y#^$}#^#_%;k#_#c$}#c#d%H_#d#l$}#l#m%KR#m#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Bj]%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q![%5_![#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Cvi!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!O$}!O!P%BX!P!Q$}!Q![%Cc![!g$}!g!h%7Z!h!l$}!l!m%;k!m#O$}#O#P!$R#P#R$}#R#S%Cc#S#X$}#X#Y%7Z#Y#^$}#^#_%;k#_#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Ev`%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q!R%Fx!R!S%Fx!S#O$}#O#P!$R#P#R$}#R#S%Fx#S#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%G]`!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q!R%Fx!R!S%Fx!S#O$}#O#P!$R#P#R$}#R#S%Fx#S#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Hp_%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q!Y%Io!Y#O$}#O#P!$R#P#R$}#R#S%Io#S#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%JS_!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q!Y%Io!Y#O$}#O#P!$R#P#R$}#R#S%Io#S#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Kdc%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q![%Lo![!c$}!c!i%Lo!i#O$}#O#P!$R#P#R$}#R#S%Lo#S#T$}#T#Z%Lo#Z#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%MSc!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q![%Lo![!c$}!c!i%Lo!i#O$}#O#P!$R#P#R$}#R#S%Lo#S#T$}#T#Z%Lo#Z#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Mg%Nr]y1s%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!_$}!_!`& k!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}x!u!}&+n!}#O$}#O#P!$R#P#R$}#R#S&+n#S#T$}#T#f&+n#f#g&>x#g#o&+n#o#p!%i#p#q$}#q#r!$g#r$g$}$g~&+nGZ&9gZ%q7[%hS%n`%w!b%s,XOr'Prs&:Ysw'Pwx(Rx#O'P#O#PAe#P#o'P#o#pEu#p#q'P#q#rAy#r~'PGZ&:eZ%q7[%hS%n`%w!bOr'Prs&;Wsw'Pwx(Rx#O'P#O#PAe#P#o'P#o#pEu#p#q'P#q#rAy#r~'PD]&;eX%q7[%hS%x,X%n`%w!bOwGgwx,kx#OGg#O#PH_#P#oGg#o#pET#p#qGg#q#rD_#r~GgGk&<_Z%q7[%kW%tp%y#t%m,XOrIqrs)}swIqwx&=Qx#OIq#O#PJs#P#oIq#o#p! T#p#qIq#q#rKX#r~IqGk&=]Z%q7[%kW%tp%y#tOrIqrs)}swIqwx&>Ox#OIq#O#PJs#P#oIq#o#p! T#p#qIq#q#rKX#r~IqFT&>]X%q7[%kW%v,X%tp%y#tOr!!urs?ms#O!!u#O#P!#m#P#o!!u#o#pNc#p#q!!u#q#rMm#r~!!uMg&?_c%q7[%hS%kW%e&j%n`%tp%w!b%y#t%Q,XOr$}rs&9Ysw$}wx&x!i!t&+n!t!u&5j!u!}&+n!}#O$}#O#P!$R#P#R$}#R#S&+n#S#T$}#T#U&+n#U#V&5j#V#Y&+n#Y#Z&>x#Z#o&+n#o#p!%i#p#q$}#q#r!$g#r$g$}$g~&+nG{&CXZ!V,X%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Ed[t]||-1}],tokenPrec:6584});function jd(t,e){let i=t.lineIndent(e.from),s=t.lineAt(t.pos,-1),r=s.from+s.text.length;return!/\S/.test(s.text)&&t.node.toi?null:i+t.unit}const Ud=Xl.define({parser:Ad.configure({props:[Ll.add({Body:t=>{var e;return null!==(e=jd(t,t.node))&&void 0!==e?e:t.continue()},IfStatement:t=>/^\s*(else:|elif )/.test(t.textAfter)?t.baseIndent:t.continue(),TryStatement:t=>/^\s*(except |finally:)/.test(t.textAfter)?t.baseIndent:t.continue(),"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression":su({closing:")"}),"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression":su({closing:"}"}),"ArrayExpression ArrayComprehensionExpression":su({closing:"]"}),Script:t=>{if(t.pos+/\s*/.exec(t.textAfter)[0].length>=t.node.to){let e=null;for(let i=t.node,s=i.to;i=i.lastChild,i&&i.to==s;)"Body"==i.type.name&&(e=i);if(e){let i=jd(t,e);if(null!=i)return i}}return t.continue()}}),ou.add({"ArrayExpression DictionaryExpression SetExpression TupleExpression":function(t){let e=t.firstChild,i=t.lastChild;return e&&e.to({from:t.from+1,to:t.to-(t.to==e.doc.length?0:1)})})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"'''",'"""']},commentTokens:{line:"#"},indentOnInput:/^\s*([\}\]\)]|else:|elif |except |finally:)$/}});function Vd(){return new Gl(Ud)}function Cd(t,e){let i,s=-1,r=-1;const n=t.split("\n");for(var h=n.length-1;h>=0;h--){let t=n[h];if(t.startsWith("SyntaxError")||t.startsWith("IndentationError"))r=h;else if(t.includes('File "", line')){i=parseInt(t.split(", line ")[1],10),i-=e-1,s=h;break}}return-1==s||-1==r?"No error report found.":`Error at line ${i}:\n`+n.slice(s+1,r+1).join("\n")}var Gd=null;try{var Dd="undefined"!=typeof module&&"function"==typeof module.require&&module.require("worker_threads")||"function"==typeof __non_webpack_require__&&__non_webpack_require__("worker_threads")||"function"==typeof require&&require("worker_threads");Gd=Dd.Worker}catch(t){}function zd(t,e,i){var s=void 0===e?null:e,r=function(t,e){return Buffer.from(t,"base64").toString(e?"utf16":"utf8")}(t,void 0!==i&&i),n=r.indexOf("\n",10)+1,h=r.substring(n)+(s?"//# sourceMappingURL="+s:"");return function(t){return new Gd(h,Object.assign({},t,{eval:!0}))}}function Hd(t,e,i){var s=void 0===e?null:e,r=function(t,e){var i=atob(t);if(e){for(var s=new Uint8Array(i.length),r=0,n=i.length;r{window.setTimeout(this.finishIt.bind(this),5e3),this.worker.postMessage(t),this.resolve=e}))}finishIt(){this.gotCalledBack||(this.worker.terminate(),this.resolve({error:{message:"Infinite loop"}}))}handleMessage(t){t.data.stdout?this.stdout.push(t.data.stdout):(this.gotCalledBack=!0,this.resolve({error:t?.data?.error,results:t?.data?.results,stdout:this.stdout.join("\n")}))}}const Kd={};function Jd(){try{return"localStorage"in window&&null!==window.localStorage}catch(t){return!1}}function t$(t,e){Jd()?localStorage.setItem(t,e):Kd[t]=e}class e$ extends L{static styles=n` + */class lt{}const ut=new WeakMap,at=(t=>(...e)=>({_$litDirective$:t,values:e}))(class extends ot{render(t){return M}update(t,[e]){var i;const s=e!==this.U;return s&&void 0!==this.U&&this.ot(void 0),(s||this.rt!==this.lt)&&(this.U=e,this.ht=null===(i=t.options)||void 0===i?void 0:i.host,this.ot(this.lt=t.element)),M}ot(t){var e;if("function"==typeof this.U){const i=null!==(e=this.ht)&&void 0!==e?e:globalThis;let s=ut.get(i);void 0===s&&(s=new WeakMap,ut.set(i,s)),void 0!==s.get(this.U)&&this.U.call(this.ht,void 0),s.set(this.U,t),void 0!==t&&this.U.call(this.ht,t)}else this.U.value=t}get rt(){var t,e,i;return"function"==typeof this.U?null===(e=ut.get(null!==(t=this.ht)&&void 0!==t?t:globalThis))||void 0===e?void 0:e.get(this.U):null===(i=this.U)||void 0===i?void 0:i.value}disconnected(){this.rt===this.lt&&this.ot(void 0)}reconnected(){this.ot(this.lt)}});class ft{constructor(){}lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){let s=[];return this.decompose(0,t,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(e,this.length,s,1),Ot.from(s,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){let i=[];return this.decompose(t,e,i,0),Ot.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),s=new pt(this),r=new pt(t);for(let t=e,n=e;;){if(s.next(t),r.next(t),t=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(n+=s.value.length,s.done||n>=i)return!0}}iter(t=1){return new pt(this,t)}iterRange(t,e=this.length){return new mt(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let s=this.line(t).from;i=this.iterRange(s,Math.max(s,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new wt(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}static of(t){if(0==t.length)throw new RangeError("A document must have at least one line");return 1!=t.length||t[0]?t.length<=32?new ct(t):Ot.from(ct.split(t,[])):ft.empty}}class ct extends ft{constructor(t,e=function(t){let e=-1;for(let i of t)e+=i.length+1;return e}(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,s){for(let r=0;;r++){let n=this.text[r],h=s+n.length;if((e?i:h)>=t)return new gt(s,h,i,n);s=h+1,i++}}decompose(t,e,i,s){let r=t<=0&&e>=this.length?this:new ct($t(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(1&s){let t=i.pop(),e=dt(r.text,t.text.slice(),0,r.length);if(e.length<=32)i.push(new ct(e,t.length+r.length));else{let t=e.length>>1;i.push(new ct(e.slice(0,t)),new ct(e.slice(t)))}}else i.push(r)}replace(t,e,i){if(!(i instanceof ct))return super.replace(t,e,i);let s=dt(this.text,dt(i.text,$t(this.text,0,t)),e),r=this.length+i.length-(e-t);return s.length<=32?new ct(s,r):Ot.from(ct.split(s,[]),r)}sliceString(t,e=this.length,i="\n"){let s="";for(let r=0,n=0;r<=e&&nt&&n&&(s+=i),tr&&(s+=h.slice(Math.max(0,t-r),e-r)),r=o+1}return s}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],s=-1;for(let r of t)i.push(r),s+=r.length+1,32==i.length&&(e.push(new ct(i,s)),i=[],s=-1);return s>-1&&e.push(new ct(i,s)),e}}class Ot extends ft{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let e of t)this.lines+=e.lines}lineInner(t,e,i,s){for(let r=0;;r++){let n=this.children[r],h=s+n.length,o=i+n.lines-1;if((e?o:h)>=t)return n.lineInner(t,e,i,s);s=h+1,i=o+1}}decompose(t,e,i,s){for(let r=0,n=0;n<=e&&r=n){let r=s&((n<=t?1:0)|(o>=e?2:0));n>=t&&o<=e&&!r?i.push(h):h.decompose(t-n,e-n,i,r)}n=o+1}}replace(t,e,i){if(i.lines=r&&e<=h){let o=n.replace(t-r,e-r,i),l=this.lines-n.lines+o.lines;if(o.lines>4&&o.lines>l>>6){let r=this.children.slice();return r[s]=o,new Ot(r,this.length-(e-t)+i.length)}return super.replace(r,h,o)}r=h+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i="\n"){let s="";for(let r=0,n=0;rt&&r&&(s+=i),tn&&(s+=h.sliceString(t-n,e-n,i)),n=o+1}return s}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof Ot))return 0;let i=0,[s,r,n,h]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;s+=e,r+=e){if(s==n||r==h)return i;let o=this.children[s],l=t.children[r];if(o!=l)return i+o.scanIdentical(l,e);i+=o.length+1}}static from(t,e=t.reduce(((t,e)=>t+e.length+1),-1)){let i=0;for(let e of t)i+=e.lines;if(i<32){let i=[];for(let e of t)e.flatten(i);return new ct(i,e)}let s=Math.max(32,i>>5),r=s<<1,n=s>>1,h=[],o=0,l=-1,u=[];function a(t){let e;if(t.lines>r&&t instanceof Ot)for(let e of t.children)a(e);else t.lines>n&&(o>n||!o)?(f(),h.push(t)):t instanceof ct&&o&&(e=u[u.length-1])instanceof ct&&t.lines+e.lines<=32?(o+=t.lines,l+=t.length+1,u[u.length-1]=new ct(e.text.concat(t.text),e.length+1+t.length)):(o+t.lines>s&&f(),o+=t.lines,l+=t.length+1,u.push(t))}function f(){0!=o&&(h.push(1==u.length?u[0]:Ot.from(u,l)),l=-1,o=u.length=0)}for(let e of t)a(e);return f(),1==h.length?h[0]:new Ot(h,e)}}function dt(t,e,i=0,s=1e9){for(let r=0,n=0,h=!0;n=i&&(l>s&&(o=o.slice(0,s-r)),r0?1:(t instanceof ct?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],n=r>>1,h=s instanceof ct?s.text.length:s.children.length;if(n==(e>0?h:0)){if(0==i)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&r)==(e>0?0:1)){if(this.offsets[i]+=e,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(s instanceof ct){let r=s.text[n+(e<0?-1:0)];if(this.offsets[i]+=e,r.length>Math.max(0,t))return this.value=0==t?r:e>0?r.slice(t):r.slice(0,r.length-t),this;t-=r.length}else{let r=s.children[n+(e<0?-1:0)];t>r.length?(t-=r.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(r),this.offsets.push(e>0?1:(r instanceof ct?r.text.length:r.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class mt{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new pt(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:s}=this.cursor.next(t);return this.pos+=(s.length+t)*e,this.value=s.length<=i?s:e<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class wt{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:s}=this.inner.next(t);return e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(ft.prototype[Symbol.iterator]=function(){return this.iter()},pt.prototype[Symbol.iterator]=mt.prototype[Symbol.iterator]=wt.prototype[Symbol.iterator]=function(){return this});class gt{constructor(t,e,i,s){this.from=t,this.to=e,this.number=i,this.text=s}get length(){return this.to-this.from}}let xt="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map((t=>t?parseInt(t,36):1));for(let t=1;tt)return xt[e-1]<=t;return!1}function yt(t){return t>=127462&&t<=127487}function Qt(t,e,i=!0,s=!0){return(i?Pt:vt)(t,e,s)}function Pt(t,e,i){if(e==t.length)return e;e&&qt(t.charCodeAt(e))&&St(t.charCodeAt(e-1))&&e--;let s=kt(t,e);for(e+=Rt(s);e=0&&yt(kt(t,s));)i++,s-=2;if(i%2==0)break;e+=2}}}return e}function vt(t,e,i){for(;e>0;){let s=Pt(t,e-2,i);if(s=56320&&t<57344}function St(t){return t>=55296&&t<56320}function kt(t,e){let i=t.charCodeAt(e);if(!St(i)||e+1==t.length)return i;let s=t.charCodeAt(e+1);return qt(s)?s-56320+(i-55296<<10)+65536:i}function It(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function Rt(t){return t<65536?1:2}const Wt=/\r\n?|\n/;var Yt=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(Yt||(Yt={}));class Xt{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return r+(t-s);r+=h}else{if(i!=Yt.Simple&&l>=t&&(i==Yt.TrackDel&&st||i==Yt.TrackBefore&&st))return null;if(l>t||l==t&&e<0&&!h)return t==s||e<0?r:r+o;r+=o}s=l}if(t>s)throw new RangeError(`Position ${t} is out of range for changeset of length ${s}`);return r}touchesRange(t,e=t){for(let i=0,s=0;i=0&&s<=e&&r>=t)return!(se)||"cover";s=r}return!1}toString(){let t="";for(let e=0;e=0?":"+s:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some((t=>"number"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Xt(t)}static create(t){return new Xt(t)}}class Mt extends Xt{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return _t(this,((e,i,s,r,n)=>t=t.replace(s,s+(i-e),n)),!1),t}mapDesc(t,e=!1){return Et(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let s=0,r=0;s=0){e[s]=h,e[s+1]=n;let o=s>>1;for(;i.length0&&Tt(i,e,r.text),r.forward(t),h+=t}let l=t[n++];for(;h>1].toJSON()))}return t}static of(t,e,i){let s=[],r=[],n=0,h=null;function o(t=!1){if(!t&&!s.length)return;nh||t<0||h>e)throw new RangeError(`Invalid change range ${t} to ${h} (in doc of length ${e})`);let a=u?"string"==typeof u?ft.of(u.split(i||Wt)):u:ft.empty,f=a.length;if(t==h&&0==f)return;tn&&Zt(s,t-n,-1),Zt(s,h-t,f),Tt(r,s,a),n=h}}(t),o(!h),h}static empty(t){return new Mt(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let s=0;se&&"string"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==r.length)e.push(r[0],0);else{for(;i.length=0&&i<=0&&i==t[r+1]?t[r]+=e:0==e&&0==t[r]?t[r+1]+=i:s?(t[r]+=e,t[r+1]+=i):t.push(e,i)}function Tt(t,e,i){if(0==i.length)return;let s=e.length-2>>1;if(s>1])),!(i||h==t.sections.length||t.sections[h+1]<0);)o=t.sections[h++],l=t.sections[h++];e(r,u,n,a,f),r=u,n=a}}}function Et(t,e,i,s=!1){let r=[],n=s?[]:null,h=new jt(t),o=new jt(e);for(let t=0,e=0;;)if(-1==h.ins)t+=h.len,h.next();else if(-1==o.ins&&e=0&&(h.done||ee&&!h.done&&t+h.len=0)){if(h.done&&o.done)return n?Mt.createSet(r,n):Xt.create(r);throw new Error("Mismatched change set lengths")}{let i=0,s=t+h.len;for(;;)if(o.ins>=0&&e>t&&e+o.lene||h.ins>=0&&h.len>e)&&(t||s.length>i),n.forward2(e),h.forward(e)}}else Zt(s,0,h.ins,t),r&&Tt(r,s,h.text),h.next()}}class jt{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return e>=t.length?ft.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?ft.empty:e[i].slice(this.off,null==t?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){-1==this.ins?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class Ut{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return 16&this.flags?this.to:this.from}get head(){return 16&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 4&this.flags?-1:8&this.flags?1:0}get bidiLevel(){let t=3&this.flags;return 3==t?null:t}get goalColumn(){let t=this.flags>>5;return 33554431==t?void 0:t}map(t,e=-1){let i,s;return this.empty?i=s=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),s=t.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new Ut(i,s,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return Gt.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return Gt.range(this.anchor,i)}eq(t){return this.anchor==t.anchor&&this.head==t.head}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||"number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid JSON representation for SelectionRange");return Gt.range(t.anchor,t.head)}static create(t,e,i){return new Ut(t,e,i)}}class Gt{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:Gt.create(this.ranges.map((i=>i.map(t,e))),this.mainIndex)}eq(t){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let e=0;et.toJSON())),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||"number"!=typeof t.main||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new Gt(t.ranges.map((t=>Ut.fromJSON(t))),t.main)}static single(t,e=t){return new Gt([Gt.range(t,e)],0)}static create(t,e=0){if(0==t.length)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;st?4:0))}static normalized(t,e=0){let i=t[e];t.sort(((t,e)=>t.from-e.from)),e=t.indexOf(i);for(let i=1;is.head?Gt.range(h,n):Gt.range(n,h))}}return new Gt(t,e)}}function Vt(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let Ct=0;class Dt{constructor(t,e,i,s,r){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=s,this.extensions=r,this.id=Ct++,this.default=t([])}static define(t={}){return new Dt(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:zt),!!t.static,t.enables)}of(t){return new Ht([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ht(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ht(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],(i=>e(i.field(t))))}}function zt(t,e){return t==e||t.length==e.length&&t.every(((t,i)=>t===e[i]))}class Ht{constructor(t,e,i,s){this.dependencies=t,this.facet=e,this.type=i,this.value=s,this.id=Ct++}dynamicSlot(t){var e;let i=this.value,s=this.facet.compareInput,r=this.id,n=t[r]>>1,h=2==this.type,o=!1,l=!1,u=[];for(let i of this.dependencies)"doc"==i?o=!0:"selection"==i?l=!0:1&(null!==(e=t[i.id])&&void 0!==e?e:1)||u.push(t[i.id]);return{create:t=>(t.values[n]=i(t),1),update(t,e){if(o&&e.docChanged||l&&(e.docChanged||e.selection)||Ft(t,u)){let e=i(t);if(h?!Nt(e,t.values[n],s):!s(e,t.values[n]))return t.values[n]=e,1}return 0},reconfigure:(t,e)=>{let o=i(t),l=e.config.address[r];if(null!=l){let i=ae(e,l);if(this.dependencies.every((i=>i instanceof Dt?e.facet(i)===t.facet(i):!(i instanceof Kt)||e.field(i,!1)==t.field(i,!1)))||(h?Nt(o,i,s):s(o,i)))return t.values[n]=i,0}return t.values[n]=o,1}}}}function Nt(t,e,i){if(t.length!=e.length)return!1;for(let s=0;st[e.id])),r=i.map((t=>t.type)),n=s.filter((t=>!(1&t))),h=t[e.id]>>1;function o(t){let i=[];for(let e=0;et===e),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(Lt).find((t=>t.field==this));return((null==e?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:t=>(t.values[e]=this.create(t),1),update:(t,i)=>{let s=t.values[e],r=this.updateF(s,i);return this.compareF(s,r)?0:(t.values[e]=r,1)},reconfigure:(t,i)=>null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}init(t){return[this,Lt.of({field:this,create:t})]}get extension(){return this}}const Jt=4,te=3,ee=2,ie=1;function se(t){return e=>new ne(e,t)}const re={highest:se(0),high:se(ie),default:se(ee),low:se(te),lowest:se(Jt)};class ne{constructor(t,e){this.inner=t,this.prec=e}}class he{of(t){return new oe(this,t)}reconfigure(t){return he.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class oe{constructor(t,e){this.compartment=t,this.inner=e}}class le{constructor(t,e,i,s,r,n){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=n,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(t,e,i){let s=[],r=Object.create(null),n=new Map;for(let i of function(t,e,i){let s=[[],[],[],[],[]],r=new Map;function n(t,h){let o=r.get(t);if(null!=o){if(o<=h)return;let e=s[o].indexOf(t);e>-1&&s[o].splice(e,1),t instanceof oe&&i.delete(t.compartment)}if(r.set(t,h),Array.isArray(t))for(let e of t)n(e,h);else if(t instanceof oe){if(i.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let s=e.get(t.compartment)||t.inner;i.set(t.compartment,s),n(s,h)}else if(t instanceof ne)n(t.inner,t.prec);else if(t instanceof Kt)s[h].push(t),t.provides&&n(t.provides,h);else if(t instanceof Ht)s[h].push(t),t.facet.extensions&&n(t.facet.extensions,h);else{let e=t.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${t}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);n(e,h)}}return n(t,ee),s.reduce(((t,e)=>t.concat(e)))}(t,e,n))i instanceof Kt?s.push(i):(r[i.facet.id]||(r[i.facet.id]=[])).push(i);let h=Object.create(null),o=[],l=[];for(let t of s)h[t.id]=l.length<<1,l.push((e=>t.slot(e)));let u=null==i?void 0:i.config.facets;for(let t in r){let e=r[t],s=e[0].facet,n=u&&u[t]||[];if(e.every((t=>0==t.type)))if(h[s.id]=o.length<<1|1,zt(n,e))o.push(i.facet(s));else{let t=s.combine(e.map((t=>t.value)));o.push(i&&s.compare(t,i.facet(s))?i.facet(s):t)}else{for(let t of e)0==t.type?(h[t.id]=o.length<<1|1,o.push(t.value)):(h[t.id]=l.length<<1,l.push((e=>t.dynamicSlot(e))));h[s.id]=l.length<<1,l.push((t=>Bt(t,s,e)))}}let a=l.map((t=>t(h)));return new le(t,n,a,h,o,r)}}function ue(t,e){if(1&e)return 2;let i=e>>1,s=t.status[i];if(4==s)throw new Error("Cyclic dependency between fields and/or facets");if(2&s)return s;t.status[i]=4;let r=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|r}function ae(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const fe=Dt.define(),ce=Dt.define({combine:t=>t.some((t=>t)),static:!0}),Oe=Dt.define({combine:t=>t.length?t[0]:void 0,static:!0}),de=Dt.define(),$e=Dt.define(),pe=Dt.define(),me=Dt.define({combine:t=>!!t.length&&t[0]});class we{constructor(t,e){this.type=t,this.value=e}static define(){return new ge}}class ge{of(t){return new we(this,t)}}class xe{constructor(t){this.map=t}of(t){return new be(this,t)}}class be{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return void 0===e?void 0:e==this.value?this:new be(this.type,e)}is(t){return this.type==t}static define(t={}){return new xe(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let s of t){let t=s.map(e);t&&i.push(t)}return i}}be.reconfigure=be.define(),be.appendConfig=be.define();class ye{constructor(t,e,i,s,r,n){this.startState=t,this.changes=e,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=n,this._doc=null,this._state=null,i&&Vt(i,e.newLength),r.some((t=>t.type==ye.time))||(this.annotations=r.concat(ye.time.of(Date.now())))}static create(t,e,i,s,r,n){return new ye(t,e,i,s,r,n)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(ye.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function Qe(t,e){let i=[];for(let s=0,r=0;;){let n,h;if(s=t[s]))n=t[s++],h=t[s++];else{if(!(r=0;r--){let n=i[r](t);n&&Object.keys(n).length&&(s=Pe(t,ve(e,n,t.changes.newLength),!0))}return s==t?t:ye.create(e,t.changes,t.selection,s.effects,s.annotations,s.scrollIntoView)}(i?function(t){let e=t.startState,i=!0;for(let s of e.facet(de)){let e=s(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:Qe(i,e))}if(!0!==i){let s,r;if(!1===i)r=t.changes.invertedDesc,s=Mt.empty(e.doc.length);else{let e=t.changes.filter(i);s=e.changes,r=e.filtered.mapDesc(e.changes).invertedDesc}t=ye.create(e,s,t.selection&&t.selection.map(r),be.mapEffects(t.effects,r),t.annotations,t.scrollIntoView)}let s=e.facet($e);for(let i=s.length-1;i>=0;i--){let r=s[i](t);t=r instanceof ye?r:Array.isArray(r)&&1==r.length&&r[0]instanceof ye?r[0]:qe(e,ke(r),!1)}return t}(r):r)}ye.time=we.define(),ye.userEvent=we.define(),ye.addToHistory=we.define(),ye.remote=we.define();const Se=[];function ke(t){return null==t?Se:Array.isArray(t)?t:[t]}var Ie=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(Ie||(Ie={}));const Re=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let We;try{We=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(I){}function Ye(t){return e=>{if(!/\S/.test(e))return Ie.Space;if(function(t){if(We)return We.test(t);for(let e=0;e"€"&&(i.toUpperCase()!=i.toLowerCase()||Re.test(i)))return!0}return!1}(e))return Ie.Word;for(let i=0;i-1)return Ie.Word;return Ie.Other}}class Xe{constructor(t,e,i,s,r,n){this.config=t,this.doc=e,this.selection=i,this.values=s,this.status=t.statusTemplate.slice(),this.computeSlot=r,n&&(n._state=this);for(let t=0;tr.set(e,t))),i=null),r.set(e.value.compartment,e.value.extension)):e.is(be.reconfigure)?(i=null,s=e.value):e.is(be.appendConfig)&&(i=null,s=ke(s).concat(e.value));i?e=t.startState.values.slice():(i=le.resolve(s,r,this),e=new Xe(i,this.doc,this.selection,i.dynamicSlots.map((()=>null)),((t,e)=>e.reconfigure(t,this)),null).values),new Xe(i,t.newDoc,t.newSelection,e,((e,i)=>i.update(e,t)),t)}replaceSelection(t){return"string"==typeof t&&(t=this.toText(t)),this.changeByRange((e=>({changes:{from:e.from,to:e.to,insert:t},range:Gt.cursor(e.from+t.length)})))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),s=this.changes(i.changes),r=[i.range],n=ke(i.effects);for(let i=1;ir.spec.fromJSON(n,t))))}return Xe.create({doc:t.doc,selection:Gt.fromJSON(t.selection),extensions:e.extensions?s.concat([e.extensions]):s})}static create(t={}){let e=le.resolve(t.extensions||[],new Map),i=t.doc instanceof ft?t.doc:ft.of((t.doc||"").split(e.staticFacet(Xe.lineSeparator)||Wt)),s=t.selection?t.selection instanceof Gt?t.selection:Gt.single(t.selection.anchor,t.selection.head):Gt.single(0);return Vt(s,i.length),e.staticFacet(ce)||(s=s.asSingle()),new Xe(e,i,s,e.dynamicSlots.map((()=>null)),((t,e)=>e.create(t)),null)}get tabSize(){return this.facet(Xe.tabSize)}get lineBreak(){return this.facet(Xe.lineSeparator)||"\n"}get readOnly(){return this.facet(me)}phrase(t,...e){for(let e of this.facet(Xe.phrases))if(Object.prototype.hasOwnProperty.call(e,t)){t=e[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,((t,i)=>{if("$"==i)return"$";let s=+(i||1);return!s||s>e.length?t:e[s-1]}))),t}languageDataAt(t,e,i=-1){let s=[];for(let r of this.facet(fe))for(let n of r(this,e,i))Object.prototype.hasOwnProperty.call(n,t)&&s.push(n[t]);return s}charCategorizer(t){return Ye(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:s}=this.doc.lineAt(t),r=this.charCategorizer(t),n=t-i,h=t-i;for(;n>0;){let t=Qt(e,n,!1);if(r(e.slice(t,n))!=Ie.Word)break;n=t}for(;ht.length?t[0]:4}),Xe.lineSeparator=Oe,Xe.readOnly=me,Xe.phrases=Dt.define({compare(t,e){let i=Object.keys(t),s=Object.keys(e);return i.length==s.length&&i.every((i=>t[i]==e[i]))}}),Xe.languageData=fe,Xe.changeFilter=de,Xe.transactionFilter=$e,Xe.transactionExtender=pe,he.reconfigure=be.define();class Ze{eq(t){return this==t}range(t,e=t){return Te.create(t,e,this)}}Ze.prototype.startSide=Ze.prototype.endSide=0,Ze.prototype.point=!1,Ze.prototype.mapMode=Yt.TrackDel;class Te{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new Te(t,e,i)}}function _e(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Ee{constructor(t,e,i,s){this.from=t,this.to=e,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,s=0){let r=i?this.to:this.from;for(let n=s,h=r.length;;){if(n==h)return n;let s=n+h>>1,o=r[s]-t||(i?this.value[s].endSide:this.value[s].startSide)-e;if(s==n)return o>=0?n:h;o>=0?h=s:n=s+1}}between(t,e,i,s){for(let r=this.findIndex(e,-1e9,!0),n=this.findIndex(i,1e9,!1,r);ru||l==u&&a.startSide>0&&a.endSide<=0)continue;(u-l||a.endSide-a.startSide)<0||(n<0&&(n=l),a.point&&(h=Math.max(h,u-l)),i.push(a),s.push(l-n),r.push(u-n))}return{mapped:i.length?new Ee(s,r,i,h):null,pos:n}}}class Ae{constructor(t,e,i,s){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=s}static create(t,e,i,s){return new Ae(t,e,i,s)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=t,n=t.filter;if(0==e.length&&!n)return this;if(i&&(e=e.slice().sort(_e)),this.isEmpty)return e.length?Ae.of(e):this;let h=new Ge(this,null,-1).goto(0),o=0,l=[],u=new je;for(;h.value||o=0){let t=e[o++];u.addInner(t.from,t.to,t.value)||l.push(t)}else 1==h.rangeIndex&&h.chunkIndexthis.chunkEnd(h.chunkIndex)||rh.to||r=r&&t<=r+n.length&&!1===n.between(r,t-r,e-r,i))return}this.nextLayer.between(t,e,i)}}iter(t=0){return Ve.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Ve.from(t).goto(e)}static compare(t,e,i,s,r=-1){let n=t.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=r)),h=e.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=r)),o=Ue(n,h,i),l=new De(n,o,r),u=new De(h,o,r);i.iterGaps(((t,e,i)=>ze(l,t,u,e,i,s))),i.empty&&0==i.length&&ze(l,0,u,0,0,s)}static eq(t,e,i=0,s){null==s&&(s=1e9);let r=t.filter((t=>!t.isEmpty&&e.indexOf(t)<0)),n=e.filter((e=>!e.isEmpty&&t.indexOf(e)<0));if(r.length!=n.length)return!1;if(!r.length)return!0;let h=Ue(r,n),o=new De(r,h,0).goto(i),l=new De(n,h,0).goto(i);for(;;){if(o.to!=l.to||!He(o.active,l.active)||o.point&&(!l.point||!o.point.eq(l.point)))return!1;if(o.to>s)return!0;o.next(),l.next()}}static spans(t,e,i,s,r=-1){let n=new De(t,null,r).goto(e),h=e,o=n.openStart;for(;;){let t=Math.min(n.to,i);if(n.point?(s.point(h,t,n.point,n.activeForPoint(n.to),o,n.pointRank),o=n.openEnd(t)+(n.to>t?1:0)):t>h&&(s.span(h,t,n.active,o),o=n.openEnd(t)),n.to>i)break;h=n.to,n.next()}return o}static of(t,e=!1){let i=new je;for(let s of t instanceof Te?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i0)return t.slice().sort(_e);e=s}return t}(t):t)i.add(s.from,s.to,s.value);return i.finish()}}Ae.empty=new Ae([],[],null,-1),Ae.empty.nextLayer=Ae.empty;class je{constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}finishChunk(t){this.chunks.push(new Ee(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new je)).add(t,e,i)}addInner(t,e,i){let s=t-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(s<0||(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),0))}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(Ae.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=Ae.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Ue(t,e,i){let s=new Map;for(let e of t)for(let t=0;t=this.minPoint)break}}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=i&&s.push(new Ge(n,e,i,r));return 1==s.length?s[0]:new Ve(s)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let t=this.heap.length>>1;t>=0;t--)Ce(this.heap,t);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let t=this.heap.length>>1;t>=0;t--)Ce(this.heap,t);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),Ce(this.heap,0)}}}function Ce(t,e){for(let i=t[e];;){let s=1+(e<<1);if(s>=t.length)break;let r=t[s];if(s+1=0&&(r=t[s+1],s++),i.compare(r)<0)break;t[s]=i,t[e]=r,e=s}}class De{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Ve.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){Ne(this.active,t),Ne(this.activeTo,t),Ne(this.activeRank,t),this.minActive=Be(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:s,rank:r}=this.cursor;for(;e-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>t){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),i&&Ne(i,r)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let r=this.cursor.value;if(r.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from=0&&!(this.activeRank[i]t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function ze(t,e,i,s,r,n){t.goto(e),i.goto(s);let h=s+r,o=s,l=s-e;for(;;){let e=t.to+l-i.to||t.endSide-i.endSide,s=e<0?t.to+l:i.to,r=Math.min(s,h);if(t.point||i.point?t.point&&i.point&&(t.point==i.point||t.point.eq(i.point))&&He(t.activeForPoint(t.to+l),i.activeForPoint(i.to))||n.comparePoint(o,r,t.point,i.point):r>o&&!He(t.active,i.active)&&n.compareRange(o,r,t.active,i.active),s>h)break;o=s,e<=0&&t.next(),e>=0&&i.next()}}function He(t,e){if(t.length!=e.length)return!1;for(let i=0;i=e;i--)t[i+1]=t[i];t[e]=i}function Be(t,e){let i=-1,s=1e9;for(let r=0;r=e)return s;if(s==t.length)break;r+=9==t.charCodeAt(s)?i-r%i:1,s=Qt(t,s)}return!0===s?-1:t.length}const Je="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),ti="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),ei="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class ii{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function r(t,e,n,h){let o=[],l=/^@(\w+)\b/.exec(t[0]),u=l&&"keyframes"==l[1];if(l&&null==e)return n.push(t[0]+";");for(let i in e){let h=e[i];if(/&/.test(i))r(i.split(/,\s*/).map((e=>t.map((t=>e.replace(/&/,t))))).reduce(((t,e)=>t.concat(e))),h,n);else if(h&&"object"==typeof h){if(!l)throw new RangeError("The value of a property ("+i+") should be a primitive value.");r(s(i),h,o,u)}else null!=h&&o.push(i.replace(/_.*/,"").replace(/[A-Z]/g,(t=>"-"+t.toLowerCase()))+": "+h+";")}(o.length||u)&&n.push((!i||l||h?t:t.map(i)).join(", ")+" {"+o.join(" ")+"}")}for(let e in t)r(s(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=ei[Je]||1;return ei[Je]=t+1,"ͼ"+t.toString(36)}static mount(t,e){(t[ti]||new ri(t)).mount(Array.isArray(e)?e:[e])}}let si=null;class ri{constructor(t){if(!t.head&&t.adoptedStyleSheets&&"undefined"!=typeof CSSStyleSheet){if(si)return t.adoptedStyleSheets=[si.sheet].concat(t.adoptedStyleSheets),t[ti]=si;this.sheet=new CSSStyleSheet,t.adoptedStyleSheets=[this.sheet].concat(t.adoptedStyleSheets),si=this}else{this.styleTag=(t.ownerDocument||t).createElement("style");let e=t.head||t;e.insertBefore(this.styleTag,e.firstChild)}this.modules=[],t[ti]=this}mount(t){let e=this.sheet,i=0,s=0;for(let r=0;r-1&&(this.modules.splice(h,1),s--,h=-1),-1==h){if(this.modules.splice(s++,0,n),e)for(let t=0;t",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"',229:"Q"},oi="undefined"!=typeof navigator&&/Chrome\/(\d+)/.exec(navigator.userAgent),li="undefined"!=typeof navigator&&/Apple Computer/.test(navigator.vendor),ui="undefined"!=typeof navigator&&/Gecko\/\d+/.test(navigator.userAgent),ai="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),fi="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ci=oi&&(ai||+oi[1]<57)||ui&&ai,Oi=0;Oi<10;Oi++)ni[48+Oi]=ni[96+Oi]=String(Oi);for(Oi=1;Oi<=24;Oi++)ni[Oi+111]="F"+Oi;for(Oi=65;Oi<=90;Oi++)ni[Oi]=String.fromCharCode(Oi+32),hi[Oi]=String.fromCharCode(Oi);for(var di in ni)hi.hasOwnProperty(di)||(hi[di]=ni[di]);function $i(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function pi(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function mi(t,e){if(!e.anchorNode)return!1;try{return pi(t,e.anchorNode)}catch(t){return!1}}function wi(t){return 3==t.nodeType?Ri(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function gi(t,e,i,s){return!!i&&(bi(t,e,i,s,-1)||bi(t,e,i,s,1))}function xi(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function bi(t,e,i,s,r){for(;;){if(t==i&&e==s)return!0;if(e==(r<0?0:yi(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=xi(t)+(r<0?0:1),t=i}else{if(1!=t.nodeType)return!1;if(1==(t=t.childNodes[e+(r<0?-1:0)]).nodeType&&"false"==t.contentEditable)return!1;e=r<0?yi(t):0}}}function yi(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}const Qi={left:0,right:0,top:0,bottom:0};function Pi(t,e){let i=e?t.left:t.right;return{left:i,right:i,top:t.top,bottom:t.bottom}}function vi(t){return{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}class qi{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){this.set(t.anchorNode,t.anchorOffset,t.focusNode,t.focusOffset)}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let Si,ki=null;function Ii(t){if(t.setActive)return t.setActive();if(ki)return t.focus(ki);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==ki?{get preventScroll(){return ki={preventScroll:!0},!0}}:void 0),!ki){ki=!1;for(let t=0;te)return i.domBoundsAround(t,e,l);if(a>=t&&-1==s&&(s=o,r=l),l>e&&i.dom.parentNode==this.dom){n=o,h=u;break}u=a,l=a+i.breakAfter}return{from:r,to:h<0?i+this.length:h,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:n=0?this.children[n].dom:null}}markDirty(t=!1){this.dirty|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.dirty|=2),1&e.dirty)return;e.dirty|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.dirty&&this.markParentsDirty(!0))}setDOM(t){this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=Mi){this.markDirty();for(let i=t;ithis.pos||t==this.pos&&(e>0||0==this.i||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Ei(t,e,i,s,r,n,h,o,l){let{children:u}=t,a=u.length?u[e]:null,f=n.length?n[n.length-1]:null,c=f?f.breakAfter:h;if(!(e==s&&a&&!h&&!c&&n.length<2&&a.merge(i,r,n.length?f:null,0==i,o,l))){if(s0&&(!h&&n.length&&a.merge(i,a.length,n[0],!1,o,0)?a.breakAfter=n.shift().breakAfter:(i2);var Li={mac:Bi||/Mac/.test(ji.platform),windows:/Win/.test(ji.platform),linux:/Linux|X11/.test(ji.platform),ie:Di,ie_version:Vi?Ui.documentMode||6:Ci?+Ci[1]:Gi?+Gi[1]:0,gecko:zi,gecko_version:zi?+(/Firefox\/(\d+)/.exec(ji.userAgent)||[0,0])[1]:0,chrome:!!Hi,chrome_version:Hi?+Hi[1]:0,ios:Bi,android:/Android\b/.test(ji.userAgent),webkit:Ni,safari:Fi,webkit_version:Ni?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:null!=Ui.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};class Ki extends Zi{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){3==t.nodeType&&this.createDOM(t)}merge(t,e,i){return(!i||i instanceof Ki&&!(this.length-(e-t)+i.length>256))&&(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Ki(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new Xi(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return ts(this.dom,t,e)}}class Ji extends Zi{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let t of e)t.setParent(this)}setAttrs(t){if(Yi(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.dirty|=6)}sync(t){this.dom?4&this.dirty&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t)}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof Ji&&i.mark.eq(this.mark))||t&&r<=0||et&&e.push(i=t&&(s=r),i=h,r++}let n=this.length-t;return this.length=t,s>-1&&(this.children.length=s,this.markDirty()),new Ji(this.mark,e,n)}domAtPos(t){return hs(this.dom,this.children,t)}coordsAt(t,e){return ls(this,t,e)}}function ts(t,e,i){let s=t.nodeValue.length;e>s&&(e=s);let r=e,n=e,h=0;0==e&&i<0||e==s&&i>=0?Li.chrome||Li.gecko||(e?(r--,h=1):n=0)?0:o.length-1];return Li.safari&&!h&&0==l.width&&(l=Array.prototype.find.call(o,(t=>t.width))||l),h?Pi(l,h<0):l||null}class es extends Zi{constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}static create(t,e,i){return new(t.customView||es)(t,e,i)}split(t){let e=es.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(){this.dom&&this.widget.updateDOM(this.dom)||(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}getSide(){return this.side}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof es&&this.widget.compare(i.widget))||t>0&&r<=0||e0?i.length-1:0;s=i[e],!(t>0?0==e:e==i.length-1||s.top0?-1:1);return 0==t&&e>0||t==this.length&&e<=0?s:Pi(s,0==t)}get isEditable(){return!1}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class is extends es{domAtPos(t){let{topView:e,text:i}=this.widget;return e?ss(t,0,e,i,((t,e)=>t.domAtPos(e)),(t=>new Xi(i,Math.min(t,i.nodeValue.length)))):new Xi(i,Math.min(t,i.nodeValue.length))}sync(){this.setDOM(this.widget.toDOM())}localPosFromDOM(t,e){let{topView:i,text:s}=this.widget;return i?rs(t,e,i,s):Math.min(e,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(t,e){let{topView:i,text:s}=this.widget;return i?ss(t,e,i,s,((t,e,i)=>t.coordsAt(e,i)),((t,e)=>ts(s,t,e))):ts(s,t,e)}destroy(){var t;super.destroy(),null===(t=this.widget.topView)||void 0===t||t.destroy()}get isEditable(){return!0}}function ss(t,e,i,s,r,n){if(i instanceof Ji){for(let h of i.children){let i=pi(h.dom,s),o=i?s.nodeValue.length:h.length;if(t=0;)if(e<0?s>0:s0?-1:1);return i&&i.tope.top?{left:e.left,right:e.right,top:i.top,bottom:i.bottom}:e}get overrideDOMText(){return ft.empty}}function hs(t,e,i){let s=0;for(let r=0;sr&&i0;s--){let i=e[s-1].dom;if(i.parentNode==t)return Xi.after(i)}return new Xi(t,0)}function os(t,e,i){let s,{children:r}=t;i>0&&e instanceof Ji&&r.length&&(s=r[r.length-1])instanceof Ji&&s.mark.eq(e.mark)?os(s,e.children[0],i-1):(r.push(e),e.setParent(t)),t.length+=e.length}function ls(t,e,i){for(let s=0,r=0;r0?o>=e:o>e)&&(e0)){let t=0;if(o==s){if(h.getSide()<=0)continue;t=i=-h.getSide()}let r=h.coordsAt(Math.max(0,e-s),i);return t&&r?Pi(r,i<0):r}s=o}let s=t.dom.lastChild;if(!s)return t.dom.getBoundingClientRect();let r=wi(s);return r[r.length-1]||null}function us(t,e){for(let i in t)"class"==i&&e.class?e.class+=" "+t.class:"style"==i&&e.style?e.style+=";"+t.style:e[i]=t[i];return e}function as(t,e){if(t==e)return!0;if(!t||!e)return!1;let i=Object.keys(t),s=Object.keys(e);if(i.length!=s.length)return!1;for(let r of i)if(-1==s.indexOf(r)||t[r]!==e[r])return!1;return!0}function fs(t,e,i){let s=null;if(e)for(let r in e)i&&r in i||t.removeAttribute(s=r);if(i)for(let r in i)e&&e[r]==i[r]||t.setAttribute(s=r,i[r]);return!!s}Ki.prototype.children=es.prototype.children=ns.prototype.children=Mi;class cs{eq(t){return!1}updateDOM(t){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}ignoreEvent(t){return!0}get customView(){return null}destroy(t){}}var Os=function(t){return t[t.Text=0]="Text",t[t.WidgetBefore=1]="WidgetBefore",t[t.WidgetAfter=2]="WidgetAfter",t[t.WidgetRange=3]="WidgetRange",t}(Os||(Os={}));class ds extends Ze{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new $s(t)}static widget(t){let e=t.side||0,i=!!t.block;return e+=i?e>0?3e8:-4e8:e>0?1e8:-1e8,new ms(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,s=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:r,end:n}=ws(t,s);e=(r?s?-3e8:-1:5e8)-1,i=1+(n?s?2e8:1:-6e8)}return new ms(t,e,i,s,t.widget||null,!0)}static line(t){return new ps(t)}static set(t,e=!1){return Ae.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}ds.none=Ae.empty;class $s extends ds{constructor(t){let{start:e,end:i}=ws(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){return this==t||t instanceof $s&&this.tagName==t.tagName&&this.class==t.class&&as(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)}}$s.prototype.point=!1;class ps extends ds{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof ps&&as(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)}}ps.prototype.mapMode=Yt.TrackBefore,ps.prototype.point=!0;class ms extends ds{constructor(t,e,i,s,r,n){super(e,i,r,t),this.block=s,this.isReplace=n,this.mapMode=s?e<=0?Yt.TrackBefore:Yt.TrackAfter:Yt.TrackDel}get type(){return this.startSide=5}eq(t){return t instanceof ms&&function(t,e){return t==e||!!(t&&e&&t.compare(e))}(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)}}function ws(t,e=!1){let{inclusiveStart:i,inclusiveEnd:s}=t;return null==i&&(i=t.inclusive),null==s&&(s=t.inclusive),{start:null!=i?i:e,end:null!=s?s:e}}function gs(t,e,i,s=0){let r=i.length-1;r>=0&&i[r]+s>=t?i[r]=Math.max(i[r],e):i.push(t,e)}ms.prototype.point=!0;class xs extends Zi{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,s,r,n){if(i){if(!(i instanceof xs))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Ai(this,t,e,i?i.children:[],r,n),!0}split(t){let e=new xs;if(e.breakAfter=this.breakAfter,0==this.length)return e;let{i,off:s}=this.childPos(t);s&&(e.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let t=i;t0&&0==this.children[i-1].length;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=void 0===this.prevAttrs?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){as(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){os(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=us(e,this.attrs||{})),i&&(this.attrs=us({class:i},this.attrs||{}))}domAtPos(t){return hs(this.dom,this.children,t)}reuseDOM(t){"DIV"==t.nodeName&&(this.setDOM(t),this.dirty|=6)}sync(t){var e;this.dom?4&this.dirty&&(Yi(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),void 0!==this.prevAttrs&&(fs(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t);let i=this.dom.lastChild;for(;i&&Zi.get(i)instanceof Ji;)i=i.lastChild;if(!(i&&this.length&&("BR"==i.nodeName||0!=(null===(e=Zi.get(i))||void 0===e?void 0:e.isEditable)||Li.ios&&this.children.some((t=>t instanceof Ki))))){let t=document.createElement("BR");t.cmIgnore=!0,this.dom.appendChild(t)}}measureTextSize(){if(0==this.children.length||this.length>20)return null;let t=0;for(let e of this.children){if(!(e instanceof Ki))return null;let i=wi(e.dom);if(1!=i.length)return null;t+=i[0].width}return{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length}}coordsAt(t,e){return ls(this,t,e)}become(t){return!1}get type(){return Os.Text}static find(t,e){for(let i=0,s=0;i=e){if(r instanceof xs)return r;if(n>e)break}s=n+r.breakAfter}return null}}class bs extends Zi{constructor(t,e,i){super(),this.widget=t,this.length=e,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof bs&&this.widget.compare(i.widget))||t>0&&r<=0||e0;){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:s}=this.cursor.next(this.skip);if(this.skip=0,s)throw new Error("Ran out of text content when drawing inline views");if(i){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer([]),this.curLine=null,t--;continue}this.text=e,this.textOff=0}let s=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(0,i)),this.getLine().append(Qs(new Ki(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=0}}span(t,e,i,s){this.buildText(e-t,i,s),this.pos=e,this.openStart<0&&(this.openStart=s)}point(t,e,i,s,r,n){if(this.disallowBlockEffectsFor[n]&&i instanceof ms){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let h=e-t;if(i instanceof ms)if(i.block){let{type:t}=i;t!=Os.WidgetAfter||this.posCovered()||this.getLine(),this.addBlockWidget(new bs(i.widget||new Ps("div"),h,t))}else{let n=es.create(i.widget||new Ps("span"),h,i.startSide),o=this.atCursorPos&&!n.isEditable&&r<=s.length&&(t0),l=!n.isEditable&&(tt.some((t=>t))});class Ys{constructor(t,e="nearest",i="nearest",s=5,r=5){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r}map(t){return t.empty?this:new Ys(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin)}}const Xs=be.define({map:(t,e)=>t.map(e)});function Ms(t,e,i){let s=t.facet(ks);s.length?s[0](e):window.onerror?window.onerror(String(e),i,void 0,void 0,e):i?console.error(i+":",e):console.error(e)}const Zs=Dt.define({combine:t=>!t.length||t[0]});let Ts=0;const _s=Dt.define();class Es{constructor(t,e,i,s){this.id=t,this.create=e,this.domEventHandlers=i,this.extension=s(this)}static define(t,e){const{eventHandlers:i,provide:s,decorations:r}=e||{};return new Es(Ts++,t,i,(t=>{let e=[_s.of(t)];return r&&e.push(Gs.of((e=>{let i=e.plugin(t);return i?r(i):ds.none}))),s&&e.push(s(t)),e}))}static fromClass(t,e){return Es.define((e=>new t(e)),e)}}class As{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(Ms(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){Ms(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(null===(e=this.value)||void 0===e?void 0:e.destroy)try{this.value.destroy()}catch(e){Ms(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const js=Dt.define(),Us=Dt.define(),Gs=Dt.define(),Vs=Dt.define(),Cs=Dt.define(),Ds=Dt.define();class zs{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new zs(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toAu)break;r+=2}if(!o)return i;new zs(o.fromA,o.toA,o.fromB,o.toB).addToSet(i),n=o.toA,h=o.toB}}}class Hs{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=Mt.empty(this.startState.doc.length);for(let t of i)this.changes=this.changes.compose(t.changes);let s=[];this.changes.iterChangedRanges(((t,e,i,r)=>s.push(new zs(t,e,i,r)))),this.changedRanges=s;let r=t.hasFocus;r!=t.inputState.notifiedFocused&&(t.inputState.notifiedFocused=r,this.flags|=1)}static create(t,e,i){return new Hs(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(10&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some((t=>t.selection))}get empty(){return 0==this.flags&&0==this.transactions.length}}var Ns=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(Ns||(Ns={}));const Fs=Ns.LTR,Bs=Ns.RTL;function Ls(t){let e=[];for(let i=0;i=e){if(h.level==i)return n;(r<0||(0!=s?s<0?h.frome:t[r].level>h.level))&&(r=n)}}if(r<0)throw new RangeError("Index out of range");return r}}const rr=[];function nr(t){return[new sr(0,t,0)]}let hr="";function or(t,e,i,s,r){var n;let h=s.head-t.from,o=-1;if(0==h){if(!r||!t.length)return null;e[0].level!=i&&(h=e[0].side(!1,i),o=0)}else if(h==t.length){if(r)return null;let t=e[e.length-1];t.level!=i&&(h=t.side(!0,i),o=e.length-1)}o<0&&(o=sr.find(e,h,null!==(n=s.bidiLevel)&&void 0!==n?n:-1,s.assoc));let l=e[o];h==l.side(r,i)&&(l=e[o+=r?1:-1],h=l.side(!r,i));let u=r==(l.dir==i),a=Qt(t.text,h,u);if(hr=t.text.slice(Math.min(h,a),Math.max(h,a)),a!=l.side(r,i))return Gt.cursor(a+t.from,u?-1:1,l.level);let f=o==(r?e.length-1:0)?null:e[o+(r?1:-1)];return f||l.level==i?f&&f.level1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=h-1);i=n+h}}readNode(t){if(t.cmIgnore)return;let e=Zi.get(t),i=e&&e.overrideDOMText;if(null!=i){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;)t.lineBreak?this.lineBreak():this.append(t.value)}else 3==t.nodeType?this.readTextNode(t):"BR"==t.nodeName?t.nextSibling&&this.lineBreak():1==t.nodeType&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(3==t.nodeType?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+Math.min(e,i.offset))}}function ar(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}class fr{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class cr extends Zi{constructor(t){super(),this.view=t,this.compositionDeco=ds.none,this.decorations=[],this.dynamicDecorationMap=[],this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new xs],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new zs(0,0,0,t.state.doc.length)],0)}get root(){return this.view.root}get editorView(){return this.view}get length(){return this.view.state.doc.length}update(t){let e=t.changedRanges;this.minWidth>0&&e.length&&(e.every((({fromA:t,toA:e})=>ethis.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.view.inputState.composing<0?this.compositionDeco=ds.none:(t.transactions.length||this.dirty)&&(this.compositionDeco=function(t,e){let i=dr(t);if(!i)return ds.none;let{from:s,to:r,node:n,text:h}=i,o=e.mapPos(s,1),l=Math.max(o,e.mapPos(r,-1)),{state:u}=t,a=3==n.nodeType?n.nodeValue:new ur([],u).readRange(n.firstChild,null).text;if(l-o{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let t=Li.chrome||Li.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.sync(t),this.dirty=0,t&&(t.written||i.selectionRange.focusNode!=t.node)&&(this.forceSelection=!0),this.dom.style.height=""}));let s=[];if(this.view.viewport.from||this.view.viewport.to=0?t[e]:null;if(!s)break;let{fromA:r,toA:n,fromB:h,toB:o}=s,{content:l,breakAtStart:u,openStart:a,openEnd:f}=ys.build(this.view.state.doc,h,o,this.decorations,this.dynamicDecorationMap),{i:c,off:O}=i.findPos(n,1),{i:d,off:$}=i.findPos(r,-1);Ei(this,d,$,c,O,l,u,a,f)}}updateSelection(t=!1,e=!1){if(!t&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange(),!e&&!this.mayControlSelection()||Li.ios&&this.view.inputState.rapidCompositionStart)return;let i=this.forceSelection;this.forceSelection=!1;let s=this.view.state.selection.main,r=this.domAtPos(s.anchor),n=s.empty?r:this.domAtPos(s.head);if(Li.gecko&&s.empty&&1==(h=r).node.nodeType&&h.node.firstChild&&(0==h.offset||"false"==h.node.childNodes[h.offset-1].contentEditable)&&(h.offset==h.node.childNodes.length||"false"==h.node.childNodes[h.offset].contentEditable)){let t=document.createTextNode("");this.view.observer.ignore((()=>r.node.insertBefore(t,r.node.childNodes[r.offset]||null))),r=n=new Xi(t,0),i=!0}var h;let o=this.view.observer.selectionRange;!i&&o.focusNode&&gi(r.node,r.offset,o.anchorNode,o.anchorOffset)&&gi(n.node,n.offset,o.focusNode,o.focusOffset)||(this.view.observer.ignore((()=>{Li.android&&Li.chrome&&this.dom.contains(o.focusNode)&&function(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(o.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let t=$i(this.root);if(t)if(s.empty){if(Li.gecko){let t=(e=r.node,i=r.offset,1!=e.nodeType?0:(i&&"false"==e.childNodes[i-1].contentEditable?1:0)|(is.head&&([r,n]=[n,r]),e.setEnd(n.node,n.offset),e.setStart(r.node,r.offset),t.removeAllRanges(),t.addRange(e)}var e,i})),this.view.observer.setSelectionRange(r,n)),this.impreciseAnchor=r.precise?null:new Xi(o.anchorNode,o.anchorOffset),this.impreciseHead=n.precise?null:new Xi(o.focusNode,o.focusOffset)}enforceCursorAssoc(){if(this.compositionDeco.size)return;let t=this.view.state.selection.main,e=$i(this.root);if(!(e&&t.empty&&t.assoc&&e.modify))return;let i=xs.find(this,t.head);if(!i)return;let s=i.posAtStart;if(t.head==s||t.head==s+i.length)return;let r=this.coordsAt(t.head,-1),n=this.coordsAt(t.head,1);if(!r||!n||r.bottom>n.top)return;let h=this.domAtPos(t.head+t.assoc);e.collapse(h.node,h.offset),e.modify("move",t.assoc<0?"forward":"backward","lineboundary")}mayControlSelection(){let t=this.root.activeElement;return t==this.dom||mi(this.dom,this.view.observer.selectionRange)&&!(t&&this.dom.contains(t))}nearest(t){for(let e=t;e;){let t=Zi.get(e);if(t&&t.rootView==this)return t;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;en||t==n&&r.type!=Os.WidgetBefore&&r.type!=Os.WidgetAfter&&(!s||2==e||this.children[s-1].breakAfter||this.children[s-1].type==Os.WidgetBefore&&e>-2))return r.coordsAt(t-n,e);i=n}}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,n=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,h=-1,o=this.view.textDirection==Ns.LTR;for(let t=0,l=0;ls)break;if(t>=i){let i=u.dom.getBoundingClientRect();if(e.push(i.height),n){let e=u.dom.lastChild,s=e?wi(e):[];if(s.length){let e=s[s.length-1],n=o?e.right-i.left:i.right-e.left;n>h&&(h=n,this.minWidth=r,this.minWidthFrom=t,this.minWidthTo=a)}}}t=a+u.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return"rtl"==getComputedStyle(this.children[e].dom).direction?Ns.RTL:Ns.LTR}measureTextSize(){for(let t of this.children)if(t instanceof xs){let e=t.measureTextSize();if(e)return e}let t,e,i=document.createElement("div");return i.className="cm-line",i.style.width="99999px",i.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore((()=>{this.dom.appendChild(i);let s=wi(i.firstChild)[0];t=i.getBoundingClientRect().height,e=s?s.width/27:7,i.remove()})),{lineHeight:t,charWidth:e}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new _i(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],n=r?r.from-1:this.length;if(n>i){let s=e.lineBlockAt(n).bottom-e.lineBlockAt(i).top;t.push(ds.replace({widget:new Or(s),block:!0,inclusive:!0,isBlockGap:!0}).range(i,n))}if(!r)break;i=r.to+1}return ds.set(t)}updateDeco(){let t=this.view.state.facet(Gs).map(((t,e)=>(this.dynamicDecorationMap[e]="function"==typeof t)?t(this.view):t));for(let e=t.length;ei.anchor?-1:1);if(!s)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(s={left:Math.min(s.left,e.left),top:Math.min(s.top,e.top),right:Math.max(s.right,e.right),bottom:Math.max(s.bottom,e.bottom)});let r=0,n=0,h=0,o=0;for(let t of this.view.state.facet(Cs).map((t=>t(this.view))))if(t){let{left:e,right:i,top:s,bottom:l}=t;null!=e&&(r=Math.max(r,e)),null!=i&&(n=Math.max(n,i)),null!=s&&(h=Math.max(h,s)),null!=l&&(o=Math.max(o,l))}let l={left:s.left-r,top:s.top-h,right:s.right+n,bottom:s.bottom+o};!function(t,e,i,s,r,n,h,o){let l=t.ownerDocument,u=l.defaultView;for(let a=t;a;)if(1==a.nodeType){let t,f=a==l.body;if(f)t=vi(u);else{if(a.scrollHeight<=a.clientHeight&&a.scrollWidth<=a.clientWidth){a=a.parentNode;continue}let e=a.getBoundingClientRect();t={left:e.left,right:e.left+a.clientWidth,top:e.top,bottom:e.top+a.clientHeight}}let c=0,O=0;if("nearest"==r)e.top0&&e.bottom>t.bottom+O&&(O=e.bottom-t.bottom+O+h)):e.bottom>t.bottom&&(O=e.bottom-t.bottom+h,i<0&&e.top-O0&&e.right>t.right+c&&(c=e.right-t.right+c+n)):e.right>t.right&&(c=e.right-t.right+n,i<0&&e.left0&&i<=0)e=yi(t=t.childNodes[e-1]);else{if(!(1==t.nodeType&&e=0))return null;t=t.childNodes[e],e=0}}}class mr{constructor(){this.changes=[]}compareRange(t,e){gs(t,e,this.changes)}comparePoint(t,e){gs(t,e,this.changes)}}function wr(t,e){return e.left>t?e.left-t:Math.max(0,t-e.right)}function gr(t,e){return e.top>t?e.top-t:Math.max(0,t-e.bottom)}function xr(t,e){return t.tope.top+1}function br(t,e){return et.bottom?{top:t.top,left:t.left,right:t.right,bottom:e}:t}function Qr(t,e,i){let s,r,n,h,o,l,u,a;for(let f=t.firstChild;f;f=f.nextSibling){let t=wi(f);for(let c=0;c$||h==$&&n>d)&&(s=f,r=O,n=d,h=$),0==d?i>O.bottom&&(!u||u.bottomO.top)&&(l=f,a=O):u&&xr(u,O)?u=yr(u,O.bottom):a&&xr(a,O)&&(a=br(a,O.top))}}if(u&&u.bottom>=i?(s=o,r=u):a&&a.top<=i&&(s=l,r=a),!s)return{node:t,offset:0};let f=Math.max(r.left,Math.min(r.right,e));return 3==s.nodeType?Pr(s,f,i):n||"true"!=s.contentEditable?{node:t,offset:Array.prototype.indexOf.call(t.childNodes,s)+(e>=(r.left+r.right)/2?1:0)}:Qr(s,f,i)}function Pr(t,e,i){let s=t.nodeValue.length,r=-1,n=1e9,h=0;for(let o=0;oi?u.top-i:i-u.bottom)-1;if(u.left-1<=e&&u.right+1>=e&&a=(u.left+u.right)/2,s=i;if((Li.chrome||Li.gecko)&&Ri(t,o).getBoundingClientRect().left==u.right&&(s=!i),a<=0)return{node:t,offset:o+(s?1:0)};r=o+(s?1:0),n=a}}}return{node:t,offset:r>-1?r:h>0?t.nodeValue.length:0}}function vr(t,{x:e,y:i},s,r=-1){var n;let h,o=t.contentDOM.getBoundingClientRect(),l=o.top+t.viewState.paddingTop,{docHeight:u}=t.viewState,a=i-l;if(a<0)return 0;if(a>u)return t.state.doc.length;for(let e=t.defaultLineHeight/2,i=!1;h=t.elementAtHeight(a),h.type!=Os.Text;)for(;a=r>0?h.bottom+e:h.top-e,!(a>=0&&a<=u);){if(i)return s?null:0;i=!0,r=-r}i=l+a;let f=h.from;if(ft.viewport.to)return t.viewport.to==t.state.doc.length?t.state.doc.length:s?null:qr(t,o,h,e,i);let c=t.dom.ownerDocument,O=t.root.elementFromPoint?t.root:c,d=O.elementFromPoint(e,i);d&&!t.contentDOM.contains(d)&&(d=null),d||(e=Math.max(o.left+1,Math.min(o.right-1,e)),d=O.elementFromPoint(e,i),d&&!t.contentDOM.contains(d)&&(d=null));let $,p=-1;if(d&&0!=(null===(n=t.docView.nearest(d))||void 0===n?void 0:n.isEditable))if(c.caretPositionFromPoint){let t=c.caretPositionFromPoint(e,i);t&&({offsetNode:$,offset:p}=t)}else if(c.caretRangeFromPoint){let t=c.caretRangeFromPoint(e,i);t&&(({startContainer:$,startOffset:p}=t),Li.safari&&function(t,e,i){let s;if(3!=t.nodeType||e!=(s=t.nodeValue.length))return!1;for(let e=t.nextSibling;e;e=e.nextSibling)if(1!=e.nodeType||"BR"!=e.nodeName)return!1;return Ri(t,s-1,s).getBoundingClientRect().left>i}($,p,e)&&($=void 0))}if(!$||!t.docView.dom.contains($)){let s=xs.find(t.docView,f);if(!s)return a>h.top+h.height/2?h.to:h.from;({node:$,offset:p}=Qr(s.dom,e,i))}return t.docView.posFromDOM($,p)}function qr(t,e,i,s,r){let n=Math.round((s-e.left)*t.defaultCharacterWidth);t.lineWrapping&&i.height>1.5*t.defaultLineHeight&&(n+=Math.floor((r-i.top)/t.defaultLineHeight)*t.viewState.heightOracle.lineLength);let h=t.state.sliceDoc(i.from,i.to);return i.from+Ke(h,n,t.state.tabSize)}function Sr(t,e,i,s){let r=t.state.doc.lineAt(e.head),n=t.bidiSpans(r),h=t.textDirectionAt(r.from);for(let o=e,l=null;;){let e=or(r,n,h,o,i),u=hr;if(!e){if(r.number==(i?t.state.doc.lines:1))return o;u="\n",r=t.state.doc.line(r.number+(i?1:-1)),n=t.bidiSpans(r),e=Gt.cursor(i?r.from:r.to)}if(l){if(!l(u))return o}else{if(!s)return e;l=s(u)}o=e}}function kr(t,e,i){let s=t.state.facet(Vs).map((e=>e(t)));for(;;){let t=!1;for(let r of s)r.between(i.from-1,i.from+1,((s,r,n)=>{i.from>s&&i.fromi.from?Gt.cursor(s,1):Gt.cursor(r,-1),t=!0)}));if(!t)return i}}class Ir{constructor(t){this.lastKeyCode=0,this.lastKeyTime=0,this.chromeScrollHack=-1,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.rapidCompositionStart=!1,this.mouseSelection=null;for(let e in Mr){let i=Mr[e];t.contentDOM.addEventListener(e,(s=>{Xr(t,s)&&!this.ignoreDuringComposition(s)&&("keydown"==e&&this.keydown(t,s)||(this.mustFlushObserver(s)&&t.observer.forceFlush(),this.runCustomHandlers(e,t,s)?s.preventDefault():i(t,s)))})),this.registeredEvents.push(e)}Li.chrome&&Li.chrome_version>=102&&t.scrollDOM.addEventListener("wheel",(()=>{this.chromeScrollHack<0?t.contentDOM.style.pointerEvents="none":window.clearTimeout(this.chromeScrollHack),this.chromeScrollHack=setTimeout((()=>{this.chromeScrollHack=-1,t.contentDOM.style.pointerEvents=""}),100)}),{passive:!0}),this.notifiedFocused=t.hasFocus,Li.safari&&t.contentDOM.addEventListener("input",(()=>null))}setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}ensureHandlers(t,e){var i;let s;this.customHandlers=[];for(let r of e)if(s=null===(i=r.update(t).spec)||void 0===i?void 0:i.domEventHandlers){this.customHandlers.push({plugin:r.value,handlers:s});for(let e in s)this.registeredEvents.indexOf(e)<0&&"scroll"!=e&&(this.registeredEvents.push(e),t.contentDOM.addEventListener(e,(i=>{Xr(t,i)&&this.runCustomHandlers(e,t,i)&&i.preventDefault()})))}}runCustomHandlers(t,e,i){for(let s of this.customHandlers){let r=s.handlers[t];if(r)try{if(r.call(s.plugin,i,e)||i.defaultPrevented)return!0}catch(t){Ms(e.state,t)}}return!1}runScrollHandlers(t,e){for(let i of this.customHandlers){let s=i.handlers.scroll;if(s)try{s.call(i.plugin,e,t)}catch(e){Ms(t.state,e)}}}keydown(t,e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),9==e.keyCode&&Date.now()t.keyCode==e.keyCode)))||e.ctrlKey||e.altKey||e.metaKey||e.synthetic||(this.pendingIOSKey=i,setTimeout((()=>this.flushIOSKey(t)),250),0))}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(this.pendingIOSKey=void 0,Wi(t.contentDOM,e.key,e.keyCode))}ignoreDuringComposition(t){return!!/^key/.test(t.type)&&(this.composing>0||!!(Li.safari&&Date.now()-this.compositionEndedAt<100)&&(this.compositionEndedAt=0,!0))}mustFlushObserver(t){return"keydown"==t.type&&229!=t.keyCode||"compositionend"==t.type&&!Li.ios}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.mouseSelection&&this.mouseSelection.update(t),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}const Rr=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Wr=[16,17,18,20,91,92,224,225];class Yr{constructor(t,e,i,s){this.view=t,this.style=i,this.mustSelect=s,this.lastEvent=e;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(Xe.allowMultipleSelections)&&function(t,e){let i=t.state.facet(vs);return i.length?i[0](e):Li.mac?e.metaKey:e.ctrlKey}(t,e),this.dragMove=function(t,e){let i=t.state.facet(qs);return i.length?i[0](e):Li.mac?!e.altKey:!e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let s=$i(t.root);if(!s||0==s.rangeCount)return!0;let r=s.getRangeAt(0).getClientRects();for(let t=0;t=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}(t,e)||1!=Hr(e))&&null,!1===this.dragging&&(e.preventDefault(),this.select(e))}move(t){if(0==t.buttons)return this.destroy();!1===this.dragging&&this.select(this.lastEvent=t)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}select(t){let e=this.style.get(t,this.extend,this.multiple);!this.mustSelect&&e.eq(this.view.state.selection)&&e.main.assoc==this.view.state.selection.main.assoc||this.view.dispatch({selection:e,userEvent:"select.pointer",scrollIntoView:!0}),this.mustSelect=!1}update(t){t.docChanged&&this.dragging&&(this.dragging=this.dragging.map(t.changes)),this.style.update(t)&&setTimeout((()=>this.select(this.lastEvent)),20)}}function Xr(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,s=e.target;s!=t.contentDOM;s=s.parentNode)if(!s||11==s.nodeType||(i=Zi.get(s))&&i.ignoreEvent(e))return!1;return!0}const Mr=Object.create(null),Zr=Li.ie&&Li.ie_version<15||Li.ios&&Li.webkit_version<604;function Tr(t,e){let i,{state:s}=t,r=1,n=s.toText(e),h=n.lines==s.selection.ranges.length,o=null!=Fr&&s.selection.ranges.every((t=>t.empty))&&Fr==n.toString();if(o){let t=-1;i=s.changeByRange((i=>{let o=s.doc.lineAt(i.from);if(o.from==t)return{range:i};t=o.from;let l=s.toText((h?n.line(r++).text:e)+s.lineBreak);return{changes:{from:o.from,insert:l},range:Gt.cursor(i.from+l.length)}}))}else i=h?s.changeByRange((t=>{let e=n.line(r++);return{changes:{from:t.from,to:t.to,insert:e.text},range:Gt.cursor(t.from+e.length)}})):s.replaceSelection(n);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Mr.keydown=(t,e)=>{t.inputState.setSelectionOrigin("select"),27==e.keyCode?t.inputState.lastEscPress=Date.now():Wr.indexOf(e.keyCode)<0&&(t.inputState.lastEscPress=0)};let _r=0;function Er(t,e,i,s){if(1==s)return Gt.cursor(e,i);if(2==s)return function(t,e,i=1){let s=t.charCategorizer(e),r=t.doc.lineAt(e),n=e-r.from;if(0==r.length)return Gt.cursor(e);0==n?i=1:n==r.length&&(i=-1);let h=n,o=n;i<0?h=Qt(r.text,n,!1):o=Qt(r.text,n);let l=s(r.text.slice(h,o));for(;h>0;){let t=Qt(r.text,h,!1);if(s(r.text.slice(t,h))!=l)break;h=t}for(;o{_r=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},Mr.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},Mr.mousedown=(t,e)=>{if(t.observer.flush(),_r>Date.now()-2e3&&1==Hr(e))return;let i=null;for(let s of t.state.facet(Ss))if(i=s(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=Gr(t,e),s=Hr(e),r=t.state.selection,n=i,h=e;return{update(t){t.docChanged&&(i&&(i.pos=t.changes.mapPos(i.pos)),r=r.map(t.changes),h=null)},get(e,o,l){let u;if(h&&e.clientX==h.clientX&&e.clientY==h.clientY?u=n:(u=n=Gr(t,e),h=e),!u||!i)return r;let a=Er(t,u.pos,u.bias,s);if(i.pos!=u.pos&&!o){let e=Er(t,i.pos,i.bias,s),r=Math.min(e.from,a.from),n=Math.max(e.to,a.to);a=rIi(t.contentDOM))),t.inputState.startMouseSelection(new Yr(t,e,i,s))}};let Ar=(t,e)=>t>=e.top&&t<=e.bottom,jr=(t,e,i)=>Ar(e,i)&&t>=i.left&&t<=i.right;function Ur(t,e,i,s){let r=xs.find(t.docView,e);if(!r)return 1;let n=e-r.posAtStart;if(0==n)return 1;if(n==r.length)return-1;let h=r.coordsAt(n,-1);if(h&&jr(i,s,h))return-1;let o=r.coordsAt(n,1);return o&&jr(i,s,o)?1:h&&Ar(s,h)?-1:1}function Gr(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:i,bias:Ur(t,i,e.clientX,e.clientY)}}const Vr=Li.ie&&Li.ie_version<=11;let Cr=null,Dr=0,zr=0;function Hr(t){if(!Vr)return t.detail;let e=Cr,i=zr;return Cr=t,zr=Date.now(),Dr=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Dr+1)%3:1}function Nr(t,e,i,s){if(!i)return;let r=t.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:n}=t.inputState,h=s&&n&&n.dragging&&n.dragMove?{from:n.dragging.from,to:n.dragging.to}:null,o={from:r,insert:i},l=t.state.changes(h?[h,o]:o);t.focus(),t.dispatch({changes:l,selection:{anchor:l.mapPos(r,-1),head:l.mapPos(r,1)},userEvent:h?"move.drop":"input.drop"})}Mr.dragstart=(t,e)=>{let{selection:{main:i}}=t.state,{mouseSelection:s}=t.inputState;s&&(s.dragging=i),e.dataTransfer&&(e.dataTransfer.setData("Text",t.state.sliceDoc(i.from,i.to)),e.dataTransfer.effectAllowed="copyMove")},Mr.drop=(t,e)=>{if(!e.dataTransfer)return;if(t.state.readOnly)return e.preventDefault();let i=e.dataTransfer.files;if(i&&i.length){e.preventDefault();let s=Array(i.length),r=0,n=()=>{++r==i.length&&Nr(t,e,s.filter((t=>null!=t)).join(t.state.lineBreak),!1)};for(let t=0;t{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(s[t]=e.result),n()},e.readAsText(i[t])}}else Nr(t,e,e.dataTransfer.getData("Text"),!0)},Mr.paste=(t,e)=>{if(t.state.readOnly)return e.preventDefault();t.observer.flush();let i=Zr?null:e.clipboardData;i?(Tr(t,i.getData("text/plain")),e.preventDefault()):function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout((()=>{t.focus(),i.remove(),Tr(t,i.value)}),50)}(t)};let Fr=null;function Br(t){setTimeout((()=>{t.hasFocus!=t.inputState.notifiedFocused&&t.update([])}),10)}function Lr(t,e){if(t.docView.compositionDeco.size){t.inputState.rapidCompositionStart=e;try{t.update([])}finally{t.inputState.rapidCompositionStart=!1}}}Mr.copy=Mr.cut=(t,e)=>{let{text:i,ranges:s,linewise:r}=function(t){let e=[],i=[],s=!1;for(let s of t.selection.ranges)s.empty||(e.push(t.sliceDoc(s.from,s.to)),i.push(s));if(!e.length){let r=-1;for(let{from:s}of t.selection.ranges){let n=t.doc.lineAt(s);n.number>r&&(e.push(n.text),i.push({from:n.from,to:Math.min(t.doc.length,n.to+1)})),r=n.number}s=!0}return{text:e.join(t.lineBreak),ranges:i,linewise:s}}(t.state);if(!i&&!r)return;Fr=r?i:null;let n=Zr?null:e.clipboardData;n?(e.preventDefault(),n.clearData(),n.setData("text/plain",i)):function(t,e){let i=t.dom.parentNode;if(!i)return;let s=i.appendChild(document.createElement("textarea"));s.style.cssText="position: fixed; left: -10000px; top: 10px",s.value=e,s.focus(),s.selectionEnd=e.length,s.selectionStart=0,setTimeout((()=>{s.remove(),t.focus()}),50)}(t,i),"cut"!=e.type||t.state.readOnly||t.dispatch({changes:s,scrollIntoView:!0,userEvent:"delete.cut"})},Mr.focus=Br,Mr.blur=t=>{t.observer.clearSelectionRange(),Br(t)},Mr.compositionstart=Mr.compositionupdate=t=>{null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0,t.docView.compositionDeco.size&&(t.observer.flush(),Lr(t,!0)))},Mr.compositionend=t=>{t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionFirstChange=null,setTimeout((()=>{t.inputState.composing<0&&Lr(t,!1)}),50)},Mr.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},Mr.beforeinput=(t,e)=>{var i;let s;if(Li.chrome&&Li.android&&(s=Rr.find((t=>t.inputType==e.inputType)))&&(t.observer.delayAndroidKey(s.key,s.keyCode),"Backspace"==s.key||"Delete"==s.key)){let e=(null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0;setTimeout((()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())}),100)}};const Kr=["pre-wrap","normal","pre-line","break-spaces"];class Jr{constructor(){this.doc=ft.empty,this.lineWrapping=!1,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength)),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Kr.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i-1,h=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=n;if(this.lineWrapping=n,this.lineHeight=e,this.charWidth=i,this.lineLength=s,h){this.heightSamples={};for(let t=0;t0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>rn&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return nn.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let r=this;for(let n=s.length-1;n>=0;n--){let{fromA:h,toA:o,fromB:l,toB:u}=s[n],a=r.lineAt(h,sn.ByPosNoHeight,e,0,0),f=a.to>=o?a:r.lineAt(o,sn.ByPosNoHeight,e,0,0);for(u+=f.to-o,o=f.to;n>0&&a.from<=s[n-1].toA;)h=s[n-1].fromA,l=s[n-1].fromB,n--,h2*r){let r=t[e-1];r.break?t.splice(--e,1,r.left,null,r.right):t.splice(--e,1,r.left,r.right),i+=1+r.break,s-=r.size}else{if(!(r>2*s))break;{let e=t[i];e.break?t.splice(i,1,e.left,null,e.right):t.splice(i,1,e.left,e.right),i+=2+e.break,r-=e.size}}else if(s=r&&n(this.blockAt(0,i,s,r))}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setHeight(t,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class on extends hn{constructor(t,e){super(t,e,Os.Text),this.collapsed=0,this.widgetHeight=0}replace(t,e,i){let s=i[0];return 1==i.length&&(s instanceof on||s instanceof ln&&4&s.flags)&&Math.abs(this.length-s.length)<10?(s instanceof ln?s=new on(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):nn.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setHeight(t,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ln extends nn{constructor(t){super(t,0)}lines(t,e){let i=t.lineAt(e).number,s=t.lineAt(e+this.length).number;return{firstLine:i,lastLine:s,lineHeight:this.height/(s-i+1)}}blockAt(t,e,i,s){let{firstLine:r,lastLine:n,lineHeight:h}=this.lines(e,s),o=Math.max(0,Math.min(n-r,Math.floor((t-i)/h))),{from:l,length:u}=e.line(r+o);return new en(l,u,i+h*o,h,Os.Text)}lineAt(t,e,i,s,r){if(e==sn.ByHeight)return this.blockAt(t,i,s,r);if(e==sn.ByPosNoHeight){let{from:e,to:s}=i.lineAt(t);return new en(e,s-e,0,0,Os.Text)}let{firstLine:n,lineHeight:h}=this.lines(i,r),{from:o,length:l,number:u}=i.lineAt(t);return new en(o,l,s+h*(u-n),h,Os.Text)}forEachLine(t,e,i,s,r,n){let{firstLine:h,lineHeight:o}=this.lines(i,r);for(let l=Math.max(t,r),u=Math.min(r+this.length,e);l<=u;){let e=i.lineAt(l);l==t&&(s+=o*(e.number-h)),n(new en(e.from,e.length,s,o,Os.Text)),s+=o,l=e.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let t=i[i.length-1];t instanceof ln?i[i.length-1]=new ln(t.length+s):i.push(null,new ln(s-1))}if(t>0){let e=i[0];e instanceof ln?i[0]=new ln(t+e.length):i.unshift(new ln(t-1),null)}return nn.of(i)}decomposeLeft(t,e){e.push(new ln(t-1),null)}decomposeRight(t,e){e.push(null,new ln(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let i=[],n=Math.max(e,s.from),h=-1,o=t.heightChanged;for(s.from>e&&i.push(new ln(s.from-e-1).updateHeight(t,e));n<=r&&s.more;){let e=t.doc.lineAt(n).length;i.length&&i.push(null);let r=s.heights[s.index++];-1==h?h=r:Math.abs(r-h)>=rn&&(h=-2);let o=new on(e,r);o.outdated=!1,i.push(o),n+=e+1}n<=r&&i.push(null,new ln(r-n).updateHeight(t,n));let l=nn.of(i);return t.heightChanged=o||h<0||Math.abs(l.height-this.height)>=rn||Math.abs(h-this.lines(t.doc,e).lineHeight)>=rn,l}return(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class un extends nn{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return 1&this.flags}blockAt(t,e,i,s){let r=i+this.left.height;return th))return l;let u=e==sn.ByPosNoHeight?sn.ByPosNoHeight:sn.ByPos;return o?l.join(this.right.lineAt(h,u,i,n,h)):this.left.lineAt(h,u,i,s,r).join(l)}forEachLine(t,e,i,s,r,n){let h=s+this.left.height,o=r+this.left.length+this.break;if(this.break)t=o&&this.right.forEachLine(t,e,i,h,o,n);else{let l=this.lineAt(o,sn.ByPos,i,s,r);t=t&&l.from<=e&&n(l),e>l.to&&this.right.forEachLine(l.to+1,e,i,h,o,n)}}replace(t,e,i){let s=this.left.length+this.break;if(ethis.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let r=[];t>0&&this.decomposeLeft(t,r);let n=r.length;for(let t of i)r.push(t);if(t>0&&an(r,n-1),e=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t2*e.size||e.size>2*t.size?nn.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=t.height+e.height,this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:r,right:n}=this,h=e+r.length+this.break,o=null;return s&&s.from<=e+r.length&&s.more?o=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=h+n.length&&s.more?o=n=n.updateHeight(t,h,i,s):n.updateHeight(t,h,i),o?this.balanced(r,n):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function an(t,e){let i,s;null==t[e]&&(i=t[e-1])instanceof ln&&(s=t[e+1])instanceof ln&&t.splice(e-1,3,new ln(i.length+1+s.length))}class fn{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof on?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new on(t-this.pos,-1)),this.writtenTo=t,e>t&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t=5)&&this.addLineDeco(s,r)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTot&&this.nodes.push(new on(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new ln(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 on)return t;let e=new on(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine(),t.type!=Os.WidgetAfter||this.isCovered||this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,t.type!=Os.WidgetBefore&&(this.covering=t)}addLineDeco(t,e){let i=this.ensureLine();i.length+=e,i.collapsed+=e,i.widgetHeight=Math.max(i.widgetHeight,t),this.writtenTo=this.pos=this.pos+e}finish(t){let e=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof on||this.isCovered?(this.writtenTot.clientHeight||t.scrollWidth>t.clientWidth)&&"visible"!=i.overflow){let e=t.getBoundingClientRect();s=Math.max(s,e.left),r=Math.min(r,e.right),n=Math.max(n,e.top),h=Math.min(h,e.bottom)}e="absolute"==i.position||"fixed"==i.position?t.offsetParent:t.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:s-i.left,right:Math.max(s,r)-i.left,top:n-(i.top+e),bottom:Math.max(n,h)-(i.top+e)}}function dn(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class $n{constructor(t,e,i){this.from=t,this.to=e,this.size=i}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i"function"!=typeof t)),this.heightMap=nn.empty().applyChanges(this.stateDeco,ft.empty,this.heightOracle.setDoc(t.doc),[new zs(0,0,0,t.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ds.set(this.lineGaps.map((t=>t.draw(!1)))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some((({from:t,to:e})=>s>=t&&s<=e))){let{from:e,to:i}=this.lineBlockAt(s);t.push(new wn(e,i))}}this.viewports=t.sort(((t,e)=>t.from-e.from)),this.scaler=this.heightMap.height<=7e6?Pn:new vn(this.heightOracle.doc,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.state.doc,0,0,(t=>{this.viewportLines.push(1==this.scaler.scale?t:qn(t,this.scaler))}))}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Gs).filter((t=>"function"!=typeof t));let s=t.changedRanges,r=zs.extendWithRanges(s,function(t,e,i){let s=new cn;return Ae.compare(t,e,i,s,0),s.changes}(i,this.stateDeco,t?t.changes:Mt.empty(this.state.doc.length))),n=this.heightMap.height;this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=n&&(t.flags|=2);let h=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.headh.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,e));let o=!t.changes.empty||2&t.flags||h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,this.updateForViewport(),o&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?Ns.RTL:Ns.LTR;let n=this.heightOracle.mustRefreshForWrapping(r),h=n||this.mustMeasureContent||this.contentDOMHeight!=e.clientHeight;this.contentDOMHeight=e.clientHeight,this.mustMeasureContent=!1;let o=0,l=0,u=parseInt(i.paddingTop)||0,a=parseInt(i.paddingBottom)||0;this.paddingTop==u&&this.paddingBottom==a||(this.paddingTop=u,this.paddingBottom=a,o|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(h=!0),this.editorWidth=t.scrollDOM.clientWidth,o|=8);let f=(this.printing?dn:On)(e,this.paddingTop),c=f.top-this.pixelViewport.top,O=f.bottom-this.pixelViewport.bottom;this.pixelViewport=f;let d=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(d!=this.inView&&(this.inView=d,d&&(h=!0)),!this.inView)return 0;let $=e.clientWidth;if(this.contentDOMWidth==$&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=$,this.editorHeight=t.scrollDOM.clientHeight,o|=8),h){let e=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(e)&&(n=!0),n||s.lineWrapping&&Math.abs($-this.contentDOMWidth)>s.charWidth){let{lineHeight:i,charWidth:h}=t.docView.measureTextSize();n=s.refresh(r,i,h,$/h,e),n&&(t.docView.minWidth=0,o|=8)}c>0&&O>0?l=Math.max(c,O):c<0&&O<0&&(l=Math.min(c,O)),s.heightChanged=!1;for(let i of this.viewports){let r=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=this.heightMap.updateHeight(s,0,n,new tn(i.from,r))}s.heightChanged&&(o|=2)}let p=!this.viewportIsAppropriate(this.viewport,l)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return p&&(this.viewport=this.getViewport(l,this.scrollTarget)),this.updateForViewport(),(2&o||p)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(n?[]:this.lineGaps)),o|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),o}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,r=this.state.doc,{visibleTop:n,visibleBottom:h}=this,o=new wn(s.lineAt(n-1e3*i,sn.ByHeight,r,0,0).from,s.lineAt(h+1e3*(1-i),sn.ByHeight,r,0,0).to);if(e){let{head:t}=e.range;if(to.to){let i,n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),h=s.lineAt(t,sn.ByPos,r,0,0);i="center"==e.y?(h.top+h.bottom)/2-n/2:"start"==e.y||"nearest"==e.y&&t=h+Math.max(10,Math.min(i,250)))&&s>n-2e3&&ri.from&&h.push({from:i.from,to:s}),r=i.from&&o.from<=i.to&&yn(h,o.from-10,o.from+10),!o.empty&&o.to>=i.from&&o.to<=i.to&&yn(h,o.to-10,o.to+10);for(let{from:s,to:r}of h)r-s>1e3&&e.push(Qn(t,(t=>t.from>=i.from&&t.to<=i.to&&Math.abs(t.from-s)<1e3&&Math.abs(t.to-r)<1e3))||new $n(s,r,this.gapSize(i,s,r,n)))}return e}gapSize(t,e,i,s){let r=bn(s,i)-bn(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){$n.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=ds.set(t.map((t=>t.draw(this.heightOracle.lineWrapping)))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];Ae.spans(t,this.viewport.from,this.viewport.to,{span(t,i){e.push({from:t,to:i})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some(((t,i)=>t.from!=e[i].from||t.to!=e[i].to));return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find((e=>e.from<=t&&e.to>=t))||qn(this.heightMap.lineAt(t,sn.ByPos,this.state.doc,0,0),this.scaler)}lineBlockAtHeight(t){return qn(this.heightMap.lineAt(this.scaler.fromDOM(t),sn.ByHeight,this.state.doc,0,0),this.scaler)}elementAtHeight(t){return qn(this.heightMap.blockAt(this.scaler.fromDOM(t),this.state.doc,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class wn{constructor(t,e){this.from=t,this.to=e}}function gn(t,e,i){let s=[],r=t,n=0;return Ae.spans(i,t,e,{span(){},point(t,e){t>r&&(s.push({from:r,to:t}),n+=t-r),r=e}},20),r=1)return e[e.length-1].to;let s=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:r}=e[t],n=r-i;if(s<=n)return i+s;s-=n}}function bn(t,e){let i=0;for(let{from:s,to:r}of t.ranges){if(e<=r){i+=e-s;break}i+=r-s}return i/t.total}function yn(t,e,i){for(let s=0;se){let n=[];r.fromi&&n.push({from:i,to:r.to}),t.splice(s,1,...n),s+=n.length-1}}}function Qn(t,e){for(let i of t)if(e(i))return i}const Pn={toDOM:t=>t,fromDOM:t=>t,scale:1};class vn{constructor(t,e,i){let s=0,r=0,n=0;this.viewports=i.map((({from:i,to:r})=>{let n=e.lineAt(i,sn.ByPos,t,0,0).top,h=e.lineAt(r,sn.ByPos,t,0,0).bottom;return s+=h-n,{from:i,to:r,top:n,bottom:h,domTop:0,domBottom:0}})),this.scale=(7e6-s)/(e.height-s);for(let t of this.viewports)t.domTop=n+(t.top-r)*this.scale,n=t.domBottom=t.domTop+(t.bottom-t.top),r=t.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let r=eqn(t,e))):t.type)}const Sn=Dt.define({combine:t=>t.join(" ")}),kn=Dt.define({combine:t=>t.indexOf(!0)>-1}),In=ii.newName(),Rn=ii.newName(),Wn=ii.newName(),Yn={"&light":"."+Rn,"&dark":"."+Wn};function Xn(t,e,i){return new ii(e,{finish:e=>/&/.test(e)?e.replace(/&\w*/,(e=>{if("&"==e)return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]})):t+" "+e})}const Mn=Xn("."+In,{"&.cm-editor":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,minHeight:"100%",display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 4px"},".cm-selectionLayer":{zIndex:-1,contain:"size style"},".cm-selectionBackground":{position:"absolute"},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{zIndex:100,contain:"size style",pointerEvents:"none"},"&.cm-focused .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{visibility:"hidden"},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{visibility:"hidden"},"100%":{}},".cm-cursor, .cm-dropCursor":{position:"absolute",borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},"&.cm-focused .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#f3f9ff"},"&dark .cm-activeLine":{backgroundColor:"#223039"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{display:"flex",height:"100%",boxSizing:"border-box",left:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".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"}},Yn),Zn={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Tn=Li.ie&&Li.ie_version<=11;class _n{constructor(t,e,i){this.view=t,this.onChange=e,this.onScrollChanged=i,this.active=!1,this.selectionRange=new qi,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.scrollTargets=[],this.intersection=null,this.resize=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver((e=>{for(let t of e)this.queue.push(t);(Li.ie&&Li.ie_version<=11||Li.ios&&t.composing)&&e.some((t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():this.flush()})),Tn&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),window.addEventListener("resize",this.onResize=this.onResize.bind(this)),"function"==typeof ResizeObserver&&(this.resize=new ResizeObserver((()=>{this.view.docView.lastUpdate{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))}),{}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver((t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))}),{})),this.listenForScroll(),this.readSelectionRange(),this.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}onScroll(t){this.intersecting&&this.flush(!1),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout((()=>{this.resizeTimeout=-1,this.view.requestMeasure()}),50))}onPrint(){this.view.viewState.printing=!0,this.view.measure(),setTimeout((()=>{this.view.viewState.printing=!1,this.view.requestMeasure()}),500)}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some(((e,i)=>e!=t[i])))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:e}=this,i=this.selectionRange;if(e.state.facet(Zs)?e.root.activeElement!=this.dom:!mi(e.dom,i))return;let s=i.anchorNode&&e.docView.nearest(i.anchorNode);s&&s.ignoreEvent(t)||((Li.ie&&Li.ie_version<=11||Li.android&&Li.chrome)&&!e.state.selection.main.empty&&i.focusNode&&gi(i.focusNode,i.focusOffset,i.anchorNode,i.anchorOffset)?this.flushSoon():this.flush(!1))}readSelectionRange(){let{root:t}=this.view,e=Li.safari&&11==t.nodeType&&function(){let t=document.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}()==this.view.contentDOM&&function(t){let e=null;function i(t){t.preventDefault(),t.stopImmediatePropagation(),e=t.getTargetRanges()[0]}if(t.contentDOM.addEventListener("beforeinput",i,!0),document.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",i,!0),!e)return null;let s=e.startContainer,r=e.startOffset,n=e.endContainer,h=e.endOffset,o=t.docView.domAtPos(t.state.selection.main.anchor);return gi(o.node,o.offset,n,h)&&([s,r,n,h]=[n,h,s,r]),{anchorNode:s,anchorOffset:r,focusNode:n,focusOffset:h}}(this.view)||$i(t);return!(!e||this.selectionRange.eq(e))&&(this.selectionRange.setRange(e),this.selectionChanged=!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(1==i.nodeType)!e&&t{let t=this.delayedAndroidKey;this.delayedAndroidKey=null,this.delayedFlush=-1,this.flush()||Wi(this.view.contentDOM,t.key,t.keyCode)})),this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e})}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=window.setTimeout((()=>{this.delayedFlush=-1,this.flush()}),20))}forceFlush(){this.delayedFlush>=0&&(window.clearTimeout(this.delayedFlush),this.delayedFlush=-1,this.flush())}processRecords(){let t=this.queue;for(let e of this.observer.takeRecords())t.push(e);t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let r of t){let t=this.readMutation(r);t&&(t.typeOver&&(s=!0),-1==e?({from:e,to:i}=t):(e=Math.min(t.from,e),i=Math.max(t.to,i)))}return{from:e,to:i,typeOver:s}}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return;t&&this.readSelectionRange();let{from:e,to:i,typeOver:s}=this.processRecords(),r=this.selectionChanged&&mi(this.dom,this.selectionRange);if(e<0&&!r)return;this.selectionChanged=!1;let n=this.view.state,h=this.onChange(e,i,s);return this.view.state==n&&this.view.update([]),h}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty("attributes"==t.type),"attributes"==t.type&&(e.dirty|=4),"childList"==t.type){let i=En(e,t.previousSibling||t.target.previousSibling,-1),s=En(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resize)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);window.removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onResize),window.removeEventListener("beforeprint",this.onPrint),this.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout)}}function En(t,e,i){for(;e;){let s=Zi.get(e);if(s&&s.parent==t)return s;let r=e.parentNode;e=r!=t.dom?r:i>0?e.nextSibling:e.previousSibling}return null}function An(t,e,i,s){let r,n,h=t.state.selection.main;if(e>-1){let s=t.docView.domBoundsAround(e,i,0);if(!s||t.state.readOnly)return!1;let{from:o,to:l}=s,u=t.docView.impreciseHead||t.docView.impreciseAnchor?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}=t.observer.selectionRange;return i&&(e.push(new fr(i,s)),r==i&&n==s||e.push(new fr(r,n))),e}(t),a=new ur(u,t.state);a.readRange(s.startDOM,s.endDOM);let f=h.from,c=null;(8===t.inputState.lastKeyCode&&t.inputState.lastKeyTime>Date.now()-100||Li.android&&a.text.length0&&o>0&&t.charCodeAt(h-1)==e.charCodeAt(o-1);)h--,o--;return"end"==s&&(i-=h+Math.max(0,n-Math.min(h,o))-n),h=h?n-i:0,o=n+(o-h),h=n):o=o?n-i:0,h=n+(h-o),o=n),{from:n,toA:h,toB:o}}(t.state.doc.sliceString(o,l,lr),a.text,f-o,c);O&&(Li.chrome&&13==t.inputState.lastKeyCode&&O.toB==O.from+2&&a.text.slice(O.from,O.toB)==lr+lr&&O.toB--,r={from:o+O.from,to:o+O.toA,insert:ft.of(a.text.slice(O.from,O.toB).split(lr))}),n=function(t,e){if(0==t.length)return null;let i=t[0].pos,s=2==t.length?t[1].pos:i;return i>-1&&s>-1?Gt.single(i+e,s+e):null}(u,o)}else if(t.hasFocus||!t.state.facet(Zs)){let e=t.observer.selectionRange,{impreciseHead:i,impreciseAnchor:s}=t.docView,r=i&&i.node==e.focusNode&&i.offset==e.focusOffset||!pi(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),o=s&&s.node==e.anchorNode&&s.offset==e.anchorOffset||!pi(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset);r==h.head&&o==h.anchor||(n=Gt.single(o,r))}if(!r&&!n)return!1;if(!r&&s&&!h.empty&&n&&n.main.empty?r={from:h.from,to:h.to,insert:t.state.doc.slice(h.from,h.to)}:r&&r.from>=h.from&&r.to<=h.to&&(r.from!=h.from||r.to!=h.to)&&h.to-h.from-(r.to-r.from)<=4?r={from:h.from,to:h.to,insert:t.state.doc.slice(h.from,r.from).append(r.insert).append(t.state.doc.slice(r.to,h.to))}:(Li.mac||Li.android)&&r&&r.from==r.to&&r.from==h.head-1&&"."==r.insert.toString()&&(r={from:h.from,to:h.to,insert:ft.of([" "])}),r){let e=t.state;if(Li.ios&&t.inputState.flushIOSKey(t))return!0;if(Li.android&&(r.from==h.from&&r.to==h.to&&1==r.insert.length&&2==r.insert.lines&&Wi(t.contentDOM,"Enter",13)||r.from==h.from-1&&r.to==h.to&&0==r.insert.length&&Wi(t.contentDOM,"Backspace",8)||r.from==h.from&&r.to==h.to+1&&0==r.insert.length&&Wi(t.contentDOM,"Delete",46)))return!0;let i,s=r.insert.toString();if(t.state.facet(Rs).some((e=>e(t,r.from,r.to,s))))return!0;if(t.inputState.composing>=0&&t.inputState.composing++,r.from>=h.from&&r.to<=h.to&&r.to-r.from>=(h.to-h.from)/3&&(!n||n.main.empty&&n.main.from==r.from+r.insert.length)&&t.inputState.composing<0){let s=h.fromr.to?e.sliceDoc(r.to,h.to):"";i=e.replaceSelection(t.state.toText(s+r.insert.sliceString(0,void 0,t.state.lineBreak)+n))}else{let s=e.changes(r),o=n&&!e.selection.main.eq(n.main)&&n.main.to<=s.newLength?n.main:void 0;if(e.selection.ranges.length>1&&t.inputState.composing>=0&&r.to<=h.to&&r.to>=h.to-10){let n=t.state.sliceDoc(r.from,r.to),l=dr(t)||t.state.doc.lineAt(h.head),u=h.to-r.to,a=h.to-h.from;i=e.changeByRange((i=>{if(i.from==h.from&&i.to==h.to)return{changes:s,range:o||i.map(s)};let f=i.to-u,c=f-n.length;if(i.to-i.from!=a||t.state.sliceDoc(c,f)!=n||l&&i.to>=l.from&&i.from<=l.to)return{range:i};let O=e.changes({from:c,to:f,insert:r.insert}),d=i.to-h.to;return{changes:O,range:o?Gt.range(Math.max(0,o.anchor+d),Math.max(0,o.head+d)):i.map(O)}}))}else i={changes:s,selection:o&&e.selection.replaceRange(o)}}let o="input.type";return t.composing&&(o+=".compose",t.inputState.compositionFirstChange&&(o+=".start",t.inputState.compositionFirstChange=!1)),t.dispatch(i,{scrollIntoView:!0,userEvent:o}),!0}if(n&&!n.main.eq(h)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin),t.dispatch({selection:n,scrollIntoView:e,userEvent:i}),!0}return!1}class jn{constructor(t={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.style.cssText="position: absolute; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),this._dispatch=t.dispatch||(t=>this.update([t])),this.dispatch=this.dispatch.bind(this),this.root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new mn(t.state||Xe.create(t)),this.plugins=this.state.facet(_s).map((t=>new As(t)));for(let t of this.plugins)t.update(this);this.observer=new _n(this,((t,e,i)=>An(this,t,e,i)),(t=>{this.inputState.runScrollHandlers(this,t),this.observer.intersecting&&this.measure()})),this.inputState=new Ir(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new cr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),t.parent&&t.parent.appendChild(this.dom)}get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}dispatch(...t){this._dispatch(1==t.length&&t[0]instanceof ye?t[0]:this.state.update(...t))}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,s=!1,r=this.state;for(let e of t){if(e.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=e.state}if(this.destroyed)return void(this.viewState.state=r);if(this.observer.clear(),r.facet(Xe.phrases)!=this.state.facet(Xe.phrases))return this.setState(r);e=Hs.create(this,r,t);let n=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(n&&(n=n.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection;n=new Ys(t.empty?t:Gt.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(Xs)&&(n=t.value)}this.viewState.update(e,n),this.bidiCache=Vn.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(Ds)!=this.styleModules&&this.mountStyles(),s=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some((t=>t.isUserEvent("select.pointer"))))}finally{this.updateState=0}if(e.startState.facet(Sn)!=e.state.facet(Sn)&&(this.viewState.mustMeasureContent=!0),(i||s||n||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!e.empty)for(let t of this.state.facet(Is))t(e)}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new mn(t),this.plugins=t.facet(_s).map((t=>new As(t))),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView=new cr(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(_s),i=t.state.facet(_s);if(e!=i){let s=[];for(let r of i){let i=e.indexOf(r);if(i<0)s.push(new As(r));else{let e=this.plugins[i];e.mustUpdate=t,s.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=s,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t-1&&cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,t&&this.observer.flush();let e=null;try{for(let t=0;;t++){this.updateState=1;let i=this.viewport,s=this.viewState.measure(this);if(!s&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let r=[];4&s||([this.measureRequests,r]=[r,this.measureRequests]);let n=r.map((t=>{try{return t.read(this)}catch(t){return Ms(this.state,t),Gn}})),h=Hs.create(this,this.state,[]),o=!1,l=!1;h.flags|=s,e?e.flags|=s:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),o=this.docView.update(h));for(let t=0;t{let i=fs(this.contentDOM,this.contentAttrs,e),s=fs(this.dom,this.editorAttrs,t);return i||s}));return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)t.is(jn.announce)&&(e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value)}mountStyles(){this.styleModules=this.state.facet(Ds),ii.mount(this.root,this.styleModules.concat(Mn).reverse())}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=requestAnimationFrame((()=>this.measure()))),t){if(null!=t.key)for(let e=0;ee.spec==t))||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return kr(this,t,Sr(this,t,e,i))}moveByGroup(t,e){return kr(this,t,Sr(this,t,e,(e=>function(t,e,i){let s=t.state.charCategorizer(e),r=s(i);return t=>{let e=s(t);return r==Ie.Space&&(r=e),r==e}}(this,t.head,e))))}moveToLineBoundary(t,e,i=!0){return function(t,e,i,s){let r=t.state.doc.lineAt(e.head),n=s&&t.lineWrapping?t.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head):null;if(n){let e=t.dom.getBoundingClientRect(),s=t.textDirectionAt(r.from),h=t.posAtCoords({x:i==(s==Ns.LTR)?e.right-1:e.left+1,y:(n.top+n.bottom)/2});if(null!=h)return Gt.cursor(h,i?-1:1)}let h=xs.find(t.docView,e.head),o=h?i?h.posAtEnd:h.posAtStart:i?r.to:r.from;return Gt.cursor(o,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return kr(this,t,function(t,e,i,s){let r=e.head,n=i?1:-1;if(r==(i?t.state.doc.length:0))return Gt.cursor(r,e.assoc);let h,o=e.goalColumn,l=t.contentDOM.getBoundingClientRect(),u=t.coordsAtPos(r),a=t.documentTop;if(u)null==o&&(o=u.left-l.left),h=n<0?u.top:u.bottom;else{let e=t.viewState.lineBlockAt(r);null==o&&(o=Math.min(l.right-l.left,t.defaultCharacterWidth*(r-e.from))),h=(n<0?e.top:e.bottom)+a}let f=l.left+o,c=null!=s?s:t.defaultLineHeight>>1;for(let i=0;;i+=10){let s=h+(c+i)*n,u=vr(t,{x:f,y:s},!1,n);if(sl.bottom||(n<0?ur))return Gt.cursor(u,e.assoc,void 0,o)}}(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),vr(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),r=this.bidiSpans(s);return Pi(i,r[sr.find(r,t-s.from,-1,e)].dir==Ns.LTR==e>0)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Ws)||tthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>Un)return nr(t.length);let e=this.textDirectionAt(t.from);for(let i of this.bidiCache)if(i.from==t.from&&i.dir==e)return i.order;let i=function(t,e){let i=t.length,s=e==Fs?1:2,r=e==Fs?2:1;if(!t||1==s&&!ir.test(t))return nr(i);for(let e=0,r=s,h=s;e=0;t-=3)if(er[t+1]==-n){let e=er[t+2],i=2&e?s:4&e?1&e?r:s:0;i&&(rr[o]=rr[er[t]]=i),l=t;break}}else{if(189==er.length)break;er[l++]=o,er[l++]=e,er[l++]=u}else if(2==(h=rr[o])||1==h){let t=h==s;u=t?0:1;for(let e=l-3;e>=0;e-=3){let i=er[e+2];if(2&i)break;if(t)er[e+2]|=2;else{if(4&i)break;er[e+2]|=4}}}for(let t=0;te;){let t=i,s=2!=rr[--i];for(;i>e&&s==(2!=rr[i-1]);)i--;h.push(new sr(i,t,s?2:1))}else h.push(new sr(e,t,0))}else for(let t=0;tDate.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore((()=>{Ii(this.contentDOM),this.docView.updateSelection()}))}destroy(){for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return Xs.of(new Ys("number"==typeof t?Gt.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}static domEventHandlers(t){return Es.define((()=>({})),{eventHandlers:t})}static theme(t,e){let i=ii.newName(),s=[Sn.of(i),Ds.of(Xn(`.${i}`,t))];return e&&e.dark&&s.push(kn.of(!0)),s}static baseTheme(t){return re.lowest(Ds.of(Xn("."+In,t,Yn)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&Zi.get(i)||Zi.get(t);return(null===(e=null==s?void 0:s.rootView)||void 0===e?void 0:e.view)||null}}jn.styleModule=Ds,jn.inputHandler=Rs,jn.perLineTextDirection=Ws,jn.exceptionSink=ks,jn.updateListener=Is,jn.editable=Zs,jn.mouseSelectionStyle=Ss,jn.dragMovesSelection=qs,jn.clickAddsSelectionRange=vs,jn.decorations=Gs,jn.atomicRanges=Vs,jn.scrollMargins=Cs,jn.darkTheme=kn,jn.contentAttributes=Us,jn.editorAttributes=js,jn.lineWrapping=jn.contentAttributes.of({class:"cm-lineWrapping"}),jn.announce=be.define();const Un=4096,Gn={};class Vn{constructor(t,e,i,s){this.from=t,this.to=e,this.dir=i,this.order=s}static update(t,e){if(e.empty)return t;let i=[],s=t.length?t[t.length-1].dir:Ns.LTR;for(let r=Math.max(0,t.length-10);r=0;r--){let e=s[r],n="function"==typeof e?e(t):e;n&&us(n,i)}return i}const Dn=Li.mac?"mac":Li.windows?"win":Li.linux?"linux":"key";function zn(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),!1!==i&&e.shiftKey&&(t="Shift-"+t),t}const Hn=jn.domEventHandlers({keydown:(t,e)=>Jn(Bn(e.state),t,e,"editor")}),Nn=Dt.define({enables:Hn}),Fn=new WeakMap;function Bn(t){let e=t.facet(Nn),i=Fn.get(e);return i||Fn.set(e,i=function(t,e=Dn){let i=Object.create(null),s=Object.create(null),r=(t,e)=>{let i=s[t];if(null==i)s[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")},n=(t,s,n,h)=>{let o=i[t]||(i[t]=Object.create(null)),l=s.split(/ (?!$)/).map((t=>function(t,e){const i=t.split(/-(?!$)/);let s,r,n,h,o=i[i.length-1];"Space"==o&&(o=" ");for(let t=0;t{let s=Ln={view:e,prefix:i,scope:t};return setTimeout((()=>{Ln==s&&(Ln=null)}),Kn),!0}]})}let u=l.join(" ");r(u,!1);let a=o[u]||(o[u]={preventDefault:!1,commands:[]});a.commands.push(n),h&&(a.preventDefault=!0)};for(let i of t){let t=i[e]||i.key;if(t)for(let e of i.scope?i.scope.split(" "):["editor"])n(e,t,i.run,i.preventDefault),i.shift&&n(e,"Shift-"+t,i.shift,i.preventDefault)}return i}(e.reduce(((t,e)=>t.concat(e)),[]))),i}let Ln=null;const Kn=4e3;function Jn(t,e,i,s){let r=function(t){var e=!(ci&&(t.ctrlKey||t.altKey||t.metaKey)||(li||fi)&&t.shiftKey&&t.key&&1==t.key.length)&&t.key||(t.shiftKey?hi:ni)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(e),n=kt(r,0),h=Rt(n)==r.length&&" "!=r,o="",l=!1;Ln&&Ln.view==i&&Ln.scope==s&&(o=Ln.prefix+" ",(l=Wr.indexOf(e.keyCode)<0)&&(Ln=null));let u,a=t=>{if(t){for(let e of t.commands)if(e(i))return!0;t.preventDefault&&(l=!0)}return!1},f=t[s];if(f){if(a(f[o+zn(r,e,!h)]))return!0;if(h&&(e.shiftKey||e.altKey||e.metaKey||n>127)&&(u=ni[e.keyCode])&&u!=r){if(a(f[o+zn(u,e,!0)]))return!0;if(e.shiftKey&&hi[e.keyCode]!=u&&a(f[o+zn(hi[e.keyCode],e,!1)]))return!0}else if(h&&e.shiftKey&&a(f[o+zn(r,e,!0)]))return!0}return l}const th=!Li.ios,eh=Dt.define({combine:t=>Me(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function ih(t={}){return[eh.of(t),rh,hh]}class sh{constructor(t,e,i,s,r){this.left=t,this.top=e,this.width=i,this.height=s,this.className=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width>=0&&(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}}const rh=Es.fromClass(class{constructor(t){this.view=t,this.rangePieces=[],this.cursors=[],this.measureReq={read:this.readPos.bind(this),write:this.drawSel.bind(this)},this.selectionLayer=t.scrollDOM.appendChild(document.createElement("div")),this.selectionLayer.className="cm-selectionLayer",this.selectionLayer.setAttribute("aria-hidden","true"),this.cursorLayer=t.scrollDOM.appendChild(document.createElement("div")),this.cursorLayer.className="cm-cursorLayer",this.cursorLayer.setAttribute("aria-hidden","true"),t.requestMeasure(this.measureReq),this.setBlinkRate()}setBlinkRate(){this.cursorLayer.style.animationDuration=this.view.state.facet(eh).cursorBlinkRate+"ms"}update(t){let e=t.startState.facet(eh)!=t.state.facet(eh);(e||t.selectionSet||t.geometryChanged||t.viewportChanged)&&this.view.requestMeasure(this.measureReq),t.transactions.some((t=>t.scrollIntoView))&&(this.cursorLayer.style.animationName="cm-blink"==this.cursorLayer.style.animationName?"cm-blink2":"cm-blink"),e&&this.setBlinkRate()}readPos(){let{state:t}=this.view,e=t.facet(eh),i=t.selection.ranges.map((t=>t.empty?[]:function(t,e){if(e.to<=t.viewport.from||e.from>=t.viewport.to)return[];let i=Math.max(e.from,t.viewport.from),s=Math.min(e.to,t.viewport.to),r=t.textDirection==Ns.LTR,n=t.contentDOM,h=n.getBoundingClientRect(),o=oh(t),l=window.getComputedStyle(n.firstChild),u=h.left+parseInt(l.paddingLeft)+Math.min(0,parseInt(l.textIndent)),a=h.right-parseInt(l.paddingRight),f=uh(t,i),c=uh(t,s),O=f.type==Os.Text?f:null,d=c.type==Os.Text?c:null;if(t.lineWrapping&&(O&&(O=lh(t,i,O)),d&&(d=lh(t,s,d))),O&&d&&O.from==d.from)return p(m(e.from,e.to,O));{let i=O?m(e.from,null,O):w(f,!1),s=d?m(null,e.to,d):w(c,!0),r=[];return(O||f).to<(d||c).from-1?r.push($(u,i.bottom,a,s.top)):i.bottomf&&s.from=n)break;o>r&&l(Math.max(t,r),null==e&&t<=f,Math.min(o,n),null==i&&o>=c,h.dir)}if(r=s.to+1,r>=n)break}return 0==o.length&&l(f,null==e,c,null==i,t.textDirection),{top:n,bottom:h,horizontal:o}}function w(t,e){let i=h.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(this.view,t))).reduce(((t,e)=>t.concat(e))),s=[];for(let i of t.selection.ranges){let r=i==t.selection.main;if(i.empty?!r||th:e.drawRangeCursor){let t=ah(this.view,i,r);t&&s.push(t)}}return{rangePieces:i,cursors:s}}drawSel({rangePieces:t,cursors:e}){if(t.length!=this.rangePieces.length||t.some(((t,e)=>!t.eq(this.rangePieces[e])))){this.selectionLayer.textContent="";for(let e of t)this.selectionLayer.appendChild(e.draw());this.rangePieces=t}if(e.length!=this.cursors.length||e.some(((t,e)=>!t.eq(this.cursors[e])))){let t=this.cursorLayer.children;if(t.length!==e.length){this.cursorLayer.textContent="";for(const t of e)this.cursorLayer.appendChild(t.draw())}else e.forEach(((e,i)=>e.adjust(t[i])));this.cursors=e}}destroy(){this.selectionLayer.remove(),this.cursorLayer.remove()}}),nh={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};th&&(nh[".cm-line"].caretColor="transparent !important");const hh=re.highest(jn.theme(nh));function oh(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==Ns.LTR?e.left:e.right-t.scrollDOM.clientWidth)-t.scrollDOM.scrollLeft,top:e.top-t.scrollDOM.scrollTop}}function lh(t,e,i){let s=Gt.cursor(e);return{from:Math.max(i.from,t.moveToLineBoundary(s,!1,!0).from),to:Math.min(i.to,t.moveToLineBoundary(s,!0,!0).from),type:Os.Text}}function uh(t,e){let i=t.lineBlockAt(e);if(Array.isArray(i.type))for(let t of i.type)if(t.to>e||t.to==e&&(t.to==i.to||t.type==Os.Text))return t;return i}function ah(t,e,i){let s=t.coordsAtPos(e.head,e.assoc||1);if(!s)return null;let r=oh(t);return new sh(s.left-r.left,s.top-r.top,-1,s.bottom-s.top,i?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary")}const fh=be.define({map:(t,e)=>null==t?null:e.mapPos(t)}),ch=Kt.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce(((t,e)=>e.is(fh)?e.value:t),t))}),Oh=Es.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(ch);null==i?null!=this.cursor&&(null===(e=this.cursor)||void 0===e||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(ch)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let t=this.view.state.field(ch),e=null!=t&&this.view.coordsAtPos(t);if(!e)return null;let i=this.view.scrollDOM.getBoundingClientRect();return{left:e.left-i.left+this.view.scrollDOM.scrollLeft,top:e.top-i.top+this.view.scrollDOM.scrollTop,height:e.bottom-e.top}}drawCursor(t){this.cursor&&(t?(this.cursor.style.left=t.left+"px",this.cursor.style.top=t.top+"px",this.cursor.style.height=t.height+"px"):this.cursor.style.left="-100000px")}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(ch)!=t&&this.view.dispatch({effects:fh.of(t)})}},{eventHandlers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function dh(){return[ch,Oh]}function $h(t,e,i,s,r){e.lastIndex=0;for(let n,h=t.iterRange(i,s),o=i;!h.next().done;o+=h.value.length)if(!h.lineBreak)for(;n=e.exec(h.value);)r(o+n.index,o+n.index+n[0].length,n)}class ph{constructor(t){let{regexp:e,decoration:i,boundary:s,maxLength:r=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");this.regexp=e,this.getDeco="function"==typeof i?i:()=>i,this.boundary=s,this.maxLength=r}createDeco(t){let e=new je;for(let{from:i,to:s}of function(t,e){let i=t.visibleRanges;if(1==i.length&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let s=[];for(let{from:r,to:n}of i)r=Math.max(t.state.doc.lineAt(r).from,r-e),n=Math.min(t.state.doc.lineAt(n).to,n+e),s.length&&s[s.length-1].to>=r?s[s.length-1].to=n:s.push({from:r,to:n});return s}(t,this.maxLength))$h(t.state.doc,this.regexp,i,s,((i,s,r)=>e.add(i,s,this.getDeco(r,t,i))));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges(((e,r,n,h)=>{h>t.view.viewport.from&&n1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let r of t.visibleRanges){let n=Math.max(r.from,i),h=Math.min(r.to,s);if(h>n){let i=t.state.doc.lineAt(n),s=i.toi.from;n--)if(this.boundary.test(i.text[n-1-i.from])){o=n;break}for(;ha.push(this.getDeco(s,t,e).range(e,i))));e=e.update({filterFrom:o,filterTo:l,filter:(t,e)=>tl,add:a})}}return e}}const mh=null!=/x/.unicode?"gu":"g",wh=new RegExp("[\0-\b\n--Ÿ­؜​‎‏\u2028\u2029‭‮\ufeff-]",mh),gh={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",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let xh=null;const bh=Dt.define({combine(t){let e=Me(t,{render:null,specialChars:wh,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==xh&&"undefined"!=typeof document&&document.body){let e=document.body.style;xh=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return xh||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,mh)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,mh)),e}});function yh(t={}){return[bh.of(t),Qh||(Qh=Es.fromClass(class{constructor(t){this.view=t,this.decorations=ds.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(bh)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new ph({regexp:t.specialChars,decoration:(e,i,s)=>{let{doc:r}=i.state,n=kt(e[0],0);if(9==n){let t=r.lineAt(s),e=i.state.tabSize,n=Le(t.text,e,s-t.from);return ds.replace({widget:new vh((e-n%e)*this.view.defaultCharacterWidth)})}return this.decorationCache[n]||(this.decorationCache[n]=ds.replace({widget:new Ph(t,n)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(bh);t.startState.facet(bh)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))]}let Qh=null;class Ph extends cs{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=function(t){return t>=32?"•":10==t?"␤":String.fromCharCode(9216+t)}(this.code),i=t.state.phrase("Control character")+" "+(gh[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let r=document.createElement("span");return r.textContent=e,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class vh extends cs{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}function qh(){return kh}const Sh=ds.line({class:"cm-activeLine"}),kh=Es.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let s of t.state.selection.ranges){if(!s.empty)return ds.none;let r=t.lineBlockAt(s.head);r.from>e&&(i.push(Sh.range(r.from)),e=r.from)}return ds.set(i)}},{decorations:t=>t.decorations}),Ih=2e3;function Rh(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),s=t.state.doc.lineAt(i),r=i-s.from,n=r>Ih?-1:r==s.length?function(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}(t,e.clientX):Le(s.text,t.state.tabSize,i-s.from);return{line:s.number,col:n,off:r}}function Wh(t,e){let i=Rh(t,e),s=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),r=t.state.doc.lineAt(e);i={line:r.number,col:i.col,off:Math.min(i.off,r.length)},s=s.map(t.changes)}},get(e,r,n){let h=Rh(t,e);if(!h)return s;let o=function(t,e,i){let s=Math.min(e.line,i.line),r=Math.max(e.line,i.line),n=[];if(e.off>Ih||i.off>Ih||e.col<0||i.col<0){let h=Math.min(e.off,i.off),o=Math.max(e.off,i.off);for(let e=s;e<=r;e++){let i=t.doc.line(e);i.length<=o&&n.push(Gt.range(i.from+h,i.to+o))}}else{let h=Math.min(e.col,i.col),o=Math.max(e.col,i.col);for(let e=s;e<=r;e++){let i=t.doc.line(e),s=Ke(i.text,h,t.tabSize,!0);if(s>-1){let e=Ke(i.text,o,t.tabSize);n.push(Gt.range(i.from+s,i.from+e))}}}return n}(t.state,i,h);return o.length?n?Gt.create(o.concat(s.ranges)):Gt.create(o):s}}:null}function Yh(t){let e=(null==t?void 0:t.eventFilter)||(t=>t.altKey&&0==t.button);return jn.mouseSelectionStyle.of(((t,i)=>e(i)?Wh(t,i):null))}const Xh={Alt:[18,t=>t.altKey],Control:[17,t=>t.ctrlKey],Shift:[16,t=>t.shiftKey],Meta:[91,t=>t.metaKey]},Mh={style:"cursor: crosshair"};function Zh(t={}){let[e,i]=Xh[t.key||"Alt"],s=Es.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventHandlers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)}}});return[s,jn.contentAttributes.of((t=>{var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.isDown)?Mh:null}))]}const Th="-10000px";class _h{constructor(t,e,i){this.facet=e,this.createTooltipView=i,this.input=t.state.facet(e),this.tooltips=this.input.filter((t=>t)),this.tooltipViews=this.tooltips.map(i)}update(t){let e=t.state.facet(this.facet),i=e.filter((t=>t));if(e===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let s=[];for(let e=0;e{var e,i,s;return{position:Li.ios?"absolute":(null===(e=t.find((t=>t.position)))||void 0===e?void 0:e.position)||"fixed",parent:(null===(i=t.find((t=>t.parent)))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(s=t.find((t=>t.tooltipSpace)))||void 0===s?void 0:s.tooltipSpace)||Eh}}}),jh=Es.fromClass(class{constructor(t){var e;this.view=t,this.inView=!0,this.lastTransaction=0,this.measureTimeout=-1;let i=t.state.facet(Ah);this.position=i.position,this.parent=i.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.manager=new _h(t,Vh,(t=>this.createTooltip(t))),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver((t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()}),{threshold:[1]}):null,this.observeIntersection(),null===(e=t.dom.ownerDocument.defaultView)||void 0===e||e.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout((()=>{this.measureTimeout=-1,this.maybeMeasure()}),50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t);e&&this.observeIntersection();let i=e||t.geometryChanged,s=t.state.facet(Ah);if(s.position!=this.position){this.position=s.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(s.parent!=this.parent){this.parent&&this.container.remove(),this.parent=s.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t){let e=t.create(this.view);if(e.dom.classList.add("cm-tooltip"),t.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",e.dom.appendChild(t)}return e.dom.style.position=this.position,e.dom.style.top=Th,this.container.appendChild(e.dom),e.mount&&e.mount(this.view),e}destroy(){var t,e;null===(t=this.view.dom.ownerDocument.defaultView)||void 0===t||t.removeEventListener("resize",this.measureSoon);for(let{dom:t}of this.manager.tooltipViews)t.remove();null===(e=this.intersectionObserver)||void 0===e||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=this.view.dom.getBoundingClientRect();return{editor:t,parent:this.parent?this.container.getBoundingClientRect():t,pos:this.manager.tooltips.map(((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)})),size:this.manager.tooltipViews.map((({dom:t})=>t.getBoundingClientRect())),space:this.view.state.facet(Ah).tooltipSpace(this.view)}}writeMeasure(t){let{editor:e,space:i}=t,s=[];for(let r=0;r=Math.min(e.bottom,i.bottom)||l.rightMath.min(e.right,i.right)+.1){o.style.top=Th;continue}let a=n.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,f=a?7:0,c=u.right-u.left,O=u.bottom-u.top,d=h.offset||Gh,$=this.view.textDirection==Ns.LTR,p=u.width>i.right-i.left?$?i.left:i.right-u.width:$?Math.min(l.left-(a?14:0)+d.x,i.right-c):Math.max(i.left,l.left-c+(a?14:0)-d.x),m=!!n.above;!n.strictSide&&(m?l.top-(u.bottom-u.top)-d.yi.bottom)&&m==i.bottom-l.bottom>l.top-i.top&&(m=!m);let w=m?l.top-O-f-d.y:l.bottom+f+d.y,g=p+c;if(!0!==h.overlap)for(let t of s)t.leftp&&t.topw&&(w=m?t.top-O-2-f:t.bottom+f+2);"absolute"==this.position?(o.style.top=w-t.parent.top+"px",o.style.left=p-t.parent.left+"px"):(o.style.top=w+"px",o.style.left=p+"px"),a&&(a.style.left=l.left+($?d.x:-d.x)-(p+14-7)+"px"),!0!==h.overlap&&s.push({left:p,top:w,right:g,bottom:w+O}),o.classList.toggle("cm-tooltip-above",m),o.classList.toggle("cm-tooltip-below",!m),h.positioned&&h.positioned()}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let t of this.manager.tooltipViews)t.dom.style.top=Th}},{eventHandlers:{scroll(){this.maybeMeasure()}}}),Uh=jn.baseTheme({".cm-tooltip":{zIndex:100},"&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"}}}),Gh={x:0,y:0},Vh=Dt.define({enables:[jh,Uh]}),Ch=Dt.define();class Dh{constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new _h(t,Ch,(t=>this.createHostedView(t)))}static create(t){return new Dh(t)}createHostedView(t){let e=t.create(this.view);return e.dom.classList.add("cm-tooltip-section"),this.dom.appendChild(e.dom),this.mounted&&e.mount&&e.mount(this.view),e}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned()}update(t){this.manager.update(t)}}const zh=Vh.compute([Ch],(t=>{let e=t.facet(Ch).filter((t=>t));return 0===e.length?null:{pos:Math.min(...e.map((t=>t.pos))),end:Math.max(...e.filter((t=>null!=t.end)).map((t=>t.end))),create:Dh.create,above:e[0].above,arrow:e.some((t=>t.arrow))}}));class Hh{constructor(t,e,i,s,r){this.view=t,this.source=e,this.field=i,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout((()=>this.startHover()),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active)return;let t=Date.now()-this.lastMove.time;ti.bottom||t.xi.right+this.view.defaultCharacterWidth)return;let s=this.view.bidiSpans(this.view.state.doc.lineAt(e)).find((t=>t.from<=e&&t.to>=e)),r=s&&s.dir==Ns.RTL?-1:1,n=this.source(this.view,e,t.x{this.pending==t&&(this.pending=null,e&&this.view.dispatch({effects:this.setHover.of(e)}))}),(t=>Ms(this.view.state,t,"hover tooltip")))}else n&&this.view.dispatch({effects:this.setHover.of(n)})}mousemove(t){var e;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let i=this.active;if(i&&!function(t){for(let e=t;e;e=e.parentNode)if(1==e.nodeType&&e.classList.contains("cm-tooltip"))return!0;return!1}(this.lastMove.target)||this.pending){let{pos:s}=i||this.pending,r=null!==(e=null==i?void 0:i.end)&&void 0!==e?e:s;(s==r?this.view.posAtCoords(this.lastMove)==s:function(t,e,i,s,r,n){let h=document.createRange(),o=t.domAtPos(e),l=t.domAtPos(i);h.setEnd(l.node,l.offset),h.setStart(o.node,o.offset);let u=h.getClientRects();h.detach();for(let t=0;tnull,update(t,s){if(t&&(e.hideOnChange&&(s.docChanged||s.selection)||e.hideOn&&e.hideOn(s,t)))return null;if(t&&s.docChanged){let e=s.changes.mapPos(t.pos,-1,Yt.TrackDel);if(null==e)return null;let i=Object.assign(Object.create(null),t);i.pos=e,null!=t.end&&(i.end=s.changes.mapPos(t.end)),t=i}for(let e of s.effects)e.is(i)&&(t=e.value),e.is(Fh)&&(t=null);return t},provide:t=>Ch.from(t)});return[s,Es.define((r=>new Hh(r,t,s,i,e.hoverTime||300))),zh]}const Fh=be.define(),Bh=Dt.define({combine(t){let e,i;for(let s of t)e=e||s.topContainer,i=i||s.bottomContainer;return{topContainer:e,bottomContainer:i}}});function Lh(t,e){let i=t.plugin(Kh),s=i?i.specs.indexOf(e):-1;return s>-1?i.panels[s]:null}const Kh=Es.fromClass(class{constructor(t){this.input=t.state.facet(eo),this.specs=this.input.filter((t=>t)),this.panels=this.specs.map((e=>e(t)));let e=t.state.facet(Bh);this.top=new Jh(t,!0,e.topContainer),this.bottom=new Jh(t,!1,e.bottomContainer),this.top.sync(this.panels.filter((t=>t.top))),this.bottom.sync(this.panels.filter((t=>!t.top)));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(t){let e=t.state.facet(Bh);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Jh(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Jh(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(eo);if(i!=this.input){let e=i.filter((t=>t)),s=[],r=[],n=[],h=[];for(let i of e){let e,o=this.specs.indexOf(i);o<0?(e=i(t.view),h.push(e)):(e=this.panels[o],e.update&&e.update(t)),s.push(e),(e.top?r:n).push(e)}this.specs=e,this.panels=s,this.top.sync(r),this.bottom.sync(n);for(let t of h)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>jn.scrollMargins.of((e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}}))});class Jh{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=to(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=to(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 to(t){let e=t.nextSibling;return t.remove(),e}const eo=Dt.define({enables:Kh});class io extends Ze{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}io.prototype.elementClass="",io.prototype.toDOM=void 0,io.prototype.mapMode=Yt.TrackBefore,io.prototype.startSide=io.prototype.endSide=-1,io.prototype.point=!0;const so=Dt.define(),ro={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>Ae.empty,lineMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},no=Dt.define();function ho(t){return[lo(),no.of(Object.assign(Object.assign({},ro),t))]}const oo=Dt.define({combine:t=>t.some((t=>t))});function lo(t){let e=[uo];return t&&!1===t.fixed&&e.push(oo.of(!0)),e}const uo=Es.fromClass(class{constructor(t){this.view=t,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight+"px",this.gutters=t.state.facet(no).map((e=>new Oo(t,e)));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!t.state.facet(oo),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,s=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(s<.8*(i.to-i.from))}t.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+"px"),this.view.state.facet(oo)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&this.dom.remove();let i=Ae.iter(this.view.state.facet(so),this.view.viewport.from),s=[],r=this.gutters.map((t=>new co(t,this.view.viewport,-this.view.documentPadding.top)));for(let t of this.view.viewportLineBlocks){let e;if(Array.isArray(t.type)){for(let i of t.type)if(i.type==Os.Text){e=i;break}}else e=t.type==Os.Text?t:void 0;if(e){s.length&&(s=[]),fo(i,s,t.from);for(let t of r)t.line(this.view,e,s)}}for(let t of r)t.finish();t&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(t){let e=t.startState.facet(no),i=t.state.facet(no),s=t.docChanged||t.heightChanged||t.viewportChanged||!Ae.eq(t.startState.facet(so),t.state.facet(so),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(s=!0);else{s=!0;let r=[];for(let s of i){let i=e.indexOf(s);i<0?r.push(new Oo(this.view,s)):(this.gutters[i].update(t),r.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),r.indexOf(t)<0&&t.destroy();for(let t of r)this.dom.appendChild(t.dom);this.gutters=r}return s}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove()}},{provide:t=>jn.scrollMargins.of((e=>{let i=e.plugin(t);return i&&0!=i.gutters.length&&i.fixed?e.textDirection==Ns.LTR?{left:i.dom.offsetWidth}:{right:i.dom.offsetWidth}:null}))});function ao(t){return Array.isArray(t)?t:[t]}function fo(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class co{constructor(t,e,i){this.gutter=t,this.height=i,this.localMarkers=[],this.i=0,this.cursor=Ae.iter(t.markers,e.from)}line(t,e,i){this.localMarkers.length&&(this.localMarkers=[]),fo(this.cursor,this.localMarkers,e.from);let s=i.length?this.localMarkers.concat(i):this.localMarkers,r=this.gutter.config.lineMarker(t,e,s);r&&s.unshift(r);let n=this.gutter;if(0==s.length&&!n.config.renderEmptyElements)return;let h=e.top-this.height;if(this.i==n.elements.length){let i=new $o(t,e.height,h,s);n.elements.push(i),n.dom.appendChild(i.dom)}else n.elements[this.i].update(t,e.height,h,s);this.height=e.bottom,this.i++}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Oo{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,(s=>{let r=t.lineBlockAtHeight(s.clientY-t.documentTop);e.domEventHandlers[i](t,r,s)&&s.preventDefault()}));this.markers=ao(e.markers(t)),e.initialSpacer&&(this.spacer=new $o(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=ao(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let i=t.view.viewport;return!Ae.eq(this.markers,e,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class $o{constructor(t,e,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,s)}update(t,e,i,s){this.height!=e&&(this.dom.style.height=(this.height=e)+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;iMe(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let s=i[t],r=e[t];i[t]=s?(t,e,i)=>s(t,e,i)||r(t,e,i):r}return i}})});class wo extends io{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function go(t,e){return t.state.facet(mo).formatNumber(e,t.state)}const xo=no.compute([mo],(t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(po),lineMarker:(t,e,i)=>i.some((t=>t.toDOM))?null:new wo(go(t,t.state.doc.lineAt(e.from).number)),lineMarkerChange:t=>t.startState.facet(mo)!=t.state.facet(mo),initialSpacer:t=>new wo(go(t,yo(t.state.doc.lines))),updateSpacer(t,e){let i=go(e.view,yo(e.view.state.doc.lines));return i==t.number?t:new wo(i)},domEventHandlers:t.facet(mo).domEventHandlers})));function bo(t={}){return[mo.of(t),lo(),xo]}function yo(t){let e=9;for(;e{let e=[],i=-1;for(let s of t.selection.ranges)if(s.empty){let r=t.doc.lineAt(s.head).from;r>i&&(i=r,e.push(Qo.range(r)))}return Ae.of(e)}));function vo(){return Po}const qo=1024;let So=0;class ko{constructor(t,e){this.from=t,this.to=e}}class Io{constructor(t={}){this.id=So++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof t&&(t=Wo.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}Io.closedBy=new Io({deserialize:t=>t.split(" ")}),Io.openedBy=new Io({deserialize:t=>t.split(" ")}),Io.group=new Io({deserialize:t=>t.split(" ")}),Io.contextHash=new Io({perNode:!0}),Io.lookAhead=new Io({perNode:!0}),Io.mounted=new Io({perNode:!0});const Ro=Object.create(null);class Wo{constructor(t,e,i,s=0){this.name=t,this.props=e,this.id=i,this.flags=s}static define(t){let e=t.props&&t.props.length?Object.create(null):Ro,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),s=new Wo(t.name||"",e,t.id,i);if(t.props)for(let i of t.props)if(Array.isArray(i)||(i=i(s)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[i[0].id]=i[1]}return s}prop(t){return this.props[t.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(Io.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let s of i.split(" "))e[s]=t[i];return t=>{for(let i=t.prop(Io.group),s=-1;s<(i?i.length:0);s++){let r=e[s<0?t.name:i[s]];if(r)return r}}}}Wo.none=new Wo("",Object.create(null),0,8);class Yo{constructor(t){this.types=t;for(let e=0;e=s&&(n.type.isAnonymous||!1!==e(n))){if(n.firstChild())continue;t=!0}for(;t&&i&&!n.type.isAnonymous&&i(n),!n.nextSibling();){if(!n.parent())return;t=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Lo(Wo.none,this.children,this.positions,0,this.children.length,0,this.length,((t,e,i)=>new To(this.type,t,e,i,this.propValues)),t.makeTree||((t,e,i)=>new To(Wo.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:s,maxBufferLength:r=qo,reused:n=[],minRepeatType:h=s.types.length}=t,o=Array.isArray(i)?new _o(i,i.length):i,l=s.types,u=0,a=0;function f(t,e,i,m,w){let{id:g,start:x,end:b,size:y}=o,Q=a;for(;y<0;){if(o.next(),-1==y){let e=n[g];return i.push(e),void m.push(x-t)}if(-3==y)return void(u=g);if(-4==y)return void(a=g);throw new RangeError(`Unrecognized record size: ${y}`)}let P,v,q=l[g],S=x-t;if(b-x<=r&&(v=$(o.pos-e,w))){let e=new Uint16Array(v.size-v.skip),i=o.pos-v.size,r=e.length;for(;o.pos>i;)r=p(v.start,e,r);P=new Eo(e,b-v.start,s),S=v.start-t}else{let t=o.pos-y;o.next();let e=[],i=[],s=g>=h?g:-1,n=0,l=b;for(;o.pos>t;)s>=0&&o.id==s&&o.size>=0?(o.end<=l-r&&(O(e,i,x,n,o.end,l,s,Q),n=e.length,l=o.end),o.next()):f(x,t,e,i,s);if(s>=0&&n>0&&n-1&&n>0){let t=c(q);P=Lo(q,e,i,0,e.length,0,b-x,t,t)}else P=d(q,e,i,b-x,Q-b)}i.push(P),m.push(S)}function c(t){return(e,i,s)=>{let r,n,h=0,o=e.length-1;if(o>=0&&(r=e[o])instanceof To){if(!o&&r.type==t&&r.length==s)return r;(n=r.prop(Io.lookAhead))&&(h=i[o]+r.length+n)}return d(t,e,i,s,h)}}function O(t,e,i,r,n,h,o,l){let u=[],a=[];for(;t.length>r;)u.push(t.pop()),a.push(e.pop()+i-n);t.push(d(s.types[o],u,a,h-n,l-h)),e.push(n-i)}function d(t,e,i,s,r=0,n){if(u){let t=[Io.contextHash,u];n=n?[t].concat(n):[t]}if(r>25){let t=[Io.lookAhead,r];n=n?[t].concat(n):[t]}return new To(t,e,i,s,n)}function $(t,e){let i=o.fork(),s=0,n=0,l=0,u=i.end-r,a={size:0,start:0,skip:0};t:for(let r=i.pos-t;i.pos>r;){let t=i.size;if(i.id==e&&t>=0){a.size=s,a.start=n,a.skip=l,l+=4,s+=4,i.next();continue}let o=i.pos-t;if(t<0||o=h?4:0,c=i.start;for(i.next();i.pos>o;){if(i.size<0){if(-3!=i.size)break t;f+=4}else i.id>=h&&(f+=4);i.next()}n=c,s+=t,l+=f}return(e<0||s==t)&&(a.size=s,a.start=n,a.skip=l),a.size>4?a:void 0}function p(t,e,i){let{id:s,start:r,end:n,size:l}=o;if(o.next(),l>=0&&s4){let s=o.pos-(l-4);for(;o.pos>s;)i=p(t,e,i)}e[--i]=h,e[--i]=n-t,e[--i]=r-t,e[--i]=s}else-3==l?u=s:-4==l&&(a=s);return i}let m=[],w=[];for(;o.pos>0;)f(t.start||0,t.bufferStart||0,m,w,-1);let g=null!==(e=t.length)&&void 0!==e?e:m.length?w[0]+m[0].length:0;return new To(l[t.topID],m.reverse(),w.reverse(),g)}(t)}}To.empty=new To(Wo.none,[],[],0);class _o{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new _o(this.buffer,this.index)}}class Eo{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return Wo.none}toString(){let t=[];for(let e=0;e0));o=n[o+3]);return h}slice(t,e,i,s){let r=this.buffer,n=new Uint16Array(e-t);for(let s=t,h=0;s=e&&ie;case 1:return i<=e&&s>e;case 2:return s>e;case 4:return!0}}function jo(t,e){let i=t.childBefore(e);for(;i;){let e=i.lastChild;if(!e||e.to!=i.to)break;e.type.isError&&e.from==e.to?(t=i,i=e.prevSibling):i=e}return t}function Uo(t,e,i,s){for(var r;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to0?h.length:-1;t!=l;t+=e){let l=h[t],u=o[t]+n.from;if(Ao(s,i,u,u+l.length))if(l instanceof Eo){if(r&Zo.ExcludeBuffers)continue;let h=l.findChild(0,l.buffer.length,e,i-u,s);if(h>-1)return new zo(new Do(n,l,t,u),null,h)}else if(r&Zo.IncludeAnonymous||!l.type.isAnonymous||No(l)){let h;if(!(r&Zo.IgnoreMounts)&&l.props&&(h=l.prop(Io.mounted))&&!h.overlay)return new Go(h.tree,u,t,n);let o=new Go(l,u,t,n);return r&Zo.IncludeAnonymous||!o.type.isAnonymous?o:o.nextChild(e<0?l.children.length-1:0,e,i,s)}}if(r&Zo.IncludeAnonymous||!n.type.isAnonymous)return null;if(t=n.index>=0?n.index+e:e<0?-1:n._parent._tree.children.length,n=n._parent,!n)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,i=0){let s;if(!(i&Zo.IgnoreOverlays)&&(s=this._tree.prop(Io.mounted))&&s.overlay){let i=t-this.from;for(let{from:t,to:r}of s.overlay)if((e>0?t<=i:t=i:r>i))return new Go(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}cursor(t=0){return new Ho(this,t)}get tree(){return this._tree}toTree(){return this._tree}resolve(t,e=0){return Uo(this,t,e,!1)}resolveInner(t,e=0){return Uo(this,t,e,!0)}enterUnfinishedNodesBefore(t){return jo(this,t)}getChild(t,e=null,i=null){let s=Vo(this,t,e,i);return s.length?s[0]:null}getChildren(t,e=null,i=null){return Vo(this,t,e,i)}toString(){return this._tree.toString()}get node(){return this}matchContext(t){return Co(this,t)}}function Vo(t,e,i,s){let r=t.cursor(),n=[];if(!r.firstChild())return n;if(null!=i)for(;!r.type.is(i);)if(!r.nextSibling())return n;for(;;){if(null!=s&&r.type.is(s))return n;if(r.type.is(e)&&n.push(r.node),!r.nextSibling())return null==s?n:[]}}function Co(t,e,i=e.length-1){for(let s=t.parent;i>=0;s=s.parent){if(!s)return!1;if(!s.type.isAnonymous){if(e[i]&&e[i]!=s.name)return!1;i--}}return!0}class Do{constructor(t,e,i,s){this.parent=t,this.buffer=e,this.index=i,this.start=s}}class zo{constructor(t,e,i){this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}child(t,e,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.context.start,i);return r<0?null:new zo(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,i=0){if(i&Zo.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return r<0?null:new zo(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new zo(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new zo(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}cursor(t=0){return new Ho(this,t)}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let n=i.buffer[this.index+1],h=i.buffer[this.index+2];t.push(i.slice(s,r,n,h)),e.push(0)}return new To(this.type,t,e,this.to-this.from)}resolve(t,e=0){return Uo(this,t,e,!1)}resolveInner(t,e=0){return Uo(this,t,e,!0)}enterUnfinishedNodesBefore(t){return jo(this,t)}toString(){return this.context.buffer.childString(this.index)}getChild(t,e=null,i=null){let s=Vo(this,t,e,i);return s.length?s[0]:null}getChildren(t,e=null,i=null){return Vo(this,t,e,i)}get node(){return this}matchContext(t){return Co(this,t)}}class Ho{constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof Go)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let e=t._parent;e;e=e._parent)this.stack.unshift(e.index);this.bufferNode=t,this.yieldBuf(t.index)}}get name(){return this.type.name}yieldNode(t){return!!t&&(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0)}yieldBuf(t,e){this.index=t;let{start:i,buffer:s}=this.buffer;return this.type=e||s.set.types[s.buffer[t]],this.from=i+s.buffer[t+1],this.to=i+s.buffer[t+2],!0}yield(t){return!!t&&(t instanceof Go?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.buffer.start,i);return!(r<0)&&(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,i=this.mode){return this.buffer?!(i&Zo.ExcludeBuffers)&&this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Zo.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&Zo.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return!!this._tree._parent&&this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode));let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let t=i<0?0:this.stack[i]+4;if(this.index!=t)return this.yieldBuf(e.findChild(t,this.index,-1,0,4))}else{let t=e.buffer[this.index+3];if(t<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(t)}return i<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:s}=this;if(s){if(t>0){if(this.index-1)for(let s=e+t,r=t<0?-1:i._tree.children.length;s!=r;s+=t){let t=i._tree.children[s];if(this.mode&Zo.IncludeAnonymous||t instanceof Eo||!t.type.isAnonymous||No(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to=0;){for(let n=t;n;n=n._parent)if(n.index==s){if(s==this.index)return n;e=n,i=r+1;break t}s=this.stack[--r]}for(let t=i;t=0;r--){if(r<0)return Co(this.node,t,s);let n=i[e.buffer[this.stack[r]]];if(!n.isAnonymous){if(t[s]&&t[s]!=n.name)return!1;s--}}return!0}}function No(t){return t.children.some((t=>t instanceof Eo||!t.type.isAnonymous||No(t)))}const Fo=new WeakMap;function Bo(t,e){if(!t.isAnonymous||e instanceof Eo||e.type!=t)return 1;let i=Fo.get(e);if(null==i){i=1;for(let s of e.children){if(s.type!=t||!(s instanceof To)){i=1;break}i+=Bo(t,s)}Fo.set(e,i)}return i}function Lo(t,e,i,s,r,n,h,o,l){let u=0;for(let i=s;i=a)break;d+=e}if(u==r+1){if(d>a){let t=i[r];e(t.children,t.positions,0,t.children.length,s[r]+o);continue}f.push(i[r])}else{let e=s[u-1]+i[u-1].length-O;f.push(Lo(t,i,s,r,u,O,e,null,l))}c.push(O+o-n)}}(e,i,s,r,0),(o||l)(f,c,h)}class Ko{constructor(t,e,i,s,r=!1,n=!1){this.from=t,this.to=e,this.tree=i,this.offset=s,this.open=(r?1:0)|(n?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],i=!1){let s=[new Ko(0,t.length,t,0,!1,i)];for(let i of e)i.to>t.length&&s.push(i);return s}static applyChanges(t,e,i=128){if(!e.length)return t;let s=[],r=1,n=t.length?t[0]:null;for(let h=0,o=0,l=0;;h++){let u=h=i)for(;n&&n.from=e.from||a<=e.to||l){let t=Math.max(e.from,o)-l,i=Math.min(e.to,a)-l;e=t>=i?null:new Ko(t,i,e.tree,e.offset+l,h>0,!!u)}if(e&&s.push(e),n.to>a)break;n=rnew ko(t.from,t.to))):[new ko(0,0)]:[new ko(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let s=this.startParse(t,e,i);for(;;){let t=s.advance();if(t)return t}}}class tl{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new Io({perNode:!0});let el=0;class il{constructor(t,e,i){this.set=t,this.base=e,this.modified=i,this.id=el++}static define(t){if(null==t?void 0:t.base)throw new Error("Can not derive from a modified tag");let e=new il([],null,[]);if(e.set.push(e),t)for(let i of t.set)e.set.push(i);return e}static defineModifier(){let t=new rl;return e=>e.modified.indexOf(t)>-1?e:rl.get(e.base||e,e.modified.concat(t).sort(((t,e)=>t.id-e.id)))}}let sl=0;class rl{constructor(){this.instances=[],this.id=sl++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find((i=>i.base==t&&function(t,e){return t.length==e.length&&t.every(((t,i)=>t==e[i]))}(e,i.modified)));if(i)return i;let s=[],r=new il(s,t,e);for(let t of e)t.instances.push(r);let n=nl(e);for(let e of t.set)for(let t of n)s.push(rl.get(e,t));return r}}function nl(t){let e=[t];for(let i=0;i0&&e+3==t.length){r=1;break}let s=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(n);if(!s)throw new RangeError("Invalid path: "+t);if(i.push("*"==s[0]?"":'"'==s[0][0]?JSON.parse(s[0]):s[0]),e+=s[0].length,e==t.length)break;let h=t[e++];if(e==t.length&&"!"==h){r=0;break}if("/"!=h)throw new RangeError("Invalid path: "+t);n=t.slice(e)}let h=i.length-1,o=i[h];if(!o)throw new RangeError("Invalid path: "+t);let l=new ll(s,r,h>0?i.slice(0,h):null);e[o]=l.sort(e[o])}}return ol.add(e)}const ol=new Io;class ll{constructor(t,e,i,s){this.tags=t,this.mode=e,this.context=i,this.next=s}sort(t){return!t||t.depth{let e=r;for(let s of t)for(let t of s.set){let s=i[t.id];if(s){e=e?e+" "+s:s;break}}return e},scope:s}}function al(t,e){let i=null;for(let s of t){let t=s.style(e);t&&(i=i?i+" "+t:t)}return i}function fl(t,e,i,s=0,r=t.length){let n=new cl(s,Array.isArray(e)?e:[e],i);n.highlightRange(t.cursor(),s,r,"",n.highlighters),n.flush(r)}class cl{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,s,r){let{type:n,from:h,to:o}=t;if(h>=i||o<=e)return;n.isTop&&(r=this.highlighters.filter((t=>!t.scope||t.scope(n))));let l=s,u=n.prop(ol),a=!1;for(;u;){if(!u.context||t.matchContext(u.context)){let t=al(r,u.tags);t&&(l&&(l+=" "),l+=t,1==u.mode?s+=(s?" ":"")+t:0==u.mode&&(a=!0));break}u=u.next}if(this.startSpan(t.from,l),a)return;let f=t.tree&&t.tree.prop(Io.mounted);if(f&&f.overlay){let n=t.node.enter(f.overlay[0].from+h,1),u=this.highlighters.filter((t=>!t.scope||t.scope(f.tree.type))),a=t.firstChild();for(let c=0,O=h;;c++){let d=c=$)&&t.nextSibling()););if(!d||$>i)break;O=d.to+h,O>e&&(this.highlightRange(n.cursor(),Math.max(e,d.from+h),Math.min(i,O),s,u),this.startSpan(O,l))}a&&t.parent()}else if(t.firstChild()){do{if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,s,r),this.startSpan(Math.min(i,t.to),l)}}while(t.nextSibling());t.parent()}}}const Ol=il.define,dl=Ol(),$l=Ol(),pl=Ol($l),ml=Ol($l),wl=Ol(),gl=Ol(wl),xl=Ol(wl),bl=Ol(),yl=Ol(bl),Ql=Ol(),Pl=Ol(),vl=Ol(),ql=Ol(vl),Sl=Ol(),kl={comment:dl,lineComment:Ol(dl),blockComment:Ol(dl),docComment:Ol(dl),name:$l,variableName:Ol($l),typeName:pl,tagName:Ol(pl),propertyName:ml,attributeName:Ol(ml),className:Ol($l),labelName:Ol($l),namespace:Ol($l),macroName:Ol($l),literal:wl,string:gl,docString:Ol(gl),character:Ol(gl),attributeValue:Ol(gl),number:xl,integer:Ol(xl),float:Ol(xl),bool:Ol(wl),regexp:Ol(wl),escape:Ol(wl),color:Ol(wl),url:Ol(wl),keyword:Ql,self:Ol(Ql),null:Ol(Ql),atom:Ol(Ql),unit:Ol(Ql),modifier:Ol(Ql),operatorKeyword:Ol(Ql),controlKeyword:Ol(Ql),definitionKeyword:Ol(Ql),moduleKeyword:Ol(Ql),operator:Pl,derefOperator:Ol(Pl),arithmeticOperator:Ol(Pl),logicOperator:Ol(Pl),bitwiseOperator:Ol(Pl),compareOperator:Ol(Pl),updateOperator:Ol(Pl),definitionOperator:Ol(Pl),typeOperator:Ol(Pl),controlOperator:Ol(Pl),punctuation:vl,separator:Ol(vl),bracket:ql,angleBracket:Ol(ql),squareBracket:Ol(ql),paren:Ol(ql),brace:Ol(ql),content:bl,heading:yl,heading1:Ol(yl),heading2:Ol(yl),heading3:Ol(yl),heading4:Ol(yl),heading5:Ol(yl),heading6:Ol(yl),contentSeparator:Ol(bl),list:Ol(bl),quote:Ol(bl),emphasis:Ol(bl),strong:Ol(bl),link:Ol(bl),monospace:Ol(bl),strikethrough:Ol(bl),inserted:Ol(),deleted:Ol(),changed:Ol(),invalid:Ol(),meta:Sl,documentMeta:Ol(Sl),annotation:Ol(Sl),processingInstruction:Ol(Sl),definition:il.defineModifier(),constant:il.defineModifier(),function:il.defineModifier(),standard:il.defineModifier(),local:il.defineModifier(),special:il.defineModifier()};var Il;ul([{tag:kl.link,class:"tok-link"},{tag:kl.heading,class:"tok-heading"},{tag:kl.emphasis,class:"tok-emphasis"},{tag:kl.strong,class:"tok-strong"},{tag:kl.keyword,class:"tok-keyword"},{tag:kl.atom,class:"tok-atom"},{tag:kl.bool,class:"tok-bool"},{tag:kl.url,class:"tok-url"},{tag:kl.labelName,class:"tok-labelName"},{tag:kl.inserted,class:"tok-inserted"},{tag:kl.deleted,class:"tok-deleted"},{tag:kl.literal,class:"tok-literal"},{tag:kl.string,class:"tok-string"},{tag:kl.number,class:"tok-number"},{tag:[kl.regexp,kl.escape,kl.special(kl.string)],class:"tok-string2"},{tag:kl.variableName,class:"tok-variableName"},{tag:kl.local(kl.variableName),class:"tok-variableName tok-local"},{tag:kl.definition(kl.variableName),class:"tok-variableName tok-definition"},{tag:kl.special(kl.variableName),class:"tok-variableName2"},{tag:kl.definition(kl.propertyName),class:"tok-propertyName tok-definition"},{tag:kl.typeName,class:"tok-typeName"},{tag:kl.namespace,class:"tok-namespace"},{tag:kl.className,class:"tok-className"},{tag:kl.macroName,class:"tok-macroName"},{tag:kl.propertyName,class:"tok-propertyName"},{tag:kl.operator,class:"tok-operator"},{tag:kl.comment,class:"tok-comment"},{tag:kl.meta,class:"tok-meta"},{tag:kl.invalid,class:"tok-invalid"},{tag:kl.punctuation,class:"tok-punctuation"}]);const Rl=new Io;class Wl{constructor(t,e,i=[]){this.data=t,Xe.prototype.hasOwnProperty("tree")||Object.defineProperty(Xe.prototype,"tree",{get(){return Ml(this)}}),this.parser=e,this.extension=[Vl.of(this),Xe.languageData.of(((t,e,i)=>t.facet(Yl(t,e,i))))].concat(i)}isActiveAt(t,e,i=-1){return Yl(t,e,i)==this.data}findRegions(t){let e=t.facet(Vl);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],s=(t,e)=>{if(t.prop(Rl)==this.data)return void i.push({from:e,to:e+t.length});let r=t.prop(Io.mounted);if(r){if(r.tree.prop(Rl)==this.data){if(r.overlay)for(let t of r.overlay)i.push({from:t.from+e,to:t.to+e});else i.push({from:e,to:e+t.length});return}if(r.overlay){let t=i.length;if(s(r.tree,r.overlay[0].from+e),i.length>t)return}}for(let i=0;it.concat(i):void 0}));var i;return new Xl(e,t.parser.configure({props:[Rl.add((t=>t.isTop?e:void 0))]}))}configure(t){return new Xl(this.data,this.parser.configure(t))}get allowsNesting(){return this.parser.hasWrappers()}}function Ml(t){let e=t.field(Wl.state,!1);return e?e.tree:To.empty}class Zl{constructor(t,e=t.length){this.doc=t,this.length=e,this.cursorPos=0,this.string="",this.cursor=t.iter()}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let Tl=null;class _l{constructor(t,e,i=[],s,r,n,h,o){this.parser=t,this.state=e,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=n,this.skipped=h,this.scheduleOn=o,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new _l(t,e,[],To.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Zl(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=To.empty&&this.isDone(null!=e?e:this.state.doc.length)?(this.takeTree(),!0):this.withContext((()=>{var i;if("number"==typeof t){let e=Date.now()+t;t=()=>Date.now()>e}for(this.parse||(this.parse=this.startParse()),null!=e&&(null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&e=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext((()=>{for(;!(e=this.parse.advance()););})),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(Ko.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Tl;Tl=this;try{return t()}finally{Tl=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=El(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:s,treeLen:r,viewport:n,skipped:h}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges(((t,i,s,r)=>e.push({fromA:t,toA:i,fromB:s,toB:r}))),i=Ko.applyChanges(i,e),s=To.empty,r=0,n={from:t.mapPos(n.from,-1),to:t.mapPos(n.to,1)},this.skipped.length){h=[];for(let e of this.skipped){let i=t.mapPos(e.from,1),s=t.mapPos(e.to,-1);it.from&&(this.fragments=El(this.fragments,i,s),this.skipped.splice(e--,1))}return!(this.skipped.length>=e||(this.reset(),0))}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Jo{createParse(e,i,s){let r=s[0].from,n=s[s.length-1].to,h={parsedPos:r,advance(){let e=Tl;if(e){for(let t of s)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=n,new To(Wo.none,[],[],n-r)},stoppedAt:null,stopAt(){}};return h}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&0==e[0].from&&e[0].to>=t}static get(){return Tl}}function El(t,e,i){return Ko.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class Al{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Al(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=_l.create(t.facet(Vl).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Al(i)}}Wl.state=Kt.define({create:Al.init,update(t,e){for(let t of e.effects)if(t.is(Wl.setState))return t.value;return e.startState.facet(Vl)!=e.state.facet(Vl)?Al.init(e.state):t.apply(e)}});let jl=t=>{let e=setTimeout((()=>t()),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(jl=t=>{let e=-1,i=setTimeout((()=>{e=requestIdleCallback(t,{timeout:400})}),100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const Ul="undefined"!=typeof navigator&&(null===(Il=navigator.scheduling)||void 0===Il?void 0:Il.isInputPending)?()=>navigator.scheduling.isInputPending():null,Gl=Es.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(Wl.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),t.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(Wl.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=jl(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnds+1e3,o=r.context.work((()=>Ul&&Ul()||Date.now()>n),s+(h?0:1e5));this.chunkBudget-=Date.now()-e,(o||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Wl.setState.of(new Al(r.context))})),this.chunkBudget>0&&(!o||h)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then((()=>this.scheduleWork())).catch((t=>Ms(this.view.state,t))).then((()=>this.workScheduled--)),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Vl=Dt.define({combine:t=>t.length?t[0]:null,enables:[Wl.state,Gl]});class Cl{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const Dl=Dt.define(),zl=Dt.define({combine:t=>{if(!t.length)return" ";if(!/^(?: +|\t+)$/.test(t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return t[0]}});function Hl(t){let e=t.facet(zl);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function Nl(t,e){let i="",s=t.tabSize;if(9==t.facet(zl).charCodeAt(0))for(;e>=s;)i+="\t",e-=s;for(let t=0;t=i.from&&s<=i.to?r&&s==t?{text:"",from:t}:(e<0?s-1&&(r+=n-this.countColumn(i,i.search(/\S|$/))),r}countColumn(t,e=t.length){return Le(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:s}=this.lineAt(t,e),r=this.options.overrideIndentation;if(r){let t=r(s);if(t>-1)return t}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Ll=new Io;function Kl(t){let e=t.type.prop(Ll);if(e)return e;let i,s=t.firstChild;if(s&&(i=s.type.prop(Io.closedBy))){let e=t.lastChild,s=e&&i.indexOf(e.name)>-1;return t=>ru(t,!0,1,void 0,s&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?tu:null}function Jl(t,e,i){for(;t;t=t.parent){let s=Kl(t);if(s)return s(eu.create(i,e,t))}return null}function tu(){return 0}class eu extends Bl{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.node=i}static create(t,e,i){return new eu(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){let t=this.state.doc.lineAt(this.node.from);for(;;){let e=this.node.resolve(t.from);for(;e.parent&&e.parent.from==e.from;)e=e.parent;if(iu(e,this.node))break;t=this.state.doc.lineAt(e.from)}return this.lineIndent(t.from)}continue(){let t=this.node.parent;return t?Jl(t,this.pos,this.base):0}}function iu(t,e){for(let i=e;i;i=i.parent)if(t==i)return!0;return!1}function su({closing:t,align:e=!0,units:i=1}){return s=>ru(s,e,i,t)}function ru(t,e,i,s,r){let n=t.textAfter,h=n.match(/^\s*/)[0].length,o=s&&n.slice(h,h+s.length)==s||r==t.pos+h,l=e?function(t){let e=t.node,i=e.childAfter(e.from),s=e.lastChild;if(!i)return null;let r=t.options.simulateBreak,n=t.state.doc.lineAt(i.from),h=null==r||r<=n.from?n.to:Math.min(n.to,r);for(let t=i.to;;){let r=e.childAfter(t);if(!r||r==s)return null;if(!r.type.isSkipped)return r.from{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let i=t.newDoc,{head:s}=t.newSelection.main,r=i.lineAt(s);if(s>r.from+200)return t;let n=i.sliceString(r.from,s);if(!e.some((t=>t.test(n))))return t;let{state:h}=t,o=-1,l=[];for(let{head:t}of h.selection.ranges){let e=h.doc.lineAt(t);if(e.from==o)continue;o=e.from;let i=Fl(h,e.from);if(null==i)continue;let s=/^\s*/.exec(e.text)[0],r=Nl(h,i);s!=r&&l.push({from:e.from,to:e.from+s.length,insert:r})}return l.length?[t,{changes:l,sequential:!0}]:t}))}const hu=Dt.define(),ou=new Io;function lu(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function uu(t,e,i){for(let s of t.facet(hu)){let r=s(t,e,i);if(r)return r}return function(t,e,i){let s=Ml(t);if(s.lengthi)continue;if(r&&n.from=e&&s.to>i&&(r=s)}}return r}(t,e,i)}function au(t,e){let i=e.mapPos(t.from,1),s=e.mapPos(t.to,-1);return i>=s?void 0:{from:i,to:s}}const fu=be.define({map:au}),cu=be.define({map:au});function Ou(t){let e=[];for(let{head:i}of t.state.selection.ranges)e.some((t=>t.from<=i&&t.to>=i))||e.push(t.lineBlockAt(i));return e}const du=Kt.define({create:()=>ds.none,update(t,e){t=t.map(e.changes);for(let i of e.effects)i.is(fu)&&!pu(t,i.value.from,i.value.to)?t=t.update({add:[Qu.range(i.value.from,i.value.to)]}):i.is(cu)&&(t=t.update({filter:(t,e)=>i.value.from!=t||i.value.to!=e,filterFrom:i.value.from,filterTo:i.value.to}));if(e.selection){let i=!1,{head:s}=e.selection.main;t.between(s,s,((t,e)=>{ts&&(i=!0)})),i&&(t=t.update({filterFrom:s,filterTo:s,filter:(t,e)=>e<=s||t>=s}))}return t},provide:t=>jn.decorations.from(t),toJSON(t,e){let i=[];return t.between(0,e.doc.length,((t,e)=>{i.push(t,e)})),i},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let i=0;i{(!r||r.from>t)&&(r={from:t,to:e})})),r}function pu(t,e,i){let s=!1;return t.between(e,e,((t,r)=>{t==e&&r==i&&(s=!0)})),s}function mu(t,e){return t.field(du,!1)?e:e.concat(be.appendConfig.of(yu()))}function wu(t,e,i=!0){let s=t.state.doc.lineAt(e.from).number,r=t.state.doc.lineAt(e.to).number;return jn.announce.of(`${t.state.phrase(i?"Folded lines":"Unfolded lines")} ${s} ${t.state.phrase("to")} ${r}.`)}const gu=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of Ou(t)){let i=uu(t.state,e.from,e.to);if(i)return t.dispatch({effects:mu(t.state,[fu.of(i),wu(t,i)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(du,!1))return!1;let e=[];for(let i of Ou(t)){let s=$u(t.state,i.from,i.to);s&&e.push(cu.of(s),wu(t,s,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,i=[];for(let s=0;s{let e=t.state.field(du,!1);if(!e||!e.size)return!1;let i=[];return e.between(0,t.state.doc.length,((t,e)=>{i.push(cu.of({from:t,to:e}))})),t.dispatch({effects:i}),!0}}],xu={placeholderDOM:null,placeholderText:"…"},bu=Dt.define({combine:t=>Me(t,xu)});function yu(t){let e=[du,Su];return t&&e.push(bu.of(t)),e}const Qu=ds.replace({widget:new class extends cs{toDOM(t){let{state:e}=t,i=e.facet(bu),s=e=>{let i=t.lineBlockAt(t.posAtDOM(e.target)),s=$u(t.state,i.from,i.to);s&&t.dispatch({effects:cu.of(s)}),e.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(t,s);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",e.phrase("folded code")),r.title=e.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}}}),Pu={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class vu extends io{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}function qu(t={}){let e=Object.assign(Object.assign({},Pu),t),i=new vu(e,!0),s=new vu(e,!1),r=Es.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(Vl)!=t.state.facet(Vl)||t.startState.field(du,!1)!=t.state.field(du,!1)||Ml(t.startState)!=Ml(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new je;for(let r of t.viewportLineBlocks){let n=$u(t.state,r.from,r.to)?s:uu(t.state,r.from,r.to)?i:null;n&&e.add(r.from,r.from,n)}return e.finish()}}),{domEventHandlers:n}=e;return[r,ho({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(r))||void 0===e?void 0:e.markers)||Ae.empty},initialSpacer:()=>new vu(e,!1),domEventHandlers:Object.assign(Object.assign({},n),{click:(t,e,i)=>{if(n.click&&n.click(t,e,i))return!0;let s=$u(t.state,e.from,e.to);if(s)return t.dispatch({effects:cu.of(s)}),!0;let r=uu(t.state,e.from,e.to);return!!r&&(t.dispatch({effects:fu.of(r)}),!0)}})}),yu()]}const Su=jn.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class ku{constructor(t,e){let i;function s(t){let e=ii.newName();return(i||(i=Object.create(null)))["."+e]=t,e}const r="string"==typeof e.all?e.all:e.all?s(e.all):void 0,n=e.scope;this.scope=n instanceof Wl?t=>t.prop(Rl)==n.data:n?t=>t==n:void 0,this.style=ul(t.map((t=>({tag:t.tag,class:t.class||s(Object.assign({},t,{tag:null}))}))),{all:r}).style,this.module=i?new ii(i):null,this.themeType=e.themeType}static define(t,e){return new ku(t,e||{})}}const Iu=Dt.define(),Ru=Dt.define({combine:t=>t.length?[t[0]]:null});function Wu(t){let e=t.facet(Iu);return e.length?e:t.facet(Ru)}function Yu(t,e){let i,s=[Mu];return t instanceof ku&&(t.module&&s.push(jn.styleModule.of(t.module)),i=t.themeType),(null==e?void 0:e.fallback)?s.push(Ru.of(t)):i?s.push(Iu.computeN([jn.darkTheme],(e=>e.facet(jn.darkTheme)==("dark"==i)?[t]:[]))):s.push(Iu.of(t)),s}class Xu{constructor(t){this.markCache=Object.create(null),this.tree=Ml(t.state),this.decorations=this.buildDeco(t,Wu(t.state))}update(t){let e=Ml(t.state),i=Wu(t.state),s=i!=Wu(t.startState);e.length{i.add(t,e,this.markCache[s]||(this.markCache[s]=ds.mark({class:s})))}),s,r);return i.finish()}}const Mu=re.high(Es.fromClass(Xu,{decorations:t=>t.decorations})),Zu=ku.define([{tag:kl.meta,color:"#7a757a"},{tag:kl.link,textDecoration:"underline"},{tag:kl.heading,textDecoration:"underline",fontWeight:"bold"},{tag:kl.emphasis,fontStyle:"italic"},{tag:kl.strong,fontWeight:"bold"},{tag:kl.strikethrough,textDecoration:"line-through"},{tag:kl.keyword,color:"#708"},{tag:[kl.atom,kl.bool,kl.url,kl.contentSeparator,kl.labelName],color:"#219"},{tag:[kl.literal,kl.inserted],color:"#164"},{tag:[kl.string,kl.deleted],color:"#a11"},{tag:[kl.regexp,kl.escape,kl.special(kl.string)],color:"#e40"},{tag:kl.definition(kl.variableName),color:"#00f"},{tag:kl.local(kl.variableName),color:"#30a"},{tag:[kl.typeName,kl.namespace],color:"#085"},{tag:kl.className,color:"#167"},{tag:[kl.special(kl.variableName),kl.macroName],color:"#256"},{tag:kl.definition(kl.propertyName),color:"#00c"},{tag:kl.comment,color:"#940"},{tag:kl.invalid,color:"#f00"}]),Tu=jn.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),_u="()[]{}",Eu=Dt.define({combine:t=>Me(t,{afterCursor:!0,brackets:_u,maxScanDistance:1e4,renderMatch:Uu})}),Au=ds.mark({class:"cm-matchingBracket"}),ju=ds.mark({class:"cm-nonmatchingBracket"});function Uu(t){let e=[],i=t.matched?Au:ju;return e.push(i.range(t.start.from,t.start.to)),t.end&&e.push(i.range(t.end.from,t.end.to)),e}const Gu=Kt.define({create:()=>ds.none,update(t,e){if(!e.docChanged&&!e.selection)return t;let i=[],s=e.state.facet(Eu);for(let t of e.state.selection.ranges){if(!t.empty)continue;let r=zu(e.state,t.head,-1,s)||t.head>0&&zu(e.state,t.head-1,1,s)||s.afterCursor&&(zu(e.state,t.head,1,s)||t.headjn.decorations.from(t)}),Vu=[Gu,Tu];function Cu(t={}){return[Eu.of(t),Vu]}function Du(t,e,i){let s=t.prop(e<0?Io.openedBy:Io.closedBy);if(s)return s;if(1==t.name.length){let s=i.indexOf(t.name);if(s>-1&&s%2==(e<0?1:0))return[i[s+e]]}return null}function zu(t,e,i,s={}){let r=s.maxScanDistance||1e4,n=s.brackets||_u,h=Ml(t),o=h.resolveInner(e,i);for(let t=o;t;t=t.parent){let e=Du(t.type,i,n);if(e&&t.from0)return null;let u={from:i<0?e-1:e,to:i>0?e+1:e},a=t.doc.iterRange(e,i>0?t.doc.length:0),f=0;for(let t=0;!a.next().done&&t<=n;){let n=a.value;i<0&&(t+=n.length);let o=e+t*i;for(let t=i>0?0:n.length-1,e=i>0?n.length:-1;t!=e;t+=i){let e=h.indexOf(n[t]);if(!(e<0||s.resolve(o+t,1).type!=r))if(e%2==0==i>0)f++;else{if(1==f)return{start:u,end:{from:o+t,to:o+t+1},matched:e>>1==l>>1};f--}}i>0&&(t+=n.length)}return a.done?{start:u,matched:!1}:null}(t,e,i,h,o.type,r,n)}function Hu(t,e,i,s,r,n){let h=s.parent,o={from:s.from,to:s.to},l=0,u=null==h?void 0:h.cursor();if(u&&(i<0?u.childBefore(s.from):u.childAfter(s.to)))do{if(i<0?u.to<=s.from:u.from>=s.to){if(0==l&&r.indexOf(u.type.name)>-1&&u.from-1||(Bu.push(t),console.warn(e))}function Ju(t,e){let i=null;for(let s of e.split(".")){let e=t[s]||kl[s];e?"function"==typeof e?i?i=e(i):Ku(s,`Modifier ${s} used at start of tag`):i?Ku(s,`Tag ${s} used as modifier`):i=e:Ku(s,`Unknown highlighting tag ${s}`)}if(!i)return 0;let s=e.replace(/ /g,"_"),r=Wo.define({id:Fu.length,name:s,props:[hl({[s]:i})]});return Fu.push(r),r.id}function ta(t,e){return({state:i,dispatch:s})=>{if(i.readOnly)return!1;let r=t(e,i);return!!r&&(s(i.update(r)),!0)}}const ea=ta(oa,0),ia=ta(ha,0),sa=ta(((t,e)=>ha(t,e,function(t){let e=[];for(let i of t.selection.ranges){let s=t.doc.lineAt(i.from),r=i.to<=s.to?s:t.doc.lineAt(i.to),n=e.length-1;n>=0&&e[n].to>s.from?e[n].to=r.to:e.push({from:s.from,to:r.to})}return e}(e))),0);function ra(t,e=t.selection.main.head){let i=t.languageDataAt("commentTokens",e);return i.length?i[0]:{}}const na=50;function ha(t,e,i=e.selection.ranges){let s=i.map((t=>ra(e,t.from).block));if(!s.every((t=>t)))return null;let r=i.map(((t,i)=>function(t,{open:e,close:i},s,r){let n,h,o=t.sliceDoc(s-na,s),l=t.sliceDoc(r,r+na),u=/\s*$/.exec(o)[0].length,a=/^\s*/.exec(l)[0].length,f=o.length-u;if(o.slice(f-e.length,f)==e&&l.slice(a,a+i.length)==i)return{open:{pos:s-u,margin:u&&1},close:{pos:r+a,margin:a&&1}};r-s<=2*na?n=h=t.sliceDoc(s,r):(n=t.sliceDoc(s,s+na),h=t.sliceDoc(r-na,r));let c=/^\s*/.exec(n)[0].length,O=/\s*$/.exec(h)[0].length,d=h.length-O-i.length;return n.slice(c,c+e.length)==e&&h.slice(d,d+i.length)==i?{open:{pos:s+c+e.length,margin:/\s/.test(n.charAt(c+e.length))?1:0},close:{pos:r-O-i.length,margin:/\s/.test(h.charAt(d-1))?1:0}}:null}(e,s[i],t.from,t.to)));if(2!=t&&!r.every((t=>t)))return{changes:e.changes(i.map(((t,e)=>r[e]?[]:[{from:t.from,insert:s[e].open+" "},{from:t.to,insert:" "+s[e].close}])))};if(1!=t&&r.some((t=>t))){let t=[];for(let e,i=0;ir&&(t==n||n>o.from)){r=o.from;let t=ra(e,i).line;if(!t)continue;let n=/^\s*/.exec(o.text)[0].length,l=n==o.length,u=o.text.slice(n,n+t.length)==t?n:-1;nt.comment<0&&(!t.empty||t.single)))){let t=[];for(let{line:e,token:i,indent:r,empty:n,single:h}of s)!h&&n||t.push({from:e.from+r,insert:i+" "});let i=e.changes(t);return{changes:i,selection:e.selection.map(i,1)}}if(1!=t&&s.some((t=>t.comment>=0))){let t=[];for(let{line:e,comment:i,token:r}of s)if(i>=0){let s=e.from+i,n=s+r.length;" "==e.text[n-e.from]&&n++,t.push({from:s,to:n})}return{changes:t}}return null}const la=we.define(),ua=we.define(),aa=Dt.define(),fa=Dt.define({combine:t=>Me(t,{minDepth:100,newGroupDelay:500},{minDepth:Math.max,newGroupDelay:Math.min})}),ca=Kt.define({create:()=>Ia.empty,update(t,e){let i=e.state.facet(fa),s=e.annotation(la);if(s){let r=e.docChanged?Gt.single(function(t){let e=0;return t.iterChangedRanges(((t,i)=>e=i)),e}(e.changes)):void 0,n=ga.fromTransaction(e,r),h=s.side,o=0==h?t.undone:t.done;return o=n?xa(o,o.length,i.minDepth,n):Pa(o,e.startState.selection),new Ia(0==h?s.rest:o,0==h?o:s.rest)}let r=e.annotation(ua);if("full"!=r&&"before"!=r||(t=t.isolate()),!1===e.annotation(ye.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let n=ga.fromTransaction(e),h=e.annotation(ye.time),o=e.annotation(ye.userEvent);return n?t=t.addChanges(n,h,o,i.newGroupDelay,i.minDepth):e.selection&&(t=t.addSelection(e.startState.selection,h,o,i.newGroupDelay)),"full"!=r&&"after"!=r||(t=t.isolate()),t},toJSON:t=>({done:t.done.map((t=>t.toJSON())),undone:t.undone.map((t=>t.toJSON()))}),fromJSON:t=>new Ia(t.done.map(ga.fromJSON),t.undone.map(ga.fromJSON))});function Oa(t={}){return[ca,fa.of(t),jn.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?$a:"historyRedo"==t.inputType?pa:null;return!!i&&(t.preventDefault(),i(e))}})]}function da(t,e){return function({state:i,dispatch:s}){if(!e&&i.readOnly)return!1;let r=i.field(ca,!1);if(!r)return!1;let n=r.pop(t,i,e);return!!n&&(s(n),!0)}}const $a=da(0,!1),pa=da(1,!1),ma=da(0,!0),wa=da(1,!0);class ga{constructor(t,e,i,s,r){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(t){return new ga(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:null===(t=this.changes)||void 0===t?void 0:t.toJSON(),mapped:null===(e=this.mapped)||void 0===e?void 0:e.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map((t=>t.toJSON()))}}static fromJSON(t){return new ga(t.changes&&Mt.fromJSON(t.changes),[],t.mapped&&Xt.fromJSON(t.mapped),t.startSelection&&Gt.fromJSON(t.startSelection),t.selectionsAfter.map(Gt.fromJSON))}static fromTransaction(t,e){let i=ya;for(let e of t.startState.facet(aa)){let s=e(t);s.length&&(i=i.concat(s))}return!i.length&&t.changes.empty?null:new ga(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,ya)}static selection(t){return new ga(void 0,ya,void 0,void 0,t)}}function xa(t,e,i,s){let r=e+1>i+20?e-i-1:0,n=t.slice(r,e);return n.push(s),n}function ba(t,e){return t.length?e.length?t.concat(e):t:e}const ya=[],Qa=200;function Pa(t,e){if(t.length){let i=t[t.length-1],s=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-Qa));return s.length&&s[s.length-1].eq(e)?t:(s.push(e),xa(t,t.length-1,1e9,i.setSelAfter(s)))}return[ga.selection([e])]}function va(t){let e=t[t.length-1],i=t.slice();return i[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),i}function qa(t,e){if(!t.length)return t;let i=t.length,s=ya;for(;i;){let r=Sa(t[i-1],e,s);if(r.changes&&!r.changes.empty||r.effects.length){let e=t.slice(0,i);return e[i-1]=r,e}e=r.mapped,i--,s=r.selectionsAfter}return s.length?[ga.selection(s)]:ya}function Sa(t,e,i){let s=ba(t.selectionsAfter.length?t.selectionsAfter.map((t=>t.map(e))):ya,i);if(!t.changes)return ga.selection(s);let r=t.changes.map(e),n=e.mapDesc(t.changes,!0),h=t.mapped?t.mapped.composeDesc(n):n;return new ga(r,be.mapEffects(t.effects,e),h,t.startSelection.map(n),s)}const ka=/^(input\.type|delete)($|\.)/;class Ia{constructor(t,e,i=0,s=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new Ia(this.done,this.undone):this}addChanges(t,e,i,s,r){let n=this.done,h=n[n.length-1];return n=h&&h.changes&&!h.changes.empty&&t.changes&&(!i||ka.test(i))&&(!h.selectionsAfter.length&&e-this.prevTimei.push(t,e))),e.iterChangedRanges(((t,e,r,n)=>{for(let t=0;t=e&&r<=h&&(s=!0)}})),s}(h.changes,t.changes)||"input.type.compose"==i)?xa(n,n.length-1,r,new ga(t.changes.compose(h.changes),ba(t.effects,h.effects),h.mapped,h.startSelection,ya)):xa(n,n.length,r,t),new Ia(n,ya,e,i)}addSelection(t,e,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:ya;return r.length>0&&e-this.prevTimet.empty!=e.ranges[i].empty)).length}(r[r.length-1],t)?this:new Ia(Pa(this.done,t),this.undone,e,i)}addMapping(t){return new Ia(qa(this.done,t),qa(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let s=0==t?this.done:this.undone;if(0==s.length)return null;let r=s[s.length-1];if(i&&r.selectionsAfter.length)return e.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:la.of({side:t,rest:va(s)}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let i=1==s.length?ya:s.slice(0,s.length-1);return r.mapped&&(i=qa(i,r.mapped)),e.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:la.of({side:t,rest:i}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}Ia.empty=new Ia(ya,ya);const Ra=[{key:"Mod-z",run:$a,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:pa,preventDefault:!0},{key:"Mod-u",run:ma,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:wa,preventDefault:!0}];function Wa(t,e){return Gt.create(t.ranges.map(e),t.mainIndex)}function Ya(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Xa({state:t,dispatch:e},i){let s=Wa(t.selection,i);return!s.eq(t.selection)&&(e(Ya(t,s)),!0)}function Ma(t,e){return Gt.cursor(e?t.to:t.from)}function Za(t,e){return Xa(t,(i=>i.empty?t.moveByChar(i,e):Ma(i,e)))}function Ta(t){return t.textDirectionAt(t.state.selection.main.head)==Ns.LTR}const _a=t=>Za(t,!Ta(t)),Ea=t=>Za(t,Ta(t));function Aa(t,e){return Xa(t,(i=>i.empty?t.moveByGroup(i,e):Ma(i,e)))}function ja(t,e,i){if(e.type.prop(i))return!0;let s=e.to-e.from;return s&&(s>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function Ua(t,e,i){let s,r,n=Ml(t).resolveInner(e.head),h=i?Io.closedBy:Io.openedBy;for(let s=e.head;;){let e=i?n.childAfter(s):n.childBefore(s);if(!e)break;ja(t,e,h)?n=e:s=i?e.to:e.from}return r=n.type.prop(h)&&(s=i?zu(t,n.from,1):zu(t,n.to,-1))&&s.matched?i?s.end.to:s.end.from:i?n.to:n.from,Gt.cursor(r,i?-1:1)}function Ga(t,e){return Xa(t,(i=>{if(!i.empty)return Ma(i,e);let s=t.moveVertically(i,e);return s.head!=i.head?s:t.moveToLineBoundary(i,e)}))}const Va=t=>Ga(t,!1),Ca=t=>Ga(t,!0);function Da(t){return Math.max(t.defaultLineHeight,Math.min(t.dom.clientHeight,innerHeight)-5)}function za(t,e){let{state:i}=t,s=Wa(i.selection,(i=>i.empty?t.moveVertically(i,e,Da(t)):Ma(i,e)));if(s.eq(i.selection))return!1;let r,n=t.coordsAtPos(i.selection.main.head),h=t.scrollDOM.getBoundingClientRect();return n&&n.top>h.top&&n.bottomza(t,!1),Na=t=>za(t,!0);function Fa(t,e,i){let s=t.lineBlockAt(e.head),r=t.moveToLineBoundary(e,i);if(r.head==e.head&&r.head!=(i?s.to:s.from)&&(r=t.moveToLineBoundary(e,i,!1)),!i&&r.head==s.from&&s.length){let i=/^\s*/.exec(t.state.sliceDoc(s.from,Math.min(s.from+100,s.to)))[0].length;i&&e.head!=s.from+i&&(r=Gt.cursor(s.from+i))}return r}const Ba=t=>Xa(t,(e=>Fa(t,e,!0))),La=t=>Xa(t,(e=>Fa(t,e,!1)));function Ka(t,e){let i=Wa(t.state.selection,(t=>{let i=e(t);return Gt.range(t.anchor,i.head,i.goalColumn)}));return!i.eq(t.state.selection)&&(t.dispatch(Ya(t.state,i)),!0)}function Ja(t,e){return Ka(t,(i=>t.moveByChar(i,e)))}const tf=t=>Ja(t,!Ta(t)),ef=t=>Ja(t,Ta(t));function sf(t,e){return Ka(t,(i=>t.moveByGroup(i,e)))}function rf(t,e){return Ka(t,(i=>t.moveVertically(i,e)))}const nf=t=>rf(t,!1),hf=t=>rf(t,!0);function of(t,e){return Ka(t,(i=>t.moveVertically(i,e,Da(t))))}const lf=t=>of(t,!1),uf=t=>of(t,!0),af=t=>Ka(t,(e=>Fa(t,e,!0))),ff=t=>Ka(t,(e=>Fa(t,e,!1))),cf=({state:t,dispatch:e})=>(e(Ya(t,{anchor:0})),!0),Of=({state:t,dispatch:e})=>(e(Ya(t,{anchor:t.doc.length})),!0),df=({state:t,dispatch:e})=>(e(Ya(t,{anchor:t.selection.main.anchor,head:0})),!0),$f=({state:t,dispatch:e})=>(e(Ya(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function pf({state:t,dispatch:e},i){if(t.readOnly)return!1;let s="delete.selection",r=t.changeByRange((t=>{let{from:e,to:r}=t;if(e==r){let t=i(e);te&&(s="delete.forward"),e=Math.min(e,t),r=Math.max(r,t)}return e==r?{range:t}:{changes:{from:e,to:r},range:Gt.cursor(e)}}));return!r.changes.empty&&(e(t.update(r,{scrollIntoView:!0,userEvent:s})),!0)}function mf(t,e,i){if(t instanceof jn)for(let s of t.state.facet(jn.atomicRanges).map((e=>e(t))))s.between(e,e,((t,s)=>{te&&(e=i?s:t)}));return e}const wf=(t,e)=>pf(t,(i=>{let s,r,{state:n}=t,h=n.doc.lineAt(i);if(!e&&i>h.from&&iwf(t,!1),xf=t=>wf(t,!0),bf=(t,e)=>pf(t,(i=>{let s=i,{state:r}=t,n=r.doc.lineAt(s),h=r.charCategorizer(s);for(let t=null;;){if(s==(e?n.to:n.from)){s==i&&n.number!=(e?r.doc.lines:1)&&(s+=e?1:-1);break}let o=Qt(n.text,s-n.from,e)+n.from,l=n.text.slice(Math.min(s,o)-n.from,Math.max(s,o)-n.from),u=h(l);if(null!=t&&u!=t)break;" "==l&&s==i||(t=u),s=o}return mf(t,s,e)})),yf=t=>bf(t,!1),Qf=t=>pf(t,(e=>{let i=t.lineBlockAt(e).to;return mf(t,e=r.number){let t=e[e.length-1];t.to=n.to,t.ranges.push(s)}else e.push({from:r.from,to:n.to,ranges:[s]});i=n.number+1}return e}function vf(t,e,i){if(t.readOnly)return!1;let s=[],r=[];for(let e of Pf(t)){if(i?e.to==t.doc.length:0==e.from)continue;let n=t.doc.lineAt(i?e.to+1:e.from-1),h=n.length+1;if(i){s.push({from:e.to,to:n.to},{from:e.from,insert:n.text+t.lineBreak});for(let i of e.ranges)r.push(Gt.range(Math.min(t.doc.length,i.anchor+h),Math.min(t.doc.length,i.head+h)))}else{s.push({from:n.from,to:e.from},{from:e.to,insert:t.lineBreak+n.text});for(let t of e.ranges)r.push(Gt.range(t.anchor-h,t.head-h))}}return!!s.length&&(e(t.update({changes:s,scrollIntoView:!0,selection:Gt.create(r,t.selection.mainIndex),userEvent:"move.line"})),!0)}function qf(t,e,i){if(t.readOnly)return!1;let s=[];for(let e of Pf(t))i?s.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):s.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});return e(t.update({changes:s,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Sf=If(!1),kf=If(!0);function If(t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let s=e.changeByRange((i=>{let{from:s,to:r}=i,n=e.doc.lineAt(s),h=!t&&s==r&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,s=Ml(t).resolveInner(e),r=s.childBefore(e),n=s.childAfter(e);return r&&n&&r.to<=e&&n.from>=e&&(i=r.type.prop(Io.closedBy))&&i.indexOf(n.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(n.from).from?{from:r.to,to:n.from}:null}(e,s);t&&(s=r=(r<=n.to?n:e.doc.lineAt(r)).to);let o=new Bl(e,{simulateBreak:s,simulateDoubleBreak:!!h}),l=Fl(o,s);for(null==l&&(l=/^\s*/.exec(e.doc.lineAt(s).text)[0].length);rn.from&&s{let r=[];for(let n=s.from;n<=s.to;){let h=t.doc.lineAt(n);h.number>i&&(s.empty||s.to>h.from)&&(e(h,r,s),i=h.number),n=h.to+1}let n=t.changes(r);return{changes:r,range:Gt.range(n.mapPos(s.anchor,1),n.mapPos(s.head,1))}}))}const Wf=({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Rf(t,((e,i)=>{i.push({from:e.from,insert:t.facet(zl)})})),{userEvent:"input.indent"})),!0),Yf=({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Rf(t,((e,i)=>{let s=/^\s*/.exec(e.text)[0];if(!s)return;let r=Le(s,t.tabSize),n=0,h=Nl(t,Math.max(0,r-Hl(t)));for(;nAa(t,!Ta(t)),shift:t=>sf(t,!Ta(t))},{mac:"Cmd-ArrowLeft",run:La,shift:ff},{key:"ArrowRight",run:Ea,shift:ef,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>Aa(t,Ta(t)),shift:t=>sf(t,Ta(t))},{mac:"Cmd-ArrowRight",run:Ba,shift:af},{key:"ArrowUp",run:Va,shift:nf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:cf,shift:df},{mac:"Ctrl-ArrowUp",run:Ha,shift:lf},{key:"ArrowDown",run:Ca,shift:hf,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Of,shift:$f},{mac:"Ctrl-ArrowDown",run:Na,shift:uf},{key:"PageUp",run:Ha,shift:lf},{key:"PageDown",run:Na,shift:uf},{key:"Home",run:La,shift:ff,preventDefault:!0},{key:"Mod-Home",run:cf,shift:df},{key:"End",run:Ba,shift:af,preventDefault:!0},{key:"Mod-End",run:Of,shift:$f},{key:"Enter",run:Sf},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:gf,shift:gf},{key:"Delete",run:xf},{key:"Mod-Backspace",mac:"Alt-Backspace",run:yf},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>bf(t,!0)},{mac:"Mod-Backspace",run:t=>pf(t,(e=>{let i=t.lineBlockAt(e).from;return mf(t,e>i?i:Math.max(0,e-1),!1)}))},{mac:"Mod-Delete",run:Qf}].concat([{key:"Ctrl-b",run:_a,shift:tf,preventDefault:!0},{key:"Ctrl-f",run:Ea,shift:ef},{key:"Ctrl-p",run:Va,shift:nf},{key:"Ctrl-n",run:Ca,shift:hf},{key:"Ctrl-a",run:t=>Xa(t,(e=>Gt.cursor(t.lineBlockAt(e.head).from,1))),shift:t=>Ka(t,(e=>Gt.cursor(t.lineBlockAt(e.head).from)))},{key:"Ctrl-e",run:t=>Xa(t,(e=>Gt.cursor(t.lineBlockAt(e.head).to,-1))),shift:t=>Ka(t,(e=>Gt.cursor(t.lineBlockAt(e.head).to)))},{key:"Ctrl-d",run:xf},{key:"Ctrl-h",run:gf},{key:"Ctrl-k",run:Qf},{key:"Ctrl-Alt-h",run:yf},{key:"Ctrl-o",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange((t=>({changes:{from:t.from,to:t.to,insert:ft.of(["",""])},range:Gt.cursor(t.from)})));return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange((e=>{if(!e.empty||0==e.from||e.from==t.doc.length)return{range:e};let i=e.from,s=t.doc.lineAt(i),r=i==s.from?i-1:Qt(s.text,i-s.from,!1)+s.from,n=i==s.to?i+1:Qt(s.text,i-s.from,!0)+s.from;return{changes:{from:r,to:n,insert:t.doc.slice(i,n).append(t.doc.slice(r,i))},range:Gt.cursor(n)}}));return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:Na}].map((t=>({mac:t.key,run:t.run,shift:t.shift})))),Mf=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:t=>Xa(t,(e=>Ua(t.state,e,!Ta(t)))),shift:t=>Ka(t,(e=>Ua(t.state,e,!Ta(t))))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>Xa(t,(e=>Ua(t.state,e,Ta(t)))),shift:t=>Ka(t,(e=>Ua(t.state,e,Ta(t))))},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>vf(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>qf(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>vf(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>qf(t,e,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,s=null;return i.ranges.length>1?s=Gt.create([i.main]):i.main.empty||(s=Gt.create([Gt.cursor(i.main.head)])),!!s&&(e(Ya(t,s)),!0)}},{key:"Mod-Enter",run:kf},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=Pf(t).map((({from:e,to:i})=>Gt.range(e,Math.min(i+1,t.doc.length))));return e(t.update({selection:Gt.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=Wa(t.selection,(e=>{var i;let s=Ml(t).resolveInner(e.head,1);for(;!(s.from=e.to||s.to>e.to&&s.from<=e.from)&&(null===(i=s.parent)||void 0===i?void 0:i.parent);)s=s.parent;return Gt.range(s.to,s.from)}));return e(Ya(t,i)),!0},preventDefault:!0},{key:"Mod-[",run:Yf},{key:"Mod-]",run:Wf},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),s=new Bl(t,{overrideIndentation:t=>{let e=i[t];return e??-1}}),r=Rf(t,((e,r,n)=>{let h=Fl(s,e.from);if(null==h)return;/\S/.test(e.text)||(h=0);let o=/^\s*/.exec(e.text)[0],l=Nl(t,h);(o!=l||n.from{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes(Pf(e).map((({from:t,to:i})=>(t>0?t--:it.moveVertically(e,!0))).map(i);return t.dispatch({changes:i,selection:s,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>function(t,e,i){let s=!1,r=Wa(t.selection,(e=>{let r=zu(t,e.head,-1)||zu(t,e.head,1)||e.head>0&&zu(t,e.head-1,1)||e.head{let e=ra(t.state);return e.line?ea(t):!!e.block&&sa(t)}},{key:"Alt-A",run:ia}].concat(Xf),Zf={key:"Tab",run:Wf,shift:Yf};function Tf(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var s in i)if(Object.prototype.hasOwnProperty.call(i,s)){var r=i[s];"string"==typeof r?t.setAttribute(s,r):null!=r&&(t[s]=r)}e++}for(;et.normalize("NFKD"):t=>t;class Af{constructor(t,e,i=0,s=t.length,r){this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,s),this.bufferStart=i,this.normalize=r?t=>r(Ef(t)):Ef,this.query=this.normalize(e)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return kt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=It(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=Rt(t);let s=this.normalize(e);for(let t=0,r=i;;t++){let n=s.charCodeAt(t),h=this.match(n,r);if(h)return this.value=h,this;if(t==s.length-1)break;r==i&&tthis.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,s=i+e[0].length;if(this.matchPos=s+(i==s?1:0),i==this.curLine.length&&this.nextLine(),ithis.value.to)return this.value={from:i,to:s,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length=i||s.to<=e){let s=new Cf(e,t.sliceString(e,i));return Vf.set(t,s),s}if(s.from==e&&s.to==i)return s;let{text:r,from:n}=s;return n>e&&(r=t.sliceString(e,n)+r,n=e),s.to=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e&&this.flat.tothis.flat.text.length-10&&(e=null),e){let t=this.flat.from+e.index,i=t+e[0].length;return this.value={from:t,to:i,match:e},this.matchPos=i+(t==i?1:0),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Cf.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function zf(t){let e=Tf("input",{class:"cm-textfield",name:"line"});function i(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!i)return;let{state:s}=t,r=s.doc.lineAt(s.selection.main.head),[,n,h,o,l]=i,u=o?+o.slice(1):0,a=h?+h:r.number;if(h&&l){let t=a/100;n&&(t=t*("-"==n?-1:1)+r.number/s.doc.lines),a=Math.round(s.doc.lines*t)}else h&&n&&(a=a*("-"==n?-1:1)+r.number);let f=s.doc.line(Math.max(1,Math.min(s.doc.lines,a)));t.dispatch({effects:Hf.of(!1),selection:Gt.cursor(f.from+Math.max(0,Math.min(u,f.length))),scrollIntoView:!0}),t.focus()}return{dom:Tf("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:Hf.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),i())},onsubmit:t=>{t.preventDefault(),i()}},Tf("label",t.state.phrase("Go to line"),": ",e)," ",Tf("button",{class:"cm-button",type:"submit"},t.state.phrase("go")))}}"undefined"!=typeof Symbol&&(Gf.prototype[Symbol.iterator]=Df.prototype[Symbol.iterator]=function(){return this});const Hf=be.define(),Nf=Kt.define({create:()=>!0,update(t,e){for(let i of e.effects)i.is(Hf)&&(t=i.value);return t},provide:t=>eo.from(t,(t=>t?zf:null))}),Ff=jn.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Bf={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Lf=Dt.define({combine:t=>Me(t,Bf,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});function Kf(t){let e=[sc,ic];return t&&e.push(Lf.of(t)),e}const Jf=ds.mark({class:"cm-selectionMatch"}),tc=ds.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ec(t,e,i,s){return!(0!=i&&t(e.sliceDoc(i-1,i))==Ie.Word||s!=e.doc.length&&t(e.sliceDoc(s,s+1))==Ie.Word)}const ic=Es.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(Lf),{state:i}=t,s=i.selection;if(s.ranges.length>1)return ds.none;let r,n=s.main,h=null;if(n.empty){if(!e.highlightWordAroundCursor)return ds.none;let t=i.wordAt(n.head);if(!t)return ds.none;h=i.charCategorizer(n.head),r=i.sliceDoc(t.from,t.to)}else{let t=n.to-n.from;if(t200)return ds.none;if(e.wholeWords){if(r=i.sliceDoc(n.from,n.to),h=i.charCategorizer(n.head),!ec(h,i,n.from,n.to)||!function(t,e,i,s){return t(e.sliceDoc(i,i+1))==Ie.Word&&t(e.sliceDoc(s-1,s))==Ie.Word}(h,i,n.from,n.to))return ds.none}else if(r=i.sliceDoc(n.from,n.to).trim(),!r)return ds.none}let o=[];for(let s of t.visibleRanges){let t=new Af(i.doc,r,s.from,s.to);for(;!t.next().done;){let{from:s,to:r}=t.value;if((!h||ec(h,i,s,r))&&(n.empty&&s<=n.from&&r>=n.to?o.push(tc.range(s,r)):(s>=n.to||r<=n.from)&&o.push(Jf.range(s,r)),o.length>e.maxMatches))return ds.none}}return ds.set(o)}},{decorations:t=>t.decorations}),sc=jn.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),rc=Dt.define({combine(t){var e;return{top:t.reduce(((t,e)=>null!=t?t:e.top),void 0)||!1,caseSensitive:t.reduce(((t,e)=>null!=t?t:e.caseSensitive),void 0)||!1,createPanel:(null===(e=t.find((t=>t.createPanel)))||void 0===e?void 0:e.createPanel)||(t=>new Ic(t))}}});class nc{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,Uf),!0}catch(t){return!1}}(this.search)),this.unquoted=t.literal?this.search:this.search.replace(/\\([nrt\\])/g,((t,e)=>"n"==e?"\n":"r"==e?"\r":"t"==e?"\t":"\\"))}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp}create(){return this.regexp?new ac(this):new lc(this)}getCursor(t,e=0,i=t.length){return this.regexp?uc(this,t,e,i):oc(this,t,e,i)}}class hc{constructor(t){this.spec=t}}function oc(t,e,i,s){return new Af(e,t.unquoted,i,s,t.caseSensitive?void 0:t=>t.toLowerCase())}class lc extends hc{constructor(t){super(t)}nextMatch(t,e,i){let s=oc(this.spec,t,i,t.length).nextOverlapping();return s.done&&(s=oc(this.spec,t,0,e).nextOverlapping()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=i;;){let i=Math.max(e,s-1e4-this.spec.unquoted.length),r=oc(this.spec,t,i,s),n=null;for(;!r.nextOverlapping().done;)n=r.value;if(n)return n;if(i==e)return null;s-=1e4}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.length)}getReplacement(t){return this.spec.replace}matchAll(t,e){let i=oc(this.spec,t,0,t.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=oc(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function uc(t,e,i,s){return new Gf(e,t.search,t.caseSensitive?void 0:{ignoreCase:!0},i,s)}class ac extends hc{nextMatch(t,e,i){let s=uc(this.spec,t,i,t.length).next();return s.done&&(s=uc(this.spec,t,0,e).next()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=1;;s++){let r=Math.max(e,i-1e4*s),n=uc(this.spec,t,r,i),h=null;for(;!n.next().done;)h=n.value;if(h&&(r==e||h.from>r+10))return h;if(r==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.length)}getReplacement(t){return this.spec.replace.replace(/\$([$&\d+])/g,((e,i)=>"$"==i?"$":"&"==i?t.match[0]:"0"!=i&&+i=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=uc(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const fc=be.define(),cc=be.define(),Oc=Kt.define({create:t=>new dc(vc(t).create(),null),update(t,e){for(let i of e.effects)i.is(fc)?t=new dc(i.value.create(),t.panel):i.is(cc)&&(t=new dc(t.query,i.value?Pc:null));return t},provide:t=>eo.from(t,(t=>t.panel))});class dc{constructor(t,e){this.query=t,this.panel=e}}const $c=ds.mark({class:"cm-searchMatch"}),pc=ds.mark({class:"cm-searchMatch cm-searchMatch-selected"}),mc=Es.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Oc))}update(t){let e=t.state.field(Oc);(e!=t.startState.field(Oc)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return ds.none;let{view:i}=this,s=new je;for(let e=0,r=i.visibleRanges,n=r.length;er[e+1].from-500;)o=r[++e].to;t.highlight(i.state.doc,h,o,((t,e)=>{let r=i.state.selection.ranges.some((i=>i.from==t&&i.to==e));s.add(t,e,r?pc:$c)}))}return s.finish()}},{decorations:t=>t.decorations});function wc(t){return e=>{let i=e.state.field(Oc,!1);return i&&i.query.spec.valid?t(e,i):qc(e)}}const gc=wc(((t,{query:e})=>{let{from:i,to:s}=t.state.selection.main,r=e.nextMatch(t.state.doc,i,s);return!(!r||r.from==i&&r.to==s||(t.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:Xc(t,r),userEvent:"select.search"}),0))})),xc=wc(((t,{query:e})=>{let{state:i}=t,{from:s,to:r}=i.selection.main,n=e.prevMatch(i.doc,s,r);return!!n&&(t.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0,effects:Xc(t,n),userEvent:"select.search"}),!0)})),bc=wc(((t,{query:e})=>{let i=e.matchAll(t.state.doc,1e3);return!(!i||!i.length||(t.dispatch({selection:Gt.create(i.map((t=>Gt.range(t.from,t.to)))),userEvent:"select.search.matches"}),0))})),yc=wc(((t,{query:e})=>{let{state:i}=t,{from:s,to:r}=i.selection.main;if(i.readOnly)return!1;let n=e.nextMatch(i.doc,s,s);if(!n)return!1;let h,o,l=[],u=[];if(n.from==s&&n.to==r&&(o=i.toText(e.getReplacement(n)),l.push({from:n.from,to:n.to,insert:o}),n=e.nextMatch(i.doc,n.from,n.to),u.push(jn.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(s).number)+"."))),n){let e=0==l.length||l[0].from>=n.to?0:n.to-n.from-o.length;h={anchor:n.from-e,head:n.to-e},u.push(Xc(t,n))}return t.dispatch({changes:l,selection:h,scrollIntoView:!!h,effects:u,userEvent:"input.replace"}),!0})),Qc=wc(((t,{query:e})=>{if(t.state.readOnly)return!1;let i=e.matchAll(t.state.doc,1e9).map((t=>{let{from:i,to:s}=t;return{from:i,to:s,insert:e.getReplacement(t)}}));if(!i.length)return!1;let s=t.state.phrase("replaced $ matches",i.length)+".";return t.dispatch({changes:i,effects:jn.announce.of(s),userEvent:"input.replace.all"}),!0}));function Pc(t){return t.state.facet(rc).createPanel(t)}function vc(t,e){var i;let s=t.selection.main,r=s.empty||s.to>s.from+100?"":t.sliceDoc(s.from,s.to),n=null!==(i=null==e?void 0:e.caseSensitive)&&void 0!==i?i:t.facet(rc).caseSensitive;return e&&!r?e:new nc({search:r.replace(/\n/g,"\\n"),caseSensitive:n})}const qc=t=>{let e=t.state.field(Oc,!1);if(e&&e.panel){let i=Lh(t,Pc);if(!i)return!1;let s=i.dom.querySelector("[main-field]");if(s&&s!=t.root.activeElement){let i=vc(t.state,e.query.spec);i.valid&&t.dispatch({effects:fc.of(i)}),s.focus(),s.select()}}else t.dispatch({effects:[cc.of(!0),e?fc.of(vc(t.state,e.query.spec)):be.appendConfig.of(Zc)]});return!0},Sc=t=>{let e=t.state.field(Oc,!1);if(!e||!e.panel)return!1;let i=Lh(t,Pc);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:cc.of(!1)}),!0},kc=[{key:"Mod-f",run:qc,scope:"editor search-panel"},{key:"F3",run:gc,shift:xc,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:gc,shift:xc,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Sc,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:t,dispatch:e})=>{let i=t.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:s,to:r}=i.main,n=[],h=0;for(let e=new Af(t.doc,t.sliceDoc(s,r));!e.next().done;){if(n.length>1e3)return!1;e.value.from==s&&(h=n.length),n.push(Gt.range(e.value.from,e.value.to))}return e(t.update({selection:Gt.create(n,h),userEvent:"select.search.matches"})),!0}},{key:"Alt-g",run:t=>{let e=Lh(t,zf);if(!e){let i=[Hf.of(!0)];null==t.state.field(Nf,!1)&&i.push(be.appendConfig.of([Nf,Ff])),t.dispatch({effects:i}),e=Lh(t,zf)}return e&&e.dom.querySelector("input").focus(),!0}},{key:"Mod-d",run:({state:t,dispatch:e})=>{let{ranges:i}=t.selection;if(i.some((t=>t.from===t.to)))return(({state:t,dispatch:e})=>{let{selection:i}=t,s=Gt.create(i.ranges.map((e=>t.wordAt(e.head)||Gt.cursor(e.head))),i.mainIndex);return!s.eq(i)&&(e(t.update({selection:s})),!0)})({state:t,dispatch:e});let s=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some((e=>t.sliceDoc(e.from,e.to)!=s)))return!1;let r=function(t,e){let{main:i,ranges:s}=t.selection,r=t.wordAt(i.head),n=r&&r.from==i.from&&r.to==i.to;for(let i=!1,r=new Af(t.doc,e,s[s.length-1].to);;){if(r.next(),!r.done){if(i&&s.some((t=>t.from==r.value.from)))continue;if(n){let e=t.wordAt(r.value.from);if(!e||e.from!=r.value.from||e.to!=r.value.to)continue}return r.value}if(i)return null;r=new Af(t.doc,e,0,Math.max(0,s[s.length-1].from-1)),i=!0}}(t,s);return!!r&&(e(t.update({selection:t.selection.addRange(Gt.range(r.from,r.to),!1),effects:jn.scrollIntoView(r.to)})),!0)},preventDefault:!0}];class Ic{constructor(t){this.view=t;let e=this.query=t.state.field(Oc).query.spec;function i(t,e,i){return Tf("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=Tf("input",{value:e.search,placeholder:Rc(t,"Find"),"aria-label":Rc(t,"Find"),class:"cm-textfield",name:"search","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Tf("input",{value:e.replace,placeholder:Rc(t,"Replace"),"aria-label":Rc(t,"Replace"),class:"cm-textfield",name:"replace",onchange:this.commit,onkeyup:this.commit}),this.caseField=Tf("input",{type:"checkbox",name:"case",checked:e.caseSensitive,onchange:this.commit}),this.reField=Tf("input",{type:"checkbox",name:"re",checked:e.regexp,onchange:this.commit}),this.dom=Tf("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",(()=>gc(t)),[Rc(t,"next")]),i("prev",(()=>xc(t)),[Rc(t,"previous")]),i("select",(()=>bc(t)),[Rc(t,"all")]),Tf("label",null,[this.caseField,Rc(t,"match case")]),Tf("label",null,[this.reField,Rc(t,"regexp")]),...t.state.readOnly?[]:[Tf("br"),this.replaceField,i("replace",(()=>yc(t)),[Rc(t,"replace")]),i("replaceAll",(()=>Qc(t)),[Rc(t,"replace all")]),Tf("button",{name:"close",onclick:()=>Sc(t),"aria-label":Rc(t,"close"),type:"button"},["×"])]])}commit(){let t=new nc({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:fc.of(t)}))}keydown(t){var e,i,s;e=this.view,i=t,s="search-panel",Jn(Bn(e.state),i,e,s)?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?xc:gc)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),yc(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(fc)&&!t.value.eq(this.query)&&this.setQuery(t.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(rc).top}}function Rc(t,e){return t.state.phrase(e)}const Wc=30,Yc=/[\s\.,:;?!]/;function Xc(t,{from:e,to:i}){let s=t.state.doc.lineAt(e),r=t.state.doc.lineAt(i).to,n=Math.max(s.from,e-Wc),h=Math.min(r,i+Wc),o=t.state.sliceDoc(n,h);if(n!=s.from)for(let t=0;to.length-Wc;t--)if(!Yc.test(o[t-1])&&Yc.test(o[t])){o=o.slice(0,t);break}return jn.announce.of(`${t.state.phrase("current match")}. ${o} ${t.state.phrase("on line")} ${s.number}.`)}const Mc=jn.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Zc=[Oc,re.lowest(mc),Mc];class Tc{constructor(t,e,i){this.state=t,this.pos=e,this.explicit=i,this.abortListeners=[]}tokenBefore(t){let e=Ml(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),s=e.text.slice(i-e.from,this.pos-e.from),r=s.search(Uc(t,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return null==this.abortListeners}addEventListener(t,e){"abort"==t&&this.abortListeners&&this.abortListeners.push(e)}}function _c(t){let e=Object.keys(t).join(""),i=/\w/.test(e);return i&&(e=e.replace(/\w/g,"")),`[${i?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function Ec(t){let e=t.map((t=>"string"==typeof t?{label:t}:t)),[i,s]=e.every((t=>/^\w+$/.test(t.label)))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),i=Object.create(null);for(let{label:s}of t){e[s[0]]=!0;for(let t=1;t{let r=t.matchBefore(s);return r||t.explicit?{from:r?r.from:t.pos,options:e,validFor:i}:null}}class Ac{constructor(t,e,i){this.completion=t,this.source=e,this.match=i}}function jc(t){return t.selection.main.head}function Uc(t,e){var i;let{source:s}=t,r=e&&"^"!=s[0],n="$"!=s[s.length-1];return r||n?new RegExp(`${r?"^":""}(?:${s})${n?"$":""}`,null!==(i=t.flags)&&void 0!==i?i:t.ignoreCase?"i":""):t}function Gc(t,e){const i=e.completion.apply||e.completion.label;let s=e.source;var r,n,h,o;"string"==typeof i?t.dispatch((r=t.state,n=i,h=s.from,o=s.to,Object.assign(Object.assign({},r.changeByRange((t=>{if(t==r.selection.main)return{changes:{from:h,to:o,insert:n},range:Gt.cursor(h+n.length)};let e=o-h;return!t.empty||e&&r.sliceDoc(t.from-e,t.from)!=r.sliceDoc(h,o)?{range:t}:{changes:{from:t.from-e,to:t.from,insert:n},range:Gt.cursor(t.from-e+n.length)}}))),{userEvent:"input.complete"}))):i(t,e.completion,s.from,s.to)}const Vc=new WeakMap;function Cc(t){if(!Array.isArray(t))return t;let e=Vc.get(t);return e||Vc.set(t,e=Ec(t)),e}class Dc{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[];for(let e=0;e=48&&l<=57||l>=97&&l<=122?2:l>=65&&l<=90?1:0:(w=It(l))!=w.toLowerCase()?1:w!=w.toUpperCase()?2:0;(!s||1==g&&$||0==m&&0!=g)&&(e[a]==l||i[a]==l&&(f=!0)?n[a++]=s:n.length&&(p=!1)),m=g,s+=Rt(l)}return a==o&&0==n[0]&&p?this.result((f?-200:0)-100,n,t):c==o&&0==O?[-200-t.length,0,d]:h>-1?[-700-t.length,h,h+this.pattern.length]:c==o?[-900-t.length,O,d]:a==o?this.result((f?-200:0)-100-700+(p?0:-1100),n,t):2==e.length?null:this.result((s[0]?-700:0)-200-1100,s,t)}result(t,e,i){let s=[t-i.length],r=1;for(let t of e){let e=t+(this.astral?Rt(kt(i,t)):1);r>1&&s[r-1]==t?s[r-1]=e:(s[r++]=t,s[r++]=e)}return s}}const zc=Dt.define({combine:t=>Me(t,{activateOnTyping:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[]},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,optionClass:(t,e)=>i=>function(t,e){return t?e?t+" "+e:t:e}(t(i),e(i)),addToOptions:(t,e)=>t.concat(e)})});function Hc(t,e,i){if(t<=i)return{from:0,to:t};if(e<=t>>1){let t=Math.floor(e/i);return{from:t*i,to:(t+1)*i}}let s=Math.floor((t-e)/i);return{from:t-(s+1)*i,to:t-s*i}}class Nc{constructor(t,e){this.view=t,this.stateField=e,this.info=null,this.placeInfo={read:()=>this.measureInfo(),write:t=>this.positionInfo(t),key:this};let i=t.state.field(e),{options:s,selected:r}=i.open,n=t.state.facet(zc);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map((t=>"cm-completionIcon-"+t))),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,i){let s=document.createElement("span");s.className="cm-completionLabel";let{label:r}=t,n=0;for(let t=1;tn&&s.appendChild(document.createTextNode(r.slice(n,e)));let o=s.appendChild(document.createElement("span"));o.appendChild(document.createTextNode(r.slice(e,h))),o.className="cm-completionMatchedText",n=h}return nt.position-e.position)).map((t=>t.render))}(n),this.optionClass=n.optionClass,this.range=Hc(s.length,r,n.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.dom.addEventListener("mousedown",(e=>{for(let i,r=e.target;r&&r!=this.dom;r=r.parentNode)if("LI"==r.nodeName&&(i=/-(\d+)$/.exec(r.id))&&+i[1]{this.info&&this.view.requestMeasure(this.placeInfo)}))}mount(){this.updateSel()}update(t){t.state.field(this.stateField)!=t.startState.field(this.stateField)&&this.updateSel()}positioned(){this.info&&this.view.requestMeasure(this.placeInfo)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected=this.range.to)&&(this.range=Hc(e.options.length,e.selected,this.view.state.facet(zc).maxRenderedOptions),this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e.options,t.id,this.range)),this.list.addEventListener("scroll",(()=>{this.info&&this.view.requestMeasure(this.placeInfo)}))),this.updateSelectedOption(e.selected)){this.info&&(this.info.remove(),this.info=null);let{completion:i}=e.options[e.selected],{info:s}=i;if(!s)return;let r="string"==typeof s?document.createTextNode(s):s(i);if(!r)return;"then"in r?r.then((e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e)})).catch((t=>Ms(this.view.state,t,"completion info"))):this.addInfoPane(r)}}addInfoPane(t){let e=this.info=document.createElement("div");e.className="cm-tooltip cm-completionInfo",e.appendChild(t),this.dom.appendChild(e),this.view.requestMeasure(this.placeInfo)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)s==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return e&&function(t,e){let i=t.getBoundingClientRect(),s=e.getBoundingClientRect();s.topi.bottom&&(t.scrollTop+=s.bottom-i.bottom)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=t.getBoundingClientRect();if(s.top>Math.min(innerHeight,e.bottom)-10||s.bottom=this.options.length?this:new Bc(this.options,Jc(e,t),this.tooltip,this.timestamp,t)}static build(t,e,i,s,r){let n=function(t,e){let i=[],s=0;for(let r of t)if(r.hasResult())if(!1===r.result.filter){let t=r.result.getMatch;for(let e of r.result.options){let n=[1e9-s++];if(t)for(let i of t(e))n.push(i);i.push(new Ac(e,r,n))}}else{let t,s=new Dc(e.sliceDoc(r.from,r.to));for(let e of r.result.options)(t=s.match(e.label))&&(null!=e.boost&&(t[0]+=e.boost),i.push(new Ac(e,r,t)))}let r=[],n=null;for(let t of i.sort(eO))!n||n.label!=t.completion.label||n.detail!=t.completion.detail||null!=n.type&&null!=t.completion.type&&n.type!=t.completion.type||n.apply!=t.completion.apply?r.push(t):Fc(t.completion)>Fc(n)&&(r[r.length-1]=t),n=t.completion;return r}(t,e);if(!n.length)return null;let h=0;if(s&&s.selected){let t=s.options[s.selected].completion;for(let e=0;ee.hasResult()?Math.min(t,e.from):t),1e8),create:(o=uO,t=>new Nc(t,o)),above:r.aboveCursor},s?s.timestamp:Date.now(),h);var o}map(t){return new Bc(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected)}}class Lc{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new Lc(tO,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,i=e.facet(zc),s=(i.override||e.languageDataAt("autocomplete",jc(e)).map(Cc)).map((e=>{let s=this.active.find((t=>t.source==e))||new sO(e,this.active.some((t=>0!=t.state))?1:0);return s.update(t,i)}));s.length==this.active.length&&s.every(((t,e)=>t==this.active[e]))&&(s=this.active);let r=t.selection||s.some((e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to)))||!function(t,e){if(t==e)return!0;for(let i=0,s=0;;){for(;i1!=t.state))&&s.some((t=>t.hasResult()))&&(s=s.map((t=>t.hasResult()?new sO(t.source,0):t)));for(let e of t.effects)e.is(lO)&&(r=r&&r.setSelected(e.value,this.id));return s==this.active&&r==this.open?this:new Lc(s,this.id,r)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:Kc}}const Kc={"aria-autocomplete":"list"};function Jc(t,e){return{"aria-autocomplete":"list","aria-haspopup":"listbox","aria-activedescendant":t+"-"+e,"aria-controls":t}}const tO=[];function eO(t,e){let i=e.match[0]-t.match[0];return i||t.completion.label.localeCompare(e.completion.label)}function iO(t){return t.isUserEvent("input.type")?"input":t.isUserEvent("delete.backward")?"delete":null}class sO{constructor(t,e,i=-1){this.source=t,this.state=e,this.explicitPos=i}hasResult(){return!1}update(t,e){let i=iO(t),s=this;i?s=s.handleUserEvent(t,i,e):t.docChanged?s=s.handleChange(t):t.selection&&0!=s.state&&(s=new sO(s.source,0));for(let e of t.effects)if(e.is(nO))s=new sO(s.source,1,e.value?jc(t.state):-1);else if(e.is(hO))s=new sO(s.source,0);else if(e.is(oO))for(let t of e.value)t.source==s.source&&(s=t);return s}handleUserEvent(t,e,i){return"delete"!=e&&i.activateOnTyping?new sO(this.source,1):this.map(t.changes)}handleChange(t){return t.changes.touchesRange(jc(t.startState))?new sO(this.source,0):this.map(t.changes)}map(t){return t.empty||this.explicitPos<0?this:new sO(this.source,this.state,t.mapPos(this.explicitPos))}}class rO extends sO{constructor(t,e,i,s,r){super(t,2,e),this.result=i,this.from=s,this.to=r}hasResult(){return!0}handleUserEvent(t,e,i){var s;let r=t.changes.mapPos(this.from),n=t.changes.mapPos(this.to,1),h=jc(t.state);if((this.explicitPos<0?h<=r:hn||"delete"==e&&jc(t.startState)==this.from)return new sO(this.source,"input"==e&&i.activateOnTyping?1:0);let o,l=this.explicitPos<0?-1:t.changes.mapPos(this.explicitPos);return function(t,e,i,s){if(!t)return!1;let r=e.sliceDoc(i,s);return"function"==typeof t?t(r,i,s,e):Uc(t,!0).test(r)}(this.result.validFor,t.state,r,n)?new rO(this.source,l,this.result,r,n):this.result.update&&(o=this.result.update(this.result,r,n,new Tc(t.state,h,l>=0)))?new rO(this.source,l,o,o.from,null!==(s=o.to)&&void 0!==s?s:jc(t.state)):new sO(this.source,1,l)}handleChange(t){return t.changes.touchesRange(this.from,this.to)?new sO(this.source,0):this.map(t.changes)}map(t){return t.empty?this:new rO(this.source,this.explicitPos<0?-1:t.mapPos(this.explicitPos),this.result,t.mapPos(this.from),t.mapPos(this.to,1))}}const nO=be.define(),hO=be.define(),oO=be.define({map:(t,e)=>t.map((t=>t.map(e)))}),lO=be.define(),uO=Kt.define({create:()=>Lc.start(),update:(t,e)=>t.update(e),provide:t=>[Vh.from(t,(t=>t.tooltip)),jn.contentAttributes.from(t,(t=>t.attrs))]});function aO(t,e="option"){return i=>{let s=i.state.field(uO,!1);if(!s||!s.open||Date.now()-s.open.timestamp<75)return!1;let r,n=1;"page"==e&&(r=function(t,e){let i=t.plugin(jh);if(!i)return null;let s=i.manager.tooltips.indexOf(e);return s<0?null:i.manager.tooltipViews[s]}(i,s.open.tooltip))&&(n=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let h=s.open.selected+n*(t?1:-1),{length:o}=s.open.options;return h<0?h="page"==e?0:o-1:h>=o&&(h="page"==e?o-1:0),i.dispatch({effects:lO.of(h)}),!0}}class fO{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const cO=Es.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.composing=0;for(let e of t.state.field(uO).active)1==e.state&&this.startQuery(e)}update(t){let e=t.state.field(uO);if(!t.selectionSet&&!t.docChanged&&t.startState.field(uO)==e)return;let i=t.transactions.some((t=>(t.selection||t.docChanged)&&!iO(t)));for(let e=0;e50&&Date.now()-s.time>1e3){for(let t of s.context.abortListeners)try{t()}catch(t){Ms(this.view.state,t)}s.context.abortListeners=null,this.running.splice(e--,1)}else s.updates.push(...t.transactions)}if(this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),this.debounceUpdate=e.active.some((t=>1==t.state&&!this.running.some((e=>e.active.source==t.source))))?setTimeout((()=>this.startUpdate()),50):-1,0!=this.composing)for(let e of t.transactions)"input"==iO(e)?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1;let{state:t}=this.view,e=t.field(uO);for(let t of e.active)1!=t.state||this.running.some((e=>e.active.source==t.source))||this.startQuery(t)}startQuery(t){let{state:e}=this.view,i=jc(e),s=new Tc(e,i,t.explicitPos==i),r=new fO(t,s);this.running.push(r),Promise.resolve(t.source(s)).then((t=>{r.context.aborted||(r.done=t||null,this.scheduleAccept())}),(t=>{this.view.dispatch({effects:hO.of(null)}),Ms(this.view.state,t)}))}scheduleAccept(){this.running.every((t=>void 0!==t.done))?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout((()=>this.accept()),50))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],i=this.view.state.facet(zc);for(let s=0;st.source==r.active.source));if(n&&1==n.state)if(null==r.done){let t=new sO(r.active.source,0);for(let e of r.updates)t=t.update(e,i);1!=t.state&&e.push(t)}else this.startQuery(n)}e.length&&this.view.dispatch({effects:oO.of(e)})}},{eventHandlers:{blur(){let t=this.view.state.field(uO,!1);t&&t.tooltip&&this.view.state.facet(zc).closeOnBlur&&this.view.dispatch({effects:hO.of(null)})},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout((()=>this.view.dispatch({effects:nO.of(!1)})),20),this.composing=0}}}),OO=jn.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",listStyle:"none",margin:0,padding:0,"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer",padding:"1px 3px",lineHeight:1.2}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"300px"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),dO={brackets:["(","[","{","'",'"'],before:")]}:;>"},$O=be.define({map(t,e){let i=e.mapPos(t,-1,Yt.TrackAfter);return i??void 0}}),pO=be.define({map:(t,e)=>e.mapPos(t)}),mO=new class extends Ze{};mO.startSide=1,mO.endSide=-1;const wO=Kt.define({create:()=>Ae.empty,update(t,e){if(e.selection){let i=e.state.doc.lineAt(e.selection.main.head).from,s=e.startState.doc.lineAt(e.startState.selection.main.head).from;i!=e.changes.mapPos(s,-1)&&(t=Ae.empty)}t=t.map(e.changes);for(let i of e.effects)i.is($O)?t=t.update({add:[mO.range(i.value,i.value+1)]}):i.is(pO)&&(t=t.update({filter:t=>t!=i.value}));return t}});function gO(){return[PO,wO]}const xO="()[]{}<>";function bO(t){for(let e=0;e<8;e+=2)if(xO.charCodeAt(e)==t)return xO.charAt(e+1);return It(t<128?t:t+1)}function yO(t,e){return t.languageDataAt("closeBrackets",e)[0]||dO}const QO="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),PO=jn.inputHandler.of(((t,e,i,s)=>{if((QO?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let r=t.state.selection.main;if(s.length>2||2==s.length&&1==Rt(kt(s,0))||e!=r.from||i!=r.to)return!1;let n=function(t,e){let i=yO(t,t.selection.main.head),s=i.brackets||dO.brackets;for(let r of s){let n=bO(kt(r,0));if(e==r)return n==r?RO(t,r,s.indexOf(r+r+r)>-1):kO(t,r,n,i.before||dO.before);if(e==n&&qO(t,t.selection.main.from))return IO(t,0,n)}return null}(t.state,s);return!!n&&(t.dispatch(n),!0)})),vO=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=yO(t,t.selection.main.head).brackets||dO.brackets,s=null,r=t.changeByRange((e=>{if(e.empty){let s=function(t,e){let i=t.sliceString(e-2,e);return Rt(kt(i,0))==i.length?i:i.slice(1)}(t.doc,e.head);for(let r of i)if(r==s&&SO(t.doc,e.head)==bO(kt(r,0)))return{changes:{from:e.head-r.length,to:e.head+r.length},range:Gt.cursor(e.head-r.length),userEvent:"delete.backward"}}return{range:s=e}}));return s||e(t.update(r,{scrollIntoView:!0})),!s}}];function qO(t,e){let i=!1;return t.field(wO).between(0,t.doc.length,(t=>{t==e&&(i=!0)})),i}function SO(t,e){let i=t.sliceString(e,e+2);return i.slice(0,Rt(kt(i,0)))}function kO(t,e,i,s){let r=null,n=t.changeByRange((n=>{if(!n.empty)return{changes:[{insert:e,from:n.from},{insert:i,from:n.to}],effects:$O.of(n.to+e.length),range:Gt.range(n.anchor+e.length,n.head+e.length)};let h=SO(t.doc,n.head);return!h||/\s/.test(h)||s.indexOf(h)>-1?{changes:{insert:e+i,from:n.head},effects:$O.of(n.head+e.length),range:Gt.cursor(n.head+e.length)}:{range:r=n}}));return r?null:t.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function IO(t,e,i){let s=null,r=t.selection.ranges.map((e=>e.empty&&SO(t.doc,e.head)==i?Gt.cursor(e.head+i.length):s=e));return s?null:t.update({selection:Gt.create(r,t.selection.mainIndex),scrollIntoView:!0,effects:t.selection.ranges.map((({from:t})=>pO.of(t)))})}function RO(t,e,i){let s=null,r=t.changeByRange((r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:e,from:r.to}],effects:$O.of(r.to+e.length),range:Gt.range(r.anchor+e.length,r.head+e.length)};let n=r.head,h=SO(t.doc,n);if(h==e){if(WO(t,n))return{changes:{insert:e+e,from:n},effects:$O.of(n+e.length),range:Gt.cursor(n+e.length)};if(qO(t,n)){let s=i&&t.sliceDoc(n,n+3*e.length)==e+e+e;return{range:Gt.cursor(n+e.length*(s?3:1)),effects:pO.of(n)}}}else{if(i&&t.sliceDoc(n-2*e.length,n)==e+e&&WO(t,n-2*e.length))return{changes:{insert:e+e+e+e,from:n},effects:$O.of(n+e.length),range:Gt.cursor(n+e.length)};if(t.charCategorizer(n)(h)!=Ie.Word){let i=t.sliceDoc(n-1,n);if(i!=e&&t.charCategorizer(n)(i)!=Ie.Word&&!function(t,e,i){let s=Ml(t).resolveInner(e,-1);for(let r=0;r<5;r++){if(t.sliceDoc(s.from,s.from+i.length)==i)return!0;let r=s.to==e&&s.parent;if(!r)break;s=r}return!1}(t,n,e))return{changes:{insert:e+e,from:n},effects:$O.of(n+e.length),range:Gt.cursor(n+e.length)}}}return{range:s=r}}));return s?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function WO(t,e){let i=Ml(t).resolveInner(e+1);return i.parent&&i.from==e}function YO(t={}){return[uO,zc.of(t),cO,MO,OO]}const XO=[{key:"Ctrl-Space",run:t=>!!t.state.field(uO,!1)&&(t.dispatch({effects:nO.of(!0)}),!0)},{key:"Escape",run:t=>{let e=t.state.field(uO,!1);return!(!e||!e.active.some((t=>0!=t.state))||(t.dispatch({effects:hO.of(null)}),0))}},{key:"ArrowDown",run:aO(!0)},{key:"ArrowUp",run:aO(!1)},{key:"PageDown",run:aO(!0,"page")},{key:"PageUp",run:aO(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field(uO,!1);return!(t.state.readOnly||!e||!e.open||Date.now()-e.open.timestamp<75||(Gc(t,e.open.options[e.open.selected]),0))}}],MO=re.highest(Nn.computeN([zc],(t=>t.facet(zc).defaultKeymap?[XO]:[])));class ZO{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class TO{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let s=t,r=i.facet(BO).markerFilter;r&&(s=r(s));let n=ds.set(s.map((t=>t.from==t.to||t.from==t.to-1&&i.doc.lineAt(t.from).to==t.from?ds.widget({widget:new JO(t),diagnostic:t}).range(t.from):ds.mark({attributes:{class:"cm-lintRange cm-lintRange-"+t.severity},diagnostic:t}).range(t.from,t.to))),!0);return new TO(n,e,_O(n))}}function _O(t,e=null,i=0){let s=null;return t.between(i,1e9,((t,i,{spec:r})=>{if(!e||r.diagnostic==e)return s=new ZO(t,i,r.diagnostic),!1})),s}function EO(t,e){return!(!t.effects.some((t=>t.is(jO)))&&!t.changes.touchesRange(e.pos))}function AO(t,e){return t.field(VO,!1)?e:e.concat(be.appendConfig.of([VO,jn.decorations.compute([VO],(t=>{let{selected:e,panel:i}=t.field(VO);return e&&i&&e.from!=e.to?ds.set([CO.range(e.from,e.to)]):ds.none})),Nh(DO,{hideOn:EO}),sd]))}const jO=be.define(),UO=be.define(),GO=be.define(),VO=Kt.define({create:()=>new TO(ds.none,null,null),update(t,e){if(e.docChanged){let i=t.diagnostics.map(e.changes),s=null;if(t.selected){let r=e.changes.mapPos(t.selected.from,1);s=_O(i,t.selected.diagnostic,r)||_O(i,null,r)}t=new TO(i,t.panel,s)}for(let i of e.effects)i.is(jO)?t=TO.init(i.value,t.panel,e.state):i.is(UO)?t=new TO(t.diagnostics,i.value?ed.open:null,t.selected):i.is(GO)&&(t=new TO(t.diagnostics,t.panel,i.value));return t},provide:t=>[eo.from(t,(t=>t.panel)),jn.decorations.from(t,(t=>t.diagnostics))]}),CO=ds.mark({class:"cm-lintRange cm-lintRange-active"});function DO(t,e,i){let{diagnostics:s}=t.state.field(VO),r=[],n=2e8,h=0;s.between(e-(i<0?1:0),e+(i>0?1:0),((t,s,{spec:o})=>{e>=t&&e<=s&&(t==s||(e>t||i>0)&&(e({dom:zO(t,r)})}:null}function zO(t,e){return Tf("ul",{class:"cm-tooltip-lint"},e.map((e=>KO(t,e,!1))))}const HO=t=>{let e=t.state.field(VO,!1);return!(!e||!e.panel||(t.dispatch({effects:UO.of(!1)}),0))},NO=[{key:"Mod-Shift-m",run:t=>{let e=t.state.field(VO,!1);e&&e.panel||t.dispatch({effects:AO(t.state,[UO.of(!0)])});let i=Lh(t,ed.open);return i&&i.dom.querySelector(".cm-panel-lint ul").focus(),!0}},{key:"F8",run:t=>{let e=t.state.field(VO,!1);if(!e)return!1;let i=t.state.selection.main,s=e.diagnostics.iter(i.to+1);return!(!s.value&&(s=e.diagnostics.iter(0),!s.value||s.from==i.from&&s.to==i.to)||(t.dispatch({selection:{anchor:s.from,head:s.to},scrollIntoView:!0}),0))}}],FO=Es.fromClass(class{constructor(t){this.view=t,this.timeout=-1,this.set=!0;let{delay:e}=t.state.facet(BO);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){let t=Date.now();if(tPromise.resolve(t(this.view))))).then((e=>{let i=e.reduce(((t,e)=>t.concat(e)));this.view.state.doc==t.doc&&this.view.dispatch(function(t,e){return{effects:AO(t,[jO.of(e)])}}(this.view.state,i))}),(t=>{Ms(this.view.state,t)}))}}update(t){let e=t.state.facet(BO);(t.docChanged||e!=t.startState.facet(BO))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}}),BO=Dt.define({combine:t=>Object.assign({sources:t.map((t=>t.source))},Me(t.map((t=>t.config)),{delay:750,markerFilter:null,tooltipFilter:null})),enables:FO});function LO(t){let e=[];if(t)t:for(let{name:i}of t){for(let t=0;tt.toLowerCase()==s.toLowerCase()))){e.push(s);continue t}}e.push("")}return e}function KO(t,e,i){var s;let r=i?LO(e.actions):[];return Tf("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Tf("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage():e.message),null===(s=e.actions)||void 0===s?void 0:s.map(((i,s)=>{let n=s=>{s.preventDefault();let r=_O(t.state.field(VO).diagnostics,e);r&&i.apply(t,r.from,r.to)},{name:h}=i,o=r[s]?h.indexOf(r[s]):-1,l=o<0?h:[h.slice(0,o),Tf("u",h.slice(o,o+1)),h.slice(o+1)];return Tf("button",{type:"button",class:"cm-diagnosticAction",onclick:n,onmousedown:n,"aria-label":` Action: ${h}${o<0?"":` (access key "${r[s]})"`}.`},l)})),e.source&&Tf("div",{class:"cm-diagnosticSource"},e.source))}class JO extends cs{constructor(t){super(),this.diagnostic=t}eq(t){return t.diagnostic==this.diagnostic}toDOM(){return Tf("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class td{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=KO(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class ed{constructor(t){this.view=t,this.items=[],this.list=Tf("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(27==e.keyCode)HO(this.view),this.view.focus();else if(38==e.keyCode||33==e.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==e.keyCode||34==e.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==e.keyCode)this.moveSelection(0);else if(35==e.keyCode)this.moveSelection(this.items.length-1);else if(13==e.keyCode)this.view.focus();else{if(!(e.keyCode>=65&&e.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],s=LO(i.actions);for(let r=0;r{for(let e=0;eHO(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(VO).selected;if(!t)return-1;for(let e=0;e{let o,l=-1;for(let t=i;ti&&(this.items.splice(i,l-i),s=!0)),e&&o.diagnostic==e.diagnostic?o.dom.hasAttribute("aria-selected")||(o.dom.setAttribute("aria-selected","true"),r=o):o.dom.hasAttribute("aria-selected")&&o.dom.removeAttribute("aria-selected"),i++}));i({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:t,panel:e})=>{t.tope.bottom&&(this.list.scrollTop+=t.bottom-e.bottom)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let t=this.list.firstChild;function e(){let e=t;t=e.nextSibling,e.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=_O(this.view.state.field(VO).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:GO.of(e)})}static open(t){return new ed(t)}}function id(t){return function(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,${encodeURIComponent(t)}')`}(``,'width="6" height="3"')}const sd=jn.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:id("#d11")},".cm-lintRange-warning":{backgroundImage:id("orange")},".cm-lintRange-info":{backgroundImage:id("#999")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}}),rd=[bo(),vo(),yh(),Oa(),qu(),ih(),dh(),Xe.allowMultipleSelections.of(!0),nu(),Yu(Zu,{fallback:!0}),Cu(),gO(),YO(),Yh(),Zh(),qh(),Kf(),Nn.of([...vO,...Mf,...kc,...Ra,...gu,...XO,...NO])];class nd{constructor(t,e,i,s,r,n,h,o,l,u=0,a){this.p=t,this.stack=e,this.state=i,this.reducePos=s,this.pos=r,this.score=n,this.buffer=h,this.bufferBase=o,this.curContext=l,this.lookAhead=u,this.parent=a}toString(){return`[${this.stack.filter(((t,e)=>e%3==0)).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let s=t.parser.context;return new nd(t,[],e,i,i,0,[],0,s?new hd(s,s.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){let e=t>>19,i=65535&t,{parser:s}=this.p,r=s.dynamicPrecedence(i);if(r&&(this.score+=r),0==e)return this.pushState(s.getGoto(this.state,i,!0),this.reducePos),in;)this.stack.pop();this.reduceContext(i,h)}storeNode(t,e,i,s=4,r=!1){if(0==t&&(!this.stack.length||this.stack[this.stack.length-1]0&&0==t.buffer[s-4]&&t.buffer[s-1]>-1){if(e==i)return;if(t.buffer[s-2]>=e)return void(t.buffer[s-2]=i)}}if(r&&this.pos!=i){let r=this.buffer.length;if(r>0&&0!=this.buffer[r-4])for(;r>0&&this.buffer[r-2]>i;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,s>4&&(s-=4);this.buffer[r]=t,this.buffer[r+1]=e,this.buffer[r+2]=i,this.buffer[r+3]=s}else this.buffer.push(t,e,i,s)}shift(t,e,i){let s=this.pos;if(131072&t)this.pushState(65535&t,this.pos);else if(262144&t)this.pos=i,this.shiftContext(e,s),e<=this.p.parser.maxNode&&this.buffer.push(e,s,i,4);else{let r=t,{parser:n}=this.p;(i>this.pos||e<=n.maxNode)&&(this.pos=i,n.stateFlag(r,1)||(this.reducePos=i)),this.pushState(r,s),this.shiftContext(e,s),e<=n.maxNode&&this.buffer.push(e,s,i,4)}}apply(t,e,i){65536&t?this.reduce(t):this.shift(t,e,i)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let s=this.pos;this.reducePos=this.pos=s+t.length,this.pushState(e,s),this.buffer.push(i,s,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(;e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),s=t.bufferBase+e;for(;t&&s==t.bufferBase;)t=t.parent;return new nd(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,s,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new ld(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(!(65536&i))return!0;if(0==i)return!1;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let i=[];for(let s,r=0;r1&e&&t==s))||i.push(e[t],s)}e=i}let i=[];for(let t=0;t>19,s=65535&t,r=this.stack.length-3*i;if(r<0||e.getGoto(this.stack[r],s,!1)<0)return!1;this.storeNode(0,this.reducePos,this.reducePos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(3!=this.stack.length)return!1;let{parser:t}=this.p;return 65535==t.data[t.stateSlot(this.state,1)]&&!t.stateSlot(this.state,4)}restart(){this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;ethis.lookAhead&&(this.emitLookAhead(),this.lookAhead=t)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class hd{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}var od;!function(t){t[t.Insert=200]="Insert",t[t.Delete=190]="Delete",t[t.Reduce=100]="Reduce",t[t.MaxNext=4]="MaxNext",t[t.MaxInsertStackDepth=300]="MaxInsertStackDepth",t[t.DampenInsertStackDepth=120]="DampenInsertStackDepth"}(od||(od={}));class ld{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=65535&t,i=t>>19;0==i?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=3*(i-1);let s=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=s}}class ud{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,0==this.index&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new ud(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;null!=t&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,0==this.index&&this.maybeNext()}fork(){return new ud(this.stack,this.pos,this.index)}}class ad{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const fd=new ad;class cd{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=fd,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,s=this.rangeIndex,r=this.pos+t;for(;ri.to:r>=i.to;){if(s==this.ranges.length-1)return null;let t=this.ranges[++s];r+=t.from-i.to,i=t}return r}peek(t){let e,i,s=this.chunkOff+t;if(s>=0&&s=this.chunk2Pos&&es.to&&(this.chunk2=this.chunk2.slice(0,s.to-e)),i=this.chunk2.charCodeAt(0)}}return e>=this.token.lookAhead&&(this.token.lookAhead=e+1),i}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(null==i||i=this.chunk2Pos&&this.posthis.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=fd,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let s of this.ranges){if(s.from>=e)break;s.to>t&&(i+=this.input.read(Math.max(s.from,t),Math.min(s.to,e)))}return i}}class Od{constructor(t,e){this.data=t,this.id=e}token(t,e){!function(t,e,i,s){let r=0,n=1<0){let i=t[s];if(o.allows(i)&&(-1==e.token.value||e.token.value==i||h.overrides(i,e.token.value))){e.acceptToken(i);break}}let s=e.next,l=0,u=t[r+2];if(!(e.next<0&&u>l&&65535==t[i+3*u-3])){for(;l>1,h=i+n+(n<<1),o=t[h],a=t[h+1];if(s=a)){r=t[h+2],e.advance();continue t}l=n+1}}break}r=t[i+3*u-1]}}(this.data,t,e,this.id)}}Od.prototype.contextual=Od.prototype.fallback=Od.prototype.extend=!1;class dd{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}}function $d(t,e=Uint16Array){if("string"!=typeof t)return t;let i=null;for(let s=0,r=0;s=92&&e--,e>=34&&e--;let r=e-32;if(r>=46&&(r-=46,i=!0),n+=r,i)break;n*=46}i?i[r++]=n:i=new e(n)}return i}const pd="undefined"!=typeof process&&process.env&&/\bparse\b/.test(process.env.LOG);let md=null;var wd,gd;function xd(t,e,i){let s=t.cursor(Zo.IncludeAnonymous);for(s.moveTo(e);;)if(!(i<0?s.childBefore(e):s.childAfter(e)))for(;;){if((i<0?s.toe)&&!s.type.isError)return i<0?Math.max(0,Math.min(s.to-1,e-25)):Math.min(t.length,Math.max(s.from+1,e+25));if(i<0?s.prevSibling():s.nextSibling())break;if(!s.parent())return i<0?0:t.length}}!function(t){t[t.Margin=25]="Margin"}(wd||(wd={}));class bd{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?xd(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?xd(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(tt)return this.nextStart=n,null;if(r instanceof To){if(n==t){if(n=Math.max(this.safeFrom,t)&&(this.trees.push(r),this.start.push(n),this.index.push(0))}else this.index[e]++,this.nextStart=n+r.length}}}class yd{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map((t=>new ad))}getActions(t){let e=0,i=null,{parser:s}=t.p,{tokenizers:r}=s,n=s.stateSlot(t.state,3),h=t.curContext?t.curContext.hash:0,o=0;for(let s=0;su.end+25&&(o=Math.max(u.lookAhead,o)),0!=u.value)){let s=e;if(u.extended>-1&&(e=this.addActions(t,u.extended,u.end,e)),e=this.addActions(t,u.value,u.end,e),!l.extend&&(i=u,e>s))break}}for(;this.actions.length>e;)this.actions.pop();return o&&t.setLookAhead(o),i||t.pos!=this.stream.end||(i=new ad,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new ad,{pos:i,p:s}=t;return e.start=i,e.end=Math.min(i+1,s.stream.end),e.value=i==s.stream.end?s.parser.eofTerm:0,e}updateCachedToken(t,e,i){if(e.token(this.stream.reset(i.pos,t),i),t.value>-1){let{parser:e}=i.p;for(let s=0;s=0&&i.p.parser.dialect.allows(r>>1)){1&r?t.extended=r>>1:t.value=r>>1;break}}}else t.value=0,t.end=Math.min(i.p.stream.end,i.pos+1)}putAction(t,e,i,s){for(let e=0;e4*t.bufferLength?new bd(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t,e,i=this.stacks,s=this.minStackPos,r=this.stacks=[];for(let n=0;ns)r.push(h);else{if(this.advanceStack(h,r,i))continue;{t||(t=[],e=[]),t.push(h);let i=this.tokens.getMainToken(h);e.push(i.value,i.end)}}break}}if(!r.length){let e=t&&function(t){let e=null;for(let i of t){let t=i.p.stoppedAt;(i.pos==i.p.stream.end||null!=t&&i.pos>t)&&i.p.parser.stateFlag(i.state,2)&&(!e||e.scorethis.stoppedAt?t[0]:this.runRecovery(t,e,r);if(i)return this.stackToTree(i.forceAll())}if(this.recovering){let t=1==this.recovering?1:3*this.recovering;if(r.length>t)for(r.sort(((t,e)=>e.score-t.score));r.length>t;)r.pop();r.some((t=>t.reducePos>s))&&this.recovering--}else if(r.length>1)t:for(let t=0;t500&&s.buffer.length>500){if(!((e.score-s.score||e.buffer.length-s.buffer.length)>0)){r.splice(t--,1);continue t}r.splice(i--,1)}}}this.minStackPos=r[0].pos;for(let t=1;t ":"";if(null!=this.stoppedAt&&s>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let e=t.curContext&&t.curContext.tracker.strict,i=e?t.curContext.hash:0;for(let h=this.fragments.nodeAt(s);h;){let s=this.parser.nodeSet.types[h.type.id]==h.type?r.getGoto(t.state,h.type.id):-1;if(s>-1&&h.length&&(!e||(h.prop(Io.contextHash)||0)==i))return t.useNode(h,s),pd&&console.log(n+this.stackID(t)+` (via reuse of ${r.getName(h.type.id)})`),!0;if(!(h instanceof To)||0==h.children.length||h.positions[0]>0)break;let o=h.children[0];if(!(o instanceof To&&0==h.positions[0]))break;h=o}}let h=r.stateSlot(t.state,4);if(h>0)return t.reduce(h),pd&&console.log(n+this.stackID(t)+` (via always-reduce ${r.getName(65535&h)})`),!0;if(t.stack.length>=15e3)for(;t.stack.length>9e3&&t.forceReduce(););let o=this.tokens.getActions(t);for(let h=0;hs?e.push(c):i.push(c)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return Pd(t,e),!0}}runRecovery(t,e,i){let s=null,r=!1;for(let n=0;n ":"";if(h.deadEnd){if(r)continue;if(r=!0,h.restart(),pd&&console.log(u+this.stackID(h)+" (restarted)"),this.advanceFully(h,i))continue}let a=h.split(),f=u;for(let t=0;a.forceReduce()&&t<10&&(pd&&console.log(f+this.stackID(a)+" (via force-reduce)"),!this.advanceFully(a,i));t++)pd&&(f=this.stackID(a)+" -> ");for(let t of h.recoverByInsert(o))pd&&console.log(u+this.stackID(t)+" (via recover-insert)"),this.advanceFully(t,i);this.stream.end>h.pos?(l==h.pos&&(l++,o=0),h.recoverByDelete(o,l),pd&&console.log(u+this.stackID(h)+` (via recover-delete ${this.parser.getName(o)})`),Pd(h,i)):(!s||s.scoret;class Sd extends Jo{constructor(t){if(super(),this.wrappers=[],14!=t.version)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let i=0;it.topRules[e][1])),s=[];for(let t=0;t=0)r(s,t,e[i++]);else{let n=e[i+-s];for(let h=-s;h>0;h--)r(e[i++],t,n);i++}}}this.nodeSet=new Yo(e.map(((e,r)=>Wo.define({name:r>=this.minRepeatTerm?void 0:e,id:r,props:s[r],top:i.indexOf(r)>-1,error:0==r,skipped:t.skippedNodes&&t.skippedNodes.indexOf(r)>-1})))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=qo;let n=$d(t.tokenData);if(this.context=t.context,this.specialized=new Uint16Array(t.specialized?t.specialized.length:0),this.specializers=[],t.specialized)for(let e=0;e"number"==typeof t?new Od(n,t):t)),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let s=new Qd(this,t,e,i);for(let r of this.wrappers)s=r(s,t,e,i);return s}getGoto(t,e,i=!1){let s=this.goto;if(e>=s[0])return-1;for(let r=s[e+1];;){let e=s[r++],n=1&e,h=s[r++];if(n&&i)return h;for(let i=r+(e>>1);r0}validAction(t,e){if(e==this.stateSlot(t,4))return!0;for(let i=this.stateSlot(t,1);;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])return!1;i=kd(this.data,i+2)}if(e==kd(this.data,i+1))return!0}}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])break;i=kd(this.data,i+2)}if(!(1&this.data[i+2])){let t=this.data[i+1];e.some(((e,i)=>1&i&&e==t))||e.push(this.data[i],t)}}return e}overrides(t,e){let i=Id(this.data,this.tokenPrecTable,e);return i<0||Id(this.data,this.tokenPrecTable,t){let i=t.tokenizers.find((t=>t.from==e));return i?i.to:e}))),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),null!=t.strict&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),null!=t.bufferLength&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return null==e?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map((()=>!1));if(t)for(let s of t.split(" ")){let t=e.indexOf(s);t>=0&&(i[t]=!0)}let s=null;for(let t=0;t{if(t.next<0)t.acceptToken(167);else if(10!=t.next&&13!=t.next);else if(e.context.depth<0)t.acceptToken(165,1);else{t.advance();let e=0;for(;32==t.next||9==t.next;)t.advance(),e++;let i=10==t.next||13==t.next||35==t.next;t.acceptToken(i?166:164,-e)}}),{contextual:!0,fallback:!0}),Yd=new dd(((t,e)=>{let i=e.context.depth;if(i<0)return;let s=t.peek(-1);if((10==s||13==s)&&e.context.depth>=0){let e=0,s=0;for(;;){if(32==t.next)e++;else{if(9!=t.next)break;e+=8-e%8}t.advance(),s++}e!=i&&10!=t.next&&13!=t.next&&35!=t.next&&(e0),this.strict=!1!==t.strict}}({start:Md,reduce:(t,e)=>t.depth<0&&Rd.indexOf(e)>-1?t.parent:t,shift:(t,e,i,s)=>162==e?new Xd(t,function(t){let e=0;for(let i=0;it.hash}),Td=new dd((t=>{for(let e=0;e<5;e++){if(t.next!="print".charCodeAt(e))return;t.advance()}if(!/\w/.test(String.fromCharCode(t.next)))for(let e=0;;e++){let i=t.peek(e);if(32!=i&&9!=i)return void(40!=i&&46!=i&&10!=i&&13!=i&&35!=i&&t.acceptToken(1))}})),_d=hl({'async "*" "**" FormatConversion FormatSpec':kl.modifier,"for while if elif else try except finally return raise break continue with pass assert await yield":kl.controlKeyword,"in not and or is del":kl.operatorKeyword,"from def class global nonlocal lambda":kl.definitionKeyword,import:kl.moduleKeyword,"with as print":kl.keyword,Boolean:kl.bool,None:kl.null,VariableName:kl.variableName,"CallExpression/VariableName":kl.function(kl.variableName),"FunctionDefinition/VariableName":kl.function(kl.definition(kl.variableName)),"ClassDefinition/VariableName":kl.definition(kl.className),PropertyName:kl.propertyName,"CallExpression/MemberExpression/PropertyName":kl.function(kl.propertyName),Comment:kl.lineComment,Number:kl.number,String:kl.string,FormatString:kl.special(kl.string),UpdateOp:kl.updateOperator,ArithOp:kl.arithmeticOperator,BitOp:kl.bitwiseOperator,CompareOp:kl.compareOperator,AssignOp:kl.definitionOperator,Ellipsis:kl.punctuation,At:kl.meta,"( )":kl.paren,"[ ]":kl.squareBracket,"{ }":kl.brace,".":kl.derefOperator,", ;":kl.separator}),Ed={__proto__:null,await:40,or:50,and:52,in:56,not:58,is:60,if:66,else:68,lambda:72,yield:90,from:92,async:98,for:100,None:152,True:154,False:154,del:168,pass:172,break:176,continue:180,return:184,raise:192,import:196,as:198,global:202,nonlocal:204,assert:208,elif:218,while:222,try:228,except:230,finally:232,with:236,def:240,class:250},Ad=Sd.deserialize({version:14,states:"!?pO`Q$IXOOO%cQ$I[O'#GaOOQ$IS'#Cm'#CmOOQ$IS'#Cn'#CnO'RQ$IWO'#ClO(tQ$I[O'#G`OOQ$IS'#Ga'#GaOOQ$IS'#DS'#DSOOQ$IS'#G`'#G`O)bQ$IWO'#CsO)rQ$IWO'#DdO*SQ$IWO'#DhOOQ$IS'#Ds'#DsO*gO`O'#DsO*oOpO'#DsO*wO!bO'#DtO+SO#tO'#DtO+_O&jO'#DtO+jO,UO'#DtO-lQ$I[O'#GQOOQ$IS'#GQ'#GQO'RQ$IWO'#GPO/OQ$I[O'#GPOOQ$IS'#E]'#E]O/gQ$IWO'#E^OOQ$IS'#GO'#GOO/qQ$IWO'#F}OOQ$IV'#F}'#F}O/|Q$IWO'#FPOOQ$IS'#Fr'#FrO0RQ$IWO'#FOOOQ$IV'#H]'#H]OOQ$IV'#F|'#F|OOQ$IT'#FR'#FRQ`Q$IXOOO'RQ$IWO'#CoO0aQ$IWO'#C{O0hQ$IWO'#DPO0vQ$IWO'#GeO1WQ$I[O'#EQO'RQ$IWO'#EROOQ$IS'#ET'#ETOOQ$IS'#EV'#EVOOQ$IS'#EX'#EXO1lQ$IWO'#EZO2SQ$IWO'#E_O/|Q$IWO'#EaO2gQ$I[O'#EaO/|Q$IWO'#EdO/gQ$IWO'#EgO/gQ$IWO'#EkO/gQ$IWO'#EnO2rQ$IWO'#EpO2yQ$IWO'#EuO3UQ$IWO'#EqO/gQ$IWO'#EuO/|Q$IWO'#EwO/|Q$IWO'#E|OOQ$IS'#Cc'#CcOOQ$IS'#Cd'#CdOOQ$IS'#Ce'#CeOOQ$IS'#Cf'#CfOOQ$IS'#Cg'#CgOOQ$IS'#Ch'#ChOOQ$IS'#Cj'#CjO'RQ$IWO,58|O'RQ$IWO,58|O'RQ$IWO,58|O'RQ$IWO,58|O'RQ$IWO,58|O'RQ$IWO,58|O3ZQ$IWO'#DmOOQ$IS,5:W,5:WO3nQ$IWO'#GoOOQ$IS,5:Z,5:ZO3{Q%1`O,5:ZO4QQ$I[O,59WO0aQ$IWO,59`O0aQ$IWO,59`O0aQ$IWO,59`O6pQ$IWO,59`O6uQ$IWO,59`O6|Q$IWO,59hO7TQ$IWO'#G`O8ZQ$IWO'#G_OOQ$IS'#G_'#G_OOQ$IS'#DY'#DYO8rQ$IWO,59_O'RQ$IWO,59_O9QQ$IWO,59_O9VQ$IWO,5:PO'RQ$IWO,5:POOQ$IS,5:O,5:OO9eQ$IWO,5:OO9jQ$IWO,5:VO'RQ$IWO,5:VO'RQ$IWO,5:TOOQ$IS,5:S,5:SO9{Q$IWO,5:SO:QQ$IWO,5:UOOOO'#FZ'#FZO:VO`O,5:_OOQ$IS,5:_,5:_OOOO'#F['#F[O:_OpO,5:_O:gQ$IWO'#DuOOOO'#F]'#F]O:wO!bO,5:`OOQ$IS,5:`,5:`OOOO'#F`'#F`O;SO#tO,5:`OOOO'#Fa'#FaO;_O&jO,5:`OOOO'#Fb'#FbO;jO,UO,5:`OOQ$IS'#Fc'#FcO;uQ$I[O,5:dO>gQ$I[O,5hQ$IZO<TAN>TO#FQQ$IWO<aAN>aO/gQ$IWO1G1^O#FbQ$I[O1G1^P#FlQ$IWO'#FWOOQ$IS1G1d1G1dP#FyQ$IWO'#F^O#GWQ$IWO7+(mOOOO-E9]-E9]O#GnQ$IWO7+'qOOQ$ISAN?VAN?VO#HXQ$IWO,5UZ%q7[%kW%y#tOr(}rs)}sw(}wx>wx#O(}#O#P2]#P#o(}#o#p:X#p#q(}#q#r2q#r~(}:Y?QX%q7[%kW%y#tOr>wrs?ms#O>w#O#PAP#P#o>w#o#p8Y#p#q>w#q#r6g#r~>w:Y?rX%q7[Or>wrs@_s#O>w#O#PAP#P#o>w#o#p8Y#p#q>w#q#r6g#r~>w:Y@dX%q7[Or>wrs-}s#O>w#O#PAP#P#o>w#o#p8Y#p#q>w#q#r6g#r~>w:YAUT%q7[O#o>w#o#p6g#p#q>w#q#r6g#r~>w`x#O!`x#O!gZ%kW%f,XOY!wZ]!Ad]^>w^r!Adrs!Bhs#O!Ad#O#P!C[#P#o!Ad#o#p!9f#p#q!Ad#q#r!7x#r~!AdEc!BoX%q7[%f,XOr>wrs@_s#O>w#O#PAP#P#o>w#o#p8Y#p#q>w#q#r6g#r~>wEc!CaT%q7[O#o!Ad#o#p!7x#p#q!Ad#q#r!7x#r~!AdGZ!CuT%q7[O#o!-l#o#p!DU#p#q!-l#q#r!DU#r~!-l0}!De]%hS%kW%f,X%n`%w!b%y#tOY!DUYZAyZ]!DU]^Ay^r!DUrs!E^sw!DUwx!5tx#O!DU#O#P!FU#P#o!DU#o#p!F[#p~!DU0}!EiX%hS%f,X%n`%w!bOrAyrsCiswAywx5Px#OAy#O#PEo#P#oAy#o#pEu#p~Ay0}!FXPO~!DU0}!Fe]%hS%kW%f,XOY!`x#O!`sw#=dwx#@Sx#O#=d#O#P#Av#P#o#=d#o#p#0Y#p~#=d2P#=mZQ1s%hS%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@Sx#O#=d#O#P#Av#P~#=d2P#>gZQ1s%hSOY#=dYZ:{Z]#=d]^:{^r#=drs#?Ysw#=dwx#@Sx#O#=d#O#P#Av#P~#=d2P#?aZQ1s%hSOY#=dYZ:{Z]#=d]^:{^r#=drs#,zsw#=dwx#@Sx#O#=d#O#P#Av#P~#=d2P#@ZZQ1s%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@|x#O#=d#O#P#Av#P~#=d2P#ATZQ1s%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#9bx#O#=d#O#P#Av#P~#=d2P#A{TQ1sOY#=dYZ:{Z]#=d]^:{^~#=dLe#Bg_Q1s%q7[%kW%y#tOY!NdYZ(}Z]!Nd]^(}^r!Ndrs# rsw!Ndwx#Cfx#O!Nd#O#P#/f#P#o!Nd#o#p#wZ]#Cf]^>w^r#Cfrs#Djs#O#Cf#O#P#Fj#P#o#Cf#o#p#8h#p#q#Cf#q#r#5h#r~#CfJ}#Dq]Q1s%q7[OY#CfYZ>wZ]#Cf]^>w^r#Cfrs#Ejs#O#Cf#O#P#Fj#P#o#Cf#o#p#8h#p#q#Cf#q#r#5h#r~#CfJ}#Eq]Q1s%q7[OY#CfYZ>wZ]#Cf]^>w^r#Cfrs#'[s#O#Cf#O#P#Fj#P#o#Cf#o#p#8h#p#q#Cf#q#r#5h#r~#CfJ}#FqXQ1s%q7[OY#CfYZ>wZ]#Cf]^>w^#o#Cf#o#p#5h#p#q#Cf#q#r#5h#r~#CfLu#GeXQ1s%q7[OY!KxYZ'PZ]!Kx]^'P^#o!Kx#o#p#HQ#p#q!Kx#q#r#HQ#r~!Kx6i#Ha]Q1s%hS%kW%n`%w!b%y#tOY#HQYZAyZ]#HQ]^Ay^r#HQrs#IYsw#HQwx#3dx#O#HQ#O#P#Mn#P#o#HQ#o#p#NS#p~#HQ6i#Ie]Q1s%hS%n`%w!bOY#HQYZAyZ]#HQ]^Ay^r#HQrs#J^sw#HQwx#3dx#O#HQ#O#P#Mn#P#o#HQ#o#p#NS#p~#HQ6i#Ji]Q1s%hS%n`%w!bOY#HQYZAyZ]#HQ]^Ay^r#HQrs#Kbsw#HQwx#3dx#O#HQ#O#P#Mn#P#o#HQ#o#p#NS#p~#HQ3k#KmZQ1s%hS%n`%w!bOY#KbYZD_Z]#Kb]^D_^w#Kbwx#)|x#O#Kb#O#P#L`#P#o#Kb#o#p#Lt#p~#Kb3k#LeTQ1sOY#KbYZD_Z]#Kb]^D_^~#Kb3k#L{ZQ1s%hSOY#,zYZ1OZ]#,z]^1O^w#,zwx#-nx#O#,z#O#P#/Q#P#o#,z#o#p#Kb#p~#,z6i#MsTQ1sOY#HQYZAyZ]#HQ]^Ay^~#HQ6i#N]]Q1s%hS%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@Sx#O#=d#O#P#Av#P#o#=d#o#p#HQ#p~#=dLu$ c_Q1s%q7[%hS%n`%w!bOY!KxYZ'PZ]!Kx]^'P^r!Kxrs$!bsw!Kxwx!MYx#O!Kx#O#P#G^#P#o!Kx#o#p#NS#p#q!Kx#q#r#HQ#r~!KxIw$!o]Q1s%q7[%hS%n`%w!bOY$!bYZGgZ]$!b]^Gg^w$!bwx#%[x#O$!b#O#P$#h#P#o$!b#o#p#Lt#p#q$!b#q#r#Kb#r~$!bIw$#oXQ1s%q7[OY$!bYZGgZ]$!b]^Gg^#o$!b#o#p#Kb#p#q$!b#q#r#Kb#r~$!bMV$$i_Q1s%q7[%kW%tp%y#tOY$%hYZIqZ]$%h]^Iq^r$%hrs# rsw$%hwx$.px#O$%h#O#P$&x#P#o$%h#o#p$-n#p#q$%h#q#r$'l#r~$%hMV$%y_Q1s%q7[%hS%kW%tp%w!b%y#tOY$%hYZIqZ]$%h]^Iq^r$%hrs# rsw$%hwx$$[x#O$%h#O#P$&x#P#o$%h#o#p$-n#p#q$%h#q#r$'l#r~$%hMV$'PXQ1s%q7[OY$%hYZIqZ]$%h]^Iq^#o$%h#o#p$'l#p#q$%h#q#r$'l#r~$%h6y$'{]Q1s%hS%kW%tp%w!b%y#tOY$'lYZKXZ]$'l]^KX^r$'lrs#1`sw$'lwx$(tx#O$'l#O#P$-Y#P#o$'l#o#p$-n#p~$'l6y$)P]Q1s%kW%tp%y#tOY$'lYZKXZ]$'l]^KX^r$'lrs#1`sw$'lwx$)xx#O$'l#O#P$-Y#P#o$'l#o#p$-n#p~$'l6y$*T]Q1s%kW%tp%y#tOY$'lYZKXZ]$'l]^KX^r$'lrs#1`sw$'lwx$*|x#O$'l#O#P$-Y#P#o$'l#o#p$-n#p~$'l5c$+XZQ1s%kW%tp%y#tOY$*|YZMmZ]$*|]^Mm^r$*|rs#6ds#O$*|#O#P$+z#P#o$*|#o#p$,`#p~$*|5c$,PTQ1sOY$*|YZMmZ]$*|]^Mm^~$*|5c$,gZQ1s%kWOY#9bYZ8tZ]#9b]^8t^r#9brs#:Us#O#9b#O#P#;h#P#o#9b#o#p$*|#p~#9b6y$-_TQ1sOY$'lYZKXZ]$'l]^KX^~$'l6y$-w]Q1s%hS%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@Sx#O#=d#O#P#Av#P#o#=d#o#p$'l#p~#=dMV$.}_Q1s%q7[%kW%tp%y#tOY$%hYZIqZ]$%h]^Iq^r$%hrs# rsw$%hwx$/|x#O$%h#O#P$&x#P#o$%h#o#p$-n#p#q$%h#q#r$'l#r~$%hKo$0Z]Q1s%q7[%kW%tp%y#tOY$/|YZ!!uZ]$/|]^!!u^r$/|rs#Djs#O$/|#O#P$1S#P#o$/|#o#p$,`#p#q$/|#q#r$*|#r~$/|Ko$1ZXQ1s%q7[OY$/|YZ!!uZ]$/|]^!!u^#o$/|#o#p$*|#p#q$/|#q#r$*|#r~$/|Mg$1}XQ1s%q7[OY!IYYZ$}Z]!IY]^$}^#o!IY#o#p$2j#p#q!IY#q#r$2j#r~!IY7Z$2{]Q1s%hS%kW%n`%tp%w!b%y#tOY$2jYZ!$gZ]$2j]^!$g^r$2jrs#IYsw$2jwx$(tx#O$2j#O#P$3t#P#o$2j#o#p$4Y#p~$2j7Z$3yTQ1sOY$2jYZ!$gZ]$2j]^!$g^~$2j7Z$4c]Q1s%hS%kWOY#=dYZ:{Z]#=d]^:{^r#=drs#>`sw#=dwx#@Sx#O#=d#O#P#Av#P#o#=d#o#p$2j#p~#=dGz$5o]$}Q%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!_$}!_!`$6h!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gz$6{Z!s,W%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gz$8R]$wQ%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!_$}!_!`$6h!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}G{$9Z_%r`%q7[%kW%f,X%tp%y#tOY$:YYZIqZ]$:Y]^Iq^r$:Yrs$;jsw$:Ywx%%zx#O$:Y#O#P%!^#P#o$:Y#o#p%$x#p#q$:Y#q#r%!r#r~$:YGk$:k_%q7[%hS%kW%f,X%tp%w!b%y#tOY$:YYZIqZ]$:Y]^Iq^r$:Yrs$;jsw$:Ywx% ^x#O$:Y#O#P%!^#P#o$:Y#o#p%$x#p#q$:Y#q#r%!r#r~$:YFy$;u_%q7[%hS%f,X%w!bOY$Sx#O$Sx#O$_Z%q7[%kW%f,X%y#tOr(}rs)}sw(}wx={x#O(}#O#P2]#P#o(}#o#p:X#p#q(}#q#r2q#r~(}Fy$?VT%q7[O#o$Sx#O$T!Q!_$}!_!`$6h!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gz%>h]%OQ%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!_$}!_!`$6h!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%?tu!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!O$}!O!P%BX!P!Q$}!Q![%Cc![!d$}!d!e%Ee!e!g$}!g!h%7Z!h!l$}!l!m%;k!m!q$}!q!r%H_!r!z$}!z!{%KR!{#O$}#O#P!$R#P#R$}#R#S%Cc#S#U$}#U#V%Ee#V#X$}#X#Y%7Z#Y#^$}#^#_%;k#_#c$}#c#d%H_#d#l$}#l#m%KR#m#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Bj]%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q![%5_![#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Cvi!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!O$}!O!P%BX!P!Q$}!Q![%Cc![!g$}!g!h%7Z!h!l$}!l!m%;k!m#O$}#O#P!$R#P#R$}#R#S%Cc#S#X$}#X#Y%7Z#Y#^$}#^#_%;k#_#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Ev`%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q!R%Fx!R!S%Fx!S#O$}#O#P!$R#P#R$}#R#S%Fx#S#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%G]`!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q!R%Fx!R!S%Fx!S#O$}#O#P!$R#P#R$}#R#S%Fx#S#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Hp_%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q!Y%Io!Y#O$}#O#P!$R#P#R$}#R#S%Io#S#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%JS_!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q!Y%Io!Y#O$}#O#P!$R#P#R$}#R#S%Io#S#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%Kdc%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q![%Lo![!c$}!c!i%Lo!i#O$}#O#P!$R#P#R$}#R#S%Lo#S#T$}#T#Z%Lo#Z#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Gy%MSc!f,V%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!Q$}!Q![%Lo![!c$}!c!i%Lo!i#O$}#O#P!$R#P#R$}#R#S%Lo#S#T$}#T#Z%Lo#Z#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Mg%Nr]y1s%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx!_$}!_!`& k!`#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}x!u!}&+n!}#O$}#O#P!$R#P#R$}#R#S&+n#S#T$}#T#f&+n#f#g&>x#g#o&+n#o#p!%i#p#q$}#q#r!$g#r$g$}$g~&+nGZ&9gZ%q7[%hS%n`%w!b%s,XOr'Prs&:Ysw'Pwx(Rx#O'P#O#PAe#P#o'P#o#pEu#p#q'P#q#rAy#r~'PGZ&:eZ%q7[%hS%n`%w!bOr'Prs&;Wsw'Pwx(Rx#O'P#O#PAe#P#o'P#o#pEu#p#q'P#q#rAy#r~'PD]&;eX%q7[%hS%x,X%n`%w!bOwGgwx,kx#OGg#O#PH_#P#oGg#o#pET#p#qGg#q#rD_#r~GgGk&<_Z%q7[%kW%tp%y#t%m,XOrIqrs)}swIqwx&=Qx#OIq#O#PJs#P#oIq#o#p! T#p#qIq#q#rKX#r~IqGk&=]Z%q7[%kW%tp%y#tOrIqrs)}swIqwx&>Ox#OIq#O#PJs#P#oIq#o#p! T#p#qIq#q#rKX#r~IqFT&>]X%q7[%kW%v,X%tp%y#tOr!!urs?ms#O!!u#O#P!#m#P#o!!u#o#pNc#p#q!!u#q#rMm#r~!!uMg&?_c%q7[%hS%kW%e&j%n`%tp%w!b%y#t%Q,XOr$}rs&9Ysw$}wx&x!i!t&+n!t!u&5j!u!}&+n!}#O$}#O#P!$R#P#R$}#R#S&+n#S#T$}#T#U&+n#U#V&5j#V#Y&+n#Y#Z&>x#Z#o&+n#o#p!%i#p#q$}#q#r!$g#r$g$}$g~&+nG{&CXZ!V,X%q7[%hS%kW%n`%tp%w!b%y#tOr$}rs&Rsw$}wxHsx#O$}#O#P!$R#P#o$}#o#p!%i#p#q$}#q#r!$g#r~$}Ed[t]||-1}],tokenPrec:6584});function jd(t,e){let i=t.lineIndent(e.from),s=t.lineAt(t.pos,-1),r=s.from+s.text.length;return!/\S/.test(s.text)&&t.node.toi?null:i+t.unit}const Ud=Xl.define({parser:Ad.configure({props:[Ll.add({Body:t=>{var e;return null!==(e=jd(t,t.node))&&void 0!==e?e:t.continue()},IfStatement:t=>/^\s*(else:|elif )/.test(t.textAfter)?t.baseIndent:t.continue(),TryStatement:t=>/^\s*(except |finally:)/.test(t.textAfter)?t.baseIndent:t.continue(),"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression":su({closing:")"}),"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression":su({closing:"}"}),"ArrayExpression ArrayComprehensionExpression":su({closing:"]"}),Script:t=>{if(t.pos+/\s*/.exec(t.textAfter)[0].length>=t.node.to){let e=null;for(let i=t.node,s=i.to;i=i.lastChild,i&&i.to==s;)"Body"==i.type.name&&(e=i);if(e){let i=jd(t,e);if(null!=i)return i}}return t.continue()}}),ou.add({"ArrayExpression DictionaryExpression SetExpression TupleExpression":function(t){let e=t.firstChild,i=t.lastChild;return e&&e.to({from:t.from+1,to:t.to-(t.to==e.doc.length?0:1)})})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"'''",'"""']},commentTokens:{line:"#"},indentOnInput:/^\s*([\}\]\)]|else:|elif |except |finally:)$/}});function Gd(){return new Cl(Ud)}function Vd(t,e){let i,s=-1,r=-1;const n=t.split("\n");for(var h=n.length-1;h>=0;h--){let t=n[h];if(t.startsWith("SyntaxError")||t.startsWith("IndentationError"))r=h;else if(t.includes('File "", line')){i=parseInt(t.split(", line ")[1],10),i-=e-1,s=h;break}}return-1==s||-1==r?"No error report found.":`Error at line ${i}:\n`+n.slice(s+1,r+1).join("\n")}var Cd=null;try{var Dd="undefined"!=typeof module&&"function"==typeof module.require&&module.require("worker_threads")||"function"==typeof __non_webpack_require__&&__non_webpack_require__("worker_threads")||"function"==typeof require&&require("worker_threads");Cd=Dd.Worker}catch(t){}function zd(t,e,i){var s=void 0===e?null:e,r=function(t,e){return Buffer.from(t,"base64").toString(e?"utf16":"utf8")}(t,void 0!==i&&i),n=r.indexOf("\n",10)+1,h=r.substring(n)+(s?"//# sourceMappingURL="+s:"");return function(t){return new Cd(h,Object.assign({},t,{eval:!0}))}}function Hd(t,e,i){var s=void 0===e?null:e,r=function(t,e){var i=atob(t);if(e){for(var s=new Uint8Array(i.length),r=0,n=i.length;r{window.setTimeout(this.finishIt.bind(this),5e3),this.worker.postMessage(t),this.resolve=e}))}finishIt(){this.gotCalledBack||(this.worker.terminate(),this.resolve({error:{message:"Infinite loop"}}))}handleMessage(t){t.data.stdout?this.stdout.push(t.data.stdout):(this.gotCalledBack=!0,this.resolve({error:t?.data?.error,results:t?.data?.results,stdout:this.stdout.join("\n")}))}}const Kd={};function Jd(){try{return"localStorage"in window&&null!==window.localStorage}catch(t){return!1}}function t$(t,e){Jd()?localStorage.setItem(t,e):Kd[t]=e}class e$ extends L{static styles=n` .loader { border: 4px solid #f3f3f3; border-radius: 50%; @@ -58,19 +58,10 @@ const J=2; transform: rotate(360deg); } } - `;render(){return Y`
`}}customElements.define("loader-element",e$);class i$ extends L{static properties={starterCode:{type:String},exerciseName:{type:String,attribute:"name"},isLoading:{type:Boolean},runStatus:{type:String},testResultsStatus:{type:String},testResultsHeader:{type:String},testResultsDetails:{type:String},runOutput:{type:String},runStdout:{type:String},showTests:{type:Boolean,attribute:"show-tests"}};static styles=n` - .editor-area { - width: 100%; - margin: 10px 0; - } - .cm-editor { - border: 1px solid #ccc; - border-radius: 4px; - } - `;editorRef=(()=>new lt)();editor=null;createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),!this.starterCode&&this.innerHTML.trim()&&(this.starterCode=this.innerHTML.trim().replace(/>/g,">"),this.innerHTML="")}render(){return Y` + `;render(){return Y`
`}}customElements.define("loader-element",e$);class i$ extends L{static properties={starterCode:{type:String},exerciseName:{type:String,attribute:"name"},isLoading:{type:Boolean},runStatus:{type:String},testResultsStatus:{type:String},testResultsHeader:{type:String},testResultsDetails:{type:String},runOutput:{type:String},runStdout:{type:String},showTests:{type:Boolean,attribute:"show-tests"}};editorRef=(()=>new lt)();editor=null;createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),!this.starterCode&&this.innerHTML.trim()&&(this.starterCode=this.innerHTML.trim().replace(/>/g,">"),this.innerHTML=""),this.style.whiteSpace="normal",this.style.fontFamily="inherit"}render(){return Y`
-
+
- `}getStorageKey(){return this.exerciseName?`${this.exerciseName}-repr`:null}firstUpdated(){const t=this.getStorageKey(),e=t?function(t,e){let i;return i=Jd()?localStorage.getItem(t):Kd[t],i??e}(t):null;e?console.log(`Loading stored code in localStorage from ${t}`):t?console.log(`No stored code found for ${t}, using starter code. Your code changes will be stored in localStorage.`):console.log("No exercise name provided, code will not be stored");const i=Xe.create({doc:e||this.starterCode||"",extensions:[rd,Vd(),Nn.of([Zf]),zl.of(" "),jn.lineWrapping,jn.updateListener.of((t=>{const e=this.getStorageKey();t.docChanged&&e&&t$(e,t.state.doc.toString())}))]});this.editor=new jn({state:i,parent:this.editorRef.value})}async onRunCode(){this.runStatus="Running code...",this.testResultsStatus="";const t=this.editor.state.doc.toString();try{const{results:e,error:i,stdout:s}=await new Ld(t);this.runOutput=i?.message||e||"",this.runStdout=s||"",this.runOutput||this.runStdout||(this.runOutput="No output from code execution.\n",this.showTests&&(this.runOutput+='To check if your function code is correct, select "Run Tests" button instead.'))}catch(t){console.warn(`Error in pyodideWorker at ${t.filename}, Line: ${t.lineno}, ${t.message}`),this.runOutput=`Error: ${t.message}`}this.runStatus=""}async onRunTests(){this.runStatus="Running tests...",this.runOutput="",this.runStdout="";let t=function(t){const e=t.split("\n");if(!e[0].includes("def")&&!e[0].includes("class"))return{status:"fail",header:"Error running tests",details:"First code line must be `def` or `class` declaration"};if(function(t){let e=1;for(;e{t.startsWith('File "__main__"')?i=!0:((t.startsWith("Trying:")||t.startsWith("1 items had no tests:"))&&(i=!1),i&&(t=t.replace("Failed example:","\n❌ Failed test:"),e.push(t)))})),e.join("\n").trim()}(t)}}}(i):function(t,e){return t.message.startsWith("Traceback")?{status:"fail",header:"Syntax error",details:Cd(t.message,e)}:"Infinite loop"==t.message?{status:"fail",header:"Infinite loop",details:"Your code did not finish executing within 60 seconds. Please look to see if you accidentally coded an infinite loop."}:{status:"fail",header:"Unexpected error occurred",details:`Error: ${t.message}`}}(s,t.startLine),this.runStdout=r||""}catch(t){console.warn(`Error in pyodideWorker at ${t.filename}, Line: ${t.lineno}, ${t.message}`)}this.runStatus="",this.testResultsStatus=t.status,this.testResultsHeader=t.header,this.testResultsDetails=t.details}async resetCode(){if(confirm("Are you sure you want to reset your code to the starter code? This cannot be undone.")){const t=Xe.create({doc:this.starterCode||"",extensions:[rd,Vd(),jn.lineWrapping]});this.editor.setState(t);const e=this.getStorageKey();e&&t$(e,this.starterCode)}}}window.customElements.define("code-exercise-element",i$),t.CodeExerciseElement=i$,Object.defineProperty(t,"t",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CodeExerciseElement={}); + `}getStorageKey(){return this.exerciseName?`${this.exerciseName}-repr`:null}firstUpdated(){const t=this.getStorageKey(),e=t?function(t,e){let i;return i=Jd()?localStorage.getItem(t):Kd[t],i??e}(t):null;e?console.log(`Loading stored code in localStorage from ${t}`):t?console.log(`No stored code found for ${t}, using starter code. Your code changes will be stored in localStorage.`):console.log("No exercise name provided, code will not be stored");const i=Xe.create({doc:e||this.starterCode||"",extensions:[rd,Gd(),Nn.of([Zf]),zl.of(" "),jn.lineWrapping,jn.updateListener.of((t=>{const e=this.getStorageKey();t.docChanged&&e&&t$(e,t.state.doc.toString())}))]});this.editor=new jn({state:i,parent:this.editorRef.value})}async onRunCode(){this.runStatus="Running code...",this.testResultsStatus="";const t=this.editor.state.doc.toString();try{const{results:e,error:i,stdout:s}=await new Ld(t);this.runOutput=i?.message||e||"",this.runStdout=s||"",this.runOutput||this.runStdout||(this.runOutput="No output from code execution.\n",this.showTests&&(this.runOutput+='To check if your function code is correct, select "Run Tests" button instead.'))}catch(t){console.warn(`Error in pyodideWorker at ${t.filename}, Line: ${t.lineno}, ${t.message}`),this.runOutput=`Error: ${t.message}`}this.runStatus=""}async onRunTests(){this.runStatus="Running tests...",this.runOutput="",this.runStdout="";let t=function(t){const e=t.split("\n");if(!e[0].includes("def")&&!e[0].includes("class"))return{status:"fail",header:"Error running tests",details:"First code line must be `def` or `class` declaration"};if(function(t){let e=1;for(;e{t.startsWith('File "__main__"')?i=!0:((t.startsWith("Trying:")||t.startsWith("1 items had no tests:"))&&(i=!1),i&&(t=t.replace("Failed example:","\n❌ Failed test:"),e.push(t)))})),e.join("\n").trim()}(t)}}}(i):function(t,e){return t.message.startsWith("Traceback")?{status:"fail",header:"Syntax error",details:Vd(t.message,e)}:"Infinite loop"==t.message?{status:"fail",header:"Infinite loop",details:"Your code did not finish executing within 60 seconds. Please look to see if you accidentally coded an infinite loop."}:{status:"fail",header:"Unexpected error occurred",details:`Error: ${t.message}`}}(s,t.startLine),this.runStdout=r||""}catch(t){console.warn(`Error in pyodideWorker at ${t.filename}, Line: ${t.lineno}, ${t.message}`)}this.runStatus="",this.testResultsStatus=t.status,this.testResultsHeader=t.header,this.testResultsDetails=t.details}async resetCode(){if(confirm("Are you sure you want to reset your code to the starter code? This cannot be undone.")){const t=Xe.create({doc:this.starterCode||"",extensions:[rd,Gd(),jn.lineWrapping]});this.editor.setState(t);const e=this.getStorageKey();e&&t$(e,this.starterCode)}}}window.customElements.define("code-exercise-element",i$),t.CodeExerciseElement=i$,Object.defineProperty(t,"t",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CodeExerciseElement={}); diff --git a/dist/worker.js b/dist/worker.js index c54f9f4..943f7ae 100644 --- a/dist/worker.js +++ b/dist/worker.js @@ -16,10 +16,6 @@ self.onmessage = async (event) => { const python = event.data; try { let results = await self.pyodide.runPythonAsync(python); - // if results is an object, convert it to a string - if (typeof results === 'object' && results !== null) { - results = JSON.stringify(results, null, 2); - } self.postMessage({results}); } catch (error) { self.postMessage({error: error}); diff --git a/index.html b/index.html index c3f4083..6935a9a 100644 --- a/index.html +++ b/index.html @@ -6,14 +6,13 @@ Python code editor @@ -22,22 +21,19 @@

Python code editor example

-def lesser_num(num1, num2): - """ Returns whichever number is lowest of the two supplied numbers. +def tell_fortune(job_title, location, partner): + """ Returns a fortune of the form: + 'You will be a <job_title> in <location> living with <partner>.' - >>> lesser_num(45, 10) - 10 - >>> lesser_num(-1, 30) - -1 - >>> lesser_num(20, 20) - 20 + >>> tell_fortune('bball player', 'Spain', 'Sonic the Hedgehog') + 'You will be a bball player in Spain living with Sonic the Hedgehog.' + >>> tell_fortune('farmer', 'Kansas', 'C3PO') + 'You will be a farmer in Kansas living with C3PO.' + >>> tell_fortune('Elvis Impersonator', 'Russia', 'Karl the Fog') + 'You will be a Elvis Impersonator in Russia living with Karl the Fog.' """ - # YOUR CODE HERE - -print(4) - -2 - + return "?" # YOUR CODE HERE +
diff --git a/package.json b/package.json index 86cecdd..06a9cdc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "python-code-exercise-element", - "version": "0.1.12", + "version": "0.1.14", "description": "A web component for Python coding exercises with doctest runner", "repository": { "type": "git", diff --git a/src/code-exercise.js b/src/code-exercise.js index 0288e75..cae52c9 100644 --- a/src/code-exercise.js +++ b/src/code-exercise.js @@ -1,4 +1,4 @@ -import {LitElement, html, css} from 'lit'; +import {LitElement, html} from 'lit'; import {ref, createRef} from 'lit/directives/ref.js'; import {basicSetup} from 'codemirror'; import {EditorState} from '@codemirror/state'; @@ -26,17 +26,6 @@ export class CodeExerciseElement extends LitElement { showTests: {type: Boolean, attribute: 'show-tests'}, }; - static styles = css` - .editor-area { - width: 100%; - margin: 10px 0; - } - .cm-editor { - border: 1px solid #ccc; - border-radius: 4px; - } - `; - editorRef = createRef(); editor = null; @@ -52,13 +41,16 @@ export class CodeExerciseElement extends LitElement { // Clear the innerHTML since it will be displayed in the editor this.innerHTML = ''; } + // Remove the pre style from the editor area + this.style.whiteSpace = 'normal'; + this.style.fontFamily = 'inherit'; } render() { return html`
-
+
- `}getStorageKey(){return this.exerciseName?`${this.exerciseName}-repr`:null}firstUpdated(){const t=this.getStorageKey(),e=t?function(t,e){let i;return i=Jd()?localStorage.getItem(t):Kd[t],i??e}(t):null;e?console.log(`Loading stored code in localStorage from ${t}`):t?console.log(`No stored code found for ${t}, using starter code. Your code changes will be stored in localStorage.`):console.log("No exercise name provided, code will not be stored");const i=Xe.create({doc:e||this.starterCode||"",extensions:[rd,Gd(),Nn.of([Zf]),zl.of(" "),jn.lineWrapping,jn.updateListener.of((t=>{const e=this.getStorageKey();t.docChanged&&e&&t$(e,t.state.doc.toString())}))]});this.editor=new jn({state:i,parent:this.editorRef.value})}async onRunCode(){this.runStatus="Running code...",this.testResultsStatus="";const t=this.editor.state.doc.toString();try{const{results:e,error:i,stdout:s}=await new Ld(t);this.runOutput=i?.message||e||"",this.runStdout=s||"",this.runOutput||this.runStdout||(this.runOutput="No output from code execution.\n",this.showTests&&(this.runOutput+='To check if your function code is correct, select "Run Tests" button instead.'))}catch(t){console.warn(`Error in pyodideWorker at ${t.filename}, Line: ${t.lineno}, ${t.message}`),this.runOutput=`Error: ${t.message}`}this.runStatus=""}async onRunTests(){this.runStatus="Running tests...",this.runOutput="",this.runStdout="";let t=function(t){const e=t.split("\n");if(!e[0].includes("def")&&!e[0].includes("class"))return{status:"fail",header:"Error running tests",details:"First code line must be `def` or `class` declaration"};let i=[...e];return i.push("import sys"),i.push("import io"),i.push("sys.stdout = io.StringIO()"),i.push("import doctest"),i.push("doctest.testmod(verbose=True)"),i.push("sys.stdout.getvalue()"),i=i.join("\n"),{status:"success",header:"Running tests...",code:i,startLine:0}}(this.editor.state.doc.toString());if(t.code)try{const{results:e,error:i,stdout:s}=await new Ld(t.code);t=e?function(t){const e=t.match(/(\d+)\spassed\sand\s(\d+)\sfailed./);if(e){const i=parseInt(e[1],10),s=i+parseInt(e[2],10);return{status:i==s?"pass":"fail",header:`${i} of ${s} tests passed`,details:function(t){let e=[],i=!1;return t.split("\n").forEach((t=>{t.startsWith('File "__main__"')?i=!0:((t.startsWith("Trying:")||t.startsWith("1 items had no tests:"))&&(i=!1),i&&(t=t.replace("Failed example:","\n❌ Failed test:"),e.push(t)))})),e.join("\n").trim()}(t)}}}(e):function(t,e){return t.message.startsWith("Traceback")?{status:"fail",header:"Syntax error",details:Vd(t.message,e)}:"Infinite loop"==t.message?{status:"fail",header:"Infinite loop",details:"Your code did not finish executing within 60 seconds. Please look to see if you accidentally coded an infinite loop."}:{status:"fail",header:"Unexpected error occurred",details:`Error: ${t.message}`}}(i,t.startLine),this.runStdout=s||""}catch(t){console.warn(`Error in pyodideWorker at ${t.filename}, Line: ${t.lineno}, ${t.message}`)}this.runStatus="",this.testResultsStatus=t.status,this.testResultsHeader=t.header,this.testResultsDetails=t.details}async resetCode(){if(confirm("Are you sure you want to reset your code to the starter code? This cannot be undone.")){const t=Xe.create({doc:this.starterCode||"",extensions:[rd,Gd(),jn.lineWrapping]});this.editor.setState(t);const e=this.getStorageKey();e&&t$(e,this.starterCode)}}}window.customElements.define("code-exercise-element",i$),t.CodeExerciseElement=i$,Object.defineProperty(t,"t",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CodeExerciseElement={}); + `}getStorageKey(){return this.exerciseName?`${this.exerciseName}-repr`:null}firstUpdated(){const t=this.getStorageKey(),e=t?function(t,e){let i;return i=Jd()?localStorage.getItem(t):Kd[t],i??e}(t):null;e?console.log(`Loading stored code in localStorage from ${t}`):t?console.log(`No stored code found for ${t}, using starter code. Your code changes will be stored in localStorage.`):console.log("No exercise name provided, code will not be stored");const i=Xe.create({doc:e||this.starterCode||"",extensions:[rd,Gd(),Nn.of([Zf]),zl.of(" "),jn.lineWrapping,jn.updateListener.of((t=>{const e=this.getStorageKey();t.docChanged&&e&&t$(e,t.state.doc.toString())}))]});this.editor=new jn({state:i,parent:this.editorRef.value})}async onRunCode(){this.runStatus="Running code...",this.testResultsStatus="";const t=this.editor.state.doc.toString();try{const{results:e,error:i,stdout:s}=await new Ld(t);this.runOutput=i?.message||e||"",this.runStdout=s||"",this.runOutput||this.runStdout||(this.runOutput="No output from code execution.\n",this.showTests&&(this.runOutput+='To check if your function code is correct, select "Run Tests" button instead.'))}catch(t){console.warn(`Error in pyodideWorker at ${t.filename}, Line: ${t.lineno}, ${t.message}`),this.runOutput=`Error: ${t.message}`}this.runStatus=""}async onRunTests(){this.runStatus="Running tests...",this.runOutput="",this.runStdout="";let t=function(t){let e=[...t.split("\n")];return e.push("import sys"),e.push("import io"),e.push("sys.stdout = io.StringIO()"),e.push("import doctest"),e.push("doctest.testmod(verbose=True)"),e.push("sys.stdout.getvalue()"),e=e.join("\n"),{status:"success",header:"Running tests...",code:e,startLine:0}}(this.editor.state.doc.toString());if(t.code)try{const{results:e,error:i,stdout:s}=await new Ld(t.code);t=e?function(t){const e=t.match(/(\d+)\spassed\sand\s(\d+)\sfailed./);if(e){const i=parseInt(e[1],10),s=i+parseInt(e[2],10);return{status:i==s?"pass":"fail",header:`${i} of ${s} tests passed`,details:function(t){let e=[],i=!1;return t.split("\n").forEach((t=>{t.startsWith('File "__main__"')?i=!0:((t.startsWith("Trying:")||t.startsWith("1 items had no tests:"))&&(i=!1),i&&(t=t.replace("Failed example:","\n❌ Failed test:"),e.push(t)))})),e.join("\n").trim()}(t)}}}(e):function(t,e){return t.message.startsWith("Traceback")?{status:"fail",header:"Syntax error",details:Vd(t.message,e)}:"Infinite loop"==t.message?{status:"fail",header:"Infinite loop",details:"Your code did not finish executing within 60 seconds. Please look to see if you accidentally coded an infinite loop."}:{status:"fail",header:"Unexpected error occurred",details:`Error: ${t.message}`}}(i,t.startLine),this.runStdout=s||""}catch(t){console.warn(`Error in pyodideWorker at ${t.filename}, Line: ${t.lineno}, ${t.message}`)}this.runStatus="",this.testResultsStatus=t.status,this.testResultsHeader=t.header,this.testResultsDetails=t.details}async resetCode(){if(confirm("Are you sure you want to reset your code to the starter code? This cannot be undone.")){const t=Xe.create({doc:this.starterCode||"",extensions:[rd,Gd(),jn.lineWrapping]});this.editor.setState(t);const e=this.getStorageKey();e&&t$(e,this.starterCode)}}}window.customElements.define("code-exercise-element",i$),t.CodeExerciseElement=i$,Object.defineProperty(t,"t",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CodeExerciseElement={}); diff --git a/src/doctest-grader.js b/src/doctest-grader.js index 787e468..41f295f 100644 --- a/src/doctest-grader.js +++ b/src/doctest-grader.js @@ -41,20 +41,13 @@ function cleanupDoctestResults(resultsStr) { export function prepareCode(code) { const lines = code.split('\n'); - if (!(lines[0].includes('def') || lines[0].includes('class'))) { - return { - status: 'fail', - header: 'Error running tests', - details: 'First code line must be `def` or `class` declaration', - }; - } - - let finalCode = [...lines]; // Copy the lines array + let finalCode = [...lines]; // Redirects stdout so we can return it finalCode.push('import sys'); finalCode.push('import io'); finalCode.push('sys.stdout = io.StringIO()'); + // Runs the doctests finalCode.push('import doctest'); finalCode.push('doctest.testmod(verbose=True)'); From c022ecef4d5a08deea36c2e1ce9edc981a296543 Mon Sep 17 00:00:00 2001 From: Pamela Fox Date: Mon, 30 Jun 2025 06:38:10 -0700 Subject: [PATCH 4/4] Update version in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 392e436..5f0fedb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "python-code-exercise-element", - "version": "0.1.17", + "version": "0.1.18", "description": "A web component for Python coding exercises with doctest runner", "repository": { "type": "git",