From 00aed821e11da1a01e8454694f2464a838eb291f Mon Sep 17 00:00:00 2001 From: Andy Bunce Date: Sat, 20 Sep 2025 17:27:38 +0100 Subject: [PATCH] [mod] improve logging --- README.md | 12 +++--- webapp/lsp/diagnostic.xqm | 0 webapp/lsp/documentSymbols.xqm | 7 ++++ webapp/lsp/jsonrpc.xqm | 40 ++++++++++++++++++- webapp/lsp/later.xq | 2 + webapp/lsp/lsp-diags.xqm | 32 +++++---------- webapp/lsp/lsp-text.xqm | 9 +---- webapp/lsp/lsp-typedefs.xqm | 15 +++++++ webapp/lsp/lsp-ws.xqm | 4 +- webapp/lsp/position.xqm | 3 +- webapp/static/clients/codemirror/grail.css | 11 ++--- .../clients/codemirror/lsp.bundle.min.js | 2 +- 12 files changed, 89 insertions(+), 48 deletions(-) delete mode 100644 webapp/lsp/diagnostic.xqm create mode 100644 webapp/lsp/later.xq diff --git a/README.md b/README.md index 7de8766..cfd071b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ Work in progress. -An attempt to write a [Language Server Protocol](https://en.wikipedia.org/wiki/Language_Server_Protocol) server for and in XQuery 4.0. It uses the [BaseX websocket](https://docs.basex.org/main/WebSockets) feature. +An attempt to write a [Language Server Protocol](https://en.wikipedia.org/wiki/Language_Server_Protocol) server for and in XQuery 4.0. It tracks the draft specifications at https://qt4cg.org/ +It written for BaseX 12.0 and uses the [BaseX websocket](https://docs.basex.org/main/WebSockets) feature. # Demo -1. Requires `Docker` or `Podman` on the local machine. -2. Clone this repo -3. Run `docker compose up -d` The LSP server shall now running on port 3000 (edit `compose.yaml` to change port) -4. In a browser navigate to `http://localhost:3000/static/clients/codemirror/` to see the CodeMirror 6 demo. +The demos expect `Docker` or `Podman` on the local machine. This is only a requirement for the demos. + +1 Clone this repo +2. Run `docker compose up -d` The LSP server shall now running on port 3000 (edit `compose.yaml` to change port) +3. In a browser navigate to `http://localhost:3000/static/clients/codemirror/` to see the CodeMirror 6 demo. In principle, the LSP can be used in any environment that can make use of a LSP server accessed via a websocket. ## LSP Server diff --git a/webapp/lsp/diagnostic.xqm b/webapp/lsp/diagnostic.xqm deleted file mode 100644 index e69de29..0000000 diff --git a/webapp/lsp/documentSymbols.xqm b/webapp/lsp/documentSymbols.xqm index 7f376d8..a298313 100644 --- a/webapp/lsp/documentSymbols.xqm +++ b/webapp/lsp/documentSymbols.xqm @@ -1,7 +1,14 @@ xquery version '4.0'; (:~ Symbols from XQuery source file :) module namespace syms="lsp/symbols"; + +import module namespace lspt = 'lsp-typedefs' at "lsp-typedefs.xqm"; import module namespace pos="lsp/position" at "position.xqm"; +(:~ symbols :) +declare function syms:list() +as map(*){ + +}; diff --git a/webapp/lsp/jsonrpc.xqm b/webapp/lsp/jsonrpc.xqm index 232e4dc..a484177 100644 --- a/webapp/lsp/jsonrpc.xqm +++ b/webapp/lsp/jsonrpc.xqm @@ -39,9 +39,17 @@ as map(*)? declare function rpc:reply($json as map(*)) as empty-sequence() { - let $f :=$rpc:Methods?($json?method) + let $f :=(void(trace($json,"➡️")),$rpc:Methods?($json?method)) let $response := $f!.($json) - return $response!ws:send(.=>trace("REPLY: "),ws:id()) + return $response!rpc:send(.) +}; + +(:~ send with logging :) +declare +function rpc:send($msg as map(*)) +as empty-sequence() +{ + ws:send($msg =>trace("⬅️"),ws:id()) }; (:~ canned initialize response :) @@ -59,6 +67,7 @@ function rpc:method-initialized($json as map(*)) as empty-sequence() { ws:set(ws:id(),"initialized", true()) + (: ,rpc:later(5000,"rpc:show-message","This is a test async message 5secs after initialized",ws:id()) :) }; (:~ unknown method response :) @@ -105,4 +114,31 @@ declare function rpc:error($message as xs:string,$json as map(*)) } } } +}; + +(:~ window/showMessage :) +declare function rpc:show-message($msg as xs:string) +as map(*) +{ +{"jsonrpc": "2.0", + "method":"window/showMessage", + "params":{"type":3, "message": $msg} + } +}; + +(:~ send message after delay :) +declare function rpc:later($msdelay as xs:integer,$fn as xs:string ,$arg, $wsid as xs:string) +{ +let $xq:=`import module namespace rpc = 'rpc' at 'jsonrpc.xqm'; +declare variable $msdelay external; +declare variable $fn external; +declare variable $arg external; +declare variable $wsid external; + +prof:sleep($msdelay), +ws:send(function-lookup(xs:QName($fn),1)($arg),$wsid) +` +let $bindings:={"msdelay": $msdelay,"wsid": $wsid, "fn": $fn,"arg":$arg} +let $opts:={"cache": true(),"base-uri": static-base-uri()} +return job:eval($xq, $bindings,$opts)=>void() }; \ No newline at end of file diff --git a/webapp/lsp/later.xq b/webapp/lsp/later.xq new file mode 100644 index 0000000..1e7d904 --- /dev/null +++ b/webapp/lsp/later.xq @@ -0,0 +1,2 @@ +import module namespace rpc = 'rpc' at 'jsonrpc.xqm'; +rpc:later(1000,"rpc:show-message","Hello","sock") \ No newline at end of file diff --git a/webapp/lsp/lsp-diags.xqm b/webapp/lsp/lsp-diags.xqm index f2f70e4..74b753d 100644 --- a/webapp/lsp/lsp-diags.xqm +++ b/webapp/lsp/lsp-diags.xqm @@ -1,10 +1,5 @@ module namespace lsp-diags = 'lsp-diags'; - -import module namespace lspt = 'lsp-typedefs' at "lsp-typedefs.xqm"; -import module namespace pos="lsp/position" at "position.xqm"; - -declare type lsp-diags:ParseResult as element(Module|ERROR); -(:~ +(:~ codemirror from: number The start position of the relevant text. to: number The end position. May be equal to from, though actually covering text is preferable. severity: "error" | "hint" | "info" | "warning" The severity of the problem. This will influence how it is displayed. @@ -13,21 +8,14 @@ source⁠?: string An optional source string indicating where the diagnostic is message: string The message associated with this diagnostic. renderMessage⁠?: fn(view: EditorView) → Node An optional custom rendering function that displays the message as a DOM node. actions⁠?: readonly Action[] An optional array of actions that can be taken on this diagnostic. - :) -declare record lsp-diags:nostic( - range as lspt:Range, - severity as xs:integer, (: enum('error', 'hint', 'info', 'warning') :) - message as xs:string, - code? as xs:string, - source as xs:string:="xquery" -); +:) +import module namespace lspt = 'lsp-typedefs' at "lsp-typedefs.xqm"; +import module namespace pos="lsp/position" at "position.xqm"; + +declare type lsp-diags:ParseResult as element(Module|ERROR); + + -declare variable $lsp-diags:severities:={ - 'error':1, - 'hint':4, - 'info':3, - 'warning':2 -}; declare function lsp-diags:publish( $uri as xs:string, @@ -60,7 +48,7 @@ as map(*)*{ let $e:= number($xml/@e)-1 return ( (: mark error :) - lsp-diags:nostic(lspt:Range(pos:toPosition($text, $b), + lspt:diagnostic(lspt:Range(pos:toPosition($text, $b), pos:toPosition($text, $e)), 1, $dmesg,'XPST0003'), @@ -68,7 +56,7 @@ as map(*)*{ (:mark after error:) if($e ge string-length($text)) then () - else lsp-diags:nostic(lspt:Range(pos:toPosition($text, $e +1 ), + else lspt:diagnostic(lspt:Range(pos:toPosition($text, $e +1 ), pos:toPosition($text, $last)), 2, "Unparsed due to previous parser error.", diff --git a/webapp/lsp/lsp-text.xqm b/webapp/lsp/lsp-text.xqm index e2f3103..b58caae 100644 --- a/webapp/lsp/lsp-text.xqm +++ b/webapp/lsp/lsp-text.xqm @@ -23,13 +23,8 @@ function lsp-text:hover($json as map(*)) as map(*) { let $r:= [ -`markdown here, this is **bold**. - -A [link](http://google.com) - -The last line.` - , -`A hover at { pos:ln-col($json?params?position) } uri: {$json?params?textDocument?uri} ` +`At { pos:ln-col($json?params?position) }, uri: {$json?params?textDocument?uri}, +[path](https://quodatum.github.io/basex-xqparse/i-BaseX.xhtml#EQName)` ] return rpc:result({"contents":$r},$json) }; diff --git a/webapp/lsp/lsp-typedefs.xqm b/webapp/lsp/lsp-typedefs.xqm index ab36c82..68c42f7 100644 --- a/webapp/lsp/lsp-typedefs.xqm +++ b/webapp/lsp/lsp-typedefs.xqm @@ -94,4 +94,19 @@ declare variable $lspt:SymbolKindMap :={ 'TypeParameter': 26 }; +declare variable $lspt:DiagnosticSeverityKinds:={ + 'error':1, + 'warning':2, + 'info':3, + 'hint':4 +}; + +declare record lspt:diagnostic( + range as lspt:Range, + severity as xs:integer, (: enum('error', 'hint', 'info', 'warning') :) + message as xs:string, + code? as xs:string, + source as xs:string:="xquery" +); + declare type lspt:TraceValue as enum( 'off' , 'messages' , 'verbose'); diff --git a/webapp/lsp/lsp-ws.xqm b/webapp/lsp/lsp-ws.xqm index 83d522f..4d21206 100644 --- a/webapp/lsp/lsp-ws.xqm +++ b/webapp/lsp/lsp-ws.xqm @@ -13,9 +13,7 @@ function lsp-ws:error($error) { trace($error,"ERR ") }; -(:~ - : Creates a WebSocket connection. Registers the user and notifies all clients. - :) +(:~ Creates a WebSocket connection. :) declare %ws:connect('/lsp') function lsp-ws:connect() as empty-sequence() { diff --git a/webapp/lsp/position.xqm b/webapp/lsp/position.xqm index dd156fa..7650b75 100644 --- a/webapp/lsp/position.xqm +++ b/webapp/lsp/position.xqm @@ -14,6 +14,7 @@ as lspt:num let $off:=if($pos?line eq 0) then 0 else $nl[$pos?line] + let $_:=substring($text,$off+1,1)=>string-to-codepoints()=>trace("LF? ") return $off+$pos?character }; @@ -22,7 +23,7 @@ declare function pos:toPosition($text as xs:string, $index as lspt:num ) as lspt:Position { - let $nl:= if($index=>trace("IN ") gt string-length($text)=>trace("L ")) + let $nl:= if($index gt string-length($text)) then error(xs:QName("pos:range"),`out of range: index={$index},length={string-length($text)}`) else index-of(string-to-codepoints($text),10) let $line:=pos:lineAt($nl,$index) diff --git a/webapp/static/clients/codemirror/grail.css b/webapp/static/clients/codemirror/grail.css index e37fc07..3786aeb 100644 --- a/webapp/static/clients/codemirror/grail.css +++ b/webapp/static/clients/codemirror/grail.css @@ -22,19 +22,16 @@ body { grid-template-rows: min-content min-content 1fr min-content; gap: 1px; -* { - padding: 0px 0px; - } -.nav-item{ - padding: 0px 9px; - margin: 0px 3px; +.navbar * { + box-sizing: content-box; } + /* Set editor dimensions */ #editor { max-width: 100%; overflow: hidden; - height:80cqh; + height:75cqh; } /* Stretch editor to fit inside its containing div */ diff --git a/webapp/static/clients/codemirror/lsp.bundle.min.js b/webapp/static/clients/codemirror/lsp.bundle.min.js index c1e787a..2531bc0 100644 --- a/webapp/static/clients/codemirror/lsp.bundle.min.js +++ b/webapp/static/clients/codemirror/lsp.bundle.min.js @@ -1 +1 @@ -var lsp=function(t){"use strict";let e=[],i=[];function n(t){if(t<768)return!1;for(let n=0,s=e.length;;){let r=n+s>>1;if(t=i[r]))return!0;n=r+1}if(n==s)return!1}}function s(t){return t>=127462&&t<=127487}(()=>{let t="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 n=0,s=0;n=0&&s(a(t,n));)i++,n-=2;if(i%2==0)break;e+=2}}}return e}function l(t,e,i){for(;e>0;){let n=o(t,e-2,i);if(n=56320&&t<57344}function c(t){return t>=55296&&t<56320}function u(t){return t<65536?1:2}class f{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){[t,e]=x(this,t,e);let n=[];return this.decompose(0,t,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(e,this.length,n,1),p.from(n,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=x(this,t,e);let i=[];return this.decompose(t,e,i,0),p.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),n=new v(this),s=new v(t);for(let t=e,r=e;;){if(n.next(t),s.next(t),t=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(r+=n.value.length,n.done||r>=i)return!0}}iter(t=1){return new v(this,t)}iterRange(t,e=this.length){return new w(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let n=this.line(t).from;i=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new b(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}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 d(t):p.from(d.split(t,[])):f.empty}}class d extends f{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,n){for(let s=0;;s++){let r=this.text[s],o=n+r.length;if((e?i:o)>=t)return new y(n,o,i,r);n=o+1,i++}}decompose(t,e,i,n){let s=t<=0&&e>=this.length?this:new d(g(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(1&n){let t=i.pop(),e=m(s.text,t.text.slice(),0,s.length);if(e.length<=32)i.push(new d(e,t.length+s.length));else{let t=e.length>>1;i.push(new d(e.slice(0,t)),new d(e.slice(t)))}}else i.push(s)}replace(t,e,i){if(!(i instanceof d))return super.replace(t,e,i);[t,e]=x(this,t,e);let n=m(this.text,m(i.text,g(this.text,0,t)),e),s=this.length+i.length-(e-t);return n.length<=32?new d(n,s):p.from(d.split(n,[]),s)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;s<=e&&rt&&r&&(n+=i),ts&&(n+=o.slice(Math.max(0,t-s),e-s)),s=l+1}return n}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],n=-1;for(let s of t)i.push(s),n+=s.length+1,32==i.length&&(e.push(new d(i,n)),i=[],n=-1);return n>-1&&e.push(new d(i,n)),e}}class p extends f{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,n){for(let s=0;;s++){let r=this.children[s],o=n+r.length,l=i+r.lines-1;if((e?l:o)>=t)return r.lineInner(t,e,i,n);n=o+1,i=l+1}}decompose(t,e,i,n){for(let s=0,r=0;r<=e&&s=r){let s=n&((r<=t?1:0)|(l>=e?2:0));r>=t&&l<=e&&!s?i.push(o):o.decompose(t-r,e-r,i,s)}r=l+1}}replace(t,e,i){if([t,e]=x(this,t,e),i.lines=s&&e<=o){let l=r.replace(t-s,e-s,i),a=this.lines-r.lines+l.lines;if(l.lines>4&&l.lines>a>>6){let s=this.children.slice();return s[n]=l,new p(s,this.length-(e-t)+i.length)}return super.replace(s,o,l)}s=o+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;st&&s&&(n+=i),tr&&(n+=o.sliceString(t-r,e-r,i)),r=l+1}return n}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof p))return 0;let i=0,[n,s,r,o]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,s+=e){if(n==r||s==o)return i;let l=this.children[n],a=t.children[s];if(l!=a)return i+l.scanIdentical(a,e);i+=l.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 d(i,e)}let n=Math.max(32,i>>5),s=n<<1,r=n>>1,o=[],l=0,a=-1,h=[];function c(t){let e;if(t.lines>s&&t instanceof p)for(let e of t.children)c(e);else t.lines>r&&(l>r||!l)?(u(),o.push(t)):t instanceof d&&l&&(e=h[h.length-1])instanceof d&&t.lines+e.lines<=32?(l+=t.lines,a+=t.length+1,h[h.length-1]=new d(e.text.concat(t.text),e.length+1+t.length)):(l+t.lines>n&&u(),l+=t.lines,a+=t.length+1,h.push(t))}function u(){0!=l&&(o.push(1==h.length?h[0]:p.from(h,a)),a=-1,l=h.length=0)}for(let e of t)c(e);return u(),1==o.length?o[0]:new p(o,e)}}function m(t,e,i=0,n=1e9){for(let s=0,r=0,o=!0;r=i&&(a>n&&(l=l.slice(0,n-s)),s0?1:(t instanceof d?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],s=this.offsets[i],r=s>>1,o=n instanceof d?n.text.length:n.children.length;if(r==(e>0?o: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&s)==(e>0?0:1)){if(this.offsets[i]+=e,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(n instanceof d){let s=n.text[r+(e<0?-1:0)];if(this.offsets[i]+=e,s.length>Math.max(0,t))return this.value=0==t?s:e>0?s.slice(t):s.slice(0,s.length-t),this;t-=s.length}else{let s=n.children[r+(e<0?-1:0)];t>s.length?(t-=s.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(s),this.offsets.push(e>0?1:(s instanceof d?s.text.length:s.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class w{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new v(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:n}=this.cursor.next(t);return this.pos+=(n.length+t)*e,this.value=n.length<=i?n:e<0?n.slice(n.length-i):n.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 b{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:n}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(f.prototype[Symbol.iterator]=function(){return this.iter()},v.prototype[Symbol.iterator]=w.prototype[Symbol.iterator]=b.prototype[Symbol.iterator]=function(){return this});class y{constructor(t,e,i,n){this.from=t,this.to=e,this.number=i,this.text=n}get length(){return this.to-this.from}}function x(t,e,i){return[e=Math.max(0,Math.min(t.length,e)),Math.max(e,Math.min(t.length,i))]}function k(t,e,i=!0,n=!0){return r(t,e,i,n)}function S(t,e){let i=t.charCodeAt(e);if(!(n=i,n>=55296&&n<56320&&e+1!=t.length))return i;var n;let s=t.charCodeAt(e+1);return function(t){return t>=56320&&t<57344}(s)?s-56320+(i-55296<<10)+65536:i}function C(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function A(t){return t<65536?1:2}const M=/\r\n?|\n/;var T=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(T||(T={}));class D{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return s+(t-n);s+=o}else{if(i!=T.Simple&&a>=t&&(i==T.TrackDel&&nt||i==T.TrackBefore&&nt))return null;if(a>t||a==t&&e<0&&!o)return t==n||e<0?s:s+l;s+=l}n=a}if(t>n)throw new RangeError(`Position ${t} is out of range for changeset of length ${n}`);return s}touchesRange(t,e=t){for(let i=0,n=0;i=0&&n<=e&&s>=t)return!(ne)||"cover";n=s}return!1}toString(){let t="";for(let e=0;e=0?":"+n:"")}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 D(t)}static create(t){return new D(t)}}class O extends D{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 P(this,(e,i,n,s,r)=>t=t.replace(n,n+(i-e),r),!1),t}mapDesc(t,e=!1){return L(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let n=0,s=0;n=0){e[n]=o,e[n+1]=r;let l=n>>1;for(;i.length0&&E(i,e,s.text),s.forward(t),o+=t}let a=t[r++];for(;o>1].toJSON()))}return t}static of(t,e,i){let n=[],s=[],r=0,o=null;function l(t=!1){if(!t&&!n.length)return;ro||t<0||o>e)throw new RangeError(`Invalid change range ${t} to ${o} (in doc of length ${e})`);let c=h?"string"==typeof h?f.of(h.split(i||M)):h:f.empty,u=c.length;if(t==o&&0==u)return;tr&&R(n,t-r,-1),R(n,o-t,u),E(s,n,c),r=o}}(t),l(!o),o}static empty(t){return new O(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let n=0;ne&&"string"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==s.length)e.push(s[0],0);else{for(;i.length=0&&i<=0&&i==t[s+1]?t[s]+=e:s>=0&&0==e&&0==t[s]?t[s+1]+=i:n?(t[s]+=e,t[s+1]+=i):t.push(e,i)}function E(t,e,i){if(0==i.length)return;let n=e.length-2>>1;if(n>1])),!(i||o==t.sections.length||t.sections[o+1]<0);)l=t.sections[o++],a=t.sections[o++];e(s,h,r,c,u),s=h,r=c}}}function L(t,e,i,n=!1){let s=[],r=n?[]:null,o=new I(t),l=new I(e);for(let t=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(-1==o.ins&&-1==l.ins){let t=Math.min(o.len,l.len);R(s,t,-1),o.forward(t),l.forward(t)}else if(l.ins>=0&&(o.ins<0||t==o.i||0==o.off&&(l.len=0&&t=0)){if(o.done&&l.done)return r?O.createSet(s,r):D.create(s);throw new Error("Mismatched change set lengths")}{let e=0,i=o.len;for(;i;)if(-1==l.ins){let t=Math.min(i,l.len);e+=t,i-=t,l.forward(t)}else{if(!(0==l.ins&&l.lene||o.ins>=0&&o.len>e)&&(t||n.length>i),r.forward2(e),o.forward(e)}}else R(n,0,o.ins,t),s&&E(s,n,o.text),o.next()}}class I{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return e>=t.length?f.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?f.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 N{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get bidiLevel(){let t=7&this.flags;return 7==t?null:t}get goalColumn(){let t=this.flags>>6;return 16777215==t?void 0:t}map(t,e=-1){let i,n;return this.empty?i=n=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),n=t.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new N(i,n,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return z.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return z.range(this.anchor,i)}eq(t,e=!1){return!(this.anchor!=t.anchor||this.head!=t.head||e&&this.empty&&this.assoc!=t.assoc)}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 z.range(t.anchor,t.head)}static create(t,e,i){return new N(t,e,i)}}class z{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:z.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;it.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 z(t.ranges.map(t=>N.fromJSON(t)),t.main)}static single(t,e=t){return new z([z.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,n=0;nt?8:0)|s)}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;in.head?z.range(o,r):z.range(r,o))}}return new z(t,e)}}function q(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let F=0;class H{constructor(t,e,i,n,s){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=n,this.id=F++,this.default=t([]),this.extensions="function"==typeof s?s(this):s}get reader(){return this}static define(t={}){return new H(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:V),!!t.static,t.enables)}of(t){return new W([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new W(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new W(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],i=>e(i.field(t)))}}function V(t,e){return t==e||t.length==e.length&&t.every((t,i)=>t===e[i])}class W{constructor(t,e,i,n){this.dependencies=t,this.facet=e,this.type=i,this.value=n,this.id=F++}dynamicSlot(t){var e;let i=this.value,n=this.facet.compareInput,s=this.id,r=t[s]>>1,o=2==this.type,l=!1,a=!1,h=[];for(let i of this.dependencies)"doc"==i?l=!0:"selection"==i?a=!0:1&(null!==(e=t[i.id])&&void 0!==e?e:1)||h.push(t[i.id]);return{create:t=>(t.values[r]=i(t),1),update(t,e){if(l&&e.docChanged||a&&(e.docChanged||e.selection)||_(t,h)){let e=i(t);if(o?!$(e,t.values[r],n):!n(e,t.values[r]))return t.values[r]=e,1}return 0},reconfigure:(t,e)=>{let l,a=e.config.address[s];if(null!=a){let s=rt(e,a);if(this.dependencies.every(i=>i instanceof H?e.facet(i)===t.facet(i):!(i instanceof U)||e.field(i,!1)==t.field(i,!1))||(o?$(l=i(t),s,n):n(l=i(t),s)))return t.values[r]=s,0}else l=i(t);return t.values[r]=l,1}}}}function $(t,e,i){if(t.length!=e.length)return!1;for(let n=0;nt[e.id]),s=i.map(t=>t.type),r=n.filter(t=>!(1&t)),o=t[e.id]>>1;function l(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(K).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 n=t.values[e],s=this.updateF(n,i);return this.compareF(n,s)?0:(t.values[e]=s,1)},reconfigure:(t,i)=>{let n,s=t.facet(K),r=i.facet(K);return(n=s.find(t=>t.field==this))&&n!=r.find(t=>t.field==this)?(t.values[e]=n.create(t),1):null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}}init(t){return[this,K.of({field:this,create:t})]}get extension(){return this}}const G=4,Y=3,X=2,J=1;function Z(t){return e=>new tt(e,t)}const Q={highest:Z(0),high:Z(J),default:Z(X),low:Z(Y),lowest:Z(G)};class tt{constructor(t,e){this.inner=t,this.prec=e}}class et{of(t){return new it(this,t)}reconfigure(t){return et.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class it{constructor(t,e){this.compartment=t,this.inner=e}}class nt{constructor(t,e,i,n,s,r){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=n,this.staticValues=s,this.facets=r,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(t,e,i){let n=[],s=Object.create(null),r=new Map;for(let i of function(t,e,i){let n=[[],[],[],[],[]],s=new Map;function r(t,o){let l=s.get(t);if(null!=l){if(l<=o)return;let e=n[l].indexOf(t);e>-1&&n[l].splice(e,1),t instanceof it&&i.delete(t.compartment)}if(s.set(t,o),Array.isArray(t))for(let e of t)r(e,o);else if(t instanceof it){if(i.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let n=e.get(t.compartment)||t.inner;i.set(t.compartment,n),r(n,o)}else if(t instanceof tt)r(t.inner,t.prec);else if(t instanceof U)n[o].push(t),t.provides&&r(t.provides,o);else if(t instanceof W)n[o].push(t),t.facet.extensions&&r(t.facet.extensions,X);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.`);r(e,o)}}return r(t,X),n.reduce((t,e)=>t.concat(e))}(t,e,r))i instanceof U?n.push(i):(s[i.facet.id]||(s[i.facet.id]=[])).push(i);let o=Object.create(null),l=[],a=[];for(let t of n)o[t.id]=a.length<<1,a.push(e=>t.slot(e));let h=null==i?void 0:i.config.facets;for(let t in s){let e=s[t],n=e[0].facet,r=h&&h[t]||[];if(e.every(t=>0==t.type))if(o[n.id]=l.length<<1|1,V(r,e))l.push(i.facet(n));else{let t=n.combine(e.map(t=>t.value));l.push(i&&n.compare(t,i.facet(n))?i.facet(n):t)}else{for(let t of e)0==t.type?(o[t.id]=l.length<<1|1,l.push(t.value)):(o[t.id]=a.length<<1,a.push(e=>t.dynamicSlot(e)));o[n.id]=a.length<<1,a.push(t=>j(t,n,e))}}let c=a.map(t=>t(o));return new nt(t,r,c,o,l,s)}}function st(t,e){if(1&e)return 2;let i=e>>1,n=t.status[i];if(4==n)throw new Error("Cyclic dependency between fields and/or facets");if(2&n)return n;t.status[i]=4;let s=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|s}function rt(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const ot=H.define(),lt=H.define({combine:t=>t.some(t=>t),static:!0}),at=H.define({combine:t=>t.length?t[0]:void 0,static:!0}),ht=H.define(),ct=H.define(),ut=H.define(),ft=H.define({combine:t=>!!t.length&&t[0]});class dt{constructor(t,e){this.type=t,this.value=e}static define(){return new pt}}class pt{of(t){return new dt(this,t)}}class mt{constructor(t){this.map=t}of(t){return new gt(this,t)}}class gt{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 gt(this.type,e)}is(t){return this.type==t}static define(t={}){return new mt(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let n of t){let t=n.map(e);t&&i.push(t)}return i}}gt.reconfigure=gt.define(),gt.appendConfig=gt.define();class vt{constructor(t,e,i,n,s,r){this.startState=t,this.changes=e,this.selection=i,this.effects=n,this.annotations=s,this.scrollIntoView=r,this._doc=null,this._state=null,i&&q(i,e.newLength),s.some(t=>t.type==vt.time)||(this.annotations=s.concat(vt.time.of(Date.now())))}static create(t,e,i,n,s,r){return new vt(t,e,i,n,s,r)}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(vt.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function wt(t,e){let i=[];for(let n=0,s=0;;){let r,o;if(n=t[n]))r=t[n++],o=t[n++];else{if(!(s=0;s--){let r=i[s](t);r&&Object.keys(r).length&&(n=bt(n,yt(e,r,t.changes.newLength),!0))}return n==t?t:vt.create(e,t.changes,t.selection,n.effects,n.annotations,n.scrollIntoView)}(i?function(t){let e=t.startState,i=!0;for(let n of e.facet(ht)){let e=n(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:wt(i,e))}if(!0!==i){let n,s;if(!1===i)s=t.changes.invertedDesc,n=O.empty(e.doc.length);else{let e=t.changes.filter(i);n=e.changes,s=e.filtered.mapDesc(e.changes).invertedDesc}t=vt.create(e,n,t.selection&&t.selection.map(s),gt.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let n=e.facet(ct);for(let i=n.length-1;i>=0;i--){let s=n[i](t);t=s instanceof vt?s:Array.isArray(s)&&1==s.length&&s[0]instanceof vt?s[0]:xt(e,St(s),!1)}return t}(s):s)}vt.time=dt.define(),vt.userEvent=dt.define(),vt.addToHistory=dt.define(),vt.remote=dt.define();const kt=[];function St(t){return null==t?kt:Array.isArray(t)?t:[t]}var Ct=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(Ct||(Ct={}));const At=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Mt;try{Mt=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}function Tt(t){return e=>{if(!/\S/.test(e))return Ct.Space;if(function(t){if(Mt)return Mt.test(t);for(let e=0;e"€"&&(i.toUpperCase()!=i.toLowerCase()||At.test(i)))return!0}return!1}(e))return Ct.Word;for(let i=0;i-1)return Ct.Word;return Ct.Other}}class Dt{constructor(t,e,i,n,s,r){this.config=t,this.doc=e,this.selection=i,this.values=n,this.status=t.statusTemplate.slice(),this.computeSlot=s,r&&(r._state=this);for(let t=0;ts.set(e,t)),i=null),s.set(e.value.compartment,e.value.extension)):e.is(gt.reconfigure)?(i=null,n=e.value):e.is(gt.appendConfig)&&(i=null,n=St(n).concat(e.value));if(i)e=t.startState.values.slice();else{i=nt.resolve(n,s,this),e=new Dt(i,this.doc,this.selection,i.dynamicSlots.map(()=>null),(t,e)=>e.reconfigure(t,this),null).values}let r=t.startState.facet(lt)?t.newSelection:t.newSelection.asSingle();new Dt(i,t.newDoc,r,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:z.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),n=this.changes(i.changes),s=[i.range],r=St(i.effects);for(let i=1;is.spec.fromJSON(r,t)))}return Dt.create({doc:t.doc,selection:z.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(t={}){let e=nt.resolve(t.extensions||[],new Map),i=t.doc instanceof f?t.doc:f.of((t.doc||"").split(e.staticFacet(Dt.lineSeparator)||M)),n=t.selection?t.selection instanceof z?t.selection:z.single(t.selection.anchor,t.selection.head):z.single(0);return q(n,i.length),e.staticFacet(lt)||(n=n.asSingle()),new Dt(e,i,n,e.dynamicSlots.map(()=>null),(t,e)=>e.create(t),null)}get tabSize(){return this.facet(Dt.tabSize)}get lineBreak(){return this.facet(Dt.lineSeparator)||"\n"}get readOnly(){return this.facet(ft)}phrase(t,...e){for(let e of this.facet(Dt.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 n=+(i||1);return!n||n>e.length?t:e[n-1]})),t}languageDataAt(t,e,i=-1){let n=[];for(let s of this.facet(ot))for(let r of s(this,e,i))Object.prototype.hasOwnProperty.call(r,t)&&n.push(r[t]);return n}charCategorizer(t){return Tt(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:n}=this.doc.lineAt(t),s=this.charCategorizer(t),r=t-i,o=t-i;for(;r>0;){let t=k(e,r,!1);if(s(e.slice(t,r))!=Ct.Word)break;r=t}for(;ot.length?t[0]:4}),Dt.lineSeparator=at,Dt.readOnly=ft,Dt.phrases=H.define({compare(t,e){let i=Object.keys(t),n=Object.keys(e);return i.length==n.length&&i.every(i=>t[i]==e[i])}}),Dt.languageData=ot,Dt.changeFilter=ht,Dt.transactionFilter=ct,Dt.transactionExtender=ut,et.reconfigure=gt.define();class Rt{eq(t){return this==t}range(t,e=t){return Et.create(t,e,this)}}Rt.prototype.startSide=Rt.prototype.endSide=0,Rt.prototype.point=!1,Rt.prototype.mapMode=T.TrackDel;let Et=class t{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(e,i,n){return new t(e,i,n)}};function Pt(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Lt{constructor(t,e,i,n){this.from=t,this.to=e,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,n=0){let s=i?this.to:this.from;for(let r=n,o=s.length;;){if(r==o)return r;let n=r+o>>1,l=s[n]-t||(i?this.value[n].endSide:this.value[n].startSide)-e;if(n==r)return l>=0?r:o;l>=0?o=n:r=n+1}}between(t,e,i,n){for(let s=this.findIndex(e,-1e9,!0),r=this.findIndex(i,1e9,!1,s);sh||a==h&&c.startSide>0&&c.endSide<=0)continue;(h-a||c.endSide-c.startSide)<0||(r<0&&(r=a),c.point&&(o=Math.max(o,h-a)),i.push(c),n.push(a-r),s.push(h-r))}return{mapped:i.length?new Lt(n,s,i,o):null,pos:r}}}class Bt{constructor(t,e,i,n){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=n}static create(t,e,i,n){return new Bt(t,e,i,n)}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:n=0,filterTo:s=this.length}=t,r=t.filter;if(0==e.length&&!r)return this;if(i&&(e=e.slice().sort(Pt)),this.isEmpty)return e.length?Bt.of(e):this;let o=new zt(this,null,-1).goto(0),l=0,a=[],h=new It;for(;o.value||l=0){let t=e[l++];h.addInner(t.from,t.to,t.value)||a.push(t)}else 1==o.rangeIndex&&o.chunkIndexthis.chunkEnd(o.chunkIndex)||so.to||s=s&&t<=s+r.length&&!1===r.between(s,t-s,e-s,i))return}this.nextLayer.between(t,e,i)}}iter(t=0){return qt.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return qt.from(t).goto(e)}static compare(t,e,i,n,s=-1){let r=t.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),o=e.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),l=Nt(r,o,i),a=new Ht(r,l,s),h=new Ht(o,l,s);i.iterGaps((t,e,i)=>Vt(a,t,h,e,i,n)),i.empty&&0==i.length&&Vt(a,0,h,0,0,n)}static eq(t,e,i=0,n){null==n&&(n=999999999);let s=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0),r=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0);if(s.length!=r.length)return!1;if(!s.length)return!0;let o=Nt(s,r),l=new Ht(s,o,0).goto(i),a=new Ht(r,o,0).goto(i);for(;;){if(l.to!=a.to||!Wt(l.active,a.active)||l.point&&(!a.point||!l.point.eq(a.point)))return!1;if(l.to>n)return!0;l.next(),a.next()}}static spans(t,e,i,n,s=-1){let r=new Ht(t,null,s).goto(e),o=e,l=r.openStart;for(;;){let t=Math.min(r.to,i);if(r.point){let i=r.activeForPoint(r.to),s=r.pointFromo&&(n.span(o,t,r.active,l),l=r.openEnd(t));if(r.to>i)return l+(r.point&&r.to>i?1:0);o=r.to,r.next()}}static of(t,e=!1){let i=new It;for(let n of t instanceof Et?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i0)return t.slice().sort(Pt);e=n}return t}(t):t)i.add(n.from,n.to,n.value);return i.finish()}static join(t){if(!t.length)return Bt.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let n=t[i];n!=Bt.empty;n=n.nextLayer)e=new Bt(n.chunkPos,n.chunk,e,Math.max(n.maxPoint,e.maxPoint));return e}}Bt.empty=new Bt([],[],null,-1),Bt.empty.nextLayer=Bt.empty;class It{finishChunk(t){this.chunks.push(new Lt(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=[])}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}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new It)).add(t,e,i)}addInner(t,e,i){let n=t-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(n<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(Bt.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=Bt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Nt(t,e,i){let n=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&&n.push(new zt(r,e,i,s));return 1==n.length?n[0]:new qt(n)}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--)Ft(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--)Ft(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(),Ft(this.heap,0)}}}function Ft(t,e){for(let i=t[e];;){let n=1+(e<<1);if(n>=t.length)break;let s=t[n];if(n+1=0&&(s=t[n+1],n++),i.compare(s)<0)break;t[n]=i,t[e]=s,e=n}}class Ht{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=qt.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){$t(this.active,t),$t(this.activeTo,t),$t(this.activeRank,t),this.minActive=jt(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:n,rank:s}=this.cursor;for(;e0;)e++;_t(this.active,e,i),_t(this.activeTo,e,n),_t(this.activeRank,e,s),t&&_t(t,e,this.cursor.from),this.minActive=jt(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>t){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&$t(i,n)}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 t=this.cursor.value;if(t.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from=0&&i[e]=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 Vt(t,e,i,n,s,r){t.goto(e),i.goto(n);let o=n+s,l=n,a=n-e;for(;;){let e=t.to+a-i.to,n=e||t.endSide-i.endSide,s=n<0?t.to+a:i.to,h=Math.min(s,o);if(t.point||i.point?t.point&&i.point&&(t.point==i.point||t.point.eq(i.point))&&Wt(t.activeForPoint(t.to),i.activeForPoint(i.to))||r.comparePoint(l,h,t.point,i.point):h>l&&!Wt(t.active,i.active)&&r.compareRange(l,h,t.active,i.active),s>o)break;(e||t.openEnd!=i.openEnd)&&r.boundChange&&r.boundChange(s),l=s,n<=0&&t.next(),n>=0&&i.next()}}function Wt(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 jt(t,e){let i=-1,n=1e9;for(let s=0;s=e)return n;if(n==t.length)break;s+=9==t.charCodeAt(n)?i-s%i:1,n=k(t,n)}return!0===n?-1:t.length}const Gt="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),Yt="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),Xt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class Jt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function n(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function s(t,e,r,o){let l=[],a=/^@(\w+)\b/.exec(t[0]),h=a&&"keyframes"==a[1];if(a&&null==e)return r.push(t[0]+";");for(let i in e){let o=e[i];if(/&/.test(i))s(i.split(/,\s*/).map(e=>t.map(t=>e.replace(/&/,t))).reduce((t,e)=>t.concat(e)),o,r);else if(o&&"object"==typeof o){if(!a)throw new RangeError("The value of a property ("+i+") should be a primitive value.");s(n(i),o,l,h)}else null!=o&&l.push(i.replace(/_.*/,"").replace(/[A-Z]/g,t=>"-"+t.toLowerCase())+": "+o+";")}(l.length||h)&&r.push((!i||a||o?t:t.map(i)).join(", ")+" {"+l.join(" ")+"}")}for(let e in t)s(n(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=Xt[Gt]||1;return Xt[Gt]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let n=t[Yt],s=i&&i.nonce;n?s&&n.setNonce(s):n=new Qt(t,s),n.mount(Array.isArray(e)?e:[e],t)}}let Zt=new Map;class Qt{constructor(t,e){let i=t.ownerDocument||t,n=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let e=Zt.get(i);if(e)return t[Yt]=e;this.sheet=new n.CSSStyleSheet,Zt.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[Yt]=this}mount(t,e){let i=this.sheet,n=0,s=0;for(let e=0;e-1&&(this.modules.splice(o,1),s--,o=-1),-1==o){if(this.modules.splice(s++,0,r),i)for(let t=0;t",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ie="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),ne="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),se=0;se<10;se++)te[48+se]=te[96+se]=String(se);for(se=1;se<=24;se++)te[se+111]="F"+se;for(se=65;se<=90;se++)te[se]=String.fromCharCode(se+32),ee[se]=String.fromCharCode(se);for(var re in te)ee.hasOwnProperty(re)||(ee[re]=te[re]);function oe(){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 n in i)if(Object.prototype.hasOwnProperty.call(i,n)){var s=i[n];"string"==typeof s?t.setAttribute(n,s):null!=s&&(t[n]=s)}e++}for(;e.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)&&(i=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.height-t.offsetHeight)<1)&&(n=1),{scaleX:i,scaleY:n}}class ye{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?ge(e):0),i,Math.min(t.focusOffset,i?ge(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}}let xe,ke=null;function Se(t){if(t.setActive)return t.setActive();if(ke)return t.focus(ke);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==ke?{get preventScroll(){return ke={preventScroll:!0},!0}}:void 0),!ke){ke=!1;for(let t=0;tMath.max(1,t.scrollHeight-t.clientHeight-4)}function De(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&n>0)return{node:i,offset:n};if(1==i.nodeType&&n>0){if("false"==i.contentEditable)return null;i=i.childNodes[n-1],n=ge(i)}else{if(!i.parentNode||pe(i))return null;n=de(i),i=i.parentNode}}}function Oe(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&ne)return i.domBoundsAround(t,e,a);if(c>=t&&-1==n&&(n=l,s=a),a>e&&i.dom.parentNode==this.dom){r=l,o=h;break}h=c,a=c+i.breakAfter}return{from:s,to:o<0?i+this.length:o,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:r=0?this.children[r].dom:null}}markDirty(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),1&e.flags)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,7&this.flags&&this.markParentsDirty(!0))}setDOM(t){this.dom!=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=Ee){this.markDirty();for(let n=t;nthis.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 Ie(t,e,i,n,s,r,o,l,a){let{children:h}=t,c=h.length?h[e]:null,u=r.length?r[r.length-1]:null,f=u?u.breakAfter:o;if(!(e==n&&c&&!o&&!f&&r.length<2&&c.merge(i,s,r.length?u:null,0==i,l,a))){if(n0&&(!o&&r.length&&c.merge(i,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(i2);var Ge={mac:Ue||/Mac/.test(ze.platform),windows:/Win/.test(ze.platform),linux:/Linux|X11/.test(ze.platform),ie:We,ie_version:He?qe.documentMode||6:Ve?+Ve[1]:Fe?+Fe[1]:0,gecko:$e,gecko_version:$e?+(/Firefox\/(\d+)/.exec(ze.userAgent)||[0,0])[1]:0,chrome:!!_e,chrome_version:_e?+_e[1]:0,ios:Ue,android:/Android\b/.test(ze.userAgent),safari:Ke,webkit_version:je?+(/\bAppleWebKit\/(\d+)/.exec(ze.userAgent)||[0,0])[1]:0,tabSize:null!=qe.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};class Ye extends Pe{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){3==t.nodeType&&this.createDOM(t)}merge(t,e,i){return!(8&this.flags||i&&(!(i instanceof Ye)||this.length-(e-t)+i.length>256||8&i.flags))&&(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Ye(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=8&this.flags,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new Re(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 function(t,e,i){let n=t.nodeValue.length;e>n&&(e=n);let s=e,r=e,o=0;0==e&&i<0||e==n&&i>=0?Ge.chrome||Ge.gecko||(e?(s--,o=1):r=0)?0:l.length-1];Ge.safari&&!o&&0==a.width&&(a=Array.prototype.find.call(l,t=>t.width)||a);return o?ve(a,o<0):a||null}(this.dom,t,e)}}class Xe extends Pe{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(Me(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!(8&(this.flags|t.flags))}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?4&this.flags&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,n,s,r){return(!i||!(!(i instanceof Xe&&i.mark.eq(this.mark))||t&&s<=0||et&&e.push(i=t&&(n=s),i=o,s++}let r=this.length-t;return this.length=t,n>-1&&(this.children.length=n,this.markDirty()),new Xe(this.mark,e,r)}domAtPos(t){return Qe(this,t)}coordsAt(t,e){return ei(this,t,e)}}class Je extends Pe{static create(t,e,i){return new Je(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=Je.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){this.dom&&this.widget.updateDOM(this.dom,t)||(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,n,s,r){return!(i&&(!(i instanceof Je&&this.widget.compare(i.widget))||t>0&&s<=0||e0)?Re.before(this.dom):Re.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let n=this.dom.getClientRects(),s=null;if(!n.length)return null;let r=this.side?this.side<0:t>0;for(let e=r?n.length-1:0;s=n[e],!(t>0?0==e:e==n.length-1||s.top0?Re.before(this.dom):Re.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return f.empty}get isHidden(){return!0}}function Qe(t,e){let i=t.dom,{children:n}=t,s=0;for(let t=0;st&&e0;t--){let e=n[t-1];if(e.dom.parentNode==i)return e.domAtPos(e.length)}for(let t=s;t0&&e instanceof Xe&&s.length&&(n=s[s.length-1])instanceof Xe&&n.mark.eq(e.mark)?ti(n,e.children[0],i-1):(s.push(e),e.setParent(t)),t.length+=e.length}function ei(t,e,i){let n=null,s=-1,r=null,o=-1;!function t(e,l){for(let a=0,h=0;a=l&&(c.children.length?t(c,l-h):(!r||r.isHidden&&(i>0||ii(r,c)))&&(u>l||h==u&&c.getSide()>0)?(r=c,o=l-h):(h-1?1:0)!=s.length-(i&&s.indexOf(i)>-1?1:0))return!1;for(let r of n)if(r!=i&&(-1==s.indexOf(r)||t[r]!==e[r]))return!1;return!0}function oi(t,e,i){let n=!1;if(e)for(let s in e)i&&s in i||(n=!0,"style"==s?t.style.cssText="":t.removeAttribute(s));if(i)for(let s in i)e&&e[s]==i[s]||(n=!0,"style"==s?t.style.cssText=i[s]:t.setAttribute(s,i[s]));return n}function li(t){let e=Object.create(null);for(let i=0;i0?3e8:-4e8:e>0?1e8:-1e8,new di(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,n=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:s,end:r}=pi(t,n);e=(s?n?-3e8:-1:5e8)-1,i=1+(r?n?2e8:1:-6e8)}return new di(t,e,i,n,t.widget||null,!0)}static line(t){return new fi(t)}static set(t,e=!1){return Bt.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}ci.none=Bt.empty;class ui extends ci{constructor(t){let{start:e,end:i}=pi(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof ui&&this.tagName==t.tagName&&(this.class||(null===(e=this.attrs)||void 0===e?void 0:e.class))==(t.class||(null===(i=t.attrs)||void 0===i?void 0:i.class))&&ri(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}ui.prototype.point=!1;class fi extends ci{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof fi&&this.spec.class==t.spec.class&&ri(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)}}fi.prototype.mapMode=T.TrackBefore,fi.prototype.point=!0;class di extends ci{constructor(t,e,i,n,s,r){super(e,i,s,t),this.block=n,this.isReplace=r,this.mapMode=n?e<=0?T.TrackBefore:T.TrackAfter:T.TrackDel}get type(){return this.startSide!=this.endSide?hi.WidgetRange:this.startSide<=0?hi.WidgetBefore:hi.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof di&&(e=this.widget,i=t.widget,e==i||!!(e&&i&&e.compare(i)))&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide;var e,i}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}function pi(t,e=!1){let{inclusiveStart:i,inclusiveEnd:n}=t;return null==i&&(i=t.inclusive),null==n&&(n=t.inclusive),{start:null!=i?i:e,end:null!=n?n:e}}function mi(t,e,i,n=0){let s=i.length-1;s>=0&&i[s]+n>=t?i[s]=Math.max(i[s],e):i.push(t,e)}di.prototype.point=!0;class gi extends Pe{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,n,s,r){if(i){if(!(i instanceof gi))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),Ne(this,t,e,i?i.children.slice():[],s,r),!0}split(t){let e=new gi;if(e.breakAfter=this.breakAfter,0==this.length)return e;let{i:i,off:n}=this.childPos(t);n&&(e.append(this.children[i].split(n),0),this.children[i].merge(n,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){ri(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){ti(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=ni(e,this.attrs||{})),i&&(this.attrs=ni({class:i},this.attrs||{}))}domAtPos(t){return Qe(this,t)}reuseDOM(t){"DIV"==t.nodeName&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?4&this.flags&&(Me(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&&(oi(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let n=this.dom.lastChild;for(;n&&Pe.get(n)instanceof Xe;)n=n.lastChild;if(!(n&&this.length&&("BR"==n.nodeName||0!=(null===(i=Pe.get(n))||void 0===i?void 0:i.isEditable)||Ge.ios&&this.children.some(t=>t instanceof Ye)))){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,e=0;for(let i of this.children){if(!(i instanceof Ye)||/[^ -~]/.test(i.text))return null;let n=ue(i.dom);if(1!=n.length)return null;e+=n[0].width,t=n[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(t,e){let i=ei(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:t}=this.parent.view.viewState,e=i.bottom-i.top;if(Math.abs(e-t.lineHeight)<2&&t.textHeight=e){if(s instanceof gi)return s;if(r>e)break}n=r+s.breakAfter}return null}}class vi extends Pe{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,n,s,r){return!(i&&(!(i instanceof vi&&this.widget.compare(i.widget))||t>0&&s<=0||e0)}}class wi extends ai{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}class bi{constructor(t,e,i,n){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=n,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(0==this.content.length)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof vi&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new gi),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(yi(new Ze(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,this.posCovered()||t&&this.content.length&&this.content[this.content.length-1]instanceof vi||this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:n}=this.cursor.next(this.skip);if(this.skip=0,n)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,this.atCursorPos=!0,t--;continue}this.text=e,this.textOff=0}let n=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(yi(new Ye(this.text.slice(this.textOff,this.textOff+n)),e),i),this.atCursorPos=!0,this.textOff+=n,t-=n,i=0}}span(t,e,i,n){this.buildText(e-t,i,n),this.pos=e,this.openStart<0&&(this.openStart=n)}point(t,e,i,n,s,r){if(this.disallowBlockEffectsFor[r]&&i instanceof di){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 o=e-t;if(i instanceof di)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new vi(i.widget||xi.block,o,i));else{let r=Je.create(i.widget||xi.inline,o,o?0:i.startSide),l=this.atCursorPos&&!r.isEditable&&s<=n.length&&(t0),a=!r.isEditable&&(tn.length||i.startSide<=0),h=this.getLine();2!=this.pendingBuffer||l||r.isEditable||(this.pendingBuffer=0),this.flushBuffer(n),l&&(h.append(yi(new Ze(1),n),s),s=n.length+Math.max(0,s-n.length)),h.append(yi(r,n),s),this.atCursorPos=a,this.pendingBuffer=a?tn.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=n.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);o&&(this.textOff+o<=this.text.length?this.textOff+=o:(this.skip+=o-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=s)}static build(t,e,i,n,s){let r=new bi(t,e,i,s);return r.openEnd=Bt.spans(n,e,i,r),r.openStart<0&&(r.openStart=r.openEnd),r.finish(r.openEnd),r}}function yi(t,e){for(let i of e)t=new Xe(i,[t],t.length);return t}class xi extends ai{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}xi.inline=new xi("span"),xi.block=new xi("div");var ki=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(ki||(ki={}));const Si=ki.LTR,Ci=ki.RTL;function Ai(t){let e=[];for(let i=0;i=e){if(o.level==i)return r;(s<0||(0!=n?n<0?o.frome:t[s].level>o.level))&&(s=r)}}if(s<0)throw new RangeError("Index out of range");return s}}function Li(t,e){if(t.length!=e.length)return!1;for(let i=0;ia&&o.push(new Pi(a,p.from,f)),Ni(t,p.direction==Si!=!(f%2)?n+1:n,s,p.inner,p.from,p.to,o),a=p.to}d=p.to}else{if(d==i||(e?Bi[d]!=l:Bi[d]==l))break;d++}u?Ii(t,a,d,n+1,s,u,o):ae;){let i=!0,c=!1;if(!h||a>r[h-1].to){let t=Bi[a-1];t!=l&&(i=!1,c=16==t)}let u=i||1!=l?null:[],f=i?n:n+1,d=a;t:for(;;)if(h&&d==r[h-1].to){if(c)break t;let p=r[--h];if(!i)for(let t=p.from,i=h;;){if(t==e)break t;if(!i||r[i-1].to!=t){if(Bi[t-1]==l)break t;break}t=r[--i].from}if(u)u.push(p);else{p.to=0;t-=3)if(Oi[t+1]==-i){let e=Oi[t+2],i=2&e?s:4&e?1&e?r:s:0;i&&(Bi[o]=Bi[Oi[t]]=i),l=t;break}}else{if(189==Oi.length)break;Oi[l++]=o,Oi[l++]=e,Oi[l++]=a}else if(2==(n=Bi[o])||1==n){let t=n==s;a=t?0:1;for(let e=l-3;e>=0;e-=3){let i=Oi[e+2];if(2&i)break;if(t)Oi[e+2]|=2;else{if(4&i)break;Oi[e+2]|=4}}}}}(t,s,r,n,l),function(t,e,i,n){for(let s=0,r=n;s<=i.length;s++){let o=s?i[s-1].to:t,l=sa;)e==r&&(e=i[--n].from,r=n?i[n-1].to:t),Bi[--e]=c;a=o}else r=o,a++}}}(s,r,n,l),Ii(t,s,r,e,i,n,o)}function zi(t){return[new Pi(0,t,0)]}let qi="";function Fi(t,e,i,n,s){var r;let o=n.head-t.from,l=Pi.find(e,o,null!==(r=n.bidiLevel)&&void 0!==r?r:-1,n.assoc),a=e[l],h=a.side(s,i);if(o==h){let t=l+=s?1:-1;if(t<0||t>=e.length)return null;a=e[l=t],o=a.side(!s,i),h=a.side(s,i)}let c=k(t.text,o,a.forward(s,i));(ca.to)&&(c=h),qi=t.text.slice(Math.min(o,c),Math.max(o,c));let u=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return u&&c==h&&u.level+(s?0:1)t.some(t=>t)}),Ji=H.define({combine:t=>t.some(t=>t)}),Zi=H.define();class Qi{constructor(t,e="nearest",i="nearest",n=5,s=5,r=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=s,this.isSnapshot=r}map(t){return t.empty?this:new Qi(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Qi(z.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const tn=gt.define({map:(t,e)=>t.map(e)}),en=gt.define();function nn(t,e,i){let n=t.facet(_i);n.length?n[0](e):window.onerror&&window.onerror(String(e),i,void 0,void 0,e)||(i?console.error(i+":",e):console.error(e))}const sn=H.define({combine:t=>!t.length||t[0]});let rn=0;const on=H.define({combine:t=>t.filter((e,i)=>{for(let n=0;n{let e=[];return r&&e.push(un.of(e=>{let i=e.plugin(t);return i?r(i):ci.none})),s&&e.push(s(t)),e})}static fromClass(t,e){return ln.define((e,i)=>new t(e,i),e)}}class an{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(nn(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){nn(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){nn(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const hn=H.define(),cn=H.define(),un=H.define(),fn=H.define(),dn=H.define(),pn=H.define();function mn(t,e){let i=t.state.facet(pn);if(!i.length)return i;let n=i.map(e=>e instanceof Function?e(t):e),s=[];return Bt.spans(n,e.from,e.to,{point(){},span(t,i,n,r){let o=t-e.from,l=i-e.from,a=s;for(let t=n.length-1;t>=0;t--,r--){let i,s=n[t].spec.bidiIsolate;if(null==s&&(s=Hi(e.text,o,l)),r>0&&a.length&&(i=a[a.length-1]).to==o&&i.direction==s)i.to=l,a=i.inner;else{let t={from:o,to:l,direction:s,inner:[]};a.push(t),a=t.inner}}}}),s}const gn=H.define();function vn(t){let e=0,i=0,n=0,s=0;for(let r of t.state.facet(gn)){let o=r(t);o&&(null!=o.left&&(e=Math.max(e,o.left)),null!=o.right&&(i=Math.max(i,o.right)),null!=o.top&&(n=Math.max(n,o.top)),null!=o.bottom&&(s=Math.max(s,o.bottom)))}return{left:e,right:i,top:n,bottom:s}}const wn=H.define();class bn{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new bn(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toAh)break;s+=2}if(!l)return i;new bn(l.fromA,l.toA,l.fromB,l.toB).addToSet(i),r=l.toA,o=l.toB}}}class yn{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=O.empty(this.startState.doc.length);for(let t of i)this.changes=this.changes.compose(t.changes);let n=[];this.changes.iterChangedRanges((t,e,i,s)=>n.push(new bn(t,e,i,s))),this.changedRanges=n}static create(t,e,i){return new yn(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return 0==this.flags&&0==this.transactions.length}}class xn extends Pe{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=ci.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new gi],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new bn(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.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.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(e=this.domChanged)||void 0===e?void 0:e.newSel)?n=this.domChanged.newSel.head:function(t,e){let i=!1;e&&t.iterChangedRanges((t,n)=>{te.from&&(i=!0)});return i}(t.changes,this.hasComposition)||t.selectionSet||(n=t.state.selection.main.head));let s=n>-1?function(t,e,i){let n=kn(t,i);if(!n)return null;let{node:s,from:r,to:o}=n,l=s.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(n.from,n.to)!=l)return null;let a=e.invertedDesc,h=new bn(a.mapPos(r),a.mapPos(o),r,o),c=[];for(let e=s.parentNode;;e=e.parentNode){let i=Pe.get(e);if(i instanceof Xe)c.push({node:e,deco:i.mark});else{if(i instanceof gi||"DIV"==e.nodeName&&e.parentNode==t.contentDOM)return{range:h,text:s,marks:c,line:e};if(e==t.contentDOM)return null;c.push({node:e,deco:new ui({inclusive:!0,attributes:li(e),tagName:e.tagName.toLowerCase()})})}}}(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:e,to:n}=this.hasComposition;i=new bn(e,n,t.changes.mapPos(e,-1),t.changes.mapPos(n,1)).addToSet(i.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(Ge.ie||Ge.chrome)&&!s&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let r=function(t,e,i){let n=new Sn;return Bt.compare(t,e,i,n),n.changes}(this.decorations,this.updateDeco(),t.changes);return i=bn.extendWithRanges(i,r),!!(7&this.flags||0!=i.length)&&(this.updateInner(i,t.startState.doc.length,s),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:n}=this.view;n.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let t=Ge.chrome||Ge.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,t),this.flags&=-8,t&&(t.written||n.selectionRange.focusNode!=t.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(t=>t.flags&=-9);let s=[];if(this.view.viewport.from||this.view.viewport.to=0?n[t]:null;if(!e)break;let r,o,l,a,{fromA:h,toA:c,fromB:u,toB:f}=e;if(i&&i.range.fromBu){let t=bi.build(this.view.state.doc,u,i.range.fromB,this.decorations,this.dynamicDecorationMap),e=bi.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);o=t.breakAtStart,l=t.openStart,a=e.openEnd;let n=this.compositionView(i);e.breakAtStart?n.breakAfter=1:e.content.length&&n.merge(n.length,n.length,e.content[0],!1,e.openStart,0)&&(n.breakAfter=e.content[0].breakAfter,e.content.shift()),t.content.length&&n.merge(0,0,t.content[t.content.length-1],!0,0,t.openEnd)&&t.content.pop(),r=t.content.concat(n).concat(e.content)}else({content:r,breakAtStart:o,openStart:l,openEnd:a}=bi.build(this.view.state.doc,u,f,this.decorations,this.dynamicDecorationMap));let{i:d,off:p}=s.findPos(c,1),{i:m,off:g}=s.findPos(h,-1);Ie(this,m,g,d,p,r,o,l,a)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let t of e.effects)t.is(en)&&(this.editContextFormatting=t.value)}compositionView(t){let e=new Ye(t.text.nodeValue);e.flags|=8;for(let{deco:i}of t.marks)e=new Xe(i,[e],e.length);let i=new gi;return i.append(e,0),i}fixCompositionDOM(t){let e=(t,e)=>{e.flags|=8|(e.children.some(t=>7&t.flags)?1:0),this.markedForComposition.add(e);let i=Pe.get(t);i&&i!=e&&(i.dom=null),e.setDOM(t)},i=this.childPos(t.range.fromB,1),n=this.children[i.i];e(t.line,n);for(let s=t.marks.length-1;s>=-1;s--)i=n.childPos(i.off,1),n=n.children[i.i],e(s>=0?t.marks[s].node:t.text,n)}updateSelection(t=!1,e=!1){!t&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,s=!n&&!(this.view.state.facet(sn)||this.dom.tabIndex>-1)&&ce(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||e||s))return;let r=this.forceSelection;this.forceSelection=!1;let o=this.view.state.selection.main,l=this.moveToLine(this.domAtPos(o.anchor)),a=o.empty?l:this.moveToLine(this.domAtPos(o.head));if(Ge.gecko&&o.empty&&!this.hasComposition&&(1==(h=l).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(()=>l.node.insertBefore(t,l.node.childNodes[l.offset]||null)),l=a=new Re(t,0),r=!0}var h;let c=this.view.observer.selectionRange;!r&&c.focusNode&&(fe(l.node,l.offset,c.anchorNode,c.anchorOffset)&&fe(a.node,a.offset,c.focusNode,c.focusOffset)||this.suppressWidgetCursorChange(c,o))||(this.view.observer.ignore(()=>{Ge.android&&Ge.chrome&&this.dom.contains(c.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}(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let t=ae(this.view.root);if(t)if(o.empty){if(Ge.gecko){let t=(e=l.node,n=l.offset,1!=e.nodeType?0:(n&&"false"==e.childNodes[n-1].contentEditable?1:0)|(no.head&&([l,a]=[a,l]),e.setEnd(a.node,a.offset),e.setStart(l.node,l.offset),t.removeAllRanges(),t.addRange(e)}else;var e,n;s&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(l,a)),this.impreciseAnchor=l.precise?null:new Re(c.anchorNode,c.anchorOffset),this.impreciseHead=a.precise?null:new Re(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&fe(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=ae(t.root),{anchorNode:n,anchorOffset:s}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let r=gi.find(this,e.head);if(!r)return;let o=r.posAtStart;if(e.head==o||e.head==o+r.length)return;let l=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!l||!a||l.bottom>a.top)return;let h=this.domAtPos(e.head+e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(n,s)}moveToLine(t){let e,i=this.dom;if(t.node!=i)return t;for(let n=t.offset;!e&&n=0;n--){let t=Pe.get(i.childNodes[n]);t instanceof gi&&(e=t.domAtPos(t.length))}return e?new Re(e.node,e.offset,!0):t}nearest(t){for(let e=t;e;){let t=Pe.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(;e=0;r--){let o=this.children[r],l=s-o.breakAfter,a=l-o.length;if(lt||o.covers(1))&&(!i||o instanceof gi&&!(i instanceof gi&&e>=0)))i=o,n=a;else if(i&&a==t&&l==t&&o instanceof vi&&Math.abs(e)<2){if(o.deco.startSide<0)break;r&&(i=null)}s=a}return i?i.coordsAt(t-n,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),n=this.children[e];if(!(n instanceof gi))return null;for(;n.children.length;){let{i:t,off:e}=n.childPos(i,1);for(;;t++){if(t==n.children.length)return null;if((n=n.children[t]).length)break}i=e}if(!(n instanceof Ye))return null;let s=k(n.text,i);if(s==i)return null;let r=Ce(n.dom,i,s).getClientRects();for(let t=0;tMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,l=this.view.textDirection==ki.LTR;for(let t=0,a=0;an)break;if(t>=i){let i=h.dom.getBoundingClientRect();if(e.push(i.height),r){let e=h.dom.lastChild,n=e?ue(e):[];if(n.length){let e=n[n.length-1],r=l?e.right-i.left:i.right-e.left;r>o&&(o=r,this.minWidth=s,this.minWidthFrom=t,this.minWidthTo=c)}}}t=c+h.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return"rtl"==getComputedStyle(this.children[e].dom).direction?ki.RTL:ki.LTR}measureTextSize(){for(let t of this.children)if(t instanceof gi){let e=t.measureTextSize();if(e)return e}let t,e,i,n=document.createElement("div");return n.className="cm-line",n.style.width="99999px",n.style.position="absolute",n.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(n);let s=ue(n.firstChild)[0];t=n.getBoundingClientRect().height,e=s?s.width/27:7,i=s?s.height:t,n.remove()}),{lineHeight:t,charWidth:e,textHeight:i}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new Be(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let s=n==e.viewports.length?null:e.viewports[n],r=s?s.from-1:this.length;if(r>i){let n=(e.lineBlockAt(r).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(ci.replace({widget:new wi(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,r))}if(!s)break;i=s.to+1}return ci.set(t)}updateDeco(){let t=1,e=this.view.state.facet(un).map(e=>(this.dynamicDecorationMap[t++]="function"==typeof e)?e(this.view):e),i=!1,n=this.view.state.facet(fn).map((t,e)=>{let n="function"==typeof t;return n&&(i=!0),n?t(this.view):t});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(Bt.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];ti.anchor?-1:1);if(!n)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,e.left),top:Math.min(n.top,e.top),right:Math.max(n.right,e.right),bottom:Math.max(n.bottom,e.bottom)});let s=vn(this.view),r={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;!function(t,e,i,n,s,r,o,l){let a=t.ownerDocument,h=a.defaultView||window;for(let c=t,u=!1;c&&!u;)if(1==c.nodeType){let t,f=c==a.body,d=1,p=1;if(f)t=we(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(u=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let e=c.getBoundingClientRect();({scaleX:d,scaleY:p}=be(c,e)),t={left:e.left,right:e.left+c.clientWidth*d,top:e.top,bottom:e.top+c.clientHeight*p}}let m=0,g=0;if("nearest"==s)e.top0&&e.bottom>t.bottom+g&&(g=e.bottom-t.bottom+o)):e.bottom>t.bottom&&(g=e.bottom-t.bottom+o,i<0&&e.top-g0&&e.right>t.right+m&&(m=e.right-t.right+r)):e.right>t.right&&(m=e.right-t.right+r,i<0&&e.leftt.bottom||e.leftt.right)&&(e={left:Math.max(e.left,t.left),right:Math.min(e.right,t.right),top:Math.max(e.top,t.top),bottom:Math.min(e.bottom,t.bottom)}),c=c.assignedSlot||c.parentNode}else{if(11!=c.nodeType)break;c=c.host}}(this.view.scrollDOM,r,i.headt?e.left-t:Math.max(0,t-e.right)}function An(t,e){return e.top>t?e.top-t:Math.max(0,t-e.bottom)}function Mn(t,e){return t.tope.top+1}function Tn(t,e){return et.bottom?{top:t.top,left:t.left,right:t.right,bottom:e}:t}function On(t,e,i){let n,s,r,o,l,a,h,c,u=!1;for(let f=t.firstChild;f;f=f.nextSibling){let t=ue(f);for(let d=0;dg||o==g&&r>m)&&(n=f,s=p,r=m,o=g,u=!m||(e0:dp.bottom&&(!h||h.bottomp.top)&&(a=f,c=p):h&&Mn(h,p)?h=Dn(h,p.bottom):c&&Mn(c,p)&&(c=Tn(c,p.top))}}if(h&&h.bottom>=i?(n=l,s=h):c&&c.top<=i&&(n=a,s=c),!n)return{node:t,offset:0};let f=Math.max(s.left,Math.min(s.right,e));return 3==n.nodeType?Rn(n,f,i):u&&"false"!=n.contentEditable?On(n,f,i):{node:t,offset:Array.prototype.indexOf.call(t.childNodes,n)+(e>=(s.left+s.right)/2?1:0)}}function Rn(t,e,i){let n=t.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;li?h.top-i:i-h.bottom)-1;if(h.left-1<=e&&h.right+1>=e&&c=(h.left+h.right)/2,n=i;if(Ge.chrome||Ge.gecko){Ce(t,l).getBoundingClientRect().left==h.right&&(n=!i)}if(c<=0)return{node:t,offset:l+(n?1:0)};s=l+(n?1:0),r=c}}}return{node:t,offset:s>-1?s:o>0?t.nodeValue.length:0}}function En(t,e,i,n=-1){var s,r;let o,l=t.contentDOM.getBoundingClientRect(),a=l.top+t.viewState.paddingTop,{docHeight:h}=t.viewState,{x:c,y:u}=e,f=u-a;if(f<0)return 0;if(f>h)return t.state.doc.length;for(let e=t.viewState.heightOracle.textHeight/2,s=!1;o=t.elementAtHeight(f),o.type!=hi.Text;)for(;f=n>0?o.bottom+e:o.top-e,!(f>=0&&f<=h);){if(s)return i?null:0;s=!0,n=-n}u=a+f;let d=o.from;if(dt.viewport.to)return t.viewport.to==t.state.doc.length?t.state.doc.length:i?null:Pn(t,l,o,c,u);let p=t.dom.ownerDocument,m=t.root.elementFromPoint?t.root:p,g=m.elementFromPoint(c,u);g&&!t.contentDOM.contains(g)&&(g=null),g||(c=Math.max(l.left+1,Math.min(l.right-1,c)),g=m.elementFromPoint(c,u),g&&!t.contentDOM.contains(g)&&(g=null));let v,w=-1;if(g&&0!=(null===(s=t.docView.nearest(g))||void 0===s?void 0:s.isEditable)){if(p.caretPositionFromPoint){let t=p.caretPositionFromPoint(c,u);t&&({offsetNode:v,offset:w}=t)}else if(p.caretRangeFromPoint){let e=p.caretRangeFromPoint(c,u);e&&(({startContainer:v,startOffset:w}=e),(!t.contentDOM.contains(v)||Ge.safari&&function(t,e,i){let n,s=t;if(3!=t.nodeType||e!=(n=t.nodeValue.length))return!1;for(;;){let t=s.nextSibling;if(t){if("BR"==t.nodeName)break;return!1}{let t=s.parentNode;if(!t||"DIV"==t.nodeName)break;s=t}}return Ce(t,n-1,n).getBoundingClientRect().right>i}(v,w,c)||Ge.chrome&&function(t,e,i){if(0!=e)return!1;for(let e=t;;){let t=e.parentNode;if(!t||1!=t.nodeType||t.firstChild!=e)return!1;if(t.classList.contains("cm-line"))break;e=t}let n=1==t.nodeType?t.getBoundingClientRect():Ce(t,0,Math.max(t.nodeValue.length,1)).getBoundingClientRect();return i-n.left>5}(v,w,c))&&(v=void 0))}v&&(w=Math.min(ge(v),w))}if(!v||!t.docView.dom.contains(v)){let e=gi.find(t.docView,d);if(!e)return f>o.top+o.height/2?o.to:o.from;({node:v,offset:w}=On(e.dom,c,u))}let b=t.docView.nearest(v);if(!b)return null;if(b.isWidget&&1==(null===(r=b.dom)||void 0===r?void 0:r.nodeType)){let t=b.dom.getBoundingClientRect();return e.y1.5*t.defaultLineHeight){let e=t.viewState.heightOracle.textHeight;r+=Math.floor((s-i.top-.5*(t.defaultLineHeight-e))/e)*t.viewState.heightOracle.lineLength}let o=t.state.sliceDoc(i.from,i.to);return i.from+Ut(o,r,t.state.tabSize)}function Ln(t,e,i){let n=t.lineBlockAt(e);if(Array.isArray(n.type)){let t;for(let s of n.type){if(s.from>e)break;if(!(s.toe)return s;t&&(s.type!=hi.Text||t.type==s.type&&!(i<0?s.frome))||(t=s)}}return t||n}return n}function Bn(t,e,i,n){let s=t.state.doc.lineAt(e.head),r=t.bidiSpans(s),o=t.textDirectionAt(s.from);for(let l=e,a=null;;){let e=Fi(s,r,o,l,i),h=qi;if(!e){if(s.number==(i?t.state.doc.lines:1))return l;h="\n",s=t.state.doc.line(s.number+(i?1:-1)),r=t.bidiSpans(s),e=t.visualLineSide(s,!i)}if(a){if(!a(h))return l}else{if(!n)return e;a=n(h)}l=e}}function In(t,e,i){for(;;){let n=0;for(let s of t)s.between(e-1,e+1,(t,s,r)=>{if(e>t&&ee(t)),i.from,e.head>i.from?-1:1);return n==i.from?i:z.cursor(n,nt)&&this.lineBreak(),n=s}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let s,r=-1,o=1;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(s=n.exec(e))&&(r=s.index,o=s[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=Pe.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+(Fn(t,i.node,i.offset)?e:0))}}function Fn(t,e,i){for(;;){if(!e||i-1;let{impreciseHead:s,impreciseAnchor:r}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let e=s||r?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}=t.observer.selectionRange;i&&(e.push(new Hn(i,n)),s==i&&r==n||e.push(new Hn(s,r)));return e}(t),i=new qn(e,t.state);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(t,e){if(0==t.length)return null;let i=t[0].pos,n=2==t.length?t[1].pos:i;return i>-1&&n>-1?z.single(i+e,n+e):null}(e,this.bounds.from)}else{let e=t.observer.selectionRange,i=s&&s.node==e.focusNode&&s.offset==e.focusOffset||!he(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),n=r&&r.node==e.anchorNode&&r.offset==e.anchorOffset||!he(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset),o=t.viewport;if((Ge.ios||Ge.chrome)&&t.state.selection.main.empty&&i!=n&&(o.from>0||o.toDate.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:n,to:o}=e.bounds,l=s.from,a=null;(8===r||Ge.android&&e.text.length0&&l>0&&t.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if("end"==n){i-=o+Math.max(0,r-Math.min(o,l))-r}if(o=o?r-i:0,l=r+(l-o),o=r}else if(l=l?r-i:0,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}(t.state.doc.sliceString(n,o,zn),e.text,l-n,a);h&&(Ge.chrome&&13==r&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==zn+zn&&h.toB--,i={from:n+h.from,to:n+h.toA,insert:f.of(e.text.slice(h.from,h.toB).split(zn))})}else n&&(!t.hasFocus&&t.state.facet(sn)||n.main.eq(s))&&(n=null);if(!i&&!n)return!1;if(!i&&e.typeOver&&!s.empty&&n&&n.main.empty?i={from:s.from,to:s.to,insert:t.state.doc.slice(s.from,s.to)}:(Ge.mac||Ge.android)&&i&&i.from==i.to&&i.from==s.head-1&&/^\. ?$/.test(i.insert.toString())&&"off"==t.contentDOM.getAttribute("autocorrect")?(n&&2==i.insert.length&&(n=z.single(n.main.anchor-1,n.main.head-1)),i={from:i.from,to:i.to,insert:f.of([i.insert.toString().replace("."," ")])}):i&&i.from>=s.from&&i.to<=s.to&&(i.from!=s.from||i.to!=s.to)&&s.to-s.from-(i.to-i.from)<=4?i={from:s.from,to:s.to,insert:t.state.doc.slice(s.from,i.from).append(i.insert).append(t.state.doc.slice(i.to,s.to))}:Ge.chrome&&i&&i.from==i.to&&i.from==s.head&&"\n "==i.insert.toString()&&t.lineWrapping&&(n&&(n=z.single(n.main.anchor-1,n.main.head-1)),i={from:s.from,to:s.to,insert:f.of([" "])}),i)return $n(t,i,n,r);if(n&&!n.main.eq(s)){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}function $n(t,e,i,n=-1){if(Ge.ios&&t.inputState.flushIOSKey(e))return!0;let s=t.state.selection.main;if(Ge.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&" "==t.state.sliceDoc(e.from,s.from))&&1==e.insert.length&&2==e.insert.lines&&Ae(t.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&0==e.insert.length||8==n&&e.insert.lengths.head)&&Ae(t.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&0==e.insert.length&&Ae(t.contentDOM,"Delete",46)))return!0;let r,o=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let l=()=>r||(r=function(t,e,i){let n,s=t.state,r=s.selection.main;if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=r.frome.to?s.sliceDoc(e.to,r.to):"";n=s.replaceSelection(t.state.toText(i+e.insert.sliceString(0,void 0,t.state.lineBreak)+o))}else{let o=s.changes(e),l=i&&i.main.to<=o.newLength?i.main:void 0;if(s.selection.ranges.length>1&&t.inputState.composing>=0&&e.to<=r.to&&e.to>=r.to-10){let a,h=t.state.sliceDoc(e.from,e.to),c=i&&kn(t,i.main.head);if(c){let t=e.insert.length-(e.to-e.from);a={from:c.from,to:c.to-t}}else a=t.state.doc.lineAt(r.head);let u=r.to-e.to,f=r.to-r.from;n=s.changeByRange(i=>{if(i.from==r.from&&i.to==r.to)return{changes:o,range:l||i.map(o)};let n=i.to-u,c=n-h.length;if(i.to-i.from!=f||t.state.sliceDoc(c,n)!=h||i.to>=a.from&&i.from<=a.to)return{range:i};let d=s.changes({from:c,to:n,insert:e.insert}),p=i.to-r.to;return{changes:d,range:l?z.range(Math.max(0,l.anchor+p),Math.max(0,l.head+p)):i.map(d)}})}else n={changes:o,selection:l&&s.selection.replaceRange(l)}}let o="input.type";(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,o+=".compose",t.inputState.compositionFirstChange&&(o+=".start",t.inputState.compositionFirstChange=!1));return s.update(n,{userEvent:o,scrollIntoView:!0})}(t,e,i));return t.state.facet(Ki).some(i=>i(t,e.from,e.to,o,l))||t.dispatch(l()),!0}class _n{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,Ge.safari&&t.contentDOM.addEventListener("input",()=>null),Ge.gecko&&function(t){vs.has(t)||(vs.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}(t.contentDOM.ownerDocument)}handleEvent(t){(function(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,n=e.target;n!=t.contentDOM;n=n.parentNode)if(!n||11==n.nodeType||(i=Pe.get(n))&&i.ignoreEvent(e))return!1;return!0})(this.view,t)&&!this.ignoreDuringComposition(t)&&("keydown"==t.type&&this.keydown(t)||(0!=this.view.updateState?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t)))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Kn(t),i=this.handlers,n=this.view.contentDOM;for(let t in e)if("scroll"!=t){let s=!e[t].handlers.length,r=i[t];r&&s!=!r.handlers.length&&(n.removeEventListener(t,this.handleEvent),r=null),r||n.addEventListener(t,this.handleEvent,{passive:s})}for(let t in i)"scroll"==t||e[t]||n.removeEventListener(t,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=t.keyCode&&Yn.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),Ge.android&&Ge.chrome&&!t.synthetic&&(13==t.keyCode||8==t.keyCode))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return!Ge.ios||t.synthetic||t.altKey||t.metaKey||!((e=Un.find(e=>e.keyCode==t.keyCode))&&!t.ctrlKey||Gn.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(229!=t.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0)}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(!("Enter"==e.key&&t&&t.from0||!!(Ge.safari&&!Ge.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function jn(t,e){return(i,n)=>{try{return e.call(t,n,i)}catch(t){nn(i.state,t)}}}function Kn(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let e of t){let t=e.spec,n=t&&t.plugin.domEventHandlers,s=t&&t.plugin.domEventObservers;if(n)for(let t in n){let s=n[t];s&&i(t).handlers.push(jn(e.value,s))}if(s)for(let t in s){let n=s[t];n&&i(t).observers.push(jn(e.value,n))}}for(let t in Zn)i(t).handlers.push(Zn[t]);for(let t in Qn)i(t).observers.push(Qn[t]);return e}const Un=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Gn="dthko",Yn=[16,17,18,20,91,92,224,225];function Xn(t){return.7*Math.max(0,t)+8}class Jn{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=function(t){let e,i,n=t.ownerDocument;for(let s=t.parentNode;s&&!(s==n.body||e&&i);)if(1==s.nodeType)!i&&s.scrollHeight>s.clientHeight&&(i=s),!e&&s.scrollWidth>s.clientWidth&&(e=s),s=s.assignedSlot||s.parentNode;else{if(11!=s.nodeType)break;s=s.host}return{x:e,y:i}}(t.contentDOM),this.atoms=t.state.facet(dn).map(e=>e(t));let s=t.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(Dt.allowMultipleSelections)&&function(t,e){let i=t.state.facet(Vi);return i.length?i[0](e):Ge.mac?e.metaKey:e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let n=ae(t.root);if(!n||0==n.rangeCount)return!0;let s=n.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!=us(e))&&null}start(t){!1===this.dragging&&this.select(t)}move(t){if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(e=this.startEvent,i=t,Math.max(Math.abs(e.clientX-i.clientX),Math.abs(e.clientY-i.clientY))<10))return;var e,i;this.select(this.lastEvent=t);let n=0,s=0,r=0,o=0,l=this.view.win.innerWidth,a=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:o,bottom:a}=this.scrollParents.y.getBoundingClientRect());let h=vn(this.view);t.clientX-h.left<=r+6?n=-Xn(r-t.clientX):t.clientX+h.right>=l-6&&(n=Xn(t.clientX-l)),t.clientY-h.top<=o+6?s=-Xn(o-t.clientY):t.clientY+h.bottom>=a-6&&(s=Xn(t.clientY-a)),this.setScrollSpeed(n,s)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),!1===this.dragging&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;it.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}const Zn=Object.create(null),Qn=Object.create(null),ts=Ge.ie&&Ge.ie_version<15||Ge.ios&&Ge.webkit_version<604;function es(t,e,i){for(let n of t.facet(e))i=n(i,t);return i}function is(t,e){e=es(t.state,Gi,e);let i,{state:n}=t,s=1,r=n.toText(e),o=r.lines==n.selection.ranges.length;if(null!=ds&&n.selection.ranges.every(t=>t.empty)&&ds==r.toString()){let t=-1;i=n.changeByRange(i=>{let l=n.doc.lineAt(i.from);if(l.from==t)return{range:i};t=l.from;let a=n.toText((o?r.line(s++).text:e)+n.lineBreak);return{changes:{from:l.from,insert:a},range:z.cursor(i.from+a.length)}})}else i=o?n.changeByRange(t=>{let e=r.line(s++);return{changes:{from:t.from,to:t.to,insert:e.text},range:z.cursor(t.from+e.length)}}):n.replaceSelection(r);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function ns(t,e,i,n){if(1==n)return z.cursor(e,i);if(2==n)return function(t,e,i=1){let n=t.charCategorizer(e),s=t.doc.lineAt(e),r=e-s.from;if(0==s.length)return z.cursor(e);0==r?i=1:r==s.length&&(i=-1);let o=r,l=r;i<0?o=k(s.text,r,!1):l=k(s.text,r);let a=n(s.text.slice(o,l));for(;o>0;){let t=k(s.text,o,!1);if(n(s.text.slice(t,o))!=a)break;o=t}for(;l{t.inputState.lastScrollTop=t.scrollDOM.scrollTop,t.inputState.lastScrollLeft=t.scrollDOM.scrollLeft},Zn.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),27==e.keyCode&&0!=t.inputState.tabFocusMode&&(t.inputState.tabFocusMode=Date.now()+2e3),!1),Qn.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},Qn.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},Zn.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let n of t.state.facet($i))if(i=n(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=os(t,e),n=us(e),s=t.state.selection;return{update(t){t.docChanged&&(i.pos=t.changes.mapPos(i.pos),s=s.map(t.changes))},get(e,r,o){let l,a=os(t,e),h=ns(t,a.pos,a.bias,n);if(i.pos!=a.pos&&!r){let e=ns(t,i.pos,i.bias,n),s=Math.min(e.from,h.from),r=Math.max(e.to,h.to);h=s1&&(l=function(t,e){for(let i=0;i=e)return z.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}(s,a.pos))?l:o?s.addRange(h):z.create([h])}}}(t,e)),i){let n=!t.hasFocus;t.inputState.startMouseSelection(new Jn(t,e,i,n)),n&&t.observer.ignore(()=>{Se(t.contentDOM);let e=t.root.activeElement;e&&!e.contains(t.contentDOM)&&e.blur()});let s=t.inputState.mouseSelection;if(s)return s.start(e),!1===s.dragging}return!1};let ss=(t,e,i)=>e>=i.top&&e<=i.bottom&&t>=i.left&&t<=i.right;function rs(t,e,i,n){let s=gi.find(t.docView,e);if(!s)return 1;let r=e-s.posAtStart;if(0==r)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&ss(i,n,o))return-1;let l=s.coordsAt(r,1);return l&&ss(i,n,l)?1:o&&o.bottom>=n?-1:1}function os(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:i,bias:rs(t,i,e.clientX,e.clientY)}}const ls=Ge.ie&&Ge.ie_version<=11;let as=null,hs=0,cs=0;function us(t){if(!ls)return t.detail;let e=as,i=cs;return as=t,cs=Date.now(),hs=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(hs+1)%3:1}function fs(t,e,i,n){if(!(i=es(t.state,Gi,i)))return;let s=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=t.inputState,o=n&&r&&function(t,e){let i=t.state.facet(Wi);return i.length?i[0](e):Ge.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:r.from,to:r.to}:null,l={from:s,insert:i},a=t.state.changes(o?[o,l]:l);t.focus(),t.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),t.inputState.draggedContent=null}Zn.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let n=t.docView.nearest(e.target);if(n&&n.isWidget){let t=n.posAtStart,e=t+n.length;(t>=i.to||e<=i.from)&&(i=z.range(t,e))}}let{inputState:n}=t;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",es(t.state,Yi,t.state.sliceDoc(i.from,i.to))),e.dataTransfer.effectAllowed="copyMove"),!1},Zn.dragend=t=>(t.inputState.draggedContent=null,!1),Zn.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let n=Array(i.length),s=0,r=()=>{++s==i.length&&fs(t,e,n.filter(t=>null!=t).join(t.state.lineBreak),!1)};for(let t=0;t{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(n[t]=e.result),r()},e.readAsText(i[t])}return!0}{let i=e.dataTransfer.getData("Text");if(i)return fs(t,e,i,!0),!0}return!1},Zn.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=ts?null:e.clipboardData;return i?(is(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{t.focus(),i.remove(),is(t,i.value)},50)}(t),!1)};let ds=null;Zn.copy=Zn.cut=(t,e)=>{let{text:i,ranges:n,linewise:s}=function(t){let e=[],i=[],n=!1;for(let n of t.selection.ranges)n.empty||(e.push(t.sliceDoc(n.from,n.to)),i.push(n));if(!e.length){let s=-1;for(let{from:n}of t.selection.ranges){let r=t.doc.lineAt(n);r.number>s&&(e.push(r.text),i.push({from:r.from,to:Math.min(t.doc.length,r.to+1)})),s=r.number}n=!0}return{text:es(t,Yi,e.join(t.lineBreak)),ranges:i,linewise:n}}(t.state);if(!i&&!s)return!1;ds=s?i:null,"cut"!=e.type||t.state.readOnly||t.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let r=ts?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",i),!0):(function(t,e){let i=t.dom.parentNode;if(!i)return;let n=i.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),t.focus()},50)}(t,i),!1)};const ps=dt.define();function ms(t,e){let i=[];for(let n of t.facet(Ui)){let s=n(t,e);s&&i.push(s)}return i.length?t.update({effects:i,annotations:ps.of(!0)}):null}function gs(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=ms(t.state,e);i?t.dispatch(i):t.update([])}},10)}Qn.focus=t=>{t.inputState.lastFocusTime=Date.now(),t.scrollDOM.scrollTop||!t.inputState.lastScrollTop&&!t.inputState.lastScrollLeft||(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),gs(t)},Qn.blur=t=>{t.observer.clearSelectionRange(),gs(t)},Qn.compositionstart=Qn.compositionupdate=t=>{t.observer.editContext||(null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0))},Qn.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,Ge.chrome&&Ge.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))},Qn.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},Zn.beforeinput=(t,e)=>{var i,n;if("insertReplacementText"==e.inputType&&t.observer.editContext){let n=null===(i=e.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),s=e.getTargetRanges();if(n&&s.length){let e=s[0],i=t.posAtDOM(e.startContainer,e.startOffset),r=t.posAtDOM(e.endContainer,e.endOffset);return $n(t,{from:i,to:r,insert:t.state.toText(n)},null),!0}}let s;if(Ge.chrome&&Ge.android&&(s=Un.find(t=>t.inputType==e.inputType))&&(t.observer.delayAndroidKey(s.key,s.keyCode),"Backspace"==s.key||"Delete"==s.key)){let e=(null===(n=window.visualViewport)||void 0===n?void 0:n.height)||0;setTimeout(()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return Ge.ios&&"deleteContentForward"==e.inputType&&t.observer.flushSoon(),Ge.safari&&"insertText"==e.inputType&&t.inputState.composing>=0&&setTimeout(()=>Qn.compositionend(t,e),20),!1};const vs=new Set;const ws=["pre-wrap","normal","pre-line","break-spaces"];let bs=!1;function ys(){bs=!1}class xs{constructor(t){this.lineWrapping=t,this.doc=f.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return ws.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i-1,l=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=s,l){this.heightSamples={};for(let t=0;t0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>As&&(bs=!0),this.height=t)}replace(t,e,i){return Ms.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let s=this,r=i.doc;for(let o=n.length-1;o>=0;o--){let{fromA:l,toA:a,fromB:h,toB:c}=n[o],u=s.lineAt(l,Cs.ByPosNoHeight,i.setDoc(e),0,0),f=u.to>=a?u:s.lineAt(a,Cs.ByPosNoHeight,i,0,0);for(c+=f.to-a,a=f.to;o>0&&u.from<=n[o-1].toA;)l=n[o-1].fromA,h=n[o-1].fromB,o--,l2*s){let s=t[e-1];s.break?t.splice(--e,1,s.left,null,s.right):t.splice(--e,1,s.left,s.right),i+=1+s.break,n-=s.size}else{if(!(s>2*n))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,s-=e.size}}else if(n=s&&r(this.blockAt(0,i,n,s))}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setHeight(n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Os extends Ds{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,n){return new Ss(n,this.length,i,this.height,this.breaks)}replace(t,e,i){let n=i[0];return 1==i.length&&(n instanceof Os||n instanceof Rs&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof Rs?n=new Os(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):Ms.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setHeight(n.heights[n.index++]):(i||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Rs extends Ms{constructor(t){super(t,0)}heightMetrics(t,e){let i,n=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-n+1,o=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*r);i=e/r,this.length>r+1&&(o=(this.height-e)/(this.length-r-1))}else i=this.height/r;return{firstLine:n,lastLine:s,perLine:i,perChar:o}}blockAt(t,e,i,n){let{firstLine:s,lastLine:r,perLine:o,perChar:l}=this.heightMetrics(e,n);if(e.lineWrapping){let s=n+(t0){let t=i[i.length-1];t instanceof Rs?i[i.length-1]=new Rs(t.length+n):i.push(null,new Rs(n-1))}if(t>0){let e=i[0];e instanceof Rs?i[0]=new Rs(t+e.length):i.unshift(new Rs(t-1),null)}return Ms.of(i)}decomposeLeft(t,e){e.push(new Rs(t-1),null)}decomposeRight(t,e){e.push(null,new Rs(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let s=e+this.length;if(n&&n.from<=e+this.length&&n.more){let i=[],r=Math.max(e,n.from),o=-1;for(n.from>e&&i.push(new Rs(n.from-e-1).updateHeight(t,e));r<=s&&n.more;){let e=t.doc.lineAt(r).length;i.length&&i.push(null);let s=n.heights[n.index++];-1==o?o=s:Math.abs(s-o)>=As&&(o=-2);let l=new Os(e,s);l.outdated=!1,i.push(l),r+=e+1}r<=s&&i.push(null,new Rs(s-r).updateHeight(t,r));let l=Ms.of(i);return(o<0||Math.abs(l.height-this.height)>=As||Math.abs(o-this.heightMetrics(t,e).perLine)>=As)&&(bs=!0),Ts(this,l)}return(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class Es extends Ms{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,n){let s=i+this.left.height;return to))return a;let h=e==Cs.ByPosNoHeight?Cs.ByPosNoHeight:Cs.ByPos;return l?a.join(this.right.lineAt(o,h,i,r,o)):this.left.lineAt(o,h,i,n,s).join(a)}forEachLine(t,e,i,n,s,r){let o=n+this.left.height,l=s+this.left.length+this.break;if(this.break)t=l&&this.right.forEachLine(t,e,i,o,l,r);else{let a=this.lineAt(l,Cs.ByPos,i,n,s);t=t&&a.from<=e&&r(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,o,l,r)}}replace(t,e,i){let n=this.left.length+this.break;if(ethis.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let s=[];t>0&&this.decomposeLeft(t,s);let r=s.length;for(let t of i)s.push(t);if(t>0&&Ps(s,r-1),e=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t2*e.size||e.size>2*t.size?Ms.of(this.break?[t,null,e]:[t,e]):(this.left=Ts(this.left,t),this.right=Ts(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:s,right:r}=this,o=e+s.length+this.break,l=null;return n&&n.from<=e+s.length&&n.more?l=s=s.updateHeight(t,e,i,n):s.updateHeight(t,e,i),n&&n.from<=o+r.length&&n.more?l=r=r.updateHeight(t,o,i,n):r.updateHeight(t,o,i),l?this.balanced(s,r):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Ps(t,e){let i,n;null==t[e]&&(i=t[e-1])instanceof Rs&&(n=t[e+1])instanceof Rs&&t.splice(e-1,3,new Rs(i.length+1+n.length))}class Ls{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 Os?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new Os(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(n,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 Os(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new Rs(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 Os)return t;let e=new Os(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof Os||this.isCovered?(this.writtenToi.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=n.overflow){let n=i.getBoundingClientRect();r=Math.max(r,n.left),o=Math.min(o,n.right),l=Math.max(l,n.top),a=Math.min(e==t.parentNode?s.innerHeight:a,n.bottom)}e="absolute"==n.position||"fixed"==n.position?i.offsetParent:i.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:r-i.left,right:Math.max(r,o)-i.left,top:l-(i.top+e),bottom:Math.max(l,a)-(i.top+e)}}function Ns(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class zs{constructor(t,e,i,n){this.from=t,this.to=e,this.size=i,this.displaySize=n}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i"function"!=typeof t&&"cm-lineWrapping"==t.class);this.heightOracle=new xs(e),this.stateDeco=t.facet(un).filter(t=>"function"!=typeof t),this.heightMap=Ms.empty().applyChanges(this.stateDeco,f.empty,this.heightOracle.setDoc(t.doc),[new bn(0,0,0,t.doc.length)]);for(let t=0;t<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());t++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ci.set(this.lineGaps.map(t=>t.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:t,to:e})=>n>=t&&n<=e)){let{from:e,to:i}=this.lineBlockAt(n);t.push(new Hs(e,i))}}return this.viewports=t.sort((t,e)=>t.from-e.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?$s:new _s(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(js(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(un).filter(t=>"function"!=typeof t);let n=t.changedRanges,s=bn.extendWithRanges(n,function(t,e,i){let n=new Bs;return Bt.compare(t,e,i,n,0),n.changes}(i,this.stateDeco,t?t.changes:O.empty(this.state.doc.length))),r=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);ys(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=r||bs)&&(t.flags|=2),o?(this.scrollAnchorPos=t.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=r);let l=s.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.headl.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,e));let a=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,t.flags|=this.updateForViewport(),(a||!t.changes.empty||2&t.flags)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(Ji)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,s=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?ki.RTL:ki.LTR;let r=this.heightOracle.mustRefreshForWrapping(s),o=e.getBoundingClientRect(),l=r||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let a=0,h=0;if(o.width&&o.height){let{scaleX:t,scaleY:i}=be(e,o);(t>.005&&Math.abs(this.scaleX-t)>.005||i>.005&&Math.abs(this.scaleY-i)>.005)&&(this.scaleX=t,this.scaleY=i,a|=16,r=l=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;this.paddingTop==c&&this.paddingBottom==u||(this.paddingTop=c,this.paddingBottom=u,a|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,a|=16);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Te(t.scrollDOM);let p=(this.printing?Ns:Is)(e,this.paddingTop),m=p.top-this.pixelViewport.top,g=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let v=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(v!=this.inView&&(this.inView=v,v&&(l=!0)),!this.inView&&!this.scrollTarget&&!function(t){let e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView||window;return e.left0&&e.top0}(t.dom))return 0;let w=o.width;if(this.contentDOMWidth==w&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=o.width,this.editorHeight=t.scrollDOM.clientHeight,a|=16),l){let e=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(e)&&(r=!0),r||n.lineWrapping&&Math.abs(w-this.contentDOMWidth)>n.charWidth){let{lineHeight:i,charWidth:o,textHeight:l}=t.docView.measureTextSize();r=i>0&&n.refresh(s,i,o,l,Math.max(5,w/o),e),r&&(t.docView.minWidth=0,a|=16)}m>0&&g>0?h=Math.max(m,g):m<0&&g<0&&(h=Math.min(m,g)),ys();for(let i of this.viewports){let s=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=(r?Ms.empty().applyChanges(this.stateDeco,f.empty,this.heightOracle,[new bn(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,r,new ks(i.from,s))}bs&&(a|=2)}let b=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return b&&(2&a&&(a|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),a|=this.updateForViewport()),(2&a||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(r?[]:this.lineGaps,t)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,s=this.heightOracle,{visibleTop:r,visibleBottom:o}=this,l=new Hs(n.lineAt(r-1e3*i,Cs.ByHeight,s,0,0).from,n.lineAt(o+1e3*(1-i),Cs.ByHeight,s,0,0).to);if(e){let{head:t}=e.range;if(tl.to){let i,r=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),o=n.lineAt(t,Cs.ByPos,s,0,0);i="center"==e.y?(o.top+o.bottom)/2-r/2:"start"==e.y||"nearest"==e.y&&t=o+Math.max(10,Math.min(i,250)))&&n>r-2e3&&s>1,r=n<<1;if(this.defaultTextDirection!=ki.LTR&&!i)return[];let o=[],l=(n,r,a,h)=>{if(r-nn&&tt.from>=a.from&&t.to<=a.to&&Math.abs(t.from-n)t.frome));if(!f){if(rt.from<=r&&t.to>=r)){let t=e.moveToLineBoundary(z.cursor(r),!1,!0).head;t>n&&(r=t)}let t=this.gapSize(a,n,r,h);f=new zs(n,r,t,i||t<2e6?t:2e6)}o.push(f)},a=e=>{if(e.lengths&&(n.push({from:s,to:t}),r+=t-s),s=e}},20),s2e6)for(let i of t)i.from>=e.from&&i.frome.from&&l(e.from,o,e,s),at.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];Bt.spans(e,this.viewport.from,this.viewport.to,{span(t,e){i.push({from:t,to:e})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let e=0;e=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||js(this.heightMap.lineAt(t,Cs.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||js(this.heightMap.lineAt(this.scaler.fromDOM(t),Cs.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return js(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Hs{constructor(t,e){this.from=t,this.to=e}}function Vs({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let n=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:s}=e[t],r=s-i;if(n<=r)return i+n;n-=r}}function Ws(t,e){let i=0;for(let{from:n,to:s}of t.ranges){if(e<=s){i+=e-n;break}i+=s-n}return i/t.total}const $s={toDOM:t=>t,fromDOM:t=>t,scale:1,eq(t){return t==this}};class _s{constructor(t,e,i){let n=0,s=0,r=0;this.viewports=i.map(({from:i,to:s})=>{let r=e.lineAt(i,Cs.ByPos,t,0,0).top,o=e.lineAt(s,Cs.ByPos,t,0,0).bottom;return n+=o-r,{from:i,to:s,top:r,bottom:o,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);for(let t of this.viewports)t.domTop=r+(t.top-s)*this.scale,r=t.domBottom=t.domTop+(t.bottom-t.top),s=t.bottom}toDOM(t){for(let e=0,i=0,n=0;;e++){let s=ee.from==t.viewports[i].from&&e.to==t.viewports[i].to))}}function js(t,e){if(1==e.scale)return t;let i=e.toDOM(t.top),n=e.toDOM(t.bottom);return new Ss(t.from,t.length,i,n-i,Array.isArray(t._content)?t._content.map(t=>js(t,e)):t._content)}const Ks=H.define({combine:t=>t.join(" ")}),Us=H.define({combine:t=>t.indexOf(!0)>-1}),Gs=Jt.newName(),Ys=Jt.newName(),Xs=Jt.newName(),Js={"&light":"."+Ys,"&dark":"."+Xs};function Zs(t,e,i){return new Jt(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 Qs=Zs("."+Gs,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Js),tr={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},er=Ge.ie&&Ge.ie_version<=11;class ir{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new ye,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let t of e)this.queue.push(t);(Ge.ie&&Ge.ie_version<=11||Ge.ios&&t.composing)&&e.some(t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length)?this.flushSoon():this.flush()}),!window.EditContext||!Ge.android||!1===t.constructor.EDIT_CONTEXT||Ge.chrome&&Ge.chrome_version<126||(this.editContext=new rr(t),t.state.facet(sn)&&(t.contentDOM.editContext=this.editContext.editContext)),er&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver(()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){("change"!=t.type&&t.type||t.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(sn)?i.root.activeElement!=this.dom:!ce(this.dom,n))return;let s=n.anchorNode&&i.docView.nearest(n.anchorNode);s&&s.ignoreEvent(t)?e||(this.selectionChanged=!1):(Ge.ie&&Ge.ie_version<=11||Ge.android&&Ge.chrome)&&!i.state.selection.main.empty&&n.focusNode&&fe(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=ae(t.root);if(!e)return!1;let i=Ge.safari&&11==t.root.nodeType&&t.root.activeElement==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return sr(t,i)}let i=null;function n(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",n,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",n,!0),i?sr(t,i):null}(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=ce(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&Ae(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let s of t){let t=this.readMutation(s);t&&(t.typeOver&&(n=!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:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&ce(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new Vn(this.view,t,e,i);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=Wn(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),n}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.flags|=4),"childList"==t.type){let i=nr(e,t.previousSibling||t.target.previousSibling,-1),n=nr(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(sn)!=t.state.facet(sn)&&(t.view.contentDOM.editContext=t.state.facet(sn)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function nr(t,e,i){for(;e;){let n=Pe.get(e);if(n&&n.parent==t)return n;let s=e.parentNode;e=s!=t.dom?s:i>0?e.nextSibling:e.previousSibling}return null}function sr(t,e){let i=e.startContainer,n=e.startOffset,s=e.endContainer,r=e.endOffset,o=t.docView.domAtPos(t.state.selection.main.anchor);return fe(o.node,o.offset,s,r)&&([i,n,s,r]=[s,r,i,n]),{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}}class rr{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=e=>{let i=t.state.selection.main,{anchor:n,head:s}=i,r=this.toEditorPos(e.updateRangeStart),o=this.toEditorPos(e.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:e.updateRangeStart,editorBase:r,drifted:!1});let l={from:r,to:o,insert:f.of(e.text.split("\n"))};if(l.from==this.from&&nthis.to&&(l.to=n),l.from==l.to&&!l.insert.length){let n=z.single(this.toEditorPos(e.selectionStart),this.toEditorPos(e.selectionEnd));return void(n.main.eq(i)||t.dispatch({selection:n,userEvent:"select"}))}if((Ge.mac||Ge.android)&&l.from==s-1&&/^\. ?$/.test(e.text)&&"off"==t.contentDOM.getAttribute("autocorrect")&&(l={from:r,to:o,insert:f.of([e.text.replace("."," ")])}),this.pendingContextChange=l,!t.state.readOnly){let i=this.to-this.from+(l.to-l.from+l.insert.length);$n(t,l,z.single(this.toEditorPos(e.selectionStart,i),this.toEditorPos(e.selectionEnd,i)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state))},this.handlers.characterboundsupdate=i=>{let n=[],s=null;for(let e=this.toEditorPos(i.rangeStart),r=this.toEditorPos(i.rangeEnd);e{let i=[];for(let t of e.getTextFormats()){let e=t.underlineStyle,n=t.underlineThickness;if("None"!=e&&"None"!=n){let s=this.toEditorPos(t.rangeStart),r=this.toEditorPos(t.rangeEnd);if(s{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:e}=this.composing;this.composing=null,e&&this.reset(t.state)}};for(let t in this.handlers)e.addEventListener(t,this.handlers[t]);this.measureReq={read:t=>{this.editContext.updateControlBounds(t.contentDOM.getBoundingClientRect());let e=ae(t.root);e&&e.rangeCount&&this.editContext.updateSelectionBounds(e.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((s,r,o,l,a)=>{if(i)return;let h=a.length-(r-s);if(n&&r>=n.to){if(n.from==s&&n.to==r&&n.insert.eq(a))return n=this.pendingContextChange=null,e+=h,void(this.to+=h);n=null,this.revertPending(t.state)}if(s+=e,(r+=e)<=this.from)this.from+=h,this.to+=h;else if(sthis.to||this.to-this.from+a.length>3e4)return void(i=!0);this.editContext.updateText(this.toContextPos(s),this.toContextPos(r),a.toString()),this.to+=h}e+=h}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(t=>!t.isUserEvent("input.type")&&t.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):this.applyEdits(t)&&this.rangeIsValid(t.state)?(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state):(this.pendingContextChange=null,this.reset(t.state)),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);this.editContext.selectionStart==i&&this.editContext.selectionEnd==n||this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to3e4)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class or{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(t=>t.forEach(t=>i(t,this)))||(t=>this.update(t)),this.dispatch=this.dispatch.bind(this),this._root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new Fs(t.state||Dt.create(t)),t.scrollTo&&t.scrollTo.is(tn)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(on).map(t=>new an(t));for(let t of this.plugins)t.update(this);this.observer=new ir(this),this.inputState=new _n(this),this.inputState.ensureHandlers(this.plugins),this.docView=new xn(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),(null===(e=document.fonts)||void 0===e?void 0:e.ready)&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...t){let e=1==t.length&&t[0]instanceof vt?t:1==t.length&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,n=!1,s=this.state;for(let e of t){if(e.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=e.state}if(this.destroyed)return void(this.viewState.state=s);let r=this.hasFocus,o=0,l=null;t.some(t=>t.annotation(ps))?(this.inputState.notifiedFocused=r,o=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,l=ms(s,r),l||(o=1));let a=this.observer.delayedAndroidKey,h=null;if(a?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(h=null)):this.observer.clear(),s.facet(Dt.phrases)!=this.state.facet(Dt.phrases))return this.setState(s);e=yn.create(this,s,t),e.flags|=o;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(c&&(c=c.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection;c=new Qi(t.empty?t:z.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(tn)&&(c=t.value.clip(this.state))}this.viewState.update(e,c),this.bidiCache=hr.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(wn)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some(t=>t.isUserEvent("select.pointer")))}finally{this.updateState=0}if(e.startState.facet(Ks)!=e.state.facet(Ks)&&(this.viewState.mustMeasureContent=!0),(i||n||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!e.empty)for(let t of this.state.facet(ji))try{t(e)}catch(t){nn(this.state,t,"update listener")}(l||h)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),h&&!Wn(this,h)&&a.force&&Ae(this.contentDOM,a.key,a.keyCode)})}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new Fs(t),this.plugins=t.facet(on).map(t=>new an(t)),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy(),this.docView=new xn(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(on),i=t.state.facet(on);if(e!=i){let n=[];for(let s of i){let i=e.indexOf(s);if(i<0)n.push(new an(s));else{let e=this.plugins[i];e.mustUpdate=t,n.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,n=i.scrollTop*this.scaleY,{scrollAnchorPos:s,scrollAnchorHeight:r}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(r=-1),this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(r<0)if(Te(i))s=-1,r=this.viewState.heightMap.height;else{let t=this.viewState.scrollAnchorAt(n);s=t.from,r=t.top}this.updateState=1;let o=this.viewState.measure(this);if(!o&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let l=[];4&o||([this.measureRequests,l]=[l,this.measureRequests]);let a=l.map(t=>{try{return t.read(this)}catch(t){return nn(this.state,t),ar}}),h=yn.create(this,this.state,[]),c=!1;h.flags|=o,e?e.flags|=o:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),c=this.docView.update(h),c&&this.docViewUpdate());for(let t=0;t1||t<-1){n+=t,i.scrollTop=n/this.scaleY,r=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let t of this.state.facet(ji))t(e)}get themeClasses(){return Gs+" "+(this.state.facet(Us)?Xs:Ys)+" "+this.state.facet(Ks)}updateAttrs(){let t=cr(this,hn,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(sn)?"true":"false",class:"cm-content",style:`${Ge.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),cr(this,cn,e);let i=this.observer.ignore(()=>{let i=oi(this.contentDOM,this.contentAttrs,e),n=oi(this.dom,this.editorAttrs,t);return i||n});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)if(t.is(or.announce)){e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(wn);let t=this.state.facet(or.cspNonce);Jt.mount(this.root,this.styleModules.concat(Qs).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(null!=t.key)for(let e=0;ee.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return Nn(this,t,Bn(this,t,e,i))}moveByGroup(t,e){return Nn(this,t,Bn(this,t,e,e=>function(t,e,i){let n=t.state.charCategorizer(e),s=n(i);return t=>{let e=n(t);return s==Ct.Space&&(s=e),s==e}}(this,t.head,e)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),s=i[e?i.length-1:0];return z.cursor(s.side(e,n)+t.from,s.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return function(t,e,i,n){let s=Ln(t,e.head,e.assoc||-1),r=n&&s.type==hi.Text&&(t.lineWrapping||s.widgetLineBreaks)?t.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head):null;if(r){let e=t.dom.getBoundingClientRect(),n=t.textDirectionAt(s.from),o=t.posAtCoords({x:i==(n==ki.LTR)?e.right-1:e.left+1,y:(r.top+r.bottom)/2});if(null!=o)return z.cursor(o,i?-1:1)}return z.cursor(i?s.to:s.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return Nn(this,t,function(t,e,i,n){let s=e.head,r=i?1:-1;if(s==(i?t.state.doc.length:0))return z.cursor(s,e.assoc);let o,l=e.goalColumn,a=t.contentDOM.getBoundingClientRect(),h=t.coordsAtPos(s,e.assoc||-1),c=t.documentTop;if(h)null==l&&(l=h.left-a.left),o=r<0?h.top:h.bottom;else{let e=t.viewState.lineBlockAt(s);null==l&&(l=Math.min(a.right-a.left,t.defaultCharacterWidth*(s-e.from))),o=(r<0?e.top:e.bottom)+c}let u=a.left+l,f=null!=n?n:t.viewState.heightOracle.textHeight>>1;for(let e=0;;e+=10){let i=o+(f+e)*r,n=En(t,{x:u,y:i},!1,r);if(ia.bottom||(r<0?ns)){let e=t.docView.coordsForChar(n),s=!e||i0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Xi)||tthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>lr)return zi(t.length);let e,i=this.textDirectionAt(t.from);for(let n of this.bidiCache)if(n.from==t.from&&n.dir==i&&(n.fresh||Li(n.isolates,e=mn(this,t))))return n.order;e||(e=mn(this,t));let n=function(t,e,i){if(!t)return[new Pi(0,0,e==Ci?1:0)];if(e==Si&&!i.length&&!Ei.test(t))return zi(t.length);if(i.length)for(;t.length>Bi.length;)Bi[Bi.length]=256;let n=[],s=e==Si?0:1;return Ni(t,s,s,i,0,t.length,n),n}(t.text,i,e);return this.bidiCache.push(new hr(t.from,t.to,i,e,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||Ge.safari&&(null===(t=this.inputState)||void 0===t?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Se(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((9==t.nodeType?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return tn.of(new Qi("number"==typeof t?z.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return tn.of(new Qi(z.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){null==t?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:"boolean"==typeof t?this.inputState.tabFocusMode=t?0:-1:0!=this.inputState.tabFocusMode&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return ln.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return ln.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=Jt.newName(),n=[Ks.of(i),wn.of(Zs(`.${i}`,t))];return e&&e.dark&&n.push(Us.of(!0)),n}static baseTheme(t){return Q.lowest(wn.of(Zs("."+Gs,t,Js)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&Pe.get(i)||Pe.get(t);return(null===(e=null==n?void 0:n.rootView)||void 0===e?void 0:e.view)||null}}or.styleModule=wn,or.inputHandler=Ki,or.clipboardInputFilter=Gi,or.clipboardOutputFilter=Yi,or.scrollHandler=Zi,or.focusChangeEffect=Ui,or.perLineTextDirection=Xi,or.exceptionSink=_i,or.updateListener=ji,or.editable=sn,or.mouseSelectionStyle=$i,or.dragMovesSelection=Wi,or.clickAddsSelectionRange=Vi,or.decorations=un,or.outerDecorations=fn,or.atomicRanges=dn,or.bidiIsolatedRanges=pn,or.scrollMargins=gn,or.darkTheme=Us,or.cspNonce=H.define({combine:t=>t.length?t[0]:""}),or.contentAttributes=cn,or.editorAttributes=hn,or.lineWrapping=or.contentAttributes.of({class:"cm-lineWrapping"}),or.announce=gt.define();const lr=4096,ar={};class hr{constructor(t,e,i,n,s,r){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=s,this.order=r}static update(t,e){if(e.empty&&!t.some(t=>t.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:ki.LTR;for(let s=Math.max(0,t.length-10);s=0;s--){let e=n[s],r="function"==typeof e?e(t):e;r&&ni(r,i)}return i}const ur=Ge.mac?"mac":Ge.windows?"win":Ge.linux?"linux":"key";function fr(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 dr=Q.default(or.domEventHandlers({keydown:(t,e)=>yr(gr(e.state),t,e,"editor")})),pr=H.define({enables:dr}),mr=new WeakMap;function gr(t){let e=t.facet(pr),i=mr.get(e);return i||mr.set(e,i=function(t,e=ur){let i=Object.create(null),n=Object.create(null),s=(t,e)=>{let i=n[t];if(null==i)n[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")},r=(t,n,r,o,l)=>{var a,h;let c=i[t]||(i[t]=Object.create(null)),u=n.split(/ (?!$)/).map(t=>function(t,e){const i=t.split(/-(?!$)/);let n,s,r,o,l=i[i.length-1];"Space"==l&&(l=" ");for(let t=0;t{let n=vr={view:e,prefix:i,scope:t};return setTimeout(()=>{vr==n&&(vr=null)},wr),!0}]})}let f=u.join(" ");s(f,!1);let d=c[f]||(c[f]={preventDefault:!1,stopPropagation:!1,run:(null===(h=null===(a=c._any)||void 0===a?void 0:a.run)||void 0===h?void 0:h.slice())||[]});r&&d.run.push(r),o&&(d.preventDefault=!0),l&&(d.stopPropagation=!0)};for(let n of t){let t=n.scope?n.scope.split(" "):["editor"];if(n.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));t._any||(t._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:s}=n;for(let e in t)t[e].run.push(t=>s(t,br))}let s=n[e]||n.key;if(s)for(let e of t)r(e,s,n.run,n.preventDefault,n.stopPropagation),n.shift&&r(e,"Shift-"+s,n.shift,n.preventDefault,n.stopPropagation)}return i}(e.reduce((t,e)=>t.concat(e),[]))),i}let vr=null;const wr=4e3;let br=null;function yr(t,e,i,n){br=e;let s=function(t){var e=!(ie&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||ne&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?ee:te)[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),r=A(S(s,0))==s.length&&" "!=s,o="",l=!1,a=!1,h=!1;vr&&vr.view==i&&vr.scope==n&&(o=vr.prefix+" ",Yn.indexOf(e.keyCode)<0&&(a=!0,vr=null));let c,u,f=new Set,d=t=>{if(t){for(let e of t.run)if(!f.has(e)&&(f.add(e),e(i)))return t.stopPropagation&&(h=!0),!0;t.preventDefault&&(t.stopPropagation&&(h=!0),a=!0)}return!1},p=t[n];return p&&(d(p[o+fr(s,e,!r)])?l=!0:!r||!(e.altKey||e.metaKey||e.ctrlKey)||Ge.windows&&e.ctrlKey&&e.altKey||Ge.mac&&e.altKey&&!e.ctrlKey||!(c=te[e.keyCode])||c==s?r&&e.shiftKey&&d(p[o+fr(s,e,!0)])&&(l=!0):(d(p[o+fr(c,e,!0)])||e.shiftKey&&(u=ee[e.keyCode])!=s&&u!=c&&d(p[o+fr(u,e,!1)]))&&(l=!0),!l&&d(p._any)&&(l=!0)),a&&(l=!0),l&&h&&e.stopPropagation(),br=null,l}class xr{constructor(t,e,i,n,s){this.className=t,this.left=e,this.top=i,this.width=n,this.height=s}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className==this.className&&(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",null!=this.width&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let n=t.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let s=kr(t);return[new xr(e,n.left-s.left,n.top-s.top,null,n.bottom-n.top)]}return function(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let n=Math.max(i.from,t.viewport.from),s=Math.min(i.to,t.viewport.to),r=t.textDirection==ki.LTR,o=t.contentDOM,l=o.getBoundingClientRect(),a=kr(t),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),u=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=l.right-(c?parseInt(c.paddingRight):0),d=Ln(t,n,1),p=Ln(t,s,-1),m=d.type==hi.Text?d:null,g=p.type==hi.Text?p:null;m&&(t.lineWrapping||d.widgetLineBreaks)&&(m=Sr(t,n,1,m));g&&(t.lineWrapping||p.widgetLineBreaks)&&(g=Sr(t,s,-1,g));if(m&&g&&m.from==g.from&&m.to==g.to)return w(b(i.from,i.to,m));{let e=m?b(i.from,null,m):y(d,!1),n=g?b(null,i.to,g):y(p,!0),s=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2h&&n.from=r)break;l>s&&a(Math.max(t,s),null==e&&t<=h,Math.min(l,r),null==i&&l>=c,o.dir)}if(s=n.to+1,s>=r)break}return 0==l.length&&a(h,null==e,c,null==i,t.textDirection),{top:s,bottom:o,horizontal:l}}function y(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(t,e,i)}}function kr(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==ki.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function Sr(t,e,i,n){let s=t.coordsAtPos(e,2*i);if(!s)return n;let r=t.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=t.posAtCoords({x:r.left+1,y:o}),a=t.posAtCoords({x:r.right-1,y:o});return null==l||null==a?n:{from:Math.max(n.from,Math.min(l,a)),to:Math.min(n.to,Math.max(l,a))}}class Cr{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(Ar)!=t.state.facet(Ar)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){!1!==this.layer.updateOnDocViewUpdate&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(Ar);for(;e{return i=t,n=this.drawn[e],!(i.constructor==n.constructor&&i.eq(n));var i,n})){let e=this.dom.firstChild,i=0;for(let n of t)n.update&&e&&n.constructor&&this.drawn[i].constructor&&n.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(n.draw(),e);for(;e;){let t=e.nextSibling;e.remove(),e=t}this.drawn=t}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Ar=H.define();function Mr(t){return[ln.define(e=>new Cr(e,t)),Ar.of(t)]}const Tr=H.define({combine:t=>Ot(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function Dr(t){return t.startState.facet(Tr)!=t.state.facet(Tr)}const Or=Mr({above:!0,markers(t){let{state:e}=t,i=e.facet(Tr),n=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty||i.drawRangeCursor){let e=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=s.empty?s:z.cursor(s.head,s.head>s.anchor?-1:1);for(let s of xr.forRange(t,e,i))n.push(s)}}return n},update(t,e){t.transactions.some(t=>t.selection)&&(e.style.animationName="cm-blink"==e.style.animationName?"cm-blink2":"cm-blink");let i=Dr(t);return i&&Rr(t.state,e),t.docChanged||t.selectionSet||i},mount(t,e){Rr(e.state,t)},class:"cm-cursorLayer"});function Rr(t,e){e.style.animationDuration=t.facet(Tr).cursorBlinkRate+"ms"}const Er=Mr({above:!1,markers:t=>t.state.selection.ranges.map(e=>e.empty?[]:xr.forRange(t,"cm-selectionBackground",e)).reduce((t,e)=>t.concat(e)),update:(t,e)=>t.docChanged||t.selectionSet||t.viewportChanged||Dr(t),class:"cm-selectionLayer"}),Pr=Q.highest(or.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),Lr=gt.define({map:(t,e)=>null==t?null:e.mapPos(t)}),Br=U.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce((t,e)=>e.is(Lr)?e.value:t,t))}),Ir=ln.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(Br);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(Br)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(Br),i=null!=e&&t.coordsAtPos(e);if(!i)return null;let n=t.scrollDOM.getBoundingClientRect();return{left:i.left-n.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-n.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/i+"px",this.cursor.style.height=t.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(Br)!=t&&this.view.dispatch({effects:Lr.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Nr(t,e,i,n,s){e.lastIndex=0;for(let r,o=t.iterRange(i,n),l=i;!o.next().done;l+=o.value.length)if(!o.lineBreak)for(;r=e.exec(o.value);)s(l+r.index,r)}class zr{constructor(t){const{regexp:e,decoration:i,decorate:n,boundary:s,maxLength:r=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,n)this.addMatch=(t,e,i,s)=>n(s,i,i+t[0].length,t,e);else if("function"==typeof i)this.addMatch=(t,e,n,s)=>{let r=i(t,e,n);r&&s(n,n+t[0].length,r)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(t,e,n,s)=>s(n,n+t[0].length,i)}this.boundary=s,this.maxLength=r}createDeco(t){let e=new It,i=e.add.bind(e);for(let{from:e,to:n}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 n=[];for(let{from:s,to:r}of i)s=Math.max(t.state.doc.lineAt(s).from,s-e),r=Math.min(t.state.doc.lineAt(r).to,r+e),n.length&&n[n.length-1].to>=s?n[n.length-1].to=r:n.push({from:s,to:r});return n}(t,this.maxLength))Nr(t.state.doc,this.regexp,e,n,(e,n)=>this.addMatch(n,t,e,i));return e.finish()}updateDeco(t,e){let i=1e9,n=-1;return t.docChanged&&t.changes.iterChanges((e,s,r,o)=>{o>=t.view.viewport.from&&r<=t.view.viewport.to&&(i=Math.min(r,i),n=Math.max(o,n))}),t.viewportMoved||n-i>1e3?this.createDeco(t.view):n>-1?this.updateRange(t.view,e.map(t.changes),i,n):e}updateRange(t,e,i,n){for(let s of t.visibleRanges){let r=Math.max(s.from,i),o=Math.min(s.to,n);if(o>=r){let i=t.state.doc.lineAt(r),n=i.toi.from;r--)if(this.boundary.test(i.text[r-1-i.from])){l=r;break}for(;oc.push(i.range(t,e));if(i==n)for(this.regexp.lastIndex=l-i.from;(h=this.regexp.exec(i.text))&&h.indexthis.addMatch(i,t,e,u));e=e.update({filterFrom:l,filterTo:a,filter:(t,e)=>ta,add:c})}}return e}}const qr=null!=/x/.unicode?"gu":"g",Fr=new RegExp("[\0-\b\n--Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\ufeff-]",qr),Hr={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Vr=null;const Wr=H.define({combine(t){let e=Ot(t,{render:null,specialChars:Fr,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==Vr&&"undefined"!=typeof document&&document.body){let e=document.body.style;Vr=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return Vr||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,qr)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,qr)),e}});let $r=null;class _r extends ai{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")+" "+(Hr[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,e);if(n)return n;let s=document.createElement("span");return s.textContent=e,s.title=i,s.setAttribute("aria-label",i),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class jr extends ai{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}const Kr=ci.line({class:"cm-activeLine"}),Ur=ln.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 n of t.state.selection.ranges){let s=t.lineBlockAt(n.head);s.from>e&&(i.push(Kr.range(s.from)),e=s.from)}return ci.set(i)}},{decorations:t=>t.decorations}),Gr=2e3;function Yr(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),n=t.state.doc.lineAt(i),s=i-n.from,r=s>Gr?-1:s==n.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):Kt(n.text,t.state.tabSize,i-n.from);return{line:n.number,col:r,off:s}}function Xr(t,e){let i=Yr(t,e),n=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),s=t.state.doc.lineAt(e);i={line:s.number,col:i.col,off:Math.min(i.off,s.length)},n=n.map(t.changes)}},get(e,s,r){let o=Yr(t,e);if(!o)return n;let l=function(t,e,i){let n=Math.min(e.line,i.line),s=Math.max(e.line,i.line),r=[];if(e.off>Gr||i.off>Gr||e.col<0||i.col<0){let o=Math.min(e.off,i.off),l=Math.max(e.off,i.off);for(let e=n;e<=s;e++){let i=t.doc.line(e);i.length<=l&&r.push(z.range(i.from+o,i.to+l))}}else{let o=Math.min(e.col,i.col),l=Math.max(e.col,i.col);for(let e=n;e<=s;e++){let i=t.doc.line(e),n=Ut(i.text,o,t.tabSize,!0);if(n<0)r.push(z.cursor(i.to));else{let e=Ut(i.text,l,t.tabSize);r.push(z.range(i.from+n,i.from+e))}}}return r}(t.state,i,o);return l.length?r?z.create(l.concat(n.ranges)):z.create(l):n}}:null}const Jr={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},Zr={style:"cursor: crosshair"};const Qr="-10000px";class to{constructor(t,e,i,n){this.facet=e,this.createTooltipView=i,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(t=>t);let s=null;this.tooltipViews=this.tooltips.map(t=>s=i(t,s))}update(t,e){var i;let n=t.state.facet(this.facet),s=n.filter(t=>t);if(n===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let r=[],o=e?[]:null;for(let i=0;ie[i]=t),e.length=o.length),this.input=n,this.tooltips=s,this.tooltipViews=r,!0}}function eo(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const io=H.define({combine:t=>{var e,i,n;return{position:Ge.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===(n=t.find(t=>t.tooltipSpace))||void 0===n?void 0:n.tooltipSpace)||eo}}}),no=new WeakMap,so=ln.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(io);this.position=e.position,this.parent=e.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new to(t,ao,(t,e)=>this.createTooltip(t,e),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),t.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let i=e||t.geometryChanged,n=t.state.facet(io);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view),n=e?e.dom:null;if(i.dom.classList.add("cm-tooltip"),t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",i.dom.appendChild(t)}return i.dom.style.position=this.position,i.dom.style.top=Qr,i.dom.style.left="0px",this.container.insertBefore(i.dom,n),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),null===(t=e.destroy)||void 0===t||t.call(e);this.parent&&this.container.remove(),null===(e=this.resizeObserver)||void 0===e||e.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,i=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(Ge.gecko)i=t.offsetParent!=this.container.ownerDocument.body;else if(t.style.top==Qr&&"0px"==t.style.left){let e=t.getBoundingClientRect();i=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}}if(i||"absolute"==this.position)if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(t=i.width/this.parent.offsetWidth,e=i.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);let n=this.view.scrollDOM.getBoundingClientRect(),s=vn(this.view);return{visible:{left:n.left+s.left,top:n.top+s.top,right:n.right-s.right,bottom:n.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)}),size:this.manager.tooltipViews.map(({dom:t})=>t.getBoundingClientRect()),space:this.view.state.facet(io).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{visible:i,space:n,scaleX:s,scaleY:r}=t,o=[];for(let l=0;l=Math.min(i.bottom,n.bottom)||u.rightMath.min(i.right,n.right)+.1)){c.style.top=Qr;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=f.right-f.left,g=null!==(e=no.get(h))&&void 0!==e?e:f.bottom-f.top,v=h.offset||lo,w=this.view.textDirection==ki.LTR,b=f.width>n.right-n.left?w?n.left:n.right-f.width:w?Math.max(n.left,Math.min(u.left-(d?14:0)+v.x,n.right-m)):Math.min(Math.max(n.left,u.left-m+(d?14:0)-v.x),n.right-m),y=this.above[l];!a.strictSide&&(y?u.top-g-p-v.yn.bottom)&&y==n.bottom-u.bottom>u.top-n.top&&(y=this.above[l]=!y);let x=(y?u.top-n.top:n.bottom-u.bottom)-p;if(xb&&t.topk&&(k=y?t.top-g-2-p:t.bottom+p+2);if("absolute"==this.position?(c.style.top=(k-t.parent.top)/r+"px",ro(c,(b-t.parent.left)/s)):(c.style.top=k/r+"px",ro(c,b/s)),d){let t=u.left+(w?v.x:-v.x)-(b+14-7);d.style.left=t/s+"px"}!0!==h.overlap&&o.push({left:b,top:k,right:S,bottom:k+g}),c.classList.toggle("cm-tooltip-above",y),c.classList.toggle("cm-tooltip-below",!y),h.positioned&&h.positioned(t.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let t of this.manager.tooltipViews)t.dom.style.top=Qr}},{eventObservers:{scroll(){this.maybeMeasure()}}});function ro(t,e){let i=parseInt(t.style.left,10);(isNaN(i)||Math.abs(e-i)>1)&&(t.style.left=e+"px")}const oo=or.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),lo={x:0,y:0},ao=H.define({enables:[so,oo]}),ho=H.define({combine:t=>t.reduce((t,e)=>t.concat(e),[])});class co{static create(t){return new co(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new to(t,ho,(t,e)=>this.createHostedView(t,e),t=>t.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)null===(t=e.destroy)||void 0===t||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let n=i[t];if(void 0!==n)if(void 0===e)e=n;else if(e!==n)return}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const uo=ao.compute([ho],t=>{let e=t.facet(ho);return 0===e.length?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var e;return null!==(e=t.end)&&void 0!==e?e:t.pos})),create:co.create,above:e[0].above,arrow:e.some(t=>t.arrow)}});class fo{constructor(t,e,i,n,s){this.view=t,this.source=e,this.field=i,this.setHover=n,this.hoverTime=s,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;ti.bottom||e.xi.right+t.defaultCharacterWidth)return;let r=t.bidiSpans(t.state.doc.lineAt(n)).find(t=>t.from<=n&&t.to>=n),o=r&&r.dir==ki.RTL?-1:1;s=e.x{this.pending==e&&(this.pending=null,!i||Array.isArray(i)&&!i.length||t.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])}))},e=>nn(t.state,e,"hover tooltip"))}else!r||Array.isArray(r)&&!r.length||t.dispatch({effects:this.setHover.of(Array.isArray(r)?r:[r])})}get tooltip(){let t=this.view.plugin(so),e=t?t.manager.tooltips.findIndex(t=>t.create==co.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:s}=this;if(n.length&&s&&!function(t,e){let i,{left:n,right:s,top:r,bottom:o}=t.getBoundingClientRect();if(i=t.querySelector(".cm-tooltip-arrow")){let t=i.getBoundingClientRect();r=Math.min(t.top,r),o=Math.max(t.bottom,o)}return e.clientX>=n-po&&e.clientX<=s+po&&e.clientY>=r-po&&e.clientY<=o+po}(s.dom,t)||this.pending){let{pos:s}=n[0]||this.pending,r=null!==(i=null===(e=n[0])||void 0===e?void 0:e.end)&&void 0!==i?i:s;(s==r?this.view.posAtCoords(this.lastMove)==s:function(t,e,i,n,s){let r=t.scrollDOM.getBoundingClientRect(),o=t.documentTop+t.documentPadding.top+t.contentHeight;if(r.left>n||r.rights||Math.min(r.bottom,o)=e&&l<=i}(this.view,s,r,t.clientX,t.clientY))||(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:e}=this;e&&e.dom.contains(t.relatedTarget)?this.watchTooltipLeave(e.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const po=4;function mo(t,e={}){let i=gt.define(),n=U.define({create:()=>[],update(t,n){if(t.length&&(e.hideOnChange&&(n.docChanged||n.selection)?t=[]:e.hideOn&&(t=t.filter(t=>!e.hideOn(n,t))),n.docChanged)){let e=[];for(let i of t){let t=n.changes.mapPos(i.pos,-1,T.TrackDel);if(null!=t){let s=Object.assign(Object.create(null),i);s.pos=t,null!=s.end&&(s.end=n.changes.mapPos(s.end)),e.push(s)}}t=e}for(let e of n.effects)e.is(i)&&(t=e.value),e.is(vo)&&(t=[]);return t},provide:t=>ho.from(t)});return{active:n,extension:[n,ln.define(s=>new fo(s,t,n,i,e.hoverTime||300)),uo]}}function go(t,e){let i=t.plugin(so);if(!i)return null;let n=i.manager.tooltips.indexOf(e);return n<0?null:i.manager.tooltipViews[n]}const vo=gt.define(),wo=H.define({combine(t){let e,i;for(let n of t)e=e||n.topContainer,i=i||n.bottomContainer;return{topContainer:e,bottomContainer:i}}});function bo(t,e){let i=t.plugin(yo),n=i?i.specs.indexOf(e):-1;return n>-1?i.panels[n]:null}const yo=ln.fromClass(class{constructor(t){this.input=t.state.facet(So),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(e=>e(t));let e=t.state.facet(wo);this.top=new xo(t,!0,e.topContainer),this.bottom=new xo(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(wo);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new xo(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new xo(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(So);if(i!=this.input){let e=i.filter(t=>t),n=[],s=[],r=[],o=[];for(let i of e){let e,l=this.specs.indexOf(i);l<0?(e=i(t.view),o.push(e)):(e=this.panels[l],e.update&&e.update(t)),n.push(e),(e.top?s:r).push(e)}this.specs=e,this.panels=n,this.top.sync(s),this.bottom.sync(r);for(let t of o)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=>or.scrollMargins.of(e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}})});class xo{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=ko(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=ko(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 ko(t){let e=t.nextSibling;return t.remove(),e}const So=H.define({enables:yo});function Co(t,e){let i,n=new Promise(t=>i=t),s=t=>function(t,e,i){let n=e.content?e.content(t,()=>o(null)):null;if(!n){if(n=oe("form"),e.input){let t=oe("input",e.input);/^(text|password|number|email|tel|url)$/.test(t.type)&&t.classList.add("cm-textfield"),t.name||(t.name="input"),n.appendChild(oe("label",(e.label||"")+": ",t))}else n.appendChild(document.createTextNode(e.label||""));n.appendChild(document.createTextNode(" ")),n.appendChild(oe("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let s="FORM"==n.nodeName?[n]:n.querySelectorAll("form");for(let t=0;t{27==t.keyCode?(t.preventDefault(),o(null)):13==t.keyCode&&(t.preventDefault(),o(e))}),e.addEventListener("submit",t=>{t.preventDefault(),o(e)})}let r=oe("div",n,oe("button",{onclick:()=>o(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(r.className=e.class);function o(e){r.contains(r.ownerDocument.activeElement)&&t.focus(),i(e)}return r.classList.add("cm-dialog"),{dom:r,top:e.top,mount:()=>{if(e.focus){let t;t="string"==typeof e.focus?n.querySelector(e.focus):n.querySelector("input")||n.querySelector("button"),t&&"select"in t?t.select():t&&"focus"in t&&t.focus()}}}}(t,e,i);t.state.field(Ao,!1)?t.dispatch({effects:Mo.of(s)}):t.dispatch({effects:gt.appendConfig.of(Ao.init(()=>[s]))});let r=To.of(s);return{close:r,result:n.then(e=>((t.win.queueMicrotask||(e=>t.win.setTimeout(e,10)))(()=>{t.state.field(Ao).indexOf(s)>-1&&t.dispatch({effects:r})}),e))}}const Ao=U.define({create:()=>[],update(t,e){for(let i of e.effects)i.is(Mo)?t=[i.value].concat(t):i.is(To)&&(t=t.filter(t=>t!=i.value));return t},provide:t=>So.computeN([t],e=>e.field(t))}),Mo=gt.define(),To=gt.define();class Do extends Rt{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Do.prototype.elementClass="",Do.prototype.toDOM=void 0,Do.prototype.mapMode=T.TrackBefore,Do.prototype.startSide=Do.prototype.endSide=-1,Do.prototype.point=!0;const Oo=H.define(),Ro=H.define(),Eo={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>Bt.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Po=H.define();function Lo(t){return[Io(),Po.of({...Eo,...t})]}const Bo=H.define({combine:t=>t.some(t=>t)});function Io(t){return[No]}const No=ln.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Po).map(e=>new Ho(t,e)),this.fixed=!t.state.facet(Bo);for(let t of this.gutters)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,n=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(n<.8*(i.to-i.from))}if(t.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Bo)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let i=Bt.iter(this.view.state.facet(Oo),this.view.viewport.from),n=[],s=this.gutters.map(t=>new Fo(t,this.view.viewport,-this.view.documentPadding.top));for(let t of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(t.type)){let e=!0;for(let r of t.type)if(r.type==hi.Text&&e){qo(i,n,r.from);for(let t of s)t.line(this.view,r,n);e=!1}else if(r.widget)for(let t of s)t.widget(this.view,r)}else if(t.type==hi.Text){qo(i,n,t.from);for(let e of s)e.line(this.view,t,n)}else if(t.widget)for(let e of s)e.widget(this.view,t);for(let t of s)t.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(Po),i=t.state.facet(Po),n=t.docChanged||t.heightChanged||t.viewportChanged||!Bt.eq(t.startState.facet(Oo),t.state.facet(Oo),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(n=!0);else{n=!0;let s=[];for(let n of i){let i=e.indexOf(n);i<0?s.push(new Ho(this.view,n)):(this.gutters[i].update(t),s.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),s.indexOf(t)<0&&t.destroy();for(let t of s)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.gutters=s}return n}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>or.scrollMargins.of(e=>{let i=e.plugin(t);if(!i||0==i.gutters.length||!i.fixed)return null;let n=i.dom.offsetWidth*e.scaleX,s=i.domAfter?i.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==ki.LTR?{left:n,right:s}:{right:n,left:s}})});function zo(t){return Array.isArray(t)?t:[t]}function qo(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class Fo{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=Bt.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:n}=this,s=(e.top-this.height)/t.scaleY,r=e.height/t.scaleY;if(this.i==n.elements.length){let e=new Vo(t,r,s,i);n.elements.push(e),n.dom.appendChild(e.dom)}else n.elements[this.i].update(t,r,s,i);this.height=e.bottom,this.i++}line(t,e,i){let n=[];qo(this.cursor,n,e.from),i.length&&(n=n.concat(i));let s=this.gutter.config.lineMarker(t,e,n);s&&n.unshift(s);let r=this.gutter;(0!=n.length||r.config.renderEmptyElements)&&this.addElement(t,e,n)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),n=i?[i]:null;for(let i of t.state.facet(Ro)){let s=i(t,e.widget,e);s&&(n||(n=[])).push(s)}n&&this.addElement(t,e,n)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Ho{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,n=>{let s,r=n.target;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let t=r.getBoundingClientRect();s=(t.top+t.bottom)/2}else s=n.clientY;let o=t.lineBlockAtHeight(s-t.documentTop);e.domEventHandlers[i](t,o,n)&&n.preventDefault()});this.markers=zo(e.markers(t)),e.initialSpacer&&(this.spacer=new Vo(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=zo(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!Bt.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 Vo{constructor(t,e,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,n)}update(t,e,i,n){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;iOt(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let n=i[t],s=e[t];i[t]=n?(t,e,i)=>n(t,e,i)||s(t,e,i):s}return i}})});class jo extends Do{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Ko(t,e){return t.state.facet(_o).formatNumber(e,t.state)}const Uo=Po.compute([_o],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(Wo),lineMarker:(t,e,i)=>i.some(t=>t.toDOM)?null:new jo(Ko(t,t.state.doc.lineAt(e.from).number)),widgetMarker:(t,e,i)=>{for(let n of t.state.facet($o)){let s=n(t,e,i);if(s)return s}return null},lineMarkerChange:t=>t.startState.facet(_o)!=t.state.facet(_o),initialSpacer:t=>new jo(Ko(t,Go(t.state.doc.lines))),updateSpacer(t,e){let i=Ko(e.view,Go(e.view.state.doc.lines));return i==t.number?t:new jo(i)},domEventHandlers:t.facet(_o).domEventHandlers,side:"before"}));function Go(t){let e=9;for(;e{let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.head).from;s>i&&(i=s,e.push(Yo.range(s)))}return Bt.of(e)});const Jo="function"==typeof String.prototype.normalize?t=>t.normalize("NFKD"):t=>t;class Zo{constructor(t,e,i=0,n=t.length,s,r){this.test=r,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,n),this.bufferStart=i,this.normalize=s?t=>s(Jo(t)):Jo,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 S(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=C(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=A(t);let n=this.normalize(e);if(n.length)for(let t=0,s=i;;t++){let r=n.charCodeAt(t),o=this.match(r,s,this.bufferPos+this.bufferStart);if(t==n.length-1){if(o)return this.value=o,this;break}s==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,n=i+e[0].length;if(this.matchPos=rl(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(ithis.value.to)&&(!this.test||this.test(i,n,e)))return this.value={from:i,to:n,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length=i||n.to<=e){let n=new nl(e,t.sliceString(e,i));return il.set(t,n),n}if(n.from==e&&n.to==i)return n;let{text:s,from:r}=n;return r>e&&(s=t.sliceString(e,r)+s,r=e),n.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){let t=this.flat.from+e.index,i=t+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(t,i,e)))return this.value={from:t,to:i,match:e},this.matchPos=rl(this.text,i+(t==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=nl.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function rl(t,e){if(e>=t.length)return e;let i,n=t.lineAt(e);for(;e=56320&&i<57344;)e++;return e}function ol(t){let e=oe("input",{class:"cm-textfield",name:"line",value:String(t.state.doc.lineAt(t.state.selection.main.head).number)});function i(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!i)return;let{state:n}=t,s=n.doc.lineAt(n.selection.main.head),[,r,o,l,a]=i,h=l?+l.slice(1):0,c=o?+o:s.number;if(o&&a){let t=c/100;r&&(t=t*("-"==r?-1:1)+s.number/n.doc.lines),c=Math.round(n.doc.lines*t)}else o&&r&&(c=c*("-"==r?-1:1)+s.number);let u=n.doc.line(Math.max(1,Math.min(n.doc.lines,c))),f=z.cursor(u.from+Math.max(0,Math.min(h,u.length)));t.dispatch({effects:[ll.of(!1),or.scrollIntoView(f.from,{y:"center"})],selection:f}),t.focus()}return{dom:oe("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:ll.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),i())},onsubmit:t=>{t.preventDefault(),i()}},oe("label",t.state.phrase("Go to line"),": ",e)," ",oe("button",{class:"cm-button",type:"submit"},t.state.phrase("go")),oe("button",{name:"close",onclick:()=>{t.dispatch({effects:ll.of(!1)}),t.focus()},"aria-label":t.state.phrase("close"),type:"button"},["×"]))}}"undefined"!=typeof Symbol&&(el.prototype[Symbol.iterator]=sl.prototype[Symbol.iterator]=function(){return this});const ll=gt.define(),al=U.define({create:()=>!0,update(t,e){for(let i of e.effects)i.is(ll)&&(t=i.value);return t},provide:t=>So.from(t,t=>t?ol:null)}),hl=or.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}}}),cl={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},ul=H.define({combine:t=>Ot(t,cl,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});const fl=ci.mark({class:"cm-selectionMatch"}),dl=ci.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function pl(t,e,i,n){return!(0!=i&&t(e.sliceDoc(i-1,i))==Ct.Word||n!=e.doc.length&&t(e.sliceDoc(n,n+1))==Ct.Word)}const ml=ln.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(ul),{state:i}=t,n=i.selection;if(n.ranges.length>1)return ci.none;let s,r=n.main,o=null;if(r.empty){if(!e.highlightWordAroundCursor)return ci.none;let t=i.wordAt(r.head);if(!t)return ci.none;o=i.charCategorizer(r.head),s=i.sliceDoc(t.from,t.to)}else{let t=r.to-r.from;if(t200)return ci.none;if(e.wholeWords){if(s=i.sliceDoc(r.from,r.to),o=i.charCategorizer(r.head),!pl(o,i,r.from,r.to)||!function(t,e,i,n){return t(e.sliceDoc(i,i+1))==Ct.Word&&t(e.sliceDoc(n-1,n))==Ct.Word}(o,i,r.from,r.to))return ci.none}else if(s=i.sliceDoc(r.from,r.to),!s)return ci.none}let l=[];for(let n of t.visibleRanges){let t=new Zo(i.doc,s,n.from,n.to);for(;!t.next().done;){let{from:n,to:s}=t.value;if((!o||pl(o,i,n,s))&&(r.empty&&n<=r.from&&s>=r.to?l.push(dl.range(n,s)):(n>=r.to||s<=r.from)&&l.push(fl.range(n,s)),l.length>e.maxMatches))return ci.none}}return ci.set(l)}},{decorations:t=>t.decorations}),gl=or.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const vl=H.define({combine:t=>Ot(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Kl(t),scrollToMatch:t=>or.scrollIntoView(t)})});class wl{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,tl),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord}unquote(t){return this.literal?t:t.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&&this.wholeWord==t.wholeWord}create(){return this.regexp?new Al(this):new xl(this)}getCursor(t,e=0,i){let n=t.doc?t:Dt.create({doc:t});return null==i&&(i=n.doc.length),this.regexp?kl(this,n,e,i):yl(this,n,e,i)}}class bl{constructor(t){this.spec=t}}function yl(t,e,i,n){return new Zo(e.doc,t.unquoted,i,n,t.caseSensitive?void 0:t=>t.toLowerCase(),t.wholeWord?function(t,e){return(i,n,s,r)=>((r>i||r+s.length=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=yl(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}function kl(t,e,i,n){return new el(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?(s=e.charCategorizer(e.selection.main.head),(t,e,i)=>!i[0].length||(s(Sl(i.input,i.index))!=Ct.Word||s(Cl(i.input,i.index))!=Ct.Word)&&(s(Cl(i.input,i.index+i[0].length))!=Ct.Word||s(Sl(i.input,i.index+i[0].length))!=Ct.Word)):void 0},i,n);var s}function Sl(t,e){return t.slice(k(t,e,!1),e)}function Cl(t,e){return t.slice(e,k(t,e))}class Al extends bl{nextMatch(t,e,i){let n=kl(this.spec,t,i,t.doc.length).next();return n.done&&(n=kl(this.spec,t,0,e).next()),n.done?null:n.value}prevMatchInRange(t,e,i){for(let n=1;;n++){let s=Math.max(e,i-1e4*n),r=kl(this.spec,t,s,i),o=null;for(;!r.next().done;)o=r.value;if(o&&(s==e||o.from>s+10))return o;if(s==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(e,i)=>{if("&"==i)return t.match[0];if("$"==i)return"$";for(let e=i.length;e>0;e--){let n=+i.slice(0,e);if(n>0&&n=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=kl(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}const Ml=gt.define(),Tl=gt.define(),Dl=U.define({create:t=>new Ol(Hl(t).create(),null),update(t,e){for(let i of e.effects)i.is(Ml)?t=new Ol(i.value.create(),t.panel):i.is(Tl)&&(t=new Ol(t.query,i.value?Fl:null));return t},provide:t=>So.from(t,t=>t.panel)});class Ol{constructor(t,e){this.query=t,this.panel=e}}const Rl=ci.mark({class:"cm-searchMatch"}),El=ci.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Pl=ln.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Dl))}update(t){let e=t.state.field(Dl);(e!=t.startState.field(Dl)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return ci.none;let{view:i}=this,n=new It;for(let e=0,s=i.visibleRanges,r=s.length;es[e+1].from-500;)l=s[++e].to;t.highlight(i.state,o,l,(t,e)=>{let s=i.state.selection.ranges.some(i=>i.from==t&&i.to==e);n.add(t,e,s?El:Rl)})}return n.finish()}},{decorations:t=>t.decorations});function Ll(t){return e=>{let i=e.state.field(Dl,!1);return i&&i.query.spec.valid?t(e,i):$l(e)}}const Bl=Ll((t,{query:e})=>{let{to:i}=t.state.selection.main,n=e.nextMatch(t.state,i,i);if(!n)return!1;let s=z.single(n.from,n.to),r=t.state.facet(vl);return t.dispatch({selection:s,effects:[Xl(t,n),r.scrollToMatch(s.main,t)],userEvent:"select.search"}),Wl(t),!0}),Il=Ll((t,{query:e})=>{let{state:i}=t,{from:n}=i.selection.main,s=e.prevMatch(i,n,n);if(!s)return!1;let r=z.single(s.from,s.to),o=t.state.facet(vl);return t.dispatch({selection:r,effects:[Xl(t,s),o.scrollToMatch(r.main,t)],userEvent:"select.search"}),Wl(t),!0}),Nl=Ll((t,{query:e})=>{let i=e.matchAll(t.state,1e3);return!(!i||!i.length)&&(t.dispatch({selection:z.create(i.map(t=>z.range(t.from,t.to))),userEvent:"select.search.matches"}),!0)}),zl=Ll((t,{query:e})=>{let{state:i}=t,{from:n,to:s}=i.selection.main;if(i.readOnly)return!1;let r=e.nextMatch(i,n,n);if(!r)return!1;let o,l,a=r,h=[],c=[];a.from==n&&a.to==s&&(l=i.toText(e.getReplacement(a)),h.push({from:a.from,to:a.to,insert:l}),a=e.nextMatch(i,a.from,a.to),c.push(or.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+".")));let u=t.state.changes(h);return a&&(o=z.single(a.from,a.to).map(u),c.push(Xl(t,a)),c.push(i.facet(vl).scrollToMatch(o.main,t))),t.dispatch({changes:u,selection:o,effects:c,userEvent:"input.replace"}),!0}),ql=Ll((t,{query:e})=>{if(t.state.readOnly)return!1;let i=e.matchAll(t.state,1e9).map(t=>{let{from:i,to:n}=t;return{from:i,to:n,insert:e.getReplacement(t)}});if(!i.length)return!1;let n=t.state.phrase("replaced $ matches",i.length)+".";return t.dispatch({changes:i,effects:or.announce.of(n),userEvent:"input.replace.all"}),!0});function Fl(t){return t.state.facet(vl).createPanel(t)}function Hl(t,e){var i,n,s,r,o;let l=t.selection.main,a=l.empty||l.to>l.from+100?"":t.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=t.facet(vl);return new wl({search:(null!==(i=null==e?void 0:e.literal)&&void 0!==i?i:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:null!==(n=null==e?void 0:e.caseSensitive)&&void 0!==n?n:h.caseSensitive,literal:null!==(s=null==e?void 0:e.literal)&&void 0!==s?s:h.literal,regexp:null!==(r=null==e?void 0:e.regexp)&&void 0!==r?r:h.regexp,wholeWord:null!==(o=null==e?void 0:e.wholeWord)&&void 0!==o?o:h.wholeWord})}function Vl(t){let e=bo(t,Fl);return e&&e.dom.querySelector("[main-field]")}function Wl(t){let e=Vl(t);e&&e==t.root.activeElement&&e.select()}const $l=t=>{let e=t.state.field(Dl,!1);if(e&&e.panel){let i=Vl(t);if(i&&i!=t.root.activeElement){let n=Hl(t.state,e.query.spec);n.valid&&t.dispatch({effects:Ml.of(n)}),i.focus(),i.select()}}else t.dispatch({effects:[Tl.of(!0),e?Ml.of(Hl(t.state,e.query.spec)):gt.appendConfig.of(Zl)]});return!0},_l=t=>{let e=t.state.field(Dl,!1);if(!e||!e.panel)return!1;let i=bo(t,Fl);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Tl.of(!1)}),!0},jl=[{key:"Mod-f",run:$l,scope:"editor search-panel"},{key:"F3",run:Bl,shift:Il,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Bl,shift:Il,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:_l,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:n,to:s}=i.main,r=[],o=0;for(let e=new Zo(t.doc,t.sliceDoc(n,s));!e.next().done;){if(r.length>1e3)return!1;e.value.from==n&&(o=r.length),r.push(z.range(e.value.from,e.value.to))}return e(t.update({selection:z.create(r,o),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:t=>{let e=bo(t,ol);if(!e){let i=[ll.of(!0)];null==t.state.field(al,!1)&&i.push(gt.appendConfig.of([al,hl])),t.dispatch({effects:i}),e=bo(t,ol)}return e&&e.dom.querySelector("input").select(),!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,n=z.create(i.ranges.map(e=>t.wordAt(e.head)||z.cursor(e.head)),i.mainIndex);return!n.eq(i)&&(e(t.update({selection:n})),!0)})({state:t,dispatch:e});let n=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some(e=>t.sliceDoc(e.from,e.to)!=n))return!1;let s=function(t,e){let{main:i,ranges:n}=t.selection,s=t.wordAt(i.head),r=s&&s.from==i.from&&s.to==i.to;for(let i=!1,s=new Zo(t.doc,e,n[n.length-1].to);;){if(s.next(),!s.done){if(i&&n.some(t=>t.from==s.value.from))continue;if(r){let e=t.wordAt(s.value.from);if(!e||e.from!=s.value.from||e.to!=s.value.to)continue}return s.value}if(i)return null;s=new Zo(t.doc,e,0,Math.max(0,n[n.length-1].from-1)),i=!0}}(t,n);return!!s&&(e(t.update({selection:t.selection.addRange(z.range(s.from,s.to),!1),effects:or.scrollIntoView(s.to)})),!0)},preventDefault:!0}];class Kl{constructor(t){this.view=t;let e=this.query=t.state.field(Dl).query.spec;function i(t,e,i){return oe("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=oe("input",{value:e.search,placeholder:Ul(t,"Find"),"aria-label":Ul(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=oe("input",{value:e.replace,placeholder:Ul(t,"Replace"),"aria-label":Ul(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=oe("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=oe("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=oe("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit}),this.dom=oe("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",()=>Bl(t),[Ul(t,"next")]),i("prev",()=>Il(t),[Ul(t,"previous")]),i("select",()=>Nl(t),[Ul(t,"all")]),oe("label",null,[this.caseField,Ul(t,"match case")]),oe("label",null,[this.reField,Ul(t,"regexp")]),oe("label",null,[this.wordField,Ul(t,"by word")]),...t.state.readOnly?[]:[oe("br"),this.replaceField,i("replace",()=>zl(t),[Ul(t,"replace")]),i("replaceAll",()=>ql(t),[Ul(t,"replace all")])],oe("button",{name:"close",onclick:()=>_l(t),"aria-label":Ul(t,"close"),type:"button"},["×"])])}commit(){let t=new wl({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:Ml.of(t)}))}keydown(t){var e,i,n;e=this.view,i=t,n="search-panel",yr(gr(e.state),i,e,n)?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Il:Bl)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),zl(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(Ml)&&!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,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(vl).top}}function Ul(t,e){return t.state.phrase(e)}const Gl=30,Yl=/[\s\.,:;?!]/;function Xl(t,{from:e,to:i}){let n=t.state.doc.lineAt(e),s=t.state.doc.lineAt(i).to,r=Math.max(n.from,e-Gl),o=Math.min(s,i+Gl),l=t.state.sliceDoc(r,o);if(r!=n.from)for(let t=0;tl.length-Gl;t--)if(!Yl.test(l[t-1])&&Yl.test(l[t])){l=l.slice(0,t);break}return or.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${n.number}.`)}const Jl=or.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"}}),Zl=[Dl,Q.low(Pl),Jl];class Ql{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class ta{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let n=i.facet(ga).markerFilter;n&&(t=n(t,i));let s=t.slice().sort((t,e)=>t.from-e.from||t.to-e.to),r=new It,o=[],l=0;for(let t=0;;){let e,n,a=t==s.length?null:s[t];if(!a&&!o.length)break;for(o.length?(e=l,n=o.reduce((t,e)=>Math.min(t,e.to),a&&a.from>e?a.from:1e8)):(e=a.from,n=a.to,o.push(a),t++);ti.from||i.to==e)){n=Math.min(i.from,n);break}o.push(i),t++,n=Math.min(i.to,n)}let h=Ma(o);if(o.some(t=>t.from==t.to||t.from==t.to-1&&i.doc.lineAt(t.from).to==t.from))r.add(e,e,ci.widget({widget:new ba(h),diagnostics:o.slice()}));else{let t=o.reduce((t,e)=>e.markClass?t+" "+e.markClass:t,"");r.add(e,n,ci.mark({class:"cm-lintRange cm-lintRange-"+h+t,diagnostics:o.slice(),inclusiveEnd:o.some(t=>t.to>n)}))}l=n;for(let t=0;t{if(!(e&&s.diagnostics.indexOf(e)<0))if(n){if(s.diagnostics.indexOf(n.diagnostic)<0)return!1;n=new Ql(n.from,i,n.diagnostic)}else n=new Ql(t,i,e||s.diagnostics[0])}),n}function ia(t,e){let i=e.pos,n=e.end||i,s=t.state.facet(ga).hideOn(t,i,n);if(null!=s)return s;let r=t.startState.doc.lineAt(e.pos);return!(!t.effects.some(t=>t.is(ra))&&!t.changes.touchesRange(r.from,Math.max(r.to,n)))}function na(t,e){return t.field(aa,!1)?e:e.concat(gt.appendConfig.of(Ba))}function sa(t,e){return{effects:na(t,[ra.of(e)])}}const ra=gt.define(),oa=gt.define(),la=gt.define(),aa=U.define({create:()=>new ta(ci.none,null,null),update(t,e){if(e.docChanged&&t.diagnostics.size){let i=t.diagnostics.map(e.changes),n=null,s=t.panel;if(t.selected){let s=e.changes.mapPos(t.selected.from,1);n=ea(i,t.selected.diagnostic,s)||ea(i,null,s)}!i.size&&s&&e.state.facet(ga).autoPanel&&(s=null),t=new ta(i,s,n)}for(let i of e.effects)if(i.is(ra)){let n=e.state.facet(ga).autoPanel?i.value.length?xa.open:null:t.panel;t=ta.init(i.value,n,e.state)}else i.is(oa)?t=new ta(t.diagnostics,i.value?xa.open:null,t.selected):i.is(la)&&(t=new ta(t.diagnostics,t.panel,i.value));return t},provide:t=>[So.from(t,t=>t.panel),or.decorations.from(t,t=>t.diagnostics)]}),ha=ci.mark({class:"cm-lintRange cm-lintRange-active"});function ca(t,e,i){let n,{diagnostics:s}=t.state.field(aa),r=-1,o=-1;s.between(e-(i<0?1:0),e+(i>0?1:0),(t,s,{spec:l})=>{if(e>=t&&e<=s&&(t==s||(e>t||i>0)&&(e({dom:ua(t,n)})}:null}function ua(t,e){return oe("ul",{class:"cm-tooltip-lint"},e.map(e=>wa(t,e,!1)))}const fa=t=>{let e=t.state.field(aa,!1);e&&e.panel||t.dispatch({effects:na(t.state,[oa.of(!0)])});let i=bo(t,xa.open);return i&&i.dom.querySelector(".cm-panel-lint ul").focus(),!0},da=t=>{let e=t.state.field(aa,!1);return!(!e||!e.panel)&&(t.dispatch({effects:oa.of(!1)}),!0)},pa=[{key:"Mod-Shift-m",run:fa,preventDefault:!0},{key:"F8",run:t=>{let e=t.state.field(aa,!1);if(!e)return!1;let i=t.state.selection.main,n=e.diagnostics.iter(i.to+1);return!(!n.value&&(n=e.diagnostics.iter(0),!n.value||n.from==i.from&&n.to==i.to))&&(t.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),!0)}}],ma=ln.fromClass(class{constructor(t){this.view=t,this.timeout=-1,this.set=!0;let{delay:e}=t.state.facet(ga);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let t=Date.now();if(t{n.push(i),clearTimeout(s),n.length==t.length?e(n):s=setTimeout(()=>e(n),200)},i)}(e.map(t=>Promise.resolve(t(this.view))),e=>{this.view.state.doc==t.doc&&this.view.dispatch(sa(this.view.state,e.reduce((t,e)=>t.concat(e))))},t=>{nn(this.view.state,t)})}}update(t){let e=t.state.facet(ga);(t.docChanged||e!=t.startState.facet(ga)||e.needsRefresh&&e.needsRefresh(t))&&(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)}});const ga=H.define({combine:t=>Object.assign({sources:t.map(t=>t.source).filter(t=>null!=t)},Ot(t.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e}))});function va(t){let e=[];if(t)t:for(let{name:i}of t){for(let t=0;tt.toLowerCase()==n.toLowerCase())){e.push(n);continue t}}e.push("")}return e}function wa(t,e,i){var n;let s=i?va(e.actions):[];return oe("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},oe("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),null===(n=e.actions)||void 0===n?void 0:n.map((i,n)=>{let r=!1,o=n=>{if(n.preventDefault(),r)return;r=!0;let s=ea(t.state.field(aa).diagnostics,e);s&&i.apply(t,s.from,s.to)},{name:l}=i,a=s[n]?l.indexOf(s[n]):-1,h=a<0?l:[l.slice(0,a),oe("u",l.slice(a,a+1)),l.slice(a+1)];return oe("button",{type:"button",class:"cm-diagnosticAction",onclick:o,onmousedown:o,"aria-label":` Action: ${l}${a<0?"":` (access key "${s[n]})"`}.`},h)}),e.source&&oe("div",{class:"cm-diagnosticSource"},e.source))}class ba extends ai{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return oe("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class ya{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=wa(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class xa{constructor(t){this.view=t,this.items=[];this.list=oe("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(27==e.keyCode)da(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],n=va(i.actions);for(let s=0;s{for(let e=0;eda(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(aa).selected;if(!t)return-1;for(let e=0;e{for(let t of l.diagnostics){if(r.has(t))continue;r.add(t);let o,l=-1;for(let e=i;ei&&(this.items.splice(i,l-i),n=!0)),e&&o.diagnostic==e.diagnostic?o.dom.hasAttribute("aria-selected")||(o.dom.setAttribute("aria-selected","true"),s=o):o.dom.hasAttribute("aria-selected")&&o.dom.removeAttribute("aria-selected"),i++}});i({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:t,panel:e})=>{let i=e.height/this.list.offsetHeight;t.tope.bottom&&(this.list.scrollTop+=(t.bottom-e.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&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=ea(this.view.state.field(aa).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:la.of(e)})}static open(t){return new xa(t)}}function ka(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,${encodeURIComponent(t)}')`}function Sa(t){return ka(``,'width="6" height="3"')}const Ca=or.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-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Sa("#d11")},".cm-lintRange-warning":{backgroundImage:Sa("orange")},".cm-lintRange-info":{backgroundImage:Sa("#999")},".cm-lintRange-hint":{backgroundImage:Sa("#66d")},".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-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".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}}});function Aa(t){return"error"==t?4:"warning"==t?3:"info"==t?2:1}function Ma(t){let e="hint",i=1;for(let n of t){let t=Aa(n.severity);t>i&&(i=t,e=n.severity)}return e}class Ta extends Do{constructor(t){super(),this.diagnostics=t,this.severity=Ma(t)}toDOM(t){let e=document.createElement("div");e.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,n=t.state.facet(Ia).tooltipFilter;return n&&(i=n(i,t.state)),i.length&&(e.onmouseover=()=>function(t,e,i){function n(){let n=t.elementAtHeight(e.getBoundingClientRect().top+5-t.documentTop);t.coordsAtPos(n.from)&&t.dispatch({effects:Ea.of({pos:n.from,above:!1,clip:!1,create:()=>({dom:ua(t,i),getCoords:()=>e.getBoundingClientRect()})})}),e.onmouseout=e.onmousemove=null,function(t,e){let i=n=>{let s=e.getBoundingClientRect();if(!(n.clientX>s.left-10&&n.clientXs.top-10&&n.clientY{clearTimeout(r),e.onmouseout=e.onmousemove=null},e.onmousemove=()=>{clearTimeout(r),r=setTimeout(n,s)}}(t,e,i)),e}}function Da(t,e){let i=Object.create(null);for(let n of e){let e=t.lineAt(n.from);(i[e.from]||(i[e.from]=[])).push(n)}let n=[];for(let t in i)n.push(new Ta(i[t]).range(+t));return Bt.of(n,!0)}const Oa=Lo({class:"cm-gutter-lint",markers:t=>t.state.field(Ra),widgetMarker:(t,e,i)=>{let n=[];return t.state.field(Ra).between(i.from,i.to,(t,e,s)=>{t>i.from&&tBt.empty,update(t,e){t=t.map(e.changes);let i=e.state.facet(Ia).markerFilter;for(let n of e.effects)if(n.is(ra)){let s=n.value;i&&(s=i(s||[],e.state)),t=Da(e.state.doc,s.slice(0))}return t}}),Ea=gt.define(),Pa=U.define({create:()=>null,update:(t,e)=>(t&&e.docChanged&&(t=ia(e,t)?null:Object.assign(Object.assign({},t),{pos:e.changes.mapPos(t.pos)})),e.effects.reduce((t,e)=>e.is(Ea)?e.value:t,t)),provide:t=>ao.from(t)}),La=or.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:ka('')},".cm-lint-marker-warning":{content:ka('')},".cm-lint-marker-error":{content:ka('')}}),Ba=[aa,or.decorations.compute([aa],t=>{let{selected:e,panel:i}=t.field(aa);return e&&i&&e.from!=e.to?ci.set([ha.range(e.from,e.to)]):ci.none}),mo(ca,{hideOn:ia}),Ca],Ia=H.define({combine:t=>Ot(t,{hoverTime:300,markerFilter:null,tooltipFilter:null})});const Na=1024;let za=0;class qa{constructor(t,e){this.from=t,this.to=e}}class Fa{constructor(t={}){this.id=za++,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=Wa.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}Fa.closedBy=new Fa({deserialize:t=>t.split(" ")}),Fa.openedBy=new Fa({deserialize:t=>t.split(" ")}),Fa.group=new Fa({deserialize:t=>t.split(" ")}),Fa.isolate=new Fa({deserialize:t=>{if(t&&"rtl"!=t&&"ltr"!=t&&"auto"!=t)throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}}),Fa.contextHash=new Fa({perNode:!0}),Fa.lookAhead=new Fa({perNode:!0}),Fa.mounted=new Fa({perNode:!0});class Ha{constructor(t,e,i){this.tree=t,this.overlay=e,this.parser=i}static get(t){return t&&t.props&&t.props[Fa.mounted.id]}}const Va=Object.create(null);class Wa{constructor(t,e,i,n=0){this.name=t,this.props=e,this.id=i,this.flags=n}static define(t){let e=t.props&&t.props.length?Object.create(null):Va,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),n=new Wa(t.name||"",e,t.id,i);if(t.props)for(let i of t.props)if(Array.isArray(i)||(i=i(n)),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 n}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(Fa.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 n of i.split(" "))e[n]=t[i];return t=>{for(let i=t.prop(Fa.group),n=-1;n<(i?i.length:0);n++){let s=e[n<0?t.name:i[n]];if(s)return s}}}}Wa.none=new Wa("",Object.create(null),0,8);class $a{constructor(t){this.types=t;for(let e=0;e=e){let o=new Qa(r.tree,r.overlay[0].from+t.from,-1,t);(s||(s=[n])).push(Ja(o,e,i,!1))}}return s?sh(s):n}(this,t,e)}iterate(t){let{enter:e,leave:i,from:n=0,to:s=this.length}=t,r=t.mode||0,o=(r&Ka.IncludeAnonymous)>0;for(let t=this.cursor(r|Ka.IncludeAnonymous);;){let r=!1;if(t.from<=s&&t.to>=n&&(!o&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;r=!0}for(;r&&i&&(o||!t.type.isAnonymous)&&i(t),!t.nextSibling();){if(!t.parent())return;r=!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:ch(Wa.none,this.children,this.positions,0,this.children.length,0,this.length,(t,e,i)=>new Ua(this.type,t,e,i,this.propValues),t.makeTree||((t,e,i)=>new Ua(Wa.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:n,maxBufferLength:s=Na,reused:r=[],minRepeatType:o=n.types.length}=t,l=Array.isArray(i)?new Ga(i,i.length):i,a=n.types,h=0,c=0;function u(t,e,i,w,b,y){let{id:x,start:k,end:S,size:C}=l,A=c,M=h;for(;C<0;){if(l.next(),-1==C){let e=r[x];return i.push(e),void w.push(k-t)}if(-3==C)return void(h=x);if(-4==C)return void(c=x);throw new RangeError(`Unrecognized record size: ${C}`)}let T,D,O=a[x],R=k-t;if(S-k<=s&&(D=g(l.pos-e,b))){let e=new Uint16Array(D.size-D.skip),i=l.pos-D.size,s=e.length;for(;l.pos>i;)s=v(D.start,e,s);T=new Ya(e,S-D.start,n),R=D.start-t}else{let t=l.pos-C;l.next();let e=[],i=[],n=x>=o?x:-1,r=0,a=S;for(;l.pos>t;)n>=0&&l.id==n&&l.size>=0?(l.end<=a-s&&(p(e,i,k,r,l.end,a,n,A,M),r=e.length,a=l.end),l.next()):y>2500?f(k,t,e,i):u(k,t,e,i,n,y+1);if(n>=0&&r>0&&r-1&&r>0){let t=d(O,M);T=ch(O,e,i,0,e.length,0,S-k,t,t)}else T=m(O,e,i,S-k,A-S,M)}i.push(T),w.push(R)}function f(t,e,i,r){let o=[],a=0,h=-1;for(;l.pos>e;){let{id:t,start:e,end:i,size:n}=l;if(n>4)l.next();else{if(h>-1&&e=0;t-=3)e[i++]=o[t],e[i++]=o[t+1]-s,e[i++]=o[t+2]-s,e[i++]=i;i.push(new Ya(e,o[2]-s,n)),r.push(s-t)}}function d(t,e){return(i,n,s)=>{let r,o,l=0,a=i.length-1;if(a>=0&&(r=i[a])instanceof Ua){if(!a&&r.type==t&&r.length==s)return r;(o=r.prop(Fa.lookAhead))&&(l=n[a]+r.length+o)}return m(t,i,n,s,l,e)}}function p(t,e,i,s,r,o,l,a,h){let c=[],u=[];for(;t.length>s;)c.push(t.pop()),u.push(e.pop()+i-r);t.push(m(n.types[l],c,u,o-r,a-o,h)),e.push(r-i)}function m(t,e,i,n,s,r,o){if(r){let t=[Fa.contextHash,r];o=o?[t].concat(o):[t]}if(s>25){let t=[Fa.lookAhead,s];o=o?[t].concat(o):[t]}return new Ua(t,e,i,n,o)}function g(t,e){let i=l.fork(),n=0,r=0,a=0,h=i.end-s,c={size:0,start:0,skip:0};t:for(let s=i.pos-t;i.pos>s;){let t=i.size;if(i.id==e&&t>=0){c.size=n,c.start=r,c.skip=a,a+=4,n+=4,i.next();continue}let l=i.pos-t;if(t<0||l=o?4:0,f=i.start;for(i.next();i.pos>l;){if(i.size<0){if(-3!=i.size)break t;u+=4}else i.id>=o&&(u+=4);i.next()}r=f,n+=t,a+=u}return(e<0||n==t)&&(c.size=n,c.start=r,c.skip=a),c.size>4?c:void 0}function v(t,e,i){let{id:n,start:s,end:r,size:a}=l;if(l.next(),a>=0&&n4){let n=l.pos-(a-4);for(;l.pos>n;)i=v(t,e,i)}e[--i]=o,e[--i]=r-t,e[--i]=s-t,e[--i]=n}else-3==a?h=n:-4==a&&(c=n);return i}let w=[],b=[];for(;l.pos>0;)u(t.start||0,t.bufferStart||0,w,b,-1,0);let y=null!==(e=t.length)&&void 0!==e?e:w.length?b[0]+w[0].length:0;return new Ua(a[t.topID],w.reverse(),b.reverse(),y)}(t)}}Ua.empty=new Ua(Wa.none,[],[],0);class Ga{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 Ga(this.buffer,this.index)}}class Ya{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return Wa.none}toString(){let t=[];for(let e=0;e0));l=r[l+3]);return o}slice(t,e,i){let n=this.buffer,s=new Uint16Array(e-t),r=0;for(let o=t,l=0;o=e&&ie;case 1:return i<=e&&n>e;case 2:return n>e;case 4:return!0}}function Ja(t,e,i,n){for(var s;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to0?o.length:-1;t!=a;t+=e){let a=o[t],h=l[t]+r.from;if(Xa(n,i,h,h+a.length))if(a instanceof Ya){if(s&Ka.ExcludeBuffers)continue;let o=a.findChild(0,a.buffer.length,e,i-h,n);if(o>-1)return new nh(new ih(r,a,t,h),null,o)}else if(s&Ka.IncludeAnonymous||!a.type.isAnonymous||lh(a)){let o;if(!(s&Ka.IgnoreMounts)&&(o=Ha.get(a))&&!o.overlay)return new Qa(o.tree,h,t,r);let l=new Qa(a,h,t,r);return s&Ka.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(e<0?a.children.length-1:0,e,i,n)}}if(s&Ka.IncludeAnonymous||!r.type.isAnonymous)return null;if(t=r.index>=0?r.index+e:e<0?-1:r._parent._tree.children.length,r=r._parent,!r)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 n;if(!(i&Ka.IgnoreOverlays)&&(n=Ha.get(this._tree))&&n.overlay){let i=t-this.from;for(let{from:t,to:s}of n.overlay)if((e>0?t<=i:t=i:s>i))return new Qa(n.tree,n.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}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function th(t,e,i,n){let s=t.cursor(),r=[];if(!s.firstChild())return r;if(null!=i)for(let t=!1;!t;)if(t=s.type.is(i),!s.nextSibling())return r;for(;;){if(null!=n&&s.type.is(n))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return null==n?r:[]}}function eh(t,e,i=e.length-1){for(let n=t;i>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[i]&&e[i]!=n.name)return!1;i--}}return!0}class ih{constructor(t,e,i,n){this.parent=t,this.buffer=e,this.index=i,this.start=n}}class nh extends Za{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]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.context.start,i);return s<0?null:new nh(this.context,this,s)}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&Ka.ExcludeBuffers)return null;let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return s<0?null:new nh(this.context,this,s)}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 nh(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 nh(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,n=this.index+4,s=i.buffer[this.index+3];if(s>n){let r=i.buffer[this.index+1];t.push(i.slice(n,s,r)),e.push(0)}return new Ua(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function sh(t){if(!t.length)return null;let e=0,i=t[0];for(let n=1;ni.from||s.to0){if(this.index-1)for(let n=e+t,s=t<0?-1:i._tree.children.length;n!=s;n+=t){let t=i._tree.children[n];if(this.mode&Ka.IncludeAnonymous||t instanceof Ya||!t.type.isAnonymous||lh(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 r=t;r;r=r._parent)if(r.index==n){if(n==this.index)return r;e=r,i=s+1;break t}n=this.stack[--s]}for(let t=i;t=0;s--){if(s<0)return eh(this._tree,t,n);let r=i[e.buffer[this.stack[s]]];if(!r.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}}function lh(t){return t.children.some(t=>t instanceof Ya||!t.type.isAnonymous||lh(t))}const ah=new WeakMap;function hh(t,e){if(!t.isAnonymous||e instanceof Ya||e.type!=t)return 1;let i=ah.get(e);if(null==i){i=1;for(let n of e.children){if(n.type!=t||!(n instanceof Ua)){i=1;break}i+=hh(t,n)}ah.set(e,i)}return i}function ch(t,e,i,n,s,r,o,l,a){let h=0;for(let i=n;i=c)break;p+=e}if(h==s+1){if(p>c){let t=i[s];e(t.children,t.positions,0,t.children.length,n[s]+l);continue}u.push(i[s])}else{let e=n[h-1]+i[h-1].length-d;u.push(ch(t,i,n,s,h,d,e,null,a))}f.push(d+l-r)}}(e,i,n,s,0),(l||a)(u,f,o)}class uh{constructor(t,e,i,n,s=!1,r=!1){this.from=t,this.to=e,this.tree=i,this.offset=n,this.open=(s?1:0)|(r?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],i=!1){let n=[new uh(0,t.length,t,0,!1,i)];for(let i of e)i.to>t.length&&n.push(i);return n}static applyChanges(t,e,i=128){if(!e.length)return t;let n=[],s=1,r=t.length?t[0]:null;for(let o=0,l=0,a=0;;o++){let h=o=i)for(;r&&r.from=e.from||c<=e.to||a){let t=Math.max(e.from,l)-a,i=Math.min(e.to,c)-a;e=t>=i?null:new uh(t,i,e.tree,e.offset+a,o>0,!!h)}if(e&&n.push(e),r.to>c)break;r=snew qa(t.from,t.to)):[new qa(0,0)]:[new qa(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let n=this.startParse(t,e,i);for(;;){let t=n.advance();if(t)return t}}}class dh{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 Fa({perNode:!0});let ph=0;class mh{constructor(t,e,i,n){this.name=t,this.set=e,this.base=i,this.modified=n,this.id=ph++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i="string"==typeof t?t:"?";if(t instanceof mh&&(e=t),null==e?void 0:e.base)throw new Error("Can not derive from a modified tag");let n=new mh(i,[],null,[]);if(n.set.push(n),e)for(let t of e.set)n.set.push(t);return n}static defineModifier(t){let e=new vh(t);return t=>t.modified.indexOf(e)>-1?t:vh.get(t.base||t,t.modified.concat(e).sort((t,e)=>t.id-e.id))}}let gh=0;class vh{constructor(t){this.name=t,this.instances=[],this.id=gh++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(i=>{return i.base==t&&(n=e,s=i.modified,n.length==s.length&&n.every((t,e)=>t==s[e]));var n,s});if(i)return i;let n=[],s=new mh(t.name,n,t,e);for(let t of e)t.instances.push(s);let r=function(t){let e=[[]];for(let i=0;ie.length-t.length)}(e);for(let e of t.set)if(!e.modified.length)for(let t of r)n.push(vh.get(e,t));return s}}function wh(t){let e=Object.create(null);for(let i in t){let n=t[i];Array.isArray(n)||(n=[n]);for(let t of i.split(" "))if(t){let i=[],s=2,r=t;for(let e=0;;){if("..."==r&&e>0&&e+3==t.length){s=1;break}let n=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(r);if(!n)throw new RangeError("Invalid path: "+t);if(i.push("*"==n[0]?"":'"'==n[0][0]?JSON.parse(n[0]):n[0]),e+=n[0].length,e==t.length)break;let o=t[e++];if(e==t.length&&"!"==o){s=0;break}if("/"!=o)throw new RangeError("Invalid path: "+t);r=t.slice(e)}let o=i.length-1,l=i[o];if(!l)throw new RangeError("Invalid path: "+t);let a=new yh(n,s,o>0?i.slice(0,o):null);e[l]=a.sort(e[l])}}return bh.add(e)}const bh=new Fa;class yh{constructor(t,e,i,n){this.tags=t,this.mode=e,this.context=i,this.next=n}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(t){return!t||t.depth{let e=s;for(let n of t)for(let t of n.set){let n=i[t.id];if(n){e=e?e+" "+n:n;break}}return e},scope:n}}function kh(t,e,i,n=0,s=t.length){let r=new Ch(n,Array.isArray(e)?e:[e],i);r.highlightRange(t.cursor(),n,s,"",r.highlighters),r.flush(s)}function Sh(t,e,i,n,s,r=0,o=t.length){let l=r;function a(e,i){if(!(e<=l)){for(let r=t.slice(l,e),o=0;;){let t=r.indexOf("\n",o),e=t<0?r.length:t;if(e>o&&n(r.slice(o,e),i),t<0)break;s(),o=t+1}l=e}}kh(e,i,(t,e,i)=>{a(t,""),a(e,i)},r,o),a(o,"")}yh.empty=new yh([],2,null);class Ch{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,n,s){let{type:r,from:o,to:l}=t;if(o>=i||l<=e)return;r.isTop&&(s=this.highlighters.filter(t=>!t.scope||t.scope(r)));let a=n,h=function(t){let e=t.type.prop(bh);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}(t)||yh.empty,c=function(t,e){let i=null;for(let n of t){let t=n.style(e);t&&(i=i?i+" "+t:t)}return i}(s,h.tags);if(c&&(a&&(a+=" "),a+=c,1==h.mode&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(e,o),a),h.opaque)return;let u=t.tree&&t.tree.prop(Fa.mounted);if(u&&u.overlay){let r=t.node.enter(u.overlay[0].from+o,1),h=this.highlighters.filter(t=>!t.scope||t.scope(u.tree.type)),c=t.firstChild();for(let f=0,d=o;;f++){let p=f=m)&&t.nextSibling()););if(!p||m>i)break;d=p.to+o,d>e&&(this.highlightRange(r.cursor(),Math.max(e,p.from+o),Math.min(i,d),"",h),this.startSpan(Math.min(i,d),a))}c&&t.parent()}else if(t.firstChild()){u&&(n="");do{if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,n,s),this.startSpan(Math.min(i,t.to),a)}}while(t.nextSibling());t.parent()}}}const Ah=mh.define,Mh=Ah(),Th=Ah(),Dh=Ah(Th),Oh=Ah(Th),Rh=Ah(),Eh=Ah(Rh),Ph=Ah(Rh),Lh=Ah(),Bh=Ah(Lh),Ih=Ah(),Nh=Ah(),zh=Ah(),qh=Ah(zh),Fh=Ah(),Hh={comment:Mh,lineComment:Ah(Mh),blockComment:Ah(Mh),docComment:Ah(Mh),name:Th,variableName:Ah(Th),typeName:Dh,tagName:Ah(Dh),propertyName:Oh,attributeName:Ah(Oh),className:Ah(Th),labelName:Ah(Th),namespace:Ah(Th),macroName:Ah(Th),literal:Rh,string:Eh,docString:Ah(Eh),character:Ah(Eh),attributeValue:Ah(Eh),number:Ph,integer:Ah(Ph),float:Ah(Ph),bool:Ah(Rh),regexp:Ah(Rh),escape:Ah(Rh),color:Ah(Rh),url:Ah(Rh),keyword:Ih,self:Ah(Ih),null:Ah(Ih),atom:Ah(Ih),unit:Ah(Ih),modifier:Ah(Ih),operatorKeyword:Ah(Ih),controlKeyword:Ah(Ih),definitionKeyword:Ah(Ih),moduleKeyword:Ah(Ih),operator:Nh,derefOperator:Ah(Nh),arithmeticOperator:Ah(Nh),logicOperator:Ah(Nh),bitwiseOperator:Ah(Nh),compareOperator:Ah(Nh),updateOperator:Ah(Nh),definitionOperator:Ah(Nh),typeOperator:Ah(Nh),controlOperator:Ah(Nh),punctuation:zh,separator:Ah(zh),bracket:qh,angleBracket:Ah(qh),squareBracket:Ah(qh),paren:Ah(qh),brace:Ah(qh),content:Lh,heading:Bh,heading1:Ah(Bh),heading2:Ah(Bh),heading3:Ah(Bh),heading4:Ah(Bh),heading5:Ah(Bh),heading6:Ah(Bh),contentSeparator:Ah(Lh),list:Ah(Lh),quote:Ah(Lh),emphasis:Ah(Lh),strong:Ah(Lh),link:Ah(Lh),monospace:Ah(Lh),strikethrough:Ah(Lh),inserted:Ah(),deleted:Ah(),changed:Ah(),invalid:Ah(),meta:Fh,documentMeta:Ah(Fh),annotation:Ah(Fh),processingInstruction:Ah(Fh),definition:mh.defineModifier("definition"),constant:mh.defineModifier("constant"),function:mh.defineModifier("function"),standard:mh.defineModifier("standard"),local:mh.defineModifier("local"),special:mh.defineModifier("special")};for(let t in Hh){let e=Hh[t];e instanceof mh&&(e.name=t)}var Vh;xh([{tag:Hh.link,class:"tok-link"},{tag:Hh.heading,class:"tok-heading"},{tag:Hh.emphasis,class:"tok-emphasis"},{tag:Hh.strong,class:"tok-strong"},{tag:Hh.keyword,class:"tok-keyword"},{tag:Hh.atom,class:"tok-atom"},{tag:Hh.bool,class:"tok-bool"},{tag:Hh.url,class:"tok-url"},{tag:Hh.labelName,class:"tok-labelName"},{tag:Hh.inserted,class:"tok-inserted"},{tag:Hh.deleted,class:"tok-deleted"},{tag:Hh.literal,class:"tok-literal"},{tag:Hh.string,class:"tok-string"},{tag:Hh.number,class:"tok-number"},{tag:[Hh.regexp,Hh.escape,Hh.special(Hh.string)],class:"tok-string2"},{tag:Hh.variableName,class:"tok-variableName"},{tag:Hh.local(Hh.variableName),class:"tok-variableName tok-local"},{tag:Hh.definition(Hh.variableName),class:"tok-variableName tok-definition"},{tag:Hh.special(Hh.variableName),class:"tok-variableName2"},{tag:Hh.definition(Hh.propertyName),class:"tok-propertyName tok-definition"},{tag:Hh.typeName,class:"tok-typeName"},{tag:Hh.namespace,class:"tok-namespace"},{tag:Hh.className,class:"tok-className"},{tag:Hh.macroName,class:"tok-macroName"},{tag:Hh.propertyName,class:"tok-propertyName"},{tag:Hh.operator,class:"tok-operator"},{tag:Hh.comment,class:"tok-comment"},{tag:Hh.meta,class:"tok-meta"},{tag:Hh.invalid,class:"tok-invalid"},{tag:Hh.punctuation,class:"tok-punctuation"}]);const Wh=new Fa;const $h=new Fa;class _h{constructor(t,e,i=[],n=""){this.data=t,this.name=n,Dt.prototype.hasOwnProperty("tree")||Object.defineProperty(Dt.prototype,"tree",{get(){return Kh(this)}}),this.parser=e,this.extension=[ec.of(this),Dt.languageData.of((t,e,i)=>{let n=jh(t,e,i),s=n.type.prop(Wh);if(!s)return[];let r=t.facet(s),o=n.type.prop($h);if(o){let s=n.resolve(e-n.from,i);for(let e of o)if(e.test(s,t)){let i=t.facet(e.facet);return"replace"==e.type?i:i.concat(r)}}return r})].concat(i)}isActiveAt(t,e,i=-1){return jh(t,e,i).type.prop(Wh)==this.data}findRegions(t){let e=t.facet(ec);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],n=(t,e)=>{if(t.prop(Wh)==this.data)return void i.push({from:e,to:e+t.length});let s=t.prop(Fa.mounted);if(s){if(s.tree.prop(Wh)==this.data){if(s.overlay)for(let t of s.overlay)i.push({from:t.from+e,to:t.to+e});else i.push({from:e,to:e+t.length});return}if(s.overlay){let t=i.length;if(n(s.tree,s.overlay[0].from+e),i.length>t)return}}for(let i=0;i=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let Gh=null;class Yh{constructor(t,e,i=[],n,s,r,o,l){this.parser=t,this.state=e,this.fragments=i,this.tree=n,this.treeLen=s,this.viewport=r,this.skipped=o,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new Yh(t,e,[],Ua.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Uh(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=Ua.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(uh.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Gh;Gh=this;try{return t()}finally{Gh=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=Xh(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:n,treeLen:s,viewport:r,skipped:o}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges((t,i,n,s)=>e.push({fromA:t,toA:i,fromB:n,toB:s})),i=uh.applyChanges(i,e),n=Ua.empty,s=0,r={from:t.mapPos(r.from,-1),to:t.mapPos(r.to,1)},this.skipped.length){o=[];for(let e of this.skipped){let i=t.mapPos(e.from,1),n=t.mapPos(e.to,-1);it.from&&(this.fragments=Xh(this.fragments,i,n),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 fh{createParse(e,i,n){let s=n[0].from,r=n[n.length-1].to;return{parsedPos:s,advance(){let e=Gh;if(e){for(let t of n)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=r,new Ua(Wa.none,[],[],r-s)},stoppedAt:null,stopAt(){}}}}}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 Gh}}function Xh(t,e,i){return uh.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class Jh{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 Jh(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Yh.create(t.facet(ec).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Jh(i)}}_h.state=U.define({create:Jh.init,update(t,e){for(let t of e.effects)if(t.is(_h.setState))return t.value;return e.startState.facet(ec)!=e.state.facet(ec)?Jh.init(e.state):t.apply(e)}});let Zh=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(Zh=t=>{let e=-1,i=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const Qh="undefined"!=typeof navigator&&(null===(Vh=navigator.scheduling)||void 0===Vh?void 0:Vh.isInputPending)?()=>navigator.scheduling.isInputPending():null,tc=ln.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(_h.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(_h.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=Zh(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEndn+1e3,l=s.context.work(()=>Qh&&Qh()||Date.now()>r,n+(o?0:1e5));this.chunkBudget-=Date.now()-e,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:_h.setState.of(new Jh(s.context))})),this.chunkBudget>0&&(!l||o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(t=>nn(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()}}}),ec=H.define({combine:t=>t.length?t[0]:null,enables:t=>[_h.state,tc,or.contentAttributes.compute([t],e=>{let i=e.facet(t);return i&&i.name?{"data-language":i.name}:{}})]}),ic=H.define(),nc=H.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function sc(t){let e=t.facet(nc);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function rc(t,e){let i="",n=t.tabSize,s=t.facet(nc)[0];if("\t"==s){for(;e>=n;)i+="\t",e-=n;s=" "}for(let t=0;t=e?function(t,e,i){let n=e.resolveStack(i),s=e.resolveInner(i,-1).resolve(i,0).enterUnfinishedNodesBefore(i);if(s!=n.node){let t=[];for(let e=s;e&&!(e.fromn.node.to||e.from==n.node.from&&e.type==n.node.type);e=e.parent)t.push(e);for(let e=t.length-1;e>=0;e--)n={node:t[e],next:n}}return hc(n,t,i)}(t,i,e):null}class lc{constructor(t,e={}){this.state=t,this.options=e,this.unit=sc(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:n,simulateDoubleBreak:s}=this.options;return null!=n&&n>=i.from&&n<=i.to?s&&n==t?{text:"",from:t}:(e<0?n-1&&(s+=r-this.countColumn(i,i.search(/\S|$/))),s}countColumn(t,e=t.length){return Kt(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:n}=this.lineAt(t,e),s=this.options.overrideIndentation;if(s){let t=s(n);if(t>-1)return t}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const ac=new Fa;function hc(t,e,i){for(let n=t;n;n=n.next){let t=cc(n.node);if(t)return t(fc.create(e,i,n))}return 0}function cc(t){let e=t.type.prop(ac);if(e)return e;let i,n=t.firstChild;if(n&&(i=n.type.prop(Fa.closedBy))){let e=t.lastChild,n=e&&i.indexOf(e.name)>-1;return t=>function(t,e,i,n,s){let r=t.textAfter,o=r.match(/^\s*/)[0].length,l=n&&r.slice(o,o+n.length)==n||s==t.pos+o,a=function(t){let e=t.node,i=e.childAfter(e.from),n=e.lastChild;if(!i)return null;let s=t.options.simulateBreak,r=t.state.doc.lineAt(i.from),o=null==s||s<=r.from?r.to:Math.min(r.to,s);for(let t=i.to;;){let s=e.childAfter(t);if(!s||s==n)return null;if(!s.type.isSkipped){if(s.from>=o)return null;let t=/^ */.exec(r.text.slice(i.to-r.from))[0].length;return{from:i.from,to:i.to+t}}t=s.to}}(t);return a?l?t.column(a.from):t.column(a.to):t.baseIndent+(l?0:t.unit*i)}(t,0,1,void 0,n&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?uc:null}function uc(){return 0}class fc extends lc{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new fc(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(dc(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return hc(this.context.next,this.base,this.pos)}}function dc(t,e){for(let i=e;i;i=i.parent)if(t==i)return!0;return!1}const pc=H.define(),mc=new Fa;function gc(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function vc(t,e,i){for(let n of t.facet(pc)){let s=n(t,e,i);if(s)return s}return function(t,e,i){let n=Kh(t);if(n.lengthi)continue;if(s&&o.from=e&&n.to>i&&(s=n)}}return s}(t,e,i)}function wc(t,e){let i=e.mapPos(t.from,1),n=e.mapPos(t.to,-1);return i>=n?void 0:{from:i,to:n}}const bc=gt.define({map:wc}),yc=gt.define({map:wc});function xc(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 kc=U.define({create:()=>ci.none,update(t,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((e,i)=>t=Sc(t,e,i)),t=t.map(e.changes);for(let i of e.effects)if(i.is(bc)&&!Ac(t,i.value.from,i.value.to)){let{preparePlaceholder:n}=e.state.facet(Rc),s=n?ci.replace({widget:new Bc(n(e.state,i.value))}):Lc;t=t.update({add:[s.range(i.value.from,i.value.to)]})}else i.is(yc)&&(t=t.update({filter:(t,e)=>i.value.from!=t||i.value.to!=e,filterFrom:i.value.from,filterTo:i.value.to}));return e.selection&&(t=Sc(t,e.selection.main.head)),t},provide:t=>or.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{te&&(n=!0)}),n?t.update({filterFrom:e,filterTo:i,filter:(t,n)=>t>=i||n<=e}):t}function Cc(t,e,i){var n;let s=null;return null===(n=t.field(kc,!1))||void 0===n||n.between(e,i,(t,e)=>{(!s||s.from>t)&&(s={from:t,to:e})}),s}function Ac(t,e,i){let n=!1;return t.between(e,e,(t,s)=>{t==e&&s==i&&(n=!0)}),n}function Mc(t,e){return t.field(kc,!1)?e:e.concat(gt.appendConfig.of(Ec()))}function Tc(t,e,i=!0){let n=t.state.doc.lineAt(e.from).number,s=t.state.doc.lineAt(e.to).number;return or.announce.of(`${t.state.phrase(i?"Folded lines":"Unfolded lines")} ${n} ${t.state.phrase("to")} ${s}.`)}const Dc=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of xc(t)){let i=vc(t.state,e.from,e.to);if(i)return t.dispatch({effects:Mc(t.state,[bc.of(i),Tc(t,i)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(kc,!1))return!1;let e=[];for(let i of xc(t)){let n=Cc(t.state,i.from,i.to);n&&e.push(yc.of(n),Tc(t,n,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,i=[];for(let n=0;n{let e=t.state.field(kc,!1);if(!e||!e.size)return!1;let i=[];return e.between(0,t.state.doc.length,(t,e)=>{i.push(yc.of({from:t,to:e}))}),t.dispatch({effects:i}),!0}}],Oc={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Rc=H.define({combine:t=>Ot(t,Oc)});function Ec(t){return[kc,zc]}function Pc(t,e){let{state:i}=t,n=i.facet(Rc),s=e=>{let i=t.lineBlockAt(t.posAtDOM(e.target)),n=Cc(t.state,i.from,i.to);n&&t.dispatch({effects:yc.of(n)}),e.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(t,s,e);let r=document.createElement("span");return r.textContent=n.placeholderText,r.setAttribute("aria-label",i.phrase("folded code")),r.title=i.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const Lc=ci.replace({widget:new class extends ai{toDOM(t){return Pc(t,null)}}});class Bc extends ai{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return Pc(t,this.value)}}const Ic={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class Nc extends Do{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}}const zc=or.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 qc{constructor(t,e){let i;function n(t){let e=Jt.newName();return(i||(i=Object.create(null)))["."+e]=t,e}this.specs=t;const s="string"==typeof e.all?e.all:e.all?n(e.all):void 0,r=e.scope;this.scope=r instanceof _h?t=>t.prop(Wh)==r.data:r?t=>t==r:void 0,this.style=xh(t.map(t=>({tag:t.tag,class:t.class||n(Object.assign({},t,{tag:null}))})),{all:s}).style,this.module=i?new Jt(i):null,this.themeType=e.themeType}static define(t,e){return new qc(t,e||{})}}const Fc=H.define(),Hc=H.define({combine:t=>t.length?[t[0]]:null});function Vc(t){let e=t.facet(Fc);return e.length?e:t.facet(Hc)}function Wc(t,e,i){let n=Vc(t),s=null;if(n)for(let t of n)if(!t.scope||i){let i=t.style(e);i&&(s=s?s+" "+i:i)}return s}class $c{constructor(t){this.markCache=Object.create(null),this.tree=Kh(t.state),this.decorations=this.buildDeco(t,Vc(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=Kh(t.state),i=Vc(t.state),n=i!=Vc(t.startState),{viewport:s}=t.view,r=t.changes.mapPos(this.decoratedTo,1);e.length=s.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=r):(e!=this.tree||t.viewportChanged||n)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=s.to)}buildDeco(t,e){if(!e||!this.tree.length)return ci.none;let i=new It;for(let{from:n,to:s}of t.visibleRanges)kh(this.tree,e,(t,e,n)=>{i.add(t,e,this.markCache[n]||(this.markCache[n]=ci.mark({class:n})))},n,s);return i.finish()}}const _c=Q.high(ln.fromClass($c,{decorations:t=>t.decorations})),jc=qc.define([{tag:Hh.meta,color:"#404740"},{tag:Hh.link,textDecoration:"underline"},{tag:Hh.heading,textDecoration:"underline",fontWeight:"bold"},{tag:Hh.emphasis,fontStyle:"italic"},{tag:Hh.strong,fontWeight:"bold"},{tag:Hh.strikethrough,textDecoration:"line-through"},{tag:Hh.keyword,color:"#708"},{tag:[Hh.atom,Hh.bool,Hh.url,Hh.contentSeparator,Hh.labelName],color:"#219"},{tag:[Hh.literal,Hh.inserted],color:"#164"},{tag:[Hh.string,Hh.deleted],color:"#a11"},{tag:[Hh.regexp,Hh.escape,Hh.special(Hh.string)],color:"#e40"},{tag:Hh.definition(Hh.variableName),color:"#00f"},{tag:Hh.local(Hh.variableName),color:"#30a"},{tag:[Hh.typeName,Hh.namespace],color:"#085"},{tag:Hh.className,color:"#167"},{tag:[Hh.special(Hh.variableName),Hh.macroName],color:"#256"},{tag:Hh.definition(Hh.propertyName),color:"#00c"},{tag:Hh.comment,color:"#940"},{tag:Hh.invalid,color:"#f00"}]),Kc=or.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Uc="()[]{}",Gc=H.define({combine:t=>Ot(t,{afterCursor:!0,brackets:Uc,maxScanDistance:1e4,renderMatch:Jc})}),Yc=ci.mark({class:"cm-matchingBracket"}),Xc=ci.mark({class:"cm-nonmatchingBracket"});function Jc(t){let e=[],i=t.matched?Yc:Xc;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 Zc=U.define({create:()=>ci.none,update(t,e){if(!e.docChanged&&!e.selection)return t;let i=[],n=e.state.facet(Gc);for(let t of e.state.selection.ranges){if(!t.empty)continue;let s=nu(e.state,t.head,-1,n)||t.head>0&&nu(e.state,t.head-1,1,n)||n.afterCursor&&(nu(e.state,t.head,1,n)||t.heador.decorations.from(t)}),Qc=[Zc,Kc];const tu=new Fa;function eu(t,e,i){let n=t.prop(e<0?Fa.openedBy:Fa.closedBy);if(n)return n;if(1==t.name.length){let n=i.indexOf(t.name);if(n>-1&&n%2==(e<0?1:0))return[i[n+e]]}return null}function iu(t){let e=t.type.prop(tu);return e?e(t.node):t}function nu(t,e,i,n={}){let s=n.maxScanDistance||1e4,r=n.brackets||Uc,o=Kh(t),l=o.resolveInner(e,i);for(let n=l;n;n=n.parent){let s=eu(n.type,i,r);if(s&&n.from0?e>=o.from&&eo.from&&e<=o.to))return su(t,e,i,n,o,s,r)}}return function(t,e,i,n,s,r,o){let l=i<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=i>0)return null;let h={from:i<0?e-1:e,to:i>0?e+1:e},c=t.doc.iterRange(e,i>0?t.doc.length:0),u=0;for(let t=0;!c.next().done&&t<=r;){let r=c.value;i<0&&(t+=r.length);let l=e+t*i;for(let t=i>0?0:r.length-1,e=i>0?r.length:-1;t!=e;t+=i){let e=o.indexOf(r[t]);if(!(e<0||n.resolveInner(l+t,1).type!=s))if(e%2==0==i>0)u++;else{if(1==u)return{start:h,end:{from:l+t,to:l+t+1},matched:e>>1==a>>1};u--}}i>0&&(t+=r.length)}return c.done?{start:h,matched:!1}:null}(t,e,i,o,l.type,s,r)}function su(t,e,i,n,s,r,o){let l=n.parent,a={from:s.from,to:s.to},h=0,c=null==l?void 0:l.cursor();if(c&&(i<0?c.childBefore(n.from):c.childAfter(n.to)))do{if(i<0?c.to<=n.from:c.from>=n.to){if(0==h&&r.indexOf(c.type.name)>-1&&c.from=this.string.length}sol(){return 0==this.pos}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pose}eatSpace(){let t=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>t}skipToEnd(){this.pos=this.string.length}skipTo(t){let e=this.string.indexOf(t,this.pos);if(e>-1)return this.pos=e,!0}backUp(t){this.pos-=t}column(){return this.lastColumnPosi?t.toLowerCase():t;return n(this.string.substr(this.pos,t.length))==n(t)?(!1!==e&&(this.pos+=t.length),!0):null}{let i=this.string.slice(this.pos).match(t);return i&&i.index>0?null:(i&&!1!==e&&(this.pos+=i[0].length),i)}}current(){return this.string.slice(this.start,this.pos)}}function lu(t){if("object"!=typeof t)return t;let e={};for(let i in t){let n=t[i];e[i]=n instanceof Array?n.slice():n}return e}const au=new WeakMap;class hu extends _h{constructor(t){let e=(i=t.languageData,H.define({combine:i?t=>t.concat(i):void 0}));var i;let n,s={name:(r=t).name||"",token:r.token,blankLine:r.blankLine||(()=>{}),startState:r.startState||(()=>!0),copyState:r.copyState||lu,indent:r.indent||(()=>null),languageData:r.languageData||{},tokenTable:r.tokenTable||pu,mergeTokens:!1!==r.mergeTokens};var r;super(e,new class extends fh{createParse(t,e,i){return new fu(n,t,e,i)}},[],t.name),this.topNode=function(t,e){let i=Wa.define({id:mu.length,name:"Document",props:[Wh.add(()=>t),ac.add(()=>t=>e.getIndent(t))],top:!0});return mu.push(i),i}(e,this),n=this,this.streamParser=s,this.stateAfter=new Fa({perNode:!0}),this.tokenTable=t.tokenTable?new yu(s.tokenTable):xu}static define(t){return new hu(t)}getIndent(t){let e,{overrideIndentation:i}=t.options;i&&(e=au.get(t.state),null!=e&&e1e4)return null;for(;n=n&&i+e.length<=s&&e.prop(t.stateAfter);if(r)return{state:t.streamParser.copyState(r),pos:i+e.length};for(let r=e.children.length-1;r>=0;r--){let o=e.children[r],l=i+e.positions[r],a=o instanceof Ua&&l=e.length)return e;s||0!=i||e.type!=t.topNode||(s=!0);for(let r=e.children.length-1;r>=0;r--){let o,l=e.positions[r],a=e.children[r];if(li&&cu(t,s.tree,0-s.offset,i,o);if(l&&l.pos<=n&&(e=uu(t,s.tree,i+s.offset,l.pos+s.offset,!1)))return{state:l.state,tree:e}}return{state:t.streamParser.startState(s?sc(s):4),tree:Ua.empty}}(t,i,r,this.to,null==s?void 0:s.state);this.state=o,this.parsedPos=this.chunkStart=r+l.length;for(let t=0;tt.from<=s.viewport.from&&t.to>=s.viewport.from)&&(this.state=this.lang.streamParser.startState(sc(s.state)),s.skipUntilInView(this.parsedPos,s.viewport.from),this.parsedPos=s.viewport.from),this.moveRangeIndex()}advance(){let t=Yh.get(),e=null==this.stoppedAt?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(e,this.chunkStart+512);for(t&&(i=Math.min(i,t.viewport.to));this.parsedPos=e?this.finish():t&&this.parsedPos>=t.viewport.to?(t.skipUntilInView(this.parsedPos,e),this.finish()):null}stopAt(t){this.stoppedAt=t}lineAfter(t){let e=this.input.chunk(t);if(this.input.lineChunks)"\n"==e&&(e="");else{let t=e.indexOf("\n");t>-1&&(e=e.slice(0,t))}return t+e.length<=this.to?e:e.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,e=this.lineAfter(t),i=t+e.length;for(let t=this.rangeIndex;;){let n=this.ranges[t].to;if(n>=i)break;if(e=e.slice(0,n-(i-e.length)),t++,t==this.ranges.length)break;let s=this.ranges[t].from,r=this.lineAfter(s);e+=r,i=s+r.length}return{line:e,end:i}}skipGapsTo(t,e,i){for(;;){let n=this.ranges[this.rangeIndex].to,s=t+e;if(i>0?n>s:n>=s)break;e+=this.ranges[++this.rangeIndex].from-n}return e}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to1){e+=n=this.skipGapsTo(e,n,1);let t=this.chunk.length;i+=n=this.skipGapsTo(i,n,-1),s+=this.chunk.length-t}let r=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&4==s&&r>=0&&this.chunk[r]==t&&this.chunk[r+2]==e?this.chunk[r+2]=i:this.chunk.push(t,e,i,s),n}parseLine(t){let{line:e,end:i}=this.nextLine(),n=0,{streamParser:s}=this.lang,r=new ou(e,t?t.state.tabSize:4,t?sc(t.state):2);if(r.eol())s.blankLine(this.state,r.indentUnit);else for(;!r.eol();){let t=du(s.token,r,this.state);if(t&&(n=this.emitToken(this.lang.tokenTable.resolve(t),this.parsedPos+r.start,this.parsedPos+r.pos,n)),r.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPose.start)return n}throw new Error("Stream parser failed to advance stream.")}const pu=Object.create(null),mu=[Wa.none],gu=new $a(mu),vu=[],wu=Object.create(null),bu=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])bu[t]=Su(pu,e);class yu{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),bu)}resolve(t){return t?this.table[t]||(this.table[t]=Su(this.extra,t)):0}}const xu=new yu(pu);function ku(t,e){vu.indexOf(t)>-1||(vu.push(t),console.warn(e))}function Su(t,e){let i=[];for(let n of e.split(" ")){let e=[];for(let i of n.split(".")){let n=t[i]||Hh[i];n?"function"==typeof n?e.length?e=e.map(n):ku(i,`Modifier ${i} used at start of tag`):e.length?ku(i,`Tag ${i} used as modifier`):e=Array.isArray(n)?n:[n]:ku(i,`Unknown highlighting tag ${i}`)}for(let t of e)i.push(t)}if(!i.length)return 0;let n=e.replace(/ /g,"_"),s=n+" "+i.map(t=>t.id),r=wu[s];if(r)return r.id;let o=wu[s]=Wa.define({id:mu.length,name:n,props:[wh({[n]:i})]});return mu.push(o),o.id}ki.RTL,ki.LTR;function Cu(t,e){return({state:i,dispatch:n})=>{if(i.readOnly)return!1;let s=t(e,i);return!!s&&(n(i.update(s)),!0)}}const Au=Cu(Eu,0),Mu=Cu(Ru,0),Tu=Cu((t,e)=>Ru(t,e,function(t){let e=[];for(let i of t.selection.ranges){let n=t.doc.lineAt(i.from),s=i.to<=n.to?n:t.doc.lineAt(i.to);s.from>n.from&&s.from==i.to&&(s=i.to==n.to+1?n:t.doc.lineAt(i.to-1));let r=e.length-1;r>=0&&e[r].to>n.from?e[r].to=s.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:s.to})}return e}(e)),0);function Du(t,e){let i=t.languageDataAt("commentTokens",e,1);return i.length?i[0]:{}}const Ou=50;function Ru(t,e,i=e.selection.ranges){let n=i.map(t=>Du(e,t.from).block);if(!n.every(t=>t))return null;let s=i.map((t,i)=>function(t,{open:e,close:i},n,s){let r,o,l=t.sliceDoc(n-Ou,n),a=t.sliceDoc(s,s+Ou),h=/\s*$/.exec(l)[0].length,c=/^\s*/.exec(a)[0].length,u=l.length-h;if(l.slice(u-e.length,u)==e&&a.slice(c,c+i.length)==i)return{open:{pos:n-h,margin:h&&1},close:{pos:s+c,margin:c&&1}};s-n<=2*Ou?r=o=t.sliceDoc(n,s):(r=t.sliceDoc(n,n+Ou),o=t.sliceDoc(s-Ou,s));let f=/^\s*/.exec(r)[0].length,d=/\s*$/.exec(o)[0].length,p=o.length-d-i.length;return r.slice(f,f+e.length)==e&&o.slice(p,p+i.length)==i?{open:{pos:n+f+e.length,margin:/\s/.test(r.charAt(f+e.length))?1:0},close:{pos:s-d-i.length,margin:/\s/.test(o.charAt(p-1))?1:0}}:null}(e,n[i],t.from,t.to));if(2!=t&&!s.every(t=>t))return{changes:e.changes(i.map((t,e)=>s[e]?[]:[{from:t.from,insert:n[e].open+" "},{from:t.to,insert:" "+n[e].close}]))};if(1!=t&&s.some(t=>t)){let t=[];for(let e,i=0;is&&(t==r||r>a.from)){s=a.from;let t=/^\s*/.exec(a.text)[0].length,e=t==a.length,i=a.text.slice(t,t+l.length)==l?t:-1;tt.comment<0&&(!t.empty||t.single))){let t=[];for(let{line:e,token:i,indent:s,empty:r,single:o}of n)!o&&r||t.push({from:e.from+s,insert:i+" "});let i=e.changes(t);return{changes:i,selection:e.selection.map(i,1)}}if(1!=t&&n.some(t=>t.comment>=0)){let t=[];for(let{line:e,comment:i,token:s}of n)if(i>=0){let n=e.from+i,r=n+s.length;" "==e.text[r-e.from]&&r++,t.push({from:n,to:r})}return{changes:t}}return null}const Pu=dt.define(),Lu=dt.define(),Bu=H.define(),Iu=H.define({combine:t=>Ot(t,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,n)=>t(i,n)||e(i,n)})}),Nu=U.define({create:()=>Zu.empty,update(t,e){let i=e.state.facet(Iu),n=e.annotation(Pu);if(n){let s=Wu.fromTransaction(e,n.selection),r=n.side,o=0==r?t.undone:t.done;return o=s?$u(o,o.length,i.minDepth,s):Uu(o,e.startState.selection),new Zu(0==r?n.rest:o,0==r?o:n.rest)}let s=e.annotation(Lu);if("full"!=s&&"before"!=s||(t=t.isolate()),!1===e.annotation(vt.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let r=Wu.fromTransaction(e),o=e.annotation(vt.time),l=e.annotation(vt.userEvent);return r?t=t.addChanges(r,o,l,i,e):e.selection&&(t=t.addSelection(e.startState.selection,o,l,i.newGroupDelay)),"full"!=s&&"after"!=s||(t=t.isolate()),t},toJSON:t=>({done:t.done.map(t=>t.toJSON()),undone:t.undone.map(t=>t.toJSON())}),fromJSON:t=>new Zu(t.done.map(Wu.fromJSON),t.undone.map(Wu.fromJSON))});function zu(t,e){return function({state:i,dispatch:n}){if(!e&&i.readOnly)return!1;let s=i.field(Nu,!1);if(!s)return!1;let r=s.pop(t,i,e);return!!r&&(n(r),!0)}}const qu=zu(0,!1),Fu=zu(1,!1),Hu=zu(0,!0),Vu=zu(1,!0);class Wu{constructor(t,e,i,n,s){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=n,this.selectionsAfter=s}setSelAfter(t){return new Wu(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 Wu(t.changes&&O.fromJSON(t.changes),[],t.mapped&&D.fromJSON(t.mapped),t.startSelection&&z.fromJSON(t.startSelection),t.selectionsAfter.map(z.fromJSON))}static fromTransaction(t,e){let i=ju;for(let e of t.startState.facet(Bu)){let n=e(t);n.length&&(i=i.concat(n))}return!i.length&&t.changes.empty?null:new Wu(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,ju)}static selection(t){return new Wu(void 0,ju,void 0,void 0,t)}}function $u(t,e,i,n){let s=e+1>i+20?e-i-1:0,r=t.slice(s,e);return r.push(n),r}function _u(t,e){return t.length?e.length?t.concat(e):t:e}const ju=[],Ku=200;function Uu(t,e){if(t.length){let i=t[t.length-1],n=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-Ku));return n.length&&n[n.length-1].eq(e)?t:(n.push(e),$u(t,t.length-1,1e9,i.setSelAfter(n)))}return[Wu.selection([e])]}function Gu(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 Yu(t,e){if(!t.length)return t;let i=t.length,n=ju;for(;i;){let s=Xu(t[i-1],e,n);if(s.changes&&!s.changes.empty||s.effects.length){let e=t.slice(0,i);return e[i-1]=s,e}e=s.mapped,i--,n=s.selectionsAfter}return n.length?[Wu.selection(n)]:ju}function Xu(t,e,i){let n=_u(t.selectionsAfter.length?t.selectionsAfter.map(t=>t.map(e)):ju,i);if(!t.changes)return Wu.selection(n);let s=t.changes.map(e),r=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(r):r;return new Wu(s,gt.mapEffects(t.effects,e),o,t.startSelection.map(r),n)}const Ju=/^(input\.type|delete)($|\.)/;class Zu{constructor(t,e,i=0,n=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new Zu(this.done,this.undone):this}addChanges(t,e,i,n,s){let r=this.done,o=r[r.length-1];return r=o&&o.changes&&!o.changes.empty&&t.changes&&(!i||Ju.test(i))&&(!o.selectionsAfter.length&&e-this.prevTimei.push(t,e)),e.iterChangedRanges((t,e,s,r)=>{for(let t=0;t=e&&s<=o&&(n=!0)}}),n}(o.changes,t.changes))||"input.type.compose"==i)?$u(r,r.length-1,n.minDepth,new Wu(t.changes.compose(o.changes),_u(gt.mapEffects(t.effects,o.changes),o.effects),o.mapped,o.startSelection,ju)):$u(r,r.length,n.minDepth,t),new Zu(r,ju,e,i)}addSelection(t,e,i,n){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:ju;return s.length>0&&e-this.prevTimet.empty!=o.ranges[e].empty).length)?this:new Zu(Uu(this.done,t),this.undone,e,i);var r,o}addMapping(t){return new Zu(Yu(this.done,t),Yu(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let n=0==t?this.done:this.undone;if(0==n.length)return null;let s=n[n.length-1],r=s.selectionsAfter[0]||e.selection;if(i&&s.selectionsAfter.length)return e.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Pu.of({side:t,rest:Gu(n),selection:r}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let i=1==n.length?ju:n.slice(0,n.length-1);return s.mapped&&(i=Yu(i,s.mapped)),e.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Pu.of({side:t,rest:i,selection:r}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}Zu.empty=new Zu(ju,ju);const Qu=[{key:"Mod-z",run:qu,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Fu,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Fu,preventDefault:!0},{key:"Mod-u",run:Hu,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Vu,preventDefault:!0}];function tf(t,e){return z.create(t.ranges.map(e),t.mainIndex)}function ef(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function nf({state:t,dispatch:e},i){let n=tf(t.selection,i);return!n.eq(t.selection,!0)&&(e(ef(t,n)),!0)}function sf(t,e){return z.cursor(e?t.to:t.from)}function rf(t,e){return nf(t,i=>i.empty?t.moveByChar(i,e):sf(i,e))}function of(t){return t.textDirectionAt(t.state.selection.main.head)==ki.LTR}const lf=t=>rf(t,!of(t)),af=t=>rf(t,of(t));function hf(t,e){return nf(t,i=>i.empty?t.moveByGroup(i,e):sf(i,e))}function cf(t,e,i){if(e.type.prop(i))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function uf(t,e,i){let n,s,r=Kh(t).resolveInner(e.head),o=i?Fa.closedBy:Fa.openedBy;for(let n=e.head;;){let e=i?r.childAfter(n):r.childBefore(n);if(!e)break;cf(t,e,o)?r=e:n=i?e.to:e.from}return s=r.type.prop(o)&&(n=i?nu(t,r.from,1):nu(t,r.to,-1))&&n.matched?i?n.end.to:n.end.from:i?r.to:r.from,z.cursor(s,i?-1:1)}function ff(t,e){return nf(t,i=>{if(!i.empty)return sf(i,e);let n=t.moveVertically(i,e);return n.head!=i.head?n:t.moveToLineBoundary(i,e)})}const df=t=>ff(t,!1),pf=t=>ff(t,!0);function mf(t){let e,i=t.scrollDOM.clientHeighti.empty?t.moveVertically(i,e,n.height):sf(i,e));if(r.eq(s.selection))return!1;if(n.selfScroll){let e=t.coordsAtPos(s.selection.main.head),o=t.scrollDOM.getBoundingClientRect(),l=o.top+n.marginTop,a=o.bottom-n.marginBottom;e&&e.top>l&&e.bottomgf(t,!1),wf=t=>gf(t,!0);function bf(t,e,i){let n=t.lineBlockAt(e.head),s=t.moveToLineBoundary(e,i);if(s.head==e.head&&s.head!=(i?n.to:n.from)&&(s=t.moveToLineBoundary(e,i,!1)),!i&&s.head==n.from&&n.length){let i=/^\s*/.exec(t.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;i&&e.head!=n.from+i&&(s=z.cursor(n.from+i))}return s}function yf(t,e){let i=tf(t.state.selection,t=>{let i=e(t);return z.range(t.anchor,i.head,i.goalColumn,i.bidiLevel||void 0)});return!i.eq(t.state.selection)&&(t.dispatch(ef(t.state,i)),!0)}function xf(t,e){return yf(t,i=>t.moveByChar(i,e))}const kf=t=>xf(t,!of(t)),Sf=t=>xf(t,of(t));function Cf(t,e){return yf(t,i=>t.moveByGroup(i,e))}function Af(t,e){return yf(t,i=>t.moveVertically(i,e))}const Mf=t=>Af(t,!1),Tf=t=>Af(t,!0);function Df(t,e){return yf(t,i=>t.moveVertically(i,e,mf(t).height))}const Of=t=>Df(t,!1),Rf=t=>Df(t,!0),Ef=({state:t,dispatch:e})=>(e(ef(t,{anchor:0})),!0),Pf=({state:t,dispatch:e})=>(e(ef(t,{anchor:t.doc.length})),!0),Lf=({state:t,dispatch:e})=>(e(ef(t,{anchor:t.selection.main.anchor,head:0})),!0),Bf=({state:t,dispatch:e})=>(e(ef(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function If(t,e){if(t.state.readOnly)return!1;let i="delete.selection",{state:n}=t,s=n.changeByRange(n=>{let{from:s,to:r}=n;if(s==r){let o=e(n);os&&(i="delete.forward",o=Nf(t,o,!0)),s=Math.min(s,o),r=Math.max(r,o)}else s=Nf(t,s,!1),r=Nf(t,r,!0);return s==r?{range:n}:{changes:{from:s,to:r},range:z.cursor(s,se(t)))n.between(e,e,(t,n)=>{te&&(e=i?n:t)});return e}const zf=(t,e,i)=>If(t,n=>{let s,r,o=n.from,{state:l}=t,a=l.doc.lineAt(o);if(i&&!e&&o>a.from&&ozf(t,!1,!0),Ff=t=>zf(t,!0,!1),Hf=(t,e)=>If(t,i=>{let n=i.head,{state:s}=t,r=s.doc.lineAt(n),o=s.charCategorizer(n);for(let t=null;;){if(n==(e?r.to:r.from)){n==i.head&&r.number!=(e?s.doc.lines:1)&&(n+=e?1:-1);break}let l=k(r.text,n-r.from,e)+r.from,a=r.text.slice(Math.min(n,l)-r.from,Math.max(n,l)-r.from),h=o(a);if(null!=t&&h!=t)break;" "==a&&n==i.head||(t=h),n=l}return n}),Vf=t=>Hf(t,!1);function Wf(t){let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.from),r=t.doc.lineAt(n.to);if(n.empty||n.to!=r.from||(r=t.doc.lineAt(n.to-1)),i>=s.number){let t=e[e.length-1];t.to=r.to,t.ranges.push(n)}else e.push({from:s.from,to:r.to,ranges:[n]});i=r.number+1}return e}function $f(t,e,i){if(t.readOnly)return!1;let n=[],s=[];for(let e of Wf(t)){if(i?e.to==t.doc.length:0==e.from)continue;let r=t.doc.lineAt(i?e.to+1:e.from-1),o=r.length+1;if(i){n.push({from:e.to,to:r.to},{from:e.from,insert:r.text+t.lineBreak});for(let i of e.ranges)s.push(z.range(Math.min(t.doc.length,i.anchor+o),Math.min(t.doc.length,i.head+o)))}else{n.push({from:r.from,to:e.from},{from:e.to,insert:t.lineBreak+r.text});for(let t of e.ranges)s.push(z.range(t.anchor-o,t.head-o))}}return!!n.length&&(e(t.update({changes:n,scrollIntoView:!0,selection:z.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0)}function _f(t,e,i){if(t.readOnly)return!1;let n=[];for(let e of Wf(t))i?n.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):n.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});return e(t.update({changes:n,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const jf=Kf(!1);function Kf(t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let n=e.changeByRange(i=>{let{from:n,to:s}=i,r=e.doc.lineAt(n),o=!t&&n==s&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,n=Kh(t).resolveInner(e),s=n.childBefore(e),r=n.childAfter(e);return s&&r&&s.to<=e&&r.from>=e&&(i=s.type.prop(Fa.closedBy))&&i.indexOf(r.name)>-1&&t.doc.lineAt(s.to).from==t.doc.lineAt(r.from).from&&!/\S/.test(t.sliceDoc(s.to,r.from))?{from:s.to,to:r.from}:null}(e,n);t&&(n=s=(s<=r.to?r:e.doc.lineAt(s)).to);let l=new lc(e,{simulateBreak:n,simulateDoubleBreak:!!o}),a=oc(l,n);for(null==a&&(a=Kt(/^\s*/.exec(e.doc.lineAt(n).text)[0],e.tabSize));sr.from&&n{let s=[];for(let r=n.from;r<=n.to;){let o=t.doc.lineAt(r);o.number>i&&(n.empty||n.to>o.from)&&(e(o,s,n),i=o.number),r=o.to+1}let r=t.changes(s);return{changes:s,range:z.range(r.mapPos(n.anchor,1),r.mapPos(n.head,1))}})}const Gf=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:t=>nf(t,e=>uf(t.state,e,!of(t))),shift:t=>yf(t,e=>uf(t.state,e,!of(t)))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>nf(t,e=>uf(t.state,e,of(t))),shift:t=>yf(t,e=>uf(t.state,e,of(t)))},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>$f(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>_f(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>$f(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>_f(t,e,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,n=null;return i.ranges.length>1?n=z.create([i.main]):i.main.empty||(n=z.create([z.cursor(i.main.head)])),!!n&&(e(ef(t,n)),!0)}},{key:"Mod-Enter",run:Kf(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=Wf(t).map(({from:e,to:i})=>z.range(e,Math.min(i+1,t.doc.length)));return e(t.update({selection:z.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=tf(t.selection,e=>{let i=Kh(t),n=i.resolveStack(e.from,1);if(e.empty){let t=i.resolveStack(e.from,-1);t.node.from>=n.node.from&&t.node.to<=n.node.to&&(n=t)}for(let t=n;t;t=t.next){let{node:i}=t;if((i.from=e.to||i.to>e.to&&i.from<=e.from)&&t.next)return z.range(i.to,i.from)}return e});return!i.eq(t.selection)&&(e(ef(t,i)),!0)},preventDefault:!0},{key:"Mod-[",run:({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Uf(t,(e,i)=>{let n=/^\s*/.exec(e.text)[0];if(!n)return;let s=Kt(n,t.tabSize),r=0,o=rc(t,Math.max(0,s-sc(t)));for(;r!t.readOnly&&(e(t.update(Uf(t,(e,i)=>{i.push({from:e.from,insert:t.facet(nc)})}),{userEvent:"input.indent"})),!0)},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),n=new lc(t,{overrideIndentation:t=>{let e=i[t];return null==e?-1:e}}),s=Uf(t,(e,s,r)=>{let o=oc(n,e.from);if(null==o)return;/\S/.test(e.text)||(o=0);let l=/^\s*/.exec(e.text)[0],a=rc(t,o);(l!=a||r.from{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes(Wf(e).map(({from:t,to:i})=>(t>0?t--:i{let i;if(t.lineWrapping){let n=t.lineBlockAt(e.head),s=t.coordsAtPos(e.head,e.assoc||1);s&&(i=n.bottom+t.documentTop-s.bottom+t.defaultLineHeight/2)}return t.moveVertically(e,!0,i)}).map(i);return t.dispatch({changes:i,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>function(t,e){let i=!1,n=tf(t.selection,e=>{let n=nu(t,e.head,-1)||nu(t,e.head,1)||e.head>0&&nu(t,e.head-1,1)||e.head{let{state:e}=t,i=e.doc.lineAt(e.selection.main.from),n=Du(t.state,i.from);return n.line?Au(t):!!n.block&&Tu(t)}},{key:"Alt-A",run:Mu},{key:"Ctrl-m",mac:"Shift-Alt-m",run:t=>(t.setTabFocusMode(),!0)}].concat([{key:"ArrowLeft",run:lf,shift:kf,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:t=>hf(t,!of(t)),shift:t=>Cf(t,!of(t)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:t=>nf(t,e=>bf(t,e,!of(t))),shift:t=>yf(t,e=>bf(t,e,!of(t))),preventDefault:!0},{key:"ArrowRight",run:af,shift:Sf,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>hf(t,of(t)),shift:t=>Cf(t,of(t)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:t=>nf(t,e=>bf(t,e,of(t))),shift:t=>yf(t,e=>bf(t,e,of(t))),preventDefault:!0},{key:"ArrowUp",run:df,shift:Mf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Ef,shift:Lf},{mac:"Ctrl-ArrowUp",run:vf,shift:Of},{key:"ArrowDown",run:pf,shift:Tf,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Pf,shift:Bf},{mac:"Ctrl-ArrowDown",run:wf,shift:Rf},{key:"PageUp",run:vf,shift:Of},{key:"PageDown",run:wf,shift:Rf},{key:"Home",run:t=>nf(t,e=>bf(t,e,!1)),shift:t=>yf(t,e=>bf(t,e,!1)),preventDefault:!0},{key:"Mod-Home",run:Ef,shift:Lf},{key:"End",run:t=>nf(t,e=>bf(t,e,!0)),shift:t=>yf(t,e=>bf(t,e,!0)),preventDefault:!0},{key:"Mod-End",run:Pf,shift:Bf},{key:"Enter",run:jf,shift:jf},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:qf,shift:qf},{key:"Delete",run:Ff},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Vf},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>Hf(t,!0)},{mac:"Mod-Backspace",run:t=>If(t,e=>{let i=t.moveToLineBoundary(e,!1).head;return e.head>i?i:Math.max(0,e.head-1)})},{mac:"Mod-Delete",run:t=>If(t,e=>{let i=t.moveToLineBoundary(e,!0).head;return e.headnf(t,e=>z.cursor(t.lineBlockAt(e.head).from,1)),shift:t=>yf(t,e=>z.cursor(t.lineBlockAt(e.head).from))},{key:"Ctrl-e",run:t=>nf(t,e=>z.cursor(t.lineBlockAt(e.head).to,-1)),shift:t=>yf(t,e=>z.cursor(t.lineBlockAt(e.head).to))},{key:"Ctrl-d",run:Ff},{key:"Ctrl-h",run:qf},{key:"Ctrl-k",run:t=>If(t,e=>{let i=t.lineBlockAt(e.head).to;return e.head{if(t.readOnly)return!1;let i=t.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:f.of(["",""])},range:z.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,n=t.doc.lineAt(i),s=i==n.from?i-1:k(n.text,i-n.from,!1)+n.from,r=i==n.to?i+1:k(n.text,i-n.from,!0)+n.from;return{changes:{from:s,to:r,insert:t.doc.slice(i,r).append(t.doc.slice(s,i))},range:z.cursor(r)}});return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:wf}].map(t=>({mac:t.key,run:t.run,shift:t.shift}))));class Yf{constructor(t,e,i,n){this.state=t,this.pos=e,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let e=Kh(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),n=e.text.slice(i-e.from,this.pos-e.from),s=n.search(td(t,!1));return s<0?null:{from:i+s,to:this.pos,text:n.slice(s)}}get aborted(){return null==this.abortListeners}addEventListener(t,e,i){"abort"==t&&this.abortListeners&&(this.abortListeners.push(e),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function Xf(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 Jf(t){let e=t.map(t=>"string"==typeof t?{label:t}:t),[i,n]=e.every(t=>/^\w+$/.test(t.label))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),i=Object.create(null);for(let{label:n}of t){e[n[0]]=!0;for(let t=1;t{let s=t.matchBefore(n);return s||t.explicit?{from:s?s.from:t.pos,options:e,validFor:i}:null}}class Zf{constructor(t,e,i,n){this.completion=t,this.source=e,this.match=i,this.score=n}}function Qf(t){return t.selection.main.from}function td(t,e){var i;let{source:n}=t,s=e&&"^"!=n[0],r="$"!=n[n.length-1];return s||r?new RegExp(`${s?"^":""}(?:${n})${r?"$":""}`,null!==(i=t.flags)&&void 0!==i?i:t.ignoreCase?"i":""):t}const ed=dt.define();const id=new WeakMap;function nd(t){if(!Array.isArray(t))return t;let e=id.get(t);return e||id.set(t,e=Jf(t)),e}const sd=gt.define(),rd=gt.define();class od{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e=48&&a<=57||a>=97&&a<=122?2:a>=65&&a<=90?1:0:(w=C(a))!=w.toLowerCase()?1:w!=w.toUpperCase()?2:0;(!n||1==b&&m||0==v&&0!=b)&&(e[c]==a||i[c]==a&&(u=!0)?r[c++]=n:r.length&&(g=!1)),v=b,n+=A(a)}return c==l&&0==r[0]&&g?this.result((u?-200:0)-100,r,t):f==l&&0==d?this.ret(-200-t.length+(p==t.length?0:-100),[0,p]):o>-1?this.ret(-700-t.length,[o,o+this.pattern.length]):f==l?this.ret(-900-t.length,[d,p]):c==l?this.result((u?-200:0)-100-700+(g?0:-1100),r,t):2==e.length?null:this.result((n[0]?-700:0)-200-1100,n,t)}result(t,e,i){let n=[],s=0;for(let t of e){let e=t+(this.astral?A(S(i,t)):1);s&&n[s-1]==t?n[s-1]=e:(n[s++]=t,n[s++]=e)}return this.ret(t-i.length,n)}}class ld{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.lengthOt(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:cd,filterStrict:!1,compareCompletions:(t,e)=>t.label.localeCompare(e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>hd(t(i),e(i)),optionClass:(t,e)=>i=>hd(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})});function hd(t,e){return t?e?t+" "+e:t:e}function cd(t,e,i,n,s,r){let o,l,a=t.textDirection==ki.RTL,h=a,c=!1,u="top",f=e.left-s.left,d=s.right-e.right,p=n.right-n.left,m=n.bottom-n.top;if(h&&f=m||t>e.top?o=i.bottom-e.top:(u="bottom",o=e.bottom-i.top)}return{style:`${u}: ${o/((e.bottom-e.top)/r.offsetHeight)}px; max-width: ${l/((e.right-e.left)/r.offsetWidth)}px`,class:"cm-completionInfo-"+(c?a?"left-narrow":"right-narrow":h?"left":"right")}}function ud(t,e,i){if(t<=i)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/i);return{from:t*i,to:(t+1)*i}}let n=Math.floor((t-e)/i);return{from:t-(n+1)*i,to:t-n*i}}class fd{constructor(t,e,i){this.view=t,this.stateField=e,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let n=t.state.field(e),{options:s,selected:r}=n.open,o=t.state.facet(ad);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,n){let s=document.createElement("span");s.className="cm-completionLabel";let r=t.displayLabel||t.label,o=0;for(let t=0;to&&s.appendChild(document.createTextNode(r.slice(o,e)));let l=s.appendChild(document.createElement("span"));l.appendChild(document.createTextNode(r.slice(e,i))),l.className="cm-completionMatchedText",o=i}return ot.position-e.position).map(t=>t.render)}(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=ud(s.length,r,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",i=>{let{options:n}=t.state.field(e).open;for(let e,s=i.target;s&&s!=this.dom;s=s.parentNode)if("LI"==s.nodeName&&(e=/-(\d+)$/.exec(s.id))&&+e[1]{let i=t.state.field(this.stateField,!1);i&&i.tooltip&&t.state.facet(ad).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:rd.of(null)})}),this.showOptions(s,n.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),n=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=n){let{options:s,selected:r,disabled:o}=i.open;n.open&&n.open.options==s||(this.range=ud(s.length,r,t.state.facet(ad).maxRenderedOptions),this.showOptions(s,i.id)),this.updateSel(),o!=(null===(e=n.open)||void 0===e?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!o)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected>-1&&e.selected=this.range.to)&&(this.range=ud(e.options.length,e.selected,this.view.state.facet(ad).maxRenderedOptions),this.showOptions(e.options,t.id)),this.updateSelectedOption(e.selected)){this.destroyInfo();let{completion:i}=e.options[e.selected],{info:n}=i;if(!n)return;let s="string"==typeof n?document.createTextNode(n):n(i);if(!s)return;"then"in s?s.then(e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e,i)}).catch(t=>nn(this.view.state,t,"completion info")):this.addInfoPane(s,i)}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",null!=t.nodeType)i.appendChild(t),this.infoDestroy=null;else{let{dom:e,destroy:n}=t;i.appendChild(e),this.infoDestroy=n||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)"LI"==i.nodeName&&i.id?n==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected"):n--;return e&&function(t,e){let i=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=i.height/t.offsetHeight;n.topi.bottom&&(t.scrollTop+=(n.bottom-i.bottom)/s)}(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(),n=t.getBoundingClientRect(),s=this.space;if(!s){let t=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:t.clientWidth,bottom:t.clientHeight}}return n.top>Math.min(s.bottom,e.bottom)-10||n.bottom{t.target==n&&t.preventDefault()});let s=null;for(let r=i.from;ri.from||0==i.from))if(s=t,"string"!=typeof a&&a.header)n.appendChild(a.header(a));else{n.appendChild(document.createElement("completion-section")).textContent=t}}const h=n.appendChild(document.createElement("li"));h.id=e+"-"+r,h.setAttribute("role","option");let c=this.optionClass(o);c&&(h.className=c);for(let t of this.optionContent){let e=t(o,this.view.state,this.view,l);e&&h.appendChild(e)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.tonew fd(i,t,e)}function pd(t){return 100*(t.boost||0)+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}class md{constructor(t,e,i,n,s,r){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=n,this.selected=s,this.disabled=r}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new md(this.options,bd(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,n,s,r){if(n&&!r&&t.some(t=>t.isPending))return n.setDisabled();let o=function(t,e){let i=[],n=null,s=t=>{i.push(t);let{section:e}=t.completion;if(e){n||(n=[]);let t="string"==typeof e?e:e.name;n.some(e=>e.name==t)||n.push("string"==typeof e?{name:t}:e)}},r=e.facet(ad);for(let n of t)if(n.hasResult()){let t=n.result.getMatch;if(!1===n.result.filter)for(let e of n.result.options)s(new Zf(e,n.source,t?t(e):[],1e9-i.length));else{let i,o=e.sliceDoc(n.from,n.to),l=r.filterStrict?new ld(o):new od(o);for(let e of n.result.options)if(i=l.match(e.label)){let r=e.displayLabel?t?t(e,i.matched):[]:i.matched;s(new Zf(e,n.source,r,i.score+(e.boost||0)))}}}if(n){let t=Object.create(null),e=0,s=(t,e)=>{var i,n;return(null!==(i=t.rank)&&void 0!==i?i:1e9)-(null!==(n=e.rank)&&void 0!==n?n:1e9)||(t.namee.score-t.score||a(t.completion,e.completion))){let e=t.completion;!l||l.label!=e.label||l.detail!=e.detail||null!=l.type&&null!=e.type&&l.type!=e.type||l.apply!=e.apply||l.boost!=e.boost?o.push(t):pd(t.completion)>pd(l)&&(o[o.length-1]=t),l=t.completion}return o}(t,e);if(!o.length)return n&&t.some(t=>t.isPending)?n.setDisabled():null;let l=e.facet(ad).selectOnOpen?0:-1;if(n&&n.selected!=l&&-1!=n.selected){let t=n.options[n.selected].completion;for(let e=0;ee.hasResult()?Math.min(t,e.from):t,1e8),create:Dd,above:s.aboveCursor},n?n.timestamp:Date.now(),l,!1)}map(t){return new md(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}setDisabled(){return new md(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class gd{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new gd(yd,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,i=e.facet(ad),n=(i.override||e.languageDataAt("autocomplete",Qf(e)).map(nd)).map(e=>(this.active.find(t=>t.source==e)||new kd(e,this.active.some(t=>0!=t.state)?1:0)).update(t,i));n.length==this.active.length&&n.every((t,e)=>t==this.active[e])&&(n=this.active);let s=this.open,r=t.effects.some(t=>t.is(Cd));s&&t.docChanged&&(s=s.map(t.changes)),t.selection||n.some(e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to))||!function(t,e){if(t==e)return!0;for(let i=0,n=0;;){for(;it.isPending)&&(s=null),!s&&n.every(t=>!t.isPending)&&n.some(t=>t.hasResult())&&(n=n.map(t=>t.hasResult()?new kd(t.source,0):t));for(let e of t.effects)e.is(Ad)&&(s=s&&s.setSelected(e.value,this.id));return n==this.active&&s==this.open?this:new gd(n,this.id,s)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?vd:wd}}const vd={"aria-autocomplete":"list"},wd={};function bd(t,e){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(i["aria-activedescendant"]=t+"-"+e),i}const yd=[];function xd(t,e){if(t.isUserEvent("input.complete")){let i=t.annotation(ed);if(i&&e.activateOnCompletion(i))return 12}let i=t.isUserEvent("input.type");return i&&e.activateOnTyping?5:i?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class kd{constructor(t,e,i=!1){this.source=t,this.state=e,this.explicit=i}hasResult(){return!1}get isPending(){return 1==this.state}update(t,e){let i=xd(t,e),n=this;(8&i||16&i&&this.touches(t))&&(n=new kd(n.source,0)),4&i&&0==n.state&&(n=new kd(this.source,1)),n=n.updateFor(t,i);for(let e of t.effects)if(e.is(sd))n=new kd(n.source,1,e.value);else if(e.is(rd))n=new kd(n.source,0);else if(e.is(Cd))for(let t of e.value)t.source==n.source&&(n=t);return n}updateFor(t,e){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(Qf(t.state))}}class Sd extends kd{constructor(t,e,i,n,s,r){super(t,3,e),this.limit=i,this.result=n,this.from=s,this.to=r}hasResult(){return!0}updateFor(t,e){var i;if(!(3&e))return this.map(t.changes);let n=this.result;n.map&&!t.changes.empty&&(n=n.map(n,t.changes));let s=t.changes.mapPos(this.from),r=t.changes.mapPos(this.to,1),o=Qf(t.state);if(o>r||!n||2&e&&(Qf(t.startState)==this.from||ot.map(t=>t.map(e))}),Ad=gt.define(),Md=U.define({create:()=>gd.start(),update:(t,e)=>t.update(e),provide:t=>[ao.from(t,t=>t.tooltip),or.contentAttributes.from(t,t=>t.attrs)]});function Td(t,e){const i=e.completion.apply||e.completion.label;let n=t.state.field(Md).active.find(t=>t.source==e.source);return n instanceof Sd&&("string"==typeof i?t.dispatch(Object.assign(Object.assign({},function(t,e,i,n){let{main:s}=t.selection,r=i-s.from,o=n-s.from;return Object.assign(Object.assign({},t.changeByRange(l=>{if(l!=s&&i!=n&&t.sliceDoc(l.from+r,l.from+o)!=t.sliceDoc(i,n))return{range:l};let a=t.toText(e);return{changes:{from:l.from+r,to:n==s.from?l.to:l.from+o,insert:a},range:z.cursor(l.from+r+a.length)}})),{scrollIntoView:!0,userEvent:"input.complete"})}(t.state,i,n.from,n.to)),{annotations:ed.of(e.completion)})):i(t,e.completion,n.from,n.to),!0)}const Dd=dd(Md,Td);function Od(t,e="option"){return i=>{let n=i.state.field(Md,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp-1?n.open.selected+r*(t?1:-1):t?0:o-1;return l<0?l="page"==e?0:o-1:l>=o&&(l="page"==e?o-1:0),i.dispatch({effects:Ad.of(l)}),!0}}const Rd=t=>!!t.state.field(Md,!1)&&(t.dispatch({effects:sd.of(!0)}),!0);class Ed{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const Pd=ln.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(Md).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(Md),i=t.state.facet(ad);if(!t.selectionSet&&!t.docChanged&&t.startState.field(Md)==e)return;let n=t.transactions.some(t=>{let e=xd(t,i);return 8&e||(t.selection||t.docChanged)&&!(3&e)});for(let e=0;e50&&Date.now()-i.time>1e3){for(let t of i.context.abortListeners)try{t()}catch(t){nn(this.view.state,t)}i.context.abortListeners=null,this.running.splice(e--,1)}else i.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(t=>t.effects.some(t=>t.is(sd)))&&(this.pendingStart=!0);let s=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(t=>t.isPending&&!this.running.some(e=>e.active.source==t.source))?setTimeout(()=>this.startUpdate(),s):-1,0!=this.composing)for(let e of t.transactions)e.isUserEvent("input.type")?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(Md);for(let t of e.active)t.isPending&&!this.running.some(e=>e.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ad).updateSyncTime))}startQuery(t){let{state:e}=this.view,i=Qf(e),n=new Yf(e,i,t.explicit,this.view),s=new Ed(t,n);this.running.push(s),Promise.resolve(t.source(n)).then(t=>{s.context.aborted||(s.done=t||null,this.scheduleAccept())},t=>{this.view.dispatch({effects:rd.of(null)}),nn(this.view.state,t)})}scheduleAccept(){this.running.every(t=>void 0!==t.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ad).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],i=this.view.state.facet(ad),n=this.view.state.field(Md);for(let s=0;st.source==r.active.source);if(o&&o.isPending)if(null==r.done){let t=new kd(r.active.source,0);for(let e of r.updates)t=t.update(e,i);t.isPending||e.push(t)}else this.startQuery(o)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:Cd.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(Md,!1);if(e&&e.tooltip&&this.view.state.facet(ad).closeOnBlur){let i=e.open&&go(this.view,e.open.tooltip);i&&i.dom.contains(t.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:rd.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:sd.of(!1)}),20),this.composing=0}}}),Ld="object"==typeof navigator&&/Win/.test(navigator.platform),Bd=Q.highest(or.domEventHandlers({keydown(t,e){let i=e.state.field(Md,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||t.key.length>1||t.ctrlKey&&(!Ld||!t.altKey)||t.metaKey)return!1;let n=i.open.options[i.open.selected],s=i.active.find(t=>t.source==n.source),r=n.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(t.key)>-1&&Td(e,n),!1}})),Id=or.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",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".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:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",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",boxSizing:"content-box"},".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"}}});class Nd{constructor(t,e,i,n){this.field=t,this.line=e,this.from=i,this.to=n}}class zd{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,T.TrackDel),i=t.mapPos(this.to,1,T.TrackDel);return null==e||null==i?null:new zd(this.field,e,i)}}class qd{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],n=[e],s=t.doc.lineAt(e),r=/^\s*/.exec(s.text)[0];for(let s of this.lines){if(i.length){let i=r,o=/^\t*/.exec(s)[0].length;for(let e=0;enew zd(t.field,n[t.line]+t.from,n[t.line]+t.to));return{text:i,ranges:o}}static parse(t){let e,i=[],n=[],s=[];for(let r of t.split(/\r\n?|\n/)){for(;e=/[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(r);){let t=e[1]?+e[1]:null,o=e[2]||e[3]||"",l=-1,a=o.replace(/\\[{}]/g,t=>t[1]);for(let e=0;e=l&&t.field++}s.push(new Nd(l,n.length,e.index,e.index+a.length)),r=r.slice(0,e.index)+o+r.slice(e.index+e[0].length)}r=r.replace(/\\([{}])/g,(t,e,i)=>{for(let t of s)t.line==n.length&&t.from>i&&(t.from--,t.to--);return e}),n.push(r)}return new qd(n,s)}}let Fd=ci.widget({widget:new class extends ai{toDOM(){let t=document.createElement("span");return t.className="cm-snippetFieldPosition",t}ignoreEvent(){return!1}}}),Hd=ci.mark({class:"cm-snippetField"});class Vd{constructor(t,e){this.ranges=t,this.active=e,this.deco=ci.set(t.map(t=>(t.from==t.to?Fd:Hd).range(t.from,t.to)))}map(t){let e=[];for(let i of this.ranges){let n=i.map(t);if(!n)return null;e.push(n)}return new Vd(e,this.active)}selectionInsideField(t){return t.ranges.every(t=>this.ranges.some(e=>e.field==this.active&&e.from<=t.from&&e.to>=t.to))}}const Wd=gt.define({map:(t,e)=>t&&t.map(e)}),$d=gt.define(),_d=U.define({create:()=>null,update(t,e){for(let i of e.effects){if(i.is(Wd))return i.value;if(i.is($d)&&t)return new Vd(t.ranges,i.value)}return t&&e.docChanged&&(t=t.map(e.changes)),t&&e.selection&&!t.selectionInsideField(e.selection)&&(t=null),t},provide:t=>or.decorations.from(t,t=>t?t.deco:ci.none)});function jd(t,e){return z.create(t.filter(t=>t.field==e).map(t=>z.range(t.from,t.to)))}function Kd(t){return({state:e,dispatch:i})=>{let n=e.field(_d,!1);if(!n||t<0&&0==n.active)return!1;let s=n.active+t,r=t>0&&!n.ranges.some(e=>e.field==s+t);return i(e.update({selection:jd(n.ranges,s),effects:Wd.of(r?null:new Vd(n.ranges,s)),scrollIntoView:!0})),!0}}const Ud=[{key:"Tab",run:Kd(1),shift:Kd(-1)},{key:"Escape",run:({state:t,dispatch:e})=>!!t.field(_d,!1)&&(e(t.update({effects:Wd.of(null)})),!0)}],Gd=H.define({combine:t=>t.length?t[0]:Ud}),Yd=Q.highest(pr.compute([Gd],t=>t.facet(Gd))),Xd=or.domEventHandlers({mousedown(t,e){let i,n=e.state.field(_d,!1);if(!n||null==(i=e.posAtCoords({x:t.clientX,y:t.clientY})))return!1;let s=n.ranges.find(t=>t.from<=i&&t.to>=i);return!(!s||s.field==n.active)&&(e.dispatch({selection:jd(n.ranges,s.field),effects:Wd.of(n.ranges.some(t=>t.field>s.field)?new Vd(n.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Jd={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Zd=gt.define({map(t,e){let i=e.mapPos(t,-1,T.TrackAfter);return null==i?void 0:i}}),Qd=new class extends Rt{};Qd.startSide=1,Qd.endSide=-1;const tp=U.define({create:()=>Bt.empty,update(t,e){if(t=t.map(e.changes),e.selection){let i=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:t=>t>=i.from&&t<=i.to})}for(let i of e.effects)i.is(Zd)&&(t=t.update({add:[Qd.range(i.value,i.value+1)]}));return t}});const ep="()[]{}<>«»»«[]{}";function ip(t){for(let e=0;e<16;e+=2)if(ep.charCodeAt(e)==t)return ep.charAt(e+1);return C(t<128?t:t+1)}function np(t,e){return t.languageDataAt("closeBrackets",e)[0]||Jd}const sp="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),rp=or.inputHandler.of((t,e,i,n)=>{if((sp?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let s=t.state.selection.main;if(n.length>2||2==n.length&&1==A(S(n,0))||e!=s.from||i!=s.to)return!1;let r=function(t,e){let i=np(t,t.selection.main.head),n=i.brackets||Jd.brackets;for(let s of n){let r=ip(S(s,0));if(e==s)return r==s?up(t,s,n.indexOf(s+s+s)>-1,i):hp(t,s,r,i.before||Jd.before);if(e==r&&lp(t,t.selection.main.from))return cp(t,s,r)}return null}(t.state,n);return!!r&&(t.dispatch(r),!0)}),op=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=np(t,t.selection.main.head).brackets||Jd.brackets,n=null,s=t.changeByRange(e=>{if(e.empty){let n=function(t,e){let i=t.sliceString(e-2,e);return A(S(i,0))==i.length?i:i.slice(1)}(t.doc,e.head);for(let s of i)if(s==n&&ap(t.doc,e.head)==ip(S(s,0)))return{changes:{from:e.head-s.length,to:e.head+s.length},range:z.cursor(e.head-s.length)}}return{range:n=e}});return n||e(t.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!n}}];function lp(t,e){let i=!1;return t.field(tp).between(0,t.doc.length,t=>{t==e&&(i=!0)}),i}function ap(t,e){let i=t.sliceString(e,e+2);return i.slice(0,A(S(i,0)))}function hp(t,e,i,n){let s=null,r=t.changeByRange(r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:i,from:r.to}],effects:Zd.of(r.to+e.length),range:z.range(r.anchor+e.length,r.head+e.length)};let o=ap(t.doc,r.head);return!o||/\s/.test(o)||n.indexOf(o)>-1?{changes:{insert:e+i,from:r.head},effects:Zd.of(r.head+e.length),range:z.cursor(r.head+e.length)}:{range:s=r}});return s?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function cp(t,e,i){let n=null,s=t.changeByRange(e=>e.empty&&ap(t.doc,e.head)==i?{changes:{from:e.head,to:e.head+i.length,insert:i},range:z.cursor(e.head+i.length)}:n={range:e});return n?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function up(t,e,i,n){let s=n.stringPrefixes||Jd.stringPrefixes,r=null,o=t.changeByRange(n=>{if(!n.empty)return{changes:[{insert:e,from:n.from},{insert:e,from:n.to}],effects:Zd.of(n.to+e.length),range:z.range(n.anchor+e.length,n.head+e.length)};let o,l=n.head,a=ap(t.doc,l);if(a==e){if(fp(t,l))return{changes:{insert:e+e,from:l},effects:Zd.of(l+e.length),range:z.cursor(l+e.length)};if(lp(t,l)){let n=i&&t.sliceDoc(l,l+3*e.length)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+n.length,insert:n},range:z.cursor(l+n.length)}}}else{if(i&&t.sliceDoc(l-2*e.length,l)==e+e&&(o=dp(t,l-2*e.length,s))>-1&&fp(t,o))return{changes:{insert:e+e+e+e,from:l},effects:Zd.of(l+e.length),range:z.cursor(l+e.length)};if(t.charCategorizer(l)(a)!=Ct.Word&&dp(t,l,s)>-1&&!function(t,e,i,n){let s=Kh(t).resolveInner(e,-1),r=n.reduce((t,e)=>Math.max(t,e.length),0);for(let o=0;o<5;o++){let o=t.sliceDoc(s.from,Math.min(s.to,s.from+i.length+r)),l=o.indexOf(i);if(!l||l>-1&&n.indexOf(o.slice(0,l))>-1){let e=s.firstChild;for(;e&&e.from==s.from&&e.to-e.from>i.length+l;){if(t.sliceDoc(e.to-i.length,e.to)==i)return!1;e=e.firstChild}return!0}let a=s.to==e&&s.parent;if(!a)break;s=a}return!1}(t,l,e,s))return{changes:{insert:e+e,from:l},effects:Zd.of(l+e.length),range:z.cursor(l+e.length)}}return{range:r=n}});return r?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fp(t,e){let i=Kh(t).resolveInner(e+1);return i.parent&&i.from==e}function dp(t,e,i){let n=t.charCategorizer(e);if(n(t.sliceDoc(e-1,e))!=Ct.Word)return e;for(let s of i){let i=e-s.length;if(t.sliceDoc(i,e)==s&&n(t.sliceDoc(i-1,i))!=Ct.Word)return i}return-1}function pp(t={}){return[Bd,Md,ad.of(t),Pd,gp,Id]}const mp=[{key:"Ctrl-Space",run:Rd},{mac:"Alt-`",run:Rd},{key:"Escape",run:t=>{let e=t.state.field(Md,!1);return!(!e||!e.active.some(t=>0!=t.state))&&(t.dispatch({effects:rd.of(null)}),!0)}},{key:"ArrowDown",run:Od(!0)},{key:"ArrowUp",run:Od(!1)},{key:"PageDown",run:Od(!0,"page")},{key:"PageUp",run:Od(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field(Md,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampt.facet(ad).defaultKeymap?[mp]:[]));function vp(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var wp={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function bp(t){wp=t}var yp={exec:()=>null};function xp(t,e=""){let i="string"==typeof t?t:t.source;const n={replace:(t,e)=>{let s="string"==typeof e?e:e.source;return s=s.replace(kp.caret,"$1"),i=i.replace(t,s),n},getRegex:()=>new RegExp(i,e)};return n}var kp={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},Sp=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Cp=/(?:[*+-]|\d{1,9}[.)])/,Ap=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Mp=xp(Ap).replace(/bull/g,Cp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Tp=xp(Ap).replace(/bull/g,Cp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Dp=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Op=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Rp=xp(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Op).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ep=xp(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Cp).getRegex(),Pp="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Lp=/|$))/,Bp=xp("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",Lp).replace("tag",Pp).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ip=xp(Dp).replace("hr",Sp).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",Pp).getRegex(),Np={blockquote:xp(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ip).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:Rp,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:Sp,html:Bp,lheading:Mp,list:Ep,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:Ip,table:yp,text:/^[^\n]+/},zp=xp("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Sp).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",Pp).getRegex(),qp={...Np,lheading:Tp,table:zp,paragraph:xp(Dp).replace("hr",Sp).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",zp).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",Pp).getRegex()},Fp={...Np,html:xp("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",Lp).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:yp,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:xp(Dp).replace("hr",Sp).replace("heading"," *#{1,6} *[^\n]").replace("lheading",Mp).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Hp=/^( {2,}|\\)\n(?!\s*$)/,Vp=/[\p{P}\p{S}]/u,Wp=/[\s\p{P}\p{S}]/u,$p=/[^\s\p{P}\p{S}]/u,_p=xp(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Wp).getRegex(),jp=/(?!~)[\p{P}\p{S}]/u,Kp=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Up=xp(Kp,"u").replace(/punct/g,Vp).getRegex(),Gp=xp(Kp,"u").replace(/punct/g,jp).getRegex(),Yp="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Xp=xp(Yp,"gu").replace(/notPunctSpace/g,$p).replace(/punctSpace/g,Wp).replace(/punct/g,Vp).getRegex(),Jp=xp(Yp,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,jp).getRegex(),Zp=xp("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,$p).replace(/punctSpace/g,Wp).replace(/punct/g,Vp).getRegex(),Qp=xp(/\\(punct)/,"gu").replace(/punct/g,Vp).getRegex(),tm=xp(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),em=xp(Lp).replace("(?:--\x3e|$)","--\x3e").getRegex(),im=xp("^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^").replace("comment",em).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),nm=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,sm=xp(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",nm).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),rm=xp(/^!?\[(label)\]\[(ref)\]/).replace("label",nm).replace("ref",Op).getRegex(),om=xp(/^!?\[(ref)\](?:\[\])?/).replace("ref",Op).getRegex(),lm={_backpedal:yp,anyPunctuation:Qp,autolink:tm,blockSkip:/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,br:Hp,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:yp,emStrongLDelim:Up,emStrongRDelimAst:Xp,emStrongRDelimUnd:Zp,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:sm,nolink:om,punctuation:_p,reflink:rm,reflinkSearch:xp("reflink|nolink(?!\\()","g").replace("reflink",rm).replace("nolink",om).getRegex(),tag:im,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\":">",'"':""","'":"'"},pm=t=>dm[t];function mm(t,e){if(e){if(kp.escapeTest.test(t))return t.replace(kp.escapeReplace,pm)}else if(kp.escapeTestNoEncode.test(t))return t.replace(kp.escapeReplaceNoEncode,pm);return t}function gm(t){try{t=encodeURI(t).replace(kp.percentDecode,"%")}catch{return null}return t}function vm(t,e){const i=t.replace(kp.findPipe,(t,e,i)=>{let n=!1,s=e;for(;--s>=0&&"\\"===i[s];)n=!n;return n?"|":" |"}).split(kp.splitPipe);let n=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),e)if(i.length>e)i.splice(e);else for(;i.length0)return{type:"space",raw:e[0]}}code(t){const e=this.rules.block.code.exec(t);if(e){const t=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?t:wm(t,"\n")}}}fences(t){const e=this.rules.block.fences.exec(t);if(e){const t=e[0],i=function(t,e,i){const n=t.match(i.other.indentCodeCompensation);if(null===n)return e;const s=n[1];return e.split("\n").map(t=>{const e=t.match(i.other.beginningSpace);if(null===e)return t;const[n]=e;return n.length>=s.length?t.slice(s.length):t}).join("\n")}(t,e[3]||"",this.rules);return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:i}}}heading(t){const e=this.rules.block.heading.exec(t);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){const e=wm(t,"#");this.options.pedantic?t=e.trim():e&&!this.rules.other.endingSpaceChar.test(e)||(t=e.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(t){const e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:wm(e[0],"\n")}}blockquote(t){const e=this.rules.block.blockquote.exec(t);if(e){let t=wm(e[0],"\n").split("\n"),i="",n="";const s=[];for(;t.length>0;){let e=!1;const r=[];let o;for(o=0;o1,s={type:"list",raw:"",ordered:n,start:n?+i.slice(0,-1):"",loose:!1,items:[]};i=n?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=n?i:"[*+-]");const r=this.rules.other.listItemRegex(i);let o=!1;for(;t;){let i=!1,n="",l="";if(!(e=r.exec(t)))break;if(this.rules.block.hr.test(t))break;n=e[0],t=t.substring(n.length);let a=e[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,t=>" ".repeat(3*t.length)),h=t.split("\n",1)[0],c=!a.trim(),u=0;if(this.options.pedantic?(u=2,l=a.trimStart()):c?u=e[1].length+1:(u=e[2].search(this.rules.other.nonSpaceChar),u=u>4?1:u,l=a.slice(u),u+=e[1].length),c&&this.rules.other.blankLine.test(h)&&(n+=h+"\n",t=t.substring(h.length+1),i=!0),!i){const e=this.rules.other.nextBulletRegex(u),i=this.rules.other.hrRegex(u),s=this.rules.other.fencesBeginRegex(u),r=this.rules.other.headingBeginRegex(u),o=this.rules.other.htmlBeginRegex(u);for(;t;){const f=t.split("\n",1)[0];let d;if(h=f,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),d=h):d=h.replace(this.rules.other.tabCharGlobal," "),s.test(h))break;if(r.test(h))break;if(o.test(h))break;if(e.test(h))break;if(i.test(h))break;if(d.search(this.rules.other.nonSpaceChar)>=u||!h.trim())l+="\n"+d.slice(u);else{if(c)break;if(a.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4)break;if(s.test(a))break;if(r.test(a))break;if(i.test(a))break;l+="\n"+h}c||h.trim()||(c=!0),n+=f+"\n",t=t.substring(f.length+1),a=d.slice(u)}}s.loose||(o?s.loose=!0:this.rules.other.doubleBlankLine.test(n)&&(o=!0));let f,d=null;this.options.gfm&&(d=this.rules.other.listIsTask.exec(l),d&&(f="[ ] "!==d[0],l=l.replace(this.rules.other.listReplaceTask,""))),s.items.push({type:"list_item",raw:n,task:!!d,checked:f,loose:!1,text:l,tokens:[]}),s.raw+=n}const l=s.items.at(-1);if(!l)return;l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd(),s.raw=s.raw.trimEnd();for(let t=0;t"space"===t.type),i=e.length>0&&e.some(t=>this.rules.other.anyLine.test(t.raw));s.loose=i}if(s.loose)for(let t=0;t({text:t,tokens:this.lexer.inline(t),header:!1,align:r.align[e]})));return r}}lheading(t){const e=this.rules.block.lheading.exec(t);if(e)return{type:"heading",raw:e[0],depth:"="===e[2].charAt(0)?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(t){const e=this.rules.block.paragraph.exec(t);if(e){const t="\n"===e[1].charAt(e[1].length-1)?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(t){const e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){const e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){const e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){const e=this.rules.inline.link.exec(t);if(e){const t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;const e=wm(t.slice(0,-1),"\\");if((t.length-e.length)%2==0)return}else{const t=function(t,e){if(-1===t.indexOf(e[1]))return-1;let i=0;for(let n=0;n0?-2:-1}(e[2],"()");if(-2===t)return;if(t>-1){const i=(0===e[0].indexOf("!")?5:4)+e[1].length+t;e[2]=e[2].substring(0,t),e[0]=e[0].substring(0,i).trim(),e[3]=""}}let i=e[2],n="";if(this.options.pedantic){const t=this.rules.other.pedanticHrefTitle.exec(i);t&&(i=t[1],n=t[3])}else n=e[3]?e[3].slice(1,-1):"";return i=i.trim(),this.rules.other.startAngleBracket.test(i)&&(i=this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?i.slice(1):i.slice(1,-1)),bm(e,{href:i?i.replace(this.rules.inline.anyPunctuation,"$1"):i,title:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n},e[0],this.lexer,this.rules)}}reflink(t,e){let i;if((i=this.rules.inline.reflink.exec(t))||(i=this.rules.inline.nolink.exec(t))){const t=e[(i[2]||i[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!t){const t=i[0].charAt(0);return{type:"text",raw:t,text:t}}return bm(i,t,i[0],this.lexer,this.rules)}}emStrong(t,e,i=""){let n=this.rules.inline.emStrongLDelim.exec(t);if(!n)return;if(n[3]&&i.match(this.rules.other.unicodeAlphaNumeric))return;if(!(n[1]||n[2]||"")||!i||this.rules.inline.punctuation.exec(i)){const i=[...n[0]].length-1;let s,r,o=i,l=0;const a="*"===n[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(a.lastIndex=0,e=e.slice(-1*t.length+i);null!=(n=a.exec(e));){if(s=n[1]||n[2]||n[3]||n[4]||n[5]||n[6],!s)continue;if(r=[...s].length,n[3]||n[4]){o+=r;continue}if((n[5]||n[6])&&i%3&&!((i+r)%3)){l+=r;continue}if(o-=r,o>0)continue;r=Math.min(r,r+o+l);const e=[...n[0]][0].length,a=t.slice(0,i+n.index+e+r);if(Math.min(i,r)%2){const t=a.slice(1,-1);return{type:"em",raw:a,text:t,tokens:this.lexer.inlineTokens(t)}}const h=a.slice(2,-2);return{type:"strong",raw:a,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){const e=this.rules.inline.code.exec(t);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," ");const i=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return i&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(t){const e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t){const e=this.rules.inline.del.exec(t);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(t){const e=this.rules.inline.autolink.exec(t);if(e){let t,i;return"@"===e[2]?(t=e[1],i="mailto:"+t):(t=e[1],i=t),{type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let t,i;if("@"===e[2])t=e[0],i="mailto:"+t;else{let n;do{n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??""}while(n!==e[0]);t=e[0],i="www."===e[1]?"http://"+e[0]:e[0]}return{type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(t){const e=this.rules.inline.text.exec(t);if(e){const t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},xm=class t{tokens;options;state;tokenizer;inlineQueue;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||wp,this.options.tokenizer=this.options.tokenizer||new ym,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const e={other:kp,block:um.normal,inline:fm.normal};this.options.pedantic?(e.block=um.pedantic,e.inline=fm.pedantic):this.options.gfm&&(e.block=um.gfm,this.options.breaks?e.inline=fm.breaks:e.inline=fm.gfm),this.tokenizer.rules=e}static get rules(){return{block:um,inline:fm}}static lex(e,i){return new t(i).lex(e)}static lexInline(e,i){return new t(i).inlineTokens(e)}lex(t){t=t.replace(kp.carriageReturn,"\n"),this.blockTokens(t,this.tokens);for(let t=0;t!!(n=i.call({lexer:this},t,e))&&(t=t.substring(n.raw.length),e.push(n),!0)))continue;if(n=this.tokenizer.space(t)){t=t.substring(n.raw.length);const i=e.at(-1);1===n.raw.length&&void 0!==i?i.raw+="\n":e.push(n);continue}if(n=this.tokenizer.code(t)){t=t.substring(n.raw.length);const i=e.at(-1);"paragraph"===i?.type||"text"===i?.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.text,this.inlineQueue.at(-1).src=i.text):e.push(n);continue}if(n=this.tokenizer.fences(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.heading(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.hr(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.blockquote(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.list(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.html(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.def(t)){t=t.substring(n.raw.length);const i=e.at(-1);"paragraph"===i?.type||"text"===i?.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.raw,this.inlineQueue.at(-1).src=i.text):this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title});continue}if(n=this.tokenizer.table(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.lheading(t)){t=t.substring(n.raw.length),e.push(n);continue}let s=t;if(this.options.extensions?.startBlock){let e=1/0;const i=t.slice(1);let n;this.options.extensions.startBlock.forEach(t=>{n=t.call({lexer:this},i),"number"==typeof n&&n>=0&&(e=Math.min(e,n))}),e<1/0&&e>=0&&(s=t.substring(0,e+1))}if(this.state.top&&(n=this.tokenizer.paragraph(s))){const r=e.at(-1);i&&"paragraph"===r?.type?(r.raw+="\n"+n.raw,r.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):e.push(n),i=s.length!==t.length,t=t.substring(n.raw.length);continue}if(n=this.tokenizer.text(t)){t=t.substring(n.raw.length);const i=e.at(-1);"text"===i?.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):e.push(n);continue}if(t){const e="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(e);break}throw new Error(e)}}return this.state.top=!0,e}inline(t,e=[]){return this.inlineQueue.push({src:t,tokens:e}),e}inlineTokens(t,e=[]){let i=t,n=null;if(this.tokens.links){const t=Object.keys(this.tokens.links);if(t.length>0)for(;null!=(n=this.tokenizer.rules.inline.reflinkSearch.exec(i));)t.includes(n[0].slice(n[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(n=this.tokenizer.rules.inline.anyPunctuation.exec(i));)i=i.slice(0,n.index)+"++"+i.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(n=this.tokenizer.rules.inline.blockSkip.exec(i));)i=i.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let s=!1,r="";for(;t;){let n;if(s||(r=""),s=!1,this.options.extensions?.inline?.some(i=>!!(n=i.call({lexer:this},t,e))&&(t=t.substring(n.raw.length),e.push(n),!0)))continue;if(n=this.tokenizer.escape(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.tag(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.link(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(n.raw.length);const i=e.at(-1);"text"===n.type&&"text"===i?.type?(i.raw+=n.raw,i.text+=n.text):e.push(n);continue}if(n=this.tokenizer.emStrong(t,i,r)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.codespan(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.br(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.del(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.autolink(t)){t=t.substring(n.raw.length),e.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(t))){t=t.substring(n.raw.length),e.push(n);continue}let o=t;if(this.options.extensions?.startInline){let e=1/0;const i=t.slice(1);let n;this.options.extensions.startInline.forEach(t=>{n=t.call({lexer:this},i),"number"==typeof n&&n>=0&&(e=Math.min(e,n))}),e<1/0&&e>=0&&(o=t.substring(0,e+1))}if(n=this.tokenizer.inlineText(o)){t=t.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(r=n.raw.slice(-1)),s=!0;const i=e.at(-1);"text"===i?.type?(i.raw+=n.raw,i.text+=n.text):e.push(n);continue}if(t){const e="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(e);break}throw new Error(e)}}return e}},km=class{options;parser;constructor(t){this.options=t||wp}space(t){return""}code({text:t,lang:e,escaped:i}){const n=(e||"").match(kp.notSpaceStart)?.[0],s=t.replace(kp.endingNewline,"")+"\n";return n?'
'+(i?s:mm(s,!0))+"
\n":"
"+(i?s:mm(s,!0))+"
\n"}blockquote({tokens:t}){return`
\n${this.parser.parse(t)}
\n`}html({text:t}){return t}heading({tokens:t,depth:e}){return`${this.parser.parseInline(t)}\n`}hr(t){return"
\n"}list(t){const e=t.ordered,i=t.start;let n="";for(let e=0;e\n"+n+"\n"}listitem(t){let e="";if(t.task){const i=this.checkbox({checked:!!t.checked});t.loose?"paragraph"===t.tokens[0]?.type?(t.tokens[0].text=i+" "+t.tokens[0].text,t.tokens[0].tokens&&t.tokens[0].tokens.length>0&&"text"===t.tokens[0].tokens[0].type&&(t.tokens[0].tokens[0].text=i+" "+mm(t.tokens[0].tokens[0].text),t.tokens[0].tokens[0].escaped=!0)):t.tokens.unshift({type:"text",raw:i+" ",text:i+" ",escaped:!0}):e+=i+" "}return e+=this.parser.parse(t.tokens,!!t.loose),`
  • ${e}
  • \n`}checkbox({checked:t}){return"'}paragraph({tokens:t}){return`

    ${this.parser.parseInline(t)}

    \n`}table(t){let e="",i="";for(let e=0;e${n}`),"\n\n"+e+"\n"+n+"
    \n"}tablerow({text:t}){return`\n${t}\n`}tablecell(t){const e=this.parser.parseInline(t.tokens),i=t.header?"th":"td";return(t.align?`<${i} align="${t.align}">`:`<${i}>`)+e+`\n`}strong({tokens:t}){return`${this.parser.parseInline(t)}`}em({tokens:t}){return`${this.parser.parseInline(t)}`}codespan({text:t}){return`${mm(t,!0)}`}br(t){return"
    "}del({tokens:t}){return`${this.parser.parseInline(t)}`}link({href:t,title:e,tokens:i}){const n=this.parser.parseInline(i),s=gm(t);if(null===s)return n;let r='
    ",r}image({href:t,title:e,text:i,tokens:n}){n&&(i=this.parser.parseInline(n,this.parser.textRenderer));const s=gm(t);if(null===s)return mm(i);let r=`${i}{const s=t[n].flat(1/0);i=i.concat(this.walkTokens(s,e))}):t.tokens&&(i=i.concat(this.walkTokens(t.tokens,e)))}}return i}use(...t){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(t=>{const i={...t};if(i.async=this.defaults.async||i.async||!1,t.extensions&&(t.extensions.forEach(t=>{if(!t.name)throw new Error("extension name required");if("renderer"in t){const i=e.renderers[t.name];e.renderers[t.name]=i?function(...e){let n=t.renderer.apply(this,e);return!1===n&&(n=i.apply(this,e)),n}:t.renderer}if("tokenizer"in t){if(!t.level||"block"!==t.level&&"inline"!==t.level)throw new Error("extension level must be 'block' or 'inline'");const i=e[t.level];i?i.unshift(t.tokenizer):e[t.level]=[t.tokenizer],t.start&&("block"===t.level?e.startBlock?e.startBlock.push(t.start):e.startBlock=[t.start]:"inline"===t.level&&(e.startInline?e.startInline.push(t.start):e.startInline=[t.start]))}"childTokens"in t&&t.childTokens&&(e.childTokens[t.name]=t.childTokens)}),i.extensions=e),t.renderer){const e=this.defaults.renderer||new km(this.defaults);for(const i in t.renderer){if(!(i in e))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;const n=i,s=t.renderer[n],r=e[n];e[n]=(...t)=>{let i=s.apply(e,t);return!1===i&&(i=r.apply(e,t)),i||""}}i.renderer=e}if(t.tokenizer){const e=this.defaults.tokenizer||new ym(this.defaults);for(const i in t.tokenizer){if(!(i in e))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;const n=i,s=t.tokenizer[n],r=e[n];e[n]=(...t)=>{let i=s.apply(e,t);return!1===i&&(i=r.apply(e,t)),i}}i.tokenizer=e}if(t.hooks){const e=this.defaults.hooks||new Am;for(const i in t.hooks){if(!(i in e))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;const n=i,s=t.hooks[n],r=e[n];Am.passThroughHooks.has(i)?e[n]=t=>{if(this.defaults.async)return Promise.resolve(s.call(e,t)).then(t=>r.call(e,t));const i=s.call(e,t);return r.call(e,i)}:e[n]=(...t)=>{let i=s.apply(e,t);return!1===i&&(i=r.apply(e,t)),i}}i.hooks=e}if(t.walkTokens){const e=this.defaults.walkTokens,n=t.walkTokens;i.walkTokens=function(t){let i=[];return i.push(n.call(this,t)),e&&(i=i.concat(e.call(this,t))),i}}this.defaults={...this.defaults,...i}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return xm.lex(t,e??this.defaults)}parser(t,e){return Cm.parse(t,e??this.defaults)}parseMarkdown(t){return(e,i)=>{const n={...i},s={...this.defaults,...n},r=this.onError(!!s.silent,!!s.async);if(!0===this.defaults.async&&!1===n.async)return r(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(null==e)return r(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof e)return r(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));s.hooks&&(s.hooks.options=s,s.hooks.block=t);const o=s.hooks?s.hooks.provideLexer():t?xm.lex:xm.lexInline,l=s.hooks?s.hooks.provideParser():t?Cm.parse:Cm.parseInline;if(s.async)return Promise.resolve(s.hooks?s.hooks.preprocess(e):e).then(t=>o(t,s)).then(t=>s.hooks?s.hooks.processAllTokens(t):t).then(t=>s.walkTokens?Promise.all(this.walkTokens(t,s.walkTokens)).then(()=>t):t).then(t=>l(t,s)).then(t=>s.hooks?s.hooks.postprocess(t):t).catch(r);try{s.hooks&&(e=s.hooks.preprocess(e));let t=o(e,s);s.hooks&&(t=s.hooks.processAllTokens(t)),s.walkTokens&&this.walkTokens(t,s.walkTokens);let i=l(t,s);return s.hooks&&(i=s.hooks.postprocess(i)),i}catch(t){return r(t)}}}onError(t,e){return i=>{if(i.message+="\nPlease report this to https://github.com/markedjs/marked.",t){const t="

    An error occurred:

    "+mm(i.message+"",!0)+"
    ";return e?Promise.resolve(t):t}if(e)return Promise.reject(i);throw i}}},Tm=new Mm;function Dm(t,e){return Tm.parse(t,e)}Dm.options=Dm.setOptions=function(t){return Tm.setOptions(t),Dm.defaults=Tm.defaults,bp(Dm.defaults),Dm},Dm.getDefaults=vp,Dm.defaults=wp,Dm.use=function(...t){return Tm.use(...t),Dm.defaults=Tm.defaults,bp(Dm.defaults),Dm},Dm.walkTokens=function(t,e){return Tm.walkTokens(t,e)},Dm.parseInline=Tm.parseInline,Dm.Parser=Cm,Dm.parser=Cm.parse,Dm.Renderer=km,Dm.TextRenderer=Sm,Dm.Lexer=xm,Dm.lexer=xm.lex,Dm.Tokenizer=ym,Dm.Hooks=Am,Dm.parse=Dm,Dm.options,Dm.setOptions,Dm.use,Dm.walkTokens,Dm.parseInline,Cm.parse,xm.lex;let Om=null;const Rm=new Mm({walkTokens(t){if(!Om||"code"!=t.type)return;let e=Om.language&&Om.language(t.lang);if(!e){let i=Om.view.state.facet(ec);i&&i.name==t.lang&&(e=i)}if(!e)return;let i={style:t=>Wc(Om.view.state,t)},n="";Sh(t.text,e.parser.parse(t.text),i,(t,e)=>{n+=e?`${Em(t)}`:Em(t)},()=>{n+="
    "}),t.escaped=!0,t.text=n}});function Em(t){return t.replace(/[\n<&]/g,t=>"\n"==t?"
    ":"<"==t?"<":"&")}function Pm(t,e){let i=t.lineAt(e);return{line:i.number-1,character:e-i.from}}function Lm(t,e){return t.line(e.line+1).from+e.character}class Bm{constructor(t,{client:e,uri:i,languageID:n}){if(this.view=t,this.client=e,this.uri=i,!n){let e=t.state.facet(ec);n=e?e.name:""}e.workspace.openFile(i,n,t),this.syncedDoc=t.state.doc,this.unsyncedChanges=O.empty(t.state.doc.length)}docToHTML(t,e="plaintext"){let i=function(t,e,i){let n=Om;try{return Om={view:t,language:e},i()}finally{Om=n}}(this.view,this.client.config.highlightLanguage,()=>function(t,e){let i=e,n=t;return"string"!=typeof n&&(i=n.kind,n=n.value),"plaintext"==i?Em(n):Rm.parse(n,{async:!1})}(t,e));return this.client.config.sanitizeHTML?this.client.config.sanitizeHTML(i):i}toPosition(t,e=this.view.state.doc){return Pm(e,t)}fromPosition(t,e=this.view.state.doc){return Lm(e,t)}reportError(t,e){Co(this.view,{label:this.view.state.phrase(t)+": "+(e.message||e),class:"cm-lsp-message cm-lsp-message-error",top:!0})}clear(){this.syncedDoc=this.view.state.doc,this.unsyncedChanges=O.empty(this.view.state.doc.length)}update(t){t.docChanged&&(this.unsyncedChanges=this.unsyncedChanges.compose(t.changes))}destroy(){this.client.workspace.closeFile(this.uri,this.view)}static get(t){return t.plugin(Im)}static create(t,e,i){return t.plugin(e,i)}}const Im=ln.fromClass(Bm);class Nm{constructor(t){this.client=t}getFile(t){return this.files.find(e=>e.uri==t)||null}requestFile(t){return Promise.resolve(this.getFile(t))}connected(){for(let t of this.files)this.client.didOpen(t)}disconnected(){}updateFile(t,e){var i;let n=this.getFile(t);n&&(null===(i=n.getView())||void 0===i||i.dispatch(e))}displayFile(t){let e=this.getFile(t);return Promise.resolve(e?e.getView():null)}}class zm{constructor(t,e,i,n,s){this.uri=t,this.languageId=e,this.version=i,this.doc=n,this.view=s}getView(){return this.view}}class qm extends Nm{constructor(){super(...arguments),this.files=[],this.fileVersions=Object.create(null)}nextFileVersion(t){var e;return this.fileVersions[t]=(null!==(e=this.fileVersions[t])&&void 0!==e?e:-1)+1}syncFiles(){let t=[];for(let e of this.files){let i=Bm.get(e.view);if(!i)continue;let n=i.unsyncedChanges;n.empty||(t.push({changes:n,file:e,prevDoc:e.doc}),e.doc=e.view.state.doc,e.version=this.nextFileVersion(e.uri),i.clear())}return t}openFile(t,e,i){if(this.getFile(t))throw new Error("Default workspace implementation doesn't support multiple views on the same file");let n=new zm(t,e,this.nextFileVersion(t),i.state.doc,i);this.files.push(n),this.client.didOpen(n)}closeFile(t){let e=this.getFile(t);e&&(this.files=this.files.filter(t=>t!=e),this.client.didClose(t))}}const Fm=or.baseTheme({".cm-lsp-documentation":{padding:"0 7px","& p, & pre":{margin:"2px 0"}},".cm-lsp-signature-tooltip":{padding:"2px 6px",borderRadius:"2.5px",position:"relative",maxWidth:"30em",maxHeight:"10em",overflowY:"scroll","& .cm-lsp-documentation":{padding:"0",fontSize:"80%"},"& .cm-lsp-signature-num":{fontFamily:"monospace",position:"absolute",left:"2px",top:"4px",fontSize:"70%",lineHeight:"1.3"},"& .cm-lsp-signature":{fontFamily:"monospace",textIndent:"1em hanging"},"& .cm-lsp-active-parameter":{fontWeight:"bold"}},".cm-lsp-signature-multiple":{paddingLeft:"1.5em"},".cm-panel.cm-lsp-rename-panel":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}},".cm-lsp-message button[type=submit]":{display:"block"},".cm-lsp-reference-panel":{fontFamily:"monospace",whiteSpace:"pre",padding:"3px 6px",maxHeight:"120px",overflow:"auto","& .cm-lsp-reference-file":{fontWeight:"bold"},"& .cm-lsp-reference":{cursor:"pointer","&[aria-selected]":{backgroundColor:"#0077ee44"}},"& .cm-lsp-reference-line":{opacity:"0.7"}}});class Hm{constructor(t,e,i){this.id=t,this.params=e,this.timeout=i,this.promise=new Promise((t,e)=>{this.resolve=t,this.reject=e})}}const Vm={general:{markdown:{parser:"marked"}},textDocument:{completion:{completionItem:{snippetSupport:!0,documentationFormat:["plaintext","markdown"],insertReplaceSupport:!1},completionList:{itemDefaults:["commitCharacters","editRange","insertTextFormat"]},completionItemKind:{valueSet:[]},contextSupport:!0},hover:{contentFormat:["markdown","plaintext"]},formatting:{},rename:{},signatureHelp:{contextSupport:!0,signatureInformation:{documentationFormat:["markdown","plaintext"],parameterInformation:{labelOffsetSupport:!0},activeParameterSupport:!0}},definition:{},declaration:{},implementation:{},typeDefinition:{},references:{},diagnostic:{}},window:{showMessage:{}}};class Wm{constructor(t){this.client=t,this.mappings=new Map,this.startDocs=new Map;for(let e of t.workspace.files)this.mappings.set(e.uri,O.empty(e.doc.length)),this.startDocs.set(e.uri,e.doc)}addChanges(t,e){let i=this.mappings.get(t);i&&this.mappings.set(t,i.composeDesc(e))}getMapping(t){let e=this.mappings.get(t);if(!e)return null;let i=this.client.workspace.getFile(t),n=null==i?void 0:i.getView(),s=n&&Bm.get(n);return s?e.composeDesc(s.unsyncedChanges):e}mapPos(t,e,i=-1,n=T.Simple){let s=this.getMapping(t);return s?s.mapPos(e,i,n):e}mapPosition(t,e,i=-1,n=T.Simple){let s=this.startDocs.get(t);if(!s)throw new Error("Cannot map from a file that's not in the workspace");let r=Lm(s,e),o=this.getMapping(t);return o?o.mapPos(r,i,n):r}destroy(){this.client.activeMappings=this.client.activeMappings.filter(t=>t!=this)}}const $m={"window/logMessage":(t,e)=>{1==e.type?console.error("[lsp] "+e.message):2==e.type&&console.warn("[lsp] "+e.message)},"window/showMessage":(t,e)=>{if(e.type>3)return;let i;for(let e of t.workspace.files)if(i=e.getView())break;i&&Co(i,{label:e.message,class:"cm-lsp-message cm-lsp-message-"+(1==e.type?"error":2==e.type?"warning":"info"),top:!0})}};function _m(t,e,i,n){if(!n||t.doc.length<1024)return[{text:t.doc.toString()}];let s=[];return i.iterChanges((t,i,n,r,o)=>{s.push({range:{start:Pm(e,t),end:Pm(e,i)},text:o.toString()})}),s.reverse()}function jm(t,e){if(null==e)return t;if("object"!=typeof t||"object"!=typeof e)return e;let i={},n=Object.keys(t),s=Object.keys(e);for(let r of n)i[r]=s.indexOf(r)>-1?jm(t[r],e[r]):t[r];for(let t of s)n.indexOf(t)<0&&(i[t]=e[t]);return i}function Km(t={}){if(t.override)return pp({override:[Gm]});{let t=[{autocomplete:Gm}];return[pp(),Dt.languageData.of(()=>t)]}}function Um(t){var e;let i=Math.ceil(t.length/50),n=[];for(let s=0;st.replace(/[^\w\s]/g,"\\$&"))).join("|")+")?\\w*$"):/^\w*$/}const Gm=t=>{var e,i;const n=t.view&&Bm.get(t.view);if(!n)return null;let s="";if(!t.explicit){s=t.view.state.sliceDoc(t.pos-1,t.pos);let r=null===(i=null===(e=n.client.serverCapabilities)||void 0===e?void 0:e.completionProvider)||void 0===i?void 0:i.triggerCharacters;if(!(/[a-zA-Z_]/.test(s)||r&&r.indexOf(s)>-1))return null}return function(t,e,i,n){if(!1===t.client.hasCapability("completionProvider"))return Promise.resolve(null);t.client.sync();let s={position:t.toPosition(e),textDocument:{uri:t.uri},context:i};return n&&n.addEventListener("abort",()=>t.client.cancelRequest(s)),t.client.request("textDocument/completion",s)}(n,t.pos,{triggerCharacter:s,triggerKind:t.explicit?1:2},t).then(e=>{var i;if(!e)return null;Array.isArray(e)&&(e={items:e});let{from:s,to:r}=function(t,e){var i;if(!e.items.length)return{from:t.pos,to:t.pos};let n=null===(i=e.itemDefaults)||void 0===i?void 0:i.editRange,s=e.items[0],r=n?"insert"in n?n.insert:n:s.textEdit?"range"in s.textEdit?s.textEdit.range:s.textEdit.insert:null;if(!r)return t.state.wordAt(t.pos)||{from:t.pos,to:t.pos};let o=t.state.doc.lineAt(t.pos);return{from:o.from+r.start.character,to:o.from+r.end.character}}(t,e),o=null===(i=e.itemDefaults)||void 0===i?void 0:i.commitCharacters;return{from:s,to:r,options:e.items.map(t=>{var e;let i=(null===(e=t.textEdit)||void 0===e?void 0:e.newText)||t.textEditText||t.insertText||t.label,s={label:i,type:t.kind&&Ym[t.kind]};return t.commitCharacters&&t.commitCharacters!=o&&(s.commitCharacters=t.commitCharacters),t.detail&&(s.detail=t.detail),2==t.insertTextFormat&&(s.apply=(t,e,n,s)=>function(t){let e=qd.parse(t);return(t,i,n,s)=>{let{text:r,ranges:o}=e.instantiate(t.state,n),{main:l}=t.state.selection,a={changes:{from:n,to:s==l.from?l.to:s,insert:f.of(r)},scrollIntoView:!0,annotations:i?[ed.of(i),vt.userEvent.of("input.complete")]:void 0};if(o.length&&(a.selection=jd(o,0)),o.some(t=>t.field>0)){let e=new Vd(o,0),i=a.effects=[Wd.of(e)];void 0===t.state.field(_d,!1)&&i.push(gt.appendConfig.of([_d,Yd,Xd,Id]))}t.dispatch(t.state.update(a))}}(i)(t,e,n,s)),t.documentation&&(s.info=()=>function(t,e){let i=document.createElement("div");return i.className="cm-lsp-documentation cm-lsp-completion-documentation",i.innerHTML=t.docToHTML(e),i}(n,t.documentation)),s}),commitCharacters:o,validFor:Um(e.items),map:(t,e)=>({...t,from:e.mapPos(t.from)})}},t=>{if("code"in t&&-32800==t.code)return null;throw t})};const Ym={1:"text",2:"method",3:"function",4:"class",5:"property",6:"variable",7:"class",8:"interface",9:"namespace",10:"property",11:"keyword",12:"constant",13:"constant",14:"keyword",16:"constant",20:"constant",21:"constant",22:"class",25:"type"};function Xm(t={}){return mo(Jm,{hideOn:t=>t.docChanged,hoverTime:t.hoverTime})}function Jm(t,e){const i=Bm.get(t);return i?function(t,e){return!1===t.client.hasCapability("hoverProvider")?Promise.resolve(null):(t.client.sync(),t.client.request("textDocument/hover",{position:t.toPosition(e),textDocument:{uri:t.uri}}))}(i,e).then(n=>n?{pos:n.range?Lm(t.state.doc,n.range.start):e,end:n.range?Lm(t.state.doc,n.range.end):e,create(){let t=document.createElement("div");return t.className="cm-lsp-hover-tooltip cm-lsp-documentation",t.innerHTML=function(t,e){return Array.isArray(e)?e.map(e=>Zm(t,e)).join("
    "):"string"==typeof e||"object"==typeof e&&"language"in e?Zm(t,e):t.docToHTML(e)}(i,n.contents),{dom:t}},above:!0}:null):Promise.resolve(null)}function Zm(t,e){if("string"==typeof e)return t.docToHTML(e,"markdown");let{language:i,value:n}=e,s=t.client.config.highlightLanguage&&t.client.config.highlightLanguage(i||"");if(!s){let e=t.view.state.facet(ec);!e||i&&e.name!=i||(s=e)}if(!s)return Em(n);let r="";return Sh(n,s.parser.parse(n),{style:e=>Wc(t.view.state,e)},(t,e)=>{r+=e?`${Em(t)}`:Em(t)},()=>{r+="
    "}),r}const Qm=t=>{const e=Bm.get(t);return!!e&&(e.client.sync(),e.client.withMapping(i=>function(t,e){return t.client.request("textDocument/formatting",{options:e,textDocument:{uri:t.uri}})}(e,{tabSize:sc(t.state),insertSpaces:t.state.facet(nc).indexOf("\t")<0}).then(n=>{if(!n)return;let s=i.getMapping(e.uri),r=[];for(let t of n){let n=i.mapPosition(e.uri,t.range.start),o=i.mapPosition(e.uri,t.range.end);if(s){if(s.touchesRange(n,o))return;n=s.mapPos(n,1),o=s.mapPos(o,-1)}r.push({from:n,to:o,insert:t.newText})}t.dispatch({changes:r,userEvent:"format"})},t=>{e.reportError("Formatting request failed",t)})),!0)},tg=[{key:"Shift-Alt-f",run:Qm,preventDefault:!0}];const eg=[{key:"F2",run:t=>{let e=t.state.wordAt(t.state.selection.main.head),i=Bm.get(t);if(!e||!i||!1===i.client.hasCapability("renameProvider"))return!1;const n=t.state.sliceDoc(e.from,e.to);let s=function(t,e){let i=t.state.field(Ao,!1)||[];for(let n of i){let i=bo(t,n);if(i&&i.dom.classList.contains(e))return i}return null}(t,"cm-lsp-rename-panel");if(s){let t=s.dom.querySelector("[name=name]");t.value=n,t.select()}else{let{close:e,result:i}=Co(t,{label:t.state.phrase("New name"),input:{name:"name",value:n},focus:!0,submitLabel:t.state.phrase("rename"),class:"cm-lsp-rename-panel"});i.then(i=>{t.dispatch({effects:e}),i&&function(t,e){const i=Bm.get(t),n=t.state.wordAt(t.state.selection.main.head);if(!i||!n)return!1;i.client.sync(),i.client.withMapping(t=>function(t,e,i){return t.client.request("textDocument/rename",{newName:i,position:t.toPosition(e),textDocument:{uri:t.uri}})}(i,n.from,e).then(e=>{if(e)for(let n in e.changes){let s=e.changes[n],r=i.client.workspace.getFile(n);s.length&&r&&i.client.workspace.updateFile(n,{changes:s.map(e=>({from:t.mapPosition(n,e.range.start),to:t.mapPosition(n,e.range.end),insert:e.newText})),userEvent:"rename"})}},t=>{i.reportError("Rename request failed",t)}))}(t,i.elements.namedItem("name").value)})}return!0},preventDefault:!0}];const ig=ln.fromClass(class{constructor(){this.activeRequest=null,this.delayedRequest=0}update(t){var e;this.activeRequest&&(t.selectionSet?(this.activeRequest.drop=!0,this.activeRequest=null):t.docChanged&&(this.activeRequest.pos=t.changes.mapPos(this.activeRequest.pos)));const i=Bm.get(t.view);if(!i)return;const n=t.view.state.field(sg);let s="";if(t.docChanged&&t.transactions.some(t=>t.isUserEvent("input.type"))){const r=null===(e=i.client.serverCapabilities)||void 0===e?void 0:e.signatureHelpProvider,o=((null==r?void 0:r.triggerCharacters)||[]).concat(n&&(null==r?void 0:r.retriggerCharacters)||[]);o&&t.changes.iterChanges((t,e,i,n,r)=>{let l=r.toString();if(l)for(let t of o)l.indexOf(t)>-1&&(s=t)})}s?this.startRequest(i,{triggerKind:2,isRetrigger:!!n,triggerCharacter:s,activeSignatureHelp:n?n.data:void 0}):n&&t.selectionSet&&(this.delayedRequest&&clearTimeout(this.delayedRequest),this.delayedRequest=setTimeout(()=>{this.startRequest(i,{triggerKind:3,isRetrigger:!0,activeSignatureHelp:n.data})},250))}startRequest(t,e){this.delayedRequest&&clearTimeout(this.delayedRequest);let{view:i}=t,n=i.state.selection.main.head;this.activeRequest&&(this.activeRequest.drop=!0);let s=this.activeRequest={pos:n,drop:!1};(function(t,e,i){return!1===t.client.hasCapability("signatureHelpProvider")?Promise.resolve(null):(t.client.sync(),t.client.request("textDocument/signatureHelp",{context:i,position:t.toPosition(e),textDocument:{uri:t.uri}}))})(t,n,e).then(t=>{var n,r,o;if(!s.drop)if(t&&t.signatures.length){let l=i.state.field(sg),a=l&&(r=l.data,o=t,r.signatures.length==o.signatures.length&&r.signatures.every((t,e)=>t.label==o.signatures[e].label)),h=a&&3==e.triggerKind?l.active:null!==(n=t.activeSignature)&&void 0!==n?n:0;if(a&&function(t,e,i){var n,s;return(null!==(n=t.signatures[i].activeParameter)&&void 0!==n?n:t.activeParameter)==(null!==(s=e.signatures[i].activeParameter)&&void 0!==s?s:e.activeParameter)}(l.data,t,h))return;i.dispatch({effects:rg.of({data:t,active:h,pos:a?l.tooltip.pos:s.pos})})}else i.state.field(sg)&&i.dispatch({effects:rg.of(null)})},1==e.triggerKind?e=>t.reportError("Signature request failed",e):void 0)}destroy(){this.delayedRequest&&clearTimeout(this.delayedRequest),this.activeRequest&&(this.activeRequest.drop=!0)}});class ng{constructor(t,e,i){this.data=t,this.active=e,this.tooltip=i}}const sg=U.define({create:()=>null,update(t,e){for(let t of e.effects)if(t.is(rg))return t.value?new ng(t.value.data,t.value.active,og(t.value.data,t.value.active,t.value.pos)):null;return t&&e.docChanged?new ng(t.data,t.active,{...t.tooltip,pos:e.changes.mapPos(t.tooltip.pos)}):t},provide:t=>ao.from(t,t=>t&&t.tooltip)}),rg=gt.define();function og(t,e,i){return{pos:i,above:!0,create:i=>function(t,e,i){var n;let s=document.createElement("div");if(s.className="cm-lsp-signature-tooltip",e.signatures.length>1){s.classList.add("cm-lsp-signature-multiple");let t=s.appendChild(document.createElement("div"));t.className="cm-lsp-signature-num",t.textContent=`${i+1}/${e.signatures.length}`}let r=e.signatures[i],o=s.appendChild(document.createElement("div"));o.className="cm-lsp-signature";let l=0,a=0,h=null!==(n=r.activeParameter)&&void 0!==n?n:e.activeParameter,c=null!=h&&r.parameters?r.parameters[h]:null;if(c&&Array.isArray(c.label))[l,a]=c.label;else if(c){let t=r.label.indexOf(c.label);t>-1&&(l=t,a=t+c.label.length)}if(a){o.appendChild(document.createTextNode(r.label.slice(0,l)));let t=o.appendChild(document.createElement("span"));t.className="cm-lsp-active-parameter",t.textContent=r.label.slice(l,a),o.appendChild(document.createTextNode(r.label.slice(a)))}else o.textContent=r.label;if(r.documentation){let e=Bm.get(t);if(e){let t=s.appendChild(document.createElement("div"));t.className="cm-lsp-signature-documentation cm-lsp-documentation",t.innerHTML=e.docToHTML(r.documentation)}}return{dom:s}}(i,t,e)}}const lg=[{key:"Mod-Shift-Space",run:t=>{let e=t.plugin(ig);e||(t.dispatch({effects:gt.appendConfig.of([sg,ig])}),e=t.plugin(ig));let i=t.state.field(sg);if(!e||void 0===i)return!1;let n=Bm.get(t);return!!n&&(e.startRequest(n,{triggerKind:1,activeSignatureHelp:i?i.data:void 0,isRetrigger:!!i}),!0)}},{key:"Mod-Shift-ArrowUp",run:t=>{let e=t.state.field(sg);return!!e&&(e.active>0&&t.dispatch({effects:rg.of({data:e.data,active:e.active-1,pos:e.tooltip.pos})}),!0)}},{key:"Mod-Shift-ArrowDown",run:t=>{let e=t.state.field(sg);return!!e&&(e.activefunction(t,e){const i=Bm.get(t);return!(!i||!1===i.client.hasCapability(e.capability)||(i.client.sync(),i.client.withMapping(n=>e.get(i,t.state.selection.main.head).then(e=>{if(!e)return;let s=Array.isArray(e)?e[0]:e;return(s.uri==i.uri?Promise.resolve(t):i.client.workspace.displayFile(s.uri)).then(t=>{if(!t)return;let e=n.getMapping(s.uri)?n.mapPosition(s.uri,s.range.start):i.fromPosition(s.range.start,t.state.doc);t.dispatch({selection:{anchor:e},scrollIntoView:!0,userEvent:"select.definition"})})},t=>i.reportError("Find definition failed",t))),0))}(t,{get:hg,capability:"definitionProvider"}),preventDefault:!0}];const ug=t=>!!t.state.field(fg,!1)&&(t.dispatch({effects:dg.of(null)}),!0),fg=U.define({create:()=>null,update(t,e){for(let t of e.effects)if(t.is(dg))return t.value;return t},provide:t=>So.from(t)}),dg=gt.define();const pg=[{key:"Shift-F12",run:t=>{const e=Bm.get(t);if(!e||!1===e.client.hasCapability("referencesProvider"))return!1;e.client.sync();let i=e.client.workspaceMapping(),n=!1;return function(t,e){return t.client.request("textDocument/references",{textDocument:{uri:t.uri},position:t.toPosition(e),context:{includeDeclaration:!0}})}(e,t.state.selection.main.head).then(t=>{if(t)return Promise.all(t.map(t=>e.client.workspace.requestFile(t.uri).then(e=>e?{file:e,range:t.range}:null))).then(t=>{let s=t.filter(t=>t);s.length&&(!function(t,e,i){let n=function(t,e){let i=!1;return setTimeout(()=>{i||e.destroy()},500),n=>{i=!0;let s=function(t){let e=t[0],i=e.length;for(let n=1;nt.file.uri)),r=document.createElement("div"),o=null;r.className="cm-lsp-reference-panel",r.tabIndex=0,r.role="listbox",r.setAttribute("aria-label",n.state.phrase("Reference list"));let l=[];for(let{file:i,range:n}of t){let t=i.uri.slice(s);if(t!=o){o=t;let e=r.appendChild(document.createElement("div"));e.className="cm-lsp-reference-file",e.textContent=t}let a=r.appendChild(document.createElement("div"));a.className="cm-lsp-reference",a.role="option";let h=e.mapPosition(i.uri,n.start,1),c=e.mapPosition(i.uri,n.end,-1),u=i.getView(),f=(u?u.state.doc:i.doc).lineAt(h),d=a.appendChild(document.createElement("span"));d.className="cm-lsp-reference-line",d.textContent=(f.number+": ").padStart(5," ");let p=f.text.slice(Math.max(0,h-f.from-50),h-f.from);p&&a.appendChild(document.createTextNode(p)),a.appendChild(document.createElement("strong")).textContent=f.text.slice(h-f.from,c-f.from);let m=f.text.slice(c-f.from,Math.min(f.length,100-p.length));m&&a.appendChild(document.createTextNode(m)),l.length||a.setAttribute("aria-selected","true"),l.push(a)}function a(){for(let t=0;t{if(!t)return;let i=e.mapPosition(s.uri,r.start,1);t.focus(),t.dispatch({selection:{anchor:i},scrollIntoView:!0})})}r.addEventListener("keydown",e=>{if(27==e.keyCode)ug(n),n.focus();else if(38==e.keyCode||33==e.keyCode)h((a()-1+t.length)%t.length);else if(40==e.keyCode||34==e.keyCode)h((a()+1)%t.length);else if(36==e.keyCode)h(0);else if(35==e.keyCode)h(l.length-1);else{if(13!=e.keyCode&&10!=e.keyCode)return;c(a())}e.preventDefault()}),r.addEventListener("click",t=>{for(let e=0;eug(n)),f.setAttribute("aria-label",n.state.phrase("close")),{dom:u,destroy:()=>e.destroy(),mount:()=>r.focus()}}}(e,i),s=void 0===t.state.field(fg,!1)?gt.appendConfig.of(fg.init(()=>n)):dg.of(n);t.dispatch({effects:s})}(e.view,s,i),n=!0)})},t=>e.reportError("Finding references failed",t)).finally(()=>{n||i.destroy()}),!0},preventDefault:!0},{key:"Escape",run:ug}];var mg=function(){function t(t){return{type:t,style:"keyword"}}for(var e=t("operator"),i={type:"atom",style:"atom"},n={type:"axis_specifier",style:"qualifier"},s={",":{type:"punctuation",style:null}},r=["after","all","allowing","ancestor","ancestor-or-self","any","array","as","ascending","at","attribute","base-uri","before","boundary-space","by","case","cast","castable","catch","child","collation","comment","construction","contains","content","context","copy","copy-namespaces","count","decimal-format","declare","default","delete","descendant","descendant-or-self","descending","diacritics","different","distance","document","document-node","element","else","empty","empty-sequence","encoding","end","entire","every","exactly","except","external","first","following","following-sibling","for","from","ftand","ftnot","ft-option","ftor","function","fuzzy","greatest","group","if","import","in","inherit","insensitive","insert","instance","intersect","into","invoke","is","item","language","last","lax","least","let","levels","lowercase","map","modify","module","most","namespace","next","no","node","nodes","no-inherit","no-preserve","not","occurs","of","only","option","order","ordered","ordering","paragraph","paragraphs","parent","phrase","preceding","preceding-sibling","preserve","previous","processing-instruction","relationship","rename","replace","return","revalidation","same","satisfies","schema","schema-attribute","schema-element","score","self","sensitive","sentence","sentences","sequence","skip","sliding","some","stable","start","stemming","stop","strict","strip","switch","text","then","thesaurus","times","to","transform","treat","try","tumbling","type","typeswitch","union","unordered","update","updating","uppercase","using","validate","value","variable","version","weight","when","where","wildcards","window","with","without","word","words","xquery"],o=0,l=r.length;o",">=","<","<=",".","|","?","and","or","div","idiv","mod","*","/","+","-"];for(o=0,l=h.length;o\"\'\/?]/);)l+=o;return gg(t,e,function(t,e){return function(i,n){return i.eatSpace(),e&&i.eat(">")?(Og(n),n.tokenize=vg,"tag"):(i.eat("/")||Dg(n,{type:"tag",name:t,tokenize:vg}),i.eat(">")?(n.tokenize=vg,"tag"):(n.tokenize=xg,"tag"))}}(l,r))}if("{"==i)return Dg(e,{type:"codeblock"}),null;if("}"==i)return Og(e),null;if(Ag(e))return">"==i?"tag":"/"==i&&t.eat(">")?(Og(e),"tag"):"variable";if(/\d/.test(i))return t.match(/^\d*(?:\.\d*)?(?:E[+\-]?\d+)?/),"atom";if("("===i&&t.eat(":"))return Dg(e,{type:"comment"}),gg(t,e,wg);if(s||'"'!==i&&"'"!==i){if("$"===i)return gg(t,e,yg);if(":"===i&&t.eat("="))return"keyword";if("("===i)return Dg(e,{type:"paren"}),null;if(")"===i)return Og(e),null;if("["===i)return Dg(e,{type:"bracket"}),null;if("]"===i)return Og(e),null;var a=mg.propertyIsEnumerable(i)&&mg[i];if(s&&'"'===i)for(;'"'!==t.next(););if(s&&"'"===i)for(;"'"!==t.next(););a||t.eatWhile(/[\w\$_-]/);var h=t.eat(":");!t.eat(":")&&h&&t.eatWhile(/[\w\$_-]/),t.match(/^[ \t]*\(/,!1)&&(n=!0);var c=t.current();return a=mg.propertyIsEnumerable(c)&&mg[c],n&&!a&&(a={type:"function_call",style:"def"}),function(t){return Tg(t,"xmlconstructor")}(e)?(Og(e),"variable"):("element"!=c&&"attribute"!=c&&"axis_specifier"!=a.type||Dg(e,{type:"xmlconstructor"}),a?a.style:"variable")}return bg(t,e,i)}function wg(t,e){for(var i,n=!1,s=!1,r=0;i=t.next();){if(")"==i&&n){if(!(r>0)){Og(e);break}r--}else":"==i&&s&&r++;n=":"==i,s="("==i}return"comment"}function bg(t,e,i,n){let s=function(t,e){return function(i,n){for(var s;s=i.next();){if(s==t){Og(n),e&&(n.tokenize=e);break}if(i.match("{",!1)&&Mg(n))return Dg(n,{type:"codeblock"}),n.tokenize=vg,"string"}return"string"}}(i,n);return Dg(e,{type:"string",name:i,tokenize:s}),gg(t,e,s)}function yg(t,e){var i=/[\w\$_-]/;if(t.eat('"')){for(;'"'!==t.next(););t.eat(":")}else t.eatWhile(i),t.match(":=",!1)||t.eat(":");return t.eatWhile(i),e.tokenize=vg,"variable"}function xg(t,e){var i=t.next();return"/"==i&&t.eat(">")?(Mg(e)&&Og(e),Ag(e)&&Og(e),"tag"):">"==i?(Mg(e)&&Og(e),"tag"):"="==i?null:'"'==i||"'"==i?bg(t,e,i,xg):(Mg(e)||Dg(e,{type:"attribute",tokenize:xg}),t.eat(/[a-zA-Z_:]/),t.eatWhile(/[-a-zA-Z0-9_:.]/),t.eatSpace(),(t.match(">",!1)||t.match("/",!1))&&(Og(e),e.tokenize=vg),"attribute")}function kg(t,e){for(var i;i=t.next();)if("-"==i&&t.match("->",!0))return e.tokenize=vg,"comment"}function Sg(t,e){for(var i;i=t.next();)if("]"==i&&t.match("]",!0))return e.tokenize=vg,"comment"}function Cg(t,e){for(var i;i=t.next();)if("?"==i&&t.match(">",!0))return e.tokenize=vg,"processingInstruction"}function Ag(t){return Tg(t,"tag")}function Mg(t){return Tg(t,"attribute")}function Tg(t,e){return t.stack.length&&t.stack[t.stack.length-1].type==e}function Dg(t,e){t.stack.push(e)}function Og(t){t.stack.pop();var e=t.stack.length&&t.stack[t.stack.length-1].tokenize;t.tokenize=e||vg}const Rg={name:"xquery",startState:function(){return{tokenize:vg,cc:[],stack:[]}},token:function(t,e){return t.eatSpace()?null:e.tokenize(t,e)},languageData:{commentTokens:{block:{open:"(:",close:":)"}}}};const Eg=[function(t={}){return[_o.of(t),Io(),Uo]}(),Xo,function(t={}){return[Wr.of(t),$r||($r=ln.fromClass(class{constructor(t){this.view=t,this.decorations=ci.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(Wr)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new zr({regexp:t.specialChars,decoration:(e,i,n)=>{let{doc:s}=i.state,r=S(e[0],0);if(9==r){let t=s.lineAt(n),e=i.state.tabSize,r=Kt(t.text,e,n-t.from);return ci.replace({widget:new jr((e-r%e)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=ci.replace({widget:new _r(t,r)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(Wr);t.startState.facet(Wr)!=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}))]}(),function(t={}){return[Nu,Iu.of(t),or.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?qu:"historyRedo"==t.inputType?Fu:null;return!!i&&(t.preventDefault(),i(e))}})]}(),function(t={}){let e={...Ic,...t},i=new Nc(e,!0),n=new Nc(e,!1),s=ln.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(ec)!=t.state.facet(ec)||t.startState.field(kc,!1)!=t.state.field(kc,!1)||Kh(t.startState)!=Kh(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new It;for(let s of t.viewportLineBlocks){let r=Cc(t.state,s.from,s.to)?n:vc(t.state,s.from,s.to)?i:null;r&&e.add(s.from,s.from,r)}return e.finish()}}),{domEventHandlers:r}=e;return[s,Lo({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.markers)||Bt.empty},initialSpacer:()=>new Nc(e,!1),domEventHandlers:{...r,click:(t,e,i)=>{if(r.click&&r.click(t,e,i))return!0;let n=Cc(t.state,e.from,e.to);if(n)return t.dispatch({effects:yc.of(n)}),!0;let s=vc(t.state,e.from,e.to);return!!s&&(t.dispatch({effects:bc.of(s)}),!0)}}}),Ec()]}(),function(t={}){return[Ia.of(t),Ra,Oa,La,Pa]}(),function(t={}){return[Tr.of(t),Or,Er,Pr,Ji.of(!0)]}(),[Br,Ir],Dt.allowMultipleSelections.of(!0),or.lineWrapping,Dt.transactionFilter.of(t=>{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:n}=t.newSelection.main,s=i.lineAt(n);if(n>s.from+200)return t;let r=i.sliceString(s.from,n);if(!e.some(t=>t.test(r)))return t;let{state:o}=t,l=-1,a=[];for(let{head:t}of o.selection.ranges){let e=o.doc.lineAt(t);if(e.from==l)continue;l=e.from;let i=oc(o,e.from);if(null==i)continue;let n=/^\s*/.exec(e.text)[0],s=rc(o,i);n!=s&&a.push({from:e.from,to:e.from+n.length,insert:s})}return a.length?[t,{changes:a,sequential:!0}]:t}),function(t,e){let i,n=[_c];return t instanceof qc&&(t.module&&n.push(or.styleModule.of(t.module)),i=t.themeType),(null==e?void 0:e.fallback)?n.push(Hc.of(t)):i?n.push(Fc.computeN([or.darkTheme],e=>e.facet(or.darkTheme)==("dark"==i)?[t]:[])):n.push(Fc.of(t)),n}(jc,{fallback:!0}),function(t={}){return[Gc.of(t),Qc]}(),[rp,tp],pp(),or.mouseSelectionStyle.of((t,e)=>{return(i=e).altKey&&0==i.button?Xr(t,e):null;var i}),function(t={}){let[e,i]=Jr[t.key||"Alt"],n=ln.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)},mousemove(t){this.set(i(t))}}});return[n,or.contentAttributes.of(t=>{var e;return(null===(e=t.plugin(n))||void 0===e?void 0:e.isDown)?Zr:null})]}(),Ur,[gl,ml],pr.of([...op,...Gf,...jl,...Qu,...Dc,...mp,...pa]),hu.define(Rg)];return t.EditorState=Dt,t.EditorView=or,t.LSPClient=class{constructor(t={}){var e;if(this.config=t,this.transport=null,this.nextReqID=0,this.requests=[],this.activeMappings=[],this.serverCapabilities=null,this.supportSync=-1,this.extensions=[],this.receiveMessage=this.receiveMessage.bind(this),this.initializing=new Promise((t,e)=>this.init={resolve:t,reject:e}),this.timeout=null!==(e=t.timeout)&&void 0!==e?e:3e3,this.workspace=t.workspace?t.workspace(this):new qm(this),t.extensions)for(let e of t.extensions)Array.isArray(e)||e.extension?this.extensions.push(e):e.editorExtension&&this.extensions.push(e.editorExtension)}get connected(){return!!this.transport}connect(t){this.transport&&this.transport.unsubscribe(this.receiveMessage),this.transport=t,t.subscribe(this.receiveMessage);let e=Vm;if(this.config.extensions)for(let t of this.config.extensions){let{clientCapabilities:i}=t;i&&(e=jm(e,i))}return this.requestInner("initialize",{processId:null,clientInfo:{name:"@codemirror/lsp-client"},rootUri:this.config.rootUri||null,capabilities:e}).promise.then(e=>{var i;this.serverCapabilities=e.capabilities;let n=e.capabilities.textDocumentSync;this.supportSync=null==n?0:"number"==typeof n?n:null!==(i=n.change)&&void 0!==i?i:0,t.send(JSON.stringify({jsonrpc:"2.0",method:"initialized",params:{}})),this.init.resolve(null)},this.init.reject),this.workspace.connected(),this}disconnect(){this.transport&&this.transport.unsubscribe(this.receiveMessage),this.serverCapabilities=null,this.initializing=new Promise((t,e)=>this.init={resolve:t,reject:e}),this.workspace.disconnected()}plugin(t,e){return[Im.of({client:this,uri:t,languageID:e}),Fm,this.extensions]}didOpen(t){this.notification("textDocument/didOpen",{textDocument:{uri:t.uri,languageId:t.languageId,text:t.doc.toString(),version:t.version}})}didClose(t){this.notification("textDocument/didClose",{textDocument:{uri:t}})}receiveMessage(t){var e;const i=JSON.parse(t);if("id"in i&&!("method"in i)){let t=this.requests.findIndex(t=>t.id==i.id);if(t<0)console.warn(`[lsp] Received a response for non-existent request ${i.id}`);else{let e=this.requests[t];clearTimeout(e.timeout),this.requests.splice(t,1),i.error?e.reject(i.error):e.resolve(i.result)}}else if("id"in i){let t={jsonrpc:"2.0",id:i.id,error:{code:-32601,message:"Method not implemented"}};this.transport.send(JSON.stringify(t))}else{let t=null===(e=this.config.notificationHandlers)||void 0===e?void 0:e[i.method];if(t&&t(this,i.params))return;if(this.config.extensions)for(let t of this.config.extensions){let{notificationHandlers:e}=t,n=null==e?void 0:e[i.method];if(n&&n(this,i.params))return}let n=$m[i.method];n?n(this,i.params):this.config.unhandledNotification&&this.config.unhandledNotification(this,i.method,i.params)}}request(t,e){return this.transport?this.initializing.then(()=>this.requestInner(t,e).promise):Promise.reject(new Error("Client not connected"))}requestInner(t,e,i=!1){let n=++this.nextReqID,s={jsonrpc:"2.0",id:n,method:t,params:e},r=new Hm(n,e,setTimeout(()=>this.timeoutRequest(r),this.timeout));this.requests.push(r);try{this.transport.send(JSON.stringify(s))}catch(t){r.reject(t)}return r}notification(t,e){this.transport&&this.initializing.then(()=>{let i={jsonrpc:"2.0",method:t,params:e};this.transport.send(JSON.stringify(i))})}cancelRequest(t){let e=this.requests.find(e=>e.params===t);e&&this.notification("$/cancelRequest",e.id)}hasCapability(t){return this.serverCapabilities?!!this.serverCapabilities[t]:null}workspaceMapping(){let t=new Wm(this);return this.activeMappings.push(t),t}withMapping(t){let e=this.workspaceMapping();return t(e).finally(()=>e.destroy())}sync(){for(let{file:t,changes:e,prevDoc:i}of this.workspace.syncFiles()){for(let i of this.activeMappings)i.addChanges(t.uri,e);this.supportSync&&this.notification("textDocument/didChange",{textDocument:{uri:t.uri,version:t.version},contentChanges:_m(t,i,e,2==this.supportSync)})}}timeoutRequest(t){let e=this.requests.indexOf(t);e>-1&&(t.reject(new Error("Request timed out")),this.requests.splice(e,1))}},t.LSPPlugin=Bm,t.StateEffect=gt,t.baseExts=Eg,t.debouncedChangeListener=function({delay:t=750,onChange:e}){let i=null,n="";return or.updateListener.of(s=>{if(s.docChanged){const r=s.state.doc.toString();i&&clearTimeout(i),i=setTimeout(()=>{r!==n&&(n=r,e(r,s.state))},t)}})},t.formatDocument=Qm,t.formatKeymap=tg,t.keymap=pr,t.languageServerExtensions=function(){return[Km(),Xm(),pr.of([...tg,...eg,...cg,...pg]),ag(),{clientCapabilities:{textDocument:{publishDiagnostics:{versionSupport:!0}}},notificationHandlers:{"textDocument/publishDiagnostics":(t,e)=>{let i=t.workspace.getFile(e.uri);if(!i||null!=e.version&&e.version!=i.version)return!1;const n=i.getView(),s=n&&Bm.get(n);return!(!n||!s||(n.dispatch(sa(n.state,e.diagnostics.map(t=>{var e,i;return{from:s.unsyncedChanges.mapPos(s.fromPosition(t.range.start,s.syncedDoc)),to:s.unsyncedChanges.mapPos(s.fromPosition(t.range.end,s.syncedDoc)),severity:(i=null!==(e=t.severity)&&void 0!==e?e:1,1==i?"error":2==i?"warning":3==i?"info":"hint"),message:t.message}}))),0))}}}]},t.languageServerSupport=function(t,e,i){return[Bm.create(t,e,i),Km(),Xm(),pr.of([...tg,...eg,...cg,...pg]),ag()]},t.linter=function(t,e={}){return[ga.of({source:t,config:e}),ma,Ba]},t.listCommands=function(t){const e=new Map,i=t.state.facet(pr);for(let t of i)for(let i of t)i.run&&i.run.name&&e.set(i.run.name,{key:i.key,fn:i.run});return e},t.openLintPanel=fa,t.openSearchPanel=$l,t.simpleWebSocketTransport=function(t){let e=[];return new Promise(function(i,n){let s=new WebSocket(t);s.onmessage=t=>{for(let i of e)i(t.data.toString())},s.onerror=t=>n(t),s.onopen=()=>i({socket:s,send:t=>s.send(t),subscribe:t=>e.push(t),unsubscribe:t=>e=e.filter(e=>e!=t)})})},t}({}); +var lsp=function(t){"use strict";let e=[],i=[];function n(t){if(t<768)return!1;for(let n=0,s=e.length;;){let r=n+s>>1;if(t=i[r]))return!0;n=r+1}if(n==s)return!1}}function s(t){return t>=127462&&t<=127487}(()=>{let t="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 n=0,s=0;n=0&&s(a(t,n));)i++,n-=2;if(i%2==0)break;e+=2}}}return e}function l(t,e,i){for(;e>0;){let n=o(t,e-2,i);if(n=56320&&t<57344}function c(t){return t>=55296&&t<56320}function u(t){return t<65536?1:2}class f{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){[t,e]=x(this,t,e);let n=[];return this.decompose(0,t,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(e,this.length,n,1),p.from(n,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=x(this,t,e);let i=[];return this.decompose(t,e,i,0),p.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),n=new v(this),s=new v(t);for(let t=e,r=e;;){if(n.next(t),s.next(t),t=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(r+=n.value.length,n.done||r>=i)return!0}}iter(t=1){return new v(this,t)}iterRange(t,e=this.length){return new w(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let n=this.line(t).from;i=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new b(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}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 d(t):p.from(d.split(t,[])):f.empty}}class d extends f{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,n){for(let s=0;;s++){let r=this.text[s],o=n+r.length;if((e?i:o)>=t)return new y(n,o,i,r);n=o+1,i++}}decompose(t,e,i,n){let s=t<=0&&e>=this.length?this:new d(g(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(1&n){let t=i.pop(),e=m(s.text,t.text.slice(),0,s.length);if(e.length<=32)i.push(new d(e,t.length+s.length));else{let t=e.length>>1;i.push(new d(e.slice(0,t)),new d(e.slice(t)))}}else i.push(s)}replace(t,e,i){if(!(i instanceof d))return super.replace(t,e,i);[t,e]=x(this,t,e);let n=m(this.text,m(i.text,g(this.text,0,t)),e),s=this.length+i.length-(e-t);return n.length<=32?new d(n,s):p.from(d.split(n,[]),s)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;s<=e&&rt&&r&&(n+=i),ts&&(n+=o.slice(Math.max(0,t-s),e-s)),s=l+1}return n}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],n=-1;for(let s of t)i.push(s),n+=s.length+1,32==i.length&&(e.push(new d(i,n)),i=[],n=-1);return n>-1&&e.push(new d(i,n)),e}}class p extends f{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,n){for(let s=0;;s++){let r=this.children[s],o=n+r.length,l=i+r.lines-1;if((e?l:o)>=t)return r.lineInner(t,e,i,n);n=o+1,i=l+1}}decompose(t,e,i,n){for(let s=0,r=0;r<=e&&s=r){let s=n&((r<=t?1:0)|(l>=e?2:0));r>=t&&l<=e&&!s?i.push(o):o.decompose(t-r,e-r,i,s)}r=l+1}}replace(t,e,i){if([t,e]=x(this,t,e),i.lines=s&&e<=o){let l=r.replace(t-s,e-s,i),a=this.lines-r.lines+l.lines;if(l.lines
    >4&&l.lines>a>>6){let s=this.children.slice();return s[n]=l,new p(s,this.length-(e-t)+i.length)}return super.replace(s,o,l)}s=o+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;st&&s&&(n+=i),tr&&(n+=o.sliceString(t-r,e-r,i)),r=l+1}return n}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof p))return 0;let i=0,[n,s,r,o]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,s+=e){if(n==r||s==o)return i;let l=this.children[n],a=t.children[s];if(l!=a)return i+l.scanIdentical(a,e);i+=l.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 d(i,e)}let n=Math.max(32,i>>5),s=n<<1,r=n>>1,o=[],l=0,a=-1,h=[];function c(t){let e;if(t.lines>s&&t instanceof p)for(let e of t.children)c(e);else t.lines>r&&(l>r||!l)?(u(),o.push(t)):t instanceof d&&l&&(e=h[h.length-1])instanceof d&&t.lines+e.lines<=32?(l+=t.lines,a+=t.length+1,h[h.length-1]=new d(e.text.concat(t.text),e.length+1+t.length)):(l+t.lines>n&&u(),l+=t.lines,a+=t.length+1,h.push(t))}function u(){0!=l&&(o.push(1==h.length?h[0]:p.from(h,a)),a=-1,l=h.length=0)}for(let e of t)c(e);return u(),1==o.length?o[0]:new p(o,e)}}function m(t,e,i=0,n=1e9){for(let s=0,r=0,o=!0;r=i&&(a>n&&(l=l.slice(0,n-s)),s0?1:(t instanceof d?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],s=this.offsets[i],r=s>>1,o=n instanceof d?n.text.length:n.children.length;if(r==(e>0?o: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&s)==(e>0?0:1)){if(this.offsets[i]+=e,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(n instanceof d){let s=n.text[r+(e<0?-1:0)];if(this.offsets[i]+=e,s.length>Math.max(0,t))return this.value=0==t?s:e>0?s.slice(t):s.slice(0,s.length-t),this;t-=s.length}else{let s=n.children[r+(e<0?-1:0)];t>s.length?(t-=s.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(s),this.offsets.push(e>0?1:(s instanceof d?s.text.length:s.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class w{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new v(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:n}=this.cursor.next(t);return this.pos+=(n.length+t)*e,this.value=n.length<=i?n:e<0?n.slice(n.length-i):n.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 b{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:n}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(f.prototype[Symbol.iterator]=function(){return this.iter()},v.prototype[Symbol.iterator]=w.prototype[Symbol.iterator]=b.prototype[Symbol.iterator]=function(){return this});class y{constructor(t,e,i,n){this.from=t,this.to=e,this.number=i,this.text=n}get length(){return this.to-this.from}}function x(t,e,i){return[e=Math.max(0,Math.min(t.length,e)),Math.max(e,Math.min(t.length,i))]}function k(t,e,i=!0,n=!0){return r(t,e,i,n)}function S(t,e){let i=t.charCodeAt(e);if(!(n=i,n>=55296&&n<56320&&e+1!=t.length))return i;var n;let s=t.charCodeAt(e+1);return function(t){return t>=56320&&t<57344}(s)?s-56320+(i-55296<<10)+65536:i}function C(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function A(t){return t<65536?1:2}const M=/\r\n?|\n/;var T=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(T||(T={}));class D{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return s+(t-n);s+=o}else{if(i!=T.Simple&&a>=t&&(i==T.TrackDel&&nt||i==T.TrackBefore&&nt))return null;if(a>t||a==t&&e<0&&!o)return t==n||e<0?s:s+l;s+=l}n=a}if(t>n)throw new RangeError(`Position ${t} is out of range for changeset of length ${n}`);return s}touchesRange(t,e=t){for(let i=0,n=0;i=0&&n<=e&&s>=t)return!(ne)||"cover";n=s}return!1}toString(){let t="";for(let e=0;e=0?":"+n:"")}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 D(t)}static create(t){return new D(t)}}class O extends D{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 P(this,(e,i,n,s,r)=>t=t.replace(n,n+(i-e),r),!1),t}mapDesc(t,e=!1){return L(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let n=0,s=0;n=0){e[n]=o,e[n+1]=r;let l=n>>1;for(;i.length0&&E(i,e,s.text),s.forward(t),o+=t}let a=t[r++];for(;o>1].toJSON()))}return t}static of(t,e,i){let n=[],s=[],r=0,o=null;function l(t=!1){if(!t&&!n.length)return;ro||t<0||o>e)throw new RangeError(`Invalid change range ${t} to ${o} (in doc of length ${e})`);let c=h?"string"==typeof h?f.of(h.split(i||M)):h:f.empty,u=c.length;if(t==o&&0==u)return;tr&&R(n,t-r,-1),R(n,o-t,u),E(s,n,c),r=o}}(t),l(!o),o}static empty(t){return new O(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let n=0;ne&&"string"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==s.length)e.push(s[0],0);else{for(;i.length=0&&i<=0&&i==t[s+1]?t[s]+=e:s>=0&&0==e&&0==t[s]?t[s+1]+=i:n?(t[s]+=e,t[s+1]+=i):t.push(e,i)}function E(t,e,i){if(0==i.length)return;let n=e.length-2>>1;if(n>1])),!(i||o==t.sections.length||t.sections[o+1]<0);)l=t.sections[o++],a=t.sections[o++];e(s,h,r,c,u),s=h,r=c}}}function L(t,e,i,n=!1){let s=[],r=n?[]:null,o=new I(t),l=new I(e);for(let t=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(-1==o.ins&&-1==l.ins){let t=Math.min(o.len,l.len);R(s,t,-1),o.forward(t),l.forward(t)}else if(l.ins>=0&&(o.ins<0||t==o.i||0==o.off&&(l.len=0&&t=0)){if(o.done&&l.done)return r?O.createSet(s,r):D.create(s);throw new Error("Mismatched change set lengths")}{let e=0,i=o.len;for(;i;)if(-1==l.ins){let t=Math.min(i,l.len);e+=t,i-=t,l.forward(t)}else{if(!(0==l.ins&&l.lene||o.ins>=0&&o.len>e)&&(t||n.length>i),r.forward2(e),o.forward(e)}}else R(n,0,o.ins,t),s&&E(s,n,o.text),o.next()}}class I{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return e>=t.length?f.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?f.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 N{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get bidiLevel(){let t=7&this.flags;return 7==t?null:t}get goalColumn(){let t=this.flags>>6;return 16777215==t?void 0:t}map(t,e=-1){let i,n;return this.empty?i=n=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),n=t.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new N(i,n,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return z.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return z.range(this.anchor,i)}eq(t,e=!1){return!(this.anchor!=t.anchor||this.head!=t.head||e&&this.empty&&this.assoc!=t.assoc)}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 z.range(t.anchor,t.head)}static create(t,e,i){return new N(t,e,i)}}class z{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:z.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;it.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 z(t.ranges.map(t=>N.fromJSON(t)),t.main)}static single(t,e=t){return new z([z.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,n=0;nt?8:0)|s)}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;in.head?z.range(o,r):z.range(r,o))}}return new z(t,e)}}function q(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let F=0;class H{constructor(t,e,i,n,s){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=n,this.id=F++,this.default=t([]),this.extensions="function"==typeof s?s(this):s}get reader(){return this}static define(t={}){return new H(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:V),!!t.static,t.enables)}of(t){return new W([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new W(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new W(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],i=>e(i.field(t)))}}function V(t,e){return t==e||t.length==e.length&&t.every((t,i)=>t===e[i])}class W{constructor(t,e,i,n){this.dependencies=t,this.facet=e,this.type=i,this.value=n,this.id=F++}dynamicSlot(t){var e;let i=this.value,n=this.facet.compareInput,s=this.id,r=t[s]>>1,o=2==this.type,l=!1,a=!1,h=[];for(let i of this.dependencies)"doc"==i?l=!0:"selection"==i?a=!0:1&(null!==(e=t[i.id])&&void 0!==e?e:1)||h.push(t[i.id]);return{create:t=>(t.values[r]=i(t),1),update(t,e){if(l&&e.docChanged||a&&(e.docChanged||e.selection)||_(t,h)){let e=i(t);if(o?!$(e,t.values[r],n):!n(e,t.values[r]))return t.values[r]=e,1}return 0},reconfigure:(t,e)=>{let l,a=e.config.address[s];if(null!=a){let s=rt(e,a);if(this.dependencies.every(i=>i instanceof H?e.facet(i)===t.facet(i):!(i instanceof U)||e.field(i,!1)==t.field(i,!1))||(o?$(l=i(t),s,n):n(l=i(t),s)))return t.values[r]=s,0}else l=i(t);return t.values[r]=l,1}}}}function $(t,e,i){if(t.length!=e.length)return!1;for(let n=0;nt[e.id]),s=i.map(t=>t.type),r=n.filter(t=>!(1&t)),o=t[e.id]>>1;function l(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(K).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 n=t.values[e],s=this.updateF(n,i);return this.compareF(n,s)?0:(t.values[e]=s,1)},reconfigure:(t,i)=>{let n,s=t.facet(K),r=i.facet(K);return(n=s.find(t=>t.field==this))&&n!=r.find(t=>t.field==this)?(t.values[e]=n.create(t),1):null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}}init(t){return[this,K.of({field:this,create:t})]}get extension(){return this}}const G=4,Y=3,X=2,J=1;function Z(t){return e=>new tt(e,t)}const Q={highest:Z(0),high:Z(J),default:Z(X),low:Z(Y),lowest:Z(G)};class tt{constructor(t,e){this.inner=t,this.prec=e}}class et{of(t){return new it(this,t)}reconfigure(t){return et.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class it{constructor(t,e){this.compartment=t,this.inner=e}}class nt{constructor(t,e,i,n,s,r){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=n,this.staticValues=s,this.facets=r,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(t,e,i){let n=[],s=Object.create(null),r=new Map;for(let i of function(t,e,i){let n=[[],[],[],[],[]],s=new Map;function r(t,o){let l=s.get(t);if(null!=l){if(l<=o)return;let e=n[l].indexOf(t);e>-1&&n[l].splice(e,1),t instanceof it&&i.delete(t.compartment)}if(s.set(t,o),Array.isArray(t))for(let e of t)r(e,o);else if(t instanceof it){if(i.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let n=e.get(t.compartment)||t.inner;i.set(t.compartment,n),r(n,o)}else if(t instanceof tt)r(t.inner,t.prec);else if(t instanceof U)n[o].push(t),t.provides&&r(t.provides,o);else if(t instanceof W)n[o].push(t),t.facet.extensions&&r(t.facet.extensions,X);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.`);r(e,o)}}return r(t,X),n.reduce((t,e)=>t.concat(e))}(t,e,r))i instanceof U?n.push(i):(s[i.facet.id]||(s[i.facet.id]=[])).push(i);let o=Object.create(null),l=[],a=[];for(let t of n)o[t.id]=a.length<<1,a.push(e=>t.slot(e));let h=null==i?void 0:i.config.facets;for(let t in s){let e=s[t],n=e[0].facet,r=h&&h[t]||[];if(e.every(t=>0==t.type))if(o[n.id]=l.length<<1|1,V(r,e))l.push(i.facet(n));else{let t=n.combine(e.map(t=>t.value));l.push(i&&n.compare(t,i.facet(n))?i.facet(n):t)}else{for(let t of e)0==t.type?(o[t.id]=l.length<<1|1,l.push(t.value)):(o[t.id]=a.length<<1,a.push(e=>t.dynamicSlot(e)));o[n.id]=a.length<<1,a.push(t=>j(t,n,e))}}let c=a.map(t=>t(o));return new nt(t,r,c,o,l,s)}}function st(t,e){if(1&e)return 2;let i=e>>1,n=t.status[i];if(4==n)throw new Error("Cyclic dependency between fields and/or facets");if(2&n)return n;t.status[i]=4;let s=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|s}function rt(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const ot=H.define(),lt=H.define({combine:t=>t.some(t=>t),static:!0}),at=H.define({combine:t=>t.length?t[0]:void 0,static:!0}),ht=H.define(),ct=H.define(),ut=H.define(),ft=H.define({combine:t=>!!t.length&&t[0]});class dt{constructor(t,e){this.type=t,this.value=e}static define(){return new pt}}class pt{of(t){return new dt(this,t)}}class mt{constructor(t){this.map=t}of(t){return new gt(this,t)}}class gt{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 gt(this.type,e)}is(t){return this.type==t}static define(t={}){return new mt(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let n of t){let t=n.map(e);t&&i.push(t)}return i}}gt.reconfigure=gt.define(),gt.appendConfig=gt.define();class vt{constructor(t,e,i,n,s,r){this.startState=t,this.changes=e,this.selection=i,this.effects=n,this.annotations=s,this.scrollIntoView=r,this._doc=null,this._state=null,i&&q(i,e.newLength),s.some(t=>t.type==vt.time)||(this.annotations=s.concat(vt.time.of(Date.now())))}static create(t,e,i,n,s,r){return new vt(t,e,i,n,s,r)}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(vt.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function wt(t,e){let i=[];for(let n=0,s=0;;){let r,o;if(n=t[n]))r=t[n++],o=t[n++];else{if(!(s=0;s--){let r=i[s](t);r&&Object.keys(r).length&&(n=bt(n,yt(e,r,t.changes.newLength),!0))}return n==t?t:vt.create(e,t.changes,t.selection,n.effects,n.annotations,n.scrollIntoView)}(i?function(t){let e=t.startState,i=!0;for(let n of e.facet(ht)){let e=n(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:wt(i,e))}if(!0!==i){let n,s;if(!1===i)s=t.changes.invertedDesc,n=O.empty(e.doc.length);else{let e=t.changes.filter(i);n=e.changes,s=e.filtered.mapDesc(e.changes).invertedDesc}t=vt.create(e,n,t.selection&&t.selection.map(s),gt.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let n=e.facet(ct);for(let i=n.length-1;i>=0;i--){let s=n[i](t);t=s instanceof vt?s:Array.isArray(s)&&1==s.length&&s[0]instanceof vt?s[0]:xt(e,St(s),!1)}return t}(s):s)}vt.time=dt.define(),vt.userEvent=dt.define(),vt.addToHistory=dt.define(),vt.remote=dt.define();const kt=[];function St(t){return null==t?kt:Array.isArray(t)?t:[t]}var Ct=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(Ct||(Ct={}));const At=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Mt;try{Mt=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}function Tt(t){return e=>{if(!/\S/.test(e))return Ct.Space;if(function(t){if(Mt)return Mt.test(t);for(let e=0;e"€"&&(i.toUpperCase()!=i.toLowerCase()||At.test(i)))return!0}return!1}(e))return Ct.Word;for(let i=0;i-1)return Ct.Word;return Ct.Other}}class Dt{constructor(t,e,i,n,s,r){this.config=t,this.doc=e,this.selection=i,this.values=n,this.status=t.statusTemplate.slice(),this.computeSlot=s,r&&(r._state=this);for(let t=0;ts.set(e,t)),i=null),s.set(e.value.compartment,e.value.extension)):e.is(gt.reconfigure)?(i=null,n=e.value):e.is(gt.appendConfig)&&(i=null,n=St(n).concat(e.value));if(i)e=t.startState.values.slice();else{i=nt.resolve(n,s,this),e=new Dt(i,this.doc,this.selection,i.dynamicSlots.map(()=>null),(t,e)=>e.reconfigure(t,this),null).values}let r=t.startState.facet(lt)?t.newSelection:t.newSelection.asSingle();new Dt(i,t.newDoc,r,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:z.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),n=this.changes(i.changes),s=[i.range],r=St(i.effects);for(let i=1;is.spec.fromJSON(r,t)))}return Dt.create({doc:t.doc,selection:z.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(t={}){let e=nt.resolve(t.extensions||[],new Map),i=t.doc instanceof f?t.doc:f.of((t.doc||"").split(e.staticFacet(Dt.lineSeparator)||M)),n=t.selection?t.selection instanceof z?t.selection:z.single(t.selection.anchor,t.selection.head):z.single(0);return q(n,i.length),e.staticFacet(lt)||(n=n.asSingle()),new Dt(e,i,n,e.dynamicSlots.map(()=>null),(t,e)=>e.create(t),null)}get tabSize(){return this.facet(Dt.tabSize)}get lineBreak(){return this.facet(Dt.lineSeparator)||"\n"}get readOnly(){return this.facet(ft)}phrase(t,...e){for(let e of this.facet(Dt.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 n=+(i||1);return!n||n>e.length?t:e[n-1]})),t}languageDataAt(t,e,i=-1){let n=[];for(let s of this.facet(ot))for(let r of s(this,e,i))Object.prototype.hasOwnProperty.call(r,t)&&n.push(r[t]);return n}charCategorizer(t){return Tt(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:n}=this.doc.lineAt(t),s=this.charCategorizer(t),r=t-i,o=t-i;for(;r>0;){let t=k(e,r,!1);if(s(e.slice(t,r))!=Ct.Word)break;r=t}for(;ot.length?t[0]:4}),Dt.lineSeparator=at,Dt.readOnly=ft,Dt.phrases=H.define({compare(t,e){let i=Object.keys(t),n=Object.keys(e);return i.length==n.length&&i.every(i=>t[i]==e[i])}}),Dt.languageData=ot,Dt.changeFilter=ht,Dt.transactionFilter=ct,Dt.transactionExtender=ut,et.reconfigure=gt.define();class Rt{eq(t){return this==t}range(t,e=t){return Et.create(t,e,this)}}Rt.prototype.startSide=Rt.prototype.endSide=0,Rt.prototype.point=!1,Rt.prototype.mapMode=T.TrackDel;let Et=class t{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(e,i,n){return new t(e,i,n)}};function Pt(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Lt{constructor(t,e,i,n){this.from=t,this.to=e,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,n=0){let s=i?this.to:this.from;for(let r=n,o=s.length;;){if(r==o)return r;let n=r+o>>1,l=s[n]-t||(i?this.value[n].endSide:this.value[n].startSide)-e;if(n==r)return l>=0?r:o;l>=0?o=n:r=n+1}}between(t,e,i,n){for(let s=this.findIndex(e,-1e9,!0),r=this.findIndex(i,1e9,!1,s);sh||a==h&&c.startSide>0&&c.endSide<=0)continue;(h-a||c.endSide-c.startSide)<0||(r<0&&(r=a),c.point&&(o=Math.max(o,h-a)),i.push(c),n.push(a-r),s.push(h-r))}return{mapped:i.length?new Lt(n,s,i,o):null,pos:r}}}class Bt{constructor(t,e,i,n){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=n}static create(t,e,i,n){return new Bt(t,e,i,n)}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:n=0,filterTo:s=this.length}=t,r=t.filter;if(0==e.length&&!r)return this;if(i&&(e=e.slice().sort(Pt)),this.isEmpty)return e.length?Bt.of(e):this;let o=new zt(this,null,-1).goto(0),l=0,a=[],h=new It;for(;o.value||l=0){let t=e[l++];h.addInner(t.from,t.to,t.value)||a.push(t)}else 1==o.rangeIndex&&o.chunkIndexthis.chunkEnd(o.chunkIndex)||so.to||s=s&&t<=s+r.length&&!1===r.between(s,t-s,e-s,i))return}this.nextLayer.between(t,e,i)}}iter(t=0){return qt.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return qt.from(t).goto(e)}static compare(t,e,i,n,s=-1){let r=t.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),o=e.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),l=Nt(r,o,i),a=new Ht(r,l,s),h=new Ht(o,l,s);i.iterGaps((t,e,i)=>Vt(a,t,h,e,i,n)),i.empty&&0==i.length&&Vt(a,0,h,0,0,n)}static eq(t,e,i=0,n){null==n&&(n=999999999);let s=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0),r=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0);if(s.length!=r.length)return!1;if(!s.length)return!0;let o=Nt(s,r),l=new Ht(s,o,0).goto(i),a=new Ht(r,o,0).goto(i);for(;;){if(l.to!=a.to||!Wt(l.active,a.active)||l.point&&(!a.point||!l.point.eq(a.point)))return!1;if(l.to>n)return!0;l.next(),a.next()}}static spans(t,e,i,n,s=-1){let r=new Ht(t,null,s).goto(e),o=e,l=r.openStart;for(;;){let t=Math.min(r.to,i);if(r.point){let i=r.activeForPoint(r.to),s=r.pointFromo&&(n.span(o,t,r.active,l),l=r.openEnd(t));if(r.to>i)return l+(r.point&&r.to>i?1:0);o=r.to,r.next()}}static of(t,e=!1){let i=new It;for(let n of t instanceof Et?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i0)return t.slice().sort(Pt);e=n}return t}(t):t)i.add(n.from,n.to,n.value);return i.finish()}static join(t){if(!t.length)return Bt.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let n=t[i];n!=Bt.empty;n=n.nextLayer)e=new Bt(n.chunkPos,n.chunk,e,Math.max(n.maxPoint,e.maxPoint));return e}}Bt.empty=new Bt([],[],null,-1),Bt.empty.nextLayer=Bt.empty;class It{finishChunk(t){this.chunks.push(new Lt(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=[])}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}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new It)).add(t,e,i)}addInner(t,e,i){let n=t-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(n<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(Bt.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=Bt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Nt(t,e,i){let n=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&&n.push(new zt(r,e,i,s));return 1==n.length?n[0]:new qt(n)}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--)Ft(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--)Ft(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(),Ft(this.heap,0)}}}function Ft(t,e){for(let i=t[e];;){let n=1+(e<<1);if(n>=t.length)break;let s=t[n];if(n+1=0&&(s=t[n+1],n++),i.compare(s)<0)break;t[n]=i,t[e]=s,e=n}}class Ht{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=qt.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){$t(this.active,t),$t(this.activeTo,t),$t(this.activeRank,t),this.minActive=jt(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:n,rank:s}=this.cursor;for(;e0;)e++;_t(this.active,e,i),_t(this.activeTo,e,n),_t(this.activeRank,e,s),t&&_t(t,e,this.cursor.from),this.minActive=jt(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>t){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&$t(i,n)}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 t=this.cursor.value;if(t.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from=0&&i[e]=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 Vt(t,e,i,n,s,r){t.goto(e),i.goto(n);let o=n+s,l=n,a=n-e;for(;;){let e=t.to+a-i.to,n=e||t.endSide-i.endSide,s=n<0?t.to+a:i.to,h=Math.min(s,o);if(t.point||i.point?t.point&&i.point&&(t.point==i.point||t.point.eq(i.point))&&Wt(t.activeForPoint(t.to),i.activeForPoint(i.to))||r.comparePoint(l,h,t.point,i.point):h>l&&!Wt(t.active,i.active)&&r.compareRange(l,h,t.active,i.active),s>o)break;(e||t.openEnd!=i.openEnd)&&r.boundChange&&r.boundChange(s),l=s,n<=0&&t.next(),n>=0&&i.next()}}function Wt(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 jt(t,e){let i=-1,n=1e9;for(let s=0;s=e)return n;if(n==t.length)break;s+=9==t.charCodeAt(n)?i-s%i:1,n=k(t,n)}return!0===n?-1:t.length}const Gt="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),Yt="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),Xt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class Jt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function n(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function s(t,e,r,o){let l=[],a=/^@(\w+)\b/.exec(t[0]),h=a&&"keyframes"==a[1];if(a&&null==e)return r.push(t[0]+";");for(let i in e){let o=e[i];if(/&/.test(i))s(i.split(/,\s*/).map(e=>t.map(t=>e.replace(/&/,t))).reduce((t,e)=>t.concat(e)),o,r);else if(o&&"object"==typeof o){if(!a)throw new RangeError("The value of a property ("+i+") should be a primitive value.");s(n(i),o,l,h)}else null!=o&&l.push(i.replace(/_.*/,"").replace(/[A-Z]/g,t=>"-"+t.toLowerCase())+": "+o+";")}(l.length||h)&&r.push((!i||a||o?t:t.map(i)).join(", ")+" {"+l.join(" ")+"}")}for(let e in t)s(n(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=Xt[Gt]||1;return Xt[Gt]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let n=t[Yt],s=i&&i.nonce;n?s&&n.setNonce(s):n=new Qt(t,s),n.mount(Array.isArray(e)?e:[e],t)}}let Zt=new Map;class Qt{constructor(t,e){let i=t.ownerDocument||t,n=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let e=Zt.get(i);if(e)return t[Yt]=e;this.sheet=new n.CSSStyleSheet,Zt.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[Yt]=this}mount(t,e){let i=this.sheet,n=0,s=0;for(let e=0;e-1&&(this.modules.splice(o,1),s--,o=-1),-1==o){if(this.modules.splice(s++,0,r),i)for(let t=0;t",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ie="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),ne="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),se=0;se<10;se++)te[48+se]=te[96+se]=String(se);for(se=1;se<=24;se++)te[se+111]="F"+se;for(se=65;se<=90;se++)te[se]=String.fromCharCode(se+32),ee[se]=String.fromCharCode(se);for(var re in te)ee.hasOwnProperty(re)||(ee[re]=te[re]);function oe(){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 n in i)if(Object.prototype.hasOwnProperty.call(i,n)){var s=i[n];"string"==typeof s?t.setAttribute(n,s):null!=s&&(t[n]=s)}e++}for(;e.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)&&(i=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.height-t.offsetHeight)<1)&&(n=1),{scaleX:i,scaleY:n}}class ye{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?ge(e):0),i,Math.min(t.focusOffset,i?ge(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}}let xe,ke=null;function Se(t){if(t.setActive)return t.setActive();if(ke)return t.focus(ke);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==ke?{get preventScroll(){return ke={preventScroll:!0},!0}}:void 0),!ke){ke=!1;for(let t=0;tMath.max(1,t.scrollHeight-t.clientHeight-4)}function De(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&n>0)return{node:i,offset:n};if(1==i.nodeType&&n>0){if("false"==i.contentEditable)return null;i=i.childNodes[n-1],n=ge(i)}else{if(!i.parentNode||pe(i))return null;n=de(i),i=i.parentNode}}}function Oe(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&ne)return i.domBoundsAround(t,e,a);if(c>=t&&-1==n&&(n=l,s=a),a>e&&i.dom.parentNode==this.dom){r=l,o=h;break}h=c,a=c+i.breakAfter}return{from:s,to:o<0?i+this.length:o,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:r=0?this.children[r].dom:null}}markDirty(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),1&e.flags)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,7&this.flags&&this.markParentsDirty(!0))}setDOM(t){this.dom!=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=Ee){this.markDirty();for(let n=t;nthis.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 Ie(t,e,i,n,s,r,o,l,a){let{children:h}=t,c=h.length?h[e]:null,u=r.length?r[r.length-1]:null,f=u?u.breakAfter:o;if(!(e==n&&c&&!o&&!f&&r.length<2&&c.merge(i,s,r.length?u:null,0==i,l,a))){if(n0&&(!o&&r.length&&c.merge(i,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(i2);var Ge={mac:Ue||/Mac/.test(ze.platform),windows:/Win/.test(ze.platform),linux:/Linux|X11/.test(ze.platform),ie:We,ie_version:He?qe.documentMode||6:Ve?+Ve[1]:Fe?+Fe[1]:0,gecko:$e,gecko_version:$e?+(/Firefox\/(\d+)/.exec(ze.userAgent)||[0,0])[1]:0,chrome:!!_e,chrome_version:_e?+_e[1]:0,ios:Ue,android:/Android\b/.test(ze.userAgent),safari:Ke,webkit_version:je?+(/\bAppleWebKit\/(\d+)/.exec(ze.userAgent)||[0,0])[1]:0,tabSize:null!=qe.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};class Ye extends Pe{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){3==t.nodeType&&this.createDOM(t)}merge(t,e,i){return!(8&this.flags||i&&(!(i instanceof Ye)||this.length-(e-t)+i.length>256||8&i.flags))&&(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Ye(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=8&this.flags,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new Re(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 function(t,e,i){let n=t.nodeValue.length;e>n&&(e=n);let s=e,r=e,o=0;0==e&&i<0||e==n&&i>=0?Ge.chrome||Ge.gecko||(e?(s--,o=1):r=0)?0:l.length-1];Ge.safari&&!o&&0==a.width&&(a=Array.prototype.find.call(l,t=>t.width)||a);return o?ve(a,o<0):a||null}(this.dom,t,e)}}class Xe extends Pe{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(Me(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!(8&(this.flags|t.flags))}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?4&this.flags&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,n,s,r){return(!i||!(!(i instanceof Xe&&i.mark.eq(this.mark))||t&&s<=0||et&&e.push(i=t&&(n=s),i=o,s++}let r=this.length-t;return this.length=t,n>-1&&(this.children.length=n,this.markDirty()),new Xe(this.mark,e,r)}domAtPos(t){return Qe(this,t)}coordsAt(t,e){return ei(this,t,e)}}class Je extends Pe{static create(t,e,i){return new Je(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=Je.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){this.dom&&this.widget.updateDOM(this.dom,t)||(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,n,s,r){return!(i&&(!(i instanceof Je&&this.widget.compare(i.widget))||t>0&&s<=0||e0)?Re.before(this.dom):Re.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let n=this.dom.getClientRects(),s=null;if(!n.length)return null;let r=this.side?this.side<0:t>0;for(let e=r?n.length-1:0;s=n[e],!(t>0?0==e:e==n.length-1||s.top0?Re.before(this.dom):Re.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return f.empty}get isHidden(){return!0}}function Qe(t,e){let i=t.dom,{children:n}=t,s=0;for(let t=0;st&&e0;t--){let e=n[t-1];if(e.dom.parentNode==i)return e.domAtPos(e.length)}for(let t=s;t0&&e instanceof Xe&&s.length&&(n=s[s.length-1])instanceof Xe&&n.mark.eq(e.mark)?ti(n,e.children[0],i-1):(s.push(e),e.setParent(t)),t.length+=e.length}function ei(t,e,i){let n=null,s=-1,r=null,o=-1;!function t(e,l){for(let a=0,h=0;a=l&&(c.children.length?t(c,l-h):(!r||r.isHidden&&(i>0||ii(r,c)))&&(u>l||h==u&&c.getSide()>0)?(r=c,o=l-h):(h-1?1:0)!=s.length-(i&&s.indexOf(i)>-1?1:0))return!1;for(let r of n)if(r!=i&&(-1==s.indexOf(r)||t[r]!==e[r]))return!1;return!0}function oi(t,e,i){let n=!1;if(e)for(let s in e)i&&s in i||(n=!0,"style"==s?t.style.cssText="":t.removeAttribute(s));if(i)for(let s in i)e&&e[s]==i[s]||(n=!0,"style"==s?t.style.cssText=i[s]:t.setAttribute(s,i[s]));return n}function li(t){let e=Object.create(null);for(let i=0;i0?3e8:-4e8:e>0?1e8:-1e8,new di(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,n=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:s,end:r}=pi(t,n);e=(s?n?-3e8:-1:5e8)-1,i=1+(r?n?2e8:1:-6e8)}return new di(t,e,i,n,t.widget||null,!0)}static line(t){return new fi(t)}static set(t,e=!1){return Bt.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}ci.none=Bt.empty;class ui extends ci{constructor(t){let{start:e,end:i}=pi(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof ui&&this.tagName==t.tagName&&(this.class||(null===(e=this.attrs)||void 0===e?void 0:e.class))==(t.class||(null===(i=t.attrs)||void 0===i?void 0:i.class))&&ri(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}ui.prototype.point=!1;class fi extends ci{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof fi&&this.spec.class==t.spec.class&&ri(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)}}fi.prototype.mapMode=T.TrackBefore,fi.prototype.point=!0;class di extends ci{constructor(t,e,i,n,s,r){super(e,i,s,t),this.block=n,this.isReplace=r,this.mapMode=n?e<=0?T.TrackBefore:T.TrackAfter:T.TrackDel}get type(){return this.startSide!=this.endSide?hi.WidgetRange:this.startSide<=0?hi.WidgetBefore:hi.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof di&&(e=this.widget,i=t.widget,e==i||!!(e&&i&&e.compare(i)))&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide;var e,i}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}function pi(t,e=!1){let{inclusiveStart:i,inclusiveEnd:n}=t;return null==i&&(i=t.inclusive),null==n&&(n=t.inclusive),{start:null!=i?i:e,end:null!=n?n:e}}function mi(t,e,i,n=0){let s=i.length-1;s>=0&&i[s]+n>=t?i[s]=Math.max(i[s],e):i.push(t,e)}di.prototype.point=!0;class gi extends Pe{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,n,s,r){if(i){if(!(i instanceof gi))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),Ne(this,t,e,i?i.children.slice():[],s,r),!0}split(t){let e=new gi;if(e.breakAfter=this.breakAfter,0==this.length)return e;let{i:i,off:n}=this.childPos(t);n&&(e.append(this.children[i].split(n),0),this.children[i].merge(n,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){ri(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){ti(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=ni(e,this.attrs||{})),i&&(this.attrs=ni({class:i},this.attrs||{}))}domAtPos(t){return Qe(this,t)}reuseDOM(t){"DIV"==t.nodeName&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?4&this.flags&&(Me(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&&(oi(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let n=this.dom.lastChild;for(;n&&Pe.get(n)instanceof Xe;)n=n.lastChild;if(!(n&&this.length&&("BR"==n.nodeName||0!=(null===(i=Pe.get(n))||void 0===i?void 0:i.isEditable)||Ge.ios&&this.children.some(t=>t instanceof Ye)))){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,e=0;for(let i of this.children){if(!(i instanceof Ye)||/[^ -~]/.test(i.text))return null;let n=ue(i.dom);if(1!=n.length)return null;e+=n[0].width,t=n[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(t,e){let i=ei(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:t}=this.parent.view.viewState,e=i.bottom-i.top;if(Math.abs(e-t.lineHeight)<2&&t.textHeight=e){if(s instanceof gi)return s;if(r>e)break}n=r+s.breakAfter}return null}}class vi extends Pe{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,n,s,r){return!(i&&(!(i instanceof vi&&this.widget.compare(i.widget))||t>0&&s<=0||e0)}}class wi extends ai{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}class bi{constructor(t,e,i,n){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=n,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(0==this.content.length)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof vi&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new gi),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(yi(new Ze(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,this.posCovered()||t&&this.content.length&&this.content[this.content.length-1]instanceof vi||this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:n}=this.cursor.next(this.skip);if(this.skip=0,n)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,this.atCursorPos=!0,t--;continue}this.text=e,this.textOff=0}let n=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(yi(new Ye(this.text.slice(this.textOff,this.textOff+n)),e),i),this.atCursorPos=!0,this.textOff+=n,t-=n,i=0}}span(t,e,i,n){this.buildText(e-t,i,n),this.pos=e,this.openStart<0&&(this.openStart=n)}point(t,e,i,n,s,r){if(this.disallowBlockEffectsFor[r]&&i instanceof di){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 o=e-t;if(i instanceof di)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new vi(i.widget||xi.block,o,i));else{let r=Je.create(i.widget||xi.inline,o,o?0:i.startSide),l=this.atCursorPos&&!r.isEditable&&s<=n.length&&(t0),a=!r.isEditable&&(tn.length||i.startSide<=0),h=this.getLine();2!=this.pendingBuffer||l||r.isEditable||(this.pendingBuffer=0),this.flushBuffer(n),l&&(h.append(yi(new Ze(1),n),s),s=n.length+Math.max(0,s-n.length)),h.append(yi(r,n),s),this.atCursorPos=a,this.pendingBuffer=a?tn.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=n.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);o&&(this.textOff+o<=this.text.length?this.textOff+=o:(this.skip+=o-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=s)}static build(t,e,i,n,s){let r=new bi(t,e,i,s);return r.openEnd=Bt.spans(n,e,i,r),r.openStart<0&&(r.openStart=r.openEnd),r.finish(r.openEnd),r}}function yi(t,e){for(let i of e)t=new Xe(i,[t],t.length);return t}class xi extends ai{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}xi.inline=new xi("span"),xi.block=new xi("div");var ki=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(ki||(ki={}));const Si=ki.LTR,Ci=ki.RTL;function Ai(t){let e=[];for(let i=0;i=e){if(o.level==i)return r;(s<0||(0!=n?n<0?o.frome:t[s].level>o.level))&&(s=r)}}if(s<0)throw new RangeError("Index out of range");return s}}function Li(t,e){if(t.length!=e.length)return!1;for(let i=0;ia&&o.push(new Pi(a,p.from,f)),Ni(t,p.direction==Si!=!(f%2)?n+1:n,s,p.inner,p.from,p.to,o),a=p.to}d=p.to}else{if(d==i||(e?Bi[d]!=l:Bi[d]==l))break;d++}u?Ii(t,a,d,n+1,s,u,o):ae;){let i=!0,c=!1;if(!h||a>r[h-1].to){let t=Bi[a-1];t!=l&&(i=!1,c=16==t)}let u=i||1!=l?null:[],f=i?n:n+1,d=a;t:for(;;)if(h&&d==r[h-1].to){if(c)break t;let p=r[--h];if(!i)for(let t=p.from,i=h;;){if(t==e)break t;if(!i||r[i-1].to!=t){if(Bi[t-1]==l)break t;break}t=r[--i].from}if(u)u.push(p);else{p.to=0;t-=3)if(Oi[t+1]==-i){let e=Oi[t+2],i=2&e?s:4&e?1&e?r:s:0;i&&(Bi[o]=Bi[Oi[t]]=i),l=t;break}}else{if(189==Oi.length)break;Oi[l++]=o,Oi[l++]=e,Oi[l++]=a}else if(2==(n=Bi[o])||1==n){let t=n==s;a=t?0:1;for(let e=l-3;e>=0;e-=3){let i=Oi[e+2];if(2&i)break;if(t)Oi[e+2]|=2;else{if(4&i)break;Oi[e+2]|=4}}}}}(t,s,r,n,l),function(t,e,i,n){for(let s=0,r=n;s<=i.length;s++){let o=s?i[s-1].to:t,l=sa;)e==r&&(e=i[--n].from,r=n?i[n-1].to:t),Bi[--e]=c;a=o}else r=o,a++}}}(s,r,n,l),Ii(t,s,r,e,i,n,o)}function zi(t){return[new Pi(0,t,0)]}let qi="";function Fi(t,e,i,n,s){var r;let o=n.head-t.from,l=Pi.find(e,o,null!==(r=n.bidiLevel)&&void 0!==r?r:-1,n.assoc),a=e[l],h=a.side(s,i);if(o==h){let t=l+=s?1:-1;if(t<0||t>=e.length)return null;a=e[l=t],o=a.side(!s,i),h=a.side(s,i)}let c=k(t.text,o,a.forward(s,i));(ca.to)&&(c=h),qi=t.text.slice(Math.min(o,c),Math.max(o,c));let u=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return u&&c==h&&u.level+(s?0:1)t.some(t=>t)}),Ji=H.define({combine:t=>t.some(t=>t)}),Zi=H.define();class Qi{constructor(t,e="nearest",i="nearest",n=5,s=5,r=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=s,this.isSnapshot=r}map(t){return t.empty?this:new Qi(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Qi(z.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const tn=gt.define({map:(t,e)=>t.map(e)}),en=gt.define();function nn(t,e,i){let n=t.facet(_i);n.length?n[0](e):window.onerror&&window.onerror(String(e),i,void 0,void 0,e)||(i?console.error(i+":",e):console.error(e))}const sn=H.define({combine:t=>!t.length||t[0]});let rn=0;const on=H.define({combine:t=>t.filter((e,i)=>{for(let n=0;n{let e=[];return r&&e.push(un.of(e=>{let i=e.plugin(t);return i?r(i):ci.none})),s&&e.push(s(t)),e})}static fromClass(t,e){return ln.define((e,i)=>new t(e,i),e)}}class an{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(nn(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){nn(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){nn(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const hn=H.define(),cn=H.define(),un=H.define(),fn=H.define(),dn=H.define(),pn=H.define();function mn(t,e){let i=t.state.facet(pn);if(!i.length)return i;let n=i.map(e=>e instanceof Function?e(t):e),s=[];return Bt.spans(n,e.from,e.to,{point(){},span(t,i,n,r){let o=t-e.from,l=i-e.from,a=s;for(let t=n.length-1;t>=0;t--,r--){let i,s=n[t].spec.bidiIsolate;if(null==s&&(s=Hi(e.text,o,l)),r>0&&a.length&&(i=a[a.length-1]).to==o&&i.direction==s)i.to=l,a=i.inner;else{let t={from:o,to:l,direction:s,inner:[]};a.push(t),a=t.inner}}}}),s}const gn=H.define();function vn(t){let e=0,i=0,n=0,s=0;for(let r of t.state.facet(gn)){let o=r(t);o&&(null!=o.left&&(e=Math.max(e,o.left)),null!=o.right&&(i=Math.max(i,o.right)),null!=o.top&&(n=Math.max(n,o.top)),null!=o.bottom&&(s=Math.max(s,o.bottom)))}return{left:e,right:i,top:n,bottom:s}}const wn=H.define();class bn{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new bn(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toAh)break;s+=2}if(!l)return i;new bn(l.fromA,l.toA,l.fromB,l.toB).addToSet(i),r=l.toA,o=l.toB}}}class yn{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=O.empty(this.startState.doc.length);for(let t of i)this.changes=this.changes.compose(t.changes);let n=[];this.changes.iterChangedRanges((t,e,i,s)=>n.push(new bn(t,e,i,s))),this.changedRanges=n}static create(t,e,i){return new yn(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return 0==this.flags&&0==this.transactions.length}}class xn extends Pe{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=ci.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new gi],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new bn(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.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.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(e=this.domChanged)||void 0===e?void 0:e.newSel)?n=this.domChanged.newSel.head:function(t,e){let i=!1;e&&t.iterChangedRanges((t,n)=>{te.from&&(i=!0)});return i}(t.changes,this.hasComposition)||t.selectionSet||(n=t.state.selection.main.head));let s=n>-1?function(t,e,i){let n=kn(t,i);if(!n)return null;let{node:s,from:r,to:o}=n,l=s.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(n.from,n.to)!=l)return null;let a=e.invertedDesc,h=new bn(a.mapPos(r),a.mapPos(o),r,o),c=[];for(let e=s.parentNode;;e=e.parentNode){let i=Pe.get(e);if(i instanceof Xe)c.push({node:e,deco:i.mark});else{if(i instanceof gi||"DIV"==e.nodeName&&e.parentNode==t.contentDOM)return{range:h,text:s,marks:c,line:e};if(e==t.contentDOM)return null;c.push({node:e,deco:new ui({inclusive:!0,attributes:li(e),tagName:e.tagName.toLowerCase()})})}}}(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:e,to:n}=this.hasComposition;i=new bn(e,n,t.changes.mapPos(e,-1),t.changes.mapPos(n,1)).addToSet(i.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(Ge.ie||Ge.chrome)&&!s&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let r=function(t,e,i){let n=new Sn;return Bt.compare(t,e,i,n),n.changes}(this.decorations,this.updateDeco(),t.changes);return i=bn.extendWithRanges(i,r),!!(7&this.flags||0!=i.length)&&(this.updateInner(i,t.startState.doc.length,s),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:n}=this.view;n.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let t=Ge.chrome||Ge.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,t),this.flags&=-8,t&&(t.written||n.selectionRange.focusNode!=t.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(t=>t.flags&=-9);let s=[];if(this.view.viewport.from||this.view.viewport.to=0?n[t]:null;if(!e)break;let r,o,l,a,{fromA:h,toA:c,fromB:u,toB:f}=e;if(i&&i.range.fromBu){let t=bi.build(this.view.state.doc,u,i.range.fromB,this.decorations,this.dynamicDecorationMap),e=bi.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);o=t.breakAtStart,l=t.openStart,a=e.openEnd;let n=this.compositionView(i);e.breakAtStart?n.breakAfter=1:e.content.length&&n.merge(n.length,n.length,e.content[0],!1,e.openStart,0)&&(n.breakAfter=e.content[0].breakAfter,e.content.shift()),t.content.length&&n.merge(0,0,t.content[t.content.length-1],!0,0,t.openEnd)&&t.content.pop(),r=t.content.concat(n).concat(e.content)}else({content:r,breakAtStart:o,openStart:l,openEnd:a}=bi.build(this.view.state.doc,u,f,this.decorations,this.dynamicDecorationMap));let{i:d,off:p}=s.findPos(c,1),{i:m,off:g}=s.findPos(h,-1);Ie(this,m,g,d,p,r,o,l,a)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let t of e.effects)t.is(en)&&(this.editContextFormatting=t.value)}compositionView(t){let e=new Ye(t.text.nodeValue);e.flags|=8;for(let{deco:i}of t.marks)e=new Xe(i,[e],e.length);let i=new gi;return i.append(e,0),i}fixCompositionDOM(t){let e=(t,e)=>{e.flags|=8|(e.children.some(t=>7&t.flags)?1:0),this.markedForComposition.add(e);let i=Pe.get(t);i&&i!=e&&(i.dom=null),e.setDOM(t)},i=this.childPos(t.range.fromB,1),n=this.children[i.i];e(t.line,n);for(let s=t.marks.length-1;s>=-1;s--)i=n.childPos(i.off,1),n=n.children[i.i],e(s>=0?t.marks[s].node:t.text,n)}updateSelection(t=!1,e=!1){!t&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,s=!n&&!(this.view.state.facet(sn)||this.dom.tabIndex>-1)&&ce(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||e||s))return;let r=this.forceSelection;this.forceSelection=!1;let o=this.view.state.selection.main,l=this.moveToLine(this.domAtPos(o.anchor)),a=o.empty?l:this.moveToLine(this.domAtPos(o.head));if(Ge.gecko&&o.empty&&!this.hasComposition&&(1==(h=l).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(()=>l.node.insertBefore(t,l.node.childNodes[l.offset]||null)),l=a=new Re(t,0),r=!0}var h;let c=this.view.observer.selectionRange;!r&&c.focusNode&&(fe(l.node,l.offset,c.anchorNode,c.anchorOffset)&&fe(a.node,a.offset,c.focusNode,c.focusOffset)||this.suppressWidgetCursorChange(c,o))||(this.view.observer.ignore(()=>{Ge.android&&Ge.chrome&&this.dom.contains(c.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}(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let t=ae(this.view.root);if(t)if(o.empty){if(Ge.gecko){let t=(e=l.node,n=l.offset,1!=e.nodeType?0:(n&&"false"==e.childNodes[n-1].contentEditable?1:0)|(no.head&&([l,a]=[a,l]),e.setEnd(a.node,a.offset),e.setStart(l.node,l.offset),t.removeAllRanges(),t.addRange(e)}else;var e,n;s&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(l,a)),this.impreciseAnchor=l.precise?null:new Re(c.anchorNode,c.anchorOffset),this.impreciseHead=a.precise?null:new Re(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&fe(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=ae(t.root),{anchorNode:n,anchorOffset:s}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let r=gi.find(this,e.head);if(!r)return;let o=r.posAtStart;if(e.head==o||e.head==o+r.length)return;let l=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!l||!a||l.bottom>a.top)return;let h=this.domAtPos(e.head+e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(n,s)}moveToLine(t){let e,i=this.dom;if(t.node!=i)return t;for(let n=t.offset;!e&&n=0;n--){let t=Pe.get(i.childNodes[n]);t instanceof gi&&(e=t.domAtPos(t.length))}return e?new Re(e.node,e.offset,!0):t}nearest(t){for(let e=t;e;){let t=Pe.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(;e=0;r--){let o=this.children[r],l=s-o.breakAfter,a=l-o.length;if(lt||o.covers(1))&&(!i||o instanceof gi&&!(i instanceof gi&&e>=0)))i=o,n=a;else if(i&&a==t&&l==t&&o instanceof vi&&Math.abs(e)<2){if(o.deco.startSide<0)break;r&&(i=null)}s=a}return i?i.coordsAt(t-n,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),n=this.children[e];if(!(n instanceof gi))return null;for(;n.children.length;){let{i:t,off:e}=n.childPos(i,1);for(;;t++){if(t==n.children.length)return null;if((n=n.children[t]).length)break}i=e}if(!(n instanceof Ye))return null;let s=k(n.text,i);if(s==i)return null;let r=Ce(n.dom,i,s).getClientRects();for(let t=0;tMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,l=this.view.textDirection==ki.LTR;for(let t=0,a=0;an)break;if(t>=i){let i=h.dom.getBoundingClientRect();if(e.push(i.height),r){let e=h.dom.lastChild,n=e?ue(e):[];if(n.length){let e=n[n.length-1],r=l?e.right-i.left:i.right-e.left;r>o&&(o=r,this.minWidth=s,this.minWidthFrom=t,this.minWidthTo=c)}}}t=c+h.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return"rtl"==getComputedStyle(this.children[e].dom).direction?ki.RTL:ki.LTR}measureTextSize(){for(let t of this.children)if(t instanceof gi){let e=t.measureTextSize();if(e)return e}let t,e,i,n=document.createElement("div");return n.className="cm-line",n.style.width="99999px",n.style.position="absolute",n.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(n);let s=ue(n.firstChild)[0];t=n.getBoundingClientRect().height,e=s?s.width/27:7,i=s?s.height:t,n.remove()}),{lineHeight:t,charWidth:e,textHeight:i}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new Be(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let s=n==e.viewports.length?null:e.viewports[n],r=s?s.from-1:this.length;if(r>i){let n=(e.lineBlockAt(r).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(ci.replace({widget:new wi(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,r))}if(!s)break;i=s.to+1}return ci.set(t)}updateDeco(){let t=1,e=this.view.state.facet(un).map(e=>(this.dynamicDecorationMap[t++]="function"==typeof e)?e(this.view):e),i=!1,n=this.view.state.facet(fn).map((t,e)=>{let n="function"==typeof t;return n&&(i=!0),n?t(this.view):t});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(Bt.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];ti.anchor?-1:1);if(!n)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,e.left),top:Math.min(n.top,e.top),right:Math.max(n.right,e.right),bottom:Math.max(n.bottom,e.bottom)});let s=vn(this.view),r={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;!function(t,e,i,n,s,r,o,l){let a=t.ownerDocument,h=a.defaultView||window;for(let c=t,u=!1;c&&!u;)if(1==c.nodeType){let t,f=c==a.body,d=1,p=1;if(f)t=we(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(u=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let e=c.getBoundingClientRect();({scaleX:d,scaleY:p}=be(c,e)),t={left:e.left,right:e.left+c.clientWidth*d,top:e.top,bottom:e.top+c.clientHeight*p}}let m=0,g=0;if("nearest"==s)e.top0&&e.bottom>t.bottom+g&&(g=e.bottom-t.bottom+o)):e.bottom>t.bottom&&(g=e.bottom-t.bottom+o,i<0&&e.top-g0&&e.right>t.right+m&&(m=e.right-t.right+r)):e.right>t.right&&(m=e.right-t.right+r,i<0&&e.leftt.bottom||e.leftt.right)&&(e={left:Math.max(e.left,t.left),right:Math.min(e.right,t.right),top:Math.max(e.top,t.top),bottom:Math.min(e.bottom,t.bottom)}),c=c.assignedSlot||c.parentNode}else{if(11!=c.nodeType)break;c=c.host}}(this.view.scrollDOM,r,i.headt?e.left-t:Math.max(0,t-e.right)}function An(t,e){return e.top>t?e.top-t:Math.max(0,t-e.bottom)}function Mn(t,e){return t.tope.top+1}function Tn(t,e){return et.bottom?{top:t.top,left:t.left,right:t.right,bottom:e}:t}function On(t,e,i){let n,s,r,o,l,a,h,c,u=!1;for(let f=t.firstChild;f;f=f.nextSibling){let t=ue(f);for(let d=0;dg||o==g&&r>m)&&(n=f,s=p,r=m,o=g,u=!m||(e0:dp.bottom&&(!h||h.bottomp.top)&&(a=f,c=p):h&&Mn(h,p)?h=Dn(h,p.bottom):c&&Mn(c,p)&&(c=Tn(c,p.top))}}if(h&&h.bottom>=i?(n=l,s=h):c&&c.top<=i&&(n=a,s=c),!n)return{node:t,offset:0};let f=Math.max(s.left,Math.min(s.right,e));return 3==n.nodeType?Rn(n,f,i):u&&"false"!=n.contentEditable?On(n,f,i):{node:t,offset:Array.prototype.indexOf.call(t.childNodes,n)+(e>=(s.left+s.right)/2?1:0)}}function Rn(t,e,i){let n=t.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;li?h.top-i:i-h.bottom)-1;if(h.left-1<=e&&h.right+1>=e&&c=(h.left+h.right)/2,n=i;if(Ge.chrome||Ge.gecko){Ce(t,l).getBoundingClientRect().left==h.right&&(n=!i)}if(c<=0)return{node:t,offset:l+(n?1:0)};s=l+(n?1:0),r=c}}}return{node:t,offset:s>-1?s:o>0?t.nodeValue.length:0}}function En(t,e,i,n=-1){var s,r;let o,l=t.contentDOM.getBoundingClientRect(),a=l.top+t.viewState.paddingTop,{docHeight:h}=t.viewState,{x:c,y:u}=e,f=u-a;if(f<0)return 0;if(f>h)return t.state.doc.length;for(let e=t.viewState.heightOracle.textHeight/2,s=!1;o=t.elementAtHeight(f),o.type!=hi.Text;)for(;f=n>0?o.bottom+e:o.top-e,!(f>=0&&f<=h);){if(s)return i?null:0;s=!0,n=-n}u=a+f;let d=o.from;if(dt.viewport.to)return t.viewport.to==t.state.doc.length?t.state.doc.length:i?null:Pn(t,l,o,c,u);let p=t.dom.ownerDocument,m=t.root.elementFromPoint?t.root:p,g=m.elementFromPoint(c,u);g&&!t.contentDOM.contains(g)&&(g=null),g||(c=Math.max(l.left+1,Math.min(l.right-1,c)),g=m.elementFromPoint(c,u),g&&!t.contentDOM.contains(g)&&(g=null));let v,w=-1;if(g&&0!=(null===(s=t.docView.nearest(g))||void 0===s?void 0:s.isEditable)){if(p.caretPositionFromPoint){let t=p.caretPositionFromPoint(c,u);t&&({offsetNode:v,offset:w}=t)}else if(p.caretRangeFromPoint){let e=p.caretRangeFromPoint(c,u);e&&(({startContainer:v,startOffset:w}=e),(!t.contentDOM.contains(v)||Ge.safari&&function(t,e,i){let n,s=t;if(3!=t.nodeType||e!=(n=t.nodeValue.length))return!1;for(;;){let t=s.nextSibling;if(t){if("BR"==t.nodeName)break;return!1}{let t=s.parentNode;if(!t||"DIV"==t.nodeName)break;s=t}}return Ce(t,n-1,n).getBoundingClientRect().right>i}(v,w,c)||Ge.chrome&&function(t,e,i){if(0!=e)return!1;for(let e=t;;){let t=e.parentNode;if(!t||1!=t.nodeType||t.firstChild!=e)return!1;if(t.classList.contains("cm-line"))break;e=t}let n=1==t.nodeType?t.getBoundingClientRect():Ce(t,0,Math.max(t.nodeValue.length,1)).getBoundingClientRect();return i-n.left>5}(v,w,c))&&(v=void 0))}v&&(w=Math.min(ge(v),w))}if(!v||!t.docView.dom.contains(v)){let e=gi.find(t.docView,d);if(!e)return f>o.top+o.height/2?o.to:o.from;({node:v,offset:w}=On(e.dom,c,u))}let b=t.docView.nearest(v);if(!b)return null;if(b.isWidget&&1==(null===(r=b.dom)||void 0===r?void 0:r.nodeType)){let t=b.dom.getBoundingClientRect();return e.y1.5*t.defaultLineHeight){let e=t.viewState.heightOracle.textHeight;r+=Math.floor((s-i.top-.5*(t.defaultLineHeight-e))/e)*t.viewState.heightOracle.lineLength}let o=t.state.sliceDoc(i.from,i.to);return i.from+Ut(o,r,t.state.tabSize)}function Ln(t,e,i){let n=t.lineBlockAt(e);if(Array.isArray(n.type)){let t;for(let s of n.type){if(s.from>e)break;if(!(s.toe)return s;t&&(s.type!=hi.Text||t.type==s.type&&!(i<0?s.frome))||(t=s)}}return t||n}return n}function Bn(t,e,i,n){let s=t.state.doc.lineAt(e.head),r=t.bidiSpans(s),o=t.textDirectionAt(s.from);for(let l=e,a=null;;){let e=Fi(s,r,o,l,i),h=qi;if(!e){if(s.number==(i?t.state.doc.lines:1))return l;h="\n",s=t.state.doc.line(s.number+(i?1:-1)),r=t.bidiSpans(s),e=t.visualLineSide(s,!i)}if(a){if(!a(h))return l}else{if(!n)return e;a=n(h)}l=e}}function In(t,e,i){for(;;){let n=0;for(let s of t)s.between(e-1,e+1,(t,s,r)=>{if(e>t&&ee(t)),i.from,e.head>i.from?-1:1);return n==i.from?i:z.cursor(n,nt)&&this.lineBreak(),n=s}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let s,r=-1,o=1;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(s=n.exec(e))&&(r=s.index,o=s[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=Pe.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+(Hn(t,i.node,i.offset)?e:0))}}function Hn(t,e,i){for(;;){if(!e||i-1;let{impreciseHead:s,impreciseAnchor:r}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let e=s||r?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}=t.observer.selectionRange;i&&(e.push(new Vn(i,n)),s==i&&r==n||e.push(new Vn(s,r)));return e}(t),i=new Fn(e,t.state);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(t,e){if(0==t.length)return null;let i=t[0].pos,n=2==t.length?t[1].pos:i;return i>-1&&n>-1?z.single(i+e,n+e):null}(e,this.bounds.from)}else{let e=t.observer.selectionRange,i=s&&s.node==e.focusNode&&s.offset==e.focusOffset||!he(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),n=r&&r.node==e.anchorNode&&r.offset==e.anchorOffset||!he(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset),o=t.viewport;if((Ge.ios||Ge.chrome)&&t.state.selection.main.empty&&i!=n&&(o.from>0||o.toDate.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:n,to:o}=e.bounds,l=s.from,a=null;(8===r||Ge.android&&e.text.length0&&l>0&&t.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if("end"==n){i-=o+Math.max(0,r-Math.min(o,l))-r}if(o=o?r-i:0,l=r+(l-o),o=r}else if(l=l?r-i:0,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}(t.state.doc.sliceString(n,o,qn),e.text,l-n,a);h&&(Ge.chrome&&13==r&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==qn+qn&&h.toB--,i={from:n+h.from,to:n+h.toA,insert:f.of(e.text.slice(h.from,h.toB).split(qn))})}else n&&(!t.hasFocus&&t.state.facet(sn)||n.main.eq(s))&&(n=null);if(!i&&!n)return!1;if(!i&&e.typeOver&&!s.empty&&n&&n.main.empty?i={from:s.from,to:s.to,insert:t.state.doc.slice(s.from,s.to)}:(Ge.mac||Ge.android)&&i&&i.from==i.to&&i.from==s.head-1&&/^\. ?$/.test(i.insert.toString())&&"off"==t.contentDOM.getAttribute("autocorrect")?(n&&2==i.insert.length&&(n=z.single(n.main.anchor-1,n.main.head-1)),i={from:i.from,to:i.to,insert:f.of([i.insert.toString().replace("."," ")])}):i&&i.from>=s.from&&i.to<=s.to&&(i.from!=s.from||i.to!=s.to)&&s.to-s.from-(i.to-i.from)<=4?i={from:s.from,to:s.to,insert:t.state.doc.slice(s.from,i.from).append(i.insert).append(t.state.doc.slice(i.to,s.to))}:Ge.chrome&&i&&i.from==i.to&&i.from==s.head&&"\n "==i.insert.toString()&&t.lineWrapping&&(n&&(n=z.single(n.main.anchor-1,n.main.head-1)),i={from:s.from,to:s.to,insert:f.of([" "])}),i)return _n(t,i,n,r);if(n&&!n.main.eq(s)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin,"select.pointer"==i&&(n=Nn(t.state.facet(dn).map(e=>e(t)),n))),t.dispatch({selection:n,scrollIntoView:e,userEvent:i}),!0}return!1}function _n(t,e,i,n=-1){if(Ge.ios&&t.inputState.flushIOSKey(e))return!0;let s=t.state.selection.main;if(Ge.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&" "==t.state.sliceDoc(e.from,s.from))&&1==e.insert.length&&2==e.insert.lines&&Ae(t.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&0==e.insert.length||8==n&&e.insert.lengths.head)&&Ae(t.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&0==e.insert.length&&Ae(t.contentDOM,"Delete",46)))return!0;let r,o=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let l=()=>r||(r=function(t,e,i){let n,s=t.state,r=s.selection.main;if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=r.frome.to?s.sliceDoc(e.to,r.to):"";n=s.replaceSelection(t.state.toText(i+e.insert.sliceString(0,void 0,t.state.lineBreak)+o))}else{let o=s.changes(e),l=i&&i.main.to<=o.newLength?i.main:void 0;if(s.selection.ranges.length>1&&t.inputState.composing>=0&&e.to<=r.to&&e.to>=r.to-10){let a,h=t.state.sliceDoc(e.from,e.to),c=i&&kn(t,i.main.head);if(c){let t=e.insert.length-(e.to-e.from);a={from:c.from,to:c.to-t}}else a=t.state.doc.lineAt(r.head);let u=r.to-e.to,f=r.to-r.from;n=s.changeByRange(i=>{if(i.from==r.from&&i.to==r.to)return{changes:o,range:l||i.map(o)};let n=i.to-u,c=n-h.length;if(i.to-i.from!=f||t.state.sliceDoc(c,n)!=h||i.to>=a.from&&i.from<=a.to)return{range:i};let d=s.changes({from:c,to:n,insert:e.insert}),p=i.to-r.to;return{changes:d,range:l?z.range(Math.max(0,l.anchor+p),Math.max(0,l.head+p)):i.map(d)}})}else n={changes:o,selection:l&&s.selection.replaceRange(l)}}let o="input.type";(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,o+=".compose",t.inputState.compositionFirstChange&&(o+=".start",t.inputState.compositionFirstChange=!1));return s.update(n,{userEvent:o,scrollIntoView:!0})}(t,e,i));return t.state.facet(Ki).some(i=>i(t,e.from,e.to,o,l))||t.dispatch(l()),!0}class jn{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,Ge.safari&&t.contentDOM.addEventListener("input",()=>null),Ge.gecko&&function(t){ws.has(t)||(ws.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}(t.contentDOM.ownerDocument)}handleEvent(t){(function(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,n=e.target;n!=t.contentDOM;n=n.parentNode)if(!n||11==n.nodeType||(i=Pe.get(n))&&i.ignoreEvent(e))return!1;return!0})(this.view,t)&&!this.ignoreDuringComposition(t)&&("keydown"==t.type&&this.keydown(t)||(0!=this.view.updateState?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t)))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Un(t),i=this.handlers,n=this.view.contentDOM;for(let t in e)if("scroll"!=t){let s=!e[t].handlers.length,r=i[t];r&&s!=!r.handlers.length&&(n.removeEventListener(t,this.handleEvent),r=null),r||n.addEventListener(t,this.handleEvent,{passive:s})}for(let t in i)"scroll"==t||e[t]||n.removeEventListener(t,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=t.keyCode&&Xn.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),Ge.android&&Ge.chrome&&!t.synthetic&&(13==t.keyCode||8==t.keyCode))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return!Ge.ios||t.synthetic||t.altKey||t.metaKey||!((e=Gn.find(e=>e.keyCode==t.keyCode))&&!t.ctrlKey||Yn.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(229!=t.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0)}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(!("Enter"==e.key&&t&&t.from0||!!(Ge.safari&&!Ge.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Kn(t,e){return(i,n)=>{try{return e.call(t,n,i)}catch(t){nn(i.state,t)}}}function Un(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let e of t){let t=e.spec,n=t&&t.plugin.domEventHandlers,s=t&&t.plugin.domEventObservers;if(n)for(let t in n){let s=n[t];s&&i(t).handlers.push(Kn(e.value,s))}if(s)for(let t in s){let n=s[t];n&&i(t).observers.push(Kn(e.value,n))}}for(let t in Qn)i(t).handlers.push(Qn[t]);for(let t in ts)i(t).observers.push(ts[t]);return e}const Gn=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Yn="dthko",Xn=[16,17,18,20,91,92,224,225];function Jn(t){return.7*Math.max(0,t)+8}class Zn{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=function(t){let e,i,n=t.ownerDocument;for(let s=t.parentNode;s&&!(s==n.body||e&&i);)if(1==s.nodeType)!i&&s.scrollHeight>s.clientHeight&&(i=s),!e&&s.scrollWidth>s.clientWidth&&(e=s),s=s.assignedSlot||s.parentNode;else{if(11!=s.nodeType)break;s=s.host}return{x:e,y:i}}(t.contentDOM),this.atoms=t.state.facet(dn).map(e=>e(t));let s=t.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(Dt.allowMultipleSelections)&&function(t,e){let i=t.state.facet(Vi);return i.length?i[0](e):Ge.mac?e.metaKey:e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let n=ae(t.root);if(!n||0==n.rangeCount)return!0;let s=n.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!=fs(e))&&null}start(t){!1===this.dragging&&this.select(t)}move(t){if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(e=this.startEvent,i=t,Math.max(Math.abs(e.clientX-i.clientX),Math.abs(e.clientY-i.clientY))<10))return;var e,i;this.select(this.lastEvent=t);let n=0,s=0,r=0,o=0,l=this.view.win.innerWidth,a=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:o,bottom:a}=this.scrollParents.y.getBoundingClientRect());let h=vn(this.view);t.clientX-h.left<=r+6?n=-Jn(r-t.clientX):t.clientX+h.right>=l-6&&(n=Jn(t.clientX-l)),t.clientY-h.top<=o+6?s=-Jn(o-t.clientY):t.clientY+h.bottom>=a-6&&(s=Jn(t.clientY-a)),this.setScrollSpeed(n,s)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),!1===this.dragging&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=Nn(this.atoms,this.style.get(t,this.extend,this.multiple));!this.mustSelect&&i.eq(e.state.selection,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}const Qn=Object.create(null),ts=Object.create(null),es=Ge.ie&&Ge.ie_version<15||Ge.ios&&Ge.webkit_version<604;function is(t,e,i){for(let n of t.facet(e))i=n(i,t);return i}function ns(t,e){e=is(t.state,Gi,e);let i,{state:n}=t,s=1,r=n.toText(e),o=r.lines==n.selection.ranges.length;if(null!=ps&&n.selection.ranges.every(t=>t.empty)&&ps==r.toString()){let t=-1;i=n.changeByRange(i=>{let l=n.doc.lineAt(i.from);if(l.from==t)return{range:i};t=l.from;let a=n.toText((o?r.line(s++).text:e)+n.lineBreak);return{changes:{from:l.from,insert:a},range:z.cursor(i.from+a.length)}})}else i=o?n.changeByRange(t=>{let e=r.line(s++);return{changes:{from:t.from,to:t.to,insert:e.text},range:z.cursor(t.from+e.length)}}):n.replaceSelection(r);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function ss(t,e,i,n){if(1==n)return z.cursor(e,i);if(2==n)return function(t,e,i=1){let n=t.charCategorizer(e),s=t.doc.lineAt(e),r=e-s.from;if(0==s.length)return z.cursor(e);0==r?i=1:r==s.length&&(i=-1);let o=r,l=r;i<0?o=k(s.text,r,!1):l=k(s.text,r);let a=n(s.text.slice(o,l));for(;o>0;){let t=k(s.text,o,!1);if(n(s.text.slice(t,o))!=a)break;o=t}for(;l{t.inputState.lastScrollTop=t.scrollDOM.scrollTop,t.inputState.lastScrollLeft=t.scrollDOM.scrollLeft},Qn.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),27==e.keyCode&&0!=t.inputState.tabFocusMode&&(t.inputState.tabFocusMode=Date.now()+2e3),!1),ts.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},ts.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},Qn.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let n of t.state.facet($i))if(i=n(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=ls(t,e),n=fs(e),s=t.state.selection;return{update(t){t.docChanged&&(i.pos=t.changes.mapPos(i.pos),s=s.map(t.changes))},get(e,r,o){let l,a=ls(t,e),h=ss(t,a.pos,a.bias,n);if(i.pos!=a.pos&&!r){let e=ss(t,i.pos,i.bias,n),s=Math.min(e.from,h.from),r=Math.max(e.to,h.to);h=s1&&(l=function(t,e){for(let i=0;i=e)return z.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}(s,a.pos))?l:o?s.addRange(h):z.create([h])}}}(t,e)),i){let n=!t.hasFocus;t.inputState.startMouseSelection(new Zn(t,e,i,n)),n&&t.observer.ignore(()=>{Se(t.contentDOM);let e=t.root.activeElement;e&&!e.contains(t.contentDOM)&&e.blur()});let s=t.inputState.mouseSelection;if(s)return s.start(e),!1===s.dragging}else t.inputState.setSelectionOrigin("select.pointer");return!1};let rs=(t,e,i)=>e>=i.top&&e<=i.bottom&&t>=i.left&&t<=i.right;function os(t,e,i,n){let s=gi.find(t.docView,e);if(!s)return 1;let r=e-s.posAtStart;if(0==r)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&rs(i,n,o))return-1;let l=s.coordsAt(r,1);return l&&rs(i,n,l)?1:o&&o.bottom>=n?-1:1}function ls(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:i,bias:os(t,i,e.clientX,e.clientY)}}const as=Ge.ie&&Ge.ie_version<=11;let hs=null,cs=0,us=0;function fs(t){if(!as)return t.detail;let e=hs,i=us;return hs=t,us=Date.now(),cs=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(cs+1)%3:1}function ds(t,e,i,n){if(!(i=is(t.state,Gi,i)))return;let s=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=t.inputState,o=n&&r&&function(t,e){let i=t.state.facet(Wi);return i.length?i[0](e):Ge.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:r.from,to:r.to}:null,l={from:s,insert:i},a=t.state.changes(o?[o,l]:l);t.focus(),t.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),t.inputState.draggedContent=null}Qn.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let n=t.docView.nearest(e.target);if(n&&n.isWidget){let t=n.posAtStart,e=t+n.length;(t>=i.to||e<=i.from)&&(i=z.range(t,e))}}let{inputState:n}=t;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",is(t.state,Yi,t.state.sliceDoc(i.from,i.to))),e.dataTransfer.effectAllowed="copyMove"),!1},Qn.dragend=t=>(t.inputState.draggedContent=null,!1),Qn.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let n=Array(i.length),s=0,r=()=>{++s==i.length&&ds(t,e,n.filter(t=>null!=t).join(t.state.lineBreak),!1)};for(let t=0;t{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(n[t]=e.result),r()},e.readAsText(i[t])}return!0}{let i=e.dataTransfer.getData("Text");if(i)return ds(t,e,i,!0),!0}return!1},Qn.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=es?null:e.clipboardData;return i?(ns(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{t.focus(),i.remove(),ns(t,i.value)},50)}(t),!1)};let ps=null;Qn.copy=Qn.cut=(t,e)=>{let{text:i,ranges:n,linewise:s}=function(t){let e=[],i=[],n=!1;for(let n of t.selection.ranges)n.empty||(e.push(t.sliceDoc(n.from,n.to)),i.push(n));if(!e.length){let s=-1;for(let{from:n}of t.selection.ranges){let r=t.doc.lineAt(n);r.number>s&&(e.push(r.text),i.push({from:r.from,to:Math.min(t.doc.length,r.to+1)})),s=r.number}n=!0}return{text:is(t,Yi,e.join(t.lineBreak)),ranges:i,linewise:n}}(t.state);if(!i&&!s)return!1;ps=s?i:null,"cut"!=e.type||t.state.readOnly||t.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let r=es?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",i),!0):(function(t,e){let i=t.dom.parentNode;if(!i)return;let n=i.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),t.focus()},50)}(t,i),!1)};const ms=dt.define();function gs(t,e){let i=[];for(let n of t.facet(Ui)){let s=n(t,e);s&&i.push(s)}return i.length?t.update({effects:i,annotations:ms.of(!0)}):null}function vs(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=gs(t.state,e);i?t.dispatch(i):t.update([])}},10)}ts.focus=t=>{t.inputState.lastFocusTime=Date.now(),t.scrollDOM.scrollTop||!t.inputState.lastScrollTop&&!t.inputState.lastScrollLeft||(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),vs(t)},ts.blur=t=>{t.observer.clearSelectionRange(),vs(t)},ts.compositionstart=ts.compositionupdate=t=>{t.observer.editContext||(null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0))},ts.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,Ge.chrome&&Ge.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))},ts.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},Qn.beforeinput=(t,e)=>{var i,n;if("insertReplacementText"==e.inputType&&t.observer.editContext){let n=null===(i=e.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),s=e.getTargetRanges();if(n&&s.length){let e=s[0],i=t.posAtDOM(e.startContainer,e.startOffset),r=t.posAtDOM(e.endContainer,e.endOffset);return _n(t,{from:i,to:r,insert:t.state.toText(n)},null),!0}}let s;if(Ge.chrome&&Ge.android&&(s=Gn.find(t=>t.inputType==e.inputType))&&(t.observer.delayAndroidKey(s.key,s.keyCode),"Backspace"==s.key||"Delete"==s.key)){let e=(null===(n=window.visualViewport)||void 0===n?void 0:n.height)||0;setTimeout(()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return Ge.ios&&"deleteContentForward"==e.inputType&&t.observer.flushSoon(),Ge.safari&&"insertText"==e.inputType&&t.inputState.composing>=0&&setTimeout(()=>ts.compositionend(t,e),20),!1};const ws=new Set;const bs=["pre-wrap","normal","pre-line","break-spaces"];let ys=!1;function xs(){ys=!1}class ks{constructor(t){this.lineWrapping=t,this.doc=f.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return bs.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i-1,l=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=s,l){this.heightSamples={};for(let t=0;t0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>Ms&&(ys=!0),this.height=t)}replace(t,e,i){return Ts.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let s=this,r=i.doc;for(let o=n.length-1;o>=0;o--){let{fromA:l,toA:a,fromB:h,toB:c}=n[o],u=s.lineAt(l,As.ByPosNoHeight,i.setDoc(e),0,0),f=u.to>=a?u:s.lineAt(a,As.ByPosNoHeight,i,0,0);for(c+=f.to-a,a=f.to;o>0&&u.from<=n[o-1].toA;)l=n[o-1].fromA,h=n[o-1].fromB,o--,l2*s){let s=t[e-1];s.break?t.splice(--e,1,s.left,null,s.right):t.splice(--e,1,s.left,s.right),i+=1+s.break,n-=s.size}else{if(!(s>2*n))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,s-=e.size}}else if(n=s&&r(this.blockAt(0,i,n,s))}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setHeight(n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Rs extends Os{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,n){return new Cs(n,this.length,i,this.height,this.breaks)}replace(t,e,i){let n=i[0];return 1==i.length&&(n instanceof Rs||n instanceof Es&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof Es?n=new Rs(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):Ts.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setHeight(n.heights[n.index++]):(i||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Es extends Ts{constructor(t){super(t,0)}heightMetrics(t,e){let i,n=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-n+1,o=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*r);i=e/r,this.length>r+1&&(o=(this.height-e)/(this.length-r-1))}else i=this.height/r;return{firstLine:n,lastLine:s,perLine:i,perChar:o}}blockAt(t,e,i,n){let{firstLine:s,lastLine:r,perLine:o,perChar:l}=this.heightMetrics(e,n);if(e.lineWrapping){let s=n+(t0){let t=i[i.length-1];t instanceof Es?i[i.length-1]=new Es(t.length+n):i.push(null,new Es(n-1))}if(t>0){let e=i[0];e instanceof Es?i[0]=new Es(t+e.length):i.unshift(new Es(t-1),null)}return Ts.of(i)}decomposeLeft(t,e){e.push(new Es(t-1),null)}decomposeRight(t,e){e.push(null,new Es(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let s=e+this.length;if(n&&n.from<=e+this.length&&n.more){let i=[],r=Math.max(e,n.from),o=-1;for(n.from>e&&i.push(new Es(n.from-e-1).updateHeight(t,e));r<=s&&n.more;){let e=t.doc.lineAt(r).length;i.length&&i.push(null);let s=n.heights[n.index++];-1==o?o=s:Math.abs(s-o)>=Ms&&(o=-2);let l=new Rs(e,s);l.outdated=!1,i.push(l),r+=e+1}r<=s&&i.push(null,new Es(s-r).updateHeight(t,r));let l=Ts.of(i);return(o<0||Math.abs(l.height-this.height)>=Ms||Math.abs(o-this.heightMetrics(t,e).perLine)>=Ms)&&(ys=!0),Ds(this,l)}return(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class Ps extends Ts{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,n){let s=i+this.left.height;return to))return a;let h=e==As.ByPosNoHeight?As.ByPosNoHeight:As.ByPos;return l?a.join(this.right.lineAt(o,h,i,r,o)):this.left.lineAt(o,h,i,n,s).join(a)}forEachLine(t,e,i,n,s,r){let o=n+this.left.height,l=s+this.left.length+this.break;if(this.break)t=l&&this.right.forEachLine(t,e,i,o,l,r);else{let a=this.lineAt(l,As.ByPos,i,n,s);t=t&&a.from<=e&&r(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,o,l,r)}}replace(t,e,i){let n=this.left.length+this.break;if(ethis.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let s=[];t>0&&this.decomposeLeft(t,s);let r=s.length;for(let t of i)s.push(t);if(t>0&&Ls(s,r-1),e=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t2*e.size||e.size>2*t.size?Ts.of(this.break?[t,null,e]:[t,e]):(this.left=Ds(this.left,t),this.right=Ds(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:s,right:r}=this,o=e+s.length+this.break,l=null;return n&&n.from<=e+s.length&&n.more?l=s=s.updateHeight(t,e,i,n):s.updateHeight(t,e,i),n&&n.from<=o+r.length&&n.more?l=r=r.updateHeight(t,o,i,n):r.updateHeight(t,o,i),l?this.balanced(s,r):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Ls(t,e){let i,n;null==t[e]&&(i=t[e-1])instanceof Es&&(n=t[e+1])instanceof Es&&t.splice(e-1,3,new Es(i.length+1+n.length))}class Bs{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 Rs?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new Rs(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(n,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 Rs(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new Es(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 Rs)return t;let e=new Rs(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof Rs||this.isCovered?(this.writtenToi.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=n.overflow){let n=i.getBoundingClientRect();r=Math.max(r,n.left),o=Math.min(o,n.right),l=Math.max(l,n.top),a=Math.min(e==t.parentNode?s.innerHeight:a,n.bottom)}e="absolute"==n.position||"fixed"==n.position?i.offsetParent:i.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:r-i.left,right:Math.max(r,o)-i.left,top:l-(i.top+e),bottom:Math.max(l,a)-(i.top+e)}}function zs(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class qs{constructor(t,e,i,n){this.from=t,this.to=e,this.size=i,this.displaySize=n}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i"function"!=typeof t&&"cm-lineWrapping"==t.class);this.heightOracle=new ks(e),this.stateDeco=t.facet(un).filter(t=>"function"!=typeof t),this.heightMap=Ts.empty().applyChanges(this.stateDeco,f.empty,this.heightOracle.setDoc(t.doc),[new bn(0,0,0,t.doc.length)]);for(let t=0;t<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());t++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ci.set(this.lineGaps.map(t=>t.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:t,to:e})=>n>=t&&n<=e)){let{from:e,to:i}=this.lineBlockAt(n);t.push(new Vs(e,i))}}return this.viewports=t.sort((t,e)=>t.from-e.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?_s:new js(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(Ks(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(un).filter(t=>"function"!=typeof t);let n=t.changedRanges,s=bn.extendWithRanges(n,function(t,e,i){let n=new Is;return Bt.compare(t,e,i,n,0),n.changes}(i,this.stateDeco,t?t.changes:O.empty(this.state.doc.length))),r=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);xs(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=r||ys)&&(t.flags|=2),o?(this.scrollAnchorPos=t.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=r);let l=s.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.headl.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,e));let a=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,t.flags|=this.updateForViewport(),(a||!t.changes.empty||2&t.flags)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(Ji)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,s=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?ki.RTL:ki.LTR;let r=this.heightOracle.mustRefreshForWrapping(s),o=e.getBoundingClientRect(),l=r||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let a=0,h=0;if(o.width&&o.height){let{scaleX:t,scaleY:i}=be(e,o);(t>.005&&Math.abs(this.scaleX-t)>.005||i>.005&&Math.abs(this.scaleY-i)>.005)&&(this.scaleX=t,this.scaleY=i,a|=16,r=l=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;this.paddingTop==c&&this.paddingBottom==u||(this.paddingTop=c,this.paddingBottom=u,a|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,a|=16);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Te(t.scrollDOM);let p=(this.printing?zs:Ns)(e,this.paddingTop),m=p.top-this.pixelViewport.top,g=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let v=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(v!=this.inView&&(this.inView=v,v&&(l=!0)),!this.inView&&!this.scrollTarget&&!function(t){let e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView||window;return e.left0&&e.top0}(t.dom))return 0;let w=o.width;if(this.contentDOMWidth==w&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=o.width,this.editorHeight=t.scrollDOM.clientHeight,a|=16),l){let e=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(e)&&(r=!0),r||n.lineWrapping&&Math.abs(w-this.contentDOMWidth)>n.charWidth){let{lineHeight:i,charWidth:o,textHeight:l}=t.docView.measureTextSize();r=i>0&&n.refresh(s,i,o,l,Math.max(5,w/o),e),r&&(t.docView.minWidth=0,a|=16)}m>0&&g>0?h=Math.max(m,g):m<0&&g<0&&(h=Math.min(m,g)),xs();for(let i of this.viewports){let s=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=(r?Ts.empty().applyChanges(this.stateDeco,f.empty,this.heightOracle,[new bn(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,r,new Ss(i.from,s))}ys&&(a|=2)}let b=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return b&&(2&a&&(a|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),a|=this.updateForViewport()),(2&a||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(r?[]:this.lineGaps,t)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,s=this.heightOracle,{visibleTop:r,visibleBottom:o}=this,l=new Vs(n.lineAt(r-1e3*i,As.ByHeight,s,0,0).from,n.lineAt(o+1e3*(1-i),As.ByHeight,s,0,0).to);if(e){let{head:t}=e.range;if(tl.to){let i,r=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),o=n.lineAt(t,As.ByPos,s,0,0);i="center"==e.y?(o.top+o.bottom)/2-r/2:"start"==e.y||"nearest"==e.y&&t=o+Math.max(10,Math.min(i,250)))&&n>r-2e3&&s>1,r=n<<1;if(this.defaultTextDirection!=ki.LTR&&!i)return[];let o=[],l=(n,r,a,h)=>{if(r-nn&&tt.from>=a.from&&t.to<=a.to&&Math.abs(t.from-n)t.frome));if(!f){if(rt.from<=r&&t.to>=r)){let t=e.moveToLineBoundary(z.cursor(r),!1,!0).head;t>n&&(r=t)}let t=this.gapSize(a,n,r,h);f=new qs(n,r,t,i||t<2e6?t:2e6)}o.push(f)},a=e=>{if(e.lengths&&(n.push({from:s,to:t}),r+=t-s),s=e}},20),s2e6)for(let i of t)i.from>=e.from&&i.frome.from&&l(e.from,o,e,s),at.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];Bt.spans(e,this.viewport.from,this.viewport.to,{span(t,e){i.push({from:t,to:e})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let e=0;e=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Ks(this.heightMap.lineAt(t,As.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Ks(this.heightMap.lineAt(this.scaler.fromDOM(t),As.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Ks(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Vs{constructor(t,e){this.from=t,this.to=e}}function Ws({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let n=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:s}=e[t],r=s-i;if(n<=r)return i+n;n-=r}}function $s(t,e){let i=0;for(let{from:n,to:s}of t.ranges){if(e<=s){i+=e-n;break}i+=s-n}return i/t.total}const _s={toDOM:t=>t,fromDOM:t=>t,scale:1,eq(t){return t==this}};class js{constructor(t,e,i){let n=0,s=0,r=0;this.viewports=i.map(({from:i,to:s})=>{let r=e.lineAt(i,As.ByPos,t,0,0).top,o=e.lineAt(s,As.ByPos,t,0,0).bottom;return n+=o-r,{from:i,to:s,top:r,bottom:o,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);for(let t of this.viewports)t.domTop=r+(t.top-s)*this.scale,r=t.domBottom=t.domTop+(t.bottom-t.top),s=t.bottom}toDOM(t){for(let e=0,i=0,n=0;;e++){let s=ee.from==t.viewports[i].from&&e.to==t.viewports[i].to))}}function Ks(t,e){if(1==e.scale)return t;let i=e.toDOM(t.top),n=e.toDOM(t.bottom);return new Cs(t.from,t.length,i,n-i,Array.isArray(t._content)?t._content.map(t=>Ks(t,e)):t._content)}const Us=H.define({combine:t=>t.join(" ")}),Gs=H.define({combine:t=>t.indexOf(!0)>-1}),Ys=Jt.newName(),Xs=Jt.newName(),Js=Jt.newName(),Zs={"&light":"."+Xs,"&dark":"."+Js};function Qs(t,e,i){return new Jt(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 tr=Qs("."+Ys,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Zs),er={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},ir=Ge.ie&&Ge.ie_version<=11;class nr{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new ye,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let t of e)this.queue.push(t);(Ge.ie&&Ge.ie_version<=11||Ge.ios&&t.composing)&&e.some(t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length)?this.flushSoon():this.flush()}),!window.EditContext||!Ge.android||!1===t.constructor.EDIT_CONTEXT||Ge.chrome&&Ge.chrome_version<126||(this.editContext=new or(t),t.state.facet(sn)&&(t.contentDOM.editContext=this.editContext.editContext)),ir&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver(()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){("change"!=t.type&&t.type||t.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(sn)?i.root.activeElement!=this.dom:!ce(this.dom,n))return;let s=n.anchorNode&&i.docView.nearest(n.anchorNode);s&&s.ignoreEvent(t)?e||(this.selectionChanged=!1):(Ge.ie&&Ge.ie_version<=11||Ge.android&&Ge.chrome)&&!i.state.selection.main.empty&&n.focusNode&&fe(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=ae(t.root);if(!e)return!1;let i=Ge.safari&&11==t.root.nodeType&&t.root.activeElement==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return rr(t,i)}let i=null;function n(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",n,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",n,!0),i?rr(t,i):null}(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=ce(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&Ae(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let s of t){let t=this.readMutation(s);t&&(t.typeOver&&(n=!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:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&ce(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new Wn(this.view,t,e,i);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=$n(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),n}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.flags|=4),"childList"==t.type){let i=sr(e,t.previousSibling||t.target.previousSibling,-1),n=sr(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(sn)!=t.state.facet(sn)&&(t.view.contentDOM.editContext=t.state.facet(sn)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function sr(t,e,i){for(;e;){let n=Pe.get(e);if(n&&n.parent==t)return n;let s=e.parentNode;e=s!=t.dom?s:i>0?e.nextSibling:e.previousSibling}return null}function rr(t,e){let i=e.startContainer,n=e.startOffset,s=e.endContainer,r=e.endOffset,o=t.docView.domAtPos(t.state.selection.main.anchor);return fe(o.node,o.offset,s,r)&&([i,n,s,r]=[s,r,i,n]),{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}}class or{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=e=>{let i=t.state.selection.main,{anchor:n,head:s}=i,r=this.toEditorPos(e.updateRangeStart),o=this.toEditorPos(e.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:e.updateRangeStart,editorBase:r,drifted:!1});let l={from:r,to:o,insert:f.of(e.text.split("\n"))};if(l.from==this.from&&nthis.to&&(l.to=n),l.from==l.to&&!l.insert.length){let n=z.single(this.toEditorPos(e.selectionStart),this.toEditorPos(e.selectionEnd));return void(n.main.eq(i)||t.dispatch({selection:n,userEvent:"select"}))}if((Ge.mac||Ge.android)&&l.from==s-1&&/^\. ?$/.test(e.text)&&"off"==t.contentDOM.getAttribute("autocorrect")&&(l={from:r,to:o,insert:f.of([e.text.replace("."," ")])}),this.pendingContextChange=l,!t.state.readOnly){let i=this.to-this.from+(l.to-l.from+l.insert.length);_n(t,l,z.single(this.toEditorPos(e.selectionStart,i),this.toEditorPos(e.selectionEnd,i)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state))},this.handlers.characterboundsupdate=i=>{let n=[],s=null;for(let e=this.toEditorPos(i.rangeStart),r=this.toEditorPos(i.rangeEnd);e{let i=[];for(let t of e.getTextFormats()){let e=t.underlineStyle,n=t.underlineThickness;if("None"!=e&&"None"!=n){let s=this.toEditorPos(t.rangeStart),r=this.toEditorPos(t.rangeEnd);if(s{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:e}=this.composing;this.composing=null,e&&this.reset(t.state)}};for(let t in this.handlers)e.addEventListener(t,this.handlers[t]);this.measureReq={read:t=>{this.editContext.updateControlBounds(t.contentDOM.getBoundingClientRect());let e=ae(t.root);e&&e.rangeCount&&this.editContext.updateSelectionBounds(e.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((s,r,o,l,a)=>{if(i)return;let h=a.length-(r-s);if(n&&r>=n.to){if(n.from==s&&n.to==r&&n.insert.eq(a))return n=this.pendingContextChange=null,e+=h,void(this.to+=h);n=null,this.revertPending(t.state)}if(s+=e,(r+=e)<=this.from)this.from+=h,this.to+=h;else if(sthis.to||this.to-this.from+a.length>3e4)return void(i=!0);this.editContext.updateText(this.toContextPos(s),this.toContextPos(r),a.toString()),this.to+=h}e+=h}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(t=>!t.isUserEvent("input.type")&&t.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):this.applyEdits(t)&&this.rangeIsValid(t.state)?(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state):(this.pendingContextChange=null,this.reset(t.state)),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);this.editContext.selectionStart==i&&this.editContext.selectionEnd==n||this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to3e4)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class lr{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(t=>t.forEach(t=>i(t,this)))||(t=>this.update(t)),this.dispatch=this.dispatch.bind(this),this._root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new Hs(t.state||Dt.create(t)),t.scrollTo&&t.scrollTo.is(tn)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(on).map(t=>new an(t));for(let t of this.plugins)t.update(this);this.observer=new nr(this),this.inputState=new jn(this),this.inputState.ensureHandlers(this.plugins),this.docView=new xn(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),(null===(e=document.fonts)||void 0===e?void 0:e.ready)&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...t){let e=1==t.length&&t[0]instanceof vt?t:1==t.length&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,n=!1,s=this.state;for(let e of t){if(e.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=e.state}if(this.destroyed)return void(this.viewState.state=s);let r=this.hasFocus,o=0,l=null;t.some(t=>t.annotation(ms))?(this.inputState.notifiedFocused=r,o=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,l=gs(s,r),l||(o=1));let a=this.observer.delayedAndroidKey,h=null;if(a?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(h=null)):this.observer.clear(),s.facet(Dt.phrases)!=this.state.facet(Dt.phrases))return this.setState(s);e=yn.create(this,s,t),e.flags|=o;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(c&&(c=c.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection;c=new Qi(t.empty?t:z.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(tn)&&(c=t.value.clip(this.state))}this.viewState.update(e,c),this.bidiCache=cr.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(wn)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some(t=>t.isUserEvent("select.pointer")))}finally{this.updateState=0}if(e.startState.facet(Us)!=e.state.facet(Us)&&(this.viewState.mustMeasureContent=!0),(i||n||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!e.empty)for(let t of this.state.facet(ji))try{t(e)}catch(t){nn(this.state,t,"update listener")}(l||h)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),h&&!$n(this,h)&&a.force&&Ae(this.contentDOM,a.key,a.keyCode)})}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new Hs(t),this.plugins=t.facet(on).map(t=>new an(t)),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy(),this.docView=new xn(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(on),i=t.state.facet(on);if(e!=i){let n=[];for(let s of i){let i=e.indexOf(s);if(i<0)n.push(new an(s));else{let e=this.plugins[i];e.mustUpdate=t,n.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,n=i.scrollTop*this.scaleY,{scrollAnchorPos:s,scrollAnchorHeight:r}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(r=-1),this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(r<0)if(Te(i))s=-1,r=this.viewState.heightMap.height;else{let t=this.viewState.scrollAnchorAt(n);s=t.from,r=t.top}this.updateState=1;let o=this.viewState.measure(this);if(!o&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let l=[];4&o||([this.measureRequests,l]=[l,this.measureRequests]);let a=l.map(t=>{try{return t.read(this)}catch(t){return nn(this.state,t),hr}}),h=yn.create(this,this.state,[]),c=!1;h.flags|=o,e?e.flags|=o:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),c=this.docView.update(h),c&&this.docViewUpdate());for(let t=0;t1||t<-1){n+=t,i.scrollTop=n/this.scaleY,r=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let t of this.state.facet(ji))t(e)}get themeClasses(){return Ys+" "+(this.state.facet(Gs)?Js:Xs)+" "+this.state.facet(Us)}updateAttrs(){let t=ur(this,hn,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(sn)?"true":"false",class:"cm-content",style:`${Ge.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),ur(this,cn,e);let i=this.observer.ignore(()=>{let i=oi(this.contentDOM,this.contentAttrs,e),n=oi(this.dom,this.editorAttrs,t);return i||n});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)if(t.is(lr.announce)){e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(wn);let t=this.state.facet(lr.cspNonce);Jt.mount(this.root,this.styleModules.concat(tr).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(null!=t.key)for(let e=0;ee.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return zn(this,t,Bn(this,t,e,i))}moveByGroup(t,e){return zn(this,t,Bn(this,t,e,e=>function(t,e,i){let n=t.state.charCategorizer(e),s=n(i);return t=>{let e=n(t);return s==Ct.Space&&(s=e),s==e}}(this,t.head,e)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),s=i[e?i.length-1:0];return z.cursor(s.side(e,n)+t.from,s.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return function(t,e,i,n){let s=Ln(t,e.head,e.assoc||-1),r=n&&s.type==hi.Text&&(t.lineWrapping||s.widgetLineBreaks)?t.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head):null;if(r){let e=t.dom.getBoundingClientRect(),n=t.textDirectionAt(s.from),o=t.posAtCoords({x:i==(n==ki.LTR)?e.right-1:e.left+1,y:(r.top+r.bottom)/2});if(null!=o)return z.cursor(o,i?-1:1)}return z.cursor(i?s.to:s.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return zn(this,t,function(t,e,i,n){let s=e.head,r=i?1:-1;if(s==(i?t.state.doc.length:0))return z.cursor(s,e.assoc);let o,l=e.goalColumn,a=t.contentDOM.getBoundingClientRect(),h=t.coordsAtPos(s,e.assoc||-1),c=t.documentTop;if(h)null==l&&(l=h.left-a.left),o=r<0?h.top:h.bottom;else{let e=t.viewState.lineBlockAt(s);null==l&&(l=Math.min(a.right-a.left,t.defaultCharacterWidth*(s-e.from))),o=(r<0?e.top:e.bottom)+c}let u=a.left+l,f=null!=n?n:t.viewState.heightOracle.textHeight>>1;for(let e=0;;e+=10){let i=o+(f+e)*r,n=En(t,{x:u,y:i},!1,r);if(ia.bottom||(r<0?ns)){let e=t.docView.coordsForChar(n),s=!e||i0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Xi)||tthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>ar)return zi(t.length);let e,i=this.textDirectionAt(t.from);for(let n of this.bidiCache)if(n.from==t.from&&n.dir==i&&(n.fresh||Li(n.isolates,e=mn(this,t))))return n.order;e||(e=mn(this,t));let n=function(t,e,i){if(!t)return[new Pi(0,0,e==Ci?1:0)];if(e==Si&&!i.length&&!Ei.test(t))return zi(t.length);if(i.length)for(;t.length>Bi.length;)Bi[Bi.length]=256;let n=[],s=e==Si?0:1;return Ni(t,s,s,i,0,t.length,n),n}(t.text,i,e);return this.bidiCache.push(new cr(t.from,t.to,i,e,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||Ge.safari&&(null===(t=this.inputState)||void 0===t?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Se(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((9==t.nodeType?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return tn.of(new Qi("number"==typeof t?z.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return tn.of(new Qi(z.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){null==t?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:"boolean"==typeof t?this.inputState.tabFocusMode=t?0:-1:0!=this.inputState.tabFocusMode&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return ln.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return ln.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=Jt.newName(),n=[Us.of(i),wn.of(Qs(`.${i}`,t))];return e&&e.dark&&n.push(Gs.of(!0)),n}static baseTheme(t){return Q.lowest(wn.of(Qs("."+Ys,t,Zs)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&Pe.get(i)||Pe.get(t);return(null===(e=null==n?void 0:n.rootView)||void 0===e?void 0:e.view)||null}}lr.styleModule=wn,lr.inputHandler=Ki,lr.clipboardInputFilter=Gi,lr.clipboardOutputFilter=Yi,lr.scrollHandler=Zi,lr.focusChangeEffect=Ui,lr.perLineTextDirection=Xi,lr.exceptionSink=_i,lr.updateListener=ji,lr.editable=sn,lr.mouseSelectionStyle=$i,lr.dragMovesSelection=Wi,lr.clickAddsSelectionRange=Vi,lr.decorations=un,lr.outerDecorations=fn,lr.atomicRanges=dn,lr.bidiIsolatedRanges=pn,lr.scrollMargins=gn,lr.darkTheme=Gs,lr.cspNonce=H.define({combine:t=>t.length?t[0]:""}),lr.contentAttributes=cn,lr.editorAttributes=hn,lr.lineWrapping=lr.contentAttributes.of({class:"cm-lineWrapping"}),lr.announce=gt.define();const ar=4096,hr={};class cr{constructor(t,e,i,n,s,r){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=s,this.order=r}static update(t,e){if(e.empty&&!t.some(t=>t.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:ki.LTR;for(let s=Math.max(0,t.length-10);s=0;s--){let e=n[s],r="function"==typeof e?e(t):e;r&&ni(r,i)}return i}const fr=Ge.mac?"mac":Ge.windows?"win":Ge.linux?"linux":"key";function dr(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 pr=Q.default(lr.domEventHandlers({keydown:(t,e)=>xr(vr(e.state),t,e,"editor")})),mr=H.define({enables:pr}),gr=new WeakMap;function vr(t){let e=t.facet(mr),i=gr.get(e);return i||gr.set(e,i=function(t,e=fr){let i=Object.create(null),n=Object.create(null),s=(t,e)=>{let i=n[t];if(null==i)n[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")},r=(t,n,r,o,l)=>{var a,h;let c=i[t]||(i[t]=Object.create(null)),u=n.split(/ (?!$)/).map(t=>function(t,e){const i=t.split(/-(?!$)/);let n,s,r,o,l=i[i.length-1];"Space"==l&&(l=" ");for(let t=0;t{let n=wr={view:e,prefix:i,scope:t};return setTimeout(()=>{wr==n&&(wr=null)},br),!0}]})}let f=u.join(" ");s(f,!1);let d=c[f]||(c[f]={preventDefault:!1,stopPropagation:!1,run:(null===(h=null===(a=c._any)||void 0===a?void 0:a.run)||void 0===h?void 0:h.slice())||[]});r&&d.run.push(r),o&&(d.preventDefault=!0),l&&(d.stopPropagation=!0)};for(let n of t){let t=n.scope?n.scope.split(" "):["editor"];if(n.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));t._any||(t._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:s}=n;for(let e in t)t[e].run.push(t=>s(t,yr))}let s=n[e]||n.key;if(s)for(let e of t)r(e,s,n.run,n.preventDefault,n.stopPropagation),n.shift&&r(e,"Shift-"+s,n.shift,n.preventDefault,n.stopPropagation)}return i}(e.reduce((t,e)=>t.concat(e),[]))),i}let wr=null;const br=4e3;let yr=null;function xr(t,e,i,n){yr=e;let s=function(t){var e=!(ie&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||ne&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?ee:te)[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),r=A(S(s,0))==s.length&&" "!=s,o="",l=!1,a=!1,h=!1;wr&&wr.view==i&&wr.scope==n&&(o=wr.prefix+" ",Xn.indexOf(e.keyCode)<0&&(a=!0,wr=null));let c,u,f=new Set,d=t=>{if(t){for(let e of t.run)if(!f.has(e)&&(f.add(e),e(i)))return t.stopPropagation&&(h=!0),!0;t.preventDefault&&(t.stopPropagation&&(h=!0),a=!0)}return!1},p=t[n];return p&&(d(p[o+dr(s,e,!r)])?l=!0:!r||!(e.altKey||e.metaKey||e.ctrlKey)||Ge.windows&&e.ctrlKey&&e.altKey||Ge.mac&&e.altKey&&!e.ctrlKey&&!e.metaKey||!(c=te[e.keyCode])||c==s?r&&e.shiftKey&&d(p[o+dr(s,e,!0)])&&(l=!0):(d(p[o+dr(c,e,!0)])||e.shiftKey&&(u=ee[e.keyCode])!=s&&u!=c&&d(p[o+dr(u,e,!1)]))&&(l=!0),!l&&d(p._any)&&(l=!0)),a&&(l=!0),l&&h&&e.stopPropagation(),yr=null,l}class kr{constructor(t,e,i,n,s){this.className=t,this.left=e,this.top=i,this.width=n,this.height=s}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className==this.className&&(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",null!=this.width&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let n=t.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let s=Sr(t);return[new kr(e,n.left-s.left,n.top-s.top,null,n.bottom-n.top)]}return function(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let n=Math.max(i.from,t.viewport.from),s=Math.min(i.to,t.viewport.to),r=t.textDirection==ki.LTR,o=t.contentDOM,l=o.getBoundingClientRect(),a=Sr(t),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),u=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=l.right-(c?parseInt(c.paddingRight):0),d=Ln(t,n,1),p=Ln(t,s,-1),m=d.type==hi.Text?d:null,g=p.type==hi.Text?p:null;m&&(t.lineWrapping||d.widgetLineBreaks)&&(m=Cr(t,n,1,m));g&&(t.lineWrapping||p.widgetLineBreaks)&&(g=Cr(t,s,-1,g));if(m&&g&&m.from==g.from&&m.to==g.to)return w(b(i.from,i.to,m));{let e=m?b(i.from,null,m):y(d,!1),n=g?b(null,i.to,g):y(p,!0),s=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2h&&n.from=r)break;l>s&&a(Math.max(t,s),null==e&&t<=h,Math.min(l,r),null==i&&l>=c,o.dir)}if(s=n.to+1,s>=r)break}return 0==l.length&&a(h,null==e,c,null==i,t.textDirection),{top:s,bottom:o,horizontal:l}}function y(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(t,e,i)}}function Sr(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==ki.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function Cr(t,e,i,n){let s=t.coordsAtPos(e,2*i);if(!s)return n;let r=t.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=t.posAtCoords({x:r.left+1,y:o}),a=t.posAtCoords({x:r.right-1,y:o});return null==l||null==a?n:{from:Math.max(n.from,Math.min(l,a)),to:Math.min(n.to,Math.max(l,a))}}class Ar{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(Mr)!=t.state.facet(Mr)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){!1!==this.layer.updateOnDocViewUpdate&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(Mr);for(;e{return i=t,n=this.drawn[e],!(i.constructor==n.constructor&&i.eq(n));var i,n})){let e=this.dom.firstChild,i=0;for(let n of t)n.update&&e&&n.constructor&&this.drawn[i].constructor&&n.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(n.draw(),e);for(;e;){let t=e.nextSibling;e.remove(),e=t}this.drawn=t}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Mr=H.define();function Tr(t){return[ln.define(e=>new Ar(e,t)),Mr.of(t)]}const Dr=H.define({combine:t=>Ot(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function Or(t){return t.startState.facet(Dr)!=t.state.facet(Dr)}const Rr=Tr({above:!0,markers(t){let{state:e}=t,i=e.facet(Dr),n=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty||i.drawRangeCursor){let e=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=s.empty?s:z.cursor(s.head,s.head>s.anchor?-1:1);for(let s of kr.forRange(t,e,i))n.push(s)}}return n},update(t,e){t.transactions.some(t=>t.selection)&&(e.style.animationName="cm-blink"==e.style.animationName?"cm-blink2":"cm-blink");let i=Or(t);return i&&Er(t.state,e),t.docChanged||t.selectionSet||i},mount(t,e){Er(e.state,t)},class:"cm-cursorLayer"});function Er(t,e){e.style.animationDuration=t.facet(Dr).cursorBlinkRate+"ms"}const Pr=Tr({above:!1,markers:t=>t.state.selection.ranges.map(e=>e.empty?[]:kr.forRange(t,"cm-selectionBackground",e)).reduce((t,e)=>t.concat(e)),update:(t,e)=>t.docChanged||t.selectionSet||t.viewportChanged||Or(t),class:"cm-selectionLayer"}),Lr=Q.highest(lr.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),Br=gt.define({map:(t,e)=>null==t?null:e.mapPos(t)}),Ir=U.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce((t,e)=>e.is(Br)?e.value:t,t))}),Nr=ln.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(Ir);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(Ir)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(Ir),i=null!=e&&t.coordsAtPos(e);if(!i)return null;let n=t.scrollDOM.getBoundingClientRect();return{left:i.left-n.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-n.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/i+"px",this.cursor.style.height=t.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(Ir)!=t&&this.view.dispatch({effects:Br.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function zr(t,e,i,n,s){e.lastIndex=0;for(let r,o=t.iterRange(i,n),l=i;!o.next().done;l+=o.value.length)if(!o.lineBreak)for(;r=e.exec(o.value);)s(l+r.index,r)}class qr{constructor(t){const{regexp:e,decoration:i,decorate:n,boundary:s,maxLength:r=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,n)this.addMatch=(t,e,i,s)=>n(s,i,i+t[0].length,t,e);else if("function"==typeof i)this.addMatch=(t,e,n,s)=>{let r=i(t,e,n);r&&s(n,n+t[0].length,r)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(t,e,n,s)=>s(n,n+t[0].length,i)}this.boundary=s,this.maxLength=r}createDeco(t){let e=new It,i=e.add.bind(e);for(let{from:e,to:n}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 n=[];for(let{from:s,to:r}of i)s=Math.max(t.state.doc.lineAt(s).from,s-e),r=Math.min(t.state.doc.lineAt(r).to,r+e),n.length&&n[n.length-1].to>=s?n[n.length-1].to=r:n.push({from:s,to:r});return n}(t,this.maxLength))zr(t.state.doc,this.regexp,e,n,(e,n)=>this.addMatch(n,t,e,i));return e.finish()}updateDeco(t,e){let i=1e9,n=-1;return t.docChanged&&t.changes.iterChanges((e,s,r,o)=>{o>=t.view.viewport.from&&r<=t.view.viewport.to&&(i=Math.min(r,i),n=Math.max(o,n))}),t.viewportMoved||n-i>1e3?this.createDeco(t.view):n>-1?this.updateRange(t.view,e.map(t.changes),i,n):e}updateRange(t,e,i,n){for(let s of t.visibleRanges){let r=Math.max(s.from,i),o=Math.min(s.to,n);if(o>=r){let i=t.state.doc.lineAt(r),n=i.toi.from;r--)if(this.boundary.test(i.text[r-1-i.from])){l=r;break}for(;oc.push(i.range(t,e));if(i==n)for(this.regexp.lastIndex=l-i.from;(h=this.regexp.exec(i.text))&&h.indexthis.addMatch(i,t,e,u));e=e.update({filterFrom:l,filterTo:a,filter:(t,e)=>ta,add:c})}}return e}}const Fr=null!=/x/.unicode?"gu":"g",Hr=new RegExp("[\0-\b\n--Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\ufeff-]",Fr),Vr={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Wr=null;const $r=H.define({combine(t){let e=Ot(t,{render:null,specialChars:Hr,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==Wr&&"undefined"!=typeof document&&document.body){let e=document.body.style;Wr=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return Wr||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,Fr)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Fr)),e}});let _r=null;class jr extends ai{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")+" "+(Vr[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,e);if(n)return n;let s=document.createElement("span");return s.textContent=e,s.title=i,s.setAttribute("aria-label",i),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class Kr extends ai{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}const Ur=ci.line({class:"cm-activeLine"}),Gr=ln.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 n of t.state.selection.ranges){let s=t.lineBlockAt(n.head);s.from>e&&(i.push(Ur.range(s.from)),e=s.from)}return ci.set(i)}},{decorations:t=>t.decorations}),Yr=2e3;function Xr(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),n=t.state.doc.lineAt(i),s=i-n.from,r=s>Yr?-1:s==n.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):Kt(n.text,t.state.tabSize,i-n.from);return{line:n.number,col:r,off:s}}function Jr(t,e){let i=Xr(t,e),n=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),s=t.state.doc.lineAt(e);i={line:s.number,col:i.col,off:Math.min(i.off,s.length)},n=n.map(t.changes)}},get(e,s,r){let o=Xr(t,e);if(!o)return n;let l=function(t,e,i){let n=Math.min(e.line,i.line),s=Math.max(e.line,i.line),r=[];if(e.off>Yr||i.off>Yr||e.col<0||i.col<0){let o=Math.min(e.off,i.off),l=Math.max(e.off,i.off);for(let e=n;e<=s;e++){let i=t.doc.line(e);i.length<=l&&r.push(z.range(i.from+o,i.to+l))}}else{let o=Math.min(e.col,i.col),l=Math.max(e.col,i.col);for(let e=n;e<=s;e++){let i=t.doc.line(e),n=Ut(i.text,o,t.tabSize,!0);if(n<0)r.push(z.cursor(i.to));else{let e=Ut(i.text,l,t.tabSize);r.push(z.range(i.from+n,i.from+e))}}}return r}(t.state,i,o);return l.length?r?z.create(l.concat(n.ranges)):z.create(l):n}}:null}const Zr={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},Qr={style:"cursor: crosshair"};const to="-10000px";class eo{constructor(t,e,i,n){this.facet=e,this.createTooltipView=i,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(t=>t);let s=null;this.tooltipViews=this.tooltips.map(t=>s=i(t,s))}update(t,e){var i;let n=t.state.facet(this.facet),s=n.filter(t=>t);if(n===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let r=[],o=e?[]:null;for(let i=0;ie[i]=t),e.length=o.length),this.input=n,this.tooltips=s,this.tooltipViews=r,!0}}function io(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const no=H.define({combine:t=>{var e,i,n;return{position:Ge.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===(n=t.find(t=>t.tooltipSpace))||void 0===n?void 0:n.tooltipSpace)||io}}}),so=new WeakMap,ro=ln.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(no);this.position=e.position,this.parent=e.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new eo(t,ho,(t,e)=>this.createTooltip(t,e),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),t.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let i=e||t.geometryChanged,n=t.state.facet(no);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view),n=e?e.dom:null;if(i.dom.classList.add("cm-tooltip"),t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",i.dom.appendChild(t)}return i.dom.style.position=this.position,i.dom.style.top=to,i.dom.style.left="0px",this.container.insertBefore(i.dom,n),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),null===(t=e.destroy)||void 0===t||t.call(e);this.parent&&this.container.remove(),null===(e=this.resizeObserver)||void 0===e||e.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,i=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(Ge.gecko)i=t.offsetParent!=this.container.ownerDocument.body;else if(t.style.top==to&&"0px"==t.style.left){let e=t.getBoundingClientRect();i=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}}if(i||"absolute"==this.position)if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(t=i.width/this.parent.offsetWidth,e=i.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);let n=this.view.scrollDOM.getBoundingClientRect(),s=vn(this.view);return{visible:{left:n.left+s.left,top:n.top+s.top,right:n.right-s.right,bottom:n.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)}),size:this.manager.tooltipViews.map(({dom:t})=>t.getBoundingClientRect()),space:this.view.state.facet(no).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{visible:i,space:n,scaleX:s,scaleY:r}=t,o=[];for(let l=0;l=Math.min(i.bottom,n.bottom)||u.rightMath.min(i.right,n.right)+.1)){c.style.top=to;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=f.right-f.left,g=null!==(e=so.get(h))&&void 0!==e?e:f.bottom-f.top,v=h.offset||ao,w=this.view.textDirection==ki.LTR,b=f.width>n.right-n.left?w?n.left:n.right-f.width:w?Math.max(n.left,Math.min(u.left-(d?14:0)+v.x,n.right-m)):Math.min(Math.max(n.left,u.left-m+(d?14:0)-v.x),n.right-m),y=this.above[l];!a.strictSide&&(y?u.top-g-p-v.yn.bottom)&&y==n.bottom-u.bottom>u.top-n.top&&(y=this.above[l]=!y);let x=(y?u.top-n.top:n.bottom-u.bottom)-p;if(xb&&t.topk&&(k=y?t.top-g-2-p:t.bottom+p+2);if("absolute"==this.position?(c.style.top=(k-t.parent.top)/r+"px",oo(c,(b-t.parent.left)/s)):(c.style.top=k/r+"px",oo(c,b/s)),d){let t=u.left+(w?v.x:-v.x)-(b+14-7);d.style.left=t/s+"px"}!0!==h.overlap&&o.push({left:b,top:k,right:S,bottom:k+g}),c.classList.toggle("cm-tooltip-above",y),c.classList.toggle("cm-tooltip-below",!y),h.positioned&&h.positioned(t.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let t of this.manager.tooltipViews)t.dom.style.top=to}},{eventObservers:{scroll(){this.maybeMeasure()}}});function oo(t,e){let i=parseInt(t.style.left,10);(isNaN(i)||Math.abs(e-i)>1)&&(t.style.left=e+"px")}const lo=lr.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),ao={x:0,y:0},ho=H.define({enables:[ro,lo]}),co=H.define({combine:t=>t.reduce((t,e)=>t.concat(e),[])});class uo{static create(t){return new uo(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new eo(t,co,(t,e)=>this.createHostedView(t,e),t=>t.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)null===(t=e.destroy)||void 0===t||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let n=i[t];if(void 0!==n)if(void 0===e)e=n;else if(e!==n)return}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const fo=ho.compute([co],t=>{let e=t.facet(co);return 0===e.length?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var e;return null!==(e=t.end)&&void 0!==e?e:t.pos})),create:uo.create,above:e[0].above,arrow:e.some(t=>t.arrow)}});class po{constructor(t,e,i,n,s){this.view=t,this.source=e,this.field=i,this.setHover=n,this.hoverTime=s,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;ti.bottom||e.xi.right+t.defaultCharacterWidth)return;let r=t.bidiSpans(t.state.doc.lineAt(n)).find(t=>t.from<=n&&t.to>=n),o=r&&r.dir==ki.RTL?-1:1;s=e.x{this.pending==e&&(this.pending=null,!i||Array.isArray(i)&&!i.length||t.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])}))},e=>nn(t.state,e,"hover tooltip"))}else!r||Array.isArray(r)&&!r.length||t.dispatch({effects:this.setHover.of(Array.isArray(r)?r:[r])})}get tooltip(){let t=this.view.plugin(ro),e=t?t.manager.tooltips.findIndex(t=>t.create==uo.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:s}=this;if(n.length&&s&&!function(t,e){let i,{left:n,right:s,top:r,bottom:o}=t.getBoundingClientRect();if(i=t.querySelector(".cm-tooltip-arrow")){let t=i.getBoundingClientRect();r=Math.min(t.top,r),o=Math.max(t.bottom,o)}return e.clientX>=n-mo&&e.clientX<=s+mo&&e.clientY>=r-mo&&e.clientY<=o+mo}(s.dom,t)||this.pending){let{pos:s}=n[0]||this.pending,r=null!==(i=null===(e=n[0])||void 0===e?void 0:e.end)&&void 0!==i?i:s;(s==r?this.view.posAtCoords(this.lastMove)==s:function(t,e,i,n,s){let r=t.scrollDOM.getBoundingClientRect(),o=t.documentTop+t.documentPadding.top+t.contentHeight;if(r.left>n||r.rights||Math.min(r.bottom,o)=e&&l<=i}(this.view,s,r,t.clientX,t.clientY))||(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:e}=this;e&&e.dom.contains(t.relatedTarget)?this.watchTooltipLeave(e.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const mo=4;function go(t,e={}){let i=gt.define(),n=U.define({create:()=>[],update(t,n){if(t.length&&(e.hideOnChange&&(n.docChanged||n.selection)?t=[]:e.hideOn&&(t=t.filter(t=>!e.hideOn(n,t))),n.docChanged)){let e=[];for(let i of t){let t=n.changes.mapPos(i.pos,-1,T.TrackDel);if(null!=t){let s=Object.assign(Object.create(null),i);s.pos=t,null!=s.end&&(s.end=n.changes.mapPos(s.end)),e.push(s)}}t=e}for(let e of n.effects)e.is(i)&&(t=e.value),e.is(wo)&&(t=[]);return t},provide:t=>co.from(t)});return{active:n,extension:[n,ln.define(s=>new po(s,t,n,i,e.hoverTime||300)),fo]}}function vo(t,e){let i=t.plugin(ro);if(!i)return null;let n=i.manager.tooltips.indexOf(e);return n<0?null:i.manager.tooltipViews[n]}const wo=gt.define(),bo=H.define({combine(t){let e,i;for(let n of t)e=e||n.topContainer,i=i||n.bottomContainer;return{topContainer:e,bottomContainer:i}}});function yo(t,e){let i=t.plugin(xo),n=i?i.specs.indexOf(e):-1;return n>-1?i.panels[n]:null}const xo=ln.fromClass(class{constructor(t){this.input=t.state.facet(Co),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(e=>e(t));let e=t.state.facet(bo);this.top=new ko(t,!0,e.topContainer),this.bottom=new ko(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(bo);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new ko(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new ko(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(Co);if(i!=this.input){let e=i.filter(t=>t),n=[],s=[],r=[],o=[];for(let i of e){let e,l=this.specs.indexOf(i);l<0?(e=i(t.view),o.push(e)):(e=this.panels[l],e.update&&e.update(t)),n.push(e),(e.top?s:r).push(e)}this.specs=e,this.panels=n,this.top.sync(s),this.bottom.sync(r);for(let t of o)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=>lr.scrollMargins.of(e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}})});class ko{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=So(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=So(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 So(t){let e=t.nextSibling;return t.remove(),e}const Co=H.define({enables:xo});function Ao(t,e){let i,n=new Promise(t=>i=t),s=t=>function(t,e,i){let n=e.content?e.content(t,()=>o(null)):null;if(!n){if(n=oe("form"),e.input){let t=oe("input",e.input);/^(text|password|number|email|tel|url)$/.test(t.type)&&t.classList.add("cm-textfield"),t.name||(t.name="input"),n.appendChild(oe("label",(e.label||"")+": ",t))}else n.appendChild(document.createTextNode(e.label||""));n.appendChild(document.createTextNode(" ")),n.appendChild(oe("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let s="FORM"==n.nodeName?[n]:n.querySelectorAll("form");for(let t=0;t{27==t.keyCode?(t.preventDefault(),o(null)):13==t.keyCode&&(t.preventDefault(),o(e))}),e.addEventListener("submit",t=>{t.preventDefault(),o(e)})}let r=oe("div",n,oe("button",{onclick:()=>o(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(r.className=e.class);function o(e){r.contains(r.ownerDocument.activeElement)&&t.focus(),i(e)}return r.classList.add("cm-dialog"),{dom:r,top:e.top,mount:()=>{if(e.focus){let t;t="string"==typeof e.focus?n.querySelector(e.focus):n.querySelector("input")||n.querySelector("button"),t&&"select"in t?t.select():t&&"focus"in t&&t.focus()}}}}(t,e,i);t.state.field(Mo,!1)?t.dispatch({effects:To.of(s)}):t.dispatch({effects:gt.appendConfig.of(Mo.init(()=>[s]))});let r=Do.of(s);return{close:r,result:n.then(e=>((t.win.queueMicrotask||(e=>t.win.setTimeout(e,10)))(()=>{t.state.field(Mo).indexOf(s)>-1&&t.dispatch({effects:r})}),e))}}const Mo=U.define({create:()=>[],update(t,e){for(let i of e.effects)i.is(To)?t=[i.value].concat(t):i.is(Do)&&(t=t.filter(t=>t!=i.value));return t},provide:t=>Co.computeN([t],e=>e.field(t))}),To=gt.define(),Do=gt.define();class Oo extends Rt{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Oo.prototype.elementClass="",Oo.prototype.toDOM=void 0,Oo.prototype.mapMode=T.TrackBefore,Oo.prototype.startSide=Oo.prototype.endSide=-1,Oo.prototype.point=!0;const Ro=H.define(),Eo=H.define(),Po={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>Bt.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Lo=H.define();function Bo(t){return[No(),Lo.of({...Po,...t})]}const Io=H.define({combine:t=>t.some(t=>t)});function No(t){return[zo]}const zo=ln.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Lo).map(e=>new Vo(t,e)),this.fixed=!t.state.facet(Io);for(let t of this.gutters)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,n=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(n<.8*(i.to-i.from))}if(t.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Io)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let i=Bt.iter(this.view.state.facet(Ro),this.view.viewport.from),n=[],s=this.gutters.map(t=>new Ho(t,this.view.viewport,-this.view.documentPadding.top));for(let t of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(t.type)){let e=!0;for(let r of t.type)if(r.type==hi.Text&&e){Fo(i,n,r.from);for(let t of s)t.line(this.view,r,n);e=!1}else if(r.widget)for(let t of s)t.widget(this.view,r)}else if(t.type==hi.Text){Fo(i,n,t.from);for(let e of s)e.line(this.view,t,n)}else if(t.widget)for(let e of s)e.widget(this.view,t);for(let t of s)t.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(Lo),i=t.state.facet(Lo),n=t.docChanged||t.heightChanged||t.viewportChanged||!Bt.eq(t.startState.facet(Ro),t.state.facet(Ro),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(n=!0);else{n=!0;let s=[];for(let n of i){let i=e.indexOf(n);i<0?s.push(new Vo(this.view,n)):(this.gutters[i].update(t),s.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),s.indexOf(t)<0&&t.destroy();for(let t of s)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.gutters=s}return n}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>lr.scrollMargins.of(e=>{let i=e.plugin(t);if(!i||0==i.gutters.length||!i.fixed)return null;let n=i.dom.offsetWidth*e.scaleX,s=i.domAfter?i.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==ki.LTR?{left:n,right:s}:{right:n,left:s}})});function qo(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 Ho{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=Bt.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:n}=this,s=(e.top-this.height)/t.scaleY,r=e.height/t.scaleY;if(this.i==n.elements.length){let e=new Wo(t,r,s,i);n.elements.push(e),n.dom.appendChild(e.dom)}else n.elements[this.i].update(t,r,s,i);this.height=e.bottom,this.i++}line(t,e,i){let n=[];Fo(this.cursor,n,e.from),i.length&&(n=n.concat(i));let s=this.gutter.config.lineMarker(t,e,n);s&&n.unshift(s);let r=this.gutter;(0!=n.length||r.config.renderEmptyElements)&&this.addElement(t,e,n)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),n=i?[i]:null;for(let i of t.state.facet(Eo)){let s=i(t,e.widget,e);s&&(n||(n=[])).push(s)}n&&this.addElement(t,e,n)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Vo{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,n=>{let s,r=n.target;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let t=r.getBoundingClientRect();s=(t.top+t.bottom)/2}else s=n.clientY;let o=t.lineBlockAtHeight(s-t.documentTop);e.domEventHandlers[i](t,o,n)&&n.preventDefault()});this.markers=qo(e.markers(t)),e.initialSpacer&&(this.spacer=new Wo(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=qo(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!Bt.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 Wo{constructor(t,e,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,n)}update(t,e,i,n){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;iOt(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let n=i[t],s=e[t];i[t]=n?(t,e,i)=>n(t,e,i)||s(t,e,i):s}return i}})});class Ko extends Oo{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Uo(t,e){return t.state.facet(jo).formatNumber(e,t.state)}const Go=Lo.compute([jo],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet($o),lineMarker:(t,e,i)=>i.some(t=>t.toDOM)?null:new Ko(Uo(t,t.state.doc.lineAt(e.from).number)),widgetMarker:(t,e,i)=>{for(let n of t.state.facet(_o)){let s=n(t,e,i);if(s)return s}return null},lineMarkerChange:t=>t.startState.facet(jo)!=t.state.facet(jo),initialSpacer:t=>new Ko(Uo(t,Yo(t.state.doc.lines))),updateSpacer(t,e){let i=Uo(e.view,Yo(e.view.state.doc.lines));return i==t.number?t:new Ko(i)},domEventHandlers:t.facet(jo).domEventHandlers,side:"before"}));function Yo(t){let e=9;for(;e{let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.head).from;s>i&&(i=s,e.push(Xo.range(s)))}return Bt.of(e)});const Zo="function"==typeof String.prototype.normalize?t=>t.normalize("NFKD"):t=>t;class Qo{constructor(t,e,i=0,n=t.length,s,r){this.test=r,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,n),this.bufferStart=i,this.normalize=s?t=>s(Zo(t)):Zo,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 S(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=C(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=A(t);let n=this.normalize(e);if(n.length)for(let t=0,s=i;;t++){let r=n.charCodeAt(t),o=this.match(r,s,this.bufferPos+this.bufferStart);if(t==n.length-1){if(o)return this.value=o,this;break}s==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,n=i+e[0].length;if(this.matchPos=ol(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(ithis.value.to)&&(!this.test||this.test(i,n,e)))return this.value={from:i,to:n,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length=i||n.to<=e){let n=new sl(e,t.sliceString(e,i));return nl.set(t,n),n}if(n.from==e&&n.to==i)return n;let{text:s,from:r}=n;return r>e&&(s=t.sliceString(e,r)+s,r=e),n.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){let t=this.flat.from+e.index,i=t+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(t,i,e)))return this.value={from:t,to:i,match:e},this.matchPos=ol(this.text,i+(t==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=sl.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function ol(t,e){if(e>=t.length)return e;let i,n=t.lineAt(e);for(;e=56320&&i<57344;)e++;return e}function ll(t){let e=oe("input",{class:"cm-textfield",name:"line",value:String(t.state.doc.lineAt(t.state.selection.main.head).number)});function i(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!i)return;let{state:n}=t,s=n.doc.lineAt(n.selection.main.head),[,r,o,l,a]=i,h=l?+l.slice(1):0,c=o?+o:s.number;if(o&&a){let t=c/100;r&&(t=t*("-"==r?-1:1)+s.number/n.doc.lines),c=Math.round(n.doc.lines*t)}else o&&r&&(c=c*("-"==r?-1:1)+s.number);let u=n.doc.line(Math.max(1,Math.min(n.doc.lines,c))),f=z.cursor(u.from+Math.max(0,Math.min(h,u.length)));t.dispatch({effects:[al.of(!1),lr.scrollIntoView(f.from,{y:"center"})],selection:f}),t.focus()}return{dom:oe("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:al.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),i())},onsubmit:t=>{t.preventDefault(),i()}},oe("label",t.state.phrase("Go to line"),": ",e)," ",oe("button",{class:"cm-button",type:"submit"},t.state.phrase("go")),oe("button",{name:"close",onclick:()=>{t.dispatch({effects:al.of(!1)}),t.focus()},"aria-label":t.state.phrase("close"),type:"button"},["×"]))}}"undefined"!=typeof Symbol&&(il.prototype[Symbol.iterator]=rl.prototype[Symbol.iterator]=function(){return this});const al=gt.define(),hl=U.define({create:()=>!0,update(t,e){for(let i of e.effects)i.is(al)&&(t=i.value);return t},provide:t=>Co.from(t,t=>t?ll:null)}),cl=lr.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}}}),ul={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},fl=H.define({combine:t=>Ot(t,ul,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});const dl=ci.mark({class:"cm-selectionMatch"}),pl=ci.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ml(t,e,i,n){return!(0!=i&&t(e.sliceDoc(i-1,i))==Ct.Word||n!=e.doc.length&&t(e.sliceDoc(n,n+1))==Ct.Word)}const gl=ln.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(fl),{state:i}=t,n=i.selection;if(n.ranges.length>1)return ci.none;let s,r=n.main,o=null;if(r.empty){if(!e.highlightWordAroundCursor)return ci.none;let t=i.wordAt(r.head);if(!t)return ci.none;o=i.charCategorizer(r.head),s=i.sliceDoc(t.from,t.to)}else{let t=r.to-r.from;if(t200)return ci.none;if(e.wholeWords){if(s=i.sliceDoc(r.from,r.to),o=i.charCategorizer(r.head),!ml(o,i,r.from,r.to)||!function(t,e,i,n){return t(e.sliceDoc(i,i+1))==Ct.Word&&t(e.sliceDoc(n-1,n))==Ct.Word}(o,i,r.from,r.to))return ci.none}else if(s=i.sliceDoc(r.from,r.to),!s)return ci.none}let l=[];for(let n of t.visibleRanges){let t=new Qo(i.doc,s,n.from,n.to);for(;!t.next().done;){let{from:n,to:s}=t.value;if((!o||ml(o,i,n,s))&&(r.empty&&n<=r.from&&s>=r.to?l.push(pl.range(n,s)):(n>=r.to||s<=r.from)&&l.push(dl.range(n,s)),l.length>e.maxMatches))return ci.none}}return ci.set(l)}},{decorations:t=>t.decorations}),vl=lr.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const wl=H.define({combine:t=>Ot(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Ul(t),scrollToMatch:t=>lr.scrollIntoView(t)})});class bl{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,el),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord}unquote(t){return this.literal?t:t.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&&this.wholeWord==t.wholeWord}create(){return this.regexp?new Ml(this):new kl(this)}getCursor(t,e=0,i){let n=t.doc?t:Dt.create({doc:t});return null==i&&(i=n.doc.length),this.regexp?Sl(this,n,e,i):xl(this,n,e,i)}}class yl{constructor(t){this.spec=t}}function xl(t,e,i,n){return new Qo(e.doc,t.unquoted,i,n,t.caseSensitive?void 0:t=>t.toLowerCase(),t.wholeWord?function(t,e){return(i,n,s,r)=>((r>i||r+s.length=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=xl(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}function Sl(t,e,i,n){return new il(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?(s=e.charCategorizer(e.selection.main.head),(t,e,i)=>!i[0].length||(s(Cl(i.input,i.index))!=Ct.Word||s(Al(i.input,i.index))!=Ct.Word)&&(s(Al(i.input,i.index+i[0].length))!=Ct.Word||s(Cl(i.input,i.index+i[0].length))!=Ct.Word)):void 0},i,n);var s}function Cl(t,e){return t.slice(k(t,e,!1),e)}function Al(t,e){return t.slice(e,k(t,e))}class Ml extends yl{nextMatch(t,e,i){let n=Sl(this.spec,t,i,t.doc.length).next();return n.done&&(n=Sl(this.spec,t,0,e).next()),n.done?null:n.value}prevMatchInRange(t,e,i){for(let n=1;;n++){let s=Math.max(e,i-1e4*n),r=Sl(this.spec,t,s,i),o=null;for(;!r.next().done;)o=r.value;if(o&&(s==e||o.from>s+10))return o;if(s==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(e,i)=>{if("&"==i)return t.match[0];if("$"==i)return"$";for(let e=i.length;e>0;e--){let n=+i.slice(0,e);if(n>0&&n=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=Sl(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}const Tl=gt.define(),Dl=gt.define(),Ol=U.define({create:t=>new Rl(Vl(t).create(),null),update(t,e){for(let i of e.effects)i.is(Tl)?t=new Rl(i.value.create(),t.panel):i.is(Dl)&&(t=new Rl(t.query,i.value?Hl:null));return t},provide:t=>Co.from(t,t=>t.panel)});class Rl{constructor(t,e){this.query=t,this.panel=e}}const El=ci.mark({class:"cm-searchMatch"}),Pl=ci.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Ll=ln.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Ol))}update(t){let e=t.state.field(Ol);(e!=t.startState.field(Ol)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return ci.none;let{view:i}=this,n=new It;for(let e=0,s=i.visibleRanges,r=s.length;es[e+1].from-500;)l=s[++e].to;t.highlight(i.state,o,l,(t,e)=>{let s=i.state.selection.ranges.some(i=>i.from==t&&i.to==e);n.add(t,e,s?Pl:El)})}return n.finish()}},{decorations:t=>t.decorations});function Bl(t){return e=>{let i=e.state.field(Ol,!1);return i&&i.query.spec.valid?t(e,i):_l(e)}}const Il=Bl((t,{query:e})=>{let{to:i}=t.state.selection.main,n=e.nextMatch(t.state,i,i);if(!n)return!1;let s=z.single(n.from,n.to),r=t.state.facet(wl);return t.dispatch({selection:s,effects:[Jl(t,n),r.scrollToMatch(s.main,t)],userEvent:"select.search"}),$l(t),!0}),Nl=Bl((t,{query:e})=>{let{state:i}=t,{from:n}=i.selection.main,s=e.prevMatch(i,n,n);if(!s)return!1;let r=z.single(s.from,s.to),o=t.state.facet(wl);return t.dispatch({selection:r,effects:[Jl(t,s),o.scrollToMatch(r.main,t)],userEvent:"select.search"}),$l(t),!0}),zl=Bl((t,{query:e})=>{let i=e.matchAll(t.state,1e3);return!(!i||!i.length)&&(t.dispatch({selection:z.create(i.map(t=>z.range(t.from,t.to))),userEvent:"select.search.matches"}),!0)}),ql=Bl((t,{query:e})=>{let{state:i}=t,{from:n,to:s}=i.selection.main;if(i.readOnly)return!1;let r=e.nextMatch(i,n,n);if(!r)return!1;let o,l,a=r,h=[],c=[];a.from==n&&a.to==s&&(l=i.toText(e.getReplacement(a)),h.push({from:a.from,to:a.to,insert:l}),a=e.nextMatch(i,a.from,a.to),c.push(lr.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+".")));let u=t.state.changes(h);return a&&(o=z.single(a.from,a.to).map(u),c.push(Jl(t,a)),c.push(i.facet(wl).scrollToMatch(o.main,t))),t.dispatch({changes:u,selection:o,effects:c,userEvent:"input.replace"}),!0}),Fl=Bl((t,{query:e})=>{if(t.state.readOnly)return!1;let i=e.matchAll(t.state,1e9).map(t=>{let{from:i,to:n}=t;return{from:i,to:n,insert:e.getReplacement(t)}});if(!i.length)return!1;let n=t.state.phrase("replaced $ matches",i.length)+".";return t.dispatch({changes:i,effects:lr.announce.of(n),userEvent:"input.replace.all"}),!0});function Hl(t){return t.state.facet(wl).createPanel(t)}function Vl(t,e){var i,n,s,r,o;let l=t.selection.main,a=l.empty||l.to>l.from+100?"":t.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=t.facet(wl);return new bl({search:(null!==(i=null==e?void 0:e.literal)&&void 0!==i?i:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:null!==(n=null==e?void 0:e.caseSensitive)&&void 0!==n?n:h.caseSensitive,literal:null!==(s=null==e?void 0:e.literal)&&void 0!==s?s:h.literal,regexp:null!==(r=null==e?void 0:e.regexp)&&void 0!==r?r:h.regexp,wholeWord:null!==(o=null==e?void 0:e.wholeWord)&&void 0!==o?o:h.wholeWord})}function Wl(t){let e=yo(t,Hl);return e&&e.dom.querySelector("[main-field]")}function $l(t){let e=Wl(t);e&&e==t.root.activeElement&&e.select()}const _l=t=>{let e=t.state.field(Ol,!1);if(e&&e.panel){let i=Wl(t);if(i&&i!=t.root.activeElement){let n=Vl(t.state,e.query.spec);n.valid&&t.dispatch({effects:Tl.of(n)}),i.focus(),i.select()}}else t.dispatch({effects:[Dl.of(!0),e?Tl.of(Vl(t.state,e.query.spec)):gt.appendConfig.of(Ql)]});return!0},jl=t=>{let e=t.state.field(Ol,!1);if(!e||!e.panel)return!1;let i=yo(t,Hl);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Dl.of(!1)}),!0},Kl=[{key:"Mod-f",run:_l,scope:"editor search-panel"},{key:"F3",run:Il,shift:Nl,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Il,shift:Nl,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:jl,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:n,to:s}=i.main,r=[],o=0;for(let e=new Qo(t.doc,t.sliceDoc(n,s));!e.next().done;){if(r.length>1e3)return!1;e.value.from==n&&(o=r.length),r.push(z.range(e.value.from,e.value.to))}return e(t.update({selection:z.create(r,o),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:t=>{let e=yo(t,ll);if(!e){let i=[al.of(!0)];null==t.state.field(hl,!1)&&i.push(gt.appendConfig.of([hl,cl])),t.dispatch({effects:i}),e=yo(t,ll)}return e&&e.dom.querySelector("input").select(),!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,n=z.create(i.ranges.map(e=>t.wordAt(e.head)||z.cursor(e.head)),i.mainIndex);return!n.eq(i)&&(e(t.update({selection:n})),!0)})({state:t,dispatch:e});let n=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some(e=>t.sliceDoc(e.from,e.to)!=n))return!1;let s=function(t,e){let{main:i,ranges:n}=t.selection,s=t.wordAt(i.head),r=s&&s.from==i.from&&s.to==i.to;for(let i=!1,s=new Qo(t.doc,e,n[n.length-1].to);;){if(s.next(),!s.done){if(i&&n.some(t=>t.from==s.value.from))continue;if(r){let e=t.wordAt(s.value.from);if(!e||e.from!=s.value.from||e.to!=s.value.to)continue}return s.value}if(i)return null;s=new Qo(t.doc,e,0,Math.max(0,n[n.length-1].from-1)),i=!0}}(t,n);return!!s&&(e(t.update({selection:t.selection.addRange(z.range(s.from,s.to),!1),effects:lr.scrollIntoView(s.to)})),!0)},preventDefault:!0}];class Ul{constructor(t){this.view=t;let e=this.query=t.state.field(Ol).query.spec;function i(t,e,i){return oe("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=oe("input",{value:e.search,placeholder:Gl(t,"Find"),"aria-label":Gl(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=oe("input",{value:e.replace,placeholder:Gl(t,"Replace"),"aria-label":Gl(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=oe("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=oe("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=oe("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit}),this.dom=oe("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",()=>Il(t),[Gl(t,"next")]),i("prev",()=>Nl(t),[Gl(t,"previous")]),i("select",()=>zl(t),[Gl(t,"all")]),oe("label",null,[this.caseField,Gl(t,"match case")]),oe("label",null,[this.reField,Gl(t,"regexp")]),oe("label",null,[this.wordField,Gl(t,"by word")]),...t.state.readOnly?[]:[oe("br"),this.replaceField,i("replace",()=>ql(t),[Gl(t,"replace")]),i("replaceAll",()=>Fl(t),[Gl(t,"replace all")])],oe("button",{name:"close",onclick:()=>jl(t),"aria-label":Gl(t,"close"),type:"button"},["×"])])}commit(){let t=new bl({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:Tl.of(t)}))}keydown(t){var e,i,n;e=this.view,i=t,n="search-panel",xr(vr(e.state),i,e,n)?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Nl:Il)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),ql(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(Tl)&&!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,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(wl).top}}function Gl(t,e){return t.state.phrase(e)}const Yl=30,Xl=/[\s\.,:;?!]/;function Jl(t,{from:e,to:i}){let n=t.state.doc.lineAt(e),s=t.state.doc.lineAt(i).to,r=Math.max(n.from,e-Yl),o=Math.min(s,i+Yl),l=t.state.sliceDoc(r,o);if(r!=n.from)for(let t=0;tl.length-Yl;t--)if(!Xl.test(l[t-1])&&Xl.test(l[t])){l=l.slice(0,t);break}return lr.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${n.number}.`)}const Zl=lr.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"}}),Ql=[Ol,Q.low(Ll),Zl];class ta{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class ea{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let n=i.facet(va).markerFilter;n&&(t=n(t,i));let s=t.slice().sort((t,e)=>t.from-e.from||t.to-e.to),r=new It,o=[],l=0;for(let t=0;;){let e,n,a=t==s.length?null:s[t];if(!a&&!o.length)break;for(o.length?(e=l,n=o.reduce((t,e)=>Math.min(t,e.to),a&&a.from>e?a.from:1e8)):(e=a.from,n=a.to,o.push(a),t++);ti.from||i.to==e)){n=Math.min(i.from,n);break}o.push(i),t++,n=Math.min(i.to,n)}let h=Ta(o);if(o.some(t=>t.from==t.to||t.from==t.to-1&&i.doc.lineAt(t.from).to==t.from))r.add(e,e,ci.widget({widget:new ya(h),diagnostics:o.slice()}));else{let t=o.reduce((t,e)=>e.markClass?t+" "+e.markClass:t,"");r.add(e,n,ci.mark({class:"cm-lintRange cm-lintRange-"+h+t,diagnostics:o.slice(),inclusiveEnd:o.some(t=>t.to>n)}))}l=n;for(let t=0;t{if(!(e&&s.diagnostics.indexOf(e)<0))if(n){if(s.diagnostics.indexOf(n.diagnostic)<0)return!1;n=new ta(n.from,i,n.diagnostic)}else n=new ta(t,i,e||s.diagnostics[0])}),n}function na(t,e){let i=e.pos,n=e.end||i,s=t.state.facet(va).hideOn(t,i,n);if(null!=s)return s;let r=t.startState.doc.lineAt(e.pos);return!(!t.effects.some(t=>t.is(oa))&&!t.changes.touchesRange(r.from,Math.max(r.to,n)))}function sa(t,e){return t.field(ha,!1)?e:e.concat(gt.appendConfig.of(Ia))}function ra(t,e){return{effects:sa(t,[oa.of(e)])}}const oa=gt.define(),la=gt.define(),aa=gt.define(),ha=U.define({create:()=>new ea(ci.none,null,null),update(t,e){if(e.docChanged&&t.diagnostics.size){let i=t.diagnostics.map(e.changes),n=null,s=t.panel;if(t.selected){let s=e.changes.mapPos(t.selected.from,1);n=ia(i,t.selected.diagnostic,s)||ia(i,null,s)}!i.size&&s&&e.state.facet(va).autoPanel&&(s=null),t=new ea(i,s,n)}for(let i of e.effects)if(i.is(oa)){let n=e.state.facet(va).autoPanel?i.value.length?ka.open:null:t.panel;t=ea.init(i.value,n,e.state)}else i.is(la)?t=new ea(t.diagnostics,i.value?ka.open:null,t.selected):i.is(aa)&&(t=new ea(t.diagnostics,t.panel,i.value));return t},provide:t=>[Co.from(t,t=>t.panel),lr.decorations.from(t,t=>t.diagnostics)]}),ca=ci.mark({class:"cm-lintRange cm-lintRange-active"});function ua(t,e,i){let n,{diagnostics:s}=t.state.field(ha),r=-1,o=-1;s.between(e-(i<0?1:0),e+(i>0?1:0),(t,s,{spec:l})=>{if(e>=t&&e<=s&&(t==s||(e>t||i>0)&&(e({dom:fa(t,n)})}:null}function fa(t,e){return oe("ul",{class:"cm-tooltip-lint"},e.map(e=>ba(t,e,!1)))}const da=t=>{let e=t.state.field(ha,!1);e&&e.panel||t.dispatch({effects:sa(t.state,[la.of(!0)])});let i=yo(t,ka.open);return i&&i.dom.querySelector(".cm-panel-lint ul").focus(),!0},pa=t=>{let e=t.state.field(ha,!1);return!(!e||!e.panel)&&(t.dispatch({effects:la.of(!1)}),!0)},ma=[{key:"Mod-Shift-m",run:da,preventDefault:!0},{key:"F8",run:t=>{let e=t.state.field(ha,!1);if(!e)return!1;let i=t.state.selection.main,n=e.diagnostics.iter(i.to+1);return!(!n.value&&(n=e.diagnostics.iter(0),!n.value||n.from==i.from&&n.to==i.to))&&(t.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),!0)}}],ga=ln.fromClass(class{constructor(t){this.view=t,this.timeout=-1,this.set=!0;let{delay:e}=t.state.facet(va);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let t=Date.now();if(t{n.push(i),clearTimeout(s),n.length==t.length?e(n):s=setTimeout(()=>e(n),200)},i)}(e.map(t=>Promise.resolve(t(this.view))),e=>{this.view.state.doc==t.doc&&this.view.dispatch(ra(this.view.state,e.reduce((t,e)=>t.concat(e))))},t=>{nn(this.view.state,t)})}}update(t){let e=t.state.facet(va);(t.docChanged||e!=t.startState.facet(va)||e.needsRefresh&&e.needsRefresh(t))&&(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)}});const va=H.define({combine:t=>Object.assign({sources:t.map(t=>t.source).filter(t=>null!=t)},Ot(t.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e}))});function wa(t){let e=[];if(t)t:for(let{name:i}of t){for(let t=0;tt.toLowerCase()==n.toLowerCase())){e.push(n);continue t}}e.push("")}return e}function ba(t,e,i){var n;let s=i?wa(e.actions):[];return oe("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},oe("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),null===(n=e.actions)||void 0===n?void 0:n.map((i,n)=>{let r=!1,o=n=>{if(n.preventDefault(),r)return;r=!0;let s=ia(t.state.field(ha).diagnostics,e);s&&i.apply(t,s.from,s.to)},{name:l}=i,a=s[n]?l.indexOf(s[n]):-1,h=a<0?l:[l.slice(0,a),oe("u",l.slice(a,a+1)),l.slice(a+1)];return oe("button",{type:"button",class:"cm-diagnosticAction",onclick:o,onmousedown:o,"aria-label":` Action: ${l}${a<0?"":` (access key "${s[n]})"`}.`},h)}),e.source&&oe("div",{class:"cm-diagnosticSource"},e.source))}class ya extends ai{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return oe("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class xa{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=ba(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class ka{constructor(t){this.view=t,this.items=[];this.list=oe("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(27==e.keyCode)pa(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],n=wa(i.actions);for(let s=0;s{for(let e=0;epa(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(ha).selected;if(!t)return-1;for(let e=0;e{for(let t of l.diagnostics){if(r.has(t))continue;r.add(t);let o,l=-1;for(let e=i;ei&&(this.items.splice(i,l-i),n=!0)),e&&o.diagnostic==e.diagnostic?o.dom.hasAttribute("aria-selected")||(o.dom.setAttribute("aria-selected","true"),s=o):o.dom.hasAttribute("aria-selected")&&o.dom.removeAttribute("aria-selected"),i++}});i({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:t,panel:e})=>{let i=e.height/this.list.offsetHeight;t.tope.bottom&&(this.list.scrollTop+=(t.bottom-e.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&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=ia(this.view.state.field(ha).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:aa.of(e)})}static open(t){return new ka(t)}}function Sa(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,${encodeURIComponent(t)}')`}function Ca(t){return Sa(``,'width="6" height="3"')}const Aa=lr.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-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Ca("#d11")},".cm-lintRange-warning":{backgroundImage:Ca("orange")},".cm-lintRange-info":{backgroundImage:Ca("#999")},".cm-lintRange-hint":{backgroundImage:Ca("#66d")},".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-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".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}}});function Ma(t){return"error"==t?4:"warning"==t?3:"info"==t?2:1}function Ta(t){let e="hint",i=1;for(let n of t){let t=Ma(n.severity);t>i&&(i=t,e=n.severity)}return e}class Da extends Oo{constructor(t){super(),this.diagnostics=t,this.severity=Ta(t)}toDOM(t){let e=document.createElement("div");e.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,n=t.state.facet(Na).tooltipFilter;return n&&(i=n(i,t.state)),i.length&&(e.onmouseover=()=>function(t,e,i){function n(){let n=t.elementAtHeight(e.getBoundingClientRect().top+5-t.documentTop);t.coordsAtPos(n.from)&&t.dispatch({effects:Pa.of({pos:n.from,above:!1,clip:!1,create:()=>({dom:fa(t,i),getCoords:()=>e.getBoundingClientRect()})})}),e.onmouseout=e.onmousemove=null,function(t,e){let i=n=>{let s=e.getBoundingClientRect();if(!(n.clientX>s.left-10&&n.clientXs.top-10&&n.clientY{clearTimeout(r),e.onmouseout=e.onmousemove=null},e.onmousemove=()=>{clearTimeout(r),r=setTimeout(n,s)}}(t,e,i)),e}}function Oa(t,e){let i=Object.create(null);for(let n of e){let e=t.lineAt(n.from);(i[e.from]||(i[e.from]=[])).push(n)}let n=[];for(let t in i)n.push(new Da(i[t]).range(+t));return Bt.of(n,!0)}const Ra=Bo({class:"cm-gutter-lint",markers:t=>t.state.field(Ea),widgetMarker:(t,e,i)=>{let n=[];return t.state.field(Ea).between(i.from,i.to,(t,e,s)=>{t>i.from&&tBt.empty,update(t,e){t=t.map(e.changes);let i=e.state.facet(Na).markerFilter;for(let n of e.effects)if(n.is(oa)){let s=n.value;i&&(s=i(s||[],e.state)),t=Oa(e.state.doc,s.slice(0))}return t}}),Pa=gt.define(),La=U.define({create:()=>null,update:(t,e)=>(t&&e.docChanged&&(t=na(e,t)?null:Object.assign(Object.assign({},t),{pos:e.changes.mapPos(t.pos)})),e.effects.reduce((t,e)=>e.is(Pa)?e.value:t,t)),provide:t=>ho.from(t)}),Ba=lr.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:Sa('')},".cm-lint-marker-warning":{content:Sa('')},".cm-lint-marker-error":{content:Sa('')}}),Ia=[ha,lr.decorations.compute([ha],t=>{let{selected:e,panel:i}=t.field(ha);return e&&i&&e.from!=e.to?ci.set([ca.range(e.from,e.to)]):ci.none}),go(ua,{hideOn:na}),Aa],Na=H.define({combine:t=>Ot(t,{hoverTime:300,markerFilter:null,tooltipFilter:null})});const za=1024;let qa=0;class Fa{constructor(t,e){this.from=t,this.to=e}}class Ha{constructor(t={}){this.id=qa++,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=$a.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}Ha.closedBy=new Ha({deserialize:t=>t.split(" ")}),Ha.openedBy=new Ha({deserialize:t=>t.split(" ")}),Ha.group=new Ha({deserialize:t=>t.split(" ")}),Ha.isolate=new Ha({deserialize:t=>{if(t&&"rtl"!=t&&"ltr"!=t&&"auto"!=t)throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}}),Ha.contextHash=new Ha({perNode:!0}),Ha.lookAhead=new Ha({perNode:!0}),Ha.mounted=new Ha({perNode:!0});class Va{constructor(t,e,i){this.tree=t,this.overlay=e,this.parser=i}static get(t){return t&&t.props&&t.props[Ha.mounted.id]}}const Wa=Object.create(null);class $a{constructor(t,e,i,n=0){this.name=t,this.props=e,this.id=i,this.flags=n}static define(t){let e=t.props&&t.props.length?Object.create(null):Wa,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),n=new $a(t.name||"",e,t.id,i);if(t.props)for(let i of t.props)if(Array.isArray(i)||(i=i(n)),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 n}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(Ha.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 n of i.split(" "))e[n]=t[i];return t=>{for(let i=t.prop(Ha.group),n=-1;n<(i?i.length:0);n++){let s=e[n<0?t.name:i[n]];if(s)return s}}}}$a.none=new $a("",Object.create(null),0,8);class _a{constructor(t){this.types=t;for(let e=0;e=e){let o=new th(r.tree,r.overlay[0].from+t.from,-1,t);(s||(s=[n])).push(Za(o,e,i,!1))}}return s?rh(s):n}(this,t,e)}iterate(t){let{enter:e,leave:i,from:n=0,to:s=this.length}=t,r=t.mode||0,o=(r&Ua.IncludeAnonymous)>0;for(let t=this.cursor(r|Ua.IncludeAnonymous);;){let r=!1;if(t.from<=s&&t.to>=n&&(!o&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;r=!0}for(;r&&i&&(o||!t.type.isAnonymous)&&i(t),!t.nextSibling();){if(!t.parent())return;r=!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:uh($a.none,this.children,this.positions,0,this.children.length,0,this.length,(t,e,i)=>new Ga(this.type,t,e,i,this.propValues),t.makeTree||((t,e,i)=>new Ga($a.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:n,maxBufferLength:s=za,reused:r=[],minRepeatType:o=n.types.length}=t,l=Array.isArray(i)?new Ya(i,i.length):i,a=n.types,h=0,c=0;function u(t,e,i,w,b,y){let{id:x,start:k,end:S,size:C}=l,A=c,M=h;for(;C<0;){if(l.next(),-1==C){let e=r[x];return i.push(e),void w.push(k-t)}if(-3==C)return void(h=x);if(-4==C)return void(c=x);throw new RangeError(`Unrecognized record size: ${C}`)}let T,D,O=a[x],R=k-t;if(S-k<=s&&(D=g(l.pos-e,b))){let e=new Uint16Array(D.size-D.skip),i=l.pos-D.size,s=e.length;for(;l.pos>i;)s=v(D.start,e,s);T=new Xa(e,S-D.start,n),R=D.start-t}else{let t=l.pos-C;l.next();let e=[],i=[],n=x>=o?x:-1,r=0,a=S;for(;l.pos>t;)n>=0&&l.id==n&&l.size>=0?(l.end<=a-s&&(p(e,i,k,r,l.end,a,n,A,M),r=e.length,a=l.end),l.next()):y>2500?f(k,t,e,i):u(k,t,e,i,n,y+1);if(n>=0&&r>0&&r-1&&r>0){let t=d(O,M);T=uh(O,e,i,0,e.length,0,S-k,t,t)}else T=m(O,e,i,S-k,A-S,M)}i.push(T),w.push(R)}function f(t,e,i,r){let o=[],a=0,h=-1;for(;l.pos>e;){let{id:t,start:e,end:i,size:n}=l;if(n>4)l.next();else{if(h>-1&&e=0;t-=3)e[i++]=o[t],e[i++]=o[t+1]-s,e[i++]=o[t+2]-s,e[i++]=i;i.push(new Xa(e,o[2]-s,n)),r.push(s-t)}}function d(t,e){return(i,n,s)=>{let r,o,l=0,a=i.length-1;if(a>=0&&(r=i[a])instanceof Ga){if(!a&&r.type==t&&r.length==s)return r;(o=r.prop(Ha.lookAhead))&&(l=n[a]+r.length+o)}return m(t,i,n,s,l,e)}}function p(t,e,i,s,r,o,l,a,h){let c=[],u=[];for(;t.length>s;)c.push(t.pop()),u.push(e.pop()+i-r);t.push(m(n.types[l],c,u,o-r,a-o,h)),e.push(r-i)}function m(t,e,i,n,s,r,o){if(r){let t=[Ha.contextHash,r];o=o?[t].concat(o):[t]}if(s>25){let t=[Ha.lookAhead,s];o=o?[t].concat(o):[t]}return new Ga(t,e,i,n,o)}function g(t,e){let i=l.fork(),n=0,r=0,a=0,h=i.end-s,c={size:0,start:0,skip:0};t:for(let s=i.pos-t;i.pos>s;){let t=i.size;if(i.id==e&&t>=0){c.size=n,c.start=r,c.skip=a,a+=4,n+=4,i.next();continue}let l=i.pos-t;if(t<0||l=o?4:0,f=i.start;for(i.next();i.pos>l;){if(i.size<0){if(-3!=i.size)break t;u+=4}else i.id>=o&&(u+=4);i.next()}r=f,n+=t,a+=u}return(e<0||n==t)&&(c.size=n,c.start=r,c.skip=a),c.size>4?c:void 0}function v(t,e,i){let{id:n,start:s,end:r,size:a}=l;if(l.next(),a>=0&&n4){let n=l.pos-(a-4);for(;l.pos>n;)i=v(t,e,i)}e[--i]=o,e[--i]=r-t,e[--i]=s-t,e[--i]=n}else-3==a?h=n:-4==a&&(c=n);return i}let w=[],b=[];for(;l.pos>0;)u(t.start||0,t.bufferStart||0,w,b,-1,0);let y=null!==(e=t.length)&&void 0!==e?e:w.length?b[0]+w[0].length:0;return new Ga(a[t.topID],w.reverse(),b.reverse(),y)}(t)}}Ga.empty=new Ga($a.none,[],[],0);class Ya{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 Ya(this.buffer,this.index)}}class Xa{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return $a.none}toString(){let t=[];for(let e=0;e0));l=r[l+3]);return o}slice(t,e,i){let n=this.buffer,s=new Uint16Array(e-t),r=0;for(let o=t,l=0;o=e&&ie;case 1:return i<=e&&n>e;case 2:return n>e;case 4:return!0}}function Za(t,e,i,n){for(var s;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to0?o.length:-1;t!=a;t+=e){let a=o[t],h=l[t]+r.from;if(Ja(n,i,h,h+a.length))if(a instanceof Xa){if(s&Ua.ExcludeBuffers)continue;let o=a.findChild(0,a.buffer.length,e,i-h,n);if(o>-1)return new sh(new nh(r,a,t,h),null,o)}else if(s&Ua.IncludeAnonymous||!a.type.isAnonymous||ah(a)){let o;if(!(s&Ua.IgnoreMounts)&&(o=Va.get(a))&&!o.overlay)return new th(o.tree,h,t,r);let l=new th(a,h,t,r);return s&Ua.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(e<0?a.children.length-1:0,e,i,n)}}if(s&Ua.IncludeAnonymous||!r.type.isAnonymous)return null;if(t=r.index>=0?r.index+e:e<0?-1:r._parent._tree.children.length,r=r._parent,!r)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 n;if(!(i&Ua.IgnoreOverlays)&&(n=Va.get(this._tree))&&n.overlay){let i=t-this.from;for(let{from:t,to:s}of n.overlay)if((e>0?t<=i:t=i:s>i))return new th(n.tree,n.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}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function eh(t,e,i,n){let s=t.cursor(),r=[];if(!s.firstChild())return r;if(null!=i)for(let t=!1;!t;)if(t=s.type.is(i),!s.nextSibling())return r;for(;;){if(null!=n&&s.type.is(n))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return null==n?r:[]}}function ih(t,e,i=e.length-1){for(let n=t;i>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[i]&&e[i]!=n.name)return!1;i--}}return!0}class nh{constructor(t,e,i,n){this.parent=t,this.buffer=e,this.index=i,this.start=n}}class sh extends Qa{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]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.context.start,i);return s<0?null:new sh(this.context,this,s)}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&Ua.ExcludeBuffers)return null;let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return s<0?null:new sh(this.context,this,s)}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 sh(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 sh(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,n=this.index+4,s=i.buffer[this.index+3];if(s>n){let r=i.buffer[this.index+1];t.push(i.slice(n,s,r)),e.push(0)}return new Ga(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function rh(t){if(!t.length)return null;let e=0,i=t[0];for(let n=1;ni.from||s.to0){if(this.index-1)for(let n=e+t,s=t<0?-1:i._tree.children.length;n!=s;n+=t){let t=i._tree.children[n];if(this.mode&Ua.IncludeAnonymous||t instanceof Xa||!t.type.isAnonymous||ah(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 r=t;r;r=r._parent)if(r.index==n){if(n==this.index)return r;e=r,i=s+1;break t}n=this.stack[--s]}for(let t=i;t=0;s--){if(s<0)return ih(this._tree,t,n);let r=i[e.buffer[this.stack[s]]];if(!r.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}}function ah(t){return t.children.some(t=>t instanceof Xa||!t.type.isAnonymous||ah(t))}const hh=new WeakMap;function ch(t,e){if(!t.isAnonymous||e instanceof Xa||e.type!=t)return 1;let i=hh.get(e);if(null==i){i=1;for(let n of e.children){if(n.type!=t||!(n instanceof Ga)){i=1;break}i+=ch(t,n)}hh.set(e,i)}return i}function uh(t,e,i,n,s,r,o,l,a){let h=0;for(let i=n;i=c)break;p+=e}if(h==s+1){if(p>c){let t=i[s];e(t.children,t.positions,0,t.children.length,n[s]+l);continue}u.push(i[s])}else{let e=n[h-1]+i[h-1].length-d;u.push(uh(t,i,n,s,h,d,e,null,a))}f.push(d+l-r)}}(e,i,n,s,0),(l||a)(u,f,o)}class fh{constructor(t,e,i,n,s=!1,r=!1){this.from=t,this.to=e,this.tree=i,this.offset=n,this.open=(s?1:0)|(r?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],i=!1){let n=[new fh(0,t.length,t,0,!1,i)];for(let i of e)i.to>t.length&&n.push(i);return n}static applyChanges(t,e,i=128){if(!e.length)return t;let n=[],s=1,r=t.length?t[0]:null;for(let o=0,l=0,a=0;;o++){let h=o=i)for(;r&&r.from=e.from||c<=e.to||a){let t=Math.max(e.from,l)-a,i=Math.min(e.to,c)-a;e=t>=i?null:new fh(t,i,e.tree,e.offset+a,o>0,!!h)}if(e&&n.push(e),r.to>c)break;r=snew Fa(t.from,t.to)):[new Fa(0,0)]:[new Fa(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let n=this.startParse(t,e,i);for(;;){let t=n.advance();if(t)return t}}}class ph{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 Ha({perNode:!0});let mh=0;class gh{constructor(t,e,i,n){this.name=t,this.set=e,this.base=i,this.modified=n,this.id=mh++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i="string"==typeof t?t:"?";if(t instanceof gh&&(e=t),null==e?void 0:e.base)throw new Error("Can not derive from a modified tag");let n=new gh(i,[],null,[]);if(n.set.push(n),e)for(let t of e.set)n.set.push(t);return n}static defineModifier(t){let e=new wh(t);return t=>t.modified.indexOf(e)>-1?t:wh.get(t.base||t,t.modified.concat(e).sort((t,e)=>t.id-e.id))}}let vh=0;class wh{constructor(t){this.name=t,this.instances=[],this.id=vh++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(i=>{return i.base==t&&(n=e,s=i.modified,n.length==s.length&&n.every((t,e)=>t==s[e]));var n,s});if(i)return i;let n=[],s=new gh(t.name,n,t,e);for(let t of e)t.instances.push(s);let r=function(t){let e=[[]];for(let i=0;ie.length-t.length)}(e);for(let e of t.set)if(!e.modified.length)for(let t of r)n.push(wh.get(e,t));return s}}function bh(t){let e=Object.create(null);for(let i in t){let n=t[i];Array.isArray(n)||(n=[n]);for(let t of i.split(" "))if(t){let i=[],s=2,r=t;for(let e=0;;){if("..."==r&&e>0&&e+3==t.length){s=1;break}let n=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(r);if(!n)throw new RangeError("Invalid path: "+t);if(i.push("*"==n[0]?"":'"'==n[0][0]?JSON.parse(n[0]):n[0]),e+=n[0].length,e==t.length)break;let o=t[e++];if(e==t.length&&"!"==o){s=0;break}if("/"!=o)throw new RangeError("Invalid path: "+t);r=t.slice(e)}let o=i.length-1,l=i[o];if(!l)throw new RangeError("Invalid path: "+t);let a=new xh(n,s,o>0?i.slice(0,o):null);e[l]=a.sort(e[l])}}return yh.add(e)}const yh=new Ha;class xh{constructor(t,e,i,n){this.tags=t,this.mode=e,this.context=i,this.next=n}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(t){return!t||t.depth{let e=s;for(let n of t)for(let t of n.set){let n=i[t.id];if(n){e=e?e+" "+n:n;break}}return e},scope:n}}function Sh(t,e,i,n=0,s=t.length){let r=new Ah(n,Array.isArray(e)?e:[e],i);r.highlightRange(t.cursor(),n,s,"",r.highlighters),r.flush(s)}function Ch(t,e,i,n,s,r=0,o=t.length){let l=r;function a(e,i){if(!(e<=l)){for(let r=t.slice(l,e),o=0;;){let t=r.indexOf("\n",o),e=t<0?r.length:t;if(e>o&&n(r.slice(o,e),i),t<0)break;s(),o=t+1}l=e}}Sh(e,i,(t,e,i)=>{a(t,""),a(e,i)},r,o),a(o,"")}xh.empty=new xh([],2,null);class Ah{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,n,s){let{type:r,from:o,to:l}=t;if(o>=i||l<=e)return;r.isTop&&(s=this.highlighters.filter(t=>!t.scope||t.scope(r)));let a=n,h=function(t){let e=t.type.prop(yh);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}(t)||xh.empty,c=function(t,e){let i=null;for(let n of t){let t=n.style(e);t&&(i=i?i+" "+t:t)}return i}(s,h.tags);if(c&&(a&&(a+=" "),a+=c,1==h.mode&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(e,o),a),h.opaque)return;let u=t.tree&&t.tree.prop(Ha.mounted);if(u&&u.overlay){let r=t.node.enter(u.overlay[0].from+o,1),h=this.highlighters.filter(t=>!t.scope||t.scope(u.tree.type)),c=t.firstChild();for(let f=0,d=o;;f++){let p=f=m)&&t.nextSibling()););if(!p||m>i)break;d=p.to+o,d>e&&(this.highlightRange(r.cursor(),Math.max(e,p.from+o),Math.min(i,d),"",h),this.startSpan(Math.min(i,d),a))}c&&t.parent()}else if(t.firstChild()){u&&(n="");do{if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,n,s),this.startSpan(Math.min(i,t.to),a)}}while(t.nextSibling());t.parent()}}}const Mh=gh.define,Th=Mh(),Dh=Mh(),Oh=Mh(Dh),Rh=Mh(Dh),Eh=Mh(),Ph=Mh(Eh),Lh=Mh(Eh),Bh=Mh(),Ih=Mh(Bh),Nh=Mh(),zh=Mh(),qh=Mh(),Fh=Mh(qh),Hh=Mh(),Vh={comment:Th,lineComment:Mh(Th),blockComment:Mh(Th),docComment:Mh(Th),name:Dh,variableName:Mh(Dh),typeName:Oh,tagName:Mh(Oh),propertyName:Rh,attributeName:Mh(Rh),className:Mh(Dh),labelName:Mh(Dh),namespace:Mh(Dh),macroName:Mh(Dh),literal:Eh,string:Ph,docString:Mh(Ph),character:Mh(Ph),attributeValue:Mh(Ph),number:Lh,integer:Mh(Lh),float:Mh(Lh),bool:Mh(Eh),regexp:Mh(Eh),escape:Mh(Eh),color:Mh(Eh),url:Mh(Eh),keyword:Nh,self:Mh(Nh),null:Mh(Nh),atom:Mh(Nh),unit:Mh(Nh),modifier:Mh(Nh),operatorKeyword:Mh(Nh),controlKeyword:Mh(Nh),definitionKeyword:Mh(Nh),moduleKeyword:Mh(Nh),operator:zh,derefOperator:Mh(zh),arithmeticOperator:Mh(zh),logicOperator:Mh(zh),bitwiseOperator:Mh(zh),compareOperator:Mh(zh),updateOperator:Mh(zh),definitionOperator:Mh(zh),typeOperator:Mh(zh),controlOperator:Mh(zh),punctuation:qh,separator:Mh(qh),bracket:Fh,angleBracket:Mh(Fh),squareBracket:Mh(Fh),paren:Mh(Fh),brace:Mh(Fh),content:Bh,heading:Ih,heading1:Mh(Ih),heading2:Mh(Ih),heading3:Mh(Ih),heading4:Mh(Ih),heading5:Mh(Ih),heading6:Mh(Ih),contentSeparator:Mh(Bh),list:Mh(Bh),quote:Mh(Bh),emphasis:Mh(Bh),strong:Mh(Bh),link:Mh(Bh),monospace:Mh(Bh),strikethrough:Mh(Bh),inserted:Mh(),deleted:Mh(),changed:Mh(),invalid:Mh(),meta:Hh,documentMeta:Mh(Hh),annotation:Mh(Hh),processingInstruction:Mh(Hh),definition:gh.defineModifier("definition"),constant:gh.defineModifier("constant"),function:gh.defineModifier("function"),standard:gh.defineModifier("standard"),local:gh.defineModifier("local"),special:gh.defineModifier("special")};for(let t in Vh){let e=Vh[t];e instanceof gh&&(e.name=t)}var Wh;kh([{tag:Vh.link,class:"tok-link"},{tag:Vh.heading,class:"tok-heading"},{tag:Vh.emphasis,class:"tok-emphasis"},{tag:Vh.strong,class:"tok-strong"},{tag:Vh.keyword,class:"tok-keyword"},{tag:Vh.atom,class:"tok-atom"},{tag:Vh.bool,class:"tok-bool"},{tag:Vh.url,class:"tok-url"},{tag:Vh.labelName,class:"tok-labelName"},{tag:Vh.inserted,class:"tok-inserted"},{tag:Vh.deleted,class:"tok-deleted"},{tag:Vh.literal,class:"tok-literal"},{tag:Vh.string,class:"tok-string"},{tag:Vh.number,class:"tok-number"},{tag:[Vh.regexp,Vh.escape,Vh.special(Vh.string)],class:"tok-string2"},{tag:Vh.variableName,class:"tok-variableName"},{tag:Vh.local(Vh.variableName),class:"tok-variableName tok-local"},{tag:Vh.definition(Vh.variableName),class:"tok-variableName tok-definition"},{tag:Vh.special(Vh.variableName),class:"tok-variableName2"},{tag:Vh.definition(Vh.propertyName),class:"tok-propertyName tok-definition"},{tag:Vh.typeName,class:"tok-typeName"},{tag:Vh.namespace,class:"tok-namespace"},{tag:Vh.className,class:"tok-className"},{tag:Vh.macroName,class:"tok-macroName"},{tag:Vh.propertyName,class:"tok-propertyName"},{tag:Vh.operator,class:"tok-operator"},{tag:Vh.comment,class:"tok-comment"},{tag:Vh.meta,class:"tok-meta"},{tag:Vh.invalid,class:"tok-invalid"},{tag:Vh.punctuation,class:"tok-punctuation"}]);const $h=new Ha;const _h=new Ha;class jh{constructor(t,e,i=[],n=""){this.data=t,this.name=n,Dt.prototype.hasOwnProperty("tree")||Object.defineProperty(Dt.prototype,"tree",{get(){return Uh(this)}}),this.parser=e,this.extension=[ic.of(this),Dt.languageData.of((t,e,i)=>{let n=Kh(t,e,i),s=n.type.prop($h);if(!s)return[];let r=t.facet(s),o=n.type.prop(_h);if(o){let s=n.resolve(e-n.from,i);for(let e of o)if(e.test(s,t)){let i=t.facet(e.facet);return"replace"==e.type?i:i.concat(r)}}return r})].concat(i)}isActiveAt(t,e,i=-1){return Kh(t,e,i).type.prop($h)==this.data}findRegions(t){let e=t.facet(ic);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],n=(t,e)=>{if(t.prop($h)==this.data)return void i.push({from:e,to:e+t.length});let s=t.prop(Ha.mounted);if(s){if(s.tree.prop($h)==this.data){if(s.overlay)for(let t of s.overlay)i.push({from:t.from+e,to:t.to+e});else i.push({from:e,to:e+t.length});return}if(s.overlay){let t=i.length;if(n(s.tree,s.overlay[0].from+e),i.length>t)return}}for(let i=0;i=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let Yh=null;class Xh{constructor(t,e,i=[],n,s,r,o,l){this.parser=t,this.state=e,this.fragments=i,this.tree=n,this.treeLen=s,this.viewport=r,this.skipped=o,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new Xh(t,e,[],Ga.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Gh(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=Ga.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(fh.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Yh;Yh=this;try{return t()}finally{Yh=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=Jh(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:n,treeLen:s,viewport:r,skipped:o}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges((t,i,n,s)=>e.push({fromA:t,toA:i,fromB:n,toB:s})),i=fh.applyChanges(i,e),n=Ga.empty,s=0,r={from:t.mapPos(r.from,-1),to:t.mapPos(r.to,1)},this.skipped.length){o=[];for(let e of this.skipped){let i=t.mapPos(e.from,1),n=t.mapPos(e.to,-1);it.from&&(this.fragments=Jh(this.fragments,i,n),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 dh{createParse(e,i,n){let s=n[0].from,r=n[n.length-1].to;return{parsedPos:s,advance(){let e=Yh;if(e){for(let t of n)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=r,new Ga($a.none,[],[],r-s)},stoppedAt:null,stopAt(){}}}}}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 Yh}}function Jh(t,e,i){return fh.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class Zh{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 Zh(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Xh.create(t.facet(ic).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Zh(i)}}jh.state=U.define({create:Zh.init,update(t,e){for(let t of e.effects)if(t.is(jh.setState))return t.value;return e.startState.facet(ic)!=e.state.facet(ic)?Zh.init(e.state):t.apply(e)}});let Qh=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(Qh=t=>{let e=-1,i=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const tc="undefined"!=typeof navigator&&(null===(Wh=navigator.scheduling)||void 0===Wh?void 0:Wh.isInputPending)?()=>navigator.scheduling.isInputPending():null,ec=ln.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(jh.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(jh.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=Qh(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEndn+1e3,l=s.context.work(()=>tc&&tc()||Date.now()>r,n+(o?0:1e5));this.chunkBudget-=Date.now()-e,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:jh.setState.of(new Zh(s.context))})),this.chunkBudget>0&&(!l||o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(t=>nn(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()}}}),ic=H.define({combine:t=>t.length?t[0]:null,enables:t=>[jh.state,ec,lr.contentAttributes.compute([t],e=>{let i=e.facet(t);return i&&i.name?{"data-language":i.name}:{}})]}),nc=H.define(),sc=H.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function rc(t){let e=t.facet(sc);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function oc(t,e){let i="",n=t.tabSize,s=t.facet(sc)[0];if("\t"==s){for(;e>=n;)i+="\t",e-=n;s=" "}for(let t=0;t=e?function(t,e,i){let n=e.resolveStack(i),s=e.resolveInner(i,-1).resolve(i,0).enterUnfinishedNodesBefore(i);if(s!=n.node){let t=[];for(let e=s;e&&!(e.fromn.node.to||e.from==n.node.from&&e.type==n.node.type);e=e.parent)t.push(e);for(let e=t.length-1;e>=0;e--)n={node:t[e],next:n}}return cc(n,t,i)}(t,i,e):null}class ac{constructor(t,e={}){this.state=t,this.options=e,this.unit=rc(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:n,simulateDoubleBreak:s}=this.options;return null!=n&&n>=i.from&&n<=i.to?s&&n==t?{text:"",from:t}:(e<0?n-1&&(s+=r-this.countColumn(i,i.search(/\S|$/))),s}countColumn(t,e=t.length){return Kt(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:n}=this.lineAt(t,e),s=this.options.overrideIndentation;if(s){let t=s(n);if(t>-1)return t}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const hc=new Ha;function cc(t,e,i){for(let n=t;n;n=n.next){let t=uc(n.node);if(t)return t(dc.create(e,i,n))}return 0}function uc(t){let e=t.type.prop(hc);if(e)return e;let i,n=t.firstChild;if(n&&(i=n.type.prop(Ha.closedBy))){let e=t.lastChild,n=e&&i.indexOf(e.name)>-1;return t=>function(t,e,i,n,s){let r=t.textAfter,o=r.match(/^\s*/)[0].length,l=n&&r.slice(o,o+n.length)==n||s==t.pos+o,a=function(t){let e=t.node,i=e.childAfter(e.from),n=e.lastChild;if(!i)return null;let s=t.options.simulateBreak,r=t.state.doc.lineAt(i.from),o=null==s||s<=r.from?r.to:Math.min(r.to,s);for(let t=i.to;;){let s=e.childAfter(t);if(!s||s==n)return null;if(!s.type.isSkipped){if(s.from>=o)return null;let t=/^ */.exec(r.text.slice(i.to-r.from))[0].length;return{from:i.from,to:i.to+t}}t=s.to}}(t);return a?l?t.column(a.from):t.column(a.to):t.baseIndent+(l?0:t.unit*i)}(t,0,1,void 0,n&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?fc:null}function fc(){return 0}class dc extends ac{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new dc(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(pc(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return cc(this.context.next,this.base,this.pos)}}function pc(t,e){for(let i=e;i;i=i.parent)if(t==i)return!0;return!1}const mc=H.define(),gc=new Ha;function vc(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function wc(t,e,i){for(let n of t.facet(mc)){let s=n(t,e,i);if(s)return s}return function(t,e,i){let n=Uh(t);if(n.lengthi)continue;if(s&&o.from=e&&n.to>i&&(s=n)}}return s}(t,e,i)}function bc(t,e){let i=e.mapPos(t.from,1),n=e.mapPos(t.to,-1);return i>=n?void 0:{from:i,to:n}}const yc=gt.define({map:bc}),xc=gt.define({map:bc});function kc(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 Sc=U.define({create:()=>ci.none,update(t,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((e,i)=>t=Cc(t,e,i)),t=t.map(e.changes);for(let i of e.effects)if(i.is(yc)&&!Mc(t,i.value.from,i.value.to)){let{preparePlaceholder:n}=e.state.facet(Ec),s=n?ci.replace({widget:new Ic(n(e.state,i.value))}):Bc;t=t.update({add:[s.range(i.value.from,i.value.to)]})}else i.is(xc)&&(t=t.update({filter:(t,e)=>i.value.from!=t||i.value.to!=e,filterFrom:i.value.from,filterTo:i.value.to}));return e.selection&&(t=Cc(t,e.selection.main.head)),t},provide:t=>lr.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{te&&(n=!0)}),n?t.update({filterFrom:e,filterTo:i,filter:(t,n)=>t>=i||n<=e}):t}function Ac(t,e,i){var n;let s=null;return null===(n=t.field(Sc,!1))||void 0===n||n.between(e,i,(t,e)=>{(!s||s.from>t)&&(s={from:t,to:e})}),s}function Mc(t,e,i){let n=!1;return t.between(e,e,(t,s)=>{t==e&&s==i&&(n=!0)}),n}function Tc(t,e){return t.field(Sc,!1)?e:e.concat(gt.appendConfig.of(Pc()))}function Dc(t,e,i=!0){let n=t.state.doc.lineAt(e.from).number,s=t.state.doc.lineAt(e.to).number;return lr.announce.of(`${t.state.phrase(i?"Folded lines":"Unfolded lines")} ${n} ${t.state.phrase("to")} ${s}.`)}const Oc=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of kc(t)){let i=wc(t.state,e.from,e.to);if(i)return t.dispatch({effects:Tc(t.state,[yc.of(i),Dc(t,i)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(Sc,!1))return!1;let e=[];for(let i of kc(t)){let n=Ac(t.state,i.from,i.to);n&&e.push(xc.of(n),Dc(t,n,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,i=[];for(let n=0;n{let e=t.state.field(Sc,!1);if(!e||!e.size)return!1;let i=[];return e.between(0,t.state.doc.length,(t,e)=>{i.push(xc.of({from:t,to:e}))}),t.dispatch({effects:i}),!0}}],Rc={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Ec=H.define({combine:t=>Ot(t,Rc)});function Pc(t){return[Sc,qc]}function Lc(t,e){let{state:i}=t,n=i.facet(Ec),s=e=>{let i=t.lineBlockAt(t.posAtDOM(e.target)),n=Ac(t.state,i.from,i.to);n&&t.dispatch({effects:xc.of(n)}),e.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(t,s,e);let r=document.createElement("span");return r.textContent=n.placeholderText,r.setAttribute("aria-label",i.phrase("folded code")),r.title=i.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const Bc=ci.replace({widget:new class extends ai{toDOM(t){return Lc(t,null)}}});class Ic extends ai{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return Lc(t,this.value)}}const Nc={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class zc extends Oo{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}}const qc=lr.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 Fc{constructor(t,e){let i;function n(t){let e=Jt.newName();return(i||(i=Object.create(null)))["."+e]=t,e}this.specs=t;const s="string"==typeof e.all?e.all:e.all?n(e.all):void 0,r=e.scope;this.scope=r instanceof jh?t=>t.prop($h)==r.data:r?t=>t==r:void 0,this.style=kh(t.map(t=>({tag:t.tag,class:t.class||n(Object.assign({},t,{tag:null}))})),{all:s}).style,this.module=i?new Jt(i):null,this.themeType=e.themeType}static define(t,e){return new Fc(t,e||{})}}const Hc=H.define(),Vc=H.define({combine:t=>t.length?[t[0]]:null});function Wc(t){let e=t.facet(Hc);return e.length?e:t.facet(Vc)}function $c(t,e,i){let n=Wc(t),s=null;if(n)for(let t of n)if(!t.scope||i){let i=t.style(e);i&&(s=s?s+" "+i:i)}return s}class _c{constructor(t){this.markCache=Object.create(null),this.tree=Uh(t.state),this.decorations=this.buildDeco(t,Wc(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=Uh(t.state),i=Wc(t.state),n=i!=Wc(t.startState),{viewport:s}=t.view,r=t.changes.mapPos(this.decoratedTo,1);e.length=s.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=r):(e!=this.tree||t.viewportChanged||n)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=s.to)}buildDeco(t,e){if(!e||!this.tree.length)return ci.none;let i=new It;for(let{from:n,to:s}of t.visibleRanges)Sh(this.tree,e,(t,e,n)=>{i.add(t,e,this.markCache[n]||(this.markCache[n]=ci.mark({class:n})))},n,s);return i.finish()}}const jc=Q.high(ln.fromClass(_c,{decorations:t=>t.decorations})),Kc=Fc.define([{tag:Vh.meta,color:"#404740"},{tag:Vh.link,textDecoration:"underline"},{tag:Vh.heading,textDecoration:"underline",fontWeight:"bold"},{tag:Vh.emphasis,fontStyle:"italic"},{tag:Vh.strong,fontWeight:"bold"},{tag:Vh.strikethrough,textDecoration:"line-through"},{tag:Vh.keyword,color:"#708"},{tag:[Vh.atom,Vh.bool,Vh.url,Vh.contentSeparator,Vh.labelName],color:"#219"},{tag:[Vh.literal,Vh.inserted],color:"#164"},{tag:[Vh.string,Vh.deleted],color:"#a11"},{tag:[Vh.regexp,Vh.escape,Vh.special(Vh.string)],color:"#e40"},{tag:Vh.definition(Vh.variableName),color:"#00f"},{tag:Vh.local(Vh.variableName),color:"#30a"},{tag:[Vh.typeName,Vh.namespace],color:"#085"},{tag:Vh.className,color:"#167"},{tag:[Vh.special(Vh.variableName),Vh.macroName],color:"#256"},{tag:Vh.definition(Vh.propertyName),color:"#00c"},{tag:Vh.comment,color:"#940"},{tag:Vh.invalid,color:"#f00"}]),Uc=lr.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Gc="()[]{}",Yc=H.define({combine:t=>Ot(t,{afterCursor:!0,brackets:Gc,maxScanDistance:1e4,renderMatch:Zc})}),Xc=ci.mark({class:"cm-matchingBracket"}),Jc=ci.mark({class:"cm-nonmatchingBracket"});function Zc(t){let e=[],i=t.matched?Xc:Jc;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 Qc=U.define({create:()=>ci.none,update(t,e){if(!e.docChanged&&!e.selection)return t;let i=[],n=e.state.facet(Yc);for(let t of e.state.selection.ranges){if(!t.empty)continue;let s=su(e.state,t.head,-1,n)||t.head>0&&su(e.state,t.head-1,1,n)||n.afterCursor&&(su(e.state,t.head,1,n)||t.headlr.decorations.from(t)}),tu=[Qc,Uc];const eu=new Ha;function iu(t,e,i){let n=t.prop(e<0?Ha.openedBy:Ha.closedBy);if(n)return n;if(1==t.name.length){let n=i.indexOf(t.name);if(n>-1&&n%2==(e<0?1:0))return[i[n+e]]}return null}function nu(t){let e=t.type.prop(eu);return e?e(t.node):t}function su(t,e,i,n={}){let s=n.maxScanDistance||1e4,r=n.brackets||Gc,o=Uh(t),l=o.resolveInner(e,i);for(let n=l;n;n=n.parent){let s=iu(n.type,i,r);if(s&&n.from0?e>=o.from&&eo.from&&e<=o.to))return ru(t,e,i,n,o,s,r)}}return function(t,e,i,n,s,r,o){let l=i<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=i>0)return null;let h={from:i<0?e-1:e,to:i>0?e+1:e},c=t.doc.iterRange(e,i>0?t.doc.length:0),u=0;for(let t=0;!c.next().done&&t<=r;){let r=c.value;i<0&&(t+=r.length);let l=e+t*i;for(let t=i>0?0:r.length-1,e=i>0?r.length:-1;t!=e;t+=i){let e=o.indexOf(r[t]);if(!(e<0||n.resolveInner(l+t,1).type!=s))if(e%2==0==i>0)u++;else{if(1==u)return{start:h,end:{from:l+t,to:l+t+1},matched:e>>1==a>>1};u--}}i>0&&(t+=r.length)}return c.done?{start:h,matched:!1}:null}(t,e,i,o,l.type,s,r)}function ru(t,e,i,n,s,r,o){let l=n.parent,a={from:s.from,to:s.to},h=0,c=null==l?void 0:l.cursor();if(c&&(i<0?c.childBefore(n.from):c.childAfter(n.to)))do{if(i<0?c.to<=n.from:c.from>=n.to){if(0==h&&r.indexOf(c.type.name)>-1&&c.from=this.string.length}sol(){return 0==this.pos}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pose}eatSpace(){let t=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>t}skipToEnd(){this.pos=this.string.length}skipTo(t){let e=this.string.indexOf(t,this.pos);if(e>-1)return this.pos=e,!0}backUp(t){this.pos-=t}column(){return this.lastColumnPosi?t.toLowerCase():t;return n(this.string.substr(this.pos,t.length))==n(t)?(!1!==e&&(this.pos+=t.length),!0):null}{let i=this.string.slice(this.pos).match(t);return i&&i.index>0?null:(i&&!1!==e&&(this.pos+=i[0].length),i)}}current(){return this.string.slice(this.start,this.pos)}}function au(t){if("object"!=typeof t)return t;let e={};for(let i in t){let n=t[i];e[i]=n instanceof Array?n.slice():n}return e}const hu=new WeakMap;class cu extends jh{constructor(t){let e=(i=t.languageData,H.define({combine:i?t=>t.concat(i):void 0}));var i;let n,s={name:(r=t).name||"",token:r.token,blankLine:r.blankLine||(()=>{}),startState:r.startState||(()=>!0),copyState:r.copyState||au,indent:r.indent||(()=>null),languageData:r.languageData||{},tokenTable:r.tokenTable||mu,mergeTokens:!1!==r.mergeTokens};var r;super(e,new class extends dh{createParse(t,e,i){return new du(n,t,e,i)}},[],t.name),this.topNode=function(t,e){let i=$a.define({id:gu.length,name:"Document",props:[$h.add(()=>t),hc.add(()=>t=>e.getIndent(t))],top:!0});return gu.push(i),i}(e,this),n=this,this.streamParser=s,this.stateAfter=new Ha({perNode:!0}),this.tokenTable=t.tokenTable?new xu(s.tokenTable):ku}static define(t){return new cu(t)}getIndent(t){let e,{overrideIndentation:i}=t.options;i&&(e=hu.get(t.state),null!=e&&e1e4)return null;for(;n=n&&i+e.length<=s&&e.prop(t.stateAfter);if(r)return{state:t.streamParser.copyState(r),pos:i+e.length};for(let r=e.children.length-1;r>=0;r--){let o=e.children[r],l=i+e.positions[r],a=o instanceof Ga&&l=e.length)return e;s||0!=i||e.type!=t.topNode||(s=!0);for(let r=e.children.length-1;r>=0;r--){let o,l=e.positions[r],a=e.children[r];if(li&&uu(t,s.tree,0-s.offset,i,o);if(l&&l.pos<=n&&(e=fu(t,s.tree,i+s.offset,l.pos+s.offset,!1)))return{state:l.state,tree:e}}return{state:t.streamParser.startState(s?rc(s):4),tree:Ga.empty}}(t,i,r,this.to,null==s?void 0:s.state);this.state=o,this.parsedPos=this.chunkStart=r+l.length;for(let t=0;tt.from<=s.viewport.from&&t.to>=s.viewport.from)&&(this.state=this.lang.streamParser.startState(rc(s.state)),s.skipUntilInView(this.parsedPos,s.viewport.from),this.parsedPos=s.viewport.from),this.moveRangeIndex()}advance(){let t=Xh.get(),e=null==this.stoppedAt?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(e,this.chunkStart+512);for(t&&(i=Math.min(i,t.viewport.to));this.parsedPos=e?this.finish():t&&this.parsedPos>=t.viewport.to?(t.skipUntilInView(this.parsedPos,e),this.finish()):null}stopAt(t){this.stoppedAt=t}lineAfter(t){let e=this.input.chunk(t);if(this.input.lineChunks)"\n"==e&&(e="");else{let t=e.indexOf("\n");t>-1&&(e=e.slice(0,t))}return t+e.length<=this.to?e:e.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,e=this.lineAfter(t),i=t+e.length;for(let t=this.rangeIndex;;){let n=this.ranges[t].to;if(n>=i)break;if(e=e.slice(0,n-(i-e.length)),t++,t==this.ranges.length)break;let s=this.ranges[t].from,r=this.lineAfter(s);e+=r,i=s+r.length}return{line:e,end:i}}skipGapsTo(t,e,i){for(;;){let n=this.ranges[this.rangeIndex].to,s=t+e;if(i>0?n>s:n>=s)break;e+=this.ranges[++this.rangeIndex].from-n}return e}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to1){e+=n=this.skipGapsTo(e,n,1);let t=this.chunk.length;i+=n=this.skipGapsTo(i,n,-1),s+=this.chunk.length-t}let r=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&4==s&&r>=0&&this.chunk[r]==t&&this.chunk[r+2]==e?this.chunk[r+2]=i:this.chunk.push(t,e,i,s),n}parseLine(t){let{line:e,end:i}=this.nextLine(),n=0,{streamParser:s}=this.lang,r=new lu(e,t?t.state.tabSize:4,t?rc(t.state):2);if(r.eol())s.blankLine(this.state,r.indentUnit);else for(;!r.eol();){let t=pu(s.token,r,this.state);if(t&&(n=this.emitToken(this.lang.tokenTable.resolve(t),this.parsedPos+r.start,this.parsedPos+r.pos,n)),r.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPose.start)return n}throw new Error("Stream parser failed to advance stream.")}const mu=Object.create(null),gu=[$a.none],vu=new _a(gu),wu=[],bu=Object.create(null),yu=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])yu[t]=Cu(mu,e);class xu{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),yu)}resolve(t){return t?this.table[t]||(this.table[t]=Cu(this.extra,t)):0}}const ku=new xu(mu);function Su(t,e){wu.indexOf(t)>-1||(wu.push(t),console.warn(e))}function Cu(t,e){let i=[];for(let n of e.split(" ")){let e=[];for(let i of n.split(".")){let n=t[i]||Vh[i];n?"function"==typeof n?e.length?e=e.map(n):Su(i,`Modifier ${i} used at start of tag`):e.length?Su(i,`Tag ${i} used as modifier`):e=Array.isArray(n)?n:[n]:Su(i,`Unknown highlighting tag ${i}`)}for(let t of e)i.push(t)}if(!i.length)return 0;let n=e.replace(/ /g,"_"),s=n+" "+i.map(t=>t.id),r=bu[s];if(r)return r.id;let o=bu[s]=$a.define({id:gu.length,name:n,props:[bh({[n]:i})]});return gu.push(o),o.id}ki.RTL,ki.LTR;function Au(t,e){return({state:i,dispatch:n})=>{if(i.readOnly)return!1;let s=t(e,i);return!!s&&(n(i.update(s)),!0)}}const Mu=Au(Pu,0),Tu=Au(Eu,0),Du=Au((t,e)=>Eu(t,e,function(t){let e=[];for(let i of t.selection.ranges){let n=t.doc.lineAt(i.from),s=i.to<=n.to?n:t.doc.lineAt(i.to);s.from>n.from&&s.from==i.to&&(s=i.to==n.to+1?n:t.doc.lineAt(i.to-1));let r=e.length-1;r>=0&&e[r].to>n.from?e[r].to=s.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:s.to})}return e}(e)),0);function Ou(t,e){let i=t.languageDataAt("commentTokens",e,1);return i.length?i[0]:{}}const Ru=50;function Eu(t,e,i=e.selection.ranges){let n=i.map(t=>Ou(e,t.from).block);if(!n.every(t=>t))return null;let s=i.map((t,i)=>function(t,{open:e,close:i},n,s){let r,o,l=t.sliceDoc(n-Ru,n),a=t.sliceDoc(s,s+Ru),h=/\s*$/.exec(l)[0].length,c=/^\s*/.exec(a)[0].length,u=l.length-h;if(l.slice(u-e.length,u)==e&&a.slice(c,c+i.length)==i)return{open:{pos:n-h,margin:h&&1},close:{pos:s+c,margin:c&&1}};s-n<=2*Ru?r=o=t.sliceDoc(n,s):(r=t.sliceDoc(n,n+Ru),o=t.sliceDoc(s-Ru,s));let f=/^\s*/.exec(r)[0].length,d=/\s*$/.exec(o)[0].length,p=o.length-d-i.length;return r.slice(f,f+e.length)==e&&o.slice(p,p+i.length)==i?{open:{pos:n+f+e.length,margin:/\s/.test(r.charAt(f+e.length))?1:0},close:{pos:s-d-i.length,margin:/\s/.test(o.charAt(p-1))?1:0}}:null}(e,n[i],t.from,t.to));if(2!=t&&!s.every(t=>t))return{changes:e.changes(i.map((t,e)=>s[e]?[]:[{from:t.from,insert:n[e].open+" "},{from:t.to,insert:" "+n[e].close}]))};if(1!=t&&s.some(t=>t)){let t=[];for(let e,i=0;is&&(t==r||r>a.from)){s=a.from;let t=/^\s*/.exec(a.text)[0].length,e=t==a.length,i=a.text.slice(t,t+l.length)==l?t:-1;tt.comment<0&&(!t.empty||t.single))){let t=[];for(let{line:e,token:i,indent:s,empty:r,single:o}of n)!o&&r||t.push({from:e.from+s,insert:i+" "});let i=e.changes(t);return{changes:i,selection:e.selection.map(i,1)}}if(1!=t&&n.some(t=>t.comment>=0)){let t=[];for(let{line:e,comment:i,token:s}of n)if(i>=0){let n=e.from+i,r=n+s.length;" "==e.text[r-e.from]&&r++,t.push({from:n,to:r})}return{changes:t}}return null}const Lu=dt.define(),Bu=dt.define(),Iu=H.define(),Nu=H.define({combine:t=>Ot(t,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,n)=>t(i,n)||e(i,n)})}),zu=U.define({create:()=>Qu.empty,update(t,e){let i=e.state.facet(Nu),n=e.annotation(Lu);if(n){let s=$u.fromTransaction(e,n.selection),r=n.side,o=0==r?t.undone:t.done;return o=s?_u(o,o.length,i.minDepth,s):Gu(o,e.startState.selection),new Qu(0==r?n.rest:o,0==r?o:n.rest)}let s=e.annotation(Bu);if("full"!=s&&"before"!=s||(t=t.isolate()),!1===e.annotation(vt.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let r=$u.fromTransaction(e),o=e.annotation(vt.time),l=e.annotation(vt.userEvent);return r?t=t.addChanges(r,o,l,i,e):e.selection&&(t=t.addSelection(e.startState.selection,o,l,i.newGroupDelay)),"full"!=s&&"after"!=s||(t=t.isolate()),t},toJSON:t=>({done:t.done.map(t=>t.toJSON()),undone:t.undone.map(t=>t.toJSON())}),fromJSON:t=>new Qu(t.done.map($u.fromJSON),t.undone.map($u.fromJSON))});function qu(t,e){return function({state:i,dispatch:n}){if(!e&&i.readOnly)return!1;let s=i.field(zu,!1);if(!s)return!1;let r=s.pop(t,i,e);return!!r&&(n(r),!0)}}const Fu=qu(0,!1),Hu=qu(1,!1),Vu=qu(0,!0),Wu=qu(1,!0);class $u{constructor(t,e,i,n,s){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=n,this.selectionsAfter=s}setSelAfter(t){return new $u(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 $u(t.changes&&O.fromJSON(t.changes),[],t.mapped&&D.fromJSON(t.mapped),t.startSelection&&z.fromJSON(t.startSelection),t.selectionsAfter.map(z.fromJSON))}static fromTransaction(t,e){let i=Ku;for(let e of t.startState.facet(Iu)){let n=e(t);n.length&&(i=i.concat(n))}return!i.length&&t.changes.empty?null:new $u(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,Ku)}static selection(t){return new $u(void 0,Ku,void 0,void 0,t)}}function _u(t,e,i,n){let s=e+1>i+20?e-i-1:0,r=t.slice(s,e);return r.push(n),r}function ju(t,e){return t.length?e.length?t.concat(e):t:e}const Ku=[],Uu=200;function Gu(t,e){if(t.length){let i=t[t.length-1],n=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-Uu));return n.length&&n[n.length-1].eq(e)?t:(n.push(e),_u(t,t.length-1,1e9,i.setSelAfter(n)))}return[$u.selection([e])]}function Yu(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 Xu(t,e){if(!t.length)return t;let i=t.length,n=Ku;for(;i;){let s=Ju(t[i-1],e,n);if(s.changes&&!s.changes.empty||s.effects.length){let e=t.slice(0,i);return e[i-1]=s,e}e=s.mapped,i--,n=s.selectionsAfter}return n.length?[$u.selection(n)]:Ku}function Ju(t,e,i){let n=ju(t.selectionsAfter.length?t.selectionsAfter.map(t=>t.map(e)):Ku,i);if(!t.changes)return $u.selection(n);let s=t.changes.map(e),r=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(r):r;return new $u(s,gt.mapEffects(t.effects,e),o,t.startSelection.map(r),n)}const Zu=/^(input\.type|delete)($|\.)/;class Qu{constructor(t,e,i=0,n=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new Qu(this.done,this.undone):this}addChanges(t,e,i,n,s){let r=this.done,o=r[r.length-1];return r=o&&o.changes&&!o.changes.empty&&t.changes&&(!i||Zu.test(i))&&(!o.selectionsAfter.length&&e-this.prevTimei.push(t,e)),e.iterChangedRanges((t,e,s,r)=>{for(let t=0;t=e&&s<=o&&(n=!0)}}),n}(o.changes,t.changes))||"input.type.compose"==i)?_u(r,r.length-1,n.minDepth,new $u(t.changes.compose(o.changes),ju(gt.mapEffects(t.effects,o.changes),o.effects),o.mapped,o.startSelection,Ku)):_u(r,r.length,n.minDepth,t),new Qu(r,Ku,e,i)}addSelection(t,e,i,n){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:Ku;return s.length>0&&e-this.prevTimet.empty!=o.ranges[e].empty).length)?this:new Qu(Gu(this.done,t),this.undone,e,i);var r,o}addMapping(t){return new Qu(Xu(this.done,t),Xu(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let n=0==t?this.done:this.undone;if(0==n.length)return null;let s=n[n.length-1],r=s.selectionsAfter[0]||e.selection;if(i&&s.selectionsAfter.length)return e.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Lu.of({side:t,rest:Yu(n),selection:r}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let i=1==n.length?Ku:n.slice(0,n.length-1);return s.mapped&&(i=Xu(i,s.mapped)),e.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Lu.of({side:t,rest:i,selection:r}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}Qu.empty=new Qu(Ku,Ku);const tf=[{key:"Mod-z",run:Fu,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Hu,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Hu,preventDefault:!0},{key:"Mod-u",run:Vu,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Wu,preventDefault:!0}];function ef(t,e){return z.create(t.ranges.map(e),t.mainIndex)}function nf(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function sf({state:t,dispatch:e},i){let n=ef(t.selection,i);return!n.eq(t.selection,!0)&&(e(nf(t,n)),!0)}function rf(t,e){return z.cursor(e?t.to:t.from)}function of(t,e){return sf(t,i=>i.empty?t.moveByChar(i,e):rf(i,e))}function lf(t){return t.textDirectionAt(t.state.selection.main.head)==ki.LTR}const af=t=>of(t,!lf(t)),hf=t=>of(t,lf(t));function cf(t,e){return sf(t,i=>i.empty?t.moveByGroup(i,e):rf(i,e))}function uf(t,e,i){if(e.type.prop(i))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function ff(t,e,i){let n,s,r=Uh(t).resolveInner(e.head),o=i?Ha.closedBy:Ha.openedBy;for(let n=e.head;;){let e=i?r.childAfter(n):r.childBefore(n);if(!e)break;uf(t,e,o)?r=e:n=i?e.to:e.from}return s=r.type.prop(o)&&(n=i?su(t,r.from,1):su(t,r.to,-1))&&n.matched?i?n.end.to:n.end.from:i?r.to:r.from,z.cursor(s,i?-1:1)}function df(t,e){return sf(t,i=>{if(!i.empty)return rf(i,e);let n=t.moveVertically(i,e);return n.head!=i.head?n:t.moveToLineBoundary(i,e)})}const pf=t=>df(t,!1),mf=t=>df(t,!0);function gf(t){let e,i=t.scrollDOM.clientHeighti.empty?t.moveVertically(i,e,n.height):rf(i,e));if(r.eq(s.selection))return!1;if(n.selfScroll){let e=t.coordsAtPos(s.selection.main.head),o=t.scrollDOM.getBoundingClientRect(),l=o.top+n.marginTop,a=o.bottom-n.marginBottom;e&&e.top>l&&e.bottomvf(t,!1),bf=t=>vf(t,!0);function yf(t,e,i){let n=t.lineBlockAt(e.head),s=t.moveToLineBoundary(e,i);if(s.head==e.head&&s.head!=(i?n.to:n.from)&&(s=t.moveToLineBoundary(e,i,!1)),!i&&s.head==n.from&&n.length){let i=/^\s*/.exec(t.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;i&&e.head!=n.from+i&&(s=z.cursor(n.from+i))}return s}function xf(t,e){let i=ef(t.state.selection,t=>{let i=e(t);return z.range(t.anchor,i.head,i.goalColumn,i.bidiLevel||void 0)});return!i.eq(t.state.selection)&&(t.dispatch(nf(t.state,i)),!0)}function kf(t,e){return xf(t,i=>t.moveByChar(i,e))}const Sf=t=>kf(t,!lf(t)),Cf=t=>kf(t,lf(t));function Af(t,e){return xf(t,i=>t.moveByGroup(i,e))}function Mf(t,e){return xf(t,i=>t.moveVertically(i,e))}const Tf=t=>Mf(t,!1),Df=t=>Mf(t,!0);function Of(t,e){return xf(t,i=>t.moveVertically(i,e,gf(t).height))}const Rf=t=>Of(t,!1),Ef=t=>Of(t,!0),Pf=({state:t,dispatch:e})=>(e(nf(t,{anchor:0})),!0),Lf=({state:t,dispatch:e})=>(e(nf(t,{anchor:t.doc.length})),!0),Bf=({state:t,dispatch:e})=>(e(nf(t,{anchor:t.selection.main.anchor,head:0})),!0),If=({state:t,dispatch:e})=>(e(nf(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function Nf(t,e){if(t.state.readOnly)return!1;let i="delete.selection",{state:n}=t,s=n.changeByRange(n=>{let{from:s,to:r}=n;if(s==r){let o=e(n);os&&(i="delete.forward",o=zf(t,o,!0)),s=Math.min(s,o),r=Math.max(r,o)}else s=zf(t,s,!1),r=zf(t,r,!0);return s==r?{range:n}:{changes:{from:s,to:r},range:z.cursor(s,se(t)))n.between(e,e,(t,n)=>{te&&(e=i?n:t)});return e}const qf=(t,e,i)=>Nf(t,n=>{let s,r,o=n.from,{state:l}=t,a=l.doc.lineAt(o);if(i&&!e&&o>a.from&&oqf(t,!1,!0),Hf=t=>qf(t,!0,!1),Vf=(t,e)=>Nf(t,i=>{let n=i.head,{state:s}=t,r=s.doc.lineAt(n),o=s.charCategorizer(n);for(let t=null;;){if(n==(e?r.to:r.from)){n==i.head&&r.number!=(e?s.doc.lines:1)&&(n+=e?1:-1);break}let l=k(r.text,n-r.from,e)+r.from,a=r.text.slice(Math.min(n,l)-r.from,Math.max(n,l)-r.from),h=o(a);if(null!=t&&h!=t)break;" "==a&&n==i.head||(t=h),n=l}return n}),Wf=t=>Vf(t,!1);function $f(t){let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.from),r=t.doc.lineAt(n.to);if(n.empty||n.to!=r.from||(r=t.doc.lineAt(n.to-1)),i>=s.number){let t=e[e.length-1];t.to=r.to,t.ranges.push(n)}else e.push({from:s.from,to:r.to,ranges:[n]});i=r.number+1}return e}function _f(t,e,i){if(t.readOnly)return!1;let n=[],s=[];for(let e of $f(t)){if(i?e.to==t.doc.length:0==e.from)continue;let r=t.doc.lineAt(i?e.to+1:e.from-1),o=r.length+1;if(i){n.push({from:e.to,to:r.to},{from:e.from,insert:r.text+t.lineBreak});for(let i of e.ranges)s.push(z.range(Math.min(t.doc.length,i.anchor+o),Math.min(t.doc.length,i.head+o)))}else{n.push({from:r.from,to:e.from},{from:e.to,insert:t.lineBreak+r.text});for(let t of e.ranges)s.push(z.range(t.anchor-o,t.head-o))}}return!!n.length&&(e(t.update({changes:n,scrollIntoView:!0,selection:z.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0)}function jf(t,e,i){if(t.readOnly)return!1;let n=[];for(let e of $f(t))i?n.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):n.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});return e(t.update({changes:n,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Kf=Uf(!1);function Uf(t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let n=e.changeByRange(i=>{let{from:n,to:s}=i,r=e.doc.lineAt(n),o=!t&&n==s&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,n=Uh(t).resolveInner(e),s=n.childBefore(e),r=n.childAfter(e);return s&&r&&s.to<=e&&r.from>=e&&(i=s.type.prop(Ha.closedBy))&&i.indexOf(r.name)>-1&&t.doc.lineAt(s.to).from==t.doc.lineAt(r.from).from&&!/\S/.test(t.sliceDoc(s.to,r.from))?{from:s.to,to:r.from}:null}(e,n);t&&(n=s=(s<=r.to?r:e.doc.lineAt(s)).to);let l=new ac(e,{simulateBreak:n,simulateDoubleBreak:!!o}),a=lc(l,n);for(null==a&&(a=Kt(/^\s*/.exec(e.doc.lineAt(n).text)[0],e.tabSize));sr.from&&n{let s=[];for(let r=n.from;r<=n.to;){let o=t.doc.lineAt(r);o.number>i&&(n.empty||n.to>o.from)&&(e(o,s,n),i=o.number),r=o.to+1}let r=t.changes(s);return{changes:s,range:z.range(r.mapPos(n.anchor,1),r.mapPos(n.head,1))}})}const Yf=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:t=>sf(t,e=>ff(t.state,e,!lf(t))),shift:t=>xf(t,e=>ff(t.state,e,!lf(t)))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>sf(t,e=>ff(t.state,e,lf(t))),shift:t=>xf(t,e=>ff(t.state,e,lf(t)))},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>_f(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>jf(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>_f(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>jf(t,e,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,n=null;return i.ranges.length>1?n=z.create([i.main]):i.main.empty||(n=z.create([z.cursor(i.main.head)])),!!n&&(e(nf(t,n)),!0)}},{key:"Mod-Enter",run:Uf(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=$f(t).map(({from:e,to:i})=>z.range(e,Math.min(i+1,t.doc.length)));return e(t.update({selection:z.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=ef(t.selection,e=>{let i=Uh(t),n=i.resolveStack(e.from,1);if(e.empty){let t=i.resolveStack(e.from,-1);t.node.from>=n.node.from&&t.node.to<=n.node.to&&(n=t)}for(let t=n;t;t=t.next){let{node:i}=t;if((i.from=e.to||i.to>e.to&&i.from<=e.from)&&t.next)return z.range(i.to,i.from)}return e});return!i.eq(t.selection)&&(e(nf(t,i)),!0)},preventDefault:!0},{key:"Mod-[",run:({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Gf(t,(e,i)=>{let n=/^\s*/.exec(e.text)[0];if(!n)return;let s=Kt(n,t.tabSize),r=0,o=oc(t,Math.max(0,s-rc(t)));for(;r!t.readOnly&&(e(t.update(Gf(t,(e,i)=>{i.push({from:e.from,insert:t.facet(sc)})}),{userEvent:"input.indent"})),!0)},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),n=new ac(t,{overrideIndentation:t=>{let e=i[t];return null==e?-1:e}}),s=Gf(t,(e,s,r)=>{let o=lc(n,e.from);if(null==o)return;/\S/.test(e.text)||(o=0);let l=/^\s*/.exec(e.text)[0],a=oc(t,o);(l!=a||r.from{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes($f(e).map(({from:t,to:i})=>(t>0?t--:i{let i;if(t.lineWrapping){let n=t.lineBlockAt(e.head),s=t.coordsAtPos(e.head,e.assoc||1);s&&(i=n.bottom+t.documentTop-s.bottom+t.defaultLineHeight/2)}return t.moveVertically(e,!0,i)}).map(i);return t.dispatch({changes:i,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>function(t,e){let i=!1,n=ef(t.selection,e=>{let n=su(t,e.head,-1)||su(t,e.head,1)||e.head>0&&su(t,e.head-1,1)||e.head{let{state:e}=t,i=e.doc.lineAt(e.selection.main.from),n=Ou(t.state,i.from);return n.line?Mu(t):!!n.block&&Du(t)}},{key:"Alt-A",run:Tu},{key:"Ctrl-m",mac:"Shift-Alt-m",run:t=>(t.setTabFocusMode(),!0)}].concat([{key:"ArrowLeft",run:af,shift:Sf,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:t=>cf(t,!lf(t)),shift:t=>Af(t,!lf(t)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:t=>sf(t,e=>yf(t,e,!lf(t))),shift:t=>xf(t,e=>yf(t,e,!lf(t))),preventDefault:!0},{key:"ArrowRight",run:hf,shift:Cf,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>cf(t,lf(t)),shift:t=>Af(t,lf(t)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:t=>sf(t,e=>yf(t,e,lf(t))),shift:t=>xf(t,e=>yf(t,e,lf(t))),preventDefault:!0},{key:"ArrowUp",run:pf,shift:Tf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Pf,shift:Bf},{mac:"Ctrl-ArrowUp",run:wf,shift:Rf},{key:"ArrowDown",run:mf,shift:Df,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Lf,shift:If},{mac:"Ctrl-ArrowDown",run:bf,shift:Ef},{key:"PageUp",run:wf,shift:Rf},{key:"PageDown",run:bf,shift:Ef},{key:"Home",run:t=>sf(t,e=>yf(t,e,!1)),shift:t=>xf(t,e=>yf(t,e,!1)),preventDefault:!0},{key:"Mod-Home",run:Pf,shift:Bf},{key:"End",run:t=>sf(t,e=>yf(t,e,!0)),shift:t=>xf(t,e=>yf(t,e,!0)),preventDefault:!0},{key:"Mod-End",run:Lf,shift:If},{key:"Enter",run:Kf,shift:Kf},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:Ff,shift:Ff},{key:"Delete",run:Hf},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Wf},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>Vf(t,!0)},{mac:"Mod-Backspace",run:t=>Nf(t,e=>{let i=t.moveToLineBoundary(e,!1).head;return e.head>i?i:Math.max(0,e.head-1)})},{mac:"Mod-Delete",run:t=>Nf(t,e=>{let i=t.moveToLineBoundary(e,!0).head;return e.headsf(t,e=>z.cursor(t.lineBlockAt(e.head).from,1)),shift:t=>xf(t,e=>z.cursor(t.lineBlockAt(e.head).from))},{key:"Ctrl-e",run:t=>sf(t,e=>z.cursor(t.lineBlockAt(e.head).to,-1)),shift:t=>xf(t,e=>z.cursor(t.lineBlockAt(e.head).to))},{key:"Ctrl-d",run:Hf},{key:"Ctrl-h",run:Ff},{key:"Ctrl-k",run:t=>Nf(t,e=>{let i=t.lineBlockAt(e.head).to;return e.head{if(t.readOnly)return!1;let i=t.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:f.of(["",""])},range:z.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,n=t.doc.lineAt(i),s=i==n.from?i-1:k(n.text,i-n.from,!1)+n.from,r=i==n.to?i+1:k(n.text,i-n.from,!0)+n.from;return{changes:{from:s,to:r,insert:t.doc.slice(i,r).append(t.doc.slice(s,i))},range:z.cursor(r)}});return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:bf}].map(t=>({mac:t.key,run:t.run,shift:t.shift}))));class Xf{constructor(t,e,i,n){this.state=t,this.pos=e,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let e=Uh(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),n=e.text.slice(i-e.from,this.pos-e.from),s=n.search(ed(t,!1));return s<0?null:{from:i+s,to:this.pos,text:n.slice(s)}}get aborted(){return null==this.abortListeners}addEventListener(t,e,i){"abort"==t&&this.abortListeners&&(this.abortListeners.push(e),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function Jf(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 Zf(t){let e=t.map(t=>"string"==typeof t?{label:t}:t),[i,n]=e.every(t=>/^\w+$/.test(t.label))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),i=Object.create(null);for(let{label:n}of t){e[n[0]]=!0;for(let t=1;t{let s=t.matchBefore(n);return s||t.explicit?{from:s?s.from:t.pos,options:e,validFor:i}:null}}class Qf{constructor(t,e,i,n){this.completion=t,this.source=e,this.match=i,this.score=n}}function td(t){return t.selection.main.from}function ed(t,e){var i;let{source:n}=t,s=e&&"^"!=n[0],r="$"!=n[n.length-1];return s||r?new RegExp(`${s?"^":""}(?:${n})${r?"$":""}`,null!==(i=t.flags)&&void 0!==i?i:t.ignoreCase?"i":""):t}const id=dt.define();function nd(t,e,i,n){let{main:s}=t.selection,r=i-s.from,o=n-s.from;return{...t.changeByRange(l=>{if(l!=s&&i!=n&&t.sliceDoc(l.from+r,l.from+o)!=t.sliceDoc(i,n))return{range:l};let a=t.toText(e);return{changes:{from:l.from+r,to:n==s.from?l.to:l.from+o,insert:a},range:z.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const sd=new WeakMap;function rd(t){if(!Array.isArray(t))return t;let e=sd.get(t);return e||sd.set(t,e=Zf(t)),e}const od=gt.define(),ld=gt.define();class ad{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e=48&&a<=57||a>=97&&a<=122?2:a>=65&&a<=90?1:0:(w=C(a))!=w.toLowerCase()?1:w!=w.toUpperCase()?2:0;(!n||1==b&&m||0==v&&0!=b)&&(e[c]==a||i[c]==a&&(u=!0)?r[c++]=n:r.length&&(g=!1)),v=b,n+=A(a)}return c==l&&0==r[0]&&g?this.result((u?-200:0)-100,r,t):f==l&&0==d?this.ret(-200-t.length+(p==t.length?0:-100),[0,p]):o>-1?this.ret(-700-t.length,[o,o+this.pattern.length]):f==l?this.ret(-900-t.length,[d,p]):c==l?this.result((u?-200:0)-100-700+(g?0:-1100),r,t):2==e.length?null:this.result((n[0]?-700:0)-200-1100,n,t)}result(t,e,i){let n=[],s=0;for(let t of e){let e=t+(this.astral?A(S(i,t)):1);s&&n[s-1]==t?n[s-1]=e:(n[s++]=t,n[s++]=e)}return this.ret(t-i.length,n)}}class hd{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.lengthOt(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:fd,filterStrict:!1,compareCompletions:(t,e)=>t.label.localeCompare(e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>ud(t(i),e(i)),optionClass:(t,e)=>i=>ud(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})});function ud(t,e){return t?e?t+" "+e:t:e}function fd(t,e,i,n,s,r){let o,l,a=t.textDirection==ki.RTL,h=a,c=!1,u="top",f=e.left-s.left,d=s.right-e.right,p=n.right-n.left,m=n.bottom-n.top;if(h&&f=m||t>e.top?o=i.bottom-e.top:(u="bottom",o=e.bottom-i.top)}return{style:`${u}: ${o/((e.bottom-e.top)/r.offsetHeight)}px; max-width: ${l/((e.right-e.left)/r.offsetWidth)}px`,class:"cm-completionInfo-"+(c?a?"left-narrow":"right-narrow":h?"left":"right")}}function dd(t,e,i){if(t<=i)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/i);return{from:t*i,to:(t+1)*i}}let n=Math.floor((t-e)/i);return{from:t-(n+1)*i,to:t-n*i}}class pd{constructor(t,e,i){this.view=t,this.stateField=e,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let n=t.state.field(e),{options:s,selected:r}=n.open,o=t.state.facet(cd);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,n){let s=document.createElement("span");s.className="cm-completionLabel";let r=t.displayLabel||t.label,o=0;for(let t=0;to&&s.appendChild(document.createTextNode(r.slice(o,e)));let l=s.appendChild(document.createElement("span"));l.appendChild(document.createTextNode(r.slice(e,i))),l.className="cm-completionMatchedText",o=i}return ot.position-e.position).map(t=>t.render)}(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=dd(s.length,r,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",i=>{let{options:n}=t.state.field(e).open;for(let e,s=i.target;s&&s!=this.dom;s=s.parentNode)if("LI"==s.nodeName&&(e=/-(\d+)$/.exec(s.id))&&+e[1]{let i=t.state.field(this.stateField,!1);i&&i.tooltip&&t.state.facet(cd).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:ld.of(null)})}),this.showOptions(s,n.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),n=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=n){let{options:s,selected:r,disabled:o}=i.open;n.open&&n.open.options==s||(this.range=dd(s.length,r,t.state.facet(cd).maxRenderedOptions),this.showOptions(s,i.id)),this.updateSel(),o!=(null===(e=n.open)||void 0===e?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!o)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected>-1&&e.selected=this.range.to)&&(this.range=dd(e.options.length,e.selected,this.view.state.facet(cd).maxRenderedOptions),this.showOptions(e.options,t.id)),this.updateSelectedOption(e.selected)){this.destroyInfo();let{completion:i}=e.options[e.selected],{info:n}=i;if(!n)return;let s="string"==typeof n?document.createTextNode(n):n(i);if(!s)return;"then"in s?s.then(e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e,i)}).catch(t=>nn(this.view.state,t,"completion info")):this.addInfoPane(s,i)}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",null!=t.nodeType)i.appendChild(t),this.infoDestroy=null;else{let{dom:e,destroy:n}=t;i.appendChild(e),this.infoDestroy=n||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)"LI"==i.nodeName&&i.id?n==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected"):n--;return e&&function(t,e){let i=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=i.height/t.offsetHeight;n.topi.bottom&&(t.scrollTop+=(n.bottom-i.bottom)/s)}(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(),n=t.getBoundingClientRect(),s=this.space;if(!s){let t=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:t.clientWidth,bottom:t.clientHeight}}return n.top>Math.min(s.bottom,e.bottom)-10||n.bottom{t.target==n&&t.preventDefault()});let s=null;for(let r=i.from;ri.from||0==i.from))if(s=t,"string"!=typeof a&&a.header)n.appendChild(a.header(a));else{n.appendChild(document.createElement("completion-section")).textContent=t}}const h=n.appendChild(document.createElement("li"));h.id=e+"-"+r,h.setAttribute("role","option");let c=this.optionClass(o);c&&(h.className=c);for(let t of this.optionContent){let e=t(o,this.view.state,this.view,l);e&&h.appendChild(e)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.tonew pd(i,t,e)}function gd(t){return 100*(t.boost||0)+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}class vd{constructor(t,e,i,n,s,r){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=n,this.selected=s,this.disabled=r}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new vd(this.options,xd(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,n,s,r){if(n&&!r&&t.some(t=>t.isPending))return n.setDisabled();let o=function(t,e){let i=[],n=null,s=t=>{i.push(t);let{section:e}=t.completion;if(e){n||(n=[]);let t="string"==typeof e?e:e.name;n.some(e=>e.name==t)||n.push("string"==typeof e?{name:t}:e)}},r=e.facet(cd);for(let n of t)if(n.hasResult()){let t=n.result.getMatch;if(!1===n.result.filter)for(let e of n.result.options)s(new Qf(e,n.source,t?t(e):[],1e9-i.length));else{let i,o=e.sliceDoc(n.from,n.to),l=r.filterStrict?new hd(o):new ad(o);for(let e of n.result.options)if(i=l.match(e.label)){let r=e.displayLabel?t?t(e,i.matched):[]:i.matched;s(new Qf(e,n.source,r,i.score+(e.boost||0)))}}}if(n){let t=Object.create(null),e=0,s=(t,e)=>{var i,n;return(null!==(i=t.rank)&&void 0!==i?i:1e9)-(null!==(n=e.rank)&&void 0!==n?n:1e9)||(t.namee.score-t.score||a(t.completion,e.completion))){let e=t.completion;!l||l.label!=e.label||l.detail!=e.detail||null!=l.type&&null!=e.type&&l.type!=e.type||l.apply!=e.apply||l.boost!=e.boost?o.push(t):gd(t.completion)>gd(l)&&(o[o.length-1]=t),l=t.completion}return o}(t,e);if(!o.length)return n&&t.some(t=>t.isPending)?n.setDisabled():null;let l=e.facet(cd).selectOnOpen?0:-1;if(n&&n.selected!=l&&-1!=n.selected){let t=n.options[n.selected].completion;for(let e=0;ee.hasResult()?Math.min(t,e.from):t,1e8),create:Rd,above:s.aboveCursor},n?n.timestamp:Date.now(),l,!1)}map(t){return new vd(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new vd(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class wd{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new wd(kd,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,i=e.facet(cd),n=(i.override||e.languageDataAt("autocomplete",td(e)).map(rd)).map(e=>(this.active.find(t=>t.source==e)||new Cd(e,this.active.some(t=>0!=t.state)?1:0)).update(t,i));n.length==this.active.length&&n.every((t,e)=>t==this.active[e])&&(n=this.active);let s=this.open,r=t.effects.some(t=>t.is(Md));s&&t.docChanged&&(s=s.map(t.changes)),t.selection||n.some(e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to))||!function(t,e){if(t==e)return!0;for(let i=0,n=0;;){for(;it.isPending)&&(s=null),!s&&n.every(t=>!t.isPending)&&n.some(t=>t.hasResult())&&(n=n.map(t=>t.hasResult()?new Cd(t.source,0):t));for(let e of t.effects)e.is(Td)&&(s=s&&s.setSelected(e.value,this.id));return n==this.active&&s==this.open?this:new wd(n,this.id,s)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?bd:yd}}const bd={"aria-autocomplete":"list"},yd={};function xd(t,e){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(i["aria-activedescendant"]=t+"-"+e),i}const kd=[];function Sd(t,e){if(t.isUserEvent("input.complete")){let i=t.annotation(id);if(i&&e.activateOnCompletion(i))return 12}let i=t.isUserEvent("input.type");return i&&e.activateOnTyping?5:i?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class Cd{constructor(t,e,i=!1){this.source=t,this.state=e,this.explicit=i}hasResult(){return!1}get isPending(){return 1==this.state}update(t,e){let i=Sd(t,e),n=this;(8&i||16&i&&this.touches(t))&&(n=new Cd(n.source,0)),4&i&&0==n.state&&(n=new Cd(this.source,1)),n=n.updateFor(t,i);for(let e of t.effects)if(e.is(od))n=new Cd(n.source,1,e.value);else if(e.is(ld))n=new Cd(n.source,0);else if(e.is(Md))for(let t of e.value)t.source==n.source&&(n=t);return n}updateFor(t,e){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(td(t.state))}}class Ad extends Cd{constructor(t,e,i,n,s,r){super(t,3,e),this.limit=i,this.result=n,this.from=s,this.to=r}hasResult(){return!0}updateFor(t,e){var i;if(!(3&e))return this.map(t.changes);let n=this.result;n.map&&!t.changes.empty&&(n=n.map(n,t.changes));let s=t.changes.mapPos(this.from),r=t.changes.mapPos(this.to,1),o=td(t.state);if(o>r||!n||2&e&&(td(t.startState)==this.from||ot.map(t=>t.map(e))}),Td=gt.define(),Dd=U.define({create:()=>wd.start(),update:(t,e)=>t.update(e),provide:t=>[ho.from(t,t=>t.tooltip),lr.contentAttributes.from(t,t=>t.attrs)]});function Od(t,e){const i=e.completion.apply||e.completion.label;let n=t.state.field(Dd).active.find(t=>t.source==e.source);return n instanceof Ad&&("string"==typeof i?t.dispatch({...nd(t.state,i,n.from,n.to),annotations:id.of(e.completion)}):i(t,e.completion,n.from,n.to),!0)}const Rd=md(Dd,Od);function Ed(t,e="option"){return i=>{let n=i.state.field(Dd,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp-1?n.open.selected+r*(t?1:-1):t?0:o-1;return l<0?l="page"==e?0:o-1:l>=o&&(l="page"==e?o-1:0),i.dispatch({effects:Td.of(l)}),!0}}const Pd=t=>!!t.state.field(Dd,!1)&&(t.dispatch({effects:od.of(!0)}),!0);class Ld{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const Bd=ln.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(Dd).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(Dd),i=t.state.facet(cd);if(!t.selectionSet&&!t.docChanged&&t.startState.field(Dd)==e)return;let n=t.transactions.some(t=>{let e=Sd(t,i);return 8&e||(t.selection||t.docChanged)&&!(3&e)});for(let e=0;e50&&Date.now()-i.time>1e3){for(let t of i.context.abortListeners)try{t()}catch(t){nn(this.view.state,t)}i.context.abortListeners=null,this.running.splice(e--,1)}else i.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(t=>t.effects.some(t=>t.is(od)))&&(this.pendingStart=!0);let s=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(t=>t.isPending&&!this.running.some(e=>e.active.source==t.source))?setTimeout(()=>this.startUpdate(),s):-1,0!=this.composing)for(let e of t.transactions)e.isUserEvent("input.type")?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(Dd);for(let t of e.active)t.isPending&&!this.running.some(e=>e.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(cd).updateSyncTime))}startQuery(t){let{state:e}=this.view,i=td(e),n=new Xf(e,i,t.explicit,this.view),s=new Ld(t,n);this.running.push(s),Promise.resolve(t.source(n)).then(t=>{s.context.aborted||(s.done=t||null,this.scheduleAccept())},t=>{this.view.dispatch({effects:ld.of(null)}),nn(this.view.state,t)})}scheduleAccept(){this.running.every(t=>void 0!==t.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(cd).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],i=this.view.state.facet(cd),n=this.view.state.field(Dd);for(let s=0;st.source==r.active.source);if(o&&o.isPending)if(null==r.done){let t=new Cd(r.active.source,0);for(let e of r.updates)t=t.update(e,i);t.isPending||e.push(t)}else this.startQuery(o)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:Md.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(Dd,!1);if(e&&e.tooltip&&this.view.state.facet(cd).closeOnBlur){let i=e.open&&vo(this.view,e.open.tooltip);i&&i.dom.contains(t.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:ld.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:od.of(!1)}),20),this.composing=0}}}),Id="object"==typeof navigator&&/Win/.test(navigator.platform),Nd=Q.highest(lr.domEventHandlers({keydown(t,e){let i=e.state.field(Dd,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||t.key.length>1||t.ctrlKey&&(!Id||!t.altKey)||t.metaKey)return!1;let n=i.open.options[i.open.selected],s=i.active.find(t=>t.source==n.source),r=n.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(t.key)>-1&&Od(e,n),!1}})),zd=lr.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",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".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:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",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",boxSizing:"content-box"},".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"}}});class qd{constructor(t,e,i,n){this.field=t,this.line=e,this.from=i,this.to=n}}class Fd{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,T.TrackDel),i=t.mapPos(this.to,1,T.TrackDel);return null==e||null==i?null:new Fd(this.field,e,i)}}class Hd{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],n=[e],s=t.doc.lineAt(e),r=/^\s*/.exec(s.text)[0];for(let s of this.lines){if(i.length){let i=r,o=/^\t*/.exec(s)[0].length;for(let e=0;enew Fd(t.field,n[t.line]+t.from,n[t.line]+t.to));return{text:i,ranges:o}}static parse(t){let e,i=[],n=[],s=[];for(let r of t.split(/\r\n?|\n/)){for(;e=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(r);){let t=e[1]?+e[1]:null,o=e[2]||e[3]||"",l=-1,a=o.replace(/\\[{}]/g,t=>t[1]);for(let e=0;e=l&&t.field++}for(let t of s)if(t.line==n.length&&t.from>e.index){let i=e[2]?3+(e[1]||"").length:2;t.from-=i,t.to-=i}s.push(new qd(l,n.length,e.index,e.index+a.length)),r=r.slice(0,e.index)+o+r.slice(e.index+e[0].length)}r=r.replace(/\\([{}])/g,(t,e,i)=>{for(let t of s)t.line==n.length&&t.from>i&&(t.from--,t.to--);return e}),n.push(r)}return new Hd(n,s)}}let Vd=ci.widget({widget:new class extends ai{toDOM(){let t=document.createElement("span");return t.className="cm-snippetFieldPosition",t}ignoreEvent(){return!1}}}),Wd=ci.mark({class:"cm-snippetField"});class $d{constructor(t,e){this.ranges=t,this.active=e,this.deco=ci.set(t.map(t=>(t.from==t.to?Vd:Wd).range(t.from,t.to)),!0)}map(t){let e=[];for(let i of this.ranges){let n=i.map(t);if(!n)return null;e.push(n)}return new $d(e,this.active)}selectionInsideField(t){return t.ranges.every(t=>this.ranges.some(e=>e.field==this.active&&e.from<=t.from&&e.to>=t.to))}}const _d=gt.define({map:(t,e)=>t&&t.map(e)}),jd=gt.define(),Kd=U.define({create:()=>null,update(t,e){for(let i of e.effects){if(i.is(_d))return i.value;if(i.is(jd)&&t)return new $d(t.ranges,i.value)}return t&&e.docChanged&&(t=t.map(e.changes)),t&&e.selection&&!t.selectionInsideField(e.selection)&&(t=null),t},provide:t=>lr.decorations.from(t,t=>t?t.deco:ci.none)});function Ud(t,e){return z.create(t.filter(t=>t.field==e).map(t=>z.range(t.from,t.to)))}function Gd(t){return({state:e,dispatch:i})=>{let n=e.field(Kd,!1);if(!n||t<0&&0==n.active)return!1;let s=n.active+t,r=t>0&&!n.ranges.some(e=>e.field==s+t);return i(e.update({selection:Ud(n.ranges,s),effects:_d.of(r?null:new $d(n.ranges,s)),scrollIntoView:!0})),!0}}const Yd=[{key:"Tab",run:Gd(1),shift:Gd(-1)},{key:"Escape",run:({state:t,dispatch:e})=>!!t.field(Kd,!1)&&(e(t.update({effects:_d.of(null)})),!0)}],Xd=H.define({combine:t=>t.length?t[0]:Yd}),Jd=Q.highest(mr.compute([Xd],t=>t.facet(Xd))),Zd=lr.domEventHandlers({mousedown(t,e){let i,n=e.state.field(Kd,!1);if(!n||null==(i=e.posAtCoords({x:t.clientX,y:t.clientY})))return!1;let s=n.ranges.find(t=>t.from<=i&&t.to>=i);return!(!s||s.field==n.active)&&(e.dispatch({selection:Ud(n.ranges,s.field),effects:_d.of(n.ranges.some(t=>t.field>s.field)?new $d(n.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Qd={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},tp=gt.define({map(t,e){let i=e.mapPos(t,-1,T.TrackAfter);return null==i?void 0:i}}),ep=new class extends Rt{};ep.startSide=1,ep.endSide=-1;const ip=U.define({create:()=>Bt.empty,update(t,e){if(t=t.map(e.changes),e.selection){let i=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:t=>t>=i.from&&t<=i.to})}for(let i of e.effects)i.is(tp)&&(t=t.update({add:[ep.range(i.value,i.value+1)]}));return t}});const np="()[]{}<>«»»«[]{}";function sp(t){for(let e=0;e<16;e+=2)if(np.charCodeAt(e)==t)return np.charAt(e+1);return C(t<128?t:t+1)}function rp(t,e){return t.languageDataAt("closeBrackets",e)[0]||Qd}const op="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),lp=lr.inputHandler.of((t,e,i,n)=>{if((op?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let s=t.state.selection.main;if(n.length>2||2==n.length&&1==A(S(n,0))||e!=s.from||i!=s.to)return!1;let r=function(t,e){let i=rp(t,t.selection.main.head),n=i.brackets||Qd.brackets;for(let s of n){let r=sp(S(s,0));if(e==s)return r==s?dp(t,s,n.indexOf(s+s+s)>-1,i):up(t,s,r,i.before||Qd.before);if(e==r&&hp(t,t.selection.main.from))return fp(t,s,r)}return null}(t.state,n);return!!r&&(t.dispatch(r),!0)}),ap=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=rp(t,t.selection.main.head).brackets||Qd.brackets,n=null,s=t.changeByRange(e=>{if(e.empty){let n=function(t,e){let i=t.sliceString(e-2,e);return A(S(i,0))==i.length?i:i.slice(1)}(t.doc,e.head);for(let s of i)if(s==n&&cp(t.doc,e.head)==sp(S(s,0)))return{changes:{from:e.head-s.length,to:e.head+s.length},range:z.cursor(e.head-s.length)}}return{range:n=e}});return n||e(t.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!n}}];function hp(t,e){let i=!1;return t.field(ip).between(0,t.doc.length,t=>{t==e&&(i=!0)}),i}function cp(t,e){let i=t.sliceString(e,e+2);return i.slice(0,A(S(i,0)))}function up(t,e,i,n){let s=null,r=t.changeByRange(r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:i,from:r.to}],effects:tp.of(r.to+e.length),range:z.range(r.anchor+e.length,r.head+e.length)};let o=cp(t.doc,r.head);return!o||/\s/.test(o)||n.indexOf(o)>-1?{changes:{insert:e+i,from:r.head},effects:tp.of(r.head+e.length),range:z.cursor(r.head+e.length)}:{range:s=r}});return s?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function fp(t,e,i){let n=null,s=t.changeByRange(e=>e.empty&&cp(t.doc,e.head)==i?{changes:{from:e.head,to:e.head+i.length,insert:i},range:z.cursor(e.head+i.length)}:n={range:e});return n?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function dp(t,e,i,n){let s=n.stringPrefixes||Qd.stringPrefixes,r=null,o=t.changeByRange(n=>{if(!n.empty)return{changes:[{insert:e,from:n.from},{insert:e,from:n.to}],effects:tp.of(n.to+e.length),range:z.range(n.anchor+e.length,n.head+e.length)};let o,l=n.head,a=cp(t.doc,l);if(a==e){if(pp(t,l))return{changes:{insert:e+e,from:l},effects:tp.of(l+e.length),range:z.cursor(l+e.length)};if(hp(t,l)){let n=i&&t.sliceDoc(l,l+3*e.length)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+n.length,insert:n},range:z.cursor(l+n.length)}}}else{if(i&&t.sliceDoc(l-2*e.length,l)==e+e&&(o=mp(t,l-2*e.length,s))>-1&&pp(t,o))return{changes:{insert:e+e+e+e,from:l},effects:tp.of(l+e.length),range:z.cursor(l+e.length)};if(t.charCategorizer(l)(a)!=Ct.Word&&mp(t,l,s)>-1&&!function(t,e,i,n){let s=Uh(t).resolveInner(e,-1),r=n.reduce((t,e)=>Math.max(t,e.length),0);for(let o=0;o<5;o++){let o=t.sliceDoc(s.from,Math.min(s.to,s.from+i.length+r)),l=o.indexOf(i);if(!l||l>-1&&n.indexOf(o.slice(0,l))>-1){let e=s.firstChild;for(;e&&e.from==s.from&&e.to-e.from>i.length+l;){if(t.sliceDoc(e.to-i.length,e.to)==i)return!1;e=e.firstChild}return!0}let a=s.to==e&&s.parent;if(!a)break;s=a}return!1}(t,l,e,s))return{changes:{insert:e+e,from:l},effects:tp.of(l+e.length),range:z.cursor(l+e.length)}}return{range:r=n}});return r?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function pp(t,e){let i=Uh(t).resolveInner(e+1);return i.parent&&i.from==e}function mp(t,e,i){let n=t.charCategorizer(e);if(n(t.sliceDoc(e-1,e))!=Ct.Word)return e;for(let s of i){let i=e-s.length;if(t.sliceDoc(i,e)==s&&n(t.sliceDoc(i-1,i))!=Ct.Word)return i}return-1}function gp(t={}){return[Nd,Dd,cd.of(t),Bd,wp,zd]}const vp=[{key:"Ctrl-Space",run:Pd},{mac:"Alt-`",run:Pd},{mac:"Alt-i",run:Pd},{key:"Escape",run:t=>{let e=t.state.field(Dd,!1);return!(!e||!e.active.some(t=>0!=t.state))&&(t.dispatch({effects:ld.of(null)}),!0)}},{key:"ArrowDown",run:Ed(!0)},{key:"ArrowUp",run:Ed(!1)},{key:"PageDown",run:Ed(!0,"page")},{key:"PageUp",run:Ed(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field(Dd,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampt.facet(cd).defaultKeymap?[vp]:[]));function bp(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var yp={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function xp(t){yp=t}var kp={exec:()=>null};function Sp(t,e=""){let i="string"==typeof t?t:t.source;const n={replace:(t,e)=>{let s="string"==typeof e?e:e.source;return s=s.replace(Cp.caret,"$1"),i=i.replace(t,s),n},getRegex:()=>new RegExp(i,e)};return n}var Cp={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},Ap=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Mp=/(?:[*+-]|\d{1,9}[.)])/,Tp=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Dp=Sp(Tp).replace(/bull/g,Mp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Op=Sp(Tp).replace(/bull/g,Mp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Rp=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Ep=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Pp=Sp(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Ep).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Lp=Sp(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Mp).getRegex(),Bp="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Ip=/|$))/,Np=Sp("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",Ip).replace("tag",Bp).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),zp=Sp(Rp).replace("hr",Ap).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",Bp).getRegex(),qp={blockquote:Sp(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",zp).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:Pp,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:Ap,html:Np,lheading:Dp,list:Lp,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:zp,table:kp,text:/^[^\n]+/},Fp=Sp("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ap).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",Bp).getRegex(),Hp={...qp,lheading:Op,table:Fp,paragraph:Sp(Rp).replace("hr",Ap).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Fp).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|textarea|!--)").replace("tag",Bp).getRegex()},Vp={...qp,html:Sp("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",Ip).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:kp,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Sp(Rp).replace("hr",Ap).replace("heading"," *#{1,6} *[^\n]").replace("lheading",Dp).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Wp=/^( {2,}|\\)\n(?!\s*$)/,$p=/[\p{P}\p{S}]/u,_p=/[\s\p{P}\p{S}]/u,jp=/[^\s\p{P}\p{S}]/u,Kp=Sp(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,_p).getRegex(),Up=/(?!~)[\p{P}\p{S}]/u,Gp=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Yp=Sp(Gp,"u").replace(/punct/g,$p).getRegex(),Xp=Sp(Gp,"u").replace(/punct/g,Up).getRegex(),Jp="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Zp=Sp(Jp,"gu").replace(/notPunctSpace/g,jp).replace(/punctSpace/g,_p).replace(/punct/g,$p).getRegex(),Qp=Sp(Jp,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,Up).getRegex(),tm=Sp("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,jp).replace(/punctSpace/g,_p).replace(/punct/g,$p).getRegex(),em=Sp(/\\(punct)/,"gu").replace(/punct/g,$p).getRegex(),im=Sp(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),nm=Sp(Ip).replace("(?:--\x3e|$)","--\x3e").getRegex(),sm=Sp("^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^").replace("comment",nm).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),rm=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,om=Sp(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",rm).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),lm=Sp(/^!?\[(label)\]\[(ref)\]/).replace("label",rm).replace("ref",Ep).getRegex(),am=Sp(/^!?\[(ref)\](?:\[\])?/).replace("ref",Ep).getRegex(),hm={_backpedal:kp,anyPunctuation:em,autolink:im,blockSkip:/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,br:Wp,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:kp,emStrongLDelim:Yp,emStrongRDelimAst:Zp,emStrongRDelimUnd:tm,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:om,nolink:am,punctuation:Kp,reflink:lm,reflinkSearch:Sp("reflink|nolink(?!\\()","g").replace("reflink",lm).replace("nolink",am).getRegex(),tag:sm,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\":">",'"':""","'":"'"},gm=t=>mm[t];function vm(t,e){if(e){if(Cp.escapeTest.test(t))return t.replace(Cp.escapeReplace,gm)}else if(Cp.escapeTestNoEncode.test(t))return t.replace(Cp.escapeReplaceNoEncode,gm);return t}function wm(t){try{t=encodeURI(t).replace(Cp.percentDecode,"%")}catch{return null}return t}function bm(t,e){const i=t.replace(Cp.findPipe,(t,e,i)=>{let n=!1,s=e;for(;--s>=0&&"\\"===i[s];)n=!n;return n?"|":" |"}).split(Cp.splitPipe);let n=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),e)if(i.length>e)i.splice(e);else for(;i.length0)return{type:"space",raw:e[0]}}code(t){const e=this.rules.block.code.exec(t);if(e){const t=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?t:ym(t,"\n")}}}fences(t){const e=this.rules.block.fences.exec(t);if(e){const t=e[0],i=function(t,e,i){const n=t.match(i.other.indentCodeCompensation);if(null===n)return e;const s=n[1];return e.split("\n").map(t=>{const e=t.match(i.other.beginningSpace);if(null===e)return t;const[n]=e;return n.length>=s.length?t.slice(s.length):t}).join("\n")}(t,e[3]||"",this.rules);return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:i}}}heading(t){const e=this.rules.block.heading.exec(t);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){const e=ym(t,"#");this.options.pedantic?t=e.trim():e&&!this.rules.other.endingSpaceChar.test(e)||(t=e.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(t){const e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:ym(e[0],"\n")}}blockquote(t){const e=this.rules.block.blockquote.exec(t);if(e){let t=ym(e[0],"\n").split("\n"),i="",n="";const s=[];for(;t.length>0;){let e=!1;const r=[];let o;for(o=0;o1,s={type:"list",raw:"",ordered:n,start:n?+i.slice(0,-1):"",loose:!1,items:[]};i=n?`\\d{1,9}\\${i.slice(-1)}`:`\\${i}`,this.options.pedantic&&(i=n?i:"[*+-]");const r=this.rules.other.listItemRegex(i);let o=!1;for(;t;){let i=!1,n="",l="";if(!(e=r.exec(t)))break;if(this.rules.block.hr.test(t))break;n=e[0],t=t.substring(n.length);let a=e[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,t=>" ".repeat(3*t.length)),h=t.split("\n",1)[0],c=!a.trim(),u=0;if(this.options.pedantic?(u=2,l=a.trimStart()):c?u=e[1].length+1:(u=e[2].search(this.rules.other.nonSpaceChar),u=u>4?1:u,l=a.slice(u),u+=e[1].length),c&&this.rules.other.blankLine.test(h)&&(n+=h+"\n",t=t.substring(h.length+1),i=!0),!i){const e=this.rules.other.nextBulletRegex(u),i=this.rules.other.hrRegex(u),s=this.rules.other.fencesBeginRegex(u),r=this.rules.other.headingBeginRegex(u),o=this.rules.other.htmlBeginRegex(u);for(;t;){const f=t.split("\n",1)[0];let d;if(h=f,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),d=h):d=h.replace(this.rules.other.tabCharGlobal," "),s.test(h))break;if(r.test(h))break;if(o.test(h))break;if(e.test(h))break;if(i.test(h))break;if(d.search(this.rules.other.nonSpaceChar)>=u||!h.trim())l+="\n"+d.slice(u);else{if(c)break;if(a.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4)break;if(s.test(a))break;if(r.test(a))break;if(i.test(a))break;l+="\n"+h}c||h.trim()||(c=!0),n+=f+"\n",t=t.substring(f.length+1),a=d.slice(u)}}s.loose||(o?s.loose=!0:this.rules.other.doubleBlankLine.test(n)&&(o=!0));let f,d=null;this.options.gfm&&(d=this.rules.other.listIsTask.exec(l),d&&(f="[ ] "!==d[0],l=l.replace(this.rules.other.listReplaceTask,""))),s.items.push({type:"list_item",raw:n,task:!!d,checked:f,loose:!1,text:l,tokens:[]}),s.raw+=n}const l=s.items.at(-1);if(!l)return;l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd(),s.raw=s.raw.trimEnd();for(let t=0;t"space"===t.type),i=e.length>0&&e.some(t=>this.rules.other.anyLine.test(t.raw));s.loose=i}if(s.loose)for(let t=0;t({text:t,tokens:this.lexer.inline(t),header:!1,align:r.align[e]})));return r}}lheading(t){const e=this.rules.block.lheading.exec(t);if(e)return{type:"heading",raw:e[0],depth:"="===e[2].charAt(0)?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(t){const e=this.rules.block.paragraph.exec(t);if(e){const t="\n"===e[1].charAt(e[1].length-1)?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(t){const e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){const e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){const e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){const e=this.rules.inline.link.exec(t);if(e){const t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;const e=ym(t.slice(0,-1),"\\");if((t.length-e.length)%2==0)return}else{const t=function(t,e){if(-1===t.indexOf(e[1]))return-1;let i=0;for(let n=0;n0?-2:-1}(e[2],"()");if(-2===t)return;if(t>-1){const i=(0===e[0].indexOf("!")?5:4)+e[1].length+t;e[2]=e[2].substring(0,t),e[0]=e[0].substring(0,i).trim(),e[3]=""}}let i=e[2],n="";if(this.options.pedantic){const t=this.rules.other.pedanticHrefTitle.exec(i);t&&(i=t[1],n=t[3])}else n=e[3]?e[3].slice(1,-1):"";return i=i.trim(),this.rules.other.startAngleBracket.test(i)&&(i=this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?i.slice(1):i.slice(1,-1)),xm(e,{href:i?i.replace(this.rules.inline.anyPunctuation,"$1"):i,title:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n},e[0],this.lexer,this.rules)}}reflink(t,e){let i;if((i=this.rules.inline.reflink.exec(t))||(i=this.rules.inline.nolink.exec(t))){const t=e[(i[2]||i[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!t){const t=i[0].charAt(0);return{type:"text",raw:t,text:t}}return xm(i,t,i[0],this.lexer,this.rules)}}emStrong(t,e,i=""){let n=this.rules.inline.emStrongLDelim.exec(t);if(!n)return;if(n[3]&&i.match(this.rules.other.unicodeAlphaNumeric))return;if(!(n[1]||n[2]||"")||!i||this.rules.inline.punctuation.exec(i)){const i=[...n[0]].length-1;let s,r,o=i,l=0;const a="*"===n[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(a.lastIndex=0,e=e.slice(-1*t.length+i);null!=(n=a.exec(e));){if(s=n[1]||n[2]||n[3]||n[4]||n[5]||n[6],!s)continue;if(r=[...s].length,n[3]||n[4]){o+=r;continue}if((n[5]||n[6])&&i%3&&!((i+r)%3)){l+=r;continue}if(o-=r,o>0)continue;r=Math.min(r,r+o+l);const e=[...n[0]][0].length,a=t.slice(0,i+n.index+e+r);if(Math.min(i,r)%2){const t=a.slice(1,-1);return{type:"em",raw:a,text:t,tokens:this.lexer.inlineTokens(t)}}const h=a.slice(2,-2);return{type:"strong",raw:a,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(t){const e=this.rules.inline.code.exec(t);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," ");const i=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return i&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(t){const e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t){const e=this.rules.inline.del.exec(t);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(t){const e=this.rules.inline.autolink.exec(t);if(e){let t,i;return"@"===e[2]?(t=e[1],i="mailto:"+t):(t=e[1],i=t),{type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let t,i;if("@"===e[2])t=e[0],i="mailto:"+t;else{let n;do{n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??""}while(n!==e[0]);t=e[0],i="www."===e[1]?"http://"+e[0]:e[0]}return{type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(t){const e=this.rules.inline.text.exec(t);if(e){const t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},Sm=class t{tokens;options;state;tokenizer;inlineQueue;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||yp,this.options.tokenizer=this.options.tokenizer||new km,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const e={other:Cp,block:dm.normal,inline:pm.normal};this.options.pedantic?(e.block=dm.pedantic,e.inline=pm.pedantic):this.options.gfm&&(e.block=dm.gfm,this.options.breaks?e.inline=pm.breaks:e.inline=pm.gfm),this.tokenizer.rules=e}static get rules(){return{block:dm,inline:pm}}static lex(e,i){return new t(i).lex(e)}static lexInline(e,i){return new t(i).inlineTokens(e)}lex(t){t=t.replace(Cp.carriageReturn,"\n"),this.blockTokens(t,this.tokens);for(let t=0;t!!(n=i.call({lexer:this},t,e))&&(t=t.substring(n.raw.length),e.push(n),!0)))continue;if(n=this.tokenizer.space(t)){t=t.substring(n.raw.length);const i=e.at(-1);1===n.raw.length&&void 0!==i?i.raw+="\n":e.push(n);continue}if(n=this.tokenizer.code(t)){t=t.substring(n.raw.length);const i=e.at(-1);"paragraph"===i?.type||"text"===i?.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.text,this.inlineQueue.at(-1).src=i.text):e.push(n);continue}if(n=this.tokenizer.fences(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.heading(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.hr(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.blockquote(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.list(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.html(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.def(t)){t=t.substring(n.raw.length);const i=e.at(-1);"paragraph"===i?.type||"text"===i?.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.raw,this.inlineQueue.at(-1).src=i.text):this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title});continue}if(n=this.tokenizer.table(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.lheading(t)){t=t.substring(n.raw.length),e.push(n);continue}let s=t;if(this.options.extensions?.startBlock){let e=1/0;const i=t.slice(1);let n;this.options.extensions.startBlock.forEach(t=>{n=t.call({lexer:this},i),"number"==typeof n&&n>=0&&(e=Math.min(e,n))}),e<1/0&&e>=0&&(s=t.substring(0,e+1))}if(this.state.top&&(n=this.tokenizer.paragraph(s))){const r=e.at(-1);i&&"paragraph"===r?.type?(r.raw+="\n"+n.raw,r.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):e.push(n),i=s.length!==t.length,t=t.substring(n.raw.length);continue}if(n=this.tokenizer.text(t)){t=t.substring(n.raw.length);const i=e.at(-1);"text"===i?.type?(i.raw+="\n"+n.raw,i.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):e.push(n);continue}if(t){const e="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(e);break}throw new Error(e)}}return this.state.top=!0,e}inline(t,e=[]){return this.inlineQueue.push({src:t,tokens:e}),e}inlineTokens(t,e=[]){let i=t,n=null;if(this.tokens.links){const t=Object.keys(this.tokens.links);if(t.length>0)for(;null!=(n=this.tokenizer.rules.inline.reflinkSearch.exec(i));)t.includes(n[0].slice(n[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(n=this.tokenizer.rules.inline.anyPunctuation.exec(i));)i=i.slice(0,n.index)+"++"+i.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(n=this.tokenizer.rules.inline.blockSkip.exec(i));)i=i.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let s=!1,r="";for(;t;){let n;if(s||(r=""),s=!1,this.options.extensions?.inline?.some(i=>!!(n=i.call({lexer:this},t,e))&&(t=t.substring(n.raw.length),e.push(n),!0)))continue;if(n=this.tokenizer.escape(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.tag(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.link(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(n.raw.length);const i=e.at(-1);"text"===n.type&&"text"===i?.type?(i.raw+=n.raw,i.text+=n.text):e.push(n);continue}if(n=this.tokenizer.emStrong(t,i,r)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.codespan(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.br(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.del(t)){t=t.substring(n.raw.length),e.push(n);continue}if(n=this.tokenizer.autolink(t)){t=t.substring(n.raw.length),e.push(n);continue}if(!this.state.inLink&&(n=this.tokenizer.url(t))){t=t.substring(n.raw.length),e.push(n);continue}let o=t;if(this.options.extensions?.startInline){let e=1/0;const i=t.slice(1);let n;this.options.extensions.startInline.forEach(t=>{n=t.call({lexer:this},i),"number"==typeof n&&n>=0&&(e=Math.min(e,n))}),e<1/0&&e>=0&&(o=t.substring(0,e+1))}if(n=this.tokenizer.inlineText(o)){t=t.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(r=n.raw.slice(-1)),s=!0;const i=e.at(-1);"text"===i?.type?(i.raw+=n.raw,i.text+=n.text):e.push(n);continue}if(t){const e="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(e);break}throw new Error(e)}}return e}},Cm=class{options;parser;constructor(t){this.options=t||yp}space(t){return""}code({text:t,lang:e,escaped:i}){const n=(e||"").match(Cp.notSpaceStart)?.[0],s=t.replace(Cp.endingNewline,"")+"\n";return n?'
    '+(i?s:vm(s,!0))+"
    \n":"
    "+(i?s:vm(s,!0))+"
    \n"}blockquote({tokens:t}){return`
    \n${this.parser.parse(t)}
    \n`}html({text:t}){return t}heading({tokens:t,depth:e}){return`${this.parser.parseInline(t)}\n`}hr(t){return"
    \n"}list(t){const e=t.ordered,i=t.start;let n="";for(let e=0;e\n"+n+"\n"}listitem(t){let e="";if(t.task){const i=this.checkbox({checked:!!t.checked});t.loose?"paragraph"===t.tokens[0]?.type?(t.tokens[0].text=i+" "+t.tokens[0].text,t.tokens[0].tokens&&t.tokens[0].tokens.length>0&&"text"===t.tokens[0].tokens[0].type&&(t.tokens[0].tokens[0].text=i+" "+vm(t.tokens[0].tokens[0].text),t.tokens[0].tokens[0].escaped=!0)):t.tokens.unshift({type:"text",raw:i+" ",text:i+" ",escaped:!0}):e+=i+" "}return e+=this.parser.parse(t.tokens,!!t.loose),`
  • ${e}
  • \n`}checkbox({checked:t}){return"'}paragraph({tokens:t}){return`

    ${this.parser.parseInline(t)}

    \n`}table(t){let e="",i="";for(let e=0;e${n}`),"\n\n"+e+"\n"+n+"
    \n"}tablerow({text:t}){return`\n${t}\n`}tablecell(t){const e=this.parser.parseInline(t.tokens),i=t.header?"th":"td";return(t.align?`<${i} align="${t.align}">`:`<${i}>`)+e+`\n`}strong({tokens:t}){return`${this.parser.parseInline(t)}`}em({tokens:t}){return`${this.parser.parseInline(t)}`}codespan({text:t}){return`${vm(t,!0)}`}br(t){return"
    "}del({tokens:t}){return`${this.parser.parseInline(t)}`}link({href:t,title:e,tokens:i}){const n=this.parser.parseInline(i),s=wm(t);if(null===s)return n;let r='
    ",r}image({href:t,title:e,text:i,tokens:n}){n&&(i=this.parser.parseInline(n,this.parser.textRenderer));const s=wm(t);if(null===s)return vm(i);let r=`${i}{const s=t[n].flat(1/0);i=i.concat(this.walkTokens(s,e))}):t.tokens&&(i=i.concat(this.walkTokens(t.tokens,e)))}}return i}use(...t){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(t=>{const i={...t};if(i.async=this.defaults.async||i.async||!1,t.extensions&&(t.extensions.forEach(t=>{if(!t.name)throw new Error("extension name required");if("renderer"in t){const i=e.renderers[t.name];e.renderers[t.name]=i?function(...e){let n=t.renderer.apply(this,e);return!1===n&&(n=i.apply(this,e)),n}:t.renderer}if("tokenizer"in t){if(!t.level||"block"!==t.level&&"inline"!==t.level)throw new Error("extension level must be 'block' or 'inline'");const i=e[t.level];i?i.unshift(t.tokenizer):e[t.level]=[t.tokenizer],t.start&&("block"===t.level?e.startBlock?e.startBlock.push(t.start):e.startBlock=[t.start]:"inline"===t.level&&(e.startInline?e.startInline.push(t.start):e.startInline=[t.start]))}"childTokens"in t&&t.childTokens&&(e.childTokens[t.name]=t.childTokens)}),i.extensions=e),t.renderer){const e=this.defaults.renderer||new Cm(this.defaults);for(const i in t.renderer){if(!(i in e))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;const n=i,s=t.renderer[n],r=e[n];e[n]=(...t)=>{let i=s.apply(e,t);return!1===i&&(i=r.apply(e,t)),i||""}}i.renderer=e}if(t.tokenizer){const e=this.defaults.tokenizer||new km(this.defaults);for(const i in t.tokenizer){if(!(i in e))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;const n=i,s=t.tokenizer[n],r=e[n];e[n]=(...t)=>{let i=s.apply(e,t);return!1===i&&(i=r.apply(e,t)),i}}i.tokenizer=e}if(t.hooks){const e=this.defaults.hooks||new Tm;for(const i in t.hooks){if(!(i in e))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;const n=i,s=t.hooks[n],r=e[n];Tm.passThroughHooks.has(i)?e[n]=t=>{if(this.defaults.async)return Promise.resolve(s.call(e,t)).then(t=>r.call(e,t));const i=s.call(e,t);return r.call(e,i)}:e[n]=(...t)=>{let i=s.apply(e,t);return!1===i&&(i=r.apply(e,t)),i}}i.hooks=e}if(t.walkTokens){const e=this.defaults.walkTokens,n=t.walkTokens;i.walkTokens=function(t){let i=[];return i.push(n.call(this,t)),e&&(i=i.concat(e.call(this,t))),i}}this.defaults={...this.defaults,...i}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return Sm.lex(t,e??this.defaults)}parser(t,e){return Mm.parse(t,e??this.defaults)}parseMarkdown(t){return(e,i)=>{const n={...i},s={...this.defaults,...n},r=this.onError(!!s.silent,!!s.async);if(!0===this.defaults.async&&!1===n.async)return r(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(null==e)return r(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof e)return r(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));s.hooks&&(s.hooks.options=s,s.hooks.block=t);const o=s.hooks?s.hooks.provideLexer():t?Sm.lex:Sm.lexInline,l=s.hooks?s.hooks.provideParser():t?Mm.parse:Mm.parseInline;if(s.async)return Promise.resolve(s.hooks?s.hooks.preprocess(e):e).then(t=>o(t,s)).then(t=>s.hooks?s.hooks.processAllTokens(t):t).then(t=>s.walkTokens?Promise.all(this.walkTokens(t,s.walkTokens)).then(()=>t):t).then(t=>l(t,s)).then(t=>s.hooks?s.hooks.postprocess(t):t).catch(r);try{s.hooks&&(e=s.hooks.preprocess(e));let t=o(e,s);s.hooks&&(t=s.hooks.processAllTokens(t)),s.walkTokens&&this.walkTokens(t,s.walkTokens);let i=l(t,s);return s.hooks&&(i=s.hooks.postprocess(i)),i}catch(t){return r(t)}}}onError(t,e){return i=>{if(i.message+="\nPlease report this to https://github.com/markedjs/marked.",t){const t="

    An error occurred:

    "+vm(i.message+"",!0)+"
    ";return e?Promise.resolve(t):t}if(e)return Promise.reject(i);throw i}}},Om=new Dm;function Rm(t,e){return Om.parse(t,e)}Rm.options=Rm.setOptions=function(t){return Om.setOptions(t),Rm.defaults=Om.defaults,xp(Rm.defaults),Rm},Rm.getDefaults=bp,Rm.defaults=yp,Rm.use=function(...t){return Om.use(...t),Rm.defaults=Om.defaults,xp(Rm.defaults),Rm},Rm.walkTokens=function(t,e){return Om.walkTokens(t,e)},Rm.parseInline=Om.parseInline,Rm.Parser=Mm,Rm.parser=Mm.parse,Rm.Renderer=Cm,Rm.TextRenderer=Am,Rm.Lexer=Sm,Rm.lexer=Sm.lex,Rm.Tokenizer=km,Rm.Hooks=Tm,Rm.parse=Rm,Rm.options,Rm.setOptions,Rm.use,Rm.walkTokens,Rm.parseInline,Mm.parse,Sm.lex;let Em=null;const Pm=new Dm({walkTokens(t){if(!Em||"code"!=t.type)return;let e=Em.language&&Em.language(t.lang);if(!e){let i=Em.view.state.facet(ic);i&&i.name==t.lang&&(e=i)}if(!e)return;let i={style:t=>$c(Em.view.state,t)},n="";Ch(t.text,e.parser.parse(t.text),i,(t,e)=>{n+=e?`${Lm(t)}`:Lm(t)},()=>{n+="
    "}),t.escaped=!0,t.text=n}});function Lm(t){return t.replace(/[\n<&]/g,t=>"\n"==t?"
    ":"<"==t?"<":"&")}function Bm(t,e){let i=t.lineAt(e);return{line:i.number-1,character:e-i.from}}function Im(t,e){return t.line(e.line+1).from+e.character}class Nm{constructor(t,{client:e,uri:i,languageID:n}){if(this.view=t,this.client=e,this.uri=i,!n){let e=t.state.facet(ic);n=e?e.name:""}e.workspace.openFile(i,n,t),this.syncedDoc=t.state.doc,this.unsyncedChanges=O.empty(t.state.doc.length)}docToHTML(t,e="plaintext"){let i=function(t,e,i){let n=Em;try{return Em={view:t,language:e},i()}finally{Em=n}}(this.view,this.client.config.highlightLanguage,()=>function(t,e){let i=e,n=t;return"string"!=typeof n&&(i=n.kind,n=n.value),"plaintext"==i?Lm(n):Pm.parse(n,{async:!1})}(t,e));return this.client.config.sanitizeHTML?this.client.config.sanitizeHTML(i):i}toPosition(t,e=this.view.state.doc){return Bm(e,t)}fromPosition(t,e=this.view.state.doc){return Im(e,t)}reportError(t,e){Ao(this.view,{label:this.view.state.phrase(t)+": "+(e.message||e),class:"cm-lsp-message cm-lsp-message-error",top:!0})}clear(){this.syncedDoc=this.view.state.doc,this.unsyncedChanges=O.empty(this.view.state.doc.length)}update(t){t.docChanged&&(this.unsyncedChanges=this.unsyncedChanges.compose(t.changes))}destroy(){this.client.workspace.closeFile(this.uri,this.view)}static get(t){return t.plugin(zm)}static create(t,e,i){return t.plugin(e,i)}}const zm=ln.fromClass(Nm);class qm{constructor(t){this.client=t}getFile(t){return this.files.find(e=>e.uri==t)||null}requestFile(t){return Promise.resolve(this.getFile(t))}connected(){for(let t of this.files)this.client.didOpen(t)}disconnected(){}updateFile(t,e){var i;let n=this.getFile(t);n&&(null===(i=n.getView())||void 0===i||i.dispatch(e))}displayFile(t){let e=this.getFile(t);return Promise.resolve(e?e.getView():null)}}class Fm{constructor(t,e,i,n,s){this.uri=t,this.languageId=e,this.version=i,this.doc=n,this.view=s}getView(){return this.view}}class Hm extends qm{constructor(){super(...arguments),this.files=[],this.fileVersions=Object.create(null)}nextFileVersion(t){var e;return this.fileVersions[t]=(null!==(e=this.fileVersions[t])&&void 0!==e?e:-1)+1}syncFiles(){let t=[];for(let e of this.files){let i=Nm.get(e.view);if(!i)continue;let n=i.unsyncedChanges;n.empty||(t.push({changes:n,file:e,prevDoc:e.doc}),e.doc=e.view.state.doc,e.version=this.nextFileVersion(e.uri),i.clear())}return t}openFile(t,e,i){if(this.getFile(t))throw new Error("Default workspace implementation doesn't support multiple views on the same file");let n=new Fm(t,e,this.nextFileVersion(t),i.state.doc,i);this.files.push(n),this.client.didOpen(n)}closeFile(t){let e=this.getFile(t);e&&(this.files=this.files.filter(t=>t!=e),this.client.didClose(t))}}const Vm=lr.baseTheme({".cm-lsp-documentation":{padding:"0 7px","& p, & pre":{margin:"2px 0"}},".cm-lsp-signature-tooltip":{padding:"2px 6px",borderRadius:"2.5px",position:"relative",maxWidth:"30em",maxHeight:"10em",overflowY:"scroll","& .cm-lsp-documentation":{padding:"0",fontSize:"80%"},"& .cm-lsp-signature-num":{fontFamily:"monospace",position:"absolute",left:"2px",top:"4px",fontSize:"70%",lineHeight:"1.3"},"& .cm-lsp-signature":{fontFamily:"monospace",textIndent:"1em hanging"},"& .cm-lsp-active-parameter":{fontWeight:"bold"}},".cm-lsp-signature-multiple":{paddingLeft:"1.5em"},".cm-panel.cm-lsp-rename-panel":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}},".cm-lsp-message button[type=submit]":{display:"block"},".cm-lsp-reference-panel":{fontFamily:"monospace",whiteSpace:"pre",padding:"3px 6px",maxHeight:"120px",overflow:"auto","& .cm-lsp-reference-file":{fontWeight:"bold"},"& .cm-lsp-reference":{cursor:"pointer","&[aria-selected]":{backgroundColor:"#0077ee44"}},"& .cm-lsp-reference-line":{opacity:"0.7"}}});class Wm{constructor(t,e,i){this.id=t,this.params=e,this.timeout=i,this.promise=new Promise((t,e)=>{this.resolve=t,this.reject=e})}}const $m={general:{markdown:{parser:"marked"}},textDocument:{completion:{completionItem:{snippetSupport:!0,documentationFormat:["plaintext","markdown"],insertReplaceSupport:!1},completionList:{itemDefaults:["commitCharacters","editRange","insertTextFormat"]},completionItemKind:{valueSet:[]},contextSupport:!0},hover:{contentFormat:["markdown","plaintext"]},formatting:{},rename:{},signatureHelp:{contextSupport:!0,signatureInformation:{documentationFormat:["markdown","plaintext"],parameterInformation:{labelOffsetSupport:!0},activeParameterSupport:!0}},definition:{},declaration:{},implementation:{},typeDefinition:{},references:{},diagnostic:{}},window:{showMessage:{}}};class _m{constructor(t){this.client=t,this.mappings=new Map,this.startDocs=new Map;for(let e of t.workspace.files)this.mappings.set(e.uri,O.empty(e.doc.length)),this.startDocs.set(e.uri,e.doc)}addChanges(t,e){let i=this.mappings.get(t);i&&this.mappings.set(t,i.composeDesc(e))}getMapping(t){let e=this.mappings.get(t);if(!e)return null;let i=this.client.workspace.getFile(t),n=null==i?void 0:i.getView(),s=n&&Nm.get(n);return s?e.composeDesc(s.unsyncedChanges):e}mapPos(t,e,i=-1,n=T.Simple){let s=this.getMapping(t);return s?s.mapPos(e,i,n):e}mapPosition(t,e,i=-1,n=T.Simple){let s=this.startDocs.get(t);if(!s)throw new Error("Cannot map from a file that's not in the workspace");let r=Im(s,e),o=this.getMapping(t);return o?o.mapPos(r,i,n):r}destroy(){this.client.activeMappings=this.client.activeMappings.filter(t=>t!=this)}}const jm={"window/logMessage":(t,e)=>{1==e.type?console.error("[lsp] "+e.message):2==e.type&&console.warn("[lsp] "+e.message)},"window/showMessage":(t,e)=>{if(e.type>3)return;let i;for(let e of t.workspace.files)if(i=e.getView())break;i&&Ao(i,{label:e.message,class:"cm-lsp-message cm-lsp-message-"+(1==e.type?"error":2==e.type?"warning":"info"),top:!0})}};function Km(t,e,i,n){if(!n||t.doc.length<1024)return[{text:t.doc.toString()}];let s=[];return i.iterChanges((t,i,n,r,o)=>{s.push({range:{start:Bm(e,t),end:Bm(e,i)},text:o.toString()})}),s.reverse()}function Um(t,e){if(null==e)return t;if("object"!=typeof t||"object"!=typeof e)return e;let i={},n=Object.keys(t),s=Object.keys(e);for(let r of n)i[r]=s.indexOf(r)>-1?Um(t[r],e[r]):t[r];for(let t of s)n.indexOf(t)<0&&(i[t]=e[t]);return i}function Gm(t={}){if(t.override)return gp({override:[Xm]});{let t=[{autocomplete:Xm}];return[gp(),Dt.languageData.of(()=>t)]}}function Ym(t){var e;let i=Math.ceil(t.length/50),n=[];for(let s=0;st.replace(/[^\w\s]/g,"\\$&"))).join("|")+")?\\w*$"):/^\w*$/}const Xm=t=>{var e,i;const n=t.view&&Nm.get(t.view);if(!n)return null;let s="";if(!t.explicit){s=t.view.state.sliceDoc(t.pos-1,t.pos);let r=null===(i=null===(e=n.client.serverCapabilities)||void 0===e?void 0:e.completionProvider)||void 0===i?void 0:i.triggerCharacters;if(!(/[a-zA-Z_]/.test(s)||r&&r.indexOf(s)>-1))return null}return function(t,e,i,n){if(!1===t.client.hasCapability("completionProvider"))return Promise.resolve(null);t.client.sync();let s={position:t.toPosition(e),textDocument:{uri:t.uri},context:i};return n&&n.addEventListener("abort",()=>t.client.cancelRequest(s)),t.client.request("textDocument/completion",s)}(n,t.pos,{triggerCharacter:s,triggerKind:t.explicit?1:2},t).then(e=>{var i;if(!e)return null;Array.isArray(e)&&(e={items:e});let{from:s,to:r}=function(t,e){var i;if(!e.items.length)return{from:t.pos,to:t.pos};let n=null===(i=e.itemDefaults)||void 0===i?void 0:i.editRange,s=e.items[0],r=n?"insert"in n?n.insert:n:s.textEdit?"range"in s.textEdit?s.textEdit.range:s.textEdit.insert:null;if(!r)return t.state.wordAt(t.pos)||{from:t.pos,to:t.pos};let o=t.state.doc.lineAt(t.pos);return{from:o.from+r.start.character,to:o.from+r.end.character}}(t,e),o=null===(i=e.itemDefaults)||void 0===i?void 0:i.commitCharacters;return{from:s,to:r,options:e.items.map(t=>{var e;let i=(null===(e=t.textEdit)||void 0===e?void 0:e.newText)||t.textEditText||t.insertText||t.label,s={label:i,type:t.kind&&Jm[t.kind]};return t.commitCharacters&&t.commitCharacters!=o&&(s.commitCharacters=t.commitCharacters),t.detail&&(s.detail=t.detail),2==t.insertTextFormat&&(s.apply=(t,e,n,s)=>function(t){let e=Hd.parse(t);return(t,i,n,s)=>{let{text:r,ranges:o}=e.instantiate(t.state,n),{main:l}=t.state.selection,a={changes:{from:n,to:s==l.from?l.to:s,insert:f.of(r)},scrollIntoView:!0,annotations:i?[id.of(i),vt.userEvent.of("input.complete")]:void 0};if(o.length&&(a.selection=Ud(o,0)),o.some(t=>t.field>0)){let e=new $d(o,0),i=a.effects=[_d.of(e)];void 0===t.state.field(Kd,!1)&&i.push(gt.appendConfig.of([Kd,Jd,Zd,zd]))}t.dispatch(t.state.update(a))}}(i)(t,e,n,s),s.label=t.label),t.documentation&&(s.info=()=>function(t,e){let i=document.createElement("div");return i.className="cm-lsp-documentation cm-lsp-completion-documentation",i.innerHTML=t.docToHTML(e),i}(n,t.documentation)),s}),commitCharacters:o,validFor:Ym(e.items),map:(t,e)=>({...t,from:e.mapPos(t.from)})}},t=>{if("code"in t&&-32800==t.code)return null;throw t})};const Jm={1:"text",2:"method",3:"function",4:"class",5:"property",6:"variable",7:"class",8:"interface",9:"namespace",10:"property",11:"keyword",12:"constant",13:"constant",14:"keyword",16:"constant",20:"constant",21:"constant",22:"class",25:"type"};function Zm(t={}){return go(Qm,{hideOn:t=>t.docChanged,hoverTime:t.hoverTime})}function Qm(t,e){const i=Nm.get(t);return i?function(t,e){return!1===t.client.hasCapability("hoverProvider")?Promise.resolve(null):(t.client.sync(),t.client.request("textDocument/hover",{position:t.toPosition(e),textDocument:{uri:t.uri}}))}(i,e).then(n=>n?{pos:n.range?Im(t.state.doc,n.range.start):e,end:n.range?Im(t.state.doc,n.range.end):e,create(){let t=document.createElement("div");return t.className="cm-lsp-hover-tooltip cm-lsp-documentation",t.innerHTML=function(t,e){return Array.isArray(e)?e.map(e=>tg(t,e)).join("
    "):"string"==typeof e||"object"==typeof e&&"language"in e?tg(t,e):t.docToHTML(e)}(i,n.contents),{dom:t}},above:!0}:null):Promise.resolve(null)}function tg(t,e){if("string"==typeof e)return t.docToHTML(e,"markdown");let{language:i,value:n}=e,s=t.client.config.highlightLanguage&&t.client.config.highlightLanguage(i||"");if(!s){let e=t.view.state.facet(ic);!e||i&&e.name!=i||(s=e)}if(!s)return Lm(n);let r="";return Ch(n,s.parser.parse(n),{style:e=>$c(t.view.state,e)},(t,e)=>{r+=e?`${Lm(t)}`:Lm(t)},()=>{r+="
    "}),r}const eg=t=>{const e=Nm.get(t);return!!e&&(e.client.sync(),e.client.withMapping(i=>function(t,e){return t.client.request("textDocument/formatting",{options:e,textDocument:{uri:t.uri}})}(e,{tabSize:rc(t.state),insertSpaces:t.state.facet(sc).indexOf("\t")<0}).then(n=>{if(!n)return;let s=i.getMapping(e.uri),r=[];for(let t of n){let n=i.mapPosition(e.uri,t.range.start),o=i.mapPosition(e.uri,t.range.end);if(s){if(s.touchesRange(n,o))return;n=s.mapPos(n,1),o=s.mapPos(o,-1)}r.push({from:n,to:o,insert:t.newText})}t.dispatch({changes:r,userEvent:"format"})},t=>{e.reportError("Formatting request failed",t)})),!0)},ig=[{key:"Shift-Alt-f",run:eg,preventDefault:!0}];const ng=[{key:"F2",run:t=>{let e=t.state.wordAt(t.state.selection.main.head),i=Nm.get(t);if(!e||!i||!1===i.client.hasCapability("renameProvider"))return!1;const n=t.state.sliceDoc(e.from,e.to);let s=function(t,e){let i=t.state.field(Mo,!1)||[];for(let n of i){let i=yo(t,n);if(i&&i.dom.classList.contains(e))return i}return null}(t,"cm-lsp-rename-panel");if(s){let t=s.dom.querySelector("[name=name]");t.value=n,t.select()}else{let{close:e,result:i}=Ao(t,{label:t.state.phrase("New name"),input:{name:"name",value:n},focus:!0,submitLabel:t.state.phrase("rename"),class:"cm-lsp-rename-panel"});i.then(i=>{t.dispatch({effects:e}),i&&function(t,e){const i=Nm.get(t),n=t.state.wordAt(t.state.selection.main.head);if(!i||!n)return!1;i.client.sync(),i.client.withMapping(t=>function(t,e,i){return t.client.request("textDocument/rename",{newName:i,position:t.toPosition(e),textDocument:{uri:t.uri}})}(i,n.from,e).then(e=>{if(e)for(let n in e.changes){let s=e.changes[n],r=i.client.workspace.getFile(n);s.length&&r&&i.client.workspace.updateFile(n,{changes:s.map(e=>({from:t.mapPosition(n,e.range.start),to:t.mapPosition(n,e.range.end),insert:e.newText})),userEvent:"rename"})}},t=>{i.reportError("Rename request failed",t)}))}(t,i.elements.namedItem("name").value)})}return!0},preventDefault:!0}];const sg=ln.fromClass(class{constructor(){this.activeRequest=null,this.delayedRequest=0}update(t){var e;this.activeRequest&&(t.selectionSet?(this.activeRequest.drop=!0,this.activeRequest=null):t.docChanged&&(this.activeRequest.pos=t.changes.mapPos(this.activeRequest.pos)));const i=Nm.get(t.view);if(!i)return;const n=t.view.state.field(og);let s="";if(t.docChanged&&t.transactions.some(t=>t.isUserEvent("input.type"))){const r=null===(e=i.client.serverCapabilities)||void 0===e?void 0:e.signatureHelpProvider,o=((null==r?void 0:r.triggerCharacters)||[]).concat(n&&(null==r?void 0:r.retriggerCharacters)||[]);o&&t.changes.iterChanges((t,e,i,n,r)=>{let l=r.toString();if(l)for(let t of o)l.indexOf(t)>-1&&(s=t)})}s?this.startRequest(i,{triggerKind:2,isRetrigger:!!n,triggerCharacter:s,activeSignatureHelp:n?n.data:void 0}):n&&t.selectionSet&&(this.delayedRequest&&clearTimeout(this.delayedRequest),this.delayedRequest=setTimeout(()=>{this.startRequest(i,{triggerKind:3,isRetrigger:!0,activeSignatureHelp:n.data})},250))}startRequest(t,e){this.delayedRequest&&clearTimeout(this.delayedRequest);let{view:i}=t,n=i.state.selection.main.head;this.activeRequest&&(this.activeRequest.drop=!0);let s=this.activeRequest={pos:n,drop:!1};(function(t,e,i){return!1===t.client.hasCapability("signatureHelpProvider")?Promise.resolve(null):(t.client.sync(),t.client.request("textDocument/signatureHelp",{context:i,position:t.toPosition(e),textDocument:{uri:t.uri}}))})(t,n,e).then(t=>{var n,r,o;if(!s.drop)if(t&&t.signatures.length){let l=i.state.field(og),a=l&&(r=l.data,o=t,r.signatures.length==o.signatures.length&&r.signatures.every((t,e)=>t.label==o.signatures[e].label)),h=a&&3==e.triggerKind?l.active:null!==(n=t.activeSignature)&&void 0!==n?n:0;if(a&&function(t,e,i){var n,s;return(null!==(n=t.signatures[i].activeParameter)&&void 0!==n?n:t.activeParameter)==(null!==(s=e.signatures[i].activeParameter)&&void 0!==s?s:e.activeParameter)}(l.data,t,h))return;i.dispatch({effects:lg.of({data:t,active:h,pos:a?l.tooltip.pos:s.pos})})}else i.state.field(og)&&i.dispatch({effects:lg.of(null)})},1==e.triggerKind?e=>t.reportError("Signature request failed",e):void 0)}destroy(){this.delayedRequest&&clearTimeout(this.delayedRequest),this.activeRequest&&(this.activeRequest.drop=!0)}});class rg{constructor(t,e,i){this.data=t,this.active=e,this.tooltip=i}}const og=U.define({create:()=>null,update(t,e){for(let t of e.effects)if(t.is(lg))return t.value?new rg(t.value.data,t.value.active,ag(t.value.data,t.value.active,t.value.pos)):null;return t&&e.docChanged?new rg(t.data,t.active,{...t.tooltip,pos:e.changes.mapPos(t.tooltip.pos)}):t},provide:t=>ho.from(t,t=>t&&t.tooltip)}),lg=gt.define();function ag(t,e,i){return{pos:i,above:!0,create:i=>function(t,e,i){var n;let s=document.createElement("div");if(s.className="cm-lsp-signature-tooltip",e.signatures.length>1){s.classList.add("cm-lsp-signature-multiple");let t=s.appendChild(document.createElement("div"));t.className="cm-lsp-signature-num",t.textContent=`${i+1}/${e.signatures.length}`}let r=e.signatures[i],o=s.appendChild(document.createElement("div"));o.className="cm-lsp-signature";let l=0,a=0,h=null!==(n=r.activeParameter)&&void 0!==n?n:e.activeParameter,c=null!=h&&r.parameters?r.parameters[h]:null;if(c&&Array.isArray(c.label))[l,a]=c.label;else if(c){let t=r.label.indexOf(c.label);t>-1&&(l=t,a=t+c.label.length)}if(a){o.appendChild(document.createTextNode(r.label.slice(0,l)));let t=o.appendChild(document.createElement("span"));t.className="cm-lsp-active-parameter",t.textContent=r.label.slice(l,a),o.appendChild(document.createTextNode(r.label.slice(a)))}else o.textContent=r.label;if(r.documentation){let e=Nm.get(t);if(e){let t=s.appendChild(document.createElement("div"));t.className="cm-lsp-signature-documentation cm-lsp-documentation",t.innerHTML=e.docToHTML(r.documentation)}}return{dom:s}}(i,t,e)}}const hg=[{key:"Mod-Shift-Space",run:t=>{let e=t.plugin(sg);e||(t.dispatch({effects:gt.appendConfig.of([og,sg])}),e=t.plugin(sg));let i=t.state.field(og);if(!e||void 0===i)return!1;let n=Nm.get(t);return!!n&&(e.startRequest(n,{triggerKind:1,activeSignatureHelp:i?i.data:void 0,isRetrigger:!!i}),!0)}},{key:"Mod-Shift-ArrowUp",run:t=>{let e=t.state.field(og);return!!e&&(e.active>0&&t.dispatch({effects:lg.of({data:e.data,active:e.active-1,pos:e.tooltip.pos})}),!0)}},{key:"Mod-Shift-ArrowDown",run:t=>{let e=t.state.field(og);return!!e&&(e.activefunction(t,e){const i=Nm.get(t);return!(!i||!1===i.client.hasCapability(e.capability)||(i.client.sync(),i.client.withMapping(n=>e.get(i,t.state.selection.main.head).then(e=>{if(!e)return;let s=Array.isArray(e)?e[0]:e;return(s.uri==i.uri?Promise.resolve(t):i.client.workspace.displayFile(s.uri)).then(t=>{if(!t)return;let e=n.getMapping(s.uri)?n.mapPosition(s.uri,s.range.start):i.fromPosition(s.range.start,t.state.doc);t.dispatch({selection:{anchor:e},scrollIntoView:!0,userEvent:"select.definition"})})},t=>i.reportError("Find definition failed",t))),0))}(t,{get:ug,capability:"definitionProvider"}),preventDefault:!0}];const dg=t=>!!t.state.field(pg,!1)&&(t.dispatch({effects:mg.of(null)}),!0),pg=U.define({create:()=>null,update(t,e){for(let t of e.effects)if(t.is(mg))return t.value;return t},provide:t=>Co.from(t)}),mg=gt.define();const gg=[{key:"Shift-F12",run:t=>{const e=Nm.get(t);if(!e||!1===e.client.hasCapability("referencesProvider"))return!1;e.client.sync();let i=e.client.workspaceMapping(),n=!1;return function(t,e){return t.client.request("textDocument/references",{textDocument:{uri:t.uri},position:t.toPosition(e),context:{includeDeclaration:!0}})}(e,t.state.selection.main.head).then(t=>{if(t)return Promise.all(t.map(t=>e.client.workspace.requestFile(t.uri).then(e=>e?{file:e,range:t.range}:null))).then(t=>{let s=t.filter(t=>t);s.length&&(!function(t,e,i){let n=function(t,e){let i=!1;return setTimeout(()=>{i||e.destroy()},500),n=>{i=!0;let s=function(t){let e=t[0],i=e.length;for(let n=1;nt.file.uri)),r=document.createElement("div"),o=null;r.className="cm-lsp-reference-panel",r.tabIndex=0,r.role="listbox",r.setAttribute("aria-label",n.state.phrase("Reference list"));let l=[];for(let{file:i,range:n}of t){let t=i.uri.slice(s);if(t!=o){o=t;let e=r.appendChild(document.createElement("div"));e.className="cm-lsp-reference-file",e.textContent=t}let a=r.appendChild(document.createElement("div"));a.className="cm-lsp-reference",a.role="option";let h=e.mapPosition(i.uri,n.start,1),c=e.mapPosition(i.uri,n.end,-1),u=i.getView(),f=(u?u.state.doc:i.doc).lineAt(h),d=a.appendChild(document.createElement("span"));d.className="cm-lsp-reference-line",d.textContent=(f.number+": ").padStart(5," ");let p=f.text.slice(Math.max(0,h-f.from-50),h-f.from);p&&a.appendChild(document.createTextNode(p)),a.appendChild(document.createElement("strong")).textContent=f.text.slice(h-f.from,c-f.from);let m=f.text.slice(c-f.from,Math.min(f.length,100-p.length));m&&a.appendChild(document.createTextNode(m)),l.length||a.setAttribute("aria-selected","true"),l.push(a)}function a(){for(let t=0;t{if(!t)return;let i=e.mapPosition(s.uri,r.start,1);t.focus(),t.dispatch({selection:{anchor:i},scrollIntoView:!0})})}r.addEventListener("keydown",e=>{if(27==e.keyCode)dg(n),n.focus();else if(38==e.keyCode||33==e.keyCode)h((a()-1+t.length)%t.length);else if(40==e.keyCode||34==e.keyCode)h((a()+1)%t.length);else if(36==e.keyCode)h(0);else if(35==e.keyCode)h(l.length-1);else{if(13!=e.keyCode&&10!=e.keyCode)return;c(a())}e.preventDefault()}),r.addEventListener("click",t=>{for(let e=0;edg(n)),f.setAttribute("aria-label",n.state.phrase("close")),{dom:u,destroy:()=>e.destroy(),mount:()=>r.focus()}}}(e,i),s=void 0===t.state.field(pg,!1)?gt.appendConfig.of(pg.init(()=>n)):mg.of(n);t.dispatch({effects:s})}(e.view,s,i),n=!0)})},t=>e.reportError("Finding references failed",t)).finally(()=>{n||i.destroy()}),!0},preventDefault:!0},{key:"Escape",run:dg}];const vg=ln.fromClass(class{constructor(){this.pending=-1}update(t){t.docChanged&&(this.pending>-1&&clearTimeout(this.pending),this.pending=setTimeout(()=>{this.pending=-1;let e=Nm.get(t.view);e&&e.client.sync()},500))}destroy(){this.pending>-1&&clearTimeout(this.pending)}});var wg=function(){function t(t){return{type:t,style:"keyword"}}for(var e=t("operator"),i={type:"atom",style:"atom"},n={type:"axis_specifier",style:"qualifier"},s={",":{type:"punctuation",style:null}},r=["after","all","allowing","ancestor","ancestor-or-self","any","array","as","ascending","at","attribute","base-uri","before","boundary-space","by","case","cast","castable","catch","child","collation","comment","construction","contains","content","context","copy","copy-namespaces","count","decimal-format","declare","default","delete","descendant","descendant-or-self","descending","diacritics","different","distance","document","document-node","element","else","empty","empty-sequence","encoding","end","entire","every","exactly","except","external","first","following","following-sibling","for","from","ftand","ftnot","ft-option","ftor","function","fuzzy","greatest","group","if","import","in","inherit","insensitive","insert","instance","intersect","into","invoke","is","item","language","last","lax","least","let","levels","lowercase","map","modify","module","most","namespace","next","no","node","nodes","no-inherit","no-preserve","not","occurs","of","only","option","order","ordered","ordering","paragraph","paragraphs","parent","phrase","preceding","preceding-sibling","preserve","previous","processing-instruction","relationship","rename","replace","return","revalidation","same","satisfies","schema","schema-attribute","schema-element","score","self","sensitive","sentence","sentences","sequence","skip","sliding","some","stable","start","stemming","stop","strict","strip","switch","text","then","thesaurus","times","to","transform","treat","try","tumbling","type","typeswitch","union","unordered","update","updating","uppercase","using","validate","value","variable","version","weight","when","where","wildcards","window","with","without","word","words","xquery"],o=0,l=r.length;o",">=","<","<=",".","|","?","and","or","div","idiv","mod","*","/","+","-"];for(o=0,l=h.length;o\"\'\/?]/);)l+=o;return bg(t,e,function(t,e){return function(i,n){return i.eatSpace(),e&&i.eat(">")?(Pg(n),n.tokenize=yg,"tag"):(i.eat("/")||Eg(n,{type:"tag",name:t,tokenize:yg}),i.eat(">")?(n.tokenize=yg,"tag"):(n.tokenize=Cg,"tag"))}}(l,r))}if("{"==i)return Eg(e,{type:"codeblock"}),null;if("}"==i)return Pg(e),null;if(Dg(e))return">"==i?"tag":"/"==i&&t.eat(">")?(Pg(e),"tag"):"variable";if(/\d/.test(i))return t.match(/^\d*(?:\.\d*)?(?:E[+\-]?\d+)?/),"atom";if("("===i&&t.eat(":"))return Eg(e,{type:"comment"}),bg(t,e,xg);if(s||'"'!==i&&"'"!==i){if("$"===i)return bg(t,e,Sg);if(":"===i&&t.eat("="))return"keyword";if("("===i)return Eg(e,{type:"paren"}),null;if(")"===i)return Pg(e),null;if("["===i)return Eg(e,{type:"bracket"}),null;if("]"===i)return Pg(e),null;var a=wg.propertyIsEnumerable(i)&&wg[i];if(s&&'"'===i)for(;'"'!==t.next(););if(s&&"'"===i)for(;"'"!==t.next(););a||t.eatWhile(/[\w\$_-]/);var h=t.eat(":");!t.eat(":")&&h&&t.eatWhile(/[\w\$_-]/),t.match(/^[ \t]*\(/,!1)&&(n=!0);var c=t.current();return a=wg.propertyIsEnumerable(c)&&wg[c],n&&!a&&(a={type:"function_call",style:"def"}),function(t){return Rg(t,"xmlconstructor")}(e)?(Pg(e),"variable"):("element"!=c&&"attribute"!=c&&"axis_specifier"!=a.type||Eg(e,{type:"xmlconstructor"}),a?a.style:"variable")}return kg(t,e,i)}function xg(t,e){for(var i,n=!1,s=!1,r=0;i=t.next();){if(")"==i&&n){if(!(r>0)){Pg(e);break}r--}else":"==i&&s&&r++;n=":"==i,s="("==i}return"comment"}function kg(t,e,i,n){let s=function(t,e){return function(i,n){for(var s;s=i.next();){if(s==t){Pg(n),e&&(n.tokenize=e);break}if(i.match("{",!1)&&Og(n))return Eg(n,{type:"codeblock"}),n.tokenize=yg,"string"}return"string"}}(i,n);return Eg(e,{type:"string",name:i,tokenize:s}),bg(t,e,s)}function Sg(t,e){var i=/[\w\$_-]/;if(t.eat('"')){for(;'"'!==t.next(););t.eat(":")}else t.eatWhile(i),t.match(":=",!1)||t.eat(":");return t.eatWhile(i),e.tokenize=yg,"variable"}function Cg(t,e){var i=t.next();return"/"==i&&t.eat(">")?(Og(e)&&Pg(e),Dg(e)&&Pg(e),"tag"):">"==i?(Og(e)&&Pg(e),"tag"):"="==i?null:'"'==i||"'"==i?kg(t,e,i,Cg):(Og(e)||Eg(e,{type:"attribute",tokenize:Cg}),t.eat(/[a-zA-Z_:]/),t.eatWhile(/[-a-zA-Z0-9_:.]/),t.eatSpace(),(t.match(">",!1)||t.match("/",!1))&&(Pg(e),e.tokenize=yg),"attribute")}function Ag(t,e){for(var i;i=t.next();)if("-"==i&&t.match("->",!0))return e.tokenize=yg,"comment"}function Mg(t,e){for(var i;i=t.next();)if("]"==i&&t.match("]",!0))return e.tokenize=yg,"comment"}function Tg(t,e){for(var i;i=t.next();)if("?"==i&&t.match(">",!0))return e.tokenize=yg,"processingInstruction"}function Dg(t){return Rg(t,"tag")}function Og(t){return Rg(t,"attribute")}function Rg(t,e){return t.stack.length&&t.stack[t.stack.length-1].type==e}function Eg(t,e){t.stack.push(e)}function Pg(t){t.stack.pop();var e=t.stack.length&&t.stack[t.stack.length-1].tokenize;t.tokenize=e||yg}const Lg={name:"xquery",startState:function(){return{tokenize:yg,cc:[],stack:[]}},token:function(t,e){return t.eatSpace()?null:e.tokenize(t,e)},languageData:{commentTokens:{block:{open:"(:",close:":)"}}}};const Bg=[function(t={}){return[jo.of(t),No(),Go]}(),Jo,function(t={}){return[$r.of(t),_r||(_r=ln.fromClass(class{constructor(t){this.view=t,this.decorations=ci.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet($r)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new qr({regexp:t.specialChars,decoration:(e,i,n)=>{let{doc:s}=i.state,r=S(e[0],0);if(9==r){let t=s.lineAt(n),e=i.state.tabSize,r=Kt(t.text,e,n-t.from);return ci.replace({widget:new Kr((e-r%e)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=ci.replace({widget:new jr(t,r)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet($r);t.startState.facet($r)!=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}))]}(),function(t={}){return[zu,Nu.of(t),lr.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?Fu:"historyRedo"==t.inputType?Hu:null;return!!i&&(t.preventDefault(),i(e))}})]}(),function(t={}){let e={...Nc,...t},i=new zc(e,!0),n=new zc(e,!1),s=ln.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(ic)!=t.state.facet(ic)||t.startState.field(Sc,!1)!=t.state.field(Sc,!1)||Uh(t.startState)!=Uh(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new It;for(let s of t.viewportLineBlocks){let r=Ac(t.state,s.from,s.to)?n:wc(t.state,s.from,s.to)?i:null;r&&e.add(s.from,s.from,r)}return e.finish()}}),{domEventHandlers:r}=e;return[s,Bo({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.markers)||Bt.empty},initialSpacer:()=>new zc(e,!1),domEventHandlers:{...r,click:(t,e,i)=>{if(r.click&&r.click(t,e,i))return!0;let n=Ac(t.state,e.from,e.to);if(n)return t.dispatch({effects:xc.of(n)}),!0;let s=wc(t.state,e.from,e.to);return!!s&&(t.dispatch({effects:yc.of(s)}),!0)}}}),Pc()]}(),function(t={}){return[Na.of(t),Ea,Ra,Ba,La]}(),function(t={}){return[Dr.of(t),Rr,Pr,Lr,Ji.of(!0)]}(),[Ir,Nr],Dt.allowMultipleSelections.of(!0),lr.lineWrapping,Dt.transactionFilter.of(t=>{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:n}=t.newSelection.main,s=i.lineAt(n);if(n>s.from+200)return t;let r=i.sliceString(s.from,n);if(!e.some(t=>t.test(r)))return t;let{state:o}=t,l=-1,a=[];for(let{head:t}of o.selection.ranges){let e=o.doc.lineAt(t);if(e.from==l)continue;l=e.from;let i=lc(o,e.from);if(null==i)continue;let n=/^\s*/.exec(e.text)[0],s=oc(o,i);n!=s&&a.push({from:e.from,to:e.from+n.length,insert:s})}return a.length?[t,{changes:a,sequential:!0}]:t}),function(t,e){let i,n=[jc];return t instanceof Fc&&(t.module&&n.push(lr.styleModule.of(t.module)),i=t.themeType),(null==e?void 0:e.fallback)?n.push(Vc.of(t)):i?n.push(Hc.computeN([lr.darkTheme],e=>e.facet(lr.darkTheme)==("dark"==i)?[t]:[])):n.push(Hc.of(t)),n}(Kc,{fallback:!0}),function(t={}){return[Yc.of(t),tu]}(),[lp,ip],gp(),lr.mouseSelectionStyle.of((t,e)=>{return(i=e).altKey&&0==i.button?Jr(t,e):null;var i}),function(t={}){let[e,i]=Zr[t.key||"Alt"],n=ln.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)},mousemove(t){this.set(i(t))}}});return[n,lr.contentAttributes.of(t=>{var e;return(null===(e=t.plugin(n))||void 0===e?void 0:e.isDown)?Qr:null})]}(),Gr,[vl,gl],mr.of([...ap,...Yf,...Kl,...tf,...Oc,...vp,...ma]),cu.define(Lg)];return t.EditorState=Dt,t.EditorView=lr,t.LSPClient=class{constructor(t={}){var e;if(this.config=t,this.transport=null,this.nextReqID=0,this.requests=[],this.activeMappings=[],this.serverCapabilities=null,this.supportSync=-1,this.extensions=[],this.receiveMessage=this.receiveMessage.bind(this),this.initializing=new Promise((t,e)=>this.init={resolve:t,reject:e}),this.timeout=null!==(e=t.timeout)&&void 0!==e?e:3e3,this.workspace=t.workspace?t.workspace(this):new Hm(this),t.extensions)for(let e of t.extensions)Array.isArray(e)||e.extension?this.extensions.push(e):e.editorExtension&&this.extensions.push(e.editorExtension)}get connected(){return!!this.transport}connect(t){this.transport&&this.transport.unsubscribe(this.receiveMessage),this.transport=t,t.subscribe(this.receiveMessage);let e=$m;if(this.config.extensions)for(let t of this.config.extensions){let{clientCapabilities:i}=t;i&&(e=Um(e,i))}return this.requestInner("initialize",{processId:null,clientInfo:{name:"@codemirror/lsp-client"},rootUri:this.config.rootUri||null,capabilities:e}).promise.then(e=>{var i;this.serverCapabilities=e.capabilities;let n=e.capabilities.textDocumentSync;this.supportSync=null==n?0:"number"==typeof n?n:null!==(i=n.change)&&void 0!==i?i:0,t.send(JSON.stringify({jsonrpc:"2.0",method:"initialized",params:{}})),this.init.resolve(null)},this.init.reject),this.workspace.connected(),this}disconnect(){this.transport&&this.transport.unsubscribe(this.receiveMessage),this.serverCapabilities=null,this.initializing=new Promise((t,e)=>this.init={resolve:t,reject:e}),this.workspace.disconnected()}plugin(t,e){return[zm.of({client:this,uri:t,languageID:e}),Vm,this.extensions]}didOpen(t){this.notification("textDocument/didOpen",{textDocument:{uri:t.uri,languageId:t.languageId,text:t.doc.toString(),version:t.version}})}didClose(t){this.notification("textDocument/didClose",{textDocument:{uri:t}})}receiveMessage(t){var e;const i=JSON.parse(t);if("id"in i&&!("method"in i)){let t=this.requests.findIndex(t=>t.id==i.id);if(t<0)console.warn(`[lsp] Received a response for non-existent request ${i.id}`);else{let e=this.requests[t];clearTimeout(e.timeout),this.requests.splice(t,1),i.error?e.reject(i.error):e.resolve(i.result)}}else if("id"in i){let t={jsonrpc:"2.0",id:i.id,error:{code:-32601,message:"Method not implemented"}};this.transport.send(JSON.stringify(t))}else{let t=null===(e=this.config.notificationHandlers)||void 0===e?void 0:e[i.method];if(t&&t(this,i.params))return;if(this.config.extensions)for(let t of this.config.extensions){let{notificationHandlers:e}=t,n=null==e?void 0:e[i.method];if(n&&n(this,i.params))return}let n=jm[i.method];n?n(this,i.params):this.config.unhandledNotification&&this.config.unhandledNotification(this,i.method,i.params)}}request(t,e){return this.transport?this.initializing.then(()=>this.requestInner(t,e).promise):Promise.reject(new Error("Client not connected"))}requestInner(t,e,i=!1){let n=++this.nextReqID,s={jsonrpc:"2.0",id:n,method:t,params:e},r=new Wm(n,e,setTimeout(()=>this.timeoutRequest(r),this.timeout));this.requests.push(r);try{this.transport.send(JSON.stringify(s))}catch(t){r.reject(t)}return r}notification(t,e){this.transport&&this.initializing.then(()=>{let i={jsonrpc:"2.0",method:t,params:e};this.transport.send(JSON.stringify(i))})}cancelRequest(t){let e=this.requests.find(e=>e.params===t);e&&this.notification("$/cancelRequest",e.id)}hasCapability(t){return this.serverCapabilities?!!this.serverCapabilities[t]:null}workspaceMapping(){let t=new _m(this);return this.activeMappings.push(t),t}withMapping(t){let e=this.workspaceMapping();return t(e).finally(()=>e.destroy())}sync(){for(let{file:t,changes:e,prevDoc:i}of this.workspace.syncFiles()){for(let i of this.activeMappings)i.addChanges(t.uri,e);this.supportSync&&this.notification("textDocument/didChange",{textDocument:{uri:t.uri,version:t.version},contentChanges:Km(t,i,e,2==this.supportSync)})}}timeoutRequest(t){let e=this.requests.indexOf(t);e>-1&&(t.reject(new Error("Request timed out")),this.requests.splice(e,1))}},t.LSPPlugin=Nm,t.StateEffect=gt,t.baseExts=Bg,t.formatDocument=eg,t.formatKeymap=ig,t.keymap=mr,t.languageServerExtensions=function(){return[Gm(),Zm(),mr.of([...ig,...ng,...fg,...gg]),cg(),{clientCapabilities:{textDocument:{publishDiagnostics:{versionSupport:!0}}},notificationHandlers:{"textDocument/publishDiagnostics":(t,e)=>{let i=t.workspace.getFile(e.uri);if(!i||null!=e.version&&e.version!=i.version)return!1;const n=i.getView(),s=n&&Nm.get(n);return!(!n||!s||(n.dispatch(ra(n.state,e.diagnostics.map(t=>{var e,i;return{from:s.unsyncedChanges.mapPos(s.fromPosition(t.range.start,s.syncedDoc)),to:s.unsyncedChanges.mapPos(s.fromPosition(t.range.end,s.syncedDoc)),severity:(i=null!==(e=t.severity)&&void 0!==e?e:1,1==i?"error":2==i?"warning":3==i?"info":"hint"),message:t.message}}))),0))}},editorExtension:vg}]},t.languageServerSupport=function(t,e,i){return[Nm.create(t,e,i),Gm(),Zm(),mr.of([...ig,...ng,...fg,...gg]),cg()]},t.linter=function(t,e={}){return[va.of({source:t,config:e}),ga,Ia]},t.listCommands=function(t){const e=new Map,i=t.state.facet(mr);for(let t of i)for(let i of t)i.run&&i.run.name&&e.set(i.run.name,{key:i.key,fn:i.run});return e},t.openLintPanel=da,t.openSearchPanel=_l,t.simpleWebSocketTransport=function(t){let e=[];return new Promise(function(i,n){let s=new WebSocket(t);s.onmessage=t=>{for(let i of e)i(t.data.toString())},s.onerror=t=>n(t),s.onopen=()=>i({socket:s,send:t=>s.send(t),subscribe:t=>e.push(t),unsubscribe:t=>e=e.filter(e=>e!=t)})})},t}({});