diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..24ae9a9 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,4 @@ +trailingComma: "es5" +tabWidth: 2 +semi: false +singleQuote: false diff --git a/demo/banner.txt b/demo/banner.txt new file mode 100644 index 0000000..7455d35 --- /dev/null +++ b/demo/banner.txt @@ -0,0 +1,13 @@ + _ _ _ _ + (_) | | | | | + ___ _ __ ___ _ ___ ___| |__ ___| | | + / __| '_ ` _ \| / __| / __| '_ \ / _ \ | | + | (__| | | | | | \__ \ \__ \ | | | __/ | | + \___|_| |_| |_| |___/ |___/_| |_|\___|_|_| + _/ | + |__/ + + This is a demo of cmjs-shell. It's not really intended for browsers + (it was built for electron), but it should work ok. Here there's a + javascript interpreter provided for test purposes. Enjoy! + diff --git a/demo/index.css b/demo/index.css new file mode 100644 index 0000000..0229443 --- /dev/null +++ b/demo/index.css @@ -0,0 +1,23 @@ +#shell-container { + width: 600px; + height: 400px; + border: 1px solid gray; + margin: 0 auto; + position: relative; +} + +#shell-container .CodeMirror { + height: 100%; + width: 100%; + font-family: consolas, 'ubuntu mono', monospace; + font-size: 10pt; +} + +.shell-error { + background: red; + color: white !important; +} + +.banner { + color: white !important; +} diff --git a/demo/index.html b/demo/index.html index aee466e..b715d54 100644 --- a/demo/index.html +++ b/demo/index.html @@ -1,115 +1,15 @@ - + - - demo - - - + + js - javascript terminal in web browser + + + + + - -
- - - - - - - - - - - + +
+ diff --git a/demo/index.js b/demo/index.js new file mode 100644 index 0000000..677d197 --- /dev/null +++ b/demo/index.js @@ -0,0 +1,90 @@ +import Shell from "../shell.js" + +// https://vitejs.dev/guide/assets.html#importing-asset-as-string +import banner from "./banner.txt?raw" + +//import {javascript} from "@codemirror/lang-javascript" +//import {StreamLanguage} from "@codemirror/language" +//import {lua} from "@codemirror/legacy-modes/mode/lua" +//import {shell} from "@codemirror/legacy-modes/mode/shell" +//import {javascript} from "@codemirror/legacy-modes/mode/javascript" + +import * as esprima from "esprima" + +/** + * this is our interpreter. note that writing responses to the shell + * is decoupled from commands -- the result of this function (via callback) + * only affects display of the prompt. + */ +function exec_function(cmd, callback) { + var ps = shell.PARSE_STATUS.OK + if (cmd.length) { + var composed = cmd.join("\n") + console.log("composed", composed) + const parse = esprima.parse + try { + parse(composed) + } catch (err) { + console.log("err", err) + if (err.description.match(/Unexpected end of input/)) { + ps = shell.PARSE_STATUS.INCOMPLETE + } + } + if (ps == shell.PARSE_STATUS.OK) { + /* + // TODO move the "shell.response" code into "composed" + // wrap async code + composed = [ + '(async () => { ', composed, '; })()', + '.then((result) => TODO)', + '.catch((error) => TODO);' + ].join(''); + */ + try { + // eval javascript + // TODO mock/patch console.log, so we see output in gui + console.log("eval:\n" + composed) + var text, + result = window.eval(composed) + console.log("eval", { text, result }) + try { + text = JSON.stringify(result) + } catch (e) { + text = result.toString() + } + // unix convention: newline after every line + text += "\n" + // send result to shell + shell.response(text) + } catch (e) { + shell.response(e.name + ": " + e.message + "\n", "shell-error") + } + } + } + callback.call(this, { parsestatus: ps }) +} + +/** one overloaded global method */ +window.print = function (a) { + shell.response(JSON.stringify(a)) +} + +/** + * this is the shell constructor + */ +var shell = new Shell({ + container: "#shell-container", + //container: document.body, + // TODO syntax highlighting + //mode: 'javascript', + //mode: javascript, + exec_function, +}) + +/** + * set up style and focus + */ +//shell.setOption( "theme", "zenburn" ); +shell.focus(); + +shell.response(banner, "banner") diff --git a/demo/setImmediate.js b/demo/setImmediate.js deleted file mode 100644 index 5abe55c..0000000 --- a/demo/setImmediate.js +++ /dev/null @@ -1,175 +0,0 @@ -(function (global, undefined) { - "use strict"; - - if (global.setImmediate) { - return; - } - - var nextHandle = 1; // Spec says greater than zero - var tasksByHandle = {}; - var currentlyRunningATask = false; - var doc = global.document; - var setImmediate; - - function addFromSetImmediateArguments(args) { - tasksByHandle[nextHandle] = partiallyApplied.apply(undefined, args); - return nextHandle++; - } - - // This function accepts the same arguments as setImmediate, but - // returns a function that requires no arguments. - function partiallyApplied(handler) { - var args = [].slice.call(arguments, 1); - return function() { - if (typeof handler === "function") { - handler.apply(undefined, args); - } else { - (new Function("" + handler))(); - } - }; - } - - function runIfPresent(handle) { - // From the spec: "Wait until any invocations of this algorithm started before this one have completed." - // So if we're currently running a task, we'll need to delay this invocation. - if (currentlyRunningATask) { - // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a - // "too much recursion" error. - setTimeout(partiallyApplied(runIfPresent, handle), 0); - } else { - var task = tasksByHandle[handle]; - if (task) { - currentlyRunningATask = true; - try { - task(); - } finally { - clearImmediate(handle); - currentlyRunningATask = false; - } - } - } - } - - function clearImmediate(handle) { - delete tasksByHandle[handle]; - } - - function installNextTickImplementation() { - setImmediate = function() { - var handle = addFromSetImmediateArguments(arguments); - process.nextTick(partiallyApplied(runIfPresent, handle)); - return handle; - }; - } - - function canUsePostMessage() { - // The test against `importScripts` prevents this implementation from being installed inside a web worker, - // where `global.postMessage` means something completely different and can't be used for this purpose. - if (global.postMessage && !global.importScripts) { - var postMessageIsAsynchronous = true; - var oldOnMessage = global.onmessage; - global.onmessage = function() { - postMessageIsAsynchronous = false; - }; - global.postMessage("", "*"); - global.onmessage = oldOnMessage; - return postMessageIsAsynchronous; - } - } - - function installPostMessageImplementation() { - // Installs an event handler on `global` for the `message` event: see - // * https://developer.mozilla.org/en/DOM/window.postMessage - // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages - - var messagePrefix = "setImmediate$" + Math.random() + "$"; - var onGlobalMessage = function(event) { - if (event.source === global && - typeof event.data === "string" && - event.data.indexOf(messagePrefix) === 0) { - runIfPresent(+event.data.slice(messagePrefix.length)); - } - }; - - if (global.addEventListener) { - global.addEventListener("message", onGlobalMessage, false); - } else { - global.attachEvent("onmessage", onGlobalMessage); - } - - setImmediate = function() { - var handle = addFromSetImmediateArguments(arguments); - global.postMessage(messagePrefix + handle, "*"); - return handle; - }; - } - - function installMessageChannelImplementation() { - var channel = new MessageChannel(); - channel.port1.onmessage = function(event) { - var handle = event.data; - runIfPresent(handle); - }; - - setImmediate = function() { - var handle = addFromSetImmediateArguments(arguments); - channel.port2.postMessage(handle); - return handle; - }; - } - - function installReadyStateChangeImplementation() { - var html = doc.documentElement; - setImmediate = function() { - var handle = addFromSetImmediateArguments(arguments); - // Create a + + + +
+ + diff --git a/docs/index.js b/docs/index.js new file mode 100644 index 0000000..5eef742 --- /dev/null +++ b/docs/index.js @@ -0,0 +1,49 @@ +(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const s of n)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function t(n){const s={};return n.integrity&&(s.integrity=n.integrity),n.referrerpolicy&&(s.referrerPolicy=n.referrerpolicy),n.crossorigin==="use-credentials"?s.credentials="include":n.crossorigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function i(n){if(n.ep)return;n.ep=!0;const s=t(n);fetch(n.href,s)}})();class K{constructor(){}lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){let n=[];return this.decompose(0,e,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(t,this.length,n,1),wt.from(n,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){let i=[];return this.decompose(e,t,i,0),wt.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),n=new Sn(this),s=new Sn(e);for(let o=t,l=t;;){if(n.next(o),s.next(o),o=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(l+=n.value.length,n.done||l>=i)return!0}}iter(e=1){return new Sn(this,e)}iterRange(e,t=this.length){return new nu(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let n=this.line(e).from;i=this.iterRange(n,Math.max(n,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new su(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?K.empty:e.length<=32?new ce(e):wt.from(ce.split(e,[]))}}class ce extends K{constructor(e,t=Jd(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,n){for(let s=0;;s++){let o=this.text[s],l=n+o.length;if((t?i:l)>=e)return new Ud(n,l,i,o);n=l+1,i++}}decompose(e,t,i,n){let s=e<=0&&t>=this.length?this:new ce(ql(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(n&1){let o=i.pop(),l=ys(s.text,o.text.slice(),0,s.length);if(l.length<=32)i.push(new ce(l,o.length+s.length));else{let a=l.length>>1;i.push(new ce(l.slice(0,a)),new ce(l.slice(a)))}}else i.push(s)}replace(e,t,i){if(!(i instanceof ce))return super.replace(e,t,i);let n=ys(this.text,ys(i.text,ql(this.text,0,e)),t),s=this.length+i.length-(t-e);return n.length<=32?new ce(n,s):wt.from(ce.split(n,[]),s)}sliceString(e,t=this.length,i=` +`){let n="";for(let s=0,o=0;s<=t&&oe&&o&&(n+=i),es&&(n+=l.slice(Math.max(0,e-s),t-s)),s=a+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],n=-1;for(let s of e)i.push(s),n+=s.length+1,i.length==32&&(t.push(new ce(i,n)),i=[],n=-1);return n>-1&&t.push(new ce(i,n)),t}}class wt extends K{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,n){for(let s=0;;s++){let o=this.children[s],l=n+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,n);n=l+1,i=a+1}}decompose(e,t,i,n){for(let s=0,o=0;o<=t&&s=o){let h=n&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if(i.lines=s&&t<=l){let a=o.replace(e-s,t-s,i),h=this.lines-o.lines+a.lines;if(a.lines>5-1&&a.lines>h>>5+1){let u=this.children.slice();return u[n]=a,new wt(u,this.length-(t-e)+i.length)}return super.replace(s,l,a)}s=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=` +`){let n="";for(let s=0,o=0;se&&s&&(n+=i),eo&&(n+=l.sliceString(e-o,t-o,i)),o=a+1}return n}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof wt))return 0;let i=0,[n,s,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;n+=t,s+=t){if(n==o||s==l)return i;let a=this.children[n],h=e.children[s];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,n)=>i+n.length+1,-1)){let i=0;for(let g of e)i+=g.lines;if(i<32){let g=[];for(let y of e)y.flatten(g);return new ce(g,t)}let n=Math.max(32,i>>5),s=n<<1,o=n>>1,l=[],a=0,h=-1,u=[];function d(g){let y;if(g.lines>s&&g instanceof wt)for(let c of g.children)d(c);else g.lines>o&&(a>o||!a)?(p(),l.push(g)):g instanceof ce&&a&&(y=u[u.length-1])instanceof ce&&g.lines+y.lines<=32?(a+=g.lines,h+=g.length+1,u[u.length-1]=new ce(y.text.concat(g.text),y.length+1+g.length)):(a+g.lines>n&&p(),a+=g.lines,h+=g.length+1,u.push(g))}function p(){a!=0&&(l.push(u.length==1?u[0]:wt.from(u,h)),h=-1,a=u.length=0)}for(let g of e)d(g);return p(),l.length==1?l[0]:new wt(l,t)}}K.empty=new ce([""],0);function Jd(r){let e=-1;for(let t of r)e+=t.length+1;return e}function ys(r,e,t=0,i=1e9){for(let n=0,s=0,o=!0;s=t&&(a>i&&(l=l.slice(0,i-n)),n0?1:(e instanceof ce?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],s=this.offsets[i],o=s>>1,l=n instanceof ce?n.text.length:n.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=` +`,this;e--}else if(n instanceof ce){let a=n.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=n.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof ce?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class nu{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new Sn(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:n}=this.cursor.next(e);return this.pos+=(n.length+e)*t,this.value=n.length<=i?n:t<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class su{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:n}=this.inner.next(e);return t?(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}}typeof Symbol<"u"&&(K.prototype[Symbol.iterator]=function(){return this.iter()},Sn.prototype[Symbol.iterator]=nu.prototype[Symbol.iterator]=su.prototype[Symbol.iterator]=function(){return this});class Ud{constructor(e,t,i,n){this.from=e,this.to=t,this.number=i,this.text=n}get length(){return this.to-this.from}}let Ti="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(r=>r?parseInt(r,36):1);for(let r=1;rr)return Ti[e-1]<=r;return!1}function Gl(r){return r>=127462&&r<=127487}const Yl=8205;function nt(r,e,t=!0,i=!0){return(t?ru:Kd)(r,e,i)}function ru(r,e,t){if(e==r.length)return e;e&&ou(r.charCodeAt(e))&&lu(r.charCodeAt(e-1))&&e--;let i=xs(r,e);for(e+=Qr(i);e=0&&Gl(xs(r,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function Kd(r,e,t){for(;e>0;){let i=ru(r,e-2,t);if(i=56320&&r<57344}function lu(r){return r>=55296&&r<56320}function xs(r,e){let t=r.charCodeAt(e);if(!lu(t)||e+1==r.length)return t;let i=r.charCodeAt(e+1);return ou(i)?(t-55296<<10)+(i-56320)+65536:t}function Qr(r){return r<65536?1:2}const eo=/\r\n?|\n/;var Qe=function(r){return r[r.Simple=0]="Simple",r[r.TrackDel=1]="TrackDel",r[r.TrackBefore=2]="TrackBefore",r[r.TrackAfter=3]="TrackAfter",r}(Qe||(Qe={}));class kt{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;te)return s+(e-n);s+=l}else{if(i!=Qe.Simple&&h>=e&&(i==Qe.TrackDel&&ne||i==Qe.TrackBefore&&ne))return null;if(h>e||h==e&&t<0&&!l)return e==n||t<0?s:s+a;s+=a}n=h}if(e>n)throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`);return s}touchesRange(e,t=e){for(let i=0,n=0;i=0&&n<=t&&l>=e)return nt?"cover":!0;n=l}return!1}toString(){let e="";for(let t=0;t=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new kt(e)}static create(e){return new kt(e)}}class ve extends kt{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return to(this,(t,i,n,s,o)=>e=e.replace(n,n+(i-t),o),!1),e}mapDesc(e,t=!1){return io(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,s=0;n=0){t[n]=l,t[n+1]=o;let a=n>>1;for(;i.length0&&Xt(i,t,s.text),s.forward(u),l+=u}let h=e[o++];for(;l>1].toJSON()))}return e}static of(e,t,i){let n=[],s=[],o=0,l=null;function a(u=!1){if(!u&&!n.length)return;op||d<0||p>t)throw new RangeError(`Invalid change range ${d} to ${p} (in doc of length ${t})`);let y=g?typeof g=="string"?K.of(g.split(i||eo)):g:K.empty,c=y.length;if(d==p&&c==0)return;do&&Pe(n,d-o,-1),Pe(n,p-d,c),Xt(s,n,y),o=p}}return h(e),a(!l),l}static empty(e){return new ve(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;nl&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;i.length=0&&t<=0&&t==r[n+1]?r[n]+=e:e==0&&r[n]==0?r[n+1]+=t:i?(r[n]+=e,r[n+1]+=t):r.push(e,t)}function Xt(r,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i>1])),!(t||o==r.sections.length||r.sections[o+1]<0);)l=r.sections[o++],a=r.sections[o++];e(n,h,s,u,d),n=h,s=u}}}function io(r,e,t,i=!1){let n=[],s=i?[]:null,o=new An(r),l=new An(e);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);Pe(n,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len=0&&a=0){let h=0,u=o.len;for(;u;)if(l.ins==-1){let d=Math.min(u,l.len);h+=d,u-=d,l.forward(d)}else if(l.ins==0&&l.lena||o.ins>=0&&o.len>a)&&(l||i.length>h),s.forward2(a),o.forward(a)}}}}class An{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i>1;return t>=e.length?K.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?K.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class pi{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&16?this.to:this.from}get head(){return this.flags&16?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&4?-1:this.flags&8?1:0}get bidiLevel(){let e=this.flags&3;return e==3?null:e}get goalColumn(){let e=this.flags>>5;return e==33554431?void 0:e}map(e,t=-1){let i,n;return this.empty?i=n=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),n=e.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new pi(i,n,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return M.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return M.range(this.anchor,i)}eq(e){return this.anchor==e.anchor&&this.head==e.head}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return M.range(e.anchor,e.head)}static create(e,t,i){return new pi(e,t,i)}}class M{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:M.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let t=0;te.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new M(e.ranges.map(t=>pi.fromJSON(t)),e.main)}static single(e,t=e){return new M([M.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;ne?4:0))}static normalized(e,t=0){let i=e[t];e.sort((n,s)=>n.from-s.from),t=e.indexOf(i);for(let n=1;ns.head?M.range(a,l):M.range(l,a))}}return new M(e,t)}}function hu(r,e){for(let t of r.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let ml=0;class W{constructor(e,t,i,n,s){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=ml++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}static define(e={}){return new W(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:gl),!!e.static,e.enables)}of(e){return new vs([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new vs(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new vs(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function gl(r,e){return r==e||r.length==e.length&&r.every((t,i)=>t===e[i])}class vs{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=ml++}dynamicSlot(e){var t;let i=this.value,n=this.facet.compareInput,s=this.id,o=e[s]>>1,l=this.type==2,a=!1,h=!1,u=[];for(let d of this.dependencies)d=="doc"?a=!0:d=="selection"?h=!0:(((t=e[d.id])!==null&&t!==void 0?t:1)&1)==0&&u.push(e[d.id]);return{create(d){return d.values[o]=i(d),1},update(d,p){if(a&&p.docChanged||h&&(p.docChanged||p.selection)||no(d,u)){let g=i(d);if(l?!Zl(g,d.values[o],n):!n(g,d.values[o]))return d.values[o]=g,1}return 0},reconfigure:(d,p)=>{let g,y=p.config.address[s];if(y!=null){let c=Bs(p,y);if(this.dependencies.every(f=>f instanceof W?p.facet(f)===d.facet(f):f instanceof zt?p.field(f,!1)==d.field(f,!1):!0)||(l?Zl(g=i(d),c,n):n(g=i(d),c)))return d.values[o]=c,0}else g=i(d);return d.values[o]=g,1}}}}function Zl(r,e,t){if(r.length!=e.length)return!1;for(let i=0;ir[a.id]),n=t.map(a=>a.type),s=i.filter(a=>!(a&1)),o=r[e.id]>>1;function l(a){let h=[];for(let u=0;ui===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Ql).find(i=>i.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,n)=>{let s=i.values[t],o=this.updateF(s,n);return this.compareF(s,o)?0:(i.values[t]=o,1)},reconfigure:(i,n)=>n.config.address[this.id]!=null?(i.values[t]=n.field(this),0):(i.values[t]=this.create(i),1)}}init(e){return[this,Ql.of({field:this,create:e})]}get extension(){return this}}const fi={lowest:4,low:3,default:2,high:1,highest:0};function on(r){return e=>new cu(e,r)}const uu={highest:on(fi.highest),high:on(fi.high),default:on(fi.default),low:on(fi.low),lowest:on(fi.lowest)};class cu{constructor(e,t){this.inner=e,this.prec=t}}class or{of(e){return new so(this,e)}reconfigure(e){return or.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class so{constructor(e,t){this.compartment=e,this.inner=t}}class Fs{constructor(e,t,i,n,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(e,t,i){let n=[],s=Object.create(null),o=new Map;for(let p of jd(e,t,o))p instanceof zt?n.push(p):(s[p.facet.id]||(s[p.facet.id]=[])).push(p);let l=Object.create(null),a=[],h=[];for(let p of n)l[p.id]=h.length<<1,h.push(g=>p.slot(g));let u=i?.config.facets;for(let p in s){let g=s[p],y=g[0].facet,c=u&&u[p]||[];if(g.every(f=>f.type==0))if(l[y.id]=a.length<<1|1,gl(c,g))a.push(i.facet(y));else{let f=y.combine(g.map(m=>m.value));a.push(i&&y.compare(f,i.facet(y))?i.facet(y):f)}else{for(let f of g)f.type==0?(l[f.id]=a.length<<1|1,a.push(f.value)):(l[f.id]=h.length<<1,h.push(m=>f.dynamicSlot(m)));l[y.id]=h.length<<1,h.push(f=>_d(f,y,g))}}let d=h.map(p=>p(l));return new Fs(e,o,d,l,a,s)}}function jd(r,e,t){let i=[[],[],[],[],[]],n=new Map;function s(o,l){let a=n.get(o);if(a!=null){if(a<=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof so&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let h of o)s(h,l);else if(o instanceof so){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),s(h,l)}else if(o instanceof cu)s(o.inner,o.prec);else if(o instanceof zt)i[l].push(o),o.provides&&s(o.provides,l);else if(o instanceof vs)i[l].push(o),o.facet.extensions&&s(o.facet.extensions,fi.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(h,l)}}return s(r,fi.default),i.reduce((o,l)=>o.concat(l))}function Dn(r,e){if(e&1)return 2;let t=e>>1,i=r.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;r.status[t]=4;let n=r.computeSlot(r,r.config.dynamicSlots[t]);return r.status[t]=2|n}function Bs(r,e){return e&1?r.config.staticValues[e>>1]:r.values[e>>1]}const fu=W.define(),du=W.define({combine:r=>r.some(e=>e),static:!0}),pu=W.define({combine:r=>r.length?r[0]:void 0,static:!0}),mu=W.define(),gu=W.define(),yu=W.define(),xu=W.define({combine:r=>r.length?r[0]:!1});class Di{constructor(e,t){this.type=e,this.value=t}static define(){return new qd}}class qd{of(e){return new Di(this,e)}}class Gd{constructor(e){this.map=e}of(e){return new de(this,e)}}class de{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new de(this.type,t)}is(e){return this.type==e}static define(e={}){return new Gd(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let n of e){let s=n.map(t);s&&i.push(s)}return i}}de.reconfigure=de.define();de.appendConfig=de.define();class we{constructor(e,t,i,n,s,o){this.startState=e,this.changes=t,this.selection=i,this.effects=n,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,i&&hu(i,t.newLength),s.some(l=>l.type==we.time)||(this.annotations=s.concat(we.time.of(Date.now())))}static create(e,t,i,n,s,o){return new we(e,t,i,n,s,o)}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(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(we.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}we.time=Di.define();we.userEvent=Di.define();we.addToHistory=Di.define();we.remote=Di.define();function Yd(r,e){let t=[];for(let i=0,n=0;;){let s,o;if(i=r[i]))s=r[i++],o=r[i++];else if(n=0;n--){let s=i[n](r);s instanceof we?r=s:Array.isArray(s)&&s.length==1&&s[0]instanceof we?r=s[0]:r=wu(e,Mi(s),!1)}return r}function Qd(r){let e=r.startState,t=e.facet(yu),i=r;for(let n=t.length-1;n>=0;n--){let s=t[n](r);s&&Object.keys(s).length&&(i=vu(i,ro(e,s,r.changes.newLength),!0))}return i==r?r:we.create(e,r.changes,r.selection,i.effects,i.annotations,i.scrollIntoView)}const ep=[];function Mi(r){return r==null?ep:Array.isArray(r)?r:[r]}var Ot=function(r){return r[r.Word=0]="Word",r[r.Space=1]="Space",r[r.Other=2]="Other",r}(Ot||(Ot={}));const tp=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let oo;try{oo=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function ip(r){if(oo)return oo.test(r);for(let e=0;e"\x80"&&(t.toUpperCase()!=t.toLowerCase()||tp.test(t)))return!0}return!1}function np(r){return e=>{if(!/\S/.test(e))return Ot.Space;if(ip(e))return Ot.Word;for(let t=0;t-1)return Ot.Word;return Ot.Other}}class G{constructor(e,t,i,n,s,o){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let l=0;ln.set(a,l)),t=null),n.set(o.value.compartment,o.value.extension)):o.is(de.reconfigure)?(t=null,i=o.value):o.is(de.appendConfig)&&(t=null,i=Mi(i).concat(o.value));let s;t?s=e.startState.values.slice():(t=Fs.resolve(i,n,this),s=new G(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,a)=>a.reconfigure(l,this),null).values),new G(t,e.newDoc,e.newSelection,s,(o,l)=>l.update(o,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:M.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),s=[i.range],o=Mi(i.effects);for(let l=1;lo.spec.fromJSON(l,a)))}}return G.create({doc:e.doc,selection:M.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=Fs.resolve(e.extensions||[],new Map),i=e.doc instanceof K?e.doc:K.of((e.doc||"").split(t.staticFacet(G.lineSeparator)||eo)),n=e.selection?e.selection instanceof M?e.selection:M.single(e.selection.anchor,e.selection.head):M.single(0);return hu(n,i.length),t.staticFacet(du)||(n=n.asSingle()),new G(t,i,n,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(G.tabSize)}get lineBreak(){return this.facet(G.lineSeparator)||` +`}get readOnly(){return this.facet(xu)}phrase(e,...t){for(let i of this.facet(G.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,n)=>{if(n=="$")return"$";let s=+(n||1);return!s||s>t.length?i:t[s-1]})),e}languageDataAt(e,t,i=-1){let n=[];for(let s of this.facet(fu))for(let o of s(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&n.push(o[e]);return n}charCategorizer(e){return np(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:i,length:n}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=nt(t,o,!1);if(s(t.slice(a,o))!=Ot.Word)break;o=a}for(;lr.length?r[0]:4});G.lineSeparator=pu;G.readOnly=xu;G.phrases=W.define({compare(r,e){let t=Object.keys(r),i=Object.keys(e);return t.length==i.length&&t.every(n=>r[n]==e[n])}});G.languageData=fu;G.changeFilter=mu;G.transactionFilter=gu;G.transactionExtender=yu;or.reconfigure=de.define();function sp(r,e,t={}){let i={};for(let n of r)for(let s of Object.keys(n)){let o=n[s],l=i[s];if(l===void 0)i[s]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,s))i[s]=t[s](l,o);else throw new Error("Config merge conflict for field "+s)}for(let n in e)i[n]===void 0&&(i[n]=e[n]);return i}class zi{eq(e){return this==e}range(e,t=e){return Cn.create(e,t,this)}}zi.prototype.startSide=zi.prototype.endSide=0;zi.prototype.point=!1;zi.prototype.mapMode=Qe.TrackDel;class Cn{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Cn(e,t,i)}}function lo(r,e){return r.from-e.from||r.value.startSide-e.value.startSide}class yl{constructor(e,t,i,n){this.from=e,this.to=t,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,n=0){let s=i?this.to:this.from;for(let o=n,l=s.length;;){if(o==l)return o;let a=o+l>>1,h=s[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,i,n){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,s);sg||p==g&&h.startSide>0&&h.endSide<=0)continue;(g-p||h.endSide-h.startSide)<0||(o<0&&(o=p),h.point&&(l=Math.max(l,g-p)),i.push(h),n.push(p-o),s.push(g-o))}return{mapped:i.length?new yl(n,s,i,l):null,pos:o}}}class me{constructor(e,t,i,n){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=n}static create(e,t,i,n){return new me(e,t,i,n)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:n=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(lo)),this.isEmpty)return t.length?me.of(t):this;let l=new Su(this,null,-1).goto(0),a=0,h=[],u=new Ts;for(;l.value||a=0){let d=t[a++];u.addInner(d.from,d.to,d.value)||h.push(d)}else l.rangeIndex==1&&l.chunkIndexthis.chunkEnd(l.chunkIndex)||sl.to||s=s&&e<=s+o.length&&o.between(s,e-s,t-s,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return En.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return En.from(e).goto(t)}static compare(e,t,i,n,s=-1){let o=e.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),l=t.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),a=ea(o,l,i),h=new ln(o,a,s),u=new ln(l,a,s);i.iterGaps((d,p,g)=>ta(h,d,u,p,g,n)),i.empty&&i.length==0&&ta(h,0,u,0,0,n)}static eq(e,t,i=0,n){n==null&&(n=1e9-1);let s=e.filter(u=>!u.isEmpty&&t.indexOf(u)<0),o=t.filter(u=>!u.isEmpty&&e.indexOf(u)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let l=ea(s,o),a=new ln(s,l,0).goto(i),h=new ln(o,l,0).goto(i);for(;;){if(a.to!=h.to||!ao(a.active,h.active)||a.point&&(!h.point||!a.point.eq(h.point)))return!1;if(a.to>n)return!0;a.next(),h.next()}}static spans(e,t,i,n,s=-1){let o=new ln(e,null,s).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let u=o.activeForPoint(o.to),d=o.pointFroml&&(n.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new Ts;for(let n of e instanceof Cn?[e]:t?rp(e):e)i.add(n.from,n.to,n.value);return i.finish()}}me.empty=new me([],[],null,-1);function rp(r){if(r.length>1)for(let e=r[0],t=1;t0)return r.slice().sort(lo);e=i}return r}me.empty.nextLayer=me.empty;class Ts{constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}finishChunk(e){this.chunks.push(new yl(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,e&&(this.from=[],this.to=[],this.value=[])}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new Ts)).add(e,t,i)}addInner(e,t,i){let n=e-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return n<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(me.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=me.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function ea(r,e,t){let i=new Map;for(let s of r)for(let o=0;o=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=i&&n.push(new Su(o,t,i,s));return n.length==1?n[0]:new En(n)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)kr(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)kr(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),kr(this.heap,0)}}}function kr(r,e){for(let t=r[e];;){let i=(e<<1)+1;if(i>=r.length)break;let n=r[i];if(i+1=0&&(n=r[i+1],i++),t.compare(n)<0)break;r[i]=t,r[e]=n,e=i}}class ln{constructor(e,t,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=En.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Xn(this.active,e),Xn(this.activeTo,e),Xn(this.activeRank,e),this.minActive=ia(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:s}=this.cursor;for(;t-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>e){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&Xn(i,n)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from=0&&i[n]=0&&!(this.activeRank[i]e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function ta(r,e,t,i,n,s){r.goto(e),t.goto(i);let o=i+n,l=i,a=i-e;for(;;){let h=r.to+a-t.to||r.endSide-t.endSide,u=h<0?r.to+a:t.to,d=Math.min(u,o);if(r.point||t.point?r.point&&t.point&&(r.point==t.point||r.point.eq(t.point))&&ao(r.activeForPoint(r.to+a),t.activeForPoint(t.to))||s.comparePoint(l,d,r.point,t.point):d>l&&!ao(r.active,t.active)&&s.compareRange(l,d,r.active,t.active),u>o)break;l=u,h<=0&&r.next(),h>=0&&t.next()}}function ao(r,e){if(r.length!=e.length)return!1;for(let t=0;t=e;i--)r[i+1]=r[i];r[e]=t}function ia(r,e){let t=-1,i=1e9;for(let n=0;n=e)return n;if(n==r.length)break;s+=r.charCodeAt(n)==9?t-s%t:1,n=nt(r,n)}return i===!0?-1:r.length}const ho="\u037C",na=typeof Symbol>"u"?"__"+ho:Symbol.for(ho),uo=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),sa=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Vi{constructor(e,t){this.rules=[];let{finish:i}=t||{};function n(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,l,a,h){let u=[],d=/^@(\w+)\b/.exec(o[0]),p=d&&d[1]=="keyframes";if(d&&l==null)return a.push(o[0]+";");for(let g in l){let y=l[g];if(/&/.test(g))s(g.split(/,\s*/).map(c=>o.map(f=>c.replace(/&/,f))).reduce((c,f)=>c.concat(f)),y,a);else if(y&&typeof y=="object"){if(!d)throw new RangeError("The value of a property ("+g+") should be a primitive value.");s(n(g),y,u,p)}else y!=null&&u.push(g.replace(/_.*/,"").replace(/[A-Z]/g,c=>"-"+c.toLowerCase())+": "+y+";")}(u.length||p)&&a.push((i&&!d&&!h?o.map(i):o).join(", ")+" {"+u.join(" ")+"}")}for(let o in e)s(n(o),e[o],this.rules)}getRules(){return this.rules.join(` +`)}static newName(){let e=sa[na]||1;return sa[na]=e+1,ho+e.toString(36)}static mount(e,t){(e[uo]||new lp(e)).mount(Array.isArray(t)?t:[t])}}let _n=null;class lp{constructor(e){if(!e.head&&e.adoptedStyleSheets&&typeof CSSStyleSheet<"u"){if(_n)return e.adoptedStyleSheets=[_n.sheet].concat(e.adoptedStyleSheets),e[uo]=_n;this.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[this.sheet].concat(e.adoptedStyleSheets),_n=this}else{this.styleTag=(e.ownerDocument||e).createElement("style");let t=e.head||e;t.insertBefore(this.styleTag,t.firstChild)}this.modules=[],e[uo]=this}mount(e){let t=this.sheet,i=0,n=0;for(let s=0;s-1&&(this.modules.splice(l,1),n--,l=-1),l==-1){if(this.modules.splice(n++,0,o),t)for(let a=0;a",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ra=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent);typeof navigator<"u"&&/Gecko\/\d+/.test(navigator.userAgent);var ap=typeof navigator<"u"&&/Mac/.test(navigator.platform),hp=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),up=ap||ra&&+ra[1]<57;for(var Be=0;Be<10;Be++)si[48+Be]=si[96+Be]=String(Be);for(var Be=1;Be<=24;Be++)si[Be+111]="F"+Be;for(var Be=65;Be<=90;Be++)si[Be]=String.fromCharCode(Be+32),Fn[Be]=String.fromCharCode(Be);for(var Ar in si)Fn.hasOwnProperty(Ar)||(Fn[Ar]=si[Ar]);function cp(r){var e=up&&(r.ctrlKey||r.altKey||r.metaKey)||hp&&r.shiftKey&&r.key&&r.key.length==1||r.key=="Unidentified",t=!e&&r.key||(r.shiftKey?Fn:si)[r.keyCode]||r.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}function Ms(r){let e;return r.nodeType==11?e=r.getSelection?r:r.ownerDocument:e=r,e.getSelection()}function Hi(r,e){return e?r==e||r.contains(e.nodeType!=1?e.parentNode:e):!1}function fp(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function ws(r,e){if(!e.anchorNode)return!1;try{return Hi(r,e.anchorNode)}catch{return!1}}function Bn(r){return r.nodeType==3?$i(r,0,r.nodeValue.length).getClientRects():r.nodeType==1?r.getClientRects():[]}function Os(r,e,t,i){return t?oa(r,e,t,i,-1)||oa(r,e,t,i,1):!1}function Ps(r){for(var e=0;;e++)if(r=r.previousSibling,!r)return e}function oa(r,e,t,i,n){for(;;){if(r==t&&e==i)return!0;if(e==(n<0?0:Tn(r))){if(r.nodeName=="DIV")return!1;let s=r.parentNode;if(!s||s.nodeType!=1)return!1;e=Ps(r)+(n<0?0:1),r=s}else if(r.nodeType==1){if(r=r.childNodes[e+(n<0?-1:0)],r.nodeType==1&&r.contentEditable=="false")return!1;e=n<0?Tn(r):0}else return!1}}function Tn(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}const Du={left:0,right:0,top:0,bottom:0};function vl(r,e){let t=e?r.left:r.right;return{left:t,right:t,top:r.top,bottom:r.bottom}}function dp(r){return{left:0,right:r.innerWidth,top:0,bottom:r.innerHeight}}function pp(r,e,t,i,n,s,o,l){let a=r.ownerDocument,h=a.defaultView||window;for(let u=r;u;)if(u.nodeType==1){let d,p=u==a.body;if(p)d=dp(h);else{if(u.scrollHeight<=u.clientHeight&&u.scrollWidth<=u.clientWidth){u=u.assignedSlot||u.parentNode;continue}let c=u.getBoundingClientRect();d={left:c.left,right:c.left+u.clientWidth,top:c.top,bottom:c.top+u.clientHeight}}let g=0,y=0;if(n=="nearest")e.top0&&e.bottom>d.bottom+y&&(y=e.bottom-d.bottom+y+o)):e.bottom>d.bottom&&(y=e.bottom-d.bottom+o,t<0&&e.top-y0&&e.right>d.right+g&&(g=e.right-d.right+g+s)):e.right>d.right&&(g=e.right-d.right+s,t<0&&e.leftt)return d.domBoundsAround(e,t,h);if(p>=e&&n==-1&&(n=a,s=h),h>t&&d.dom.parentNode==this.dom){o=a,l=u;break}u=p,h=p+d.breakAfter}return{from:s,to:l<0?i+this.length:l,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o=0?this.children[o].dom:null}}markDirty(e=!1){this.dirty|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.dirty|=2),t.dirty&1)return;t.dirty|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.dirty&&this.markParentsDirty(!0))}setDOM(e){this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,i=wl){this.markDirty();for(let n=e;nthis.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Cu(r,e,t,i,n,s,o,l,a){let{children:h}=r,u=h.length?h[e]:null,d=s.length?s[s.length-1]:null,p=d?d.breakAfter:o;if(!(e==i&&u&&!o&&!p&&s.length<2&&u.merge(t,n,s.length?d:null,t==0,l,a))){if(i0&&(!o&&s.length&&u.merge(t,u.length,s[0],!1,l,0)?u.breakAfter=s.shift().breakAfter:(t2);var N={mac:ca||/Mac/.test(et.platform),windows:/Win/.test(et.platform),linux:/Linux|X11/.test(et.platform),ie:lr,ie_version:Fu?co.documentMode||6:po?+po[1]:fo?+fo[1]:0,gecko:ha,gecko_version:ha?+(/Firefox\/(\d+)/.exec(et.userAgent)||[0,0])[1]:0,chrome:!!Cr,chrome_version:Cr?+Cr[1]:0,ios:ca,android:/Android\b/.test(et.userAgent),webkit:ua,safari:Bu,webkit_version:ua?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:co.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const xp=256;class ri extends ne{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,i){return i&&(!(i instanceof ri)||this.length-(t-e)+i.length>xp)?!1:(this.text=this.text.slice(0,e)+(i?i.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new ri(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new Re(this.dom,e)}domBoundsAround(e,t,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return mo(this.dom,e,t)}}class Et extends ne{constructor(e,t=[],i=0){super(),this.mark=e,this.children=t,this.length=i;for(let n of t)n.setParent(this)}setAttrs(e){if(ku(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.dirty|=6)}sync(e){this.dom?this.dirty&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e)}merge(e,t,i,n,s,o){return i&&(!(i instanceof Et&&i.mark.eq(this.mark))||e&&s<=0||te&&t.push(i=e&&(n=s),i=a,s++}let o=this.length-e;return this.length=e,n>-1&&(this.children.length=n,this.markDirty()),new Et(this.mark,t,o)}domAtPos(e){return Ou(this,e)}coordsAt(e,t){return Nu(this,e,t)}}function mo(r,e,t){let i=r.nodeValue.length;e>i&&(e=i);let n=e,s=e,o=0;e==0&&t<0||e==i&&t>=0?N.chrome||N.gecko||(e?(n--,o=1):s=0)?0:l.length-1];return N.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?vl(a,o<0):a||null}class Kt extends ne{constructor(e,t,i){super(),this.widget=e,this.length=t,this.side=i,this.prevWidget=null}static create(e,t,i){return new(e.customView||Kt)(e,t,i)}split(e){let t=Kt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}getSide(){return this.side}merge(e,t,i,n,s,o){return i&&(!(i instanceof Kt)||!this.widget.compare(i.widget)||e>0&&s<=0||t0?i.length-1:0;n=i[s],!(e>0?s==0:s==i.length-1||n.top0?-1:1);return this.length?n:vl(n,this.side>0)}get isEditable(){return!1}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class Tu extends Kt{domAtPos(e){let{topView:t,text:i}=this.widget;return t?go(e,0,t,i,(n,s)=>n.domAtPos(s),n=>new Re(i,Math.min(n,i.nodeValue.length))):new Re(i,Math.min(e,i.nodeValue.length))}sync(){this.setDOM(this.widget.toDOM())}localPosFromDOM(e,t){let{topView:i,text:n}=this.widget;return i?Mu(e,t,i,n):Math.min(t,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(e,t){let{topView:i,text:n}=this.widget;return i?go(e,t,i,n,(s,o,l)=>s.coordsAt(o,l),(s,o)=>mo(n,s,o)):mo(n,e,t)}destroy(){var e;super.destroy(),(e=this.widget.topView)===null||e===void 0||e.destroy()}get isEditable(){return!0}canReuseDOM(){return!0}}function go(r,e,t,i,n,s){if(t instanceof Et){for(let o=t.dom.firstChild;o;o=o.nextSibling){let l=ne.get(o);if(!l)return s(r,e);let a=Hi(o,i),h=l.length+(a?i.nodeValue.length:0);if(r0?-1:1);return i&&i.topt.top?{left:t.left,right:t.right,top:i.top,bottom:i.bottom}:t}get overrideDOMText(){return K.empty}}ri.prototype.children=Kt.prototype.children=Wi.prototype.children=wl;function vp(r,e){let t=r.parent,i=t?t.children.indexOf(r):-1;for(;t&&i>=0;)if(e<0?i>0:is&&e0;s--){let o=i[s-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let s=n;s0&&e instanceof Et&&n.length&&(i=n[n.length-1])instanceof Et&&i.mark.eq(e.mark)?Pu(i,e.children[0],t-1):(n.push(e),e.setParent(r)),r.length+=e.length}function Nu(r,e,t){let i=null,n=-1,s=null,o=-1;function l(h,u){for(let d=0,p=0;d=u&&(g.children.length?l(g,u-p):!s&&(y>u||p==y&&g.getSide()>0)?(s=g,o=u-p):(p0?3e8:-4e8:t>0?1e8:-1e8,new wi(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,n;if(e.isBlockGap)i=-5e8,n=4e8;else{let{start:s,end:o}=Iu(e,t);i=(s?t?-3e8:-1:5e8)-1,n=(o?t?2e8:1:-6e8)+1}return new wi(e,i,n,t,e.widget||null,!0)}static line(e){return new $n(e)}static set(e,t=!1){return me.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}ge.none=me.empty;class hr extends ge{constructor(e){let{start:t,end:i}=Iu(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){return this==e||e instanceof hr&&this.tagName==e.tagName&&this.class==e.class&&Sl(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}hr.prototype.point=!1;class $n extends ge{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof $n&&Sl(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}$n.prototype.mapMode=Qe.TrackBefore;$n.prototype.point=!0;class wi extends ge{constructor(e,t,i,n,s,o){super(t,i,s,e),this.block=n,this.isReplace=o,this.mapMode=n?t<=0?Qe.TrackBefore:Qe.TrackAfter:Qe.TrackDel}get type(){return this.startSide=5}eq(e){return e instanceof wi&&Sp(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}wi.prototype.point=!0;function Iu(r,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=r;return t==null&&(t=r.inclusive),i==null&&(i=r.inclusive),{start:t??e,end:i??e}}function Sp(r,e){return r==e||!!(r&&e&&r.compare(e))}function vo(r,e,t,i=0){let n=t.length-1;n>=0&&t[n]+i>=r?t[n]=Math.max(t[n],e):t.push(r,e)}class Je extends ne{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,i,n,s,o){if(i){if(!(i instanceof Je))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),Eu(this,e,t,i?i.children:[],s,o),!0}split(e){let t=new Je;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i,off:n}=this.childPos(e);n&&(t.append(this.children[i].split(n),0),this.children[i].merge(n,this.children[i].length,null,!1,0,0),i++);for(let s=i;s0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=e,t}transferDOM(e){!this.dom||(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){Sl(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Pu(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=yo(t,this.attrs||{})),i&&(this.attrs=yo({class:i},this.attrs||{}))}domAtPos(e){return Ou(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.dirty|=6)}sync(e){var t;this.dom?this.dirty&4&&(ku(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(xo(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e);let i=this.dom.lastChild;for(;i&&ne.get(i)instanceof Et;)i=i.lastChild;if(!i||!this.length||i.nodeName!="BR"&&((t=ne.get(i))===null||t===void 0?void 0:t.isEditable)==!1&&(!N.ios||!this.children.some(n=>n instanceof ri))){let n=document.createElement("BR");n.cmIgnore=!0,this.dom.appendChild(n)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0;for(let t of this.children){if(!(t instanceof ri)||/[^ -~]/.test(t.text))return null;let i=Bn(t.dom);if(i.length!=1)return null;e+=i[0].width}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length}:null}coordsAt(e,t){return Nu(this,e,t)}become(e){return!1}get type(){return Se.Text}static find(e,t){for(let i=0,n=0;i=t){if(s instanceof Je)return s;if(o>t)break}n=o+s.breakAfter}return null}}class gi extends ne{constructor(e,t,i){super(),this.widget=e,this.length=t,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(e,t,i,n,s,o){return i&&(!(i instanceof gi)||!this.widget.compare(i.widget)||e>0&&s<=0||t0;){if(this.textOff==this.text.length){let{value:s,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer([]),this.curLine=null,e--;continue}else this.text=s,this.textOff=0}let n=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-i)),this.getLine().append(jn(new ri(this.text.slice(this.textOff,this.textOff+n)),t),i),this.atCursorPos=!0,this.textOff+=n,e-=n,i=0}}span(e,t,i,n){this.buildText(t-e,i,n),this.pos=t,this.openStart<0&&(this.openStart=n)}point(e,t,i,n,s,o){if(this.disallowBlockEffectsFor[o]&&i instanceof wi){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=t-e;if(i instanceof wi)if(i.block){let{type:a}=i;a==Se.WidgetAfter&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new gi(i.widget||new fa("div"),l,a))}else{let a=Kt.create(i.widget||new fa("span"),l,l?0:i.startSide),h=this.atCursorPos&&!a.isEditable&&s<=n.length&&(e0),u=!a.isEditable&&(er.some(e=>e)}),Dp=W.define({combine:r=>r.some(e=>e)});class Ns{constructor(e,t="nearest",i="nearest",n=5,s=5){this.range=e,this.y=t,this.x=i,this.yMargin=n,this.xMargin=s}map(e){return e.empty?this:new Ns(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin)}}const da=de.define({map:(r,e)=>r.map(e)});function ii(r,e,t){let i=r.facet(Vu);i.length?i[0](e):window.onerror?window.onerror(String(e),t,void 0,void 0,e):t?console.error(t+":",e):console.error(e)}const ur=W.define({combine:r=>r.length?r[0]:!0});let bp=0;const mn=W.define();class Mn{constructor(e,t,i,n){this.id=e,this.create=t,this.domEventHandlers=i,this.extension=n(this)}static define(e,t){const{eventHandlers:i,provide:n,decorations:s}=t||{};return new Mn(bp++,e,i,o=>{let l=[mn.of(o)];return s&&l.push(On.of(a=>{let h=a.plugin(o);return h?s(h):ge.none})),n&&l.push(n(o)),l})}static fromClass(e,t){return Mn.define(i=>new e(i),t)}}class Er{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(ii(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){ii(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){ii(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Wu=W.define(),bl=W.define(),On=W.define(),Ju=W.define(),Uu=W.define(),gn=W.define();class At{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new At(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toAu)break;s+=2}if(!a)return i;new At(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}}class Is{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=ve.empty(this.startState.doc.length);for(let o of i)this.changes=this.changes.compose(o.changes);let n=[];this.changes.iterChangedRanges((o,l,a,h)=>n.push(new At(o,l,a,h))),this.changedRanges=n;let s=e.hasFocus;s!=e.inputState.notifiedFocused&&(e.inputState.notifiedFocused=s,this.flags|=1)}static create(e,t,i){return new Is(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}var ze=function(r){return r[r.LTR=0]="LTR",r[r.RTL=1]="RTL",r}(ze||(ze={}));const So=ze.LTR,kp=ze.RTL;function Xu(r){let e=[];for(let t=0;t=t){if(l.level==i)return o;(s<0||(n!=0?n<0?l.fromt:e[s].level>l.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}}const oe=[];function Bp(r,e){let t=r.length,i=e==So?1:2,n=e==So?2:1;if(!r||i==1&&!Fp.test(r))return Ku(t);for(let o=0,l=i,a=i;o=0;p-=3)if(ut[p+1]==-u){let g=ut[p+2],y=g&2?i:g&4?g&1?n:i:0;y&&(oe[o]=oe[ut[p]]=y),l=p;break}}else{if(ut.length==189)break;ut[l++]=o,ut[l++]=h,ut[l++]=a}else if((d=oe[o])==2||d==1){let p=d==i;a=p?0:1;for(let g=l-3;g>=0;g-=3){let y=ut[g+2];if(y&2)break;if(p)ut[g+2]|=2;else{if(y&4)break;ut[g+2]|=4}}}for(let o=0;ol;){let u=h,d=oe[--h]!=2;for(;h>l&&d==(oe[h-1]!=2);)h--;s.push(new Pi(h,u,d?2:1))}else s.push(new Pi(l,o,0))}else for(let o=0;o1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=s+o}}readNode(e){if(e.cmIgnore)return;let t=ne.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+Math.min(t,i.offset))}}function pa(r){return r.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(r.nodeName)}class ma{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class ga extends ne{constructor(e){super(),this.view=e,this.compositionDeco=ge.none,this.decorations=[],this.dynamicDecorationMap=[],this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new Je],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new At(0,0,0,e.state.doc.length)],0)}get editorView(){return this.view}get length(){return this.view.state.doc.length}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:o,toA:l})=>lthis.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.view.inputState.composing<0?this.compositionDeco=ge.none:(e.transactions.length||this.dirty)&&(this.compositionDeco=Op(this.view,e.changes)),(N.ie||N.chrome)&&!this.compositionDeco.size&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,n=this.updateDeco(),s=Lp(i,n,e.changes);return t=At.extendWithRanges(t,s),this.dirty==0&&t.length==0?!1:(this.updateInner(t,e.startState.doc.length),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t);let{observer:i}=this.view;i.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=N.chrome||N.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.sync(s),this.dirty=0,s&&(s.written||i.selectionRange.focusNode!=s.node)&&(this.forceSelection=!0),this.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to=0?e[n]:null;if(!s)break;let{fromA:o,toA:l,fromB:a,toB:h}=s,{content:u,breakAtStart:d,openStart:p,openEnd:g}=Dl.build(this.view.state.doc,a,h,this.decorations,this.dynamicDecorationMap),{i:y,off:c}=i.findPos(l,1),{i:f,off:m}=i.findPos(o,-1);Cu(this,f,m,y,c,u,d,p,g)}}updateSelection(e=!1,t=!1){if((e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange(),!(t||this.mayControlSelection()))return;let i=this.forceSelection;this.forceSelection=!1;let n=this.view.state.selection.main,s=this.domAtPos(n.anchor),o=n.empty?s:this.domAtPos(n.head);if(N.gecko&&n.empty&&Mp(s)){let a=document.createTextNode("");this.view.observer.ignore(()=>s.node.insertBefore(a,s.node.childNodes[s.offset]||null)),s=o=new Re(a,0),i=!0}let l=this.view.observer.selectionRange;(i||!l.focusNode||!Os(s.node,s.offset,l.anchorNode,l.anchorOffset)||!Os(o.node,o.offset,l.focusNode,l.focusOffset))&&(this.view.observer.ignore(()=>{N.android&&N.chrome&&this.dom.contains(l.focusNode)&&Rp(l.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let a=Ms(this.view.root);if(a)if(n.empty){if(N.gecko){let h=Np(s.node,s.offset);if(h&&h!=3){let u=Gu(s.node,s.offset,h==1?1:-1);u&&(s=new Re(u,h==1?0:u.nodeValue.length))}}a.collapse(s.node,s.offset),n.bidiLevel!=null&&l.cursorBidiLevel!=null&&(l.cursorBidiLevel=n.bidiLevel)}else if(a.extend){a.collapse(s.node,s.offset);try{a.extend(o.node,o.offset)}catch{}}else{let h=document.createRange();n.anchor>n.head&&([s,o]=[o,s]),h.setEnd(o.node,o.offset),h.setStart(s.node,s.offset),a.removeAllRanges(),a.addRange(h)}}),this.view.observer.setSelectionRange(s,o)),this.impreciseAnchor=s.precise?null:new Re(l.anchorNode,l.anchorOffset),this.impreciseHead=o.precise?null:new Re(l.focusNode,l.focusOffset)}enforceCursorAssoc(){if(this.compositionDeco.size)return;let{view:e}=this,t=e.state.selection.main,i=Ms(e.root),{anchorNode:n,anchorOffset:s}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=Je.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let u=this.domAtPos(t.head+t.assoc);i.collapse(u.node,u.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let d=e.observer.selectionRange;e.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=t.from&&i.collapse(n,s)}mayControlSelection(){let e=this.view.root.activeElement;return e==this.dom||ws(this.dom,this.view.observer.selectionRange)&&!(e&&this.dom.contains(e))}nearest(e){for(let t=e;t;){let i=ne.get(t);if(i&&i.rootView==this)return i;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;to||e==o&&s.type!=Se.WidgetBefore&&s.type!=Se.WidgetAfter&&(!n||t==2||this.children[n-1].breakAfter||this.children[n-1].type==Se.WidgetBefore&&t>-2))return s.coordsAt(e-o,t);i=o}}measureVisibleLineHeights(e){let t=[],{from:i,to:n}=e,s=this.view.contentDOM.clientWidth,o=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==ze.LTR;for(let h=0,u=0;un)break;if(h>=i){let g=d.dom.getBoundingClientRect();if(t.push(g.height),o){let y=d.dom.lastChild,c=y?Bn(y):[];if(c.length){let f=c[c.length-1],m=a?f.right-g.left:g.right-f.left;m>l&&(l=m,this.minWidth=s,this.minWidthFrom=h,this.minWidthTo=p)}}}h=p+d.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?ze.RTL:ze.LTR}measureTextSize(){for(let n of this.children)if(n instanceof Je){let s=n.measureTextSize();if(s)return s}let e=document.createElement("div"),t,i;return e.className="cm-line",e.style.width="99999px",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let n=Bn(e.firstChild)[0];t=e.getBoundingClientRect().height,i=n?n.width/27:7,e.remove()}),{lineHeight:t,charWidth:i}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Au(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let s=n==t.viewports.length?null:t.viewports[n],o=s?s.from-1:this.length;if(o>i){let l=t.lineBlockAt(o).bottom-t.lineBlockAt(i).top;e.push(ge.replace({widget:new ya(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!s)break;i=s.to+1}return ge.set(e)}updateDeco(){let e=this.view.state.facet(On).map((t,i)=>(this.dynamicDecorationMap[i]=typeof t=="function")?t(this.view):t);for(let t=e.length;tt.anchor?-1:1),n;if(!i)return;!t.empty&&(n=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,n.left),top:Math.min(i.top,n.top),right:Math.max(i.right,n.right),bottom:Math.max(i.bottom,n.bottom)});let s=0,o=0,l=0,a=0;for(let u of this.view.state.facet(Uu).map(d=>d(this.view)))if(u){let{left:d,right:p,top:g,bottom:y}=u;d!=null&&(s=Math.max(s,d)),p!=null&&(o=Math.max(o,p)),g!=null&&(l=Math.max(l,g)),y!=null&&(a=Math.max(a,y))}let h={left:i.left-s,top:i.top-l,right:i.right+o,bottom:i.bottom+a};pp(this.view.scrollDOM,h,t.head0&&t<=0)r=r.childNodes[e-1],e=Tn(r);else if(r.nodeType==1&&e=0)r=r.childNodes[e],e=0;else return null}}function Np(r,e){return r.nodeType!=1?0:(e&&r.childNodes[e-1].contentEditable=="false"?1:0)|(e0;){let h=nt(n.text,o,!1);if(i(n.text.slice(h,o))!=a)break;o=h}for(;lr?e.left-r:Math.max(0,r-e.right)}function Hp(r,e){return e.top>r?e.top-r:Math.max(0,r-e.bottom)}function Fr(r,e){return r.tope.top+1}function xa(r,e){return er.bottom?{top:r.top,left:r.left,right:r.right,bottom:e}:r}function bo(r,e,t){let i,n,s,o,l=!1,a,h,u,d;for(let y=r.firstChild;y;y=y.nextSibling){let c=Bn(y);for(let f=0;fv||o==v&&s>x)&&(i=y,n=m,s=x,o=v,l=!x||(x>0?f0)),x==0?t>m.bottom&&(!u||u.bottomm.top)&&(h=y,d=m):u&&Fr(u,m)?u=va(u,m.bottom):d&&Fr(d,m)&&(d=xa(d,m.top))}}if(u&&u.bottom>=t?(i=a,n=u):d&&d.top<=t&&(i=h,n=d),!i)return{node:r,offset:0};let p=Math.max(n.left,Math.min(n.right,e));if(i.nodeType==3)return wa(i,p,t);if(l&&i.contentEditable!="false")return bo(i,p,t);let g=Array.prototype.indexOf.call(r.childNodes,i)+(e>=(n.left+n.right)/2?1:0);return{node:r,offset:g}}function wa(r,e,t){let i=r.nodeValue.length,n=-1,s=1e9,o=0;for(let l=0;lt?u.top-t:t-u.bottom)-1;if(u.left-1<=e&&u.right+1>=e&&d=(u.left+u.right)/2,g=p;if((N.chrome||N.gecko)&&$i(r,l).getBoundingClientRect().left==u.right&&(g=!p),d<=0)return{node:r,offset:l+(g?1:0)};n=l+(g?1:0),s=d}}}return{node:r,offset:n>-1?n:o>0?r.nodeValue.length:0}}function Yu(r,{x:e,y:t},i,n=-1){var s;let o=r.contentDOM.getBoundingClientRect(),l=o.top+r.viewState.paddingTop,a,{docHeight:h}=r.viewState,u=t-l;if(u<0)return 0;if(u>h)return r.state.doc.length;for(let m=r.defaultLineHeight/2,x=!1;a=r.elementAtHeight(u),a.type!=Se.Text;)for(;u=n>0?a.bottom+m:a.top-m,!(u>=0&&u<=h);){if(x)return i?null:0;x=!0,n=-n}t=l+u;let d=a.from;if(dr.viewport.to)return r.viewport.to==r.state.doc.length?r.state.doc.length:i?null:Sa(r,o,a,e,t);let p=r.dom.ownerDocument,g=r.root.elementFromPoint?r.root:p,y=g.elementFromPoint(e,t);y&&!r.contentDOM.contains(y)&&(y=null),y||(e=Math.max(o.left+1,Math.min(o.right-1,e)),y=g.elementFromPoint(e,t),y&&!r.contentDOM.contains(y)&&(y=null));let c,f=-1;if(y&&((s=r.docView.nearest(y))===null||s===void 0?void 0:s.isEditable)!=!1){if(p.caretPositionFromPoint){let m=p.caretPositionFromPoint(e,t);m&&({offsetNode:c,offset:f}=m)}else if(p.caretRangeFromPoint){let m=p.caretRangeFromPoint(e,t);m&&({startContainer:c,startOffset:f}=m,(!r.contentDOM.contains(c)||N.safari&&$p(c,f,e)||N.chrome&&Wp(c,f,e))&&(c=void 0))}}if(!c||!r.docView.dom.contains(c)){let m=Je.find(r.docView,d);if(!m)return u>a.top+a.height/2?a.to:a.from;({node:c,offset:f}=bo(m.dom,e,t))}return r.docView.posFromDOM(c,f)}function Sa(r,e,t,i,n){let s=Math.round((i-e.left)*r.defaultCharacterWidth);if(r.lineWrapping&&t.height>r.defaultLineHeight*1.5){let l=Math.floor((n-t.top)/r.defaultLineHeight);s+=l*r.viewState.heightOracle.lineLength}let o=r.state.sliceDoc(t.from,t.to);return t.from+op(o,s,r.state.tabSize)}function $p(r,e,t){let i;if(r.nodeType!=3||e!=(i=r.nodeValue.length))return!1;for(let n=r.nextSibling;n;n=n.nextSibling)if(n.nodeType!=1||n.nodeName!="BR")return!1;return $i(r,i-1,i).getBoundingClientRect().left>t}function Wp(r,e,t){if(e!=0)return!1;for(let n=r;;){let s=n.parentNode;if(!s||s.nodeType!=1||s.firstChild!=n)return!1;if(s.classList.contains("cm-line"))break;n=s}let i=r.nodeType==1?r.getBoundingClientRect():$i(r,0,Math.max(r.nodeValue.length,1)).getBoundingClientRect();return t-i.left>5}function Jp(r,e,t,i){let n=r.state.doc.lineAt(e.head),s=!i||!r.lineWrapping?null:r.coordsAtPos(e.assoc<0&&e.head>n.from?e.head-1:e.head);if(s){let a=r.dom.getBoundingClientRect(),h=r.textDirectionAt(n.from),u=r.posAtCoords({x:t==(h==ze.LTR)?a.right-1:a.left+1,y:(s.top+s.bottom)/2});if(u!=null)return M.cursor(u,t?-1:1)}let o=Je.find(r.docView,e.head),l=o?t?o.posAtEnd:o.posAtStart:t?n.to:n.from;return M.cursor(l,t?-1:1)}function Da(r,e,t,i){let n=r.state.doc.lineAt(e.head),s=r.bidiSpans(n),o=r.textDirectionAt(n.from);for(let l=e,a=null;;){let h=Tp(n,s,o,l,t),u=_u;if(!h){if(n.number==(t?r.state.doc.lines:1))return l;u=` +`,n=r.state.doc.line(n.number+(t?1:-1)),s=r.bidiSpans(n),h=M.cursor(t?n.from:n.to)}if(a){if(!a(u))return l}else{if(!i)return h;a=i(u)}l=h}}function Up(r,e,t){let i=r.state.charCategorizer(e),n=i(t);return s=>{let o=i(s);return n==Ot.Space&&(n=o),n==o}}function Xp(r,e,t,i){let n=e.head,s=t?1:-1;if(n==(t?r.state.doc.length:0))return M.cursor(n,e.assoc);let o=e.goalColumn,l,a=r.contentDOM.getBoundingClientRect(),h=r.coordsAtPos(n),u=r.documentTop;if(h)o==null&&(o=h.left-a.left),l=s<0?h.top:h.bottom;else{let g=r.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,r.defaultCharacterWidth*(n-g.from))),l=(s<0?g.top:g.bottom)+u}let d=a.left+o,p=i??r.defaultLineHeight>>1;for(let g=0;;g+=10){let y=l+(p+g)*s,c=Yu(r,{x:d,y},!1,s);if(ya.bottom||(s<0?cn))return M.cursor(c,e.assoc,void 0,o)}}function Br(r,e,t){let i=r.state.facet(Ju).map(n=>n(r));for(;;){let n=!1;for(let s of i)s.between(t.from-1,t.from+1,(o,l,a)=>{t.from>o&&t.fromt.from?M.cursor(o,1):M.cursor(l,-1),n=!0)});if(!n)return t}}class Kp{constructor(e){this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.chromeScrollHack=-1,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.mouseSelection=null;for(let t in Ae){let i=Ae[t];e.contentDOM.addEventListener(t,n=>{!ba(e,n)||this.ignoreDuringComposition(n)||t=="keydown"&&this.keydown(e,n)||(this.mustFlushObserver(n)&&e.observer.forceFlush(),this.runCustomHandlers(t,e,n)?n.preventDefault():i(e,n))},ko[t]),this.registeredEvents.push(t)}N.chrome&&N.chrome_version==102&&e.scrollDOM.addEventListener("wheel",()=>{this.chromeScrollHack<0?e.contentDOM.style.pointerEvents="none":window.clearTimeout(this.chromeScrollHack),this.chromeScrollHack=setTimeout(()=>{this.chromeScrollHack=-1,e.contentDOM.style.pointerEvents=""},100)},{passive:!0}),this.notifiedFocused=e.hasFocus,N.safari&&e.contentDOM.addEventListener("input",()=>null)}setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}ensureHandlers(e,t){var i;let n;this.customHandlers=[];for(let s of t)if(n=(i=s.update(e).spec)===null||i===void 0?void 0:i.domEventHandlers){this.customHandlers.push({plugin:s.value,handlers:n});for(let o in n)this.registeredEvents.indexOf(o)<0&&o!="scroll"&&(this.registeredEvents.push(o),e.contentDOM.addEventListener(o,l=>{!ba(e,l)||this.runCustomHandlers(o,e,l)&&l.preventDefault()}))}}runCustomHandlers(e,t,i){for(let n of this.customHandlers){let s=n.handlers[e];if(s)try{if(s.call(n.plugin,i,t)||i.defaultPrevented)return!0}catch(o){ii(t.state,o)}}return!1}runScrollHandlers(e,t){this.lastScrollTop=e.scrollDOM.scrollTop,this.lastScrollLeft=e.scrollDOM.scrollLeft;for(let i of this.customHandlers){let n=i.handlers.scroll;if(n)try{n.call(i.plugin,t,e)}catch(s){ii(e.state,s)}}}keydown(e,t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&Date.now()n.keyCode==t.keyCode))&&!t.ctrlKey||_p.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=i||t,setTimeout(()=>this.flushIOSKey(e),250),!0):!1}flushIOSKey(e){let t=this.pendingIOSKey;return t?(this.pendingIOSKey=void 0,Oi(e.contentDOM,t.key,t.keyCode)):!1}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:N.safari&&!N.ios&&Date.now()-this.compositionEndedAt<100?(this.compositionEndedAt=0,!0):!1:!1}mustFlushObserver(e){return e.type=="keydown"&&e.keyCode!=229}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.mouseSelection&&this.mouseSelection.update(e),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}const Zu=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],_p="dthko",Qu=[16,17,18,20,91,92,224,225];class jp{constructor(e,t,i,n){this.view=e,this.style=i,this.mustSelect=n,this.lastEvent=t;let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(G.allowMultipleSelections)&&qp(e,t),this.dragMove=Gp(e,t),this.dragging=Yp(e,t)&&nc(t)==1?null:!1,this.dragging===!1&&(t.preventDefault(),this.select(t))}move(e){if(e.buttons==0)return this.destroy();this.dragging===!1&&this.select(this.lastEvent=e)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}select(e){let t=this.style.get(e,this.extend,this.multiple);(this.mustSelect||!t.eq(this.view.state.selection)||t.main.assoc!=this.view.state.selection.main.assoc)&&this.view.dispatch({selection:t,userEvent:"select.pointer",scrollIntoView:!0}),this.mustSelect=!1}update(e){e.docChanged&&this.dragging&&(this.dragging=this.dragging.map(e.changes)),this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function qp(r,e){let t=r.state.facet(Lu);return t.length?t[0](e):N.mac?e.metaKey:e.ctrlKey}function Gp(r,e){let t=r.state.facet(Ru);return t.length?t[0](e):N.mac?!e.altKey:!e.ctrlKey}function Yp(r,e){let{main:t}=r.state.selection;if(t.empty)return!1;let i=Ms(r.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let s=0;s=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function ba(r,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=r.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=ne.get(t))&&i.ignoreEvent(e))return!1;return!0}const Ae=Object.create(null),ko=Object.create(null),ec=N.ie&&N.ie_version<15||N.ios&&N.webkit_version<604;function Zp(r){let e=r.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{r.focus(),t.remove(),tc(r,t.value)},50)}function tc(r,e){let{state:t}=r,i,n=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(Ao!=null&&t.selection.ranges.every(a=>a.empty)&&Ao==s.toString()){let a=-1;i=t.changeByRange(h=>{let u=t.doc.lineAt(h.from);if(u.from==a)return{range:h};a=u.from;let d=t.toText((o?s.line(n++).text:e)+t.lineBreak);return{changes:{from:u.from,insert:d},range:M.cursor(h.from+d.length)}})}else o?i=t.changeByRange(a=>{let h=s.line(n++);return{changes:{from:a.from,to:a.to,insert:h.text},range:M.cursor(a.from+h.length)}}):i=t.replaceSelection(s);r.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Ae.keydown=(r,e)=>{r.inputState.setSelectionOrigin("select"),e.keyCode==27?r.inputState.lastEscPress=Date.now():Qu.indexOf(e.keyCode)<0&&(r.inputState.lastEscPress=0)};Ae.touchstart=(r,e)=>{r.inputState.lastTouchTime=Date.now(),r.inputState.setSelectionOrigin("select.pointer")};Ae.touchmove=r=>{r.inputState.setSelectionOrigin("select.pointer")};ko.touchstart=ko.touchmove={passive:!0};Ae.mousedown=(r,e)=>{if(r.observer.flush(),r.inputState.lastTouchTime>Date.now()-2e3)return;let t=null;for(let i of r.state.facet(zu))if(t=i(r,e),t)break;if(!t&&e.button==0&&(t=tm(r,e)),t){let i=r.root.activeElement!=r.contentDOM;i&&r.observer.ignore(()=>bu(r.contentDOM)),r.inputState.startMouseSelection(new jp(r,e,t,i))}};function ka(r,e,t,i){if(i==1)return M.cursor(e,t);if(i==2)return zp(r.state,e,t);{let n=Je.find(r.docView,e),s=r.state.doc.lineAt(n?n.posAtEnd:e),o=n?n.posAtStart:s.from,l=n?n.posAtEnd:s.to;return lr>=e.top&&r<=e.bottom,Aa=(r,e,t)=>ic(e,t)&&r>=t.left&&r<=t.right;function Qp(r,e,t,i){let n=Je.find(r.docView,e);if(!n)return 1;let s=e-n.posAtStart;if(s==0)return 1;if(s==n.length)return-1;let o=n.coordsAt(s,-1);if(o&&Aa(t,i,o))return-1;let l=n.coordsAt(s,1);return l&&Aa(t,i,l)?1:o&&ic(i,o)?-1:1}function Ca(r,e){let t=r.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:Qp(r,t,e.clientX,e.clientY)}}const em=N.ie&&N.ie_version<=11;let Ea=null,Fa=0,Ba=0;function nc(r){if(!em)return r.detail;let e=Ea,t=Ba;return Ea=r,Ba=Date.now(),Fa=!e||t>Date.now()-400&&Math.abs(e.clientX-r.clientX)<2&&Math.abs(e.clientY-r.clientY)<2?(Fa+1)%3:1}function tm(r,e){let t=Ca(r,e),i=nc(e),n=r.state.selection,s=t,o=e;return{update(l){l.docChanged&&(t.pos=l.changes.mapPos(t.pos),n=n.map(l.changes),o=null)},get(l,a,h){let u;o&&l.clientX==o.clientX&&l.clientY==o.clientY?u=s:(u=s=Ca(r,l),o=l);let d=ka(r,u.pos,u.bias,i);if(t.pos!=u.pos&&!a){let p=ka(r,t.pos,t.bias,i),g=Math.min(p.from,d.from),y=Math.max(p.to,d.to);d=g1&&n.ranges.some(p=>p.eq(d))?im(n,d):h?n.addRange(d):M.create([d])}}}function im(r,e){for(let t=0;;t++)if(r.ranges[t].eq(e))return M.create(r.ranges.slice(0,t).concat(r.ranges.slice(t+1)),r.mainIndex==t?0:r.mainIndex-(r.mainIndex>t?1:0))}Ae.dragstart=(r,e)=>{let{selection:{main:t}}=r.state,{mouseSelection:i}=r.inputState;i&&(i.dragging=t),e.dataTransfer&&(e.dataTransfer.setData("Text",r.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove")};function Ta(r,e,t,i){if(!t)return;let n=r.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:s}=r.inputState,o=i&&s&&s.dragging&&s.dragMove?{from:s.dragging.from,to:s.dragging.to}:null,l={from:n,insert:t},a=r.state.changes(o?[o,l]:l);r.focus(),r.dispatch({changes:a,selection:{anchor:a.mapPos(n,-1),head:a.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"})}Ae.drop=(r,e)=>{if(!e.dataTransfer)return;if(r.state.readOnly)return e.preventDefault();let t=e.dataTransfer.files;if(t&&t.length){e.preventDefault();let i=Array(t.length),n=0,s=()=>{++n==t.length&&Ta(r,e,i.filter(o=>o!=null).join(r.state.lineBreak),!1)};for(let o=0;o{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),s()},l.readAsText(t[o])}}else Ta(r,e,e.dataTransfer.getData("Text"),!0)};Ae.paste=(r,e)=>{if(r.state.readOnly)return e.preventDefault();r.observer.flush();let t=ec?null:e.clipboardData;t?(tc(r,t.getData("text/plain")),e.preventDefault()):Zp(r)};function nm(r,e){let t=r.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),r.focus()},50)}function sm(r){let e=[],t=[],i=!1;for(let n of r.selection.ranges)n.empty||(e.push(r.sliceDoc(n.from,n.to)),t.push(n));if(!e.length){let n=-1;for(let{from:s}of r.selection.ranges){let o=r.doc.lineAt(s);o.number>n&&(e.push(o.text),t.push({from:o.from,to:Math.min(r.doc.length,o.to+1)})),n=o.number}i=!0}return{text:e.join(r.lineBreak),ranges:t,linewise:i}}let Ao=null;Ae.copy=Ae.cut=(r,e)=>{let{text:t,ranges:i,linewise:n}=sm(r.state);if(!t&&!n)return;Ao=n?t:null;let s=ec?null:e.clipboardData;s?(e.preventDefault(),s.clearData(),s.setData("text/plain",t)):nm(r,t),e.type=="cut"&&!r.state.readOnly&&r.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"})};function sc(r){setTimeout(()=>{r.hasFocus!=r.inputState.notifiedFocused&&r.update([])},10)}Ae.focus=r=>{r.inputState.lastFocusTime=Date.now(),!r.scrollDOM.scrollTop&&(r.inputState.lastScrollTop||r.inputState.lastScrollLeft)&&(r.scrollDOM.scrollTop=r.inputState.lastScrollTop,r.scrollDOM.scrollLeft=r.inputState.lastScrollLeft),sc(r)};Ae.blur=r=>{r.observer.clearSelectionRange(),sc(r)};Ae.compositionstart=Ae.compositionupdate=r=>{r.inputState.compositionFirstChange==null&&(r.inputState.compositionFirstChange=!0),r.inputState.composing<0&&(r.inputState.composing=0)};Ae.compositionend=r=>{r.inputState.composing=-1,r.inputState.compositionEndedAt=Date.now(),r.inputState.compositionFirstChange=null,N.chrome&&N.android&&r.observer.flushSoon(),setTimeout(()=>{r.inputState.composing<0&&r.docView.compositionDeco.size&&r.update([])},50)};Ae.contextmenu=r=>{r.inputState.lastContextMenu=Date.now()};Ae.beforeinput=(r,e)=>{var t;let i;if(N.chrome&&N.android&&(i=Zu.find(n=>n.inputType==e.inputType))&&(r.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let n=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var s;(((s=window.visualViewport)===null||s===void 0?void 0:s.height)||0)>n+10&&r.hasFocus&&(r.contentDOM.blur(),r.focus())},100)}};const Ma=["pre-wrap","normal","pre-line","break-spaces"];class rm{constructor(e){this.lineWrapping=e,this.doc=K.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength)),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Ma.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i-1,l=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=i,this.lineLength=n,l){this.heightSamples={};for(let a=0;a0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>Ss&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return Ke.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,n){let s=this;for(let o=n.length-1;o>=0;o--){let{fromA:l,toA:a,fromB:h,toB:u}=n[o],d=s.lineAt(l,te.ByPosNoHeight,t,0,0),p=d.to>=a?d:s.lineAt(a,te.ByPosNoHeight,t,0,0);for(u+=p.to-a,a=p.to;o>0&&d.from<=n[o-1].toA;)l=n[o-1].fromA,h=n[o-1].fromB,o--,ls*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(s>n*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,s-=l.size}else break;else if(n=s&&o(this.blockAt(0,i,n,s))}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setHeight(e,n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ye extends rc{constructor(e,t){super(e,t,Se.Text),this.collapsed=0,this.widgetHeight=0}replace(e,t,i){let n=i[0];return i.length==1&&(n instanceof Ye||n instanceof Ee&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof Ee?n=new Ye(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):Ke.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setHeight(e,n.heights[n.index++]):(i||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Ee extends Ke{constructor(e){super(e,0)}lines(e,t){let i=e.lineAt(t).number,n=e.lineAt(t+this.length).number;return{firstLine:i,lastLine:n,lineHeight:this.height/(n-i+1)}}blockAt(e,t,i,n){let{firstLine:s,lastLine:o,lineHeight:l}=this.lines(t,n),a=Math.max(0,Math.min(o-s,Math.floor((e-i)/l))),{from:h,length:u}=t.line(s+a);return new jt(h,u,i+l*a,l,Se.Text)}lineAt(e,t,i,n,s){if(t==te.ByHeight)return this.blockAt(e,i,n,s);if(t==te.ByPosNoHeight){let{from:d,to:p}=i.lineAt(e);return new jt(d,p-d,0,0,Se.Text)}let{firstLine:o,lineHeight:l}=this.lines(i,s),{from:a,length:h,number:u}=i.lineAt(e);return new jt(a,h,n+l*(u-o),l,Se.Text)}forEachLine(e,t,i,n,s,o){let{firstLine:l,lineHeight:a}=this.lines(i,s);for(let h=Math.max(e,s),u=Math.min(s+this.length,t);h<=u;){let d=i.lineAt(h);h==e&&(n+=a*(d.number-l)),o(new jt(d.from,d.length,n,a,Se.Text)),n+=a,h=d.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let s=i[i.length-1];s instanceof Ee?i[i.length-1]=new Ee(s.length+n):i.push(null,new Ee(n-1))}if(e>0){let s=i[0];s instanceof Ee?i[0]=new Ee(e+s.length):i.unshift(new Ee(e-1),null)}return Ke.of(i)}decomposeLeft(e,t){t.push(new Ee(e-1),null)}decomposeRight(e,t){t.push(null,new Ee(this.length-e-1))}updateHeight(e,t=0,i=!1,n){let s=t+this.length;if(n&&n.from<=t+this.length&&n.more){let o=[],l=Math.max(t,n.from),a=-1,h=e.heightChanged;for(n.from>t&&o.push(new Ee(n.from-t-1).updateHeight(e,t));l<=s&&n.more;){let d=e.doc.lineAt(l).length;o.length&&o.push(null);let p=n.heights[n.index++];a==-1?a=p:Math.abs(p-a)>=Ss&&(a=-2);let g=new Ye(d,p);g.outdated=!1,o.push(g),l+=d+1}l<=s&&o.push(null,new Ee(s-l).updateHeight(e,l));let u=Ke.of(o);return e.heightChanged=h||a<0||Math.abs(u.height-this.height)>=Ss||Math.abs(a-this.lines(e.doc,t).lineHeight)>=Ss,u}else(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class lm extends Ke{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,n){let s=i+this.left.height;return el))return h;let u=t==te.ByPosNoHeight?te.ByPosNoHeight:te.ByPos;return a?h.join(this.right.lineAt(l,u,i,o,l)):this.left.lineAt(l,u,i,n,s).join(h)}forEachLine(e,t,i,n,s,o){let l=n+this.left.height,a=s+this.left.length+this.break;if(this.break)e=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,te.ByPos,i,n,s);e=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let n=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let l of i)s.push(l);if(e>0&&Oa(s,o-1),t=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e2*t.size||t.size>2*e.size?Ke.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,n){let{left:s,right:o}=this,l=t+s.length+this.break,a=null;return n&&n.from<=t+s.length&&n.more?a=s=s.updateHeight(e,t,i,n):s.updateHeight(e,t,i),n&&n.from<=l+o.length&&n.more?a=o=o.updateHeight(e,l,i,n):o.updateHeight(e,l,i),a?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Oa(r,e){let t,i;r[e]==null&&(t=r[e-1])instanceof Ee&&(i=r[e+1])instanceof Ee&&r.splice(e-1,3,new Ee(t.length+1+i.length))}const am=5;class kl{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof Ye?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Ye(i-this.pos,-1)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e=am)&&this.addLineDeco(n,s)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenToe&&this.nodes.push(new Ye(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new Ee(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ye)return e;let t=new Ye(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine(),e.type==Se.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,e.type!=Se.WidgetBefore&&(this.covering=e)}addLineDeco(e,t){let i=this.ensureLine();i.length+=t,i.collapsed+=t,i.widgetHeight=Math.max(i.widgetHeight,e),this.writtenTo=this.pos=this.pos+t}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ye)&&!this.isCovered?this.nodes.push(new Ye(0,-1)):(this.writtenTou.clientHeight||u.scrollWidth>u.clientWidth)&&d.overflow!="visible"){let p=u.getBoundingClientRect();s=Math.max(s,p.left),o=Math.min(o,p.right),l=Math.max(l,p.top),a=h==r.parentNode?p.bottom:Math.min(a,p.bottom)}h=d.position=="absolute"||d.position=="fixed"?u.offsetParent:u.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function fm(r,e){let t=r.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Tr{constructor(e,t,i){this.from=e,this.to=t,this.size=i}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;itypeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new rm(t),this.stateDeco=e.facet(On).filter(i=>typeof i!="function"),this.heightMap=Ke.empty().applyChanges(this.stateDeco,K.empty,this.heightOracle.setDoc(e.doc),[new At(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ge.set(this.lineGaps.map(i=>i.draw(!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some(({from:s,to:o})=>n>=s&&n<=o)){let{from:s,to:o}=this.lineBlockAt(n);e.push(new qn(s,o))}}this.viewports=e.sort((i,n)=>i.from-n.from),this.scaler=this.heightMap.height<=7e6?Na:new gm(this.heightOracle.doc,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.state.doc,0,0,e=>{this.viewportLines.push(this.scaler.scale==1?e:yn(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(On).filter(h=>typeof h!="function");let n=e.changedRanges,s=At.extendWithRanges(n,hm(i,this.stateDeco,e?e.changes:ve.empty(this.state.doc.length))),o=this.heightMap.height;this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),this.heightMap.height!=o&&(e.flags|=2);let l=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.headl.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,t));let a=!e.changes.empty||e.flags&2||l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,this.updateForViewport(),a&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>2e3<<1)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Dp)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),n=this.heightOracle,s=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?ze.RTL:ze.LTR;let o=this.heightOracle.mustRefreshForWrapping(s),l=o||this.mustMeasureContent||this.contentDOMHeight!=t.clientHeight;this.contentDOMHeight=t.clientHeight,this.mustMeasureContent=!1;let a=0,h=0,u=parseInt(i.paddingTop)||0,d=parseInt(i.paddingBottom)||0;(this.paddingTop!=u||this.paddingBottom!=d)&&(this.paddingTop=u,this.paddingBottom=d,a|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,a|=8);let p=(this.printing?fm:cm)(t,this.paddingTop),g=p.top-this.pixelViewport.top,y=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let c=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(c!=this.inView&&(this.inView=c,c&&(l=!0)),!this.inView&&!this.scrollTarget)return 0;let f=t.clientWidth;if((this.contentDOMWidth!=f||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=f,this.editorHeight=e.scrollDOM.clientHeight,a|=8),l){let x=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(x)&&(o=!0),o||n.lineWrapping&&Math.abs(f-this.contentDOMWidth)>n.charWidth){let{lineHeight:v,charWidth:S}=e.docView.measureTextSize();o=v>0&&n.refresh(s,v,S,f/S,x),o&&(e.docView.minWidth=0,a|=8)}g>0&&y>0?h=Math.max(g,y):g<0&&y<0&&(h=Math.min(g,y)),n.heightChanged=!1;for(let v of this.viewports){let S=v.from==this.viewport.from?x:e.docView.measureVisibleLineHeights(v);this.heightMap=(o?Ke.empty().applyChanges(this.stateDeco,K.empty,this.heightOracle,[new At(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new om(v.from,S))}n.heightChanged&&(a|=2)}let m=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return m&&(this.viewport=this.getViewport(h,this.scrollTarget)),this.updateForViewport(),(a&2||m)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>2e3<<1)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),n=this.heightMap,s=this.state.doc,{visibleTop:o,visibleBottom:l}=this,a=new qn(n.lineAt(o-i*1e3,te.ByHeight,s,0,0).from,n.lineAt(l+(1-i)*1e3,te.ByHeight,s,0,0).to);if(t){let{head:h}=t.range;if(ha.to){let u=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),d=n.lineAt(h,te.ByPos,s,0,0),p;t.y=="center"?p=(d.top+d.bottom)/2-u/2:t.y=="start"||t.y=="nearest"&&h=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&s>1,o=n<<1;if(this.defaultTextDirection!=ze.LTR&&!i)return[];let l=[],a=(h,u,d,p)=>{if(u-hh&&ff.from>=d.from&&f.to<=d.to&&Math.abs(f.from-h)f.fromm));if(!c){if(uf.from<=u&&f.to>=u)){let f=t.moveToLineBoundary(M.cursor(u),!1,!0).head;f>h&&(u=f)}c=new Tr(h,u,this.gapSize(d,h,u,p))}l.push(c)};for(let h of this.viewportLines){if(h.lengthh.from&&a(h.from,p,h,u),gt.draw(this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];me.spans(e,this.viewport.from,this.viewport.to,{span(n,s){t.push({from:n,to:s})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some((n,s)=>n.from!=t[s].from||n.to!=t[s].to);return this.visibleRanges=t,i?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||yn(this.heightMap.lineAt(e,te.ByPos,this.state.doc,0,0),this.scaler)}lineBlockAtHeight(e){return yn(this.heightMap.lineAt(this.scaler.fromDOM(e),te.ByHeight,this.state.doc,0,0),this.scaler)}elementAtHeight(e){return yn(this.heightMap.blockAt(this.scaler.fromDOM(e),this.state.doc,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class qn{constructor(e,t){this.from=e,this.to=t}}function pm(r,e,t){let i=[],n=r,s=0;return me.spans(t,r,e,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),s+=o-n),n=l}},20),n=1)return e[e.length-1].to;let i=Math.floor(r*t);for(let n=0;;n++){let{from:s,to:o}=e[n],l=o-s;if(i<=l)return s+i;i-=l}}function Yn(r,e){let t=0;for(let{from:i,to:n}of r.ranges){if(e<=n){t+=e-i;break}t+=n-i}return t/r.total}function mm(r,e){for(let t of r)if(e(t))return t}const Na={toDOM(r){return r},fromDOM(r){return r},scale:1};class gm{constructor(e,t,i){let n=0,s=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,te.ByPos,e,0,0).top,u=t.lineAt(a,te.ByPos,e,0,0).bottom;return n+=u-h,{from:l,to:a,top:h,bottom:u,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(t.height-n);for(let l of this.viewports)l.domTop=o+(l.top-s)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),s=l.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let s=tyn(n,e)):r.type)}const Zn=W.define({combine:r=>r.join(" ")}),Co=W.define({combine:r=>r.indexOf(!0)>-1}),Eo=Vi.newName(),oc=Vi.newName(),lc=Vi.newName(),ac={"&light":"."+oc,"&dark":"."+lc};function Fo(r,e,t){return new Vi(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return r;if(!t||!t[n])throw new RangeError(`Unsupported selector: ${n}`);return t[n]}):r+" "+i}})}const ym=Fo("."+Eo,{"&.cm-editor":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,minHeight:"100%",display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},"&.cm-focused .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",left:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},ac);class xm{constructor(e,t,i,n){this.typeOver=n,this.bounds=null,this.text="";let{impreciseHead:s,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let l=s||o?[]:wm(e),a=new ju(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Sm(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!Hi(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),h=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!Hi(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset);this.newSel=M.single(h,a)}}}function hc(r,e){let t,{newSel:i}=e,n=r.state.selection.main;if(e.bounds){let{from:s,to:o}=e.bounds,l=n.from,a=null;(r.inputState.lastKeyCode===8&&r.inputState.lastKeyTime>Date.now()-100||N.android&&e.text.length=n.from&&t.to<=n.to&&(t.from!=n.from||t.to!=n.to)&&n.to-n.from-(t.to-t.from)<=4?t={from:n.from,to:n.to,insert:r.state.doc.slice(n.from,t.from).append(t.insert).append(r.state.doc.slice(t.to,n.to))}:(N.mac||N.android)&&t&&t.from==t.to&&t.from==n.head-1&&/^\. ?$/.test(t.insert.toString())?(i&&t.insert.length==2&&(i=M.single(i.main.anchor-1,i.main.head-1)),t={from:n.from,to:n.to,insert:K.of([" "])}):N.chrome&&t&&t.from==t.to&&t.from==n.head&&t.insert.toString()==` + `&&r.lineWrapping&&(i&&(i=M.single(i.main.anchor-1,i.main.head-1)),t={from:n.from,to:n.to,insert:K.of([" "])}),t){let s=r.state;if(N.ios&&r.inputState.flushIOSKey(r)||N.android&&(t.from==n.from&&t.to==n.to&&t.insert.length==1&&t.insert.lines==2&&Oi(r.contentDOM,"Enter",13)||t.from==n.from-1&&t.to==n.to&&t.insert.length==0&&Oi(r.contentDOM,"Backspace",8)||t.from==n.from&&t.to==n.to+1&&t.insert.length==0&&Oi(r.contentDOM,"Delete",46)))return!0;let o=t.insert.toString();if(r.state.facet(Hu).some(h=>h(r,t.from,t.to,o)))return!0;r.inputState.composing>=0&&r.inputState.composing++;let l;if(t.from>=n.from&&t.to<=n.to&&t.to-t.from>=(n.to-n.from)/3&&(!i||i.main.empty&&i.main.from==t.from+t.insert.length)&&r.inputState.composing<0){let h=n.fromt.to?s.sliceDoc(t.to,n.to):"";l=s.replaceSelection(r.state.toText(h+t.insert.sliceString(0,void 0,r.state.lineBreak)+u))}else{let h=s.changes(t),u=i&&!s.selection.main.eq(i.main)&&i.main.to<=h.newLength?i.main:void 0;if(s.selection.ranges.length>1&&r.inputState.composing>=0&&t.to<=n.to&&t.to>=n.to-10){let d=r.state.sliceDoc(t.from,t.to),p=qu(r)||r.state.doc.lineAt(n.head),g=n.to-t.to,y=n.to-n.from;l=s.changeByRange(c=>{if(c.from==n.from&&c.to==n.to)return{changes:h,range:u||c.map(h)};let f=c.to-g,m=f-d.length;if(c.to-c.from!=y||r.state.sliceDoc(m,f)!=d||p&&c.to>=p.from&&c.from<=p.to)return{range:c};let x=s.changes({from:m,to:f,insert:t.insert}),v=c.to-n.to;return{changes:x,range:u?M.range(Math.max(0,u.anchor+v),Math.max(0,u.head+v)):c.map(x)}})}else l={changes:h,selection:u&&s.selection.replaceRange(u)}}let a="input.type";return r.composing&&(a+=".compose",r.inputState.compositionFirstChange&&(a+=".start",r.inputState.compositionFirstChange=!1)),r.dispatch(l,{scrollIntoView:!0,userEvent:a}),!0}else if(i&&!i.main.eq(n)){let s=!1,o="select";return r.inputState.lastSelectionTime>Date.now()-50&&(r.inputState.lastSelectionOrigin=="select"&&(s=!0),o=r.inputState.lastSelectionOrigin),r.dispatch({selection:i,scrollIntoView:s,userEvent:o}),!0}else return!1}function vm(r,e,t,i){let n=Math.min(r.length,e.length),s=0;for(;s0&&l>0&&r.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,s-Math.min(o,l));t-=o+a-s}if(o=o?s-t:0;s-=a,l=s+(l-o),o=s}else if(l=l?s-t:0;s-=a,o=s+(o-l),l=s}return{from:s,toA:o,toB:l}}function wm(r){let e=[];if(r.root.activeElement!=r.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:s}=r.observer.selectionRange;return t&&(e.push(new ma(t,i)),(n!=t||s!=i)&&e.push(new ma(n,s))),e}function Sm(r,e){if(r.length==0)return null;let t=r[0].pos,i=r.length==2?r[1].pos:t;return t>-1&&i>-1?M.single(t+e,i+e):null}const Dm={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Mr=N.ie&&N.ie_version<=11;class bm{constructor(e){this.view=e,this.active=!1,this.selectionRange=new mp,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.resize=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(N.ie&&N.ie_version<=11||N.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Mr&&(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),typeof ResizeObserver=="function"&&(this.resize=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?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")))},{}),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(e){this.view.inputState.runScrollHandlers(this.view,e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(){this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500)}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(ur)?i.root.activeElement!=this.dom:!ws(i.dom,n))return;let s=n.anchorNode&&i.docView.nearest(n.anchorNode);if(s&&s.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(N.ie&&N.ie_version<=11||N.android&&N.chrome)&&!i.state.selection.main.empty&&n.focusNode&&Os(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=N.safari&&e.root.nodeType==11&&fp(this.dom.ownerDocument)==this.dom&&km(this.view)||Ms(e.root);if(!t||this.selectionRange.eq(t))return!1;let i=ws(this.dom,t);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),!this.flush()&&s.force&&Oi(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}processRecords(){let e=this.queue;for(let s of this.observer.takeRecords())e.push(s);e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let s of e){let o=this.readMutation(s);!o||(o.typeOver&&(n=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&ws(this.dom,this.selectionRange);return e<0&&!n?null:(e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1,new xm(this.view,e,t,i))}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return!1;let i=this.view.state,n=hc(this.view,t);return this.view.state==i&&this.view.update([]),n}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.dirty|=4),e.type=="childList"){let i=Ia(t,e.previousSibling||e.target.previousSibling,-1),n=Ia(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:n?t.posBefore(n):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resize)===null||i===void 0||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}}function Ia(r,e,t){for(;e;){let i=ne.get(e);if(i&&i.parent==r)return i;let n=e.parentNode;e=n!=r.dom?n:t>0?e.nextSibling:e.previousSibling}return null}function km(r){let e=null;function t(a){a.preventDefault(),a.stopImmediatePropagation(),e=a.getTargetRanges()[0]}if(r.contentDOM.addEventListener("beforeinput",t,!0),r.dom.ownerDocument.execCommand("indent"),r.contentDOM.removeEventListener("beforeinput",t,!0),!e)return null;let i=e.startContainer,n=e.startOffset,s=e.endContainer,o=e.endOffset,l=r.docView.domAtPos(r.state.selection.main.anchor);return Os(l.node,l.offset,s,o)&&([i,n,s,o]=[s,o,i,n]),{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:o}}class q{constructor(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.style.cssText="position: absolute; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),this._dispatch=e.dispatch||(t=>this.update([t])),this.dispatch=this.dispatch.bind(this),this._root=e.root||gp(e.parent)||document,this.viewState=new Pa(e.state||G.create(e)),this.plugins=this.state.facet(mn).map(t=>new Er(t));for(let t of this.plugins)t.update(this);this.observer=new bm(this),this.inputState=new Kp(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new ga(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}dispatch(...e){this._dispatch(e.length==1&&e[0]instanceof we?e[0]:this.state.update(...e))}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,n,s=this.state;for(let h of e){if(h.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=h.state}if(this.destroyed){this.viewState.state=s;return}let o=this.observer.delayedAndroidKey,l=null;if(o?(this.observer.clearDelayedAndroidKey(),l=this.observer.readChange(),(l&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(l=null)):this.observer.clear(),s.facet(G.phrases)!=this.state.facet(G.phrases))return this.setState(s);n=Is.create(this,s,e);let a=this.viewState.scrollTarget;try{this.updateState=2;for(let h of e){if(a&&(a=a.map(h.changes)),h.scrollIntoView){let{main:u}=h.state.selection;a=new Ns(u.empty?u:M.cursor(u.head,u.head>u.anchor?-1:1))}for(let u of h.effects)u.is(da)&&(a=u.value)}this.viewState.update(n,a),this.bidiCache=Ls.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),t=this.docView.update(n),this.state.facet(gn)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(h=>h.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(Zn)!=n.state.facet(Zn)&&(this.viewState.mustMeasureContent=!0),(t||i||a||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!n.empty)for(let h of this.state.facet(wo))h(n);l&&!hc(this,l)&&o.force&&Oi(this.contentDOM,o.key,o.keyCode)}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new Pa(e),this.plugins=e.facet(mn).map(i=>new Er(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView=new ga(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(mn),i=e.state.facet(mn);if(t!=i){let n=[];for(let s of i){let o=t.indexOf(s);if(o<0)n.push(new Er(s));else{let l=this.plugins[o];l.mustUpdate=e,n.push(l)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=n,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let n of this.plugins)n.mustUpdate=e;for(let n=0;n-1&&cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,{scrollHeight:i,scrollTop:n,clientHeight:s}=this.scrollDOM,o=n>i-s-4?i:n;try{for(let l=0;;l++){this.updateState=1;let a=this.viewport,h=this.viewState.lineBlockAtHeight(o),u=this.viewState.measure(this);if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let d=[];u&4||([this.measureRequests,d]=[d,this.measureRequests]);let p=d.map(f=>{try{return f.read(this)}catch(m){return ii(this.state,m),La}}),g=Is.create(this,this.state,[]),y=!1,c=!1;g.flags|=u,t?t.flags|=u:t=g,this.updateState=2,g.empty||(this.updatePlugins(g),this.inputState.update(g),this.updateAttrs(),y=this.docView.update(g));for(let f=0;f1||f<-1)&&(this.scrollDOM.scrollTop+=f,c=!0)}if(y&&this.docView.updateSelection(!0),this.viewport.from==a.from&&this.viewport.to==a.to&&!c&&this.measureRequests.length==0)break}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(wo))l(t)}get themeClasses(){return Eo+" "+(this.state.facet(Co)?lc:oc)+" "+this.state.facet(Zn)}updateAttrs(){let e=Ra(this,Wu,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(ur)?"true":"false",class:"cm-content",style:`${N.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Ra(this,bl,t);let i=this.observer.ignore(()=>{let n=xo(this.contentDOM,this.contentAttrs,t),s=xo(this.dom,this.editorAttrs,e);return n||s});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let n of i.effects)if(n.is(q.announce)){t&&(this.announceDOM.textContent=""),t=!1;let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(gn),Vi.mount(this.root,this.styleModules.concat(ym).reverse())}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(e.key!=null){for(let t=0;ti.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return Br(this,e,Da(this,e,t,i))}moveByGroup(e,t){return Br(this,e,Da(this,e,t,i=>Up(this,e.head,i)))}moveToLineBoundary(e,t,i=!0){return Jp(this,e,t,i)}moveVertically(e,t,i){return Br(this,e,Xp(this,e,t,i))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),Yu(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(e),s=this.bidiSpans(n),o=s[Pi.find(s,e-n.from,-1,t)];return vl(i,o.dir==ze.LTR==t>0)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet($u)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Am)return Ku(e.length);let t=this.textDirectionAt(e.from);for(let n of this.bidiCache)if(n.from==e.from&&n.dir==t)return n.order;let i=Bp(e.text,t);return this.bidiCache.push(new Ls(e.from,e.to,t,i)),i}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||N.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{bu(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return da.of(new Ns(typeof e=="number"?M.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return Mn.define(()=>({}),{eventHandlers:e})}static theme(e,t){let i=Vi.newName(),n=[Zn.of(i),gn.of(Fo(`.${i}`,e))];return t&&t.dark&&n.push(Co.of(!0)),n}static baseTheme(e){return uu.lowest(gn.of(Fo("."+Eo,e,ac)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&ne.get(i)||ne.get(e);return((t=n?.rootView)===null||t===void 0?void 0:t.view)||null}}q.styleModule=gn;q.inputHandler=Hu;q.perLineTextDirection=$u;q.exceptionSink=Vu;q.updateListener=wo;q.editable=ur;q.mouseSelectionStyle=zu;q.dragMovesSelection=Ru;q.clickAddsSelectionRange=Lu;q.decorations=On;q.atomicRanges=Ju;q.scrollMargins=Uu;q.darkTheme=Co;q.contentAttributes=bl;q.editorAttributes=Wu;q.lineWrapping=q.contentAttributes.of({class:"cm-lineWrapping"});q.announce=de.define();const Am=4096,La={};class Ls{constructor(e,t,i,n){this.from=e,this.to=t,this.dir=i,this.order=n}static update(e,t){if(t.empty)return e;let i=[],n=e.length?e[e.length-1].dir:ze.LTR;for(let s=Math.max(0,e.length-10);s=0;n--){let s=i[n],o=typeof s=="function"?s(r):s;o&&yo(o,t)}return t}const Cm=N.mac?"mac":N.windows?"win":N.linux?"linux":"key";function Em(r,e){const t=r.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let n,s,o,l;for(let a=0;ai.concat(n),[]))),t}let Jt=null;const Tm=4e3;function Mm(r,e=Cm){let t=Object.create(null),i=Object.create(null),n=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},s=(o,l,a,h)=>{var u,d;let p=t[o]||(t[o]=Object.create(null)),g=l.split(/ (?!$)/).map(f=>Em(f,e));for(let f=1;f{let v=Jt={view:x,prefix:m,scope:o};return setTimeout(()=>{Jt==v&&(Jt=null)},Tm),!0}]})}let y=g.join(" ");n(y,!1);let c=p[y]||(p[y]={preventDefault:!1,run:((d=(u=p._any)===null||u===void 0?void 0:u.run)===null||d===void 0?void 0:d.slice())||[]});a&&c.run.push(a),h&&(c.preventDefault=!0)};for(let o of r){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let u=t[h]||(t[h]=Object.create(null));u._any||(u._any={preventDefault:!1,run:[]});for(let d in u)u[d].run.push(o.any)}let a=o[e]||o.key;if(!!a)for(let h of l)s(h,a,o.run,o.preventDefault),o.shift&&s(h,"Shift-"+a,o.shift,o.preventDefault)}return t}function Om(r,e,t,i){let n=cp(e),s=xs(n,0),o=Qr(s)==n.length&&n!=" ",l="",a=!1;Jt&&Jt.view==t&&Jt.scope==i&&(l=Jt.prefix+" ",(a=Qu.indexOf(e.keyCode)<0)&&(Jt=null));let h=new Set,u=y=>{if(y){for(let c of y.run)if(!h.has(c)&&(h.add(c),c(t,e)))return!0;y.preventDefault&&(a=!0)}return!1},d=r[i],p,g;if(d){if(u(d[l+Qn(n,e,!o)]))return!0;if(o&&(e.altKey||e.metaKey||e.ctrlKey)&&(p=si[e.keyCode])&&p!=n){if(u(d[l+Qn(p,e,!0)]))return!0;if(e.shiftKey&&(g=Fn[e.keyCode])!=n&&g!=p&&u(d[l+Qn(g,e,!1)]))return!0}else if(o&&e.shiftKey&&u(d[l+Qn(n,e,!0)]))return!0;if(u(d._any))return!0}return a}const Pm=!N.ios,Nm={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};Pm&&(Nm[".cm-line"].caretColor="transparent !important");class Ji extends zi{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Ji.prototype.elementClass="";Ji.prototype.toDOM=void 0;Ji.prototype.mapMode=Qe.TrackBefore;Ji.prototype.startSide=Ji.prototype.endSide=-1;Ji.prototype.point=!0;const Im=1024;let Lm=0;class Or{constructor(e,t){this.from=e,this.to=t}}class se{constructor(e={}){this.id=Lm++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=qe.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}se.closedBy=new se({deserialize:r=>r.split(" ")});se.openedBy=new se({deserialize:r=>r.split(" ")});se.group=new se({deserialize:r=>r.split(" ")});se.contextHash=new se({perNode:!0});se.lookAhead=new se({perNode:!0});se.mounted=new se({perNode:!0});const Rm=Object.create(null);class qe{constructor(e,t,i,n=0){this.name=e,this.props=t,this.id=i,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):Rm,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new qe(e.name||"",t,e.id,i);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(n)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return n}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(se.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let n of i.split(" "))t[n]=e[i];return i=>{for(let n=i.prop(se.group),s=-1;s<(n?n.length:0);s++){let o=t[s<0?i.name:n[s]];if(o)return o}}}}qe.none=new qe("",Object.create(null),0,8);class Al{constructor(e){this.types=e;for(let t=0;t=n&&(o.type.isAnonymous||t(o)!==!1)){if(o.firstChild())continue;l=!0}for(;l&&i&&!o.type.isAnonymous&&i(o),!o.nextSibling();){if(!o.parent())return;l=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Fl(qe.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,n)=>new ae(this.type,t,i,n,this.propValues),e.makeTree||((t,i,n)=>new ae(qe.none,t,i,n)))}static build(e){return Vm(e)}}ae.empty=new ae(qe.none,[],[],0);class Cl{constructor(e,t){this.buffer=e,this.index=t}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 Cl(this.buffer,this.index)}}class bi{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return qe.none}toString(){let e=[];for(let t=0;t0));a=o[a+3]);return l}slice(e,t,i){let n=this.buffer,s=new Uint16Array(t-e),o=0;for(let l=e,a=0;l=e&&te;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function fc(r,e){let t=r.childBefore(e);for(;t;){let i=t.lastChild;if(!i||i.to!=t.to)break;i.type.isError&&i.from==i.to?(r=t,t=i.prevSibling):t=i}return r}function Ui(r,e,t,i){for(var n;r.from==r.to||(t<1?r.from>=e:r.from>e)||(t>-1?r.to<=e:r.to0?l.length:-1;e!=h;e+=t){let u=l[e],d=a[e]+o.from;if(!!cc(n,i,d,d+u.length)){if(u instanceof bi){if(s&Ie.ExcludeBuffers)continue;let p=u.findChild(0,u.buffer.length,t,i-d,n);if(p>-1)return new qt(new zm(o,u,e,d),null,p)}else if(s&Ie.IncludeAnonymous||!u.type.isAnonymous||El(u)){let p;if(!(s&Ie.IgnoreMounts)&&u.props&&(p=u.prop(se.mounted))&&!p.overlay)return new It(p.tree,d,e,o);let g=new It(u,d,e,o);return s&Ie.IncludeAnonymous||!g.type.isAnonymous?g:g.nextChild(t<0?u.children.length-1:0,t,i,n)}}}if(s&Ie.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))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(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(e,t,i=0){let n;if(!(i&Ie.IgnoreOverlays)&&(n=this._tree.prop(se.mounted))&&n.overlay){let s=e-this.from;for(let{from:o,to:l}of n.overlay)if((t>0?o<=s:o=s:l>s))return new It(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}cursor(e=0){return new Vs(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return Ui(this,e,t,!1)}resolveInner(e,t=0){return Ui(this,e,t,!0)}enterUnfinishedNodesBefore(e){return fc(this,e)}getChild(e,t=null,i=null){let n=Rs(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return Rs(this,e,t,i)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return zs(this,e)}}function Rs(r,e,t,i){let n=r.cursor(),s=[];if(!n.firstChild())return s;if(t!=null){for(;!n.type.is(t);)if(!n.nextSibling())return s}for(;;){if(i!=null&&n.type.is(i))return s;if(n.type.is(e)&&s.push(n.node),!n.nextSibling())return i==null?s:[]}}function zs(r,e,t=e.length-1){for(let i=r.parent;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class zm{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class qt{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(e,t,i){this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.context.start,i);return s<0?null:new qt(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,i=0){if(i&Ie.ExcludeBuffers)return null;let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new qt(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new qt(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new qt(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new Vs(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,n=this.index+4,s=i.buffer[this.index+3];if(s>n){let o=i.buffer[this.index+1];e.push(i.slice(n,s,o)),t.push(0)}return new ae(this.type,e,t,this.to-this.from)}resolve(e,t=0){return Ui(this,e,t,!1)}resolveInner(e,t=0){return Ui(this,e,t,!0)}enterUnfinishedNodesBefore(e){return fc(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,i=null){let n=Rs(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return Rs(this,e,t,i)}get node(){return this}matchContext(e){return zs(this,e)}}class Vs{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof It)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:n}=this.buffer;return this.type=t||n.set.types[n.buffer[e]],this.from=i+n.buffer[e+1],this.to=i+n.buffer[e+2],!0}yield(e){return e?e instanceof It?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:n}=this.buffer,s=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.buffer.start,i);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&Ie.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Ie.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&Ie.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let n=i<0?0:this.stack[i]+4;if(this.index!=n)return this.yieldBuf(t.findChild(n,this.index,-1,0,4))}else{let n=t.buffer[this.index+3];if(n<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(n)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:n}=this;if(n){if(e>0){if(this.index-1)for(let s=t+e,o=e<0?-1:i._tree.children.length;s!=o;s+=e){let l=i._tree.children[s];if(this.mode&Ie.IncludeAnonymous||l instanceof bi||!l.type.isAnonymous||El(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to=0;){for(let o=e;o;o=o._parent)if(o.index==n){if(n==this.index)return o;t=o,i=s+1;break e}n=this.stack[--s]}}for(let n=i;n=0;s--){if(s<0)return zs(this.node,e,n);let o=i[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[n]&&e[n]!=o.name)return!1;n--}}return!0}}function El(r){return r.children.some(e=>e instanceof bi||!e.type.isAnonymous||El(e))}function Vm(r){var e;let{buffer:t,nodeSet:i,maxBufferLength:n=Im,reused:s=[],minRepeatType:o=i.types.length}=r,l=Array.isArray(t)?new Cl(t,t.length):t,a=i.types,h=0,u=0;function d(S,D,w,b,E){let{id:C,start:F,end:B,size:I}=l,R=u;for(;I<0;)if(l.next(),I==-1){let he=s[C];w.push(he),b.push(F-S);return}else if(I==-3){h=C;return}else if(I==-4){u=C;return}else throw new RangeError(`Unrecognized record size: ${I}`);let X=a[C],j,Z,ht=F-S;if(B-F<=n&&(Z=c(l.pos-D,E))){let he=new Uint16Array(Z.size-Z.skip),J=l.pos-Z.size,ee=he.length;for(;l.pos>J;)ee=f(Z.start,he,ee);j=new bi(he,B-Z.start,i),ht=Z.start-S}else{let he=l.pos-I;l.next();let J=[],ee=[],ue=C>=o?C:-1,xe=0,Oe=B;for(;l.pos>he;)ue>=0&&l.id==ue&&l.size>=0?(l.end<=Oe-n&&(g(J,ee,F,xe,l.end,Oe,ue,R),xe=J.length,Oe=l.end),l.next()):d(F,he,J,ee,ue);if(ue>=0&&xe>0&&xe-1&&xe>0){let lt=p(X);j=Fl(X,J,ee,0,J.length,0,B-F,lt,lt)}else j=y(X,J,ee,B-F,R-B)}w.push(j),b.push(ht)}function p(S){return(D,w,b)=>{let E=0,C=D.length-1,F,B;if(C>=0&&(F=D[C])instanceof ae){if(!C&&F.type==S&&F.length==b)return F;(B=F.prop(se.lookAhead))&&(E=w[C]+F.length+B)}return y(S,D,w,b,E)}}function g(S,D,w,b,E,C,F,B){let I=[],R=[];for(;S.length>b;)I.push(S.pop()),R.push(D.pop()+w-E);S.push(y(i.types[F],I,R,C-E,B-C)),D.push(E-w)}function y(S,D,w,b,E=0,C){if(h){let F=[se.contextHash,h];C=C?[F].concat(C):[F]}if(E>25){let F=[se.lookAhead,E];C=C?[F].concat(C):[F]}return new ae(S,D,w,b,C)}function c(S,D){let w=l.fork(),b=0,E=0,C=0,F=w.end-n,B={size:0,start:0,skip:0};e:for(let I=w.pos-S;w.pos>I;){let R=w.size;if(w.id==D&&R>=0){B.size=b,B.start=E,B.skip=C,C+=4,b+=4,w.next();continue}let X=w.pos-R;if(R<0||X=o?4:0,Z=w.start;for(w.next();w.pos>X;){if(w.size<0)if(w.size==-3)j+=4;else break e;else w.id>=o&&(j+=4);w.next()}E=Z,b+=R,C+=j}return(D<0||b==S)&&(B.size=b,B.start=E,B.skip=C),B.size>4?B:void 0}function f(S,D,w){let{id:b,start:E,end:C,size:F}=l;if(l.next(),F>=0&&b4){let I=l.pos-(F-4);for(;l.pos>I;)w=f(S,D,w)}D[--w]=B,D[--w]=C-S,D[--w]=E-S,D[--w]=b}else F==-3?h=b:F==-4&&(u=b);return w}let m=[],x=[];for(;l.pos>0;)d(r.start||0,r.bufferStart||0,m,x,-1);let v=(e=r.length)!==null&&e!==void 0?e:m.length?x[0]+m[0].length:0;return new ae(a[r.topID],m.reverse(),x.reverse(),v)}const Ha=new WeakMap;function Ds(r,e){if(!r.isAnonymous||e instanceof bi||e.type!=r)return 1;let t=Ha.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=r||!(i instanceof ae)){t=1;break}t+=Ds(r,i)}Ha.set(e,t)}return t}function Fl(r,e,t,i,n,s,o,l,a){let h=0;for(let y=i;y=u)break;w+=b}if(v==S+1){if(w>u){let b=y[S];g(b.children,b.positions,0,b.children.length,c[S]+x);continue}d.push(y[S])}else{let b=c[v-1]+y[v-1].length-D;d.push(Fl(r,y,c,S,v,D,b,null,a))}p.push(D+x-s)}}return g(e,t,i,n,0),(l||a)(d,p,o)}class yi{constructor(e,t,i,n,s=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=n,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let n=[new yi(0,e.length,e,0,!1,i)];for(let s of t)s.to>e.length&&n.push(s);return n}static applyChanges(e,t,i=128){if(!t.length)return e;let n=[],s=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let u=l=i)for(;o&&o.from=p.from||d<=p.to||h){let g=Math.max(p.from,a)-h,y=Math.min(p.to,d)-h;p=g>=y?null:new yi(g,y,p.tree,p.offset+h,l>0,!!u)}if(p&&n.push(p),o.to>d)break;o=snew Or(n.from,n.to)):[new Or(0,0)]:[new Or(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let n=this.startParse(e,t,i);for(;;){let s=n.advance();if(s)return s}}}class Hm{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new se({perNode:!0});class Y{constructor(){}lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){let n=[];return this.decompose(0,e,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(t,this.length,n,1),St.from(n,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){let i=[];return this.decompose(e,t,i,0),St.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),n=new bn(this),s=new bn(e);for(let o=t,l=t;;){if(n.next(o),s.next(o),o=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(l+=n.value.length,n.done||l>=i)return!0}}iter(e=1){return new bn(this,e)}iterRange(e,t=this.length){return new pc(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let n=this.line(e).from;i=this.iterRange(n,Math.max(n,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new mc(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?Y.empty:e.length<=32?new fe(e):St.from(fe.split(e,[]))}}class fe extends Y{constructor(e,t=$m(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,n){for(let s=0;;s++){let o=this.text[s],l=n+o.length;if((t?i:l)>=e)return new Wm(n,l,i,o);n=l+1,i++}}decompose(e,t,i,n){let s=e<=0&&t>=this.length?this:new fe($a(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(n&1){let o=i.pop(),l=bs(s.text,o.text.slice(),0,s.length);if(l.length<=32)i.push(new fe(l,o.length+s.length));else{let a=l.length>>1;i.push(new fe(l.slice(0,a)),new fe(l.slice(a)))}}else i.push(s)}replace(e,t,i){if(!(i instanceof fe))return super.replace(e,t,i);let n=bs(this.text,bs(i.text,$a(this.text,0,e)),t),s=this.length+i.length-(t-e);return n.length<=32?new fe(n,s):St.from(fe.split(n,[]),s)}sliceString(e,t=this.length,i=` +`){let n="";for(let s=0,o=0;s<=t&&oe&&o&&(n+=i),es&&(n+=l.slice(Math.max(0,e-s),t-s)),s=a+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],n=-1;for(let s of e)i.push(s),n+=s.length+1,i.length==32&&(t.push(new fe(i,n)),i=[],n=-1);return n>-1&&t.push(new fe(i,n)),t}}class St extends Y{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,n){for(let s=0;;s++){let o=this.children[s],l=n+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,n);n=l+1,i=a+1}}decompose(e,t,i,n){for(let s=0,o=0;o<=t&&s=o){let h=n&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if(i.lines=s&&t<=l){let a=o.replace(e-s,t-s,i),h=this.lines-o.lines+a.lines;if(a.lines>5-1&&a.lines>h>>5+1){let u=this.children.slice();return u[n]=a,new St(u,this.length-(t-e)+i.length)}return super.replace(s,l,a)}s=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=` +`){let n="";for(let s=0,o=0;se&&s&&(n+=i),eo&&(n+=l.sliceString(e-o,t-o,i)),o=a+1}return n}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof St))return 0;let i=0,[n,s,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;n+=t,s+=t){if(n==o||s==l)return i;let a=this.children[n],h=e.children[s];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,n)=>i+n.length+1,-1)){let i=0;for(let g of e)i+=g.lines;if(i<32){let g=[];for(let y of e)y.flatten(g);return new fe(g,t)}let n=Math.max(32,i>>5),s=n<<1,o=n>>1,l=[],a=0,h=-1,u=[];function d(g){let y;if(g.lines>s&&g instanceof St)for(let c of g.children)d(c);else g.lines>o&&(a>o||!a)?(p(),l.push(g)):g instanceof fe&&a&&(y=u[u.length-1])instanceof fe&&g.lines+y.lines<=32?(a+=g.lines,h+=g.length+1,u[u.length-1]=new fe(y.text.concat(g.text),y.length+1+g.length)):(a+g.lines>n&&p(),a+=g.lines,h+=g.length+1,u.push(g))}function p(){a!=0&&(l.push(u.length==1?u[0]:St.from(u,h)),h=-1,a=u.length=0)}for(let g of e)d(g);return p(),l.length==1?l[0]:new St(l,t)}}Y.empty=new fe([""],0);function $m(r){let e=-1;for(let t of r)e+=t.length+1;return e}function bs(r,e,t=0,i=1e9){for(let n=0,s=0,o=!0;s=t&&(a>i&&(l=l.slice(0,i-n)),n0?1:(e instanceof fe?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],s=this.offsets[i],o=s>>1,l=n instanceof fe?n.text.length:n.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=` +`,this;e--}else if(n instanceof fe){let a=n.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=n.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof fe?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class pc{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new bn(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:n}=this.cursor.next(e);return this.pos+=(n.length+e)*t,this.value=n.length<=i?n:t<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class mc{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:n}=this.inner.next(e);return t?(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}}typeof Symbol<"u"&&(Y.prototype[Symbol.iterator]=function(){return this.iter()},bn.prototype[Symbol.iterator]=pc.prototype[Symbol.iterator]=mc.prototype[Symbol.iterator]=function(){return this});class Wm{constructor(e,t,i,n){this.from=e,this.to=t,this.number=i,this.text=n}get length(){return this.to-this.from}}let Ni="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(r=>r?parseInt(r,36):1);for(let r=1;rr)return Ni[e-1]<=r;return!1}function Wa(r){return r>=127462&&r<=127487}const Ja=8205;function Gt(r,e,t=!0,i=!0){return(t?gc:Um)(r,e,i)}function gc(r,e,t){if(e==r.length)return e;e&&yc(r.charCodeAt(e))&&xc(r.charCodeAt(e-1))&&e--;let i=Pr(r,e);for(e+=Ua(i);e=0&&Wa(Pr(r,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function Um(r,e,t){for(;e>0;){let i=gc(r,e-2,t);if(i=56320&&r<57344}function xc(r){return r>=55296&&r<56320}function Pr(r,e){let t=r.charCodeAt(e);if(!xc(t)||e+1==r.length)return t;let i=r.charCodeAt(e+1);return yc(i)?(t-55296<<10)+(i-56320)+65536:t}function Ua(r){return r<65536?1:2}const Bo=/\r\n?|\n/;var tt=function(r){return r[r.Simple=0]="Simple",r[r.TrackDel=1]="TrackDel",r[r.TrackBefore=2]="TrackBefore",r[r.TrackAfter=3]="TrackAfter",r}(tt||(tt={}));class Lt{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;te)return s+(e-n);s+=l}else{if(i!=tt.Simple&&h>=e&&(i==tt.TrackDel&&ne||i==tt.TrackBefore&&ne))return null;if(h>e||h==e&&t<0&&!l)return e==n||t<0?s:s+a;s+=a}n=h}if(e>n)throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`);return s}touchesRange(e,t=e){for(let i=0,n=0;i=0&&n<=t&&l>=e)return nt?"cover":!0;n=l}return!1}toString(){let e="";for(let t=0;t=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Lt(e)}static create(e){return new Lt(e)}}class be extends Lt{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return To(this,(t,i,n,s,o)=>e=e.replace(n,n+(i-t),o),!1),e}mapDesc(e,t=!1){return Mo(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,s=0;n=0){t[n]=l,t[n+1]=o;let a=n>>1;for(;i.length0&&Yt(i,t,s.text),s.forward(u),l+=u}let h=e[o++];for(;l>1].toJSON()))}return e}static of(e,t,i){let n=[],s=[],o=0,l=null;function a(u=!1){if(!u&&!n.length)return;op||d<0||p>t)throw new RangeError(`Invalid change range ${d} to ${p} (in doc of length ${t})`);let y=g?typeof g=="string"?Y.of(g.split(i||Bo)):g:Y.empty,c=y.length;if(d==p&&c==0)return;do&&Ne(n,d-o,-1),Ne(n,p-d,c),Yt(s,n,y),o=p}}return h(e),a(!l),l}static empty(e){return new be(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;nl&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;i.length=0&&t<=0&&t==r[n+1]?r[n]+=e:e==0&&r[n]==0?r[n+1]+=t:i?(r[n]+=e,r[n+1]+=t):r.push(e,t)}function Yt(r,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i>1])),!(t||o==r.sections.length||r.sections[o+1]<0);)l=r.sections[o++],a=r.sections[o++];e(n,h,s,u,d),n=h,s=u}}}function Mo(r,e,t,i=!1){let n=[],s=i?[]:null,o=new Pn(r),l=new Pn(e);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);Ne(n,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len=0&&a=0){let h=0,u=o.len;for(;u;)if(l.ins==-1){let d=Math.min(u,l.len);h+=d,u-=d,l.forward(d)}else if(l.ins==0&&l.lena||o.ins>=0&&o.len>a)&&(l||i.length>h),s.forward2(a),o.forward(a)}}}}class Pn{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i>1;return t>=e.length?Y.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?Y.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class mi{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&16?this.to:this.from}get head(){return this.flags&16?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&4?-1:this.flags&8?1:0}get bidiLevel(){let e=this.flags&3;return e==3?null:e}get goalColumn(){let e=this.flags>>5;return e==33554431?void 0:e}map(e,t=-1){let i,n;return this.empty?i=n=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),n=e.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new mi(i,n,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return z.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return z.range(this.anchor,i)}eq(e){return this.anchor==e.anchor&&this.head==e.head}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return z.range(e.anchor,e.head)}static create(e,t,i){return new mi(e,t,i)}}class z{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:z.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let t=0;te.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new z(e.ranges.map(t=>mi.fromJSON(t)),e.main)}static single(e,t=e){return new z([z.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;ne?4:0))}static normalized(e,t=0){let i=e[t];e.sort((n,s)=>n.from-s.from),t=e.indexOf(i);for(let n=1;ns.head?z.range(a,l):z.range(l,a))}}return new z(e,t)}}function wc(r,e){for(let t of r.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Bl=0;class U{constructor(e,t,i,n,s){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=Bl++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}static define(e={}){return new U(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:Tl),!!e.static,e.enables)}of(e){return new ks([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ks(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new ks(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function Tl(r,e){return r==e||r.length==e.length&&r.every((t,i)=>t===e[i])}class ks{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=Bl++}dynamicSlot(e){var t;let i=this.value,n=this.facet.compareInput,s=this.id,o=e[s]>>1,l=this.type==2,a=!1,h=!1,u=[];for(let d of this.dependencies)d=="doc"?a=!0:d=="selection"?h=!0:(((t=e[d.id])!==null&&t!==void 0?t:1)&1)==0&&u.push(e[d.id]);return{create(d){return d.values[o]=i(d),1},update(d,p){if(a&&p.docChanged||h&&(p.docChanged||p.selection)||Oo(d,u)){let g=i(d);if(l?!Xa(g,d.values[o],n):!n(g,d.values[o]))return d.values[o]=g,1}return 0},reconfigure:(d,p)=>{let g,y=p.config.address[s];if(y!=null){let c=$s(p,y);if(this.dependencies.every(f=>f instanceof U?p.facet(f)===d.facet(f):f instanceof ki?p.field(f,!1)==d.field(f,!1):!0)||(l?Xa(g=i(d),c,n):n(g=i(d),c)))return d.values[o]=c,0}else g=i(d);return d.values[o]=g,1}}}}function Xa(r,e,t){if(r.length!=e.length)return!1;for(let i=0;ir[a.id]),n=t.map(a=>a.type),s=i.filter(a=>!(a&1)),o=r[e.id]>>1;function l(a){let h=[];for(let u=0;ui===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Ka).find(i=>i.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,n)=>{let s=i.values[t],o=this.updateF(s,n);return this.compareF(s,o)?0:(i.values[t]=o,1)},reconfigure:(i,n)=>n.config.address[this.id]!=null?(i.values[t]=n.field(this),0):(i.values[t]=this.create(i),1)}}init(e){return[this,Ka.of({field:this,create:e})]}get extension(){return this}}const di={lowest:4,low:3,default:2,high:1,highest:0};function an(r){return e=>new Sc(e,r)}const Km={highest:an(di.highest),high:an(di.high),default:an(di.default),low:an(di.low),lowest:an(di.lowest)};class Sc{constructor(e,t){this.inner=e,this.prec=t}}class cr{of(e){return new Po(this,e)}reconfigure(e){return cr.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Po{constructor(e,t){this.compartment=e,this.inner=t}}class Hs{constructor(e,t,i,n,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(e,t,i){let n=[],s=Object.create(null),o=new Map;for(let p of _m(e,t,o))p instanceof ki?n.push(p):(s[p.facet.id]||(s[p.facet.id]=[])).push(p);let l=Object.create(null),a=[],h=[];for(let p of n)l[p.id]=h.length<<1,h.push(g=>p.slot(g));let u=i?.config.facets;for(let p in s){let g=s[p],y=g[0].facet,c=u&&u[p]||[];if(g.every(f=>f.type==0))if(l[y.id]=a.length<<1|1,Tl(c,g))a.push(i.facet(y));else{let f=y.combine(g.map(m=>m.value));a.push(i&&y.compare(f,i.facet(y))?i.facet(y):f)}else{for(let f of g)f.type==0?(l[f.id]=a.length<<1|1,a.push(f.value)):(l[f.id]=h.length<<1,h.push(m=>f.dynamicSlot(m)));l[y.id]=h.length<<1,h.push(f=>Xm(f,y,g))}}let d=h.map(p=>p(l));return new Hs(e,o,d,l,a,s)}}function _m(r,e,t){let i=[[],[],[],[],[]],n=new Map;function s(o,l){let a=n.get(o);if(a!=null){if(a<=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof Po&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let h of o)s(h,l);else if(o instanceof Po){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),s(h,l)}else if(o instanceof Sc)s(o.inner,o.prec);else if(o instanceof ki)i[l].push(o),o.provides&&s(o.provides,l);else if(o instanceof ks)i[l].push(o),o.facet.extensions&&s(o.facet.extensions,di.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(h,l)}}return s(r,di.default),i.reduce((o,l)=>o.concat(l))}function kn(r,e){if(e&1)return 2;let t=e>>1,i=r.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;r.status[t]=4;let n=r.computeSlot(r,r.config.dynamicSlots[t]);return r.status[t]=2|n}function $s(r,e){return e&1?r.config.staticValues[e>>1]:r.values[e>>1]}const Dc=U.define(),bc=U.define({combine:r=>r.some(e=>e),static:!0}),kc=U.define({combine:r=>r.length?r[0]:void 0,static:!0}),Ac=U.define(),Cc=U.define(),Ec=U.define(),Fc=U.define({combine:r=>r.length?r[0]:!1});class Wn{constructor(e,t){this.type=e,this.value=t}static define(){return new jm}}class jm{of(e){return new Wn(this,e)}}class qm{constructor(e){this.map=e}of(e){return new ke(this,e)}}class ke{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new ke(this.type,t)}is(e){return this.type==e}static define(e={}){return new qm(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let n of e){let s=n.map(t);s&&i.push(s)}return i}}ke.reconfigure=ke.define();ke.appendConfig=ke.define();class Ve{constructor(e,t,i,n,s,o){this.startState=e,this.changes=t,this.selection=i,this.effects=n,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,i&&wc(i,t.newLength),s.some(l=>l.type==Ve.time)||(this.annotations=s.concat(Ve.time.of(Date.now())))}static create(e,t,i,n,s,o){return new Ve(e,t,i,n,s,o)}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(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(Ve.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Ve.time=Wn.define();Ve.userEvent=Wn.define();Ve.addToHistory=Wn.define();Ve.remote=Wn.define();function Gm(r,e){let t=[];for(let i=0,n=0;;){let s,o;if(i=r[i]))s=r[i++],o=r[i++];else if(n=0;n--){let s=i[n](r);s instanceof Ve?r=s:Array.isArray(s)&&s.length==1&&s[0]instanceof Ve?r=s[0]:r=Tc(e,Ii(s),!1)}return r}function Zm(r){let e=r.startState,t=e.facet(Ec),i=r;for(let n=t.length-1;n>=0;n--){let s=t[n](r);s&&Object.keys(s).length&&(i=Bc(i,No(e,s,r.changes.newLength),!0))}return i==r?r:Ve.create(e,r.changes,r.selection,i.effects,i.annotations,i.scrollIntoView)}const Qm=[];function Ii(r){return r==null?Qm:Array.isArray(r)?r:[r]}var Pt=function(r){return r[r.Word=0]="Word",r[r.Space=1]="Space",r[r.Other=2]="Other",r}(Pt||(Pt={}));const eg=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Io;try{Io=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function tg(r){if(Io)return Io.test(r);for(let e=0;e"\x80"&&(t.toUpperCase()!=t.toLowerCase()||eg.test(t)))return!0}return!1}function ig(r){return e=>{if(!/\S/.test(e))return Pt.Space;if(tg(e))return Pt.Word;for(let t=0;t-1)return Pt.Word;return Pt.Other}}class Q{constructor(e,t,i,n,s,o){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let l=0;ln.set(a,l)),t=null),n.set(o.value.compartment,o.value.extension)):o.is(ke.reconfigure)?(t=null,i=o.value):o.is(ke.appendConfig)&&(t=null,i=Ii(i).concat(o.value));let s;t?s=e.startState.values.slice():(t=Hs.resolve(i,n,this),s=new Q(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,a)=>a.reconfigure(l,this),null).values),new Q(t,e.newDoc,e.newSelection,s,(o,l)=>l.update(o,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:z.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),s=[i.range],o=Ii(i.effects);for(let l=1;lo.spec.fromJSON(l,a)))}}return Q.create({doc:e.doc,selection:z.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=Hs.resolve(e.extensions||[],new Map),i=e.doc instanceof Y?e.doc:Y.of((e.doc||"").split(t.staticFacet(Q.lineSeparator)||Bo)),n=e.selection?e.selection instanceof z?e.selection:z.single(e.selection.anchor,e.selection.head):z.single(0);return wc(n,i.length),t.staticFacet(bc)||(n=n.asSingle()),new Q(t,i,n,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(Q.tabSize)}get lineBreak(){return this.facet(Q.lineSeparator)||` +`}get readOnly(){return this.facet(Fc)}phrase(e,...t){for(let i of this.facet(Q.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,n)=>{if(n=="$")return"$";let s=+(n||1);return!s||s>t.length?i:t[s-1]})),e}languageDataAt(e,t,i=-1){let n=[];for(let s of this.facet(Dc))for(let o of s(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&n.push(o[e]);return n}charCategorizer(e){return ig(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:i,length:n}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=Gt(t,o,!1);if(s(t.slice(a,o))!=Pt.Word)break;o=a}for(;lr.length?r[0]:4});Q.lineSeparator=kc;Q.readOnly=Fc;Q.phrases=U.define({compare(r,e){let t=Object.keys(r),i=Object.keys(e);return t.length==i.length&&t.every(n=>r[n]==e[n])}});Q.languageData=Dc;Q.changeFilter=Ac;Q.transactionFilter=Cc;Q.transactionExtender=Ec;cr.reconfigure=ke.define();class Xi{eq(e){return this==e}range(e,t=e){return Nn.create(e,t,this)}}Xi.prototype.startSide=Xi.prototype.endSide=0;Xi.prototype.point=!1;Xi.prototype.mapMode=tt.TrackDel;class Nn{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Nn(e,t,i)}}function Lo(r,e){return r.from-e.from||r.value.startSide-e.value.startSide}class Ml{constructor(e,t,i,n){this.from=e,this.to=t,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,n=0){let s=i?this.to:this.from;for(let o=n,l=s.length;;){if(o==l)return o;let a=o+l>>1,h=s[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,i,n){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,s);sg||p==g&&h.startSide>0&&h.endSide<=0)continue;(g-p||h.endSide-h.startSide)<0||(o<0&&(o=p),h.point&&(l=Math.max(l,g-p)),i.push(h),n.push(p-o),s.push(g-o))}return{mapped:i.length?new Ml(n,s,i,l):null,pos:o}}}class ye{constructor(e,t,i,n){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=n}static create(e,t,i,n){return new ye(e,t,i,n)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:n=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(Lo)),this.isEmpty)return t.length?ye.of(t):this;let l=new Mc(this,null,-1).goto(0),a=0,h=[],u=new Ws;for(;l.value||a=0){let d=t[a++];u.addInner(d.from,d.to,d.value)||h.push(d)}else l.rangeIndex==1&&l.chunkIndexthis.chunkEnd(l.chunkIndex)||sl.to||s=s&&e<=s+o.length&&o.between(s,e-s,t-s,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return In.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return In.from(e).goto(t)}static compare(e,t,i,n,s=-1){let o=e.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),l=t.filter(d=>d.maxPoint>0||!d.isEmpty&&d.maxPoint>=s),a=_a(o,l,i),h=new hn(o,a,s),u=new hn(l,a,s);i.iterGaps((d,p,g)=>ja(h,d,u,p,g,n)),i.empty&&i.length==0&&ja(h,0,u,0,0,n)}static eq(e,t,i=0,n){n==null&&(n=1e9-1);let s=e.filter(u=>!u.isEmpty&&t.indexOf(u)<0),o=t.filter(u=>!u.isEmpty&&e.indexOf(u)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let l=_a(s,o),a=new hn(s,l,0).goto(i),h=new hn(o,l,0).goto(i);for(;;){if(a.to!=h.to||!Ro(a.active,h.active)||a.point&&(!h.point||!a.point.eq(h.point)))return!1;if(a.to>n)return!0;a.next(),h.next()}}static spans(e,t,i,n,s=-1){let o=new hn(e,null,s).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let u=o.activeForPoint(o.to),d=o.pointFroml&&(n.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new Ws;for(let n of e instanceof Nn?[e]:t?ng(e):e)i.add(n.from,n.to,n.value);return i.finish()}}ye.empty=new ye([],[],null,-1);function ng(r){if(r.length>1)for(let e=r[0],t=1;t0)return r.slice().sort(Lo);e=i}return r}ye.empty.nextLayer=ye.empty;class Ws{constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}finishChunk(e){this.chunks.push(new Ml(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,e&&(this.from=[],this.to=[],this.value=[])}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new Ws)).add(e,t,i)}addInner(e,t,i){let n=e-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return n<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(ye.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=ye.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function _a(r,e,t){let i=new Map;for(let s of r)for(let o=0;o=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=i&&n.push(new Mc(o,t,i,s));return n.length==1?n[0]:new In(n)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)Nr(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)Nr(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Nr(this.heap,0)}}}function Nr(r,e){for(let t=r[e];;){let i=(e<<1)+1;if(i>=r.length)break;let n=r[i];if(i+1=0&&(n=r[i+1],i++),t.compare(n)<0)break;r[i]=t,r[e]=n,e=i}}class hn{constructor(e,t,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=In.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){ts(this.active,e),ts(this.activeTo,e),ts(this.activeRank,e),this.minActive=qa(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:s}=this.cursor;for(;t-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>e){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&ts(i,n)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from=0&&i[n]=0&&!(this.activeRank[i]e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function ja(r,e,t,i,n,s){r.goto(e),t.goto(i);let o=i+n,l=i,a=i-e;for(;;){let h=r.to+a-t.to||r.endSide-t.endSide,u=h<0?r.to+a:t.to,d=Math.min(u,o);if(r.point||t.point?r.point&&t.point&&(r.point==t.point||r.point.eq(t.point))&&Ro(r.activeForPoint(r.to+a),t.activeForPoint(t.to))||s.comparePoint(l,d,r.point,t.point):d>l&&!Ro(r.active,t.active)&&s.compareRange(l,d,r.active,t.active),u>o)break;l=u,h<=0&&r.next(),h>=0&&t.next()}}function Ro(r,e){if(r.length!=e.length)return!1;for(let t=0;t=e;i--)r[i+1]=r[i];r[e]=t}function qa(r,e){let t=-1,i=1e9;for(let n=0;n=e)return n;if(n==r.length)break;s+=r.charCodeAt(n)==9?t-s%t:1,n=Gt(r,n)}return i===!0?-1:r.length}const zo="\u037C",Ga=typeof Symbol>"u"?"__"+zo:Symbol.for(zo),Vo=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Ya=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Ki{constructor(e,t){this.rules=[];let{finish:i}=t||{};function n(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,l,a,h){let u=[],d=/^@(\w+)\b/.exec(o[0]),p=d&&d[1]=="keyframes";if(d&&l==null)return a.push(o[0]+";");for(let g in l){let y=l[g];if(/&/.test(g))s(g.split(/,\s*/).map(c=>o.map(f=>c.replace(/&/,f))).reduce((c,f)=>c.concat(f)),y,a);else if(y&&typeof y=="object"){if(!d)throw new RangeError("The value of a property ("+g+") should be a primitive value.");s(n(g),y,u,p)}else y!=null&&u.push(g.replace(/_.*/,"").replace(/[A-Z]/g,c=>"-"+c.toLowerCase())+": "+y+";")}(u.length||p)&&a.push((i&&!d&&!h?o.map(i):o).join(", ")+" {"+u.join(" ")+"}")}for(let o in e)s(n(o),e[o],this.rules)}getRules(){return this.rules.join(` +`)}static newName(){let e=Ya[Ga]||1;return Ya[Ga]=e+1,zo+e.toString(36)}static mount(e,t){(e[Vo]||new rg(e)).mount(Array.isArray(t)?t:[t])}}let ns=null;class rg{constructor(e){if(!e.head&&e.adoptedStyleSheets&&typeof CSSStyleSheet<"u"){if(ns)return e.adoptedStyleSheets=[ns.sheet].concat(e.adoptedStyleSheets),e[Vo]=ns;this.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[this.sheet].concat(e.adoptedStyleSheets),ns=this}else{this.styleTag=(e.ownerDocument||e).createElement("style");let t=e.head||e;t.insertBefore(this.styleTag,t.firstChild)}this.modules=[],e[Vo]=this}mount(e){let t=this.sheet,i=0,n=0;for(let s=0;s-1&&(this.modules.splice(l,1),n--,l=-1),l==-1){if(this.modules.splice(n++,0,o),t)for(let a=0;a",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Za=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent);typeof navigator<"u"&&/Gecko\/\d+/.test(navigator.userAgent);var og=typeof navigator<"u"&&/Mac/.test(navigator.platform);typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);og||Za&&+Za[1]<57;for(var Te=0;Te<10;Te++)_i[48+Te]=_i[96+Te]=String(Te);for(var Te=1;Te<=24;Te++)_i[Te+111]="F"+Te;for(var Te=65;Te<=90;Te++)_i[Te]=String.fromCharCode(Te+32),Ho[Te]=String.fromCharCode(Te);for(var Ir in _i)Ho.hasOwnProperty(Ir)||(Ho[Ir]=_i[Ir]);function Js(r){let e;return r.nodeType==11?e=r.getSelection?r:r.ownerDocument:e=r,e.getSelection()}function ji(r,e){return e?r==e||r.contains(e.nodeType!=1?e.parentNode:e):!1}function lg(r){let e=r.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function As(r,e){if(!e.anchorNode)return!1;try{return ji(r,e.anchorNode)}catch{return!1}}function Ln(r){return r.nodeType==3?qi(r,0,r.nodeValue.length).getClientRects():r.nodeType==1?r.getClientRects():[]}function Us(r,e,t,i){return t?Qa(r,e,t,i,-1)||Qa(r,e,t,i,1):!1}function Xs(r){for(var e=0;;e++)if(r=r.previousSibling,!r)return e}function Qa(r,e,t,i,n){for(;;){if(r==t&&e==i)return!0;if(e==(n<0?0:Rn(r))){if(r.nodeName=="DIV")return!1;let s=r.parentNode;if(!s||s.nodeType!=1)return!1;e=Xs(r)+(n<0?0:1),r=s}else if(r.nodeType==1){if(r=r.childNodes[e+(n<0?-1:0)],r.nodeType==1&&r.contentEditable=="false")return!1;e=n<0?Rn(r):0}else return!1}}function Rn(r){return r.nodeType==3?r.nodeValue.length:r.childNodes.length}const Oc={left:0,right:0,top:0,bottom:0};function Ol(r,e){let t=e?r.left:r.right;return{left:t,right:t,top:r.top,bottom:r.bottom}}function ag(r){return{left:0,right:r.innerWidth,top:0,bottom:r.innerHeight}}function hg(r,e,t,i,n,s,o,l){let a=r.ownerDocument,h=a.defaultView||window;for(let u=r;u;)if(u.nodeType==1){let d,p=u==a.body;if(p)d=ag(h);else{if(u.scrollHeight<=u.clientHeight&&u.scrollWidth<=u.clientWidth){u=u.assignedSlot||u.parentNode;continue}let c=u.getBoundingClientRect();d={left:c.left,right:c.left+u.clientWidth,top:c.top,bottom:c.top+u.clientHeight}}let g=0,y=0;if(n=="nearest")e.top0&&e.bottom>d.bottom+y&&(y=e.bottom-d.bottom+y+o)):e.bottom>d.bottom&&(y=e.bottom-d.bottom+o,t<0&&e.top-y0&&e.right>d.right+g&&(g=e.right-d.right+g+s)):e.right>d.right&&(g=e.right-d.right+s,t<0&&e.leftt)return d.domBoundsAround(e,t,h);if(p>=e&&n==-1&&(n=a,s=h),h>t&&d.dom.parentNode==this.dom){o=a,l=u;break}u=p,h=p+d.breakAfter}return{from:s,to:l<0?i+this.length:l,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o=0?this.children[o].dom:null}}markDirty(e=!1){this.dirty|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.dirty|=2),t.dirty&1)return;t.dirty|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.dirty&&this.markParentsDirty(!0))}setDOM(e){this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,i=Pl){this.markDirty();for(let n=e;nthis.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Lc(r,e,t,i,n,s,o,l,a){let{children:h}=r,u=h.length?h[e]:null,d=s.length?s[s.length-1]:null,p=d?d.breakAfter:o;if(!(e==i&&u&&!o&&!p&&s.length<2&&u.merge(t,n,s.length?d:null,t==0,l,a))){if(i0&&(!o&&s.length&&u.merge(t,u.length,s[0],!1,l,0)?u.breakAfter=s.shift().breakAfter:(t2);var L={mac:sh||/Mac/.test(it.platform),windows:/Win/.test(it.platform),linux:/Linux|X11/.test(it.platform),ie:fr,ie_version:zc?$o.documentMode||6:Jo?+Jo[1]:Wo?+Wo[1]:0,gecko:ih,gecko_version:ih?+(/Firefox\/(\d+)/.exec(it.userAgent)||[0,0])[1]:0,chrome:!!Lr,chrome_version:Lr?+Lr[1]:0,ios:sh,android:/Android\b/.test(it.userAgent),webkit:nh,safari:Vc,webkit_version:nh?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:$o.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const dg=256;class oi extends re{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,i){return i&&(!(i instanceof oi)||this.length-(t-e)+i.length>dg)?!1:(this.text=this.text.slice(0,e)+(i?i.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new oi(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new He(this.dom,e)}domBoundsAround(e,t,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return Uo(this.dom,e,t)}}class Ft extends re{constructor(e,t=[],i=0){super(),this.mark=e,this.children=t,this.length=i;for(let n of t)n.setParent(this)}setAttrs(e){if(Nc(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.dirty|=6)}sync(e){this.dom?this.dirty&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e)}merge(e,t,i,n,s,o){return i&&(!(i instanceof Ft&&i.mark.eq(this.mark))||e&&s<=0||te&&t.push(i=e&&(n=s),i=a,s++}let o=this.length-e;return this.length=e,n>-1&&(this.children.length=n,this.markDirty()),new Ft(this.mark,t,o)}domAtPos(e){return Wc(this,e)}coordsAt(e,t){return Uc(this,e,t)}}function Uo(r,e,t){let i=r.nodeValue.length;e>i&&(e=i);let n=e,s=e,o=0;e==0&&t<0||e==i&&t>=0?L.chrome||L.gecko||(e?(n--,o=1):s=0)?0:l.length-1];return L.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?Ol(a,o<0):a||null}class Zt extends re{constructor(e,t,i){super(),this.widget=e,this.length=t,this.side=i,this.prevWidget=null}static create(e,t,i){return new(e.customView||Zt)(e,t,i)}split(e){let t=Zt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}getSide(){return this.side}merge(e,t,i,n,s,o){return i&&(!(i instanceof Zt)||!this.widget.compare(i.widget)||e>0&&s<=0||t0?i.length-1:0;n=i[s],!(e>0?s==0:s==i.length-1||n.top0?-1:1);return this.length?n:Ol(n,this.side>0)}get isEditable(){return!1}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class Hc extends Zt{domAtPos(e){let{topView:t,text:i}=this.widget;return t?Xo(e,0,t,i,(n,s)=>n.domAtPos(s),n=>new He(i,Math.min(n,i.nodeValue.length))):new He(i,Math.min(e,i.nodeValue.length))}sync(){this.setDOM(this.widget.toDOM())}localPosFromDOM(e,t){let{topView:i,text:n}=this.widget;return i?$c(e,t,i,n):Math.min(t,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(e,t){let{topView:i,text:n}=this.widget;return i?Xo(e,t,i,n,(s,o,l)=>s.coordsAt(o,l),(s,o)=>Uo(n,s,o)):Uo(n,e,t)}destroy(){var e;super.destroy(),(e=this.widget.topView)===null||e===void 0||e.destroy()}get isEditable(){return!0}canReuseDOM(){return!0}}function Xo(r,e,t,i,n,s){if(t instanceof Ft){for(let o=t.dom.firstChild;o;o=o.nextSibling){let l=re.get(o);if(!l)return s(r,e);let a=ji(o,i),h=l.length+(a?i.nodeValue.length:0);if(r0?-1:1);return i&&i.topt.top?{left:t.left,right:t.right,top:i.top,bottom:i.bottom}:t}get overrideDOMText(){return Y.empty}}oi.prototype.children=Zt.prototype.children=Gi.prototype.children=Pl;function pg(r,e){let t=r.parent,i=t?t.children.indexOf(r):-1;for(;t&&i>=0;)if(e<0?i>0:is&&e0;s--){let o=i[s-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let s=n;s0&&e instanceof Ft&&n.length&&(i=n[n.length-1])instanceof Ft&&i.mark.eq(e.mark)?Jc(i,e.children[0],t-1):(n.push(e),e.setParent(r)),r.length+=e.length}function Uc(r,e,t){let i=null,n=-1,s=null,o=-1;function l(h,u){for(let d=0,p=0;d=u&&(g.children.length?l(g,u-p):!s&&(y>u||p==y&&g.getSide()>0)?(s=g,o=u-p):(p0?3e8:-4e8:t>0?1e8:-1e8,new Si(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,n;if(e.isBlockGap)i=-5e8,n=4e8;else{let{start:s,end:o}=Xc(e,t);i=(s?t?-3e8:-1:5e8)-1,n=(o?t?2e8:1:-6e8)+1}return new Si(e,i,n,t,e.widget||null,!0)}static line(e){return new Jn(e)}static set(e,t=!1){return ye.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}Me.none=ye.empty;class pr extends Me{constructor(e){let{start:t,end:i}=Xc(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){return this==e||e instanceof pr&&this.tagName==e.tagName&&this.class==e.class&&Nl(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}pr.prototype.point=!1;class Jn extends Me{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Jn&&Nl(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}Jn.prototype.mapMode=tt.TrackBefore;Jn.prototype.point=!0;class Si extends Me{constructor(e,t,i,n,s,o){super(t,i,s,e),this.block=n,this.isReplace=o,this.mapMode=n?t<=0?tt.TrackBefore:tt.TrackAfter:tt.TrackDel}get type(){return this.startSide=5}eq(e){return e instanceof Si&&gg(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}Si.prototype.point=!0;function Xc(r,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=r;return t==null&&(t=r.inclusive),i==null&&(i=r.inclusive),{start:t??e,end:i??e}}function gg(r,e){return r==e||!!(r&&e&&r.compare(e))}function jo(r,e,t,i=0){let n=t.length-1;n>=0&&t[n]+i>=r?t[n]=Math.max(t[n],e):t.push(r,e)}class Ue extends re{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,i,n,s,o){if(i){if(!(i instanceof Ue))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),Rc(this,e,t,i?i.children:[],s,o),!0}split(e){let t=new Ue;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i,off:n}=this.childPos(e);n&&(t.append(this.children[i].split(n),0),this.children[i].merge(n,this.children[i].length,null,!1,0,0),i++);for(let s=i;s0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=e,t}transferDOM(e){!this.dom||(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){Nl(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Jc(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=Ko(t,this.attrs||{})),i&&(this.attrs=Ko({class:i},this.attrs||{}))}domAtPos(e){return Wc(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.dirty|=6)}sync(e){var t;this.dom?this.dirty&4&&(Nc(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(_o(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e);let i=this.dom.lastChild;for(;i&&re.get(i)instanceof Ft;)i=i.lastChild;if(!i||!this.length||i.nodeName!="BR"&&((t=re.get(i))===null||t===void 0?void 0:t.isEditable)==!1&&(!L.ios||!this.children.some(n=>n instanceof oi))){let n=document.createElement("BR");n.cmIgnore=!0,this.dom.appendChild(n)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0;for(let t of this.children){if(!(t instanceof oi)||/[^ -~]/.test(t.text))return null;let i=Ln(t.dom);if(i.length!=1)return null;e+=i[0].width}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length}:null}coordsAt(e,t){return Uc(this,e,t)}become(e){return!1}get type(){return De.Text}static find(e,t){for(let i=0,n=0;i=t){if(s instanceof Ue)return s;if(o>t)break}n=o+s.breakAfter}return null}}class xi extends re{constructor(e,t,i){super(),this.widget=e,this.length=t,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(e,t,i,n,s,o){return i&&(!(i instanceof xi)||!this.widget.compare(i.widget)||e>0&&s<=0||t0;){if(this.textOff==this.text.length){let{value:s,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer([]),this.curLine=null,e--;continue}else this.text=s,this.textOff=0}let n=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-i)),this.getLine().append(ss(new oi(this.text.slice(this.textOff,this.textOff+n)),t),i),this.atCursorPos=!0,this.textOff+=n,e-=n,i=0}}span(e,t,i,n){this.buildText(t-e,i,n),this.pos=t,this.openStart<0&&(this.openStart=n)}point(e,t,i,n,s,o){if(this.disallowBlockEffectsFor[o]&&i instanceof Si){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=t-e;if(i instanceof Si)if(i.block){let{type:a}=i;a==De.WidgetAfter&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new xi(i.widget||new rh("div"),l,a))}else{let a=Zt.create(i.widget||new rh("span"),l,l?0:i.startSide),h=this.atCursorPos&&!a.isEditable&&s<=n.length&&(e0),u=!a.isEditable&&(er.some(e=>e)}),yg=U.define({combine:r=>r.some(e=>e)});class Ks{constructor(e,t="nearest",i="nearest",n=5,s=5){this.range=e,this.y=t,this.x=i,this.yMargin=n,this.xMargin=s}map(e){return e.empty?this:new Ks(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin)}}const oh=ke.define({map:(r,e)=>r.map(e)});function ni(r,e,t){let i=r.facet(qc);i.length?i[0](e):window.onerror?window.onerror(String(e),t,void 0,void 0,e):t?console.error(t+":",e):console.error(e)}const mr=U.define({combine:r=>r.length?r[0]:!0});let xg=0;const xn=U.define();class zn{constructor(e,t,i,n){this.id=e,this.create=t,this.domEventHandlers=i,this.extension=n(this)}static define(e,t){const{eventHandlers:i,provide:n,decorations:s}=t||{};return new zn(xg++,e,i,o=>{let l=[xn.of(o)];return s&&l.push(Vn.of(a=>{let h=a.plugin(o);return h?s(h):Me.none})),n&&l.push(n(o)),l})}static fromClass(e,t){return zn.define(i=>new e(i),t)}}class Rr{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(ni(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){ni(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){ni(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Zc=U.define(),Ll=U.define(),Vn=U.define(),Qc=U.define(),ef=U.define(),vn=U.define();class Ct{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new Ct(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toAu)break;s+=2}if(!a)return i;new Ct(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}}class _s{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=be.empty(this.startState.doc.length);for(let o of i)this.changes=this.changes.compose(o.changes);let n=[];this.changes.iterChangedRanges((o,l,a,h)=>n.push(new Ct(o,l,a,h))),this.changedRanges=n;let s=e.hasFocus;s!=e.inputState.notifiedFocused&&(e.inputState.notifiedFocused=s,this.flags|=1)}static create(e,t,i){return new _s(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}var Xe=function(r){return r[r.LTR=0]="LTR",r[r.RTL=1]="RTL",r}(Xe||(Xe={}));const Go=Xe.LTR,vg=Xe.RTL;function tf(r){let e=[];for(let t=0;t=t){if(l.level==i)return o;(s<0||(n!=0?n<0?l.fromt:e[s].level>l.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}}const le=[];function kg(r,e){let t=r.length,i=e==Go?1:2,n=e==Go?2:1;if(!r||i==1&&!bg.test(r))return nf(t);for(let o=0,l=i,a=i;o=0;p-=3)if(ct[p+1]==-u){let g=ct[p+2],y=g&2?i:g&4?g&1?n:i:0;y&&(le[o]=le[ct[p]]=y),l=p;break}}else{if(ct.length==189)break;ct[l++]=o,ct[l++]=h,ct[l++]=a}else if((d=le[o])==2||d==1){let p=d==i;a=p?0:1;for(let g=l-3;g>=0;g-=3){let y=ct[g+2];if(y&2)break;if(p)ct[g+2]|=2;else{if(y&4)break;ct[g+2]|=4}}}for(let o=0;ol;){let u=h,d=le[--h]!=2;for(;h>l&&d==(le[h-1]!=2);)h--;s.push(new Ri(h,u,d?2:1))}else s.push(new Ri(l,o,0))}else for(let o=0;o1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=s+o}}readNode(e){if(e.cmIgnore)return;let t=re.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+Math.min(t,i.offset))}}function lh(r){return r.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(r.nodeName)}class ah{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class hh extends re{constructor(e){super(),this.view=e,this.compositionDeco=Me.none,this.decorations=[],this.dynamicDecorationMap=[],this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new Ue],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Ct(0,0,0,e.state.doc.length)],0)}get editorView(){return this.view}get length(){return this.view.state.doc.length}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:o,toA:l})=>lthis.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.view.inputState.composing<0?this.compositionDeco=Me.none:(e.transactions.length||this.dirty)&&(this.compositionDeco=Eg(this.view,e.changes)),(L.ie||L.chrome)&&!this.compositionDeco.size&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,n=this.updateDeco(),s=Mg(i,n,e.changes);return t=Ct.extendWithRanges(t,s),this.dirty==0&&t.length==0?!1:(this.updateInner(t,e.startState.doc.length),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t);let{observer:i}=this.view;i.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=L.chrome||L.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.sync(s),this.dirty=0,s&&(s.written||i.selectionRange.focusNode!=s.node)&&(this.forceSelection=!0),this.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to=0?e[n]:null;if(!s)break;let{fromA:o,toA:l,fromB:a,toB:h}=s,{content:u,breakAtStart:d,openStart:p,openEnd:g}=Il.build(this.view.state.doc,a,h,this.decorations,this.dynamicDecorationMap),{i:y,off:c}=i.findPos(l,1),{i:f,off:m}=i.findPos(o,-1);Lc(this,f,m,y,c,u,d,p,g)}}updateSelection(e=!1,t=!1){if((e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange(),!(t||this.mayControlSelection()))return;let i=this.forceSelection;this.forceSelection=!1;let n=this.view.state.selection.main,s=this.domAtPos(n.anchor),o=n.empty?s:this.domAtPos(n.head);if(L.gecko&&n.empty&&Cg(s)){let a=document.createTextNode("");this.view.observer.ignore(()=>s.node.insertBefore(a,s.node.childNodes[s.offset]||null)),s=o=new He(a,0),i=!0}let l=this.view.observer.selectionRange;(i||!l.focusNode||!Us(s.node,s.offset,l.anchorNode,l.anchorOffset)||!Us(o.node,o.offset,l.focusNode,l.focusOffset))&&(this.view.observer.ignore(()=>{L.android&&L.chrome&&this.dom.contains(l.focusNode)&&Og(l.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let a=Js(this.view.root);if(a)if(n.empty){if(L.gecko){let h=Bg(s.node,s.offset);if(h&&h!=3){let u=lf(s.node,s.offset,h==1?1:-1);u&&(s=new He(u,h==1?0:u.nodeValue.length))}}a.collapse(s.node,s.offset),n.bidiLevel!=null&&l.cursorBidiLevel!=null&&(l.cursorBidiLevel=n.bidiLevel)}else if(a.extend){a.collapse(s.node,s.offset);try{a.extend(o.node,o.offset)}catch{}}else{let h=document.createRange();n.anchor>n.head&&([s,o]=[o,s]),h.setEnd(o.node,o.offset),h.setStart(s.node,s.offset),a.removeAllRanges(),a.addRange(h)}}),this.view.observer.setSelectionRange(s,o)),this.impreciseAnchor=s.precise?null:new He(l.anchorNode,l.anchorOffset),this.impreciseHead=o.precise?null:new He(l.focusNode,l.focusOffset)}enforceCursorAssoc(){if(this.compositionDeco.size)return;let{view:e}=this,t=e.state.selection.main,i=Js(e.root),{anchorNode:n,anchorOffset:s}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=Ue.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let u=this.domAtPos(t.head+t.assoc);i.collapse(u.node,u.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let d=e.observer.selectionRange;e.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=t.from&&i.collapse(n,s)}mayControlSelection(){let e=this.view.root.activeElement;return e==this.dom||As(this.dom,this.view.observer.selectionRange)&&!(e&&this.dom.contains(e))}nearest(e){for(let t=e;t;){let i=re.get(t);if(i&&i.rootView==this)return i;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;to||e==o&&s.type!=De.WidgetBefore&&s.type!=De.WidgetAfter&&(!n||t==2||this.children[n-1].breakAfter||this.children[n-1].type==De.WidgetBefore&&t>-2))return s.coordsAt(e-o,t);i=o}}measureVisibleLineHeights(e){let t=[],{from:i,to:n}=e,s=this.view.contentDOM.clientWidth,o=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==Xe.LTR;for(let h=0,u=0;un)break;if(h>=i){let g=d.dom.getBoundingClientRect();if(t.push(g.height),o){let y=d.dom.lastChild,c=y?Ln(y):[];if(c.length){let f=c[c.length-1],m=a?f.right-g.left:g.right-f.left;m>l&&(l=m,this.minWidth=s,this.minWidthFrom=h,this.minWidthTo=p)}}}h=p+d.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?Xe.RTL:Xe.LTR}measureTextSize(){for(let n of this.children)if(n instanceof Ue){let s=n.measureTextSize();if(s)return s}let e=document.createElement("div"),t,i;return e.className="cm-line",e.style.width="99999px",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let n=Ln(e.firstChild)[0];t=e.getBoundingClientRect().height,i=n?n.width/27:7,e.remove()}),{lineHeight:t,charWidth:i}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Ic(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let s=n==t.viewports.length?null:t.viewports[n],o=s?s.from-1:this.length;if(o>i){let l=t.lineBlockAt(o).bottom-t.lineBlockAt(i).top;e.push(Me.replace({widget:new uh(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!s)break;i=s.to+1}return Me.set(e)}updateDeco(){let e=this.view.state.facet(Vn).map((t,i)=>(this.dynamicDecorationMap[i]=typeof t=="function")?t(this.view):t);for(let t=e.length;tt.anchor?-1:1),n;if(!i)return;!t.empty&&(n=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,n.left),top:Math.min(i.top,n.top),right:Math.max(i.right,n.right),bottom:Math.max(i.bottom,n.bottom)});let s=0,o=0,l=0,a=0;for(let u of this.view.state.facet(ef).map(d=>d(this.view)))if(u){let{left:d,right:p,top:g,bottom:y}=u;d!=null&&(s=Math.max(s,d)),p!=null&&(o=Math.max(o,p)),g!=null&&(l=Math.max(l,g)),y!=null&&(a=Math.max(a,y))}let h={left:i.left-s,top:i.top-l,right:i.right+o,bottom:i.bottom+a};hg(this.view.scrollDOM,h,t.head0&&t<=0)r=r.childNodes[e-1],e=Rn(r);else if(r.nodeType==1&&e=0)r=r.childNodes[e],e=0;else return null}}function Bg(r,e){return r.nodeType!=1?0:(e&&r.childNodes[e-1].contentEditable=="false"?1:0)|(e0;){let h=Gt(n.text,o,!1);if(i(n.text.slice(h,o))!=a)break;o=h}for(;lr?e.left-r:Math.max(0,r-e.right)}function Ig(r,e){return e.top>r?e.top-r:Math.max(0,r-e.bottom)}function zr(r,e){return r.tope.top+1}function ch(r,e){return er.bottom?{top:r.top,left:r.left,right:r.right,bottom:e}:r}function Zo(r,e,t){let i,n,s,o,l=!1,a,h,u,d;for(let y=r.firstChild;y;y=y.nextSibling){let c=Ln(y);for(let f=0;fv||o==v&&s>x)&&(i=y,n=m,s=x,o=v,l=!x||(x>0?f0)),x==0?t>m.bottom&&(!u||u.bottomm.top)&&(h=y,d=m):u&&zr(u,m)?u=fh(u,m.bottom):d&&zr(d,m)&&(d=ch(d,m.top))}}if(u&&u.bottom>=t?(i=a,n=u):d&&d.top<=t&&(i=h,n=d),!i)return{node:r,offset:0};let p=Math.max(n.left,Math.min(n.right,e));if(i.nodeType==3)return dh(i,p,t);if(l&&i.contentEditable!="false")return Zo(i,p,t);let g=Array.prototype.indexOf.call(r.childNodes,i)+(e>=(n.left+n.right)/2?1:0);return{node:r,offset:g}}function dh(r,e,t){let i=r.nodeValue.length,n=-1,s=1e9,o=0;for(let l=0;lt?u.top-t:t-u.bottom)-1;if(u.left-1<=e&&u.right+1>=e&&d=(u.left+u.right)/2,g=p;if((L.chrome||L.gecko)&&qi(r,l).getBoundingClientRect().left==u.right&&(g=!p),d<=0)return{node:r,offset:l+(g?1:0)};n=l+(g?1:0),s=d}}}return{node:r,offset:n>-1?n:o>0?r.nodeValue.length:0}}function af(r,{x:e,y:t},i,n=-1){var s;let o=r.contentDOM.getBoundingClientRect(),l=o.top+r.viewState.paddingTop,a,{docHeight:h}=r.viewState,u=t-l;if(u<0)return 0;if(u>h)return r.state.doc.length;for(let m=r.defaultLineHeight/2,x=!1;a=r.elementAtHeight(u),a.type!=De.Text;)for(;u=n>0?a.bottom+m:a.top-m,!(u>=0&&u<=h);){if(x)return i?null:0;x=!0,n=-n}t=l+u;let d=a.from;if(dr.viewport.to)return r.viewport.to==r.state.doc.length?r.state.doc.length:i?null:ph(r,o,a,e,t);let p=r.dom.ownerDocument,g=r.root.elementFromPoint?r.root:p,y=g.elementFromPoint(e,t);y&&!r.contentDOM.contains(y)&&(y=null),y||(e=Math.max(o.left+1,Math.min(o.right-1,e)),y=g.elementFromPoint(e,t),y&&!r.contentDOM.contains(y)&&(y=null));let c,f=-1;if(y&&((s=r.docView.nearest(y))===null||s===void 0?void 0:s.isEditable)!=!1){if(p.caretPositionFromPoint){let m=p.caretPositionFromPoint(e,t);m&&({offsetNode:c,offset:f}=m)}else if(p.caretRangeFromPoint){let m=p.caretRangeFromPoint(e,t);m&&({startContainer:c,startOffset:f}=m,(!r.contentDOM.contains(c)||L.safari&&Lg(c,f,e)||L.chrome&&Rg(c,f,e))&&(c=void 0))}}if(!c||!r.docView.dom.contains(c)){let m=Ue.find(r.docView,d);if(!m)return u>a.top+a.height/2?a.to:a.from;({node:c,offset:f}=Zo(m.dom,e,t))}return r.docView.posFromDOM(c,f)}function ph(r,e,t,i,n){let s=Math.round((i-e.left)*r.defaultCharacterWidth);if(r.lineWrapping&&t.height>r.defaultLineHeight*1.5){let l=Math.floor((n-t.top)/r.defaultLineHeight);s+=l*r.viewState.heightOracle.lineLength}let o=r.state.sliceDoc(t.from,t.to);return t.from+sg(o,s,r.state.tabSize)}function Lg(r,e,t){let i;if(r.nodeType!=3||e!=(i=r.nodeValue.length))return!1;for(let n=r.nextSibling;n;n=n.nextSibling)if(n.nodeType!=1||n.nodeName!="BR")return!1;return qi(r,i-1,i).getBoundingClientRect().left>t}function Rg(r,e,t){if(e!=0)return!1;for(let n=r;;){let s=n.parentNode;if(!s||s.nodeType!=1||s.firstChild!=n)return!1;if(s.classList.contains("cm-line"))break;n=s}let i=r.nodeType==1?r.getBoundingClientRect():qi(r,0,Math.max(r.nodeValue.length,1)).getBoundingClientRect();return t-i.left>5}function zg(r,e,t,i){let n=r.state.doc.lineAt(e.head),s=!i||!r.lineWrapping?null:r.coordsAtPos(e.assoc<0&&e.head>n.from?e.head-1:e.head);if(s){let a=r.dom.getBoundingClientRect(),h=r.textDirectionAt(n.from),u=r.posAtCoords({x:t==(h==Xe.LTR)?a.right-1:a.left+1,y:(s.top+s.bottom)/2});if(u!=null)return z.cursor(u,t?-1:1)}let o=Ue.find(r.docView,e.head),l=o?t?o.posAtEnd:o.posAtStart:t?n.to:n.from;return z.cursor(l,t?-1:1)}function mh(r,e,t,i){let n=r.state.doc.lineAt(e.head),s=r.bidiSpans(n),o=r.textDirectionAt(n.from);for(let l=e,a=null;;){let h=Ag(n,s,o,l,t),u=sf;if(!h){if(n.number==(t?r.state.doc.lines:1))return l;u=` +`,n=r.state.doc.line(n.number+(t?1:-1)),s=r.bidiSpans(n),h=z.cursor(t?n.from:n.to)}if(a){if(!a(u))return l}else{if(!i)return h;a=i(u)}l=h}}function Vg(r,e,t){let i=r.state.charCategorizer(e),n=i(t);return s=>{let o=i(s);return n==Pt.Space&&(n=o),n==o}}function Hg(r,e,t,i){let n=e.head,s=t?1:-1;if(n==(t?r.state.doc.length:0))return z.cursor(n,e.assoc);let o=e.goalColumn,l,a=r.contentDOM.getBoundingClientRect(),h=r.coordsAtPos(n),u=r.documentTop;if(h)o==null&&(o=h.left-a.left),l=s<0?h.top:h.bottom;else{let g=r.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,r.defaultCharacterWidth*(n-g.from))),l=(s<0?g.top:g.bottom)+u}let d=a.left+o,p=i??r.defaultLineHeight>>1;for(let g=0;;g+=10){let y=l+(p+g)*s,c=af(r,{x:d,y},!1,s);if(ya.bottom||(s<0?cn))return z.cursor(c,e.assoc,void 0,o)}}function Vr(r,e,t){let i=r.state.facet(Qc).map(n=>n(r));for(;;){let n=!1;for(let s of i)s.between(t.from-1,t.from+1,(o,l,a)=>{t.from>o&&t.fromt.from?z.cursor(o,1):z.cursor(l,-1),n=!0)});if(!n)return t}}class $g{constructor(e){this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.chromeScrollHack=-1,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.mouseSelection=null;for(let t in Ce){let i=Ce[t];e.contentDOM.addEventListener(t,n=>{!gh(e,n)||this.ignoreDuringComposition(n)||t=="keydown"&&this.keydown(e,n)||(this.mustFlushObserver(n)&&e.observer.forceFlush(),this.runCustomHandlers(t,e,n)?n.preventDefault():i(e,n))},Qo[t]),this.registeredEvents.push(t)}L.chrome&&L.chrome_version==102&&e.scrollDOM.addEventListener("wheel",()=>{this.chromeScrollHack<0?e.contentDOM.style.pointerEvents="none":window.clearTimeout(this.chromeScrollHack),this.chromeScrollHack=setTimeout(()=>{this.chromeScrollHack=-1,e.contentDOM.style.pointerEvents=""},100)},{passive:!0}),this.notifiedFocused=e.hasFocus,L.safari&&e.contentDOM.addEventListener("input",()=>null)}setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}ensureHandlers(e,t){var i;let n;this.customHandlers=[];for(let s of t)if(n=(i=s.update(e).spec)===null||i===void 0?void 0:i.domEventHandlers){this.customHandlers.push({plugin:s.value,handlers:n});for(let o in n)this.registeredEvents.indexOf(o)<0&&o!="scroll"&&(this.registeredEvents.push(o),e.contentDOM.addEventListener(o,l=>{!gh(e,l)||this.runCustomHandlers(o,e,l)&&l.preventDefault()}))}}runCustomHandlers(e,t,i){for(let n of this.customHandlers){let s=n.handlers[e];if(s)try{if(s.call(n.plugin,i,t)||i.defaultPrevented)return!0}catch(o){ni(t.state,o)}}return!1}runScrollHandlers(e,t){this.lastScrollTop=e.scrollDOM.scrollTop,this.lastScrollLeft=e.scrollDOM.scrollLeft;for(let i of this.customHandlers){let n=i.handlers.scroll;if(n)try{n.call(i.plugin,t,e)}catch(s){ni(e.state,s)}}}keydown(e,t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&Date.now()n.keyCode==t.keyCode))&&!t.ctrlKey||Wg.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=i||t,setTimeout(()=>this.flushIOSKey(e),250),!0):!1}flushIOSKey(e){let t=this.pendingIOSKey;return t?(this.pendingIOSKey=void 0,Li(e.contentDOM,t.key,t.keyCode)):!1}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:L.safari&&!L.ios&&Date.now()-this.compositionEndedAt<100?(this.compositionEndedAt=0,!0):!1:!1}mustFlushObserver(e){return e.type=="keydown"&&e.keyCode!=229}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.mouseSelection&&this.mouseSelection.update(e),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}const hf=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Wg="dthko",Jg=[16,17,18,20,91,92,224,225];class Ug{constructor(e,t,i,n){this.view=e,this.style=i,this.mustSelect=n,this.lastEvent=t;let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(Q.allowMultipleSelections)&&Xg(e,t),this.dragMove=Kg(e,t),this.dragging=_g(e,t)&&df(t)==1?null:!1,this.dragging===!1&&(t.preventDefault(),this.select(t))}move(e){if(e.buttons==0)return this.destroy();this.dragging===!1&&this.select(this.lastEvent=e)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}select(e){let t=this.style.get(e,this.extend,this.multiple);(this.mustSelect||!t.eq(this.view.state.selection)||t.main.assoc!=this.view.state.selection.main.assoc)&&this.view.dispatch({selection:t,userEvent:"select.pointer",scrollIntoView:!0}),this.mustSelect=!1}update(e){e.docChanged&&this.dragging&&(this.dragging=this.dragging.map(e.changes)),this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Xg(r,e){let t=r.state.facet(Kc);return t.length?t[0](e):L.mac?e.metaKey:e.ctrlKey}function Kg(r,e){let t=r.state.facet(_c);return t.length?t[0](e):L.mac?!e.altKey:!e.ctrlKey}function _g(r,e){let{main:t}=r.state.selection;if(t.empty)return!1;let i=Js(r.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let s=0;s=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function gh(r,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=r.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=re.get(t))&&i.ignoreEvent(e))return!1;return!0}const Ce=Object.create(null),Qo=Object.create(null),uf=L.ie&&L.ie_version<15||L.ios&&L.webkit_version<604;function jg(r){let e=r.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{r.focus(),t.remove(),cf(r,t.value)},50)}function cf(r,e){let{state:t}=r,i,n=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(el!=null&&t.selection.ranges.every(a=>a.empty)&&el==s.toString()){let a=-1;i=t.changeByRange(h=>{let u=t.doc.lineAt(h.from);if(u.from==a)return{range:h};a=u.from;let d=t.toText((o?s.line(n++).text:e)+t.lineBreak);return{changes:{from:u.from,insert:d},range:z.cursor(h.from+d.length)}})}else o?i=t.changeByRange(a=>{let h=s.line(n++);return{changes:{from:a.from,to:a.to,insert:h.text},range:z.cursor(a.from+h.length)}}):i=t.replaceSelection(s);r.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Ce.keydown=(r,e)=>{r.inputState.setSelectionOrigin("select"),e.keyCode==27?r.inputState.lastEscPress=Date.now():Jg.indexOf(e.keyCode)<0&&(r.inputState.lastEscPress=0)};Ce.touchstart=(r,e)=>{r.inputState.lastTouchTime=Date.now(),r.inputState.setSelectionOrigin("select.pointer")};Ce.touchmove=r=>{r.inputState.setSelectionOrigin("select.pointer")};Qo.touchstart=Qo.touchmove={passive:!0};Ce.mousedown=(r,e)=>{if(r.observer.flush(),r.inputState.lastTouchTime>Date.now()-2e3)return;let t=null;for(let i of r.state.facet(jc))if(t=i(r,e),t)break;if(!t&&e.button==0&&(t=Yg(r,e)),t){let i=r.root.activeElement!=r.contentDOM;i&&r.observer.ignore(()=>Pc(r.contentDOM)),r.inputState.startMouseSelection(new Ug(r,e,t,i))}};function yh(r,e,t,i){if(i==1)return z.cursor(e,t);if(i==2)return Pg(r.state,e,t);{let n=Ue.find(r.docView,e),s=r.state.doc.lineAt(n?n.posAtEnd:e),o=n?n.posAtStart:s.from,l=n?n.posAtEnd:s.to;return lr>=e.top&&r<=e.bottom,xh=(r,e,t)=>ff(e,t)&&r>=t.left&&r<=t.right;function qg(r,e,t,i){let n=Ue.find(r.docView,e);if(!n)return 1;let s=e-n.posAtStart;if(s==0)return 1;if(s==n.length)return-1;let o=n.coordsAt(s,-1);if(o&&xh(t,i,o))return-1;let l=n.coordsAt(s,1);return l&&xh(t,i,l)?1:o&&ff(i,o)?-1:1}function vh(r,e){let t=r.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:qg(r,t,e.clientX,e.clientY)}}const Gg=L.ie&&L.ie_version<=11;let wh=null,Sh=0,Dh=0;function df(r){if(!Gg)return r.detail;let e=wh,t=Dh;return wh=r,Dh=Date.now(),Sh=!e||t>Date.now()-400&&Math.abs(e.clientX-r.clientX)<2&&Math.abs(e.clientY-r.clientY)<2?(Sh+1)%3:1}function Yg(r,e){let t=vh(r,e),i=df(e),n=r.state.selection,s=t,o=e;return{update(l){l.docChanged&&(t.pos=l.changes.mapPos(t.pos),n=n.map(l.changes),o=null)},get(l,a,h){let u;o&&l.clientX==o.clientX&&l.clientY==o.clientY?u=s:(u=s=vh(r,l),o=l);let d=yh(r,u.pos,u.bias,i);if(t.pos!=u.pos&&!a){let p=yh(r,t.pos,t.bias,i),g=Math.min(p.from,d.from),y=Math.max(p.to,d.to);d=g1&&n.ranges.some(p=>p.eq(d))?Zg(n,d):h?n.addRange(d):z.create([d])}}}function Zg(r,e){for(let t=0;;t++)if(r.ranges[t].eq(e))return z.create(r.ranges.slice(0,t).concat(r.ranges.slice(t+1)),r.mainIndex==t?0:r.mainIndex-(r.mainIndex>t?1:0))}Ce.dragstart=(r,e)=>{let{selection:{main:t}}=r.state,{mouseSelection:i}=r.inputState;i&&(i.dragging=t),e.dataTransfer&&(e.dataTransfer.setData("Text",r.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove")};function bh(r,e,t,i){if(!t)return;let n=r.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:s}=r.inputState,o=i&&s&&s.dragging&&s.dragMove?{from:s.dragging.from,to:s.dragging.to}:null,l={from:n,insert:t},a=r.state.changes(o?[o,l]:l);r.focus(),r.dispatch({changes:a,selection:{anchor:a.mapPos(n,-1),head:a.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"})}Ce.drop=(r,e)=>{if(!e.dataTransfer)return;if(r.state.readOnly)return e.preventDefault();let t=e.dataTransfer.files;if(t&&t.length){e.preventDefault();let i=Array(t.length),n=0,s=()=>{++n==t.length&&bh(r,e,i.filter(o=>o!=null).join(r.state.lineBreak),!1)};for(let o=0;o{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),s()},l.readAsText(t[o])}}else bh(r,e,e.dataTransfer.getData("Text"),!0)};Ce.paste=(r,e)=>{if(r.state.readOnly)return e.preventDefault();r.observer.flush();let t=uf?null:e.clipboardData;t?(cf(r,t.getData("text/plain")),e.preventDefault()):jg(r)};function Qg(r,e){let t=r.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),r.focus()},50)}function e0(r){let e=[],t=[],i=!1;for(let n of r.selection.ranges)n.empty||(e.push(r.sliceDoc(n.from,n.to)),t.push(n));if(!e.length){let n=-1;for(let{from:s}of r.selection.ranges){let o=r.doc.lineAt(s);o.number>n&&(e.push(o.text),t.push({from:o.from,to:Math.min(r.doc.length,o.to+1)})),n=o.number}i=!0}return{text:e.join(r.lineBreak),ranges:t,linewise:i}}let el=null;Ce.copy=Ce.cut=(r,e)=>{let{text:t,ranges:i,linewise:n}=e0(r.state);if(!t&&!n)return;el=n?t:null;let s=uf?null:e.clipboardData;s?(e.preventDefault(),s.clearData(),s.setData("text/plain",t)):Qg(r,t),e.type=="cut"&&!r.state.readOnly&&r.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"})};function pf(r){setTimeout(()=>{r.hasFocus!=r.inputState.notifiedFocused&&r.update([])},10)}Ce.focus=r=>{r.inputState.lastFocusTime=Date.now(),!r.scrollDOM.scrollTop&&(r.inputState.lastScrollTop||r.inputState.lastScrollLeft)&&(r.scrollDOM.scrollTop=r.inputState.lastScrollTop,r.scrollDOM.scrollLeft=r.inputState.lastScrollLeft),pf(r)};Ce.blur=r=>{r.observer.clearSelectionRange(),pf(r)};Ce.compositionstart=Ce.compositionupdate=r=>{r.inputState.compositionFirstChange==null&&(r.inputState.compositionFirstChange=!0),r.inputState.composing<0&&(r.inputState.composing=0)};Ce.compositionend=r=>{r.inputState.composing=-1,r.inputState.compositionEndedAt=Date.now(),r.inputState.compositionFirstChange=null,L.chrome&&L.android&&r.observer.flushSoon(),setTimeout(()=>{r.inputState.composing<0&&r.docView.compositionDeco.size&&r.update([])},50)};Ce.contextmenu=r=>{r.inputState.lastContextMenu=Date.now()};Ce.beforeinput=(r,e)=>{var t;let i;if(L.chrome&&L.android&&(i=hf.find(n=>n.inputType==e.inputType))&&(r.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let n=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var s;(((s=window.visualViewport)===null||s===void 0?void 0:s.height)||0)>n+10&&r.hasFocus&&(r.contentDOM.blur(),r.focus())},100)}};const kh=["pre-wrap","normal","pre-line","break-spaces"];class t0{constructor(e){this.lineWrapping=e,this.doc=Y.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength)),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return kh.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i-1,l=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=i,this.lineLength=n,l){this.heightSamples={};for(let a=0;a0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>Cs&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return _e.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,n){let s=this;for(let o=n.length-1;o>=0;o--){let{fromA:l,toA:a,fromB:h,toB:u}=n[o],d=s.lineAt(l,ie.ByPosNoHeight,t,0,0),p=d.to>=a?d:s.lineAt(a,ie.ByPosNoHeight,t,0,0);for(u+=p.to-a,a=p.to;o>0&&d.from<=n[o-1].toA;)l=n[o-1].fromA,h=n[o-1].fromB,o--,ls*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(s>n*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,s-=l.size}else break;else if(n=s&&o(this.blockAt(0,i,n,s))}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setHeight(e,n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ze extends mf{constructor(e,t){super(e,t,De.Text),this.collapsed=0,this.widgetHeight=0}replace(e,t,i){let n=i[0];return i.length==1&&(n instanceof Ze||n instanceof Fe&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof Fe?n=new Ze(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):_e.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setHeight(e,n.heights[n.index++]):(i||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Fe extends _e{constructor(e){super(e,0)}lines(e,t){let i=e.lineAt(t).number,n=e.lineAt(t+this.length).number;return{firstLine:i,lastLine:n,lineHeight:this.height/(n-i+1)}}blockAt(e,t,i,n){let{firstLine:s,lastLine:o,lineHeight:l}=this.lines(t,n),a=Math.max(0,Math.min(o-s,Math.floor((e-i)/l))),{from:h,length:u}=t.line(s+a);return new ei(h,u,i+l*a,l,De.Text)}lineAt(e,t,i,n,s){if(t==ie.ByHeight)return this.blockAt(e,i,n,s);if(t==ie.ByPosNoHeight){let{from:d,to:p}=i.lineAt(e);return new ei(d,p-d,0,0,De.Text)}let{firstLine:o,lineHeight:l}=this.lines(i,s),{from:a,length:h,number:u}=i.lineAt(e);return new ei(a,h,n+l*(u-o),l,De.Text)}forEachLine(e,t,i,n,s,o){let{firstLine:l,lineHeight:a}=this.lines(i,s);for(let h=Math.max(e,s),u=Math.min(s+this.length,t);h<=u;){let d=i.lineAt(h);h==e&&(n+=a*(d.number-l)),o(new ei(d.from,d.length,n,a,De.Text)),n+=a,h=d.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let s=i[i.length-1];s instanceof Fe?i[i.length-1]=new Fe(s.length+n):i.push(null,new Fe(n-1))}if(e>0){let s=i[0];s instanceof Fe?i[0]=new Fe(e+s.length):i.unshift(new Fe(e-1),null)}return _e.of(i)}decomposeLeft(e,t){t.push(new Fe(e-1),null)}decomposeRight(e,t){t.push(null,new Fe(this.length-e-1))}updateHeight(e,t=0,i=!1,n){let s=t+this.length;if(n&&n.from<=t+this.length&&n.more){let o=[],l=Math.max(t,n.from),a=-1,h=e.heightChanged;for(n.from>t&&o.push(new Fe(n.from-t-1).updateHeight(e,t));l<=s&&n.more;){let d=e.doc.lineAt(l).length;o.length&&o.push(null);let p=n.heights[n.index++];a==-1?a=p:Math.abs(p-a)>=Cs&&(a=-2);let g=new Ze(d,p);g.outdated=!1,o.push(g),l+=d+1}l<=s&&o.push(null,new Fe(s-l).updateHeight(e,l));let u=_e.of(o);return e.heightChanged=h||a<0||Math.abs(u.height-this.height)>=Cs||Math.abs(a-this.lines(e.doc,t).lineHeight)>=Cs,u}else(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class n0 extends _e{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,n){let s=i+this.left.height;return el))return h;let u=t==ie.ByPosNoHeight?ie.ByPosNoHeight:ie.ByPos;return a?h.join(this.right.lineAt(l,u,i,o,l)):this.left.lineAt(l,u,i,n,s).join(h)}forEachLine(e,t,i,n,s,o){let l=n+this.left.height,a=s+this.left.length+this.break;if(this.break)e=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,ie.ByPos,i,n,s);e=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let n=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let l of i)s.push(l);if(e>0&&Ah(s,o-1),t=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e2*t.size||t.size>2*e.size?_e.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,n){let{left:s,right:o}=this,l=t+s.length+this.break,a=null;return n&&n.from<=t+s.length&&n.more?a=s=s.updateHeight(e,t,i,n):s.updateHeight(e,t,i),n&&n.from<=l+o.length&&n.more?a=o=o.updateHeight(e,l,i,n):o.updateHeight(e,l,i),a?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Ah(r,e){let t,i;r[e]==null&&(t=r[e-1])instanceof Fe&&(i=r[e+1])instanceof Fe&&r.splice(e-1,3,new Fe(t.length+1+i.length))}const s0=5;class Rl{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof Ze?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Ze(i-this.pos,-1)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e=s0)&&this.addLineDeco(n,s)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenToe&&this.nodes.push(new Ze(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new Fe(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ze)return e;let t=new Ze(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine(),e.type==De.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,e.type!=De.WidgetBefore&&(this.covering=e)}addLineDeco(e,t){let i=this.ensureLine();i.length+=t,i.collapsed+=t,i.widgetHeight=Math.max(i.widgetHeight,e),this.writtenTo=this.pos=this.pos+t}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ze)&&!this.isCovered?this.nodes.push(new Ze(0,-1)):(this.writtenTou.clientHeight||u.scrollWidth>u.clientWidth)&&d.overflow!="visible"){let p=u.getBoundingClientRect();s=Math.max(s,p.left),o=Math.min(o,p.right),l=Math.max(l,p.top),a=h==r.parentNode?p.bottom:Math.min(a,p.bottom)}h=d.position=="absolute"||d.position=="fixed"?u.offsetParent:u.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function a0(r,e){let t=r.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Hr{constructor(e,t,i){this.from=e,this.to=t,this.size=i}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;itypeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new t0(t),this.stateDeco=e.facet(Vn).filter(i=>typeof i!="function"),this.heightMap=_e.empty().applyChanges(this.stateDeco,Y.empty,this.heightOracle.setDoc(e.doc),[new Ct(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Me.set(this.lineGaps.map(i=>i.draw(!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some(({from:s,to:o})=>n>=s&&n<=o)){let{from:s,to:o}=this.lineBlockAt(n);e.push(new rs(s,o))}}this.viewports=e.sort((i,n)=>i.from-n.from),this.scaler=this.heightMap.height<=7e6?Eh:new f0(this.heightOracle.doc,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.state.doc,0,0,e=>{this.viewportLines.push(this.scaler.scale==1?e:wn(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Vn).filter(h=>typeof h!="function");let n=e.changedRanges,s=Ct.extendWithRanges(n,r0(i,this.stateDeco,e?e.changes:be.empty(this.state.doc.length))),o=this.heightMap.height;this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),this.heightMap.height!=o&&(e.flags|=2);let l=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.headl.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,t));let a=!e.changes.empty||e.flags&2||l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,this.updateForViewport(),a&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>2e3<<1)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(yg)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),n=this.heightOracle,s=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?Xe.RTL:Xe.LTR;let o=this.heightOracle.mustRefreshForWrapping(s),l=o||this.mustMeasureContent||this.contentDOMHeight!=t.clientHeight;this.contentDOMHeight=t.clientHeight,this.mustMeasureContent=!1;let a=0,h=0,u=parseInt(i.paddingTop)||0,d=parseInt(i.paddingBottom)||0;(this.paddingTop!=u||this.paddingBottom!=d)&&(this.paddingTop=u,this.paddingBottom=d,a|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,a|=8);let p=(this.printing?a0:l0)(t,this.paddingTop),g=p.top-this.pixelViewport.top,y=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let c=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(c!=this.inView&&(this.inView=c,c&&(l=!0)),!this.inView&&!this.scrollTarget)return 0;let f=t.clientWidth;if((this.contentDOMWidth!=f||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=f,this.editorHeight=e.scrollDOM.clientHeight,a|=8),l){let x=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(x)&&(o=!0),o||n.lineWrapping&&Math.abs(f-this.contentDOMWidth)>n.charWidth){let{lineHeight:v,charWidth:S}=e.docView.measureTextSize();o=v>0&&n.refresh(s,v,S,f/S,x),o&&(e.docView.minWidth=0,a|=8)}g>0&&y>0?h=Math.max(g,y):g<0&&y<0&&(h=Math.min(g,y)),n.heightChanged=!1;for(let v of this.viewports){let S=v.from==this.viewport.from?x:e.docView.measureVisibleLineHeights(v);this.heightMap=(o?_e.empty().applyChanges(this.stateDeco,Y.empty,this.heightOracle,[new Ct(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new i0(v.from,S))}n.heightChanged&&(a|=2)}let m=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return m&&(this.viewport=this.getViewport(h,this.scrollTarget)),this.updateForViewport(),(a&2||m)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>2e3<<1)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),n=this.heightMap,s=this.state.doc,{visibleTop:o,visibleBottom:l}=this,a=new rs(n.lineAt(o-i*1e3,ie.ByHeight,s,0,0).from,n.lineAt(l+(1-i)*1e3,ie.ByHeight,s,0,0).to);if(t){let{head:h}=t.range;if(ha.to){let u=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),d=n.lineAt(h,ie.ByPos,s,0,0),p;t.y=="center"?p=(d.top+d.bottom)/2-u/2:t.y=="start"||t.y=="nearest"&&h=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&s>1,o=n<<1;if(this.defaultTextDirection!=Xe.LTR&&!i)return[];let l=[],a=(h,u,d,p)=>{if(u-hh&&ff.from>=d.from&&f.to<=d.to&&Math.abs(f.from-h)f.fromm));if(!c){if(uf.from<=u&&f.to>=u)){let f=t.moveToLineBoundary(z.cursor(u),!1,!0).head;f>h&&(u=f)}c=new Hr(h,u,this.gapSize(d,h,u,p))}l.push(c)};for(let h of this.viewportLines){if(h.lengthh.from&&a(h.from,p,h,u),gt.draw(this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];ye.spans(e,this.viewport.from,this.viewport.to,{span(n,s){t.push({from:n,to:s})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some((n,s)=>n.from!=t[s].from||n.to!=t[s].to);return this.visibleRanges=t,i?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||wn(this.heightMap.lineAt(e,ie.ByPos,this.state.doc,0,0),this.scaler)}lineBlockAtHeight(e){return wn(this.heightMap.lineAt(this.scaler.fromDOM(e),ie.ByHeight,this.state.doc,0,0),this.scaler)}elementAtHeight(e){return wn(this.heightMap.blockAt(this.scaler.fromDOM(e),this.state.doc,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class rs{constructor(e,t){this.from=e,this.to=t}}function u0(r,e,t){let i=[],n=r,s=0;return ye.spans(t,r,e,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),s+=o-n),n=l}},20),n=1)return e[e.length-1].to;let i=Math.floor(r*t);for(let n=0;;n++){let{from:s,to:o}=e[n],l=o-s;if(i<=l)return s+i;i-=l}}function ls(r,e){let t=0;for(let{from:i,to:n}of r.ranges){if(e<=n){t+=e-i;break}t+=n-i}return t/r.total}function c0(r,e){for(let t of r)if(e(t))return t}const Eh={toDOM(r){return r},fromDOM(r){return r},scale:1};class f0{constructor(e,t,i){let n=0,s=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,ie.ByPos,e,0,0).top,u=t.lineAt(a,ie.ByPos,e,0,0).bottom;return n+=u-h,{from:l,to:a,top:h,bottom:u,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(t.height-n);for(let l of this.viewports)l.domTop=o+(l.top-s)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),s=l.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let s=twn(n,e)):r.type)}const as=U.define({combine:r=>r.join(" ")}),tl=U.define({combine:r=>r.indexOf(!0)>-1}),il=Ki.newName(),gf=Ki.newName(),yf=Ki.newName(),xf={"&light":"."+gf,"&dark":"."+yf};function nl(r,e,t){return new Ki(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return r;if(!t||!t[n])throw new RangeError(`Unsupported selector: ${n}`);return t[n]}):r+" "+i}})}const d0=nl("."+il,{"&.cm-editor":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,minHeight:"100%",display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},"&.cm-focused .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",left:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},xf);class p0{constructor(e,t,i,n){this.typeOver=n,this.bounds=null,this.text="";let{impreciseHead:s,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let l=s||o?[]:g0(e),a=new rf(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=y0(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!ji(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),h=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!ji(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset);this.newSel=z.single(h,a)}}}function vf(r,e){let t,{newSel:i}=e,n=r.state.selection.main;if(e.bounds){let{from:s,to:o}=e.bounds,l=n.from,a=null;(r.inputState.lastKeyCode===8&&r.inputState.lastKeyTime>Date.now()-100||L.android&&e.text.length=n.from&&t.to<=n.to&&(t.from!=n.from||t.to!=n.to)&&n.to-n.from-(t.to-t.from)<=4?t={from:n.from,to:n.to,insert:r.state.doc.slice(n.from,t.from).append(t.insert).append(r.state.doc.slice(t.to,n.to))}:(L.mac||L.android)&&t&&t.from==t.to&&t.from==n.head-1&&/^\. ?$/.test(t.insert.toString())?(i&&t.insert.length==2&&(i=z.single(i.main.anchor-1,i.main.head-1)),t={from:n.from,to:n.to,insert:Y.of([" "])}):L.chrome&&t&&t.from==t.to&&t.from==n.head&&t.insert.toString()==` + `&&r.lineWrapping&&(i&&(i=z.single(i.main.anchor-1,i.main.head-1)),t={from:n.from,to:n.to,insert:Y.of([" "])}),t){let s=r.state;if(L.ios&&r.inputState.flushIOSKey(r)||L.android&&(t.from==n.from&&t.to==n.to&&t.insert.length==1&&t.insert.lines==2&&Li(r.contentDOM,"Enter",13)||t.from==n.from-1&&t.to==n.to&&t.insert.length==0&&Li(r.contentDOM,"Backspace",8)||t.from==n.from&&t.to==n.to+1&&t.insert.length==0&&Li(r.contentDOM,"Delete",46)))return!0;let o=t.insert.toString();if(r.state.facet(Gc).some(h=>h(r,t.from,t.to,o)))return!0;r.inputState.composing>=0&&r.inputState.composing++;let l;if(t.from>=n.from&&t.to<=n.to&&t.to-t.from>=(n.to-n.from)/3&&(!i||i.main.empty&&i.main.from==t.from+t.insert.length)&&r.inputState.composing<0){let h=n.fromt.to?s.sliceDoc(t.to,n.to):"";l=s.replaceSelection(r.state.toText(h+t.insert.sliceString(0,void 0,r.state.lineBreak)+u))}else{let h=s.changes(t),u=i&&!s.selection.main.eq(i.main)&&i.main.to<=h.newLength?i.main:void 0;if(s.selection.ranges.length>1&&r.inputState.composing>=0&&t.to<=n.to&&t.to>=n.to-10){let d=r.state.sliceDoc(t.from,t.to),p=of(r)||r.state.doc.lineAt(n.head),g=n.to-t.to,y=n.to-n.from;l=s.changeByRange(c=>{if(c.from==n.from&&c.to==n.to)return{changes:h,range:u||c.map(h)};let f=c.to-g,m=f-d.length;if(c.to-c.from!=y||r.state.sliceDoc(m,f)!=d||p&&c.to>=p.from&&c.from<=p.to)return{range:c};let x=s.changes({from:m,to:f,insert:t.insert}),v=c.to-n.to;return{changes:x,range:u?z.range(Math.max(0,u.anchor+v),Math.max(0,u.head+v)):c.map(x)}})}else l={changes:h,selection:u&&s.selection.replaceRange(u)}}let a="input.type";return r.composing&&(a+=".compose",r.inputState.compositionFirstChange&&(a+=".start",r.inputState.compositionFirstChange=!1)),r.dispatch(l,{scrollIntoView:!0,userEvent:a}),!0}else if(i&&!i.main.eq(n)){let s=!1,o="select";return r.inputState.lastSelectionTime>Date.now()-50&&(r.inputState.lastSelectionOrigin=="select"&&(s=!0),o=r.inputState.lastSelectionOrigin),r.dispatch({selection:i,scrollIntoView:s,userEvent:o}),!0}else return!1}function m0(r,e,t,i){let n=Math.min(r.length,e.length),s=0;for(;s0&&l>0&&r.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,s-Math.min(o,l));t-=o+a-s}if(o=o?s-t:0;s-=a,l=s+(l-o),o=s}else if(l=l?s-t:0;s-=a,o=s+(o-l),l=s}return{from:s,toA:o,toB:l}}function g0(r){let e=[];if(r.root.activeElement!=r.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:s}=r.observer.selectionRange;return t&&(e.push(new ah(t,i)),(n!=t||s!=i)&&e.push(new ah(n,s))),e}function y0(r,e){if(r.length==0)return null;let t=r[0].pos,i=r.length==2?r[1].pos:t;return t>-1&&i>-1?z.single(t+e,i+e):null}const x0={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},$r=L.ie&&L.ie_version<=11;class v0{constructor(e){this.view=e,this.active=!1,this.selectionRange=new ug,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.resize=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(L.ie&&L.ie_version<=11||L.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),$r&&(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),typeof ResizeObserver=="function"&&(this.resize=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?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")))},{}),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(e){this.view.inputState.runScrollHandlers(this.view,e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(){this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500)}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(mr)?i.root.activeElement!=this.dom:!As(i.dom,n))return;let s=n.anchorNode&&i.docView.nearest(n.anchorNode);if(s&&s.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(L.ie&&L.ie_version<=11||L.android&&L.chrome)&&!i.state.selection.main.empty&&n.focusNode&&Us(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=L.safari&&e.root.nodeType==11&&lg(this.dom.ownerDocument)==this.dom&&w0(this.view)||Js(e.root);if(!t||this.selectionRange.eq(t))return!1;let i=As(this.dom,t);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),!this.flush()&&s.force&&Li(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}processRecords(){let e=this.queue;for(let s of this.observer.takeRecords())e.push(s);e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let s of e){let o=this.readMutation(s);!o||(o.typeOver&&(n=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&As(this.dom,this.selectionRange);return e<0&&!n?null:(e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1,new p0(this.view,e,t,i))}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return!1;let i=this.view.state,n=vf(this.view,t);return this.view.state==i&&this.view.update([]),n}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.dirty|=4),e.type=="childList"){let i=Fh(t,e.previousSibling||e.target.previousSibling,-1),n=Fh(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:n?t.posBefore(n):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resize)===null||i===void 0||i.disconnect();for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}}function Fh(r,e,t){for(;e;){let i=re.get(e);if(i&&i.parent==r)return i;let n=e.parentNode;e=n!=r.dom?n:t>0?e.nextSibling:e.previousSibling}return null}function w0(r){let e=null;function t(a){a.preventDefault(),a.stopImmediatePropagation(),e=a.getTargetRanges()[0]}if(r.contentDOM.addEventListener("beforeinput",t,!0),r.dom.ownerDocument.execCommand("indent"),r.contentDOM.removeEventListener("beforeinput",t,!0),!e)return null;let i=e.startContainer,n=e.startOffset,s=e.endContainer,o=e.endOffset,l=r.docView.domAtPos(r.state.selection.main.anchor);return Us(l.node,l.offset,s,o)&&([i,n,s,o]=[s,o,i,n]),{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:o}}class pe{constructor(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.style.cssText="position: absolute; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),this._dispatch=e.dispatch||(t=>this.update([t])),this.dispatch=this.dispatch.bind(this),this._root=e.root||cg(e.parent)||document,this.viewState=new Ch(e.state||Q.create(e)),this.plugins=this.state.facet(xn).map(t=>new Rr(t));for(let t of this.plugins)t.update(this);this.observer=new v0(this),this.inputState=new $g(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new hh(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}dispatch(...e){this._dispatch(e.length==1&&e[0]instanceof Ve?e[0]:this.state.update(...e))}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,n,s=this.state;for(let h of e){if(h.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=h.state}if(this.destroyed){this.viewState.state=s;return}let o=this.observer.delayedAndroidKey,l=null;if(o?(this.observer.clearDelayedAndroidKey(),l=this.observer.readChange(),(l&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(l=null)):this.observer.clear(),s.facet(Q.phrases)!=this.state.facet(Q.phrases))return this.setState(s);n=_s.create(this,s,e);let a=this.viewState.scrollTarget;try{this.updateState=2;for(let h of e){if(a&&(a=a.map(h.changes)),h.scrollIntoView){let{main:u}=h.state.selection;a=new Ks(u.empty?u:z.cursor(u.head,u.head>u.anchor?-1:1))}for(let u of h.effects)u.is(oh)&&(a=u.value)}this.viewState.update(n,a),this.bidiCache=js.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),t=this.docView.update(n),this.state.facet(vn)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(h=>h.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(as)!=n.state.facet(as)&&(this.viewState.mustMeasureContent=!0),(t||i||a||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!n.empty)for(let h of this.state.facet(qo))h(n);l&&!vf(this,l)&&o.force&&Li(this.contentDOM,o.key,o.keyCode)}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new Ch(e),this.plugins=e.facet(xn).map(i=>new Rr(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView=new hh(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(xn),i=e.state.facet(xn);if(t!=i){let n=[];for(let s of i){let o=t.indexOf(s);if(o<0)n.push(new Rr(s));else{let l=this.plugins[o];l.mustUpdate=e,n.push(l)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=n,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let n of this.plugins)n.mustUpdate=e;for(let n=0;n-1&&cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,{scrollHeight:i,scrollTop:n,clientHeight:s}=this.scrollDOM,o=n>i-s-4?i:n;try{for(let l=0;;l++){this.updateState=1;let a=this.viewport,h=this.viewState.lineBlockAtHeight(o),u=this.viewState.measure(this);if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let d=[];u&4||([this.measureRequests,d]=[d,this.measureRequests]);let p=d.map(f=>{try{return f.read(this)}catch(m){return ni(this.state,m),Bh}}),g=_s.create(this,this.state,[]),y=!1,c=!1;g.flags|=u,t?t.flags|=u:t=g,this.updateState=2,g.empty||(this.updatePlugins(g),this.inputState.update(g),this.updateAttrs(),y=this.docView.update(g));for(let f=0;f1||f<-1)&&(this.scrollDOM.scrollTop+=f,c=!0)}if(y&&this.docView.updateSelection(!0),this.viewport.from==a.from&&this.viewport.to==a.to&&!c&&this.measureRequests.length==0)break}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(qo))l(t)}get themeClasses(){return il+" "+(this.state.facet(tl)?yf:gf)+" "+this.state.facet(as)}updateAttrs(){let e=Th(this,Zc,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(mr)?"true":"false",class:"cm-content",style:`${L.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Th(this,Ll,t);let i=this.observer.ignore(()=>{let n=_o(this.contentDOM,this.contentAttrs,t),s=_o(this.dom,this.editorAttrs,e);return n||s});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let n of i.effects)if(n.is(pe.announce)){t&&(this.announceDOM.textContent=""),t=!1;let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(vn),Ki.mount(this.root,this.styleModules.concat(d0).reverse())}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(e.key!=null){for(let t=0;ti.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return Vr(this,e,mh(this,e,t,i))}moveByGroup(e,t){return Vr(this,e,mh(this,e,t,i=>Vg(this,e.head,i)))}moveToLineBoundary(e,t,i=!0){return zg(this,e,t,i)}moveVertically(e,t,i){return Vr(this,e,Hg(this,e,t,i))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),af(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(e),s=this.bidiSpans(n),o=s[Ri.find(s,e-n.from,-1,t)];return Ol(i,o.dir==Xe.LTR==t>0)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(Yc)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>S0)return nf(e.length);let t=this.textDirectionAt(e.from);for(let n of this.bidiCache)if(n.from==e.from&&n.dir==t)return n.order;let i=kg(e.text,t);return this.bidiCache.push(new js(e.from,e.to,t,i)),i}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||L.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Pc(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return oh.of(new Ks(typeof e=="number"?z.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return zn.define(()=>({}),{eventHandlers:e})}static theme(e,t){let i=Ki.newName(),n=[as.of(i),vn.of(nl(`.${i}`,e))];return t&&t.dark&&n.push(tl.of(!0)),n}static baseTheme(e){return Km.lowest(vn.of(nl("."+il,e,xf)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&re.get(i)||re.get(e);return((t=n?.rootView)===null||t===void 0?void 0:t.view)||null}}pe.styleModule=vn;pe.inputHandler=Gc;pe.perLineTextDirection=Yc;pe.exceptionSink=qc;pe.updateListener=qo;pe.editable=mr;pe.mouseSelectionStyle=jc;pe.dragMovesSelection=_c;pe.clickAddsSelectionRange=Kc;pe.decorations=Vn;pe.atomicRanges=Qc;pe.scrollMargins=ef;pe.darkTheme=tl;pe.contentAttributes=Ll;pe.editorAttributes=Zc;pe.lineWrapping=pe.contentAttributes.of({class:"cm-lineWrapping"});pe.announce=ke.define();const S0=4096,Bh={};class js{constructor(e,t,i,n){this.from=e,this.to=t,this.dir=i,this.order=n}static update(e,t){if(t.empty)return e;let i=[],n=e.length?e[e.length-1].dir:Xe.LTR;for(let s=Math.max(0,e.length-10);s=0;n--){let s=i[n],o=typeof s=="function"?s(r):s;o&&Ko(o,t)}return t}const D0=!L.ios,b0={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};D0&&(b0[".cm-line"].caretColor="transparent !important");class Yi extends Xi{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Yi.prototype.elementClass="";Yi.prototype.toDOM=void 0;Yi.prototype.mapMode=tt.TrackBefore;Yi.prototype.startSide=Yi.prototype.endSide=-1;Yi.prototype.point=!0;let k0=0;class xt{constructor(e,t,i){this.set=e,this.base=t,this.modified=i,this.id=k0++}static define(e){if(e?.base)throw new Error("Can not derive from a modified tag");let t=new xt([],null,[]);if(t.set.push(t),e)for(let i of e.set)t.set.push(i);return t}static defineModifier(){let e=new qs;return t=>t.modified.indexOf(e)>-1?t:qs.get(t.base||t,t.modified.concat(e).sort((i,n)=>i.id-n.id))}}let A0=0;class qs{constructor(){this.instances=[],this.id=A0++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&C0(t,l.modified));if(i)return i;let n=[],s=new xt(n,e,t);for(let l of t)l.instances.push(s);let o=E0(t);for(let l of e.set)if(!l.modified.length)for(let a of o)n.push(qs.get(l,a));return s}}function C0(r,e){return r.length==e.length&&r.every((t,i)=>t==e[i])}function E0(r){let e=[[]];for(let t=0;ti.length-t.length)}function F0(r){let e=Object.create(null);for(let t in r){let i=r[t];Array.isArray(i)||(i=[i]);for(let n of t.split(" "))if(n){let s=[],o=2,l=n;for(let d=0;;){if(l=="..."&&d>0&&d+3==n.length){o=1;break}let p=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!p)throw new RangeError("Invalid path: "+n);if(s.push(p[0]=="*"?"":p[0][0]=='"'?JSON.parse(p[0]):p[0]),d+=p[0].length,d==n.length)break;let g=n[d++];if(d==n.length&&g=="!"){o=0;break}if(g!="/")throw new RangeError("Invalid path: "+n);l=n.slice(d)}let a=s.length-1,h=s[a];if(!h)throw new RangeError("Invalid path: "+n);let u=new sl(i,o,a>0?s.slice(0,a):null);e[h]=u.sort(e[h])}}return B0.add(e)}const B0=new se;class sl{constructor(e,t,i,n){this.tags=e,this.mode=t,this.context=i,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth{let o=n;for(let l of s)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}const O=xt.define,hs=O(),Vt=O(),Mh=O(Vt),Oh=O(Vt),Ht=O(),us=O(Ht),Wr=O(Ht),gt=O(),hi=O(gt),ft=O(),dt=O(),rl=O(),un=O(rl),cs=O(),H={comment:hs,lineComment:O(hs),blockComment:O(hs),docComment:O(hs),name:Vt,variableName:O(Vt),typeName:Mh,tagName:O(Mh),propertyName:Oh,attributeName:O(Oh),className:O(Vt),labelName:O(Vt),namespace:O(Vt),macroName:O(Vt),literal:Ht,string:us,docString:O(us),character:O(us),attributeValue:O(us),number:Wr,integer:O(Wr),float:O(Wr),bool:O(Ht),regexp:O(Ht),escape:O(Ht),color:O(Ht),url:O(Ht),keyword:ft,self:O(ft),null:O(ft),atom:O(ft),unit:O(ft),modifier:O(ft),operatorKeyword:O(ft),controlKeyword:O(ft),definitionKeyword:O(ft),moduleKeyword:O(ft),operator:dt,derefOperator:O(dt),arithmeticOperator:O(dt),logicOperator:O(dt),bitwiseOperator:O(dt),compareOperator:O(dt),updateOperator:O(dt),definitionOperator:O(dt),typeOperator:O(dt),controlOperator:O(dt),punctuation:rl,separator:O(rl),bracket:un,angleBracket:O(un),squareBracket:O(un),paren:O(un),brace:O(un),content:gt,heading:hi,heading1:O(hi),heading2:O(hi),heading3:O(hi),heading4:O(hi),heading5:O(hi),heading6:O(hi),contentSeparator:O(gt),list:O(gt),quote:O(gt),emphasis:O(gt),strong:O(gt),link:O(gt),monospace:O(gt),strikethrough:O(gt),inserted:O(),deleted:O(),changed:O(),invalid:O(),meta:cs,documentMeta:O(cs),annotation:O(cs),processingInstruction:O(cs),definition:xt.defineModifier(),constant:xt.defineModifier(),function:xt.defineModifier(),standard:xt.defineModifier(),local:xt.defineModifier(),special:xt.defineModifier()};T0([{tag:H.link,class:"tok-link"},{tag:H.heading,class:"tok-heading"},{tag:H.emphasis,class:"tok-emphasis"},{tag:H.strong,class:"tok-strong"},{tag:H.keyword,class:"tok-keyword"},{tag:H.atom,class:"tok-atom"},{tag:H.bool,class:"tok-bool"},{tag:H.url,class:"tok-url"},{tag:H.labelName,class:"tok-labelName"},{tag:H.inserted,class:"tok-inserted"},{tag:H.deleted,class:"tok-deleted"},{tag:H.literal,class:"tok-literal"},{tag:H.string,class:"tok-string"},{tag:H.number,class:"tok-number"},{tag:[H.regexp,H.escape,H.special(H.string)],class:"tok-string2"},{tag:H.variableName,class:"tok-variableName"},{tag:H.local(H.variableName),class:"tok-variableName tok-local"},{tag:H.definition(H.variableName),class:"tok-variableName tok-definition"},{tag:H.special(H.variableName),class:"tok-variableName2"},{tag:H.definition(H.propertyName),class:"tok-propertyName tok-definition"},{tag:H.typeName,class:"tok-typeName"},{tag:H.namespace,class:"tok-namespace"},{tag:H.className,class:"tok-className"},{tag:H.macroName,class:"tok-macroName"},{tag:H.propertyName,class:"tok-propertyName"},{tag:H.operator,class:"tok-operator"},{tag:H.comment,class:"tok-comment"},{tag:H.meta,class:"tok-meta"},{tag:H.invalid,class:"tok-invalid"},{tag:H.punctuation,class:"tok-punctuation"}]);var Jr;const Gs=new se;function M0(r){return U.define({combine:r?e=>e.concat(r):void 0})}class Dt{constructor(e,t,i=[],n=""){this.data=e,this.name=n,Q.prototype.hasOwnProperty("tree")||Object.defineProperty(Q.prototype,"tree",{get(){return Ys(this)}}),this.parser=t,this.extension=[en.of(this),Q.languageData.of((s,o,l)=>s.facet(Ph(s,o,l)))].concat(i)}isActiveAt(e,t,i=-1){return Ph(e,t,i)==this.data}findRegions(e){let t=e.facet(en);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(s,o)=>{if(s.prop(Gs)==this.data){i.push({from:o,to:o+s.length});return}let l=s.prop(se.mounted);if(l){if(l.tree.prop(Gs)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+s.length});return}else if(l.overlay){let a=i.length;if(n(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let cn=null;class Zi{constructor(e,t,i=[],n,s,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=n,this.treeLen=s,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new Zi(e,t,[],ae.empty,0,i,[],null)}startParse(){return this.parser.startParse(new O0(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=ae.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let n=Date.now()+e;e=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(yi.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=cn;cn=this;try{return e()}finally{cn=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Nh(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:n,treeLen:s,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,u,d,p)=>a.push({fromA:h,toA:u,fromB:d,toB:p})),i=yi.applyChanges(i,a),n=ae.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let u=e.mapPos(h.from,1),d=e.mapPos(h.to,-1);ue.from&&(this.fragments=Nh(this.fragments,n,s),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends dc{createParse(t,i,n){let s=n[0].from,o=n[n.length-1].to;return{parsedPos:s,advance(){let a=cn;if(a){for(let h of n)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new ae(qe.none,[],[],o-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return cn}}function Nh(r,e,t){return yi.applyChanges(r,[{fromA:e,toA:t,fromB:e,toB:t}])}class Qi{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new Qi(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Zi.create(e.facet(en).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new Qi(i)}}Dt.state=ki.define({create:Qi.init,update(r,e){for(let t of e.effects)if(t.is(Dt.setState))return t.value;return e.startState.facet(en)!=e.state.facet(en)?Qi.init(e.state):r.apply(e)}});let wf=r=>{let e=setTimeout(()=>r(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(wf=r=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(r,{timeout:500-100})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Ur=typeof navigator<"u"&&((Jr=navigator.scheduling)===null||Jr===void 0?void 0:Jr.isInputPending)?()=>navigator.scheduling.isInputPending():null,P0=zn.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Dt.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),e.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Dt.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=wf(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEndn+1e3,a=s.context.work(()=>Ur&&Ur()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Dt.setState.of(new Qi(s.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>ni(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),en=U.define({combine(r){return r.length?r[0]:null},enables:r=>[Dt.state,P0,pe.contentAttributes.compute([r],e=>{let t=e.facet(r);return t&&t.name?{"data-language":t.name}:{}})]}),N0=U.define(),I0=U.define({combine:r=>{if(!r.length)return" ";if(!/^(?: +|\t+)$/.test(r[0]))throw new Error("Invalid indent unit: "+JSON.stringify(r[0]));return r[0]}});function ol(r){let e=r.facet(I0);return e.charCodeAt(0)==9?r.tabSize*e.length:e.length}function Ih(r,e,t,i=0,n=0){e==null&&(e=r.search(/[^\s\u00a0]/),e==-1&&(e=r.length));let s=n;for(let o=i;o=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.post}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPosi?o.toLowerCase():o,s=this.string.substr(this.pos,e.length);return n(s)==n(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let n=this.string.slice(this.pos).match(e);return n&&n.index>0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}}current(){return this.string.slice(this.start,this.pos)}}function L0(r){return{name:r.name||"",token:r.token,blankLine:r.blankLine||(()=>{}),startState:r.startState||(()=>!0),copyState:r.copyState||R0,indent:r.indent||(()=>null),languageData:r.languageData||{},tokenTable:r.tokenTable||Hl}}function R0(r){if(typeof r!="object")return r;let e={};for(let t in r){let i=r[t];e[t]=i instanceof Array?i.slice():i}return e}class zl extends Dt{constructor(e){let t=M0(e.languageData),i=L0(e),n,s=new class extends dc{createParse(o,l,a){return new V0(n,o,l,a)}};super(t,s,[N0.of((o,l)=>this.getIndent(o,l))],e.name),this.topNode=W0(t),n=this,this.streamParser=i,this.stateAfter=new se({perNode:!0}),this.tokenTable=e.tokenTable?new Af(i.tokenTable):$0}static define(e){return new zl(e)}getIndent(e,t){let i=Ys(e.state),n=i.resolve(t);for(;n&&n.type!=this.topNode;)n=n.parent;if(!n)return null;let s=Vl(this,i,0,n.from,t),o,l;if(s?(l=s.state,o=s.pos+1):(l=this.streamParser.startState(e.unit),o=0),t-o>1e4)return null;for(;o=i&&t+e.length<=n&&e.prop(r.stateAfter);if(s)return{state:r.streamParser.copyState(s),pos:t+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],a=t+e.positions[o],h=l instanceof ae&&a=e.length)return e;!n&&e.type==r.topNode&&(n=!0);for(let s=e.children.length-1;s>=0;s--){let o=e.positions[s],l=e.children[s],a;if(ot&&Vl(r,n.tree,0-n.offset,t,o),a;if(l&&(a=Df(r,n.tree,t+n.offset,l.pos+n.offset,!1)))return{state:l.state,tree:a}}return{state:r.streamParser.startState(i?ol(i):4),tree:ae.empty}}class V0{constructor(e,t,i,n){this.lang=e,this.input=t,this.fragments=i,this.ranges=n,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=n[n.length-1].to;let s=Zi.get(),o=n[0].from,{state:l,tree:a}=z0(e,i,o,s?.state);this.state=l,this.parsedPos=this.chunkStart=o+a.length;for(let h=0;h=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)t==` +`&&(t="");else{let i=t.indexOf(` +`);i>-1&&(t=t.slice(0,i))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),i=e+t.length;for(let n=this.rangeIndex;;){let s=this.ranges[n].to;if(s>=i||(t=t.slice(0,s-(i-t.length)),n++,n==this.ranges.length))break;let o=this.ranges[n].from,l=this.lineAfter(o);t+=l,i=o+l.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let n=this.ranges[this.rangeIndex].to,s=e+t;if(i>0?n>s:n>=s)break;let o=this.ranges[++this.rangeIndex].from;t+=o-n}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to1){s=this.skipGapsTo(t,s,1),t+=s;let o=this.chunk.length;s=this.skipGapsTo(i,s,-1),i+=s,n+=this.chunk.length-o}return this.chunk.push(e,t,i,n),s}parseLine(e){let{line:t,end:i}=this.nextLine(),n=0,{streamParser:s}=this.lang,o=new Sf(t,e?e.state.tabSize:4,e?ol(e.state):2);if(o.eol())s.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=bf(s.token,o,this.state);if(l&&(n=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,4,n)),o.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPose.start)return n}throw new Error("Stream parser failed to advance stream.")}const Hl=Object.create(null),Hn=[qe.none],H0=new Al(Hn),Lh=[],kf=Object.create(null);for(let[r,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"]])kf[r]=Cf(Hl,e);class Af{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),kf)}resolve(e){return e?this.table[e]||(this.table[e]=Cf(this.extra,e)):0}}const $0=new Af(Hl);function Xr(r,e){Lh.indexOf(r)>-1||(Lh.push(r),console.warn(e))}function Cf(r,e){let t=null;for(let s of e.split(".")){let o=r[s]||H[s];o?typeof o=="function"?t?t=o(t):Xr(s,`Modifier ${s} used at start of tag`):t?Xr(s,`Tag ${s} used as modifier`):t=o:Xr(s,`Unknown highlighting tag ${s}`)}if(!t)return 0;let i=e.replace(/ /g,"_"),n=qe.define({id:Hn.length,name:i,props:[F0({[i]:t})]});return Hn.push(n),n.id}function W0(r){let e=qe.define({id:Hn.length,name:"Document",props:[Gs.add(()=>r)]});return Hn.push(e),e}const J0=1024;let U0=0;class Kr{constructor(e,t){this.from=e,this.to=t}}class _{constructor(e={}){this.id=U0++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=rt.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}_.closedBy=new _({deserialize:r=>r.split(" ")});_.openedBy=new _({deserialize:r=>r.split(" ")});_.group=new _({deserialize:r=>r.split(" ")});_.contextHash=new _({perNode:!0});_.lookAhead=new _({perNode:!0});_.mounted=new _({perNode:!0});const X0=Object.create(null);class rt{constructor(e,t,i,n=0){this.name=e,this.props=t,this.id=i,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):X0,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new rt(e.name||"",t,e.id,i);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(n)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return n}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(_.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let n of i.split(" "))t[n]=e[i];return i=>{for(let n=i.prop(_.group),s=-1;s<(n?n.length:0);s++){let o=t[s<0?i.name:n[s]];if(o)return o}}}}rt.none=new rt("",Object.create(null),0,8);const fs=new WeakMap,Rh=new WeakMap;var Le;(function(r){r[r.ExcludeBuffers=1]="ExcludeBuffers",r[r.IncludeAnonymous=2]="IncludeAnonymous",r[r.IgnoreMounts=4]="IgnoreMounts",r[r.IgnoreOverlays=8]="IgnoreOverlays"})(Le||(Le={}));class $e{constructor(e,t,i,n,s){if(this.type=e,this.children=t,this.positions=i,this.length=n,this.props=null,s&&s.length){this.props=Object.create(null);for(let[o,l]of s)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=this.prop(_.mounted);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let n=i.toString();n&&(t&&(t+=","),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new er(this.topNode,e)}cursorAt(e,t=0,i=0){let n=fs.get(this)||this.topNode,s=new er(n);return s.moveTo(e,t),fs.set(this,s._tree),s}get topNode(){return new Rt(this,0,0,null)}resolve(e,t=0){let i=tn(fs.get(this)||this.topNode,e,t,!1);return fs.set(this,i),i}resolveInner(e,t=0){let i=tn(Rh.get(this)||this.topNode,e,t,!0);return Rh.set(this,i),i}iterate(e){let{enter:t,leave:i,from:n=0,to:s=this.length}=e;for(let o=this.cursor((e.mode||0)|Le.IncludeAnonymous);;){let l=!1;if(o.from<=s&&o.to>=n&&(o.type.isAnonymous||t(o)!==!1)){if(o.firstChild())continue;l=!0}for(;l&&i&&!o.type.isAnonymous&&i(o),!o.nextSibling();){if(!o.parent())return;l=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Jl(rt.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,n)=>new $e(this.type,t,i,n,this.propValues),e.makeTree||((t,i,n)=>new $e(rt.none,t,i,n)))}static build(e){return _0(e)}}$e.empty=new $e(rt.none,[],[],0);class $l{constructor(e,t){this.buffer=e,this.index=t}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 $l(this.buffer,this.index)}}class Ai{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return rt.none}toString(){let e=[];for(let t=0;t0));a=o[a+3]);return l}slice(e,t,i){let n=this.buffer,s=new Uint16Array(t-e),o=0;for(let l=e,a=0;l=e&&te;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function Ff(r,e){let t=r.childBefore(e);for(;t;){let i=t.lastChild;if(!i||i.to!=t.to)break;i.type.isError&&i.from==i.to?(r=t,t=i.prevSibling):t=i}return r}function tn(r,e,t,i){for(var n;r.from==r.to||(t<1?r.from>=e:r.from>e)||(t>-1?r.to<=e:r.to0?l.length:-1;e!=h;e+=t){let u=l[e],d=a[e]+o.from;if(!!Ef(n,i,d,d+u.length)){if(u instanceof Ai){if(s&Le.ExcludeBuffers)continue;let p=u.findChild(0,u.buffer.length,t,i-d,n);if(p>-1)return new ti(new K0(o,u,e,d),null,p)}else if(s&Le.IncludeAnonymous||!u.type.isAnonymous||Wl(u)){let p;if(!(s&Le.IgnoreMounts)&&u.props&&(p=u.prop(_.mounted))&&!p.overlay)return new Rt(p.tree,d,e,o);let g=new Rt(u,d,e,o);return s&Le.IncludeAnonymous||!g.type.isAnonymous?g:g.nextChild(t<0?u.children.length-1:0,t,i,n)}}}if(s&Le.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))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(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(e,t,i=0){let n;if(!(i&Le.IgnoreOverlays)&&(n=this._tree.prop(_.mounted))&&n.overlay){let s=e-this.from;for(let{from:o,to:l}of n.overlay)if((t>0?o<=s:o=s:l>s))return new Rt(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}cursor(e=0){return new er(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return tn(this,e,t,!1)}resolveInner(e,t=0){return tn(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Ff(this,e)}getChild(e,t=null,i=null){let n=Zs(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return Zs(this,e,t,i)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return Qs(this,e)}}function Zs(r,e,t,i){let n=r.cursor(),s=[];if(!n.firstChild())return s;if(t!=null){for(;!n.type.is(t);)if(!n.nextSibling())return s}for(;;){if(i!=null&&n.type.is(i))return s;if(n.type.is(e)&&s.push(n.node),!n.nextSibling())return i==null?s:[]}}function Qs(r,e,t=e.length-1){for(let i=r.parent;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class K0{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class ti{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(e,t,i){this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.context.start,i);return s<0?null:new ti(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,i=0){if(i&Le.ExcludeBuffers)return null;let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new ti(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new ti(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new ti(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new er(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,n=this.index+4,s=i.buffer[this.index+3];if(s>n){let o=i.buffer[this.index+1];e.push(i.slice(n,s,o)),t.push(0)}return new $e(this.type,e,t,this.to-this.from)}resolve(e,t=0){return tn(this,e,t,!1)}resolveInner(e,t=0){return tn(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Ff(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,i=null){let n=Zs(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return Zs(this,e,t,i)}get node(){return this}matchContext(e){return Qs(this,e)}}class er{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof Rt)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:n}=this.buffer;return this.type=t||n.set.types[n.buffer[e]],this.from=i+n.buffer[e+1],this.to=i+n.buffer[e+2],!0}yield(e){return e?e instanceof Rt?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:n}=this.buffer,s=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.buffer.start,i);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&Le.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Le.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&Le.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let n=i<0?0:this.stack[i]+4;if(this.index!=n)return this.yieldBuf(t.findChild(n,this.index,-1,0,4))}else{let n=t.buffer[this.index+3];if(n<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(n)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:n}=this;if(n){if(e>0){if(this.index-1)for(let s=t+e,o=e<0?-1:i._tree.children.length;s!=o;s+=e){let l=i._tree.children[s];if(this.mode&Le.IncludeAnonymous||l instanceof Ai||!l.type.isAnonymous||Wl(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to=0;){for(let o=e;o;o=o._parent)if(o.index==n){if(n==this.index)return o;t=o,i=s+1;break e}n=this.stack[--s]}}for(let n=i;n=0;s--){if(s<0)return Qs(this.node,e,n);let o=i[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[n]&&e[n]!=o.name)return!1;n--}}return!0}}function Wl(r){return r.children.some(e=>e instanceof Ai||!e.type.isAnonymous||Wl(e))}function _0(r){var e;let{buffer:t,nodeSet:i,maxBufferLength:n=J0,reused:s=[],minRepeatType:o=i.types.length}=r,l=Array.isArray(t)?new $l(t,t.length):t,a=i.types,h=0,u=0;function d(S,D,w,b,E){let{id:C,start:F,end:B,size:I}=l,R=u;for(;I<0;)if(l.next(),I==-1){let he=s[C];w.push(he),b.push(F-S);return}else if(I==-3){h=C;return}else if(I==-4){u=C;return}else throw new RangeError(`Unrecognized record size: ${I}`);let X=a[C],j,Z,ht=F-S;if(B-F<=n&&(Z=c(l.pos-D,E))){let he=new Uint16Array(Z.size-Z.skip),J=l.pos-Z.size,ee=he.length;for(;l.pos>J;)ee=f(Z.start,he,ee);j=new Ai(he,B-Z.start,i),ht=Z.start-S}else{let he=l.pos-I;l.next();let J=[],ee=[],ue=C>=o?C:-1,xe=0,Oe=B;for(;l.pos>he;)ue>=0&&l.id==ue&&l.size>=0?(l.end<=Oe-n&&(g(J,ee,F,xe,l.end,Oe,ue,R),xe=J.length,Oe=l.end),l.next()):d(F,he,J,ee,ue);if(ue>=0&&xe>0&&xe-1&&xe>0){let lt=p(X);j=Jl(X,J,ee,0,J.length,0,B-F,lt,lt)}else j=y(X,J,ee,B-F,R-B)}w.push(j),b.push(ht)}function p(S){return(D,w,b)=>{let E=0,C=D.length-1,F,B;if(C>=0&&(F=D[C])instanceof $e){if(!C&&F.type==S&&F.length==b)return F;(B=F.prop(_.lookAhead))&&(E=w[C]+F.length+B)}return y(S,D,w,b,E)}}function g(S,D,w,b,E,C,F,B){let I=[],R=[];for(;S.length>b;)I.push(S.pop()),R.push(D.pop()+w-E);S.push(y(i.types[F],I,R,C-E,B-C)),D.push(E-w)}function y(S,D,w,b,E=0,C){if(h){let F=[_.contextHash,h];C=C?[F].concat(C):[F]}if(E>25){let F=[_.lookAhead,E];C=C?[F].concat(C):[F]}return new $e(S,D,w,b,C)}function c(S,D){let w=l.fork(),b=0,E=0,C=0,F=w.end-n,B={size:0,start:0,skip:0};e:for(let I=w.pos-S;w.pos>I;){let R=w.size;if(w.id==D&&R>=0){B.size=b,B.start=E,B.skip=C,C+=4,b+=4,w.next();continue}let X=w.pos-R;if(R<0||X=o?4:0,Z=w.start;for(w.next();w.pos>X;){if(w.size<0)if(w.size==-3)j+=4;else break e;else w.id>=o&&(j+=4);w.next()}E=Z,b+=R,C+=j}return(D<0||b==S)&&(B.size=b,B.start=E,B.skip=C),B.size>4?B:void 0}function f(S,D,w){let{id:b,start:E,end:C,size:F}=l;if(l.next(),F>=0&&b4){let I=l.pos-(F-4);for(;l.pos>I;)w=f(S,D,w)}D[--w]=B,D[--w]=C-S,D[--w]=E-S,D[--w]=b}else F==-3?h=b:F==-4&&(u=b);return w}let m=[],x=[];for(;l.pos>0;)d(r.start||0,r.bufferStart||0,m,x,-1);let v=(e=r.length)!==null&&e!==void 0?e:m.length?x[0]+m[0].length:0;return new $e(a[r.topID],m.reverse(),x.reverse(),v)}const zh=new WeakMap;function Es(r,e){if(!r.isAnonymous||e instanceof Ai||e.type!=r)return 1;let t=zh.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=r||!(i instanceof $e)){t=1;break}t+=Es(r,i)}zh.set(e,t)}return t}function Jl(r,e,t,i,n,s,o,l,a){let h=0;for(let y=i;y=u)break;w+=b}if(v==S+1){if(w>u){let b=y[S];g(b.children,b.positions,0,b.children.length,c[S]+x);continue}d.push(y[S])}else{let b=c[v-1]+y[v-1].length-D;d.push(Jl(r,y,c,S,v,D,b,null,a))}p.push(D+x-s)}}return g(e,t,i,n,0),(l||a)(d,p,o)}class vi{constructor(e,t,i,n,s=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=n,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let n=[new vi(0,e.length,e,0,!1,i)];for(let s of t)s.to>e.length&&n.push(s);return n}static applyChanges(e,t,i=128){if(!t.length)return e;let n=[],s=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let u=l=i)for(;o&&o.from=p.from||d<=p.to||h){let g=Math.max(p.from,a)-h,y=Math.min(p.to,d)-h;p=g>=y?null:new vi(g,y,p.tree,p.offset+h,l>0,!!u)}if(p&&n.push(p),o.to>d)break;o=snew Kr(n.from,n.to)):[new Kr(0,0)]:[new Kr(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let n=this.startParse(e,t,i);for(;;){let s=n.advance();if(s)return s}}}class q0{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new _({perNode:!0});let G0=0;class vt{constructor(e,t,i){this.set=e,this.base=t,this.modified=i,this.id=G0++}static define(e){if(e?.base)throw new Error("Can not derive from a modified tag");let t=new vt([],null,[]);if(t.set.push(t),e)for(let i of e.set)t.set.push(i);return t}static defineModifier(){let e=new tr;return t=>t.modified.indexOf(e)>-1?t:tr.get(t.base||t,t.modified.concat(e).sort((i,n)=>i.id-n.id))}}let Y0=0;class tr{constructor(){this.instances=[],this.id=Y0++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Z0(t,l.modified));if(i)return i;let n=[],s=new vt(n,e,t);for(let l of t)l.instances.push(s);let o=Q0(t);for(let l of e.set)if(!l.modified.length)for(let a of o)n.push(tr.get(l,a));return s}}function Z0(r,e){return r.length==e.length&&r.every((t,i)=>t==e[i])}function Q0(r){let e=[[]];for(let t=0;ti.length-t.length)}function ey(r){let e=Object.create(null);for(let t in r){let i=r[t];Array.isArray(i)||(i=[i]);for(let n of t.split(" "))if(n){let s=[],o=2,l=n;for(let d=0;;){if(l=="..."&&d>0&&d+3==n.length){o=1;break}let p=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!p)throw new RangeError("Invalid path: "+n);if(s.push(p[0]=="*"?"":p[0][0]=='"'?JSON.parse(p[0]):p[0]),d+=p[0].length,d==n.length)break;let g=n[d++];if(d==n.length&&g=="!"){o=0;break}if(g!="/")throw new RangeError("Invalid path: "+n);l=n.slice(d)}let a=s.length-1,h=s[a];if(!h)throw new RangeError("Invalid path: "+n);let u=new ll(i,o,a>0?s.slice(0,a):null);e[h]=u.sort(e[h])}}return ty.add(e)}const ty=new _;class ll{constructor(e,t,i,n){this.tags=e,this.mode=t,this.context=i,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth{let o=n;for(let l of s)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}const P=vt.define,ds=P(),$t=P(),Vh=P($t),Hh=P($t),Wt=P(),ps=P(Wt),_r=P(Wt),yt=P(),ui=P(yt),pt=P(),mt=P(),al=P(),fn=P(al),ms=P(),$={comment:ds,lineComment:P(ds),blockComment:P(ds),docComment:P(ds),name:$t,variableName:P($t),typeName:Vh,tagName:P(Vh),propertyName:Hh,attributeName:P(Hh),className:P($t),labelName:P($t),namespace:P($t),macroName:P($t),literal:Wt,string:ps,docString:P(ps),character:P(ps),attributeValue:P(ps),number:_r,integer:P(_r),float:P(_r),bool:P(Wt),regexp:P(Wt),escape:P(Wt),color:P(Wt),url:P(Wt),keyword:pt,self:P(pt),null:P(pt),atom:P(pt),unit:P(pt),modifier:P(pt),operatorKeyword:P(pt),controlKeyword:P(pt),definitionKeyword:P(pt),moduleKeyword:P(pt),operator:mt,derefOperator:P(mt),arithmeticOperator:P(mt),logicOperator:P(mt),bitwiseOperator:P(mt),compareOperator:P(mt),updateOperator:P(mt),definitionOperator:P(mt),typeOperator:P(mt),controlOperator:P(mt),punctuation:al,separator:P(al),bracket:fn,angleBracket:P(fn),squareBracket:P(fn),paren:P(fn),brace:P(fn),content:yt,heading:ui,heading1:P(ui),heading2:P(ui),heading3:P(ui),heading4:P(ui),heading5:P(ui),heading6:P(ui),contentSeparator:P(yt),list:P(yt),quote:P(yt),emphasis:P(yt),strong:P(yt),link:P(yt),monospace:P(yt),strikethrough:P(yt),inserted:P(),deleted:P(),changed:P(),invalid:P(),meta:ms,documentMeta:P(ms),annotation:P(ms),processingInstruction:P(ms),definition:vt.defineModifier(),constant:vt.defineModifier(),function:vt.defineModifier(),standard:vt.defineModifier(),local:vt.defineModifier(),special:vt.defineModifier()};iy([{tag:$.link,class:"tok-link"},{tag:$.heading,class:"tok-heading"},{tag:$.emphasis,class:"tok-emphasis"},{tag:$.strong,class:"tok-strong"},{tag:$.keyword,class:"tok-keyword"},{tag:$.atom,class:"tok-atom"},{tag:$.bool,class:"tok-bool"},{tag:$.url,class:"tok-url"},{tag:$.labelName,class:"tok-labelName"},{tag:$.inserted,class:"tok-inserted"},{tag:$.deleted,class:"tok-deleted"},{tag:$.literal,class:"tok-literal"},{tag:$.string,class:"tok-string"},{tag:$.number,class:"tok-number"},{tag:[$.regexp,$.escape,$.special($.string)],class:"tok-string2"},{tag:$.variableName,class:"tok-variableName"},{tag:$.local($.variableName),class:"tok-variableName tok-local"},{tag:$.definition($.variableName),class:"tok-variableName tok-definition"},{tag:$.special($.variableName),class:"tok-variableName2"},{tag:$.definition($.propertyName),class:"tok-propertyName tok-definition"},{tag:$.typeName,class:"tok-typeName"},{tag:$.namespace,class:"tok-namespace"},{tag:$.className,class:"tok-className"},{tag:$.macroName,class:"tok-macroName"},{tag:$.propertyName,class:"tok-propertyName"},{tag:$.operator,class:"tok-operator"},{tag:$.comment,class:"tok-comment"},{tag:$.meta,class:"tok-meta"},{tag:$.invalid,class:"tok-invalid"},{tag:$.punctuation,class:"tok-punctuation"}]);var jr;const hl=new _;class Nt{constructor(e,t,i=[],n=""){this.data=e,this.name=n,G.prototype.hasOwnProperty("tree")||Object.defineProperty(G.prototype,"tree",{get(){return li(this)}}),this.parser=t,this.extension=[sn.of(this),G.languageData.of((s,o,l)=>s.facet($h(s,o,l)))].concat(i)}isActiveAt(e,t,i=-1){return $h(e,t,i)==this.data}findRegions(e){let t=e.facet(sn);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(s,o)=>{if(s.prop(hl)==this.data){i.push({from:o,to:o+s.length});return}let l=s.prop(_.mounted);if(l){if(l.tree.prop(hl)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+s.length});return}else if(l.overlay){let a=i.length;if(n(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let dn=null;class ir{constructor(e,t,i=[],n,s,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=n,this.treeLen=s,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new ir(e,t,[],$e.empty,0,i,[],null)}startParse(){return this.parser.startParse(new ny(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=$e.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let n=Date.now()+e;e=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(vi.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=dn;dn=this;try{return e()}finally{dn=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Wh(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:n,treeLen:s,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,u,d,p)=>a.push({fromA:h,toA:u,fromB:d,toB:p})),i=vi.applyChanges(i,a),n=$e.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let u=e.mapPos(h.from,1),d=e.mapPos(h.to,-1);ue.from&&(this.fragments=Wh(this.fragments,n,s),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends j0{createParse(t,i,n){let s=n[0].from,o=n[n.length-1].to;return{parsedPos:s,advance(){let a=dn;if(a){for(let h of n)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new $e(rt.none,[],[],o-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return dn}}function Wh(r,e,t){return vi.applyChanges(r,[{fromA:e,toA:t,fromB:e,toB:t}])}class nn{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new nn(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=ir.create(e.facet(sn).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new nn(i)}}Nt.state=zt.define({create:nn.init,update(r,e){for(let t of e.effects)if(t.is(Nt.setState))return t.value;return e.startState.facet(sn)!=e.state.facet(sn)?nn.init(e.state):r.apply(e)}});let Bf=r=>{let e=setTimeout(()=>r(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Bf=r=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(r,{timeout:500-100})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const qr=typeof navigator<"u"&&((jr=navigator.scheduling)===null||jr===void 0?void 0:jr.isInputPending)?()=>navigator.scheduling.isInputPending():null,sy=Mn.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Nt.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),e.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Nt.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Bf(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEndn+1e3,a=s.context.work(()=>qr&&qr()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Nt.setState.of(new nn(s.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>ii(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),sn=W.define({combine(r){return r.length?r[0]:null},enables:r=>[Nt.state,sy,q.contentAttributes.compute([r],e=>{let t=e.facet(r);return t&&t.name?{"data-language":t.name}:{}})]}),ry=W.define(),Ul=W.define({combine:r=>{if(!r.length)return" ";if(!/^(?: +|\t+)$/.test(r[0]))throw new Error("Invalid indent unit: "+JSON.stringify(r[0]));return r[0]}});function nr(r){let e=r.facet(Ul);return e.charCodeAt(0)==9?r.tabSize*e.length:e.length}function sr(r,e){let t="",i=r.tabSize;if(r.facet(Ul).charCodeAt(0)==9)for(;e>=i;)t+=" ",e-=i;for(let n=0;n=i.from&&n<=i.to?s&&n==e?{text:"",from:e}:(t<0?n-1&&(s+=o-this.countColumn(i,i.search(/\S|$/))),s}countColumn(e,t=e.length){return xl(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:n}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let o=s(n);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const oy=new _;function ly(r,e,t){return Mf(e.resolveInner(t).enterUnfinishedNodesBefore(t),t,r)}function ay(r){return r.pos==r.options.simulateBreak&&r.options.simulateDoubleBreak}function hy(r){let e=r.type.prop(oy);if(e)return e;let t=r.firstChild,i;if(t&&(i=t.type.prop(_.closedBy))){let n=r.lastChild,s=n&&i.indexOf(n.name)>-1;return o=>dy(o,!0,1,void 0,s&&!ay(o)?n.from:void 0)}return r.parent==null?uy:null}function Mf(r,e,t){for(;r;r=r.parent){let i=hy(r);if(i)return i(Xl.create(t,e,r))}return null}function uy(){return 0}class Xl extends gr{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.node=i}static create(e,t,i){return new Xl(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){let e=this.state.doc.lineAt(this.node.from);for(;;){let t=this.node.resolve(e.from);for(;t.parent&&t.parent.from==t.from;)t=t.parent;if(cy(t,this.node))break;e=this.state.doc.lineAt(t.from)}return this.lineIndent(e.from)}continue(){let e=this.node.parent;return e?Mf(e,this.pos,this.base):0}}function cy(r,e){for(let t=e;t;t=t.parent)if(r==t)return!0;return!1}function fy(r){let e=r.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let n=r.options.simulateBreak,s=r.state.doc.lineAt(t.from),o=n==null||n<=s.from?s.to:Math.min(s.to,n);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped)return a.from-1&&n%2==(e<0?1:0))return[t[n+e]]}return null}function Bi(r,e,t,i={}){let n=i.maxScanDistance||py,s=i.brackets||my,o=li(r),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=ul(a.type,t,s);if(h&&a.from=i.to){if(a==0&&n.indexOf(h.type.name)>-1&&h.from0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},u=r.doc.iterRange(e,t>0?r.doc.length:0),d=0;for(let p=0;!u.next().done&&p<=s;){let g=u.value;t<0&&(p+=g.length);let y=e+p*t;for(let c=t>0?0:g.length-1,f=t>0?g.length:-1;c!=f;c+=t){let m=o.indexOf(g[c]);if(!(m<0||i.resolveInner(y+c,1).type!=n))if(m%2==0==t>0)d++;else{if(d==1)return{start:h,end:{from:y+c,to:y+c+1},matched:m>>1==a>>1};d--}}t>0&&(p+=g.length)}return u.done?{start:h,matched:!1}:null}const xy=Object.create(null),Jh=[rt.none],Uh=[],vy=Object.create(null);for(let[r,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"]])vy[r]=wy(xy,e);function Gr(r,e){Uh.indexOf(r)>-1||(Uh.push(r),console.warn(e))}function wy(r,e){let t=null;for(let s of e.split(".")){let o=r[s]||$[s];o?typeof o=="function"?t?t=o(t):Gr(s,`Modifier ${s} used at start of tag`):t?Gr(s,`Tag ${s} used as modifier`):t=o:Gr(s,`Unknown highlighting tag ${s}`)}if(!t)return 0;let i=e.replace(/ /g,"_"),n=rt.define({id:Jh.length,name:i,props:[ey({[i]:t})]});return Jh.push(n),n.id}const Sy=r=>{let e=_l(r.state);return e.line?Dy(r):e.block?ky(r):!1};function Kl(r,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let n=r(e,t);return n?(i(t.update(n)),!0):!1}}const Dy=Kl(Ey,0),by=Kl(Of,0),ky=Kl((r,e)=>Of(r,e,Cy(e)),0);function _l(r,e=r.selection.main.head){let t=r.languageDataAt("commentTokens",e);return t.length?t[0]:{}}const pn=50;function Ay(r,{open:e,close:t},i,n){let s=r.sliceDoc(i-pn,i),o=r.sliceDoc(n,n+pn),l=/\s*$/.exec(s)[0].length,a=/^\s*/.exec(o)[0].length,h=s.length-l;if(s.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:n+a,margin:a&&1}};let u,d;n-i<=2*pn?u=d=r.sliceDoc(i,n):(u=r.sliceDoc(i,i+pn),d=r.sliceDoc(n-pn,n));let p=/^\s*/.exec(u)[0].length,g=/\s*$/.exec(d)[0].length,y=d.length-g-t.length;return u.slice(p,p+e.length)==e&&d.slice(y,y+t.length)==t?{open:{pos:i+p+e.length,margin:/\s/.test(u.charAt(p+e.length))?1:0},close:{pos:n-g-t.length,margin:/\s/.test(d.charAt(y-1))?1:0}}:null}function Cy(r){let e=[];for(let t of r.selection.ranges){let i=r.doc.lineAt(t.from),n=t.to<=i.to?i:r.doc.lineAt(t.to),s=e.length-1;s>=0&&e[s].to>i.from?e[s].to=n.to:e.push({from:i.from,to:n.to})}return e}function Of(r,e,t=e.selection.ranges){let i=t.map(s=>_l(e,s.from).block);if(!i.every(s=>s))return null;let n=t.map((s,o)=>Ay(e,i[o],s.from,s.to));if(r!=2&&!n.every(s=>s))return{changes:e.changes(t.map((s,o)=>n[o]?[]:[{from:s.from,insert:i[o].open+" "},{from:s.to,insert:" "+i[o].close}]))};if(r!=1&&n.some(s=>s)){let s=[];for(let o=0,l;on&&(s==o||o>u.from)){n=u.from;let d=_l(e,h).line;if(!d)continue;let p=/^\s*/.exec(u.text)[0].length,g=p==u.length,y=u.text.slice(p,p+d.length)==d?p:-1;ps.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:l,token:a,indent:h,empty:u,single:d}of i)(d||!u)&&s.push({from:l.from+h,insert:a+" "});let o=e.changes(s);return{changes:o,selection:e.selection.map(o,1)}}else if(r!=1&&i.some(s=>s.comment>=0)){let s=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let h=o.from+l,u=h+a.length;o.text[u-o.from]==" "&&u++,s.push({from:h,to:u})}return{changes:s}}return null}const cl=Di.define(),Fy=Di.define(),By=W.define(),Ty=W.define({combine(r){return sp(r,{minDepth:100,newGroupDelay:500},{minDepth:Math.max,newGroupDelay:Math.min})}});function My(r){let e=0;return r.iterChangedRanges((t,i)=>e=i),e}const Oy=zt.define({create(){return bt.empty},update(r,e){let t=e.state.facet(Ty),i=e.annotation(cl);if(i){let a=e.docChanged?M.single(My(e.changes)):void 0,h=je.fromTransaction(e,a),u=i.side,d=u==0?r.undone:r.done;return h?d=rr(d,d.length,t.minDepth,h):d=Nf(d,e.startState.selection),new bt(u==0?i.rest:d,u==0?d:i.rest)}let n=e.annotation(Fy);if((n=="full"||n=="before")&&(r=r.isolate()),e.annotation(we.addToHistory)===!1)return e.changes.empty?r:r.addMapping(e.changes.desc);let s=je.fromTransaction(e),o=e.annotation(we.time),l=e.annotation(we.userEvent);return s?r=r.addChanges(s,o,l,t.newGroupDelay,t.minDepth):e.selection&&(r=r.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(n=="full"||n=="after")&&(r=r.isolate()),r},toJSON(r){return{done:r.done.map(e=>e.toJSON()),undone:r.undone.map(e=>e.toJSON())}},fromJSON(r){return new bt(r.done.map(je.fromJSON),r.undone.map(je.fromJSON))}});function yr(r,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let n=t.field(Oy,!1);if(!n)return!1;let s=n.pop(r,t,e);return s?(i(s),!0):!1}}const Py=yr(0,!1),Xh=yr(1,!1),Ny=yr(0,!0),Iy=yr(1,!0);class je{constructor(e,t,i,n,s){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=n,this.selectionsAfter=s}setSelAfter(e){return new je(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(n=>n.toJSON())}}static fromJSON(e){return new je(e.changes&&ve.fromJSON(e.changes),[],e.mapped&&kt.fromJSON(e.mapped),e.startSelection&&M.fromJSON(e.startSelection),e.selectionsAfter.map(M.fromJSON))}static fromTransaction(e,t){let i=st;for(let n of e.startState.facet(By)){let s=n(e);s.length&&(i=i.concat(s))}return!i.length&&e.changes.empty?null:new je(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,st)}static selection(e){return new je(void 0,st,void 0,void 0,e)}}function rr(r,e,t,i){let n=e+1>t+20?e-t-1:0,s=r.slice(n,e);return s.push(i),s}function Ly(r,e){let t=[],i=!1;return r.iterChangedRanges((n,s)=>t.push(n,s)),e.iterChangedRanges((n,s,o,l)=>{for(let a=0;a=h&&o<=u&&(i=!0)}}),i}function Ry(r,e){return r.ranges.length==e.ranges.length&&r.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function Pf(r,e){return r.length?e.length?r.concat(e):r:e}const st=[],zy=200;function Nf(r,e){if(r.length){let t=r[r.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-zy));return i.length&&i[i.length-1].eq(e)?r:(i.push(e),rr(r,r.length-1,1e9,t.setSelAfter(i)))}else return[je.selection([e])]}function Vy(r){let e=r[r.length-1],t=r.slice();return t[r.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Yr(r,e){if(!r.length)return r;let t=r.length,i=st;for(;t;){let n=Hy(r[t-1],e,i);if(n.changes&&!n.changes.empty||n.effects.length){let s=r.slice(0,t);return s[t-1]=n,s}else e=n.mapped,t--,i=n.selectionsAfter}return i.length?[je.selection(i)]:st}function Hy(r,e,t){let i=Pf(r.selectionsAfter.length?r.selectionsAfter.map(l=>l.map(e)):st,t);if(!r.changes)return je.selection(i);let n=r.changes.map(e),s=e.mapDesc(r.changes,!0),o=r.mapped?r.mapped.composeDesc(s):s;return new je(n,de.mapEffects(r.effects,e),o,r.startSelection.map(s),i)}const $y=/^(input\.type|delete)($|\.)/;class bt{constructor(e,t,i=0,n=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new bt(this.done,this.undone):this}addChanges(e,t,i,n,s){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||$y.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime0&&t-this.prevTimet.empty?r.moveByChar(t,e):xr(t,e))}function We(r){return r.textDirectionAt(r.state.selection.main.head)==ze.LTR}const Lf=r=>If(r,!We(r)),Rf=r=>If(r,We(r));function zf(r,e){return at(r,t=>t.empty?r.moveByGroup(t,e):xr(t,e))}const Wy=r=>zf(r,!We(r)),Jy=r=>zf(r,We(r));function Uy(r,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(r.sliceDoc(e.from,e.to)))||e.firstChild}function vr(r,e,t){let i=li(r).resolveInner(e.head),n=t?_.closedBy:_.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;Uy(r,h,n)?i=h:a=t?h.to:h.from}let s=i.type.prop(n),o,l;return s&&(o=t?Bi(r,i.from,1):Bi(r,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,M.cursor(l,t?-1:1)}const Xy=r=>at(r,e=>vr(r.state,e,!We(r))),Ky=r=>at(r,e=>vr(r.state,e,We(r)));function Vf(r,e){return at(r,t=>{if(!t.empty)return xr(t,e);let i=r.moveVertically(t,e);return i.head!=t.head?i:r.moveToLineBoundary(t,e)})}const Hf=r=>Vf(r,!1),$f=r=>Vf(r,!0);function Wf(r){return Math.max(r.defaultLineHeight,Math.min(r.dom.clientHeight,innerHeight)-5)}function Jf(r,e){let{state:t}=r,i=rn(t.selection,l=>l.empty?r.moveVertically(l,e,Wf(r)):xr(l,e));if(i.eq(t.selection))return!1;let n=r.coordsAtPos(t.selection.main.head),s=r.scrollDOM.getBoundingClientRect(),o;return n&&n.top>s.top&&n.bottomJf(r,!1),fl=r=>Jf(r,!0);function ai(r,e,t){let i=r.lineBlockAt(e.head),n=r.moveToLineBoundary(e,t);if(n.head==e.head&&n.head!=(t?i.to:i.from)&&(n=r.moveToLineBoundary(e,t,!1)),!t&&n.head==i.from&&i.length){let s=/^\s*/.exec(r.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;s&&e.head!=i.from+s&&(n=M.cursor(i.from+s))}return n}const _y=r=>at(r,e=>ai(r,e,!0)),jy=r=>at(r,e=>ai(r,e,!1)),qy=r=>at(r,e=>ai(r,e,!We(r))),Gy=r=>at(r,e=>ai(r,e,We(r))),Yy=r=>at(r,e=>M.cursor(r.lineBlockAt(e.head).from,1)),Zy=r=>at(r,e=>M.cursor(r.lineBlockAt(e.head).to,-1));function Qy(r,e,t){let i=!1,n=rn(r.selection,s=>{let o=Bi(r,s.head,-1)||Bi(r,s.head,1)||s.head>0&&Bi(r,s.head-1,1)||s.headQy(r,e,!1);function ot(r,e){let t=rn(r.state.selection,i=>{let n=e(i);return M.range(i.anchor,n.head,n.goalColumn)});return t.eq(r.state.selection)?!1:(r.dispatch(Bt(r.state,t)),!0)}function Uf(r,e){return ot(r,t=>r.moveByChar(t,e))}const Xf=r=>Uf(r,!We(r)),Kf=r=>Uf(r,We(r));function _f(r,e){return ot(r,t=>r.moveByGroup(t,e))}const t1=r=>_f(r,!We(r)),i1=r=>_f(r,We(r)),n1=r=>ot(r,e=>vr(r.state,e,!We(r))),s1=r=>ot(r,e=>vr(r.state,e,We(r)));function jf(r,e){return ot(r,t=>r.moveVertically(t,e))}const qf=r=>jf(r,!1),Gf=r=>jf(r,!0);function Yf(r,e){return ot(r,t=>r.moveVertically(t,e,Wf(r)))}const jh=r=>Yf(r,!1),qh=r=>Yf(r,!0),r1=r=>ot(r,e=>ai(r,e,!0)),o1=r=>ot(r,e=>ai(r,e,!1)),l1=r=>ot(r,e=>ai(r,e,!We(r))),a1=r=>ot(r,e=>ai(r,e,We(r))),h1=r=>ot(r,e=>M.cursor(r.lineBlockAt(e.head).from)),u1=r=>ot(r,e=>M.cursor(r.lineBlockAt(e.head).to)),Gh=({state:r,dispatch:e})=>(e(Bt(r,{anchor:0})),!0),Yh=({state:r,dispatch:e})=>(e(Bt(r,{anchor:r.doc.length})),!0),Zh=({state:r,dispatch:e})=>(e(Bt(r,{anchor:r.selection.main.anchor,head:0})),!0),Qh=({state:r,dispatch:e})=>(e(Bt(r,{anchor:r.selection.main.anchor,head:r.doc.length})),!0),c1=({state:r,dispatch:e})=>(e(r.update({selection:{anchor:0,head:r.doc.length},userEvent:"select"})),!0),f1=({state:r,dispatch:e})=>{let t=Sr(r).map(({from:i,to:n})=>M.range(i,Math.min(n+1,r.doc.length)));return e(r.update({selection:M.create(t),userEvent:"select"})),!0},d1=({state:r,dispatch:e})=>{let t=rn(r.selection,i=>{var n;let s=li(r).resolveInner(i.head,1);for(;!(s.from=i.to||s.to>i.to&&s.from<=i.from||!(!((n=s.parent)===null||n===void 0)&&n.parent));)s=s.parent;return M.range(s.to,s.from)});return e(Bt(r,t)),!0},p1=({state:r,dispatch:e})=>{let t=r.selection,i=null;return t.ranges.length>1?i=M.create([t.main]):t.main.empty||(i=M.create([M.cursor(t.main.head)])),i?(e(Bt(r,i)),!0):!1};function wr(r,e){if(r.state.readOnly)return!1;let t="delete.selection",{state:i}=r,n=i.changeByRange(s=>{let{from:o,to:l}=s;if(o==l){let a=e(o);ao&&(t="delete.forward",a=gs(r,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=gs(r,o,!1),l=gs(r,l,!0);return o==l?{range:s}:{changes:{from:o,to:l},range:M.cursor(o)}});return n.changes.empty?!1:(r.dispatch(i.update(n,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?q.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function gs(r,e,t){if(r instanceof q)for(let i of r.state.facet(q.atomicRanges).map(n=>n(r)))i.between(e,e,(n,s)=>{ne&&(e=t?s:n)});return e}const Zf=(r,e)=>wr(r,t=>{let{state:i}=r,n=i.doc.lineAt(t),s,o;if(!e&&t>n.from&&tZf(r,!1),Qf=r=>Zf(r,!0),ed=(r,e)=>wr(r,t=>{let i=t,{state:n}=r,s=n.doc.lineAt(i),o=n.charCategorizer(i);for(let l=null;;){if(i==(e?s.to:s.from)){i==t&&s.number!=(e?n.doc.lines:1)&&(i+=e?1:-1);break}let a=nt(s.text,i-s.from,e)+s.from,h=s.text.slice(Math.min(i,a)-s.from,Math.max(i,a)-s.from),u=o(h);if(l!=null&&u!=l)break;(h!=" "||i!=t)&&(l=u),i=a}return i}),td=r=>ed(r,!1),m1=r=>ed(r,!0),id=r=>wr(r,e=>{let t=r.lineBlockAt(e).to;return ewr(r,e=>{let t=r.lineBlockAt(e).from;return e>t?t:Math.max(0,e-1)}),y1=({state:r,dispatch:e})=>{if(r.readOnly)return!1;let t=r.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:K.of(["",""])},range:M.cursor(i.from)}));return e(r.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},x1=({state:r,dispatch:e})=>{if(r.readOnly)return!1;let t=r.changeByRange(i=>{if(!i.empty||i.from==0||i.from==r.doc.length)return{range:i};let n=i.from,s=r.doc.lineAt(n),o=n==s.from?n-1:nt(s.text,n-s.from,!1)+s.from,l=n==s.to?n+1:nt(s.text,n-s.from,!0)+s.from;return{changes:{from:o,to:l,insert:r.doc.slice(n,l).append(r.doc.slice(o,n))},range:M.cursor(l)}});return t.changes.empty?!1:(e(r.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Sr(r){let e=[],t=-1;for(let i of r.selection.ranges){let n=r.doc.lineAt(i.from),s=r.doc.lineAt(i.to);if(!i.empty&&i.to==s.from&&(s=r.doc.lineAt(i.to-1)),t>=n.number){let o=e[e.length-1];o.to=s.to,o.ranges.push(i)}else e.push({from:n.from,to:s.to,ranges:[i]});t=s.number+1}return e}function nd(r,e,t){if(r.readOnly)return!1;let i=[],n=[];for(let s of Sr(r)){if(t?s.to==r.doc.length:s.from==0)continue;let o=r.doc.lineAt(t?s.to+1:s.from-1),l=o.length+1;if(t){i.push({from:s.to,to:o.to},{from:s.from,insert:o.text+r.lineBreak});for(let a of s.ranges)n.push(M.range(Math.min(r.doc.length,a.anchor+l),Math.min(r.doc.length,a.head+l)))}else{i.push({from:o.from,to:s.from},{from:s.to,insert:r.lineBreak+o.text});for(let a of s.ranges)n.push(M.range(a.anchor-l,a.head-l))}}return i.length?(e(r.update({changes:i,scrollIntoView:!0,selection:M.create(n,r.selection.mainIndex),userEvent:"move.line"})),!0):!1}const v1=({state:r,dispatch:e})=>nd(r,e,!1),w1=({state:r,dispatch:e})=>nd(r,e,!0);function sd(r,e,t){if(r.readOnly)return!1;let i=[];for(let n of Sr(r))t?i.push({from:n.from,insert:r.doc.slice(n.from,n.to)+r.lineBreak}):i.push({from:n.to,insert:r.lineBreak+r.doc.slice(n.from,n.to)});return e(r.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const S1=({state:r,dispatch:e})=>sd(r,e,!1),D1=({state:r,dispatch:e})=>sd(r,e,!0),b1=r=>{if(r.state.readOnly)return!1;let{state:e}=r,t=e.changes(Sr(e).map(({from:n,to:s})=>(n>0?n--:sr.moveVertically(n,!0)).map(t);return r.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function k1(r,e){if(/\(\)|\[\]|\{\}/.test(r.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=li(r).resolveInner(e),i=t.childBefore(e),n=t.childAfter(e),s;return i&&n&&i.to<=e&&n.from>=e&&(s=i.type.prop(_.closedBy))&&s.indexOf(n.name)>-1&&r.doc.lineAt(i.to).from==r.doc.lineAt(n.from).from?{from:i.to,to:n.from}:null}const A1=rd(!1),C1=rd(!0);function rd(r){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(n=>{let{from:s,to:o}=n,l=e.doc.lineAt(s),a=!r&&s==o&&k1(e,s);r&&(s=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new gr(e,{simulateBreak:s,simulateDoubleBreak:!!a}),u=Tf(h,s);for(u==null&&(u=/^\s*/.exec(e.doc.lineAt(s).text)[0].length);ol.from&&s{let n=[];for(let o=i.from;o<=i.to;){let l=r.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,n,i),t=l.number),o=l.to+1}let s=r.changes(n);return{changes:n,range:M.range(s.mapPos(i.anchor,1),s.mapPos(i.head,1))}})}const E1=({state:r,dispatch:e})=>{if(r.readOnly)return!1;let t=Object.create(null),i=new gr(r,{overrideIndentation:s=>{let o=t[s];return o??-1}}),n=jl(r,(s,o,l)=>{let a=Tf(i,s.from);if(a==null)return;/\S/.test(s.text)||(a=0);let h=/^\s*/.exec(s.text)[0],u=sr(r,a);(h!=u||l.fromr.readOnly?!1:(e(r.update(jl(r,(t,i)=>{i.push({from:t.from,insert:r.facet(Ul)})}),{userEvent:"input.indent"})),!0),B1=({state:r,dispatch:e})=>r.readOnly?!1:(e(r.update(jl(r,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let s=xl(n,r.tabSize),o=0,l=sr(r,Math.max(0,s-nr(r)));for(;o({mac:r.key,run:r.run,shift:r.shift}))),eu=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Xy,shift:n1},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Ky,shift:s1},{key:"Alt-ArrowUp",run:v1},{key:"Shift-Alt-ArrowUp",run:S1},{key:"Alt-ArrowDown",run:w1},{key:"Shift-Alt-ArrowDown",run:D1},{key:"Escape",run:p1},{key:"Mod-Enter",run:C1},{key:"Alt-l",mac:"Ctrl-l",run:f1},{key:"Mod-i",run:d1,preventDefault:!0},{key:"Mod-[",run:B1},{key:"Mod-]",run:F1},{key:"Mod-Alt-\\",run:E1},{key:"Shift-Mod-k",run:b1},{key:"Shift-Mod-\\",run:e1},{key:"Mod-/",run:Sy},{key:"Alt-A",run:by}].concat(M1);var od=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};/*! queue-microtask. MIT License. Feross Aboukhadijeh */let tu;var Zr=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:od):r=>(tu||(tu=Promise.resolve())).then(r).catch(e=>setTimeout(()=>{throw e},0));const Tt={EDIT:"edit",EXEC:"exec"},Mt={NULL:"",OK:"OK",INCOMPLETE:"Incomplete",PARSE_ERR:"ParseError",ERR:"Err"},O1=2500,iu="shell.history",P1="shell-prompt";function ci(r,e){return r.line(e.line).from+e.ch}const pl=de.define(),N1=de.define(),I1=zt.define({create(){return ge.none},update(r,e){r=r.map(e.changes);for(let t of e.effects)t.is(pl)?r=r.update({add:t.value,sort:!0}):t.is(N1)&&(r=r.update({filter:t.value}));return r},provide:r=>q.decorations.from(r)});function L1(r){var e,t=Tt.EDIT,i="",n=this;n.opts=r,n.cm=null,this.function_tip={},this.EXEC_STATE=Tt,this.PARSE_STATUS=Mt,n.language=null;var s=0,o=[],l=[],a=[],h=[],u=!1,d=null,p=!1,g=!1;class y{current_line=null;commands=[];actual_commands=[];pointer=0;reset_pointer(){this.pointer=0,this.commands=this.actual_commands.slice(0)}push(w){this.actual_commands.push(w),this.commands=this.actual_commands.slice(0)}save(w){w=w||{};var b=w.max||O1,E=w.key||iu;localStorage.setItem(E,JSON.stringify(this.actual_commands.slice(-b)))}restore(w){w=w||{};var b=w.key||iu,E=localStorage.getItem(b);E&&(this.actual_commands=JSON.parse(E)),this.reset_pointer()}clear(){this.actual_commands=[],this.commands=[],this.pointer=0,this.save()}}const c=new y;function f(D){var w=zl.define({startState:function(){return{base:D.startState(),linecount:0}},token:function(b,E){if(b.sol()){var C=E.linecount;if(E.linecount++,u||a[C])return b.skipToEnd(),"unstyled";h[C]&&(E.base=D.startState())}return D.token(b,E.base)},indent:D?.indent&&function(b,E){return console.log("outerLanguage indent",{base:D,state:b,textAfter:E}),D.indent(b.base,E)},blankLine:function(b){b.linecount++,D.blankLine&&D.blankLine(b.base)}});n.language=w}this.clearHistory=function(){c.clear()},this.getCM=function(){return e},this.setOption=function(D,w){r.debug&&console.info("set option",D,w)},this.getOption=function(D){r.debug&&console.info("get option",D)};var m=function(D){d&&!g&&(p?D.type==="keyup"&&D.key==="Enter"&&(p=!1):d.push(D))},x=function(){var D=d;if(d=null,p=!1,D&&D.length){console.log(`playbackEvents: tmp=${JSON.stringify(D)}`);var w=e.getInputField();D.forEach(function(b){if(d){m(b);return}var E=new KeyboardEvent(b.type,b);Object.defineProperties(E,{charCode:{get:function(){return b.charCode}},which:{get:function(){return b.which}},keyCode:{get:function(){return b.keyCode}},key:{get:function(){return b.key}},char:{get:function(){return b.char}},target:{get:function(){return b.target}}}),g=!0,w.dispatchEvent(E),g=!1})}};this.block=function(w){if(console.log(`block: state=${JSON.stringify(t)}`),t===Tt.EXEC)return!1;console.log("block: view",e);var b=e.state.doc,E=b.lines,C=b.line(E);console.log(`block: message=${JSON.stringify(w)}`),w?w=` +`+w+` +`:w=` +`;var F=b.line(b.lines).from;e.dispatch({changes:{from:F,to:void 0,insert:w}}),t=Tt.EXEC;var B=C.text.slice(s);return o.push(B),B.trim().length>0&&(c.push(B),c.save()),c.reset_pointer(),d=[],!0},this.unblock=function(D,w){if(t=Tt.EDIT,D&&D.prompt)o=[],v(D.prompt||n.opts.initial_prompt,D.prompt_class,D.continuation);else{var b=D?D.parsestatus||Mt.OK:Mt.NULL;b===Mt.INCOMPLETE?v(n.opts.continuation_prompt,void 0,!0):(o=[],v(n.opts.initial_prompt))}w||x()},this.get_history=function(){return c.actual_commands.slice(0)},this.insert_node=function(D,w){var b=e.state.doc,E=Math.max(b.lines-1,0);e.addLineWidget(E,D,{handleMouseEvents:!0}),w&&e.dispatch({effects:q.scrollIntoView(b.line(E).from)})},this.select_all=function(){e.dispatch({selection:{anchor:0,head:e.state.doc.length}})},this.response=function(w,b,E){console.log(`response: text=${JSON.stringify(w)}`);var C=e.state.doc,F=C.lines,B,I=F;if(w&&typeof w!="string")try{w=w.toString()}catch(Ci){w="Unrenderable message: "+Ci.message}var R=C.line(F),X=R?R.length:0,j=w.split(` +`),Z=void 0,ht=!1;if(t!==Tt.EXEC&&(X=0,j.length>1&&h.length)){var he=h.length-1;h[he]=void 0,h[he+j.length-1]=1}w="";for(var J=0;J1&&(ht=!0),ee.length>1){for(var ue="",xe=ee.length-1;xe>=0;xe--)ue=ue+ee[xe].substring(ue.length);w+=ue}else w+=j[J]}console.log(`response: text2=${JSON.stringify(w)}`),ht&&(Z={line:I,ch:X},X=0),E&&(u=!0),e.dispatch({changes:{from:ci(C,{line:I,ch:X}),to:Z&&ci(C,Z),insert:w}}),B=C.lines,R=C.line(B);var Oe=R.text.length;if(console.log(`doc.lines=${C.lines} lastline.text=${R.text} endch=${Oe}`),E){var lt=B;if(Oe==0&<--,lt>=I)for(var J=I;J<=lt;J++)a[J]=1}if(b){const Ci=ci(C,{line:I,ch:X}),Un=ci(C,{line:B,ch:Oe});if(Cie.dispatch({selection:{anchor:e.state.doc.length}})),u=!1};function v(D,w,b){typeof w>"u"&&(w=P1),typeof D>"u"&&(n.opts?i=n.opts.default_prompt:D="? "),i=D,console.log("set_prompt: cm",e);var E=e.state.doc,C=E.lines;console.log("set_prompt: doc.lines",E.lines),console.log("set_prompt: cm.state.doc.line(doc.lines)",e.state.doc.line(E.lines));var F=e.state.doc.line(C).text;if(b||(h[C]=1),s=F.length+i.length,console.log(`set_prompt: lastline=${F} prompt_text=${i}`),e.dispatch({changes:{from:ci(E,{line:C,ch:F.length}),to:void 0,insert:i}}),w){const B=ge.mark({attributes:{className:w}});e.dispatch({effects:pl.of([B.range(ci(E,{line:C,ch:F.length}),ci(E,{line:C,ch:s}))])})}}this.prompt=function(D,w,b){v(D,w,b)},this.execute_block=function(D){let w=D.split(/\n/g);l=l.concat(w),S(e)};function S(D,w){if(t===Tt.EXEC)return;var b=D.state.doc,E=b.lines,C=b.line(E);console.log("line",C);const F=b.length;D.dispatch({changes:{from:F,to:void 0,insert:` +`}}),t=Tt.EXEC;var B;w?(B="",o=[B]):(B=C.text.slice(s),o.push(B)),B.trim().length>0&&(c.push(B),c.save()),c.reset_pointer(),n.opts.exec_function&&(d||(d=[]),console.log("command_buffer",o),n.opts.exec_function.call(this,o,function(R){if(t=Tt.EDIT,R&&R.prompt)o=[],v(R.prompt||n.opts.initial_prompt,R.prompt_class,R.continuation);else{var X=R?R.parsestatus||Mt.OK:Mt.NULL;console.log(`handleResult: parseStatus=${JSON.stringify(X)}`),X===Mt.INCOMPLETE?v(n.opts.continuation_prompt,void 0,!0):(o=[],v(n.opts.initial_prompt))}E=D.state.doc.lines,l.length?(console.log("handleResult: setImmediate paste"),Zr(function(){var Z=l[0];console.log(`handleResult: setImmediate paste: text=${JSON.stringify(Z)}`),l.splice(0,1),b.replaceRange(Z,{line:E,ch:s},void 0,"paste-continuation"),l.length?S(D):x()})):(console.log("handleResult: setImmediate playbackEvents"),Zr(x))}))}this.clear=function(D){var w=e.state.doc,b=w.lines;b>0&&e.dispatch({changes:{from:0,to:w.line(w.lines).from,insert:""}}),a.splice(0,a.length),u=!1,h.splice(0,h.length);var E=w.line(w.lines);w.setSelection({line:w.lines,ch:E.length}),D&&this.focus()},this.get_width_in_chars=function(){return Math.floor(this.opts.container.clientWidth/e.defaultCharacterWidth)-n.opts.initial_prompt.length},this.cancel=function(){S(e,!0)},this.get_current_line=function(){var D=e.state.doc,w=D.line(D.lines),b=e.state.selection.main.head;return{text:w.text.slice(s),pos:b?b-s:-1}},this.get_caret_line=function(){var D=e.state.selection.main.head,w=e.state.doc.lineAt(D);return{text:w,pos:D}},this.get_selections=function(){return e.state.doc.getSelections()},this.focus=function(){e.focus()},this.show_function_tip=function(D){if(this.function_tip||(this.function_tip={}),D!==this.function_tip.cached_tip){var w=e.cursorCoords();this.function_tip.cached_tip=D,this.function_tip.node||(this.function_tip.container_node=document.createElement("div"),this.function_tip.container_node.className="cmjs-shell-function-tip-container",this.function_tip.node=document.createElement("div"),this.function_tip.node.className="cmjs-shell-function-tip",this.function_tip.container_node.appendChild(this.function_tip.node),r.container.appendChild(this.function_tip.container_node)),this.function_tip.visible=!0,this.function_tip.node.innerHTML=D,this.function_tip.container_node.setAttribute("style","top: "+w.top+"px; left: "+w.left+"px;"),this.function_tip.container_node.classList.add("visible")}},this.hide_function_tip=function(D){return this.function_tip?(D||(this.function_tip.cached_tip=null),this.function_tip.visible?(this.function_tip.container_node.classList.remove("visible"),this.function_tip.visible=!1,!0):!1):!1},function(){r=r||{},r.initial_prompt=r.initial_prompt||"> ",r.continuation_prompt=r.continuation_prompt||"+ ",r.exec_function=r.exec_function||function(E,C){r.debug&&console.info("DUMMY");var F=Mt.OK,B=null;E.length&&E[E.length-1].match(/_\s*$/)&&(F=Mt.INCOMPLETE),C.call(this,{parsestatus:F,err:B})},r.function_key_callback=r.function_key_callback||function(){},r.container=r.container||document.body,typeof r.container=="string"&&(r.container=document.querySelector(r.container)),f(r.mode);const D=[{key:"Enter",preventDefault:!0,run:(E,C)=>(console.log("Enter",E,C),S(E),!0)}];console.log("keymaps",{terminalKeymap:D,historyKeymap:Kh,defaultKeymap:eu}),console.log("opts.container",r.container),e=new q({extensions:[I1,uc.of([...D,...eu,...Kh])],doc:"",parent:r.container});var w=e.contentDOM;w.addEventListener("keydown",m),w.addEventListener("keyup",m),w.addEventListener("keypress",m),w.addEventListener("char",m),r.suppress_initial_prompt||v(r.initial_prompt);var b=null;r.hint_function&&(b=function(E,C){var F=E.state.doc,B=F.line(F.lines),I=E.state.selection.main.head,R=s;r.hint_function.call(n,B.substr(R),I-R,function(X,j){!X||!X.length?C(null):C({list:X,from:{line:pos.line,ch:j+R},to:{line:pos.line,ch:I}})})},b.async=!0),c.restore(),n.opts=r,r.debug&&(n.cm=e)}()}const R1=` _ _ _ _ + (_) | | | | | + ___ _ __ ___ _ ___ ___| |__ ___| | | + / __| '_ \` _ \\| / __| / __| '_ \\ / _ \\ | | + | (__| | | | | | \\__ \\ \\__ \\ | | | __/ | | + \\___|_| |_| |_| |___/ |___/_| |_|\\___|_|_| + _/ | + |__/ + + This is a demo of cmjs-shell. It's not really intended for browsers + (it was built for electron), but it should work ok. Here there's a + javascript interpreter provided for test purposes. Enjoy! + +`;var ld={exports:{}};(function(r,e){(function(i,n){r.exports=n()})(od,function(){return function(t){var i={};function n(s){if(i[s])return i[s].exports;var o=i[s]={exports:{},id:s,loaded:!1};return t[s].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}return n.m=t,n.c=i,n.p="",n(0)}([function(t,i,n){Object.defineProperty(i,"__esModule",{value:!0});var s=n(1),o=n(3),l=n(8),a=n(15);function h(y,c,f){var m=null,x=function(F,B){f&&f(F,B),m&&m.visit(F,B)},v=typeof f=="function"?x:null,S=!1;if(c){S=typeof c.comment=="boolean"&&c.comment;var D=typeof c.attachComment=="boolean"&&c.attachComment;(S||D)&&(m=new s.CommentHandler,m.attach=D,c.comment=!0,v=x)}var w=!1;c&&typeof c.sourceType=="string"&&(w=c.sourceType==="module");var b;c&&typeof c.jsx=="boolean"&&c.jsx?b=new o.JSXParser(y,c,v):b=new l.Parser(y,c,v);var E=w?b.parseModule():b.parseScript(),C=E;return S&&m&&(C.comments=m.comments),b.config.tokens&&(C.tokens=b.tokens),b.config.tolerant&&(C.errors=b.errorHandler.errors),C}i.parse=h;function u(y,c,f){var m=c||{};return m.sourceType="module",h(y,m,f)}i.parseModule=u;function d(y,c,f){var m=c||{};return m.sourceType="script",h(y,m,f)}i.parseScript=d;function p(y,c,f){var m=new a.Tokenizer(y,c),x;x=[];try{for(;;){var v=m.getNextToken();if(!v)break;f&&(v=f(v)),x.push(v)}}catch(S){m.errorHandler.tolerate(S)}return m.errorHandler.tolerant&&(x.errors=m.errors()),x}i.tokenize=p;var g=n(2);i.Syntax=g.Syntax,i.version="4.0.1"},function(t,i,n){Object.defineProperty(i,"__esModule",{value:!0});var s=n(2),o=function(){function l(){this.attach=!1,this.comments=[],this.stack=[],this.leading=[],this.trailing=[]}return l.prototype.insertInnerComments=function(a,h){if(a.type===s.Syntax.BlockStatement&&a.body.length===0){for(var u=[],d=this.leading.length-1;d>=0;--d){var p=this.leading[d];h.end.offset>=p.start&&(u.unshift(p.comment),this.leading.splice(d,1),this.trailing.splice(d,1))}u.length&&(a.innerComments=u)}},l.prototype.findTrailingComments=function(a){var h=[];if(this.trailing.length>0){for(var u=this.trailing.length-1;u>=0;--u){var d=this.trailing[u];d.start>=a.end.offset&&h.unshift(d.comment)}return this.trailing.length=0,h}var p=this.stack[this.stack.length-1];if(p&&p.node.trailingComments){var g=p.node.trailingComments[0];g&&g.range[0]>=a.end.offset&&(h=p.node.trailingComments,delete p.node.trailingComments)}return h},l.prototype.findLeadingComments=function(a){for(var h=[],u;this.stack.length>0;){var d=this.stack[this.stack.length-1];if(d&&d.start>=a.start.offset)u=d.node,this.stack.pop();else break}if(u){for(var p=u.leadingComments?u.leadingComments.length:0,g=p-1;g>=0;--g){var y=u.leadingComments[g];y.range[1]<=a.start.offset&&(h.unshift(y),u.leadingComments.splice(g,1))}return u.leadingComments&&u.leadingComments.length===0&&delete u.leadingComments,h}for(var g=this.leading.length-1;g>=0;--g){var d=this.leading[g];d.start<=a.start.offset&&(h.unshift(d.comment),this.leading.splice(g,1))}return h},l.prototype.visitNode=function(a,h){if(!(a.type===s.Syntax.Program&&a.body.length>0)){this.insertInnerComments(a,h);var u=this.findTrailingComments(h),d=this.findLeadingComments(h);d.length>0&&(a.leadingComments=d),u.length>0&&(a.trailingComments=u),this.stack.push({node:a,start:h.start.offset})}},l.prototype.visitComment=function(a,h){var u=a.type[0]==="L"?"Line":"Block",d={type:u,value:a.value};if(a.range&&(d.range=a.range),a.loc&&(d.loc=a.loc),this.comments.push(d),this.attach){var p={comment:{type:u,value:a.value,range:[h.start.offset,h.end.offset]},start:h.start.offset};a.loc&&(p.comment.loc=a.loc),a.type=u,this.leading.push(p),this.trailing.push(p)}},l.prototype.visit=function(a,h){a.type==="LineComment"?this.visitComment(a,h):a.type==="BlockComment"?this.visitComment(a,h):this.attach&&this.visitNode(a,h)},l}();i.CommentHandler=o},function(t,i){Object.defineProperty(i,"__esModule",{value:!0}),i.Syntax={AssignmentExpression:"AssignmentExpression",AssignmentPattern:"AssignmentPattern",ArrayExpression:"ArrayExpression",ArrayPattern:"ArrayPattern",ArrowFunctionExpression:"ArrowFunctionExpression",AwaitExpression:"AwaitExpression",BlockStatement:"BlockStatement",BinaryExpression:"BinaryExpression",BreakStatement:"BreakStatement",CallExpression:"CallExpression",CatchClause:"CatchClause",ClassBody:"ClassBody",ClassDeclaration:"ClassDeclaration",ClassExpression:"ClassExpression",ConditionalExpression:"ConditionalExpression",ContinueStatement:"ContinueStatement",DoWhileStatement:"DoWhileStatement",DebuggerStatement:"DebuggerStatement",EmptyStatement:"EmptyStatement",ExportAllDeclaration:"ExportAllDeclaration",ExportDefaultDeclaration:"ExportDefaultDeclaration",ExportNamedDeclaration:"ExportNamedDeclaration",ExportSpecifier:"ExportSpecifier",ExpressionStatement:"ExpressionStatement",ForStatement:"ForStatement",ForOfStatement:"ForOfStatement",ForInStatement:"ForInStatement",FunctionDeclaration:"FunctionDeclaration",FunctionExpression:"FunctionExpression",Identifier:"Identifier",IfStatement:"IfStatement",ImportDeclaration:"ImportDeclaration",ImportDefaultSpecifier:"ImportDefaultSpecifier",ImportNamespaceSpecifier:"ImportNamespaceSpecifier",ImportSpecifier:"ImportSpecifier",Literal:"Literal",LabeledStatement:"LabeledStatement",LogicalExpression:"LogicalExpression",MemberExpression:"MemberExpression",MetaProperty:"MetaProperty",MethodDefinition:"MethodDefinition",NewExpression:"NewExpression",ObjectExpression:"ObjectExpression",ObjectPattern:"ObjectPattern",Program:"Program",Property:"Property",RestElement:"RestElement",ReturnStatement:"ReturnStatement",SequenceExpression:"SequenceExpression",SpreadElement:"SpreadElement",Super:"Super",SwitchCase:"SwitchCase",SwitchStatement:"SwitchStatement",TaggedTemplateExpression:"TaggedTemplateExpression",TemplateElement:"TemplateElement",TemplateLiteral:"TemplateLiteral",ThisExpression:"ThisExpression",ThrowStatement:"ThrowStatement",TryStatement:"TryStatement",UnaryExpression:"UnaryExpression",UpdateExpression:"UpdateExpression",VariableDeclaration:"VariableDeclaration",VariableDeclarator:"VariableDeclarator",WhileStatement:"WhileStatement",WithStatement:"WithStatement",YieldExpression:"YieldExpression"}},function(t,i,n){var s=this&&this.__extends||function(){var c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(f,m){f.__proto__=m}||function(f,m){for(var x in m)m.hasOwnProperty(x)&&(f[x]=m[x])};return function(f,m){c(f,m);function x(){this.constructor=f}f.prototype=m===null?Object.create(m):(x.prototype=m.prototype,new x)}}();Object.defineProperty(i,"__esModule",{value:!0});var o=n(4),l=n(5),a=n(6),h=n(7),u=n(8),d=n(13),p=n(14);d.TokenName[100]="JSXIdentifier",d.TokenName[101]="JSXText";function g(c){var f;switch(c.type){case a.JSXSyntax.JSXIdentifier:var m=c;f=m.name;break;case a.JSXSyntax.JSXNamespacedName:var x=c;f=g(x.namespace)+":"+g(x.name);break;case a.JSXSyntax.JSXMemberExpression:var v=c;f=g(v.object)+"."+g(v.property);break}return f}var y=function(c){s(f,c);function f(m,x,v){return c.call(this,m,x,v)||this}return f.prototype.parsePrimaryExpression=function(){return this.match("<")?this.parseJSXRoot():c.prototype.parsePrimaryExpression.call(this)},f.prototype.startJSX=function(){this.scanner.index=this.startMarker.index,this.scanner.lineNumber=this.startMarker.line,this.scanner.lineStart=this.startMarker.index-this.startMarker.column},f.prototype.finishJSX=function(){this.nextToken()},f.prototype.reenterJSX=function(){this.startJSX(),this.expectJSX("}"),this.config.tokens&&this.tokens.pop()},f.prototype.createJSXNode=function(){return this.collectComments(),{index:this.scanner.index,line:this.scanner.lineNumber,column:this.scanner.index-this.scanner.lineStart}},f.prototype.createJSXChildNode=function(){return{index:this.scanner.index,line:this.scanner.lineNumber,column:this.scanner.index-this.scanner.lineStart}},f.prototype.scanXHTMLEntity=function(m){for(var x="&",v=!0,S=!1,D=!1,w=!1;!this.scanner.eof()&&v&&!S;){var b=this.scanner.source[this.scanner.index];if(b===m)break;if(S=b===";",x+=b,++this.scanner.index,!S)switch(x.length){case 2:D=b==="#";break;case 3:D&&(w=b==="x",v=w||o.Character.isDecimalDigit(b.charCodeAt(0)),D=D&&!w);break;default:v=v&&!(D&&!o.Character.isDecimalDigit(b.charCodeAt(0))),v=v&&!(w&&!o.Character.isHexDigit(b.charCodeAt(0)));break}}if(v&&S&&x.length>2){var E=x.substr(1,x.length-2);D&&E.length>1?x=String.fromCharCode(parseInt(E.substr(1),10)):w&&E.length>2?x=String.fromCharCode(parseInt("0"+E.substr(1),16)):!D&&!w&&p.XHTMLEntities[E]&&(x=p.XHTMLEntities[E])}return x},f.prototype.lexJSX=function(){var m=this.scanner.source.charCodeAt(this.scanner.index);if(m===60||m===62||m===47||m===58||m===61||m===123||m===125){var x=this.scanner.source[this.scanner.index++];return{type:7,value:x,lineNumber:this.scanner.lineNumber,lineStart:this.scanner.lineStart,start:this.scanner.index-1,end:this.scanner.index}}if(m===34||m===39){for(var v=this.scanner.index,S=this.scanner.source[this.scanner.index++],D="";!this.scanner.eof();){var w=this.scanner.source[this.scanner.index++];if(w===S)break;w==="&"?D+=this.scanXHTMLEntity(S):D+=w}return{type:8,value:D,lineNumber:this.scanner.lineNumber,lineStart:this.scanner.lineStart,start:v,end:this.scanner.index}}if(m===46){var b=this.scanner.source.charCodeAt(this.scanner.index+1),E=this.scanner.source.charCodeAt(this.scanner.index+2),x=b===46&&E===46?"...":".",v=this.scanner.index;return this.scanner.index+=x.length,{type:7,value:x,lineNumber:this.scanner.lineNumber,lineStart:this.scanner.lineStart,start:v,end:this.scanner.index}}if(m===96)return{type:10,value:"",lineNumber:this.scanner.lineNumber,lineStart:this.scanner.lineStart,start:this.scanner.index,end:this.scanner.index};if(o.Character.isIdentifierStart(m)&&m!==92){var v=this.scanner.index;for(++this.scanner.index;!this.scanner.eof();){var w=this.scanner.source.charCodeAt(this.scanner.index);if(o.Character.isIdentifierPart(w)&&w!==92)++this.scanner.index;else if(w===45)++this.scanner.index;else break}var C=this.scanner.source.slice(v,this.scanner.index);return{type:100,value:C,lineNumber:this.scanner.lineNumber,lineStart:this.scanner.lineStart,start:v,end:this.scanner.index}}return this.scanner.lex()},f.prototype.nextJSXToken=function(){this.collectComments(),this.startMarker.index=this.scanner.index,this.startMarker.line=this.scanner.lineNumber,this.startMarker.column=this.scanner.index-this.scanner.lineStart;var m=this.lexJSX();return this.lastMarker.index=this.scanner.index,this.lastMarker.line=this.scanner.lineNumber,this.lastMarker.column=this.scanner.index-this.scanner.lineStart,this.config.tokens&&this.tokens.push(this.convertToken(m)),m},f.prototype.nextJSXText=function(){this.startMarker.index=this.scanner.index,this.startMarker.line=this.scanner.lineNumber,this.startMarker.column=this.scanner.index-this.scanner.lineStart;for(var m=this.scanner.index,x="";!this.scanner.eof();){var v=this.scanner.source[this.scanner.index];if(v==="{"||v==="<")break;++this.scanner.index,x+=v,o.Character.isLineTerminator(v.charCodeAt(0))&&(++this.scanner.lineNumber,v==="\r"&&this.scanner.source[this.scanner.index]===` +`&&++this.scanner.index,this.scanner.lineStart=this.scanner.index)}this.lastMarker.index=this.scanner.index,this.lastMarker.line=this.scanner.lineNumber,this.lastMarker.column=this.scanner.index-this.scanner.lineStart;var S={type:101,value:x,lineNumber:this.scanner.lineNumber,lineStart:this.scanner.lineStart,start:m,end:this.scanner.index};return x.length>0&&this.config.tokens&&this.tokens.push(this.convertToken(S)),S},f.prototype.peekJSXToken=function(){var m=this.scanner.saveState();this.scanner.scanComments();var x=this.lexJSX();return this.scanner.restoreState(m),x},f.prototype.expectJSX=function(m){var x=this.nextJSXToken();(x.type!==7||x.value!==m)&&this.throwUnexpectedToken(x)},f.prototype.matchJSX=function(m){var x=this.peekJSXToken();return x.type===7&&x.value===m},f.prototype.parseJSXIdentifier=function(){var m=this.createJSXNode(),x=this.nextJSXToken();return x.type!==100&&this.throwUnexpectedToken(x),this.finalize(m,new l.JSXIdentifier(x.value))},f.prototype.parseJSXElementName=function(){var m=this.createJSXNode(),x=this.parseJSXIdentifier();if(this.matchJSX(":")){var v=x;this.expectJSX(":");var S=this.parseJSXIdentifier();x=this.finalize(m,new l.JSXNamespacedName(v,S))}else if(this.matchJSX("."))for(;this.matchJSX(".");){var D=x;this.expectJSX(".");var w=this.parseJSXIdentifier();x=this.finalize(m,new l.JSXMemberExpression(D,w))}return x},f.prototype.parseJSXAttributeName=function(){var m=this.createJSXNode(),x,v=this.parseJSXIdentifier();if(this.matchJSX(":")){var S=v;this.expectJSX(":");var D=this.parseJSXIdentifier();x=this.finalize(m,new l.JSXNamespacedName(S,D))}else x=v;return x},f.prototype.parseJSXStringLiteralAttribute=function(){var m=this.createJSXNode(),x=this.nextJSXToken();x.type!==8&&this.throwUnexpectedToken(x);var v=this.getTokenRaw(x);return this.finalize(m,new h.Literal(x.value,v))},f.prototype.parseJSXExpressionAttribute=function(){var m=this.createJSXNode();this.expectJSX("{"),this.finishJSX(),this.match("}")&&this.tolerateError("JSX attributes must only be assigned a non-empty expression");var x=this.parseAssignmentExpression();return this.reenterJSX(),this.finalize(m,new l.JSXExpressionContainer(x))},f.prototype.parseJSXAttributeValue=function(){return this.matchJSX("{")?this.parseJSXExpressionAttribute():this.matchJSX("<")?this.parseJSXElement():this.parseJSXStringLiteralAttribute()},f.prototype.parseJSXNameValueAttribute=function(){var m=this.createJSXNode(),x=this.parseJSXAttributeName(),v=null;return this.matchJSX("=")&&(this.expectJSX("="),v=this.parseJSXAttributeValue()),this.finalize(m,new l.JSXAttribute(x,v))},f.prototype.parseJSXSpreadAttribute=function(){var m=this.createJSXNode();this.expectJSX("{"),this.expectJSX("..."),this.finishJSX();var x=this.parseAssignmentExpression();return this.reenterJSX(),this.finalize(m,new l.JSXSpreadAttribute(x))},f.prototype.parseJSXAttributes=function(){for(var m=[];!this.matchJSX("/")&&!this.matchJSX(">");){var x=this.matchJSX("{")?this.parseJSXSpreadAttribute():this.parseJSXNameValueAttribute();m.push(x)}return m},f.prototype.parseJSXOpeningElement=function(){var m=this.createJSXNode();this.expectJSX("<");var x=this.parseJSXElementName(),v=this.parseJSXAttributes(),S=this.matchJSX("/");return S&&this.expectJSX("/"),this.expectJSX(">"),this.finalize(m,new l.JSXOpeningElement(x,S,v))},f.prototype.parseJSXBoundaryElement=function(){var m=this.createJSXNode();if(this.expectJSX("<"),this.matchJSX("/")){this.expectJSX("/");var x=this.parseJSXElementName();return this.expectJSX(">"),this.finalize(m,new l.JSXClosingElement(x))}var v=this.parseJSXElementName(),S=this.parseJSXAttributes(),D=this.matchJSX("/");return D&&this.expectJSX("/"),this.expectJSX(">"),this.finalize(m,new l.JSXOpeningElement(v,D,S))},f.prototype.parseJSXEmptyExpression=function(){var m=this.createJSXChildNode();return this.collectComments(),this.lastMarker.index=this.scanner.index,this.lastMarker.line=this.scanner.lineNumber,this.lastMarker.column=this.scanner.index-this.scanner.lineStart,this.finalize(m,new l.JSXEmptyExpression)},f.prototype.parseJSXExpressionContainer=function(){var m=this.createJSXNode();this.expectJSX("{");var x;return this.matchJSX("}")?(x=this.parseJSXEmptyExpression(),this.expectJSX("}")):(this.finishJSX(),x=this.parseAssignmentExpression(),this.reenterJSX()),this.finalize(m,new l.JSXExpressionContainer(x))},f.prototype.parseJSXChildren=function(){for(var m=[];!this.scanner.eof();){var x=this.createJSXChildNode(),v=this.nextJSXText();if(v.start0){var w=this.finalize(m.node,new l.JSXElement(m.opening,m.children,m.closing));m=x[x.length-1],m.children.push(w),x.pop()}else break}}return m},f.prototype.parseJSXElement=function(){var m=this.createJSXNode(),x=this.parseJSXOpeningElement(),v=[],S=null;if(!x.selfClosing){var D=this.parseComplexJSXElement({node:m,opening:x,closing:S,children:v});v=D.children,S=D.closing}return this.finalize(m,new l.JSXElement(x,v,S))},f.prototype.parseJSXRoot=function(){this.config.tokens&&this.tokens.pop(),this.startJSX();var m=this.parseJSXElement();return this.finishJSX(),m},f.prototype.isStartOfExpression=function(){return c.prototype.isStartOfExpression.call(this)||this.match("<")},f}(u.Parser);i.JSXParser=y},function(t,i){Object.defineProperty(i,"__esModule",{value:!0});var n={NonAsciiIdentifierStart:/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,NonAsciiIdentifierPart:/[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/};i.Character={fromCodePoint:function(s){return s<65536?String.fromCharCode(s):String.fromCharCode(55296+(s-65536>>10))+String.fromCharCode(56320+(s-65536&1023))},isWhiteSpace:function(s){return s===32||s===9||s===11||s===12||s===160||s>=5760&&[5760,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279].indexOf(s)>=0},isLineTerminator:function(s){return s===10||s===13||s===8232||s===8233},isIdentifierStart:function(s){return s===36||s===95||s>=65&&s<=90||s>=97&&s<=122||s===92||s>=128&&n.NonAsciiIdentifierStart.test(i.Character.fromCodePoint(s))},isIdentifierPart:function(s){return s===36||s===95||s>=65&&s<=90||s>=97&&s<=122||s>=48&&s<=57||s===92||s>=128&&n.NonAsciiIdentifierPart.test(i.Character.fromCodePoint(s))},isDecimalDigit:function(s){return s>=48&&s<=57},isHexDigit:function(s){return s>=48&&s<=57||s>=65&&s<=70||s>=97&&s<=102},isOctalDigit:function(s){return s>=48&&s<=55}}},function(t,i,n){Object.defineProperty(i,"__esModule",{value:!0});var s=n(6),o=function(){function m(x){this.type=s.JSXSyntax.JSXClosingElement,this.name=x}return m}();i.JSXClosingElement=o;var l=function(){function m(x,v,S){this.type=s.JSXSyntax.JSXElement,this.openingElement=x,this.children=v,this.closingElement=S}return m}();i.JSXElement=l;var a=function(){function m(){this.type=s.JSXSyntax.JSXEmptyExpression}return m}();i.JSXEmptyExpression=a;var h=function(){function m(x){this.type=s.JSXSyntax.JSXExpressionContainer,this.expression=x}return m}();i.JSXExpressionContainer=h;var u=function(){function m(x){this.type=s.JSXSyntax.JSXIdentifier,this.name=x}return m}();i.JSXIdentifier=u;var d=function(){function m(x,v){this.type=s.JSXSyntax.JSXMemberExpression,this.object=x,this.property=v}return m}();i.JSXMemberExpression=d;var p=function(){function m(x,v){this.type=s.JSXSyntax.JSXAttribute,this.name=x,this.value=v}return m}();i.JSXAttribute=p;var g=function(){function m(x,v){this.type=s.JSXSyntax.JSXNamespacedName,this.namespace=x,this.name=v}return m}();i.JSXNamespacedName=g;var y=function(){function m(x,v,S){this.type=s.JSXSyntax.JSXOpeningElement,this.name=x,this.selfClosing=v,this.attributes=S}return m}();i.JSXOpeningElement=y;var c=function(){function m(x){this.type=s.JSXSyntax.JSXSpreadAttribute,this.argument=x}return m}();i.JSXSpreadAttribute=c;var f=function(){function m(x,v){this.type=s.JSXSyntax.JSXText,this.value=x,this.raw=v}return m}();i.JSXText=f},function(t,i){Object.defineProperty(i,"__esModule",{value:!0}),i.JSXSyntax={JSXAttribute:"JSXAttribute",JSXClosingElement:"JSXClosingElement",JSXElement:"JSXElement",JSXEmptyExpression:"JSXEmptyExpression",JSXExpressionContainer:"JSXExpressionContainer",JSXIdentifier:"JSXIdentifier",JSXMemberExpression:"JSXMemberExpression",JSXNamespacedName:"JSXNamespacedName",JSXOpeningElement:"JSXOpeningElement",JSXSpreadAttribute:"JSXSpreadAttribute",JSXText:"JSXText"}},function(t,i,n){Object.defineProperty(i,"__esModule",{value:!0});var s=n(2),o=function(){function k(A){this.type=s.Syntax.ArrayExpression,this.elements=A}return k}();i.ArrayExpression=o;var l=function(){function k(A){this.type=s.Syntax.ArrayPattern,this.elements=A}return k}();i.ArrayPattern=l;var a=function(){function k(A,T,V){this.type=s.Syntax.ArrowFunctionExpression,this.id=null,this.params=A,this.body=T,this.generator=!1,this.expression=V,this.async=!1}return k}();i.ArrowFunctionExpression=a;var h=function(){function k(A,T,V){this.type=s.Syntax.AssignmentExpression,this.operator=A,this.left=T,this.right=V}return k}();i.AssignmentExpression=h;var u=function(){function k(A,T){this.type=s.Syntax.AssignmentPattern,this.left=A,this.right=T}return k}();i.AssignmentPattern=u;var d=function(){function k(A,T,V){this.type=s.Syntax.ArrowFunctionExpression,this.id=null,this.params=A,this.body=T,this.generator=!1,this.expression=V,this.async=!0}return k}();i.AsyncArrowFunctionExpression=d;var p=function(){function k(A,T,V){this.type=s.Syntax.FunctionDeclaration,this.id=A,this.params=T,this.body=V,this.generator=!1,this.expression=!1,this.async=!0}return k}();i.AsyncFunctionDeclaration=p;var g=function(){function k(A,T,V){this.type=s.Syntax.FunctionExpression,this.id=A,this.params=T,this.body=V,this.generator=!1,this.expression=!1,this.async=!0}return k}();i.AsyncFunctionExpression=g;var y=function(){function k(A){this.type=s.Syntax.AwaitExpression,this.argument=A}return k}();i.AwaitExpression=y;var c=function(){function k(A,T,V){var Ge=A==="||"||A==="&&";this.type=Ge?s.Syntax.LogicalExpression:s.Syntax.BinaryExpression,this.operator=A,this.left=T,this.right=V}return k}();i.BinaryExpression=c;var f=function(){function k(A){this.type=s.Syntax.BlockStatement,this.body=A}return k}();i.BlockStatement=f;var m=function(){function k(A){this.type=s.Syntax.BreakStatement,this.label=A}return k}();i.BreakStatement=m;var x=function(){function k(A,T){this.type=s.Syntax.CallExpression,this.callee=A,this.arguments=T}return k}();i.CallExpression=x;var v=function(){function k(A,T){this.type=s.Syntax.CatchClause,this.param=A,this.body=T}return k}();i.CatchClause=v;var S=function(){function k(A){this.type=s.Syntax.ClassBody,this.body=A}return k}();i.ClassBody=S;var D=function(){function k(A,T,V){this.type=s.Syntax.ClassDeclaration,this.id=A,this.superClass=T,this.body=V}return k}();i.ClassDeclaration=D;var w=function(){function k(A,T,V){this.type=s.Syntax.ClassExpression,this.id=A,this.superClass=T,this.body=V}return k}();i.ClassExpression=w;var b=function(){function k(A,T){this.type=s.Syntax.MemberExpression,this.computed=!0,this.object=A,this.property=T}return k}();i.ComputedMemberExpression=b;var E=function(){function k(A,T,V){this.type=s.Syntax.ConditionalExpression,this.test=A,this.consequent=T,this.alternate=V}return k}();i.ConditionalExpression=E;var C=function(){function k(A){this.type=s.Syntax.ContinueStatement,this.label=A}return k}();i.ContinueStatement=C;var F=function(){function k(){this.type=s.Syntax.DebuggerStatement}return k}();i.DebuggerStatement=F;var B=function(){function k(A,T){this.type=s.Syntax.ExpressionStatement,this.expression=A,this.directive=T}return k}();i.Directive=B;var I=function(){function k(A,T){this.type=s.Syntax.DoWhileStatement,this.body=A,this.test=T}return k}();i.DoWhileStatement=I;var R=function(){function k(){this.type=s.Syntax.EmptyStatement}return k}();i.EmptyStatement=R;var X=function(){function k(A){this.type=s.Syntax.ExportAllDeclaration,this.source=A}return k}();i.ExportAllDeclaration=X;var j=function(){function k(A){this.type=s.Syntax.ExportDefaultDeclaration,this.declaration=A}return k}();i.ExportDefaultDeclaration=j;var Z=function(){function k(A,T,V){this.type=s.Syntax.ExportNamedDeclaration,this.declaration=A,this.specifiers=T,this.source=V}return k}();i.ExportNamedDeclaration=Z;var ht=function(){function k(A,T){this.type=s.Syntax.ExportSpecifier,this.exported=T,this.local=A}return k}();i.ExportSpecifier=ht;var he=function(){function k(A){this.type=s.Syntax.ExpressionStatement,this.expression=A}return k}();i.ExpressionStatement=he;var J=function(){function k(A,T,V){this.type=s.Syntax.ForInStatement,this.left=A,this.right=T,this.body=V,this.each=!1}return k}();i.ForInStatement=J;var ee=function(){function k(A,T,V){this.type=s.Syntax.ForOfStatement,this.left=A,this.right=T,this.body=V}return k}();i.ForOfStatement=ee;var ue=function(){function k(A,T,V,Ge){this.type=s.Syntax.ForStatement,this.init=A,this.test=T,this.update=V,this.body=Ge}return k}();i.ForStatement=ue;var xe=function(){function k(A,T,V,Ge){this.type=s.Syntax.FunctionDeclaration,this.id=A,this.params=T,this.body=V,this.generator=Ge,this.expression=!1,this.async=!1}return k}();i.FunctionDeclaration=xe;var Oe=function(){function k(A,T,V,Ge){this.type=s.Syntax.FunctionExpression,this.id=A,this.params=T,this.body=V,this.generator=Ge,this.expression=!1,this.async=!1}return k}();i.FunctionExpression=Oe;var lt=function(){function k(A){this.type=s.Syntax.Identifier,this.name=A}return k}();i.Identifier=lt;var Ci=function(){function k(A,T,V){this.type=s.Syntax.IfStatement,this.test=A,this.consequent=T,this.alternate=V}return k}();i.IfStatement=Ci;var Un=function(){function k(A,T){this.type=s.Syntax.ImportDeclaration,this.specifiers=A,this.source=T}return k}();i.ImportDeclaration=Un;var Dr=function(){function k(A){this.type=s.Syntax.ImportDefaultSpecifier,this.local=A}return k}();i.ImportDefaultSpecifier=Dr;var ad=function(){function k(A){this.type=s.Syntax.ImportNamespaceSpecifier,this.local=A}return k}();i.ImportNamespaceSpecifier=ad;var hd=function(){function k(A,T){this.type=s.Syntax.ImportSpecifier,this.local=A,this.imported=T}return k}();i.ImportSpecifier=hd;var ud=function(){function k(A,T){this.type=s.Syntax.LabeledStatement,this.label=A,this.body=T}return k}();i.LabeledStatement=ud;var cd=function(){function k(A,T){this.type=s.Syntax.Literal,this.value=A,this.raw=T}return k}();i.Literal=cd;var fd=function(){function k(A,T){this.type=s.Syntax.MetaProperty,this.meta=A,this.property=T}return k}();i.MetaProperty=fd;var dd=function(){function k(A,T,V,Ge,br){this.type=s.Syntax.MethodDefinition,this.key=A,this.computed=T,this.value=V,this.kind=Ge,this.static=br}return k}();i.MethodDefinition=dd;var pd=function(){function k(A){this.type=s.Syntax.Program,this.body=A,this.sourceType="module"}return k}();i.Module=pd;var md=function(){function k(A,T){this.type=s.Syntax.NewExpression,this.callee=A,this.arguments=T}return k}();i.NewExpression=md;var gd=function(){function k(A){this.type=s.Syntax.ObjectExpression,this.properties=A}return k}();i.ObjectExpression=gd;var yd=function(){function k(A){this.type=s.Syntax.ObjectPattern,this.properties=A}return k}();i.ObjectPattern=yd;var xd=function(){function k(A,T,V,Ge,br,Wd){this.type=s.Syntax.Property,this.key=T,this.computed=V,this.value=Ge,this.kind=A,this.method=br,this.shorthand=Wd}return k}();i.Property=xd;var vd=function(){function k(A,T,V,Ge){this.type=s.Syntax.Literal,this.value=A,this.raw=T,this.regex={pattern:V,flags:Ge}}return k}();i.RegexLiteral=vd;var wd=function(){function k(A){this.type=s.Syntax.RestElement,this.argument=A}return k}();i.RestElement=wd;var Sd=function(){function k(A){this.type=s.Syntax.ReturnStatement,this.argument=A}return k}();i.ReturnStatement=Sd;var Dd=function(){function k(A){this.type=s.Syntax.Program,this.body=A,this.sourceType="script"}return k}();i.Script=Dd;var bd=function(){function k(A){this.type=s.Syntax.SequenceExpression,this.expressions=A}return k}();i.SequenceExpression=bd;var kd=function(){function k(A){this.type=s.Syntax.SpreadElement,this.argument=A}return k}();i.SpreadElement=kd;var Ad=function(){function k(A,T){this.type=s.Syntax.MemberExpression,this.computed=!1,this.object=A,this.property=T}return k}();i.StaticMemberExpression=Ad;var Cd=function(){function k(){this.type=s.Syntax.Super}return k}();i.Super=Cd;var Ed=function(){function k(A,T){this.type=s.Syntax.SwitchCase,this.test=A,this.consequent=T}return k}();i.SwitchCase=Ed;var Fd=function(){function k(A,T){this.type=s.Syntax.SwitchStatement,this.discriminant=A,this.cases=T}return k}();i.SwitchStatement=Fd;var Bd=function(){function k(A,T){this.type=s.Syntax.TaggedTemplateExpression,this.tag=A,this.quasi=T}return k}();i.TaggedTemplateExpression=Bd;var Td=function(){function k(A,T){this.type=s.Syntax.TemplateElement,this.value=A,this.tail=T}return k}();i.TemplateElement=Td;var Md=function(){function k(A,T){this.type=s.Syntax.TemplateLiteral,this.quasis=A,this.expressions=T}return k}();i.TemplateLiteral=Md;var Od=function(){function k(){this.type=s.Syntax.ThisExpression}return k}();i.ThisExpression=Od;var Pd=function(){function k(A){this.type=s.Syntax.ThrowStatement,this.argument=A}return k}();i.ThrowStatement=Pd;var Nd=function(){function k(A,T,V){this.type=s.Syntax.TryStatement,this.block=A,this.handler=T,this.finalizer=V}return k}();i.TryStatement=Nd;var Id=function(){function k(A,T){this.type=s.Syntax.UnaryExpression,this.operator=A,this.argument=T,this.prefix=!0}return k}();i.UnaryExpression=Id;var Ld=function(){function k(A,T,V){this.type=s.Syntax.UpdateExpression,this.operator=A,this.argument=T,this.prefix=V}return k}();i.UpdateExpression=Ld;var Rd=function(){function k(A,T){this.type=s.Syntax.VariableDeclaration,this.declarations=A,this.kind=T}return k}();i.VariableDeclaration=Rd;var zd=function(){function k(A,T){this.type=s.Syntax.VariableDeclarator,this.id=A,this.init=T}return k}();i.VariableDeclarator=zd;var Vd=function(){function k(A,T){this.type=s.Syntax.WhileStatement,this.test=A,this.body=T}return k}();i.WhileStatement=Vd;var Hd=function(){function k(A,T){this.type=s.Syntax.WithStatement,this.object=A,this.body=T}return k}();i.WithStatement=Hd;var $d=function(){function k(A,T){this.type=s.Syntax.YieldExpression,this.argument=A,this.delegate=T}return k}();i.YieldExpression=$d},function(t,i,n){Object.defineProperty(i,"__esModule",{value:!0});var s=n(9),o=n(10),l=n(11),a=n(7),h=n(12),u=n(2),d=n(13),p="ArrowParameterPlaceHolder",g=function(){function y(c,f,m){f===void 0&&(f={}),this.config={range:typeof f.range=="boolean"&&f.range,loc:typeof f.loc=="boolean"&&f.loc,source:null,tokens:typeof f.tokens=="boolean"&&f.tokens,comment:typeof f.comment=="boolean"&&f.comment,tolerant:typeof f.tolerant=="boolean"&&f.tolerant},this.config.loc&&f.source&&f.source!==null&&(this.config.source=String(f.source)),this.delegate=m,this.errorHandler=new o.ErrorHandler,this.errorHandler.tolerant=this.config.tolerant,this.scanner=new h.Scanner(c,this.errorHandler),this.scanner.trackComment=this.config.comment,this.operatorPrecedence={")":0,";":0,",":0,"=":0,"]":0,"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":11,"/":11,"%":11},this.lookahead={type:2,value:"",lineNumber:this.scanner.lineNumber,lineStart:0,start:0,end:0},this.hasLineTerminator=!1,this.context={isModule:!1,await:!1,allowIn:!0,allowStrictDirective:!0,allowYield:!0,firstCoverInitializedNameError:null,isAssignmentTarget:!1,isBindingElement:!1,inFunctionBody:!1,inIteration:!1,inSwitch:!1,labelSet:{},strict:!1},this.tokens=[],this.startMarker={index:0,line:this.scanner.lineNumber,column:0},this.lastMarker={index:0,line:this.scanner.lineNumber,column:0},this.nextToken(),this.lastMarker={index:this.scanner.index,line:this.scanner.lineNumber,column:this.scanner.index-this.scanner.lineStart}}return y.prototype.throwError=function(c){var f=Array.prototype.slice.call(arguments,1),m=c.replace(/%(\d)/g,function(D,w){return s.assert(w0&&this.delegate)for(var f=0;f>="||c===">>>="||c==="&="||c==="^="||c==="|="},y.prototype.isolateCoverGrammar=function(c){var f=this.context.isBindingElement,m=this.context.isAssignmentTarget,x=this.context.firstCoverInitializedNameError;this.context.isBindingElement=!0,this.context.isAssignmentTarget=!0,this.context.firstCoverInitializedNameError=null;var v=c.call(this);return this.context.firstCoverInitializedNameError!==null&&this.throwUnexpectedToken(this.context.firstCoverInitializedNameError),this.context.isBindingElement=f,this.context.isAssignmentTarget=m,this.context.firstCoverInitializedNameError=x,v},y.prototype.inheritCoverGrammar=function(c){var f=this.context.isBindingElement,m=this.context.isAssignmentTarget,x=this.context.firstCoverInitializedNameError;this.context.isBindingElement=!0,this.context.isAssignmentTarget=!0,this.context.firstCoverInitializedNameError=null;var v=c.call(this);return this.context.isBindingElement=this.context.isBindingElement&&f,this.context.isAssignmentTarget=this.context.isAssignmentTarget&&m,this.context.firstCoverInitializedNameError=x||this.context.firstCoverInitializedNameError,v},y.prototype.consumeSemicolon=function(){this.match(";")?this.nextToken():this.hasLineTerminator||(this.lookahead.type!==2&&!this.match("}")&&this.throwUnexpectedToken(this.lookahead),this.lastMarker.index=this.startMarker.index,this.lastMarker.line=this.startMarker.line,this.lastMarker.column=this.startMarker.column)},y.prototype.parsePrimaryExpression=function(){var c=this.createNode(),f,m,x;switch(this.lookahead.type){case 3:(this.context.isModule||this.context.await)&&this.lookahead.value==="await"&&this.tolerateUnexpectedToken(this.lookahead),f=this.matchAsyncFunction()?this.parseFunctionExpression():this.finalize(c,new a.Identifier(this.nextToken().value));break;case 6:case 8:this.context.strict&&this.lookahead.octal&&this.tolerateUnexpectedToken(this.lookahead,l.Messages.StrictOctalLiteral),this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1,m=this.nextToken(),x=this.getTokenRaw(m),f=this.finalize(c,new a.Literal(m.value,x));break;case 1:this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1,m=this.nextToken(),x=this.getTokenRaw(m),f=this.finalize(c,new a.Literal(m.value==="true",x));break;case 5:this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1,m=this.nextToken(),x=this.getTokenRaw(m),f=this.finalize(c,new a.Literal(null,x));break;case 10:f=this.parseTemplateLiteral();break;case 7:switch(this.lookahead.value){case"(":this.context.isBindingElement=!1,f=this.inheritCoverGrammar(this.parseGroupExpression);break;case"[":f=this.inheritCoverGrammar(this.parseArrayInitializer);break;case"{":f=this.inheritCoverGrammar(this.parseObjectInitializer);break;case"/":case"/=":this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1,this.scanner.index=this.startMarker.index,m=this.nextRegexToken(),x=this.getTokenRaw(m),f=this.finalize(c,new a.RegexLiteral(m.regex,x,m.pattern,m.flags));break;default:f=this.throwUnexpectedToken(this.nextToken())}break;case 4:!this.context.strict&&this.context.allowYield&&this.matchKeyword("yield")?f=this.parseIdentifierName():!this.context.strict&&this.matchKeyword("let")?f=this.finalize(c,new a.Identifier(this.nextToken().value)):(this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1,this.matchKeyword("function")?f=this.parseFunctionExpression():this.matchKeyword("this")?(this.nextToken(),f=this.finalize(c,new a.ThisExpression)):this.matchKeyword("class")?f=this.parseClassExpression():f=this.throwUnexpectedToken(this.nextToken()));break;default:f=this.throwUnexpectedToken(this.nextToken())}return f},y.prototype.parseSpreadElement=function(){var c=this.createNode();this.expect("...");var f=this.inheritCoverGrammar(this.parseAssignmentExpression);return this.finalize(c,new a.SpreadElement(f))},y.prototype.parseArrayInitializer=function(){var c=this.createNode(),f=[];for(this.expect("[");!this.match("]");)if(this.match(","))this.nextToken(),f.push(null);else if(this.match("...")){var m=this.parseSpreadElement();this.match("]")||(this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1,this.expect(",")),f.push(m)}else f.push(this.inheritCoverGrammar(this.parseAssignmentExpression)),this.match("]")||this.expect(",");return this.expect("]"),this.finalize(c,new a.ArrayExpression(f))},y.prototype.parsePropertyMethod=function(c){this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1;var f=this.context.strict,m=this.context.allowStrictDirective;this.context.allowStrictDirective=c.simple;var x=this.isolateCoverGrammar(this.parseFunctionSourceElements);return this.context.strict&&c.firstRestricted&&this.tolerateUnexpectedToken(c.firstRestricted,c.message),this.context.strict&&c.stricted&&this.tolerateUnexpectedToken(c.stricted,c.message),this.context.strict=f,this.context.allowStrictDirective=m,x},y.prototype.parsePropertyMethodFunction=function(){var c=!1,f=this.createNode(),m=this.context.allowYield;this.context.allowYield=!0;var x=this.parseFormalParameters(),v=this.parsePropertyMethod(x);return this.context.allowYield=m,this.finalize(f,new a.FunctionExpression(null,x.params,v,c))},y.prototype.parsePropertyMethodAsyncFunction=function(){var c=this.createNode(),f=this.context.allowYield,m=this.context.await;this.context.allowYield=!1,this.context.await=!0;var x=this.parseFormalParameters(),v=this.parsePropertyMethod(x);return this.context.allowYield=f,this.context.await=m,this.finalize(c,new a.AsyncFunctionExpression(null,x.params,v))},y.prototype.parseObjectPropertyKey=function(){var c=this.createNode(),f=this.nextToken(),m;switch(f.type){case 8:case 6:this.context.strict&&f.octal&&this.tolerateUnexpectedToken(f,l.Messages.StrictOctalLiteral);var x=this.getTokenRaw(f);m=this.finalize(c,new a.Literal(f.value,x));break;case 3:case 1:case 5:case 4:m=this.finalize(c,new a.Identifier(f.value));break;case 7:f.value==="["?(m=this.isolateCoverGrammar(this.parseAssignmentExpression),this.expect("]")):m=this.throwUnexpectedToken(f);break;default:m=this.throwUnexpectedToken(f)}return m},y.prototype.isPropertyKey=function(c,f){return c.type===u.Syntax.Identifier&&c.name===f||c.type===u.Syntax.Literal&&c.value===f},y.prototype.parseObjectProperty=function(c){var f=this.createNode(),m=this.lookahead,x,v=null,S=null,D=!1,w=!1,b=!1,E=!1;if(m.type===3){var C=m.value;this.nextToken(),D=this.match("["),E=!this.hasLineTerminator&&C==="async"&&!this.match(":")&&!this.match("(")&&!this.match("*")&&!this.match(","),v=E?this.parseObjectPropertyKey():this.finalize(f,new a.Identifier(C))}else this.match("*")?this.nextToken():(D=this.match("["),v=this.parseObjectPropertyKey());var F=this.qualifiedPropertyName(this.lookahead);if(m.type===3&&!E&&m.value==="get"&&F)x="get",D=this.match("["),v=this.parseObjectPropertyKey(),this.context.allowYield=!1,S=this.parseGetterMethod();else if(m.type===3&&!E&&m.value==="set"&&F)x="set",D=this.match("["),v=this.parseObjectPropertyKey(),S=this.parseSetterMethod();else if(m.type===7&&m.value==="*"&&F)x="init",D=this.match("["),v=this.parseObjectPropertyKey(),S=this.parseGeneratorMethod(),w=!0;else if(v||this.throwUnexpectedToken(this.lookahead),x="init",this.match(":")&&!E)!D&&this.isPropertyKey(v,"__proto__")&&(c.value&&this.tolerateError(l.Messages.DuplicateProtoProperty),c.value=!0),this.nextToken(),S=this.inheritCoverGrammar(this.parseAssignmentExpression);else if(this.match("("))S=E?this.parsePropertyMethodAsyncFunction():this.parsePropertyMethodFunction(),w=!0;else if(m.type===3){var C=this.finalize(f,new a.Identifier(m.value));if(this.match("=")){this.context.firstCoverInitializedNameError=this.lookahead,this.nextToken(),b=!0;var B=this.isolateCoverGrammar(this.parseAssignmentExpression);S=this.finalize(f,new a.AssignmentPattern(C,B))}else b=!0,S=C}else this.throwUnexpectedToken(this.nextToken());return this.finalize(f,new a.Property(x,v,D,S,w,b))},y.prototype.parseObjectInitializer=function(){var c=this.createNode();this.expect("{");for(var f=[],m={value:!1};!this.match("}");)f.push(this.parseObjectProperty(m)),this.match("}")||this.expectCommaSeparator();return this.expect("}"),this.finalize(c,new a.ObjectExpression(f))},y.prototype.parseTemplateHead=function(){s.assert(this.lookahead.head,"Template literal must start with a template head");var c=this.createNode(),f=this.nextToken(),m=f.value,x=f.cooked;return this.finalize(c,new a.TemplateElement({raw:m,cooked:x},f.tail))},y.prototype.parseTemplateElement=function(){this.lookahead.type!==10&&this.throwUnexpectedToken();var c=this.createNode(),f=this.nextToken(),m=f.value,x=f.cooked;return this.finalize(c,new a.TemplateElement({raw:m,cooked:x},f.tail))},y.prototype.parseTemplateLiteral=function(){var c=this.createNode(),f=[],m=[],x=this.parseTemplateHead();for(m.push(x);!x.tail;)f.push(this.parseExpression()),x=this.parseTemplateElement(),m.push(x);return this.finalize(c,new a.TemplateLiteral(m,f))},y.prototype.reinterpretExpressionAsPattern=function(c){switch(c.type){case u.Syntax.Identifier:case u.Syntax.MemberExpression:case u.Syntax.RestElement:case u.Syntax.AssignmentPattern:break;case u.Syntax.SpreadElement:c.type=u.Syntax.RestElement,this.reinterpretExpressionAsPattern(c.argument);break;case u.Syntax.ArrayExpression:c.type=u.Syntax.ArrayPattern;for(var f=0;f")||this.expect("=>"),c={type:p,params:[],async:!1};else{var f=this.lookahead,m=[];if(this.match("..."))c=this.parseRestElement(m),this.expect(")"),this.match("=>")||this.expect("=>"),c={type:p,params:[c],async:!1};else{var x=!1;if(this.context.isBindingElement=!0,c=this.inheritCoverGrammar(this.parseAssignmentExpression),this.match(",")){var v=[];for(this.context.isAssignmentTarget=!1,v.push(c);this.lookahead.type!==2&&this.match(",");){if(this.nextToken(),this.match(")")){this.nextToken();for(var S=0;S")||this.expect("=>"),this.context.isBindingElement=!1;for(var S=0;S")&&(c.type===u.Syntax.Identifier&&c.name==="yield"&&(x=!0,c={type:p,params:[c],async:!1}),!x)){if(this.context.isBindingElement||this.throwUnexpectedToken(this.lookahead),c.type===u.Syntax.SequenceExpression)for(var S=0;S")){for(var w=0;w0){this.nextToken(),this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1;for(var v=[c,this.lookahead],S=f,D=this.isolateCoverGrammar(this.parseExponentiationExpression),w=[S,m.value,D],b=[x];x=this.binaryPrecedence(this.lookahead),!(x<=0);){for(;w.length>2&&x<=b[b.length-1];){D=w.pop();var E=w.pop();b.pop(),S=w.pop(),v.pop();var C=this.startNode(v[v.length-1]);w.push(this.finalize(C,new a.BinaryExpression(E,S,D)))}w.push(this.nextToken().value),b.push(x),v.push(this.lookahead),w.push(this.isolateCoverGrammar(this.parseExponentiationExpression))}var F=w.length-1;f=w[F];for(var B=v.pop();F>1;){var I=v.pop(),R=B&&B.lineStart,C=this.startNode(I,R),E=w[F-1];f=this.finalize(C,new a.BinaryExpression(E,w[F-2],f)),F-=2,B=I}}return f},y.prototype.parseConditionalExpression=function(){var c=this.lookahead,f=this.inheritCoverGrammar(this.parseBinaryExpression);if(this.match("?")){this.nextToken();var m=this.context.allowIn;this.context.allowIn=!0;var x=this.isolateCoverGrammar(this.parseAssignmentExpression);this.context.allowIn=m,this.expect(":");var v=this.isolateCoverGrammar(this.parseAssignmentExpression);f=this.finalize(this.startNode(c),new a.ConditionalExpression(f,x,v)),this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1}return f},y.prototype.checkPatternParam=function(c,f){switch(f.type){case u.Syntax.Identifier:this.validateParam(c,f,f.name);break;case u.Syntax.RestElement:this.checkPatternParam(c,f.argument);break;case u.Syntax.AssignmentPattern:this.checkPatternParam(c,f.left);break;case u.Syntax.ArrayPattern:for(var m=0;m")){this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1;var v=c.async,S=this.reinterpretAsCoverFormalsList(c);if(S){this.hasLineTerminator&&this.tolerateUnexpectedToken(this.lookahead),this.context.firstCoverInitializedNameError=null;var D=this.context.strict,w=this.context.allowStrictDirective;this.context.allowStrictDirective=S.simple;var b=this.context.allowYield,E=this.context.await;this.context.allowYield=!0,this.context.await=v;var C=this.startNode(f);this.expect("=>");var F=void 0;if(this.match("{")){var B=this.context.allowIn;this.context.allowIn=!0,F=this.parseFunctionSourceElements(),this.context.allowIn=B}else F=this.isolateCoverGrammar(this.parseAssignmentExpression);var I=F.type!==u.Syntax.BlockStatement;this.context.strict&&S.firstRestricted&&this.throwUnexpectedToken(S.firstRestricted,S.message),this.context.strict&&S.stricted&&this.tolerateUnexpectedToken(S.stricted,S.message),c=v?this.finalize(C,new a.AsyncArrowFunctionExpression(S.params,F,I)):this.finalize(C,new a.ArrowFunctionExpression(S.params,F,I)),this.context.strict=D,this.context.allowStrictDirective=w,this.context.allowYield=b,this.context.await=E}}else if(this.matchAssign()){if(this.context.isAssignmentTarget||this.tolerateError(l.Messages.InvalidLHSInAssignment),this.context.strict&&c.type===u.Syntax.Identifier){var R=c;this.scanner.isRestrictedWord(R.name)&&this.tolerateUnexpectedToken(m,l.Messages.StrictLHSAssignment),this.scanner.isStrictModeReservedWord(R.name)&&this.tolerateUnexpectedToken(m,l.Messages.StrictReservedWord)}this.match("=")?this.reinterpretExpressionAsPattern(c):(this.context.isAssignmentTarget=!1,this.context.isBindingElement=!1),m=this.nextToken();var X=m.value,j=this.isolateCoverGrammar(this.parseAssignmentExpression);c=this.finalize(this.startNode(f),new a.AssignmentExpression(X,c,j)),this.context.firstCoverInitializedNameError=null}}return c},y.prototype.parseExpression=function(){var c=this.lookahead,f=this.isolateCoverGrammar(this.parseAssignmentExpression);if(this.match(",")){var m=[];for(m.push(f);this.lookahead.type!==2&&this.match(",");)this.nextToken(),m.push(this.isolateCoverGrammar(this.parseAssignmentExpression));f=this.finalize(this.startNode(c),new a.SequenceExpression(m))}return f},y.prototype.parseStatementListItem=function(){var c;if(this.context.isAssignmentTarget=!0,this.context.isBindingElement=!0,this.lookahead.type===4)switch(this.lookahead.value){case"export":this.context.isModule||this.tolerateUnexpectedToken(this.lookahead,l.Messages.IllegalExportDeclaration),c=this.parseExportDeclaration();break;case"import":this.context.isModule||this.tolerateUnexpectedToken(this.lookahead,l.Messages.IllegalImportDeclaration),c=this.parseImportDeclaration();break;case"const":c=this.parseLexicalDeclaration({inFor:!1});break;case"function":c=this.parseFunctionDeclaration();break;case"class":c=this.parseClassDeclaration();break;case"let":c=this.isLexicalDeclaration()?this.parseLexicalDeclaration({inFor:!1}):this.parseStatement();break;default:c=this.parseStatement();break}else c=this.parseStatement();return c},y.prototype.parseBlock=function(){var c=this.createNode();this.expect("{");for(var f=[];!this.match("}");)f.push(this.parseStatementListItem());return this.expect("}"),this.finalize(c,new a.BlockStatement(f))},y.prototype.parseLexicalBinding=function(c,f){var m=this.createNode(),x=[],v=this.parsePattern(x,c);this.context.strict&&v.type===u.Syntax.Identifier&&this.scanner.isRestrictedWord(v.name)&&this.tolerateError(l.Messages.StrictVarName);var S=null;return c==="const"?!this.matchKeyword("in")&&!this.matchContextualKeyword("of")&&(this.match("=")?(this.nextToken(),S=this.isolateCoverGrammar(this.parseAssignmentExpression)):this.throwError(l.Messages.DeclarationMissingInitializer,"const")):(!f.inFor&&v.type!==u.Syntax.Identifier||this.match("="))&&(this.expect("="),S=this.isolateCoverGrammar(this.parseAssignmentExpression)),this.finalize(m,new a.VariableDeclarator(v,S))},y.prototype.parseBindingList=function(c,f){for(var m=[this.parseLexicalBinding(c,f)];this.match(",");)this.nextToken(),m.push(this.parseLexicalBinding(c,f));return m},y.prototype.isLexicalDeclaration=function(){var c=this.scanner.saveState();this.scanner.scanComments();var f=this.scanner.lex();return this.scanner.restoreState(c),f.type===3||f.type===7&&f.value==="["||f.type===7&&f.value==="{"||f.type===4&&f.value==="let"||f.type===4&&f.value==="yield"},y.prototype.parseLexicalDeclaration=function(c){var f=this.createNode(),m=this.nextToken().value;s.assert(m==="let"||m==="const","Lexical declaration must be either let or const");var x=this.parseBindingList(m,c);return this.consumeSemicolon(),this.finalize(f,new a.VariableDeclaration(x,m))},y.prototype.parseBindingRestElement=function(c,f){var m=this.createNode();this.expect("...");var x=this.parsePattern(c,f);return this.finalize(m,new a.RestElement(x))},y.prototype.parseArrayPattern=function(c,f){var m=this.createNode();this.expect("[");for(var x=[];!this.match("]");)if(this.match(","))this.nextToken(),x.push(null);else{if(this.match("...")){x.push(this.parseBindingRestElement(c,f));break}else x.push(this.parsePatternWithDefault(c,f));this.match("]")||this.expect(",")}return this.expect("]"),this.finalize(m,new a.ArrayPattern(x))},y.prototype.parsePropertyPattern=function(c,f){var m=this.createNode(),x=!1,v=!1,S=!1,D,w;if(this.lookahead.type===3){var b=this.lookahead;D=this.parseVariableIdentifier();var E=this.finalize(m,new a.Identifier(b.value));if(this.match("=")){c.push(b),v=!0,this.nextToken();var C=this.parseAssignmentExpression();w=this.finalize(this.startNode(b),new a.AssignmentPattern(E,C))}else this.match(":")?(this.expect(":"),w=this.parsePatternWithDefault(c,f)):(c.push(b),v=!0,w=E)}else x=this.match("["),D=this.parseObjectPropertyKey(),this.expect(":"),w=this.parsePatternWithDefault(c,f);return this.finalize(m,new a.Property("init",D,x,w,S,v))},y.prototype.parseObjectPattern=function(c,f){var m=this.createNode(),x=[];for(this.expect("{");!this.match("}");)x.push(this.parsePropertyPattern(c,f)),this.match("}")||this.expect(",");return this.expect("}"),this.finalize(m,new a.ObjectPattern(x))},y.prototype.parsePattern=function(c,f){var m;return this.match("[")?m=this.parseArrayPattern(c,f):this.match("{")?m=this.parseObjectPattern(c,f):(this.matchKeyword("let")&&(f==="const"||f==="let")&&this.tolerateUnexpectedToken(this.lookahead,l.Messages.LetInLexicalBinding),c.push(this.lookahead),m=this.parseVariableIdentifier(f)),m},y.prototype.parsePatternWithDefault=function(c,f){var m=this.lookahead,x=this.parsePattern(c,f);if(this.match("=")){this.nextToken();var v=this.context.allowYield;this.context.allowYield=!0;var S=this.isolateCoverGrammar(this.parseAssignmentExpression);this.context.allowYield=v,x=this.finalize(this.startNode(m),new a.AssignmentPattern(x,S))}return x},y.prototype.parseVariableIdentifier=function(c){var f=this.createNode(),m=this.nextToken();return m.type===4&&m.value==="yield"?this.context.strict?this.tolerateUnexpectedToken(m,l.Messages.StrictReservedWord):this.context.allowYield||this.throwUnexpectedToken(m):m.type!==3?this.context.strict&&m.type===4&&this.scanner.isStrictModeReservedWord(m.value)?this.tolerateUnexpectedToken(m,l.Messages.StrictReservedWord):(this.context.strict||m.value!=="let"||c!=="var")&&this.throwUnexpectedToken(m):(this.context.isModule||this.context.await)&&m.type===3&&m.value==="await"&&this.tolerateUnexpectedToken(m),this.finalize(f,new a.Identifier(m.value))},y.prototype.parseVariableDeclaration=function(c){var f=this.createNode(),m=[],x=this.parsePattern(m,"var");this.context.strict&&x.type===u.Syntax.Identifier&&this.scanner.isRestrictedWord(x.name)&&this.tolerateError(l.Messages.StrictVarName);var v=null;return this.match("=")?(this.nextToken(),v=this.isolateCoverGrammar(this.parseAssignmentExpression)):x.type!==u.Syntax.Identifier&&!c.inFor&&this.expect("="),this.finalize(f,new a.VariableDeclarator(x,v))},y.prototype.parseVariableDeclarationList=function(c){var f={inFor:c.inFor},m=[];for(m.push(this.parseVariableDeclaration(f));this.match(",");)this.nextToken(),m.push(this.parseVariableDeclaration(f));return m},y.prototype.parseVariableStatement=function(){var c=this.createNode();this.expectKeyword("var");var f=this.parseVariableDeclarationList({inFor:!1});return this.consumeSemicolon(),this.finalize(c,new a.VariableDeclaration(f,"var"))},y.prototype.parseEmptyStatement=function(){var c=this.createNode();return this.expect(";"),this.finalize(c,new a.EmptyStatement)},y.prototype.parseExpressionStatement=function(){var c=this.createNode(),f=this.parseExpression();return this.consumeSemicolon(),this.finalize(c,new a.ExpressionStatement(f))},y.prototype.parseIfClause=function(){return this.context.strict&&this.matchKeyword("function")&&this.tolerateError(l.Messages.StrictFunction),this.parseStatement()},y.prototype.parseIfStatement=function(){var c=this.createNode(),f,m=null;this.expectKeyword("if"),this.expect("(");var x=this.parseExpression();return!this.match(")")&&this.config.tolerant?(this.tolerateUnexpectedToken(this.nextToken()),f=this.finalize(this.createNode(),new a.EmptyStatement)):(this.expect(")"),f=this.parseIfClause(),this.matchKeyword("else")&&(this.nextToken(),m=this.parseIfClause())),this.finalize(c,new a.IfStatement(x,f,m))},y.prototype.parseDoWhileStatement=function(){var c=this.createNode();this.expectKeyword("do");var f=this.context.inIteration;this.context.inIteration=!0;var m=this.parseStatement();this.context.inIteration=f,this.expectKeyword("while"),this.expect("(");var x=this.parseExpression();return!this.match(")")&&this.config.tolerant?this.tolerateUnexpectedToken(this.nextToken()):(this.expect(")"),this.match(";")&&this.nextToken()),this.finalize(c,new a.DoWhileStatement(m,x))},y.prototype.parseWhileStatement=function(){var c=this.createNode(),f;this.expectKeyword("while"),this.expect("(");var m=this.parseExpression();if(!this.match(")")&&this.config.tolerant)this.tolerateUnexpectedToken(this.nextToken()),f=this.finalize(this.createNode(),new a.EmptyStatement);else{this.expect(")");var x=this.context.inIteration;this.context.inIteration=!0,f=this.parseStatement(),this.context.inIteration=x}return this.finalize(c,new a.WhileStatement(m,f))},y.prototype.parseForStatement=function(){var c=null,f=null,m=null,x=!0,v,S,D=this.createNode();if(this.expectKeyword("for"),this.expect("("),this.match(";"))this.nextToken();else if(this.matchKeyword("var")){c=this.createNode(),this.nextToken();var w=this.context.allowIn;this.context.allowIn=!1;var b=this.parseVariableDeclarationList({inFor:!0});if(this.context.allowIn=w,b.length===1&&this.matchKeyword("in")){var E=b[0];E.init&&(E.id.type===u.Syntax.ArrayPattern||E.id.type===u.Syntax.ObjectPattern||this.context.strict)&&this.tolerateError(l.Messages.ForInOfLoopInitializer,"for-in"),c=this.finalize(c,new a.VariableDeclaration(b,"var")),this.nextToken(),v=c,S=this.parseExpression(),c=null}else b.length===1&&b[0].init===null&&this.matchContextualKeyword("of")?(c=this.finalize(c,new a.VariableDeclaration(b,"var")),this.nextToken(),v=c,S=this.parseAssignmentExpression(),c=null,x=!1):(c=this.finalize(c,new a.VariableDeclaration(b,"var")),this.expect(";"))}else if(this.matchKeyword("const")||this.matchKeyword("let")){c=this.createNode();var C=this.nextToken().value;if(!this.context.strict&&this.lookahead.value==="in")c=this.finalize(c,new a.Identifier(C)),this.nextToken(),v=c,S=this.parseExpression(),c=null;else{var w=this.context.allowIn;this.context.allowIn=!1;var b=this.parseBindingList(C,{inFor:!0});this.context.allowIn=w,b.length===1&&b[0].init===null&&this.matchKeyword("in")?(c=this.finalize(c,new a.VariableDeclaration(b,C)),this.nextToken(),v=c,S=this.parseExpression(),c=null):b.length===1&&b[0].init===null&&this.matchContextualKeyword("of")?(c=this.finalize(c,new a.VariableDeclaration(b,C)),this.nextToken(),v=c,S=this.parseAssignmentExpression(),c=null,x=!1):(this.consumeSemicolon(),c=this.finalize(c,new a.VariableDeclaration(b,C)))}}else{var F=this.lookahead,w=this.context.allowIn;if(this.context.allowIn=!1,c=this.inheritCoverGrammar(this.parseAssignmentExpression),this.context.allowIn=w,this.matchKeyword("in"))(!this.context.isAssignmentTarget||c.type===u.Syntax.AssignmentExpression)&&this.tolerateError(l.Messages.InvalidLHSInForIn),this.nextToken(),this.reinterpretExpressionAsPattern(c),v=c,S=this.parseExpression(),c=null;else if(this.matchContextualKeyword("of"))(!this.context.isAssignmentTarget||c.type===u.Syntax.AssignmentExpression)&&this.tolerateError(l.Messages.InvalidLHSInForLoop),this.nextToken(),this.reinterpretExpressionAsPattern(c),v=c,S=this.parseAssignmentExpression(),c=null,x=!1;else{if(this.match(",")){for(var B=[c];this.match(",");)this.nextToken(),B.push(this.isolateCoverGrammar(this.parseAssignmentExpression));c=this.finalize(this.startNode(F),new a.SequenceExpression(B))}this.expect(";")}}typeof v>"u"&&(this.match(";")||(f=this.parseExpression()),this.expect(";"),this.match(")")||(m=this.parseExpression()));var I;if(!this.match(")")&&this.config.tolerant)this.tolerateUnexpectedToken(this.nextToken()),I=this.finalize(this.createNode(),new a.EmptyStatement);else{this.expect(")");var R=this.context.inIteration;this.context.inIteration=!0,I=this.isolateCoverGrammar(this.parseStatement),this.context.inIteration=R}return typeof v>"u"?this.finalize(D,new a.ForStatement(c,f,m,I)):x?this.finalize(D,new a.ForInStatement(v,S,I)):this.finalize(D,new a.ForOfStatement(v,S,I))},y.prototype.parseContinueStatement=function(){var c=this.createNode();this.expectKeyword("continue");var f=null;if(this.lookahead.type===3&&!this.hasLineTerminator){var m=this.parseVariableIdentifier();f=m;var x="$"+m.name;Object.prototype.hasOwnProperty.call(this.context.labelSet,x)||this.throwError(l.Messages.UnknownLabel,m.name)}return this.consumeSemicolon(),f===null&&!this.context.inIteration&&this.throwError(l.Messages.IllegalContinue),this.finalize(c,new a.ContinueStatement(f))},y.prototype.parseBreakStatement=function(){var c=this.createNode();this.expectKeyword("break");var f=null;if(this.lookahead.type===3&&!this.hasLineTerminator){var m=this.parseVariableIdentifier(),x="$"+m.name;Object.prototype.hasOwnProperty.call(this.context.labelSet,x)||this.throwError(l.Messages.UnknownLabel,m.name),f=m}return this.consumeSemicolon(),f===null&&!this.context.inIteration&&!this.context.inSwitch&&this.throwError(l.Messages.IllegalBreak),this.finalize(c,new a.BreakStatement(f))},y.prototype.parseReturnStatement=function(){this.context.inFunctionBody||this.tolerateError(l.Messages.IllegalReturn);var c=this.createNode();this.expectKeyword("return");var f=!this.match(";")&&!this.match("}")&&!this.hasLineTerminator&&this.lookahead.type!==2||this.lookahead.type===8||this.lookahead.type===10,m=f?this.parseExpression():null;return this.consumeSemicolon(),this.finalize(c,new a.ReturnStatement(m))},y.prototype.parseWithStatement=function(){this.context.strict&&this.tolerateError(l.Messages.StrictModeWith);var c=this.createNode(),f;this.expectKeyword("with"),this.expect("(");var m=this.parseExpression();return!this.match(")")&&this.config.tolerant?(this.tolerateUnexpectedToken(this.nextToken()),f=this.finalize(this.createNode(),new a.EmptyStatement)):(this.expect(")"),f=this.parseStatement()),this.finalize(c,new a.WithStatement(m,f))},y.prototype.parseSwitchCase=function(){var c=this.createNode(),f;this.matchKeyword("default")?(this.nextToken(),f=null):(this.expectKeyword("case"),f=this.parseExpression()),this.expect(":");for(var m=[];!(this.match("}")||this.matchKeyword("default")||this.matchKeyword("case"));)m.push(this.parseStatementListItem());return this.finalize(c,new a.SwitchCase(f,m))},y.prototype.parseSwitchStatement=function(){var c=this.createNode();this.expectKeyword("switch"),this.expect("(");var f=this.parseExpression();this.expect(")");var m=this.context.inSwitch;this.context.inSwitch=!0;var x=[],v=!1;for(this.expect("{");!this.match("}");){var S=this.parseSwitchCase();S.test===null&&(v&&this.throwError(l.Messages.MultipleDefaultsInSwitch),v=!0),x.push(S)}return this.expect("}"),this.context.inSwitch=m,this.finalize(c,new a.SwitchStatement(f,x))},y.prototype.parseLabelledStatement=function(){var c=this.createNode(),f=this.parseExpression(),m;if(f.type===u.Syntax.Identifier&&this.match(":")){this.nextToken();var x=f,v="$"+x.name;Object.prototype.hasOwnProperty.call(this.context.labelSet,v)&&this.throwError(l.Messages.Redeclaration,"Label",x.name),this.context.labelSet[v]=!0;var S=void 0;if(this.matchKeyword("class"))this.tolerateUnexpectedToken(this.lookahead),S=this.parseClassDeclaration();else if(this.matchKeyword("function")){var D=this.lookahead,w=this.parseFunctionDeclaration();this.context.strict?this.tolerateUnexpectedToken(D,l.Messages.StrictFunction):w.generator&&this.tolerateUnexpectedToken(D,l.Messages.GeneratorInLegacyContext),S=w}else S=this.parseStatement();delete this.context.labelSet[v],m=new a.LabeledStatement(x,S)}else this.consumeSemicolon(),m=new a.ExpressionStatement(f);return this.finalize(c,m)},y.prototype.parseThrowStatement=function(){var c=this.createNode();this.expectKeyword("throw"),this.hasLineTerminator&&this.throwError(l.Messages.NewlineAfterThrow);var f=this.parseExpression();return this.consumeSemicolon(),this.finalize(c,new a.ThrowStatement(f))},y.prototype.parseCatchClause=function(){var c=this.createNode();this.expectKeyword("catch"),this.expect("("),this.match(")")&&this.throwUnexpectedToken(this.lookahead);for(var f=[],m=this.parsePattern(f),x={},v=0;v0&&this.tolerateError(l.Messages.BadGetterArity);var v=this.parsePropertyMethod(x);return this.context.allowYield=m,this.finalize(c,new a.FunctionExpression(null,x.params,v,f))},y.prototype.parseSetterMethod=function(){var c=this.createNode(),f=!1,m=this.context.allowYield;this.context.allowYield=!f;var x=this.parseFormalParameters();x.params.length!==1?this.tolerateError(l.Messages.BadSetterArity):x.params[0]instanceof a.RestElement&&this.tolerateError(l.Messages.BadSetterRestParameter);var v=this.parsePropertyMethod(x);return this.context.allowYield=m,this.finalize(c,new a.FunctionExpression(null,x.params,v,f))},y.prototype.parseGeneratorMethod=function(){var c=this.createNode(),f=!0,m=this.context.allowYield;this.context.allowYield=!0;var x=this.parseFormalParameters();this.context.allowYield=!1;var v=this.parsePropertyMethod(x);return this.context.allowYield=m,this.finalize(c,new a.FunctionExpression(null,x.params,v,f))},y.prototype.isStartOfExpression=function(){var c=!0,f=this.lookahead.value;switch(this.lookahead.type){case 7:c=f==="["||f==="("||f==="{"||f==="+"||f==="-"||f==="!"||f==="~"||f==="++"||f==="--"||f==="/"||f==="/=";break;case 4:c=f==="class"||f==="delete"||f==="function"||f==="let"||f==="new"||f==="super"||f==="this"||f==="typeof"||f==="void"||f==="yield";break}return c},y.prototype.parseYieldExpression=function(){var c=this.createNode();this.expectKeyword("yield");var f=null,m=!1;if(!this.hasLineTerminator){var x=this.context.allowYield;this.context.allowYield=!1,m=this.match("*"),m?(this.nextToken(),f=this.parseAssignmentExpression()):this.isStartOfExpression()&&(f=this.parseAssignmentExpression()),this.context.allowYield=x}return this.finalize(c,new a.YieldExpression(f,m))},y.prototype.parseClassElement=function(c){var f=this.lookahead,m=this.createNode(),x="",v=null,S=null,D=!1,w=!1,b=!1,E=!1;if(this.match("*"))this.nextToken();else{D=this.match("["),v=this.parseObjectPropertyKey();var C=v;if(C.name==="static"&&(this.qualifiedPropertyName(this.lookahead)||this.match("*"))&&(f=this.lookahead,b=!0,D=this.match("["),this.match("*")?this.nextToken():v=this.parseObjectPropertyKey()),f.type===3&&!this.hasLineTerminator&&f.value==="async"){var F=this.lookahead.value;F!==":"&&F!=="("&&F!=="*"&&(E=!0,f=this.lookahead,v=this.parseObjectPropertyKey(),f.type===3&&f.value==="constructor"&&this.tolerateUnexpectedToken(f,l.Messages.ConstructorIsAsync))}}var B=this.qualifiedPropertyName(this.lookahead);return f.type===3?f.value==="get"&&B?(x="get",D=this.match("["),v=this.parseObjectPropertyKey(),this.context.allowYield=!1,S=this.parseGetterMethod()):f.value==="set"&&B&&(x="set",D=this.match("["),v=this.parseObjectPropertyKey(),S=this.parseSetterMethod()):f.type===7&&f.value==="*"&&B&&(x="init",D=this.match("["),v=this.parseObjectPropertyKey(),S=this.parseGeneratorMethod(),w=!0),!x&&v&&this.match("(")&&(x="init",S=E?this.parsePropertyMethodAsyncFunction():this.parsePropertyMethodFunction(),w=!0),x||this.throwUnexpectedToken(this.lookahead),x==="init"&&(x="method"),D||(b&&this.isPropertyKey(v,"prototype")&&this.throwUnexpectedToken(f,l.Messages.StaticPrototype),!b&&this.isPropertyKey(v,"constructor")&&((x!=="method"||!w||S&&S.generator)&&this.throwUnexpectedToken(f,l.Messages.ConstructorSpecialMethod),c.value?this.throwUnexpectedToken(f,l.Messages.DuplicateConstructor):c.value=!0,x="constructor")),this.finalize(m,new a.MethodDefinition(v,D,S,x,b))},y.prototype.parseClassElementList=function(){var c=[],f={value:!1};for(this.expect("{");!this.match("}");)this.match(";")?this.nextToken():c.push(this.parseClassElement(f));return this.expect("}"),c},y.prototype.parseClassBody=function(){var c=this.createNode(),f=this.parseClassElementList();return this.finalize(c,new a.ClassBody(f))},y.prototype.parseClassDeclaration=function(c){var f=this.createNode(),m=this.context.strict;this.context.strict=!0,this.expectKeyword("class");var x=c&&this.lookahead.type!==3?null:this.parseVariableIdentifier(),v=null;this.matchKeyword("extends")&&(this.nextToken(),v=this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall));var S=this.parseClassBody();return this.context.strict=m,this.finalize(f,new a.ClassDeclaration(x,v,S))},y.prototype.parseClassExpression=function(){var c=this.createNode(),f=this.context.strict;this.context.strict=!0,this.expectKeyword("class");var m=this.lookahead.type===3?this.parseVariableIdentifier():null,x=null;this.matchKeyword("extends")&&(this.nextToken(),x=this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall));var v=this.parseClassBody();return this.context.strict=f,this.finalize(c,new a.ClassExpression(m,x,v))},y.prototype.parseModule=function(){this.context.strict=!0,this.context.isModule=!0,this.scanner.isModule=!0;for(var c=this.createNode(),f=this.parseDirectivePrologues();this.lookahead.type!==2;)f.push(this.parseStatementListItem());return this.finalize(c,new a.Module(f))},y.prototype.parseScript=function(){for(var c=this.createNode(),f=this.parseDirectivePrologues();this.lookahead.type!==2;)f.push(this.parseStatementListItem());return this.finalize(c,new a.Script(f))},y.prototype.parseModuleSpecifier=function(){var c=this.createNode();this.lookahead.type!==8&&this.throwError(l.Messages.InvalidModuleSpecifier);var f=this.nextToken(),m=this.getTokenRaw(f);return this.finalize(c,new a.Literal(f.value,m))},y.prototype.parseImportSpecifier=function(){var c=this.createNode(),f,m;return this.lookahead.type===3?(f=this.parseVariableIdentifier(),m=f,this.matchContextualKeyword("as")&&(this.nextToken(),m=this.parseVariableIdentifier())):(f=this.parseIdentifierName(),m=f,this.matchContextualKeyword("as")?(this.nextToken(),m=this.parseVariableIdentifier()):this.throwUnexpectedToken(this.nextToken())),this.finalize(c,new a.ImportSpecifier(m,f))},y.prototype.parseNamedImports=function(){this.expect("{");for(var c=[];!this.match("}");)c.push(this.parseImportSpecifier()),this.match("}")||this.expect(",");return this.expect("}"),c},y.prototype.parseImportDefaultSpecifier=function(){var c=this.createNode(),f=this.parseIdentifierName();return this.finalize(c,new a.ImportDefaultSpecifier(f))},y.prototype.parseImportNamespaceSpecifier=function(){var c=this.createNode();this.expect("*"),this.matchContextualKeyword("as")||this.throwError(l.Messages.NoAsAfterImportNamespace),this.nextToken();var f=this.parseIdentifierName();return this.finalize(c,new a.ImportNamespaceSpecifier(f))},y.prototype.parseImportDeclaration=function(){this.context.inFunctionBody&&this.throwError(l.Messages.IllegalImportDeclaration);var c=this.createNode();this.expectKeyword("import");var f,m=[];if(this.lookahead.type===8)f=this.parseModuleSpecifier();else{if(this.match("{")?m=m.concat(this.parseNamedImports()):this.match("*")?m.push(this.parseImportNamespaceSpecifier()):this.isIdentifierName(this.lookahead)&&!this.matchKeyword("default")?(m.push(this.parseImportDefaultSpecifier()),this.match(",")&&(this.nextToken(),this.match("*")?m.push(this.parseImportNamespaceSpecifier()):this.match("{")?m=m.concat(this.parseNamedImports()):this.throwUnexpectedToken(this.lookahead))):this.throwUnexpectedToken(this.nextToken()),!this.matchContextualKeyword("from")){var x=this.lookahead.value?l.Messages.UnexpectedToken:l.Messages.MissingFromClause;this.throwError(x,this.lookahead.value)}this.nextToken(),f=this.parseModuleSpecifier()}return this.consumeSemicolon(),this.finalize(c,new a.ImportDeclaration(m,f))},y.prototype.parseExportSpecifier=function(){var c=this.createNode(),f=this.parseIdentifierName(),m=f;return this.matchContextualKeyword("as")&&(this.nextToken(),m=this.parseIdentifierName()),this.finalize(c,new a.ExportSpecifier(f,m))},y.prototype.parseExportDeclaration=function(){this.context.inFunctionBody&&this.throwError(l.Messages.IllegalExportDeclaration);var c=this.createNode();this.expectKeyword("export");var f;if(this.matchKeyword("default"))if(this.nextToken(),this.matchKeyword("function")){var m=this.parseFunctionDeclaration(!0);f=this.finalize(c,new a.ExportDefaultDeclaration(m))}else if(this.matchKeyword("class")){var m=this.parseClassDeclaration(!0);f=this.finalize(c,new a.ExportDefaultDeclaration(m))}else if(this.matchContextualKeyword("async")){var m=this.matchAsyncFunction()?this.parseFunctionDeclaration(!0):this.parseAssignmentExpression();f=this.finalize(c,new a.ExportDefaultDeclaration(m))}else{this.matchContextualKeyword("from")&&this.throwError(l.Messages.UnexpectedToken,this.lookahead.value);var m=this.match("{")?this.parseObjectInitializer():this.match("[")?this.parseArrayInitializer():this.parseAssignmentExpression();this.consumeSemicolon(),f=this.finalize(c,new a.ExportDefaultDeclaration(m))}else if(this.match("*")){if(this.nextToken(),!this.matchContextualKeyword("from")){var x=this.lookahead.value?l.Messages.UnexpectedToken:l.Messages.MissingFromClause;this.throwError(x,this.lookahead.value)}this.nextToken();var v=this.parseModuleSpecifier();this.consumeSemicolon(),f=this.finalize(c,new a.ExportAllDeclaration(v))}else if(this.lookahead.type===4){var m=void 0;switch(this.lookahead.value){case"let":case"const":m=this.parseLexicalDeclaration({inFor:!1});break;case"var":case"class":case"function":m=this.parseStatementListItem();break;default:this.throwUnexpectedToken(this.lookahead)}f=this.finalize(c,new a.ExportNamedDeclaration(m,[],null))}else if(this.matchAsyncFunction()){var m=this.parseFunctionDeclaration();f=this.finalize(c,new a.ExportNamedDeclaration(m,[],null))}else{var S=[],D=null,w=!1;for(this.expect("{");!this.match("}");)w=w||this.matchKeyword("default"),S.push(this.parseExportSpecifier()),this.match("}")||this.expect(",");if(this.expect("}"),this.matchContextualKeyword("from"))this.nextToken(),D=this.parseModuleSpecifier(),this.consumeSemicolon();else if(w){var x=this.lookahead.value?l.Messages.UnexpectedToken:l.Messages.MissingFromClause;this.throwError(x,this.lookahead.value)}else this.consumeSemicolon();f=this.finalize(c,new a.ExportNamedDeclaration(null,S,D))}return f},y}();i.Parser=g},function(t,i){Object.defineProperty(i,"__esModule",{value:!0});function n(s,o){if(!s)throw new Error("ASSERT: "+o)}i.assert=n},function(t,i){Object.defineProperty(i,"__esModule",{value:!0});var n=function(){function s(){this.errors=[],this.tolerant=!1}return s.prototype.recordError=function(o){this.errors.push(o)},s.prototype.tolerate=function(o){if(this.tolerant)this.recordError(o);else throw o},s.prototype.constructError=function(o,l){var a=new Error(o);try{throw a}catch(h){Object.create&&Object.defineProperty&&(a=Object.create(h),Object.defineProperty(a,"column",{value:l}))}return a},s.prototype.createError=function(o,l,a,h){var u="Line "+l+": "+h,d=this.constructError(u,a);return d.index=o,d.lineNumber=l,d.description=h,d},s.prototype.throwError=function(o,l,a,h){throw this.createError(o,l,a,h)},s.prototype.tolerateError=function(o,l,a,h){var u=this.createError(o,l,a,h);if(this.tolerant)this.recordError(u);else throw u},s}();i.ErrorHandler=n},function(t,i){Object.defineProperty(i,"__esModule",{value:!0}),i.Messages={BadGetterArity:"Getter must not have any formal parameters",BadSetterArity:"Setter must have exactly one formal parameter",BadSetterRestParameter:"Setter function argument must not be a rest parameter",ConstructorIsAsync:"Class constructor may not be an async method",ConstructorSpecialMethod:"Class constructor may not be an accessor",DeclarationMissingInitializer:"Missing initializer in %0 declaration",DefaultRestParameter:"Unexpected token =",DuplicateBinding:"Duplicate binding %0",DuplicateConstructor:"A class may only have one constructor",DuplicateProtoProperty:"Duplicate __proto__ fields are not allowed in object literals",ForInOfLoopInitializer:"%0 loop variable declaration may not have an initializer",GeneratorInLegacyContext:"Generator declarations are not allowed in legacy contexts",IllegalBreak:"Illegal break statement",IllegalContinue:"Illegal continue statement",IllegalExportDeclaration:"Unexpected token",IllegalImportDeclaration:"Unexpected token",IllegalLanguageModeDirective:"Illegal 'use strict' directive in function with non-simple parameter list",IllegalReturn:"Illegal return statement",InvalidEscapedReservedWord:"Keyword must not contain escaped characters",InvalidHexEscapeSequence:"Invalid hexadecimal escape sequence",InvalidLHSInAssignment:"Invalid left-hand side in assignment",InvalidLHSInForIn:"Invalid left-hand side in for-in",InvalidLHSInForLoop:"Invalid left-hand side in for-loop",InvalidModuleSpecifier:"Unexpected token",InvalidRegExp:"Invalid regular expression",LetInLexicalBinding:"let is disallowed as a lexically bound name",MissingFromClause:"Unexpected token",MultipleDefaultsInSwitch:"More than one default clause in switch statement",NewlineAfterThrow:"Illegal newline after throw",NoAsAfterImportNamespace:"Unexpected token",NoCatchOrFinally:"Missing catch or finally after try",ParameterAfterRestParameter:"Rest parameter must be last formal parameter",Redeclaration:"%0 '%1' has already been declared",StaticPrototype:"Classes may not have static property named prototype",StrictCatchVariable:"Catch variable may not be eval or arguments in strict mode",StrictDelete:"Delete of an unqualified identifier in strict mode.",StrictFunction:"In strict mode code, functions can only be declared at top level or inside a block",StrictFunctionName:"Function name may not be eval or arguments in strict mode",StrictLHSAssignment:"Assignment to eval or arguments is not allowed in strict mode",StrictLHSPostfix:"Postfix increment/decrement may not have eval or arguments operand in strict mode",StrictLHSPrefix:"Prefix increment/decrement may not have eval or arguments operand in strict mode",StrictModeWith:"Strict mode code may not include a with statement",StrictOctalLiteral:"Octal literals are not allowed in strict mode.",StrictParamDupe:"Strict mode function may not have duplicate parameter names",StrictParamName:"Parameter name eval or arguments is not allowed in strict mode",StrictReservedWord:"Use of future reserved word in strict mode",StrictVarName:"Variable name may not be eval or arguments in strict mode",TemplateOctalLiteral:"Octal literals are not allowed in template strings.",UnexpectedEOS:"Unexpected end of input",UnexpectedIdentifier:"Unexpected identifier",UnexpectedNumber:"Unexpected number",UnexpectedReserved:"Unexpected reserved word",UnexpectedString:"Unexpected string",UnexpectedTemplate:"Unexpected quasi %0",UnexpectedToken:"Unexpected token %0",UnexpectedTokenIllegal:"Unexpected token ILLEGAL",UnknownLabel:"Undefined label '%0'",UnterminatedRegExp:"Invalid regular expression: missing /"}},function(t,i,n){Object.defineProperty(i,"__esModule",{value:!0});var s=n(9),o=n(4),l=n(11);function a(d){return"0123456789abcdef".indexOf(d.toLowerCase())}function h(d){return"01234567".indexOf(d)}var u=function(){function d(p,g){this.source=p,this.errorHandler=g,this.trackComment=!1,this.isModule=!1,this.length=p.length,this.index=0,this.lineNumber=p.length>0?1:0,this.lineStart=0,this.curlyStack=[]}return d.prototype.saveState=function(){return{index:this.index,lineNumber:this.lineNumber,lineStart:this.lineStart}},d.prototype.restoreState=function(p){this.index=p.index,this.lineNumber=p.lineNumber,this.lineStart=p.lineStart},d.prototype.eof=function(){return this.index>=this.length},d.prototype.throwUnexpectedToken=function(p){return p===void 0&&(p=l.Messages.UnexpectedTokenIllegal),this.errorHandler.throwError(this.index,this.lineNumber,this.index-this.lineStart+1,p)},d.prototype.tolerateUnexpectedToken=function(p){p===void 0&&(p=l.Messages.UnexpectedTokenIllegal),this.errorHandler.tolerateError(this.index,this.lineNumber,this.index-this.lineStart+1,p)},d.prototype.skipSingleLineComment=function(p){var g=[],y,c;for(this.trackComment&&(g=[],y=this.index-p,c={start:{line:this.lineNumber,column:this.index-this.lineStart-p},end:{}});!this.eof();){var f=this.source.charCodeAt(this.index);if(++this.index,o.Character.isLineTerminator(f)){if(this.trackComment){c.end={line:this.lineNumber,column:this.index-this.lineStart-1};var m={multiLine:!1,slice:[y+p,this.index-1],range:[y,this.index-1],loc:c};g.push(m)}return f===13&&this.source.charCodeAt(this.index)===10&&++this.index,++this.lineNumber,this.lineStart=this.index,g}}if(this.trackComment){c.end={line:this.lineNumber,column:this.index-this.lineStart};var m={multiLine:!1,slice:[y+p,this.index],range:[y,this.index],loc:c};g.push(m)}return g},d.prototype.skipMultiLineComment=function(){var p=[],g,y;for(this.trackComment&&(p=[],g=this.index-2,y={start:{line:this.lineNumber,column:this.index-this.lineStart-2},end:{}});!this.eof();){var c=this.source.charCodeAt(this.index);if(o.Character.isLineTerminator(c))c===13&&this.source.charCodeAt(this.index+1)===10&&++this.index,++this.lineNumber,++this.index,this.lineStart=this.index;else if(c===42){if(this.source.charCodeAt(this.index+1)===47){if(this.index+=2,this.trackComment){y.end={line:this.lineNumber,column:this.index-this.lineStart};var f={multiLine:!0,slice:[g+2,this.index-2],range:[g,this.index],loc:y};p.push(f)}return p}++this.index}else++this.index}if(this.trackComment){y.end={line:this.lineNumber,column:this.index-this.lineStart};var f={multiLine:!0,slice:[g+2,this.index],range:[g,this.index],loc:y};p.push(f)}return this.tolerateUnexpectedToken(),p},d.prototype.scanComments=function(){var p;this.trackComment&&(p=[]);for(var g=this.index===0;!this.eof();){var y=this.source.charCodeAt(this.index);if(o.Character.isWhiteSpace(y))++this.index;else if(o.Character.isLineTerminator(y))++this.index,y===13&&this.source.charCodeAt(this.index)===10&&++this.index,++this.lineNumber,this.lineStart=this.index,g=!0;else if(y===47)if(y=this.source.charCodeAt(this.index+1),y===47){this.index+=2;var c=this.skipSingleLineComment(2);this.trackComment&&(p=p.concat(c)),g=!0}else if(y===42){this.index+=2;var c=this.skipMultiLineComment();this.trackComment&&(p=p.concat(c))}else break;else if(g&&y===45)if(this.source.charCodeAt(this.index+1)===45&&this.source.charCodeAt(this.index+2)===62){this.index+=3;var c=this.skipSingleLineComment(3);this.trackComment&&(p=p.concat(c))}else break;else if(y===60&&!this.isModule)if(this.source.slice(this.index+1,this.index+4)==="!--"){this.index+=4;var c=this.skipSingleLineComment(4);this.trackComment&&(p=p.concat(c))}else break;else break}return p},d.prototype.isFutureReservedWord=function(p){switch(p){case"enum":case"export":case"import":case"super":return!0;default:return!1}},d.prototype.isStrictModeReservedWord=function(p){switch(p){case"implements":case"interface":case"package":case"private":case"protected":case"public":case"static":case"yield":case"let":return!0;default:return!1}},d.prototype.isRestrictedWord=function(p){return p==="eval"||p==="arguments"},d.prototype.isKeyword=function(p){switch(p.length){case 2:return p==="if"||p==="in"||p==="do";case 3:return p==="var"||p==="for"||p==="new"||p==="try"||p==="let";case 4:return p==="this"||p==="else"||p==="case"||p==="void"||p==="with"||p==="enum";case 5:return p==="while"||p==="break"||p==="catch"||p==="throw"||p==="const"||p==="yield"||p==="class"||p==="super";case 6:return p==="return"||p==="typeof"||p==="delete"||p==="switch"||p==="export"||p==="import";case 7:return p==="default"||p==="finally"||p==="extends";case 8:return p==="function"||p==="continue"||p==="debugger";case 10:return p==="instanceof";default:return!1}},d.prototype.codePointAt=function(p){var g=this.source.charCodeAt(p);if(g>=55296&&g<=56319){var y=this.source.charCodeAt(p+1);if(y>=56320&&y<=57343){var c=g;g=(c-55296)*1024+y-56320+65536}}return g},d.prototype.scanHexEscape=function(p){for(var g=p==="u"?4:2,y=0,c=0;c1114111||p!=="}")&&this.throwUnexpectedToken(),o.Character.fromCodePoint(g)},d.prototype.getIdentifier=function(){for(var p=this.index++;!this.eof();){var g=this.source.charCodeAt(this.index);if(g===92)return this.index=p,this.getComplexIdentifier();if(g>=55296&&g<57343)return this.index=p,this.getComplexIdentifier();if(o.Character.isIdentifierPart(g))++this.index;else break}return this.source.slice(p,this.index)},d.prototype.getComplexIdentifier=function(){var p=this.codePointAt(this.index),g=o.Character.fromCodePoint(p);this.index+=g.length;var y;for(p===92&&(this.source.charCodeAt(this.index)!==117&&this.throwUnexpectedToken(),++this.index,this.source[this.index]==="{"?(++this.index,y=this.scanUnicodeCodePointEscape()):(y=this.scanHexEscape("u"),(y===null||y==="\\"||!o.Character.isIdentifierStart(y.charCodeAt(0)))&&this.throwUnexpectedToken()),g=y);!this.eof()&&(p=this.codePointAt(this.index),!!o.Character.isIdentifierPart(p));)y=o.Character.fromCodePoint(p),g+=y,this.index+=y.length,p===92&&(g=g.substr(0,g.length-1),this.source.charCodeAt(this.index)!==117&&this.throwUnexpectedToken(),++this.index,this.source[this.index]==="{"?(++this.index,y=this.scanUnicodeCodePointEscape()):(y=this.scanHexEscape("u"),(y===null||y==="\\"||!o.Character.isIdentifierPart(y.charCodeAt(0)))&&this.throwUnexpectedToken()),g+=y);return g},d.prototype.octalToDecimal=function(p){var g=p!=="0",y=h(p);return!this.eof()&&o.Character.isOctalDigit(this.source.charCodeAt(this.index))&&(g=!0,y=y*8+h(this.source[this.index++]),"0123".indexOf(p)>=0&&!this.eof()&&o.Character.isOctalDigit(this.source.charCodeAt(this.index))&&(y=y*8+h(this.source[this.index++]))),{code:y,octal:g}},d.prototype.scanIdentifier=function(){var p,g=this.index,y=this.source.charCodeAt(g)===92?this.getComplexIdentifier():this.getIdentifier();if(y.length===1?p=3:this.isKeyword(y)?p=4:y==="null"?p=5:y==="true"||y==="false"?p=1:p=3,p!==3&&g+y.length!==this.index){var c=this.index;this.index=g,this.tolerateUnexpectedToken(l.Messages.InvalidEscapedReservedWord),this.index=c}return{type:p,value:y,lineNumber:this.lineNumber,lineStart:this.lineStart,start:g,end:this.index}},d.prototype.scanPunctuator=function(){var p=this.index,g=this.source[this.index];switch(g){case"(":case"{":g==="{"&&this.curlyStack.push("{"),++this.index;break;case".":++this.index,this.source[this.index]==="."&&this.source[this.index+1]==="."&&(this.index+=2,g="...");break;case"}":++this.index,this.curlyStack.pop();break;case")":case";":case",":case"[":case"]":case":":case"?":case"~":++this.index;break;default:g=this.source.substr(this.index,4),g===">>>="?this.index+=4:(g=g.substr(0,3),g==="==="||g==="!=="||g===">>>"||g==="<<="||g===">>="||g==="**="?this.index+=3:(g=g.substr(0,2),g==="&&"||g==="||"||g==="=="||g==="!="||g==="+="||g==="-="||g==="*="||g==="/="||g==="++"||g==="--"||g==="<<"||g===">>"||g==="&="||g==="|="||g==="^="||g==="%="||g==="<="||g===">="||g==="=>"||g==="**"?this.index+=2:(g=this.source[this.index],"<>=!+-*%&|^/".indexOf(g)>=0&&++this.index)))}return this.index===p&&this.throwUnexpectedToken(),{type:7,value:g,lineNumber:this.lineNumber,lineStart:this.lineStart,start:p,end:this.index}},d.prototype.scanHexLiteral=function(p){for(var g="";!this.eof()&&o.Character.isHexDigit(this.source.charCodeAt(this.index));)g+=this.source[this.index++];return g.length===0&&this.throwUnexpectedToken(),o.Character.isIdentifierStart(this.source.charCodeAt(this.index))&&this.throwUnexpectedToken(),{type:6,value:parseInt("0x"+g,16),lineNumber:this.lineNumber,lineStart:this.lineStart,start:p,end:this.index}},d.prototype.scanBinaryLiteral=function(p){for(var g="",y;!this.eof()&&(y=this.source[this.index],!(y!=="0"&&y!=="1"));)g+=this.source[this.index++];return g.length===0&&this.throwUnexpectedToken(),this.eof()||(y=this.source.charCodeAt(this.index),(o.Character.isIdentifierStart(y)||o.Character.isDecimalDigit(y))&&this.throwUnexpectedToken()),{type:6,value:parseInt(g,2),lineNumber:this.lineNumber,lineStart:this.lineStart,start:p,end:this.index}},d.prototype.scanOctalLiteral=function(p,g){var y="",c=!1;for(o.Character.isOctalDigit(p.charCodeAt(0))?(c=!0,y="0"+this.source[this.index++]):++this.index;!this.eof()&&o.Character.isOctalDigit(this.source.charCodeAt(this.index));)y+=this.source[this.index++];return!c&&y.length===0&&this.throwUnexpectedToken(),(o.Character.isIdentifierStart(this.source.charCodeAt(this.index))||o.Character.isDecimalDigit(this.source.charCodeAt(this.index)))&&this.throwUnexpectedToken(),{type:6,value:parseInt(y,8),octal:c,lineNumber:this.lineNumber,lineStart:this.lineStart,start:g,end:this.index}},d.prototype.isImplicitOctalLiteral=function(){for(var p=this.index+1;p=0&&(c=c.replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g,function(m,x,v){var S=parseInt(x||v,16);return S>1114111&&f.throwUnexpectedToken(l.Messages.InvalidRegExp),S<=65535?String.fromCharCode(S):y}).replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,y));try{RegExp(c)}catch{this.throwUnexpectedToken(l.Messages.InvalidRegExp)}try{return new RegExp(p,g)}catch{return null}},d.prototype.scanRegExpBody=function(){var p=this.source[this.index];s.assert(p==="/","Regular expression literal must start with a slash");for(var g=this.source[this.index++],y=!1,c=!1;!this.eof();)if(p=this.source[this.index++],g+=p,p==="\\")p=this.source[this.index++],o.Character.isLineTerminator(p.charCodeAt(0))&&this.throwUnexpectedToken(l.Messages.UnterminatedRegExp),g+=p;else if(o.Character.isLineTerminator(p.charCodeAt(0)))this.throwUnexpectedToken(l.Messages.UnterminatedRegExp);else if(y)p==="]"&&(y=!1);else if(p==="/"){c=!0;break}else p==="["&&(y=!0);return c||this.throwUnexpectedToken(l.Messages.UnterminatedRegExp),g.substr(1,g.length-2)},d.prototype.scanRegExpFlags=function(){for(var p="",g="";!this.eof();){var y=this.source[this.index];if(!o.Character.isIdentifierPart(y.charCodeAt(0)))break;if(++this.index,y==="\\"&&!this.eof())if(y=this.source[this.index],y==="u"){++this.index;var c=this.index,f=this.scanHexEscape("u");if(f!==null)for(g+=f,p+="\\u";c=55296&&p<57343&&o.Character.isIdentifierStart(this.codePointAt(this.index))?this.scanIdentifier():this.scanPunctuator()},d}();i.Scanner=u},function(t,i){Object.defineProperty(i,"__esModule",{value:!0}),i.TokenName={},i.TokenName[1]="Boolean",i.TokenName[2]="",i.TokenName[3]="Identifier",i.TokenName[4]="Keyword",i.TokenName[5]="Null",i.TokenName[6]="Numeric",i.TokenName[7]="Punctuator",i.TokenName[8]="String",i.TokenName[9]="RegularExpression",i.TokenName[10]="Template"},function(t,i){Object.defineProperty(i,"__esModule",{value:!0}),i.XHTMLEntities={quot:'"',amp:"&",apos:"'",gt:">",nbsp:"\xA0",iexcl:"\xA1",cent:"\xA2",pound:"\xA3",curren:"\xA4",yen:"\xA5",brvbar:"\xA6",sect:"\xA7",uml:"\xA8",copy:"\xA9",ordf:"\xAA",laquo:"\xAB",not:"\xAC",shy:"\xAD",reg:"\xAE",macr:"\xAF",deg:"\xB0",plusmn:"\xB1",sup2:"\xB2",sup3:"\xB3",acute:"\xB4",micro:"\xB5",para:"\xB6",middot:"\xB7",cedil:"\xB8",sup1:"\xB9",ordm:"\xBA",raquo:"\xBB",frac14:"\xBC",frac12:"\xBD",frac34:"\xBE",iquest:"\xBF",Agrave:"\xC0",Aacute:"\xC1",Acirc:"\xC2",Atilde:"\xC3",Auml:"\xC4",Aring:"\xC5",AElig:"\xC6",Ccedil:"\xC7",Egrave:"\xC8",Eacute:"\xC9",Ecirc:"\xCA",Euml:"\xCB",Igrave:"\xCC",Iacute:"\xCD",Icirc:"\xCE",Iuml:"\xCF",ETH:"\xD0",Ntilde:"\xD1",Ograve:"\xD2",Oacute:"\xD3",Ocirc:"\xD4",Otilde:"\xD5",Ouml:"\xD6",times:"\xD7",Oslash:"\xD8",Ugrave:"\xD9",Uacute:"\xDA",Ucirc:"\xDB",Uuml:"\xDC",Yacute:"\xDD",THORN:"\xDE",szlig:"\xDF",agrave:"\xE0",aacute:"\xE1",acirc:"\xE2",atilde:"\xE3",auml:"\xE4",aring:"\xE5",aelig:"\xE6",ccedil:"\xE7",egrave:"\xE8",eacute:"\xE9",ecirc:"\xEA",euml:"\xEB",igrave:"\xEC",iacute:"\xED",icirc:"\xEE",iuml:"\xEF",eth:"\xF0",ntilde:"\xF1",ograve:"\xF2",oacute:"\xF3",ocirc:"\xF4",otilde:"\xF5",ouml:"\xF6",divide:"\xF7",oslash:"\xF8",ugrave:"\xF9",uacute:"\xFA",ucirc:"\xFB",uuml:"\xFC",yacute:"\xFD",thorn:"\xFE",yuml:"\xFF",OElig:"\u0152",oelig:"\u0153",Scaron:"\u0160",scaron:"\u0161",Yuml:"\u0178",fnof:"\u0192",circ:"\u02C6",tilde:"\u02DC",Alpha:"\u0391",Beta:"\u0392",Gamma:"\u0393",Delta:"\u0394",Epsilon:"\u0395",Zeta:"\u0396",Eta:"\u0397",Theta:"\u0398",Iota:"\u0399",Kappa:"\u039A",Lambda:"\u039B",Mu:"\u039C",Nu:"\u039D",Xi:"\u039E",Omicron:"\u039F",Pi:"\u03A0",Rho:"\u03A1",Sigma:"\u03A3",Tau:"\u03A4",Upsilon:"\u03A5",Phi:"\u03A6",Chi:"\u03A7",Psi:"\u03A8",Omega:"\u03A9",alpha:"\u03B1",beta:"\u03B2",gamma:"\u03B3",delta:"\u03B4",epsilon:"\u03B5",zeta:"\u03B6",eta:"\u03B7",theta:"\u03B8",iota:"\u03B9",kappa:"\u03BA",lambda:"\u03BB",mu:"\u03BC",nu:"\u03BD",xi:"\u03BE",omicron:"\u03BF",pi:"\u03C0",rho:"\u03C1",sigmaf:"\u03C2",sigma:"\u03C3",tau:"\u03C4",upsilon:"\u03C5",phi:"\u03C6",chi:"\u03C7",psi:"\u03C8",omega:"\u03C9",thetasym:"\u03D1",upsih:"\u03D2",piv:"\u03D6",ensp:"\u2002",emsp:"\u2003",thinsp:"\u2009",zwnj:"\u200C",zwj:"\u200D",lrm:"\u200E",rlm:"\u200F",ndash:"\u2013",mdash:"\u2014",lsquo:"\u2018",rsquo:"\u2019",sbquo:"\u201A",ldquo:"\u201C",rdquo:"\u201D",bdquo:"\u201E",dagger:"\u2020",Dagger:"\u2021",bull:"\u2022",hellip:"\u2026",permil:"\u2030",prime:"\u2032",Prime:"\u2033",lsaquo:"\u2039",rsaquo:"\u203A",oline:"\u203E",frasl:"\u2044",euro:"\u20AC",image:"\u2111",weierp:"\u2118",real:"\u211C",trade:"\u2122",alefsym:"\u2135",larr:"\u2190",uarr:"\u2191",rarr:"\u2192",darr:"\u2193",harr:"\u2194",crarr:"\u21B5",lArr:"\u21D0",uArr:"\u21D1",rArr:"\u21D2",dArr:"\u21D3",hArr:"\u21D4",forall:"\u2200",part:"\u2202",exist:"\u2203",empty:"\u2205",nabla:"\u2207",isin:"\u2208",notin:"\u2209",ni:"\u220B",prod:"\u220F",sum:"\u2211",minus:"\u2212",lowast:"\u2217",radic:"\u221A",prop:"\u221D",infin:"\u221E",ang:"\u2220",and:"\u2227",or:"\u2228",cap:"\u2229",cup:"\u222A",int:"\u222B",there4:"\u2234",sim:"\u223C",cong:"\u2245",asymp:"\u2248",ne:"\u2260",equiv:"\u2261",le:"\u2264",ge:"\u2265",sub:"\u2282",sup:"\u2283",nsub:"\u2284",sube:"\u2286",supe:"\u2287",oplus:"\u2295",otimes:"\u2297",perp:"\u22A5",sdot:"\u22C5",lceil:"\u2308",rceil:"\u2309",lfloor:"\u230A",rfloor:"\u230B",loz:"\u25CA",spades:"\u2660",clubs:"\u2663",hearts:"\u2665",diams:"\u2666",lang:"\u27E8",rang:"\u27E9"}},function(t,i,n){Object.defineProperty(i,"__esModule",{value:!0});var s=n(10),o=n(12),l=n(13),a=function(){function u(){this.values=[],this.curly=this.paren=-1}return u.prototype.beforeFunctionExpression=function(d){return["(","{","[","in","typeof","instanceof","new","return","case","delete","throw","void","=","+=","-=","*=","**=","/=","%=","<<=",">>=",">>>=","&=","|=","^=",",","+","-","*","**","/","%","++","--","<<",">>",">>>","&","|","^","!","~","&&","||","?",":","===","==",">=","<=","<",">","!=","!=="].indexOf(d)>=0},u.prototype.isRegexStart=function(){var d=this.values[this.values.length-1],p=d!==null;switch(d){case"this":case"]":p=!1;break;case")":var g=this.values[this.paren-1];p=g==="if"||g==="while"||g==="for"||g==="with";break;case"}":if(p=!1,this.values[this.curly-3]==="function"){var y=this.values[this.curly-4];p=y?!this.beforeFunctionExpression(y):!1}else if(this.values[this.curly-4]==="function"){var y=this.values[this.curly-5];p=y?!this.beforeFunctionExpression(y):!0}break}return p},u.prototype.push=function(d){d.type===7||d.type===4?(d.value==="{"?this.curly=this.values.length:d.value==="("&&(this.paren=this.values.length),this.values.push(d.value)):this.values.push(null)},u}(),h=function(){function u(d,p){this.errorHandler=new s.ErrorHandler,this.errorHandler.tolerant=p?typeof p.tolerant=="boolean"&&p.tolerant:!1,this.scanner=new o.Scanner(d,this.errorHandler),this.scanner.trackComment=p?typeof p.comment=="boolean"&&p.comment:!1,this.trackRange=p?typeof p.range=="boolean"&&p.range:!1,this.trackLoc=p?typeof p.loc=="boolean"&&p.loc:!1,this.buffer=[],this.reader=new a}return u.prototype.errors=function(){return this.errorHandler.errors},u.prototype.getNextToken=function(){if(this.buffer.length===0){var d=this.scanner.scanComments();if(this.scanner.trackComment)for(var p=0;p + + terminal + based on feathericon/build/svg/terminal.svg + + + + + + + diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..1147b18 --- /dev/null +++ b/license.txt @@ -0,0 +1,19 @@ +Copyright (c) 2016 Structured Data LLC + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index 151ad9b..89fd5b5 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,26 @@ "version": "0.3.10", "license": "MIT", "description": "Command shell based on CodeMirror.", - "keywords": ["shell", "console"], + "keywords": [ + "shell", + "console" + ], "repository": { - "type" : "git", - "url" : "https://github.com/sdllc/cmjs-shell.git" + "type": "git", + "url": "https://github.com/sdllc/cmjs-shell.git" }, - "main": "shell.js" + "main": "shell.js", + "scripts": { + "dev": "cd demo && npx vite", + "build": "cd demo && npx vite build && touch ../docs/.nojekyll", + "pretty": "prettier --write shell.js demo/index.js" + }, + "devDependencies": { + "@codemirror/commands": "^6.1.2", + "@codemirror/state": "^6.1.4", + "@codemirror/view": "^6.6.0", + "prettier": "^2.8.0", + "queue-microtask": "^1.2.3", + "vite": "^3.2.4" + } } diff --git a/README.md b/readme.md similarity index 100% rename from README.md rename to readme.md diff --git a/scripts/build-demo.sh b/scripts/build-demo.sh new file mode 100755 index 0000000..d5e991d --- /dev/null +++ b/scripts/build-demo.sh @@ -0,0 +1,13 @@ +#! /bin/sh + +dirty="$(git status --porcelain | grep -v '^?? ')" +if [[ "$dirty" != "" ]] +then + echo "error: git is dirty" + echo "$dirty" + exit 1 +fi + +npm run build +git add docs +git commit -m build diff --git a/shell.js b/shell.js index 9ac8497..b51f318 100644 --- a/shell.js +++ b/shell.js @@ -22,29 +22,118 @@ * */ -(function(){ - -"use strict"; - -// enums will get exported - -var EXEC_STATE = { - EDIT: "edit", - EXEC: "exec" -}; - -var PARSE_STATUS = { - NULL: "", - OK: "OK", - INCOMPLETE: "Incomplete", - PARSE_ERR: "ParseError", - ERR: "Err" -}; - -const MAX_HISTORY_DEFAULT = 2500; - -const HISTORY_KEY_DEFAULT = "shell.history"; -const DEFAULT_PROMPT_CLASS = "shell-prompt"; +/* + +codemirror partial readonly +https://discuss.codemirror.net/t/how-to-make-certain-ranges-readonly-in-codemirror6/3400 +https://www.npmjs.com/package/codemirror-readonly-ranges +https://stackoverflow.com/questions/17415100/codemirror-particular-lines-readonly + +https://discuss.codemirror.net/t/easily-track-remove-content-with-decorations/4606 + +2021-01-14 codemirror 6 + +https://github.com/codemirror/dev/issues/44#issuecomment-789093799 +https://codemirror.net/6/docs/guide/#state-fields +how to listen for changes + +import { EditorState, EditorView, basicSetup } from '@codemirror/basic-setup'; +import { StateField } from '@codemirror/state'; + +// Define StateField +const listenChangesExtension = StateField.define({ + // we won't use the actual StateField value, null or undefined is fine + create: () => null, + update: (value, transaction) => { + if (transaction.docChanged) { + // access new content via the Transaction + console.log(transaction.newDoc.toJSON()); + } + return null; + }, +}); + +// Element for EditorView +const parent = window.document.querySelector('#my-div') as HTMLDivElement; + +// Initialize with StateField as extension +const editor = EditorView({ + state: EditorState.create({ + extensions: [basicSetup, listenChangesExtension], + doc: 'print("hello github")', + }), + parent, +}); + + +*/ + +//import * as CodeMirror from "codemirror" +//import {EditorView, Range, Decoration} from "@codemirror/view" +import { EditorView, Decoration, keymap } from "@codemirror/view" +import { StateField, StateEffect } from "@codemirror/state" +import { StreamLanguage } from "@codemirror/language" +//import { javascript } from "@codemirror/lang-javascript" +//import { parseMixed } from "@lezer/common" +//import readOnlyRangesExtension from "codemirror-readonly-ranges" +import { defaultKeymap, history, historyKeymap } from "@codemirror/commands" + +import setImmediate from "queue-microtask" + +export const EXEC_STATE = { + EDIT: "edit", + EXEC: "exec", +} + +export const PARSE_STATUS = { + NULL: "", + OK: "OK", + INCOMPLETE: "Incomplete", + PARSE_ERR: "ParseError", + ERR: "Err", +} + +const MAX_HISTORY_DEFAULT = 2500 + +const HISTORY_KEY_DEFAULT = "shell.history" +const DEFAULT_PROMPT_CLASS = "shell-prompt" + +function posToOffset(doc, pos) { + //return doc.line(pos.line + 1).from + pos.ch + return doc.line(pos.line).from + pos.ch +} + +function offsetToPos(doc, offset) { + let line = doc.lineAt(offset) + //return {line: line.number - 1, ch: offset - line.from} + return { line: line.number, ch: offset - line.from } +} + +// https://codemirror.net/docs/migration/#marked-text +const addMarks = StateEffect.define() +const filterMarks = StateEffect.define() +// This value must be added to the set of extensions to enable this +const markFieldExtension = StateField.define({ + // Start with an empty set of decorations + create() { + return Decoration.none + }, + // This is called whenever the editor updates—it computes the new set + update(value, tr) { + // Move the decorations to account for document changes + value = value.map(tr.changes) + // If this transaction adds or removes decorations, apply those changes + for (let effect of tr.effects) { + if (effect.is(addMarks)) + value = value.update({ add: effect.value, sort: true }) + else if (effect.is(filterMarks)) + value = value.update({ filter: effect.value }) + } + return value + }, + // Indicate that this field provides a set of decorations + provide: (f) => EditorView.decorations.from(f), +}) /** * shell implmentation based on CodeMirror (which is awesome) @@ -62,1130 +151,1479 @@ const DEFAULT_PROMPT_CLASS = "shell-prompt"; * function_key_callback: called on function keys (+ some others) * */ -var Shell = function( CodeMirror_, opts ){ - - var cm; - var state = EXEC_STATE.EDIT; - var prompt_text = ""; - var instance = this; - - var prompt_len = 0; - - var command_buffer = []; - var paste_buffer = []; - - var unstyled_lines = []; - var block_reset = []; - - var unstyled_flag = false; - var cached_prompt = null; - - var event_cache = null; - var event_cache_skip = false; - var event_playback = false; - - /** - * FIXME: cap and flush this thing at (X) number of lines - * - * soft persistence, meaning: up up to a command, modify it - * slightly, then down, up, modifications are retained. reverts - * on new command. - */ - var history = { - - current_line: null, - commands: [], - actual_commands: [], - pointer: 0, - - reset_pointer: function(){ - this.pointer = 0; - this.commands = this.actual_commands.slice(0); - }, - - push: function( line ){ - this.actual_commands.push( line ); - this.commands = this.actual_commands.slice(0); - }, - - save: function(opts){ - opts = opts || {}; - var max = opts.max || MAX_HISTORY_DEFAULT; - var key = opts.key || HISTORY_KEY_DEFAULT; - localStorage.setItem( key, JSON.stringify( this.actual_commands.slice(-max))); - }, - - restore: function(opts){ - opts = opts || {}; - var key = opts.key || HISTORY_KEY_DEFAULT; - var val = localStorage.getItem(key); - if( val ) this.actual_commands = JSON.parse( val ); - this.reset_pointer(); - }, - - clear: function(){ - this.actual_commands = []; - this.commands = []; - this.pointer = 0; - this.save(); +export default function Shell(opts) { + /** @type {import("codemirror").EditorView} */ + var view + + var state = EXEC_STATE.EDIT + var prompt_text = "" + var instance = this + instance.opts = opts + instance.cm = null + this.function_tip = {} + this.EXEC_STATE = EXEC_STATE + this.PARSE_STATUS = PARSE_STATUS + instance.language = null + + var prompt_len = 0 + + var command_buffer = [] + var paste_buffer = [] + + var unstyled_lines = [] + var block_reset = [] + + var unstyled_flag = false + var cached_prompt = null + + var event_cache = null + var event_cache_skip = false + var event_playback = false + + /** + * FIXME: cap and flush this thing at (X) number of lines + * + * soft persistence, meaning: up up to a command, modify it + * slightly, then down, up, modifications are retained. reverts + * on new command. + */ + class History { + /** @type {string | null} */ + current_line = null + commands = [] + actual_commands = [] + pointer = 0 + + reset_pointer() { + this.pointer = 0 + this.commands = this.actual_commands.slice(0) + } + + push(line) { + this.actual_commands.push(line) + this.commands = this.actual_commands.slice(0) + } + + save(opts) { + opts = opts || {} + var max = opts.max || MAX_HISTORY_DEFAULT + var key = opts.key || HISTORY_KEY_DEFAULT + localStorage.setItem( + key, + JSON.stringify(this.actual_commands.slice(-max)) + ) + } + + restore(opts) { + opts = opts || {} + var key = opts.key || HISTORY_KEY_DEFAULT + var val = localStorage.getItem(key) + if (val) this.actual_commands = JSON.parse(val) + this.reset_pointer() + } + + clear() { + this.actual_commands = [] + this.commands = [] + this.pointer = 0 + this.save() + } + } + + const history = new History() + + /** + * overlay mode to support unstyled text -- file contents (the pager) + * in our particular case but could be anything. this is based on + * CM's "overlay" mode, but that one doesn't work because it parses + * regardless and we get stuck in string-mode after a stray apostrophe. + * + * in this one, null styling is the default, and greedy; but if we are + * not unstyled, then we pass through to (base). base should be a string + * mode name, which must have been previously registered. + */ + /** + * + * // TODO param {import("@codemirror/language").Language} innerLanguage + * // TODO param {import("@codemirror/legacy-modes").Mode} innerMode + * @param {*} base + */ + + function init_overlay_mode(base) { + // CodeMirror.defineMode in codemirror 6 + // https://discuss.codemirror.net/t/how-to-create-custom-syntax-highlighter-using-stream-parser/3752 + // https://github.com/codemirror/legacy-modes/blob/main/mode/shell.js + // https://github.com/codemirror/legacy-modes/search?q=startState + // https://github.com/codemirror/legacy-modes/search?q=copyState + // https://codemirror.net/examples/mixed-language/ + // https://discuss.codemirror.net/t/equivalent-of-getstateafter-in-cm6/3855 + // https://marijnhaverbeke.nl/blog/codemirror-mode-system.html + /* + CM.defineMode( name, function(config, parserConfig) { + base = CM.getMode( config, parserConfig.backdrop || baseMode ); + return { ... }; + }); + */ + //var config = {} // TODO + //var parserConfig = {} // TODO + + //var base = CM.getMode( config, parserConfig.backdrop || baseName ); + + var outerLanguage = StreamLanguage.define({ + startState: function () { + return { + base: base.startState(), + linecount: 0, } - - - }; - - /** - * overlay mode to support unstyled text -- file contents (the pager) - * in our particular case but could be anything. this is based on - * CM's "overlay" mode, but that one doesn't work because it parses - * regardless and we get stuck in string-mode after a stray apostrophe. - * - * in this one, null styling is the default, and greedy; but if we are - * not unstyled, then we pass through to (base). base should be a string - * mode name, which must have been previously registered. - */ - function init_overlay_mode( CM, base, name ){ - - CM.defineMode( name, function(config, parserConfig) { - base = CM.getMode( config, parserConfig.backdrop || base ); - return { - - startState: function() { - return { - base: CM.startState(base), - linecount: 0 - }; - }, - - copyState: function(state) { - return { - base: CM.copyState(base, state.base), - linecount: state.linecount - }; - }, - - token: function(stream, state) { - if( stream.sol()){ - var lc = state.linecount; - state.linecount++; - if( unstyled_flag || unstyled_lines[lc] ){ - stream.skipToEnd(); - return "unstyled"; - } - if( block_reset[lc] ){ - state.base = CM.startState(base); - } - } - return base.token(stream, state.base); - - }, - - indent: base.indent && function(state, textAfter) { - return base.indent(state.base, textAfter); - }, - - electricChars: base.electricChars, - - innerMode: function(state) { return {state: state.base, mode: base}; }, - - blankLine: function(state) { - state.linecount++; - if (base.blankLine) base.blankLine(state.base); - } - - }; - }); - - } - - /** destructively clear all history */ - this.clearHistory = function(){ - history.clear(); - }; + }, + + /* FIXME TypeError: base.copyState is not a function + copyState: function(state) { + return { + base: base.copyState(state.base), + linecount: state.linecount + }; + }, + */ + + token: function (stream, state) { + if (stream.sol()) { + var lc = state.linecount + state.linecount++ + if (unstyled_flag || unstyled_lines[lc]) { + stream.skipToEnd() + return "unstyled" + } + if (block_reset[lc]) { + state.base = base.startState() + } + } + return base.token(stream, state.base) + }, + + // FIXME TypeError: Cannot read properties of undefined (reading 'unit') + indent: + base?.indent && + function (state, textAfter) { + console.log("outerLanguage indent", { base, state, textAfter }) + return base.indent(state.base, textAfter) + }, + + // FIXME + //electricChars: base.electricChars, + + // FIXME + //innerMode: function(state) { return {state: state.base, mode: base}; }, + + blankLine: function (state) { + state.linecount++ + if (base.blankLine) base.blankLine(state.base) + }, + }) + + /* TODO overlay LRLanguage and StreamLanguage + + const mixedParser = outerLanguage.parser.configure({ + // simple: one node has the inner content + //wrap: parseMixed(node => { + // return node.name == "ScriptText" ? {parser: innerParser} : null + //}), + + // overlay: multiple node have the inner content + wrap: parseMixed(node => { + return node.type.isTop ? { + parser: innerLanguage.parser, + overlay: node => node.type.name == "Text" + } : null + }) + }) + const mixedLang = LRLanguage.define({parser: mixedParser}) + */ + + instance.language = outerLanguage + } + + /** destructively clear all history */ + this.clearHistory = function () { + history.clear() + } - /** + /** * get the CM object. necessary for some clients * to handle events. FIXME -- pass through events. */ - this.getCM = function(){ - return cm; - }; + this.getCM = function () { + return view + } + + /** set CM option directly -- REMOVE */ + this.setOption = function (option, value) { + if (opts.debug) console.info("set option", option, value) + // FIXME + //cm.setOption( option, value ); + } + + /** get CM option directly -- REMOVE */ + this.getOption = function (option) { + if (opts.debug) console.info("get option", option) + // FIXME + //return cm.getOption( option ); + } + + /** cache events if we're blocking */ + var cacheEvent = function (event) { + if (event_cache && !event_playback) { + if (event_cache_skip) { + if (event.type === "keyup" && event.key === "Enter") + event_cache_skip = false + } else { + event_cache.push(event) + } + } + } - /** set CM option directly -- REMOVE */ - this.setOption = function( option, value ){ - if( opts.debug ) console.info( "set option", option, value ); - cm.setOption( option, value ); - }; - - /** get CM option directly -- REMOVE */ - this.getOption = function( option ){ - if( opts.debug ) console.info( "get option", option ); - return cm.getOption( option ); - }; - - /** cache events if we're blocking */ - var cacheEvent = function(event){ - if( event_cache && !event_playback ){ - if( event_cache_skip ){ - if( event.type === "keyup" && event.key === "Enter" ) - event_cache_skip = false; - } - else { - event_cache.push( event ); - } - } - }; - - /** - * when unblocking (exiting an explicit block or exec), - * replay cached keyboard events. in some cases a played-back - * event may trigger execution, which turns caching back on. - * in that case, stop processing and dump all the - * original source events back into the cache. - */ - var playbackEvents = function(){ - - // flush cache. set to null to act as flag - - var tmp = event_cache; - event_cache = null; - event_cache_skip = false; - - if( tmp && tmp.length ){ - - var inputTarget = cm.getInputField(); - tmp.forEach( function( src ){ - - if( event_cache ){ - cacheEvent( src ); - return; - } - - var event = new KeyboardEvent( src.type, src ); - Object.defineProperties( event, { - charCode: { get: function(){ return src.charCode; }}, - which: { get: function(){ return src.which; }}, - keyCode: { get: function(){ return src.keyCode; }}, - key: { get: function(){ return src.key; }}, - char: { get: function(){ return src.char; }}, - target: { get: function(){ return src.target; }} - }); - event_playback = true; - inputTarget.dispatchEvent( event ); - event_playback = false; - - }); - } - - }; - - /** - * block. this is used for operations called by the code, rather than - * the user -- we don't want the user to be able to run commands, because - * they'll fail. - */ - this.block = function(message){ - - // this bit is right from exec: - - if( state === EXEC_STATE.EXEC ){ - return false; - } - - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - var line = doc.getLine( lineno ); - - if( !message ) message = "\n"; - else message = "\n" + message + "\n"; - - doc.replaceRange( message, { line: lineno+1, ch: 0 }, undefined, "prompt"); - doc.setCursor({ line: lineno+1, ch: 0 }); - - state = EXEC_STATE.EXEC; - - var command = line.substr(prompt_len); - command_buffer.push(command); - - if( command.trim().length > 0 ){ - history.push(command); - history.save(); // this is perhaps unecessarily aggressive - } - - // this automatically resets the pointer (NOT windows style) - history.reset_pointer(); - - // turn on event caching - event_cache = []; - - // now leave it in this state... - return true; - - }; - - /** unblock, should be symmetrical. */ - this.unblock = function( rslt, ignore_cached_events ){ - - // again this is from exec (but we're skipping the - // bit about pasting) - - state = EXEC_STATE.EDIT; - - if( rslt && rslt.prompt ){ - command_buffer = []; - set_prompt( rslt.prompt || instance.opts.initial_prompt, rslt.prompt_class, rslt.continuation ); - } - else { - var ps = rslt ? rslt.parsestatus || PARSE_STATUS.OK : PARSE_STATUS.NULL; - if( ps === PARSE_STATUS.INCOMPLETE ){ - set_prompt( instance.opts.continuation_prompt, undefined, true ); - } - else { - command_buffer = []; - set_prompt( instance.opts.initial_prompt ); - } - } - - if( !ignore_cached_events ) playbackEvents(); - - }; - - /** - * get history as array - */ - this.get_history = function(){ - return history.actual_commands.slice(0); - }; - - /** - * insert an arbitrary node, via CM's widget - * - * @param scroll -- scroll to the following line so the node is visible - */ - this.insert_node = function(node, scroll){ - - var doc = cm.getDoc(); - var line = Math.max( doc.lastLine() - 1, 0 ); - cm.addLineWidget( line, node, { - handleMouseEvents: true - }); - if( scroll ) cm.scrollIntoView({line: line+1, ch: 0}); - - }; - - /** - * select all -- this doesn't seem to work using the standard event... ? - */ - this.select_all = function(){ - cm.execCommand( 'selectAll' ); - }; - - /** - * handler for command responses, stuff that the system - * sends to the shell (callbacks, generally). optional className is a - * style applied to the block. "unstyled", if set, prevents language - * styling on the block. - */ - this.response = function(text, className, unstyled){ - - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - var end, start = lineno; - - if( text && typeof text !== "string" ){ - try { text = text.toString(); } - catch( e ){ - text = "Unrenderable message: " + e.message; - } - }; - - // don't add newlines. respect existing length. this is so we - // can handle \r (without a \n). FIXME: if there's a prompt, go - // up one line. - - var lastline = doc.getLine(lineno); - var ch = lastline ? lastline.length : 0; - - // second cut, a little more thorough - // one more patch, to stop breaking on windows CRLFs - - var lines = text.split( "\n" ); - var replace_end = undefined; - var inline_replacement = false; - - // fix here in case there's already a prompt (this is a rare case?) - - if( state !== EXEC_STATE.EXEC ){ - - ch = 0; // insert before anything else on line - - // this is new: in the event that there is already a prompt, - // and we are maintaining styling "breaks", then we may - // need to offset the last break by some number of lines. - - // actually we know it's only going to be the last one, so - // we can skip the loop. - - if( lines.length > 1 && block_reset.length ){ - var blast = block_reset.length - 1 ; - block_reset[ blast ] = undefined; - block_reset[ blast + lines.length - 1 ] = 1; - } - - } - - - text = ""; - - for( var i = 0; i< lines.length; i++ ){ - - var overwrite = lines[i].split( '\r' ); - - if( i ) text += "\n"; - else if( overwrite.length > 1 ) inline_replacement = true; - - if (overwrite.length > 1 ) { - var final_text = ""; - for( var j = overwrite.length - 1; j >= 0; j-- ){ - final_text = final_text + overwrite[j].substring( final_text.length ); - } - text += final_text; - } - else text += lines[i]; - } - - if( inline_replacement ){ - replace_end = { line: start, ch: ch }; - ch = 0; - } - - // for styling before we have built the table - if( unstyled ) unstyled_flag = true; - - doc.replaceRange( text, { line: start, ch: ch }, replace_end, "callback"); - end = doc.lastLine(); - lastline = doc.getLine(end); - var endch = lastline.length; - - if( unstyled ){ - var u_end = end; - if( endch == 0 ) u_end--; - if( u_end >= start ){ - for( var i = start; i<= u_end; i++ ) unstyled_lines[i] = 1; - } - } - - // can specify class - if( className ){ - doc.markText( { line: start, ch: ch }, { line: end, ch: endch }, { - className: className - }); - } - - // don't scroll in exec mode, on the theory that (1) we might get - // more messages, and (2) we'll scroll when we enter the caret - //if( state !== EXEC_STATE.EXEC ) - { - cm.scrollIntoView({line: doc.lastLine(), ch: endch}); - } - - // the problem with that is that it's annoying when you want to see - // the messages (for long-running code, for example). - - unstyled_flag = false; - - }; - - /** - * this is history in the sense of up arrow/down arrow in the shell. - * it's not really connected to any underlying history (although that - * would probably be useful). - * - * FIXME: move more of this into the history class - */ - function shell_history( up ){ - - if( state == EXEC_STATE.EXEC ) return; - - // can we move in this direction? [FIXME: bell?] - if( up && history.pointer >= history.commands.length ) return; - if( !up && history.pointer == 0 ) return; - - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - var line = doc.getLine( lineno ).substr(prompt_len); - - // capture current (see history class for note on soft persistence) - if( history.pointer == 0 ) history.current_line = line; - else history.commands[ history.commands.length - history.pointer ] = line; - - // move - if( up ) history.pointer++; - else history.pointer--; - - // at current, use our buffer - if( history.pointer == 0 ){ - doc.replaceRange( history.current_line, { line: lineno, ch: prompt_len }, {line: lineno, ch: prompt_len + line.length }, "history"); - } - else { - var text = history.commands[ history.commands.length - history.pointer ]; - doc.replaceRange( text, - { line: lineno, ch: prompt_len }, - { line: lineno, ch: prompt_len + line.length }, "history"); - } - - var linelen = cm.getLine( lineno ).length; - - // after changing the text the caret should be at the end of the line - // (and the line should be in view) - - cm.scrollIntoView( {line: lineno, ch: linelen }); - cm.getDoc().setSelection({ line: lineno, ch: linelen }); - - } - - /** - * set prompt with optional class - */ - function set_prompt( text, prompt_class, is_continuation ){ - - if( typeof prompt_class === "undefined" ) - prompt_class = DEFAULT_PROMPT_CLASS; - - if( typeof text === "undefined" ){ - if( instance.opts ) prompt_text = instance.opts.default_prompt; - else text = "? " ; - } - - prompt_text = text; - - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - var lastline = cm.getLine(lineno); - - if( !is_continuation ) block_reset[lineno] = 1; - - prompt_len = lastline.length + prompt_text.length; - - doc.replaceRange( prompt_text, { line: lineno, ch: lastline.length }, undefined, "prompt" ); - if( prompt_class ){ - doc.markText( { line: lineno, ch: lastline.length }, { line: lineno, ch: prompt_len }, { - className: prompt_class - }); - } - - doc.setSelection({ line: lineno, ch: prompt_len }); - cm.scrollIntoView({line: lineno, ch: prompt_len }); - - } - - /** - * external function to set a prompt. this is intended to be used with - * a delayed startup, where there may be text echoed to the screen (and - * hence we need an initialized console) before we know what the correct - * prompt is. - */ - this.prompt = function( text, className, is_continuation ){ - set_prompt( text, className, is_continuation ); - }; + /** + * when unblocking (exiting an explicit block or exec), + * replay cached keyboard events. in some cases a played-back + * event may trigger execution, which turns caching back on. + * in that case, stop processing and dump all the + * original source events back into the cache. + */ + var playbackEvents = function () { + // flush cache. set to null to act as flag + + var tmp = event_cache + event_cache = null + event_cache_skip = false + + if (tmp && tmp.length) { + console.log(`playbackEvents: tmp=${JSON.stringify(tmp)}`) + // FIXME + var inputTarget = view.getInputField() + tmp.forEach(function (src) { + if (event_cache) { + cacheEvent(src) + return + } + + var event = new KeyboardEvent(src.type, src) + Object.defineProperties(event, { + charCode: { + get: function () { + return src.charCode + }, + }, + which: { + get: function () { + return src.which + }, + }, + keyCode: { + get: function () { + return src.keyCode + }, + }, + key: { + get: function () { + return src.key + }, + }, + char: { + get: function () { + return src.char + }, + }, + target: { + get: function () { + return src.target + }, + }, + }) + event_playback = true + inputTarget.dispatchEvent(event) + event_playback = false + }) + } + } + + /** + * block. this is used for operations called by the code, rather than + * the user -- we don't want the user to be able to run commands, because + * they'll fail. + * @param {string} message + */ + this.block = function block(message) { + console.log(`block: state=${JSON.stringify(state)}`) + + // this bit is right from exec: + + if (state === EXEC_STATE.EXEC) { + return false + } + + console.log("block: view", view) + + var doc = view.state.doc + var lineno = doc.lines + var line = doc.line(lineno) + + console.log(`block: message=${JSON.stringify(message)}`) + + if (!message) message = "\n" + else message = "\n" + message + "\n" + + //doc.replaceRange( message, { line: lineno+1, ch: 0 }, undefined, "prompt"); + var pos = doc.line(doc.lines).from + view.dispatch({ changes: { from: pos, to: undefined, insert: message } }) + //view.dispatch({selection: {anchor: pos}}) + + state = EXEC_STATE.EXEC + + var command = line.text.slice(prompt_len) + command_buffer.push(command) + + if (command.trim().length > 0) { + history.push(command) + history.save() // this is perhaps unecessarily aggressive + } + + // this automatically resets the pointer (NOT windows style) + history.reset_pointer() + + // turn on event caching + event_cache = [] + + // now leave it in this state... + return true + } + + /** unblock, should be symmetrical. */ + this.unblock = function (result, ignore_cached_events) { + // again this is from exec (but we're skipping the + // bit about pasting) + + state = EXEC_STATE.EDIT + + if (result && result.prompt) { + command_buffer = [] + set_prompt( + result.prompt || instance.opts.initial_prompt, + result.prompt_class, + result.continuation + ) + } else { + var ps = result + ? result.parsestatus || PARSE_STATUS.OK + : PARSE_STATUS.NULL + if (ps === PARSE_STATUS.INCOMPLETE) { + set_prompt(instance.opts.continuation_prompt, undefined, true) + } else { + command_buffer = [] + set_prompt(instance.opts.initial_prompt) + } + } + + if (!ignore_cached_events) playbackEvents() + } + + /** + * get history as array + */ + this.get_history = function () { + return history.actual_commands.slice(0) + } + + /** + * insert an arbitrary node, via CM's widget + * + * @param scroll -- scroll to the following line so the node is visible + */ + this.insert_node = function (node, scroll) { + var doc = view.state.doc + var line = Math.max(doc.lines - 1, 0) + view.addLineWidget(line, node, { + handleMouseEvents: true, + }) + if (scroll) + view.dispatch({ effects: EditorView.scrollIntoView(doc.line(line).from) }) + } + + /** + * select all -- this doesn't seem to work using the standard event... ? + */ + this.select_all = function () { + //cm.execCommand( 'selectAll' ); + view.dispatch({ selection: { anchor: 0, head: view.state.doc.length } }) + } + + this.scrollToEnd = function scrollToEnd() { + + var doc = view.state.doc + + //console.log(`doc.length ${doc.length}`) + + // wait for new doc.length + //setImmediate(() => { + //console.log(`setImmediate doc.length ${doc.length}`) + // scroll to end + view.dispatch({ effects: EditorView.scrollIntoView(doc.length) }) + // set cursor + view.dispatch({ selection: { anchor: view.state.doc.length } }) + //}) + + } + + /** + * handler for command responses, stuff that the system + * sends to the shell (callbacks, generally). optional className is a + * style applied to the block. "unstyled", if set, prevents language + * styling on the block. + */ + this.response = function response(text, className, unstyled) { + // FIXME add newline after result + + console.log(`response: text=${JSON.stringify(text)}`) + + var doc = view.state.doc + var lineno = doc.lines + var end, + start = lineno + + if (text && typeof text !== "string") { + try { + text = text.toString() + } catch (e) { + text = "Unrenderable message: " + e.message + } + } + + // don't add newlines. respect existing length. this is so we + // can handle \r (without a \n). FIXME: if there's a prompt, go + // up one line. + + var lastline = doc.line(lineno) + var ch = lastline ? lastline.length : 0 + + // second cut, a little more thorough + // one more patch, to stop breaking on windows CRLFs + + var lines = text.split("\n") + var replace_end = undefined + var inline_replacement = false + + // fix here in case there's already a prompt (this is a rare case?) + + if (state !== EXEC_STATE.EXEC) { + ch = 0 // insert before anything else on line + + // this is new: in the event that there is already a prompt, + // and we are maintaining styling "breaks", then we may + // need to offset the last break by some number of lines. + + // actually we know it's only going to be the last one, so + // we can skip the loop. + + if (lines.length > 1 && block_reset.length) { + var blast = block_reset.length - 1 + block_reset[blast] = undefined + block_reset[blast + lines.length - 1] = 1 + } + } + + // parse carriage-return \r + text = "" + for (var i = 0; i < lines.length; i++) { + var overwrite = lines[i].split("\r") + if (i) text += "\n" + else if (overwrite.length > 1) inline_replacement = true + if (overwrite.length > 1) { + var final_text = "" + for (var j = overwrite.length - 1; j >= 0; j--) { + final_text = final_text + overwrite[j].substring(final_text.length) + } + text += final_text + } else text += lines[i] + } + console.log(`response: text2=${JSON.stringify(text)}`) + if (inline_replacement) { + replace_end = { line: start, ch: ch } + ch = 0 + } + + // for styling before we have built the table + if (unstyled) unstyled_flag = true + + //doc.replaceRange( text, { line: start, ch: ch }, replace_end, "callback"); + view.dispatch({ + changes: { + from: posToOffset(doc, { line: start, ch: ch }), + to: replace_end && posToOffset(doc, replace_end), + insert: text, + // TODO class callback? + }, + }) + + end = doc.lines + lastline = doc.line(end) + var endch = lastline.text.length + console.log( + `doc.lines=${doc.lines} lastline.text=${lastline.text} endch=${endch}` + ) + + // TODO what is this? + if (unstyled) { + var u_end = end + if (endch == 0) u_end-- + if (u_end >= start) { + for ( + // @ts-ignore + var i = start; + i <= u_end; + i++ + ) + unstyled_lines[i] = 1 + } + } + + // can specify class + /* FIXME + if( className ){ + doc.markText( { line: start, ch: ch }, { line: end, ch: endch }, { + className: className + }); + } + */ + + if (className) { + const from = posToOffset(doc, { line: start, ch: ch }) + const to = posToOffset(doc, { line: end, ch: endch }) + if (from < to) { + // https://codemirror.net/docs/migration/#marked-text + const strikeMark = Decoration.mark({ + attributes: { + //style: "text-decoration: line-through", + className: className, + }, + }) + console.dir([ + `addMarks: className = ${className}`, + { line: start, ch: ch }, + { line: end, ch: endch }, + ]) + view.dispatch({ + effects: addMarks.of([strikeMark.range(from, to)]), + }) + } + // else: range is empty + } + + // don't scroll in exec mode, on the theory that (1) we might get + // more messages, and (2) we'll scroll when we enter the caret + //if( state !== EXEC_STATE.EXEC ) + /* FIXME + { + cm.scrollIntoView({line: doc.lines, ch: endch}); + } + */ + + this.scrollToEnd() + + // the problem with that is that it's annoying when you want to see + // the messages (for long-running code, for example). + + unstyled_flag = false + } + + /** + * this is history in the sense of up arrow/down arrow in the shell. + * it's not really connected to any underlying history (although that + * would probably be useful). + * + * FIXME: move more of this into the history class + */ + function shell_history(up) { + if (state == EXEC_STATE.EXEC) return + + // can we move in this direction? [FIXME: bell?] + if (up && history.pointer >= history.commands.length) return + if (!up && history.pointer == 0) return + + var doc = view.state.doc + var lineno = doc.lines + var line = doc.line(lineno).text.slice(prompt_len) + + // capture current (see history class for note on soft persistence) + if (history.pointer == 0) history.current_line = line + else history.commands[history.commands.length - history.pointer] = line + + // move + if (up) history.pointer++ + else history.pointer-- + + // at current, use our buffer + if (history.pointer == 0) { + //doc.replaceRange( history.current_line, { line: lineno, ch: prompt_len }, {line: lineno, ch: prompt_len + line.length }, "history"); + view.dispatch({ + changes: { + from: posToOffset(doc, { line: lineno, ch: prompt_len }), + to: posToOffset(doc, { line: lineno, ch: prompt_len + line.length }), + insert: String(history.current_line), // FIXME + }, + }) + } else { + var text = history.commands[history.commands.length - history.pointer] + // FIXME + doc.replaceRange( + text, + { line: lineno, ch: prompt_len }, + { line: lineno, ch: prompt_len + line.length }, + "history" + ) + } + + var linelen = view.state.doc.line(lineno).text.length + + // after changing the text the caret should be at the end of the line + // (and the line should be in view) + + view.scrollIntoView({ line: lineno, ch: linelen }) + view.state.doc.setSelection({ line: lineno, ch: linelen }) + } + + /** + * set prompt with optional class + */ + function set_prompt(text, prompt_class, is_continuation) { + if (typeof prompt_class === "undefined") prompt_class = DEFAULT_PROMPT_CLASS + + if (typeof text === "undefined") { + if (instance.opts) prompt_text = instance.opts.default_prompt + else text = "? " + } + + prompt_text = text + + console.log("set_prompt: cm", view) + + var doc = view.state.doc + var lineno = doc.lines + console.log("set_prompt: doc.lines", doc.lines) + console.log( + "set_prompt: cm.state.doc.line(doc.lines)", + view.state.doc.line(doc.lines) + ) + var lastline = view.state.doc.line(lineno).text + + if (!is_continuation) block_reset[lineno] = 1 + + /* + const docLength = doc.length; + view.dispatch({changes: { + //from: posToOffset(doc, { line: lineno, ch: 0 }), + from: docLength, + to: undefined, + insert: "\n", + // TODO class prompt? + }}) + //doc.setCursor({ line: lineno+1, ch: 0 }); + //view.dispatch({selection: {anchor: posToOffset(doc, { line: lineno, ch: 0 })}}) + // doc.length is not-yet updated at this point + // so we use docLength + 1 + view.dispatch({selection: {anchor: docLength + 1}}) + */ + + prompt_len = lastline.length + prompt_text.length + + console.log(`set_prompt: lastline=${lastline} prompt_text=${prompt_text}`) + + //doc.replaceRange( prompt_text, { line: lineno, ch: lastline.length }, undefined, "prompt" ); + view.dispatch({ + changes: { + from: posToOffset(doc, { line: lineno, ch: lastline.length }), + to: undefined, + //insert: prompt_text, + insert: prompt_text, + }, + }) + + /* FIXME + if( prompt_class ){ + doc.markText( { line: lineno, ch: lastline.length }, { line: lineno, ch: prompt_len }, { + className: prompt_class + }); + } + */ + if (prompt_class) { + // https://codemirror.net/docs/migration/#marked-text + const strikeMark = Decoration.mark({ + attributes: { + //style: "text-decoration: line-through", + className: prompt_class, + }, + }) + false && + console.dir([ + `addMarks: prompt_class = ${prompt_class}`, + { line: lineno, ch: lastline.length }, + { line: lineno, ch: prompt_len }, + ]) + view.dispatch({ + effects: addMarks.of([ + strikeMark.range( + posToOffset(doc, { line: lineno, ch: lastline.length }), + posToOffset(doc, { line: lineno, ch: prompt_len }) + ), + ]), + }) + } + + /* FIXME + doc.setSelection({ line: lineno, ch: prompt_len }); + cm.scrollIntoView({line: lineno, ch: prompt_len }); + */ + } + + /** + * external function to set a prompt. this is intended to be used with + * a delayed startup, where there may be text echoed to the screen (and + * hence we need an initialized console) before we know what the correct + * prompt is. + */ + this.prompt = function (text, className, is_continuation) { + set_prompt(text, className, is_continuation) + } /** * for external client that wants to execute a block of code with * side effects -- as if the user had typed it in. */ - this.execute_block = function( code ){ - let lines = code.split( /\n/g ); - paste_buffer = paste_buffer.concat( lines ); - exec_line( cm ); + this.execute_block = function (code) { + let lines = code.split(/\n/g) + paste_buffer = paste_buffer.concat(lines) + exec_line(view) + } + + /** + * execute the current line. this happens on enter as + * well as on paste (in the case of paste, it might + * get called multiple times -- once for each line in + * the paste). + */ + function exec_line(view, cancel) { + if (state === EXEC_STATE.EXEC) { + return + } + + var doc = view.state.doc + var lineno = doc.lines + var line = doc.line(lineno) + console.log("line", line) + + // TODO what is this? + //doc.replaceRange( "\n", { line: lineno+1, ch: 0 }, undefined, "prompt"); + //var pos = doc.line(doc.lines).from; + // insert newline at end of document + const docLength = doc.length + view.dispatch({ + changes: { + //from: posToOffset(doc, { line: lineno, ch: 0 }), + from: docLength, + to: undefined, + insert: "\n", + // TODO class prompt? + }, + }) + //doc.setCursor({ line: lineno+1, ch: 0 }); + //view.dispatch({selection: {anchor: posToOffset(doc, { line: lineno, ch: 0 })}}) + // doc.length is not-yet updated at this point + // so we use docLength + 1 + //view.dispatch({selection: {anchor: docLength + 1}}) + + state = EXEC_STATE.EXEC + var command + + if (cancel) { + command = "" + command_buffer = [command] + } else { + command = line.text.slice(prompt_len) + command_buffer.push(command) + } + + // you can exec an empty line, but we don't put it into history. + // the container can just do nothing on an empty command, if it + // wants to, but it might want to know about it. + + if (command.trim().length > 0) { + history.push(command) + history.save() // this is perhaps unecessarily aggressive + } + + // this automatically resets the pointer (NOT windows style) + + history.reset_pointer() + + if (instance.opts.exec_function) { + // turn on event caching. if we're being called + // from a paste block, it might already be in place + // so don't destroy it. + + if (!event_cache) event_cache = [] + + console.log("command_buffer", command_buffer) + + instance.opts.exec_function.call( + this, + command_buffer, + // callback + function handleResult(result) { + //console.log(`handleResult: result=${JSON.stringify(result)}`) + // handleResult: result={"parsestatus":"OK"} + + // UPDATE: new style of return where the command processor + // handles the multiline-buffer (specifically for R's debugger). + + // in that case, always clear command buffer and accept the prompt + // from the callback. + + state = EXEC_STATE.EDIT + + if (result && result.prompt) { + command_buffer = [] + set_prompt( + result.prompt || instance.opts.initial_prompt, + result.prompt_class, + result.continuation + ) + } else { + var parseStatus = result + ? result.parsestatus || PARSE_STATUS.OK + : PARSE_STATUS.NULL + console.log( + `handleResult: parseStatus=${JSON.stringify(parseStatus)}` + ) + if (parseStatus === PARSE_STATUS.INCOMPLETE) { + set_prompt(instance.opts.continuation_prompt, undefined, true) + } else { + command_buffer = [] + set_prompt(instance.opts.initial_prompt) + } + } + + lineno = view.state.doc.lines + + if (paste_buffer.length) { + console.log(`handleResult: setImmediate paste`) + + setImmediate(function paste() { + var text = paste_buffer[0] + console.log( + `handleResult: setImmediate paste: text=${JSON.stringify(text)}` + ) + paste_buffer.splice(0, 1) + // FIXME 5to6 + doc.replaceRange( + text, + { line: lineno, ch: prompt_len }, + undefined, + "paste-continuation" + ) + + // if the last line of the paste buffer is a newline, then exec. + // otherwise enter the text on the line and play back cached events. + + if (paste_buffer.length) exec_line(view) + else playbackEvents() + }) + } else { + console.log(`handleResult: setImmediate playbackEvents`) + setImmediate(playbackEvents) + } + instance.scrollToEnd() + } + ) + } + } + + /** + * clear console. two things to note: (1) this does not work in + * exec state. (2) preserves last line, which we assume is a prompt/command. + */ + this.clear = function (focus) { + var doc = view.state.doc + var lastline = doc.lines + if (lastline > 0) { + view.dispatch({ + changes: { from: 0, to: doc.line(doc.lines).from, insert: "" }, + }) + } + + // reset unstyled + unstyled_lines.splice(0, unstyled_lines.length) + unstyled_flag = false + + block_reset.splice(0, block_reset.length) + + // move cursor to edit position + var text = doc.line(doc.lines) + // FIXME + doc.setSelection({ line: doc.lines, ch: text.length }) + + // optionally focus + if (focus) this.focus() + } + + /** + * get shell width in chars. not sure how CM gets this (possibly a dummy node?) + */ + this.get_width_in_chars = function () { + return ( + Math.floor(this.opts.container.clientWidth / view.defaultCharacterWidth) - + instance.opts.initial_prompt.length + ) + } + + /** refresh layout, force on nonstandard resizes */ + /* TODO migrate + this.refresh = function(){ + cm.refresh(); }; + */ + + /** + * cancel the current line; clear parse buffer and reset history. + */ + this.cancel = function () { + exec_line(view, true) + } + + /** + * get current line (peek) + */ + this.get_current_line = function () { + var doc = view.state.doc + var line = doc.line(doc.lines) + var cursor = view.state.selection.main.head + return { + text: line.text.slice(prompt_len), + //pos: ( index == pos.line ? pos.ch - prompt_len : -1 ), + pos: cursor ? cursor - prompt_len : -1, + } + } + + /** + * get line caret is on. may include prompt. + */ + this.get_caret_line = function () { + var cursor = view.state.selection.main.head + var line = view.state.doc.lineAt(cursor) + return { text: line, pos: cursor } + } + + /** + * get selections + */ + this.get_selections = function () { + return view.state.doc.getSelections() + } + + /** + * wrapper for focus call + */ + this.focus = function () { + view.focus() + } + + /** + * show function tip + */ + this.show_function_tip = function (text) { + if (!this.function_tip) this.function_tip = {} + if (text === this.function_tip.cached_tip) return + var where = view.cursorCoords() + this.function_tip.cached_tip = text + if (!this.function_tip.node) { + this.function_tip.container_node = document.createElement("div") + this.function_tip.container_node.className = + "cmjs-shell-function-tip-container" + this.function_tip.node = document.createElement("div") + this.function_tip.node.className = "cmjs-shell-function-tip" + this.function_tip.container_node.appendChild(this.function_tip.node) + opts.container.appendChild(this.function_tip.container_node) + } + this.function_tip.visible = true + this.function_tip.node.innerHTML = text + + // the container/child lets you relatively position the tip in css + this.function_tip.container_node.setAttribute( + "style", + "top: " + where.top + "px; left: " + where.left + "px;" + ) + this.function_tip.container_node.classList.add("visible") + } + + /** + * hide function tip. + * + * @return true if we consumed the event, or false + */ + this.hide_function_tip = function (user) { + if (!this.function_tip) return false + if (!user) this.function_tip.cached_tip = null + if (this.function_tip.visible) { + this.function_tip.container_node.classList.remove("visible") + this.function_tip.visible = false + return true + } + return false + } + + /** + * constructor body + */ + ;(function () { + opts = opts || {} + + // prompts + opts.initial_prompt = opts.initial_prompt || "> " + opts.continuation_prompt = opts.continuation_prompt || "+ " + + // dummy functions + opts.exec_function = + opts.exec_function || + function (cmd, callback) { + if (opts.debug) console.info("DUMMY") + var ps = PARSE_STATUS.OK + var err = null + if (cmd.length) { + if (cmd[cmd.length - 1].match(/_\s*$/)) ps = PARSE_STATUS.INCOMPLETE + } + callback.call(this, { parsestatus: ps, err: err }) + } + opts.function_key_callback = opts.function_key_callback || function () {} + + // container is string (id) or node + opts.container = opts.container || document.body + if (typeof opts.container === "string") { + opts.container = document.querySelector(opts.container) + } + + // special codemirror mode to support unstyled blocks (full lines only) + let modename = "unstyled-overlay" + init_overlay_mode(opts.mode) + + // remove default to inputStyle -> contenteditable. CM seems to be + // checking for key existence, so undefined doesn't work. add if necessary. + + let PS1 = "> " // node + //let PS1 = "~ $ " // bash + + // FIXME backspace-delete and arrow-keys should be limited to the writable ranges + // https://github.com/andrebnassis/codemirror-readonly-ranges/issues/3 + function getReadOnlyRanges(targetState) { + //console.log(`targetState.doc`, targetState.doc) + //return [] + if (targetState.doc.lines <= 1) { + return [] + } + //console.log(`targetState.doc.length=${targetState.doc.length} targetState.doc.lines=${targetState.doc.lines} lastLine.from=${targetState.doc.line(targetState.doc.lines - 1).from}`) + return [ + { + from: 0, + to: targetState.doc.line(targetState.doc.lines).from + PS1.length, + }, + ] + } + + /** @type {import("@codemirror/view").KeyBinding} */ + // FIXME not reached. parser throws + // FIXME parser is off, still not reached + const terminalKeymap = [ + { + key: "Enter", + preventDefault: true, // insert newline in exec_line + // cursor can be in the middle of the last line + run: (view, event) => { + console.log("Enter", view, event) + exec_line(view) + return true; // dont call other handlers + // defaultKeymap would insert \n + }, + }, + ] + + console.log("keymaps", { terminalKeymap, historyKeymap, defaultKeymap }) + + // NOTE this must come before other extensions like basicSetup + // https://discuss.codemirror.net/t/enter-and-backspace-key-not-passed-to-keydown-dom-event-handler/3887 + // FIXME TypeError: EditorView.domEventHandlers.of is not a function + /* + const handleEvents = EditorView.domEventHandlers.of({ + drop(event, view) { console.log("drop", event); }, + paste(event, view) { console.log("paste", event); }, + keydown(event, view) { console.log("keydown", event); }, + }) + */ + + // FIXME: this doesn't need to be global, if we can box it up then require() it + console.log("opts.container", opts.container) + view = new EditorView({ + extensions: [ + // FIXME use LRLanguage javascript + //instance.language, + markFieldExtension, + // FIXME cannot enter newline at end of document + // https://github.com/andrebnassis/codemirror-readonly-ranges/issues/4 + //readOnlyRangesExtension(getReadOnlyRanges), + // NO NOTE terminalKeymap must come before defaultKeymap, + // so we can handle "Enter" https://discuss.codemirror.net/t/enter-and-backspace-key-not-passed-to-keydown-dom-event-handler/3887 + keymap.of([...terminalKeymap, ...defaultKeymap, ...historyKeymap]), + //keymap.of([...terminalKeymap]), + //handleEvents, + ], + doc: "", + parent: opts.container, + //mode: modename, // opts.mode, + //allowDropFileTypes: opts.drop_files, + //viewportMargin: 50, + //inputStyle: opts.inputStyle, + /* + https://stackoverflow.com/questions/72404988/codemirror-6-how-to-get-editor-value-on-input-update-change-event + extensions: [ + EditorView.updateListener.of(function(e) { + sync_val = e.state.doc.toString(); + }) + ] + + https://stackoverflow.com/questions/72716094/how-to-programmatically-change-the-editors-value-in-codemirror-6 + view.dispatch({ + changes: {from: 0, to: editor.state.doc.length, insert: 'New Test Text'} + }); + + */ + /* + dispatch: (tr) => { + console.log("tr", tr); + if (tr.changes.empty == false) { + //tr.changes.mapPos() + //for (const change of tr.changes) { console.log("change", change); } + } + //view.dispatch(tr); // deadloop + }, + */ + }) + + var inputfield = view.contentDOM + + inputfield.addEventListener("keydown", cacheEvent) + inputfield.addEventListener("keyup", cacheEvent) + inputfield.addEventListener("keypress", cacheEvent) + inputfield.addEventListener("char", cacheEvent) + + // if you suppress the initial prompt, you must call the "prompt" method + + if (!opts.suppress_initial_prompt) set_prompt(opts.initial_prompt) + + var local_hint_function = null + if (opts.hint_function) { + local_hint_function = function (cm, callback) { + var doc = cm.state.doc + var line = doc.line(doc.lines) + var cursor = cm.state.selection.main.head + var plen = prompt_len + + opts.hint_function.call( + instance, + line.substr(plen), + cursor - plen, + function (completions, position) { + if (!completions || !completions.length) { + callback(null) + } else { + // FIXME cursor -> pos + callback({ + list: completions, + from: { line: pos.line, ch: position + plen }, + to: { line: pos.line, ch: cursor }, + }) + } + } + ) + } + // @ts-ignore + local_hint_function.async = true + } + + // FIXME handle events. dispatch? + + /* + + cm.on( "cut", function( cm, e ){ + if( state !== EXEC_STATE.EDIT ) e.preventDefault(); + else { + var doc = cm.state.doc; + var start = doc.getCursor( "from" ); + var end = doc.getCursor( "to" ); + var line = doc.lines; + if( start.line !== line + || end.line !== line + || start.ch < prompt_len + || end.ch < prompt_len + || start.ch === end.ch ) e.preventDefault(); + } + }); + + cm.on( "cursorActivity", function(cm, e){ + var cursor = cm.state.selection.main.head; + var doc = cm.state.doc; + var lineno = doc.lines; + var lastline = doc.line( lineno ); + if( pos.line !== lineno || pos.ch < prompt_len ){ + cm.setOption( "cursorBlinkRate", 0 ); + } + else if( state === EXEC_STATE.EXEC + && pos.line === lineno + && pos.ch == lastline.length ){ + cm.setOption( "cursorBlinkRate", -1 ); + } + else cm.setOption( "cursorBlinkRate", 530 ); // CM default -- make an option? + }); + + cm.on( "change", function( cm, e ){ + if( e.origin && e.origin[0] === "+" ){ + var doc = cm.state.doc; + var lastline = doc.lines; + if( opts.tip_function ) opts.tip_function( doc.line( lastline ), e.from.ch + e.text.length ); + } + else { + instance.hide_function_tip( true ); + } + }); + + // notification listener for CM scroll event, + // which may be more useful that normal scroll event + if( opts.scroll ){ + cm.on( "scroll", opts.scroll ); + } + + // notification listener for CM viewport change event + if( opts.viewport_change ){ + cm.on( "viewportChange", opts.viewport_change ); + }; + + cm.on( "beforeChange", function(cm, e){ + + // todo: split paste into separate lines, + // paste with carets and exec in order (line-by-line) + + if( e.origin ){ + + var doc = cm.state.doc; + var lastline = doc.lines; + + if( e.origin[0] === "+" ){ + if( state === EXEC_STATE.EXEC ) e.cancel(); + if( e.from.line != lastline ){ + e.to.line = e.from.line = lastline; + e.from.ch = e.to.ch = doc.line( lastline ).length; + } + else if( e.from.ch < prompt_len ){ + e.from.ch = e.to.ch = prompt_len; + } + } + else if( e.origin === "undo" ){ + if( state !== EXEC_STATE.EDIT ) e.cancel(); + if( e.from.line !== lastline + || e.to.line !== lastline + || e.from.ch < prompt_len + || e.to.ch < prompt_len + || e.from.ch === e.to.ch ) e.cancel(); + } + else if( e.origin === "paste" ){ + if( state !== EXEC_STATE.EDIT ) e.cancel(); + + // text is split into multiple lines, which is handy. + // if the last line includes a carriage return, then + // that becomes a new (empty) entry in the array. + + if( e.from.line != lastline ){ + e.to.line = e.from.line = lastline; + e.from.ch = e.to.ch = doc.line( lastline ).length; + } + else if( e.from.ch < prompt_len ){ + e.from.ch = e.to.ch = prompt_len; + } + + // after adjusting for position (above), we don't + // have to do anything for a paste w/o newline. + + if( e.text.length === 1 ) return; + + // there's a bit of weirdness with text after the + // paste position if the paste has newlines. take whatever's + // on the line AFTER the paste position and store that + // in the paste array (FIXME: need to not execute it, + // but we can't edit the document in this callback). + + // capture lines after 1 + + paste_buffer = e.text.slice(1); + + // and drop from the paste + + e.text.splice(1); + + // do the exec after CM has finished processing the change + + setImmediate(function(){ + exec_line( cm ); + }); + + } + } + // dev // else console.info( e.origin ); + }); + + cm.setOption("extraKeys", { + + // command history + Up: function(cm){ + if( event_cache ) return; + + shell_history( true ); + }, + Down: function(cm){ + if( event_cache ) return; + + shell_history( false ); + }, + + Esc: function(cm){ + + if( event_cache ){ + opts.function_key_callback( 'esc' ); + event_cache = []; + } + else { + // don't pass through if we consume it + if( !instance.hide_function_tip( true )) + opts.function_key_callback( 'esc' ); + } + }, + + F3: function(cm){ + if( event_cache ) return; + + opts.function_key_callback( 'f3' ); + }, + + // keep in bounds + Left: function(cm){ + if( event_cache ) return; + + var cursor = cm.state.selection.main.head; + var doc = cm.state.doc; + var lineno = doc.lines; + + if( pos.line < lineno ){ + doc.setSelection({ line: lineno, ch: doc.line(lineno).length }); + } + else if( pos.ch > prompt_len ){ + doc.setSelection({ line: lineno, ch: pos.ch-1 }); + } + }, + + Right: function(cm){ + if( event_cache ) return; + + var cursor = cm.state.selection.main.head; + var doc = cm.state.doc; + var lineno = doc.lines; + + if( pos.line < lineno ){ + doc.setCursor({ line: lineno, ch: doc.line(lineno).length }); + } + else if( pos.ch < prompt_len ){ + doc.setCursor({ line: lineno, ch: prompt_len }); + } + else { + doc.setCursor({ line: lineno, ch: pos.ch+1 }); + } + }, + + 'Ctrl-Left': function(cm){ + if( event_cache ) return; + + var cursor = cm.state.selection.main.head; + var doc = cm.state.doc; + var lineno = doc.lines; + if( pos.line < lineno ){ + doc.setCursor({ line: lineno, ch: doc.line(lineno).length }); + } + else if( pos.ch <= prompt_len ){ + doc.setCursor({ line: lineno, ch: prompt_len }); + } + else return CodeMirror_.Pass + }, + + 'Ctrl+Right': function(cm){ + if( event_cache ) return; + + var cursor = cm.state.selection.main.head; + var doc = cm.state.doc; + var lineno = doc.lines; + if( pos.line < lineno ){ + doc.setCursor({ line: lineno, ch: doc.line(lineno).length }); + } + else if( pos.ch < prompt_len ){ + doc.setCursor({ line: lineno, ch: prompt_len }); + } + else { + return CodeMirror_.pass; + } + + }, + + Home: function(cm){ + if( event_cache ) return; + + var doc = cm.state.doc; + doc.setSelection({ line: doc.lines, ch: prompt_len }); + }, + + Tab: function(cm){ + if( event_cache ) return; + + if( opts.hint_function ){ + + // we're treating this slightly differently by passing only + // (1) the current line, and (2) the caret position in that + // line (offset for prompt) + + cm.showHint({ + hint: local_hint_function + }); + + } + }, + + // exec + Enter: function(cm) { + if( event_cache ) return; + event_cache_skip = true; + exec_line( cm ); + } + + }); + */ + + // FIXME: optional + history.restore() + + // expose the options object + instance.opts = opts - /** - * execute the current line. this happens on enter as - * well as on paste (in the case of paste, it might - * get called multiple times -- once for each line in - * the paste). - */ - function exec_line( cm, cancel ){ - - if( state === EXEC_STATE.EXEC ){ - return; - } - - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - var line = doc.getLine( lineno ); - - doc.replaceRange( "\n", { line: lineno+1, ch: 0 }, undefined, "prompt"); - doc.setCursor({ line: lineno+1, ch: 0 }); - - state = EXEC_STATE.EXEC; - var command; - - if( cancel ){ - command = ""; - command_buffer = [command]; - } - else { - command = line.substr(prompt_len); - command_buffer.push(command); - - } - - // you can exec an empty line, but we don't put it into history. - // the container can just do nothing on an empty command, if it - // wants to, but it might want to know about it. - - if( command.trim().length > 0 ){ - - history.push(command); - history.save(); // this is perhaps unecessarily aggressive - - } - - // this automatically resets the pointer (NOT windows style) - - history.reset_pointer(); - - if( instance.opts.exec_function ){ - - // turn on event caching. if we're being called - // from a paste block, it might already be in place - // so don't destroy it. - - if( !event_cache ) event_cache = []; - - instance.opts.exec_function.call( this, command_buffer, function(rslt){ - - // UPDATE: new style of return where the command processor - // handles the multiline-buffer (specifically for R's debugger). - - // in that case, always clear command buffer and accept the prompt - // from the callback. - - state = EXEC_STATE.EDIT; - - if( rslt && rslt.prompt ){ - command_buffer = []; - set_prompt( rslt.prompt || instance.opts.initial_prompt, rslt.prompt_class, rslt.continuation ); - } - else { - var ps = rslt ? rslt.parsestatus || PARSE_STATUS.OK : PARSE_STATUS.NULL; - if( ps === PARSE_STATUS.INCOMPLETE ){ - set_prompt( instance.opts.continuation_prompt, undefined, true ); - } - else { - command_buffer = []; - set_prompt( instance.opts.initial_prompt ); - } - } - - lineno = cm.getDoc().lastLine(); - - if( paste_buffer.length ){ - - setImmediate( function(){ - var text = paste_buffer[0]; - paste_buffer.splice(0,1); - doc.replaceRange( text, { line: lineno, ch: prompt_len }, undefined, "paste-continuation"); - - // if the last line of the paste buffer is a newline, then exec. - // otherwise enter the text on the line and play back cached events. - - if( paste_buffer.length ) exec_line(cm); - else playbackEvents(); - - }); - } - else { - setImmediate( function(){ - playbackEvents(); - }); - } - - }); - } - - } - - /** - * clear console. two things to note: (1) this does not work in - * exec state. (2) preserves last line, which we assume is a prompt/command. - */ - this.clear = function(focus){ - - var doc = cm.getDoc(); - var lastline = doc.lastLine(); - if( lastline > 0 ){ - doc.replaceRange( "", { line: 0, ch: 0 }, { line: lastline, ch: 0 }); - } - - // reset unstyled - unstyled_lines.splice(0, unstyled_lines.length); - unstyled_flag = false; - - block_reset.splice(0, block_reset.length); - - // move cursor to edit position - var text = doc.getLine( doc.lastLine()); - doc.setSelection({ line: doc.lastLine(), ch: text.length }); - - // optionally focus - if( focus ) this.focus(); - - }; - - /** - * get shell width in chars. not sure how CM gets this (possibly a dummy node?) - */ - this.get_width_in_chars = function(){ - return Math.floor( this.opts.container.clientWidth / cm.defaultCharWidth()) - instance.opts.initial_prompt.length; - }; - - /** refresh layout, force on nonstandard resizes */ - this.refresh = function(){ - cm.refresh(); - }; - - /** - * cancel the current line; clear parse buffer and reset history. - */ - this.cancel = function(){ - exec_line( cm, true ); - }; - - /** - * get current line (peek) - */ - this.get_current_line = function(){ - var doc = cm.getDoc(); - var index = doc.lastLine(); - var line = doc.getLine(index); - var pos = cm.getCursor(); - return { text: line.substr( prompt_len ), - pos: ( index == pos.line ? pos.ch - prompt_len : -1 ) - }; - }; - - /** - * get line caret is on. may include prompt. - */ - this.get_caret_line = function(){ - var doc = cm.getDoc(); - var pos = cm.getCursor(); - var line = doc.getLine(pos.line); - return { text: line, pos: pos.ch }; - }; - - /** - * get selections - */ - this.get_selections = function(){ - return cm.getDoc().getSelections(); - }; - - /** - * wrapper for focus call - */ - this.focus = function(){ cm.focus(); }; - - /** - * show function tip - */ - this.show_function_tip = function( text ){ - - if( !this.function_tip ) this.function_tip = {}; - if( text === this.function_tip.cached_tip ) return; - var where = cm.cursorCoords(); - this.function_tip.cached_tip = text; - if( !this.function_tip.node ){ - this.function_tip.container_node = document.createElement( "div" ); - this.function_tip.container_node.className = "cmjs-shell-function-tip-container"; - this.function_tip.node = document.createElement( "div" ); - this.function_tip.node.className = "cmjs-shell-function-tip"; - this.function_tip.container_node.appendChild( this.function_tip.node ); - opts.container.appendChild(this.function_tip.container_node); - } - this.function_tip.visible = true; - this.function_tip.node.innerHTML = text; - - // the container/child lets you relatively position the tip in css - this.function_tip.container_node.setAttribute( "style", "top: " + where.top + "px; left: " + where.left + "px;" ); - this.function_tip.container_node.classList.add( "visible" ); - }; - - /** - * hide function tip. - * - * @return true if we consumed the event, or false - */ - this.hide_function_tip = function( user ){ - if( !this.function_tip ) return false; - if( !user ) this.function_tip.cached_tip = null; - if( this.function_tip.visible ){ - this.function_tip.container_node.classList.remove( "visible" ); - this.function_tip.visible = false; - return true; - } - return false; - }; - - /** - * constructor body - */ - (function(){ - - opts = opts || {}; - - // prompts - opts.initial_prompt = opts.initial_prompt || "> "; - opts.continuation_prompt = opts.continuation_prompt || "+ "; - - // dummy functions - opts.exec_function = opts.exec_function || function( cmd, callback ){ - if( opts.debug ) console.info( "DUMMY" ); - var ps = PARSE_STATUS.OK; - var err = null; - if( cmd.length ){ - if( cmd[cmd.length-1].match( /_\s*$/)) ps = PARSE_STATUS.INCOMPLETE; - } - callback.call(this, { parsestatus: ps, err: err }); - }; - opts.function_key_callback = opts.function_key_callback || function(){}; - - // container is string (id) or node - opts.container = opts.container || document.body; - if( typeof( opts.container ) === "string" ){ - opts.container = document.querySelector(opts.container); - } - - // special codemirror mode to support unstyled blocks (full lines only) - let modename = "unstyled-overlay"; - init_overlay_mode( CodeMirror_, opts.mode, modename ); - - // remove default to inputStyle -> contenteditable. CM seems to be - // checking for key existence, so undefined doesn't work. add if necessary. - let cm_opts = { - value: "", - mode: modename, // opts.mode, - allowDropFileTypes: opts.drop_files, - viewportMargin: 50 - }; - if( opts.inputStyle ) cm_opts.inputStyle = opts.inputStyle; - - // FIXME: this doesn't need to be global, if we can box it up then require() it - cm = CodeMirror_( function(elt){opts.container.appendChild( elt ); }, cm_opts ); - - var inputfield = cm.getInputField(); - - inputfield.addEventListener( "keydown", cacheEvent ); - inputfield.addEventListener( "keyup", cacheEvent ); - inputfield.addEventListener( "keypress", cacheEvent ); - inputfield.addEventListener( "char", cacheEvent ); - - // if you suppress the initial prompt, you must call the "prompt" method - - if( !opts.suppress_initial_prompt ) set_prompt( opts.initial_prompt ); - - var local_hint_function = null; - if( opts.hint_function ){ - local_hint_function = function( cm, callback ){ - - var doc = cm.getDoc(); - var line = doc.getLine(doc.lastLine()); - var pos = cm.getCursor(); - var plen = prompt_len; - - opts.hint_function.call( instance, line.substr(plen), pos.ch - plen, function( completions, position ){ - if( !completions || !completions.length ){ - callback(null); - } - else { - callback({ list: completions, - from: { line: pos.line, ch: position + plen }, - to: { line: pos.line, ch: pos.ch } }); - } - }); - - }; - local_hint_function.async = true; - } - - cm.on( "cut", function( cm, e ){ - if( state !== EXEC_STATE.EDIT ) e.preventDefault(); - else { - var doc = cm.getDoc(); - var start = doc.getCursor( "from" ); - var end = doc.getCursor( "to" ); - var line = doc.lastLine(); - if( start.line !== line - || end.line !== line - || start.ch < prompt_len - || end.ch < prompt_len - || start.ch === end.ch ) e.preventDefault(); - } - }); - - cm.on( "cursorActivity", function(cm, e){ - var pos = cm.getCursor(); - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - var lastline = doc.getLine( lineno ); - if( pos.line !== lineno || pos.ch < prompt_len ){ - cm.setOption( "cursorBlinkRate", 0 ); - } - else if( state === EXEC_STATE.EXEC - && pos.line === lineno - && pos.ch == lastline.length ){ - cm.setOption( "cursorBlinkRate", -1 ); - } - else cm.setOption( "cursorBlinkRate", 530 ); // CM default -- make an option? - }); - - cm.on( "change", function( cm, e ){ - if( e.origin && e.origin[0] === "+" ){ - var doc = cm.getDoc(); - var lastline = doc.lastLine(); - if( opts.tip_function ) opts.tip_function( doc.getLine( lastline ), e.from.ch + e.text.length ); - } - else { - instance.hide_function_tip( true ); - } - }); - - // notification listener for CM scroll event, - // which may be more useful that normal scroll event - if( opts.scroll ){ - cm.on( "scroll", opts.scroll ); - } - - // notification listener for CM viewport change event - if( opts.viewport_change ){ - cm.on( "viewportChange", opts.viewport_change ); - }; - - cm.on( "beforeChange", function(cm, e){ - - // todo: split paste into separate lines, - // paste with carets and exec in order (line-by-line) - - if( e.origin ){ - - var doc = cm.getDoc(); - var lastline = doc.lastLine(); - - if( e.origin[0] === "+" ){ - if( state === EXEC_STATE.EXEC ) e.cancel(); - if( e.from.line != lastline ){ - e.to.line = e.from.line = lastline; - e.from.ch = e.to.ch = doc.getLine( lastline ).length; - } - else if( e.from.ch < prompt_len ){ - e.from.ch = e.to.ch = prompt_len; - } - } - else if( e.origin === "undo" ){ - if( state !== EXEC_STATE.EDIT ) e.cancel(); - if( e.from.line !== lastline - || e.to.line !== lastline - || e.from.ch < prompt_len - || e.to.ch < prompt_len - || e.from.ch === e.to.ch ) e.cancel(); - } - else if( e.origin === "paste" ){ - if( state !== EXEC_STATE.EDIT ) e.cancel(); - - // text is split into multiple lines, which is handy. - // if the last line includes a carriage return, then - // that becomes a new (empty) entry in the array. - - if( e.from.line != lastline ){ - e.to.line = e.from.line = lastline; - e.from.ch = e.to.ch = doc.getLine( lastline ).length; - } - else if( e.from.ch < prompt_len ){ - e.from.ch = e.to.ch = prompt_len; - } - - // after adjusting for position (above), we don't - // have to do anything for a paste w/o newline. - - if( e.text.length === 1 ) return; - - // there's a bit of weirdness with text after the - // paste position if the paste has newlines. take whatever's - // on the line AFTER the paste position and store that - // in the paste array (FIXME: need to not execute it, - // but we can't edit the document in this callback). - - // capture lines after 1 - - paste_buffer = e.text.slice(1); - - // and drop from the paste - - e.text.splice(1); - - // do the exec after CM has finished processing the change - - setImmediate(function(){ - exec_line( cm ); - }); - - } - } - // dev // else console.info( e.origin ); - }); - - cm.setOption("extraKeys", { - - // command history - Up: function(cm){ - if( event_cache ) return; - - shell_history( true ); - }, - Down: function(cm){ - if( event_cache ) return; - - shell_history( false ); - }, - - Esc: function(cm){ - - if( event_cache ){ - opts.function_key_callback( 'esc' ); - event_cache = []; - } - else { - // don't pass through if we consume it - if( !instance.hide_function_tip( true )) - opts.function_key_callback( 'esc' ); - } - }, - - F3: function(cm){ - if( event_cache ) return; - - opts.function_key_callback( 'f3' ); - }, - - // keep in bounds - Left: function(cm){ - if( event_cache ) return; - - var pos = cm.getCursor(); - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - - if( pos.line < lineno ){ - doc.setSelection({ line: lineno, ch: doc.getLine(lineno).length }); - } - else if( pos.ch > prompt_len ){ - doc.setSelection({ line: lineno, ch: pos.ch-1 }); - } - }, - - Right: function(cm){ - if( event_cache ) return; - - var pos = cm.getCursor(); - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - - if( pos.line < lineno ){ - doc.setCursor({ line: lineno, ch: doc.getLine(lineno).length }); - } - else if( pos.ch < prompt_len ){ - doc.setCursor({ line: lineno, ch: prompt_len }); - } - else { - doc.setCursor({ line: lineno, ch: pos.ch+1 }); - } - }, - - 'Ctrl-Left': function(cm){ - if( event_cache ) return; - - var pos = cm.getCursor(); - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - if( pos.line < lineno ){ - doc.setCursor({ line: lineno, ch: doc.getLine(lineno).length }); - } - else if( pos.ch <= prompt_len ){ - doc.setCursor({ line: lineno, ch: prompt_len }); - } - else return CodeMirror_.Pass - }, - - 'Ctrl+Right': function(cm){ - if( event_cache ) return; - - var pos = cm.getCursor(); - var doc = cm.getDoc(); - var lineno = doc.lastLine(); - if( pos.line < lineno ){ - doc.setCursor({ line: lineno, ch: doc.getLine(lineno).length }); - } - else if( pos.ch < prompt_len ){ - doc.setCursor({ line: lineno, ch: prompt_len }); - } - else { - return CodeMirror_.pass; - } - - }, - - Home: function(cm){ - if( event_cache ) return; - - var doc = cm.getDoc(); - doc.setSelection({ line: doc.lastLine(), ch: prompt_len }); - }, - - Tab: function(cm){ - if( event_cache ) return; - - if( opts.hint_function ){ - - // we're treating this slightly differently by passing only - // (1) the current line, and (2) the caret position in that - // line (offset for prompt) - - cm.showHint({ - hint: local_hint_function - }); - - } - }, - - // exec - Enter: function(cm) { - if( event_cache ) return; - event_cache_skip = true; - exec_line( cm ); - } - - }); - - // FIXME: optional - history.restore(); - - // expose the options object - instance.opts = opts; - - // this is exported for debug purposes (FIXME: flag) - if( opts.debug ) instance.cm = cm; - - })(); - -}; - -// export the enum types on the prototype -Shell.prototype.EXEC_STATE = EXEC_STATE; -Shell.prototype.PARSE_STATUS = PARSE_STATUS; - -// and the factory as a module (or to the browser) -if( typeof module !== "undefined" ) module.exports = Shell; -else window.Shell = Shell; - -})(); + // this is exported for debug purposes (FIXME: flag) + if (opts.debug) instance.cm = view + })() +}