From d12f0d2c5939ac0289b5fd06cca2eba6687b3b21 Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Fri, 10 Jul 2026 10:46:55 -0700 Subject: [PATCH 1/6] Rich SQL editor completions: column types, view columns, ranking _editor_schema() emits lang-sql Completion objects (column type as detail, boost above keywords) and gives views their real columns via PRAGMA table_xinfo in a self/children container labelled 'view'. _table_columns() is unchanged for the write-template path. Note the table_columns field in the database JSON context now carries this richer shape. Co-Authored-By: Claude Fable 5 --- datasette/views/database.py | 11 +++-- datasette/views/execute_write.py | 4 +- datasette/views/query_helpers.py | 51 +++++++++++++++++++++ tests/test_queries.py | 77 ++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 5 deletions(-) diff --git a/datasette/views/database.py b/datasette/views/database.py index 10dc66ae..d9ca8012 100644 --- a/datasette/views/database.py +++ b/datasette/views/database.py @@ -36,7 +36,10 @@ from datasette.utils.asgi import AsgiFileDownload, NotFound, Response, Forbidden from datasette.plugins import pm from .base import DatasetteError, View, stream_csv -from .query_helpers import _ensure_stored_query_execution_permissions, _table_columns +from .query_helpers import ( + _ensure_stored_query_execution_permissions, + _editor_schema, +) from .table_extras import ( QueryExtraContext, resolve_query_extras, @@ -201,7 +204,7 @@ class DatabaseView(View): "queries_count": queries_count, "allow_execute_sql": allow_execute_sql, "table_columns": ( - await _table_columns(datasette, database) if allow_execute_sql else {} + await _editor_schema(datasette, database) if allow_execute_sql else {} ), "metadata": await datasette.get_database_metadata(database), } @@ -242,7 +245,7 @@ class DatabaseView(View): queries_count=queries_count, allow_execute_sql=allow_execute_sql, table_columns=( - await _table_columns(datasette, database) + await _editor_schema(datasette, database) if allow_execute_sql else {} ), @@ -1094,7 +1097,7 @@ class QueryView(View): datasette, database, request, rows, columns ), table_columns=( - await _table_columns(datasette, database) + await _editor_schema(datasette, database) if allow_execute_sql else {} ), diff --git a/datasette/views/execute_write.py b/datasette/views/execute_write.py index dd35b127..f51b1f45 100644 --- a/datasette/views/execute_write.py +++ b/datasette/views/execute_write.py @@ -21,6 +21,7 @@ from .query_helpers import ( _inserted_row_url, _json_or_form_payload, _prepare_execute_write, + _editor_schema, _table_columns, _wants_json, ) @@ -266,6 +267,7 @@ class ExecuteWriteView(BaseView): write_template_tables = await _write_template_tables( self.ds, db, table_columns, hidden_table_names, request.actor ) + editor_schema = await _editor_schema(self.ds, db.name) write_template_operations = _write_template_operations(write_template_tables) write_create_table_template_sql = await _create_table_template_sql( self.ds, db, request.actor @@ -328,7 +330,7 @@ class ExecuteWriteView(BaseView): "sql_parameter_name_prefix": SQL_PARAMETER_FORM_PREFIX, "execute_disabled": bool(execute_disabled_reason), "execute_disabled_reason": execute_disabled_reason, - "table_columns": table_columns, + "table_columns": editor_schema, "write_template_tables": write_template_tables, "write_template_operations": write_template_operations, "write_create_table_template_sql": write_create_table_template_sql, diff --git a/datasette/views/query_helpers.py b/datasette/views/query_helpers.py index 588891d4..0e02f2eb 100644 --- a/datasette/views/query_helpers.py +++ b/datasette/views/query_helpers.py @@ -634,3 +634,54 @@ async def _table_columns(datasette, database_name): for view_name in await db.view_names(): table_columns[view_name] = [] return table_columns + + +def _column_completion(name, type_): + # A @codemirror/lang-sql Completion object for a single column. boost keeps + # columns ranked above bare SQL keywords in the autocomplete popup. + completion = { + "label": name, + "type": "property", + "boost": 10, + } + if type_: + completion["detail"] = type_ + return completion + + +async def _editor_schema(datasette, database_name): + """ + Build a lang-sql SQLNamespace for the CodeMirror SQL editor autocomplete. + + Returns a dict keyed by table or view name. Table values are lists of + Completion objects (one per column, carrying the column's SQLite type as + ``detail``). Views are wrapped in a ``{"self": Completion, "children": [...]}`` + container so the popup can label them as views while still completing their + real columns. See @codemirror/lang-sql >= 6.6 SQLNamespace / Completion. + """ + internal_db = datasette.get_internal_database() + result = await internal_db.execute( + "select table_name, name, type from catalog_columns where database_name = ?", + [database_name], + ) + schema = {} + for row in result.rows: + schema.setdefault(row["table_name"], []).append( + _column_completion(row["name"], row["type"]) + ) + # Views are not represented in catalog_columns, so pull their real columns + # directly (PRAGMA table_xinfo works against views too). + db = datasette.get_database(database_name) + for view_name in await db.view_names(): + columns = await db.table_column_details(view_name) + schema[view_name] = { + "self": { + "label": view_name, + "type": "class", + "detail": "view", + }, + "children": [ + _column_completion(column.name, column.type) for column in columns + ], + } + return schema diff --git a/tests/test_queries.py b/tests/test_queries.py index ffa948a9..bd2e2b95 100644 --- a/tests/test_queries.py +++ b/tests/test_queries.py @@ -94,6 +94,83 @@ async def test_queries_internal_table_schema(): ] +@pytest.mark.asyncio +async def test_editor_schema_rich_completions(): + from datasette.fixtures import TABLES + from datasette.views.query_helpers import _editor_schema + + ds = Datasette(memory=True) + db = ds.add_memory_database("editor_schema") + await ds.invoke_startup() + await db.execute_write_script(TABLES) + await ds.refresh_schemas() + + schema = await _editor_schema(ds, "editor_schema") + + # Tables are plain lists of Completion objects carrying type + boost + attractions = schema["roadside_attractions"] + assert isinstance(attractions, list) + pk_completion = next(c for c in attractions if c["label"] == "pk") + assert pk_completion == { + "label": "pk", + "type": "property", + "boost": 10, + "detail": "INTEGER", + } + # Every column completion is boosted above bare keywords + assert all(c["boost"] == 10 and c["type"] == "property" for c in attractions) + + # Views are wrapped in a self/children container labelled as a view + view = schema["paginated_view"] + assert view["self"] == { + "label": "paginated_view", + "type": "class", + "detail": "view", + } + child_labels = [c["label"] for c in view["children"]] + assert child_labels == ["content", "content_extra"] + # Column type inherited from the underlying table flows through as detail; + # the computed expression column has no declared type so carries no detail + content = next(c for c in view["children"] if c["label"] == "content") + assert content["detail"] == "TEXT" + content_extra = next(c for c in view["children"] if c["label"] == "content_extra") + assert "detail" not in content_extra + + # Whole payload must be JSON-serializable + json.dumps(schema) + + +@pytest.mark.asyncio +async def test_database_page_editor_schema_permission_gated(): + import secrets + from datasette.database import Database + from datasette.fixtures import TABLES + + async def schema_for(datasette): + # Unique memory name so parallel instances don't share a backing DB + name = f"editor_gated_{secrets.token_hex(8)}" + db = datasette.add_database( + Database(datasette, memory_name=name), name="editor_gated" + ) + await datasette.invoke_startup() + await db.execute_write_script(TABLES) + await datasette.refresh_schemas() + response = await datasette.client.get("/editor_gated.json") + assert response.status_code == 200 + return response.json()["table_columns"] + + # execute-sql allowed (default): rich schema is emitted + allowed = await schema_for(Datasette(memory=True)) + assert isinstance(allowed["roadside_attractions"], list) + assert allowed["paginated_view"]["self"]["detail"] == "view" + + # execute-sql denied: no schema leak, empty dict + denied = await schema_for( + Datasette(memory=True, settings={"default_allow_sql": False}) + ) + assert denied == {} + + @pytest.mark.asyncio async def test_add_get_and_remove_query(): ds = Datasette(memory=True) From 7e555b01f61c9dd5473905b768bfb421e9d27236 Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Fri, 10 Jul 2026 10:47:47 -0700 Subject: [PATCH 2/6] SQL editor: dynamic schema updates via Compartment (editor.updateSchema) Per-view Compartment wraps the sql() extension; window.editor.updateSchema( {schema, defaultTable, defaultSchema}) reconfigures autocomplete live. Declares @codemirror/state as a direct dependency since it is now imported directly. Co-Authored-By: Claude Fable 5 --- datasette/static/cm-editor.bundle.js | 2 +- datasette/static/cm-editor.js | 31 +++++++++++++++++++++------- package-lock.json | 1 + package.json | 1 + 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/datasette/static/cm-editor.bundle.js b/datasette/static/cm-editor.bundle.js index 3705ba06..4a1c1bf6 100644 --- a/datasette/static/cm-editor.bundle.js +++ b/datasette/static/cm-editor.bundle.js @@ -1 +1 @@ -var cm=function(t){"use strict";let e=[],i=[];function n(t){if(t<768)return!1;for(let n=0,s=e.length;;){let r=n+s>>1;if(t=i[r]))return!0;n=r+1}if(n==s)return!1}}function s(t){return t>=127462&&t<=127487}(()=>{let t="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let n=0,s=0;n=0&&s(a(t,n));)i++,n-=2;if(i%2==0)break;e+=2}}}return e}function l(t,e,i){for(;e>1;){let n=o(t,e-2,i);if(n=56320&&t<57344}function c(t){return t>=55296&&t<56320}function u(t){return t<65536?1:2}class f{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=x(this,t,e);let n=[];return this.decompose(0,t,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(e,this.length,n,1),p.from(n,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=x(this,t,e);let i=[];return this.decompose(t,e,i,0),p.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),n=new v(this),s=new v(t);for(let t=e,r=e;;){if(n.next(t),s.next(t),t=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(r+=n.value.length,n.done||r>=i)return!0}}iter(t=1){return new v(this,t)}iterRange(t,e=this.length){return new w(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let n=this.line(t).from;i=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new b(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(0==t.length)throw new RangeError("A document must have at least one line");return 1!=t.length||t[0]?t.length<=32?new d(t):p.from(d.split(t,[])):f.empty}}class d extends f{constructor(t,e=function(t){let e=-1;for(let i of t)e+=i.length+1;return e}(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,n){for(let s=0;;s++){let r=this.text[s],o=n+r.length;if((e?i:o)>=t)return new y(n,o,i,r);n=o+1,i++}}decompose(t,e,i,n){let s=t<=0&&e>=this.length?this:new d(g(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(1&n){let t=i.pop(),e=m(s.text,t.text.slice(),0,s.length);if(e.length<=32)i.push(new d(e,t.length+s.length));else{let t=e.length>>1;i.push(new d(e.slice(0,t)),new d(e.slice(t)))}}else i.push(s)}replace(t,e,i){if(!(i instanceof d))return super.replace(t,e,i);[t,e]=x(this,t,e);let n=m(this.text,m(i.text,g(this.text,0,t)),e),s=this.length+i.length-(e-t);return n.length<=32?new d(n,s):p.from(d.split(n,[]),s)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;s<=e&&rt&&r&&(n+=i),ts&&(n+=o.slice(Math.max(0,t-s),e-s)),s=l+1}return n}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],n=-1;for(let s of t)i.push(s),n+=s.length+1,32==i.length&&(e.push(new d(i,n)),i=[],n=-1);return n>-1&&e.push(new d(i,n)),e}}class p extends f{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let e of t)this.lines+=e.lines}lineInner(t,e,i,n){for(let s=0;;s++){let r=this.children[s],o=n+r.length,l=i+r.lines-1;if((e?l:o)>=t)return r.lineInner(t,e,i,n);n=o+1,i=l+1}}decompose(t,e,i,n){for(let s=0,r=0;r<=e&&s=r){let s=n&((r<=t?1:0)|(l>=e?2:0));r>=t&&l<=e&&!s?i.push(o):o.decompose(t-r,e-r,i,s)}r=l+1}}replace(t,e,i){if([t,e]=x(this,t,e),i.lines=s&&e<=o){let l=r.replace(t-s,e-s,i),a=this.lines-r.lines+l.lines;if(l.lines>4&&l.lines>a>>6){let s=this.children.slice();return s[n]=l,new p(s,this.length-(e-t)+i.length)}return super.replace(s,o,l)}s=o+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;st&&s&&(n+=i),tr&&(n+=o.sliceString(t-r,e-r,i)),r=l+1}return n}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof p))return 0;let i=0,[n,s,r,o]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,s+=e){if(n==r||s==o)return i;let l=this.children[n],a=t.children[s];if(l!=a)return i+l.scanIdentical(a,e);i+=l.length+1}}static from(t,e=t.reduce((t,e)=>t+e.length+1,-1)){let i=0;for(let e of t)i+=e.lines;if(i<32){let i=[];for(let e of t)e.flatten(i);return new d(i,e)}let n=Math.max(32,i>>5),s=n<<1,r=n>>1,o=[],l=0,a=-1,h=[];function c(t){let e;if(t.lines>s&&t instanceof p)for(let e of t.children)c(e);else t.lines>r&&(l>r||!l)?(u(),o.push(t)):t instanceof d&&l&&(e=h[h.length-1])instanceof d&&t.lines+e.lines<=32?(l+=t.lines,a+=t.length+1,h[h.length-1]=new d(e.text.concat(t.text),e.length+1+t.length)):(l+t.lines>n&&u(),l+=t.lines,a+=t.length+1,h.push(t))}function u(){0!=l&&(o.push(1==h.length?h[0]:p.from(h,a)),a=-1,l=h.length=0)}for(let e of t)c(e);return u(),1==o.length?o[0]:new p(o,e)}}function m(t,e,i=0,n=1e9){for(let s=0,r=0,o=!0;r=i&&(a>n&&(l=l.slice(0,n-s)),s0?1:(t instanceof d?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],s=this.offsets[i],r=s>>1,o=n instanceof d?n.text.length:n.children.length;if(r==(e>0?o:0)){if(0==i)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&s)==(e>0?0:1)){if(this.offsets[i]+=e,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(n instanceof d){let s=n.text[r+(e<0?-1:0)];if(this.offsets[i]+=e,s.length>Math.max(0,t))return this.value=0==t?s:e>0?s.slice(t):s.slice(0,s.length-t),this;t-=s.length}else{let s=n.children[r+(e<0?-1:0)];t>s.length?(t-=s.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(s),this.offsets.push(e>0?1:(s instanceof d?s.text.length:s.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class w{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new v(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:n}=this.cursor.next(t);return this.pos+=(n.length+t)*e,this.value=n.length<=i?n:e<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class b{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:n}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(f.prototype[Symbol.iterator]=function(){return this.iter()},v.prototype[Symbol.iterator]=w.prototype[Symbol.iterator]=b.prototype[Symbol.iterator]=function(){return this});class y{constructor(t,e,i,n){this.from=t,this.to=e,this.number=i,this.text=n}get length(){return this.to-this.from}}function x(t,e,i){return[e=Math.max(0,Math.min(t.length,e)),Math.max(e,Math.min(t.length,i))]}function k(t,e,i=!0,n=!0){return r(t,e,i,n)}function S(t,e){let i=t.charCodeAt(e);if(!(n=i,n>=55296&&n<56320&&e+1!=t.length))return i;var n;let s=t.charCodeAt(e+1);return function(t){return t>=56320&&t<57344}(s)?s-56320+(i-55296<<10)+65536:i}function C(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function A(t){return t<65536?1:2}const M=/\r\n?|\n/;var O=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(O||(O={}));class T{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return s+(t-n);s+=o}else{if(i!=O.Simple&&a>=t&&(i==O.TrackDel&&nt||i==O.TrackBefore&&nt))return null;if(a>t||a==t&&e<0&&!o)return t==n||e<0?s:s+l;s+=l}n=a}if(t>n)throw new RangeError(`Position ${t} is out of range for changeset of length ${n}`);return s}touchesRange(t,e=t){for(let i=0,n=0;i=0&&n<=e&&s>=t)return!(ne)||"cover";n=s}return!1}toString(){let t="";for(let e=0;e=0?":"+n:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(t=>"number"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeDesc");return new T(t)}static create(t){return new T(t)}}class D extends T{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return B(this,(e,i,n,s,r)=>t=t.replace(n,n+(i-e),r),!1),t}mapDesc(t,e=!1){return E(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let n=0,s=0;n=0){e[n]=o,e[n+1]=r;let l=n>>1;for(;i.length0&&P(i,e,s.text),s.forward(t),o+=t}let a=t[r++];for(;o>1].toJSON()))}return t}static of(t,e,i){let n=[],s=[],r=0,o=null;function l(t=!1){if(!t&&!n.length)return;ro||t<0||o>e)throw new RangeError(`Invalid change range ${t} to ${o} (in doc of length ${e})`);let c=h?"string"==typeof h?f.of(h.split(i||M)):h:f.empty,u=c.length;if(t==o&&0==u)return;tr&&R(n,t-r,-1),R(n,o-t,u),P(s,n,c),r=o}}(t),l(!o),o}static empty(t){return new D(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let n=0;ne&&"string"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==s.length)e.push(s[0],0);else{for(;i.length=0&&i<=0&&i==t[s+1]?t[s]+=e:s>=0&&0==e&&0==t[s]?t[s+1]+=i:n?(t[s]+=e,t[s+1]+=i):t.push(e,i)}function P(t,e,i){if(0==i.length)return;let n=e.length-2>>1;if(n>1])),!(i||o==t.sections.length||t.sections[o+1]<0);)l=t.sections[o++],a=t.sections[o++];e(s,h,r,c,u),s=h,r=c}}}function E(t,e,i,n=!1){let s=[],r=n?[]:null,o=new I(t),l=new I(e);for(let t=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(-1==o.ins&&-1==l.ins){let t=Math.min(o.len,l.len);R(s,t,-1),o.forward(t),l.forward(t)}else if(l.ins>=0&&(o.ins<0||t==o.i||0==o.off&&(l.len=0&&t=0)){if(o.done&&l.done)return r?D.createSet(s,r):T.create(s);throw new Error("Mismatched change set lengths")}{let e=0,i=o.len;for(;i;)if(-1==l.ins){let t=Math.min(i,l.len);e+=t,i-=t,l.forward(t)}else{if(!(0==l.ins&&l.lene||o.ins>=0&&o.len>e)&&(t||n.length>i),r.forward2(e),o.forward(e)}}else R(n,0,o.ins,t),s&&P(s,n,o.text),o.next()}}class I{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return e>=t.length?f.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?f.empty:e[i].slice(this.off,null==t?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){-1==this.ins?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class N{constructor(t,e,i,n){this.from=t,this.to=e,this.flags=i,this.goalColumn=n}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get undirectional(){return(64&this.flags)>0}get bidiLevel(){let t=7&this.flags;return 7==t?null:t}map(t,e=-1){let i,n;return this.empty?i=n=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),n=t.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new N(i,n,this.flags,this.goalColumn)}extend(t,e=t,i=0){if(t<=this.anchor&&e>=this.anchor)return W.range(t,e,void 0,void 0,i);let n=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return W.range(this.anchor,n,void 0,void 0,i)}eq(t,e=!1){return!(this.anchor!=t.anchor||this.head!=t.head||this.goalColumn!=t.goalColumn||e&&this.empty&&this.assoc!=t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||"number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid JSON representation for SelectionRange");return W.range(t.anchor,t.head)}static create(t,e,i,n){return new N(t,e,i,n)}}class W{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:W.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;it.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||"number"!=typeof t.main||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new W(t.ranges.map(t=>N.fromJSON(t)),t.main)}static single(t,e=t){return new W([W.range(t,e)],0)}static create(t,e=0){if(0==t.length)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;nt.from-e.from),e=t.indexOf(i);for(let i=1;in.head?W.range(o,r):W.range(r,o))}}return new W(t,e)}}function H(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let V=0;class z{constructor(t,e,i,n,s){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=n,this.id=V++,this.default=t([]),this.extensions="function"==typeof s?s(this):s}get reader(){return this}static define(t={}){return new z(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:F),!!t.static,t.enables)}of(t){return new q([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new q(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new q(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],i=>e(i.field(t)))}}function F(t,e){return t==e||t.length==e.length&&t.every((t,i)=>t===e[i])}class q{constructor(t,e,i,n){this.dependencies=t,this.facet=e,this.type=i,this.value=n,this.id=V++}dynamicSlot(t){var e;let i=this.value,n=this.facet.compareInput,s=this.id,r=t[s]>>1,o=2==this.type,l=!1,a=!1,h=[];for(let i of this.dependencies)"doc"==i?l=!0:"selection"==i?a=!0:1&(null!==(e=t[i.id])&&void 0!==e?e:1)||h.push(t[i.id]);return{create:t=>(t.values[r]=i(t),1),update(t,e){if(l&&e.docChanged||a&&(e.docChanged||e.selection)||U(t,h)){let e=i(t);if(o?!_(e,t.values[r],n):!n(e,t.values[r]))return t.values[r]=e,1}return 0},reconfigure:(t,e)=>{let l,a=e.config.address[s];if(null!=a){let s=rt(e,a);if(this.dependencies.every(i=>i instanceof z?e.facet(i)===t.facet(i):!(i instanceof K)||e.field(i,!1)==t.field(i,!1))||(o?_(l=i(t),s,n):n(l=i(t),s)))return t.values[r]=s,0}else l=i(t);return t.values[r]=l,1}}}get extension(){return this}}function _(t,e,i){if(t.length!=e.length)return!1;for(let n=0;nt[e.id]),s=i.map(t=>t.type),r=n.filter(t=>!(1&t)),o=t[e.id]>>1;function l(t){let i=[];for(let e=0;et===e),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet($).find(t=>t.field==this);return((null==e?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:t=>(t.values[e]=this.create(t),1),update:(t,i)=>{let n=t.values[e],s=this.updateF(n,i);return this.compareF(n,s)?0:(t.values[e]=s,1)},reconfigure:(t,i)=>{let n,s=t.facet($),r=i.facet($);return(n=s.find(t=>t.field==this))&&n!=r.find(t=>t.field==this)?(t.values[e]=n.create(t),1):null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}}init(t){return[this,$.of({field:this,create:t})]}get extension(){return this}}const j=4,X=3,G=2,Y=1;function J(t){return e=>new tt(e,t)}const Z={highest:J(0),high:J(Y),default:J(G),low:J(X),lowest:J(j)};class tt{constructor(t,e){this.inner=t,this.prec=e}get extension(){return this}}class et{of(t){return new it(this,t)}reconfigure(t){return et.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class it{constructor(t,e){this.compartment=t,this.inner=e}get extension(){return this}}class nt{constructor(t,e,i,n,s,r){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=n,this.staticValues=s,this.facets=r,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(t,e,i){let n=[],s=Object.create(null),r=new Map;for(let i of function(t,e,i){let n=[[],[],[],[],[]],s=new Map;function r(t,o){let l=s.get(t);if(null!=l){if(l<=o)return;let e=n[l].indexOf(t);e>-1&&n[l].splice(e,1),t instanceof it&&i.delete(t.compartment)}if(s.set(t,o),Array.isArray(t))for(let e of t)r(e,o);else if(t instanceof it){if(i.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let n=e.get(t.compartment)||t.inner;i.set(t.compartment,n),r(n,o)}else if(t instanceof tt)r(t.inner,t.prec);else if(t instanceof K)n[o].push(t),t.provides&&r(t.provides,o);else if(t instanceof q)n[o].push(t),t.facet.extensions&&r(t.facet.extensions,G);else{let e=t.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${t}).`);if(e==t)throw new Error(`Unrecognized extension value in extension set (${t}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(e,o)}}return r(t,G),n.reduce((t,e)=>t.concat(e))}(t,e,r))i instanceof K?n.push(i):(s[i.facet.id]||(s[i.facet.id]=[])).push(i);let o=Object.create(null),l=[],a=[];for(let t of n)o[t.id]=a.length<<1,a.push(e=>t.slot(e));let h=null==i?void 0:i.config.facets;for(let t in s){let e=s[t],n=e[0].facet,r=h&&h[t]||[];if(e.every(t=>0==t.type))if(o[n.id]=l.length<<1|1,F(r,e))l.push(i.facet(n));else{let t=n.combine(e.map(t=>t.value));l.push(i&&n.compare(t,i.facet(n))?i.facet(n):t)}else{for(let t of e)0==t.type?(o[t.id]=l.length<<1|1,l.push(t.value)):(o[t.id]=a.length<<1,a.push(e=>t.dynamicSlot(e)));o[n.id]=a.length<<1,a.push(t=>Q(t,n,e))}}let c=a.map(t=>t(o));return new nt(t,r,c,o,l,s)}}function st(t,e){if(1&e)return 2;let i=e>>1,n=t.status[i];if(4==n)throw new Error("Cyclic dependency between fields and/or facets");if(2&n)return n;t.status[i]=4;let s=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|s}function rt(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const ot=z.define(),lt=z.define({combine:t=>t.some(t=>t),static:!0}),at=z.define({combine:t=>t.length?t[0]:void 0,static:!0}),ht=z.define(),ct=z.define(),ut=z.define(),ft=z.define({combine:t=>!!t.length&&t[0]});class dt{constructor(t,e){this.type=t,this.value=e}static define(){return new pt}}class pt{of(t){return new dt(this,t)}}class mt{constructor(t){this.map=t}of(t){return new gt(this,t)}}class gt{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return void 0===e?void 0:e==this.value?this:new gt(this.type,e)}is(t){return this.type==t}static define(t={}){return new mt(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let n of t){let t=n.map(e);t&&i.push(t)}return i}}gt.reconfigure=gt.define(),gt.appendConfig=gt.define();class vt{constructor(t,e,i,n,s,r){this.startState=t,this.changes=e,this.selection=i,this.effects=n,this.annotations=s,this.scrollIntoView=r,this._doc=null,this._state=null,i&&H(i,e.newLength),s.some(t=>t.type==vt.time)||(this.annotations=s.concat(vt.time.of(Date.now())))}static create(t,e,i,n,s,r){return new vt(t,e,i,n,s,r)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(vt.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function wt(t,e){let i=[];for(let n=0,s=0;;){let r,o;if(n=t[n]))r=t[n++],o=t[n++];else{if(!(s=0;s--){let r=i[s](t);r&&Object.keys(r).length&&(n=bt(n,yt(e,r,t.changes.newLength),!0))}return n==t?t:vt.create(e,t.changes,t.selection,n.effects,n.annotations,n.scrollIntoView)}(i?function(t){let e=t.startState,i=!0;for(let n of e.facet(ht)){let e=n(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:wt(i,e))}if(!0!==i){let n,s;if(!1===i)s=t.changes.invertedDesc,n=D.empty(e.doc.length);else{let e=t.changes.filter(i);n=e.changes,s=e.filtered.mapDesc(e.changes).invertedDesc}t=vt.create(e,n,t.selection&&t.selection.map(s),gt.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let n=e.facet(ct);for(let i=n.length-1;i>=0;i--){let s=n[i](t);t=s instanceof vt?s:Array.isArray(s)&&1==s.length&&s[0]instanceof vt?s[0]:xt(e,St(s),!1)}return t}(s):s)}vt.time=dt.define(),vt.userEvent=dt.define(),vt.addToHistory=dt.define(),vt.remote=dt.define();const kt=[];function St(t){return null==t?kt:Array.isArray(t)?t:[t]}var Ct=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(Ct||(Ct={}));const At=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Mt;try{Mt=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}function Ot(t){return e=>{if(!/\S/.test(e))return Ct.Space;if(function(t){if(Mt)return Mt.test(t);for(let e=0;e"€"&&(i.toUpperCase()!=i.toLowerCase()||At.test(i)))return!0}return!1}(e))return Ct.Word;for(let i=0;i-1)return Ct.Word;return Ct.Other}}class Tt{constructor(t,e,i,n,s,r){this.config=t,this.doc=e,this.selection=i,this.values=n,this.status=t.statusTemplate.slice(),this.computeSlot=s,r&&(r._state=this);for(let t=0;ts.set(e,t)),i=null),s.set(e.value.compartment,e.value.extension)):e.is(gt.reconfigure)?(i=null,n=e.value):e.is(gt.appendConfig)&&(i=null,n=St(n).concat(e.value));if(i)e=t.startState.values.slice();else{i=nt.resolve(n,s,this),e=new Tt(i,this.doc,this.selection,i.dynamicSlots.map(()=>null),(t,e)=>e.reconfigure(t,this),null).values}let r=t.startState.facet(lt)?t.newSelection:t.newSelection.asSingle();new Tt(i,t.newDoc,r,e,(e,i)=>i.update(e,t),t)}replaceSelection(t){return"string"==typeof t&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:W.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),n=this.changes(i.changes),s=[i.range],r=St(i.effects);for(let i=1;is.spec.fromJSON(r,t)))}return Tt.create({doc:t.doc,selection:W.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(t={}){let e=nt.resolve(t.extensions||[],new Map),i=t.doc instanceof f?t.doc:f.of((t.doc||"").split(e.staticFacet(Tt.lineSeparator)||M)),n=t.selection?t.selection instanceof W?t.selection:W.single(t.selection.anchor,t.selection.head):W.single(0);return H(n,i.length),e.staticFacet(lt)||(n=n.asSingle()),new Tt(e,i,n,e.dynamicSlots.map(()=>null),(t,e)=>e.create(t),null)}get tabSize(){return this.facet(Tt.tabSize)}get lineBreak(){return this.facet(Tt.lineSeparator)||"\n"}get readOnly(){return this.facet(ft)}phrase(t,...e){for(let e of this.facet(Tt.phrases))if(Object.prototype.hasOwnProperty.call(e,t)){t=e[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(t,i)=>{if("$"==i)return"$";let n=+(i||1);return!n||n>e.length?t:e[n-1]})),t}languageDataAt(t,e,i=-1){let n=[];for(let s of this.facet(ot))for(let r of s(this,e,i))Object.prototype.hasOwnProperty.call(r,t)&&n.push(r[t]);return n}charCategorizer(t){let e=this.languageDataAt("wordChars",t);return Ot(e.length?e[0]:"")}wordAt(t){let{text:e,from:i,length:n}=this.doc.lineAt(t),s=this.charCategorizer(t),r=t-i,o=t-i;for(;r>0;){let t=k(e,r,!1);if(s(e.slice(t,r))!=Ct.Word)break;r=t}for(;ot.length?t[0]:4}),Tt.lineSeparator=at,Tt.readOnly=ft,Tt.phrases=z.define({compare(t,e){let i=Object.keys(t),n=Object.keys(e);return i.length==n.length&&i.every(i=>t[i]==e[i])}}),Tt.languageData=ot,Tt.changeFilter=ht,Tt.transactionFilter=ct,Tt.transactionExtender=ut,et.reconfigure=gt.define();class Rt{eq(t){return this==t}range(t,e=t){return Bt.create(t,e,this)}}function Pt(t,e){return t==e||t.constructor==e.constructor&&t.eq(e)}Rt.prototype.startSide=Rt.prototype.endSide=0,Rt.prototype.point=!1,Rt.prototype.mapMode=O.TrackDel;let Bt=class t{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(e,i,n){return new t(e,i,n)}};function Et(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Lt{constructor(t,e,i,n){this.from=t,this.to=e,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,n=0){let s=i?this.to:this.from;for(let r=n,o=s.length;;){if(r==o)return r;let n=r+o>>1,l=s[n]-t||(i?this.value[n].endSide:this.value[n].startSide)-e;if(n==r)return l>=0?r:o;l>=0?o=n:r=n+1}}between(t,e,i,n){for(let s=this.findIndex(e,-1e9,!0),r=this.findIndex(i,1e9,!1,s);sh||a==h&&c.startSide>0&&c.endSide<=0)continue;(h-a||c.endSide-c.startSide)<0||(r<0&&(r=a),c.point&&(o=Math.max(o,h-a)),i.push(c),n.push(a-r),s.push(h-r))}return{mapped:i.length?new Lt(n,s,i,o):null,pos:r}}}class It{constructor(t,e,i,n){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=n}static create(t,e,i,n){return new It(t,e,i,n)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:n=0,filterTo:s=this.length}=t,r=t.filter;if(0==e.length&&!r)return this;if(i&&(e=e.slice().sort(Et)),this.isEmpty)return e.length?It.of(e):this;let o=new Ht(this,null,-1).goto(0),l=0,a=[],h=new Nt;for(;o.value||l=0){let t=e[l++];h.addInner(t.from,t.to,t.value)||a.push(t)}else 1==o.rangeIndex&&o.chunkIndexthis.chunkEnd(o.chunkIndex)||so.to||s=s&&t<=s+r.length&&!1===r.between(s,t-s,e-s,i))return}this.nextLayer.between(t,e,i)}}iter(t=0){return Vt.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Vt.from(t).goto(e)}static compare(t,e,i,n,s=-1){let r=t.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),o=e.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),l=Wt(r,o,i),a=new Ft(r,l,s),h=new Ft(o,l,s);i.iterGaps((t,e,i)=>qt(a,t,h,e,i,n)),i.empty&&0==i.length&&qt(a,0,h,0,0,n)}static eq(t,e,i=0,n){null==n&&(n=999999999);let s=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0),r=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0);if(s.length!=r.length)return!1;if(!s.length)return!0;let o=Wt(s,r),l=new Ft(s,o,0).goto(i),a=new Ft(r,o,0).goto(i);for(;;){if(l.to!=a.to||!_t(l.active,a.active)||l.point&&(!a.point||!Pt(l.point,a.point)))return!1;if(l.to>n)return!0;l.next(),a.next()}}static spans(t,e,i,n,s=-1){let r=new Ft(t,null,s).goto(e),o=e,l=r.openStart;for(;;){let t=Math.min(r.to,i);if(r.point){let i=r.activeForPoint(r.to),s=r.pointFromo&&(n.span(o,t,r.active,l),l=r.openEnd(t));if(r.to>i)return l+(r.point&&r.to>i?1:0);o=r.to,r.next()}}static of(t,e=!1){let i=new Nt;for(let n of t instanceof Bt?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i0)return t.slice().sort(Et);e=n}return t}(t):t)i.add(n.from,n.to,n.value);return i.finish()}static join(t){if(!t.length)return It.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let n=t[i];n!=It.empty;n=n.nextLayer)e=new It(n.chunkPos,n.chunk,e,Math.max(n.maxPoint,e.maxPoint));return e}}It.empty=new It([],[],null,-1),It.empty.nextLayer=It.empty;class Nt{finishChunk(t){this.chunks.push(new Lt(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new Nt)).add(t,e,i)}addInner(t,e,i){let n=t-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(n<0)&&(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(It.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=It.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Wt(t,e,i){let n=new Map;for(let e of t)for(let t=0;t=this.minPoint)break}}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=i&&n.push(new Ht(r,e,i,s));return 1==n.length?n[0]:new Vt(n)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let t=this.heap.length>>1;t>=0;t--)zt(this.heap,t);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let t=this.heap.length>>1;t>=0;t--)zt(this.heap,t);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),zt(this.heap,0)}}}function zt(t,e){for(let i=t[e];;){let n=1+(e<<1);if(n>=t.length)break;let s=t[n];if(n+1=0&&(s=t[n+1],n++),i.compare(s)<0)break;t[n]=i,t[e]=s,e=n}}class Ft{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Vt.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){Ut(this.active,t),Ut(this.activeTo,t),Ut(this.activeRank,t),this.minActive=$t(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:n,rank:s}=this.cursor;for(;e0;)e++;Qt(this.active,e,i),Qt(this.activeTo,e,n),Qt(this.activeRank,e,s),t&&Qt(t,e,this.cursor.from),this.minActive=$t(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>t){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&Ut(i,n)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let t=this.cursor.value;if(t.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from=0&&i[e]=0&&!(this.activeRank[i]t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function qt(t,e,i,n,s,r){t.goto(e),i.goto(n);let o=n+s,l=n,a=n-e,h=!!r.boundChange;for(let e=!1;;){let n=t.to+a-i.to,s=n||t.endSide-i.endSide,c=s<0?t.to+a:i.to,u=Math.min(c,o);if(t.point||i.point?(t.point&&i.point&&Pt(t.point,i.point)&&_t(t.activeForPoint(t.to),i.activeForPoint(i.to))||r.comparePoint(l,u,t.point,i.point),e=!1):(e&&r.boundChange(l),u>l&&!_t(t.active,i.active)&&r.compareRange(l,u,t.active,i.active),h&&uo)break;l=c,s<=0&&t.next(),s>=0&&i.next()}}function _t(t,e){if(t.length!=e.length)return!1;for(let i=0;i=e;i--)t[i+1]=t[i];t[e]=i}function $t(t,e){let i=-1,n=1e9;for(let s=0;s=e)return n;if(n==t.length)break;s+=9==t.charCodeAt(n)?i-s%i:1,n=k(t,n)}return!0===n?-1:t.length}const Xt="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),Gt="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),Yt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class Jt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function n(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function s(t,e,r,o){let l=[],a=/^@(\w+)\b/.exec(t[0]),h=a&&"keyframes"==a[1];if(a&&null==e)return r.push(t[0]+";");for(let i in e){let o=e[i];if(/&/.test(i))s(i.split(/,\s*/).map(e=>t.map(t=>e.replace(/&/,t))).reduce((t,e)=>t.concat(e)),o,r);else if(o&&"object"==typeof o){if(!a)throw new RangeError("The value of a property ("+i+") should be a primitive value.");s(n(i),o,l,h)}else null!=o&&l.push(i.replace(/_.*/,"").replace(/[A-Z]/g,t=>"-"+t.toLowerCase())+": "+o+";")}(l.length||h)&&r.push((!i||a||o?t:t.map(i)).join(", ")+" {"+l.join(" ")+"}")}for(let e in t)s(n(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=Yt[Xt]||1;return Yt[Xt]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let n=t[Gt],s=i&&i.nonce;n?s&&n.setNonce(s):n=new te(t,s),n.mount(Array.isArray(e)?e:[e],t)}}let Zt=new Map;class te{constructor(t,e){let i=t.ownerDocument||t,n=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let e=Zt.get(i);if(e)return t[Gt]=e;this.sheet=new n.CSSStyleSheet,Zt.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[Gt]=this}mount(t,e){let i=this.sheet,n=0,s=0;for(let e=0;e-1&&(this.modules.splice(o,1),s--,o=-1),-1==o){if(this.modules.splice(s++,0,r),i)for(let t=0;t",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ne="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),se="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),re=0;re<10;re++)ee[48+re]=ee[96+re]=String(re);for(re=1;re<=24;re++)ee[re+111]="F"+re;for(re=65;re<=90;re++)ee[re]=String.fromCharCode(re+32),ie[re]=String.fromCharCode(re);for(var oe in ee)ie.hasOwnProperty(oe)||(ie[oe]=ee[oe]);function le(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var n in i)if(Object.prototype.hasOwnProperty.call(i,n)){var s=i[n];"string"==typeof s?t.setAttribute(n,s):null!=s&&(t[n]=s)}e++}for(;e2);var ye={mac:be||/Mac/.test(he.platform),windows:/Win/.test(he.platform),linux:/Linux|X11/.test(he.platform),ie:pe,ie_version:fe?ce.documentMode||6:de?+de[1]:ue?+ue[1]:0,gecko:me,gecko_version:me?+(/Firefox\/(\d+)/.exec(he.userAgent)||[0,0])[1]:0,chrome:!!ge,chrome_version:ge?+ge[1]:0,ios:be,android:/Android\b/.test(he.userAgent),webkit:ve,webkit_version:ve?+(/\bAppleWebKit\/(\d+)/.exec(he.userAgent)||[0,0])[1]:0,safari:we,safari_version:we?+(/\bVersion\/(\d+(\.\d+)?)/.exec(he.userAgent)||[0,0])[1]:0,tabSize:null!=ce.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};function xe(t,e){for(let i in t)"class"==i&&e.class?e.class+=" "+t.class:"style"==i&&e.style?e.style+=";"+t.style:e[i]=t[i];return e}const ke=Object.create(null);function Se(t,e,i){if(t==e)return!0;t||(t=ke),e||(e=ke);let n=Object.keys(t),s=Object.keys(e);if(n.length-(i&&n.indexOf(i)>-1?1:0)!=s.length-(i&&s.indexOf(i)>-1?1:0))return!1;for(let r of n)if(r!=i&&(-1==s.indexOf(r)||t[r]!==e[r]))return!1;return!0}function Ce(t,e,i){let n=!1;if(e)for(let s in e)i&&s in i||(n=!0,"style"==s?t.style.cssText="":t.removeAttribute(s));if(i)for(let s in i)e&&e[s]==i[s]||(n=!0,"style"==s?t.style.cssText=i[s]:t.setAttribute(s,i[s]));return n}function Ae(t){let e=Object.create(null);for(let i=0;i0?3e8:-4e8:e>0?1e8:-1e8,new Pe(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,n=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:s,end:r}=Be(t,n);e=(s?n?-3e8:-1:5e8)-1,i=1+(r?n?2e8:1:-6e8)}return new Pe(t,e,i,n,t.widget||null,!0)}static line(t){return new Re(t)}static set(t,e=!1){return It.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}Te.none=It.empty;class De extends Te{constructor(t){let{start:e,end:i}=Be(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?xe(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||ke}eq(t){return this==t||t instanceof De&&this.tagName==t.tagName&&Se(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}De.prototype.point=!1;class Re extends Te{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Re&&this.spec.class==t.spec.class&&Se(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}Re.prototype.mapMode=O.TrackBefore,Re.prototype.point=!0;class Pe extends Te{constructor(t,e,i,n,s,r){super(e,i,s,t),this.block=n,this.isReplace=r,this.mapMode=n?e<=0?O.TrackBefore:O.TrackAfter:O.TrackDel}get type(){return this.startSide!=this.endSide?Oe.WidgetRange:this.startSide<=0?Oe.WidgetBefore:Oe.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof Pe&&(e=this.widget,i=t.widget,e==i||!!(e&&i&&e.compare(i)))&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide;var e,i}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}function Be(t,e=!1){let{inclusiveStart:i,inclusiveEnd:n}=t;return null==i&&(i=t.inclusive),null==n&&(n=t.inclusive),{start:null!=i?i:e,end:null!=n?n:e}}function Ee(t,e,i,n=0){let s=i.length-1;s>=0&&i[s]+n>=t?i[s]=Math.max(i[s],e):i.push(t,e)}Pe.prototype.point=!0;class Le extends Rt{constructor(t,e,i){super(),this.tagName=t,this.attributes=e,this.rank=i}eq(t){return t==this||t instanceof Le&&this.tagName==t.tagName&&Se(this.attributes,t.attributes)}static create(t){return new Le(t.tagName,t.attributes||ke,null==t.rank?50:Math.max(0,Math.min(t.rank,100)))}static set(t,e=!1){return It.of(t,e)}}function Ie(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function Ne(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function We(t,e){if(!e.anchorNode)return!1;try{return Ne(t,e.anchorNode)}catch(t){return!1}}function He(t){return 3==t.nodeType?Je(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function Ve(t,e,i,n){return!!i&&(qe(t,e,i,n,-1)||qe(t,e,i,n,1))}function ze(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function Fe(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function qe(t,e,i,n,s){for(;;){if(t==i&&e==n)return!0;if(e==(s<0?0:_e(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=ze(t)+(s<0?0:1),t=i}else{if(1!=t.nodeType)return!1;if(1==(t=t.childNodes[e+(s<0?-1:0)]).nodeType&&"false"==t.contentEditable)return!1;e=s<0?_e(t):0}}}function _e(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Ue(t,e){let{left:i,right:n}=t;if(i==n)return t;let s=e?i:n;return{left:s,right:s,top:t.top,bottom:t.bottom}}function Qe(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function $e(t,e){let i=e.width/t.offsetWidth,n=e.height/t.offsetHeight;return(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)&&(i=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.height-t.offsetHeight)<1)&&(n=1),{scaleX:i,scaleY:n}}function Ke(t,e=!0){let i=t.ownerDocument,n=null,s=null;for(let r=t.parentNode;r&&(r!=i.body&&(e&&!n||!s));)if(1==r.nodeType)!s&&r.scrollHeight>r.clientHeight&&(s=r),e&&!n&&r.scrollWidth>r.clientWidth&&(n=r),r=r.assignedSlot||r.parentNode;else{if(11!=r.nodeType)break;r=r.host}return{x:n,y:s}}Le.prototype.startSide=Le.prototype.endSide=-1;class je{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?_e(e):0),i,Math.min(t.focusOffset,i?_e(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}}let Xe,Ge=null;function Ye(t){if(t.setActive)return t.setActive();if(Ge)return t.focus(Ge);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==Ge?{get preventScroll(){return Ge={preventScroll:!0},!0}}:void 0),!Ge){Ge=!1;for(let t=0;tMath.max(0,t.document.documentElement.scrollHeight-t.innerHeight-4):t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function ei(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&n>0)return{node:i,offset:n};if(1==i.nodeType&&n>0){if("false"==i.contentEditable)return null;i=i.childNodes[n-1],n=_e(i)}else{if(!i.parentNode||Fe(i))return null;n=ze(i),i=i.parentNode}}}function ii(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&n=26&&(Ge=!1);class ni{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new ni(t.parentNode,ze(t),e)}static after(t,e){return new ni(t.parentNode,ze(t)+1,e)}}var si=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(si||(si={}));const ri=si.LTR,oi=si.RTL;function li(t){let e=[];for(let i=0;i=e){if(o.level==i)return r;(s<0||(0!=n?n<0?o.frome:t[s].level>o.level))&&(s=r)}}if(s<0)throw new RangeError("Index out of range");return s}}function mi(t,e){if(t.length!=e.length)return!1;for(let i=0;ia&&o.push(new pi(a,p.from,f)),wi(t,p.direction==ri!=!(f%2)?n+1:n,s,p.inner,p.from,p.to,o),a=p.to}d=p.to}else{if(d==i||(e?gi[d]!=l:gi[d]==l))break;d++}u?vi(t,a,d,n+1,s,u,o):ae;){let i=!0,c=!1;if(!h||a>r[h-1].to){let t=gi[a-1];t!=l&&(i=!1,c=16==t)}let u=i||1!=l?null:[],f=i?n:n+1,d=a;t:for(;;)if(h&&d==r[h-1].to){if(c)break t;let p=r[--h];if(!i)for(let t=p.from,i=h;;){if(t==e)break t;if(!i||r[i-1].to!=t){if(gi[t-1]==l)break t;break}t=r[--i].from}if(u)u.push(p);else{p.to=0;t-=3)if(ui[t+1]==-i){let e=ui[t+2],i=2&e?s:4&e?1&e?r:s:0;i&&(gi[o]=gi[ui[t]]=i),l=t;break}}else{if(189==ui.length)break;ui[l++]=o,ui[l++]=e,ui[l++]=a}else if(2==(n=gi[o])||1==n){let t=n==s;a=t?0:1;for(let e=l-3;e>=0;e-=3){let i=ui[e+2];if(2&i)break;if(t)ui[e+2]|=2;else{if(4&i)break;ui[e+2]|=4}}}}}(t,s,r,n,l),function(t,e,i,n){for(let s=0,r=n;s<=i.length;s++){let o=s?i[s-1].to:t,l=sa;)e==r&&(e=i[--n].from,r=n?i[n-1].to:t),gi[--e]=c;a=o}else r=o,a++}}}(s,r,n,l),vi(t,s,r,e,i,n,o)}function bi(t){return[new pi(0,t,0)]}let yi="";function xi(t,e,i,n,s){var r;let o=n.head-t.from,l=pi.find(e,o,null!==(r=n.bidiLevel)&&void 0!==r?r:-1,n.assoc),a=e[l],h=a.side(s,i);if(o==h){let t=l+=s?1:-1;if(t<0||t>=e.length)return null;a=e[l=t],o=a.side(!s,i),h=a.side(s,i)}let c=k(t.text,o,a.forward(s,i));(ca.to)&&(c=h),yi=t.text.slice(Math.min(o,c),Math.max(o,c));let u=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return u&&c==h&&u.level+(s?0:1)t.some(t=>t)}),Ei=z.define({combine:t=>t.some(t=>t)}),Li=z.define();class Ii{constructor(t,e,i,n,s,r=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=s,this.isSnapshot=r}map(t){return t.empty?this:new Ii(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Ii(W.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Ni=gt.define({map:(t,e)=>t.map(e)}),Wi=gt.define();function Hi(t,e,i){let n=t.facet(Mi);n.length?n[0](e):window.onerror&&window.onerror(String(e),i,void 0,void 0,e)||(i?console.error(i+":",e):console.error(e))}const Vi=z.define({combine:t=>!t.length||t[0]});let zi=0;const Fi=z.define({combine:t=>t.filter((e,i)=>{for(let n=0;n{let e=[];return r&&e.push($i.of(e=>{let i=e.plugin(t);return i?r(i):Te.none})),s&&e.push(s(t)),e})}static fromClass(t,e){return qi.define((e,i)=>new t(e,i),e)}}class _i{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(Hi(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){Hi(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(null===(e=this.value)||void 0===e?void 0:e.destroy)try{this.value.destroy()}catch(e){Hi(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Ui=z.define(),Qi=z.define(),$i=z.define(),Ki=z.define(),ji=z.define(),Xi=z.define(),Gi=z.define();function Yi(t,e){let i=t.state.facet(Gi);if(!i.length)return i;let n=i.map(e=>e instanceof Function?e(t):e),s=[];return It.spans(n,e.from,e.to,{point(){},span(t,i,n,r){let o=t-e.from,l=i-e.from,a=s;for(let t=n.length-1;t>=0;t--,r--){let i,s=n[t].spec.bidiIsolate;if(null==s&&(s=ki(e.text,o,l)),r>0&&a.length&&(i=a[a.length-1]).to==o&&i.direction==s)i.to=l,a=i.inner;else{let t={from:o,to:l,direction:s,inner:[]};a.push(t),a=t.inner}}}}),s}const Ji=z.define();function Zi(t){let e=0,i=0,n=0,s=0;for(let r of t.state.facet(Ji)){let o=r(t);o&&(null!=o.left&&(e=Math.max(e,o.left)),null!=o.right&&(i=Math.max(i,o.right)),null!=o.top&&(n=Math.max(n,o.top)),null!=o.bottom&&(s=Math.max(s,o.bottom)))}return{left:e,right:i,top:n,bottom:s}}const tn=z.define();class en{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new en(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toAn.push(new en(t,e,i,s))),this.changedRanges=n}static create(t,e,i){return new nn(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return 0==this.flags&&0==this.transactions.length}}const sn=[];class rn{constructor(t,e,i=0){this.dom=t,this.length=e,this.flags=i,this.parent=null,t.cmTile=this}get breakAfter(){return 1&this.flags}get children(){return sn}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,4&this.flags){this.flags&=-5;let t=this.domAttrs;t&&function(t,e){for(let i=t.attributes.length-1;i>=0;i--){let n=t.attributes[i].name;null==e[n]&&t.removeAttribute(n)}for(let i in e){let n=e[i];"style"==i?t.style.cssText=n:t.getAttribute(i)!=n&&t.setAttribute(i,n)}}(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t,t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let e of this.children){if(e==t)return i;i+=e.length+e.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e,i){return null}domPosFor(t,e){let i=ze(this.dom),n=this.length?t>0:e>0;return new ni(this.parent.dom,i+(n?1:0),0==t||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&2&this.parent.flags&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof an)return t;return null}static get(t){return t.cmTile}}class on extends rn{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t),t.parent=this}sync(t){if(2&this.flags)return;super.sync(t);let e,i=this.dom,n=null,s=(null==t?void 0:t.node)==i?t:null,r=0;for(let o of this.children){if(o.sync(t),r+=o.length+o.breakAfter,e=n?n.nextSibling:i.firstChild,s&&e!=o.dom&&(s.written=!0),o.dom.parentNode==i)for(;e&&e!=o.dom;)e=ln(e);else i.insertBefore(o.dom,e);n=o.dom}for(e=n?n.nextSibling:i.firstChild,s&&e&&(s.written=!0);e;)e=ln(e);this.length=r}}function ln(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class an extends on{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=rn.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,n=0,s=0;;)if(n==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&s++,n=e.pop()}else{let r=i.children[n++];if(r instanceof hn)e.push(n),i=r,n=0;else{let e=s+r.length,i=t(r,s);if(void 0!==i)return i;s=e+r.breakAfter}}}resolveBlock(t,e){let i,n,s=-1,r=-1;if(this.blockTiles((o,l)=>{let a=l+o.length;if(t>=l&&t<=a){if(o.isWidget()&&e>=-1&&e<=1){if(32&o.flags)return!0;16&o.flags&&(i=void 0)}(lt||t==l&&(e>1?o.length:o.covers(-1)))&&(!n||!o.isWidget()&&n.isWidget())&&(n=o,r=t-l)}}),!i&&!n)throw new Error("No tile at position "+t);return i&&e<0||!n?{tile:i,offset:s}:{tile:n,offset:r}}}class hn extends on{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return!!this.children.length&&(t<0?this.children[0].covers(-1):this.lastChild.covers(1))}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new hn(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class cn extends on{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let n=new cn(e||document.createElement("div"),t);return e&&i||(n.flags|=4),n}get domAttrs(){return this.attrs}resolveInline(t,e,i){let n=null,s=-1,r=null,o=-1;!function t(l,a){for(let h=0,c=0;h=a&&(u.isComposite()?t(u,a-c):(!r||r.isHidden&&(e>0&&!(32&r.flags)||i&&un(r,u)))&&(f>a||32&u.flags)?(r=u,o=a-c):(cn&&(t=n);let s=t,r=t,o=0;0==t&&e<0||t==n&&e>=0?ye.chrome||ye.gecko||(t?(s--,o=1):r=0)?0:l.length-1];return ye.safari&&!o&&0==a.width&&(a=Array.prototype.find.call(l,t=>t.width)||a),null==i?a:Ue(a,(o?o>0:e<0)==i)}static of(t,e){let i=new dn(e||document.createTextNode(t),t);return e||(i.flags|=2),i}}class pn extends rn{constructor(t,e,i,n){super(t,e,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return!(48&this.flags)&&(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let n=this.widget.coordsAt(this.dom,t,e);if(n)return n;if(i)return Ue(this.dom.getBoundingClientRect(),this.length?0==t:e<=0);{let e=this.dom.getClientRects(),i=null;if(!e.length)return null;let n=!!(16&this.flags)||!(32&this.flags)&&t>0;for(let s=n?e.length-1:0;i=e[s],!(t>0?0==s:s==e.length-1||i.top0==i)}}class gn{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:n,index:s,beforeBreak:r,parents:o}=this;for(;t||e>0;)if(n.isComposite())if(r){if(!t)break;i&&i.break(),t--,r=!1}else if(s==n.children.length){if(!t&&!o.length)break;i&&i.leave(n),r=!!n.breakAfter,({tile:n,index:s}=o.pop()),s++}else{let l=n.children[s],a=l.breakAfter;!(e>0?l.length<=t:l.length=0;t--){let i=e.marks[t],s=n.lastChild;if(s instanceof fn&&s.mark.eq(i.mark))s.dom!=i.dom&&s.setDOM(An(i.dom)),n=s;else{if(this.cache.reused.get(i)){let t=rn.get(i.dom);t&&t.setDOM(An(i.dom))}let t=fn.of(i.mark,i.dom);n.append(t),n=t}this.cache.reused.set(i,2)}let s=rn.get(t.text);s&&this.cache.reused.set(s,2);let r=new dn(t.text,t.text.nodeValue);r.flags|=8,this.pos=t.range.toB,n.append(r)}addInlineWidget(t,e,i){let n=this.afterWidget&&48&t.flags&&(48&this.afterWidget.flags)==(48&t.flags);n||this.flushBuffer();let s=this.ensureMarks(e,i);n||16&t.flags||s.append(this.getBuffer(1)),s.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).append(t),this.pos+=t.length,this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}continueWidget(t){(this.afterWidget||this.lastBlock).length+=t,this.pos+=t}addLineStart(t,e){var i;t||(t=Cn);let n=cn.start(t,e||(null===(i=this.cache.find(cn))||void 0===i?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(t){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let n=this.curLine;for(let s=t.length-1;s>=0;s--){let r,o=t[s];if(e>0&&(r=n.lastChild)&&r instanceof fn&&r.mark.eq(o))n=r,e--;else{let t=fn.of(o,null===(i=this.cache.find(fn,t=>t.mark.eq(o)))||void 0===i?void 0:i.dom);n.append(t),n=t,e=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;t&&Sn(this.curLine,!1)&&("BR"==t.dom.nodeName||!t.isWidget()||ye.ios&&Sn(this.curLine,!0))||this.curLine.append(this.cache.findWidget(On,0,32)||new pn(On.toDOM(),0,On,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to=this.pos){let e=102*t.rank+t.value.rank,i=new vn(t.from,t.to,t.value,e),n=this.wrappers.length;for(;n>0&&(this.wrappers[n-1].rank-i.rank||this.wrappers[n-1].to-i.to)<0;)n--;this.wrappers.splice(n,0,i)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let n=e.lastChild;if(i.fromt.wrapper.eq(i.wrapper)))||void 0===t?void 0:t.dom);e.append(n),e=n}}return e}blockPosCovered(){let t=this.lastBlock;return null!=t&&!t.breakAfter&&(!t.isWidget()||(160&t.flags)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(mn,void 0,1);return i&&(i.flags=e),i||new mn(e)}flushBuffer(){!this.afterWidget||32&this.afterWidget.flags||(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class bn{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:n}=this.cursor.next(this.skipCount);if(this.skipCount=0,n)throw new Error("Ran out of text content when drawing inline views");this.text=e;let s=this.textOff=Math.min(t,e.length);return i?null:e.slice(0,s)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}}const yn=[pn,cn,dn,fn,mn,hn,an];for(let t=0;t[]),this.index=yn.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let n=t.bucket,s=this.buckets[n],r=this.index[n];for(let t=0;t{if(this.cache.add(t),t.isComposite())return!1},enter:t=>this.cache.add(t),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let n=0,s=0,r=0;;){let o=rn){let t=l-n;this.preserve(t,!r,!o),n=l,s+=t}if(!o)break;e&&o.fromA<=e.range.fromA&&o.toA>=e.range.toA?(this.forward(o.fromA,e.range.fromA,e.range.fromA1;i--){let n=i==t.parents.length?t.tile:t.parents[i].tile;n instanceof fn&&e.push(n.mark)}return e}(this.old),s=this.openMarks;this.old.advance(t,i?1:-1,{skip:(t,e,i)=>{if(t.isWidget())if(this.openWidget)this.builder.continueWidget(i-e);else{let r=i>0||e{t.isLine()?this.builder.addLineStart(t.attrs,this.cache.maybeReuse(t)):(this.cache.add(t),t instanceof fn&&n.unshift(t.mark)),this.openWidget=!1},leave:t=>{t.isLine()?n.length&&(n.length=s=0):t instanceof fn&&(n.shift(),s=Math.min(s,n.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,e){let i=null,n=this.builder,s=-1,r=It.spans(this.decorations,t,e,{point:(t,e,r,o,l,a)=>{if(r instanceof Pe){if(this.disallowBlockEffectsFor[a]){if(r.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.view.state.doc.lineAt(t).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=o.length,l>o.length)n.continueWidget(e-t);else{let s=r.widget||(r.block?Mn.block:Mn.inline),a=function(t){let e=t.isReplace?(t.startSide<0?64:0)|(t.endSide>0?128:0):t.startSide>0?32:16;t.block&&(e|=256);return e}(r),h=this.cache.findWidget(s,e-t,a)||pn.of(s,this.view,e-t,a);r.block?(r.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(h)):(n.ensureLine(i),n.addInlineWidget(h,o,l))}i=null}else i=function(t,e){let i=e.spec.attributes,n=e.spec.class;if(!i&&!n)return t;t||(t={class:"cm-line"});i&&xe(i,t);n&&(t.class+=" "+n);return t}(i,r);e>t&&this.text.skip(e-t)},span:(t,e,r,o)=>{for(let s=t;s-1&&(this.openWidget=r>s),this.openWidget||n.addLineStartIfNotCovered(i),this.openMarks=r}forward(t,e,i=1){e-t<=10?this.old.advance(e-t,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(e-t-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(t){let e=[],i=null;for(let n=t.parentNode;;n=n.parentNode){let t=rn.get(n);if(n==this.view.contentDOM)break;t instanceof fn?e.push(t):(null==t?void 0:t.isLine())?i=t:t instanceof hn||("DIV"!=n.nodeName||i||n==this.view.contentDOM?i||e.push(fn.of(new De({tagName:n.nodeName.toLowerCase(),attributes:Ae(n)}),n)):i=new cn(n,Cn))}return{line:i,marks:e}}}function Sn(t,e){let i=t=>{for(let n of t.children)if((e?n.isText():n.length)||i(n))return!0;return!1};return i(t)}const Cn={class:"cm-line"};function An(t){let e=rn.get(t);return e&&e.setDOM(t.cloneNode()),t}class Mn extends Me{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}Mn.inline=new Mn("span"),Mn.block=new Mn("div");const On=new class extends Me{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Tn{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=Te.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new an(t,t.contentDOM),this.updateInner([new en(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:t,toA:e})=>ethis.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(e=this.domChanged)||void 0===e?void 0:e.newSel)?n=this.domChanged.newSel.head:function(t,e){let i=!1;e&&t.iterChangedRanges((t,n)=>{te.from&&(i=!0)});return i}(t.changes,this.hasComposition)||t.selectionSet||(n=t.state.selection.main.head));let s=n>-1?function(t,e,i){let n=Rn(t,i);if(!n)return null;let{node:s,from:r,to:o}=n,l=s.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(n.from,n.to)!=l)return null;let a=e.invertedDesc;return{range:new en(a.mapPos(r),a.mapPos(o),r,o),text:s}}(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:e,to:n}=this.hasComposition;i=new en(e,n,t.changes.mapPos(e,-1),t.changes.mapPos(n,1)).addToSet(i.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(ye.ie||ye.chrome)&&!s&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let r=this.decorations,o=this.blockWrappers;this.updateDeco();let l=function(t,e,i){let n=new Pn;return It.compare(t,e,i,n),n.changes}(r,this.decorations,t.changes);l.length&&(i=en.extendWithRanges(i,l));let a=function(t,e,i){let n=new Bn;return It.compare(t,e,i,n),n.changes}(o,this.blockWrappers,t.changes);return a.length&&(i=en.extendWithRanges(i,a)),s&&!i.some(t=>t.fromA<=s.range.fromA&&t.toA>=s.range.toA)&&(i=s.range.addToSet(i.slice())),!(2&this.tile.flags&&0==i.length)&&(this.updateInner(i,s),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let i=this.tile,n=new kn(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);e&&rn.get(e.text)&&n.cache.reused.set(rn.get(e.text),2),this.tile=n.run(t,e),Dn(i,n.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let n=ye.chrome||ye.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(n),!n||!n.written&&i.selectionRange.focusNode==n.node&&this.tile.dom.contains(n.node)||(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to-1)&&We(i,this.view.observer.selectionRange)&&!(n&&i.contains(n));if(!(s||e||r))return;let o=this.forceSelection;this.forceSelection=!1;let l,a,h=this.view.state.selection.main;if(h.empty?a=l=this.inlineDOMNearPos(h.anchor,h.assoc||1):(a=this.inlineDOMNearPos(h.head,h.head==h.from?1:-1),l=this.inlineDOMNearPos(h.anchor,h.anchor==h.from?1:-1)),ye.gecko&&h.empty&&!this.hasComposition&&(1==(c=l).node.nodeType&&c.node.firstChild&&(0==c.offset||"false"==c.node.childNodes[c.offset-1].contentEditable)&&(c.offset==c.node.childNodes.length||"false"==c.node.childNodes[c.offset].contentEditable))){let t=document.createTextNode("");this.view.observer.ignore(()=>l.node.insertBefore(t,l.node.childNodes[l.offset]||null)),l=a=new ni(t,0),o=!0}var c;let u=this.view.observer.selectionRange;!o&&u.focusNode&&(Ve(l.node,l.offset,u.anchorNode,u.anchorOffset)&&Ve(a.node,a.offset,u.focusNode,u.focusOffset)||this.suppressWidgetCursorChange(u,h))||(this.view.observer.ignore(()=>{ye.android&&ye.chrome&&i.contains(u.focusNode)&&function(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(u.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let t=Ie(this.view.root);if(t)if(h.empty){if(ye.gecko){let t=(e=l.node,s=l.offset,1!=e.nodeType?0:(s&&"false"==e.childNodes[s-1].contentEditable?1:0)|(sh.head&&([l,a]=[a,l]),e.setEnd(a.node,a.offset),e.setStart(l.node,l.offset),t.removeAllRanges(),t.addRange(e)}else;var e,s;r&&this.view.root.activeElement==i&&(i.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(l,a)),this.impreciseAnchor=l.precise?null:new ni(u.anchorNode,u.anchorOffset),this.impreciseHead=a.precise?null:new ni(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Ve(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=Ie(t.root),{anchorNode:n,anchorOffset:s}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let r=this.lineAt(e.head,e.assoc);if(!r)return;let o=r.posAtStart;if(e.head==o||e.head==o+r.length)return;let l=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!l||!a||l.bottom>a.top)return;let h=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(n,s)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return 2&this.tile.dom.compareDocumentPosition(t)?0:this.view.state.doc.length;let n=i.posAtStart;if(!i.isComposite())return i.isText()?t==i.dom?n+e:n+(e?i.length:0):n;{let s;if(t==i.dom)s=i.dom.childNodes[e];else{let n=0==_e(t)?0:0==e?-1:1;for(;;){let e=t.parentNode;if(e==i.dom)break;0==n&&e.firstChild!=e.lastChild&&(n=t==e.firstChild?-1:1),t=e}s=n<0?t:t.nextSibling}if(s==i.dom.firstChild)return n;for(;s&&!rn.get(s);)s=s.nextSibling;if(!s)return n+i.length;for(let t=0,e=n;;t++){let n=i.children[t];if(n.dom==s)return e;e+=n.length+n.breakAfter}}}domAtPos(t,e){let{tile:i,offset:n}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(n,e):i.domIn(n,e)}inlineDOMNearPos(t,e){let i,n,s=-1,r=!1,o=-1,l=!1;return this.tile.blockTiles((e,a)=>{if(e.isWidget()){if(32&e.flags&&a>=t)return!0;16&e.flags&&(r=!0)}else{let h=a+e.length;if(a<=t&&(i=e,s=t-a,r=h=t&&!n&&(n=e,o=t-a,l=a>t),a>t&&n)return!0}}),i||n?(r&&n?i=null:l&&i&&(n=null),i&&e<0||!n?i.domIn(s,e):n.domIn(o,e)):this.domAtPos(t,e)}coordsAt(t,e,i){let{tile:n,offset:s}=this.tile.resolveBlock(t,e);return n.isWidget()?n.widget instanceof En?null:n.coordsInWidget(s,e,!0):n.coordsIn(s,e,i)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;return function t(e,i){if(e.isComposite())for(let n of e.children){if(n.length>=i){let e=t(n,i);if(e)return e}if((i-=n.length)<0)break}else if(e.isText()&&iMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,l=this.view.textDirection==si.LTR,a=0,h=(t,c,u)=>{for(let f=0;fn);f++){let n=t.children[f],d=c+n.length,p=n.dom.getBoundingClientRect(),{height:m}=p;if(u&&!f&&(a+=p.top-u.top),n instanceof hn)d>i&&h(n,c,p);else if(c>=i&&(a>0&&e.push(-a),e.push(m+a),a=0,r)){let t=n.dom.lastChild,e=t?He(t):[];if(e.length){let t=e[e.length-1],i=l?t.right-p.left:p.right-t.left;i>o&&(o=i,this.minWidth=s,this.minWidthFrom=c,this.minWidthTo=d)}}u&&f==t.children.length-1&&(a+=u.bottom-p.bottom),c=d+n.breakAfter}};return h(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return"rtl"==getComputedStyle(e.dom).direction?si.RTL:si.LTR}measureTextSize(){let t=this.tile.blockTiles(t=>{if(t.isLine()&&t.children.length&&t.length<=20){let e,i=0;for(let n of t.children){if(!n.isText()||/[^ -~]/.test(n.text))return;let t=He(n.dom);if(1!=t.length)return;i+=t[0].width,e=t[0].height}if(i)return{lineHeight:t.dom.getBoundingClientRect().height,charWidth:i/t.length,textHeight:e}}});if(t)return t;let e,i,n,s=document.createElement("div");return s.className="cm-line",s.style.width="99999px",s.style.position="absolute",s.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(s);let t=He(s.firstChild)[0];e=s.getBoundingClientRect().height,i=t&&t.width?t.width/27:7,n=t&&t.height?t.height:e,s.remove()}),{lineHeight:e,charWidth:i,textHeight:n}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let s=n==e.viewports.length?null:e.viewports[n],r=s?s.from-1:this.view.state.doc.length;if(r>i){let n=(e.lineBlockAt(r).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(Te.replace({widget:new En(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,r))}if(!s)break;i=s.to+1}return Te.set(t)}updateDeco(){let t=1,e=this.view.state.facet($i).map(e=>(this.dynamicDecorationMap[t++]="function"==typeof e)?e(this.view):e),i=!1,n=this.view.state.facet(ji).map((t,e)=>{let n="function"==typeof t;return n&&(i=!0),n?t(this.view):t});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(It.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t"function"==typeof t?t(this.view):t)}scrollIntoView(t){if(t.isSnapshot){let e=this.view.viewState.lineBlockAt(t.range.head);return this.view.scrollDOM.scrollTop=e.top-t.yMargin,void(this.view.scrollDOM.scrollLeft=t.xMargin)}for(let e of this.view.state.facet(Li))try{if(e(this.view,t.range,t))return!0}catch(t){Hi(this.view.state,t,"scroll handler")}let e,{range:i}=t,n=this.coordsAt(i.head,i.assoc||(i.head>i.anchor?-1:1));if(!n)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,e.left),top:Math.min(n.top,e.top),right:Math.max(n.right,e.right),bottom:Math.max(n.bottom,e.bottom)});let s=Zi(this.view),r={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;if(function(t,e,i,n,s,r,o,l){let a=t.ownerDocument,h=a.defaultView||window;for(let c=t,u=!1;c&&!u;)if(1==c.nodeType){let t,f=c==a.body,d=1,p=1;if(f)t=Qe(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(u=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let e=c.getBoundingClientRect();({scaleX:d,scaleY:p}=$e(c,e)),t={left:e.left,right:e.left+c.clientWidth*d,top:e.top,bottom:e.top+c.clientHeight*p}}let m=0,g=0;if("nearest"==s)e.top0&&e.bottom>t.bottom+g&&(g=e.bottom-t.bottom+o)):e.bottom>t.bottom-o&&(g=e.bottom-t.bottom+o,i<0&&e.top-g0&&e.right>t.right+m&&(m=e.right-t.right+r)):e.right>t.right-r&&(m=e.right-t.right+r,i<0&&e.leftt.bottom||e.leftt.right)&&(e={left:Math.max(e.left,t.left),right:Math.min(e.right,t.right),top:Math.max(e.top,t.top),bottom:Math.min(e.bottom,t.bottom)}),c=c.assignedSlot||c.parentNode}else{if(11!=c.nodeType)break;c=c.host}}(this.view.scrollDOM,r,i.head1&&(n.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||n.bottomt.isWidget()||t.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){Dn(this.tile)}}function Dn(t,e){let i=null==e?void 0:e.get(t);if(1!=i){null==i&&t.destroy();for(let i of t.children)Dn(i,e)}}function Rn(t,e){let i=t.observer.selectionRange;if(!i.focusNode)return null;let n=ei(i.focusNode,i.focusOffset),s=ii(i.focusNode,i.focusOffset),r=n||s;if(s&&n&&s.node!=n.node){let e=rn.get(s.node);if(!e||e.isText()&&e.text!=s.node.nodeValue)r=s;else if(t.docView.lastCompositionAfterCursor){let t=rn.get(n.node);!t||t.isText()&&t.text!=n.node.nodeValue||(r=s)}}if(t.docView.lastCompositionAfterCursor=r!=n,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}let Pn=class{constructor(){this.changes=[]}compareRange(t,e){Ee(t,e,this.changes)}comparePoint(t,e){Ee(t,e,this.changes)}boundChange(t){Ee(t,t,this.changes)}};class Bn{constructor(){this.changes=[]}compareRange(t,e){Ee(t,e,this.changes)}comparePoint(){}boundChange(t){Ee(t,t,this.changes)}}class En extends Me{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Ln(t,e,i){let n=t.lineBlockAt(e);if(Array.isArray(n.type)){let t;for(let s of n.type){if(s.from>e)break;if(!(s.toe)return s;t&&(s.type!=Oe.Text||t.type==s.type&&!(i<0?s.frome))||(t=s)}}return t||n}return n}function In(t,e,i,n){let s=t.state.doc.lineAt(e.head),r=t.bidiSpans(s),o=t.textDirectionAt(s.from);for(let l=e,a=null;;){let e=xi(s,r,o,l,i),h=yi;if(!e){if(s.number==(i?t.state.doc.lines:1))return l;h="\n",s=t.state.doc.line(s.number+(i?1:-1)),r=t.bidiSpans(s),e=t.visualLineSide(s,!i)}if(a){if(!a(h))return l}else{if(!n)return e;a=n(h)}l=e}}function Nn(t,e,i){for(;;){let n=0;for(let s of t)s.between(e-1,e+1,(t,s,r)=>{if(e>t&&ee(t)),i.from,e.head>i.from?-1:1);return n==i.from?i:W.cursor(n,nt.viewState.docHeight)return new Vn(t.state.doc.length,-1);if(s=t.elementAtHeight(h),null==n)break;if(s.type==Oe.Text){if(n<0?s.tot.viewport.to)break;let e=t.docView.coordsAt(n<0?s.from:s.to,n>0?-1:1);if(e&&(n<0?e.top<=h+o:e.bottom>=h+o))break}let e=t.viewState.heightOracle.textHeight/2;h=n>0?s.bottom+e:s.top-e}if(t.viewport.from>=s.to||t.viewport.to<=s.from){if(i)return null;if(s.type==Oe.Text){let e=function(t,e,i,n,s){let r=Math.round((n-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&i.height>1.5*t.defaultLineHeight){let e=t.viewState.heightOracle.textHeight;r+=Math.floor((s-i.top-.5*(t.defaultLineHeight-e))/e)*t.viewState.heightOracle.lineLength}let o=t.state.sliceDoc(i.from,i.to);return i.from+jt(o,r,t.state.tabSize)}(t,r,s,l,a);return new Vn(e,e==s.from?1:-1)}}if(s.type!=Oe.Text)return h<(s.top+s.bottom)/2?new Vn(s.from,1):new Vn(s.to,-1);let c=t.docView.lineAt(s.from,2);return c&&c.length==s.length||(c=t.docView.lineAt(s.from,-2)),new Fn(t,l,a,t.textDirectionAt(s.from)).scanTile(c,s.from)}class Fn{constructor(t,e,i,n){this.view=t,this.x=e,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(t){return(!this.line||this.line.from>t||this.line.to1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from>1;e:if(a.has(f)){let t=o+Math.floor(Math.random()*i);for(let e=0;e1)){if(i.bottomthis.y)(!s||s.top>i.top)&&(s=i),a=-1;else{let t=i.left>this.x?this.x-i.left:i.right(i+i+o)/3)return this.y=n.bottom-1,this.scan(t,e,!0);if(s&&s.top<(i+o+o)/3)return this.y=s.top+1,this.scan(t,e,!0)}let f=(h?this.dirAt(t[c],1):this.baseDir)==si.LTR;return{i:c,after:this.x>(r.left+r.right)/2==f}}scanText(t,e){let i=[];for(let n=0;n{let s=i[n]-e,r=i[n+1]-e;return Je(t.dom,s,r).getClientRects()});return n.after?new Vn(i[n.i+1],-1):new Vn(i[n.i],1)}scanTile(t,e){if(!t.length)return new Vn(e,1);if(1==t.children.length){let i=t.children[0];if(i.isText())return this.scanText(i,e);if(i.isComposite())return this.scanTile(i,e)}let i=[e];for(let n=0,s=e;n{let i=t.children[e];return 48&i.flags?null:(1==i.dom.nodeType?i.dom:Je(i.dom,0,i.length)).getClientRects()}),s=t.children[n.i],r=i[n.i];return s.isText()?this.scanText(s,r):s.isComposite()?this.scanTile(s,r):n.after?new Vn(i[n.i+1],-1):new Vn(r,1)}}const qn="￿";class _n{constructor(t,e){this.points=t,this.view=e,this.text="",this.lineSeparator=e.state.facet(Tt.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=qn}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let n=t;;){this.findPointBefore(i,n);let t=this.text.length;this.readNode(n);let s=rn.get(n),r=n.nextSibling;if(r==e){(null==s?void 0:s.breakAfter)&&!r&&i!=this.view.contentDOM&&this.lineBreak();break}let o=rn.get(r);(s&&o?s.breakAfter:(s?s.breakAfter:Fe(n))||Fe(r)&&("BR"!=n.nodeName||(null==s?void 0:s.isWidget()))&&this.text.length>t)&&!Qn(r,e)&&this.lineBreak(),n=r}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let s,r=-1,o=1;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(s=n.exec(e))&&(r=s.index,o=s[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=o-1);i=r+o}}readNode(t){let e=rn.get(t),i=e&&e.overrideDOMText;if(null!=i){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;)t.lineBreak?this.lineBreak():this.append(t.value)}else 3==t.nodeType?this.readTextNode(t):"BR"==t.nodeName?t.nextSibling&&this.lineBreak():1==t.nodeType&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(3==t.nodeType?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(Un(t,i.node,i.offset)?e:0))}}function Un(t,e,i){for(;;){if(!e||i<_e(e))return!1;if(e==t)return!0;i=ze(e)+1,e=e.parentNode}}function Qn(t,e){let i;for(;t!=e&&t;t=t.nextSibling){let e=rn.get(t);if(!(null==e?void 0:e.isWidget()))return!1;e&&(i||(i=[])).push(e)}if(i)for(let t of i){let e=t.overrideDOMText;if(null==e?void 0:e.length)return!1}return!0}class $n{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class Kn{constructor(t,e,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:s,impreciseAnchor:r}=t.docView,o=t.state.selection;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=jn(t.docView.tile,e,i,0))){let e=s||r?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}=t.observer.selectionRange;i&&(e.push(new $n(i,n)),s==i&&r==n||e.push(new $n(s,r)));return e}(t),i=new _n(e,t);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(t,e){if(0==t.length)return null;let i=t[0].pos,n=2==t.length?t[1].pos:i;return i>-1&&n>-1?W.single(i+e,n+e):null}(e,this.bounds.from)}else{let e=t.observer.selectionRange,i=s&&s.node==e.focusNode&&s.offset==e.focusOffset||!Ne(t.contentDOM,e.focusNode)?o.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),n=r&&r.node==e.anchorNode&&r.offset==e.anchorOffset||!Ne(t.contentDOM,e.anchorNode)?o.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset),l=t.viewport;if((ye.ios||ye.chrome)&&i!=n&&Math.min(i,n)<=o.main.from&&Math.max(i,n)>=o.main.to&&(l.from>0||l.to-1&&o.ranges.length>1)this.newSel=o.replaceRange(W.range(n,i));else if(t.lineWrapping&&n==i&&(!o.main.empty||o.main.head!=i)&&t.inputState.lastTouchTime>Date.now()-100){let e=t.coordsAtPos(i,-1),n=0;e&&(n=t.inputState.lastTouchY<=e.bottom?-1:1),this.newSel=W.create([W.cursor(i,n)])}else this.newSel=W.single(n,i)}}}function jn(t,e,i,n){if(t.isComposite()){let s=-1,r=-1,o=-1,l=-1;for(let a=0,h=n,c=n;ai)return jn(n,e,i,h);if(u>=e&&-1==s&&(s=a,r=h),h>i&&n.dom.parentNode==t.dom){o=a,l=c;break}c=u,h=u+n.breakAfter}return{from:r,to:l<0?n+t.length:l,startDOM:(s?t.children[s-1].dom.nextSibling:null)||t.dom.firstChild,endDOM:o=0?t.children[o].dom:null}}return t.isText()?{from:n,to:n+t.length,startDOM:t.dom,endDOM:t.dom.nextSibling}:null}function Xn(t,e){let i,{newSel:n}=e,{state:s}=t,r=s.selection.main,o=t.inputState.lastKeyTime>Date.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:t,to:n}=e.bounds,l=r.from,a=null;(8===o||ye.android&&e.text.length=t&&r.to<=n&&(e.typeOver||u!=e.text)&&u.slice(0,r.from-t)==e.text.slice(0,r.from-t)&&u.slice(r.to-t)==e.text.slice(h=e.text.length-(u.length-(r.to-t)))?i={from:r.from,to:r.to,insert:f.of(e.text.slice(r.from-t,h).split(qn))}:(c=Yn(u,e.text,l-t,a))&&(ye.chrome&&13==o&&c.toB==c.from+2&&e.text.slice(c.from,c.toB)==qn+qn&&c.toB--,i={from:t+c.from,to:t+c.toA,insert:f.of(e.text.slice(c.from,c.toB).split(qn))})}else n&&(!t.hasFocus&&s.facet(Vi)||Jn(n,r))&&(n=null);if(!i&&!n)return!1;if((ye.mac||ye.android)&&i&&i.from==i.to&&i.from==r.head-1&&/^\. ?$/.test(i.insert.toString())&&"off"==t.contentDOM.getAttribute("autocorrect")?(n&&2==i.insert.length&&(n=W.single(n.main.anchor-1,n.main.head-1)),i={from:i.from,to:i.to,insert:f.of([i.insert.toString().replace("."," ")])}):s.doc.lineAt(r.from).toDate.now()-50?i={from:r.from,to:r.to,insert:s.toText(t.inputState.insertingText)}:ye.chrome&&i&&i.from==i.to&&i.from==r.head&&"\n "==i.insert.toString()&&t.lineWrapping&&(n&&(n=W.single(n.main.anchor-1,n.main.head-1)),i={from:r.from,to:r.to,insert:f.of([" "])}),i)return Gn(t,i,n,o);if(n&&!Jn(n,r)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin,"select.pointer"==i&&(n=Wn(s.facet(Xi).map(e=>e(t)),n))),t.dispatch({selection:n,scrollIntoView:e,userEvent:i}),!0}return!1}function Gn(t,e,i,n=-1){if(ye.ios&&t.inputState.flushIOSKey(e))return!0;let s=t.state.selection.main;if(ye.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&" "==t.state.sliceDoc(e.from,s.from))&&1==e.insert.length&&2==e.insert.lines&&Ze(t.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&0==e.insert.length||8==n&&e.insert.lengths.head)&&Ze(t.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&0==e.insert.length&&Ze(t.contentDOM,"Delete",46)))return!0;let r,o=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let l=()=>r||(r=function(t,e,i){let n,s=t.state,r=s.selection.main,o=-1;if(e.from==e.to&&e.fromr.to){let i=e.frome(t)),n,i);e.from==l&&(o=l)}if(o>-1)n={changes:e,selection:W.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=r.frome.to?s.sliceDoc(e.to,r.to):"";n=s.replaceSelection(t.state.toText(i+e.insert.sliceString(0,void 0,t.state.lineBreak)+o))}else{let o=s.changes(e),l=i&&i.main.to<=o.newLength?i.main:void 0;if(s.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let a,h=t.state.sliceDoc(e.from,e.to),c=i&&Rn(t,i.main.head);if(c){let t=e.insert.length-(e.to-e.from);a={from:c.from,to:c.to-t}}else a=t.state.doc.lineAt(r.head);let u=r.to-e.to;n=s.changeByRange(i=>{if(i.from==r.from&&i.to==r.to)return{changes:o,range:l||i.map(o)};let n=i.to-u,c=n-h.length;if(t.state.sliceDoc(c,n)!=h||n>=a.from&&c<=a.to)return{range:i};let f=s.changes({from:c,to:n,insert:e.insert}),d=i.to-r.to;return{changes:f,range:l?W.range(Math.max(0,l.anchor+d),Math.max(0,l.head+d)):i.map(f)}})}else n={changes:o,selection:l&&s.selection.replaceRange(l)}}let l="input.type";(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,l+=".compose",t.inputState.compositionFirstChange&&(l+=".start",t.inputState.compositionFirstChange=!1));return s.update(n,{userEvent:l,scrollIntoView:!0})}(t,e,i));return t.state.facet(Ti).some(i=>i(t,e.from,e.to,o,l))||t.dispatch(l()),!0}function Yn(t,e,i,n){let s=Math.min(t.length,e.length),r=0;for(;r0&&l>0&&t.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if("end"==n){i-=o+Math.max(0,r-Math.min(o,l))-r}if(o=o?r-i:0,l=r+(l-o),o=r}else if(l=l?r-i:0,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function Jn(t,e){return e.head==t.main.head&&e.anchor==t.main.anchor}class Zn{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,ye.safari&&t.contentDOM.addEventListener("input",()=>null),ye.gecko&&function(t){Ss.has(t)||(Ss.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}(t.contentDOM.ownerDocument)}handleEvent(t){(function(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,n=e.target;n!=t.contentDOM;n=n.parentNode)if(!n||11==n.nodeType||(i=rn.get(n))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0})(this.view,t)&&!this.ignoreDuringComposition(t)&&("keydown"==t.type&&this.keydown(t)||(0!=this.view.updateState?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t)))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=es(t),i=this.handlers,n=this.view.contentDOM;for(let t in e)if("scroll"!=t){let s=!e[t].handlers.length,r=i[t];r&&s!=!r.handlers.length&&(n.removeEventListener(t,this.handleEvent),r=null),r||n.addEventListener(t,this.handleEvent,{passive:s})}for(let t in i)"scroll"==t||e[t]||n.removeEventListener(t,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=t.keyCode&&ss.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),ye.android&&ye.chrome&&!t.synthetic&&(13==t.keyCode||8==t.keyCode))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;if(ye.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&(is.some(e=>e.keyCode==t.keyCode)&&!t.ctrlKey||ns.indexOf(t.key)>-1&&t.ctrlKey)){let i={ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey,shiftKey:t.shiftKey};return i.shiftKey&&ye.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&((e=this.view.win).visualViewport&&e.visualViewport.height*e.visualViewport.scale/e.document.documentElement.clientHeight<.85)&&(i.shiftKey=!1),this.pendingIOSKey={key:t.key,keyCode:t.keyCode,mods:i},setTimeout(()=>this.flushIOSKey(),250),!0}var e;return 229!=t.keyCode&&this.view.observer.forceFlush(),!1}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(!("Enter"==e.key&&t&&t.from0||!!(ye.safari&&!ye.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function ts(t,e){return(i,n)=>{try{return e.call(t,n,i)}catch(t){Hi(i.state,t)}}}function es(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let e of t){let t=e.spec,n=t&&t.plugin.domEventHandlers,s=t&&t.plugin.domEventObservers;if(n)for(let t in n){let s=n[t];s&&i(t).handlers.push(ts(e.value,s))}if(s)for(let t in s){let n=s[t];n&&i(t).observers.push(ts(e.value,n))}}for(let t in ls)i(t).handlers.push(ls[t]);for(let t in as)i(t).observers.push(as[t]);return e}const is=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],ns="dthko",ss=[16,17,18,20,91,92,224,225];function rs(t){return.7*Math.max(0,t)+8}class os{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=Ke(t.contentDOM),this.atoms=t.state.facet(Xi).map(e=>e(t));let s=t.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(Tt.allowMultipleSelections)&&function(t,e){let i=t.state.facet(Si);return i.length?i[0](e):ye.mac?e.metaKey:e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let n=Ie(t.root);if(!n||0==n.rangeCount)return!0;let s=n.getRangeAt(0).getClientRects();for(let t=0;t=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}(t,e)||1!=vs(e))&&null}start(t){!1===this.dragging&&this.select(t)}move(t){if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(e=this.startEvent,i=t,Math.max(Math.abs(e.clientX-i.clientX),Math.abs(e.clientY-i.clientY))<10))return;var e,i;this.select(this.lastEvent=t);let n=0,s=0,r=0,o=0,l=this.view.win.innerWidth,a=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:o,bottom:a}=this.scrollParents.y.getBoundingClientRect());let h=Zi(this.view);t.clientX-h.left<=r+6?n=-rs(r-t.clientX):t.clientX+h.right>=l-6&&(n=rs(t.clientX-l)),t.clientY-h.top<=o+6?s=-rs(o-t.clientY):t.clientY+h.bottom>=a-6&&(s=rs(t.clientY-a)),this.setScrollSpeed(n,s)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),!1===this.dragging&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=Wn(this.atoms,this.style.get(t,this.extend,this.multiple));!this.mustSelect&&i.eq(e.state.selection,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}const ls=Object.create(null),as=Object.create(null),hs=ye.ie&&ye.ie_version<15||ye.ios&&ye.webkit_version<604;function cs(t,e,i){for(let n of t.facet(e))i=n(i,t);return i}function us(t,e){e=cs(t.state,Ri,e);let i,{state:n}=t,s=1,r=n.toText(e),o=r.lines==n.selection.ranges.length;if(null!=bs&&n.selection.ranges.every(t=>t.empty)&&bs==r.toString()){let t=-1;i=n.changeByRange(i=>{let l=n.doc.lineAt(i.from);if(l.from==t)return{range:i};t=l.from;let a=n.toText((o?r.line(s++).text:e)+n.lineBreak);return{changes:{from:l.from,insert:a},range:W.cursor(i.from+a.length)}})}else i=o?n.changeByRange(t=>{let e=r.line(s++);return{changes:{from:t.from,to:t.to,insert:e.text},range:W.cursor(t.from+e.length)}}):n.replaceSelection(r);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function fs(t,e,i,n){if(1==n)return W.cursor(e,i);if(2==n)return function(t,e,i=1){let n=t.charCategorizer(e),s=t.doc.lineAt(e),r=e-s.from;if(0==s.length)return W.cursor(e);0==r?i=1:r==s.length&&(i=-1);let o=r,l=r;i<0?o=k(s.text,r,!1):l=k(s.text,r);let a=n(s.text.slice(o,l));for(;o>0;){let t=k(s.text,o,!1);if(n(s.text.slice(t,o))!=a)break;o=t}for(;l{let e=t.inputState;e.lastScrollTop=t.scrollDOM.scrollTop,e.lastScrollLeft=t.scrollDOM.scrollLeft,ye.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())},as.wheel=as.mousewheel=t=>{t.inputState.lastWheelEvent=Date.now()},ls.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),27==e.keyCode&&0!=t.inputState.tabFocusMode&&(t.inputState.tabFocusMode=Date.now()+2e3),!1),as.touchstart=(t,e)=>{let i=t.inputState,n=e.targetTouches[0];i.touchActive=!0,i.lastTouchTime=Date.now(),n&&(i.lastTouchX=n.clientX,i.lastTouchY=n.clientY),i.setSelectionOrigin("select.pointer")},as.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},as.touchend=(t,e)=>{t.inputState.touchActive=!1},ls.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let n of t.state.facet(Ai))if(i=n(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),n=vs(e),s=t.state.selection;return{update(t){t.docChanged&&(i.pos=t.changes.mapPos(i.pos),s=s.map(t.changes))},get(e,r,o){let l,a=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),h=fs(t,a.pos,a.assoc,n);if(i.pos!=a.pos&&!r){let e=fs(t,i.pos,i.assoc,n),s=Math.min(e.from,h.from),r=Math.max(e.to,h.to);h=s1&&(l=function(t,e){for(let i=0;i=e)return W.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}(s,a.pos))?l:o?s.addRange(h):W.create([h])}}}(t,e)),i){let n=!t.hasFocus;t.inputState.startMouseSelection(new os(t,e,i,n)),n&&t.observer.ignore(()=>{Ye(t.contentDOM);let e=t.root.activeElement;e&&!e.contains(t.contentDOM)&&e.blur()});let s=t.inputState.mouseSelection;if(s)return s.start(e),!1===s.dragging}else t.inputState.setSelectionOrigin("select.pointer");return!1};const ds=ye.ie&&ye.ie_version<=11;let ps=null,ms=0,gs=0;function vs(t){if(!ds)return t.detail;let e=ps,i=gs;return ps=t,gs=Date.now(),ms=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(ms+1)%3:1}function ws(t,e,i,n){if(!(i=cs(t.state,Ri,i)))return;let s=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=t.inputState,o=n&&r&&function(t,e){let i=t.state.facet(Ci);return i.length?i[0](e):ye.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:r.from,to:r.to}:null,l={from:s,insert:i},a=t.state.changes(o?[o,l]:l);t.focus(),t.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),t.inputState.draggedContent=null}ls.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let n=t.docView.tile.nearest(e.target);if(n&&n.isWidget()){let t=n.posAtStart,e=t+n.length;(t>=i.to||e<=i.from)&&(i=W.undirectionalRange(t,e))}}let{inputState:n}=t;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",cs(t.state,Pi,t.state.sliceDoc(i.from,i.to))),e.dataTransfer.effectAllowed="copyMove"),!1},ls.dragend=t=>(t.inputState.draggedContent=null,!1),ls.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let n=Array(i.length),s=0,r=()=>{++s==i.length&&ws(t,e,n.filter(t=>null!=t).join(t.state.lineBreak),!1)};for(let t=0;t{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(n[t]=e.result),r()},e.readAsText(i[t])}return!0}{let i=e.dataTransfer.getData("Text");if(i)return ws(t,e,i,!0),!0}return!1},ls.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=hs?null:e.clipboardData;return i?(us(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{t.focus(),i.remove(),us(t,i.value)},50)}(t),!1)};let bs=null;ls.copy=ls.cut=(t,e)=>{if(!We(t.contentDOM,t.observer.selectionRange))return!1;let{text:i,ranges:n,linewise:s}=function(t){let e=[],i=[],n=!1;for(let n of t.selection.ranges)n.empty||(e.push(t.sliceDoc(n.from,n.to)),i.push(n));if(!e.length){let s=-1;for(let{from:n}of t.selection.ranges){let r=t.doc.lineAt(n);r.number>s&&(e.push(r.text),i.push({from:r.from,to:Math.min(t.doc.length,r.to+1)})),s=r.number}n=!0}return{text:cs(t,Pi,e.join(t.lineBreak)),ranges:i,linewise:n}}(t.state);if(!i&&!s)return!1;bs=s?i:null,"cut"!=e.type||t.state.readOnly||t.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let r=hs?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",i),!0):(function(t,e){let i=t.dom.parentNode;if(!i)return;let n=i.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),t.focus()},50)}(t,i),!1)};const ys=dt.define();function xs(t,e){let i=[];for(let n of t.facet(Di)){let s=n(t,e);s&&i.push(s)}return i.length?t.update({effects:i,annotations:ys.of(!0)}):null}function ks(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=xs(t.state,e);i?t.dispatch(i):t.update([])}},10)}as.focus=t=>{t.inputState.lastFocusTime=Date.now(),t.scrollDOM.scrollTop||!t.inputState.lastScrollTop&&!t.inputState.lastScrollLeft||(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),ks(t)},as.blur=t=>{t.observer.clearSelectionRange(),ks(t)},as.compositionstart=as.compositionupdate=t=>{t.observer.editContext||(null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0))},as.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,ye.chrome&&ye.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))},as.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},ls.beforeinput=(t,e)=>{var i,n;if("insertText"!=e.inputType&&"insertCompositionText"!=e.inputType||(t.inputState.insertingText=e.data,t.inputState.insertingTextAt=Date.now()),"insertReplacementText"==e.inputType&&t.observer.editContext){let n=null===(i=e.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),s=e.getTargetRanges();if(n&&s.length){let e=s[0],i=t.posAtDOM(e.startContainer,e.startOffset),r=t.posAtDOM(e.endContainer,e.endOffset);return Gn(t,{from:i,to:r,insert:t.state.toText(n)},null),!0}}let s;if(ye.chrome&&ye.android&&(s=is.find(t=>t.inputType==e.inputType))&&(t.observer.delayAndroidKey(s.key,s.keyCode),"Backspace"==s.key||"Delete"==s.key)){let e=(null===(n=window.visualViewport)||void 0===n?void 0:n.height)||0;setTimeout(()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return ye.ios&&"deleteContentForward"==e.inputType&&t.observer.flushSoon(),ye.safari&&"insertText"==e.inputType&&t.inputState.composing>=0&&setTimeout(()=>as.compositionend(t,e),20),!1};const Ss=new Set;const Cs=["pre-wrap","normal","pre-line","break-spaces"];let As=!1;function Ms(){As=!1}class Os{constructor(t){this.lineWrapping=t,this.doc=f.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Cs.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i-1,l=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=s,l){this.heightSamples={};for(let t=0;t0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>Ps&&(As=!0),this.height=t)}replace(t,e,i){return Bs.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let s=this,r=i.doc;for(let o=n.length-1;o>=0;o--){let{fromA:l,toA:a,fromB:h,toB:c}=n[o],u=s.lineAt(l,Rs.ByPosNoHeight,i.setDoc(e),0,0),f=u.to>=a?u:s.lineAt(a,Rs.ByPosNoHeight,i,0,0);for(c+=f.to-a,a=f.to;o>0&&u.from<=n[o-1].toA;)l=n[o-1].fromA,h=n[o-1].fromB,o--,l2*s){let s=t[e-1];s.break?t.splice(--e,1,s.left,null,s.right):t.splice(--e,1,s.left,s.right),i+=1+s.break,n-=s.size}else{if(!(s>2*n))break;{let e=t[i];e.break?t.splice(i,1,e.left,null,e.right):t.splice(i,1,e.left,e.right),i+=2+e.break,s-=e.size}}else if(n=s&&r(this.lineAt(0,Rs.ByPos,i,n,s))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setMeasuredHeight(n),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ns extends Is{constructor(t,e,i){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(t,e){return new Ds(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let n=i[0];return 1==i.length&&(n instanceof Ns||n instanceof Ws&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof Ws?n=new Ns(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):Bs.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setMeasuredHeight(n):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Ws extends Bs{constructor(t){super(t,0)}heightMetrics(t,e){let i,n=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-n+1,o=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*r);i=e/r,this.length>r+1&&(o=(this.height-e)/(this.length-r-1))}else i=this.height/r;return{firstLine:n,lastLine:s,perLine:i,perChar:o}}blockAt(t,e,i,n){let{firstLine:s,lastLine:r,perLine:o,perChar:l}=this.heightMetrics(e,n);if(e.lineWrapping){let s=n+(t0){let t=i[i.length-1];t instanceof Ws?i[i.length-1]=new Ws(t.length+n):i.push(null,new Ws(n-1))}if(t>0){let e=i[0];e instanceof Ws?i[0]=new Ws(t+e.length):i.unshift(new Ws(t-1),null)}return Bs.of(i)}decomposeLeft(t,e){e.push(new Ws(t-1),null)}decomposeRight(t,e){e.push(null,new Ws(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let s=e+this.length;if(n&&n.from<=e+this.length&&n.more){let i=[],r=Math.max(e,n.from),o=-1;for(n.from>e&&i.push(new Ws(n.from-e-1).updateHeight(t,e));r<=s&&n.more;){let e=t.doc.lineAt(r).length;i.length&&i.push(null);let s=n.heights[n.index++],l=0;s<0&&(l=-s,s=n.heights[n.index++]),-1==o?o=s:Math.abs(s-o)>=Ps&&(o=-2);let a=new Ns(e,s,l);a.outdated=!1,i.push(a),r+=e+1}r<=s&&i.push(null,new Ws(s-r).updateHeight(t,r));let l=Bs.of(i);return(o<0||Math.abs(l.height-this.height)>=Ps||Math.abs(o-this.heightMetrics(t,e).perLine)>=Ps)&&(As=!0),Es(this,l)}return(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class Hs extends Bs{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return 1&this.flags}blockAt(t,e,i,n){let s=i+this.left.height;return to))return a;let h=e==Rs.ByPosNoHeight?Rs.ByPosNoHeight:Rs.ByPos;return l?a.join(this.right.lineAt(o,h,i,r,o)):this.left.lineAt(o,h,i,n,s).join(a)}forEachLine(t,e,i,n,s,r){let o=n+this.left.height,l=s+this.left.length+this.break;if(this.break)t=l&&this.right.forEachLine(t,e,i,o,l,r);else{let a=this.lineAt(l,Rs.ByPos,i,n,s);t=t&&a.from<=e&&r(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,o,l,r)}}replace(t,e,i){let n=this.left.length+this.break;if(ethis.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let s=[];t>0&&this.decomposeLeft(t,s);let r=s.length;for(let t of i)s.push(t);if(t>0&&Vs(s,r-1),e=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t2*e.size||e.size>2*t.size?Bs.of(this.break?[t,null,e]:[t,e]):(this.left=Es(this.left,t),this.right=Es(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:s,right:r}=this,o=e+s.length+this.break,l=null;return n&&n.from<=e+s.length&&n.more?l=s=s.updateHeight(t,e,i,n):s.updateHeight(t,e,i),n&&n.from<=o+r.length&&n.more?l=r=r.updateHeight(t,o,i,n):r.updateHeight(t,o,i),l?this.balanced(s,r):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Vs(t,e){let i,n;null==t[e]&&(i=t[e-1])instanceof Ws&&(n=t[e+1])instanceof Ws&&t.splice(e-1,3,new Ws(i.length+1+n.length))}class zs{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof Ns?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new Ns(t-this.pos,-1,0)),this.writtenTo=t,e>t&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t=5)&&this.addLineDeco(n,s,r)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTot&&this.nodes.push(new Ns(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new Ws(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof Ns)return t;let e=new Ns(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof Ns||this.isCovered?(this.writtenToi.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=n.overflow){let n=i.getBoundingClientRect();r=Math.max(r,n.left),o=Math.min(o,n.right),l=Math.max(l,n.top),a=Math.min(e==t.parentNode?s.innerHeight:a,n.bottom)}e="absolute"==n.position||"fixed"==n.position?i.offsetParent:i.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:r-i.left,right:Math.max(r,o)-i.left,top:l-(i.top+e),bottom:Math.max(l,a)-(i.top+e)}}function _s(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class Us{constructor(t,e,i,n){this.from=t,this.to=e,this.size=i,this.displaySize=n}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i"function"!=typeof t&&"cm-lineWrapping"==t.class);this.heightOracle=new Os(i),this.stateDeco=Ys(e),this.heightMap=Bs.empty().applyChanges(this.stateDeco,f.empty,this.heightOracle.setDoc(e.doc),[new en(0,0,0,e.doc.length)]);for(let t=0;t<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());t++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Te.set(this.lineGaps.map(t=>t.draw(this,!1))),this.scrollParent=t.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:t,to:e})=>n>=t&&n<=e)){let{from:e,to:i}=this.lineBlockAt(n);t.push(new Ks(e,i))}}return this.viewports=t.sort((t,e)=>t.from-e.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Gs:new Js(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(Zs(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=Ys(this.state);let n=t.changedRanges,s=en.extendWithRanges(n,function(t,e,i){let n=new Fs;return It.compare(t,e,i,n,0),n.changes}(i,this.stateDeco,t?t.changes:D.empty(this.state.doc.length))),r=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Ms(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=r||As)&&(t.flags|=2),o?(this.scrollAnchorPos=t.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=r);let l=s.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.headl.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,e));let a=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,t.flags|=this.updateForViewport(),(a||!t.changes.empty||2&t.flags)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(Ei)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:t}=this,e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,s=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?si.RTL:si.LTR;let r=this.heightOracle.mustRefreshForWrapping(s)||"refresh"===this.mustMeasureContent,o=e.getBoundingClientRect(),l=r||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let a=0,h=0;if(o.width&&o.height){let{scaleX:t,scaleY:i}=$e(e,o);(t>.005&&Math.abs(this.scaleX-t)>.005||i>.005&&Math.abs(this.scaleY-i)>.005)&&(this.scaleX=t,this.scaleY=i,a|=16,r=l=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;this.paddingTop==c&&this.paddingBottom==u||(this.paddingTop=c,this.paddingBottom=u,a|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,a|=16);let d=Ke(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=ti(this.scrollParent||t.win);let m=(this.printing?_s:qs)(e,this.paddingTop),g=m.top-this.pixelViewport.top,v=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(l=!0)),!this.inView&&!this.scrollTarget&&!function(t){let e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView||window;return e.left0&&e.top0}(t.dom))return 0;let b=o.width;if(this.contentDOMWidth==b&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=o.width,this.editorHeight=t.scrollDOM.clientHeight,a|=16),l){let e=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(e)&&(r=!0),r||n.lineWrapping&&Math.abs(b-this.contentDOMWidth)>n.charWidth){let{lineHeight:i,charWidth:o,textHeight:l}=t.docView.measureTextSize();r=i>0&&n.refresh(s,i,o,l,Math.max(5,b/o),e),r&&(t.docView.minWidth=0,a|=16)}g>0&&v>0?h=Math.max(g,v):g<0&&v<0&&(h=Math.min(g,v)),Ms();for(let i of this.viewports){let s=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=(r?Bs.empty().applyChanges(this.stateDeco,f.empty,this.heightOracle,[new en(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,r,new Ts(i.from,s))}As&&(a|=2)}let y=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return y&&(2&a&&(a|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),a|=this.updateForViewport()),(2&a||y)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(r?[]:this.lineGaps,t)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,s=this.heightOracle,{visibleTop:r,visibleBottom:o}=this,l=new Ks(n.lineAt(r-1e3*i,Rs.ByHeight,s,0,0).from,n.lineAt(o+1e3*(1-i),Rs.ByHeight,s,0,0).to);if(e){let{head:t}=e.range;if(tl.to){let i,r=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),o=n.lineAt(t,Rs.ByPos,s,0,0);i="center"==e.y?(o.top+o.bottom)/2-r/2:"start"==e.y||"nearest"==e.y&&t=o+Math.max(10,Math.min(i,250)))&&n>r-2e3&&s>1,r=n<<1;if(this.defaultTextDirection!=si.LTR&&!i)return[];let o=[],l=(n,r,a,h)=>{if(r-nn&&tt.from>=a.from&&t.to<=a.to&&Math.abs(t.from-n)t.frome));if(!f){if(rt.from<=r&&t.to>=r)){let t=e.moveToLineBoundary(W.cursor(r),!1,!0).head;t>n&&(r=t)}let t=this.gapSize(a,n,r,h);f=new Us(n,r,t,i||t<2e6?t:2e6)}o.push(f)},a=e=>{if(e.lengths&&(n.push({from:s,to:t}),r+=t-s),s=e}},20),s2e6)for(let i of t)i.from>=e.from&&i.frome.from&&l(e.from,o,e,s),at.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];It.spans(e,this.viewport.from,this.viewport.to,{span(t,e){i.push({from:t,to:e})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let e=0;e=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Zs(this.heightMap.lineAt(t,Rs.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Zs(this.heightMap.lineAt(this.scaler.fromDOM(t),Rs.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Zs(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Ks{constructor(t,e){this.from=t,this.to=e}}function js({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let n=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:s}=e[t],r=s-i;if(n<=r)return i+n;n-=r}}function Xs(t,e){let i=0;for(let{from:n,to:s}of t.ranges){if(e<=s){i+=e-n;break}i+=s-n}return i/t.total}const Gs={toDOM:t=>t,fromDOM:t=>t,scale:1,eq(t){return t==this}};function Ys(t){let e=t.facet($i).filter(t=>"function"!=typeof t),i=t.facet(ji).filter(t=>"function"!=typeof t);return i.length&&e.push(It.join(i)),e}class Js{constructor(t,e,i){let n=0,s=0,r=0;this.viewports=i.map(({from:i,to:s})=>{let r=e.lineAt(i,Rs.ByPos,t,0,0).top,o=e.lineAt(s,Rs.ByPos,t,0,0).bottom;return n+=o-r,{from:i,to:s,top:r,bottom:o,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);for(let t of this.viewports)t.domTop=r+(t.top-s)*this.scale,r=t.domBottom=t.domTop+(t.bottom-t.top),s=t.bottom}toDOM(t){for(let e=0,i=0,n=0;;e++){let s=ee.from==t.viewports[i].from&&e.to==t.viewports[i].to))}}function Zs(t,e){if(1==e.scale)return t;let i=e.toDOM(t.top),n=e.toDOM(t.bottom);return new Ds(t.from,t.length,i,n-i,Array.isArray(t._content)?t._content.map(t=>Zs(t,e)):t._content)}const tr=z.define({combine:t=>t.join(" ")}),er=z.define({combine:t=>t.indexOf(!0)>-1}),ir=Jt.newName(),nr=Jt.newName(),sr=Jt.newName(),rr={"&light":"."+nr,"&dark":"."+sr};function or(t,e,i){return new Jt(e,{finish:e=>/&/.test(e)?e.replace(/&\w*/,e=>{if("&"==e)return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]}):t+" "+e})}const lr=or("."+ir,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},rr),ar={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},hr=ye.ie&&ye.ie_version<=11;class cr{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new je,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let t of e)this.queue.push(t);(ye.ie&&ye.ie_version<=11||ye.ios&&t.composing)&&e.some(t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length)?this.flushSoon():this.flush()}),!window.EditContext||!ye.android||!1===t.constructor.EDIT_CONTEXT||ye.chrome&&ye.chrome_version<126||(this.editContext=new dr(t),t.state.facet(Vi)&&(t.contentDOM.editContext=this.editContext.editContext)),hr&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver(()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){("change"!=t.type&&t.type||t.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(Vi)?i.root.activeElement!=this.dom:!We(this.dom,n))return;let s=n.anchorNode&&i.docView.tile.nearest(n.anchorNode);s&&s.isWidget()&&s.widget.ignoreEvent(t)?e||(this.selectionChanged=!1):(ye.ie&&ye.ie_version<=11||ye.android&&ye.chrome)&&!i.state.selection.main.empty&&n.focusNode&&Ve(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=Ie(t.root);if(!e)return!1;let i=ye.safari&&11==t.root.nodeType&&t.root.activeElement==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return fr(t,i)}let i=null;function n(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",n,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",n,!0),i?fr(t,i):null}(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=We(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&Ze(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let s of t){let t=this.readMutation(s);t&&(t.typeOver&&(n=!0),-1==e?({from:e,to:i}=t):(e=Math.min(t.from,e),i=Math.max(t.to,i)))}return{from:e,to:i,typeOver:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&We(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new Kn(this.view,t,e,i);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=Xn(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!Jn(this.view.state.selection,e.newSel.main))&&this.view.update([]),n}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty("attributes"==t.type),"childList"==t.type){let i=ur(e,t.previousSibling||t.target.previousSibling,-1),n=ur(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(Vi)!=t.state.facet(Vi)&&(t.view.contentDOM.editContext=t.state.facet(Vi)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function ur(t,e,i){for(;e;){let n=rn.get(e);if(n&&n.parent==t)return n;let s=e.parentNode;e=s!=t.dom?s:i>0?e.nextSibling:e.previousSibling}return null}function fr(t,e){let i=e.startContainer,n=e.startOffset,s=e.endContainer,r=e.endOffset,o=t.docView.domAtPos(t.state.selection.main.anchor,1);return Ve(o.node,o.offset,s,r)&&([i,n,s,r]=[s,r,i,n]),{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}}class dr{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let n=t.state.selection.main,{anchor:s,head:r}=n,o=this.toEditorPos(i.updateRangeStart),l=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:o,drifted:!1});let a=l-o>i.text.length;o==this.from&&sthis.to&&(l=s);let h=Yn(t.state.sliceDoc(o,l),i.text,(a?n.from:n.to)-o,a?"end":null);if(!h){let e=W.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));return void(Jn(e,n)||t.dispatch({selection:e,userEvent:"select"}))}let c={from:h.from+o,to:h.toA+o,insert:f.of(i.text.slice(h.from,h.toB).split("\n"))};if((ye.mac||ye.android)&&c.from==r-1&&/^\. ?$/.test(i.text)&&"off"==t.contentDOM.getAttribute("autocorrect")&&(c={from:o,to:l,insert:f.of([i.text.replace("."," ")])}),this.pendingContextChange=c,!t.state.readOnly){let e=this.to-this.from+(c.to-c.from+c.insert.length);Gn(t,c,W.single(this.toEditorPos(i.selectionStart,e),this.toEditorPos(i.selectionEnd,e)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),c.from=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let n=[],s=null;for(let e=this.toEditorPos(i.rangeStart),r=this.toEditorPos(i.rangeEnd);e{let i=[];for(let t of e.getTextFormats()){let e=t.underlineStyle,n=t.underlineThickness;if(!/none/i.test(e)&&!/none/i.test(n)){let s=this.toEditorPos(t.rangeStart),r=this.toEditorPos(t.rangeEnd);if(s{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:e}=this.composing;this.composing=null,e&&this.reset(t.state)}};for(let t in this.handlers)e.addEventListener(t,this.handlers[t]);this.measureReq={read:t=>{let e=Ie(t.root);e&&e.rangeCount&&this.editContext.updateSelectionBounds(e.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((s,r,o,l,a)=>{if(i)return;let h=a.length-(r-s);if(n&&r>=n.to){if(n.from==s&&n.to==r&&n.insert.eq(a))return n=this.pendingContextChange=null,e+=h,void(this.to+=h);n=null,this.revertPending(t.state)}if(s+=e,(r+=e)<=this.from)this.from+=h,this.to+=h;else if(sthis.to||this.to-this.from+a.length>3e4)return void(i=!0);this.editContext.updateText(this.toContextPos(s),this.toContextPos(r),a.toString()),this.to+=h}e+=h}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(t=>!t.isUserEvent("input.type")&&t.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):this.applyEdits(t)&&this.rangeIsValid(t.state)?(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state):(this.pendingContextChange=null,this.reset(t.state)),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);this.editContext.selectionStart==i&&this.editContext.selectionEnd==n||this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to3e4)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class pr{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(t=>t.forEach(t=>i(t,this)))||(t=>this.update(t)),this.dispatch=this.dispatch.bind(this),this._root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new $s(this,t.state||Tt.create(t)),t.scrollTo&&t.scrollTo.is(Ni)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Fi).map(t=>new _i(t));for(let t of this.plugins)t.update(this);this.observer=new cr(this),this.inputState=new Zn(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Tn(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),(null===(e=document.fonts)||void 0===e?void 0:e.ready)&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...t){let e=1==t.length&&t[0]instanceof vt?t:1==t.length&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,n=!1,s=this.state;for(let e of t){if(e.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=e.state}if(this.destroyed)return void(this.viewState.state=s);let r=this.hasFocus,o=0,l=null;t.some(t=>t.annotation(ys))?(this.inputState.notifiedFocused=r,o=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,l=xs(s,r),l||(o=1));let a=this.observer.delayedAndroidKey,h=null;if(a?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(h=null)):this.observer.clear(),s.facet(Tt.phrases)!=this.state.facet(Tt.phrases))return this.setState(s);e=nn.create(this,s,t),e.flags|=o;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(c&&(c=c.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection,{x:i,y:n}=this.state.facet(pr.cursorScrollMargin);c=new Ii(t.empty?t:W.cursor(t.head,t.head>t.anchor?-1:1),"nearest","nearest",n,i)}for(let t of e.effects)t.is(Ni)&&(c=t.value.clip(this.state))}this.viewState.update(e,c),this.bidiCache=vr.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(tn)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some(t=>t.isUserEvent("select.pointer")))}finally{this.updateState=0}if(e.startState.facet(tr)!=e.state.facet(tr)&&(this.viewState.mustMeasureContent=!0),(i||n||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!e.empty)for(let t of this.state.facet(Oi))try{t(e)}catch(t){Hi(this.state,t,"update listener")}(l||h)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),h&&!Xn(this,h)&&a.force&&Ze(this.contentDOM,a.key,a.keyCode)})}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new $s(this,t),this.plugins=t.facet(Fi).map(t=>new _i(t)),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy(),this.docView=new Tn(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(Fi),i=t.state.facet(Fi);if(e!=i){let n=[];for(let s of i){let i=e.indexOf(s);if(i<0)n.push(new _i(s));else{let e=this.plugins[i];e.mustUpdate=t,n.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.viewState.scrollParent,n=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:r}=this.viewState;Math.abs(n-this.viewState.scrollOffset)>1&&(r=-1),this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(r<0)if(ti(i||this.win))s=-1,r=this.viewState.heightMap.height;else{let t=this.viewState.scrollAnchorAt(n);s=t.from,r=t.top}this.updateState=1;let o=this.viewState.measure();if(!o&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let l=[];4&o||([this.measureRequests,l]=[l,this.measureRequests]);let a=l.map(t=>{try{return t.read(this)}catch(t){return Hi(this.state,t),gr}}),h=nn.create(this,this.state,[]),c=!1;h.flags|=o,e?e.flags|=o:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),c=this.docView.update(h),c&&this.docViewUpdate());for(let t=0;t1||t<-1)&&!(ye.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){n+=t,i?i.scrollTop+=t:this.win.scrollBy(0,t),r=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let t of this.state.facet(Oi))t(e)}get themeClasses(){return ir+" "+(this.state.facet(er)?sr:nr)+" "+this.state.facet(tr)}updateAttrs(){let t=wr(this,Ui,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Vi)?"true":"false",class:"cm-content",style:`${ye.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),wr(this,Qi,e);let i=this.observer.ignore(()=>{let i=Ce(this.contentDOM,this.contentAttrs,e),n=Ce(this.dom,this.editorAttrs,t);return i||n});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)if(t.is(pr.announce)){e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(tn);let t=this.state.facet(pr.cspNonce);Jt.mount(this.root,this.styleModules.concat(lr).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(null!=t.key)for(let e=0;ee.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return Hn(this,t,In(this,t,e,i))}moveByGroup(t,e){return Hn(this,t,In(this,t,e,e=>function(t,e,i){let n=t.state.charCategorizer(e),s=n(i);return t=>{let e=n(t);return s==Ct.Space&&(s=e),s==e}}(this,t.head,e)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),s=i[e?i.length-1:0];return W.cursor(s.side(e,n)+t.from,s.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return function(t,e,i,n){let s=Ln(t,e.head,e.assoc||-1),r=n&&s.type==Oe.Text&&(t.lineWrapping||s.widgetLineBreaks)?t.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head):null;if(r){let e=t.dom.getBoundingClientRect(),n=t.textDirectionAt(s.from),o=t.posAtCoords({x:i==(n==si.LTR)?e.right-1:e.left+1,y:(r.top+r.bottom)/2});if(null!=o)return W.cursor(o,i?-1:1)}return W.cursor(i?s.to:s.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return Hn(this,t,function(t,e,i,n){let s=e.head,r=i?1:-1;if(s==(i?t.state.doc.length:0))return W.cursor(s,e.assoc);let o,l=e.goalColumn,a=t.contentDOM.getBoundingClientRect(),h=t.coordsAtPos(s,e.assoc||((e.empty?i:e.head==e.from)?1:-1)),c=t.documentTop;if(h)null==l&&(l=h.left-a.left),o=r<0?h.top:h.bottom;else{let e=t.viewState.lineBlockAt(s);null==l&&(l=Math.min(a.right-a.left,t.defaultCharacterWidth*(s-e.from))),o=(r<0?e.top:e.bottom)+c}let u=a.left+l,f=t.viewState.heightOracle.textHeight>>1,d=null!=n?n:f;for(let e=0;;e+=f){let n=o+(d+e)*r,s=zn(t,{x:u,y:n},!1,r);if(i?n>a.bottom:no:cthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>mr)return bi(t.length);let e,i=this.textDirectionAt(t.from);for(let n of this.bidiCache)if(n.from==t.from&&n.dir==i&&(n.fresh||mi(n.isolates,e=Yi(this,t))))return n.order;e||(e=Yi(this,t));let n=function(t,e,i){if(!t)return[new pi(0,0,e==oi?1:0)];if(e==ri&&!i.length&&!di.test(t))return bi(t.length);if(i.length)for(;t.length>gi.length;)gi[gi.length]=256;let n=[],s=e==ri?0:1;return wi(t,s,s,i,0,t.length,n),n}(t.text,i,e);return this.bidiCache.push(new vr(t.from,t.to,i,e,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||ye.safari&&(null===(t=this.inputState)||void 0===t?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ye(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((9==t.nodeType?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){var i,n,s,r;return Ni.of(new Ii("number"==typeof t?W.cursor(t):t,null!==(i=e.y)&&void 0!==i?i:"nearest",null!==(n=e.x)&&void 0!==n?n:"nearest",null!==(s=e.yMargin)&&void 0!==s?s:5,null!==(r=e.xMargin)&&void 0!==r?r:5))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Ni.of(new Ii(W.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){null==t?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:"boolean"==typeof t?this.inputState.tabFocusMode=t?0:-1:0!=this.inputState.tabFocusMode&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return qi.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return qi.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=Jt.newName(),n=[tr.of(i),tn.of(or(`.${i}`,t))];return e&&e.dark&&n.push(er.of(!0)),n}static baseTheme(t){return Z.lowest(tn.of(or("."+ir,t,rr)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&rn.get(i)||rn.get(t);return(null===(e=null==n?void 0:n.root)||void 0===e?void 0:e.view)||null}}pr.styleModule=tn,pr.inputHandler=Ti,pr.clipboardInputFilter=Ri,pr.clipboardOutputFilter=Pi,pr.scrollHandler=Li,pr.focusChangeEffect=Di,pr.perLineTextDirection=Bi,pr.exceptionSink=Mi,pr.updateListener=Oi,pr.editable=Vi,pr.mouseSelectionStyle=Ai,pr.dragMovesSelection=Ci,pr.clickAddsSelectionRange=Si,pr.decorations=$i,pr.blockWrappers=Ki,pr.outerDecorations=ji,pr.atomicRanges=Xi,pr.bidiIsolatedRanges=Gi,pr.cursorScrollMargin=z.define({combine:t=>{let e=5,i=5;for(let n of t)"number"==typeof n?e=i=n:({x:e,y:i}=n);return{x:e,y:i}}}),pr.scrollMargins=Ji,pr.darkTheme=er,pr.cspNonce=z.define({combine:t=>t.length?t[0]:""}),pr.contentAttributes=Qi,pr.editorAttributes=Ui,pr.lineWrapping=pr.contentAttributes.of({class:"cm-lineWrapping"}),pr.announce=gt.define();const mr=4096,gr={};class vr{constructor(t,e,i,n,s,r){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=s,this.order=r}static update(t,e){if(e.empty&&!t.some(t=>t.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:si.LTR;for(let s=Math.max(0,t.length-10);s=0;s--){let e=n[s],r="function"==typeof e?e(t):e;r&&xe(r,i)}return i}const br=ye.mac?"mac":ye.windows?"win":ye.linux?"linux":"key";function yr(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),!1!==i&&e.shiftKey&&(t="Shift-"+t),t}const xr=Z.default(pr.domEventHandlers({keydown:(t,e)=>Tr(Cr(e.state),t,e,"editor")})),kr=z.define({enables:xr}),Sr=new WeakMap;function Cr(t){let e=t.facet(kr),i=Sr.get(e);return i||Sr.set(e,i=function(t,e=br){let i=Object.create(null),n=Object.create(null),s=(t,e)=>{let i=n[t];if(null==i)n[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")},r=(t,n,r,o,l)=>{var a,h;let c=i[t]||(i[t]=Object.create(null)),u=n.split(/ (?!$)/).map(t=>function(t,e){const i=t.split(/-(?!$)/);let n,s,r,o,l=i[i.length-1];"Space"==l&&(l=" ");for(let t=0;t{let n=Ar={view:e,prefix:i,scope:t};return setTimeout(()=>{Ar==n&&(Ar=null)},Mr),!0}]})}let f=u.join(" ");s(f,!1);let d=c[f]||(c[f]={preventDefault:!1,stopPropagation:!1,run:(null===(h=null===(a=c._any)||void 0===a?void 0:a.run)||void 0===h?void 0:h.slice())||[]});r&&d.run.push(r),o&&(d.preventDefault=!0),l&&(d.stopPropagation=!0)};for(let n of t){let t=n.scope?n.scope.split(" "):["editor"];if(n.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));t._any||(t._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:s}=n;for(let e in t)t[e].run.push(t=>s(t,Or))}let s=n[e]||n.key;if(s)for(let e of t)r(e,s,n.run,n.preventDefault,n.stopPropagation),n.shift&&r(e,"Shift-"+s,n.shift,n.preventDefault,n.stopPropagation)}return i}(e.reduce((t,e)=>t.concat(e),[]))),i}let Ar=null;const Mr=4e3;let Or=null;function Tr(t,e,i,n){Or=e;let s=function(t){var e=!(ne&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||se&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?ie:ee)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(e),r=A(S(s,0))==s.length&&" "!=s,o="",l=!1,a=!1,h=!1;Ar&&Ar.view==i&&Ar.scope==n&&(o=Ar.prefix+" ",ss.indexOf(e.keyCode)<0&&(a=!0,Ar=null));let c,u,f=new Set,d=t=>{if(t){for(let e of t.run)if(!f.has(e)&&(f.add(e),e(i)))return t.stopPropagation&&(h=!0),!0;t.preventDefault&&(t.stopPropagation&&(h=!0),a=!0)}return!1},p=t[n];return p&&(d(p[o+yr(s,e,!r)])?l=!0:!r||!(e.altKey||e.metaKey||e.ctrlKey)||ye.windows&&e.ctrlKey&&e.altKey||ye.mac&&e.altKey&&!e.ctrlKey&&!e.metaKey||!(c=ee[e.keyCode])||c==s?r&&e.shiftKey&&d(p[o+yr(s,e,!0)])&&(l=!0):(d(p[o+yr(c,e,!0)])||e.shiftKey&&(u=ie[e.keyCode])!=s&&u!=c&&d(p[o+yr(u,e,!1)]))&&(l=!0),!l&&d(p._any)&&(l=!0)),a&&(l=!0),l&&h&&e.stopPropagation(),Or=null,l}class Dr{constructor(t,e,i,n,s){this.className=t,this.left=e,this.top=i,this.width=n,this.height=s}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className==this.className&&(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",null!=this.width&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let n=t.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let s=Rr(t);return[new Dr(e,n.left-s.left,n.top-s.top,null,n.bottom-n.top)]}return function(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let n=Math.max(i.from,t.viewport.from),s=Math.min(i.to,t.viewport.to),r=t.textDirection==si.LTR,o=t.contentDOM,l=o.getBoundingClientRect(),a=Rr(t),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),u=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=l.right-(c?parseInt(c.paddingRight):0),d=Ln(t,n,1),p=Ln(t,s,-1),m=d.type==Oe.Text?d:null,g=p.type==Oe.Text?p:null;m&&(t.lineWrapping||d.widgetLineBreaks)&&(m=Pr(t,n,1,m));g&&(t.lineWrapping||p.widgetLineBreaks)&&(g=Pr(t,s,-1,g));if(m&&g&&m.from==g.from&&m.to==g.to)return w(b(i.from,i.to,m));{let e=m?b(i.from,null,m):y(d,!1),n=g?b(null,i.to,g):y(p,!0),s=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2h&&n.from=r)break;l>s&&a(Math.max(t,s),null==e&&t<=h,Math.min(l,r),null==i&&l>=c,o.dir)}if(s=n.to+1,s>=r)break}return 0==l.length&&a(h,null==e,c,null==i,t.textDirection),{top:s,bottom:o,horizontal:l}}function y(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(t,e,i)}}function Rr(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==si.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function Pr(t,e,i,n){let s=t.coordsAtPos(e,2*i);if(!s)return n;let r=t.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=t.posAtCoords({x:r.left+1,y:o}),a=t.posAtCoords({x:r.right-1,y:o});return null==l||null==a?n:{from:Math.max(n.from,Math.min(l,a)),to:Math.min(n.to,Math.max(l,a))}}class Br{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(Er)!=t.state.facet(Er)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){!1!==this.layer.updateOnDocViewUpdate&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(Er);for(;e{return i=t,n=this.drawn[e],!(i.constructor==n.constructor&&i.eq(n));var i,n})){let e=this.dom.firstChild,i=0;for(let n of t)n.update&&e&&n.constructor&&this.drawn[i].constructor&&n.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(n.draw(),e);for(;e;){let t=e.nextSibling;e.remove(),e=t}this.drawn=t,ye.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Er=z.define();function Lr(t){return[qi.define(e=>new Br(e,t)),Er.of(t)]}const Ir=z.define({combine:t=>Dt(t,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function Nr(t={}){return[Ir.of(t),Hr,zr,Fr,Ei.of(!0)]}function Wr(t){return t.startState.facet(Ir)!=t.state.facet(Ir)}const Hr=Lr({above:!0,markers(t){let{state:e}=t,i=e.facet(Ir),n=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty||i.drawRangeCursor&&!(r&&ye.ios&&i.iosSelectionHandles)){let e=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=s.empty?s:W.cursor(s.head,s.assoc);for(let s of Dr.forRange(t,e,i))n.push(s)}}return n},update(t,e){t.transactions.some(t=>t.selection)&&(e.style.animationName="cm-blink"==e.style.animationName?"cm-blink2":"cm-blink");let i=Wr(t);return i&&Vr(t.state,e),t.docChanged||t.selectionSet||i},mount(t,e){Vr(e.state,t)},class:"cm-cursorLayer"});function Vr(t,e){e.style.animationDuration=t.facet(Ir).cursorBlinkRate+"ms"}const zr=Lr({above:!1,markers(t){let e=[],{main:i,ranges:n}=t.state.selection;for(let i of n)if(!i.empty)for(let n of Dr.forRange(t,"cm-selectionBackground",i))e.push(n);if(ye.ios&&!i.empty&&t.state.facet(Ir).iosSelectionHandles){for(let n of Dr.forRange(t,"cm-selectionHandle cm-selectionHandle-start",W.cursor(i.from,1)))e.push(n);for(let n of Dr.forRange(t,"cm-selectionHandle cm-selectionHandle-end",W.cursor(i.to,1)))e.push(n)}return e},update:(t,e)=>t.docChanged||t.selectionSet||t.viewportChanged||Wr(t),class:"cm-selectionLayer"}),Fr=Z.highest(pr.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),qr=gt.define({map:(t,e)=>null==t?null:e.mapPos(t)}),_r=K.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce((t,e)=>e.is(qr)?e.value:t,t))}),Ur=qi.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(_r);null==i?null!=this.cursor&&(null===(e=this.cursor)||void 0===e||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(_r)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(_r),i=null!=e&&t.coordsAtPos(e);if(!i)return null;let n=t.scrollDOM.getBoundingClientRect();return{left:i.left-n.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-n.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/i+"px",this.cursor.style.height=t.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(_r)!=t&&this.view.dispatch({effects:qr.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Qr(t,e,i,n,s){e.lastIndex=0;for(let r,o=t.iterRange(i,n),l=i;!o.next().done;l+=o.value.length)if(!o.lineBreak)for(;r=e.exec(o.value);)s(l+r.index,r)}class $r{constructor(t){const{regexp:e,decoration:i,decorate:n,boundary:s,maxLength:r=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,n)this.addMatch=(t,e,i,s)=>n(s,i,i+t[0].length,t,e);else if("function"==typeof i)this.addMatch=(t,e,n,s)=>{let r=i(t,e,n);r&&s(n,n+t[0].length,r)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(t,e,n,s)=>s(n,n+t[0].length,i)}this.boundary=s,this.maxLength=r}createDeco(t){let e=new Nt,i=e.add.bind(e);for(let{from:e,to:n}of function(t,e){let i=t.visibleRanges;if(1==i.length&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let n=[];for(let{from:s,to:r}of i)s=Math.max(t.state.doc.lineAt(s).from,s-e),r=Math.min(t.state.doc.lineAt(r).to,r+e),n.length&&n[n.length-1].to>=s?n[n.length-1].to=r:n.push({from:s,to:r});return n}(t,this.maxLength))Qr(t.state.doc,this.regexp,e,n,(e,n)=>this.addMatch(n,t,e,i));return e.finish()}updateDeco(t,e){let i=1e9,n=-1;return t.docChanged&&t.changes.iterChanges((e,s,r,o)=>{o>=t.view.viewport.from&&r<=t.view.viewport.to&&(i=Math.min(r,i),n=Math.max(o,n))}),t.viewportMoved||n-i>1e3?this.createDeco(t.view):n>-1?this.updateRange(t.view,e.map(t.changes),i,n):e}updateRange(t,e,i,n){for(let s of t.visibleRanges){let r=Math.max(s.from,i),o=Math.min(s.to,n);if(o>=r){let i=t.state.doc.lineAt(r),n=i.toi.from;r--)if(this.boundary.test(i.text[r-1-i.from])){l=r;break}for(;oc.push(i.range(t,e));if(i==n)for(this.regexp.lastIndex=l-i.from;(h=this.regexp.exec(i.text))&&h.indexthis.addMatch(i,t,e,u));e=e.update({filterFrom:l,filterTo:a,filter:(t,e)=>ta,add:c})}}return e}}const Kr=null!=/x/.unicode?"gu":"g",jr=new RegExp("[\0-\b\n--Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\ufeff-]",Kr),Xr={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Gr=null;const Yr=z.define({combine(t){let e=Dt(t,{render:null,specialChars:jr,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==Gr&&"undefined"!=typeof document&&document.body){let e=document.body.style;Gr=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return Gr||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,Kr)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Kr)),e}});function Jr(t={}){return[Yr.of(t),Zr||(Zr=qi.fromClass(class{constructor(t){this.view=t,this.decorations=Te.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(Yr)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new $r({regexp:t.specialChars,decoration:(e,i,n)=>{let{doc:s}=i.state,r=S(e[0],0);if(9==r){let t=s.lineAt(n),e=i.state.tabSize,r=Kt(t.text,e,n-t.from);return Te.replace({widget:new eo((e-r%e)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=Te.replace({widget:new to(t,r)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(Yr);t.startState.facet(Yr)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))]}let Zr=null;class to extends Me{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=function(t){return t>=32?"•":10==t?"␤":String.fromCharCode(9216+t)}(this.code),i=t.state.phrase("Control character")+" "+(Xr[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,e);if(n)return n;let s=document.createElement("span");return s.textContent=e,s.title=i,s.setAttribute("aria-label",i),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class eo extends Me{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}const io=Te.line({class:"cm-activeLine"}),no=qi.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let n of t.state.selection.ranges){let s=t.lineBlockAt(n.head);s.from>e&&(i.push(io.range(s.from)),e=s.from)}return Te.set(i)}},{decorations:t=>t.decorations}),so=2e3;function ro(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),n=t.state.doc.lineAt(i),s=i-n.from,r=s>so?-1:s==n.length?function(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}(t,e.clientX):Kt(n.text,t.state.tabSize,i-n.from);return{line:n.number,col:r,off:s}}function oo(t,e){let i=ro(t,e),n=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),s=t.state.doc.lineAt(e);i={line:s.number,col:i.col,off:Math.min(i.off,s.length)},n=n.map(t.changes)}},get(e,s,r){let o=ro(t,e);if(!o)return n;let l=function(t,e,i){let n=Math.min(e.line,i.line),s=Math.max(e.line,i.line),r=[];if(e.off>so||i.off>so||e.col<0||i.col<0){let o=Math.min(e.off,i.off),l=Math.max(e.off,i.off);for(let e=n;e<=s;e++){let i=t.doc.line(e);i.length<=l&&r.push(W.range(i.from+o,i.to+l))}}else{let o=Math.min(e.col,i.col),l=Math.max(e.col,i.col);for(let e=n;e<=s;e++){let i=t.doc.line(e),n=jt(i.text,o,t.tabSize,!0);if(n<0)r.push(W.cursor(i.to));else{let e=jt(i.text,l,t.tabSize);r.push(W.range(i.from+n,i.from+e))}}}return r}(t.state,i,o);return l.length?r?W.create(l.concat(n.ranges)):W.create(l):n}}:null}function lo(t){let e=(null==t?void 0:t.eventFilter)||(t=>t.altKey&&0==t.button);return pr.mouseSelectionStyle.of((t,i)=>e(i)?oo(t,i):null)}const ao={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},ho={style:"cursor: crosshair"};function co(t={}){let[e,i]=ao[t.key||"Alt"],n=qi.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)},mousemove(t){this.set(i(t))}}});return[n,pr.contentAttributes.of(t=>{var e;return(null===(e=t.plugin(n))||void 0===e?void 0:e.isDown)?ho:null})]}const uo="-10000px";class fo{constructor(t,e,i,n){this.facet=e,this.createTooltipView=i,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(t=>t);let s=null;this.tooltipViews=this.tooltips.map(t=>s=i(t,s))}update(t,e){var i;let n=t.state.facet(this.facet),s=n.filter(t=>t);if(n===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let r=[],o=e?[]:null;for(let i=0;ie[i]=t),e.length=o.length),this.input=n,this.tooltips=s,this.tooltipViews=r,!0}}function po(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const mo=z.define({combine:t=>{var e,i,n;return{position:ye.ios?"absolute":(null===(e=t.find(t=>t.position))||void 0===e?void 0:e.position)||"fixed",parent:(null===(i=t.find(t=>t.parent))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(n=t.find(t=>t.tooltipSpace))||void 0===n?void 0:n.tooltipSpace)||po}}}),go=new WeakMap,vo=qi.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(mo);this.position=e.position,this.parent=e.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new fo(t,xo,(t,e)=>this.createTooltip(t,e),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),t.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let i=e||t.geometryChanged,n=t.state.facet(mo);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view),n=e?e.dom:null;if(i.dom.classList.add("cm-tooltip"),t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",i.dom.appendChild(t)}return i.dom.style.position=this.position,i.dom.style.top=uo,i.dom.style.left="0px",this.container.insertBefore(i.dom,n),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),null===(t=e.destroy)||void 0===t||t.call(e);this.parent&&this.container.remove(),null===(e=this.resizeObserver)||void 0===e||e.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,i=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(ye.safari){let e=t.getBoundingClientRect();i=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}else i=!!t.offsetParent&&t.offsetParent!=this.container.ownerDocument.body}if(i||"absolute"==this.position)if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(t=i.width/this.parent.offsetWidth,e=i.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);let n=this.view.scrollDOM.getBoundingClientRect(),s=Zi(this.view);return{visible:{left:n.left+s.left,top:n.top+s.top,right:n.right-s.right,bottom:n.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)}),size:this.manager.tooltipViews.map(({dom:t})=>t.getBoundingClientRect()),space:this.view.state.facet(mo).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{visible:i,space:n,scaleX:s,scaleY:r}=t,o=[];for(let l=0;l=Math.min(i.bottom,n.bottom)||u.rightMath.min(i.right,n.right)+.1)){c.style.top=uo;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=f.right-f.left,g=null!==(e=go.get(h))&&void 0!==e?e:f.bottom-f.top,v=h.offset||yo,w=this.view.textDirection==si.LTR,b=f.width>n.right-n.left?w?n.left:n.right-f.width:w?Math.max(n.left,Math.min(u.left-(d?14:0)+v.x,n.right-m)):Math.min(Math.max(n.left,u.left-m+(d?14:0)-v.x),n.right-m),y=this.above[l];!a.strictSide&&(y?u.top-g-p-v.yn.bottom)&&y==n.bottom-u.bottom>u.top-n.top&&(y=this.above[l]=!y);let x=(y?u.top-n.top:n.bottom-u.bottom)-p;if(xb&&t.topk&&(k=y?t.top-g-2-p:t.bottom+p+2);if("absolute"==this.position?(c.style.top=(k-t.parent.top)/r+"px",wo(c,(b-t.parent.left)/s)):(c.style.top=k/r+"px",wo(c,b/s)),d){let t=u.left+(w?v.x:-v.x)-(b+14-7);d.style.left=t/s+"px"}!0!==h.overlap&&o.push({left:b,top:k,right:S,bottom:k+g}),c.classList.toggle("cm-tooltip-above",y),c.classList.toggle("cm-tooltip-below",!y),h.positioned&&h.positioned(t.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let t of this.manager.tooltipViews)t.dom.style.top=uo}},{eventObservers:{scroll(){this.maybeMeasure()}}});function wo(t,e){let i=parseInt(t.style.left,10);(isNaN(i)||Math.abs(e-i)>1)&&(t.style.left=e+"px")}const bo=pr.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),yo={x:0,y:0},xo=z.define({enables:[vo,bo]}),ko=z.define({combine:t=>t.reduce((t,e)=>t.concat(e),[])});class So{static create(t){return new So(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new fo(t,ko,(t,e)=>this.createHostedView(t,e),t=>t.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)null===(t=e.destroy)||void 0===t||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let n=i[t];if(void 0!==n)if(void 0===e)e=n;else if(e!==n)return}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Co=xo.compute([ko],t=>{let e=t.facet(ko);return 0===e.length?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var e;return null!==(e=t.end)&&void 0!==e?e:t.pos})),create:So.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),Ao=z.define();class Mo{constructor(t,e,i,n,s,r){this.view=t,this.source=e,this.field=i,this.locked=n,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(t){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;ti.bottom||e.xi.right+t.defaultCharacterWidth)return;let r=t.bidiSpans(t.state.doc.lineAt(n)).find(t=>t.from<=n&&t.to>=n),o=r&&r.dir==si.RTL?-1:1;s=e.x{if(e&&(!Array.isArray(e)||e.length)){let i=Array.isArray(e)?e:[e];n&&this.locked.set(i,n),t.dispatch({effects:this.setHover.of(i)})}};if(s&&"then"in s){let i=this.pending={pos:e};s.then(t=>{this.pending==i&&(this.pending=null,r(t))},e=>Hi(t.state,e,"hover tooltip"))}else r(s)}get tooltip(){let t=this.view.plugin(vo),e=t?t.manager.tooltips.findIndex(t=>t.create==So.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:s}=this;if(n.length&&!this.locked.has(n)&&s&&!function(t,e){let i,{left:n,right:s,top:r,bottom:o}=t.getBoundingClientRect();if(i=t.querySelector(".cm-tooltip-arrow")){let t=i.getBoundingClientRect();r=Math.min(t.top,r),o=Math.max(t.bottom,o)}return e.clientX>=n-Oo&&e.clientX<=s+Oo&&e.clientY>=r-Oo&&e.clientY<=o+Oo}(s.dom,t)||this.pending){let{pos:s}=n[0]||this.pending,r=null!==(i=null===(e=n[0])||void 0===e?void 0:e.end)&&void 0!==i?i:s;(s==r?this.view.posAtCoords(this.lastMove)==s:function(t,e,i,n,s){let r=t.scrollDOM.getBoundingClientRect(),o=t.documentTop+t.documentPadding.top+t.contentHeight;if(r.left>n||r.rights||Math.min(r.bottom,o)=e&&l<=i}(this.view,s,r,t.clientX,t.clientY))||(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length&&!this.locked.has(e)){let{tooltip:e}=this;e&&e.dom.contains(t.relatedTarget)?this.watchTooltipLeave(e.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e);let{active:n}=this;!n.length||this.locked.has(n)||this.view.dom.contains(i.relatedTarget)||this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Oo=4;function To(t,e={}){let i=gt.define(),n=new WeakMap,s=K.define({create:()=>[],update(t,r){let o=n.get(t);if(t.length&&(e.hideOnChange&&(r.docChanged||r.selection)||o&&o(r)?t=[]:e.hideOn&&(t=t.filter(t=>!e.hideOn(r,t)))),r.docChanged&&t.length){let e=[];for(let i of t){let t=r.changes.mapPos(i.pos,-1,O.TrackDel);if(null!=t){let n=Object.assign(Object.create(null),i);n.pos=t,null!=n.end&&(n.end=r.changes.mapPos(n.end)),e.push(n)}}t=e}for(let e of r.effects)e.is(i)&&(t=e.value,o=void 0),(e.is(Ro)&&!e.value||e.value==s)&&(t=[]);return t.length&&o&&n.set(t,o),t},provide:t=>ko.from(t)});const r=qi.define(r=>new Mo(r,t,s,n,i,e.hoverTime||300));return{active:s,extension:[s,r,Ao.of(r),Co]}}function Do(t,e){let i=t.plugin(vo);if(!i)return null;let n=i.manager.tooltips.indexOf(e);return n<0?null:i.manager.tooltipViews[n]}const Ro=gt.define(),Po=z.define({combine(t){let e,i;for(let n of t)e=e||n.topContainer,i=i||n.bottomContainer;return{topContainer:e,bottomContainer:i}}});function Bo(t,e){let i=t.plugin(Eo),n=i?i.specs.indexOf(e):-1;return n>-1?i.panels[n]:null}const Eo=qi.fromClass(class{constructor(t){this.input=t.state.facet(No),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(e=>e(t));let e=t.state.facet(Po);this.top=new Lo(t,!0,e.topContainer),this.bottom=new Lo(t,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(t){let e=t.state.facet(Po);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Lo(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Lo(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(No);if(i!=this.input){let e=i.filter(t=>t),n=[],s=[],r=[],o=[];for(let i of e){let e,l=this.specs.indexOf(i);l<0?(e=i(t.view),o.push(e)):(e=this.panels[l],e.update&&e.update(t)),n.push(e),(e.top?s:r).push(e)}this.specs=e,this.panels=n,this.top.sync(s),this.bottom.sync(r);for(let t of o)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>pr.scrollMargins.of(e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}})});class Lo{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=Io(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Io(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(this.container&&this.classes!=this.view.themeClasses){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function Io(t){let e=t.nextSibling;return t.remove(),e}const No=z.define({enables:Eo});function Wo(t,e){let i,n=new Promise(t=>i=t),s=t=>function(t,e,i){let n=e.content?e.content(t,()=>o(null)):null;if(!n){if(n=le("form"),e.input){let t=le("input",e.input);/^(text|password|number|email|tel|url)$/.test(t.type)&&t.classList.add("cm-textfield"),t.name||(t.name="input"),n.appendChild(le("label",(e.label||"")+": ",t))}else n.appendChild(document.createTextNode(e.label||""));n.appendChild(document.createTextNode(" ")),n.appendChild(le("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let s="FORM"==n.nodeName?[n]:n.querySelectorAll("form");for(let t=0;t{27==t.keyCode?(t.preventDefault(),o(null)):13==t.keyCode&&(t.preventDefault(),o(e))}),e.addEventListener("submit",t=>{t.preventDefault(),o(e)})}let r=le("div",n,le("button",{onclick:()=>o(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(r.className=e.class);function o(e){r.contains(r.ownerDocument.activeElement)&&t.focus(),i(e)}return r.classList.add("cm-dialog"),{dom:r,top:e.top,mount:()=>{if(e.focus){let t;t="string"==typeof e.focus?n.querySelector(e.focus):n.querySelector("input")||n.querySelector("button"),t&&"select"in t?t.select():t&&"focus"in t&&t.focus()}}}}(t,e,i);t.state.field(Ho,!1)?t.dispatch({effects:Vo.of(s)}):t.dispatch({effects:gt.appendConfig.of(Ho.init(()=>[s]))});let r=zo.of(s);return{close:r,result:n.then(e=>((t.win.queueMicrotask||(e=>t.win.setTimeout(e,10)))(()=>{t.state.field(Ho).indexOf(s)>-1&&t.dispatch({effects:r})}),e))}}const Ho=K.define({create:()=>[],update(t,e){for(let i of e.effects)i.is(Vo)?t=[i.value].concat(t):i.is(zo)&&(t=t.filter(t=>t!=i.value));return t},provide:t=>No.computeN([t],e=>e.field(t))}),Vo=gt.define(),zo=gt.define();class Fo extends Rt{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Fo.prototype.elementClass="",Fo.prototype.toDOM=void 0,Fo.prototype.mapMode=O.TrackBefore,Fo.prototype.startSide=Fo.prototype.endSide=-1,Fo.prototype.point=!0;const qo=z.define(),_o=z.define(),Uo={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>It.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Qo=z.define();function $o(t){return[jo(),Qo.of({...Uo,...t})]}const Ko=z.define({combine:t=>t.some(t=>t)});function jo(t){let e=[Xo];return t&&!1===t.fixed&&e.push(Ko.of(!0)),e}const Xo=qi.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Qo).map(e=>new Zo(t,e)),this.fixed=!t.state.facet(Ko);for(let t of this.gutters)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,n=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(n<.8*(i.to-i.from))}if(t.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Ko)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let i=It.iter(this.view.state.facet(qo),this.view.viewport.from),n=[],s=this.gutters.map(t=>new Jo(t,this.view.viewport,-this.view.documentPadding.top));for(let t of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(t.type)){let e=!0;for(let r of t.type)if(r.type==Oe.Text&&e){Yo(i,n,r.from);for(let t of s)t.line(this.view,r,n);e=!1}else if(r.widget)for(let t of s)t.widget(this.view,r)}else if(t.type==Oe.Text){Yo(i,n,t.from);for(let e of s)e.line(this.view,t,n)}else if(t.widget)for(let e of s)e.widget(this.view,t);for(let t of s)t.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(Qo),i=t.state.facet(Qo),n=t.docChanged||t.heightChanged||t.viewportChanged||!It.eq(t.startState.facet(qo),t.state.facet(qo),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(n=!0);else{n=!0;let s=[];for(let n of i){let i=e.indexOf(n);i<0?s.push(new Zo(this.view,n)):(this.gutters[i].update(t),s.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),s.indexOf(t)<0&&t.destroy();for(let t of s)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.gutters=s}return n}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>pr.scrollMargins.of(e=>{let i=e.plugin(t);if(!i||0==i.gutters.length||!i.fixed)return null;let n=i.dom.offsetWidth*e.scaleX,s=i.domAfter?i.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==si.LTR?{left:n,right:s}:{right:n,left:s}})});function Go(t){return Array.isArray(t)?t:[t]}function Yo(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class Jo{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=It.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:n}=this,s=(e.top-this.height)/t.scaleY,r=e.height/t.scaleY;if(this.i==n.elements.length){let e=new tl(t,r,s,i);n.elements.push(e),n.dom.appendChild(e.dom)}else n.elements[this.i].update(t,r,s,i);this.height=e.bottom,this.i++}line(t,e,i){let n=[];Yo(this.cursor,n,e.from),i.length&&(n=n.concat(i));let s=this.gutter.config.lineMarker(t,e,n);s&&n.unshift(s);let r=this.gutter;(0!=n.length||r.config.renderEmptyElements)&&this.addElement(t,e,n)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),n=i?[i]:null;for(let i of t.state.facet(_o)){let s=i(t,e.widget,e);s&&(n||(n=[])).push(s)}n&&this.addElement(t,e,n)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Zo{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,n=>{let s,r=n.target;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let t=r.getBoundingClientRect();s=(t.top+t.bottom)/2}else s=n.clientY;let o=t.lineBlockAtHeight(s-t.documentTop);e.domEventHandlers[i](t,o,n)&&n.preventDefault()});this.markers=Go(e.markers(t)),e.initialSpacer&&(this.spacer=new tl(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=Go(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let i=t.view.viewport;return!It.eq(this.markers,e,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class tl{constructor(t,e,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,n)}update(t,e,i,n){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;iDt(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let n=i[t],s=e[t];i[t]=n?(t,e,i)=>n(t,e,i)||s(t,e,i):s}return i}})});class sl extends Fo{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function rl(t,e){return t.state.facet(nl).formatNumber(e,t.state)}const ol=Qo.compute([nl],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(el),lineMarker:(t,e,i)=>i.some(t=>t.toDOM)?null:new sl(rl(t,t.state.doc.lineAt(e.from).number)),widgetMarker:(t,e,i)=>{for(let n of t.state.facet(il)){let s=n(t,e,i);if(s)return s}return null},lineMarkerChange:t=>t.startState.facet(nl)!=t.state.facet(nl),initialSpacer:t=>new sl(rl(t,al(t.state.doc.lines))),updateSpacer(t,e){let i=rl(e.view,al(e.view.state.doc.lines));return i==t.number?t:new sl(i)},domEventHandlers:t.facet(nl).domEventHandlers,side:"before"}));function ll(t={}){return[nl.of(t),jo(),ol]}function al(t){let e=9;for(;e{let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.head).from;s>i&&(i=s,e.push(hl.range(s)))}return It.of(e)});const ul=1024;let fl=0;class dl{constructor(t,e){this.from=t,this.to=e}}class pl{constructor(t={}){this.id=fl++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof t&&(t=vl.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}pl.closedBy=new pl({deserialize:t=>t.split(" ")}),pl.openedBy=new pl({deserialize:t=>t.split(" ")}),pl.group=new pl({deserialize:t=>t.split(" ")}),pl.isolate=new pl({deserialize:t=>{if(t&&"rtl"!=t&&"ltr"!=t&&"auto"!=t)throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}}),pl.contextHash=new pl({perNode:!0}),pl.lookAhead=new pl({perNode:!0}),pl.mounted=new pl({perNode:!0});class ml{constructor(t,e,i,n=!1){this.tree=t,this.overlay=e,this.parser=i,this.bracketed=n}static get(t){return t&&t.props&&t.props[pl.mounted.id]}}const gl=Object.create(null);class vl{constructor(t,e,i,n=0){this.name=t,this.props=e,this.id=i,this.flags=n}static define(t){let e=t.props&&t.props.length?Object.create(null):gl,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),n=new vl(t.name||"",e,t.id,i);if(t.props)for(let i of t.props)if(Array.isArray(i)||(i=i(n)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[i[0].id]=i[1]}return n}prop(t){return this.props[t.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(pl.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let n of i.split(" "))e[n]=t[i];return t=>{for(let i=t.prop(pl.group),n=-1;n<(i?i.length:0);n++){let s=e[n<0?t.name:i[n]];if(s)return s}}}}vl.none=new vl("",Object.create(null),0,8);class wl{constructor(t){this.types=t;for(let e=0;e=e){let o=new Tl(r.tree,r.overlay[0].from+t.from,-1,t);(s||(s=[n])).push(Ml(o,e,i,!1))}}return s?El(s):n}(this,t,e)}iterate(t){let{enter:e,leave:i,from:n=0,to:s=this.length}=t,r=t.mode||0,o=(r&xl.IncludeAnonymous)>0;for(let t=this.cursor(r|xl.IncludeAnonymous);;){let r=!1;if(t.from<=s&&t.to>=n&&(!o&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;r=!0}for(;r&&i&&(o||!t.type.isAnonymous)&&i(t),!t.nextSibling();){if(!t.parent())return;r=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Vl(vl.none,this.children,this.positions,0,this.children.length,0,this.length,(t,e,i)=>new kl(this.type,t,e,i,this.propValues),t.makeTree||((t,e,i)=>new kl(vl.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:n,maxBufferLength:s=ul,reused:r=[],minRepeatType:o=n.types.length}=t,l=Array.isArray(i)?new Sl(i,i.length):i,a=n.types,h=0,c=0;function u(t,e,i,w,b,y){let{id:x,start:k,end:S,size:C}=l,A=c,M=h;if(C<0){if(l.next(),-1==C){let e=r[x];return i.push(e),void w.push(k-t)}if(-3==C)return void(h=x);if(-4==C)return void(c=x);throw new RangeError(`Unrecognized record size: ${C}`)}let O,T,D=a[x],R=k-t;if(S-k<=s&&(T=g(l.pos-e,b))){let e=new Uint16Array(T.size-T.skip),i=l.pos-T.size,s=e.length;for(;l.pos>i;)s=v(T.start,e,s);O=new Cl(e,S-T.start,n),R=T.start-t}else{let t=l.pos-C;l.next();let e=[],i=[],n=x>=o?x:-1,r=0,a=S;for(;l.pos>t;)n>=0&&l.id==n&&l.size>=0?(l.end<=a-s&&(p(e,i,k,r,l.end,a,n,A,M),r=e.length,a=l.end),l.next()):y>2500?f(k,t,e,i):u(k,t,e,i,n,y+1);if(n>=0&&r>0&&r-1&&r>0){let t=d(D,M);O=Vl(D,e,i,0,e.length,0,S-k,t,t)}else O=m(D,e,i,S-k,A-S,M)}i.push(O),w.push(R)}function f(t,e,i,r){let o=[],a=0,h=-1;for(;l.pos>e;){let{id:t,start:e,end:i,size:n}=l;if(n>4)l.next();else{if(h>-1&&e=0;t-=3)e[i++]=o[t],e[i++]=o[t+1]-s,e[i++]=o[t+2]-s,e[i++]=i;i.push(new Cl(e,o[2]-s,n)),r.push(s-t)}}function d(t,e){return(i,n,s)=>{let r,o,l=0,a=i.length-1;if(a>=0&&(r=i[a])instanceof kl){if(!a&&r.type==t&&r.length==s)return r;(o=r.prop(pl.lookAhead))&&(l=n[a]+r.length+o)}return m(t,i,n,s,l,e)}}function p(t,e,i,s,r,o,l,a,h){let c=[],u=[];for(;t.length>s;)c.push(t.pop()),u.push(e.pop()+i-r);t.push(m(n.types[l],c,u,o-r,a-o,h)),e.push(r-i)}function m(t,e,i,n,s,r,o){if(r){let t=[pl.contextHash,r];o=o?[t].concat(o):[t]}if(s>25){let t=[pl.lookAhead,s];o=o?[t].concat(o):[t]}return new kl(t,e,i,n,o)}function g(t,e){let i=l.fork(),n=0,r=0,a=0,h=i.end-s,c={size:0,start:0,skip:0};t:for(let s=i.pos-t;i.pos>s;){let t=i.size;if(i.id==e&&t>=0){c.size=n,c.start=r,c.skip=a,a+=4,n+=4,i.next();continue}let l=i.pos-t;if(t<0||l=o?4:0,f=i.start;for(i.next();i.pos>l;){if(i.size<0){if(-3!=i.size&&-4!=i.size)break t;u+=4}else i.id>=o&&(u+=4);i.next()}r=f,n+=t,a+=u}return(e<0||n==t)&&(c.size=n,c.start=r,c.skip=a),c.size>4?c:void 0}function v(t,e,i){let{id:n,start:s,end:r,size:a}=l;if(l.next(),a>=0&&n4){let n=l.pos-(a-4);for(;l.pos>n;)i=v(t,e,i)}e[--i]=o,e[--i]=r-t,e[--i]=s-t,e[--i]=n}else-3==a?h=n:-4==a&&(c=n);return i}let w=[],b=[];for(;l.pos>0;)u(t.start||0,t.bufferStart||0,w,b,-1,0);let y=null!==(e=t.length)&&void 0!==e?e:w.length?b[0]+w[0].length:0;return new kl(a[t.topID],w.reverse(),b.reverse(),y)}(t)}}kl.empty=new kl(vl.none,[],[],0);class Sl{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new Sl(this.buffer,this.index)}}class Cl{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return vl.none}toString(){let t=[];for(let e=0;e0));l=r[l+3]);return o}slice(t,e,i){let n=this.buffer,s=new Uint16Array(e-t),r=0;for(let o=t,l=0;o=e&&ie;case 1:return i<=e&&n>e;case 2:return n>e;case 4:return!0}}function Ml(t,e,i,n){for(var s;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to0?o.length:-1;t!=a;t+=e){let a,h=o[t],c=l[t]+r.from;if(s&xl.EnterBracketed&&h instanceof kl&&(a=ml.get(h))&&!a.overlay&&a.bracketed&&i>=c&&i<=c+h.length||Al(n,i,c,c+h.length))if(h instanceof Cl){if(s&xl.ExcludeBuffers)continue;let o=h.findChild(0,h.buffer.length,e,i-c,n);if(o>-1)return new Bl(new Pl(r,h,t,c),null,o)}else if(s&xl.IncludeAnonymous||!h.type.isAnonymous||Nl(h)){let o;if(!(s&xl.IgnoreMounts)&&(o=ml.get(h))&&!o.overlay)return new Tl(o.tree,c,t,r);let l=new Tl(h,c,t,r);return s&xl.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(e<0?h.children.length-1:0,e,i,n,s)}}if(s&xl.IncludeAnonymous||!r.type.isAnonymous)return null;if(t=r.index>=0?r.index+e:e<0?-1:r._parent._tree.children.length,r=r._parent,!r)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,e,i=0){let n;if(!(i&xl.IgnoreOverlays)&&(n=ml.get(this._tree))&&n.overlay){let s=t-this.from,r=i&xl.EnterBracketed&&n.bracketed;for(let{from:t,to:i}of n.overlay)if((e>0||r?t<=s:t=s:i>s))return new Tl(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Dl(t,e,i,n){let s=t.cursor(),r=[];if(!s.firstChild())return r;if(null!=i)for(let t=!1;!t;)if(t=s.type.is(i),!s.nextSibling())return r;for(;;){if(null!=n&&s.type.is(n))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return null==n?r:[]}}function Rl(t,e,i=e.length-1){for(let n=t;i>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[i]&&e[i]!=n.name)return!1;i--}}return!0}class Pl{constructor(t,e,i,n){this.parent=t,this.buffer=e,this.index=i,this.start=n}}class Bl extends Ol{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.context.start,i);return s<0?null:new Bl(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,e,i=0){if(i&xl.ExcludeBuffers)return null;let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return s<0?null:new Bl(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new Bl(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new Bl(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,n=this.index+4,s=i.buffer[this.index+3];if(s>n){let r=i.buffer[this.index+1];t.push(i.slice(n,s,r)),e.push(0)}return new kl(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function El(t){if(!t.length)return null;let e=0,i=t[0];for(let n=1;ni.from||s.to0){if(this.index-1)for(let n=e+t,s=t<0?-1:i._tree.children.length;n!=s;n+=t){let t=i._tree.children[n];if(this.mode&xl.IncludeAnonymous||t instanceof Cl||!t.type.isAnonymous||Nl(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to=0;){for(let r=t;r;r=r._parent)if(r.index==n){if(n==this.index)return r;e=r,i=s+1;break t}n=this.stack[--s]}for(let t=i;t=0;s--){if(s<0)return Rl(this._tree,t,n);let r=i[e.buffer[this.stack[s]]];if(!r.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}}function Nl(t){return t.children.some(t=>t instanceof Cl||!t.type.isAnonymous||Nl(t))}const Wl=new WeakMap;function Hl(t,e){if(!t.isAnonymous||e instanceof Cl||e.type!=t)return 1;let i=Wl.get(e);if(null==i){i=1;for(let n of e.children){if(n.type!=t||!(n instanceof kl)){i=1;break}i+=Hl(t,n)}Wl.set(e,i)}return i}function Vl(t,e,i,n,s,r,o,l,a){let h=0;for(let i=n;i=c)break;p+=e}if(h==s+1){if(p>c){let t=i[s];e(t.children,t.positions,0,t.children.length,n[s]+l);continue}u.push(i[s])}else{let e=n[h-1]+i[h-1].length-d;u.push(Vl(t,i,n,s,h,d,e,null,a))}f.push(d+l-r)}}(e,i,n,s,0),(l||a)(u,f,o)}class zl{constructor(t,e,i,n,s=!1,r=!1){this.from=t,this.to=e,this.tree=i,this.offset=n,this.open=(s?1:0)|(r?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],i=!1){let n=[new zl(0,t.length,t,0,!1,i)];for(let i of e)i.to>t.length&&n.push(i);return n}static applyChanges(t,e,i=128){if(!e.length)return t;let n=[],s=1,r=t.length?t[0]:null;for(let o=0,l=0,a=0;;o++){let h=o=i)for(;r&&r.from=e.from||c<=e.to||a){let t=Math.max(e.from,l)-a,i=Math.min(e.to,c)-a;e=t>=i?null:new zl(t,i,e.tree,e.offset+a,o>0,!!h)}if(e&&n.push(e),r.to>c)break;r=snew dl(t.from,t.to)):[new dl(0,0)]:[new dl(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let n=this.startParse(t,e,i);for(;;){let t=n.advance();if(t)return t}}}class ql{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new pl({perNode:!0});let _l=0;class Ul{constructor(t,e,i,n){this.name=t,this.set=e,this.base=i,this.modified=n,this.id=_l++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i="string"==typeof t?t:"?";if(t instanceof Ul&&(e=t),null==e?void 0:e.base)throw new Error("Can not derive from a modified tag");let n=new Ul(i,[],null,[]);if(n.set.push(n),e)for(let t of e.set)n.set.push(t);return n}static defineModifier(t){let e=new $l(t);return t=>t.modified.indexOf(e)>-1?t:$l.get(t.base||t,t.modified.concat(e).sort((t,e)=>t.id-e.id))}}let Ql=0;class $l{constructor(t){this.name=t,this.instances=[],this.id=Ql++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(i=>{return i.base==t&&(n=e,s=i.modified,n.length==s.length&&n.every((t,e)=>t==s[e]));var n,s});if(i)return i;let n=[],s=new Ul(t.name,n,t,e);for(let t of e)t.instances.push(s);let r=function(t){let e=[[]];for(let i=0;ie.length-t.length)}(e);for(let e of t.set)if(!e.modified.length)for(let t of r)n.push($l.get(e,t));return s}}function Kl(t){let e=Object.create(null);for(let i in t){let n=t[i];Array.isArray(n)||(n=[n]);for(let t of i.split(" "))if(t){let i=[],s=2,r=t;for(let e=0;;){if("..."==r&&e>0&&e+3==t.length){s=1;break}let n=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(r);if(!n)throw new RangeError("Invalid path: "+t);if(i.push("*"==n[0]?"":'"'==n[0][0]?JSON.parse(n[0]):n[0]),e+=n[0].length,e==t.length)break;let o=t[e++];if(e==t.length&&"!"==o){s=0;break}if("/"!=o)throw new RangeError("Invalid path: "+t);r=t.slice(e)}let o=i.length-1,l=i[o];if(!l)throw new RangeError("Invalid path: "+t);let a=new Xl(n,s,o>0?i.slice(0,o):null);e[l]=a.sort(e[l])}}return jl.add(e)}const jl=new pl({combine(t,e){let i,n,s;for(;t||e;){if(!t||e&&t.depth>=e.depth?(s=e,e=e.next):(s=t,t=t.next),i&&i.mode==s.mode&&!s.context&&!i.context)continue;let r=new Xl(s.tags,s.mode,s.context);i?i.next=r:n=r,i=r}return n}});class Xl{constructor(t,e,i,n){this.tags=t,this.mode=e,this.context=i,this.next=n}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(t){return!t||t.depth{let e=s;for(let n of t)for(let t of n.set){let n=i[t.id];if(n){e=e?e+" "+n:n;break}}return e},scope:n}}function Yl(t,e,i,n=0,s=t.length){let r=new Jl(n,Array.isArray(e)?e:[e],i);r.highlightRange(t.cursor(),n,s,"",r.highlighters),r.flush(s)}Xl.empty=new Xl([],2,null);class Jl{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,n,s){let{type:r,from:o,to:l}=t;if(o>=i||l<=e)return;r.isTop&&(s=this.highlighters.filter(t=>!t.scope||t.scope(r)));let a=n,h=function(t){let e=t.type.prop(jl);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}(t)||Xl.empty,c=function(t,e){let i=null;for(let n of t){let t=n.style(e);t&&(i=i?i+" "+t:t)}return i}(s,h.tags);if(c&&(a&&(a+=" "),a+=c,1==h.mode&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(e,o),a),h.opaque)return;let u=t.tree&&t.tree.prop(pl.mounted);if(u&&u.overlay){let r=t.node.enter(u.overlay[0].from+o,1),h=this.highlighters.filter(t=>!t.scope||t.scope(u.tree.type)),c=t.firstChild();for(let f=0,d=o;;f++){let p=f=m)&&t.nextSibling()););if(!p||m>i)break;d=p.to+o,d>e&&(this.highlightRange(r.cursor(),Math.max(e,p.from+o),Math.min(i,d),"",h),this.startSpan(Math.min(i,d),a))}c&&t.parent()}else if(t.firstChild()){u&&(n="");do{if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,n,s),this.startSpan(Math.min(i,t.to),a)}}while(t.nextSibling());t.parent()}}}const Zl=Ul.define,ta=Zl(),ea=Zl(),ia=Zl(ea),na=Zl(ea),sa=Zl(),ra=Zl(sa),oa=Zl(sa),la=Zl(),aa=Zl(la),ha=Zl(),ca=Zl(),ua=Zl(),fa=Zl(ua),da=Zl(),pa={comment:ta,lineComment:Zl(ta),blockComment:Zl(ta),docComment:Zl(ta),name:ea,variableName:Zl(ea),typeName:ia,tagName:Zl(ia),propertyName:na,attributeName:Zl(na),className:Zl(ea),labelName:Zl(ea),namespace:Zl(ea),macroName:Zl(ea),literal:sa,string:ra,docString:Zl(ra),character:Zl(ra),attributeValue:Zl(ra),number:oa,integer:Zl(oa),float:Zl(oa),bool:Zl(sa),regexp:Zl(sa),escape:Zl(sa),color:Zl(sa),url:Zl(sa),keyword:ha,self:Zl(ha),null:Zl(ha),atom:Zl(ha),unit:Zl(ha),modifier:Zl(ha),operatorKeyword:Zl(ha),controlKeyword:Zl(ha),definitionKeyword:Zl(ha),moduleKeyword:Zl(ha),operator:ca,derefOperator:Zl(ca),arithmeticOperator:Zl(ca),logicOperator:Zl(ca),bitwiseOperator:Zl(ca),compareOperator:Zl(ca),updateOperator:Zl(ca),definitionOperator:Zl(ca),typeOperator:Zl(ca),controlOperator:Zl(ca),punctuation:ua,separator:Zl(ua),bracket:fa,angleBracket:Zl(fa),squareBracket:Zl(fa),paren:Zl(fa),brace:Zl(fa),content:la,heading:aa,heading1:Zl(aa),heading2:Zl(aa),heading3:Zl(aa),heading4:Zl(aa),heading5:Zl(aa),heading6:Zl(aa),contentSeparator:Zl(la),list:Zl(la),quote:Zl(la),emphasis:Zl(la),strong:Zl(la),link:Zl(la),monospace:Zl(la),strikethrough:Zl(la),inserted:Zl(),deleted:Zl(),changed:Zl(),invalid:Zl(),meta:da,documentMeta:Zl(da),annotation:Zl(da),processingInstruction:Zl(da),definition:Ul.defineModifier("definition"),constant:Ul.defineModifier("constant"),function:Ul.defineModifier("function"),standard:Ul.defineModifier("standard"),local:Ul.defineModifier("local"),special:Ul.defineModifier("special")};for(let t in pa){let e=pa[t];e instanceof Ul&&(e.name=t)}var ma;Gl([{tag:pa.link,class:"tok-link"},{tag:pa.heading,class:"tok-heading"},{tag:pa.emphasis,class:"tok-emphasis"},{tag:pa.strong,class:"tok-strong"},{tag:pa.keyword,class:"tok-keyword"},{tag:pa.atom,class:"tok-atom"},{tag:pa.bool,class:"tok-bool"},{tag:pa.url,class:"tok-url"},{tag:pa.labelName,class:"tok-labelName"},{tag:pa.inserted,class:"tok-inserted"},{tag:pa.deleted,class:"tok-deleted"},{tag:pa.literal,class:"tok-literal"},{tag:pa.string,class:"tok-string"},{tag:pa.number,class:"tok-number"},{tag:[pa.regexp,pa.escape,pa.special(pa.string)],class:"tok-string2"},{tag:pa.variableName,class:"tok-variableName"},{tag:pa.local(pa.variableName),class:"tok-variableName tok-local"},{tag:pa.definition(pa.variableName),class:"tok-variableName tok-definition"},{tag:pa.special(pa.variableName),class:"tok-variableName2"},{tag:pa.definition(pa.propertyName),class:"tok-propertyName tok-definition"},{tag:pa.typeName,class:"tok-typeName"},{tag:pa.namespace,class:"tok-namespace"},{tag:pa.className,class:"tok-className"},{tag:pa.macroName,class:"tok-macroName"},{tag:pa.propertyName,class:"tok-propertyName"},{tag:pa.operator,class:"tok-operator"},{tag:pa.comment,class:"tok-comment"},{tag:pa.meta,class:"tok-meta"},{tag:pa.invalid,class:"tok-invalid"},{tag:pa.punctuation,class:"tok-punctuation"}]);const ga=new pl;const va=new pl;class wa{constructor(t,e,i=[],n=""){this.data=t,this.name=n,Tt.prototype.hasOwnProperty("tree")||Object.defineProperty(Tt.prototype,"tree",{get(){return xa(this)}}),this.parser=e,this.extension=[Ra.of(this),Tt.languageData.of((t,e,i)=>{let n=ba(t,e,i),s=n.type.prop(ga);if(!s)return[];let r=t.facet(s),o=n.type.prop(va);if(o){let s=n.resolve(e-n.from,i);for(let e of o)if(e.test(s,t)){let i=t.facet(e.facet);return"replace"==e.type?i:i.concat(r)}}return r})].concat(i)}isActiveAt(t,e,i=-1){return ba(t,e,i).type.prop(ga)==this.data}findRegions(t){let e=t.facet(Ra);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],n=(t,e)=>{if(t.prop(ga)==this.data)return void i.push({from:e,to:e+t.length});let s=t.prop(pl.mounted);if(s){if(s.tree.prop(ga)==this.data){if(s.overlay)for(let t of s.overlay)i.push({from:t.from+e,to:t.to+e});else i.push({from:e,to:e+t.length});return}if(s.overlay){let t=i.length;if(n(s.tree,s.overlay[0].from+e),i.length>t)return}}for(let i=0;it.concat(i):void 0}));var i;return new ya(e,t.parser.configure({props:[ga.add(t=>t.isTop?e:void 0)]}),t.name)}configure(t,e){return new ya(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function xa(t){let e=t.field(wa.state,!1);return e?e.tree:kl.empty}class ka{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let Sa=null;class Ca{constructor(t,e,i=[],n,s,r,o,l){this.parser=t,this.state=e,this.fragments=i,this.tree=n,this.treeLen=s,this.viewport=r,this.skipped=o,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new Ca(t,e,[],kl.empty,0,i,[],null)}startParse(){return this.parser.startParse(new ka(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=kl.empty&&this.isDone(null!=e?e:this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if("number"==typeof t){let e=Date.now()+t;t=()=>Date.now()>e}for(this.parse||(this.parse=this.startParse()),null!=e&&(null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&e=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(zl.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Sa;Sa=this;try{return t()}finally{Sa=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=Aa(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:n,treeLen:s,viewport:r,skipped:o}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges((t,i,n,s)=>e.push({fromA:t,toA:i,fromB:n,toB:s})),i=zl.applyChanges(i,e),n=kl.empty,s=0,r={from:t.mapPos(r.from,-1),to:t.mapPos(r.to,1)},this.skipped.length){o=[];for(let e of this.skipped){let i=t.mapPos(e.from,1),n=t.mapPos(e.to,-1);it.from&&(this.fragments=Aa(this.fragments,i,n),this.skipped.splice(e--,1))}return!(this.skipped.length>=e)&&(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Fl{createParse(e,i,n){let s=n[0].from,r=n[n.length-1].to;return{parsedPos:s,advance(){let e=Sa;if(e){for(let t of n)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=r,new kl(vl.none,[],[],r-s)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&0==e[0].from&&e[0].to>=t}static get(){return Sa}}function Aa(t,e,i){return zl.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class Ma{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Ma(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Ca.create(t.facet(Ra).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Ma(i)}}wa.state=K.define({create:Ma.init,update(t,e){for(let t of e.effects)if(t.is(wa.setState))return t.value;return e.startState.facet(Ra)!=e.state.facet(Ra)?Ma.init(e.state):t.apply(e)}});let Oa=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(Oa=t=>{let e=-1,i=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const Ta="undefined"!=typeof navigator&&(null===(ma=navigator.scheduling)||void 0===ma?void 0:ma.isInputPending)?()=>navigator.scheduling.isInputPending():null,Da=qi.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(wa.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(wa.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=Oa(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEndn+1e3,l=s.context.work(()=>Ta&&Ta()||Date.now()>r,n+(o?0:1e5));this.chunkBudget-=Date.now()-e,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:wa.setState.of(new Ma(s.context))})),this.chunkBudget>0&&(!l||o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Hi(this.view.state,t)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ra=z.define({combine:t=>t.length?t[0]:null,enables:t=>[wa.state,Da,pr.contentAttributes.compute([t],e=>{let i=e.facet(t);return i&&i.name?{"data-language":i.name}:{}})]});class Pa{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const Ba=z.define(),Ea=z.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function La(t){let e=t.facet(Ea);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function Ia(t,e){let i="",n=t.tabSize,s=t.facet(Ea)[0];if("\t"==s){for(;e>=n;)i+="\t",e-=n;s=" "}for(let t=0;t=e?function(t,e,i){let n=e.resolveStack(i),s=e.resolveInner(i,-1).resolve(i,0).enterUnfinishedNodesBefore(i);if(s!=n.node){let t=[];for(let e=s;e&&!(e.fromn.node.to||e.from==n.node.from&&e.type==n.node.type);e=e.parent)t.push(e);for(let e=t.length-1;e>=0;e--)n={node:t[e],next:n}}return Va(n,t,i)}(t,i,e):null}class Wa{constructor(t,e={}){this.state=t,this.options=e,this.unit=La(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:n,simulateDoubleBreak:s}=this.options;return null!=n&&n>=i.from&&n<=i.to?s&&n==t?{text:"",from:t}:(e<0?n-1&&(s+=r-this.countColumn(i,i.search(/\S|$/))),s}countColumn(t,e=t.length){return Kt(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:n}=this.lineAt(t,e),s=this.options.overrideIndentation;if(s){let t=s(n);if(t>-1)return t}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Ha=new pl;function Va(t,e,i){for(let n=t;n;n=n.next){let t=za(n.node);if(t)return t(qa.create(e,i,n))}return 0}function za(t){let e=t.type.prop(Ha);if(e)return e;let i,n=t.firstChild;if(n&&(i=n.type.prop(pl.closedBy))){let e=t.lastChild,n=e&&i.indexOf(e.name)>-1;return t=>function(t,e,i,n,s){let r=t.textAfter,o=r.match(/^\s*/)[0].length,l=n&&r.slice(o,o+n.length)==n||s==t.pos+o,a=e?function(t){let e=t.node,i=e.childAfter(e.from),n=e.lastChild;if(!i)return null;let s=t.options.simulateBreak,r=t.state.doc.lineAt(i.from),o=null==s||s<=r.from?r.to:Math.min(r.to,s);for(let t=i.to;;){let s=e.childAfter(t);if(!s||s==n)return null;if(!s.type.isSkipped){if(s.from>=o)return null;let t=/^ */.exec(r.text.slice(i.to-r.from))[0].length;return{from:i.from,to:i.to+t}}t=s.to}}(t):null;return a?l?t.column(a.from):t.column(a.to):t.baseIndent+(l?0:t.unit*i)}(t,!0,1,void 0,n&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?Fa:null}function Fa(){return 0}class qa extends Wa{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new qa(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(_a(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return Va(this.context.next,this.base,this.pos)}}function _a(t,e){for(let i=e;i;i=i.parent)if(t==i)return!0;return!1}function Ua({except:t,units:e=1}={}){return i=>{let n=t&&t.test(i.textAfter);return i.baseIndent+(n?0:e*i.unit)}}const Qa=z.define(),$a=new pl;function Ka(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function ja(t,e,i){for(let n of t.facet(Qa)){let s=n(t,e,i);if(s)return s}return function(t,e,i){let n=xa(t);if(n.lengthi)continue;if(s&&o.from=e&&n.to>i&&(s=n)}}return s}(t,e,i)}function Xa(t,e){let i=e.mapPos(t.from,1),n=e.mapPos(t.to,-1);return i>=n?void 0:{from:i,to:n}}const Ga=gt.define({map:Xa}),Ya=gt.define({map:Xa});function Ja(t){let e=[];for(let{head:i}of t.state.selection.ranges)e.some(t=>t.from<=i&&t.to>=i)||e.push(t.lineBlockAt(i));return e}const Za=K.define({create:()=>Te.none,update(t,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((e,i)=>t=th(t,e,i)),t=t.map(e.changes);let i=[];for(let n of e.effects)n.is(Ga)&&!ih(t,n.value.from,n.value.to)?i.push(n.value):n.is(Ya)&&(t=t.update({filter:(t,e)=>n.value.from!=t||n.value.to!=e,filterFrom:n.value.from,filterTo:n.value.to}));if(i.length){let{preparePlaceholder:n}=e.state.facet(lh),s=i.map(t=>(n?Te.replace({widget:new uh(n(e.state,t))}):ch).range(t.from,t.to));t=t.update({add:s})}return e.selection&&(t=th(t,e.selection.main.head)),t},provide:t=>pr.decorations.from(t),toJSON(t,e){let i=[];return t.between(0,e.doc.length,(t,e)=>{i.push(t,e)}),i},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let i=0;i{te&&(n=!0)}),n?t.update({filterFrom:e,filterTo:i,filter:(t,n)=>t>=i||n<=e}):t}function eh(t,e,i){var n;let s=null;return null===(n=t.field(Za,!1))||void 0===n||n.between(e,i,(t,e)=>{(!s||s.from>t)&&(s={from:t,to:e})}),s}function ih(t,e,i){let n=!1;return t.between(e,e,(t,s)=>{t==e&&s==i&&(n=!0)}),n}function nh(t,e){return t.field(Za,!1)?e:e.concat(gt.appendConfig.of(ah()))}function sh(t,e,i=!0){let n=t.state.doc.lineAt(e.from).number,s=t.state.doc.lineAt(e.to).number;return pr.announce.of(`${t.state.phrase(i?"Folded lines":"Unfolded lines")} ${n} ${t.state.phrase("to")} ${s}.`)}const rh=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of Ja(t)){let i=ja(t.state,e.from,e.to);if(i)return t.dispatch({effects:nh(t.state,[Ga.of(i),sh(t,i)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(Za,!1))return!1;let e=[];for(let i of Ja(t)){let n=eh(t.state,i.from,i.to);n&&e.push(Ya.of(n),sh(t,n,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,i=[];for(let n=0;n{let e=t.state.field(Za,!1);if(!e||!e.size)return!1;let i=[];return e.between(0,t.state.doc.length,(t,e)=>{i.push(Ya.of({from:t,to:e}))}),t.dispatch({effects:i}),!0}}],oh={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},lh=z.define({combine:t=>Dt(t,oh)});function ah(t){let e=[Za,mh];return t&&e.push(lh.of(t)),e}function hh(t,e){let{state:i}=t,n=i.facet(lh),s=e=>{let i=t.lineBlockAt(t.posAtDOM(e.target)),n=eh(t.state,i.from,i.to);n&&t.dispatch({effects:Ya.of(n)}),e.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(t,s,e);let r=document.createElement("span");return r.textContent=n.placeholderText,r.setAttribute("aria-label",i.phrase("folded code")),r.title=i.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const ch=Te.replace({widget:new class extends Me{toDOM(t){return hh(t,null)}}});class uh extends Me{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return hh(t,this.value)}}const fh={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class dh extends Fo{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}function ph(t={}){let e={...fh,...t},i=new dh(e,!0),n=new dh(e,!1),s=qi.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(Ra)!=t.state.facet(Ra)||t.startState.field(Za,!1)!=t.state.field(Za,!1)||xa(t.startState)!=xa(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new Nt;for(let s of t.viewportLineBlocks){let r=eh(t.state,s.from,s.to)?n:ja(t.state,s.from,s.to)?i:null;r&&e.add(s.from,s.from,r)}return e.finish()}}),{domEventHandlers:r}=e;return[s,$o({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.markers)||It.empty},initialSpacer:()=>new dh(e,!1),domEventHandlers:{...r,click:(t,e,i)=>{if(r.click&&r.click(t,e,i))return!0;let n=eh(t.state,e.from,e.to);if(n)return t.dispatch({effects:Ya.of(n)}),!0;let s=ja(t.state,e.from,e.to);return!!s&&(t.dispatch({effects:Ga.of(s)}),!0)}}}),ah()]}const mh=pr.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class gh{constructor(t,e){let i;function n(t){let e=Jt.newName();return(i||(i=Object.create(null)))["."+e]=t,e}this.specs=t;const s="string"==typeof e.all?e.all:e.all?n(e.all):void 0,r=e.scope;this.scope=r instanceof wa?t=>t.prop(ga)==r.data:r?t=>t==r:void 0,this.style=Gl(t.map(t=>({tag:t.tag,class:t.class||n(Object.assign({},t,{tag:null}))})),{all:s}).style,this.module=i?new Jt(i):null,this.themeType=e.themeType}static define(t,e){return new gh(t,e||{})}}const vh=z.define(),wh=z.define({combine:t=>t.length?[t[0]]:null});function bh(t){let e=t.facet(vh);return e.length?e:t.facet(wh)}function yh(t,e){let i,n=[kh];return t instanceof gh&&(t.module&&n.push(pr.styleModule.of(t.module)),i=t.themeType),(null==e?void 0:e.fallback)?n.push(wh.of(t)):i?n.push(vh.computeN([pr.darkTheme],e=>e.facet(pr.darkTheme)==("dark"==i)?[t]:[])):n.push(vh.of(t)),n}class xh{constructor(t){this.markCache=Object.create(null),this.tree=xa(t.state),this.decorations=this.buildDeco(t,bh(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=xa(t.state),i=bh(t.state),n=i!=bh(t.startState),{viewport:s}=t.view,r=t.changes.mapPos(this.decoratedTo,1);e.length=s.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=r):(e!=this.tree||t.viewportChanged||n)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=s.to)}buildDeco(t,e){if(!e||!this.tree.length)return Te.none;let i=new Nt;for(let{from:n,to:s}of t.visibleRanges)Yl(this.tree,e,(t,e,n)=>{i.add(t,e,this.markCache[n]||(this.markCache[n]=Te.mark({class:n})))},n,s);return i.finish()}}const kh=Z.high(qi.fromClass(xh,{decorations:t=>t.decorations})),Sh=gh.define([{tag:pa.meta,color:"#404740"},{tag:pa.link,textDecoration:"underline"},{tag:pa.heading,textDecoration:"underline",fontWeight:"bold"},{tag:pa.emphasis,fontStyle:"italic"},{tag:pa.strong,fontWeight:"bold"},{tag:pa.strikethrough,textDecoration:"line-through"},{tag:pa.keyword,color:"#708"},{tag:[pa.atom,pa.bool,pa.url,pa.contentSeparator,pa.labelName],color:"#219"},{tag:[pa.literal,pa.inserted],color:"#164"},{tag:[pa.string,pa.deleted],color:"#a11"},{tag:[pa.regexp,pa.escape,pa.special(pa.string)],color:"#e40"},{tag:pa.definition(pa.variableName),color:"#00f"},{tag:pa.local(pa.variableName),color:"#30a"},{tag:[pa.typeName,pa.namespace],color:"#085"},{tag:pa.className,color:"#167"},{tag:[pa.special(pa.variableName),pa.macroName],color:"#256"},{tag:pa.definition(pa.propertyName),color:"#00c"},{tag:pa.comment,color:"#940"},{tag:pa.invalid,color:"#f00"}]),Ch=pr.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Ah="()[]{}",Mh=z.define({combine:t=>Dt(t,{afterCursor:!0,brackets:Ah,maxScanDistance:1e4,renderMatch:Dh})}),Oh=Te.mark({class:"cm-matchingBracket"}),Th=Te.mark({class:"cm-nonmatchingBracket"});function Dh(t){let e=[],i=t.matched?Oh:Th;return e.push(i.range(t.start.from,t.start.to)),t.end&&e.push(i.range(t.end.from,t.end.to)),e}function Rh(t){let e=[],i=t.facet(Mh);for(let n of t.selection.ranges){if(!n.empty)continue;let s=Nh(t,n.head,-1,i)||n.head>0&&Nh(t,n.head-1,1,i)||i.afterCursor&&(Nh(t,n.head,1,i)||n.headt.decorations}),Ch];function Bh(t={}){return[Mh.of(t),Ph]}const Eh=new pl;function Lh(t,e,i){let n=t.prop(e<0?pl.openedBy:pl.closedBy);if(n)return n;if(1==t.name.length){let n=i.indexOf(t.name);if(n>-1&&n%2==(e<0?1:0))return[i[n+e]]}return null}function Ih(t){let e=t.type.prop(Eh);return e?e(t.node):t}function Nh(t,e,i,n={}){let s=n.maxScanDistance||1e4,r=n.brackets||Ah,o=xa(t),l=o.resolveInner(e,i);for(let n=l;n;n=n.parent){let s=Lh(n.type,i,r);if(s&&n.from0?e>=o.from&&eo.from&&e<=o.to))return Wh(t,e,i,n,o,s,r)}}return function(t,e,i,n,s,r,o){if(i<0?!e:e==t.doc.length)return null;let l=i<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=i>0)return null;let h={from:i<0?e-1:e,to:i>0?e+1:e},c=t.doc.iterRange(e,i>0?t.doc.length:0),u=0;for(let t=0;!c.next().done&&t<=r;){let r=c.value;i<0&&(t+=r.length);let l=e+t*i;for(let t=i>0?0:r.length-1,e=i>0?r.length:-1;t!=e;t+=i){let e=o.indexOf(r[t]);if(!(e<0||n.resolveInner(l+t,1).type!=s))if(e%2==0==i>0)u++;else{if(1==u)return{start:h,end:{from:l+t,to:l+t+1},matched:e>>1==a>>1};u--}}i>0&&(t+=r.length)}return c.done?{start:h,matched:!1}:null}(t,e,i,o,l.type,s,r)}function Wh(t,e,i,n,s,r,o){let l=n.parent,a={from:s.from,to:s.to},h=0,c=null==l?void 0:l.cursor();if(c&&(i<0?c.childBefore(n.from):c.childAfter(n.to)))do{if(i<0?c.to<=n.from:c.from>=n.to){if(0==h&&r.indexOf(c.type.name)>-1&&c.from-1||(zh.push(t),console.warn(e))}function Uh(t,e){let i=[];for(let n of e.split(" ")){let e=[];for(let i of n.split(".")){let n=t[i]||pa[i];n?"function"==typeof n?e.length?e=e.map(n):_h(i,`Modifier ${i} used at start of tag`):e.length?_h(i,`Tag ${i} used as modifier`):e=Array.isArray(n)?n:[n]:_h(i,`Unknown highlighting tag ${i}`)}for(let t of e)i.push(t)}if(!i.length)return 0;let n=e.replace(/ /g,"_"),s=n+" "+i.map(t=>t.id),r=Fh[s];if(r)return r.id;let o=Fh[s]=vl.define({id:Vh.length,name:n,props:[Kl({[n]:i})]});return Vh.push(o),o.id}si.RTL,si.LTR;function Qh(t,e){return({state:i,dispatch:n})=>{if(i.readOnly)return!1;let s=t(e,i);return!!s&&(n(i.update(s)),!0)}}const $h=Qh(Jh,0),Kh=Qh(Yh,0),jh=Qh((t,e)=>Yh(t,e,function(t){let e=[];for(let i of t.selection.ranges){let n=t.doc.lineAt(i.from),s=i.to<=n.to?n:t.doc.lineAt(i.to);s.from>n.from&&s.from==i.to&&(s=i.to==n.to+1?n:t.doc.lineAt(i.to-1));let r=e.length-1;r>=0&&e[r].to>n.from?e[r].to=s.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:s.to})}return e}(e)),0);function Xh(t,e){let i=t.languageDataAt("commentTokens",e,1);return i.length?i[0]:{}}const Gh=50;function Yh(t,e,i=e.selection.ranges){let n=i.map(t=>Xh(e,t.from).block);if(!n.every(t=>t))return null;let s=i.map((t,i)=>function(t,{open:e,close:i},n,s){let r,o,l=t.sliceDoc(n-Gh,n),a=t.sliceDoc(s,s+Gh),h=/\s*$/.exec(l)[0].length,c=/^\s*/.exec(a)[0].length,u=l.length-h;if(l.slice(u-e.length,u)==e&&a.slice(c,c+i.length)==i)return{open:{pos:n-h,margin:h&&1},close:{pos:s+c,margin:c&&1}};s-n<=2*Gh?r=o=t.sliceDoc(n,s):(r=t.sliceDoc(n,n+Gh),o=t.sliceDoc(s-Gh,s));let f=/^\s*/.exec(r)[0].length,d=/\s*$/.exec(o)[0].length,p=o.length-d-i.length;return r.slice(f,f+e.length)==e&&o.slice(p,p+i.length)==i?{open:{pos:n+f+e.length,margin:/\s/.test(r.charAt(f+e.length))?1:0},close:{pos:s-d-i.length,margin:/\s/.test(o.charAt(p-1))?1:0}}:null}(e,n[i],t.from,t.to));if(2!=t&&!s.every(t=>t))return{changes:e.changes(i.map((t,e)=>s[e]?[]:[{from:t.from,insert:n[e].open+" "},{from:t.to,insert:" "+n[e].close}]))};if(1!=t&&s.some(t=>t)){let t=[];for(let e,i=0;is&&(t==r||r>a.from)){s=a.from;let t=/^\s*/.exec(a.text)[0].length,e=t==a.length,r=a.text.slice(t,t+i.length)==i?t:-1;tt.comment<0&&(!t.empty||t.single))){let t=[];for(let{line:e,token:i,indent:s,empty:r,single:o}of n)!o&&r||t.push({from:e.from+s,insert:i+" "});let i=e.changes(t);return{changes:i,selection:e.selection.map(i,1)}}if(1!=t&&n.some(t=>t.comment>=0)){let t=[];for(let{line:e,comment:i,token:s}of n)if(i>=0){let n=e.from+i,r=n+s.length;" "==e.text[r-e.from]&&r++,t.push({from:n,to:r})}return{changes:t}}return null}const Zh=dt.define(),tc=dt.define(),ec=z.define(),ic=z.define({combine:t=>Dt(t,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,n)=>t(i,n)||e(i,n)})}),nc=K.define({create:()=>yc.empty,update(t,e){let i=e.state.facet(ic),n=e.annotation(Zh);if(n){let s=cc.fromTransaction(e,n.selection),r=n.side,o=0==r?t.undone:t.done;return o=s?uc(o,o.length,i.minDepth,s):mc(o,e.startState.selection),new yc(0==r?n.rest:o,0==r?o:n.rest)}let s=e.annotation(tc);if("full"!=s&&"before"!=s||(t=t.isolate()),!1===e.annotation(vt.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let r=cc.fromTransaction(e),o=e.annotation(vt.time),l=e.annotation(vt.userEvent);return r?t=t.addChanges(r,o,l,i,e):e.selection&&(t=t.addSelection(e.startState.selection,o,l,i.newGroupDelay)),"full"!=s&&"after"!=s||(t=t.isolate()),t},toJSON:t=>({done:t.done.map(t=>t.toJSON()),undone:t.undone.map(t=>t.toJSON())}),fromJSON:t=>new yc(t.done.map(cc.fromJSON),t.undone.map(cc.fromJSON))});function sc(t={}){return[nc,ic.of(t),pr.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?oc:"historyRedo"==t.inputType?lc:null;return!!i&&(t.preventDefault(),i(e))}})]}function rc(t,e){return function({state:i,dispatch:n}){if(!e&&i.readOnly)return!1;let s=i.field(nc,!1);if(!s)return!1;let r=s.pop(t,i,e);return!!r&&(n(r),!0)}}const oc=rc(0,!1),lc=rc(1,!1),ac=rc(0,!0),hc=rc(1,!0);class cc{constructor(t,e,i,n,s){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=n,this.selectionsAfter=s}setSelAfter(t){return new cc(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:null===(t=this.changes)||void 0===t?void 0:t.toJSON(),mapped:null===(e=this.mapped)||void 0===e?void 0:e.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(t=>t.toJSON())}}static fromJSON(t){return new cc(t.changes&&D.fromJSON(t.changes),[],t.mapped&&T.fromJSON(t.mapped),t.startSelection&&W.fromJSON(t.startSelection),t.selectionsAfter.map(W.fromJSON))}static fromTransaction(t,e){let i=dc;for(let e of t.startState.facet(ec)){let n=e(t);n.length&&(i=i.concat(n))}return!i.length&&t.changes.empty?null:new cc(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,dc)}static selection(t){return new cc(void 0,dc,void 0,void 0,t)}}function uc(t,e,i,n){let s=e+1>i+20?e-i-1:0,r=t.slice(s,e);return r.push(n),r}function fc(t,e){return t.length?e.length?t.concat(e):t:e}const dc=[],pc=200;function mc(t,e){if(t.length){let i=t[t.length-1],n=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-pc));return n.length&&n[n.length-1].eq(e)?t:(n.push(e),uc(t,t.length-1,1e9,i.setSelAfter(n)))}return[cc.selection([e])]}function gc(t){let e=t[t.length-1],i=t.slice();return i[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),i}function vc(t,e){if(!t.length)return t;let i=t.length,n=dc;for(;i;){let s=wc(t[i-1],e,n);if(s.changes&&!s.changes.empty||s.effects.length){let e=t.slice(0,i);return e[i-1]=s,e}e=s.mapped,i--,n=s.selectionsAfter}return n.length?[cc.selection(n)]:dc}function wc(t,e,i){let n=fc(t.selectionsAfter.length?t.selectionsAfter.map(t=>t.map(e)):dc,i);if(!t.changes)return cc.selection(n);let s=t.changes.map(e),r=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(r):r;return new cc(s,gt.mapEffects(t.effects,e),o,t.startSelection.map(r),n)}const bc=/^(input\.type|delete)($|\.)/;class yc{constructor(t,e,i=0,n=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new yc(this.done,this.undone):this}addChanges(t,e,i,n,s){let r=this.done,o=r[r.length-1];return r=o&&o.changes&&!o.changes.empty&&t.changes&&(!i||bc.test(i))&&(!o.selectionsAfter.length&&e-this.prevTimei.push(t,e)),e.iterChangedRanges((t,e,s,r)=>{for(let t=0;t=e&&s<=o&&(n=!0)}}),n}(o.changes,t.changes))||"input.type.compose"==i)?uc(r,r.length-1,n.minDepth,new cc(t.changes.compose(o.changes),fc(gt.mapEffects(t.effects,o.changes),o.effects),o.mapped,o.startSelection,dc)):uc(r,r.length,n.minDepth,t),new yc(r,dc,e,i)}addSelection(t,e,i,n){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:dc;return s.length>0&&e-this.prevTimet.empty!=o.ranges[e].empty).length)?this:new yc(mc(this.done,t),this.undone,e,i);var r,o}addMapping(t){return new yc(vc(this.done,t),vc(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let n=0==t?this.done:this.undone;if(0==n.length)return null;let s=n[n.length-1],r=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):e.selection);if(i&&s.selectionsAfter.length)return e.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Zh.of({side:t,rest:gc(n),selection:r}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let i=1==n.length?dc:n.slice(0,n.length-1);return s.mapped&&(i=vc(i,s.mapped)),e.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Zh.of({side:t,rest:i,selection:r}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}yc.empty=new yc(dc,dc);const xc=[{key:"Mod-z",run:oc,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:lc,preventDefault:!0},{linux:"Ctrl-Shift-z",run:lc,preventDefault:!0},{key:"Mod-u",run:ac,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:hc,preventDefault:!0}];function kc(t,e){return W.create(t.ranges.map(e),t.mainIndex)}function Sc(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Cc({state:t,dispatch:e},i){let n=kc(t.selection,i);return!n.eq(t.selection,!0)&&(e(Sc(t,n)),!0)}function Ac(t,e){return W.cursor(e?t.to:t.from)}function Mc(t,e){return Cc(t,i=>i.empty?t.moveByChar(i,e):Ac(i,e))}function Oc(t){return t.textDirectionAt(t.state.selection.main.head)==si.LTR}const Tc=t=>Mc(t,!Oc(t)),Dc=t=>Mc(t,Oc(t));function Rc(t,e){return Cc(t,i=>i.empty?t.moveByGroup(i,e):Ac(i,e))}function Pc(t,e,i){if(e.type.prop(i))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function Bc(t,e,i){let n,s,r=xa(t).resolveInner(e.head),o=i?pl.closedBy:pl.openedBy;for(let n=e.head;;){let e=i?r.childAfter(n):r.childBefore(n);if(!e)break;Pc(t,e,o)?r=e:n=i?e.to:e.from}return s=r.type.prop(o)&&(n=i?Nh(t,r.from,1):Nh(t,r.to,-1))&&n.matched?i?n.end.to:n.end.from:i?r.to:r.from,W.cursor(s,i?-1:1)}function Ec(t,e){return Cc(t,i=>{if(!i.empty)return Ac(i,e);let n=t.moveVertically(i,e);return n.head!=i.head?n:t.moveToLineBoundary(i,e)})}const Lc=t=>Ec(t,!1),Ic=t=>Ec(t,!0);function Nc(t){let e,i=t.scrollDOM.clientHeighti.empty?t.moveVertically(i,e,n.height):Ac(i,e));if(r.eq(s.selection))return!1;if(n.selfScroll){let e=t.coordsAtPos(s.selection.main.head),o=t.scrollDOM.getBoundingClientRect(),l=o.top+n.marginTop,a=o.bottom-n.marginBottom;e&&e.top>l&&e.bottomWc(t,!1),Vc=t=>Wc(t,!0);function zc(t,e,i){let n=t.lineBlockAt(e.head),s=t.moveToLineBoundary(e,i);if(s.head==e.head&&s.head!=(i?n.to:n.from)&&(s=t.moveToLineBoundary(e,i,!1)),!i&&s.head==n.from&&n.length){let i=/^\s*/.exec(t.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;i&&e.head!=n.from+i&&(s=W.cursor(n.from+i))}return s}function Fc(t,e,i){let n=kc(t.state.selection,t=>{t.undirectional&&t.head>=t.anchor!=e&&(t=W.range(t.head,t.anchor));let n=i(t);return W.range(t.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return!n.eq(t.state.selection)&&(t.dispatch(Sc(t.state,n)),!0)}function qc(t,e){return Fc(t,e,i=>t.moveByChar(i,e))}const _c=t=>qc(t,!Oc(t)),Uc=t=>qc(t,Oc(t));function Qc(t,e){return Fc(t,e,i=>t.moveByGroup(i,e))}function $c(t,e){return Fc(t,e,i=>t.moveVertically(i,e))}const Kc=t=>$c(t,!1),jc=t=>$c(t,!0);function Xc(t,e){return Fc(t,e,i=>t.moveVertically(i,e,Nc(t).height))}const Gc=t=>Xc(t,!1),Yc=t=>Xc(t,!0),Jc=({state:t,dispatch:e})=>(e(Sc(t,{anchor:0})),!0),Zc=({state:t,dispatch:e})=>(e(Sc(t,{anchor:t.doc.length})),!0),tu=({state:t,dispatch:e})=>(e(Sc(t,{anchor:t.selection.main.anchor,head:0})),!0),eu=({state:t,dispatch:e})=>(e(Sc(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function iu(t,e){let{state:i}=t,n=i.selection,s=i.selection.ranges.slice();for(let n of i.selection.ranges){let r=i.doc.lineAt(n.head);if(e?r.to0)for(let i=n;;){let n=t.moveVertically(i,e);if(n.headr.to){s.some(t=>t.head==n.head)||s.push(n);break}if(n.head==i.head)break;i=n}}return s.length!=n.ranges.length&&(t.dispatch(Sc(i,W.create(s,s.length-1))),!0)}function nu(t,e){if(t.state.readOnly)return!1;let i="delete.selection",{state:n}=t,s=n.changeByRange(n=>{let{from:s,to:r}=n;if(s==r){let o=e(n);os&&(i="delete.forward",o=su(t,o,!0)),s=Math.min(s,o),r=Math.max(r,o)}else s=su(t,s,!1),r=su(t,r,!0);return s==r?{range:n}:{changes:{from:s,to:r},range:W.cursor(s,se(t)))n.between(e,e,(t,n)=>{te&&(e=i?n:t)});return e}const ru=(t,e,i)=>nu(t,n=>{let s,r,o=n.from,{state:l}=t,a=l.doc.lineAt(o);if(i&&!e&&o>a.from&&oru(t,!1,!0),lu=t=>ru(t,!0,!1),au=(t,e)=>nu(t,i=>{let n=i.head,{state:s}=t,r=s.doc.lineAt(n),o=s.charCategorizer(n);for(let t=null;;){if(n==(e?r.to:r.from)){n==i.head&&r.number!=(e?s.doc.lines:1)&&(n+=e?1:-1);break}let l=k(r.text,n-r.from,e)+r.from,a=r.text.slice(Math.min(n,l)-r.from,Math.max(n,l)-r.from),h=o(a);if(null!=t&&h!=t)break;" "==a&&n==i.head||(t=h),n=l}return n}),hu=t=>au(t,!1);function cu(t){let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.from),r=t.doc.lineAt(n.to);if(n.empty||n.to!=r.from||(r=t.doc.lineAt(n.to-1)),i>=s.number){let t=e[e.length-1];t.to=r.to,t.ranges.push(n)}else e.push({from:s.from,to:r.to,ranges:[n]});i=r.number+1}return e}function uu(t,e,i){if(t.readOnly)return!1;let n=[],s=[];for(let e of cu(t)){if(i?e.to==t.doc.length:0==e.from)continue;let r=t.doc.lineAt(i?e.to+1:e.from-1),o=r.length+1;if(i){n.push({from:e.to,to:r.to},{from:e.from,insert:r.text+t.lineBreak});for(let i of e.ranges)s.push(W.range(Math.min(t.doc.length,i.anchor+o),Math.min(t.doc.length,i.head+o)))}else{n.push({from:r.from,to:e.from},{from:e.to,insert:t.lineBreak+r.text});for(let t of e.ranges)s.push(W.range(t.anchor-o,t.head-o))}}return!!n.length&&(e(t.update({changes:n,scrollIntoView:!0,selection:W.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0)}function fu(t,e,i){if(t.readOnly)return!1;let n=[];for(let e of cu(t))i?n.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):n.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});let s=t.changes(n);return e(t.update({changes:s,selection:t.selection.map(s,i?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const du=pu(!1);function pu(t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let n=e.changeByRange(i=>{let{from:n,to:s}=i,r=e.doc.lineAt(n),o=!t&&n==s&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,n=xa(t).resolveInner(e),s=n.childBefore(e),r=n.childAfter(e);return s&&r&&s.to<=e&&r.from>=e&&(i=s.type.prop(pl.closedBy))&&i.indexOf(r.name)>-1&&t.doc.lineAt(s.to).from==t.doc.lineAt(r.from).from&&!/\S/.test(t.sliceDoc(s.to,r.from))?{from:s.to,to:r.from}:null}(e,n);t&&(n=s=(s<=r.to?r:e.doc.lineAt(s)).to);let l=new Wa(e,{simulateBreak:n,simulateDoubleBreak:!!o}),a=Na(l,n);for(null==a&&(a=Kt(/^\s*/.exec(e.doc.lineAt(n).text)[0],e.tabSize));sr.from&&n{let s=[];for(let r=n.from;r<=n.to;){let o=t.doc.lineAt(r);o.number>i&&(n.empty||n.to>o.from)&&(e(o,s,n),i=o.number),r=o.to+1}let r=t.changes(s);return{changes:s,range:W.range(r.mapPos(n.anchor,1),r.mapPos(n.head,1))}})}const gu=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:t=>Cc(t,e=>Bc(t.state,e,!Oc(t))),shift:t=>{let e=!Oc(t);return Fc(t,e,i=>Bc(t.state,i,e))}},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>Cc(t,e=>Bc(t.state,e,Oc(t))),shift:t=>{let e=Oc(t);return Fc(t,e,i=>Bc(t.state,i,e))}},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>uu(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>fu(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>uu(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>fu(t,e,!0)},{key:"Mod-Alt-ArrowUp",run:t=>iu(t,!1)},{key:"Mod-Alt-ArrowDown",run:t=>iu(t,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,n=null;return i.ranges.length>1?n=W.create([i.main]):i.main.empty||(n=W.create([W.cursor(i.main.head)])),!!n&&(e(Sc(t,n)),!0)}},{key:"Mod-Enter",run:pu(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=cu(t).map(({from:e,to:i})=>W.range(e,Math.min(i+1,t.doc.length)));return e(t.update({selection:W.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=kc(t.selection,e=>{let i=xa(t),n=i.resolveStack(e.from,1);if(e.empty){let t=i.resolveStack(e.from,-1);t.node.from>=n.node.from&&t.node.to<=n.node.to&&(n=t)}for(let t=n;t;t=t.next){let{node:i}=t;if((i.from=e.to||i.to>e.to&&i.from<=e.from)&&t.next)return W.range(i.to,i.from)}return e});return!i.eq(t.selection)&&(e(Sc(t,i)),!0)},preventDefault:!0},{key:"Mod-[",run:({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(mu(t,(e,i)=>{let n=/^\s*/.exec(e.text)[0];if(!n)return;let s=Kt(n,t.tabSize),r=0,o=Ia(t,Math.max(0,s-La(t)));for(;r!t.readOnly&&(e(t.update(mu(t,(e,i)=>{i.push({from:e.from,insert:t.facet(Ea)})}),{userEvent:"input.indent"})),!0)},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),n=new Wa(t,{overrideIndentation:t=>{let e=i[t];return null==e?-1:e}}),s=mu(t,(e,s,r)=>{let o=Na(n,e.from);if(null==o)return;/\S/.test(e.text)||(o=0);let l=/^\s*/.exec(e.text)[0],a=Ia(t,o);(l!=a||r.from{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes(cu(e).map(({from:t,to:i})=>(t>0?t--:i{let i;if(t.lineWrapping){let n=t.lineBlockAt(e.head),s=t.coordsAtPos(e.head,e.assoc||1);s&&(i=n.bottom+t.documentTop-s.bottom+t.defaultLineHeight/2)}return t.moveVertically(e,!0,i)}).map(i);return t.dispatch({changes:i,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>function(t,e,i){let n=!1,s=kc(t.selection,e=>{let s=Nh(t,e.head,-1)||Nh(t,e.head,1)||e.head>0&&Nh(t,e.head-1,1)||e.head{let{state:e}=t,i=e.doc.lineAt(e.selection.main.from),n=Xh(t.state,i.from);return n.line?$h(t):!!n.block&&jh(t)}},{key:"Alt-A",run:Kh},{key:"Ctrl-m",mac:"Shift-Alt-m",run:t=>(t.setTabFocusMode(),!0)}].concat([{key:"ArrowLeft",run:Tc,shift:_c,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:t=>Rc(t,!Oc(t)),shift:t=>Qc(t,!Oc(t)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:t=>Cc(t,e=>zc(t,e,!Oc(t))),shift:t=>{let e=!Oc(t);return Fc(t,e,i=>zc(t,i,e))},preventDefault:!0},{key:"ArrowRight",run:Dc,shift:Uc,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>Rc(t,Oc(t)),shift:t=>Qc(t,Oc(t)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:t=>Cc(t,e=>zc(t,e,Oc(t))),shift:t=>{let e=Oc(t);return Fc(t,e,i=>zc(t,i,e))},preventDefault:!0},{key:"ArrowUp",run:Lc,shift:Kc,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Jc,shift:tu},{mac:"Ctrl-ArrowUp",run:Hc,shift:Gc},{key:"ArrowDown",run:Ic,shift:jc,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Zc,shift:eu},{mac:"Ctrl-ArrowDown",run:Vc,shift:Yc},{key:"PageUp",run:Hc,shift:Gc},{key:"PageDown",run:Vc,shift:Yc},{key:"Home",run:t=>Cc(t,e=>zc(t,e,!1)),shift:t=>Fc(t,!1,e=>zc(t,e,!1)),preventDefault:!0},{key:"Mod-Home",run:Jc,shift:tu},{key:"End",run:t=>Cc(t,e=>zc(t,e,!0)),shift:t=>Fc(t,!0,e=>zc(t,e,!0)),preventDefault:!0},{key:"Mod-End",run:Zc,shift:eu},{key:"Enter",run:du,shift:du},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:ou,shift:ou,preventDefault:!0},{key:"Delete",run:lu,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:hu,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>au(t,!0),preventDefault:!0},{mac:"Mod-Backspace",run:t=>nu(t,e=>{let i=t.moveToLineBoundary(e,!1).head;return e.head>i?i:Math.max(0,e.head-1)}),preventDefault:!0},{mac:"Mod-Delete",run:t=>nu(t,e=>{let i=t.moveToLineBoundary(e,!0).head;return e.headCc(t,e=>W.cursor(t.lineBlockAt(e.head).from,1)),shift:t=>Fc(t,!1,e=>W.cursor(t.lineBlockAt(e.head).from))},{key:"Ctrl-e",run:t=>Cc(t,e=>W.cursor(t.lineBlockAt(e.head).to,-1)),shift:t=>Fc(t,!0,e=>W.cursor(t.lineBlockAt(e.head).to))},{key:"Ctrl-d",run:lu},{key:"Ctrl-h",run:ou},{key:"Ctrl-k",run:t=>nu(t,e=>{let i=t.lineBlockAt(e.head).to;return e.head{if(t.readOnly)return!1;let i=t.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:f.of(["",""])},range:W.cursor(t.from)}));return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange(e=>{if(!e.empty||0==e.from||e.from==t.doc.length)return{range:e};let i=e.from,n=t.doc.lineAt(i),s=i==n.from?i-1:k(n.text,i-n.from,!1)+n.from,r=i==n.to?i+1:k(n.text,i-n.from,!0)+n.from;return{changes:{from:s,to:r,insert:t.doc.slice(i,r).append(t.doc.slice(s,i))},range:W.cursor(r)}});return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:Vc}].map(t=>({mac:t.key,run:t.run,shift:t.shift})))),vu="function"==typeof String.prototype.normalize?t=>t.normalize("NFKD"):t=>t;class wu{constructor(t,e,i=0,n=t.length,s,r){this.test=r,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,n),this.bufferStart=i,this.normalize=s?t=>s(vu(t)):vu,this.query=this.normalize(e)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return S(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=C(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=A(t);let n=this.normalize(e);if(n.length)for(let t=0,s=i,r=!0;;t++){let i=n.charCodeAt(t),o=this.match(i,s,r,this.bufferPos+this.bufferStart,t==n.length-1);if(o)return this.value=o,this;if(t==n.length-1)break;r&&tthis.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,n=i+e[0].length;if(this.matchPos=Au(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(ithis.value.to)&&(!this.test||this.test(i,n,e)))return this.value={from:i,to:n,precise:!0,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length=i||n.to<=e){let n=new Su(e,t.sliceString(e,i));return ku.set(t,n),n}if(n.from==e&&n.to==i)return n;let{text:s,from:r}=n;return r>e&&(s=t.sliceString(e,r)+s,r=e),n.to=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e){let t=this.flat.from+e.index,i=t+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(t,i,e)))return this.value={from:t,to:i,precise:!0,match:e},this.matchPos=Au(this.text,i+(t==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Su.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function Au(t,e){if(e>=t.length)return e;let i,n=t.lineAt(e);for(;e=56320&&i<57344;)e++;return e}"undefined"!=typeof Symbol&&(xu.prototype[Symbol.iterator]=Cu.prototype[Symbol.iterator]=function(){return this});const Mu={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Ou=z.define({combine:t=>Dt(t,Mu,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});function Tu(t){let e=[Eu,Bu];return t&&e.push(Ou.of(t)),e}const Du=Te.mark({class:"cm-selectionMatch"}),Ru=Te.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Pu(t,e,i,n){return!(0!=i&&t(e.sliceDoc(i-1,i))==Ct.Word||n!=e.doc.length&&t(e.sliceDoc(n,n+1))==Ct.Word)}const Bu=qi.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(Ou),{state:i}=t,n=i.selection;if(n.ranges.length>1)return Te.none;let s,r=n.main,o=null;if(r.empty){if(!e.highlightWordAroundCursor)return Te.none;let t=i.wordAt(r.head);if(!t)return Te.none;o=i.charCategorizer(r.head),s=i.sliceDoc(t.from,t.to)}else{let t=r.to-r.from;if(t200)return Te.none;if(e.wholeWords){if(s=i.sliceDoc(r.from,r.to),o=i.charCategorizer(r.head),!Pu(o,i,r.from,r.to)||!function(t,e,i,n){return t(e.sliceDoc(i,i+1))==Ct.Word&&t(e.sliceDoc(n-1,n))==Ct.Word}(o,i,r.from,r.to))return Te.none}else if(s=i.sliceDoc(r.from,r.to),!s)return Te.none}let l=[];for(let n of t.visibleRanges){let t=new wu(i.doc,s,n.from,n.to);for(;!t.next().done;){let{from:n,to:s}=t.value;if((!o||Pu(o,i,n,s))&&(r.empty&&n<=r.from&&s>=r.to?l.push(Ru.range(n,s)):(n>=r.to||s<=r.from)&&l.push(Du.range(n,s)),l.length>e.maxMatches))return Te.none}}return Te.set(l)}},{decorations:t=>t.decorations}),Eu=pr.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const Lu=z.define({combine:t=>Dt(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new cf(t),scrollToMatch:t=>pr.scrollIntoView(t)})});class Iu{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,yu),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(t,e)=>"n"==e?"\n":"r"==e?"\r":"t"==e?"\t":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new qu(this):new Hu(this)}getCursor(t,e=0,i){let n=t.doc?t:Tt.create({doc:t});return null==i&&(i=n.doc.length),this.regexp?Vu(this,n,e,i):Wu(this,n,e,i)}}class Nu{constructor(t){this.spec=t}}function Wu(t,e,i,n){let s;return t.wholeWord&&(s=function(t,e){return(i,n,s,r)=>((r>i||r+s.length{if(i&&!i(n,s,r,o))return!1;let l=n>=o&&s<=o+r.length?r.slice(n-o,s-o):e.doc.sliceString(n,s);return t(l,e,n,s)}}(t.test,e,s)),new wu(e.doc,t.unquoted,i,n,t.caseSensitive?void 0:t=>t.toLowerCase(),s)}class Hu extends Nu{constructor(t){super(t)}nextMatch(t,e,i){let n=Wu(this.spec,t,i,t.doc.length).nextOverlapping();if(n.done){let i=Math.min(t.doc.length,e+this.spec.unquoted.length);n=Wu(this.spec,t,0,i).nextOverlapping()}return n.done||n.value.from==e&&n.value.to==i?null:n.value}prevMatchInRange(t,e,i){for(let n=i;;){let i=Math.max(e,n-1e4-this.spec.unquoted.length),s=Wu(this.spec,t,i,n),r=null;for(;!s.nextOverlapping().done;)r=s.value;if(r)return r;if(i==e)return null;n-=1e4}}prevMatch(t,e,i){let n=this.prevMatchInRange(t,0,e);return n||(n=this.prevMatchInRange(t,Math.max(0,i-this.spec.unquoted.length),t.doc.length)),!n||n.from==e&&n.to==i?null:n}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,e){let i=Wu(this.spec,t,0,t.doc.length),n=[];for(;!i.next().done;){if(n.length>=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=Wu(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}function Vu(t,e,i,n){let s;var r;return t.wholeWord&&(r=e.charCategorizer(e.selection.main.head),s=(t,e,i)=>!i[0].length||(r(zu(i.input,i.index))!=Ct.Word||r(Fu(i.input,i.index))!=Ct.Word)&&(r(Fu(i.input,i.index+i[0].length))!=Ct.Word||r(zu(i.input,i.index+i[0].length))!=Ct.Word)),t.test&&(s=function(t,e,i){return(n,s,r)=>(!i||i(n,s,r))&&t(r[0],e,n,s)}(t.test,e,s)),new xu(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:s},i,n)}function zu(t,e){return t.slice(k(t,e,!1),e)}function Fu(t,e){return t.slice(e,k(t,e))}class qu extends Nu{nextMatch(t,e,i){let n=Vu(this.spec,t,i,t.doc.length).next();return n.done&&(n=Vu(this.spec,t,0,e).next()),n.done?null:n.value}prevMatchInRange(t,e,i){for(let n=1;;n++){let s=Math.max(e,i-1e4*n),r=Vu(this.spec,t,s,i),o=null;for(;!r.next().done;)o=r.value;if(o&&(s==e||o.from>s+10))return o;if(s==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(e,i)=>{if("&"==i)return t.match[0];if("$"==i)return"$";for(let e=i.length;e>0;e--){let n=+i.slice(0,e);if(n>0&&n=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=Vu(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}const _u=gt.define(),Uu=gt.define(),Qu=K.define({create:t=>new $u(sf(t).create(),null),update(t,e){for(let i of e.effects)i.is(_u)?t=new $u(i.value.create(),t.panel):i.is(Uu)&&(t=new $u(t.query,i.value?nf:null));return t},provide:t=>No.from(t,t=>t.panel)});class $u{constructor(t,e){this.query=t,this.panel=e}}const Ku=Te.mark({class:"cm-searchMatch"}),ju=Te.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Xu=qi.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Qu))}update(t){let e=t.state.field(Qu);(e!=t.startState.field(Qu)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return Te.none;let{view:i}=this,n=new Nt;for(let e=0,s=i.visibleRanges,r=s.length;es[e+1].from-500;)l=s[++e].to;t.highlight(i.state,o,l,(t,e)=>{let s=i.state.selection.ranges.some(i=>i.from==t&&i.to==e);n.add(t,e,s?ju:Ku)})}return n.finish()}},{decorations:t=>t.decorations});function Gu(t){return e=>{let i=e.state.field(Qu,!1);return i&&i.query.spec.valid?t(e,i):lf(e)}}const Yu=Gu((t,{query:e})=>{let{to:i}=t.state.selection.main,n=e.nextMatch(t.state,i,i);if(!n)return!1;let s=W.single(n.from,n.to),r=t.state.facet(Lu);return t.dispatch({selection:s,effects:[pf(t,n),r.scrollToMatch(s.main,t)],userEvent:"select.search"}),of(t),!0}),Ju=Gu((t,{query:e})=>{let{state:i}=t,{from:n}=i.selection.main,s=e.prevMatch(i,n,n);if(!s)return!1;let r=W.single(s.from,s.to),o=t.state.facet(Lu);return t.dispatch({selection:r,effects:[pf(t,s),o.scrollToMatch(r.main,t)],userEvent:"select.search"}),of(t),!0}),Zu=Gu((t,{query:e})=>{let i=e.matchAll(t.state,1e3);return!(!i||!i.length)&&(t.dispatch({selection:W.create(i.map(t=>W.range(t.from,t.to))),userEvent:"select.search.matches"}),!0)}),tf=Gu((t,{query:e})=>{let{state:i}=t,{from:n,to:s}=i.selection.main;if(i.readOnly)return!1;let r=e.nextMatch(i,n,n);if(!r)return!1;let o,l,a=r,h=[],c=[];a.precise?a.from==n&&a.to==s&&(l=i.toText(e.getReplacement(a)),h.push({from:a.from,to:a.to,insert:l}),a=e.nextMatch(i,a.from,a.to),c.push(pr.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+"."))):a=e.nextMatch(i,a.from,a.to);let u=t.state.changes(h);return a&&(o=W.single(a.from,a.to).map(u),c.push(pf(t,a)),c.push(i.facet(Lu).scrollToMatch(o.main,t))),t.dispatch({changes:u,selection:o,effects:c,userEvent:"input.replace"}),!0}),ef=Gu((t,{query:e})=>{if(t.state.readOnly)return!1;let i=[];for(let n of e.matchAll(t.state,1e9)){let{from:t,to:s,precise:r}=n;r&&i.push({from:t,to:s,insert:e.getReplacement(n)})}if(!i.length)return!1;let n=t.state.phrase("replaced $ matches",i.length)+".";return t.dispatch({changes:i,effects:pr.announce.of(n),userEvent:"input.replace.all"}),!0});function nf(t){return t.state.facet(Lu).createPanel(t)}function sf(t,e){var i,n,s,r,o;let l=t.selection.main,a=l.empty||l.to>l.from+100?"":t.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=t.facet(Lu);return new Iu({search:(null!==(i=null==e?void 0:e.literal)&&void 0!==i?i:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:null!==(n=null==e?void 0:e.caseSensitive)&&void 0!==n?n:h.caseSensitive,literal:null!==(s=null==e?void 0:e.literal)&&void 0!==s?s:h.literal,regexp:null!==(r=null==e?void 0:e.regexp)&&void 0!==r?r:h.regexp,wholeWord:null!==(o=null==e?void 0:e.wholeWord)&&void 0!==o?o:h.wholeWord})}function rf(t){let e=Bo(t,nf);return e&&e.dom.querySelector("[main-field]")}function of(t){let e=rf(t);e&&e==t.root.activeElement&&e.select()}const lf=t=>{let e=t.state.field(Qu,!1);if(e&&e.panel){let i=rf(t);if(i&&i!=t.root.activeElement){let n=sf(t.state,e.query.spec);n.valid&&t.dispatch({effects:_u.of(n)}),i.focus(),i.select()}}else t.dispatch({effects:[Uu.of(!0),e?_u.of(sf(t.state,e.query.spec)):gt.appendConfig.of(gf)]});return!0},af=t=>{let e=t.state.field(Qu,!1);if(!e||!e.panel)return!1;let i=Bo(t,nf);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Uu.of(!1)}),!0},hf=[{key:"Mod-f",run:lf,scope:"editor search-panel"},{key:"F3",run:Yu,shift:Ju,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Yu,shift:Ju,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:af,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:t,dispatch:e})=>{let i=t.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:n,to:s}=i.main,r=[],o=0;for(let e=new wu(t.doc,t.sliceDoc(n,s));!e.next().done;){if(r.length>1e3)return!1;e.value.from==n&&(o=r.length),r.push(W.range(e.value.from,e.value.to))}return e(t.update({selection:W.create(r,o),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:t=>{let{state:e}=t,i=String(e.doc.lineAt(t.state.selection.main.head).number),{close:n,result:s}=Wo(t,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:i},focus:!0,submitLabel:e.phrase("go")});return s.then(i=>{let s=i&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(i.elements.line.value);if(!s)return void t.dispatch({effects:n});let r=e.doc.lineAt(e.selection.main.head),[,o,l,a,h]=s,c=a?+a.slice(1):0,u=l?+l:r.number;if(l&&h){let t=u/100;o&&(t=t*("-"==o?-1:1)+r.number/e.doc.lines),u=Math.round(e.doc.lines*t)}else l&&o&&(u=u*("-"==o?-1:1)+r.number);let f=e.doc.line(Math.max(1,Math.min(e.doc.lines,u))),d=W.cursor(f.from+Math.max(0,Math.min(c,f.length)));t.dispatch({effects:[n,pr.scrollIntoView(d.from,{y:"center"})],selection:d})}),!0}},{key:"Mod-d",run:({state:t,dispatch:e})=>{let{ranges:i}=t.selection;if(i.some(t=>t.from===t.to))return(({state:t,dispatch:e})=>{let{selection:i}=t,n=W.create(i.ranges.map(e=>t.wordAt(e.head)||W.cursor(e.head)),i.mainIndex);return!n.eq(i)&&(e(t.update({selection:n})),!0)})({state:t,dispatch:e});let n=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some(e=>t.sliceDoc(e.from,e.to)!=n))return!1;let s=function(t,e){let{main:i,ranges:n}=t.selection,s=t.wordAt(i.head),r=s&&s.from==i.from&&s.to==i.to;for(let i=!1,s=new wu(t.doc,e,n[n.length-1].to);;){if(s.next(),!s.done){if(i&&n.some(t=>t.from==s.value.from))continue;if(r){let e=t.wordAt(s.value.from);if(!e||e.from!=s.value.from||e.to!=s.value.to)continue}return s.value}if(i)return null;s=new wu(t.doc,e,0,Math.max(0,n[n.length-1].from-1)),i=!0}}(t,n);return!!s&&(e(t.update({selection:t.selection.addRange(W.range(s.from,s.to),!1),effects:pr.scrollIntoView(s.to)})),!0)},preventDefault:!0}];class cf{constructor(t){this.view=t;let e=this.query=t.state.field(Qu).query.spec;function i(t,e,i){return le("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=le("input",{value:e.search,placeholder:uf(t,"Find"),"aria-label":uf(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=le("input",{value:e.replace,placeholder:uf(t,"Replace"),"aria-label":uf(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=le("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=le("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=le("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit}),this.dom=le("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",()=>Yu(t),[uf(t,"next")]),i("prev",()=>Ju(t),[uf(t,"previous")]),i("select",()=>Zu(t),[uf(t,"all")]),le("label",null,[this.caseField,uf(t,"match case")]),le("label",null,[this.reField,uf(t,"regexp")]),le("label",null,[this.wordField,uf(t,"by word")]),...t.state.readOnly?[]:[le("br"),this.replaceField,i("replace",()=>tf(t),[uf(t,"replace")]),i("replaceAll",()=>ef(t),[uf(t,"replace all")])],le("button",{name:"close",onclick:()=>af(t),"aria-label":uf(t,"close"),type:"button"},["×"])])}commit(){let t=new Iu({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:_u.of(t)}))}keydown(t){var e,i,n;e=this.view,i=t,n="search-panel",Tr(Cr(e.state),i,e,n)?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Ju:Yu)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),tf(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(_u)&&!t.value.eq(this.query)&&this.setQuery(t.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Lu).top}}function uf(t,e){return t.state.phrase(e)}const ff=30,df=/[\s\.,:;?!]/;function pf(t,{from:e,to:i}){let n=t.state.doc.lineAt(e),s=t.state.doc.lineAt(i).to,r=Math.max(n.from,e-ff),o=Math.min(s,i+ff),l=t.state.sliceDoc(r,o);if(r!=n.from)for(let t=0;tl.length-ff;t--)if(!df.test(l[t-1])&&df.test(l[t])){l=l.slice(0,t);break}return pr.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${n.number}.`)}const mf=pr.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),gf=[Qu,Z.low(Xu),mf];class vf{constructor(t,e,i,n){this.state=t,this.pos=e,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let e=xa(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),n=e.text.slice(i-e.from,this.pos-e.from),s=n.search(kf(t,!1));return s<0?null:{from:i+s,to:this.pos,text:n.slice(s)}}get aborted(){return null==this.abortListeners}addEventListener(t,e,i){"abort"==t&&this.abortListeners&&(this.abortListeners.push(e),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function wf(t){let e=Object.keys(t).join(""),i=/\w/.test(e);return i&&(e=e.replace(/\w/g,"")),`[${i?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function bf(t){let e=t.map(t=>"string"==typeof t?{label:t}:t),[i,n]=e.every(t=>/^\w+$/.test(t.label))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),i=Object.create(null);for(let{label:n}of t){e[n[0]]=!0;for(let t=1;t{let s=t.matchBefore(n);return s||t.explicit?{from:s?s.from:t.pos,options:e,validFor:i}:null}}class yf{constructor(t,e,i,n){this.completion=t,this.source=e,this.match=i,this.score=n}}function xf(t){return t.selection.main.from}function kf(t,e){var i;let{source:n}=t,s=e&&"^"!=n[0],r="$"!=n[n.length-1];return s||r?new RegExp(`${s?"^":""}(?:${n})${r?"$":""}`,null!==(i=t.flags)&&void 0!==i?i:t.ignoreCase?"i":""):t}const Sf=dt.define();function Cf(t,e,i,n){let{main:s}=t.selection,r=i-s.from,o=n-s.from;return{...t.changeByRange(l=>{if(l!=s&&i!=n&&t.sliceDoc(l.from+r,l.from+o)!=t.sliceDoc(i,n))return{range:l};let a=t.toText(e);return{changes:{from:l.from+r,to:n==s.from?l.to:l.from+o,insert:a},range:W.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const Af=new WeakMap;function Mf(t){if(!Array.isArray(t))return t;let e=Af.get(t);return e||Af.set(t,e=bf(t)),e}const Of=gt.define(),Tf=gt.define();class Df{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e=48&&a<=57||a>=97&&a<=122?2:a>=65&&a<=90?1:0:(w=C(a))!=w.toLowerCase()?1:w!=w.toUpperCase()?2:0;(!n||1==b&&m||0==v&&0!=b)&&(e[c]==a||i[c]==a&&(u=!0)?r[c++]=n:r.length&&(g=!1)),v=b,n+=A(a)}return c==l&&0==r[0]&&g?this.result((u?-200:0)-100,r,t):f==l&&0==d?this.ret(-200-t.length+(p==t.length?0:-100),[0,p]):o>-1?this.ret(-700-t.length,[o,o+this.pattern.length]):f==l?this.ret(-900-t.length,[d,p]):c==l?this.result((u?-200:0)-100-700+(g?0:-1100),r,t):2==e.length?null:this.result((n[0]?-700:0)-200-1100,n,t)}result(t,e,i){let n=[],s=0;for(let t of e){let e=t+(this.astral?A(S(i,t)):1);s&&n[s-1]==t?n[s-1]=e:(n[s++]=t,n[s++]=e)}return this.ret(t-i.length,n)}}class Rf{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.lengthDt(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Ef,filterStrict:!1,compareCompletions:(t,e)=>(t.sortText||t.label).localeCompare(e.sortText||e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>Bf(t(i),e(i)),optionClass:(t,e)=>i=>Bf(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})});function Bf(t,e){return t?e?t+" "+e:t:e}function Ef(t,e,i,n,s,r){let o,l,a=t.textDirection==si.RTL,h=a,c=!1,u="top",f=e.left-s.left,d=s.right-e.right,p=n.right-n.left,m=n.bottom-n.top;if(h&&f=m||t>e.top?o=i.bottom-e.top:(u="bottom",o=e.bottom-i.top)}return{style:`${u}: ${o/((e.bottom-e.top)/r.offsetHeight)}px; max-width: ${l/((e.right-e.left)/r.offsetWidth)}px`,class:"cm-completionInfo-"+(c?a?"left-narrow":"right-narrow":h?"left":"right")}}const Lf=gt.define();function If(t,e,i){if(t<=i)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/i);return{from:t*i,to:(t+1)*i}}let n=Math.ceil((t-e)/i);return{from:t-n*i,to:t-(n-1)*i}}class Nf{constructor(t,e,i){this.view=t,this.stateField=e,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let n=t.state.field(e),{options:s,selected:r}=n.open,o=t.state.facet(Pf);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map(t=>"cm-completionIcon-"+t)),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,i,n){let s=document.createElement("span");s.className="cm-completionLabel";let r=t.displayLabel||t.label,o=0;for(let t=0;to&&s.appendChild(document.createTextNode(r.slice(o,e)));let l=s.appendChild(document.createElement("span"));l.appendChild(document.createTextNode(r.slice(e,i))),l.className="cm-completionMatchedText",o=i}return ot.position-e.position).map(t=>t.render)}(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=If(s.length,r,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",i=>{let{options:n}=t.state.field(e).open;for(let e,s=i.target;s&&s!=this.dom;s=s.parentNode)if("LI"==s.nodeName&&(e=/-(\d+)$/.exec(s.id))&&+e[1]this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;null!=e&&(t.dispatch({effects:Lf.of(e)}),i.preventDefault())}}),this.dom.addEventListener("focusout",e=>{let i=t.state.field(this.stateField,!1);i&&i.tooltip&&t.state.facet(Pf).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:Tf.of(null)})}),this.showOptions(s,n.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),n=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=n){let{options:s,selected:r,disabled:o}=i.open;n.open&&n.open.options==s||(this.range=If(s.length,r,t.state.facet(Pf).maxRenderedOptions),this.showOptions(s,i.id)),this.updateSel(),o!=(null===(e=n.open)||void 0===e?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!o)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;(e.selected>-1&&e.selected=this.range.to)&&(this.range=If(e.options.length,e.selected,this.view.state.facet(Pf).maxRenderedOptions),this.showOptions(e.options,t.id));let i=this.updateSelectedOption(e.selected);if(i){this.destroyInfo();let{completion:n}=e.options[e.selected],{info:s}=n;if(!s)return;let r="string"==typeof s?document.createTextNode(s):s(n);if(!r)return;"then"in r?r.then(e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e,n)}).catch(t=>Hi(this.view.state,t,"completion info")):(this.addInfoPane(r,n),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(65535*Math.random()).toString(16),null!=t.nodeType)i.appendChild(t),this.infoDestroy=null;else{let{dom:e,destroy:n}=t;i.appendChild(e),this.infoDestroy=n||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)"LI"==i.nodeName&&i.id?n==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby")):n--;return e&&function(t,e){let i=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=i.height/t.offsetHeight;n.topi.bottom&&(t.scrollTop+=(n.bottom-i.bottom)/s)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=t.getBoundingClientRect(),s=this.space;if(!s){let t=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:t.clientWidth,bottom:t.clientHeight}}return n.top>Math.min(s.bottom,e.bottom)-10||n.bottom{t.target==n&&t.preventDefault()});let s=null;for(let r=i.from;ri.from||0==i.from))if(s=t,"string"!=typeof a&&a.header)n.appendChild(a.header(a));else{n.appendChild(document.createElement("completion-section")).textContent=t}}const h=n.appendChild(document.createElement("li"));h.id=e+"-"+r,h.setAttribute("role","option");let c=this.optionClass(o);c&&(h.className=c);for(let t of this.optionContent){let e=t(o,this.view.state,this.view,l);e&&h.appendChild(e)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.tonew Nf(i,t,e)}function Hf(t){return 100*(t.boost||0)+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}class Vf{constructor(t,e,i,n,s,r){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=n,this.selected=s,this.disabled=r}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new Vf(this.options,_f(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,n,s,r){if(n&&!r&&t.some(t=>t.isPending))return n.setDisabled();let o=function(t,e){let i=[],n=null,s=null,r=t=>{i.push(t);let{section:e}=t.completion;if(e){n||(n=[]);let t="string"==typeof e?e:e.name;n.some(e=>e.name==t)||n.push("string"==typeof e?{name:t}:e)}},o=e.facet(Pf);for(let n of t)if(n.hasResult()){let t=n.result.getMatch;if(!1===n.result.filter)for(let e of n.result.options)r(new yf(e,n.source,t?t(e):[],1e9-i.length));else{let i,l=e.sliceDoc(n.from,n.to),a=o.filterStrict?new Rf(l):new Df(l);for(let e of n.result.options)if(i=a.match(e.label)){let o=e.displayLabel?t?t(e,i.matched):[]:i.matched,l=i.score+(e.boost||0);if(r(new yf(e,n.source,o,l)),"object"==typeof e.section&&"dynamic"===e.section.rank){let{name:t}=e.section;s||(s=Object.create(null)),s[t]=Math.max(l,s[t]||-1e9)}}}}if(n){let t=Object.create(null),e=0,r=(t,e)=>("dynamic"===t.rank&&"dynamic"===e.rank?s[e.name]-s[t.name]:0)||("number"==typeof t.rank?t.rank:1e9)-("number"==typeof e.rank?e.rank:1e9)||(t.namee.score-t.score||h(t.completion,e.completion))){let e=t.completion;!a||a.label!=e.label||a.detail!=e.detail||null!=a.type&&null!=e.type&&a.type!=e.type||a.apply!=e.apply||a.boost!=e.boost?l.push(t):Hf(t.completion)>Hf(a)&&(l[l.length-1]=t),a=t.completion}return l}(t,e);if(!o.length)return n&&t.some(t=>t.isPending)?n.setDisabled():null;let l=e.facet(Pf).selectOnOpen?0:-1;if(n&&n.selected!=l&&-1!=n.selected){let t=n.options[n.selected].completion;for(let e=0;ee.hasResult()?Math.min(t,e.from):t,1e8),create:Yf,above:s.aboveCursor},n?n.timestamp:Date.now(),l,!1)}map(t){return new Vf(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Vf(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class zf{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new zf(Uf,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,i=e.facet(Pf),n=(i.override||e.languageDataAt("autocomplete",xf(e)).map(Mf)).map(e=>(this.active.find(t=>t.source==e)||new $f(e,this.active.some(t=>0!=t.state)?1:0)).update(t,i));n.length==this.active.length&&n.every((t,e)=>t==this.active[e])&&(n=this.active);let s=this.open,r=t.effects.some(t=>t.is(jf));s&&t.docChanged&&(s=s.map(t.changes)),t.selection||n.some(e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to))||!function(t,e){if(t==e)return!0;for(let i=0,n=0;;){for(;it.isPending)&&(s=null),!s&&n.every(t=>!t.isPending)&&n.some(t=>t.hasResult())&&(n=n.map(t=>t.hasResult()?new $f(t.source,0):t));for(let e of t.effects)e.is(Lf)&&(s=s&&s.setSelected(e.value,this.id));return n==this.active&&s==this.open?this:new zf(n,this.id,s)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Ff:qf}}const Ff={"aria-autocomplete":"list"},qf={};function _f(t,e){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(i["aria-activedescendant"]=t+"-"+e),i}const Uf=[];function Qf(t,e){if(t.isUserEvent("input.complete")){let i=t.annotation(Sf);if(i&&e.activateOnCompletion(i))return 12}let i=t.isUserEvent("input.type");return i&&e.activateOnTyping?5:i?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class $f{constructor(t,e,i=!1){this.source=t,this.state=e,this.explicit=i}hasResult(){return!1}get isPending(){return 1==this.state}update(t,e){let i=Qf(t,e),n=this;(8&i||16&i&&this.touches(t))&&(n=new $f(n.source,0)),4&i&&0==n.state&&(n=new $f(this.source,1)),n=n.updateFor(t,i);for(let e of t.effects)if(e.is(Of))n=new $f(n.source,1,e.value);else if(e.is(Tf))n=new $f(n.source,0);else if(e.is(jf))for(let t of e.value)t.source==n.source&&(n=t);return n}updateFor(t,e){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(xf(t.state))}}class Kf extends $f{constructor(t,e,i,n,s,r){super(t,3,e),this.limit=i,this.result=n,this.from=s,this.to=r}hasResult(){return!0}updateFor(t,e){var i;if(!(3&e))return this.map(t.changes);let n=this.result;n.map&&!t.changes.empty&&(n=n.map(n,t.changes));let s=t.changes.mapPos(this.from),r=t.changes.mapPos(this.to,1),o=xf(t.state);if(o>r||!n||2&e&&(xf(t.startState)==this.from||ot.map(t=>t.map(e))}),Xf=K.define({create:()=>zf.start(),update:(t,e)=>t.update(e),provide:t=>[xo.from(t,t=>t.tooltip),pr.contentAttributes.from(t,t=>t.attrs)]});function Gf(t,e){const i=e.completion.apply||e.completion.label;let n=t.state.field(Xf).active.find(t=>t.source==e.source);return n instanceof Kf&&("string"==typeof i?t.dispatch({...Cf(t.state,i,n.from,n.to),annotations:Sf.of(e.completion)}):i(t,e.completion,n.from,n.to),!0)}const Yf=Wf(Xf,Gf);function Jf(t,e="option"){return i=>{let n=i.state.field(Xf,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp-1?n.open.selected+r*(t?1:-1):t?0:o-1;return l<0?l="page"==e?0:o-1:l>=o&&(l="page"==e?o-1:0),i.dispatch({effects:Lf.of(l)}),!0}}const Zf=t=>!!t.state.field(Xf,!1)&&(t.dispatch({effects:Of.of(!0)}),!0);class td{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const ed=qi.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(Xf).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(Xf),i=t.state.facet(Pf);if(!t.selectionSet&&!t.docChanged&&t.startState.field(Xf)==e)return;let n=t.transactions.some(t=>{let e=Qf(t,i);return 8&e||(t.selection||t.docChanged)&&!(3&e)});for(let e=0;e50&&Date.now()-i.time>1e3){for(let t of i.context.abortListeners)try{t()}catch(t){Hi(this.view.state,t)}i.context.abortListeners=null,this.running.splice(e--,1)}else i.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(t=>t.effects.some(t=>t.is(Of)))&&(this.pendingStart=!0);let s=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(t=>t.isPending&&!this.running.some(e=>e.active.source==t.source))?setTimeout(()=>this.startUpdate(),s):-1,0!=this.composing)for(let e of t.transactions)e.isUserEvent("input.type")?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(Xf);for(let t of e.active)t.isPending&&!this.running.some(e=>e.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Pf).updateSyncTime))}startQuery(t){let{state:e}=this.view,i=xf(e),n=new vf(e,i,t.explicit,this.view),s=new td(t,n);this.running.push(s),Promise.resolve(t.source(n)).then(t=>{s.context.aborted||(s.done=t||null,this.scheduleAccept())},t=>{this.view.dispatch({effects:Tf.of(null)}),Hi(this.view.state,t)})}scheduleAccept(){this.running.every(t=>void 0!==t.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Pf).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],i=this.view.state.facet(Pf),n=this.view.state.field(Xf);for(let s=0;st.source==r.active.source);if(o&&o.isPending)if(null==r.done){let t=new $f(r.active.source,0);for(let e of r.updates)t=t.update(e,i);t.isPending||e.push(t)}else this.startQuery(o)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:jf.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(Xf,!1);if(e&&e.tooltip&&this.view.state.facet(Pf).closeOnBlur){let i=e.open&&Do(this.view,e.open.tooltip);i&&i.dom.contains(t.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:Tf.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:Of.of(!1)}),20),this.composing=0}}}),id="object"==typeof navigator&&/Win/.test(navigator.platform),nd=Z.highest(pr.domEventHandlers({keydown(t,e){let i=e.state.field(Xf,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||t.key.length>1||t.ctrlKey&&(!id||!t.altKey)||t.metaKey)return!1;let n=i.open.options[i.open.selected],s=i.active.find(t=>t.source==n.source),r=n.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(t.key)>-1&&Gf(e,n),!1}})),sd=pr.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),rd={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},od=gt.define({map(t,e){let i=e.mapPos(t,-1,O.TrackAfter);return null==i?void 0:i}}),ld=new class extends Rt{};ld.startSide=1,ld.endSide=-1;const ad=K.define({create:()=>It.empty,update(t,e){if(t=t.map(e.changes),e.selection){let i=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:t=>t>=i.from&&t<=i.to})}for(let i of e.effects)i.is(od)&&(t=t.update({add:[ld.range(i.value,i.value+1)]}));return t}});const hd="()[]{}<>«»»«[]{}";function cd(t){for(let e=0;e<16;e+=2)if(hd.charCodeAt(e)==t)return hd.charAt(e+1);return C(t<128?t:t+1)}function ud(t,e){return t.languageDataAt("closeBrackets",e)[0]||rd}const fd="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),dd=pr.inputHandler.of((t,e,i,n)=>{if((fd?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let s=t.state.selection.main;if(n.length>2||2==n.length&&1==A(S(n,0))||e!=s.from||i!=s.to)return!1;let r=function(t,e){let i=ud(t,t.selection.main.head),n=i.brackets||rd.brackets;for(let s of n){let r=cd(S(s,0));if(e==s)return r==s?bd(t,s,n.indexOf(s+s+s)>-1,i):vd(t,s,r,i.before||rd.before);if(e==r&&md(t,t.selection.main.from))return wd(t,s,r)}return null}(t.state,n);return!!r&&(t.dispatch(r),!0)}),pd=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=ud(t,t.selection.main.head).brackets||rd.brackets,n=null,s=t.changeByRange(e=>{if(e.empty){let n=function(t,e){let i=t.sliceString(e-2,e);return A(S(i,0))==i.length?i:i.slice(1)}(t.doc,e.head);for(let s of i)if(s==n&&gd(t.doc,e.head)==cd(S(s,0)))return{changes:{from:e.head-s.length,to:e.head+s.length},range:W.cursor(e.head-s.length)}}return{range:n=e}});return n||e(t.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!n}}];function md(t,e){let i=!1;return t.field(ad).between(0,t.doc.length,t=>{t==e&&(i=!0)}),i}function gd(t,e){let i=t.sliceString(e,e+2);return i.slice(0,A(S(i,0)))}function vd(t,e,i,n){let s=null,r=t.changeByRange(r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:i,from:r.to}],effects:od.of(r.to+e.length),range:W.range(r.anchor+e.length,r.head+e.length)};let o=gd(t.doc,r.head);return!o||/\s/.test(o)||n.indexOf(o)>-1?{changes:{insert:e+i,from:r.head},effects:od.of(r.head+e.length),range:W.cursor(r.head+e.length)}:{range:s=r}});return s?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function wd(t,e,i){let n=null,s=t.changeByRange(e=>e.empty&&gd(t.doc,e.head)==i?{changes:{from:e.head,to:e.head+i.length,insert:i},range:W.cursor(e.head+i.length)}:n={range:e});return n?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function bd(t,e,i,n){let s=n.stringPrefixes||rd.stringPrefixes,r=null,o=t.changeByRange(n=>{if(!n.empty)return{changes:[{insert:e,from:n.from},{insert:e,from:n.to}],effects:od.of(n.to+e.length),range:W.range(n.anchor+e.length,n.head+e.length)};let o,l=n.head,a=gd(t.doc,l);if(a==e){if(yd(t,l))return{changes:{insert:e+e,from:l},effects:od.of(l+e.length),range:W.cursor(l+e.length)};if(md(t,l)){let n=i&&t.sliceDoc(l,l+3*e.length)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+n.length,insert:n},range:W.cursor(l+n.length)}}}else{if(i&&t.sliceDoc(l-2*e.length,l)==e+e&&(o=xd(t,l-2*e.length,s))>-1&&yd(t,o))return{changes:{insert:e+e+e+e,from:l},effects:od.of(l+e.length),range:W.cursor(l+e.length)};if(t.charCategorizer(l)(a)!=Ct.Word&&xd(t,l,s)>-1&&!function(t,e,i,n){let s=xa(t).resolveInner(e,-1),r=n.reduce((t,e)=>Math.max(t,e.length),0);for(let o=0;o<5;o++){let o=t.sliceDoc(s.from,Math.min(s.to,s.from+i.length+r)),l=o.indexOf(i);if(!l||l>-1&&n.indexOf(o.slice(0,l))>-1){let e=s.firstChild;for(;e&&e.from==s.from&&e.to-e.from>i.length+l;){if(t.sliceDoc(e.to-i.length,e.to)==i)return!1;e=e.firstChild}return!0}let a=s.to==e&&s.parent;if(!a)break;s=a}return!1}(t,l,e,s))return{changes:{insert:e+e,from:l},effects:od.of(l+e.length),range:W.cursor(l+e.length)}}return{range:r=n}});return r?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function yd(t,e){let i=xa(t).resolveInner(e+1);return i.parent&&i.from==e}function xd(t,e,i){let n=t.charCategorizer(e);if(n(t.sliceDoc(e-1,e))!=Ct.Word)return e;for(let s of i){let i=e-s.length;if(t.sliceDoc(i,e)==s&&n(t.sliceDoc(i-1,i))!=Ct.Word)return i}return-1}function kd(t={}){return[nd,Xf,Pf.of(t),ed,Cd,sd]}const Sd=[{key:"Ctrl-Space",run:Zf},{mac:"Alt-`",run:Zf},{mac:"Alt-i",run:Zf},{key:"Escape",run:t=>{let e=t.state.field(Xf,!1);return!(!e||!e.active.some(t=>0!=t.state))&&(t.dispatch({effects:Tf.of(null)}),!0)}},{key:"ArrowDown",run:Jf(!0)},{key:"ArrowUp",run:Jf(!1)},{key:"PageDown",run:Jf(!0,"page")},{key:"PageUp",run:Jf(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field(Xf,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampt.facet(Pf).defaultKeymap?[Sd]:[]));class Ad{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class Md{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let n=i.facet(Wd).markerFilter;n&&(t=n(t,i));let s=t.slice().sort((t,e)=>t.from-e.from||t.to-e.to),r=new Nt,o=[],l=0,a=i.doc.iter(),h=0,c=i.doc.length;for(let t=0;;){let e,i,n=t==s.length?null:s[t];if(!n&&!o.length)break;if(o.length)e=l,i=o.reduce((t,e)=>Math.min(t,e.to),n&&n.from>e?n.from:1e8);else{if(e=n.from,e>c)break;i=n.to,o.push(n),t++}for(;tn.from||n.to==e)){i=Math.min(n.from,i);break}o.push(n),t++,i=Math.min(n.to,i)}i=Math.min(i,c);let u=!1;if(o.some(t=>t.from==e&&(t.to==i||i==c))&&(u=e==i,!u&&i-e<10)){let t=e-(h+a.value.length);t>0&&(a.next(t),h=e);for(let t=e;;){if(t>=i){u=!0;break}if(!a.lineBreak&&h+a.value.length>t)break;t=h+a.value.length,h+=a.value.length,a.next()}}let f=Kd(o);if(u)r.add(e,e,Te.widget({widget:new Fd(f),diagnostics:o.slice()}));else{let t=o.reduce((t,e)=>e.markClass?t+" "+e.markClass:t,"");r.add(e,i,Te.mark({class:"cm-lintRange cm-lintRange-"+f+t,diagnostics:o.slice(),inclusiveEnd:o.some(t=>t.to>i)}))}if(l=i,l==c)break;for(let t=0;t{if(!(e&&s.diagnostics.indexOf(e)<0))if(n){if(s.diagnostics.indexOf(n.diagnostic)<0)return!1;n=new Ad(n.from,i,n.diagnostic)}else n=new Ad(t,i,e||s.diagnostics[0])}),n}const Td=gt.define(),Dd=gt.define(),Rd=gt.define(),Pd=K.define({create:()=>new Md(Te.none,null,null),update(t,e){if(e.docChanged&&t.diagnostics.size){let i=t.diagnostics.map(e.changes),n=null,s=t.panel;if(t.selected){let s=e.changes.mapPos(t.selected.from,1);n=Od(i,t.selected.diagnostic,s)||Od(i,null,s)}!i.size&&s&&e.state.facet(Wd).autoPanel&&(s=null),t=new Md(i,s,n)}for(let i of e.effects)if(i.is(Td)){let n=e.state.facet(Wd).autoPanel?i.value.length?_d.open:null:t.panel;t=Md.init(i.value,n,e.state)}else i.is(Dd)?t=new Md(t.diagnostics,i.value?_d.open:null,t.selected):i.is(Rd)&&(t=new Md(t.diagnostics,t.panel,i.value));return t},provide:t=>[No.from(t,t=>t.panel),pr.decorations.from(t,t=>t.diagnostics)]}),Bd=Te.mark({class:"cm-lintRange cm-lintRange-active"});function Ed(t,e,i){let n,{diagnostics:s}=t.state.field(Pd),r=-1,o=-1;s.between(e-(i<0?1:0),e+(i>0?1:0),(t,s,{spec:l})=>{if(e>=t&&e<=s&&(t==s||(e>t||i>0)&&(e({dom:Ld(t,n)})}:null}function Ld(t,e){return le("ul",{class:"cm-tooltip-lint"},e.map(e=>zd(t,e,!1)))}const Id=t=>{let e=t.state.field(Pd,!1);return!(!e||!e.panel)&&(t.dispatch({effects:Dd.of(!1)}),!0)},Nd=[{key:"Mod-Shift-m",run:t=>{let e=t.state.field(Pd,!1);var i,n;e&&e.panel||t.dispatch({effects:(i=t.state,n=[Dd.of(!0)],i.field(Pd,!1)?n:n.concat(gt.appendConfig.of(Xd)))});let s=Bo(t,_d.open);return s&&s.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:t=>{let e=t.state.field(Pd,!1);if(!e)return!1;let i=t.state.selection.main,n=Od(e.diagnostics,null,i.to+1);return!(!n&&(n=Od(e.diagnostics,null,0),!n||n.from==i.from&&n.to==i.to))&&(t.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),function(t,e,i,n={}){var s;let r=t.state.facet(Ao).map(e=>t.plugin(e)).filter(t=>!!t);if(n.tooltip&&n.tooltip.active){let t=r.find(t=>t.field==n.tooltip.active);t&&(r=[t])}for(let o of r)o.activateHover(t,e,i,null!==(s=n.until)&&void 0!==s?s:()=>!1)}(t,n.from,1,{tooltip:jd,until:t=>t.docChanged||t.newSelection.main.headn.to}),!0)}}],Wd=z.define({combine:t=>({sources:t.map(t=>t.source).filter(t=>null!=t),...Dt(t.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:Hd,tooltipFilter:Hd,needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e,hideOn:(t,e)=>t?e?(i,n,s)=>t(i,n,s)||e(i,n,s):t:e,autoPanel:(t,e)=>t||e})})});function Hd(t,e){return t?e?(i,n)=>e(t(i,n),n):t:e}function Vd(t){let e=[];if(t)t:for(let{name:i}of t){for(let t=0;tt.toLowerCase()==n.toLowerCase())){e.push(n);continue t}}e.push("")}return e}function zd(t,e,i){var n;let s=i?Vd(e.actions):[];return le("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},le("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),null===(n=e.actions)||void 0===n?void 0:n.map((i,n)=>{let r=!1,o=n=>{if(n.preventDefault(),r)return;r=!0;let s=Od(t.state.field(Pd).diagnostics,e);s&&i.apply(t,s.from,s.to)},{name:l}=i,a=s[n]?l.indexOf(s[n]):-1,h=a<0?l:[l.slice(0,a),le("u",l.slice(a,a+1)),l.slice(a+1)];return le("button",{type:"button",class:"cm-diagnosticAction"+(i.markClass?" "+i.markClass:""),onclick:o,onmousedown:o,"aria-label":` Action: ${l}${a<0?"":` (access key "${s[n]})"`}.`},h)}),e.source&&le("div",{class:"cm-diagnosticSource"},e.source))}class Fd extends Me{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return le("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class qd{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=zd(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class _d{constructor(t){this.view=t,this.items=[];this.list=le("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(!(e.ctrlKey||e.altKey||e.metaKey)){if(27==e.keyCode)Id(this.view),this.view.focus();else if(38==e.keyCode||33==e.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==e.keyCode||34==e.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==e.keyCode)this.moveSelection(0);else if(35==e.keyCode)this.moveSelection(this.items.length-1);else if(13==e.keyCode)this.view.focus();else{if(!(e.keyCode>=65&&e.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],n=Vd(i.actions);for(let s=0;s{for(let e=0;eId(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(Pd).selected;if(!t)return-1;for(let e=0;e{for(let t of l.diagnostics){if(r.has(t))continue;r.add(t);let o,l=-1;for(let e=i;ei&&(this.items.splice(i,l-i),n=!0)),e&&o.diagnostic==e.diagnostic?o.dom.hasAttribute("aria-selected")||(o.dom.setAttribute("aria-selected","true"),s=o):o.dom.hasAttribute("aria-selected")&&o.dom.removeAttribute("aria-selected"),i++}});i({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:t,panel:e})=>{let i=e.height/this.list.offsetHeight;t.tope.bottom&&(this.list.scrollTop+=(t.bottom-e.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let t=this.list.firstChild;function e(){let e=t;t=e.nextSibling,e.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=Od(this.view.state.field(Pd).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:Rd.of(e)})}static open(t){return new _d(t)}}function Ud(t){return function(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,${encodeURIComponent(t)}')`}(``,'width="6" height="3"')}const Qd=pr.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Ud("#f11")},".cm-lintRange-warning":{backgroundImage:Ud("orange")},".cm-lintRange-info":{backgroundImage:Ud("#999")},".cm-lintRange-hint":{backgroundImage:Ud("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function $d(t){return"error"==t?4:"warning"==t?3:"info"==t?2:1}function Kd(t){let e="hint",i=1;for(let n of t){let t=$d(n.severity);t>i&&(i=t,e=n.severity)}return e}const jd=To(Ed,{hideOn:function(t,e){let i=e.pos,n=e.end||i,s=t.state.facet(Wd).hideOn(t,i,n);if(null!=s)return s;let r=t.startState.doc.lineAt(e.pos);return!(!t.effects.some(t=>t.is(Td))&&!t.changes.touchesRange(r.from,Math.max(r.to,n)))}}),Xd=[Pd,pr.decorations.compute([Pd],t=>{let{selected:e,panel:i}=t.field(Pd);return e&&i&&e.from!=e.to?Te.set([Bd.range(e.from,e.to)]):Te.none}),jd,Qd],Gd=(()=>[ll(),cl,Jr(),sc(),ph(),Nr(),[_r,Ur],Tt.allowMultipleSelections.of(!0),Tt.transactionFilter.of(t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let i=t.newDoc,{head:n}=t.newSelection.main,s=i.lineAt(n);if(n>s.from+200)return t;let r=i.sliceString(s.from,n);if(!e.some(t=>t.test(r)))return t;let{state:o}=t,l=-1,a=[];for(let{head:t}of o.selection.ranges){let e=o.doc.lineAt(t);if(e.from==l)continue;l=e.from;let i=Na(o,e.from);if(null==i)continue;let n=/^\s*/.exec(e.text)[0],s=Ia(o,i);n!=s&&a.push({from:e.from,to:e.from+n.length,insert:s})}return a.length?[t,{changes:a,sequential:!0}]:t}),yh(Sh,{fallback:!0}),Bh(),[dd,ad],kd(),lo(),co(),no,Tu(),kr.of([...pd,...gu,...hf,...xc,...rh,...Sd,...Nd])])();class Yd{constructor(t,e,i,n,s,r,o,l,a,h=0,c){this.p=t,this.stack=e,this.state=i,this.reducePos=n,this.pos=s,this.score=r,this.buffer=o,this.bufferBase=l,this.curContext=a,this.lookAhead=h,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let n=t.parser.context;return new Yd(t,[],e,i,i,0,[],0,n?new Jd(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,n=65535&t,{parser:s}=this.p,r=this.reducePos=2e3&&!(null===(e=this.p.parser.nodeSet.types[n])||void 0===e?void 0:e.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=h):this.p.lastBigReductionSizel;)this.stack.pop();this.reduceContext(n,a)}storeNode(t,e,i,n=4,s=!1){if(0==t&&(!this.stack.length||this.stack[this.stack.length-1]0&&0==this.buffer[t-4]&&this.buffer[t-1]>-1){if(e==i)return;if(this.buffer[t-2]>=e)return void(this.buffer[t-2]=i)}}if(s&&this.pos!=i){let s=this.buffer.length;if(s>0&&(0!=this.buffer[s-4]||this.buffer[s-1]<0)){let t=!1;for(let e=s;e>0&&this.buffer[e-2]>i;e-=4)if(this.buffer[e-1]>=0){t=!0;break}if(t)for(;s>0&&this.buffer[s-2]>i;)this.buffer[s]=this.buffer[s-4],this.buffer[s+1]=this.buffer[s-3],this.buffer[s+2]=this.buffer[s-2],this.buffer[s+3]=this.buffer[s-1],s-=4,n>4&&(n-=4)}this.buffer[s]=t,this.buffer[s+1]=e,this.buffer[s+2]=i,this.buffer[s+3]=n}else this.buffer.push(t,e,i,n)}shift(t,e,i,n){if(131072&t)this.pushState(65535&t,this.pos);else if(262144&t)this.pos=n,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,n,4);else{let s=t,{parser:r}=this.p;this.pos=n;let o=r.stateFlag(s,1);!o&&(n>i||e<=r.maxNode)&&(this.reducePos=n),this.pushState(s,o?i:Math.min(i,this.reducePos)),this.shiftContext(e,i),e<=r.maxNode&&this.buffer.push(e,i,n,4)}}apply(t,e,i,n){65536&t?this.reduce(t):this.shift(t,e,i,n)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let n=this.pos;this.reducePos=this.pos=n+t.length,this.pushState(e,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&0==t.buffer[e-4]&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),n=t.bufferBase+e;for(;t&&n==t.bufferBase;)t=t.parent;return new Yd(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new Zd(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(0==i)return!1;if(!(65536&i))return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let i=[];for(let n,s=0;s1&e&&t==n)||i.push(e[t],n)}e=i}let i=[];for(let t=0;t>19,n=65535&e,s=this.stack.length-3*i;if(s<0||t.getGoto(this.stack[s],n,!1)<0){let t=this.findForcedReduction();if(null==t)return!1;e=t}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(n,s)=>{if(!e.includes(n))return e.push(n),t.allActions(n,e=>{if(393216&e);else if(65536&e){let i=(e>>19)-s;if(i>1){let n=65535&e,s=this.stack.length-3*i;if(s>=0&&t.getGoto(this.stack[s],n,!1)>=0)return i<<19|65536|n}}else{let t=i(e,s+1);if(null!=t)return t}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(3!=this.stack.length)return!1;let{parser:t}=this.p;return 65535==t.data[t.stateSlot(this.state,1)]&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e0&&this.emitLookAhead()}}class Jd{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class Zd{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=65535&t,i=t>>19;0==i?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=3*(i-1);let n=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=n}}class tp{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,0==this.index&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new tp(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;null!=t&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,0==this.index&&this.maybeNext()}fork(){return new tp(this.stack,this.pos,this.index)}}function ep(t,e=Uint16Array){if("string"!=typeof t)return t;let i=null;for(let n=0,s=0;n=92&&e--,e>=34&&e--;let s=e-32;if(s>=46&&(s-=46,i=!0),r+=s,i)break;r*=46}i?i[s++]=r:i=new e(r)}return i}class ip{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const np=new ip;class sp{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=np,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,n=this.rangeIndex,s=this.pos+t;for(;si.to:s>=i.to;){if(n==this.ranges.length-1)return null;let t=this.ranges[++n];s+=t.from-i.to,i=t}return s}clipPos(t){if(t>=this.range.from&&tt)return Math.max(t,e.from);return this.end}peek(t){let e,i,n=this.chunkOff+t;if(n>=0&&n=this.chunk2Pos&&en.to&&(this.chunk2=this.chunk2.slice(0,n.to-e)),i=this.chunk2.charCodeAt(0)}}return e>=this.token.lookAhead&&(this.token.lookAhead=e+1),i}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(null==i||i=this.chunk2Pos&&this.posthis.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=np,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let n of this.ranges){if(n.from>=e)break;n.to>t&&(i+=this.input.read(Math.max(n.from,t),Math.min(n.to,e)))}return i}}class rp{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:i}=e.p;!function(t,e,i,n,s,r){let o=0,l=1<0){let i=t[n];if(a.allows(i)&&(-1==e.token.value||e.token.value==i||ap(i,e.token.value,s,r))){e.acceptToken(i);break}}let n=e.next,h=0,c=t[o+2];if(!(e.next<0&&c>h&&65535==t[i+3*c-3])){for(;h>1,r=i+s+(s<<1),l=t[r],a=t[r+1]||65536;if(n=a)){o=t[r+2],e.advance();continue t}h=s+1}}break}o=t[i+3*c-1]}}(this.data,t,e,this.id,i.data,i.tokenPrecTable)}}rp.prototype.contextual=rp.prototype.fallback=rp.prototype.extend=!1,rp.prototype.fallback=rp.prototype.extend=!1;class op{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}}function lp(t,e,i){for(let n,s=e;65535!=(n=t[s]);s++)if(n==i)return s-e;return-1}function ap(t,e,i,n){let s=lp(i,n,e);return s<0||lp(i,n,t)e)&&!n.type.isError)return i<0?Math.max(0,Math.min(n.to-1,e-25)):Math.min(t.length,Math.max(n.from+1,e+25));if(i<0?n.prevSibling():n.nextSibling())break;if(!n.parent())return i<0?0:t.length}}class fp{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?up(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?up(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(tt)return this.nextStart=r,null;if(s instanceof kl){if(r==t){if(r=Math.max(this.safeFrom,t)&&(this.trees.push(s),this.start.push(r),this.index.push(0))}else this.index[e]++,this.nextStart=r+s.length}}}class dp{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(t=>new ip)}getActions(t){let e=0,i=null,{parser:n}=t.p,{tokenizers:s}=n,r=n.stateSlot(t.state,3),o=t.curContext?t.curContext.hash:0,l=0;for(let n=0;nh.end+25&&(l=Math.max(h.lookAhead,l)),0!=h.value)){let n=e;if(h.extended>-1&&(e=this.addActions(t,h.extended,h.end,e)),e=this.addActions(t,h.value,h.end,e),!a.extend&&(i=h,e>n))break}}for(;this.actions.length>e;)this.actions.pop();return l&&t.setLookAhead(l),i||t.pos!=this.stream.end||(i=new ip,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new ip,{pos:i,p:n}=t;return e.start=i,e.end=Math.min(i+1,n.stream.end),e.value=i==n.stream.end?n.parser.eofTerm:0,e}updateCachedToken(t,e,i){let n=this.stream.clipPos(i.pos);if(e.token(this.stream.reset(n,t),i),t.value>-1){let{parser:e}=i.p;for(let n=0;n=0&&i.p.parser.dialect.allows(s>>1)){1&s?t.extended=s>>1:t.value=s>>1;break}}}else t.value=0,t.end=this.stream.clipPos(n+1)}putAction(t,e,i,n){for(let e=0;e4*t.bufferLength?new fp(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t,e,i=this.stacks,n=this.minStackPos,s=this.stacks=[];if(this.bigReductionCount>300&&1==i.length){let[t]=i;for(;t.forceReduce()&&t.stack.length&&t.stack[t.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let r=0;rn)s.push(o);else{if(this.advanceStack(o,s,i))continue;{t||(t=[],e=[]),t.push(o);let i=this.tokens.getMainToken(o);e.push(i.value,i.end)}}break}}if(!s.length){let e=t&&function(t){let e=null;for(let i of t){let t=i.p.stoppedAt;(i.pos==i.p.stream.end||null!=t&&i.pos>t)&&i.p.parser.stateFlag(i.state,2)&&(!e||e.scorethis.stoppedAt?t[0]:this.runRecovery(t,e,s);if(i)return hp&&console.log("Force-finish "+this.stackID(i)),this.stackToTree(i.forceAll())}if(this.recovering){let t=1==this.recovering?1:3*this.recovering;if(s.length>t)for(s.sort((t,e)=>e.score-t.score);s.length>t;)s.pop();s.some(t=>t.reducePos>n)&&this.recovering--}else if(s.length>1){t:for(let t=0;t500&&n.buffer.length>500){if(!((e.score-n.score||e.buffer.length-n.buffer.length)>0)){s.splice(t--,1);continue t}s.splice(i--,1)}}}s.length>12&&(s.sort((t,e)=>e.score-t.score),s.splice(12,s.length-12))}this.minStackPos=s[0].pos;for(let t=1;t ":"";if(null!=this.stoppedAt&&n>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let e=t.curContext&&t.curContext.tracker.strict,i=e?t.curContext.hash:0;for(let o=this.fragments.nodeAt(n);o;){let n=this.parser.nodeSet.types[o.type.id]==o.type?s.getGoto(t.state,o.type.id):-1;if(n>-1&&o.length&&(!e||(o.prop(pl.contextHash)||0)==i))return t.useNode(o,n),hp&&console.log(r+this.stackID(t)+` (via reuse of ${s.getName(o.type.id)})`),!0;if(!(o instanceof kl)||0==o.children.length||o.positions[0]>0)break;let l=o.children[0];if(!(l instanceof kl&&0==o.positions[0]))break;o=l}}let o=s.stateSlot(t.state,4);if(o>0)return t.reduce(o),hp&&console.log(r+this.stackID(t)+` (via always-reduce ${s.getName(65535&o)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let l=this.tokens.getActions(t);for(let o=0;on?e.push(f):i.push(f)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return mp(t,e),!0}}runRecovery(t,e,i){let n=null,s=!1;for(let r=0;r ":"";if(o.deadEnd){if(s)continue;if(s=!0,o.restart(),hp&&console.log(h+this.stackID(o)+" (restarted)"),this.advanceFully(o,i))continue}let c=o.split(),u=h;for(let t=0;t<10&&c.forceReduce();t++){if(hp&&console.log(u+this.stackID(c)+" (via force-reduce)"),this.advanceFully(c,i))break;hp&&(u=this.stackID(c)+" -> ")}for(let t of o.recoverByInsert(l))hp&&console.log(h+this.stackID(t)+" (via recover-insert)"),this.advanceFully(t,i);this.stream.end>o.pos?(a==o.pos&&(a++,l=0),o.recoverByDelete(l,a),hp&&console.log(h+this.stackID(o)+` (via recover-delete ${this.parser.getName(l)})`),mp(o,i)):(!n||n.scoret.topRules[e][1]),n=[];for(let t=0;t=0)s(n,t,e[i++]);else{let r=e[i+-n];for(let o=-n;o>0;o--)s(e[i++],t,r);i++}}}this.nodeSet=new wl(e.map((e,s)=>vl.define({name:s>=this.minRepeatTerm?void 0:e,id:s,props:n[s],top:i.indexOf(s)>-1,error:0==s,skipped:t.skippedNodes&&t.skippedNodes.indexOf(s)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=ul;let r=ep(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let t=0;t"number"==typeof t?new rp(r,t):t),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let n=new pp(this,t,e,i);for(let s of this.wrappers)n=s(n,t,e,i);return n}getGoto(t,e,i=!1){let n=this.goto;if(e>=n[0])return-1;for(let s=n[e+1];;){let e=n[s++],r=1&e,o=n[s++];if(r&&i)return o;for(let i=s+(e>>1);s0}validAction(t,e){return!!this.allActions(t,t=>t==e||null)}allActions(t,e){let i=this.stateSlot(t,4),n=i?e(i):void 0;for(let i=this.stateSlot(t,1);null==n;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])break;i=wp(this.data,i+2)}n=e(wp(this.data,i+1))}return n}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])break;i=wp(this.data,i+2)}if(!(1&this.data[i+2])){let t=this.data[i+1];e.some((e,i)=>1&i&&e==t)||e.push(this.data[i],t)}}return e}configure(t){let e=Object.assign(Object.create(vp.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(e=>{let i=t.tokenizers.find(t=>t.from==e);return i?i.to:e})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,n)=>{let s=t.specializers.find(t=>t.from==i.external);if(!s)return i;let r=Object.assign(Object.assign({},i),{external:s.to});return e.specializers[n]=bp(r),r})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),null!=t.strict&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),null!=t.bufferLength&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return null==e?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let n of t.split(" ")){let t=e.indexOf(n);t>=0&&(i[t]=!0)}let n=null;for(let t=0;tt.external(i,n)<<1|e}return t.get}function yp(t){return t>=65&&t<=90||t>=97&&t<=122||t>=48&&t<=57}function xp(t){return t>=48&&t<=57||t>=97&&t<=102||t>=65&&t<=70}function kp(t,e,i){for(let n=!1;;){if(t.next<0)return;if(t.next==e&&!n)return void t.advance();n=i&&!n&&92==t.next,t.advance()}}function Sp(t,e){for(;95==t.next||yp(t.next);)null!=e&&(e+=String.fromCharCode(t.next)),t.advance();return e}function Cp(t,e){for(;48==t.next||49==t.next;)t.advance();e&&t.next==e&&t.advance()}function Ap(t,e){for(;;){if(46==t.next){if(e)break;e=!0}else if(t.next<48||t.next>57)break;t.advance()}if(69==t.next||101==t.next)for(t.advance(),43!=t.next&&45!=t.next||t.advance();t.next>=48&&t.next<=57;)t.advance()}function Mp(t){for(;!(t.next<0||10==t.next);)t.advance()}function Op(t,e){for(let i=0;i!=&|~^/",specialVar:"?",identifierQuotes:'"',caseInsensitiveIdentifiers:!1,words:Dp("absolute action add after all allocate alter and any are as asc assertion at authorization before begin between both breadth by call cascade cascaded case cast catalog check close collate collation column commit condition connect connection constraint constraints constructor continue corresponding count create cross cube current current_date current_default_transform_group current_transform_group_for_type current_path current_role current_time current_timestamp current_user cursor cycle data day deallocate declare default deferrable deferred delete depth deref desc describe descriptor deterministic diagnostics disconnect distinct do domain drop dynamic each else elseif end end-exec equals escape except exception exec execute exists exit external fetch first for foreign found from free full function general get global go goto grant group grouping handle having hold hour identity if immediate in indicator initially inner inout input insert intersect into is isolation join key language last lateral leading leave left level like limit local localtime localtimestamp locator loop map match method minute modifies module month names natural nesting new next no none not of old on only open option or order ordinality out outer output overlaps pad parameter partial path prepare preserve primary prior privileges procedure public read reads recursive redo ref references referencing relative release repeat resignal restrict result return returns revoke right role rollback rollup routine row rows savepoint schema scroll search second section select session session_user set sets signal similar size some space specific specifictype sql sqlexception sqlstate sqlwarning start state static system_user table temporary then timezone_hour timezone_minute to trailing transaction translation treat trigger under undo union unique unnest until update usage user using value values view when whenever where while with without work write year zone ","array binary bit boolean char character clob date decimal double float int integer interval large national nchar nclob numeric object precision real smallint time timestamp varchar varying ")};function Pp(t){return new op(e=>{var i;let{next:n}=e;if(e.advance(),Op(n,Tp)){for(;Op(e.next,Tp);)e.advance();e.acceptToken(36)}else if(36==n&&t.doubleDollarQuotedStrings){let t=Sp(e,"");36==e.next&&(e.advance(),function(t,e){t:for(;;){if(t.next<0)return;if(36==t.next){t.advance();for(let i=0;i1){e.advance(),kp(e,39,t.backslashEscapes),e.acceptToken(3);break}if(!yp(e.next))break;e.advance()}else if(t.plsqlQuotingMechanism&&(113==n||81==n)&&39==e.next&&e.peek(1)>0&&!Op(e.peek(1),Tp)){let t=e.peek(1);e.advance(2),function(t,e){let i="[{<(".indexOf(String.fromCharCode(e)),n=i<0?e:"]}>)".charCodeAt(i);for(;;){if(t.next<0)return;if(t.next==n&&39==t.peek(1))return void t.advance(2);t.advance()}}(e,t),e.acceptToken(3)}else if(Op(n,t.identifierQuotes)){kp(e,91==n?93:n,!1),e.acceptToken(19)}else if(40==n)e.acceptToken(7);else if(41==n)e.acceptToken(8);else if(123==n)e.acceptToken(9);else if(125==n)e.acceptToken(10);else if(91==n)e.acceptToken(11);else if(93==n)e.acceptToken(12);else if(59==n)e.acceptToken(13);else if(t.unquotedBitLiterals&&48==n&&98==e.next)e.advance(),Cp(e),e.acceptToken(22);else if(98!=n&&66!=n||39!=e.next&&34!=e.next){if(48==n&&(120==e.next||88==e.next)||(120==n||88==n)&&39==e.next){let t=39==e.next;for(e.advance();xp(e.next);)e.advance();t&&39==e.next&&e.advance(),e.acceptToken(4)}else if(46==n&&e.next>=48&&e.next<=57)Ap(e,!0),e.acceptToken(4);else if(46==n)e.acceptToken(14);else if(n>=48&&n<=57)Ap(e,!1),e.acceptToken(4);else if(Op(n,t.operatorChars)){for(;Op(e.next,t.operatorChars);)e.advance();e.acceptToken(15)}else if(Op(n,t.specialVar))e.next==n&&e.advance(),function(t){if(39==t.next||34==t.next||96==t.next){let e=t.next;t.advance(),kp(t,e,!1)}else Sp(t)}(e),e.acceptToken(17);else if(58==n||44==n)e.acceptToken(16);else if(yp(n)){let s=Sp(e,String.fromCharCode(n));e.acceptToken(46==e.next||46==e.peek(-s.length-1)?18:null!==(i=t.words[s.toLowerCase()])&&void 0!==i?i:18)}}else{const i=e.next;e.advance(),t.treatBitsAsBytes?(kp(e,i,t.backslashEscapes),e.acceptToken(23)):(Cp(e,i),e.acceptToken(22))}else e.advance(),kp(e,39,t.backslashEscapes),e.acceptToken(3);else e.advance(),kp(e,39,!0),e.acceptToken(3);else Mp(e),e.acceptToken(1)})}const Bp=Pp(Rp),Ep=vp.deserialize({version:14,states:"%vQ]QQOOO#wQRO'#DSO$OQQO'#CwO%eQQO'#CxO%lQQO'#CyO%sQQO'#CzOOQQ'#DS'#DSOOQQ'#C}'#C}O'UQRO'#C{OOQQ'#Cv'#CvOOQQ'#C|'#C|Q]QQOOQOQQOOO'`QQO'#DOO(xQRO,59cO)PQQO,59cO)UQQO'#DSOOQQ,59d,59dO)cQQO,59dOOQQ,59e,59eO)jQQO,59eOOQQ,59f,59fO)qQQO,59fOOQQ-E6{-E6{OOQQ,59b,59bOOQQ-E6z-E6zOOQQ,59j,59jOOQQ-E6|-E6|O+VQRO1G.}O+^QQO,59cOOQQ1G/O1G/OOOQQ1G/P1G/POOQQ1G/Q1G/QP+kQQO'#C}O+rQQO1G.}O)PQQO,59cO,PQQO'#Cw",stateData:",[~OtOSPOSQOS~ORUOSUOTUOUUOVROXSOZTO]XO^QO_UO`UOaPObPOcPOdUOeUOfUOgUOhUO~O^]ORvXSvXTvXUvXVvXXvXZvX]vX_vX`vXavXbvXcvXdvXevXfvXgvXhvX~OsvX~P!jOa_Ob_Oc_O~ORUOSUOTUOUUOVROXSOZTO^tO_UO`UOa`Ob`Oc`OdUOeUOfUOgUOhUO~OWaO~P$ZOYcO~P$ZO[eO~P$ZORUOSUOTUOUUOVROXSOZTO^QO_UO`UOaPObPOcPOdUOeUOfUOgUOhUO~O]hOsoX~P%zOajObjOcjO~O^]ORkaSkaTkaUkaVkaXkaZka]ka_ka`kaakabkackadkaekafkagkahka~Oska~P'kO^]O~OWvXYvX[vX~P!jOWnO~P$ZOYoO~P$ZO[pO~P$ZO^]ORkiSkiTkiUkiVkiXkiZki]ki_ki`kiakibkickidkiekifkigkihki~Oski~P)xOWkaYka[ka~P'kO]hO~P$ZOWkiYki[ki~P)xOasObsOcsO~O",goto:"#hwPPPPPPPPPPPPPPPPPPPPPPPPPPx||||!Y!^!d!xPPP#[TYOZeUORSTWZbdfqT[OZQZORiZSWOZQbRQdSQfTZgWbdfqQ^PWk^lmrQl_Qm`RrseVORSTWZbdfq",nodeNames:"⚠ LineComment BlockComment String Number Bool Null ( ) { } [ ] ; . Operator Punctuation SpecialVar Identifier QuotedIdentifier Keyword Type Bits Bytes Builtin Script Statement CompositeIdentifier Parens Braces Brackets Statement",maxTerm:38,nodeProps:[["isolate",-4,1,2,3,19,""]],skippedNodes:[0,1,2],repeatNodeCount:3,tokenData:"RORO",tokenizers:[0,Bp],topRules:{Script:[0,25]},tokenPrec:0});function Lp(t){let e=t.cursor().moveTo(t.from,-1);for(;/Comment/.test(e.name);)e.moveTo(e.from,-1);return e.node}function Ip(t,e){let i=t.sliceString(e.from,e.to),n=/^([`'"\[])(.*)([`'"\]])$/.exec(i);return n?n[2]:i}function Np(t){return t&&("Identifier"==t.name||"QuotedIdentifier"==t.name)}function Wp(t,e){if("CompositeIdentifier"==e.name){let i=[];for(let n=e.firstChild;n;n=n.nextSibling)Np(n)&&i.push(Ip(t,n));return i}return[Ip(t,e)]}function Hp(t,e){for(let i=[];;){if(!e||"."!=e.name)return i;let n=Lp(e);if(!Np(n))return i;i.unshift(Ip(t,n)),e=Lp(n)}}function Vp(t,e){let i=xa(t).resolveInner(e,-1),n=function(t,e){let i;for(let t=e;!i;t=t.parent){if(!t)return null;"Statement"==t.name&&(i=t)}let n=null;for(let e=i.firstChild,s=!1,r=null;e;e=e.nextSibling){let i="Keyword"==e.name?t.sliceString(e.from,e.to).toLowerCase():null,o=null;if(s)if("as"==i&&r&&Np(e.nextSibling))o=Ip(t,e.nextSibling);else{if(i&&zp.has(i))break;r&&Np(e)&&(o=Ip(t,e))}else s="from"==i;o&&(n||(n=Object.create(null)),n[o]=Wp(t,r)),r=/Identifier$/.test(e.name)?e:null}return n}(t.doc,i);return"Identifier"==i.name||"QuotedIdentifier"==i.name||"Keyword"==i.name?{from:i.from,quoted:"QuotedIdentifier"==i.name?t.doc.sliceString(i.from,i.from+1):null,parents:Hp(t.doc,Lp(i)),aliases:n}:"."==i.name?{from:e,quoted:null,parents:Hp(t.doc,i),aliases:n}:{from:e,quoted:null,parents:[],empty:!0,aliases:n}}const zp=new Set("where group having order union intersect except all distinct limit offset fetch for".split(" "));function Fp(t,e,i){return i.map(i=>({...i,label:i.label[0]==t?i.label:t+i.label+e,apply:void 0}))}const qp=/^\w*$/,_p=/^[`'"\[]?\w*[`'"\]]?$/;function Up(t){return t.self&&"string"==typeof t.self.label}class Qp{constructor(t,e){this.idQuote=t,this.idCaseInsensitive=e,this.list=[],this.children=void 0}child(t){let e=this.children||(this.children=Object.create(null)),i=e[t];return i||(t&&!this.list.some(e=>e.label==t)&&this.list.push($p(t,"type",this.idQuote,this.idCaseInsensitive)),e[t]=new Qp(this.idQuote,this.idCaseInsensitive))}maybeChild(t){return this.children?this.children[t]:null}addCompletion(t){let e=this.list.findIndex(e=>e.label==t.label);e>-1?this.list[e]=t:this.list.push(t)}addCompletions(t){for(let e of t)this.addCompletion("string"==typeof e?$p(e,"property",this.idQuote,this.idCaseInsensitive):e)}addNamespace(t){Array.isArray(t)?this.addCompletions(t):Up(t)?this.addNamespace(t.children):this.addNamespaceObject(t)}addNamespaceObject(t){for(let e of Object.keys(t)){let i=t[e],n=null,s=e.replace(/\\?\./g,t=>"."==t?"\0":t).split("\0"),r=this;Up(i)&&(n=i.self,i=i.children);for(let t=0;t{return i(e?n.toUpperCase():n,21==(s=t[n])?"type":20==s?"keyword":"variable");var s});return s=["QuotedIdentifier","String","LineComment","BlockComment","."],r=bf(n),t=>{for(let e=xa(t.state).resolveInner(t.pos,-1);e;e=e.parent){if(s.indexOf(e.name)>-1)return null;if(e.type.isTop)break}return r(t)};var s,r}let Xp=Ep.configure({props:[Ha.add({Statement:Ua()}),$a.add({Statement:(t,e)=>({from:Math.min(t.from+100,e.doc.lineAt(t.from).to),to:t.to}),BlockComment:t=>({from:t.from+2,to:t.to-2})}),Kl({Keyword:pa.keyword,Type:pa.typeName,Builtin:pa.standard(pa.name),Bits:pa.number,Bytes:pa.string,Bool:pa.bool,Null:pa.null,Number:pa.number,String:pa.string,Identifier:pa.name,QuotedIdentifier:pa.special(pa.string),SpecialVar:pa.special(pa.name),LineComment:pa.lineComment,BlockComment:pa.blockComment,Operator:pa.operator,"Semi Punctuation":pa.punctuation,"( )":pa.paren,"{ }":pa.brace,"[ ]":pa.squareBracket})]});class Gp{constructor(t,e,i){this.dialect=t,this.language=e,this.spec=i}get extension(){return this.language.extension}configureLanguage(t,e){return new Gp(this.dialect,this.language.configure(t,e),this.spec)}static define(t){let e=function(t,e,i,n){let s={};for(let e in Rp)s[e]=(t.hasOwnProperty(e)?t:Rp)[e];return e&&(s.words=Dp(e,i||"",n)),s}(t,t.keywords,t.types,t.builtin),i=ya.define({name:"sql",parser:Xp.configure({tokenizers:[{from:Bp,to:Pp(e)}]}),languageData:{commentTokens:{line:"--",block:{open:"/*",close:"*/"}},closeBrackets:{brackets:["(","[","{","'",'"',"`"]}}});return new Gp(e,i,t)}}function Yp(t,e){return{label:t,type:e,boost:-1}}function Jp(t,e=!1,i){return jp(t.dialect.words,e,i||Yp)}function Zp(t){return t.schema?function(t,e,i,n,s,r){var o;let l=(null===(o=null==r?void 0:r.spec.identifierQuotes)||void 0===o?void 0:o[0])||'"',a=new Qp(l,!!(null==r?void 0:r.spec.caseInsensitiveIdentifiers)),h=s?a.child(s):null;return a.addNamespace(t),e&&(h||a).addCompletions(e),i&&a.addCompletions(i),h&&a.addCompletions(h.list),n&&a.addCompletions((h||a).child(n).list),t=>{let{parents:e,from:i,quoted:s,empty:r,aliases:o}=Vp(t.state,t.pos);if(r&&!t.explicit)return null;o&&1==e.length&&(e=o[e[0]]||e);let l=a;for(let t of e){for(;!l.children||!l.children[t];)if(l==a&&h)l=h;else{if(l!=h||!n)return null;l=l.child(n)}let e=l.maybeChild(t);if(!e)return null;l=e}let c=l.list;if(l==a&&o&&(c=c.concat(Object.keys(o).map(t=>({label:t,type:"constant"})))),s){let e=s[0],n=Kp(e);return{from:i,to:t.state.sliceDoc(t.pos,t.pos+1)==n?t.pos+1:void 0,options:Fp(e,n,c),validFor:_p}}return{from:i,options:c,validFor:qp}}}(t.schema,t.tables,t.schemas,t.defaultTable,t.defaultSchema,t.dialect||im):()=>null}function tm(t){return t.schema?(t.dialect||im).language.data.of({autocomplete:Zp(t)}):[]}function em(t={}){let e=t.dialect||im;return new Pa(e.language,[tm(t),e.language.data.of({autocomplete:Jp(e,t.upperCaseKeywords,t.keywordCompletion)})])}const im=Gp.define({}),nm=Gp.define({keywords:"and as asc between by case cast count current_date current_time current_timestamp desc distinct each else escape except exists explain filter first for from full generated group having if in index inner intersect into isnull join last left like limit not null or order outer over pragma primary query raise range regexp right rollback row select set table then to union unique using values view virtual when where",types:"null integer real text blob",builtin:"",operatorChars:"*+-%<>!=&|/~",identifierQuotes:'`"',specialVar:"@:?$",caseInsensitiveIdentifiers:!0});return t.editorFromTextArea=function(t,e={}){let i=new pr({doc:t.value,extensions:[kr.of([{key:"Shift-Enter",run:function(){return t.value=i.state.doc.toString(),t.form.submit(),!0}},{key:"Meta-Enter",run:function(){return t.value=i.state.doc.toString(),t.form.submit(),!0}}]),Gd,pr.lineWrapping,em({dialect:nm,schema:e.schema,defaultTable:e.defaultTable,defaultSchema:e.defaultSchema})]}),n=i.contentDOM.closest(".cm-editor");return new ResizeObserver(function(){i.requestMeasure()}).observe(n,{attributes:!0}),t.parentNode.insertBefore(i.dom,t),t.style.display="none",t.form&&t.form.addEventListener("submit",()=>{t.value=i.state.doc.toString()}),i},t}({}); +var cm=function(t){"use strict";let e=[],i=[];function n(t){if(t<768)return!1;for(let n=0,s=e.length;;){let r=n+s>>1;if(t=i[r]))return!0;n=r+1}if(n==s)return!1}}function s(t){return t>=127462&&t<=127487}(()=>{let t="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(t=>t?parseInt(t,36):1);for(let n=0,s=0;n=0&&s(a(t,n));)i++,n-=2;if(i%2==0)break;e+=2}}}return e}function l(t,e,i){for(;e>1;){let n=o(t,e-2,i);if(n=56320&&t<57344}function c(t){return t>=55296&&t<56320}function u(t){return t<65536?1:2}class f{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=x(this,t,e);let n=[];return this.decompose(0,t,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(e,this.length,n,1),p.from(n,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=x(this,t,e);let i=[];return this.decompose(t,e,i,0),p.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),n=new v(this),s=new v(t);for(let t=e,r=e;;){if(n.next(t),s.next(t),t=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(r+=n.value.length,n.done||r>=i)return!0}}iter(t=1){return new v(this,t)}iterRange(t,e=this.length){return new w(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let n=this.line(t).from;i=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new b(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(0==t.length)throw new RangeError("A document must have at least one line");return 1!=t.length||t[0]?t.length<=32?new d(t):p.from(d.split(t,[])):f.empty}}class d extends f{constructor(t,e=function(t){let e=-1;for(let i of t)e+=i.length+1;return e}(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,n){for(let s=0;;s++){let r=this.text[s],o=n+r.length;if((e?i:o)>=t)return new y(n,o,i,r);n=o+1,i++}}decompose(t,e,i,n){let s=t<=0&&e>=this.length?this:new d(g(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(1&n){let t=i.pop(),e=m(s.text,t.text.slice(),0,s.length);if(e.length<=32)i.push(new d(e,t.length+s.length));else{let t=e.length>>1;i.push(new d(e.slice(0,t)),new d(e.slice(t)))}}else i.push(s)}replace(t,e,i){if(!(i instanceof d))return super.replace(t,e,i);[t,e]=x(this,t,e);let n=m(this.text,m(i.text,g(this.text,0,t)),e),s=this.length+i.length-(e-t);return n.length<=32?new d(n,s):p.from(d.split(n,[]),s)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;s<=e&&rt&&r&&(n+=i),ts&&(n+=o.slice(Math.max(0,t-s),e-s)),s=l+1}return n}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],n=-1;for(let s of t)i.push(s),n+=s.length+1,32==i.length&&(e.push(new d(i,n)),i=[],n=-1);return n>-1&&e.push(new d(i,n)),e}}class p extends f{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let e of t)this.lines+=e.lines}lineInner(t,e,i,n){for(let s=0;;s++){let r=this.children[s],o=n+r.length,l=i+r.lines-1;if((e?l:o)>=t)return r.lineInner(t,e,i,n);n=o+1,i=l+1}}decompose(t,e,i,n){for(let s=0,r=0;r<=e&&s=r){let s=n&((r<=t?1:0)|(l>=e?2:0));r>=t&&l<=e&&!s?i.push(o):o.decompose(t-r,e-r,i,s)}r=l+1}}replace(t,e,i){if([t,e]=x(this,t,e),i.lines=s&&e<=o){let l=r.replace(t-s,e-s,i),a=this.lines-r.lines+l.lines;if(l.lines>4&&l.lines>a>>6){let s=this.children.slice();return s[n]=l,new p(s,this.length-(e-t)+i.length)}return super.replace(s,o,l)}s=o+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i="\n"){[t,e]=x(this,t,e);let n="";for(let s=0,r=0;st&&s&&(n+=i),tr&&(n+=o.sliceString(t-r,e-r,i)),r=l+1}return n}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof p))return 0;let i=0,[n,s,r,o]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,s+=e){if(n==r||s==o)return i;let l=this.children[n],a=t.children[s];if(l!=a)return i+l.scanIdentical(a,e);i+=l.length+1}}static from(t,e=t.reduce((t,e)=>t+e.length+1,-1)){let i=0;for(let e of t)i+=e.lines;if(i<32){let i=[];for(let e of t)e.flatten(i);return new d(i,e)}let n=Math.max(32,i>>5),s=n<<1,r=n>>1,o=[],l=0,a=-1,h=[];function c(t){let e;if(t.lines>s&&t instanceof p)for(let e of t.children)c(e);else t.lines>r&&(l>r||!l)?(u(),o.push(t)):t instanceof d&&l&&(e=h[h.length-1])instanceof d&&t.lines+e.lines<=32?(l+=t.lines,a+=t.length+1,h[h.length-1]=new d(e.text.concat(t.text),e.length+1+t.length)):(l+t.lines>n&&u(),l+=t.lines,a+=t.length+1,h.push(t))}function u(){0!=l&&(o.push(1==h.length?h[0]:p.from(h,a)),a=-1,l=h.length=0)}for(let e of t)c(e);return u(),1==o.length?o[0]:new p(o,e)}}function m(t,e,i=0,n=1e9){for(let s=0,r=0,o=!0;r=i&&(a>n&&(l=l.slice(0,n-s)),s0?1:(t instanceof d?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],s=this.offsets[i],r=s>>1,o=n instanceof d?n.text.length:n.children.length;if(r==(e>0?o:0)){if(0==i)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&s)==(e>0?0:1)){if(this.offsets[i]+=e,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(n instanceof d){let s=n.text[r+(e<0?-1:0)];if(this.offsets[i]+=e,s.length>Math.max(0,t))return this.value=0==t?s:e>0?s.slice(t):s.slice(0,s.length-t),this;t-=s.length}else{let s=n.children[r+(e<0?-1:0)];t>s.length?(t-=s.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(s),this.offsets.push(e>0?1:(s instanceof d?s.text.length:s.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class w{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new v(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:n}=this.cursor.next(t);return this.pos+=(n.length+t)*e,this.value=n.length<=i?n:e<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class b{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:n}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(f.prototype[Symbol.iterator]=function(){return this.iter()},v.prototype[Symbol.iterator]=w.prototype[Symbol.iterator]=b.prototype[Symbol.iterator]=function(){return this});class y{constructor(t,e,i,n){this.from=t,this.to=e,this.number=i,this.text=n}get length(){return this.to-this.from}}function x(t,e,i){return[e=Math.max(0,Math.min(t.length,e)),Math.max(e,Math.min(t.length,i))]}function k(t,e,i=!0,n=!0){return r(t,e,i,n)}function S(t,e){let i=t.charCodeAt(e);if(!(n=i,n>=55296&&n<56320&&e+1!=t.length))return i;var n;let s=t.charCodeAt(e+1);return function(t){return t>=56320&&t<57344}(s)?s-56320+(i-55296<<10)+65536:i}function C(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function A(t){return t<65536?1:2}const M=/\r\n?|\n/;var O=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(O||(O={}));class T{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return s+(t-n);s+=o}else{if(i!=O.Simple&&a>=t&&(i==O.TrackDel&&nt||i==O.TrackBefore&&nt))return null;if(a>t||a==t&&e<0&&!o)return t==n||e<0?s:s+l;s+=l}n=a}if(t>n)throw new RangeError(`Position ${t} is out of range for changeset of length ${n}`);return s}touchesRange(t,e=t){for(let i=0,n=0;i=0&&n<=e&&s>=t)return!(ne)||"cover";n=s}return!1}toString(){let t="";for(let e=0;e=0?":"+n:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(t=>"number"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeDesc");return new T(t)}static create(t){return new T(t)}}class D extends T{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return B(this,(e,i,n,s,r)=>t=t.replace(n,n+(i-e),r),!1),t}mapDesc(t,e=!1){return E(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let n=0,s=0;n=0){e[n]=o,e[n+1]=r;let l=n>>1;for(;i.length0&&P(i,e,s.text),s.forward(t),o+=t}let a=t[r++];for(;o>1].toJSON()))}return t}static of(t,e,i){let n=[],s=[],r=0,o=null;function l(t=!1){if(!t&&!n.length)return;ro||t<0||o>e)throw new RangeError(`Invalid change range ${t} to ${o} (in doc of length ${e})`);let c=h?"string"==typeof h?f.of(h.split(i||M)):h:f.empty,u=c.length;if(t==o&&0==u)return;tr&&R(n,t-r,-1),R(n,o-t,u),P(s,n,c),r=o}}(t),l(!o),o}static empty(t){return new D(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let n=0;ne&&"string"!=typeof t))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==s.length)e.push(s[0],0);else{for(;i.length=0&&i<=0&&i==t[s+1]?t[s]+=e:s>=0&&0==e&&0==t[s]?t[s+1]+=i:n?(t[s]+=e,t[s+1]+=i):t.push(e,i)}function P(t,e,i){if(0==i.length)return;let n=e.length-2>>1;if(n>1])),!(i||o==t.sections.length||t.sections[o+1]<0);)l=t.sections[o++],a=t.sections[o++];e(s,h,r,c,u),s=h,r=c}}}function E(t,e,i,n=!1){let s=[],r=n?[]:null,o=new I(t),l=new I(e);for(let t=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(-1==o.ins&&-1==l.ins){let t=Math.min(o.len,l.len);R(s,t,-1),o.forward(t),l.forward(t)}else if(l.ins>=0&&(o.ins<0||t==o.i||0==o.off&&(l.len=0&&t=0)){if(o.done&&l.done)return r?D.createSet(s,r):T.create(s);throw new Error("Mismatched change set lengths")}{let e=0,i=o.len;for(;i;)if(-1==l.ins){let t=Math.min(i,l.len);e+=t,i-=t,l.forward(t)}else{if(!(0==l.ins&&l.lene||o.ins>=0&&o.len>e)&&(t||n.length>i),r.forward2(e),o.forward(e)}}else R(n,0,o.ins,t),s&&P(s,n,o.text),o.next()}}class I{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return e>=t.length?f.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?f.empty:e[i].slice(this.off,null==t?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){-1==this.ins?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class N{constructor(t,e,i,n){this.from=t,this.to=e,this.flags=i,this.goalColumn=n}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get undirectional(){return(64&this.flags)>0}get bidiLevel(){let t=7&this.flags;return 7==t?null:t}map(t,e=-1){let i,n;return this.empty?i=n=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),n=t.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new N(i,n,this.flags,this.goalColumn)}extend(t,e=t,i=0){if(t<=this.anchor&&e>=this.anchor)return W.range(t,e,void 0,void 0,i);let n=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return W.range(this.anchor,n,void 0,void 0,i)}eq(t,e=!1){return!(this.anchor!=t.anchor||this.head!=t.head||this.goalColumn!=t.goalColumn||e&&this.empty&&this.assoc!=t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||"number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid JSON representation for SelectionRange");return W.range(t.anchor,t.head)}static create(t,e,i,n){return new N(t,e,i,n)}}class W{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:W.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;it.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||"number"!=typeof t.main||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new W(t.ranges.map(t=>N.fromJSON(t)),t.main)}static single(t,e=t){return new W([W.range(t,e)],0)}static create(t,e=0){if(0==t.length)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;nt.from-e.from),e=t.indexOf(i);for(let i=1;in.head?W.range(o,r):W.range(r,o))}}return new W(t,e)}}function H(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let V=0;class z{constructor(t,e,i,n,s){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=n,this.id=V++,this.default=t([]),this.extensions="function"==typeof s?s(this):s}get reader(){return this}static define(t={}){return new z(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:F),!!t.static,t.enables)}of(t){return new q([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new q(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new q(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],i=>e(i.field(t)))}}function F(t,e){return t==e||t.length==e.length&&t.every((t,i)=>t===e[i])}class q{constructor(t,e,i,n){this.dependencies=t,this.facet=e,this.type=i,this.value=n,this.id=V++}dynamicSlot(t){var e;let i=this.value,n=this.facet.compareInput,s=this.id,r=t[s]>>1,o=2==this.type,l=!1,a=!1,h=[];for(let i of this.dependencies)"doc"==i?l=!0:"selection"==i?a=!0:1&(null!==(e=t[i.id])&&void 0!==e?e:1)||h.push(t[i.id]);return{create:t=>(t.values[r]=i(t),1),update(t,e){if(l&&e.docChanged||a&&(e.docChanged||e.selection)||U(t,h)){let e=i(t);if(o?!_(e,t.values[r],n):!n(e,t.values[r]))return t.values[r]=e,1}return 0},reconfigure:(t,e)=>{let l,a=e.config.address[s];if(null!=a){let s=rt(e,a);if(this.dependencies.every(i=>i instanceof z?e.facet(i)===t.facet(i):!(i instanceof K)||e.field(i,!1)==t.field(i,!1))||(o?_(l=i(t),s,n):n(l=i(t),s)))return t.values[r]=s,0}else l=i(t);return t.values[r]=l,1}}}get extension(){return this}}function _(t,e,i){if(t.length!=e.length)return!1;for(let n=0;nt[e.id]),s=i.map(t=>t.type),r=n.filter(t=>!(1&t)),o=t[e.id]>>1;function l(t){let i=[];for(let e=0;et===e),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet($).find(t=>t.field==this);return((null==e?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:t=>(t.values[e]=this.create(t),1),update:(t,i)=>{let n=t.values[e],s=this.updateF(n,i);return this.compareF(n,s)?0:(t.values[e]=s,1)},reconfigure:(t,i)=>{let n,s=t.facet($),r=i.facet($);return(n=s.find(t=>t.field==this))&&n!=r.find(t=>t.field==this)?(t.values[e]=n.create(t),1):null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}}init(t){return[this,$.of({field:this,create:t})]}get extension(){return this}}const j=4,X=3,G=2,Y=1;function J(t){return e=>new tt(e,t)}const Z={highest:J(0),high:J(Y),default:J(G),low:J(X),lowest:J(j)};class tt{constructor(t,e){this.inner=t,this.prec=e}get extension(){return this}}class et{of(t){return new it(this,t)}reconfigure(t){return et.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class it{constructor(t,e){this.compartment=t,this.inner=e}get extension(){return this}}class nt{constructor(t,e,i,n,s,r){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=n,this.staticValues=s,this.facets=r,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(t,e,i){let n=[],s=Object.create(null),r=new Map;for(let i of function(t,e,i){let n=[[],[],[],[],[]],s=new Map;function r(t,o){let l=s.get(t);if(null!=l){if(l<=o)return;let e=n[l].indexOf(t);e>-1&&n[l].splice(e,1),t instanceof it&&i.delete(t.compartment)}if(s.set(t,o),Array.isArray(t))for(let e of t)r(e,o);else if(t instanceof it){if(i.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let n=e.get(t.compartment)||t.inner;i.set(t.compartment,n),r(n,o)}else if(t instanceof tt)r(t.inner,t.prec);else if(t instanceof K)n[o].push(t),t.provides&&r(t.provides,o);else if(t instanceof q)n[o].push(t),t.facet.extensions&&r(t.facet.extensions,G);else{let e=t.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${t}).`);if(e==t)throw new Error(`Unrecognized extension value in extension set (${t}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(e,o)}}return r(t,G),n.reduce((t,e)=>t.concat(e))}(t,e,r))i instanceof K?n.push(i):(s[i.facet.id]||(s[i.facet.id]=[])).push(i);let o=Object.create(null),l=[],a=[];for(let t of n)o[t.id]=a.length<<1,a.push(e=>t.slot(e));let h=null==i?void 0:i.config.facets;for(let t in s){let e=s[t],n=e[0].facet,r=h&&h[t]||[];if(e.every(t=>0==t.type))if(o[n.id]=l.length<<1|1,F(r,e))l.push(i.facet(n));else{let t=n.combine(e.map(t=>t.value));l.push(i&&n.compare(t,i.facet(n))?i.facet(n):t)}else{for(let t of e)0==t.type?(o[t.id]=l.length<<1|1,l.push(t.value)):(o[t.id]=a.length<<1,a.push(e=>t.dynamicSlot(e)));o[n.id]=a.length<<1,a.push(t=>Q(t,n,e))}}let c=a.map(t=>t(o));return new nt(t,r,c,o,l,s)}}function st(t,e){if(1&e)return 2;let i=e>>1,n=t.status[i];if(4==n)throw new Error("Cyclic dependency between fields and/or facets");if(2&n)return n;t.status[i]=4;let s=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|s}function rt(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const ot=z.define(),lt=z.define({combine:t=>t.some(t=>t),static:!0}),at=z.define({combine:t=>t.length?t[0]:void 0,static:!0}),ht=z.define(),ct=z.define(),ut=z.define(),ft=z.define({combine:t=>!!t.length&&t[0]});class dt{constructor(t,e){this.type=t,this.value=e}static define(){return new pt}}class pt{of(t){return new dt(this,t)}}class mt{constructor(t){this.map=t}of(t){return new gt(this,t)}}class gt{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return void 0===e?void 0:e==this.value?this:new gt(this.type,e)}is(t){return this.type==t}static define(t={}){return new mt(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let n of t){let t=n.map(e);t&&i.push(t)}return i}}gt.reconfigure=gt.define(),gt.appendConfig=gt.define();class vt{constructor(t,e,i,n,s,r){this.startState=t,this.changes=e,this.selection=i,this.effects=n,this.annotations=s,this.scrollIntoView=r,this._doc=null,this._state=null,i&&H(i,e.newLength),s.some(t=>t.type==vt.time)||(this.annotations=s.concat(vt.time.of(Date.now())))}static create(t,e,i,n,s,r){return new vt(t,e,i,n,s,r)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(vt.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function wt(t,e){let i=[];for(let n=0,s=0;;){let r,o;if(n=t[n]))r=t[n++],o=t[n++];else{if(!(s=0;s--){let r=i[s](t);r&&Object.keys(r).length&&(n=bt(n,yt(e,r,t.changes.newLength),!0))}return n==t?t:vt.create(e,t.changes,t.selection,n.effects,n.annotations,n.scrollIntoView)}(i?function(t){let e=t.startState,i=!0;for(let n of e.facet(ht)){let e=n(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:wt(i,e))}if(!0!==i){let n,s;if(!1===i)s=t.changes.invertedDesc,n=D.empty(e.doc.length);else{let e=t.changes.filter(i);n=e.changes,s=e.filtered.mapDesc(e.changes).invertedDesc}t=vt.create(e,n,t.selection&&t.selection.map(s),gt.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let n=e.facet(ct);for(let i=n.length-1;i>=0;i--){let s=n[i](t);t=s instanceof vt?s:Array.isArray(s)&&1==s.length&&s[0]instanceof vt?s[0]:xt(e,St(s),!1)}return t}(s):s)}vt.time=dt.define(),vt.userEvent=dt.define(),vt.addToHistory=dt.define(),vt.remote=dt.define();const kt=[];function St(t){return null==t?kt:Array.isArray(t)?t:[t]}var Ct=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(Ct||(Ct={}));const At=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Mt;try{Mt=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}function Ot(t){return e=>{if(!/\S/.test(e))return Ct.Space;if(function(t){if(Mt)return Mt.test(t);for(let e=0;e"€"&&(i.toUpperCase()!=i.toLowerCase()||At.test(i)))return!0}return!1}(e))return Ct.Word;for(let i=0;i-1)return Ct.Word;return Ct.Other}}class Tt{constructor(t,e,i,n,s,r){this.config=t,this.doc=e,this.selection=i,this.values=n,this.status=t.statusTemplate.slice(),this.computeSlot=s,r&&(r._state=this);for(let t=0;ts.set(e,t)),i=null),s.set(e.value.compartment,e.value.extension)):e.is(gt.reconfigure)?(i=null,n=e.value):e.is(gt.appendConfig)&&(i=null,n=St(n).concat(e.value));if(i)e=t.startState.values.slice();else{i=nt.resolve(n,s,this),e=new Tt(i,this.doc,this.selection,i.dynamicSlots.map(()=>null),(t,e)=>e.reconfigure(t,this),null).values}let r=t.startState.facet(lt)?t.newSelection:t.newSelection.asSingle();new Tt(i,t.newDoc,r,e,(e,i)=>i.update(e,t),t)}replaceSelection(t){return"string"==typeof t&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:W.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),n=this.changes(i.changes),s=[i.range],r=St(i.effects);for(let i=1;is.spec.fromJSON(r,t)))}return Tt.create({doc:t.doc,selection:W.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(t={}){let e=nt.resolve(t.extensions||[],new Map),i=t.doc instanceof f?t.doc:f.of((t.doc||"").split(e.staticFacet(Tt.lineSeparator)||M)),n=t.selection?t.selection instanceof W?t.selection:W.single(t.selection.anchor,t.selection.head):W.single(0);return H(n,i.length),e.staticFacet(lt)||(n=n.asSingle()),new Tt(e,i,n,e.dynamicSlots.map(()=>null),(t,e)=>e.create(t),null)}get tabSize(){return this.facet(Tt.tabSize)}get lineBreak(){return this.facet(Tt.lineSeparator)||"\n"}get readOnly(){return this.facet(ft)}phrase(t,...e){for(let e of this.facet(Tt.phrases))if(Object.prototype.hasOwnProperty.call(e,t)){t=e[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(t,i)=>{if("$"==i)return"$";let n=+(i||1);return!n||n>e.length?t:e[n-1]})),t}languageDataAt(t,e,i=-1){let n=[];for(let s of this.facet(ot))for(let r of s(this,e,i))Object.prototype.hasOwnProperty.call(r,t)&&n.push(r[t]);return n}charCategorizer(t){let e=this.languageDataAt("wordChars",t);return Ot(e.length?e[0]:"")}wordAt(t){let{text:e,from:i,length:n}=this.doc.lineAt(t),s=this.charCategorizer(t),r=t-i,o=t-i;for(;r>0;){let t=k(e,r,!1);if(s(e.slice(t,r))!=Ct.Word)break;r=t}for(;ot.length?t[0]:4}),Tt.lineSeparator=at,Tt.readOnly=ft,Tt.phrases=z.define({compare(t,e){let i=Object.keys(t),n=Object.keys(e);return i.length==n.length&&i.every(i=>t[i]==e[i])}}),Tt.languageData=ot,Tt.changeFilter=ht,Tt.transactionFilter=ct,Tt.transactionExtender=ut,et.reconfigure=gt.define();class Rt{eq(t){return this==t}range(t,e=t){return Bt.create(t,e,this)}}function Pt(t,e){return t==e||t.constructor==e.constructor&&t.eq(e)}Rt.prototype.startSide=Rt.prototype.endSide=0,Rt.prototype.point=!1,Rt.prototype.mapMode=O.TrackDel;let Bt=class t{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(e,i,n){return new t(e,i,n)}};function Et(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Lt{constructor(t,e,i,n){this.from=t,this.to=e,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,n=0){let s=i?this.to:this.from;for(let r=n,o=s.length;;){if(r==o)return r;let n=r+o>>1,l=s[n]-t||(i?this.value[n].endSide:this.value[n].startSide)-e;if(n==r)return l>=0?r:o;l>=0?o=n:r=n+1}}between(t,e,i,n){for(let s=this.findIndex(e,-1e9,!0),r=this.findIndex(i,1e9,!1,s);sh||a==h&&c.startSide>0&&c.endSide<=0)continue;(h-a||c.endSide-c.startSide)<0||(r<0&&(r=a),c.point&&(o=Math.max(o,h-a)),i.push(c),n.push(a-r),s.push(h-r))}return{mapped:i.length?new Lt(n,s,i,o):null,pos:r}}}class It{constructor(t,e,i,n){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=n}static create(t,e,i,n){return new It(t,e,i,n)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:n=0,filterTo:s=this.length}=t,r=t.filter;if(0==e.length&&!r)return this;if(i&&(e=e.slice().sort(Et)),this.isEmpty)return e.length?It.of(e):this;let o=new Ht(this,null,-1).goto(0),l=0,a=[],h=new Nt;for(;o.value||l=0){let t=e[l++];h.addInner(t.from,t.to,t.value)||a.push(t)}else 1==o.rangeIndex&&o.chunkIndexthis.chunkEnd(o.chunkIndex)||so.to||s=s&&t<=s+r.length&&!1===r.between(s,t-s,e-s,i))return}this.nextLayer.between(t,e,i)}}iter(t=0){return Vt.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Vt.from(t).goto(e)}static compare(t,e,i,n,s=-1){let r=t.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),o=e.filter(t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s),l=Wt(r,o,i),a=new Ft(r,l,s),h=new Ft(o,l,s);i.iterGaps((t,e,i)=>qt(a,t,h,e,i,n)),i.empty&&0==i.length&&qt(a,0,h,0,0,n)}static eq(t,e,i=0,n){null==n&&(n=999999999);let s=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0),r=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0);if(s.length!=r.length)return!1;if(!s.length)return!0;let o=Wt(s,r),l=new Ft(s,o,0).goto(i),a=new Ft(r,o,0).goto(i);for(;;){if(l.to!=a.to||!_t(l.active,a.active)||l.point&&(!a.point||!Pt(l.point,a.point)))return!1;if(l.to>n)return!0;l.next(),a.next()}}static spans(t,e,i,n,s=-1){let r=new Ft(t,null,s).goto(e),o=e,l=r.openStart;for(;;){let t=Math.min(r.to,i);if(r.point){let i=r.activeForPoint(r.to),s=r.pointFromo&&(n.span(o,t,r.active,l),l=r.openEnd(t));if(r.to>i)return l+(r.point&&r.to>i?1:0);o=r.to,r.next()}}static of(t,e=!1){let i=new Nt;for(let n of t instanceof Bt?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i0)return t.slice().sort(Et);e=n}return t}(t):t)i.add(n.from,n.to,n.value);return i.finish()}static join(t){if(!t.length)return It.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let n=t[i];n!=It.empty;n=n.nextLayer)e=new It(n.chunkPos,n.chunk,e,Math.max(n.maxPoint,e.maxPoint));return e}}It.empty=new It([],[],null,-1),It.empty.nextLayer=It.empty;class Nt{finishChunk(t){this.chunks.push(new Lt(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new Nt)).add(t,e,i)}addInner(t,e,i){let n=t-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(n<0)&&(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(It.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=It.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Wt(t,e,i){let n=new Map;for(let e of t)for(let t=0;t=this.minPoint)break}}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=i&&n.push(new Ht(r,e,i,s));return 1==n.length?n[0]:new Vt(n)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let t=this.heap.length>>1;t>=0;t--)zt(this.heap,t);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let t=this.heap.length>>1;t>=0;t--)zt(this.heap,t);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),zt(this.heap,0)}}}function zt(t,e){for(let i=t[e];;){let n=1+(e<<1);if(n>=t.length)break;let s=t[n];if(n+1=0&&(s=t[n+1],n++),i.compare(s)<0)break;t[n]=i,t[e]=s,e=n}}class Ft{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Vt.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){Ut(this.active,t),Ut(this.activeTo,t),Ut(this.activeRank,t),this.minActive=$t(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:n,rank:s}=this.cursor;for(;e0;)e++;Qt(this.active,e,i),Qt(this.activeTo,e,n),Qt(this.activeRank,e,s),t&&Qt(t,e,this.cursor.from),this.minActive=$t(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>t){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&Ut(i,n)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let t=this.cursor.value;if(t.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from=0&&i[e]=0&&!(this.activeRank[i]t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function qt(t,e,i,n,s,r){t.goto(e),i.goto(n);let o=n+s,l=n,a=n-e,h=!!r.boundChange;for(let e=!1;;){let n=t.to+a-i.to,s=n||t.endSide-i.endSide,c=s<0?t.to+a:i.to,u=Math.min(c,o);if(t.point||i.point?(t.point&&i.point&&Pt(t.point,i.point)&&_t(t.activeForPoint(t.to),i.activeForPoint(i.to))||r.comparePoint(l,u,t.point,i.point),e=!1):(e&&r.boundChange(l),u>l&&!_t(t.active,i.active)&&r.compareRange(l,u,t.active,i.active),h&&uo)break;l=c,s<=0&&t.next(),s>=0&&i.next()}}function _t(t,e){if(t.length!=e.length)return!1;for(let i=0;i=e;i--)t[i+1]=t[i];t[e]=i}function $t(t,e){let i=-1,n=1e9;for(let s=0;s=e)return n;if(n==t.length)break;s+=9==t.charCodeAt(n)?i-s%i:1,n=k(t,n)}return!0===n?-1:t.length}const Xt="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),Gt="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),Yt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class Jt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function n(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function s(t,e,r,o){let l=[],a=/^@(\w+)\b/.exec(t[0]),h=a&&"keyframes"==a[1];if(a&&null==e)return r.push(t[0]+";");for(let i in e){let o=e[i];if(/&/.test(i))s(i.split(/,\s*/).map(e=>t.map(t=>e.replace(/&/,t))).reduce((t,e)=>t.concat(e)),o,r);else if(o&&"object"==typeof o){if(!a)throw new RangeError("The value of a property ("+i+") should be a primitive value.");s(n(i),o,l,h)}else null!=o&&l.push(i.replace(/_.*/,"").replace(/[A-Z]/g,t=>"-"+t.toLowerCase())+": "+o+";")}(l.length||h)&&r.push((!i||a||o?t:t.map(i)).join(", ")+" {"+l.join(" ")+"}")}for(let e in t)s(n(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=Yt[Xt]||1;return Yt[Xt]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let n=t[Gt],s=i&&i.nonce;n?s&&n.setNonce(s):n=new te(t,s),n.mount(Array.isArray(e)?e:[e],t)}}let Zt=new Map;class te{constructor(t,e){let i=t.ownerDocument||t,n=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let e=Zt.get(i);if(e)return t[Gt]=e;this.sheet=new n.CSSStyleSheet,Zt.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[Gt]=this}mount(t,e){let i=this.sheet,n=0,s=0;for(let e=0;e-1&&(this.modules.splice(o,1),s--,o=-1),-1==o){if(this.modules.splice(s++,0,r),i)for(let t=0;t",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},ne="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),se="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),re=0;re<10;re++)ee[48+re]=ee[96+re]=String(re);for(re=1;re<=24;re++)ee[re+111]="F"+re;for(re=65;re<=90;re++)ee[re]=String.fromCharCode(re+32),ie[re]=String.fromCharCode(re);for(var oe in ee)ie.hasOwnProperty(oe)||(ie[oe]=ee[oe]);function le(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var n in i)if(Object.prototype.hasOwnProperty.call(i,n)){var s=i[n];"string"==typeof s?t.setAttribute(n,s):null!=s&&(t[n]=s)}e++}for(;e2);var ye={mac:be||/Mac/.test(he.platform),windows:/Win/.test(he.platform),linux:/Linux|X11/.test(he.platform),ie:pe,ie_version:fe?ce.documentMode||6:de?+de[1]:ue?+ue[1]:0,gecko:me,gecko_version:me?+(/Firefox\/(\d+)/.exec(he.userAgent)||[0,0])[1]:0,chrome:!!ge,chrome_version:ge?+ge[1]:0,ios:be,android:/Android\b/.test(he.userAgent),webkit:ve,webkit_version:ve?+(/\bAppleWebKit\/(\d+)/.exec(he.userAgent)||[0,0])[1]:0,safari:we,safari_version:we?+(/\bVersion\/(\d+(\.\d+)?)/.exec(he.userAgent)||[0,0])[1]:0,tabSize:null!=ce.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};function xe(t,e){for(let i in t)"class"==i&&e.class?e.class+=" "+t.class:"style"==i&&e.style?e.style+=";"+t.style:e[i]=t[i];return e}const ke=Object.create(null);function Se(t,e,i){if(t==e)return!0;t||(t=ke),e||(e=ke);let n=Object.keys(t),s=Object.keys(e);if(n.length-(i&&n.indexOf(i)>-1?1:0)!=s.length-(i&&s.indexOf(i)>-1?1:0))return!1;for(let r of n)if(r!=i&&(-1==s.indexOf(r)||t[r]!==e[r]))return!1;return!0}function Ce(t,e,i){let n=!1;if(e)for(let s in e)i&&s in i||(n=!0,"style"==s?t.style.cssText="":t.removeAttribute(s));if(i)for(let s in i)e&&e[s]==i[s]||(n=!0,"style"==s?t.style.cssText=i[s]:t.setAttribute(s,i[s]));return n}function Ae(t){let e=Object.create(null);for(let i=0;i0?3e8:-4e8:e>0?1e8:-1e8,new Pe(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,n=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:s,end:r}=Be(t,n);e=(s?n?-3e8:-1:5e8)-1,i=1+(r?n?2e8:1:-6e8)}return new Pe(t,e,i,n,t.widget||null,!0)}static line(t){return new Re(t)}static set(t,e=!1){return It.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}Te.none=It.empty;class De extends Te{constructor(t){let{start:e,end:i}=Be(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?xe(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||ke}eq(t){return this==t||t instanceof De&&this.tagName==t.tagName&&Se(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}De.prototype.point=!1;class Re extends Te{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Re&&this.spec.class==t.spec.class&&Se(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}Re.prototype.mapMode=O.TrackBefore,Re.prototype.point=!0;class Pe extends Te{constructor(t,e,i,n,s,r){super(e,i,s,t),this.block=n,this.isReplace=r,this.mapMode=n?e<=0?O.TrackBefore:O.TrackAfter:O.TrackDel}get type(){return this.startSide!=this.endSide?Oe.WidgetRange:this.startSide<=0?Oe.WidgetBefore:Oe.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof Pe&&(e=this.widget,i=t.widget,e==i||!!(e&&i&&e.compare(i)))&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide;var e,i}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}function Be(t,e=!1){let{inclusiveStart:i,inclusiveEnd:n}=t;return null==i&&(i=t.inclusive),null==n&&(n=t.inclusive),{start:null!=i?i:e,end:null!=n?n:e}}function Ee(t,e,i,n=0){let s=i.length-1;s>=0&&i[s]+n>=t?i[s]=Math.max(i[s],e):i.push(t,e)}Pe.prototype.point=!0;class Le extends Rt{constructor(t,e,i){super(),this.tagName=t,this.attributes=e,this.rank=i}eq(t){return t==this||t instanceof Le&&this.tagName==t.tagName&&Se(this.attributes,t.attributes)}static create(t){return new Le(t.tagName,t.attributes||ke,null==t.rank?50:Math.max(0,Math.min(t.rank,100)))}static set(t,e=!1){return It.of(t,e)}}function Ie(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function Ne(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function We(t,e){if(!e.anchorNode)return!1;try{return Ne(t,e.anchorNode)}catch(t){return!1}}function He(t){return 3==t.nodeType?Je(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function Ve(t,e,i,n){return!!i&&(qe(t,e,i,n,-1)||qe(t,e,i,n,1))}function ze(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function Fe(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function qe(t,e,i,n,s){for(;;){if(t==i&&e==n)return!0;if(e==(s<0?0:_e(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=ze(t)+(s<0?0:1),t=i}else{if(1!=t.nodeType)return!1;if(1==(t=t.childNodes[e+(s<0?-1:0)]).nodeType&&"false"==t.contentEditable)return!1;e=s<0?_e(t):0}}}function _e(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Ue(t,e){let{left:i,right:n}=t;if(i==n)return t;let s=e?i:n;return{left:s,right:s,top:t.top,bottom:t.bottom}}function Qe(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function $e(t,e){let i=e.width/t.offsetWidth,n=e.height/t.offsetHeight;return(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)&&(i=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.height-t.offsetHeight)<1)&&(n=1),{scaleX:i,scaleY:n}}function Ke(t,e=!0){let i=t.ownerDocument,n=null,s=null;for(let r=t.parentNode;r&&(r!=i.body&&(e&&!n||!s));)if(1==r.nodeType)!s&&r.scrollHeight>r.clientHeight&&(s=r),e&&!n&&r.scrollWidth>r.clientWidth&&(n=r),r=r.assignedSlot||r.parentNode;else{if(11!=r.nodeType)break;r=r.host}return{x:n,y:s}}Le.prototype.startSide=Le.prototype.endSide=-1;class je{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?_e(e):0),i,Math.min(t.focusOffset,i?_e(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}}let Xe,Ge=null;function Ye(t){if(t.setActive)return t.setActive();if(Ge)return t.focus(Ge);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==Ge?{get preventScroll(){return Ge={preventScroll:!0},!0}}:void 0),!Ge){Ge=!1;for(let t=0;tMath.max(0,t.document.documentElement.scrollHeight-t.innerHeight-4):t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function ei(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&n>0)return{node:i,offset:n};if(1==i.nodeType&&n>0){if("false"==i.contentEditable)return null;i=i.childNodes[n-1],n=_e(i)}else{if(!i.parentNode||Fe(i))return null;n=ze(i),i=i.parentNode}}}function ii(t,e){for(let i=t,n=e;;){if(3==i.nodeType&&n=26&&(Ge=!1);class ni{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new ni(t.parentNode,ze(t),e)}static after(t,e){return new ni(t.parentNode,ze(t)+1,e)}}var si=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(si||(si={}));const ri=si.LTR,oi=si.RTL;function li(t){let e=[];for(let i=0;i=e){if(o.level==i)return r;(s<0||(0!=n?n<0?o.frome:t[s].level>o.level))&&(s=r)}}if(s<0)throw new RangeError("Index out of range");return s}}function mi(t,e){if(t.length!=e.length)return!1;for(let i=0;ia&&o.push(new pi(a,p.from,f)),wi(t,p.direction==ri!=!(f%2)?n+1:n,s,p.inner,p.from,p.to,o),a=p.to}d=p.to}else{if(d==i||(e?gi[d]!=l:gi[d]==l))break;d++}u?vi(t,a,d,n+1,s,u,o):ae;){let i=!0,c=!1;if(!h||a>r[h-1].to){let t=gi[a-1];t!=l&&(i=!1,c=16==t)}let u=i||1!=l?null:[],f=i?n:n+1,d=a;t:for(;;)if(h&&d==r[h-1].to){if(c)break t;let p=r[--h];if(!i)for(let t=p.from,i=h;;){if(t==e)break t;if(!i||r[i-1].to!=t){if(gi[t-1]==l)break t;break}t=r[--i].from}if(u)u.push(p);else{p.to=0;t-=3)if(ui[t+1]==-i){let e=ui[t+2],i=2&e?s:4&e?1&e?r:s:0;i&&(gi[o]=gi[ui[t]]=i),l=t;break}}else{if(189==ui.length)break;ui[l++]=o,ui[l++]=e,ui[l++]=a}else if(2==(n=gi[o])||1==n){let t=n==s;a=t?0:1;for(let e=l-3;e>=0;e-=3){let i=ui[e+2];if(2&i)break;if(t)ui[e+2]|=2;else{if(4&i)break;ui[e+2]|=4}}}}}(t,s,r,n,l),function(t,e,i,n){for(let s=0,r=n;s<=i.length;s++){let o=s?i[s-1].to:t,l=sa;)e==r&&(e=i[--n].from,r=n?i[n-1].to:t),gi[--e]=c;a=o}else r=o,a++}}}(s,r,n,l),vi(t,s,r,e,i,n,o)}function bi(t){return[new pi(0,t,0)]}let yi="";function xi(t,e,i,n,s){var r;let o=n.head-t.from,l=pi.find(e,o,null!==(r=n.bidiLevel)&&void 0!==r?r:-1,n.assoc),a=e[l],h=a.side(s,i);if(o==h){let t=l+=s?1:-1;if(t<0||t>=e.length)return null;a=e[l=t],o=a.side(!s,i),h=a.side(s,i)}let c=k(t.text,o,a.forward(s,i));(ca.to)&&(c=h),yi=t.text.slice(Math.min(o,c),Math.max(o,c));let u=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return u&&c==h&&u.level+(s?0:1)t.some(t=>t)}),Ei=z.define({combine:t=>t.some(t=>t)}),Li=z.define();class Ii{constructor(t,e,i,n,s,r=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=s,this.isSnapshot=r}map(t){return t.empty?this:new Ii(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Ii(W.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Ni=gt.define({map:(t,e)=>t.map(e)}),Wi=gt.define();function Hi(t,e,i){let n=t.facet(Mi);n.length?n[0](e):window.onerror&&window.onerror(String(e),i,void 0,void 0,e)||(i?console.error(i+":",e):console.error(e))}const Vi=z.define({combine:t=>!t.length||t[0]});let zi=0;const Fi=z.define({combine:t=>t.filter((e,i)=>{for(let n=0;n{let e=[];return r&&e.push($i.of(e=>{let i=e.plugin(t);return i?r(i):Te.none})),s&&e.push(s(t)),e})}static fromClass(t,e){return qi.define((e,i)=>new t(e,i),e)}}class _i{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(Hi(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){Hi(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(null===(e=this.value)||void 0===e?void 0:e.destroy)try{this.value.destroy()}catch(e){Hi(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Ui=z.define(),Qi=z.define(),$i=z.define(),Ki=z.define(),ji=z.define(),Xi=z.define(),Gi=z.define();function Yi(t,e){let i=t.state.facet(Gi);if(!i.length)return i;let n=i.map(e=>e instanceof Function?e(t):e),s=[];return It.spans(n,e.from,e.to,{point(){},span(t,i,n,r){let o=t-e.from,l=i-e.from,a=s;for(let t=n.length-1;t>=0;t--,r--){let i,s=n[t].spec.bidiIsolate;if(null==s&&(s=ki(e.text,o,l)),r>0&&a.length&&(i=a[a.length-1]).to==o&&i.direction==s)i.to=l,a=i.inner;else{let t={from:o,to:l,direction:s,inner:[]};a.push(t),a=t.inner}}}}),s}const Ji=z.define();function Zi(t){let e=0,i=0,n=0,s=0;for(let r of t.state.facet(Ji)){let o=r(t);o&&(null!=o.left&&(e=Math.max(e,o.left)),null!=o.right&&(i=Math.max(i,o.right)),null!=o.top&&(n=Math.max(n,o.top)),null!=o.bottom&&(s=Math.max(s,o.bottom)))}return{left:e,right:i,top:n,bottom:s}}const tn=z.define();class en{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new en(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toAn.push(new en(t,e,i,s))),this.changedRanges=n}static create(t,e,i){return new nn(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return 0==this.flags&&0==this.transactions.length}}const sn=[];class rn{constructor(t,e,i=0){this.dom=t,this.length=e,this.flags=i,this.parent=null,t.cmTile=this}get breakAfter(){return 1&this.flags}get children(){return sn}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,4&this.flags){this.flags&=-5;let t=this.domAttrs;t&&function(t,e){for(let i=t.attributes.length-1;i>=0;i--){let n=t.attributes[i].name;null==e[n]&&t.removeAttribute(n)}for(let i in e){let n=e[i];"style"==i?t.style.cssText=n:t.getAttribute(i)!=n&&t.setAttribute(i,n)}}(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t,t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let e of this.children){if(e==t)return i;i+=e.length+e.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e,i){return null}domPosFor(t,e){let i=ze(this.dom),n=this.length?t>0:e>0;return new ni(this.parent.dom,i+(n?1:0),0==t||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&2&this.parent.flags&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof an)return t;return null}static get(t){return t.cmTile}}class on extends rn{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t),t.parent=this}sync(t){if(2&this.flags)return;super.sync(t);let e,i=this.dom,n=null,s=(null==t?void 0:t.node)==i?t:null,r=0;for(let o of this.children){if(o.sync(t),r+=o.length+o.breakAfter,e=n?n.nextSibling:i.firstChild,s&&e!=o.dom&&(s.written=!0),o.dom.parentNode==i)for(;e&&e!=o.dom;)e=ln(e);else i.insertBefore(o.dom,e);n=o.dom}for(e=n?n.nextSibling:i.firstChild,s&&e&&(s.written=!0);e;)e=ln(e);this.length=r}}function ln(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class an extends on{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=rn.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,n=0,s=0;;)if(n==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&s++,n=e.pop()}else{let r=i.children[n++];if(r instanceof hn)e.push(n),i=r,n=0;else{let e=s+r.length,i=t(r,s);if(void 0!==i)return i;s=e+r.breakAfter}}}resolveBlock(t,e){let i,n,s=-1,r=-1;if(this.blockTiles((o,l)=>{let a=l+o.length;if(t>=l&&t<=a){if(o.isWidget()&&e>=-1&&e<=1){if(32&o.flags)return!0;16&o.flags&&(i=void 0)}(lt||t==l&&(e>1?o.length:o.covers(-1)))&&(!n||!o.isWidget()&&n.isWidget())&&(n=o,r=t-l)}}),!i&&!n)throw new Error("No tile at position "+t);return i&&e<0||!n?{tile:i,offset:s}:{tile:n,offset:r}}}class hn extends on{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return!!this.children.length&&(t<0?this.children[0].covers(-1):this.lastChild.covers(1))}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new hn(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class cn extends on{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let n=new cn(e||document.createElement("div"),t);return e&&i||(n.flags|=4),n}get domAttrs(){return this.attrs}resolveInline(t,e,i){let n=null,s=-1,r=null,o=-1;!function t(l,a){for(let h=0,c=0;h=a&&(u.isComposite()?t(u,a-c):(!r||r.isHidden&&(e>0&&!(32&r.flags)||i&&un(r,u)))&&(f>a||32&u.flags)?(r=u,o=a-c):(cn&&(t=n);let s=t,r=t,o=0;0==t&&e<0||t==n&&e>=0?ye.chrome||ye.gecko||(t?(s--,o=1):r=0)?0:l.length-1];return ye.safari&&!o&&0==a.width&&(a=Array.prototype.find.call(l,t=>t.width)||a),null==i?a:Ue(a,(o?o>0:e<0)==i)}static of(t,e){let i=new dn(e||document.createTextNode(t),t);return e||(i.flags|=2),i}}class pn extends rn{constructor(t,e,i,n){super(t,e,n),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return!(48&this.flags)&&(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let n=this.widget.coordsAt(this.dom,t,e);if(n)return n;if(i)return Ue(this.dom.getBoundingClientRect(),this.length?0==t:e<=0);{let e=this.dom.getClientRects(),i=null;if(!e.length)return null;let n=!!(16&this.flags)||!(32&this.flags)&&t>0;for(let s=n?e.length-1:0;i=e[s],!(t>0?0==s:s==e.length-1||i.top0==i)}}class gn{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:n,index:s,beforeBreak:r,parents:o}=this;for(;t||e>0;)if(n.isComposite())if(r){if(!t)break;i&&i.break(),t--,r=!1}else if(s==n.children.length){if(!t&&!o.length)break;i&&i.leave(n),r=!!n.breakAfter,({tile:n,index:s}=o.pop()),s++}else{let l=n.children[s],a=l.breakAfter;!(e>0?l.length<=t:l.length=0;t--){let i=e.marks[t],s=n.lastChild;if(s instanceof fn&&s.mark.eq(i.mark))s.dom!=i.dom&&s.setDOM(An(i.dom)),n=s;else{if(this.cache.reused.get(i)){let t=rn.get(i.dom);t&&t.setDOM(An(i.dom))}let t=fn.of(i.mark,i.dom);n.append(t),n=t}this.cache.reused.set(i,2)}let s=rn.get(t.text);s&&this.cache.reused.set(s,2);let r=new dn(t.text,t.text.nodeValue);r.flags|=8,this.pos=t.range.toB,n.append(r)}addInlineWidget(t,e,i){let n=this.afterWidget&&48&t.flags&&(48&this.afterWidget.flags)==(48&t.flags);n||this.flushBuffer();let s=this.ensureMarks(e,i);n||16&t.flags||s.append(this.getBuffer(1)),s.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).append(t),this.pos+=t.length,this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}continueWidget(t){(this.afterWidget||this.lastBlock).length+=t,this.pos+=t}addLineStart(t,e){var i;t||(t=Cn);let n=cn.start(t,e||(null===(i=this.cache.find(cn))||void 0===i?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(t){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let n=this.curLine;for(let s=t.length-1;s>=0;s--){let r,o=t[s];if(e>0&&(r=n.lastChild)&&r instanceof fn&&r.mark.eq(o))n=r,e--;else{let t=fn.of(o,null===(i=this.cache.find(fn,t=>t.mark.eq(o)))||void 0===i?void 0:i.dom);n.append(t),n=t,e=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;t&&Sn(this.curLine,!1)&&("BR"==t.dom.nodeName||!t.isWidget()||ye.ios&&Sn(this.curLine,!0))||this.curLine.append(this.cache.findWidget(On,0,32)||new pn(On.toDOM(),0,On,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to=this.pos){let e=102*t.rank+t.value.rank,i=new vn(t.from,t.to,t.value,e),n=this.wrappers.length;for(;n>0&&(this.wrappers[n-1].rank-i.rank||this.wrappers[n-1].to-i.to)<0;)n--;this.wrappers.splice(n,0,i)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let n=e.lastChild;if(i.fromt.wrapper.eq(i.wrapper)))||void 0===t?void 0:t.dom);e.append(n),e=n}}return e}blockPosCovered(){let t=this.lastBlock;return null!=t&&!t.breakAfter&&(!t.isWidget()||(160&t.flags)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(mn,void 0,1);return i&&(i.flags=e),i||new mn(e)}flushBuffer(){!this.afterWidget||32&this.afterWidget.flags||(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class bn{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:n}=this.cursor.next(this.skipCount);if(this.skipCount=0,n)throw new Error("Ran out of text content when drawing inline views");this.text=e;let s=this.textOff=Math.min(t,e.length);return i?null:e.slice(0,s)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}}const yn=[pn,cn,dn,fn,mn,hn,an];for(let t=0;t[]),this.index=yn.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let n=t.bucket,s=this.buckets[n],r=this.index[n];for(let t=0;t{if(this.cache.add(t),t.isComposite())return!1},enter:t=>this.cache.add(t),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let n=0,s=0,r=0;;){let o=rn){let t=l-n;this.preserve(t,!r,!o),n=l,s+=t}if(!o)break;e&&o.fromA<=e.range.fromA&&o.toA>=e.range.toA?(this.forward(o.fromA,e.range.fromA,e.range.fromA1;i--){let n=i==t.parents.length?t.tile:t.parents[i].tile;n instanceof fn&&e.push(n.mark)}return e}(this.old),s=this.openMarks;this.old.advance(t,i?1:-1,{skip:(t,e,i)=>{if(t.isWidget())if(this.openWidget)this.builder.continueWidget(i-e);else{let r=i>0||e{t.isLine()?this.builder.addLineStart(t.attrs,this.cache.maybeReuse(t)):(this.cache.add(t),t instanceof fn&&n.unshift(t.mark)),this.openWidget=!1},leave:t=>{t.isLine()?n.length&&(n.length=s=0):t instanceof fn&&(n.shift(),s=Math.min(s,n.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,e){let i=null,n=this.builder,s=-1,r=It.spans(this.decorations,t,e,{point:(t,e,r,o,l,a)=>{if(r instanceof Pe){if(this.disallowBlockEffectsFor[a]){if(r.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.view.state.doc.lineAt(t).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=o.length,l>o.length)n.continueWidget(e-t);else{let s=r.widget||(r.block?Mn.block:Mn.inline),a=function(t){let e=t.isReplace?(t.startSide<0?64:0)|(t.endSide>0?128:0):t.startSide>0?32:16;t.block&&(e|=256);return e}(r),h=this.cache.findWidget(s,e-t,a)||pn.of(s,this.view,e-t,a);r.block?(r.startSide>0&&n.addLineStartIfNotCovered(i),n.addBlockWidget(h)):(n.ensureLine(i),n.addInlineWidget(h,o,l))}i=null}else i=function(t,e){let i=e.spec.attributes,n=e.spec.class;if(!i&&!n)return t;t||(t={class:"cm-line"});i&&xe(i,t);n&&(t.class+=" "+n);return t}(i,r);e>t&&this.text.skip(e-t)},span:(t,e,r,o)=>{for(let s=t;s-1&&(this.openWidget=r>s),this.openWidget||n.addLineStartIfNotCovered(i),this.openMarks=r}forward(t,e,i=1){e-t<=10?this.old.advance(e-t,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(e-t-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(t){let e=[],i=null;for(let n=t.parentNode;;n=n.parentNode){let t=rn.get(n);if(n==this.view.contentDOM)break;t instanceof fn?e.push(t):(null==t?void 0:t.isLine())?i=t:t instanceof hn||("DIV"!=n.nodeName||i||n==this.view.contentDOM?i||e.push(fn.of(new De({tagName:n.nodeName.toLowerCase(),attributes:Ae(n)}),n)):i=new cn(n,Cn))}return{line:i,marks:e}}}function Sn(t,e){let i=t=>{for(let n of t.children)if((e?n.isText():n.length)||i(n))return!0;return!1};return i(t)}const Cn={class:"cm-line"};function An(t){let e=rn.get(t);return e&&e.setDOM(t.cloneNode()),t}class Mn extends Me{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}Mn.inline=new Mn("span"),Mn.block=new Mn("div");const On=new class extends Me{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Tn{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=Te.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new an(t,t.contentDOM),this.updateInner([new en(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:t,toA:e})=>ethis.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(e=this.domChanged)||void 0===e?void 0:e.newSel)?n=this.domChanged.newSel.head:function(t,e){let i=!1;e&&t.iterChangedRanges((t,n)=>{te.from&&(i=!0)});return i}(t.changes,this.hasComposition)||t.selectionSet||(n=t.state.selection.main.head));let s=n>-1?function(t,e,i){let n=Rn(t,i);if(!n)return null;let{node:s,from:r,to:o}=n,l=s.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(n.from,n.to)!=l)return null;let a=e.invertedDesc;return{range:new en(a.mapPos(r),a.mapPos(o),r,o),text:s}}(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:e,to:n}=this.hasComposition;i=new en(e,n,t.changes.mapPos(e,-1),t.changes.mapPos(n,1)).addToSet(i.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(ye.ie||ye.chrome)&&!s&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let r=this.decorations,o=this.blockWrappers;this.updateDeco();let l=function(t,e,i){let n=new Pn;return It.compare(t,e,i,n),n.changes}(r,this.decorations,t.changes);l.length&&(i=en.extendWithRanges(i,l));let a=function(t,e,i){let n=new Bn;return It.compare(t,e,i,n),n.changes}(o,this.blockWrappers,t.changes);return a.length&&(i=en.extendWithRanges(i,a)),s&&!i.some(t=>t.fromA<=s.range.fromA&&t.toA>=s.range.toA)&&(i=s.range.addToSet(i.slice())),!(2&this.tile.flags&&0==i.length)&&(this.updateInner(i,s),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let i=this.tile,n=new kn(this.view,i,this.blockWrappers,this.decorations,this.dynamicDecorationMap);e&&rn.get(e.text)&&n.cache.reused.set(rn.get(e.text),2),this.tile=n.run(t,e),Dn(i,n.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let n=ye.chrome||ye.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(n),!n||!n.written&&i.selectionRange.focusNode==n.node&&this.tile.dom.contains(n.node)||(this.forceSelection=!0),this.tile.dom.style.height=""});let n=[];if(this.view.viewport.from||this.view.viewport.to-1)&&We(i,this.view.observer.selectionRange)&&!(n&&i.contains(n));if(!(s||e||r))return;let o=this.forceSelection;this.forceSelection=!1;let l,a,h=this.view.state.selection.main;if(h.empty?a=l=this.inlineDOMNearPos(h.anchor,h.assoc||1):(a=this.inlineDOMNearPos(h.head,h.head==h.from?1:-1),l=this.inlineDOMNearPos(h.anchor,h.anchor==h.from?1:-1)),ye.gecko&&h.empty&&!this.hasComposition&&(1==(c=l).node.nodeType&&c.node.firstChild&&(0==c.offset||"false"==c.node.childNodes[c.offset-1].contentEditable)&&(c.offset==c.node.childNodes.length||"false"==c.node.childNodes[c.offset].contentEditable))){let t=document.createTextNode("");this.view.observer.ignore(()=>l.node.insertBefore(t,l.node.childNodes[l.offset]||null)),l=a=new ni(t,0),o=!0}var c;let u=this.view.observer.selectionRange;!o&&u.focusNode&&(Ve(l.node,l.offset,u.anchorNode,u.anchorOffset)&&Ve(a.node,a.offset,u.focusNode,u.focusOffset)||this.suppressWidgetCursorChange(u,h))||(this.view.observer.ignore(()=>{ye.android&&ye.chrome&&i.contains(u.focusNode)&&function(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(u.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let t=Ie(this.view.root);if(t)if(h.empty){if(ye.gecko){let t=(e=l.node,s=l.offset,1!=e.nodeType?0:(s&&"false"==e.childNodes[s-1].contentEditable?1:0)|(sh.head&&([l,a]=[a,l]),e.setEnd(a.node,a.offset),e.setStart(l.node,l.offset),t.removeAllRanges(),t.addRange(e)}else;var e,s;r&&this.view.root.activeElement==i&&(i.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(l,a)),this.impreciseAnchor=l.precise?null:new ni(u.anchorNode,u.anchorOffset),this.impreciseHead=a.precise?null:new ni(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Ve(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=Ie(t.root),{anchorNode:n,anchorOffset:s}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let r=this.lineAt(e.head,e.assoc);if(!r)return;let o=r.posAtStart;if(e.head==o||e.head==o+r.length)return;let l=this.coordsAt(e.head,-1),a=this.coordsAt(e.head,1);if(!l||!a||l.bottom>a.top)return;let h=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(h.node,h.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(n,s)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return 2&this.tile.dom.compareDocumentPosition(t)?0:this.view.state.doc.length;let n=i.posAtStart;if(!i.isComposite())return i.isText()?t==i.dom?n+e:n+(e?i.length:0):n;{let s;if(t==i.dom)s=i.dom.childNodes[e];else{let n=0==_e(t)?0:0==e?-1:1;for(;;){let e=t.parentNode;if(e==i.dom)break;0==n&&e.firstChild!=e.lastChild&&(n=t==e.firstChild?-1:1),t=e}s=n<0?t:t.nextSibling}if(s==i.dom.firstChild)return n;for(;s&&!rn.get(s);)s=s.nextSibling;if(!s)return n+i.length;for(let t=0,e=n;;t++){let n=i.children[t];if(n.dom==s)return e;e+=n.length+n.breakAfter}}}domAtPos(t,e){let{tile:i,offset:n}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(n,e):i.domIn(n,e)}inlineDOMNearPos(t,e){let i,n,s=-1,r=!1,o=-1,l=!1;return this.tile.blockTiles((e,a)=>{if(e.isWidget()){if(32&e.flags&&a>=t)return!0;16&e.flags&&(r=!0)}else{let h=a+e.length;if(a<=t&&(i=e,s=t-a,r=h=t&&!n&&(n=e,o=t-a,l=a>t),a>t&&n)return!0}}),i||n?(r&&n?i=null:l&&i&&(n=null),i&&e<0||!n?i.domIn(s,e):n.domIn(o,e)):this.domAtPos(t,e)}coordsAt(t,e,i){let{tile:n,offset:s}=this.tile.resolveBlock(t,e);return n.isWidget()?n.widget instanceof En?null:n.coordsInWidget(s,e,!0):n.coordsIn(s,e,i)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;return function t(e,i){if(e.isComposite())for(let n of e.children){if(n.length>=i){let e=t(n,i);if(e)return e}if((i-=n.length)<0)break}else if(e.isText()&&iMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,l=this.view.textDirection==si.LTR,a=0,h=(t,c,u)=>{for(let f=0;fn);f++){let n=t.children[f],d=c+n.length,p=n.dom.getBoundingClientRect(),{height:m}=p;if(u&&!f&&(a+=p.top-u.top),n instanceof hn)d>i&&h(n,c,p);else if(c>=i&&(a>0&&e.push(-a),e.push(m+a),a=0,r)){let t=n.dom.lastChild,e=t?He(t):[];if(e.length){let t=e[e.length-1],i=l?t.right-p.left:p.right-t.left;i>o&&(o=i,this.minWidth=s,this.minWidthFrom=c,this.minWidthTo=d)}}u&&f==t.children.length-1&&(a+=u.bottom-p.bottom),c=d+n.breakAfter}};return h(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return"rtl"==getComputedStyle(e.dom).direction?si.RTL:si.LTR}measureTextSize(){let t=this.tile.blockTiles(t=>{if(t.isLine()&&t.children.length&&t.length<=20){let e,i=0;for(let n of t.children){if(!n.isText()||/[^ -~]/.test(n.text))return;let t=He(n.dom);if(1!=t.length)return;i+=t[0].width,e=t[0].height}if(i)return{lineHeight:t.dom.getBoundingClientRect().height,charWidth:i/t.length,textHeight:e}}});if(t)return t;let e,i,n,s=document.createElement("div");return s.className="cm-line",s.style.width="99999px",s.style.position="absolute",s.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(s);let t=He(s.firstChild)[0];e=s.getBoundingClientRect().height,i=t&&t.width?t.width/27:7,n=t&&t.height?t.height:e,s.remove()}),{lineHeight:e,charWidth:i,textHeight:n}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let s=n==e.viewports.length?null:e.viewports[n],r=s?s.from-1:this.view.state.doc.length;if(r>i){let n=(e.lineBlockAt(r).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(Te.replace({widget:new En(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,r))}if(!s)break;i=s.to+1}return Te.set(t)}updateDeco(){let t=1,e=this.view.state.facet($i).map(e=>(this.dynamicDecorationMap[t++]="function"==typeof e)?e(this.view):e),i=!1,n=this.view.state.facet(ji).map((t,e)=>{let n="function"==typeof t;return n&&(i=!0),n?t(this.view):t});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(It.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t"function"==typeof t?t(this.view):t)}scrollIntoView(t){if(t.isSnapshot){let e=this.view.viewState.lineBlockAt(t.range.head);return this.view.scrollDOM.scrollTop=e.top-t.yMargin,void(this.view.scrollDOM.scrollLeft=t.xMargin)}for(let e of this.view.state.facet(Li))try{if(e(this.view,t.range,t))return!0}catch(t){Hi(this.view.state,t,"scroll handler")}let e,{range:i}=t,n=this.coordsAt(i.head,i.assoc||(i.head>i.anchor?-1:1));if(!n)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,e.left),top:Math.min(n.top,e.top),right:Math.max(n.right,e.right),bottom:Math.max(n.bottom,e.bottom)});let s=Zi(this.view),r={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom},{offsetWidth:o,offsetHeight:l}=this.view.scrollDOM;if(function(t,e,i,n,s,r,o,l){let a=t.ownerDocument,h=a.defaultView||window;for(let c=t,u=!1;c&&!u;)if(1==c.nodeType){let t,f=c==a.body,d=1,p=1;if(f)t=Qe(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(u=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let e=c.getBoundingClientRect();({scaleX:d,scaleY:p}=$e(c,e)),t={left:e.left,right:e.left+c.clientWidth*d,top:e.top,bottom:e.top+c.clientHeight*p}}let m=0,g=0;if("nearest"==s)e.top0&&e.bottom>t.bottom+g&&(g=e.bottom-t.bottom+o)):e.bottom>t.bottom-o&&(g=e.bottom-t.bottom+o,i<0&&e.top-g0&&e.right>t.right+m&&(m=e.right-t.right+r)):e.right>t.right-r&&(m=e.right-t.right+r,i<0&&e.leftt.bottom||e.leftt.right)&&(e={left:Math.max(e.left,t.left),right:Math.min(e.right,t.right),top:Math.max(e.top,t.top),bottom:Math.min(e.bottom,t.bottom)}),c=c.assignedSlot||c.parentNode}else{if(11!=c.nodeType)break;c=c.host}}(this.view.scrollDOM,r,i.head1&&(n.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||n.bottomt.isWidget()||t.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){Dn(this.tile)}}function Dn(t,e){let i=null==e?void 0:e.get(t);if(1!=i){null==i&&t.destroy();for(let i of t.children)Dn(i,e)}}function Rn(t,e){let i=t.observer.selectionRange;if(!i.focusNode)return null;let n=ei(i.focusNode,i.focusOffset),s=ii(i.focusNode,i.focusOffset),r=n||s;if(s&&n&&s.node!=n.node){let e=rn.get(s.node);if(!e||e.isText()&&e.text!=s.node.nodeValue)r=s;else if(t.docView.lastCompositionAfterCursor){let t=rn.get(n.node);!t||t.isText()&&t.text!=n.node.nodeValue||(r=s)}}if(t.docView.lastCompositionAfterCursor=r!=n,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}let Pn=class{constructor(){this.changes=[]}compareRange(t,e){Ee(t,e,this.changes)}comparePoint(t,e){Ee(t,e,this.changes)}boundChange(t){Ee(t,t,this.changes)}};class Bn{constructor(){this.changes=[]}compareRange(t,e){Ee(t,e,this.changes)}comparePoint(){}boundChange(t){Ee(t,t,this.changes)}}class En extends Me{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Ln(t,e,i){let n=t.lineBlockAt(e);if(Array.isArray(n.type)){let t;for(let s of n.type){if(s.from>e)break;if(!(s.toe)return s;t&&(s.type!=Oe.Text||t.type==s.type&&!(i<0?s.frome))||(t=s)}}return t||n}return n}function In(t,e,i,n){let s=t.state.doc.lineAt(e.head),r=t.bidiSpans(s),o=t.textDirectionAt(s.from);for(let l=e,a=null;;){let e=xi(s,r,o,l,i),h=yi;if(!e){if(s.number==(i?t.state.doc.lines:1))return l;h="\n",s=t.state.doc.line(s.number+(i?1:-1)),r=t.bidiSpans(s),e=t.visualLineSide(s,!i)}if(a){if(!a(h))return l}else{if(!n)return e;a=n(h)}l=e}}function Nn(t,e,i){for(;;){let n=0;for(let s of t)s.between(e-1,e+1,(t,s,r)=>{if(e>t&&ee(t)),i.from,e.head>i.from?-1:1);return n==i.from?i:W.cursor(n,nt.viewState.docHeight)return new Vn(t.state.doc.length,-1);if(s=t.elementAtHeight(h),null==n)break;if(s.type==Oe.Text){if(n<0?s.tot.viewport.to)break;let e=t.docView.coordsAt(n<0?s.from:s.to,n>0?-1:1);if(e&&(n<0?e.top<=h+o:e.bottom>=h+o))break}let e=t.viewState.heightOracle.textHeight/2;h=n>0?s.bottom+e:s.top-e}if(t.viewport.from>=s.to||t.viewport.to<=s.from){if(i)return null;if(s.type==Oe.Text){let e=function(t,e,i,n,s){let r=Math.round((n-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&i.height>1.5*t.defaultLineHeight){let e=t.viewState.heightOracle.textHeight;r+=Math.floor((s-i.top-.5*(t.defaultLineHeight-e))/e)*t.viewState.heightOracle.lineLength}let o=t.state.sliceDoc(i.from,i.to);return i.from+jt(o,r,t.state.tabSize)}(t,r,s,l,a);return new Vn(e,e==s.from?1:-1)}}if(s.type!=Oe.Text)return h<(s.top+s.bottom)/2?new Vn(s.from,1):new Vn(s.to,-1);let c=t.docView.lineAt(s.from,2);return c&&c.length==s.length||(c=t.docView.lineAt(s.from,-2)),new Fn(t,l,a,t.textDirectionAt(s.from)).scanTile(c,s.from)}class Fn{constructor(t,e,i,n){this.view=t,this.x=e,this.y=i,this.baseDir=n,this.line=null,this.spans=null}bidiSpansAt(t){return(!this.line||this.line.from>t||this.line.to1||i.length&&(i[0].level!=this.baseDir||i[0].to+n.from>1;e:if(a.has(f)){let t=o+Math.floor(Math.random()*i);for(let e=0;e1)){if(i.bottomthis.y)(!s||s.top>i.top)&&(s=i),a=-1;else{let t=i.left>this.x?this.x-i.left:i.right(i+i+o)/3)return this.y=n.bottom-1,this.scan(t,e,!0);if(s&&s.top<(i+o+o)/3)return this.y=s.top+1,this.scan(t,e,!0)}let f=(h?this.dirAt(t[c],1):this.baseDir)==si.LTR;return{i:c,after:this.x>(r.left+r.right)/2==f}}scanText(t,e){let i=[];for(let n=0;n{let s=i[n]-e,r=i[n+1]-e;return Je(t.dom,s,r).getClientRects()});return n.after?new Vn(i[n.i+1],-1):new Vn(i[n.i],1)}scanTile(t,e){if(!t.length)return new Vn(e,1);if(1==t.children.length){let i=t.children[0];if(i.isText())return this.scanText(i,e);if(i.isComposite())return this.scanTile(i,e)}let i=[e];for(let n=0,s=e;n{let i=t.children[e];return 48&i.flags?null:(1==i.dom.nodeType?i.dom:Je(i.dom,0,i.length)).getClientRects()}),s=t.children[n.i],r=i[n.i];return s.isText()?this.scanText(s,r):s.isComposite()?this.scanTile(s,r):n.after?new Vn(i[n.i+1],-1):new Vn(r,1)}}const qn="￿";class _n{constructor(t,e){this.points=t,this.view=e,this.text="",this.lineSeparator=e.state.facet(Tt.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=qn}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let n=t;;){this.findPointBefore(i,n);let t=this.text.length;this.readNode(n);let s=rn.get(n),r=n.nextSibling;if(r==e){(null==s?void 0:s.breakAfter)&&!r&&i!=this.view.contentDOM&&this.lineBreak();break}let o=rn.get(r);(s&&o?s.breakAfter:(s?s.breakAfter:Fe(n))||Fe(r)&&("BR"!=n.nodeName||(null==s?void 0:s.isWidget()))&&this.text.length>t)&&!Qn(r,e)&&this.lineBreak(),n=r}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let s,r=-1,o=1;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(s=n.exec(e))&&(r=s.index,o=s[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=o-1);i=r+o}}readNode(t){let e=rn.get(t),i=e&&e.overrideDOMText;if(null!=i){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;)t.lineBreak?this.lineBreak():this.append(t.value)}else 3==t.nodeType?this.readTextNode(t):"BR"==t.nodeName?t.nextSibling&&this.lineBreak():1==t.nodeType&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(3==t.nodeType?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(Un(t,i.node,i.offset)?e:0))}}function Un(t,e,i){for(;;){if(!e||i<_e(e))return!1;if(e==t)return!0;i=ze(e)+1,e=e.parentNode}}function Qn(t,e){let i;for(;t!=e&&t;t=t.nextSibling){let e=rn.get(t);if(!(null==e?void 0:e.isWidget()))return!1;e&&(i||(i=[])).push(e)}if(i)for(let t of i){let e=t.overrideDOMText;if(null==e?void 0:e.length)return!1}return!0}class $n{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class Kn{constructor(t,e,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:s,impreciseAnchor:r}=t.docView,o=t.state.selection;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=jn(t.docView.tile,e,i,0))){let e=s||r?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}=t.observer.selectionRange;i&&(e.push(new $n(i,n)),s==i&&r==n||e.push(new $n(s,r)));return e}(t),i=new _n(e,t);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(t,e){if(0==t.length)return null;let i=t[0].pos,n=2==t.length?t[1].pos:i;return i>-1&&n>-1?W.single(i+e,n+e):null}(e,this.bounds.from)}else{let e=t.observer.selectionRange,i=s&&s.node==e.focusNode&&s.offset==e.focusOffset||!Ne(t.contentDOM,e.focusNode)?o.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),n=r&&r.node==e.anchorNode&&r.offset==e.anchorOffset||!Ne(t.contentDOM,e.anchorNode)?o.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset),l=t.viewport;if((ye.ios||ye.chrome)&&i!=n&&Math.min(i,n)<=o.main.from&&Math.max(i,n)>=o.main.to&&(l.from>0||l.to-1&&o.ranges.length>1)this.newSel=o.replaceRange(W.range(n,i));else if(t.lineWrapping&&n==i&&(!o.main.empty||o.main.head!=i)&&t.inputState.lastTouchTime>Date.now()-100){let e=t.coordsAtPos(i,-1),n=0;e&&(n=t.inputState.lastTouchY<=e.bottom?-1:1),this.newSel=W.create([W.cursor(i,n)])}else this.newSel=W.single(n,i)}}}function jn(t,e,i,n){if(t.isComposite()){let s=-1,r=-1,o=-1,l=-1;for(let a=0,h=n,c=n;ai)return jn(n,e,i,h);if(u>=e&&-1==s&&(s=a,r=h),h>i&&n.dom.parentNode==t.dom){o=a,l=c;break}c=u,h=u+n.breakAfter}return{from:r,to:l<0?n+t.length:l,startDOM:(s?t.children[s-1].dom.nextSibling:null)||t.dom.firstChild,endDOM:o=0?t.children[o].dom:null}}return t.isText()?{from:n,to:n+t.length,startDOM:t.dom,endDOM:t.dom.nextSibling}:null}function Xn(t,e){let i,{newSel:n}=e,{state:s}=t,r=s.selection.main,o=t.inputState.lastKeyTime>Date.now()-100?t.inputState.lastKeyCode:-1;if(e.bounds){let{from:t,to:n}=e.bounds,l=r.from,a=null;(8===o||ye.android&&e.text.length=t&&r.to<=n&&(e.typeOver||u!=e.text)&&u.slice(0,r.from-t)==e.text.slice(0,r.from-t)&&u.slice(r.to-t)==e.text.slice(h=e.text.length-(u.length-(r.to-t)))?i={from:r.from,to:r.to,insert:f.of(e.text.slice(r.from-t,h).split(qn))}:(c=Yn(u,e.text,l-t,a))&&(ye.chrome&&13==o&&c.toB==c.from+2&&e.text.slice(c.from,c.toB)==qn+qn&&c.toB--,i={from:t+c.from,to:t+c.toA,insert:f.of(e.text.slice(c.from,c.toB).split(qn))})}else n&&(!t.hasFocus&&s.facet(Vi)||Jn(n,r))&&(n=null);if(!i&&!n)return!1;if((ye.mac||ye.android)&&i&&i.from==i.to&&i.from==r.head-1&&/^\. ?$/.test(i.insert.toString())&&"off"==t.contentDOM.getAttribute("autocorrect")?(n&&2==i.insert.length&&(n=W.single(n.main.anchor-1,n.main.head-1)),i={from:i.from,to:i.to,insert:f.of([i.insert.toString().replace("."," ")])}):s.doc.lineAt(r.from).toDate.now()-50?i={from:r.from,to:r.to,insert:s.toText(t.inputState.insertingText)}:ye.chrome&&i&&i.from==i.to&&i.from==r.head&&"\n "==i.insert.toString()&&t.lineWrapping&&(n&&(n=W.single(n.main.anchor-1,n.main.head-1)),i={from:r.from,to:r.to,insert:f.of([" "])}),i)return Gn(t,i,n,o);if(n&&!Jn(n,r)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin,"select.pointer"==i&&(n=Wn(s.facet(Xi).map(e=>e(t)),n))),t.dispatch({selection:n,scrollIntoView:e,userEvent:i}),!0}return!1}function Gn(t,e,i,n=-1){if(ye.ios&&t.inputState.flushIOSKey(e))return!0;let s=t.state.selection.main;if(ye.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&" "==t.state.sliceDoc(e.from,s.from))&&1==e.insert.length&&2==e.insert.lines&&Ze(t.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&0==e.insert.length||8==n&&e.insert.lengths.head)&&Ze(t.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&0==e.insert.length&&Ze(t.contentDOM,"Delete",46)))return!0;let r,o=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let l=()=>r||(r=function(t,e,i){let n,s=t.state,r=s.selection.main,o=-1;if(e.from==e.to&&e.fromr.to){let i=e.frome(t)),n,i);e.from==l&&(o=l)}if(o>-1)n={changes:e,selection:W.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=r.frome.to?s.sliceDoc(e.to,r.to):"";n=s.replaceSelection(t.state.toText(i+e.insert.sliceString(0,void 0,t.state.lineBreak)+o))}else{let o=s.changes(e),l=i&&i.main.to<=o.newLength?i.main:void 0;if(s.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let a,h=t.state.sliceDoc(e.from,e.to),c=i&&Rn(t,i.main.head);if(c){let t=e.insert.length-(e.to-e.from);a={from:c.from,to:c.to-t}}else a=t.state.doc.lineAt(r.head);let u=r.to-e.to;n=s.changeByRange(i=>{if(i.from==r.from&&i.to==r.to)return{changes:o,range:l||i.map(o)};let n=i.to-u,c=n-h.length;if(t.state.sliceDoc(c,n)!=h||n>=a.from&&c<=a.to)return{range:i};let f=s.changes({from:c,to:n,insert:e.insert}),d=i.to-r.to;return{changes:f,range:l?W.range(Math.max(0,l.anchor+d),Math.max(0,l.head+d)):i.map(f)}})}else n={changes:o,selection:l&&s.selection.replaceRange(l)}}let l="input.type";(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,l+=".compose",t.inputState.compositionFirstChange&&(l+=".start",t.inputState.compositionFirstChange=!1));return s.update(n,{userEvent:l,scrollIntoView:!0})}(t,e,i));return t.state.facet(Ti).some(i=>i(t,e.from,e.to,o,l))||t.dispatch(l()),!0}function Yn(t,e,i,n){let s=Math.min(t.length,e.length),r=0;for(;r0&&l>0&&t.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if("end"==n){i-=o+Math.max(0,r-Math.min(o,l))-r}if(o=o?r-i:0,l=r+(l-o),o=r}else if(l=l?r-i:0,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function Jn(t,e){return e.head==t.main.head&&e.anchor==t.main.anchor}class Zn{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,ye.safari&&t.contentDOM.addEventListener("input",()=>null),ye.gecko&&function(t){Ss.has(t)||(Ss.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}(t.contentDOM.ownerDocument)}handleEvent(t){(function(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,n=e.target;n!=t.contentDOM;n=n.parentNode)if(!n||11==n.nodeType||(i=rn.get(n))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0})(this.view,t)&&!this.ignoreDuringComposition(t)&&("keydown"==t.type&&this.keydown(t)||(0!=this.view.updateState?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t)))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=es(t),i=this.handlers,n=this.view.contentDOM;for(let t in e)if("scroll"!=t){let s=!e[t].handlers.length,r=i[t];r&&s!=!r.handlers.length&&(n.removeEventListener(t,this.handleEvent),r=null),r||n.addEventListener(t,this.handleEvent,{passive:s})}for(let t in i)"scroll"==t||e[t]||n.removeEventListener(t,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=t.keyCode&&ss.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),ye.android&&ye.chrome&&!t.synthetic&&(13==t.keyCode||8==t.keyCode))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;if(ye.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&(is.some(e=>e.keyCode==t.keyCode)&&!t.ctrlKey||ns.indexOf(t.key)>-1&&t.ctrlKey)){let i={ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey,shiftKey:t.shiftKey};return i.shiftKey&&ye.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&((e=this.view.win).visualViewport&&e.visualViewport.height*e.visualViewport.scale/e.document.documentElement.clientHeight<.85)&&(i.shiftKey=!1),this.pendingIOSKey={key:t.key,keyCode:t.keyCode,mods:i},setTimeout(()=>this.flushIOSKey(),250),!0}var e;return 229!=t.keyCode&&this.view.observer.forceFlush(),!1}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(!("Enter"==e.key&&t&&t.from0||!!(ye.safari&&!ye.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function ts(t,e){return(i,n)=>{try{return e.call(t,n,i)}catch(t){Hi(i.state,t)}}}function es(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let e of t){let t=e.spec,n=t&&t.plugin.domEventHandlers,s=t&&t.plugin.domEventObservers;if(n)for(let t in n){let s=n[t];s&&i(t).handlers.push(ts(e.value,s))}if(s)for(let t in s){let n=s[t];n&&i(t).observers.push(ts(e.value,n))}}for(let t in ls)i(t).handlers.push(ls[t]);for(let t in as)i(t).observers.push(as[t]);return e}const is=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],ns="dthko",ss=[16,17,18,20,91,92,224,225];function rs(t){return.7*Math.max(0,t)+8}class os{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=Ke(t.contentDOM),this.atoms=t.state.facet(Xi).map(e=>e(t));let s=t.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(Tt.allowMultipleSelections)&&function(t,e){let i=t.state.facet(Si);return i.length?i[0](e):ye.mac?e.metaKey:e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let n=Ie(t.root);if(!n||0==n.rangeCount)return!0;let s=n.getRangeAt(0).getClientRects();for(let t=0;t=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}(t,e)||1!=vs(e))&&null}start(t){!1===this.dragging&&this.select(t)}move(t){if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(e=this.startEvent,i=t,Math.max(Math.abs(e.clientX-i.clientX),Math.abs(e.clientY-i.clientY))<10))return;var e,i;this.select(this.lastEvent=t);let n=0,s=0,r=0,o=0,l=this.view.win.innerWidth,a=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:o,bottom:a}=this.scrollParents.y.getBoundingClientRect());let h=Zi(this.view);t.clientX-h.left<=r+6?n=-rs(r-t.clientX):t.clientX+h.right>=l-6&&(n=rs(t.clientX-l)),t.clientY-h.top<=o+6?s=-rs(o-t.clientY):t.clientY+h.bottom>=a-6&&(s=rs(t.clientY-a)),this.setScrollSpeed(n,s)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),!1===this.dragging&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=Wn(this.atoms,this.style.get(t,this.extend,this.multiple));!this.mustSelect&&i.eq(e.state.selection,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}const ls=Object.create(null),as=Object.create(null),hs=ye.ie&&ye.ie_version<15||ye.ios&&ye.webkit_version<604;function cs(t,e,i){for(let n of t.facet(e))i=n(i,t);return i}function us(t,e){e=cs(t.state,Ri,e);let i,{state:n}=t,s=1,r=n.toText(e),o=r.lines==n.selection.ranges.length;if(null!=bs&&n.selection.ranges.every(t=>t.empty)&&bs==r.toString()){let t=-1;i=n.changeByRange(i=>{let l=n.doc.lineAt(i.from);if(l.from==t)return{range:i};t=l.from;let a=n.toText((o?r.line(s++).text:e)+n.lineBreak);return{changes:{from:l.from,insert:a},range:W.cursor(i.from+a.length)}})}else i=o?n.changeByRange(t=>{let e=r.line(s++);return{changes:{from:t.from,to:t.to,insert:e.text},range:W.cursor(t.from+e.length)}}):n.replaceSelection(r);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function fs(t,e,i,n){if(1==n)return W.cursor(e,i);if(2==n)return function(t,e,i=1){let n=t.charCategorizer(e),s=t.doc.lineAt(e),r=e-s.from;if(0==s.length)return W.cursor(e);0==r?i=1:r==s.length&&(i=-1);let o=r,l=r;i<0?o=k(s.text,r,!1):l=k(s.text,r);let a=n(s.text.slice(o,l));for(;o>0;){let t=k(s.text,o,!1);if(n(s.text.slice(t,o))!=a)break;o=t}for(;l{let e=t.inputState;e.lastScrollTop=t.scrollDOM.scrollTop,e.lastScrollLeft=t.scrollDOM.scrollLeft,ye.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())},as.wheel=as.mousewheel=t=>{t.inputState.lastWheelEvent=Date.now()},ls.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),27==e.keyCode&&0!=t.inputState.tabFocusMode&&(t.inputState.tabFocusMode=Date.now()+2e3),!1),as.touchstart=(t,e)=>{let i=t.inputState,n=e.targetTouches[0];i.touchActive=!0,i.lastTouchTime=Date.now(),n&&(i.lastTouchX=n.clientX,i.lastTouchY=n.clientY),i.setSelectionOrigin("select.pointer")},as.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},as.touchend=(t,e)=>{t.inputState.touchActive=!1},ls.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let n of t.state.facet(Ai))if(i=n(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),n=vs(e),s=t.state.selection;return{update(t){t.docChanged&&(i.pos=t.changes.mapPos(i.pos),s=s.map(t.changes))},get(e,r,o){let l,a=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),h=fs(t,a.pos,a.assoc,n);if(i.pos!=a.pos&&!r){let e=fs(t,i.pos,i.assoc,n),s=Math.min(e.from,h.from),r=Math.max(e.to,h.to);h=s1&&(l=function(t,e){for(let i=0;i=e)return W.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}(s,a.pos))?l:o?s.addRange(h):W.create([h])}}}(t,e)),i){let n=!t.hasFocus;t.inputState.startMouseSelection(new os(t,e,i,n)),n&&t.observer.ignore(()=>{Ye(t.contentDOM);let e=t.root.activeElement;e&&!e.contains(t.contentDOM)&&e.blur()});let s=t.inputState.mouseSelection;if(s)return s.start(e),!1===s.dragging}else t.inputState.setSelectionOrigin("select.pointer");return!1};const ds=ye.ie&&ye.ie_version<=11;let ps=null,ms=0,gs=0;function vs(t){if(!ds)return t.detail;let e=ps,i=gs;return ps=t,gs=Date.now(),ms=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(ms+1)%3:1}function ws(t,e,i,n){if(!(i=cs(t.state,Ri,i)))return;let s=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=t.inputState,o=n&&r&&function(t,e){let i=t.state.facet(Ci);return i.length?i[0](e):ye.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:r.from,to:r.to}:null,l={from:s,insert:i},a=t.state.changes(o?[o,l]:l);t.focus(),t.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),t.inputState.draggedContent=null}ls.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let n=t.docView.tile.nearest(e.target);if(n&&n.isWidget()){let t=n.posAtStart,e=t+n.length;(t>=i.to||e<=i.from)&&(i=W.undirectionalRange(t,e))}}let{inputState:n}=t;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",cs(t.state,Pi,t.state.sliceDoc(i.from,i.to))),e.dataTransfer.effectAllowed="copyMove"),!1},ls.dragend=t=>(t.inputState.draggedContent=null,!1),ls.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let n=Array(i.length),s=0,r=()=>{++s==i.length&&ws(t,e,n.filter(t=>null!=t).join(t.state.lineBreak),!1)};for(let t=0;t{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(n[t]=e.result),r()},e.readAsText(i[t])}return!0}{let i=e.dataTransfer.getData("Text");if(i)return ws(t,e,i,!0),!0}return!1},ls.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=hs?null:e.clipboardData;return i?(us(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{t.focus(),i.remove(),us(t,i.value)},50)}(t),!1)};let bs=null;ls.copy=ls.cut=(t,e)=>{if(!We(t.contentDOM,t.observer.selectionRange))return!1;let{text:i,ranges:n,linewise:s}=function(t){let e=[],i=[],n=!1;for(let n of t.selection.ranges)n.empty||(e.push(t.sliceDoc(n.from,n.to)),i.push(n));if(!e.length){let s=-1;for(let{from:n}of t.selection.ranges){let r=t.doc.lineAt(n);r.number>s&&(e.push(r.text),i.push({from:r.from,to:Math.min(t.doc.length,r.to+1)})),s=r.number}n=!0}return{text:cs(t,Pi,e.join(t.lineBreak)),ranges:i,linewise:n}}(t.state);if(!i&&!s)return!1;bs=s?i:null,"cut"!=e.type||t.state.readOnly||t.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let r=hs?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",i),!0):(function(t,e){let i=t.dom.parentNode;if(!i)return;let n=i.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),t.focus()},50)}(t,i),!1)};const ys=dt.define();function xs(t,e){let i=[];for(let n of t.facet(Di)){let s=n(t,e);s&&i.push(s)}return i.length?t.update({effects:i,annotations:ys.of(!0)}):null}function ks(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=xs(t.state,e);i?t.dispatch(i):t.update([])}},10)}as.focus=t=>{t.inputState.lastFocusTime=Date.now(),t.scrollDOM.scrollTop||!t.inputState.lastScrollTop&&!t.inputState.lastScrollLeft||(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),ks(t)},as.blur=t=>{t.observer.clearSelectionRange(),ks(t)},as.compositionstart=as.compositionupdate=t=>{t.observer.editContext||(null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0))},as.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,ye.chrome&&ye.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))},as.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},ls.beforeinput=(t,e)=>{var i,n;if("insertText"!=e.inputType&&"insertCompositionText"!=e.inputType||(t.inputState.insertingText=e.data,t.inputState.insertingTextAt=Date.now()),"insertReplacementText"==e.inputType&&t.observer.editContext){let n=null===(i=e.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),s=e.getTargetRanges();if(n&&s.length){let e=s[0],i=t.posAtDOM(e.startContainer,e.startOffset),r=t.posAtDOM(e.endContainer,e.endOffset);return Gn(t,{from:i,to:r,insert:t.state.toText(n)},null),!0}}let s;if(ye.chrome&&ye.android&&(s=is.find(t=>t.inputType==e.inputType))&&(t.observer.delayAndroidKey(s.key,s.keyCode),"Backspace"==s.key||"Delete"==s.key)){let e=(null===(n=window.visualViewport)||void 0===n?void 0:n.height)||0;setTimeout(()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return ye.ios&&"deleteContentForward"==e.inputType&&t.observer.flushSoon(),ye.safari&&"insertText"==e.inputType&&t.inputState.composing>=0&&setTimeout(()=>as.compositionend(t,e),20),!1};const Ss=new Set;const Cs=["pre-wrap","normal","pre-line","break-spaces"];let As=!1;function Ms(){As=!1}class Os{constructor(t){this.lineWrapping=t,this.doc=f.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Cs.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i-1,l=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=s,l){this.heightSamples={};for(let t=0;t0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>Ps&&(As=!0),this.height=t)}replace(t,e,i){return Bs.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let s=this,r=i.doc;for(let o=n.length-1;o>=0;o--){let{fromA:l,toA:a,fromB:h,toB:c}=n[o],u=s.lineAt(l,Rs.ByPosNoHeight,i.setDoc(e),0,0),f=u.to>=a?u:s.lineAt(a,Rs.ByPosNoHeight,i,0,0);for(c+=f.to-a,a=f.to;o>0&&u.from<=n[o-1].toA;)l=n[o-1].fromA,h=n[o-1].fromB,o--,l2*s){let s=t[e-1];s.break?t.splice(--e,1,s.left,null,s.right):t.splice(--e,1,s.left,s.right),i+=1+s.break,n-=s.size}else{if(!(s>2*n))break;{let e=t[i];e.break?t.splice(i,1,e.left,null,e.right):t.splice(i,1,e.left,e.right),i+=2+e.break,s-=e.size}}else if(n=s&&r(this.lineAt(0,Rs.ByPos,i,n,s))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setMeasuredHeight(n),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ns extends Is{constructor(t,e,i){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(t,e){return new Ds(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let n=i[0];return 1==i.length&&(n instanceof Ns||n instanceof Ws&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof Ws?n=new Ns(n.length,this.height,this.spaceAbove):n.height=this.height,this.outdated||(n.outdated=!1),n):Bs.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setMeasuredHeight(n):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Ws extends Bs{constructor(t){super(t,0)}heightMetrics(t,e){let i,n=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-n+1,o=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*r);i=e/r,this.length>r+1&&(o=(this.height-e)/(this.length-r-1))}else i=this.height/r;return{firstLine:n,lastLine:s,perLine:i,perChar:o}}blockAt(t,e,i,n){let{firstLine:s,lastLine:r,perLine:o,perChar:l}=this.heightMetrics(e,n);if(e.lineWrapping){let s=n+(t0){let t=i[i.length-1];t instanceof Ws?i[i.length-1]=new Ws(t.length+n):i.push(null,new Ws(n-1))}if(t>0){let e=i[0];e instanceof Ws?i[0]=new Ws(t+e.length):i.unshift(new Ws(t-1),null)}return Bs.of(i)}decomposeLeft(t,e){e.push(new Ws(t-1),null)}decomposeRight(t,e){e.push(null,new Ws(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let s=e+this.length;if(n&&n.from<=e+this.length&&n.more){let i=[],r=Math.max(e,n.from),o=-1;for(n.from>e&&i.push(new Ws(n.from-e-1).updateHeight(t,e));r<=s&&n.more;){let e=t.doc.lineAt(r).length;i.length&&i.push(null);let s=n.heights[n.index++],l=0;s<0&&(l=-s,s=n.heights[n.index++]),-1==o?o=s:Math.abs(s-o)>=Ps&&(o=-2);let a=new Ns(e,s,l);a.outdated=!1,i.push(a),r+=e+1}r<=s&&i.push(null,new Ws(s-r).updateHeight(t,r));let l=Bs.of(i);return(o<0||Math.abs(l.height-this.height)>=Ps||Math.abs(o-this.heightMetrics(t,e).perLine)>=Ps)&&(As=!0),Es(this,l)}return(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class Hs extends Bs{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return 1&this.flags}blockAt(t,e,i,n){let s=i+this.left.height;return to))return a;let h=e==Rs.ByPosNoHeight?Rs.ByPosNoHeight:Rs.ByPos;return l?a.join(this.right.lineAt(o,h,i,r,o)):this.left.lineAt(o,h,i,n,s).join(a)}forEachLine(t,e,i,n,s,r){let o=n+this.left.height,l=s+this.left.length+this.break;if(this.break)t=l&&this.right.forEachLine(t,e,i,o,l,r);else{let a=this.lineAt(l,Rs.ByPos,i,n,s);t=t&&a.from<=e&&r(a),e>a.to&&this.right.forEachLine(a.to+1,e,i,o,l,r)}}replace(t,e,i){let n=this.left.length+this.break;if(ethis.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let s=[];t>0&&this.decomposeLeft(t,s);let r=s.length;for(let t of i)s.push(t);if(t>0&&Vs(s,r-1),e=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t2*e.size||e.size>2*t.size?Bs.of(this.break?[t,null,e]:[t,e]):(this.left=Es(this.left,t),this.right=Es(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:s,right:r}=this,o=e+s.length+this.break,l=null;return n&&n.from<=e+s.length&&n.more?l=s=s.updateHeight(t,e,i,n):s.updateHeight(t,e,i),n&&n.from<=o+r.length&&n.more?l=r=r.updateHeight(t,o,i,n):r.updateHeight(t,o,i),l?this.balanced(s,r):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Vs(t,e){let i,n;null==t[e]&&(i=t[e-1])instanceof Ws&&(n=t[e+1])instanceof Ws&&t.splice(e-1,3,new Ws(i.length+1+n.length))}class zs{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof Ns?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new Ns(t-this.pos,-1,0)),this.writtenTo=t,e>t&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t=5)&&this.addLineDeco(n,s,r)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTot&&this.nodes.push(new Ns(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new Ws(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof Ns)return t;let e=new Ns(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof Ns||this.isCovered?(this.writtenToi.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=n.overflow){let n=i.getBoundingClientRect();r=Math.max(r,n.left),o=Math.min(o,n.right),l=Math.max(l,n.top),a=Math.min(e==t.parentNode?s.innerHeight:a,n.bottom)}e="absolute"==n.position||"fixed"==n.position?i.offsetParent:i.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:r-i.left,right:Math.max(r,o)-i.left,top:l-(i.top+e),bottom:Math.max(l,a)-(i.top+e)}}function _s(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class Us{constructor(t,e,i,n){this.from=t,this.to=e,this.size=i,this.displaySize=n}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i"function"!=typeof t&&"cm-lineWrapping"==t.class);this.heightOracle=new Os(i),this.stateDeco=Ys(e),this.heightMap=Bs.empty().applyChanges(this.stateDeco,f.empty,this.heightOracle.setDoc(e.doc),[new en(0,0,0,e.doc.length)]);for(let t=0;t<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());t++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Te.set(this.lineGaps.map(t=>t.draw(this,!1))),this.scrollParent=t.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:t,to:e})=>n>=t&&n<=e)){let{from:e,to:i}=this.lineBlockAt(n);t.push(new Ks(e,i))}}return this.viewports=t.sort((t,e)=>t.from-e.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Gs:new Js(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(Zs(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=Ys(this.state);let n=t.changedRanges,s=en.extendWithRanges(n,function(t,e,i){let n=new Fs;return It.compare(t,e,i,n,0),n.changes}(i,this.stateDeco,t?t.changes:D.empty(this.state.doc.length))),r=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Ms(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=r||As)&&(t.flags|=2),o?(this.scrollAnchorPos=t.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=r);let l=s.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.headl.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,e));let a=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,t.flags|=this.updateForViewport(),(a||!t.changes.empty||2&t.flags)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(Ei)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:t}=this,e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,s=i.whiteSpace;this.defaultTextDirection="rtl"==i.direction?si.RTL:si.LTR;let r=this.heightOracle.mustRefreshForWrapping(s)||"refresh"===this.mustMeasureContent,o=e.getBoundingClientRect(),l=r||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let a=0,h=0;if(o.width&&o.height){let{scaleX:t,scaleY:i}=$e(e,o);(t>.005&&Math.abs(this.scaleX-t)>.005||i>.005&&Math.abs(this.scaleY-i)>.005)&&(this.scaleX=t,this.scaleY=i,a|=16,r=l=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;this.paddingTop==c&&this.paddingBottom==u||(this.paddingTop=c,this.paddingBottom=u,a|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,a|=16);let d=Ke(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=ti(this.scrollParent||t.win);let m=(this.printing?_s:qs)(e,this.paddingTop),g=m.top-this.pixelViewport.top,v=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(l=!0)),!this.inView&&!this.scrollTarget&&!function(t){let e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView||window;return e.left0&&e.top0}(t.dom))return 0;let b=o.width;if(this.contentDOMWidth==b&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=o.width,this.editorHeight=t.scrollDOM.clientHeight,a|=16),l){let e=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(e)&&(r=!0),r||n.lineWrapping&&Math.abs(b-this.contentDOMWidth)>n.charWidth){let{lineHeight:i,charWidth:o,textHeight:l}=t.docView.measureTextSize();r=i>0&&n.refresh(s,i,o,l,Math.max(5,b/o),e),r&&(t.docView.minWidth=0,a|=16)}g>0&&v>0?h=Math.max(g,v):g<0&&v<0&&(h=Math.min(g,v)),Ms();for(let i of this.viewports){let s=i.from==this.viewport.from?e:t.docView.measureVisibleLineHeights(i);this.heightMap=(r?Bs.empty().applyChanges(this.stateDeco,f.empty,this.heightOracle,[new en(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,r,new Ts(i.from,s))}As&&(a|=2)}let y=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return y&&(2&a&&(a|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),a|=this.updateForViewport()),(2&a||y)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(r?[]:this.lineGaps,t)),a|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),a}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,s=this.heightOracle,{visibleTop:r,visibleBottom:o}=this,l=new Ks(n.lineAt(r-1e3*i,Rs.ByHeight,s,0,0).from,n.lineAt(o+1e3*(1-i),Rs.ByHeight,s,0,0).to);if(e){let{head:t}=e.range;if(tl.to){let i,r=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),o=n.lineAt(t,Rs.ByPos,s,0,0);i="center"==e.y?(o.top+o.bottom)/2-r/2:"start"==e.y||"nearest"==e.y&&t=o+Math.max(10,Math.min(i,250)))&&n>r-2e3&&s>1,r=n<<1;if(this.defaultTextDirection!=si.LTR&&!i)return[];let o=[],l=(n,r,a,h)=>{if(r-nn&&tt.from>=a.from&&t.to<=a.to&&Math.abs(t.from-n)t.frome));if(!f){if(rt.from<=r&&t.to>=r)){let t=e.moveToLineBoundary(W.cursor(r),!1,!0).head;t>n&&(r=t)}let t=this.gapSize(a,n,r,h);f=new Us(n,r,t,i||t<2e6?t:2e6)}o.push(f)},a=e=>{if(e.lengths&&(n.push({from:s,to:t}),r+=t-s),s=e}},20),s2e6)for(let i of t)i.from>=e.from&&i.frome.from&&l(e.from,o,e,s),at.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];It.spans(e,this.viewport.from,this.viewport.to,{span(t,e){i.push({from:t,to:e})},point(){}},20);let n=0;if(i.length!=this.visibleRanges.length)n=12;else for(let e=0;e=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Zs(this.heightMap.lineAt(t,Rs.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Zs(this.heightMap.lineAt(this.scaler.fromDOM(t),Rs.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Zs(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Ks{constructor(t,e){this.from=t,this.to=e}}function js({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let n=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:s}=e[t],r=s-i;if(n<=r)return i+n;n-=r}}function Xs(t,e){let i=0;for(let{from:n,to:s}of t.ranges){if(e<=s){i+=e-n;break}i+=s-n}return i/t.total}const Gs={toDOM:t=>t,fromDOM:t=>t,scale:1,eq(t){return t==this}};function Ys(t){let e=t.facet($i).filter(t=>"function"!=typeof t),i=t.facet(ji).filter(t=>"function"!=typeof t);return i.length&&e.push(It.join(i)),e}class Js{constructor(t,e,i){let n=0,s=0,r=0;this.viewports=i.map(({from:i,to:s})=>{let r=e.lineAt(i,Rs.ByPos,t,0,0).top,o=e.lineAt(s,Rs.ByPos,t,0,0).bottom;return n+=o-r,{from:i,to:s,top:r,bottom:o,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);for(let t of this.viewports)t.domTop=r+(t.top-s)*this.scale,r=t.domBottom=t.domTop+(t.bottom-t.top),s=t.bottom}toDOM(t){for(let e=0,i=0,n=0;;e++){let s=ee.from==t.viewports[i].from&&e.to==t.viewports[i].to))}}function Zs(t,e){if(1==e.scale)return t;let i=e.toDOM(t.top),n=e.toDOM(t.bottom);return new Ds(t.from,t.length,i,n-i,Array.isArray(t._content)?t._content.map(t=>Zs(t,e)):t._content)}const tr=z.define({combine:t=>t.join(" ")}),er=z.define({combine:t=>t.indexOf(!0)>-1}),ir=Jt.newName(),nr=Jt.newName(),sr=Jt.newName(),rr={"&light":"."+nr,"&dark":"."+sr};function or(t,e,i){return new Jt(e,{finish:e=>/&/.test(e)?e.replace(/&\w*/,e=>{if("&"==e)return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]}):t+" "+e})}const lr=or("."+ir,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},rr),ar={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},hr=ye.ie&&ye.ie_version<=11;class cr{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new je,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let t of e)this.queue.push(t);(ye.ie&&ye.ie_version<=11||ye.ios&&t.composing)&&e.some(t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length)?this.flushSoon():this.flush()}),!window.EditContext||!ye.android||!1===t.constructor.EDIT_CONTEXT||ye.chrome&&ye.chrome_version<126||(this.editContext=new dr(t),t.state.facet(Vi)&&(t.contentDOM.editContext=this.editContext.editContext)),hr&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver(()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){("change"!=t.type&&t.type||t.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(Vi)?i.root.activeElement!=this.dom:!We(this.dom,n))return;let s=n.anchorNode&&i.docView.tile.nearest(n.anchorNode);s&&s.isWidget()&&s.widget.ignoreEvent(t)?e||(this.selectionChanged=!1):(ye.ie&&ye.ie_version<=11||ye.android&&ye.chrome)&&!i.state.selection.main.empty&&n.focusNode&&Ve(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=Ie(t.root);if(!e)return!1;let i=ye.safari&&11==t.root.nodeType&&t.root.activeElement==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return fr(t,i)}let i=null;function n(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",n,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",n,!0),i?fr(t,i):null}(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=We(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&Ze(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let s of t){let t=this.readMutation(s);t&&(t.typeOver&&(n=!0),-1==e?({from:e,to:i}=t):(e=Math.min(t.from,e),i=Math.max(t.to,i)))}return{from:e,to:i,typeOver:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&We(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new Kn(this.view,t,e,i);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=Xn(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!Jn(this.view.state.selection,e.newSel.main))&&this.view.update([]),n}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty("attributes"==t.type),"childList"==t.type){let i=ur(e,t.previousSibling||t.target.previousSibling,-1),n=ur(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(Vi)!=t.state.facet(Vi)&&(t.view.contentDOM.editContext=t.state.facet(Vi)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function ur(t,e,i){for(;e;){let n=rn.get(e);if(n&&n.parent==t)return n;let s=e.parentNode;e=s!=t.dom?s:i>0?e.nextSibling:e.previousSibling}return null}function fr(t,e){let i=e.startContainer,n=e.startOffset,s=e.endContainer,r=e.endOffset,o=t.docView.domAtPos(t.state.selection.main.anchor,1);return Ve(o.node,o.offset,s,r)&&([i,n,s,r]=[s,r,i,n]),{anchorNode:i,anchorOffset:n,focusNode:s,focusOffset:r}}class dr{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let n=t.state.selection.main,{anchor:s,head:r}=n,o=this.toEditorPos(i.updateRangeStart),l=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:o,drifted:!1});let a=l-o>i.text.length;o==this.from&&sthis.to&&(l=s);let h=Yn(t.state.sliceDoc(o,l),i.text,(a?n.from:n.to)-o,a?"end":null);if(!h){let e=W.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));return void(Jn(e,n)||t.dispatch({selection:e,userEvent:"select"}))}let c={from:h.from+o,to:h.toA+o,insert:f.of(i.text.slice(h.from,h.toB).split("\n"))};if((ye.mac||ye.android)&&c.from==r-1&&/^\. ?$/.test(i.text)&&"off"==t.contentDOM.getAttribute("autocorrect")&&(c={from:o,to:l,insert:f.of([i.text.replace("."," ")])}),this.pendingContextChange=c,!t.state.readOnly){let e=this.to-this.from+(c.to-c.from+c.insert.length);Gn(t,c,W.single(this.toEditorPos(i.selectionStart,e),this.toEditorPos(i.selectionEnd,e)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),c.from=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let n=[],s=null;for(let e=this.toEditorPos(i.rangeStart),r=this.toEditorPos(i.rangeEnd);e{let i=[];for(let t of e.getTextFormats()){let e=t.underlineStyle,n=t.underlineThickness;if(!/none/i.test(e)&&!/none/i.test(n)){let s=this.toEditorPos(t.rangeStart),r=this.toEditorPos(t.rangeEnd);if(s{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:e}=this.composing;this.composing=null,e&&this.reset(t.state)}};for(let t in this.handlers)e.addEventListener(t,this.handlers[t]);this.measureReq={read:t=>{let e=Ie(t.root);e&&e.rangeCount&&this.editContext.updateSelectionBounds(e.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((s,r,o,l,a)=>{if(i)return;let h=a.length-(r-s);if(n&&r>=n.to){if(n.from==s&&n.to==r&&n.insert.eq(a))return n=this.pendingContextChange=null,e+=h,void(this.to+=h);n=null,this.revertPending(t.state)}if(s+=e,(r+=e)<=this.from)this.from+=h,this.to+=h;else if(sthis.to||this.to-this.from+a.length>3e4)return void(i=!0);this.editContext.updateText(this.toContextPos(s),this.toContextPos(r),a.toString()),this.to+=h}e+=h}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(t=>!t.isUserEvent("input.type")&&t.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):this.applyEdits(t)&&this.rangeIsValid(t.state)?(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state):(this.pendingContextChange=null,this.reset(t.state)),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);this.editContext.selectionStart==i&&this.editContext.selectionEnd==n||this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to3e4)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class pr{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(t=>t.forEach(t=>i(t,this)))||(t=>this.update(t)),this.dispatch=this.dispatch.bind(this),this._root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new $s(this,t.state||Tt.create(t)),t.scrollTo&&t.scrollTo.is(Ni)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Fi).map(t=>new _i(t));for(let t of this.plugins)t.update(this);this.observer=new cr(this),this.inputState=new Zn(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Tn(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),(null===(e=document.fonts)||void 0===e?void 0:e.ready)&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...t){let e=1==t.length&&t[0]instanceof vt?t:1==t.length&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,n=!1,s=this.state;for(let e of t){if(e.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=e.state}if(this.destroyed)return void(this.viewState.state=s);let r=this.hasFocus,o=0,l=null;t.some(t=>t.annotation(ys))?(this.inputState.notifiedFocused=r,o=1):r!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=r,l=xs(s,r),l||(o=1));let a=this.observer.delayedAndroidKey,h=null;if(a?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(h=null)):this.observer.clear(),s.facet(Tt.phrases)!=this.state.facet(Tt.phrases))return this.setState(s);e=nn.create(this,s,t),e.flags|=o;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(c&&(c=c.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection,{x:i,y:n}=this.state.facet(pr.cursorScrollMargin);c=new Ii(t.empty?t:W.cursor(t.head,t.head>t.anchor?-1:1),"nearest","nearest",n,i)}for(let t of e.effects)t.is(Ni)&&(c=t.value.clip(this.state))}this.viewState.update(e,c),this.bidiCache=vr.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(tn)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some(t=>t.isUserEvent("select.pointer")))}finally{this.updateState=0}if(e.startState.facet(tr)!=e.state.facet(tr)&&(this.viewState.mustMeasureContent=!0),(i||n||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!e.empty)for(let t of this.state.facet(Oi))try{t(e)}catch(t){Hi(this.state,t,"update listener")}(l||h)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),h&&!Xn(this,h)&&a.force&&Ze(this.contentDOM,a.key,a.keyCode)})}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new $s(this,t),this.plugins=t.facet(Fi).map(t=>new _i(t)),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy(),this.docView=new Tn(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(Fi),i=t.state.facet(Fi);if(e!=i){let n=[];for(let s of i){let i=e.indexOf(s);if(i<0)n.push(new _i(s));else{let e=this.plugins[i];e.mustUpdate=t,n.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.viewState.scrollParent,n=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:r}=this.viewState;Math.abs(n-this.viewState.scrollOffset)>1&&(r=-1),this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(r<0)if(ti(i||this.win))s=-1,r=this.viewState.heightMap.height;else{let t=this.viewState.scrollAnchorAt(n);s=t.from,r=t.top}this.updateState=1;let o=this.viewState.measure();if(!o&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let l=[];4&o||([this.measureRequests,l]=[l,this.measureRequests]);let a=l.map(t=>{try{return t.read(this)}catch(t){return Hi(this.state,t),gr}}),h=nn.create(this,this.state,[]),c=!1;h.flags|=o,e?e.flags|=o:e=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),c=this.docView.update(h),c&&this.docViewUpdate());for(let t=0;t1||t<-1)&&!(ye.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){n+=t,i?i.scrollTop+=t:this.win.scrollBy(0,t),r=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let t of this.state.facet(Oi))t(e)}get themeClasses(){return ir+" "+(this.state.facet(er)?sr:nr)+" "+this.state.facet(tr)}updateAttrs(){let t=wr(this,Ui,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Vi)?"true":"false",class:"cm-content",style:`${ye.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),wr(this,Qi,e);let i=this.observer.ignore(()=>{let i=Ce(this.contentDOM,this.contentAttrs,e),n=Ce(this.dom,this.editorAttrs,t);return i||n});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)if(t.is(pr.announce)){e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(tn);let t=this.state.facet(pr.cspNonce);Jt.mount(this.root,this.styleModules.concat(lr).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(null!=t.key)for(let e=0;ee.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return Hn(this,t,In(this,t,e,i))}moveByGroup(t,e){return Hn(this,t,In(this,t,e,e=>function(t,e,i){let n=t.state.charCategorizer(e),s=n(i);return t=>{let e=n(t);return s==Ct.Space&&(s=e),s==e}}(this,t.head,e)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),s=i[e?i.length-1:0];return W.cursor(s.side(e,n)+t.from,s.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return function(t,e,i,n){let s=Ln(t,e.head,e.assoc||-1),r=n&&s.type==Oe.Text&&(t.lineWrapping||s.widgetLineBreaks)?t.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head):null;if(r){let e=t.dom.getBoundingClientRect(),n=t.textDirectionAt(s.from),o=t.posAtCoords({x:i==(n==si.LTR)?e.right-1:e.left+1,y:(r.top+r.bottom)/2});if(null!=o)return W.cursor(o,i?-1:1)}return W.cursor(i?s.to:s.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return Hn(this,t,function(t,e,i,n){let s=e.head,r=i?1:-1;if(s==(i?t.state.doc.length:0))return W.cursor(s,e.assoc);let o,l=e.goalColumn,a=t.contentDOM.getBoundingClientRect(),h=t.coordsAtPos(s,e.assoc||((e.empty?i:e.head==e.from)?1:-1)),c=t.documentTop;if(h)null==l&&(l=h.left-a.left),o=r<0?h.top:h.bottom;else{let e=t.viewState.lineBlockAt(s);null==l&&(l=Math.min(a.right-a.left,t.defaultCharacterWidth*(s-e.from))),o=(r<0?e.top:e.bottom)+c}let u=a.left+l,f=t.viewState.heightOracle.textHeight>>1,d=null!=n?n:f;for(let e=0;;e+=f){let n=o+(d+e)*r,s=zn(t,{x:u,y:n},!1,r);if(i?n>a.bottom:no:cthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>mr)return bi(t.length);let e,i=this.textDirectionAt(t.from);for(let n of this.bidiCache)if(n.from==t.from&&n.dir==i&&(n.fresh||mi(n.isolates,e=Yi(this,t))))return n.order;e||(e=Yi(this,t));let n=function(t,e,i){if(!t)return[new pi(0,0,e==oi?1:0)];if(e==ri&&!i.length&&!di.test(t))return bi(t.length);if(i.length)for(;t.length>gi.length;)gi[gi.length]=256;let n=[],s=e==ri?0:1;return wi(t,s,s,i,0,t.length,n),n}(t.text,i,e);return this.bidiCache.push(new vr(t.from,t.to,i,e,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||ye.safari&&(null===(t=this.inputState)||void 0===t?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ye(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((9==t.nodeType?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){var i,n,s,r;return Ni.of(new Ii("number"==typeof t?W.cursor(t):t,null!==(i=e.y)&&void 0!==i?i:"nearest",null!==(n=e.x)&&void 0!==n?n:"nearest",null!==(s=e.yMargin)&&void 0!==s?s:5,null!==(r=e.xMargin)&&void 0!==r?r:5))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Ni.of(new Ii(W.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){null==t?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:"boolean"==typeof t?this.inputState.tabFocusMode=t?0:-1:0!=this.inputState.tabFocusMode&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return qi.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return qi.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=Jt.newName(),n=[tr.of(i),tn.of(or(`.${i}`,t))];return e&&e.dark&&n.push(er.of(!0)),n}static baseTheme(t){return Z.lowest(tn.of(or("."+ir,t,rr)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&rn.get(i)||rn.get(t);return(null===(e=null==n?void 0:n.root)||void 0===e?void 0:e.view)||null}}pr.styleModule=tn,pr.inputHandler=Ti,pr.clipboardInputFilter=Ri,pr.clipboardOutputFilter=Pi,pr.scrollHandler=Li,pr.focusChangeEffect=Di,pr.perLineTextDirection=Bi,pr.exceptionSink=Mi,pr.updateListener=Oi,pr.editable=Vi,pr.mouseSelectionStyle=Ai,pr.dragMovesSelection=Ci,pr.clickAddsSelectionRange=Si,pr.decorations=$i,pr.blockWrappers=Ki,pr.outerDecorations=ji,pr.atomicRanges=Xi,pr.bidiIsolatedRanges=Gi,pr.cursorScrollMargin=z.define({combine:t=>{let e=5,i=5;for(let n of t)"number"==typeof n?e=i=n:({x:e,y:i}=n);return{x:e,y:i}}}),pr.scrollMargins=Ji,pr.darkTheme=er,pr.cspNonce=z.define({combine:t=>t.length?t[0]:""}),pr.contentAttributes=Qi,pr.editorAttributes=Ui,pr.lineWrapping=pr.contentAttributes.of({class:"cm-lineWrapping"}),pr.announce=gt.define();const mr=4096,gr={};class vr{constructor(t,e,i,n,s,r){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=s,this.order=r}static update(t,e){if(e.empty&&!t.some(t=>t.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:si.LTR;for(let s=Math.max(0,t.length-10);s=0;s--){let e=n[s],r="function"==typeof e?e(t):e;r&&xe(r,i)}return i}const br=ye.mac?"mac":ye.windows?"win":ye.linux?"linux":"key";function yr(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),!1!==i&&e.shiftKey&&(t="Shift-"+t),t}const xr=Z.default(pr.domEventHandlers({keydown:(t,e)=>Tr(Cr(e.state),t,e,"editor")})),kr=z.define({enables:xr}),Sr=new WeakMap;function Cr(t){let e=t.facet(kr),i=Sr.get(e);return i||Sr.set(e,i=function(t,e=br){let i=Object.create(null),n=Object.create(null),s=(t,e)=>{let i=n[t];if(null==i)n[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")},r=(t,n,r,o,l)=>{var a,h;let c=i[t]||(i[t]=Object.create(null)),u=n.split(/ (?!$)/).map(t=>function(t,e){const i=t.split(/-(?!$)/);let n,s,r,o,l=i[i.length-1];"Space"==l&&(l=" ");for(let t=0;t{let n=Ar={view:e,prefix:i,scope:t};return setTimeout(()=>{Ar==n&&(Ar=null)},Mr),!0}]})}let f=u.join(" ");s(f,!1);let d=c[f]||(c[f]={preventDefault:!1,stopPropagation:!1,run:(null===(h=null===(a=c._any)||void 0===a?void 0:a.run)||void 0===h?void 0:h.slice())||[]});r&&d.run.push(r),o&&(d.preventDefault=!0),l&&(d.stopPropagation=!0)};for(let n of t){let t=n.scope?n.scope.split(" "):["editor"];if(n.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));t._any||(t._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:s}=n;for(let e in t)t[e].run.push(t=>s(t,Or))}let s=n[e]||n.key;if(s)for(let e of t)r(e,s,n.run,n.preventDefault,n.stopPropagation),n.shift&&r(e,"Shift-"+s,n.shift,n.preventDefault,n.stopPropagation)}return i}(e.reduce((t,e)=>t.concat(e),[]))),i}let Ar=null;const Mr=4e3;let Or=null;function Tr(t,e,i,n){Or=e;let s=function(t){var e=!(ne&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||se&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?ie:ee)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(e),r=A(S(s,0))==s.length&&" "!=s,o="",l=!1,a=!1,h=!1;Ar&&Ar.view==i&&Ar.scope==n&&(o=Ar.prefix+" ",ss.indexOf(e.keyCode)<0&&(a=!0,Ar=null));let c,u,f=new Set,d=t=>{if(t){for(let e of t.run)if(!f.has(e)&&(f.add(e),e(i)))return t.stopPropagation&&(h=!0),!0;t.preventDefault&&(t.stopPropagation&&(h=!0),a=!0)}return!1},p=t[n];return p&&(d(p[o+yr(s,e,!r)])?l=!0:!r||!(e.altKey||e.metaKey||e.ctrlKey)||ye.windows&&e.ctrlKey&&e.altKey||ye.mac&&e.altKey&&!e.ctrlKey&&!e.metaKey||!(c=ee[e.keyCode])||c==s?r&&e.shiftKey&&d(p[o+yr(s,e,!0)])&&(l=!0):(d(p[o+yr(c,e,!0)])||e.shiftKey&&(u=ie[e.keyCode])!=s&&u!=c&&d(p[o+yr(u,e,!1)]))&&(l=!0),!l&&d(p._any)&&(l=!0)),a&&(l=!0),l&&h&&e.stopPropagation(),Or=null,l}class Dr{constructor(t,e,i,n,s){this.className=t,this.left=e,this.top=i,this.width=n,this.height=s}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className==this.className&&(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",null!=this.width&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let n=t.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let s=Rr(t);return[new Dr(e,n.left-s.left,n.top-s.top,null,n.bottom-n.top)]}return function(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let n=Math.max(i.from,t.viewport.from),s=Math.min(i.to,t.viewport.to),r=t.textDirection==si.LTR,o=t.contentDOM,l=o.getBoundingClientRect(),a=Rr(t),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),u=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),f=l.right-(c?parseInt(c.paddingRight):0),d=Ln(t,n,1),p=Ln(t,s,-1),m=d.type==Oe.Text?d:null,g=p.type==Oe.Text?p:null;m&&(t.lineWrapping||d.widgetLineBreaks)&&(m=Pr(t,n,1,m));g&&(t.lineWrapping||p.widgetLineBreaks)&&(g=Pr(t,s,-1,g));if(m&&g&&m.from==g.from&&m.to==g.to)return w(b(i.from,i.to,m));{let e=m?b(i.from,null,m):y(d,!1),n=g?b(null,i.to,g):y(p,!0),s=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2h&&n.from=r)break;l>s&&a(Math.max(t,s),null==e&&t<=h,Math.min(l,r),null==i&&l>=c,o.dir)}if(s=n.to+1,s>=r)break}return 0==l.length&&a(h,null==e,c,null==i,t.textDirection),{top:s,bottom:o,horizontal:l}}function y(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(t,e,i)}}function Rr(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==si.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function Pr(t,e,i,n){let s=t.coordsAtPos(e,2*i);if(!s)return n;let r=t.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=t.posAtCoords({x:r.left+1,y:o}),a=t.posAtCoords({x:r.right-1,y:o});return null==l||null==a?n:{from:Math.max(n.from,Math.min(l,a)),to:Math.min(n.to,Math.max(l,a))}}class Br{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(Er)!=t.state.facet(Er)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){!1!==this.layer.updateOnDocViewUpdate&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(Er);for(;e{return i=t,n=this.drawn[e],!(i.constructor==n.constructor&&i.eq(n));var i,n})){let e=this.dom.firstChild,i=0;for(let n of t)n.update&&e&&n.constructor&&this.drawn[i].constructor&&n.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(n.draw(),e);for(;e;){let t=e.nextSibling;e.remove(),e=t}this.drawn=t,ye.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Er=z.define();function Lr(t){return[qi.define(e=>new Br(e,t)),Er.of(t)]}const Ir=z.define({combine:t=>Dt(t,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function Nr(t={}){return[Ir.of(t),Hr,zr,Fr,Ei.of(!0)]}function Wr(t){return t.startState.facet(Ir)!=t.state.facet(Ir)}const Hr=Lr({above:!0,markers(t){let{state:e}=t,i=e.facet(Ir),n=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty||i.drawRangeCursor&&!(r&&ye.ios&&i.iosSelectionHandles)){let e=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=s.empty?s:W.cursor(s.head,s.assoc);for(let s of Dr.forRange(t,e,i))n.push(s)}}return n},update(t,e){t.transactions.some(t=>t.selection)&&(e.style.animationName="cm-blink"==e.style.animationName?"cm-blink2":"cm-blink");let i=Wr(t);return i&&Vr(t.state,e),t.docChanged||t.selectionSet||i},mount(t,e){Vr(e.state,t)},class:"cm-cursorLayer"});function Vr(t,e){e.style.animationDuration=t.facet(Ir).cursorBlinkRate+"ms"}const zr=Lr({above:!1,markers(t){let e=[],{main:i,ranges:n}=t.state.selection;for(let i of n)if(!i.empty)for(let n of Dr.forRange(t,"cm-selectionBackground",i))e.push(n);if(ye.ios&&!i.empty&&t.state.facet(Ir).iosSelectionHandles){for(let n of Dr.forRange(t,"cm-selectionHandle cm-selectionHandle-start",W.cursor(i.from,1)))e.push(n);for(let n of Dr.forRange(t,"cm-selectionHandle cm-selectionHandle-end",W.cursor(i.to,1)))e.push(n)}return e},update:(t,e)=>t.docChanged||t.selectionSet||t.viewportChanged||Wr(t),class:"cm-selectionLayer"}),Fr=Z.highest(pr.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),qr=gt.define({map:(t,e)=>null==t?null:e.mapPos(t)}),_r=K.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce((t,e)=>e.is(qr)?e.value:t,t))}),Ur=qi.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(_r);null==i?null!=this.cursor&&(null===(e=this.cursor)||void 0===e||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(_r)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(_r),i=null!=e&&t.coordsAtPos(e);if(!i)return null;let n=t.scrollDOM.getBoundingClientRect();return{left:i.left-n.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-n.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/i+"px",this.cursor.style.height=t.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(_r)!=t&&this.view.dispatch({effects:qr.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Qr(t,e,i,n,s){e.lastIndex=0;for(let r,o=t.iterRange(i,n),l=i;!o.next().done;l+=o.value.length)if(!o.lineBreak)for(;r=e.exec(o.value);)s(l+r.index,r)}class $r{constructor(t){const{regexp:e,decoration:i,decorate:n,boundary:s,maxLength:r=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,n)this.addMatch=(t,e,i,s)=>n(s,i,i+t[0].length,t,e);else if("function"==typeof i)this.addMatch=(t,e,n,s)=>{let r=i(t,e,n);r&&s(n,n+t[0].length,r)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(t,e,n,s)=>s(n,n+t[0].length,i)}this.boundary=s,this.maxLength=r}createDeco(t){let e=new Nt,i=e.add.bind(e);for(let{from:e,to:n}of function(t,e){let i=t.visibleRanges;if(1==i.length&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let n=[];for(let{from:s,to:r}of i)s=Math.max(t.state.doc.lineAt(s).from,s-e),r=Math.min(t.state.doc.lineAt(r).to,r+e),n.length&&n[n.length-1].to>=s?n[n.length-1].to=r:n.push({from:s,to:r});return n}(t,this.maxLength))Qr(t.state.doc,this.regexp,e,n,(e,n)=>this.addMatch(n,t,e,i));return e.finish()}updateDeco(t,e){let i=1e9,n=-1;return t.docChanged&&t.changes.iterChanges((e,s,r,o)=>{o>=t.view.viewport.from&&r<=t.view.viewport.to&&(i=Math.min(r,i),n=Math.max(o,n))}),t.viewportMoved||n-i>1e3?this.createDeco(t.view):n>-1?this.updateRange(t.view,e.map(t.changes),i,n):e}updateRange(t,e,i,n){for(let s of t.visibleRanges){let r=Math.max(s.from,i),o=Math.min(s.to,n);if(o>=r){let i=t.state.doc.lineAt(r),n=i.toi.from;r--)if(this.boundary.test(i.text[r-1-i.from])){l=r;break}for(;oc.push(i.range(t,e));if(i==n)for(this.regexp.lastIndex=l-i.from;(h=this.regexp.exec(i.text))&&h.indexthis.addMatch(i,t,e,u));e=e.update({filterFrom:l,filterTo:a,filter:(t,e)=>ta,add:c})}}return e}}const Kr=null!=/x/.unicode?"gu":"g",jr=new RegExp("[\0-\b\n--Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\ufeff-]",Kr),Xr={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Gr=null;const Yr=z.define({combine(t){let e=Dt(t,{render:null,specialChars:jr,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==Gr&&"undefined"!=typeof document&&document.body){let e=document.body.style;Gr=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return Gr||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,Kr)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Kr)),e}});function Jr(t={}){return[Yr.of(t),Zr||(Zr=qi.fromClass(class{constructor(t){this.view=t,this.decorations=Te.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(Yr)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new $r({regexp:t.specialChars,decoration:(e,i,n)=>{let{doc:s}=i.state,r=S(e[0],0);if(9==r){let t=s.lineAt(n),e=i.state.tabSize,r=Kt(t.text,e,n-t.from);return Te.replace({widget:new eo((e-r%e)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=Te.replace({widget:new to(t,r)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(Yr);t.startState.facet(Yr)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))]}let Zr=null;class to extends Me{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=function(t){return t>=32?"•":10==t?"␤":String.fromCharCode(9216+t)}(this.code),i=t.state.phrase("Control character")+" "+(Xr[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,e);if(n)return n;let s=document.createElement("span");return s.textContent=e,s.title=i,s.setAttribute("aria-label",i),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class eo extends Me{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}const io=Te.line({class:"cm-activeLine"}),no=qi.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let n of t.state.selection.ranges){let s=t.lineBlockAt(n.head);s.from>e&&(i.push(io.range(s.from)),e=s.from)}return Te.set(i)}},{decorations:t=>t.decorations}),so=2e3;function ro(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),n=t.state.doc.lineAt(i),s=i-n.from,r=s>so?-1:s==n.length?function(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}(t,e.clientX):Kt(n.text,t.state.tabSize,i-n.from);return{line:n.number,col:r,off:s}}function oo(t,e){let i=ro(t,e),n=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),s=t.state.doc.lineAt(e);i={line:s.number,col:i.col,off:Math.min(i.off,s.length)},n=n.map(t.changes)}},get(e,s,r){let o=ro(t,e);if(!o)return n;let l=function(t,e,i){let n=Math.min(e.line,i.line),s=Math.max(e.line,i.line),r=[];if(e.off>so||i.off>so||e.col<0||i.col<0){let o=Math.min(e.off,i.off),l=Math.max(e.off,i.off);for(let e=n;e<=s;e++){let i=t.doc.line(e);i.length<=l&&r.push(W.range(i.from+o,i.to+l))}}else{let o=Math.min(e.col,i.col),l=Math.max(e.col,i.col);for(let e=n;e<=s;e++){let i=t.doc.line(e),n=jt(i.text,o,t.tabSize,!0);if(n<0)r.push(W.cursor(i.to));else{let e=jt(i.text,l,t.tabSize);r.push(W.range(i.from+n,i.from+e))}}}return r}(t.state,i,o);return l.length?r?W.create(l.concat(n.ranges)):W.create(l):n}}:null}function lo(t){let e=(null==t?void 0:t.eventFilter)||(t=>t.altKey&&0==t.button);return pr.mouseSelectionStyle.of((t,i)=>e(i)?oo(t,i):null)}const ao={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},ho={style:"cursor: crosshair"};function co(t={}){let[e,i]=ao[t.key||"Alt"],n=qi.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)},mousemove(t){this.set(i(t))}}});return[n,pr.contentAttributes.of(t=>{var e;return(null===(e=t.plugin(n))||void 0===e?void 0:e.isDown)?ho:null})]}const uo="-10000px";class fo{constructor(t,e,i,n){this.facet=e,this.createTooltipView=i,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(t=>t);let s=null;this.tooltipViews=this.tooltips.map(t=>s=i(t,s))}update(t,e){var i;let n=t.state.facet(this.facet),s=n.filter(t=>t);if(n===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let r=[],o=e?[]:null;for(let i=0;ie[i]=t),e.length=o.length),this.input=n,this.tooltips=s,this.tooltipViews=r,!0}}function po(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const mo=z.define({combine:t=>{var e,i,n;return{position:ye.ios?"absolute":(null===(e=t.find(t=>t.position))||void 0===e?void 0:e.position)||"fixed",parent:(null===(i=t.find(t=>t.parent))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(n=t.find(t=>t.tooltipSpace))||void 0===n?void 0:n.tooltipSpace)||po}}}),go=new WeakMap,vo=qi.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(mo);this.position=e.position,this.parent=e.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new fo(t,xo,(t,e)=>this.createTooltip(t,e),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),t.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let i=e||t.geometryChanged,n=t.state.facet(mo);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view),n=e?e.dom:null;if(i.dom.classList.add("cm-tooltip"),t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",i.dom.appendChild(t)}return i.dom.style.position=this.position,i.dom.style.top=uo,i.dom.style.left="0px",this.container.insertBefore(i.dom,n),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),null===(t=e.destroy)||void 0===t||t.call(e);this.parent&&this.container.remove(),null===(e=this.resizeObserver)||void 0===e||e.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,i=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(ye.safari){let e=t.getBoundingClientRect();i=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}else i=!!t.offsetParent&&t.offsetParent!=this.container.ownerDocument.body}if(i||"absolute"==this.position)if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(t=i.width/this.parent.offsetWidth,e=i.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);let n=this.view.scrollDOM.getBoundingClientRect(),s=Zi(this.view);return{visible:{left:n.left+s.left,top:n.top+s.top,right:n.right-s.right,bottom:n.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)}),size:this.manager.tooltipViews.map(({dom:t})=>t.getBoundingClientRect()),space:this.view.state.facet(mo).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{visible:i,space:n,scaleX:s,scaleY:r}=t,o=[];for(let l=0;l=Math.min(i.bottom,n.bottom)||u.rightMath.min(i.right,n.right)+.1)){c.style.top=uo;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=f.right-f.left,g=null!==(e=go.get(h))&&void 0!==e?e:f.bottom-f.top,v=h.offset||yo,w=this.view.textDirection==si.LTR,b=f.width>n.right-n.left?w?n.left:n.right-f.width:w?Math.max(n.left,Math.min(u.left-(d?14:0)+v.x,n.right-m)):Math.min(Math.max(n.left,u.left-m+(d?14:0)-v.x),n.right-m),y=this.above[l];!a.strictSide&&(y?u.top-g-p-v.yn.bottom)&&y==n.bottom-u.bottom>u.top-n.top&&(y=this.above[l]=!y);let x=(y?u.top-n.top:n.bottom-u.bottom)-p;if(xb&&t.topk&&(k=y?t.top-g-2-p:t.bottom+p+2);if("absolute"==this.position?(c.style.top=(k-t.parent.top)/r+"px",wo(c,(b-t.parent.left)/s)):(c.style.top=k/r+"px",wo(c,b/s)),d){let t=u.left+(w?v.x:-v.x)-(b+14-7);d.style.left=t/s+"px"}!0!==h.overlap&&o.push({left:b,top:k,right:S,bottom:k+g}),c.classList.toggle("cm-tooltip-above",y),c.classList.toggle("cm-tooltip-below",!y),h.positioned&&h.positioned(t.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let t of this.manager.tooltipViews)t.dom.style.top=uo}},{eventObservers:{scroll(){this.maybeMeasure()}}});function wo(t,e){let i=parseInt(t.style.left,10);(isNaN(i)||Math.abs(e-i)>1)&&(t.style.left=e+"px")}const bo=pr.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),yo={x:0,y:0},xo=z.define({enables:[vo,bo]}),ko=z.define({combine:t=>t.reduce((t,e)=>t.concat(e),[])});class So{static create(t){return new So(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new fo(t,ko,(t,e)=>this.createHostedView(t,e),t=>t.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)null===(t=e.destroy)||void 0===t||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let n=i[t];if(void 0!==n)if(void 0===e)e=n;else if(e!==n)return}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Co=xo.compute([ko],t=>{let e=t.facet(ko);return 0===e.length?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var e;return null!==(e=t.end)&&void 0!==e?e:t.pos})),create:So.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),Ao=z.define();class Mo{constructor(t,e,i,n,s,r){this.view=t,this.source=e,this.field=i,this.locked=n,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(t){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;ti.bottom||e.xi.right+t.defaultCharacterWidth)return;let r=t.bidiSpans(t.state.doc.lineAt(n)).find(t=>t.from<=n&&t.to>=n),o=r&&r.dir==si.RTL?-1:1;s=e.x{if(e&&(!Array.isArray(e)||e.length)){let i=Array.isArray(e)?e:[e];n&&this.locked.set(i,n),t.dispatch({effects:this.setHover.of(i)})}};if(s&&"then"in s){let i=this.pending={pos:e};s.then(t=>{this.pending==i&&(this.pending=null,r(t))},e=>Hi(t.state,e,"hover tooltip"))}else r(s)}get tooltip(){let t=this.view.plugin(vo),e=t?t.manager.tooltips.findIndex(t=>t.create==So.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:s}=this;if(n.length&&!this.locked.has(n)&&s&&!function(t,e){let i,{left:n,right:s,top:r,bottom:o}=t.getBoundingClientRect();if(i=t.querySelector(".cm-tooltip-arrow")){let t=i.getBoundingClientRect();r=Math.min(t.top,r),o=Math.max(t.bottom,o)}return e.clientX>=n-Oo&&e.clientX<=s+Oo&&e.clientY>=r-Oo&&e.clientY<=o+Oo}(s.dom,t)||this.pending){let{pos:s}=n[0]||this.pending,r=null!==(i=null===(e=n[0])||void 0===e?void 0:e.end)&&void 0!==i?i:s;(s==r?this.view.posAtCoords(this.lastMove)==s:function(t,e,i,n,s){let r=t.scrollDOM.getBoundingClientRect(),o=t.documentTop+t.documentPadding.top+t.contentHeight;if(r.left>n||r.rights||Math.min(r.bottom,o)=e&&l<=i}(this.view,s,r,t.clientX,t.clientY))||(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length&&!this.locked.has(e)){let{tooltip:e}=this;e&&e.dom.contains(t.relatedTarget)?this.watchTooltipLeave(e.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e);let{active:n}=this;!n.length||this.locked.has(n)||this.view.dom.contains(i.relatedTarget)||this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Oo=4;function To(t,e={}){let i=gt.define(),n=new WeakMap,s=K.define({create:()=>[],update(t,r){let o=n.get(t);if(t.length&&(e.hideOnChange&&(r.docChanged||r.selection)||o&&o(r)?t=[]:e.hideOn&&(t=t.filter(t=>!e.hideOn(r,t)))),r.docChanged&&t.length){let e=[];for(let i of t){let t=r.changes.mapPos(i.pos,-1,O.TrackDel);if(null!=t){let n=Object.assign(Object.create(null),i);n.pos=t,null!=n.end&&(n.end=r.changes.mapPos(n.end)),e.push(n)}}t=e}for(let e of r.effects)e.is(i)&&(t=e.value,o=void 0),(e.is(Ro)&&!e.value||e.value==s)&&(t=[]);return t.length&&o&&n.set(t,o),t},provide:t=>ko.from(t)});const r=qi.define(r=>new Mo(r,t,s,n,i,e.hoverTime||300));return{active:s,extension:[s,r,Ao.of(r),Co]}}function Do(t,e){let i=t.plugin(vo);if(!i)return null;let n=i.manager.tooltips.indexOf(e);return n<0?null:i.manager.tooltipViews[n]}const Ro=gt.define(),Po=z.define({combine(t){let e,i;for(let n of t)e=e||n.topContainer,i=i||n.bottomContainer;return{topContainer:e,bottomContainer:i}}});function Bo(t,e){let i=t.plugin(Eo),n=i?i.specs.indexOf(e):-1;return n>-1?i.panels[n]:null}const Eo=qi.fromClass(class{constructor(t){this.input=t.state.facet(No),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(e=>e(t));let e=t.state.facet(Po);this.top=new Lo(t,!0,e.topContainer),this.bottom=new Lo(t,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(t){let e=t.state.facet(Po);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Lo(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Lo(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(No);if(i!=this.input){let e=i.filter(t=>t),n=[],s=[],r=[],o=[];for(let i of e){let e,l=this.specs.indexOf(i);l<0?(e=i(t.view),o.push(e)):(e=this.panels[l],e.update&&e.update(t)),n.push(e),(e.top?s:r).push(e)}this.specs=e,this.panels=n,this.top.sync(s),this.bottom.sync(r);for(let t of o)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>pr.scrollMargins.of(e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}})});class Lo{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=Io(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Io(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(this.container&&this.classes!=this.view.themeClasses){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function Io(t){let e=t.nextSibling;return t.remove(),e}const No=z.define({enables:Eo});function Wo(t,e){let i,n=new Promise(t=>i=t),s=t=>function(t,e,i){let n=e.content?e.content(t,()=>o(null)):null;if(!n){if(n=le("form"),e.input){let t=le("input",e.input);/^(text|password|number|email|tel|url)$/.test(t.type)&&t.classList.add("cm-textfield"),t.name||(t.name="input"),n.appendChild(le("label",(e.label||"")+": ",t))}else n.appendChild(document.createTextNode(e.label||""));n.appendChild(document.createTextNode(" ")),n.appendChild(le("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let s="FORM"==n.nodeName?[n]:n.querySelectorAll("form");for(let t=0;t{27==t.keyCode?(t.preventDefault(),o(null)):13==t.keyCode&&(t.preventDefault(),o(e))}),e.addEventListener("submit",t=>{t.preventDefault(),o(e)})}let r=le("div",n,le("button",{onclick:()=>o(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(r.className=e.class);function o(e){r.contains(r.ownerDocument.activeElement)&&t.focus(),i(e)}return r.classList.add("cm-dialog"),{dom:r,top:e.top,mount:()=>{if(e.focus){let t;t="string"==typeof e.focus?n.querySelector(e.focus):n.querySelector("input")||n.querySelector("button"),t&&"select"in t?t.select():t&&"focus"in t&&t.focus()}}}}(t,e,i);t.state.field(Ho,!1)?t.dispatch({effects:Vo.of(s)}):t.dispatch({effects:gt.appendConfig.of(Ho.init(()=>[s]))});let r=zo.of(s);return{close:r,result:n.then(e=>((t.win.queueMicrotask||(e=>t.win.setTimeout(e,10)))(()=>{t.state.field(Ho).indexOf(s)>-1&&t.dispatch({effects:r})}),e))}}const Ho=K.define({create:()=>[],update(t,e){for(let i of e.effects)i.is(Vo)?t=[i.value].concat(t):i.is(zo)&&(t=t.filter(t=>t!=i.value));return t},provide:t=>No.computeN([t],e=>e.field(t))}),Vo=gt.define(),zo=gt.define();class Fo extends Rt{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Fo.prototype.elementClass="",Fo.prototype.toDOM=void 0,Fo.prototype.mapMode=O.TrackBefore,Fo.prototype.startSide=Fo.prototype.endSide=-1,Fo.prototype.point=!0;const qo=z.define(),_o=z.define(),Uo={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>It.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Qo=z.define();function $o(t){return[jo(),Qo.of({...Uo,...t})]}const Ko=z.define({combine:t=>t.some(t=>t)});function jo(t){let e=[Xo];return t&&!1===t.fixed&&e.push(Ko.of(!0)),e}const Xo=qi.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(Qo).map(e=>new Zo(t,e)),this.fixed=!t.state.facet(Ko);for(let t of this.gutters)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,n=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(n<.8*(i.to-i.from))}if(t.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Ko)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let i=It.iter(this.view.state.facet(qo),this.view.viewport.from),n=[],s=this.gutters.map(t=>new Jo(t,this.view.viewport,-this.view.documentPadding.top));for(let t of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(t.type)){let e=!0;for(let r of t.type)if(r.type==Oe.Text&&e){Yo(i,n,r.from);for(let t of s)t.line(this.view,r,n);e=!1}else if(r.widget)for(let t of s)t.widget(this.view,r)}else if(t.type==Oe.Text){Yo(i,n,t.from);for(let e of s)e.line(this.view,t,n)}else if(t.widget)for(let e of s)e.widget(this.view,t);for(let t of s)t.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(Qo),i=t.state.facet(Qo),n=t.docChanged||t.heightChanged||t.viewportChanged||!It.eq(t.startState.facet(qo),t.state.facet(qo),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(n=!0);else{n=!0;let s=[];for(let n of i){let i=e.indexOf(n);i<0?s.push(new Zo(this.view,n)):(this.gutters[i].update(t),s.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),s.indexOf(t)<0&&t.destroy();for(let t of s)"after"==t.config.side?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.gutters=s}return n}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>pr.scrollMargins.of(e=>{let i=e.plugin(t);if(!i||0==i.gutters.length||!i.fixed)return null;let n=i.dom.offsetWidth*e.scaleX,s=i.domAfter?i.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==si.LTR?{left:n,right:s}:{right:n,left:s}})});function Go(t){return Array.isArray(t)?t:[t]}function Yo(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class Jo{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=It.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:n}=this,s=(e.top-this.height)/t.scaleY,r=e.height/t.scaleY;if(this.i==n.elements.length){let e=new tl(t,r,s,i);n.elements.push(e),n.dom.appendChild(e.dom)}else n.elements[this.i].update(t,r,s,i);this.height=e.bottom,this.i++}line(t,e,i){let n=[];Yo(this.cursor,n,e.from),i.length&&(n=n.concat(i));let s=this.gutter.config.lineMarker(t,e,n);s&&n.unshift(s);let r=this.gutter;(0!=n.length||r.config.renderEmptyElements)&&this.addElement(t,e,n)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),n=i?[i]:null;for(let i of t.state.facet(_o)){let s=i(t,e.widget,e);s&&(n||(n=[])).push(s)}n&&this.addElement(t,e,n)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Zo{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,n=>{let s,r=n.target;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let t=r.getBoundingClientRect();s=(t.top+t.bottom)/2}else s=n.clientY;let o=t.lineBlockAtHeight(s-t.documentTop);e.domEventHandlers[i](t,o,n)&&n.preventDefault()});this.markers=Go(e.markers(t)),e.initialSpacer&&(this.spacer=new tl(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=Go(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let i=t.view.viewport;return!It.eq(this.markers,e,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class tl{constructor(t,e,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,n)}update(t,e,i,n){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;iDt(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let n=i[t],s=e[t];i[t]=n?(t,e,i)=>n(t,e,i)||s(t,e,i):s}return i}})});class sl extends Fo{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function rl(t,e){return t.state.facet(nl).formatNumber(e,t.state)}const ol=Qo.compute([nl],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(el),lineMarker:(t,e,i)=>i.some(t=>t.toDOM)?null:new sl(rl(t,t.state.doc.lineAt(e.from).number)),widgetMarker:(t,e,i)=>{for(let n of t.state.facet(il)){let s=n(t,e,i);if(s)return s}return null},lineMarkerChange:t=>t.startState.facet(nl)!=t.state.facet(nl),initialSpacer:t=>new sl(rl(t,al(t.state.doc.lines))),updateSpacer(t,e){let i=rl(e.view,al(e.view.state.doc.lines));return i==t.number?t:new sl(i)},domEventHandlers:t.facet(nl).domEventHandlers,side:"before"}));function ll(t={}){return[nl.of(t),jo(),ol]}function al(t){let e=9;for(;e{let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.head).from;s>i&&(i=s,e.push(hl.range(s)))}return It.of(e)});const ul=1024;let fl=0;class dl{constructor(t,e){this.from=t,this.to=e}}class pl{constructor(t={}){this.id=fl++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof t&&(t=vl.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}pl.closedBy=new pl({deserialize:t=>t.split(" ")}),pl.openedBy=new pl({deserialize:t=>t.split(" ")}),pl.group=new pl({deserialize:t=>t.split(" ")}),pl.isolate=new pl({deserialize:t=>{if(t&&"rtl"!=t&&"ltr"!=t&&"auto"!=t)throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}}),pl.contextHash=new pl({perNode:!0}),pl.lookAhead=new pl({perNode:!0}),pl.mounted=new pl({perNode:!0});class ml{constructor(t,e,i,n=!1){this.tree=t,this.overlay=e,this.parser=i,this.bracketed=n}static get(t){return t&&t.props&&t.props[pl.mounted.id]}}const gl=Object.create(null);class vl{constructor(t,e,i,n=0){this.name=t,this.props=e,this.id=i,this.flags=n}static define(t){let e=t.props&&t.props.length?Object.create(null):gl,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),n=new vl(t.name||"",e,t.id,i);if(t.props)for(let i of t.props)if(Array.isArray(i)||(i=i(n)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[i[0].id]=i[1]}return n}prop(t){return this.props[t.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(pl.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let n of i.split(" "))e[n]=t[i];return t=>{for(let i=t.prop(pl.group),n=-1;n<(i?i.length:0);n++){let s=e[n<0?t.name:i[n]];if(s)return s}}}}vl.none=new vl("",Object.create(null),0,8);class wl{constructor(t){this.types=t;for(let e=0;e=e){let o=new Tl(r.tree,r.overlay[0].from+t.from,-1,t);(s||(s=[n])).push(Ml(o,e,i,!1))}}return s?El(s):n}(this,t,e)}iterate(t){let{enter:e,leave:i,from:n=0,to:s=this.length}=t,r=t.mode||0,o=(r&xl.IncludeAnonymous)>0;for(let t=this.cursor(r|xl.IncludeAnonymous);;){let r=!1;if(t.from<=s&&t.to>=n&&(!o&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;r=!0}for(;r&&i&&(o||!t.type.isAnonymous)&&i(t),!t.nextSibling();){if(!t.parent())return;r=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Vl(vl.none,this.children,this.positions,0,this.children.length,0,this.length,(t,e,i)=>new kl(this.type,t,e,i,this.propValues),t.makeTree||((t,e,i)=>new kl(vl.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:n,maxBufferLength:s=ul,reused:r=[],minRepeatType:o=n.types.length}=t,l=Array.isArray(i)?new Sl(i,i.length):i,a=n.types,h=0,c=0;function u(t,e,i,w,b,y){let{id:x,start:k,end:S,size:C}=l,A=c,M=h;if(C<0){if(l.next(),-1==C){let e=r[x];return i.push(e),void w.push(k-t)}if(-3==C)return void(h=x);if(-4==C)return void(c=x);throw new RangeError(`Unrecognized record size: ${C}`)}let O,T,D=a[x],R=k-t;if(S-k<=s&&(T=g(l.pos-e,b))){let e=new Uint16Array(T.size-T.skip),i=l.pos-T.size,s=e.length;for(;l.pos>i;)s=v(T.start,e,s);O=new Cl(e,S-T.start,n),R=T.start-t}else{let t=l.pos-C;l.next();let e=[],i=[],n=x>=o?x:-1,r=0,a=S;for(;l.pos>t;)n>=0&&l.id==n&&l.size>=0?(l.end<=a-s&&(p(e,i,k,r,l.end,a,n,A,M),r=e.length,a=l.end),l.next()):y>2500?f(k,t,e,i):u(k,t,e,i,n,y+1);if(n>=0&&r>0&&r-1&&r>0){let t=d(D,M);O=Vl(D,e,i,0,e.length,0,S-k,t,t)}else O=m(D,e,i,S-k,A-S,M)}i.push(O),w.push(R)}function f(t,e,i,r){let o=[],a=0,h=-1;for(;l.pos>e;){let{id:t,start:e,end:i,size:n}=l;if(n>4)l.next();else{if(h>-1&&e=0;t-=3)e[i++]=o[t],e[i++]=o[t+1]-s,e[i++]=o[t+2]-s,e[i++]=i;i.push(new Cl(e,o[2]-s,n)),r.push(s-t)}}function d(t,e){return(i,n,s)=>{let r,o,l=0,a=i.length-1;if(a>=0&&(r=i[a])instanceof kl){if(!a&&r.type==t&&r.length==s)return r;(o=r.prop(pl.lookAhead))&&(l=n[a]+r.length+o)}return m(t,i,n,s,l,e)}}function p(t,e,i,s,r,o,l,a,h){let c=[],u=[];for(;t.length>s;)c.push(t.pop()),u.push(e.pop()+i-r);t.push(m(n.types[l],c,u,o-r,a-o,h)),e.push(r-i)}function m(t,e,i,n,s,r,o){if(r){let t=[pl.contextHash,r];o=o?[t].concat(o):[t]}if(s>25){let t=[pl.lookAhead,s];o=o?[t].concat(o):[t]}return new kl(t,e,i,n,o)}function g(t,e){let i=l.fork(),n=0,r=0,a=0,h=i.end-s,c={size:0,start:0,skip:0};t:for(let s=i.pos-t;i.pos>s;){let t=i.size;if(i.id==e&&t>=0){c.size=n,c.start=r,c.skip=a,a+=4,n+=4,i.next();continue}let l=i.pos-t;if(t<0||l=o?4:0,f=i.start;for(i.next();i.pos>l;){if(i.size<0){if(-3!=i.size&&-4!=i.size)break t;u+=4}else i.id>=o&&(u+=4);i.next()}r=f,n+=t,a+=u}return(e<0||n==t)&&(c.size=n,c.start=r,c.skip=a),c.size>4?c:void 0}function v(t,e,i){let{id:n,start:s,end:r,size:a}=l;if(l.next(),a>=0&&n4){let n=l.pos-(a-4);for(;l.pos>n;)i=v(t,e,i)}e[--i]=o,e[--i]=r-t,e[--i]=s-t,e[--i]=n}else-3==a?h=n:-4==a&&(c=n);return i}let w=[],b=[];for(;l.pos>0;)u(t.start||0,t.bufferStart||0,w,b,-1,0);let y=null!==(e=t.length)&&void 0!==e?e:w.length?b[0]+w[0].length:0;return new kl(a[t.topID],w.reverse(),b.reverse(),y)}(t)}}kl.empty=new kl(vl.none,[],[],0);class Sl{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new Sl(this.buffer,this.index)}}class Cl{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return vl.none}toString(){let t=[];for(let e=0;e0));l=r[l+3]);return o}slice(t,e,i){let n=this.buffer,s=new Uint16Array(e-t),r=0;for(let o=t,l=0;o=e&&ie;case 1:return i<=e&&n>e;case 2:return n>e;case 4:return!0}}function Ml(t,e,i,n){for(var s;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to0?o.length:-1;t!=a;t+=e){let a,h=o[t],c=l[t]+r.from;if(s&xl.EnterBracketed&&h instanceof kl&&(a=ml.get(h))&&!a.overlay&&a.bracketed&&i>=c&&i<=c+h.length||Al(n,i,c,c+h.length))if(h instanceof Cl){if(s&xl.ExcludeBuffers)continue;let o=h.findChild(0,h.buffer.length,e,i-c,n);if(o>-1)return new Bl(new Pl(r,h,t,c),null,o)}else if(s&xl.IncludeAnonymous||!h.type.isAnonymous||Nl(h)){let o;if(!(s&xl.IgnoreMounts)&&(o=ml.get(h))&&!o.overlay)return new Tl(o.tree,c,t,r);let l=new Tl(h,c,t,r);return s&xl.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(e<0?h.children.length-1:0,e,i,n,s)}}if(s&xl.IncludeAnonymous||!r.type.isAnonymous)return null;if(t=r.index>=0?r.index+e:e<0?-1:r._parent._tree.children.length,r=r._parent,!r)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,e,i=0){let n;if(!(i&xl.IgnoreOverlays)&&(n=ml.get(this._tree))&&n.overlay){let s=t-this.from,r=i&xl.EnterBracketed&&n.bracketed;for(let{from:t,to:i}of n.overlay)if((e>0||r?t<=s:t=s:i>s))return new Tl(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Dl(t,e,i,n){let s=t.cursor(),r=[];if(!s.firstChild())return r;if(null!=i)for(let t=!1;!t;)if(t=s.type.is(i),!s.nextSibling())return r;for(;;){if(null!=n&&s.type.is(n))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return null==n?r:[]}}function Rl(t,e,i=e.length-1){for(let n=t;i>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[i]&&e[i]!=n.name)return!1;i--}}return!0}class Pl{constructor(t,e,i,n){this.parent=t,this.buffer=e,this.index=i,this.start=n}}class Bl extends Ol{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.context.start,i);return s<0?null:new Bl(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,e,i=0){if(i&xl.ExcludeBuffers)return null;let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return s<0?null:new Bl(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new Bl(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new Bl(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,n=this.index+4,s=i.buffer[this.index+3];if(s>n){let r=i.buffer[this.index+1];t.push(i.slice(n,s,r)),e.push(0)}return new kl(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function El(t){if(!t.length)return null;let e=0,i=t[0];for(let n=1;ni.from||s.to0){if(this.index-1)for(let n=e+t,s=t<0?-1:i._tree.children.length;n!=s;n+=t){let t=i._tree.children[n];if(this.mode&xl.IncludeAnonymous||t instanceof Cl||!t.type.isAnonymous||Nl(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to=0;){for(let r=t;r;r=r._parent)if(r.index==n){if(n==this.index)return r;e=r,i=s+1;break t}n=this.stack[--s]}for(let t=i;t=0;s--){if(s<0)return Rl(this._tree,t,n);let r=i[e.buffer[this.stack[s]]];if(!r.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}}function Nl(t){return t.children.some(t=>t instanceof Cl||!t.type.isAnonymous||Nl(t))}const Wl=new WeakMap;function Hl(t,e){if(!t.isAnonymous||e instanceof Cl||e.type!=t)return 1;let i=Wl.get(e);if(null==i){i=1;for(let n of e.children){if(n.type!=t||!(n instanceof kl)){i=1;break}i+=Hl(t,n)}Wl.set(e,i)}return i}function Vl(t,e,i,n,s,r,o,l,a){let h=0;for(let i=n;i=c)break;p+=e}if(h==s+1){if(p>c){let t=i[s];e(t.children,t.positions,0,t.children.length,n[s]+l);continue}u.push(i[s])}else{let e=n[h-1]+i[h-1].length-d;u.push(Vl(t,i,n,s,h,d,e,null,a))}f.push(d+l-r)}}(e,i,n,s,0),(l||a)(u,f,o)}class zl{constructor(t,e,i,n,s=!1,r=!1){this.from=t,this.to=e,this.tree=i,this.offset=n,this.open=(s?1:0)|(r?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],i=!1){let n=[new zl(0,t.length,t,0,!1,i)];for(let i of e)i.to>t.length&&n.push(i);return n}static applyChanges(t,e,i=128){if(!e.length)return t;let n=[],s=1,r=t.length?t[0]:null;for(let o=0,l=0,a=0;;o++){let h=o=i)for(;r&&r.from=e.from||c<=e.to||a){let t=Math.max(e.from,l)-a,i=Math.min(e.to,c)-a;e=t>=i?null:new zl(t,i,e.tree,e.offset+a,o>0,!!h)}if(e&&n.push(e),r.to>c)break;r=snew dl(t.from,t.to)):[new dl(0,0)]:[new dl(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let n=this.startParse(t,e,i);for(;;){let t=n.advance();if(t)return t}}}class ql{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new pl({perNode:!0});let _l=0;class Ul{constructor(t,e,i,n){this.name=t,this.set=e,this.base=i,this.modified=n,this.id=_l++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i="string"==typeof t?t:"?";if(t instanceof Ul&&(e=t),null==e?void 0:e.base)throw new Error("Can not derive from a modified tag");let n=new Ul(i,[],null,[]);if(n.set.push(n),e)for(let t of e.set)n.set.push(t);return n}static defineModifier(t){let e=new $l(t);return t=>t.modified.indexOf(e)>-1?t:$l.get(t.base||t,t.modified.concat(e).sort((t,e)=>t.id-e.id))}}let Ql=0;class $l{constructor(t){this.name=t,this.instances=[],this.id=Ql++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(i=>{return i.base==t&&(n=e,s=i.modified,n.length==s.length&&n.every((t,e)=>t==s[e]));var n,s});if(i)return i;let n=[],s=new Ul(t.name,n,t,e);for(let t of e)t.instances.push(s);let r=function(t){let e=[[]];for(let i=0;ie.length-t.length)}(e);for(let e of t.set)if(!e.modified.length)for(let t of r)n.push($l.get(e,t));return s}}function Kl(t){let e=Object.create(null);for(let i in t){let n=t[i];Array.isArray(n)||(n=[n]);for(let t of i.split(" "))if(t){let i=[],s=2,r=t;for(let e=0;;){if("..."==r&&e>0&&e+3==t.length){s=1;break}let n=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(r);if(!n)throw new RangeError("Invalid path: "+t);if(i.push("*"==n[0]?"":'"'==n[0][0]?JSON.parse(n[0]):n[0]),e+=n[0].length,e==t.length)break;let o=t[e++];if(e==t.length&&"!"==o){s=0;break}if("/"!=o)throw new RangeError("Invalid path: "+t);r=t.slice(e)}let o=i.length-1,l=i[o];if(!l)throw new RangeError("Invalid path: "+t);let a=new Xl(n,s,o>0?i.slice(0,o):null);e[l]=a.sort(e[l])}}return jl.add(e)}const jl=new pl({combine(t,e){let i,n,s;for(;t||e;){if(!t||e&&t.depth>=e.depth?(s=e,e=e.next):(s=t,t=t.next),i&&i.mode==s.mode&&!s.context&&!i.context)continue;let r=new Xl(s.tags,s.mode,s.context);i?i.next=r:n=r,i=r}return n}});class Xl{constructor(t,e,i,n){this.tags=t,this.mode=e,this.context=i,this.next=n}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(t){return!t||t.depth{let e=s;for(let n of t)for(let t of n.set){let n=i[t.id];if(n){e=e?e+" "+n:n;break}}return e},scope:n}}function Yl(t,e,i,n=0,s=t.length){let r=new Jl(n,Array.isArray(e)?e:[e],i);r.highlightRange(t.cursor(),n,s,"",r.highlighters),r.flush(s)}Xl.empty=new Xl([],2,null);class Jl{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,n,s){let{type:r,from:o,to:l}=t;if(o>=i||l<=e)return;r.isTop&&(s=this.highlighters.filter(t=>!t.scope||t.scope(r)));let a=n,h=function(t){let e=t.type.prop(jl);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}(t)||Xl.empty,c=function(t,e){let i=null;for(let n of t){let t=n.style(e);t&&(i=i?i+" "+t:t)}return i}(s,h.tags);if(c&&(a&&(a+=" "),a+=c,1==h.mode&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(e,o),a),h.opaque)return;let u=t.tree&&t.tree.prop(pl.mounted);if(u&&u.overlay){let r=t.node.enter(u.overlay[0].from+o,1),h=this.highlighters.filter(t=>!t.scope||t.scope(u.tree.type)),c=t.firstChild();for(let f=0,d=o;;f++){let p=f=m)&&t.nextSibling()););if(!p||m>i)break;d=p.to+o,d>e&&(this.highlightRange(r.cursor(),Math.max(e,p.from+o),Math.min(i,d),"",h),this.startSpan(Math.min(i,d),a))}c&&t.parent()}else if(t.firstChild()){u&&(n="");do{if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,n,s),this.startSpan(Math.min(i,t.to),a)}}while(t.nextSibling());t.parent()}}}const Zl=Ul.define,ta=Zl(),ea=Zl(),ia=Zl(ea),na=Zl(ea),sa=Zl(),ra=Zl(sa),oa=Zl(sa),la=Zl(),aa=Zl(la),ha=Zl(),ca=Zl(),ua=Zl(),fa=Zl(ua),da=Zl(),pa={comment:ta,lineComment:Zl(ta),blockComment:Zl(ta),docComment:Zl(ta),name:ea,variableName:Zl(ea),typeName:ia,tagName:Zl(ia),propertyName:na,attributeName:Zl(na),className:Zl(ea),labelName:Zl(ea),namespace:Zl(ea),macroName:Zl(ea),literal:sa,string:ra,docString:Zl(ra),character:Zl(ra),attributeValue:Zl(ra),number:oa,integer:Zl(oa),float:Zl(oa),bool:Zl(sa),regexp:Zl(sa),escape:Zl(sa),color:Zl(sa),url:Zl(sa),keyword:ha,self:Zl(ha),null:Zl(ha),atom:Zl(ha),unit:Zl(ha),modifier:Zl(ha),operatorKeyword:Zl(ha),controlKeyword:Zl(ha),definitionKeyword:Zl(ha),moduleKeyword:Zl(ha),operator:ca,derefOperator:Zl(ca),arithmeticOperator:Zl(ca),logicOperator:Zl(ca),bitwiseOperator:Zl(ca),compareOperator:Zl(ca),updateOperator:Zl(ca),definitionOperator:Zl(ca),typeOperator:Zl(ca),controlOperator:Zl(ca),punctuation:ua,separator:Zl(ua),bracket:fa,angleBracket:Zl(fa),squareBracket:Zl(fa),paren:Zl(fa),brace:Zl(fa),content:la,heading:aa,heading1:Zl(aa),heading2:Zl(aa),heading3:Zl(aa),heading4:Zl(aa),heading5:Zl(aa),heading6:Zl(aa),contentSeparator:Zl(la),list:Zl(la),quote:Zl(la),emphasis:Zl(la),strong:Zl(la),link:Zl(la),monospace:Zl(la),strikethrough:Zl(la),inserted:Zl(),deleted:Zl(),changed:Zl(),invalid:Zl(),meta:da,documentMeta:Zl(da),annotation:Zl(da),processingInstruction:Zl(da),definition:Ul.defineModifier("definition"),constant:Ul.defineModifier("constant"),function:Ul.defineModifier("function"),standard:Ul.defineModifier("standard"),local:Ul.defineModifier("local"),special:Ul.defineModifier("special")};for(let t in pa){let e=pa[t];e instanceof Ul&&(e.name=t)}var ma;Gl([{tag:pa.link,class:"tok-link"},{tag:pa.heading,class:"tok-heading"},{tag:pa.emphasis,class:"tok-emphasis"},{tag:pa.strong,class:"tok-strong"},{tag:pa.keyword,class:"tok-keyword"},{tag:pa.atom,class:"tok-atom"},{tag:pa.bool,class:"tok-bool"},{tag:pa.url,class:"tok-url"},{tag:pa.labelName,class:"tok-labelName"},{tag:pa.inserted,class:"tok-inserted"},{tag:pa.deleted,class:"tok-deleted"},{tag:pa.literal,class:"tok-literal"},{tag:pa.string,class:"tok-string"},{tag:pa.number,class:"tok-number"},{tag:[pa.regexp,pa.escape,pa.special(pa.string)],class:"tok-string2"},{tag:pa.variableName,class:"tok-variableName"},{tag:pa.local(pa.variableName),class:"tok-variableName tok-local"},{tag:pa.definition(pa.variableName),class:"tok-variableName tok-definition"},{tag:pa.special(pa.variableName),class:"tok-variableName2"},{tag:pa.definition(pa.propertyName),class:"tok-propertyName tok-definition"},{tag:pa.typeName,class:"tok-typeName"},{tag:pa.namespace,class:"tok-namespace"},{tag:pa.className,class:"tok-className"},{tag:pa.macroName,class:"tok-macroName"},{tag:pa.propertyName,class:"tok-propertyName"},{tag:pa.operator,class:"tok-operator"},{tag:pa.comment,class:"tok-comment"},{tag:pa.meta,class:"tok-meta"},{tag:pa.invalid,class:"tok-invalid"},{tag:pa.punctuation,class:"tok-punctuation"}]);const ga=new pl;const va=new pl;class wa{constructor(t,e,i=[],n=""){this.data=t,this.name=n,Tt.prototype.hasOwnProperty("tree")||Object.defineProperty(Tt.prototype,"tree",{get(){return xa(this)}}),this.parser=e,this.extension=[Ra.of(this),Tt.languageData.of((t,e,i)=>{let n=ba(t,e,i),s=n.type.prop(ga);if(!s)return[];let r=t.facet(s),o=n.type.prop(va);if(o){let s=n.resolve(e-n.from,i);for(let e of o)if(e.test(s,t)){let i=t.facet(e.facet);return"replace"==e.type?i:i.concat(r)}}return r})].concat(i)}isActiveAt(t,e,i=-1){return ba(t,e,i).type.prop(ga)==this.data}findRegions(t){let e=t.facet(Ra);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],n=(t,e)=>{if(t.prop(ga)==this.data)return void i.push({from:e,to:e+t.length});let s=t.prop(pl.mounted);if(s){if(s.tree.prop(ga)==this.data){if(s.overlay)for(let t of s.overlay)i.push({from:t.from+e,to:t.to+e});else i.push({from:e,to:e+t.length});return}if(s.overlay){let t=i.length;if(n(s.tree,s.overlay[0].from+e),i.length>t)return}}for(let i=0;it.concat(i):void 0}));var i;return new ya(e,t.parser.configure({props:[ga.add(t=>t.isTop?e:void 0)]}),t.name)}configure(t,e){return new ya(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function xa(t){let e=t.field(wa.state,!1);return e?e.tree:kl.empty}class ka{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let Sa=null;class Ca{constructor(t,e,i=[],n,s,r,o,l){this.parser=t,this.state=e,this.fragments=i,this.tree=n,this.treeLen=s,this.viewport=r,this.skipped=o,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new Ca(t,e,[],kl.empty,0,i,[],null)}startParse(){return this.parser.startParse(new ka(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=kl.empty&&this.isDone(null!=e?e:this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if("number"==typeof t){let e=Date.now()+t;t=()=>Date.now()>e}for(this.parse||(this.parse=this.startParse()),null!=e&&(null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&e=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(zl.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Sa;Sa=this;try{return t()}finally{Sa=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=Aa(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:n,treeLen:s,viewport:r,skipped:o}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges((t,i,n,s)=>e.push({fromA:t,toA:i,fromB:n,toB:s})),i=zl.applyChanges(i,e),n=kl.empty,s=0,r={from:t.mapPos(r.from,-1),to:t.mapPos(r.to,1)},this.skipped.length){o=[];for(let e of this.skipped){let i=t.mapPos(e.from,1),n=t.mapPos(e.to,-1);it.from&&(this.fragments=Aa(this.fragments,i,n),this.skipped.splice(e--,1))}return!(this.skipped.length>=e)&&(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Fl{createParse(e,i,n){let s=n[0].from,r=n[n.length-1].to;return{parsedPos:s,advance(){let e=Sa;if(e){for(let t of n)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=r,new kl(vl.none,[],[],r-s)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&0==e[0].from&&e[0].to>=t}static get(){return Sa}}function Aa(t,e,i){return zl.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class Ma{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Ma(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Ca.create(t.facet(Ra).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Ma(i)}}wa.state=K.define({create:Ma.init,update(t,e){for(let t of e.effects)if(t.is(wa.setState))return t.value;return e.startState.facet(Ra)!=e.state.facet(Ra)?Ma.init(e.state):t.apply(e)}});let Oa=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(Oa=t=>{let e=-1,i=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const Ta="undefined"!=typeof navigator&&(null===(ma=navigator.scheduling)||void 0===ma?void 0:ma.isInputPending)?()=>navigator.scheduling.isInputPending():null,Da=qi.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(wa.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(wa.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=Oa(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEndn+1e3,l=s.context.work(()=>Ta&&Ta()||Date.now()>r,n+(o?0:1e5));this.chunkBudget-=Date.now()-e,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:wa.setState.of(new Ma(s.context))})),this.chunkBudget>0&&(!l||o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Hi(this.view.state,t)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ra=z.define({combine:t=>t.length?t[0]:null,enables:t=>[wa.state,Da,pr.contentAttributes.compute([t],e=>{let i=e.facet(t);return i&&i.name?{"data-language":i.name}:{}})]});class Pa{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const Ba=z.define(),Ea=z.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function La(t){let e=t.facet(Ea);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function Ia(t,e){let i="",n=t.tabSize,s=t.facet(Ea)[0];if("\t"==s){for(;e>=n;)i+="\t",e-=n;s=" "}for(let t=0;t=e?function(t,e,i){let n=e.resolveStack(i),s=e.resolveInner(i,-1).resolve(i,0).enterUnfinishedNodesBefore(i);if(s!=n.node){let t=[];for(let e=s;e&&!(e.fromn.node.to||e.from==n.node.from&&e.type==n.node.type);e=e.parent)t.push(e);for(let e=t.length-1;e>=0;e--)n={node:t[e],next:n}}return Va(n,t,i)}(t,i,e):null}class Wa{constructor(t,e={}){this.state=t,this.options=e,this.unit=La(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:n,simulateDoubleBreak:s}=this.options;return null!=n&&n>=i.from&&n<=i.to?s&&n==t?{text:"",from:t}:(e<0?n-1&&(s+=r-this.countColumn(i,i.search(/\S|$/))),s}countColumn(t,e=t.length){return Kt(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:n}=this.lineAt(t,e),s=this.options.overrideIndentation;if(s){let t=s(n);if(t>-1)return t}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Ha=new pl;function Va(t,e,i){for(let n=t;n;n=n.next){let t=za(n.node);if(t)return t(qa.create(e,i,n))}return 0}function za(t){let e=t.type.prop(Ha);if(e)return e;let i,n=t.firstChild;if(n&&(i=n.type.prop(pl.closedBy))){let e=t.lastChild,n=e&&i.indexOf(e.name)>-1;return t=>function(t,e,i,n,s){let r=t.textAfter,o=r.match(/^\s*/)[0].length,l=n&&r.slice(o,o+n.length)==n||s==t.pos+o,a=e?function(t){let e=t.node,i=e.childAfter(e.from),n=e.lastChild;if(!i)return null;let s=t.options.simulateBreak,r=t.state.doc.lineAt(i.from),o=null==s||s<=r.from?r.to:Math.min(r.to,s);for(let t=i.to;;){let s=e.childAfter(t);if(!s||s==n)return null;if(!s.type.isSkipped){if(s.from>=o)return null;let t=/^ */.exec(r.text.slice(i.to-r.from))[0].length;return{from:i.from,to:i.to+t}}t=s.to}}(t):null;return a?l?t.column(a.from):t.column(a.to):t.baseIndent+(l?0:t.unit*i)}(t,!0,1,void 0,n&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?Fa:null}function Fa(){return 0}class qa extends Wa{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new qa(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(_a(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return Va(this.context.next,this.base,this.pos)}}function _a(t,e){for(let i=e;i;i=i.parent)if(t==i)return!0;return!1}function Ua({except:t,units:e=1}={}){return i=>{let n=t&&t.test(i.textAfter);return i.baseIndent+(n?0:e*i.unit)}}const Qa=z.define(),$a=new pl;function Ka(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function ja(t,e,i){for(let n of t.facet(Qa)){let s=n(t,e,i);if(s)return s}return function(t,e,i){let n=xa(t);if(n.lengthi)continue;if(s&&o.from=e&&n.to>i&&(s=n)}}return s}(t,e,i)}function Xa(t,e){let i=e.mapPos(t.from,1),n=e.mapPos(t.to,-1);return i>=n?void 0:{from:i,to:n}}const Ga=gt.define({map:Xa}),Ya=gt.define({map:Xa});function Ja(t){let e=[];for(let{head:i}of t.state.selection.ranges)e.some(t=>t.from<=i&&t.to>=i)||e.push(t.lineBlockAt(i));return e}const Za=K.define({create:()=>Te.none,update(t,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((e,i)=>t=th(t,e,i)),t=t.map(e.changes);let i=[];for(let n of e.effects)n.is(Ga)&&!ih(t,n.value.from,n.value.to)?i.push(n.value):n.is(Ya)&&(t=t.update({filter:(t,e)=>n.value.from!=t||n.value.to!=e,filterFrom:n.value.from,filterTo:n.value.to}));if(i.length){let{preparePlaceholder:n}=e.state.facet(lh),s=i.map(t=>(n?Te.replace({widget:new uh(n(e.state,t))}):ch).range(t.from,t.to));t=t.update({add:s})}return e.selection&&(t=th(t,e.selection.main.head)),t},provide:t=>pr.decorations.from(t),toJSON(t,e){let i=[];return t.between(0,e.doc.length,(t,e)=>{i.push(t,e)}),i},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let i=0;i{te&&(n=!0)}),n?t.update({filterFrom:e,filterTo:i,filter:(t,n)=>t>=i||n<=e}):t}function eh(t,e,i){var n;let s=null;return null===(n=t.field(Za,!1))||void 0===n||n.between(e,i,(t,e)=>{(!s||s.from>t)&&(s={from:t,to:e})}),s}function ih(t,e,i){let n=!1;return t.between(e,e,(t,s)=>{t==e&&s==i&&(n=!0)}),n}function nh(t,e){return t.field(Za,!1)?e:e.concat(gt.appendConfig.of(ah()))}function sh(t,e,i=!0){let n=t.state.doc.lineAt(e.from).number,s=t.state.doc.lineAt(e.to).number;return pr.announce.of(`${t.state.phrase(i?"Folded lines":"Unfolded lines")} ${n} ${t.state.phrase("to")} ${s}.`)}const rh=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of Ja(t)){let i=ja(t.state,e.from,e.to);if(i)return t.dispatch({effects:nh(t.state,[Ga.of(i),sh(t,i)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(Za,!1))return!1;let e=[];for(let i of Ja(t)){let n=eh(t.state,i.from,i.to);n&&e.push(Ya.of(n),sh(t,n,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,i=[];for(let n=0;n{let e=t.state.field(Za,!1);if(!e||!e.size)return!1;let i=[];return e.between(0,t.state.doc.length,(t,e)=>{i.push(Ya.of({from:t,to:e}))}),t.dispatch({effects:i}),!0}}],oh={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},lh=z.define({combine:t=>Dt(t,oh)});function ah(t){let e=[Za,mh];return t&&e.push(lh.of(t)),e}function hh(t,e){let{state:i}=t,n=i.facet(lh),s=e=>{let i=t.lineBlockAt(t.posAtDOM(e.target)),n=eh(t.state,i.from,i.to);n&&t.dispatch({effects:Ya.of(n)}),e.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(t,s,e);let r=document.createElement("span");return r.textContent=n.placeholderText,r.setAttribute("aria-label",i.phrase("folded code")),r.title=i.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const ch=Te.replace({widget:new class extends Me{toDOM(t){return hh(t,null)}}});class uh extends Me{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return hh(t,this.value)}}const fh={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class dh extends Fo{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}function ph(t={}){let e={...fh,...t},i=new dh(e,!0),n=new dh(e,!1),s=qi.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(Ra)!=t.state.facet(Ra)||t.startState.field(Za,!1)!=t.state.field(Za,!1)||xa(t.startState)!=xa(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new Nt;for(let s of t.viewportLineBlocks){let r=eh(t.state,s.from,s.to)?n:ja(t.state,s.from,s.to)?i:null;r&&e.add(s.from,s.from,r)}return e.finish()}}),{domEventHandlers:r}=e;return[s,$o({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.markers)||It.empty},initialSpacer:()=>new dh(e,!1),domEventHandlers:{...r,click:(t,e,i)=>{if(r.click&&r.click(t,e,i))return!0;let n=eh(t.state,e.from,e.to);if(n)return t.dispatch({effects:Ya.of(n)}),!0;let s=ja(t.state,e.from,e.to);return!!s&&(t.dispatch({effects:Ga.of(s)}),!0)}}}),ah()]}const mh=pr.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class gh{constructor(t,e){let i;function n(t){let e=Jt.newName();return(i||(i=Object.create(null)))["."+e]=t,e}this.specs=t;const s="string"==typeof e.all?e.all:e.all?n(e.all):void 0,r=e.scope;this.scope=r instanceof wa?t=>t.prop(ga)==r.data:r?t=>t==r:void 0,this.style=Gl(t.map(t=>({tag:t.tag,class:t.class||n(Object.assign({},t,{tag:null}))})),{all:s}).style,this.module=i?new Jt(i):null,this.themeType=e.themeType}static define(t,e){return new gh(t,e||{})}}const vh=z.define(),wh=z.define({combine:t=>t.length?[t[0]]:null});function bh(t){let e=t.facet(vh);return e.length?e:t.facet(wh)}function yh(t,e){let i,n=[kh];return t instanceof gh&&(t.module&&n.push(pr.styleModule.of(t.module)),i=t.themeType),(null==e?void 0:e.fallback)?n.push(wh.of(t)):i?n.push(vh.computeN([pr.darkTheme],e=>e.facet(pr.darkTheme)==("dark"==i)?[t]:[])):n.push(vh.of(t)),n}class xh{constructor(t){this.markCache=Object.create(null),this.tree=xa(t.state),this.decorations=this.buildDeco(t,bh(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=xa(t.state),i=bh(t.state),n=i!=bh(t.startState),{viewport:s}=t.view,r=t.changes.mapPos(this.decoratedTo,1);e.length=s.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=r):(e!=this.tree||t.viewportChanged||n)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=s.to)}buildDeco(t,e){if(!e||!this.tree.length)return Te.none;let i=new Nt;for(let{from:n,to:s}of t.visibleRanges)Yl(this.tree,e,(t,e,n)=>{i.add(t,e,this.markCache[n]||(this.markCache[n]=Te.mark({class:n})))},n,s);return i.finish()}}const kh=Z.high(qi.fromClass(xh,{decorations:t=>t.decorations})),Sh=gh.define([{tag:pa.meta,color:"#404740"},{tag:pa.link,textDecoration:"underline"},{tag:pa.heading,textDecoration:"underline",fontWeight:"bold"},{tag:pa.emphasis,fontStyle:"italic"},{tag:pa.strong,fontWeight:"bold"},{tag:pa.strikethrough,textDecoration:"line-through"},{tag:pa.keyword,color:"#708"},{tag:[pa.atom,pa.bool,pa.url,pa.contentSeparator,pa.labelName],color:"#219"},{tag:[pa.literal,pa.inserted],color:"#164"},{tag:[pa.string,pa.deleted],color:"#a11"},{tag:[pa.regexp,pa.escape,pa.special(pa.string)],color:"#e40"},{tag:pa.definition(pa.variableName),color:"#00f"},{tag:pa.local(pa.variableName),color:"#30a"},{tag:[pa.typeName,pa.namespace],color:"#085"},{tag:pa.className,color:"#167"},{tag:[pa.special(pa.variableName),pa.macroName],color:"#256"},{tag:pa.definition(pa.propertyName),color:"#00c"},{tag:pa.comment,color:"#940"},{tag:pa.invalid,color:"#f00"}]),Ch=pr.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Ah="()[]{}",Mh=z.define({combine:t=>Dt(t,{afterCursor:!0,brackets:Ah,maxScanDistance:1e4,renderMatch:Dh})}),Oh=Te.mark({class:"cm-matchingBracket"}),Th=Te.mark({class:"cm-nonmatchingBracket"});function Dh(t){let e=[],i=t.matched?Oh:Th;return e.push(i.range(t.start.from,t.start.to)),t.end&&e.push(i.range(t.end.from,t.end.to)),e}function Rh(t){let e=[],i=t.facet(Mh);for(let n of t.selection.ranges){if(!n.empty)continue;let s=Nh(t,n.head,-1,i)||n.head>0&&Nh(t,n.head-1,1,i)||i.afterCursor&&(Nh(t,n.head,1,i)||n.headt.decorations}),Ch];function Bh(t={}){return[Mh.of(t),Ph]}const Eh=new pl;function Lh(t,e,i){let n=t.prop(e<0?pl.openedBy:pl.closedBy);if(n)return n;if(1==t.name.length){let n=i.indexOf(t.name);if(n>-1&&n%2==(e<0?1:0))return[i[n+e]]}return null}function Ih(t){let e=t.type.prop(Eh);return e?e(t.node):t}function Nh(t,e,i,n={}){let s=n.maxScanDistance||1e4,r=n.brackets||Ah,o=xa(t),l=o.resolveInner(e,i);for(let n=l;n;n=n.parent){let s=Lh(n.type,i,r);if(s&&n.from0?e>=o.from&&eo.from&&e<=o.to))return Wh(t,e,i,n,o,s,r)}}return function(t,e,i,n,s,r,o){if(i<0?!e:e==t.doc.length)return null;let l=i<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=i>0)return null;let h={from:i<0?e-1:e,to:i>0?e+1:e},c=t.doc.iterRange(e,i>0?t.doc.length:0),u=0;for(let t=0;!c.next().done&&t<=r;){let r=c.value;i<0&&(t+=r.length);let l=e+t*i;for(let t=i>0?0:r.length-1,e=i>0?r.length:-1;t!=e;t+=i){let e=o.indexOf(r[t]);if(!(e<0||n.resolveInner(l+t,1).type!=s))if(e%2==0==i>0)u++;else{if(1==u)return{start:h,end:{from:l+t,to:l+t+1},matched:e>>1==a>>1};u--}}i>0&&(t+=r.length)}return c.done?{start:h,matched:!1}:null}(t,e,i,o,l.type,s,r)}function Wh(t,e,i,n,s,r,o){let l=n.parent,a={from:s.from,to:s.to},h=0,c=null==l?void 0:l.cursor();if(c&&(i<0?c.childBefore(n.from):c.childAfter(n.to)))do{if(i<0?c.to<=n.from:c.from>=n.to){if(0==h&&r.indexOf(c.type.name)>-1&&c.from-1||(zh.push(t),console.warn(e))}function Uh(t,e){let i=[];for(let n of e.split(" ")){let e=[];for(let i of n.split(".")){let n=t[i]||pa[i];n?"function"==typeof n?e.length?e=e.map(n):_h(i,`Modifier ${i} used at start of tag`):e.length?_h(i,`Tag ${i} used as modifier`):e=Array.isArray(n)?n:[n]:_h(i,`Unknown highlighting tag ${i}`)}for(let t of e)i.push(t)}if(!i.length)return 0;let n=e.replace(/ /g,"_"),s=n+" "+i.map(t=>t.id),r=Fh[s];if(r)return r.id;let o=Fh[s]=vl.define({id:Vh.length,name:n,props:[Kl({[n]:i})]});return Vh.push(o),o.id}si.RTL,si.LTR;function Qh(t,e){return({state:i,dispatch:n})=>{if(i.readOnly)return!1;let s=t(e,i);return!!s&&(n(i.update(s)),!0)}}const $h=Qh(Jh,0),Kh=Qh(Yh,0),jh=Qh((t,e)=>Yh(t,e,function(t){let e=[];for(let i of t.selection.ranges){let n=t.doc.lineAt(i.from),s=i.to<=n.to?n:t.doc.lineAt(i.to);s.from>n.from&&s.from==i.to&&(s=i.to==n.to+1?n:t.doc.lineAt(i.to-1));let r=e.length-1;r>=0&&e[r].to>n.from?e[r].to=s.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:s.to})}return e}(e)),0);function Xh(t,e){let i=t.languageDataAt("commentTokens",e,1);return i.length?i[0]:{}}const Gh=50;function Yh(t,e,i=e.selection.ranges){let n=i.map(t=>Xh(e,t.from).block);if(!n.every(t=>t))return null;let s=i.map((t,i)=>function(t,{open:e,close:i},n,s){let r,o,l=t.sliceDoc(n-Gh,n),a=t.sliceDoc(s,s+Gh),h=/\s*$/.exec(l)[0].length,c=/^\s*/.exec(a)[0].length,u=l.length-h;if(l.slice(u-e.length,u)==e&&a.slice(c,c+i.length)==i)return{open:{pos:n-h,margin:h&&1},close:{pos:s+c,margin:c&&1}};s-n<=2*Gh?r=o=t.sliceDoc(n,s):(r=t.sliceDoc(n,n+Gh),o=t.sliceDoc(s-Gh,s));let f=/^\s*/.exec(r)[0].length,d=/\s*$/.exec(o)[0].length,p=o.length-d-i.length;return r.slice(f,f+e.length)==e&&o.slice(p,p+i.length)==i?{open:{pos:n+f+e.length,margin:/\s/.test(r.charAt(f+e.length))?1:0},close:{pos:s-d-i.length,margin:/\s/.test(o.charAt(p-1))?1:0}}:null}(e,n[i],t.from,t.to));if(2!=t&&!s.every(t=>t))return{changes:e.changes(i.map((t,e)=>s[e]?[]:[{from:t.from,insert:n[e].open+" "},{from:t.to,insert:" "+n[e].close}]))};if(1!=t&&s.some(t=>t)){let t=[];for(let e,i=0;is&&(t==r||r>a.from)){s=a.from;let t=/^\s*/.exec(a.text)[0].length,e=t==a.length,r=a.text.slice(t,t+i.length)==i?t:-1;tt.comment<0&&(!t.empty||t.single))){let t=[];for(let{line:e,token:i,indent:s,empty:r,single:o}of n)!o&&r||t.push({from:e.from+s,insert:i+" "});let i=e.changes(t);return{changes:i,selection:e.selection.map(i,1)}}if(1!=t&&n.some(t=>t.comment>=0)){let t=[];for(let{line:e,comment:i,token:s}of n)if(i>=0){let n=e.from+i,r=n+s.length;" "==e.text[r-e.from]&&r++,t.push({from:n,to:r})}return{changes:t}}return null}const Zh=dt.define(),tc=dt.define(),ec=z.define(),ic=z.define({combine:t=>Dt(t,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,n)=>t(i,n)||e(i,n)})}),nc=K.define({create:()=>yc.empty,update(t,e){let i=e.state.facet(ic),n=e.annotation(Zh);if(n){let s=cc.fromTransaction(e,n.selection),r=n.side,o=0==r?t.undone:t.done;return o=s?uc(o,o.length,i.minDepth,s):mc(o,e.startState.selection),new yc(0==r?n.rest:o,0==r?o:n.rest)}let s=e.annotation(tc);if("full"!=s&&"before"!=s||(t=t.isolate()),!1===e.annotation(vt.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let r=cc.fromTransaction(e),o=e.annotation(vt.time),l=e.annotation(vt.userEvent);return r?t=t.addChanges(r,o,l,i,e):e.selection&&(t=t.addSelection(e.startState.selection,o,l,i.newGroupDelay)),"full"!=s&&"after"!=s||(t=t.isolate()),t},toJSON:t=>({done:t.done.map(t=>t.toJSON()),undone:t.undone.map(t=>t.toJSON())}),fromJSON:t=>new yc(t.done.map(cc.fromJSON),t.undone.map(cc.fromJSON))});function sc(t={}){return[nc,ic.of(t),pr.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?oc:"historyRedo"==t.inputType?lc:null;return!!i&&(t.preventDefault(),i(e))}})]}function rc(t,e){return function({state:i,dispatch:n}){if(!e&&i.readOnly)return!1;let s=i.field(nc,!1);if(!s)return!1;let r=s.pop(t,i,e);return!!r&&(n(r),!0)}}const oc=rc(0,!1),lc=rc(1,!1),ac=rc(0,!0),hc=rc(1,!0);class cc{constructor(t,e,i,n,s){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=n,this.selectionsAfter=s}setSelAfter(t){return new cc(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:null===(t=this.changes)||void 0===t?void 0:t.toJSON(),mapped:null===(e=this.mapped)||void 0===e?void 0:e.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(t=>t.toJSON())}}static fromJSON(t){return new cc(t.changes&&D.fromJSON(t.changes),[],t.mapped&&T.fromJSON(t.mapped),t.startSelection&&W.fromJSON(t.startSelection),t.selectionsAfter.map(W.fromJSON))}static fromTransaction(t,e){let i=dc;for(let e of t.startState.facet(ec)){let n=e(t);n.length&&(i=i.concat(n))}return!i.length&&t.changes.empty?null:new cc(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,dc)}static selection(t){return new cc(void 0,dc,void 0,void 0,t)}}function uc(t,e,i,n){let s=e+1>i+20?e-i-1:0,r=t.slice(s,e);return r.push(n),r}function fc(t,e){return t.length?e.length?t.concat(e):t:e}const dc=[],pc=200;function mc(t,e){if(t.length){let i=t[t.length-1],n=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-pc));return n.length&&n[n.length-1].eq(e)?t:(n.push(e),uc(t,t.length-1,1e9,i.setSelAfter(n)))}return[cc.selection([e])]}function gc(t){let e=t[t.length-1],i=t.slice();return i[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),i}function vc(t,e){if(!t.length)return t;let i=t.length,n=dc;for(;i;){let s=wc(t[i-1],e,n);if(s.changes&&!s.changes.empty||s.effects.length){let e=t.slice(0,i);return e[i-1]=s,e}e=s.mapped,i--,n=s.selectionsAfter}return n.length?[cc.selection(n)]:dc}function wc(t,e,i){let n=fc(t.selectionsAfter.length?t.selectionsAfter.map(t=>t.map(e)):dc,i);if(!t.changes)return cc.selection(n);let s=t.changes.map(e),r=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(r):r;return new cc(s,gt.mapEffects(t.effects,e),o,t.startSelection.map(r),n)}const bc=/^(input\.type|delete)($|\.)/;class yc{constructor(t,e,i=0,n=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new yc(this.done,this.undone):this}addChanges(t,e,i,n,s){let r=this.done,o=r[r.length-1];return r=o&&o.changes&&!o.changes.empty&&t.changes&&(!i||bc.test(i))&&(!o.selectionsAfter.length&&e-this.prevTimei.push(t,e)),e.iterChangedRanges((t,e,s,r)=>{for(let t=0;t=e&&s<=o&&(n=!0)}}),n}(o.changes,t.changes))||"input.type.compose"==i)?uc(r,r.length-1,n.minDepth,new cc(t.changes.compose(o.changes),fc(gt.mapEffects(t.effects,o.changes),o.effects),o.mapped,o.startSelection,dc)):uc(r,r.length,n.minDepth,t),new yc(r,dc,e,i)}addSelection(t,e,i,n){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:dc;return s.length>0&&e-this.prevTimet.empty!=o.ranges[e].empty).length)?this:new yc(mc(this.done,t),this.undone,e,i);var r,o}addMapping(t){return new yc(vc(this.done,t),vc(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let n=0==t?this.done:this.undone;if(0==n.length)return null;let s=n[n.length-1],r=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):e.selection);if(i&&s.selectionsAfter.length)return e.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:Zh.of({side:t,rest:gc(n),selection:r}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let i=1==n.length?dc:n.slice(0,n.length-1);return s.mapped&&(i=vc(i,s.mapped)),e.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:Zh.of({side:t,rest:i,selection:r}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}yc.empty=new yc(dc,dc);const xc=[{key:"Mod-z",run:oc,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:lc,preventDefault:!0},{linux:"Ctrl-Shift-z",run:lc,preventDefault:!0},{key:"Mod-u",run:ac,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:hc,preventDefault:!0}];function kc(t,e){return W.create(t.ranges.map(e),t.mainIndex)}function Sc(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Cc({state:t,dispatch:e},i){let n=kc(t.selection,i);return!n.eq(t.selection,!0)&&(e(Sc(t,n)),!0)}function Ac(t,e){return W.cursor(e?t.to:t.from)}function Mc(t,e){return Cc(t,i=>i.empty?t.moveByChar(i,e):Ac(i,e))}function Oc(t){return t.textDirectionAt(t.state.selection.main.head)==si.LTR}const Tc=t=>Mc(t,!Oc(t)),Dc=t=>Mc(t,Oc(t));function Rc(t,e){return Cc(t,i=>i.empty?t.moveByGroup(i,e):Ac(i,e))}function Pc(t,e,i){if(e.type.prop(i))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function Bc(t,e,i){let n,s,r=xa(t).resolveInner(e.head),o=i?pl.closedBy:pl.openedBy;for(let n=e.head;;){let e=i?r.childAfter(n):r.childBefore(n);if(!e)break;Pc(t,e,o)?r=e:n=i?e.to:e.from}return s=r.type.prop(o)&&(n=i?Nh(t,r.from,1):Nh(t,r.to,-1))&&n.matched?i?n.end.to:n.end.from:i?r.to:r.from,W.cursor(s,i?-1:1)}function Ec(t,e){return Cc(t,i=>{if(!i.empty)return Ac(i,e);let n=t.moveVertically(i,e);return n.head!=i.head?n:t.moveToLineBoundary(i,e)})}const Lc=t=>Ec(t,!1),Ic=t=>Ec(t,!0);function Nc(t){let e,i=t.scrollDOM.clientHeighti.empty?t.moveVertically(i,e,n.height):Ac(i,e));if(r.eq(s.selection))return!1;if(n.selfScroll){let e=t.coordsAtPos(s.selection.main.head),o=t.scrollDOM.getBoundingClientRect(),l=o.top+n.marginTop,a=o.bottom-n.marginBottom;e&&e.top>l&&e.bottomWc(t,!1),Vc=t=>Wc(t,!0);function zc(t,e,i){let n=t.lineBlockAt(e.head),s=t.moveToLineBoundary(e,i);if(s.head==e.head&&s.head!=(i?n.to:n.from)&&(s=t.moveToLineBoundary(e,i,!1)),!i&&s.head==n.from&&n.length){let i=/^\s*/.exec(t.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;i&&e.head!=n.from+i&&(s=W.cursor(n.from+i))}return s}function Fc(t,e,i){let n=kc(t.state.selection,t=>{t.undirectional&&t.head>=t.anchor!=e&&(t=W.range(t.head,t.anchor));let n=i(t);return W.range(t.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return!n.eq(t.state.selection)&&(t.dispatch(Sc(t.state,n)),!0)}function qc(t,e){return Fc(t,e,i=>t.moveByChar(i,e))}const _c=t=>qc(t,!Oc(t)),Uc=t=>qc(t,Oc(t));function Qc(t,e){return Fc(t,e,i=>t.moveByGroup(i,e))}function $c(t,e){return Fc(t,e,i=>t.moveVertically(i,e))}const Kc=t=>$c(t,!1),jc=t=>$c(t,!0);function Xc(t,e){return Fc(t,e,i=>t.moveVertically(i,e,Nc(t).height))}const Gc=t=>Xc(t,!1),Yc=t=>Xc(t,!0),Jc=({state:t,dispatch:e})=>(e(Sc(t,{anchor:0})),!0),Zc=({state:t,dispatch:e})=>(e(Sc(t,{anchor:t.doc.length})),!0),tu=({state:t,dispatch:e})=>(e(Sc(t,{anchor:t.selection.main.anchor,head:0})),!0),eu=({state:t,dispatch:e})=>(e(Sc(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function iu(t,e){let{state:i}=t,n=i.selection,s=i.selection.ranges.slice();for(let n of i.selection.ranges){let r=i.doc.lineAt(n.head);if(e?r.to0)for(let i=n;;){let n=t.moveVertically(i,e);if(n.headr.to){s.some(t=>t.head==n.head)||s.push(n);break}if(n.head==i.head)break;i=n}}return s.length!=n.ranges.length&&(t.dispatch(Sc(i,W.create(s,s.length-1))),!0)}function nu(t,e){if(t.state.readOnly)return!1;let i="delete.selection",{state:n}=t,s=n.changeByRange(n=>{let{from:s,to:r}=n;if(s==r){let o=e(n);os&&(i="delete.forward",o=su(t,o,!0)),s=Math.min(s,o),r=Math.max(r,o)}else s=su(t,s,!1),r=su(t,r,!0);return s==r?{range:n}:{changes:{from:s,to:r},range:W.cursor(s,se(t)))n.between(e,e,(t,n)=>{te&&(e=i?n:t)});return e}const ru=(t,e,i)=>nu(t,n=>{let s,r,o=n.from,{state:l}=t,a=l.doc.lineAt(o);if(i&&!e&&o>a.from&&oru(t,!1,!0),lu=t=>ru(t,!0,!1),au=(t,e)=>nu(t,i=>{let n=i.head,{state:s}=t,r=s.doc.lineAt(n),o=s.charCategorizer(n);for(let t=null;;){if(n==(e?r.to:r.from)){n==i.head&&r.number!=(e?s.doc.lines:1)&&(n+=e?1:-1);break}let l=k(r.text,n-r.from,e)+r.from,a=r.text.slice(Math.min(n,l)-r.from,Math.max(n,l)-r.from),h=o(a);if(null!=t&&h!=t)break;" "==a&&n==i.head||(t=h),n=l}return n}),hu=t=>au(t,!1);function cu(t){let e=[],i=-1;for(let n of t.selection.ranges){let s=t.doc.lineAt(n.from),r=t.doc.lineAt(n.to);if(n.empty||n.to!=r.from||(r=t.doc.lineAt(n.to-1)),i>=s.number){let t=e[e.length-1];t.to=r.to,t.ranges.push(n)}else e.push({from:s.from,to:r.to,ranges:[n]});i=r.number+1}return e}function uu(t,e,i){if(t.readOnly)return!1;let n=[],s=[];for(let e of cu(t)){if(i?e.to==t.doc.length:0==e.from)continue;let r=t.doc.lineAt(i?e.to+1:e.from-1),o=r.length+1;if(i){n.push({from:e.to,to:r.to},{from:e.from,insert:r.text+t.lineBreak});for(let i of e.ranges)s.push(W.range(Math.min(t.doc.length,i.anchor+o),Math.min(t.doc.length,i.head+o)))}else{n.push({from:r.from,to:e.from},{from:e.to,insert:t.lineBreak+r.text});for(let t of e.ranges)s.push(W.range(t.anchor-o,t.head-o))}}return!!n.length&&(e(t.update({changes:n,scrollIntoView:!0,selection:W.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0)}function fu(t,e,i){if(t.readOnly)return!1;let n=[];for(let e of cu(t))i?n.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):n.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});let s=t.changes(n);return e(t.update({changes:s,selection:t.selection.map(s,i?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const du=pu(!1);function pu(t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let n=e.changeByRange(i=>{let{from:n,to:s}=i,r=e.doc.lineAt(n),o=!t&&n==s&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,n=xa(t).resolveInner(e),s=n.childBefore(e),r=n.childAfter(e);return s&&r&&s.to<=e&&r.from>=e&&(i=s.type.prop(pl.closedBy))&&i.indexOf(r.name)>-1&&t.doc.lineAt(s.to).from==t.doc.lineAt(r.from).from&&!/\S/.test(t.sliceDoc(s.to,r.from))?{from:s.to,to:r.from}:null}(e,n);t&&(n=s=(s<=r.to?r:e.doc.lineAt(s)).to);let l=new Wa(e,{simulateBreak:n,simulateDoubleBreak:!!o}),a=Na(l,n);for(null==a&&(a=Kt(/^\s*/.exec(e.doc.lineAt(n).text)[0],e.tabSize));sr.from&&n{let s=[];for(let r=n.from;r<=n.to;){let o=t.doc.lineAt(r);o.number>i&&(n.empty||n.to>o.from)&&(e(o,s,n),i=o.number),r=o.to+1}let r=t.changes(s);return{changes:s,range:W.range(r.mapPos(n.anchor,1),r.mapPos(n.head,1))}})}const gu=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:t=>Cc(t,e=>Bc(t.state,e,!Oc(t))),shift:t=>{let e=!Oc(t);return Fc(t,e,i=>Bc(t.state,i,e))}},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>Cc(t,e=>Bc(t.state,e,Oc(t))),shift:t=>{let e=Oc(t);return Fc(t,e,i=>Bc(t.state,i,e))}},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>uu(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>fu(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>uu(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>fu(t,e,!0)},{key:"Mod-Alt-ArrowUp",run:t=>iu(t,!1)},{key:"Mod-Alt-ArrowDown",run:t=>iu(t,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,n=null;return i.ranges.length>1?n=W.create([i.main]):i.main.empty||(n=W.create([W.cursor(i.main.head)])),!!n&&(e(Sc(t,n)),!0)}},{key:"Mod-Enter",run:pu(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=cu(t).map(({from:e,to:i})=>W.range(e,Math.min(i+1,t.doc.length)));return e(t.update({selection:W.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=kc(t.selection,e=>{let i=xa(t),n=i.resolveStack(e.from,1);if(e.empty){let t=i.resolveStack(e.from,-1);t.node.from>=n.node.from&&t.node.to<=n.node.to&&(n=t)}for(let t=n;t;t=t.next){let{node:i}=t;if((i.from=e.to||i.to>e.to&&i.from<=e.from)&&t.next)return W.range(i.to,i.from)}return e});return!i.eq(t.selection)&&(e(Sc(t,i)),!0)},preventDefault:!0},{key:"Mod-[",run:({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(mu(t,(e,i)=>{let n=/^\s*/.exec(e.text)[0];if(!n)return;let s=Kt(n,t.tabSize),r=0,o=Ia(t,Math.max(0,s-La(t)));for(;r!t.readOnly&&(e(t.update(mu(t,(e,i)=>{i.push({from:e.from,insert:t.facet(Ea)})}),{userEvent:"input.indent"})),!0)},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),n=new Wa(t,{overrideIndentation:t=>{let e=i[t];return null==e?-1:e}}),s=mu(t,(e,s,r)=>{let o=Na(n,e.from);if(null==o)return;/\S/.test(e.text)||(o=0);let l=/^\s*/.exec(e.text)[0],a=Ia(t,o);(l!=a||r.from{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes(cu(e).map(({from:t,to:i})=>(t>0?t--:i{let i;if(t.lineWrapping){let n=t.lineBlockAt(e.head),s=t.coordsAtPos(e.head,e.assoc||1);s&&(i=n.bottom+t.documentTop-s.bottom+t.defaultLineHeight/2)}return t.moveVertically(e,!0,i)}).map(i);return t.dispatch({changes:i,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>function(t,e,i){let n=!1,s=kc(t.selection,e=>{let s=Nh(t,e.head,-1)||Nh(t,e.head,1)||e.head>0&&Nh(t,e.head-1,1)||e.head{let{state:e}=t,i=e.doc.lineAt(e.selection.main.from),n=Xh(t.state,i.from);return n.line?$h(t):!!n.block&&jh(t)}},{key:"Alt-A",run:Kh},{key:"Ctrl-m",mac:"Shift-Alt-m",run:t=>(t.setTabFocusMode(),!0)}].concat([{key:"ArrowLeft",run:Tc,shift:_c,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:t=>Rc(t,!Oc(t)),shift:t=>Qc(t,!Oc(t)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:t=>Cc(t,e=>zc(t,e,!Oc(t))),shift:t=>{let e=!Oc(t);return Fc(t,e,i=>zc(t,i,e))},preventDefault:!0},{key:"ArrowRight",run:Dc,shift:Uc,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>Rc(t,Oc(t)),shift:t=>Qc(t,Oc(t)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:t=>Cc(t,e=>zc(t,e,Oc(t))),shift:t=>{let e=Oc(t);return Fc(t,e,i=>zc(t,i,e))},preventDefault:!0},{key:"ArrowUp",run:Lc,shift:Kc,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Jc,shift:tu},{mac:"Ctrl-ArrowUp",run:Hc,shift:Gc},{key:"ArrowDown",run:Ic,shift:jc,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Zc,shift:eu},{mac:"Ctrl-ArrowDown",run:Vc,shift:Yc},{key:"PageUp",run:Hc,shift:Gc},{key:"PageDown",run:Vc,shift:Yc},{key:"Home",run:t=>Cc(t,e=>zc(t,e,!1)),shift:t=>Fc(t,!1,e=>zc(t,e,!1)),preventDefault:!0},{key:"Mod-Home",run:Jc,shift:tu},{key:"End",run:t=>Cc(t,e=>zc(t,e,!0)),shift:t=>Fc(t,!0,e=>zc(t,e,!0)),preventDefault:!0},{key:"Mod-End",run:Zc,shift:eu},{key:"Enter",run:du,shift:du},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:ou,shift:ou,preventDefault:!0},{key:"Delete",run:lu,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:hu,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>au(t,!0),preventDefault:!0},{mac:"Mod-Backspace",run:t=>nu(t,e=>{let i=t.moveToLineBoundary(e,!1).head;return e.head>i?i:Math.max(0,e.head-1)}),preventDefault:!0},{mac:"Mod-Delete",run:t=>nu(t,e=>{let i=t.moveToLineBoundary(e,!0).head;return e.headCc(t,e=>W.cursor(t.lineBlockAt(e.head).from,1)),shift:t=>Fc(t,!1,e=>W.cursor(t.lineBlockAt(e.head).from))},{key:"Ctrl-e",run:t=>Cc(t,e=>W.cursor(t.lineBlockAt(e.head).to,-1)),shift:t=>Fc(t,!0,e=>W.cursor(t.lineBlockAt(e.head).to))},{key:"Ctrl-d",run:lu},{key:"Ctrl-h",run:ou},{key:"Ctrl-k",run:t=>nu(t,e=>{let i=t.lineBlockAt(e.head).to;return e.head{if(t.readOnly)return!1;let i=t.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:f.of(["",""])},range:W.cursor(t.from)}));return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange(e=>{if(!e.empty||0==e.from||e.from==t.doc.length)return{range:e};let i=e.from,n=t.doc.lineAt(i),s=i==n.from?i-1:k(n.text,i-n.from,!1)+n.from,r=i==n.to?i+1:k(n.text,i-n.from,!0)+n.from;return{changes:{from:s,to:r,insert:t.doc.slice(i,r).append(t.doc.slice(s,i))},range:W.cursor(r)}});return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:Vc}].map(t=>({mac:t.key,run:t.run,shift:t.shift})))),vu="function"==typeof String.prototype.normalize?t=>t.normalize("NFKD"):t=>t;class wu{constructor(t,e,i=0,n=t.length,s,r){this.test=r,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,n),this.bufferStart=i,this.normalize=s?t=>s(vu(t)):vu,this.query=this.normalize(e)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return S(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=C(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=A(t);let n=this.normalize(e);if(n.length)for(let t=0,s=i,r=!0;;t++){let i=n.charCodeAt(t),o=this.match(i,s,r,this.bufferPos+this.bufferStart,t==n.length-1);if(o)return this.value=o,this;if(t==n.length-1)break;r&&tthis.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,n=i+e[0].length;if(this.matchPos=Au(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(ithis.value.to)&&(!this.test||this.test(i,n,e)))return this.value={from:i,to:n,precise:!0,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length=i||n.to<=e){let n=new Su(e,t.sliceString(e,i));return ku.set(t,n),n}if(n.from==e&&n.to==i)return n;let{text:s,from:r}=n;return r>e&&(s=t.sliceString(e,r)+s,r=e),n.to=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e){let t=this.flat.from+e.index,i=t+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(t,i,e)))return this.value={from:t,to:i,precise:!0,match:e},this.matchPos=Au(this.text,i+(t==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Su.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function Au(t,e){if(e>=t.length)return e;let i,n=t.lineAt(e);for(;e=56320&&i<57344;)e++;return e}"undefined"!=typeof Symbol&&(xu.prototype[Symbol.iterator]=Cu.prototype[Symbol.iterator]=function(){return this});const Mu={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Ou=z.define({combine:t=>Dt(t,Mu,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});function Tu(t){let e=[Eu,Bu];return t&&e.push(Ou.of(t)),e}const Du=Te.mark({class:"cm-selectionMatch"}),Ru=Te.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Pu(t,e,i,n){return!(0!=i&&t(e.sliceDoc(i-1,i))==Ct.Word||n!=e.doc.length&&t(e.sliceDoc(n,n+1))==Ct.Word)}const Bu=qi.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(Ou),{state:i}=t,n=i.selection;if(n.ranges.length>1)return Te.none;let s,r=n.main,o=null;if(r.empty){if(!e.highlightWordAroundCursor)return Te.none;let t=i.wordAt(r.head);if(!t)return Te.none;o=i.charCategorizer(r.head),s=i.sliceDoc(t.from,t.to)}else{let t=r.to-r.from;if(t200)return Te.none;if(e.wholeWords){if(s=i.sliceDoc(r.from,r.to),o=i.charCategorizer(r.head),!Pu(o,i,r.from,r.to)||!function(t,e,i,n){return t(e.sliceDoc(i,i+1))==Ct.Word&&t(e.sliceDoc(n-1,n))==Ct.Word}(o,i,r.from,r.to))return Te.none}else if(s=i.sliceDoc(r.from,r.to),!s)return Te.none}let l=[];for(let n of t.visibleRanges){let t=new wu(i.doc,s,n.from,n.to);for(;!t.next().done;){let{from:n,to:s}=t.value;if((!o||Pu(o,i,n,s))&&(r.empty&&n<=r.from&&s>=r.to?l.push(Ru.range(n,s)):(n>=r.to||s<=r.from)&&l.push(Du.range(n,s)),l.length>e.maxMatches))return Te.none}}return Te.set(l)}},{decorations:t=>t.decorations}),Eu=pr.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const Lu=z.define({combine:t=>Dt(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new cf(t),scrollToMatch:t=>pr.scrollIntoView(t)})});class Iu{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,yu),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(t,e)=>"n"==e?"\n":"r"==e?"\r":"t"==e?"\t":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new qu(this):new Hu(this)}getCursor(t,e=0,i){let n=t.doc?t:Tt.create({doc:t});return null==i&&(i=n.doc.length),this.regexp?Vu(this,n,e,i):Wu(this,n,e,i)}}class Nu{constructor(t){this.spec=t}}function Wu(t,e,i,n){let s;return t.wholeWord&&(s=function(t,e){return(i,n,s,r)=>((r>i||r+s.length{if(i&&!i(n,s,r,o))return!1;let l=n>=o&&s<=o+r.length?r.slice(n-o,s-o):e.doc.sliceString(n,s);return t(l,e,n,s)}}(t.test,e,s)),new wu(e.doc,t.unquoted,i,n,t.caseSensitive?void 0:t=>t.toLowerCase(),s)}class Hu extends Nu{constructor(t){super(t)}nextMatch(t,e,i){let n=Wu(this.spec,t,i,t.doc.length).nextOverlapping();if(n.done){let i=Math.min(t.doc.length,e+this.spec.unquoted.length);n=Wu(this.spec,t,0,i).nextOverlapping()}return n.done||n.value.from==e&&n.value.to==i?null:n.value}prevMatchInRange(t,e,i){for(let n=i;;){let i=Math.max(e,n-1e4-this.spec.unquoted.length),s=Wu(this.spec,t,i,n),r=null;for(;!s.nextOverlapping().done;)r=s.value;if(r)return r;if(i==e)return null;n-=1e4}}prevMatch(t,e,i){let n=this.prevMatchInRange(t,0,e);return n||(n=this.prevMatchInRange(t,Math.max(0,i-this.spec.unquoted.length),t.doc.length)),!n||n.from==e&&n.to==i?null:n}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,e){let i=Wu(this.spec,t,0,t.doc.length),n=[];for(;!i.next().done;){if(n.length>=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=Wu(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}function Vu(t,e,i,n){let s;var r;return t.wholeWord&&(r=e.charCategorizer(e.selection.main.head),s=(t,e,i)=>!i[0].length||(r(zu(i.input,i.index))!=Ct.Word||r(Fu(i.input,i.index))!=Ct.Word)&&(r(Fu(i.input,i.index+i[0].length))!=Ct.Word||r(zu(i.input,i.index+i[0].length))!=Ct.Word)),t.test&&(s=function(t,e,i){return(n,s,r)=>(!i||i(n,s,r))&&t(r[0],e,n,s)}(t.test,e,s)),new xu(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:s},i,n)}function zu(t,e){return t.slice(k(t,e,!1),e)}function Fu(t,e){return t.slice(e,k(t,e))}class qu extends Nu{nextMatch(t,e,i){let n=Vu(this.spec,t,i,t.doc.length).next();return n.done&&(n=Vu(this.spec,t,0,e).next()),n.done?null:n.value}prevMatchInRange(t,e,i){for(let n=1;;n++){let s=Math.max(e,i-1e4*n),r=Vu(this.spec,t,s,i),o=null;for(;!r.next().done;)o=r.value;if(o&&(s==e||o.from>s+10))return o;if(s==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(e,i)=>{if("&"==i)return t.match[0];if("$"==i)return"$";for(let e=i.length;e>0;e--){let n=+i.slice(0,e);if(n>0&&n=e)return null;n.push(i.value)}return n}highlight(t,e,i,n){let s=Vu(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!s.next().done;)n(s.value.from,s.value.to)}}const _u=gt.define(),Uu=gt.define(),Qu=K.define({create:t=>new $u(sf(t).create(),null),update(t,e){for(let i of e.effects)i.is(_u)?t=new $u(i.value.create(),t.panel):i.is(Uu)&&(t=new $u(t.query,i.value?nf:null));return t},provide:t=>No.from(t,t=>t.panel)});class $u{constructor(t,e){this.query=t,this.panel=e}}const Ku=Te.mark({class:"cm-searchMatch"}),ju=Te.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Xu=qi.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Qu))}update(t){let e=t.state.field(Qu);(e!=t.startState.field(Qu)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return Te.none;let{view:i}=this,n=new Nt;for(let e=0,s=i.visibleRanges,r=s.length;es[e+1].from-500;)l=s[++e].to;t.highlight(i.state,o,l,(t,e)=>{let s=i.state.selection.ranges.some(i=>i.from==t&&i.to==e);n.add(t,e,s?ju:Ku)})}return n.finish()}},{decorations:t=>t.decorations});function Gu(t){return e=>{let i=e.state.field(Qu,!1);return i&&i.query.spec.valid?t(e,i):lf(e)}}const Yu=Gu((t,{query:e})=>{let{to:i}=t.state.selection.main,n=e.nextMatch(t.state,i,i);if(!n)return!1;let s=W.single(n.from,n.to),r=t.state.facet(Lu);return t.dispatch({selection:s,effects:[pf(t,n),r.scrollToMatch(s.main,t)],userEvent:"select.search"}),of(t),!0}),Ju=Gu((t,{query:e})=>{let{state:i}=t,{from:n}=i.selection.main,s=e.prevMatch(i,n,n);if(!s)return!1;let r=W.single(s.from,s.to),o=t.state.facet(Lu);return t.dispatch({selection:r,effects:[pf(t,s),o.scrollToMatch(r.main,t)],userEvent:"select.search"}),of(t),!0}),Zu=Gu((t,{query:e})=>{let i=e.matchAll(t.state,1e3);return!(!i||!i.length)&&(t.dispatch({selection:W.create(i.map(t=>W.range(t.from,t.to))),userEvent:"select.search.matches"}),!0)}),tf=Gu((t,{query:e})=>{let{state:i}=t,{from:n,to:s}=i.selection.main;if(i.readOnly)return!1;let r=e.nextMatch(i,n,n);if(!r)return!1;let o,l,a=r,h=[],c=[];a.precise?a.from==n&&a.to==s&&(l=i.toText(e.getReplacement(a)),h.push({from:a.from,to:a.to,insert:l}),a=e.nextMatch(i,a.from,a.to),c.push(pr.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(n).number)+"."))):a=e.nextMatch(i,a.from,a.to);let u=t.state.changes(h);return a&&(o=W.single(a.from,a.to).map(u),c.push(pf(t,a)),c.push(i.facet(Lu).scrollToMatch(o.main,t))),t.dispatch({changes:u,selection:o,effects:c,userEvent:"input.replace"}),!0}),ef=Gu((t,{query:e})=>{if(t.state.readOnly)return!1;let i=[];for(let n of e.matchAll(t.state,1e9)){let{from:t,to:s,precise:r}=n;r&&i.push({from:t,to:s,insert:e.getReplacement(n)})}if(!i.length)return!1;let n=t.state.phrase("replaced $ matches",i.length)+".";return t.dispatch({changes:i,effects:pr.announce.of(n),userEvent:"input.replace.all"}),!0});function nf(t){return t.state.facet(Lu).createPanel(t)}function sf(t,e){var i,n,s,r,o;let l=t.selection.main,a=l.empty||l.to>l.from+100?"":t.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=t.facet(Lu);return new Iu({search:(null!==(i=null==e?void 0:e.literal)&&void 0!==i?i:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:null!==(n=null==e?void 0:e.caseSensitive)&&void 0!==n?n:h.caseSensitive,literal:null!==(s=null==e?void 0:e.literal)&&void 0!==s?s:h.literal,regexp:null!==(r=null==e?void 0:e.regexp)&&void 0!==r?r:h.regexp,wholeWord:null!==(o=null==e?void 0:e.wholeWord)&&void 0!==o?o:h.wholeWord})}function rf(t){let e=Bo(t,nf);return e&&e.dom.querySelector("[main-field]")}function of(t){let e=rf(t);e&&e==t.root.activeElement&&e.select()}const lf=t=>{let e=t.state.field(Qu,!1);if(e&&e.panel){let i=rf(t);if(i&&i!=t.root.activeElement){let n=sf(t.state,e.query.spec);n.valid&&t.dispatch({effects:_u.of(n)}),i.focus(),i.select()}}else t.dispatch({effects:[Uu.of(!0),e?_u.of(sf(t.state,e.query.spec)):gt.appendConfig.of(gf)]});return!0},af=t=>{let e=t.state.field(Qu,!1);if(!e||!e.panel)return!1;let i=Bo(t,nf);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Uu.of(!1)}),!0},hf=[{key:"Mod-f",run:lf,scope:"editor search-panel"},{key:"F3",run:Yu,shift:Ju,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Yu,shift:Ju,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:af,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:t,dispatch:e})=>{let i=t.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:n,to:s}=i.main,r=[],o=0;for(let e=new wu(t.doc,t.sliceDoc(n,s));!e.next().done;){if(r.length>1e3)return!1;e.value.from==n&&(o=r.length),r.push(W.range(e.value.from,e.value.to))}return e(t.update({selection:W.create(r,o),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:t=>{let{state:e}=t,i=String(e.doc.lineAt(t.state.selection.main.head).number),{close:n,result:s}=Wo(t,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:i},focus:!0,submitLabel:e.phrase("go")});return s.then(i=>{let s=i&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(i.elements.line.value);if(!s)return void t.dispatch({effects:n});let r=e.doc.lineAt(e.selection.main.head),[,o,l,a,h]=s,c=a?+a.slice(1):0,u=l?+l:r.number;if(l&&h){let t=u/100;o&&(t=t*("-"==o?-1:1)+r.number/e.doc.lines),u=Math.round(e.doc.lines*t)}else l&&o&&(u=u*("-"==o?-1:1)+r.number);let f=e.doc.line(Math.max(1,Math.min(e.doc.lines,u))),d=W.cursor(f.from+Math.max(0,Math.min(c,f.length)));t.dispatch({effects:[n,pr.scrollIntoView(d.from,{y:"center"})],selection:d})}),!0}},{key:"Mod-d",run:({state:t,dispatch:e})=>{let{ranges:i}=t.selection;if(i.some(t=>t.from===t.to))return(({state:t,dispatch:e})=>{let{selection:i}=t,n=W.create(i.ranges.map(e=>t.wordAt(e.head)||W.cursor(e.head)),i.mainIndex);return!n.eq(i)&&(e(t.update({selection:n})),!0)})({state:t,dispatch:e});let n=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some(e=>t.sliceDoc(e.from,e.to)!=n))return!1;let s=function(t,e){let{main:i,ranges:n}=t.selection,s=t.wordAt(i.head),r=s&&s.from==i.from&&s.to==i.to;for(let i=!1,s=new wu(t.doc,e,n[n.length-1].to);;){if(s.next(),!s.done){if(i&&n.some(t=>t.from==s.value.from))continue;if(r){let e=t.wordAt(s.value.from);if(!e||e.from!=s.value.from||e.to!=s.value.to)continue}return s.value}if(i)return null;s=new wu(t.doc,e,0,Math.max(0,n[n.length-1].from-1)),i=!0}}(t,n);return!!s&&(e(t.update({selection:t.selection.addRange(W.range(s.from,s.to),!1),effects:pr.scrollIntoView(s.to)})),!0)},preventDefault:!0}];class cf{constructor(t){this.view=t;let e=this.query=t.state.field(Qu).query.spec;function i(t,e,i){return le("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=le("input",{value:e.search,placeholder:uf(t,"Find"),"aria-label":uf(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=le("input",{value:e.replace,placeholder:uf(t,"Replace"),"aria-label":uf(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=le("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=le("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=le("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit}),this.dom=le("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",()=>Yu(t),[uf(t,"next")]),i("prev",()=>Ju(t),[uf(t,"previous")]),i("select",()=>Zu(t),[uf(t,"all")]),le("label",null,[this.caseField,uf(t,"match case")]),le("label",null,[this.reField,uf(t,"regexp")]),le("label",null,[this.wordField,uf(t,"by word")]),...t.state.readOnly?[]:[le("br"),this.replaceField,i("replace",()=>tf(t),[uf(t,"replace")]),i("replaceAll",()=>ef(t),[uf(t,"replace all")])],le("button",{name:"close",onclick:()=>af(t),"aria-label":uf(t,"close"),type:"button"},["×"])])}commit(){let t=new Iu({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:_u.of(t)}))}keydown(t){var e,i,n;e=this.view,i=t,n="search-panel",Tr(Cr(e.state),i,e,n)?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Ju:Yu)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),tf(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(_u)&&!t.value.eq(this.query)&&this.setQuery(t.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Lu).top}}function uf(t,e){return t.state.phrase(e)}const ff=30,df=/[\s\.,:;?!]/;function pf(t,{from:e,to:i}){let n=t.state.doc.lineAt(e),s=t.state.doc.lineAt(i).to,r=Math.max(n.from,e-ff),o=Math.min(s,i+ff),l=t.state.sliceDoc(r,o);if(r!=n.from)for(let t=0;tl.length-ff;t--)if(!df.test(l[t-1])&&df.test(l[t])){l=l.slice(0,t);break}return pr.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${n.number}.`)}const mf=pr.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),gf=[Qu,Z.low(Xu),mf];class vf{constructor(t,e,i,n){this.state=t,this.pos=e,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let e=xa(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),n=e.text.slice(i-e.from,this.pos-e.from),s=n.search(kf(t,!1));return s<0?null:{from:i+s,to:this.pos,text:n.slice(s)}}get aborted(){return null==this.abortListeners}addEventListener(t,e,i){"abort"==t&&this.abortListeners&&(this.abortListeners.push(e),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function wf(t){let e=Object.keys(t).join(""),i=/\w/.test(e);return i&&(e=e.replace(/\w/g,"")),`[${i?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function bf(t){let e=t.map(t=>"string"==typeof t?{label:t}:t),[i,n]=e.every(t=>/^\w+$/.test(t.label))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),i=Object.create(null);for(let{label:n}of t){e[n[0]]=!0;for(let t=1;t{let s=t.matchBefore(n);return s||t.explicit?{from:s?s.from:t.pos,options:e,validFor:i}:null}}class yf{constructor(t,e,i,n){this.completion=t,this.source=e,this.match=i,this.score=n}}function xf(t){return t.selection.main.from}function kf(t,e){var i;let{source:n}=t,s=e&&"^"!=n[0],r="$"!=n[n.length-1];return s||r?new RegExp(`${s?"^":""}(?:${n})${r?"$":""}`,null!==(i=t.flags)&&void 0!==i?i:t.ignoreCase?"i":""):t}const Sf=dt.define();function Cf(t,e,i,n){let{main:s}=t.selection,r=i-s.from,o=n-s.from;return{...t.changeByRange(l=>{if(l!=s&&i!=n&&t.sliceDoc(l.from+r,l.from+o)!=t.sliceDoc(i,n))return{range:l};let a=t.toText(e);return{changes:{from:l.from+r,to:n==s.from?l.to:l.from+o,insert:a},range:W.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const Af=new WeakMap;function Mf(t){if(!Array.isArray(t))return t;let e=Af.get(t);return e||Af.set(t,e=bf(t)),e}const Of=gt.define(),Tf=gt.define();class Df{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e=48&&a<=57||a>=97&&a<=122?2:a>=65&&a<=90?1:0:(w=C(a))!=w.toLowerCase()?1:w!=w.toUpperCase()?2:0;(!n||1==b&&m||0==v&&0!=b)&&(e[c]==a||i[c]==a&&(u=!0)?r[c++]=n:r.length&&(g=!1)),v=b,n+=A(a)}return c==l&&0==r[0]&&g?this.result((u?-200:0)-100,r,t):f==l&&0==d?this.ret(-200-t.length+(p==t.length?0:-100),[0,p]):o>-1?this.ret(-700-t.length,[o,o+this.pattern.length]):f==l?this.ret(-900-t.length,[d,p]):c==l?this.result((u?-200:0)-100-700+(g?0:-1100),r,t):2==e.length?null:this.result((n[0]?-700:0)-200-1100,n,t)}result(t,e,i){let n=[],s=0;for(let t of e){let e=t+(this.astral?A(S(i,t)):1);s&&n[s-1]==t?n[s-1]=e:(n[s++]=t,n[s++]=e)}return this.ret(t-i.length,n)}}class Rf{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.lengthDt(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Ef,filterStrict:!1,compareCompletions:(t,e)=>(t.sortText||t.label).localeCompare(e.sortText||e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>Bf(t(i),e(i)),optionClass:(t,e)=>i=>Bf(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})});function Bf(t,e){return t?e?t+" "+e:t:e}function Ef(t,e,i,n,s,r){let o,l,a=t.textDirection==si.RTL,h=a,c=!1,u="top",f=e.left-s.left,d=s.right-e.right,p=n.right-n.left,m=n.bottom-n.top;if(h&&f=m||t>e.top?o=i.bottom-e.top:(u="bottom",o=e.bottom-i.top)}return{style:`${u}: ${o/((e.bottom-e.top)/r.offsetHeight)}px; max-width: ${l/((e.right-e.left)/r.offsetWidth)}px`,class:"cm-completionInfo-"+(c?a?"left-narrow":"right-narrow":h?"left":"right")}}const Lf=gt.define();function If(t,e,i){if(t<=i)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/i);return{from:t*i,to:(t+1)*i}}let n=Math.ceil((t-e)/i);return{from:t-n*i,to:t-(n-1)*i}}class Nf{constructor(t,e,i){this.view=t,this.stateField=e,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let n=t.state.field(e),{options:s,selected:r}=n.open,o=t.state.facet(Pf);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map(t=>"cm-completionIcon-"+t)),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,i,n){let s=document.createElement("span");s.className="cm-completionLabel";let r=t.displayLabel||t.label,o=0;for(let t=0;to&&s.appendChild(document.createTextNode(r.slice(o,e)));let l=s.appendChild(document.createElement("span"));l.appendChild(document.createTextNode(r.slice(e,i))),l.className="cm-completionMatchedText",o=i}return ot.position-e.position).map(t=>t.render)}(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=If(s.length,r,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",i=>{let{options:n}=t.state.field(e).open;for(let e,s=i.target;s&&s!=this.dom;s=s.parentNode)if("LI"==s.nodeName&&(e=/-(\d+)$/.exec(s.id))&&+e[1]this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;null!=e&&(t.dispatch({effects:Lf.of(e)}),i.preventDefault())}}),this.dom.addEventListener("focusout",e=>{let i=t.state.field(this.stateField,!1);i&&i.tooltip&&t.state.facet(Pf).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:Tf.of(null)})}),this.showOptions(s,n.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),n=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=n){let{options:s,selected:r,disabled:o}=i.open;n.open&&n.open.options==s||(this.range=If(s.length,r,t.state.facet(Pf).maxRenderedOptions),this.showOptions(s,i.id)),this.updateSel(),o!=(null===(e=n.open)||void 0===e?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!o)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;(e.selected>-1&&e.selected=this.range.to)&&(this.range=If(e.options.length,e.selected,this.view.state.facet(Pf).maxRenderedOptions),this.showOptions(e.options,t.id));let i=this.updateSelectedOption(e.selected);if(i){this.destroyInfo();let{completion:n}=e.options[e.selected],{info:s}=n;if(!s)return;let r="string"==typeof s?document.createTextNode(s):s(n);if(!r)return;"then"in r?r.then(e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e,n)}).catch(t=>Hi(this.view.state,t,"completion info")):(this.addInfoPane(r,n),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(65535*Math.random()).toString(16),null!=t.nodeType)i.appendChild(t),this.infoDestroy=null;else{let{dom:e,destroy:n}=t;i.appendChild(e),this.infoDestroy=n||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)"LI"==i.nodeName&&i.id?n==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby")):n--;return e&&function(t,e){let i=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=i.height/t.offsetHeight;n.topi.bottom&&(t.scrollTop+=(n.bottom-i.bottom)/s)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=t.getBoundingClientRect(),s=this.space;if(!s){let t=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:t.clientWidth,bottom:t.clientHeight}}return n.top>Math.min(s.bottom,e.bottom)-10||n.bottom{t.target==n&&t.preventDefault()});let s=null;for(let r=i.from;ri.from||0==i.from))if(s=t,"string"!=typeof a&&a.header)n.appendChild(a.header(a));else{n.appendChild(document.createElement("completion-section")).textContent=t}}const h=n.appendChild(document.createElement("li"));h.id=e+"-"+r,h.setAttribute("role","option");let c=this.optionClass(o);c&&(h.className=c);for(let t of this.optionContent){let e=t(o,this.view.state,this.view,l);e&&h.appendChild(e)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.tonew Nf(i,t,e)}function Hf(t){return 100*(t.boost||0)+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}class Vf{constructor(t,e,i,n,s,r){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=n,this.selected=s,this.disabled=r}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new Vf(this.options,_f(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,n,s,r){if(n&&!r&&t.some(t=>t.isPending))return n.setDisabled();let o=function(t,e){let i=[],n=null,s=null,r=t=>{i.push(t);let{section:e}=t.completion;if(e){n||(n=[]);let t="string"==typeof e?e:e.name;n.some(e=>e.name==t)||n.push("string"==typeof e?{name:t}:e)}},o=e.facet(Pf);for(let n of t)if(n.hasResult()){let t=n.result.getMatch;if(!1===n.result.filter)for(let e of n.result.options)r(new yf(e,n.source,t?t(e):[],1e9-i.length));else{let i,l=e.sliceDoc(n.from,n.to),a=o.filterStrict?new Rf(l):new Df(l);for(let e of n.result.options)if(i=a.match(e.label)){let o=e.displayLabel?t?t(e,i.matched):[]:i.matched,l=i.score+(e.boost||0);if(r(new yf(e,n.source,o,l)),"object"==typeof e.section&&"dynamic"===e.section.rank){let{name:t}=e.section;s||(s=Object.create(null)),s[t]=Math.max(l,s[t]||-1e9)}}}}if(n){let t=Object.create(null),e=0,r=(t,e)=>("dynamic"===t.rank&&"dynamic"===e.rank?s[e.name]-s[t.name]:0)||("number"==typeof t.rank?t.rank:1e9)-("number"==typeof e.rank?e.rank:1e9)||(t.namee.score-t.score||h(t.completion,e.completion))){let e=t.completion;!a||a.label!=e.label||a.detail!=e.detail||null!=a.type&&null!=e.type&&a.type!=e.type||a.apply!=e.apply||a.boost!=e.boost?l.push(t):Hf(t.completion)>Hf(a)&&(l[l.length-1]=t),a=t.completion}return l}(t,e);if(!o.length)return n&&t.some(t=>t.isPending)?n.setDisabled():null;let l=e.facet(Pf).selectOnOpen?0:-1;if(n&&n.selected!=l&&-1!=n.selected){let t=n.options[n.selected].completion;for(let e=0;ee.hasResult()?Math.min(t,e.from):t,1e8),create:Yf,above:s.aboveCursor},n?n.timestamp:Date.now(),l,!1)}map(t){return new Vf(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Vf(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class zf{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new zf(Uf,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,i=e.facet(Pf),n=(i.override||e.languageDataAt("autocomplete",xf(e)).map(Mf)).map(e=>(this.active.find(t=>t.source==e)||new $f(e,this.active.some(t=>0!=t.state)?1:0)).update(t,i));n.length==this.active.length&&n.every((t,e)=>t==this.active[e])&&(n=this.active);let s=this.open,r=t.effects.some(t=>t.is(jf));s&&t.docChanged&&(s=s.map(t.changes)),t.selection||n.some(e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to))||!function(t,e){if(t==e)return!0;for(let i=0,n=0;;){for(;it.isPending)&&(s=null),!s&&n.every(t=>!t.isPending)&&n.some(t=>t.hasResult())&&(n=n.map(t=>t.hasResult()?new $f(t.source,0):t));for(let e of t.effects)e.is(Lf)&&(s=s&&s.setSelected(e.value,this.id));return n==this.active&&s==this.open?this:new zf(n,this.id,s)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Ff:qf}}const Ff={"aria-autocomplete":"list"},qf={};function _f(t,e){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(i["aria-activedescendant"]=t+"-"+e),i}const Uf=[];function Qf(t,e){if(t.isUserEvent("input.complete")){let i=t.annotation(Sf);if(i&&e.activateOnCompletion(i))return 12}let i=t.isUserEvent("input.type");return i&&e.activateOnTyping?5:i?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class $f{constructor(t,e,i=!1){this.source=t,this.state=e,this.explicit=i}hasResult(){return!1}get isPending(){return 1==this.state}update(t,e){let i=Qf(t,e),n=this;(8&i||16&i&&this.touches(t))&&(n=new $f(n.source,0)),4&i&&0==n.state&&(n=new $f(this.source,1)),n=n.updateFor(t,i);for(let e of t.effects)if(e.is(Of))n=new $f(n.source,1,e.value);else if(e.is(Tf))n=new $f(n.source,0);else if(e.is(jf))for(let t of e.value)t.source==n.source&&(n=t);return n}updateFor(t,e){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(xf(t.state))}}class Kf extends $f{constructor(t,e,i,n,s,r){super(t,3,e),this.limit=i,this.result=n,this.from=s,this.to=r}hasResult(){return!0}updateFor(t,e){var i;if(!(3&e))return this.map(t.changes);let n=this.result;n.map&&!t.changes.empty&&(n=n.map(n,t.changes));let s=t.changes.mapPos(this.from),r=t.changes.mapPos(this.to,1),o=xf(t.state);if(o>r||!n||2&e&&(xf(t.startState)==this.from||ot.map(t=>t.map(e))}),Xf=K.define({create:()=>zf.start(),update:(t,e)=>t.update(e),provide:t=>[xo.from(t,t=>t.tooltip),pr.contentAttributes.from(t,t=>t.attrs)]});function Gf(t,e){const i=e.completion.apply||e.completion.label;let n=t.state.field(Xf).active.find(t=>t.source==e.source);return n instanceof Kf&&("string"==typeof i?t.dispatch({...Cf(t.state,i,n.from,n.to),annotations:Sf.of(e.completion)}):i(t,e.completion,n.from,n.to),!0)}const Yf=Wf(Xf,Gf);function Jf(t,e="option"){return i=>{let n=i.state.field(Xf,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp-1?n.open.selected+r*(t?1:-1):t?0:o-1;return l<0?l="page"==e?0:o-1:l>=o&&(l="page"==e?o-1:0),i.dispatch({effects:Lf.of(l)}),!0}}const Zf=t=>!!t.state.field(Xf,!1)&&(t.dispatch({effects:Of.of(!0)}),!0);class td{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const ed=qi.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(Xf).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(Xf),i=t.state.facet(Pf);if(!t.selectionSet&&!t.docChanged&&t.startState.field(Xf)==e)return;let n=t.transactions.some(t=>{let e=Qf(t,i);return 8&e||(t.selection||t.docChanged)&&!(3&e)});for(let e=0;e50&&Date.now()-i.time>1e3){for(let t of i.context.abortListeners)try{t()}catch(t){Hi(this.view.state,t)}i.context.abortListeners=null,this.running.splice(e--,1)}else i.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(t=>t.effects.some(t=>t.is(Of)))&&(this.pendingStart=!0);let s=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(t=>t.isPending&&!this.running.some(e=>e.active.source==t.source))?setTimeout(()=>this.startUpdate(),s):-1,0!=this.composing)for(let e of t.transactions)e.isUserEvent("input.type")?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(Xf);for(let t of e.active)t.isPending&&!this.running.some(e=>e.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Pf).updateSyncTime))}startQuery(t){let{state:e}=this.view,i=xf(e),n=new vf(e,i,t.explicit,this.view),s=new td(t,n);this.running.push(s),Promise.resolve(t.source(n)).then(t=>{s.context.aborted||(s.done=t||null,this.scheduleAccept())},t=>{this.view.dispatch({effects:Tf.of(null)}),Hi(this.view.state,t)})}scheduleAccept(){this.running.every(t=>void 0!==t.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Pf).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],i=this.view.state.facet(Pf),n=this.view.state.field(Xf);for(let s=0;st.source==r.active.source);if(o&&o.isPending)if(null==r.done){let t=new $f(r.active.source,0);for(let e of r.updates)t=t.update(e,i);t.isPending||e.push(t)}else this.startQuery(o)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:jf.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(Xf,!1);if(e&&e.tooltip&&this.view.state.facet(Pf).closeOnBlur){let i=e.open&&Do(this.view,e.open.tooltip);i&&i.dom.contains(t.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:Tf.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:Of.of(!1)}),20),this.composing=0}}}),id="object"==typeof navigator&&/Win/.test(navigator.platform),nd=Z.highest(pr.domEventHandlers({keydown(t,e){let i=e.state.field(Xf,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||t.key.length>1||t.ctrlKey&&(!id||!t.altKey)||t.metaKey)return!1;let n=i.open.options[i.open.selected],s=i.active.find(t=>t.source==n.source),r=n.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(t.key)>-1&&Gf(e,n),!1}})),sd=pr.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),rd={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},od=gt.define({map(t,e){let i=e.mapPos(t,-1,O.TrackAfter);return null==i?void 0:i}}),ld=new class extends Rt{};ld.startSide=1,ld.endSide=-1;const ad=K.define({create:()=>It.empty,update(t,e){if(t=t.map(e.changes),e.selection){let i=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:t=>t>=i.from&&t<=i.to})}for(let i of e.effects)i.is(od)&&(t=t.update({add:[ld.range(i.value,i.value+1)]}));return t}});const hd="()[]{}<>«»»«[]{}";function cd(t){for(let e=0;e<16;e+=2)if(hd.charCodeAt(e)==t)return hd.charAt(e+1);return C(t<128?t:t+1)}function ud(t,e){return t.languageDataAt("closeBrackets",e)[0]||rd}const fd="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),dd=pr.inputHandler.of((t,e,i,n)=>{if((fd?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let s=t.state.selection.main;if(n.length>2||2==n.length&&1==A(S(n,0))||e!=s.from||i!=s.to)return!1;let r=function(t,e){let i=ud(t,t.selection.main.head),n=i.brackets||rd.brackets;for(let s of n){let r=cd(S(s,0));if(e==s)return r==s?bd(t,s,n.indexOf(s+s+s)>-1,i):vd(t,s,r,i.before||rd.before);if(e==r&&md(t,t.selection.main.from))return wd(t,s,r)}return null}(t.state,n);return!!r&&(t.dispatch(r),!0)}),pd=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=ud(t,t.selection.main.head).brackets||rd.brackets,n=null,s=t.changeByRange(e=>{if(e.empty){let n=function(t,e){let i=t.sliceString(e-2,e);return A(S(i,0))==i.length?i:i.slice(1)}(t.doc,e.head);for(let s of i)if(s==n&&gd(t.doc,e.head)==cd(S(s,0)))return{changes:{from:e.head-s.length,to:e.head+s.length},range:W.cursor(e.head-s.length)}}return{range:n=e}});return n||e(t.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!n}}];function md(t,e){let i=!1;return t.field(ad).between(0,t.doc.length,t=>{t==e&&(i=!0)}),i}function gd(t,e){let i=t.sliceString(e,e+2);return i.slice(0,A(S(i,0)))}function vd(t,e,i,n){let s=null,r=t.changeByRange(r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:i,from:r.to}],effects:od.of(r.to+e.length),range:W.range(r.anchor+e.length,r.head+e.length)};let o=gd(t.doc,r.head);return!o||/\s/.test(o)||n.indexOf(o)>-1?{changes:{insert:e+i,from:r.head},effects:od.of(r.head+e.length),range:W.cursor(r.head+e.length)}:{range:s=r}});return s?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function wd(t,e,i){let n=null,s=t.changeByRange(e=>e.empty&&gd(t.doc,e.head)==i?{changes:{from:e.head,to:e.head+i.length,insert:i},range:W.cursor(e.head+i.length)}:n={range:e});return n?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function bd(t,e,i,n){let s=n.stringPrefixes||rd.stringPrefixes,r=null,o=t.changeByRange(n=>{if(!n.empty)return{changes:[{insert:e,from:n.from},{insert:e,from:n.to}],effects:od.of(n.to+e.length),range:W.range(n.anchor+e.length,n.head+e.length)};let o,l=n.head,a=gd(t.doc,l);if(a==e){if(yd(t,l))return{changes:{insert:e+e,from:l},effects:od.of(l+e.length),range:W.cursor(l+e.length)};if(md(t,l)){let n=i&&t.sliceDoc(l,l+3*e.length)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+n.length,insert:n},range:W.cursor(l+n.length)}}}else{if(i&&t.sliceDoc(l-2*e.length,l)==e+e&&(o=xd(t,l-2*e.length,s))>-1&&yd(t,o))return{changes:{insert:e+e+e+e,from:l},effects:od.of(l+e.length),range:W.cursor(l+e.length)};if(t.charCategorizer(l)(a)!=Ct.Word&&xd(t,l,s)>-1&&!function(t,e,i,n){let s=xa(t).resolveInner(e,-1),r=n.reduce((t,e)=>Math.max(t,e.length),0);for(let o=0;o<5;o++){let o=t.sliceDoc(s.from,Math.min(s.to,s.from+i.length+r)),l=o.indexOf(i);if(!l||l>-1&&n.indexOf(o.slice(0,l))>-1){let e=s.firstChild;for(;e&&e.from==s.from&&e.to-e.from>i.length+l;){if(t.sliceDoc(e.to-i.length,e.to)==i)return!1;e=e.firstChild}return!0}let a=s.to==e&&s.parent;if(!a)break;s=a}return!1}(t,l,e,s))return{changes:{insert:e+e,from:l},effects:od.of(l+e.length),range:W.cursor(l+e.length)}}return{range:r=n}});return r?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function yd(t,e){let i=xa(t).resolveInner(e+1);return i.parent&&i.from==e}function xd(t,e,i){let n=t.charCategorizer(e);if(n(t.sliceDoc(e-1,e))!=Ct.Word)return e;for(let s of i){let i=e-s.length;if(t.sliceDoc(i,e)==s&&n(t.sliceDoc(i-1,i))!=Ct.Word)return i}return-1}function kd(t={}){return[nd,Xf,Pf.of(t),ed,Cd,sd]}const Sd=[{key:"Ctrl-Space",run:Zf},{mac:"Alt-`",run:Zf},{mac:"Alt-i",run:Zf},{key:"Escape",run:t=>{let e=t.state.field(Xf,!1);return!(!e||!e.active.some(t=>0!=t.state))&&(t.dispatch({effects:Tf.of(null)}),!0)}},{key:"ArrowDown",run:Jf(!0)},{key:"ArrowUp",run:Jf(!1)},{key:"PageDown",run:Jf(!0,"page")},{key:"PageUp",run:Jf(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field(Xf,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampt.facet(Pf).defaultKeymap?[Sd]:[]));class Ad{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class Md{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let n=i.facet(Wd).markerFilter;n&&(t=n(t,i));let s=t.slice().sort((t,e)=>t.from-e.from||t.to-e.to),r=new Nt,o=[],l=0,a=i.doc.iter(),h=0,c=i.doc.length;for(let t=0;;){let e,i,n=t==s.length?null:s[t];if(!n&&!o.length)break;if(o.length)e=l,i=o.reduce((t,e)=>Math.min(t,e.to),n&&n.from>e?n.from:1e8);else{if(e=n.from,e>c)break;i=n.to,o.push(n),t++}for(;tn.from||n.to==e)){i=Math.min(n.from,i);break}o.push(n),t++,i=Math.min(n.to,i)}i=Math.min(i,c);let u=!1;if(o.some(t=>t.from==e&&(t.to==i||i==c))&&(u=e==i,!u&&i-e<10)){let t=e-(h+a.value.length);t>0&&(a.next(t),h=e);for(let t=e;;){if(t>=i){u=!0;break}if(!a.lineBreak&&h+a.value.length>t)break;t=h+a.value.length,h+=a.value.length,a.next()}}let f=Kd(o);if(u)r.add(e,e,Te.widget({widget:new Fd(f),diagnostics:o.slice()}));else{let t=o.reduce((t,e)=>e.markClass?t+" "+e.markClass:t,"");r.add(e,i,Te.mark({class:"cm-lintRange cm-lintRange-"+f+t,diagnostics:o.slice(),inclusiveEnd:o.some(t=>t.to>i)}))}if(l=i,l==c)break;for(let t=0;t{if(!(e&&s.diagnostics.indexOf(e)<0))if(n){if(s.diagnostics.indexOf(n.diagnostic)<0)return!1;n=new Ad(n.from,i,n.diagnostic)}else n=new Ad(t,i,e||s.diagnostics[0])}),n}const Td=gt.define(),Dd=gt.define(),Rd=gt.define(),Pd=K.define({create:()=>new Md(Te.none,null,null),update(t,e){if(e.docChanged&&t.diagnostics.size){let i=t.diagnostics.map(e.changes),n=null,s=t.panel;if(t.selected){let s=e.changes.mapPos(t.selected.from,1);n=Od(i,t.selected.diagnostic,s)||Od(i,null,s)}!i.size&&s&&e.state.facet(Wd).autoPanel&&(s=null),t=new Md(i,s,n)}for(let i of e.effects)if(i.is(Td)){let n=e.state.facet(Wd).autoPanel?i.value.length?_d.open:null:t.panel;t=Md.init(i.value,n,e.state)}else i.is(Dd)?t=new Md(t.diagnostics,i.value?_d.open:null,t.selected):i.is(Rd)&&(t=new Md(t.diagnostics,t.panel,i.value));return t},provide:t=>[No.from(t,t=>t.panel),pr.decorations.from(t,t=>t.diagnostics)]}),Bd=Te.mark({class:"cm-lintRange cm-lintRange-active"});function Ed(t,e,i){let n,{diagnostics:s}=t.state.field(Pd),r=-1,o=-1;s.between(e-(i<0?1:0),e+(i>0?1:0),(t,s,{spec:l})=>{if(e>=t&&e<=s&&(t==s||(e>t||i>0)&&(e({dom:Ld(t,n)})}:null}function Ld(t,e){return le("ul",{class:"cm-tooltip-lint"},e.map(e=>zd(t,e,!1)))}const Id=t=>{let e=t.state.field(Pd,!1);return!(!e||!e.panel)&&(t.dispatch({effects:Dd.of(!1)}),!0)},Nd=[{key:"Mod-Shift-m",run:t=>{let e=t.state.field(Pd,!1);var i,n;e&&e.panel||t.dispatch({effects:(i=t.state,n=[Dd.of(!0)],i.field(Pd,!1)?n:n.concat(gt.appendConfig.of(Xd)))});let s=Bo(t,_d.open);return s&&s.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:t=>{let e=t.state.field(Pd,!1);if(!e)return!1;let i=t.state.selection.main,n=Od(e.diagnostics,null,i.to+1);return!(!n&&(n=Od(e.diagnostics,null,0),!n||n.from==i.from&&n.to==i.to))&&(t.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),function(t,e,i,n={}){var s;let r=t.state.facet(Ao).map(e=>t.plugin(e)).filter(t=>!!t);if(n.tooltip&&n.tooltip.active){let t=r.find(t=>t.field==n.tooltip.active);t&&(r=[t])}for(let o of r)o.activateHover(t,e,i,null!==(s=n.until)&&void 0!==s?s:()=>!1)}(t,n.from,1,{tooltip:jd,until:t=>t.docChanged||t.newSelection.main.headn.to}),!0)}}],Wd=z.define({combine:t=>({sources:t.map(t=>t.source).filter(t=>null!=t),...Dt(t.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:Hd,tooltipFilter:Hd,needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e,hideOn:(t,e)=>t?e?(i,n,s)=>t(i,n,s)||e(i,n,s):t:e,autoPanel:(t,e)=>t||e})})});function Hd(t,e){return t?e?(i,n)=>e(t(i,n),n):t:e}function Vd(t){let e=[];if(t)t:for(let{name:i}of t){for(let t=0;tt.toLowerCase()==n.toLowerCase())){e.push(n);continue t}}e.push("")}return e}function zd(t,e,i){var n;let s=i?Vd(e.actions):[];return le("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},le("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),null===(n=e.actions)||void 0===n?void 0:n.map((i,n)=>{let r=!1,o=n=>{if(n.preventDefault(),r)return;r=!0;let s=Od(t.state.field(Pd).diagnostics,e);s&&i.apply(t,s.from,s.to)},{name:l}=i,a=s[n]?l.indexOf(s[n]):-1,h=a<0?l:[l.slice(0,a),le("u",l.slice(a,a+1)),l.slice(a+1)];return le("button",{type:"button",class:"cm-diagnosticAction"+(i.markClass?" "+i.markClass:""),onclick:o,onmousedown:o,"aria-label":` Action: ${l}${a<0?"":` (access key "${s[n]})"`}.`},h)}),e.source&&le("div",{class:"cm-diagnosticSource"},e.source))}class Fd extends Me{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return le("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class qd{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=zd(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class _d{constructor(t){this.view=t,this.items=[];this.list=le("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(!(e.ctrlKey||e.altKey||e.metaKey)){if(27==e.keyCode)Id(this.view),this.view.focus();else if(38==e.keyCode||33==e.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==e.keyCode||34==e.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==e.keyCode)this.moveSelection(0);else if(35==e.keyCode)this.moveSelection(this.items.length-1);else if(13==e.keyCode)this.view.focus();else{if(!(e.keyCode>=65&&e.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],n=Vd(i.actions);for(let s=0;s{for(let e=0;eId(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(Pd).selected;if(!t)return-1;for(let e=0;e{for(let t of l.diagnostics){if(r.has(t))continue;r.add(t);let o,l=-1;for(let e=i;ei&&(this.items.splice(i,l-i),n=!0)),e&&o.diagnostic==e.diagnostic?o.dom.hasAttribute("aria-selected")||(o.dom.setAttribute("aria-selected","true"),s=o):o.dom.hasAttribute("aria-selected")&&o.dom.removeAttribute("aria-selected"),i++}});i({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:t,panel:e})=>{let i=e.height/this.list.offsetHeight;t.tope.bottom&&(this.list.scrollTop+=(t.bottom-e.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let t=this.list.firstChild;function e(){let e=t;t=e.nextSibling,e.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=Od(this.view.state.field(Pd).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:Rd.of(e)})}static open(t){return new _d(t)}}function Ud(t){return function(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,${encodeURIComponent(t)}')`}(``,'width="6" height="3"')}const Qd=pr.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Ud("#f11")},".cm-lintRange-warning":{backgroundImage:Ud("orange")},".cm-lintRange-info":{backgroundImage:Ud("#999")},".cm-lintRange-hint":{backgroundImage:Ud("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function $d(t){return"error"==t?4:"warning"==t?3:"info"==t?2:1}function Kd(t){let e="hint",i=1;for(let n of t){let t=$d(n.severity);t>i&&(i=t,e=n.severity)}return e}const jd=To(Ed,{hideOn:function(t,e){let i=e.pos,n=e.end||i,s=t.state.facet(Wd).hideOn(t,i,n);if(null!=s)return s;let r=t.startState.doc.lineAt(e.pos);return!(!t.effects.some(t=>t.is(Td))&&!t.changes.touchesRange(r.from,Math.max(r.to,n)))}}),Xd=[Pd,pr.decorations.compute([Pd],t=>{let{selected:e,panel:i}=t.field(Pd);return e&&i&&e.from!=e.to?Te.set([Bd.range(e.from,e.to)]):Te.none}),jd,Qd],Gd=(()=>[ll(),cl,Jr(),sc(),ph(),Nr(),[_r,Ur],Tt.allowMultipleSelections.of(!0),Tt.transactionFilter.of(t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let i=t.newDoc,{head:n}=t.newSelection.main,s=i.lineAt(n);if(n>s.from+200)return t;let r=i.sliceString(s.from,n);if(!e.some(t=>t.test(r)))return t;let{state:o}=t,l=-1,a=[];for(let{head:t}of o.selection.ranges){let e=o.doc.lineAt(t);if(e.from==l)continue;l=e.from;let i=Na(o,e.from);if(null==i)continue;let n=/^\s*/.exec(e.text)[0],s=Ia(o,i);n!=s&&a.push({from:e.from,to:e.from+n.length,insert:s})}return a.length?[t,{changes:a,sequential:!0}]:t}),yh(Sh,{fallback:!0}),Bh(),[dd,ad],kd(),lo(),co(),no,Tu(),kr.of([...pd,...gu,...hf,...xc,...rh,...Sd,...Nd])])();class Yd{constructor(t,e,i,n,s,r,o,l,a,h=0,c){this.p=t,this.stack=e,this.state=i,this.reducePos=n,this.pos=s,this.score=r,this.buffer=o,this.bufferBase=l,this.curContext=a,this.lookAhead=h,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let n=t.parser.context;return new Yd(t,[],e,i,i,0,[],0,n?new Jd(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,n=65535&t,{parser:s}=this.p,r=this.reducePos=2e3&&!(null===(e=this.p.parser.nodeSet.types[n])||void 0===e?void 0:e.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=h):this.p.lastBigReductionSizel;)this.stack.pop();this.reduceContext(n,a)}storeNode(t,e,i,n=4,s=!1){if(0==t&&(!this.stack.length||this.stack[this.stack.length-1]0&&0==this.buffer[t-4]&&this.buffer[t-1]>-1){if(e==i)return;if(this.buffer[t-2]>=e)return void(this.buffer[t-2]=i)}}if(s&&this.pos!=i){let s=this.buffer.length;if(s>0&&(0!=this.buffer[s-4]||this.buffer[s-1]<0)){let t=!1;for(let e=s;e>0&&this.buffer[e-2]>i;e-=4)if(this.buffer[e-1]>=0){t=!0;break}if(t)for(;s>0&&this.buffer[s-2]>i;)this.buffer[s]=this.buffer[s-4],this.buffer[s+1]=this.buffer[s-3],this.buffer[s+2]=this.buffer[s-2],this.buffer[s+3]=this.buffer[s-1],s-=4,n>4&&(n-=4)}this.buffer[s]=t,this.buffer[s+1]=e,this.buffer[s+2]=i,this.buffer[s+3]=n}else this.buffer.push(t,e,i,n)}shift(t,e,i,n){if(131072&t)this.pushState(65535&t,this.pos);else if(262144&t)this.pos=n,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,n,4);else{let s=t,{parser:r}=this.p;this.pos=n;let o=r.stateFlag(s,1);!o&&(n>i||e<=r.maxNode)&&(this.reducePos=n),this.pushState(s,o?i:Math.min(i,this.reducePos)),this.shiftContext(e,i),e<=r.maxNode&&this.buffer.push(e,i,n,4)}}apply(t,e,i,n){65536&t?this.reduce(t):this.shift(t,e,i,n)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let n=this.pos;this.reducePos=this.pos=n+t.length,this.pushState(e,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&0==t.buffer[e-4]&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),n=t.bufferBase+e;for(;t&&n==t.bufferBase;)t=t.parent;return new Yd(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new Zd(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(0==i)return!1;if(!(65536&i))return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let i=[];for(let n,s=0;s1&e&&t==n)||i.push(e[t],n)}e=i}let i=[];for(let t=0;t>19,n=65535&e,s=this.stack.length-3*i;if(s<0||t.getGoto(this.stack[s],n,!1)<0){let t=this.findForcedReduction();if(null==t)return!1;e=t}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(n,s)=>{if(!e.includes(n))return e.push(n),t.allActions(n,e=>{if(393216&e);else if(65536&e){let i=(e>>19)-s;if(i>1){let n=65535&e,s=this.stack.length-3*i;if(s>=0&&t.getGoto(this.stack[s],n,!1)>=0)return i<<19|65536|n}}else{let t=i(e,s+1);if(null!=t)return t}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(3!=this.stack.length)return!1;let{parser:t}=this.p;return 65535==t.data[t.stateSlot(this.state,1)]&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e0&&this.emitLookAhead()}}class Jd{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class Zd{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=65535&t,i=t>>19;0==i?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=3*(i-1);let n=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=n}}class tp{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,0==this.index&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new tp(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;null!=t&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,0==this.index&&this.maybeNext()}fork(){return new tp(this.stack,this.pos,this.index)}}function ep(t,e=Uint16Array){if("string"!=typeof t)return t;let i=null;for(let n=0,s=0;n=92&&e--,e>=34&&e--;let s=e-32;if(s>=46&&(s-=46,i=!0),r+=s,i)break;r*=46}i?i[s++]=r:i=new e(r)}return i}class ip{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const np=new ip;class sp{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=np,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,n=this.rangeIndex,s=this.pos+t;for(;si.to:s>=i.to;){if(n==this.ranges.length-1)return null;let t=this.ranges[++n];s+=t.from-i.to,i=t}return s}clipPos(t){if(t>=this.range.from&&tt)return Math.max(t,e.from);return this.end}peek(t){let e,i,n=this.chunkOff+t;if(n>=0&&n=this.chunk2Pos&&en.to&&(this.chunk2=this.chunk2.slice(0,n.to-e)),i=this.chunk2.charCodeAt(0)}}return e>=this.token.lookAhead&&(this.token.lookAhead=e+1),i}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(null==i||i=this.chunk2Pos&&this.posthis.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=np,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let n of this.ranges){if(n.from>=e)break;n.to>t&&(i+=this.input.read(Math.max(n.from,t),Math.min(n.to,e)))}return i}}class rp{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:i}=e.p;!function(t,e,i,n,s,r){let o=0,l=1<0){let i=t[n];if(a.allows(i)&&(-1==e.token.value||e.token.value==i||ap(i,e.token.value,s,r))){e.acceptToken(i);break}}let n=e.next,h=0,c=t[o+2];if(!(e.next<0&&c>h&&65535==t[i+3*c-3])){for(;h>1,r=i+s+(s<<1),l=t[r],a=t[r+1]||65536;if(n=a)){o=t[r+2],e.advance();continue t}h=s+1}}break}o=t[i+3*c-1]}}(this.data,t,e,this.id,i.data,i.tokenPrecTable)}}rp.prototype.contextual=rp.prototype.fallback=rp.prototype.extend=!1,rp.prototype.fallback=rp.prototype.extend=!1;class op{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}}function lp(t,e,i){for(let n,s=e;65535!=(n=t[s]);s++)if(n==i)return s-e;return-1}function ap(t,e,i,n){let s=lp(i,n,e);return s<0||lp(i,n,t)e)&&!n.type.isError)return i<0?Math.max(0,Math.min(n.to-1,e-25)):Math.min(t.length,Math.max(n.from+1,e+25));if(i<0?n.prevSibling():n.nextSibling())break;if(!n.parent())return i<0?0:t.length}}class fp{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?up(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?up(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(tt)return this.nextStart=r,null;if(s instanceof kl){if(r==t){if(r=Math.max(this.safeFrom,t)&&(this.trees.push(s),this.start.push(r),this.index.push(0))}else this.index[e]++,this.nextStart=r+s.length}}}class dp{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(t=>new ip)}getActions(t){let e=0,i=null,{parser:n}=t.p,{tokenizers:s}=n,r=n.stateSlot(t.state,3),o=t.curContext?t.curContext.hash:0,l=0;for(let n=0;nh.end+25&&(l=Math.max(h.lookAhead,l)),0!=h.value)){let n=e;if(h.extended>-1&&(e=this.addActions(t,h.extended,h.end,e)),e=this.addActions(t,h.value,h.end,e),!a.extend&&(i=h,e>n))break}}for(;this.actions.length>e;)this.actions.pop();return l&&t.setLookAhead(l),i||t.pos!=this.stream.end||(i=new ip,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new ip,{pos:i,p:n}=t;return e.start=i,e.end=Math.min(i+1,n.stream.end),e.value=i==n.stream.end?n.parser.eofTerm:0,e}updateCachedToken(t,e,i){let n=this.stream.clipPos(i.pos);if(e.token(this.stream.reset(n,t),i),t.value>-1){let{parser:e}=i.p;for(let n=0;n=0&&i.p.parser.dialect.allows(s>>1)){1&s?t.extended=s>>1:t.value=s>>1;break}}}else t.value=0,t.end=this.stream.clipPos(n+1)}putAction(t,e,i,n){for(let e=0;e4*t.bufferLength?new fp(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t,e,i=this.stacks,n=this.minStackPos,s=this.stacks=[];if(this.bigReductionCount>300&&1==i.length){let[t]=i;for(;t.forceReduce()&&t.stack.length&&t.stack[t.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let r=0;rn)s.push(o);else{if(this.advanceStack(o,s,i))continue;{t||(t=[],e=[]),t.push(o);let i=this.tokens.getMainToken(o);e.push(i.value,i.end)}}break}}if(!s.length){let e=t&&function(t){let e=null;for(let i of t){let t=i.p.stoppedAt;(i.pos==i.p.stream.end||null!=t&&i.pos>t)&&i.p.parser.stateFlag(i.state,2)&&(!e||e.scorethis.stoppedAt?t[0]:this.runRecovery(t,e,s);if(i)return hp&&console.log("Force-finish "+this.stackID(i)),this.stackToTree(i.forceAll())}if(this.recovering){let t=1==this.recovering?1:3*this.recovering;if(s.length>t)for(s.sort((t,e)=>e.score-t.score);s.length>t;)s.pop();s.some(t=>t.reducePos>n)&&this.recovering--}else if(s.length>1){t:for(let t=0;t500&&n.buffer.length>500){if(!((e.score-n.score||e.buffer.length-n.buffer.length)>0)){s.splice(t--,1);continue t}s.splice(i--,1)}}}s.length>12&&(s.sort((t,e)=>e.score-t.score),s.splice(12,s.length-12))}this.minStackPos=s[0].pos;for(let t=1;t ":"";if(null!=this.stoppedAt&&n>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let e=t.curContext&&t.curContext.tracker.strict,i=e?t.curContext.hash:0;for(let o=this.fragments.nodeAt(n);o;){let n=this.parser.nodeSet.types[o.type.id]==o.type?s.getGoto(t.state,o.type.id):-1;if(n>-1&&o.length&&(!e||(o.prop(pl.contextHash)||0)==i))return t.useNode(o,n),hp&&console.log(r+this.stackID(t)+` (via reuse of ${s.getName(o.type.id)})`),!0;if(!(o instanceof kl)||0==o.children.length||o.positions[0]>0)break;let l=o.children[0];if(!(l instanceof kl&&0==o.positions[0]))break;o=l}}let o=s.stateSlot(t.state,4);if(o>0)return t.reduce(o),hp&&console.log(r+this.stackID(t)+` (via always-reduce ${s.getName(65535&o)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let l=this.tokens.getActions(t);for(let o=0;on?e.push(f):i.push(f)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return mp(t,e),!0}}runRecovery(t,e,i){let n=null,s=!1;for(let r=0;r ":"";if(o.deadEnd){if(s)continue;if(s=!0,o.restart(),hp&&console.log(h+this.stackID(o)+" (restarted)"),this.advanceFully(o,i))continue}let c=o.split(),u=h;for(let t=0;t<10&&c.forceReduce();t++){if(hp&&console.log(u+this.stackID(c)+" (via force-reduce)"),this.advanceFully(c,i))break;hp&&(u=this.stackID(c)+" -> ")}for(let t of o.recoverByInsert(l))hp&&console.log(h+this.stackID(t)+" (via recover-insert)"),this.advanceFully(t,i);this.stream.end>o.pos?(a==o.pos&&(a++,l=0),o.recoverByDelete(l,a),hp&&console.log(h+this.stackID(o)+` (via recover-delete ${this.parser.getName(l)})`),mp(o,i)):(!n||n.scoret.topRules[e][1]),n=[];for(let t=0;t=0)s(n,t,e[i++]);else{let r=e[i+-n];for(let o=-n;o>0;o--)s(e[i++],t,r);i++}}}this.nodeSet=new wl(e.map((e,s)=>vl.define({name:s>=this.minRepeatTerm?void 0:e,id:s,props:n[s],top:i.indexOf(s)>-1,error:0==s,skipped:t.skippedNodes&&t.skippedNodes.indexOf(s)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=ul;let r=ep(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let t=0;t"number"==typeof t?new rp(r,t):t),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let n=new pp(this,t,e,i);for(let s of this.wrappers)n=s(n,t,e,i);return n}getGoto(t,e,i=!1){let n=this.goto;if(e>=n[0])return-1;for(let s=n[e+1];;){let e=n[s++],r=1&e,o=n[s++];if(r&&i)return o;for(let i=s+(e>>1);s0}validAction(t,e){return!!this.allActions(t,t=>t==e||null)}allActions(t,e){let i=this.stateSlot(t,4),n=i?e(i):void 0;for(let i=this.stateSlot(t,1);null==n;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])break;i=wp(this.data,i+2)}n=e(wp(this.data,i+1))}return n}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(65535==this.data[i]){if(1!=this.data[i+1])break;i=wp(this.data,i+2)}if(!(1&this.data[i+2])){let t=this.data[i+1];e.some((e,i)=>1&i&&e==t)||e.push(this.data[i],t)}}return e}configure(t){let e=Object.assign(Object.create(vp.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(e=>{let i=t.tokenizers.find(t=>t.from==e);return i?i.to:e})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,n)=>{let s=t.specializers.find(t=>t.from==i.external);if(!s)return i;let r=Object.assign(Object.assign({},i),{external:s.to});return e.specializers[n]=bp(r),r})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),null!=t.strict&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),null!=t.bufferLength&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return null==e?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let n of t.split(" ")){let t=e.indexOf(n);t>=0&&(i[t]=!0)}let n=null;for(let t=0;tt.external(i,n)<<1|e}return t.get}function yp(t){return t>=65&&t<=90||t>=97&&t<=122||t>=48&&t<=57}function xp(t){return t>=48&&t<=57||t>=97&&t<=102||t>=65&&t<=70}function kp(t,e,i){for(let n=!1;;){if(t.next<0)return;if(t.next==e&&!n)return void t.advance();n=i&&!n&&92==t.next,t.advance()}}function Sp(t,e){for(;95==t.next||yp(t.next);)null!=e&&(e+=String.fromCharCode(t.next)),t.advance();return e}function Cp(t,e){for(;48==t.next||49==t.next;)t.advance();e&&t.next==e&&t.advance()}function Ap(t,e){for(;;){if(46==t.next){if(e)break;e=!0}else if(t.next<48||t.next>57)break;t.advance()}if(69==t.next||101==t.next)for(t.advance(),43!=t.next&&45!=t.next||t.advance();t.next>=48&&t.next<=57;)t.advance()}function Mp(t){for(;!(t.next<0||10==t.next);)t.advance()}function Op(t,e){for(let i=0;i!=&|~^/",specialVar:"?",identifierQuotes:'"',caseInsensitiveIdentifiers:!1,words:Dp("absolute action add after all allocate alter and any are as asc assertion at authorization before begin between both breadth by call cascade cascaded case cast catalog check close collate collation column commit condition connect connection constraint constraints constructor continue corresponding count create cross cube current current_date current_default_transform_group current_transform_group_for_type current_path current_role current_time current_timestamp current_user cursor cycle data day deallocate declare default deferrable deferred delete depth deref desc describe descriptor deterministic diagnostics disconnect distinct do domain drop dynamic each else elseif end end-exec equals escape except exception exec execute exists exit external fetch first for foreign found from free full function general get global go goto grant group grouping handle having hold hour identity if immediate in indicator initially inner inout input insert intersect into is isolation join key language last lateral leading leave left level like limit local localtime localtimestamp locator loop map match method minute modifies module month names natural nesting new next no none not of old on only open option or order ordinality out outer output overlaps pad parameter partial path prepare preserve primary prior privileges procedure public read reads recursive redo ref references referencing relative release repeat resignal restrict result return returns revoke right role rollback rollup routine row rows savepoint schema scroll search second section select session session_user set sets signal similar size some space specific specifictype sql sqlexception sqlstate sqlwarning start state static system_user table temporary then timezone_hour timezone_minute to trailing transaction translation treat trigger under undo union unique unnest until update usage user using value values view when whenever where while with without work write year zone ","array binary bit boolean char character clob date decimal double float int integer interval large national nchar nclob numeric object precision real smallint time timestamp varchar varying ")};function Pp(t){return new op(e=>{var i;let{next:n}=e;if(e.advance(),Op(n,Tp)){for(;Op(e.next,Tp);)e.advance();e.acceptToken(36)}else if(36==n&&t.doubleDollarQuotedStrings){let t=Sp(e,"");36==e.next&&(e.advance(),function(t,e){t:for(;;){if(t.next<0)return;if(36==t.next){t.advance();for(let i=0;i1){e.advance(),kp(e,39,t.backslashEscapes),e.acceptToken(3);break}if(!yp(e.next))break;e.advance()}else if(t.plsqlQuotingMechanism&&(113==n||81==n)&&39==e.next&&e.peek(1)>0&&!Op(e.peek(1),Tp)){let t=e.peek(1);e.advance(2),function(t,e){let i="[{<(".indexOf(String.fromCharCode(e)),n=i<0?e:"]}>)".charCodeAt(i);for(;;){if(t.next<0)return;if(t.next==n&&39==t.peek(1))return void t.advance(2);t.advance()}}(e,t),e.acceptToken(3)}else if(Op(n,t.identifierQuotes)){kp(e,91==n?93:n,!1),e.acceptToken(19)}else if(40==n)e.acceptToken(7);else if(41==n)e.acceptToken(8);else if(123==n)e.acceptToken(9);else if(125==n)e.acceptToken(10);else if(91==n)e.acceptToken(11);else if(93==n)e.acceptToken(12);else if(59==n)e.acceptToken(13);else if(t.unquotedBitLiterals&&48==n&&98==e.next)e.advance(),Cp(e),e.acceptToken(22);else if(98!=n&&66!=n||39!=e.next&&34!=e.next){if(48==n&&(120==e.next||88==e.next)||(120==n||88==n)&&39==e.next){let t=39==e.next;for(e.advance();xp(e.next);)e.advance();t&&39==e.next&&e.advance(),e.acceptToken(4)}else if(46==n&&e.next>=48&&e.next<=57)Ap(e,!0),e.acceptToken(4);else if(46==n)e.acceptToken(14);else if(n>=48&&n<=57)Ap(e,!1),e.acceptToken(4);else if(Op(n,t.operatorChars)){for(;Op(e.next,t.operatorChars);)e.advance();e.acceptToken(15)}else if(Op(n,t.specialVar))e.next==n&&e.advance(),function(t){if(39==t.next||34==t.next||96==t.next){let e=t.next;t.advance(),kp(t,e,!1)}else Sp(t)}(e),e.acceptToken(17);else if(58==n||44==n)e.acceptToken(16);else if(yp(n)){let s=Sp(e,String.fromCharCode(n));e.acceptToken(46==e.next||46==e.peek(-s.length-1)?18:null!==(i=t.words[s.toLowerCase()])&&void 0!==i?i:18)}}else{const i=e.next;e.advance(),t.treatBitsAsBytes?(kp(e,i,t.backslashEscapes),e.acceptToken(23)):(Cp(e,i),e.acceptToken(22))}else e.advance(),kp(e,39,t.backslashEscapes),e.acceptToken(3);else e.advance(),kp(e,39,!0),e.acceptToken(3);else Mp(e),e.acceptToken(1)})}const Bp=Pp(Rp),Ep=vp.deserialize({version:14,states:"%vQ]QQOOO#wQRO'#DSO$OQQO'#CwO%eQQO'#CxO%lQQO'#CyO%sQQO'#CzOOQQ'#DS'#DSOOQQ'#C}'#C}O'UQRO'#C{OOQQ'#Cv'#CvOOQQ'#C|'#C|Q]QQOOQOQQOOO'`QQO'#DOO(xQRO,59cO)PQQO,59cO)UQQO'#DSOOQQ,59d,59dO)cQQO,59dOOQQ,59e,59eO)jQQO,59eOOQQ,59f,59fO)qQQO,59fOOQQ-E6{-E6{OOQQ,59b,59bOOQQ-E6z-E6zOOQQ,59j,59jOOQQ-E6|-E6|O+VQRO1G.}O+^QQO,59cOOQQ1G/O1G/OOOQQ1G/P1G/POOQQ1G/Q1G/QP+kQQO'#C}O+rQQO1G.}O)PQQO,59cO,PQQO'#Cw",stateData:",[~OtOSPOSQOS~ORUOSUOTUOUUOVROXSOZTO]XO^QO_UO`UOaPObPOcPOdUOeUOfUOgUOhUO~O^]ORvXSvXTvXUvXVvXXvXZvX]vX_vX`vXavXbvXcvXdvXevXfvXgvXhvX~OsvX~P!jOa_Ob_Oc_O~ORUOSUOTUOUUOVROXSOZTO^tO_UO`UOa`Ob`Oc`OdUOeUOfUOgUOhUO~OWaO~P$ZOYcO~P$ZO[eO~P$ZORUOSUOTUOUUOVROXSOZTO^QO_UO`UOaPObPOcPOdUOeUOfUOgUOhUO~O]hOsoX~P%zOajObjOcjO~O^]ORkaSkaTkaUkaVkaXkaZka]ka_ka`kaakabkackadkaekafkagkahka~Oska~P'kO^]O~OWvXYvX[vX~P!jOWnO~P$ZOYoO~P$ZO[pO~P$ZO^]ORkiSkiTkiUkiVkiXkiZki]ki_ki`kiakibkickidkiekifkigkihki~Oski~P)xOWkaYka[ka~P'kO]hO~P$ZOWkiYki[ki~P)xOasObsOcsO~O",goto:"#hwPPPPPPPPPPPPPPPPPPPPPPPPPPx||||!Y!^!d!xPPP#[TYOZeUORSTWZbdfqT[OZQZORiZSWOZQbRQdSQfTZgWbdfqQ^PWk^lmrQl_Qm`RrseVORSTWZbdfq",nodeNames:"⚠ LineComment BlockComment String Number Bool Null ( ) { } [ ] ; . Operator Punctuation SpecialVar Identifier QuotedIdentifier Keyword Type Bits Bytes Builtin Script Statement CompositeIdentifier Parens Braces Brackets Statement",maxTerm:38,nodeProps:[["isolate",-4,1,2,3,19,""]],skippedNodes:[0,1,2],repeatNodeCount:3,tokenData:"RORO",tokenizers:[0,Bp],topRules:{Script:[0,25]},tokenPrec:0});function Lp(t){let e=t.cursor().moveTo(t.from,-1);for(;/Comment/.test(e.name);)e.moveTo(e.from,-1);return e.node}function Ip(t,e){let i=t.sliceString(e.from,e.to),n=/^([`'"\[])(.*)([`'"\]])$/.exec(i);return n?n[2]:i}function Np(t){return t&&("Identifier"==t.name||"QuotedIdentifier"==t.name)}function Wp(t,e){if("CompositeIdentifier"==e.name){let i=[];for(let n=e.firstChild;n;n=n.nextSibling)Np(n)&&i.push(Ip(t,n));return i}return[Ip(t,e)]}function Hp(t,e){for(let i=[];;){if(!e||"."!=e.name)return i;let n=Lp(e);if(!Np(n))return i;i.unshift(Ip(t,n)),e=Lp(n)}}function Vp(t,e){let i=xa(t).resolveInner(e,-1),n=function(t,e){let i;for(let t=e;!i;t=t.parent){if(!t)return null;"Statement"==t.name&&(i=t)}let n=null;for(let e=i.firstChild,s=!1,r=null;e;e=e.nextSibling){let i="Keyword"==e.name?t.sliceString(e.from,e.to).toLowerCase():null,o=null;if(s)if("as"==i&&r&&Np(e.nextSibling))o=Ip(t,e.nextSibling);else{if(i&&zp.has(i))break;r&&Np(e)&&(o=Ip(t,e))}else s="from"==i;o&&(n||(n=Object.create(null)),n[o]=Wp(t,r)),r=/Identifier$/.test(e.name)?e:null}return n}(t.doc,i);return"Identifier"==i.name||"QuotedIdentifier"==i.name||"Keyword"==i.name?{from:i.from,quoted:"QuotedIdentifier"==i.name?t.doc.sliceString(i.from,i.from+1):null,parents:Hp(t.doc,Lp(i)),aliases:n}:"."==i.name?{from:e,quoted:null,parents:Hp(t.doc,i),aliases:n}:{from:e,quoted:null,parents:[],empty:!0,aliases:n}}const zp=new Set("where group having order union intersect except all distinct limit offset fetch for".split(" "));function Fp(t,e,i){return i.map(i=>({...i,label:i.label[0]==t?i.label:t+i.label+e,apply:void 0}))}const qp=/^\w*$/,_p=/^[`'"\[]?\w*[`'"\]]?$/;function Up(t){return t.self&&"string"==typeof t.self.label}class Qp{constructor(t,e){this.idQuote=t,this.idCaseInsensitive=e,this.list=[],this.children=void 0}child(t){let e=this.children||(this.children=Object.create(null)),i=e[t];return i||(t&&!this.list.some(e=>e.label==t)&&this.list.push($p(t,"type",this.idQuote,this.idCaseInsensitive)),e[t]=new Qp(this.idQuote,this.idCaseInsensitive))}maybeChild(t){return this.children?this.children[t]:null}addCompletion(t){let e=this.list.findIndex(e=>e.label==t.label);e>-1?this.list[e]=t:this.list.push(t)}addCompletions(t){for(let e of t)this.addCompletion("string"==typeof e?$p(e,"property",this.idQuote,this.idCaseInsensitive):e)}addNamespace(t){Array.isArray(t)?this.addCompletions(t):Up(t)?this.addNamespace(t.children):this.addNamespaceObject(t)}addNamespaceObject(t){for(let e of Object.keys(t)){let i=t[e],n=null,s=e.replace(/\\?\./g,t=>"."==t?"\0":t).split("\0"),r=this;Up(i)&&(n=i.self,i=i.children);for(let t=0;t{return i(e?n.toUpperCase():n,21==(s=t[n])?"type":20==s?"keyword":"variable");var s});return s=["QuotedIdentifier","String","LineComment","BlockComment","."],r=bf(n),t=>{for(let e=xa(t.state).resolveInner(t.pos,-1);e;e=e.parent){if(s.indexOf(e.name)>-1)return null;if(e.type.isTop)break}return r(t)};var s,r}let Xp=Ep.configure({props:[Ha.add({Statement:Ua()}),$a.add({Statement:(t,e)=>({from:Math.min(t.from+100,e.doc.lineAt(t.from).to),to:t.to}),BlockComment:t=>({from:t.from+2,to:t.to-2})}),Kl({Keyword:pa.keyword,Type:pa.typeName,Builtin:pa.standard(pa.name),Bits:pa.number,Bytes:pa.string,Bool:pa.bool,Null:pa.null,Number:pa.number,String:pa.string,Identifier:pa.name,QuotedIdentifier:pa.special(pa.string),SpecialVar:pa.special(pa.name),LineComment:pa.lineComment,BlockComment:pa.blockComment,Operator:pa.operator,"Semi Punctuation":pa.punctuation,"( )":pa.paren,"{ }":pa.brace,"[ ]":pa.squareBracket})]});class Gp{constructor(t,e,i){this.dialect=t,this.language=e,this.spec=i}get extension(){return this.language.extension}configureLanguage(t,e){return new Gp(this.dialect,this.language.configure(t,e),this.spec)}static define(t){let e=function(t,e,i,n){let s={};for(let e in Rp)s[e]=(t.hasOwnProperty(e)?t:Rp)[e];return e&&(s.words=Dp(e,i||"",n)),s}(t,t.keywords,t.types,t.builtin),i=ya.define({name:"sql",parser:Xp.configure({tokenizers:[{from:Bp,to:Pp(e)}]}),languageData:{commentTokens:{line:"--",block:{open:"/*",close:"*/"}},closeBrackets:{brackets:["(","[","{","'",'"',"`"]}}});return new Gp(e,i,t)}}function Yp(t,e){return{label:t,type:e,boost:-1}}function Jp(t,e=!1,i){return jp(t.dialect.words,e,i||Yp)}function Zp(t){return t.schema?function(t,e,i,n,s,r){var o;let l=(null===(o=null==r?void 0:r.spec.identifierQuotes)||void 0===o?void 0:o[0])||'"',a=new Qp(l,!!(null==r?void 0:r.spec.caseInsensitiveIdentifiers)),h=s?a.child(s):null;return a.addNamespace(t),e&&(h||a).addCompletions(e),i&&a.addCompletions(i),h&&a.addCompletions(h.list),n&&a.addCompletions((h||a).child(n).list),t=>{let{parents:e,from:i,quoted:s,empty:r,aliases:o}=Vp(t.state,t.pos);if(r&&!t.explicit)return null;o&&1==e.length&&(e=o[e[0]]||e);let l=a;for(let t of e){for(;!l.children||!l.children[t];)if(l==a&&h)l=h;else{if(l!=h||!n)return null;l=l.child(n)}let e=l.maybeChild(t);if(!e)return null;l=e}let c=l.list;if(l==a&&o&&(c=c.concat(Object.keys(o).map(t=>({label:t,type:"constant"})))),s){let e=s[0],n=Kp(e);return{from:i,to:t.state.sliceDoc(t.pos,t.pos+1)==n?t.pos+1:void 0,options:Fp(e,n,c),validFor:_p}}return{from:i,options:c,validFor:qp}}}(t.schema,t.tables,t.schemas,t.defaultTable,t.defaultSchema,t.dialect||em):()=>null}function tm(t){return t.schema?(t.dialect||em).language.data.of({autocomplete:Zp(t)}):[]}const em=Gp.define({}),im=Gp.define({keywords:"and as asc between by case cast count current_date current_time current_timestamp desc distinct each else escape except exists explain filter first for from full generated group having if in index inner intersect into isnull join last left like limit not null or order outer over pragma primary query raise range regexp right rollback row select set table then to union unique using values view virtual when where",types:"null integer real text blob",builtin:"",operatorChars:"*+-%<>!=&|/~",identifierQuotes:'`"',specialVar:"@:?$",caseInsensitiveIdentifiers:!0});function nm(t){return function(t={}){let e=t.dialect||em;return new Pa(e.language,[tm(t),e.language.data.of({autocomplete:Jp(e,t.upperCaseKeywords,t.keywordCompletion)})])}({dialect:im,schema:t.schema,defaultTable:t.defaultTable,defaultSchema:t.defaultSchema})}return t.editorFromTextArea=function(t,e={}){let i=new et,n=new pr({doc:t.value,extensions:[kr.of([{key:"Shift-Enter",run:function(){return t.value=n.state.doc.toString(),t.form.submit(),!0}},{key:"Meta-Enter",run:function(){return t.value=n.state.doc.toString(),t.form.submit(),!0}}]),Gd,pr.lineWrapping,i.of(nm(e))]});n.updateSchema=t=>n.dispatch({effects:i.reconfigure(nm(t))});let s=n.contentDOM.closest(".cm-editor");return new ResizeObserver(function(){n.requestMeasure()}).observe(s,{attributes:!0}),t.parentNode.insertBefore(n.dom,t),t.style.display="none",t.form&&t.form.addEventListener("submit",()=>{t.value=n.state.doc.toString()}),n},t}({}); diff --git a/datasette/static/cm-editor.js b/datasette/static/cm-editor.js index cc88dbd9..dd3f6dd7 100644 --- a/datasette/static/cm-editor.js +++ b/datasette/static/cm-editor.js @@ -1,4 +1,5 @@ import { EditorView, basicSetup } from "codemirror"; +import { Compartment } from "@codemirror/state"; import { keymap } from "@codemirror/view"; import { sql, SQLDialect } from "@codemirror/lang-sql"; @@ -17,10 +18,22 @@ const SQLite = SQLDialect.define({ caseInsensitiveIdentifiers: true, }); +// Builds the sql() extension from a {schema, defaultTable, defaultSchema} conf object +function sqlExtension(conf) { + return sql({ + dialect: SQLite, + schema: conf.schema, + defaultTable: conf.defaultTable, + defaultSchema: conf.defaultSchema, + }); +} + // Utility function from https://codemirror.net/docs/migration/ export function editorFromTextArea(textarea, conf = {}) { - // This could also be configured with a set of tables and columns for better autocomplete: - // https://github.com/codemirror/lang-sql#user-content-sqlconfig.tables + // Wraps the sql() extension so it can be swapped out later via view.updateSchema() + // https://codemirror.net/examples/config/#dynamic-configuration + let sqlCompartment = new Compartment(); + let view = new EditorView({ doc: textarea.value, extensions: [ @@ -46,15 +59,17 @@ export function editorFromTextArea(textarea, conf = {}) { // Meta-Enter from running basicSetup, EditorView.lineWrapping, - sql({ - dialect: SQLite, - schema: conf.schema, - defaultTable: conf.defaultTable, - defaultSchema: conf.defaultSchema, - }), + sqlCompartment.of(sqlExtension(conf)), ], }); + // Allows callers (and plugins) to update the schema/defaultTable/defaultSchema + // used for autocomplete after the editor has already been created. + view.updateSchema = (conf2) => + view.dispatch({ + effects: sqlCompartment.reconfigure(sqlExtension(conf2)), + }); + // Idea taken from https://discuss.codemirror.net/t/resizing-codemirror-6/3265. // Using CSS resize: both and scheduling a measurement when the element changes. let editorDOM = view.contentDOM.closest(".cm-editor"); diff --git a/package-lock.json b/package-lock.json index aeec1594..6e6fc4f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "name": "datasette", "dependencies": { "@codemirror/lang-sql": "^6.10.0", + "@codemirror/state": "^6.7.1", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-terser": "^0.1.0", "codemirror": "^6.0.2", diff --git a/package.json b/package.json index 91335fb5..53126ba6 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "@codemirror/lang-sql": "^6.10.0", + "@codemirror/state": "^6.7.1", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-terser": "^0.1.0", "codemirror": "^6.0.2", From b9716d42780363f8e61ad475ac9cbe8e7c9c6658 Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Fri, 10 Jul 2026 10:56:21 -0700 Subject: [PATCH 3/6] Add /{database}/-/editor-schema.json endpoint for SQL editor consumers Neutral {database, tables: [{name, view, columns: [{name, type}]}]} shape, gated on view-database + execute-sql with no table-name leak on 403, hidden tables excluded. /-/schema.json was already taken by the DDL endpoint, hence editor-schema.json. _editor_schema() now maps from the shared _schema_tables() introspection helper. Co-Authored-By: Claude Fable 5 --- datasette/app.py | 5 + datasette/views/query_helpers.py | 86 +++++++++++----- datasette/views/special.py | 53 ++++++++++ docs/json_api.rst | 54 ++++++++++ tests/test_schema_endpoints.py | 164 +++++++++++++++++++++++++++++++ 5 files changed, 338 insertions(+), 24 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 4ba5d20f..3d7037ac 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -85,6 +85,7 @@ from .views.special import ( JumpView, InstanceSchemaView, DatabaseSchemaView, + DatabaseEditorSchemaView, TableSchemaView, ) from .views.table import ( @@ -2716,6 +2717,10 @@ class Datasette: DatabaseSchemaView.as_view(self), r"/(?P[^\/\.]+)/-/schema(\.(?Pjson|md))?$", ) + add_route( + DatabaseEditorSchemaView.as_view(self), + r"/(?P[^\/\.]+)/-/editor-schema\.json$", + ) add_route( QueryParametersView.as_view(self), r"/(?P[^\/\.]+)/-/query/parameters$", diff --git a/datasette/views/query_helpers.py b/datasette/views/query_helpers.py index 0e02f2eb..014026f5 100644 --- a/datasette/views/query_helpers.py +++ b/datasette/views/query_helpers.py @@ -649,6 +649,52 @@ def _column_completion(name, type_): return completion +async def _schema_tables(datasette, database_name, *, include_hidden=True): + """ + Neutral introspection of a database's tables and views for SQL editors. + + Returns an ordered list of dicts, one per table or view:: + + {"name": str, "view": bool, + "columns": [{"name": str, "type": str}, ...]} + + ``type`` is the SQLite declared column type (empty string when the column + has no declared type). Regular-table columns come from the internal + ``catalog_columns`` catalog; views are absent from that catalog so their + columns are read directly via PRAGMA table_xinfo. Hidden tables (FTS shadow + tables and the like) are excluded unless ``include_hidden`` is True. This is + the shared, serialization-agnostic source for both ``_editor_schema`` (which + maps it to lang-sql Completion objects) and the ``/-/editor-schema.json`` + endpoint (which emits it directly). + """ + internal_db = datasette.get_internal_database() + result = await internal_db.execute( + "select table_name, name, type from catalog_columns where database_name = ?", + [database_name], + ) + table_columns = {} + for row in result.rows: + table_columns.setdefault(row["table_name"], []).append( + {"name": row["name"], "type": row["type"]} + ) + db = datasette.get_database(database_name) + hidden = set() if include_hidden else set(await db.hidden_table_names()) + tables = [] + for table_name, columns in table_columns.items(): + if table_name in hidden: + continue + tables.append({"name": table_name, "view": False, "columns": columns}) + # Views are not represented in catalog_columns, so pull their real columns + # directly (PRAGMA table_xinfo works against views too). + for view_name in await db.view_names(): + columns = [ + {"name": column.name, "type": column.type} + for column in await db.table_column_details(view_name) + ] + tables.append({"name": view_name, "view": True, "columns": columns}) + return tables + + async def _editor_schema(datasette, database_name): """ Build a lang-sql SQLNamespace for the CodeMirror SQL editor autocomplete. @@ -659,29 +705,21 @@ async def _editor_schema(datasette, database_name): container so the popup can label them as views while still completing their real columns. See @codemirror/lang-sql >= 6.6 SQLNamespace / Completion. """ - internal_db = datasette.get_internal_database() - result = await internal_db.execute( - "select table_name, name, type from catalog_columns where database_name = ?", - [database_name], - ) schema = {} - for row in result.rows: - schema.setdefault(row["table_name"], []).append( - _column_completion(row["name"], row["type"]) - ) - # Views are not represented in catalog_columns, so pull their real columns - # directly (PRAGMA table_xinfo works against views too). - db = datasette.get_database(database_name) - for view_name in await db.view_names(): - columns = await db.table_column_details(view_name) - schema[view_name] = { - "self": { - "label": view_name, - "type": "class", - "detail": "view", - }, - "children": [ - _column_completion(column.name, column.type) for column in columns - ], - } + for table in await _schema_tables(datasette, database_name, include_hidden=True): + completions = [ + _column_completion(column["name"], column["type"]) + for column in table["columns"] + ] + if table["view"]: + schema[table["name"]] = { + "self": { + "label": table["name"], + "type": "class", + "detail": "view", + }, + "children": completions, + } + else: + schema[table["name"]] = completions return schema diff --git a/datasette/views/special.py b/datasette/views/special.py index c13191a1..c92ebc8f 100644 --- a/datasette/views/special.py +++ b/datasette/views/special.py @@ -1345,6 +1345,59 @@ class DatabaseSchemaView(SchemaBaseView): return await self.format_html_response(request, schemas) +class DatabaseEditorSchemaView(BaseView): + """ + JSON introspection of a database's tables, views and columns shaped for SQL + editor autocomplete consumers (the CodeMirror ```` + component and external clients such as datasette-paper). + + Distinct from :class:`DatabaseSchemaView` (``//-/schema.json``), which + returns the raw DDL as a SQL string gated on ``view-database`` alone. This + endpoint returns a neutral structured payload and is gated on both + ``view-database`` and ``execute-sql`` — the same permissions as the inline + editor schema handed to the SQL query page. + """ + + name = "database_editor_schema" + has_json_alternate = False + + async def get(self, request): + from .query_helpers import _schema_tables + + database_name = request.url_vars["database"] + + # view-database is checked first so actors without it cannot + # distinguish an existing database from a missing one, and a denied + # request only ever leaks the permission action name, never table names. + await self.ds.ensure_permission( + action="view-database", + resource=DatabaseResource(database=database_name), + actor=request.actor, + ) + if database_name not in self.ds.databases: + headers = {} + if self.ds.cors: + add_cors_headers(headers) + return Response.json( + error_body("Database not found", 404), status=404, headers=headers + ) + await self.ds.ensure_permission( + action="execute-sql", + resource=DatabaseResource(database=database_name), + actor=request.actor, + ) + + await self.ds.refresh_schemas() + tables = await _schema_tables(self.ds, database_name, include_hidden=False) + + headers = {} + if self.ds.cors: + add_cors_headers(headers) + return Response.json( + {"database": database_name, "tables": tables}, headers=headers + ) + + class TableSchemaView(SchemaBaseView): """ Displays schema for a specific table. diff --git a/docs/json_api.rst b/docs/json_api.rst index a96fd73d..b3eace7b 100644 --- a/docs/json_api.rst +++ b/docs/json_api.rst @@ -152,6 +152,60 @@ Values for named SQL parameters can be provided as additional query string param The response uses the same default representation described above. +.. _json_api_editor_schema: + +Schema for SQL editors +---------------------- + +The ``/-/editor-schema.json`` endpoint returns a machine-readable description of +a database's tables, views and columns, shaped for SQL editor autocomplete. It +powers Datasette's own CodeMirror SQL editor and is available for external +consumers such as embeddable editor components. + +:: + + GET //-/editor-schema.json + +Access requires both the :ref:`actions_view_database` and +:ref:`actions_execute_sql` permissions for the database - the same gate as the +inline editor schema on the SQL query page. A request that fails either check +receives a ``403`` JSON error that does not reveal any table or column names. + +The response is a neutral structure - a ``database`` name and a list of +``tables``, each with a ``view`` flag (``true`` for SQL views) and a list of +``columns`` carrying the SQLite declared ``type`` (an empty string when the +column has no declared type): + +.. code-block:: json + + { + "database": "fixtures", + "tables": [ + { + "name": "facetable", + "view": false, + "columns": [ + {"name": "pk", "type": "INTEGER"}, + {"name": "state", "type": "TEXT"} + ] + }, + { + "name": "paginated_view", + "view": true, + "columns": [ + {"name": "content", "type": "TEXT"} + ] + } + ] + } + +Hidden tables - such as the shadow tables that back SQLite full-text search - +are excluded from the response. + +This endpoint is distinct from the :ref:`database schema endpoint ` +at ``//-/schema.json``, which returns the raw ``CREATE`` statements as +a SQL string. + .. _json_api_shapes: Different shapes diff --git a/tests/test_schema_endpoints.py b/tests/test_schema_endpoints.py index c95d8614..f4fc8aa0 100644 --- a/tests/test_schema_endpoints.py +++ b/tests/test_schema_endpoints.py @@ -1,3 +1,5 @@ +import json + import pytest import pytest_asyncio from datasette.app import Datasette @@ -245,3 +247,165 @@ async def test_table_not_exists(schema_ds): response = await schema_ds.client.get("/schema_public_db/nonexistent/-/schema.md") assert response.status_code == 404 assert "not found" in response.text.lower() + + +# --------------------------------------------------------------------------- +# //-/editor-schema.json — neutral structured schema for SQL editors +# --------------------------------------------------------------------------- + + +@pytest_asyncio.fixture(scope="module") +async def editor_schema_ds(): + """Datasette instance exercising the editor-schema endpoint. + + - public db: tables + a view + an FTS table (hidden shadow tables) + - private db: gated behind view-database (allow root only) + - noexec db: view-database allowed for anyone, execute-sql denied + """ + ds = Datasette( + config={ + "databases": { + "editor_private_db": {"allow": {"id": "root"}}, + "editor_noexec_db": { + # Everyone may view the database, but nobody may run SQL + "allow_sql": {"id": "root"}, + }, + } + } + ) + + public_db = ds.add_memory_database("editor_public_db") + await public_db.execute_write( + "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)" + ) + await public_db.execute_write( + "CREATE TABLE posts (id INTEGER PRIMARY KEY, title TEXT, body TEXT)" + ) + await public_db.execute_write( + "CREATE VIEW recent_posts AS SELECT id, title FROM posts ORDER BY id DESC" + ) + # An FTS table produces hidden shadow tables (users_fts_data, etc.) + await public_db.execute_write( + "CREATE VIRTUAL TABLE users_fts USING fts5(name, content=users)" + ) + + private_db = ds.add_memory_database("editor_private_db") + await private_db.execute_write( + "CREATE TABLE secret_data (id INTEGER PRIMARY KEY, value TEXT)" + ) + + noexec_db = ds.add_memory_database("editor_noexec_db") + await noexec_db.execute_write( + "CREATE TABLE locked (id INTEGER PRIMARY KEY, value TEXT)" + ) + + await ds.invoke_startup() + await ds.refresh_schemas() + return ds + + +@pytest.mark.asyncio +async def test_editor_schema_allowed_shape(editor_schema_ds): + """Authorized fetch returns tables, columns, types and views in the + documented neutral shape.""" + response = await editor_schema_ds.client.get( + "/editor_public_db/-/editor-schema.json" + ) + assert response.status_code == 200 + data = response.json() + assert data["database"] == "editor_public_db" + assert isinstance(data["tables"], list) + + by_name = {t["name"]: t for t in data["tables"]} + + # Regular table with columns + declared types + users = by_name["users"] + assert users["view"] is False + assert users["columns"] == [ + {"name": "id", "type": "INTEGER"}, + {"name": "name", "type": "TEXT"}, + ] + + posts = by_name["posts"] + assert posts["view"] is False + assert {c["name"] for c in posts["columns"]} == {"id", "title", "body"} + + # View is flagged and carries its real columns + view = by_name["recent_posts"] + assert view["view"] is True + assert [c["name"] for c in view["columns"]] == ["id", "title"] + + # Whole payload is JSON-serializable and every entry matches the shape + for table in data["tables"]: + assert set(table) == {"name", "view", "columns"} + for column in table["columns"]: + assert set(column) == {"name", "type"} + + +@pytest.mark.asyncio +async def test_editor_schema_excludes_hidden_tables(editor_schema_ds): + """FTS shadow tables (hidden_table_names) must not appear.""" + response = await editor_schema_ds.client.get( + "/editor_public_db/-/editor-schema.json" + ) + assert response.status_code == 200 + names = {t["name"] for t in response.json()["tables"]} + assert not any("_fts_" in name or name.endswith("_fts") for name in names), names + # Sanity: the visible objects are still there + assert {"users", "posts", "recent_posts"} <= names + + +@pytest.mark.asyncio +async def test_editor_schema_denied_view_database_403_no_leak(editor_schema_ds): + """Anonymous user lacking view-database gets a 403 that leaks no names.""" + response = await editor_schema_ds.client.get( + "/editor_private_db/-/editor-schema.json" + ) + assert response.status_code == 403 + body = response.text + assert "secret_data" not in body + data = response.json() + assert data["ok"] is False + assert "secret_data" not in json.dumps(data) + + # The permitted actor can read it + response = await editor_schema_ds.client.get( + "/editor_private_db/-/editor-schema.json", actor={"id": "root"} + ) + assert response.status_code == 200 + names = {t["name"] for t in response.json()["tables"]} + assert "secret_data" in names + + +@pytest.mark.asyncio +async def test_editor_schema_denied_execute_sql_403_no_leak(editor_schema_ds): + """A viewer who lacks execute-sql gets a 403 with no schema data.""" + # Anonymous user may view editor_noexec_db but not run SQL against it + response = await editor_schema_ds.client.get( + "/editor_noexec_db/-/editor-schema.json" + ) + assert response.status_code == 403 + data = response.json() + assert data["ok"] is False + assert "tables" not in data + assert "locked" not in json.dumps(data) + + # The actor granted execute-sql can read the schema + response = await editor_schema_ds.client.get( + "/editor_noexec_db/-/editor-schema.json", actor={"id": "root"} + ) + assert response.status_code == 200 + names = {t["name"] for t in response.json()["tables"]} + assert "locked" in names + + +@pytest.mark.asyncio +async def test_editor_schema_database_not_found(editor_schema_ds): + """A non-existent database returns a 404 JSON error.""" + response = await editor_schema_ds.client.get( + "/nonexistent_db/-/editor-schema.json" + ) + assert response.status_code == 404 + data = response.json() + assert data["ok"] is False + assert "not found" in data["error"].lower() From 49f1660dcda23bce06524e6f349755071fb79b1d Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Fri, 10 Jul 2026 10:59:23 -0700 Subject: [PATCH 4/6] Document DatabaseEditorSchemaView label for docs coverage test Co-Authored-By: Claude Fable 5 --- docs/json_api.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/json_api.rst b/docs/json_api.rst index b3eace7b..8eeba631 100644 --- a/docs/json_api.rst +++ b/docs/json_api.rst @@ -154,6 +154,8 @@ The response uses the same default representation described above. .. _json_api_editor_schema: +.. _DatabaseEditorSchemaView: + Schema for SQL editors ---------------------- From cc1a24fb4f659580a46da55b0a97790325bc2aa8 Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Fri, 10 Jul 2026 10:59:23 -0700 Subject: [PATCH 5/6] Pass defaultTable to the SQL editor from table-scoped pages The table page's 'View and edit SQL' link now carries ?_table=; QueryView validates it against the actor-visible tables/views for the database before exposing it as default_table, so the editor completes that table's columns unprefixed. Stored/canned queries are unaffected. Co-Authored-By: Claude Fable 5 --- datasette/templates/_codemirror_foot.html | 3 ++ datasette/templates/table.html | 2 +- datasette/views/database.py | 15 ++++++++ docs/template_context.rst | 3 ++ tests/test_html.py | 47 +++++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/datasette/templates/_codemirror_foot.html b/datasette/templates/_codemirror_foot.html index a624c8a4..2912292c 100644 --- a/datasette/templates/_codemirror_foot.html +++ b/datasette/templates/_codemirror_foot.html @@ -15,6 +15,9 @@ if (sqlInput) { var editor = (window.editor = cm.editorFromTextArea(sqlInput, { schema, + {% if default_table is defined and default_table %} + defaultTable: {{ default_table|tojson }}, + {% endif %} })); if (sqlFormat) { sqlFormat.addEventListener("click", (ev) => { diff --git a/datasette/templates/table.html b/datasette/templates/table.html index c2131360..cd7c9329 100644 --- a/datasette/templates/table.html +++ b/datasette/templates/table.html @@ -126,7 +126,7 @@ {% endif %} {% if query.sql and allow_execute_sql %} -

View and edit SQL

+

View and edit SQL

{% endif %} diff --git a/datasette/views/database.py b/datasette/views/database.py index d9ca8012..0133289a 100644 --- a/datasette/views/database.py +++ b/datasette/views/database.py @@ -457,6 +457,11 @@ class QueryContext(Context): "help": "Dictionary mapping table names to lists of column names, used to power SQL autocomplete." } ) + default_table: str = field( + metadata={ + "help": "Name of the focal table for this query, if any - set when the query page was reached from a table-scoped context (such as the table page's 'View and edit SQL' link) so the SQL editor can complete that table's columns unprefixed. ``None`` otherwise, including for stored/canned queries." + } + ) alternate_url_json: str = field( metadata={"help": "URL for alternate JSON version of this page"} ) @@ -716,6 +721,15 @@ class QueryView(View): # Create lookup dict for quick access allowed_dict = {r.child: r for r in allowed_tables_page.resources} + # If the request carries a ?_table= pointing at a real (visible) table + # or view in this database, treat this as a table-scoped query - e.g. + # arriving here via the "View and edit SQL" link on a table page - so + # the SQL editor can offer that table's columns unprefixed. Anything + # else (including stored/canned queries, which may reference more + # than one table) leaves this as None. + requested_table = request.args.get("_table") + default_table = requested_table if requested_table in allowed_dict else None + # Are we a stored query? stored_query = None stored_query_write = False @@ -1101,6 +1115,7 @@ class QueryView(View): if allow_execute_sql else {} ), + default_table=default_table, columns=columns, renderers=renderers, url_csv=datasette.urls.path( diff --git a/docs/template_context.rst b/docs/template_context.rst index e445b335..890846bb 100644 --- a/docs/template_context.rst +++ b/docs/template_context.rst @@ -168,6 +168,9 @@ The page for arbitrary SQL queries (/database/-/query?sql=...) and stored querie ``db_is_immutable`` - ``bool`` Boolean indicating if this database is immutable +``default_table`` - ``str`` + Name of the focal table for this query, if any - set when the query page was reached from a table-scoped context (such as the table page's 'View and edit SQL' link) so the SQL editor can complete that table's columns unprefixed. ``None`` otherwise, including for stored/canned queries. + ``display_rows`` - ``list`` List of result rows formatted for HTML display. Each row is a list of rendered cell values in the same order as ``columns``. diff --git a/tests/test_html.py b/tests/test_html.py index b4c47d80..f53ed09c 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -284,6 +284,53 @@ async def test_query_page_with_no_sql(ds_client): assert 'class="rows-and-columns"' not in response.text +@pytest.mark.asyncio +async def test_table_page_view_and_edit_sql_link_carries_table(ds_client): + # The table page's "View and edit SQL" link should point at the query + # page with a &_table= param identifying the focal table, so the SQL + # editor can offer that table's columns unprefixed. + response = await ds_client.get("/fixtures/facetable") + assert response.status_code == 200 + soup = Soup(response.content, "html.parser") + link = soup.find("span", string="View and edit SQL").find_parent("a") + assert link is not None + assert "_table=facetable" in link["href"] + + +@pytest.mark.asyncio +async def test_query_page_default_table_from_table_scoped_link(ds_client): + # Following the table page's edit-SQL link should result in a query page + # whose SQL editor is initialized with defaultTable set to that table. + table_response = await ds_client.get("/fixtures/facetable") + soup = Soup(table_response.content, "html.parser") + href = soup.find("span", string="View and edit SQL").find_parent("a")["href"] + response = await ds_client.get(href, follow_redirects=True) + assert response.status_code == 200 + assert 'defaultTable: "facetable"' in response.text + + +@pytest.mark.asyncio +async def test_query_page_no_default_table_without_table_scope(ds_client): + # The plain database query page (no focal table) should not set + # defaultTable at all. + response = await ds_client.get("/fixtures/-/query?sql=select+1") + assert response.status_code == 200 + assert "defaultTable" not in response.text + + +@pytest.mark.asyncio +async def test_query_page_ignores_invalid_table_param(ds_client): + # A ?_table= value that isn't a real table/view in this database should + # not be reflected back into the page - and should not break execution + # of the query itself (leading-underscore params are not treated as SQL + # bind parameters unless they appear as :name in the SQL). + response = await ds_client.get( + "/fixtures/-/query?sql=select+1&_table=not_a_real_table" + ) + assert response.status_code == 200 + assert "defaultTable" not in response.text + + @pytest.mark.asyncio async def test_query_csv_with_no_sql_is_400(ds_client): # https://github.com/simonw/datasette/issues/2743 From 174099b70757f0d3631ad9e386b17e25778ebe91 Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Fri, 10 Jul 2026 11:01:38 -0700 Subject: [PATCH 6/6] Update test_execute_sql schema assertions for rich completion shape Follow-up to d12f0d2c: the test regexes the inlined schema= JS and still asserted the old flat list-of-strings shape. Co-Authored-By: Claude Fable 5 --- tests/test_permissions.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 88fe577f..892777e1 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -295,13 +295,24 @@ def test_execute_sql(config): # Extract the schema= portion of the JavaScript schema_json = schema_re.search(response_text).group(1) schema = json.loads(schema_json) - assert set(schema["attraction_characteristic"]) == {"name", "pk"} - assert schema["paginated_view"] == [] + assert {c["label"] for c in schema["attraction_characteristic"]} == { + "name", + "pk", + } + # Views are self/children containers carrying their real columns + assert schema["paginated_view"]["self"]["detail"] == "view" + assert {c["label"] for c in schema["paginated_view"]["children"]} == { + "content", + "content_extra", + } assert form_fragment in response_text query_response = client.get("/fixtures/-/query?sql=select+1", cookies=cookies) assert query_response.status == 200 schema2 = json.loads(schema_re.search(query_response.text).group(1)) - assert set(schema2["attraction_characteristic"]) == {"name", "pk"} + assert {c["label"] for c in schema2["attraction_characteristic"]} == { + "name", + "pk", + } assert ( client.get("/fixtures/facet_cities?_where=id=3", cookies=cookies).status == 200