arize-phoenix 11.23.1__py3-none-any.whl → 12.28.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {arize_phoenix-11.23.1.dist-info → arize_phoenix-12.28.1.dist-info}/METADATA +61 -36
- {arize_phoenix-11.23.1.dist-info → arize_phoenix-12.28.1.dist-info}/RECORD +212 -162
- {arize_phoenix-11.23.1.dist-info → arize_phoenix-12.28.1.dist-info}/WHEEL +1 -1
- {arize_phoenix-11.23.1.dist-info → arize_phoenix-12.28.1.dist-info}/licenses/IP_NOTICE +1 -1
- phoenix/__generated__/__init__.py +0 -0
- phoenix/__generated__/classification_evaluator_configs/__init__.py +20 -0
- phoenix/__generated__/classification_evaluator_configs/_document_relevance_classification_evaluator_config.py +17 -0
- phoenix/__generated__/classification_evaluator_configs/_hallucination_classification_evaluator_config.py +17 -0
- phoenix/__generated__/classification_evaluator_configs/_models.py +18 -0
- phoenix/__generated__/classification_evaluator_configs/_tool_selection_classification_evaluator_config.py +17 -0
- phoenix/__init__.py +2 -1
- phoenix/auth.py +27 -2
- phoenix/config.py +1594 -81
- phoenix/db/README.md +546 -28
- phoenix/db/bulk_inserter.py +119 -116
- phoenix/db/engines.py +140 -33
- phoenix/db/facilitator.py +22 -1
- phoenix/db/helpers.py +818 -65
- phoenix/db/iam_auth.py +64 -0
- phoenix/db/insertion/dataset.py +133 -1
- phoenix/db/insertion/document_annotation.py +9 -6
- phoenix/db/insertion/evaluation.py +2 -3
- phoenix/db/insertion/helpers.py +2 -2
- phoenix/db/insertion/session_annotation.py +176 -0
- phoenix/db/insertion/span_annotation.py +3 -4
- phoenix/db/insertion/trace_annotation.py +3 -4
- phoenix/db/insertion/types.py +41 -18
- phoenix/db/migrations/versions/01a8342c9cdf_add_user_id_on_datasets.py +40 -0
- phoenix/db/migrations/versions/0df286449799_add_session_annotations_table.py +105 -0
- phoenix/db/migrations/versions/272b66ff50f8_drop_single_indices.py +119 -0
- phoenix/db/migrations/versions/58228d933c91_dataset_labels.py +67 -0
- phoenix/db/migrations/versions/699f655af132_experiment_tags.py +57 -0
- phoenix/db/migrations/versions/735d3d93c33e_add_composite_indices.py +41 -0
- phoenix/db/migrations/versions/ab513d89518b_add_user_id_on_dataset_versions.py +40 -0
- phoenix/db/migrations/versions/d0690a79ea51_users_on_experiments.py +40 -0
- phoenix/db/migrations/versions/deb2c81c0bb2_dataset_splits.py +139 -0
- phoenix/db/migrations/versions/e76cbd66ffc3_add_experiments_dataset_examples.py +87 -0
- phoenix/db/models.py +364 -56
- phoenix/db/pg_config.py +10 -0
- phoenix/db/types/trace_retention.py +7 -6
- phoenix/experiments/functions.py +69 -19
- phoenix/inferences/inferences.py +1 -2
- phoenix/server/api/auth.py +9 -0
- phoenix/server/api/auth_messages.py +46 -0
- phoenix/server/api/context.py +60 -0
- phoenix/server/api/dataloaders/__init__.py +36 -0
- phoenix/server/api/dataloaders/annotation_summaries.py +60 -8
- phoenix/server/api/dataloaders/average_experiment_repeated_run_group_latency.py +50 -0
- phoenix/server/api/dataloaders/average_experiment_run_latency.py +17 -24
- phoenix/server/api/dataloaders/cache/two_tier_cache.py +1 -2
- phoenix/server/api/dataloaders/dataset_dataset_splits.py +52 -0
- phoenix/server/api/dataloaders/dataset_example_revisions.py +0 -1
- phoenix/server/api/dataloaders/dataset_example_splits.py +40 -0
- phoenix/server/api/dataloaders/dataset_examples_and_versions_by_experiment_run.py +47 -0
- phoenix/server/api/dataloaders/dataset_labels.py +36 -0
- phoenix/server/api/dataloaders/document_evaluation_summaries.py +2 -2
- phoenix/server/api/dataloaders/document_evaluations.py +6 -9
- phoenix/server/api/dataloaders/experiment_annotation_summaries.py +88 -34
- phoenix/server/api/dataloaders/experiment_dataset_splits.py +43 -0
- phoenix/server/api/dataloaders/experiment_error_rates.py +21 -28
- phoenix/server/api/dataloaders/experiment_repeated_run_group_annotation_summaries.py +77 -0
- phoenix/server/api/dataloaders/experiment_repeated_run_groups.py +57 -0
- phoenix/server/api/dataloaders/experiment_runs_by_experiment_and_example.py +44 -0
- phoenix/server/api/dataloaders/latency_ms_quantile.py +40 -8
- phoenix/server/api/dataloaders/record_counts.py +37 -10
- phoenix/server/api/dataloaders/session_annotations_by_session.py +29 -0
- phoenix/server/api/dataloaders/span_cost_summary_by_experiment_repeated_run_group.py +64 -0
- phoenix/server/api/dataloaders/span_cost_summary_by_project.py +28 -14
- phoenix/server/api/dataloaders/span_costs.py +3 -9
- phoenix/server/api/dataloaders/table_fields.py +2 -2
- phoenix/server/api/dataloaders/token_prices_by_model.py +30 -0
- phoenix/server/api/dataloaders/trace_annotations_by_trace.py +27 -0
- phoenix/server/api/exceptions.py +5 -1
- phoenix/server/api/helpers/playground_clients.py +263 -83
- phoenix/server/api/helpers/playground_spans.py +2 -1
- phoenix/server/api/helpers/playground_users.py +26 -0
- phoenix/server/api/helpers/prompts/conversions/google.py +103 -0
- phoenix/server/api/helpers/prompts/models.py +61 -19
- phoenix/server/api/input_types/{SpanAnnotationFilter.py → AnnotationFilter.py} +22 -14
- phoenix/server/api/input_types/ChatCompletionInput.py +3 -0
- phoenix/server/api/input_types/CreateProjectSessionAnnotationInput.py +37 -0
- phoenix/server/api/input_types/DatasetFilter.py +5 -2
- phoenix/server/api/input_types/ExperimentRunSort.py +237 -0
- phoenix/server/api/input_types/GenerativeModelInput.py +3 -0
- phoenix/server/api/input_types/ProjectSessionSort.py +158 -1
- phoenix/server/api/input_types/PromptVersionInput.py +47 -1
- phoenix/server/api/input_types/SpanSort.py +3 -2
- phoenix/server/api/input_types/UpdateAnnotationInput.py +34 -0
- phoenix/server/api/input_types/UserRoleInput.py +1 -0
- phoenix/server/api/mutations/__init__.py +8 -0
- phoenix/server/api/mutations/annotation_config_mutations.py +8 -8
- phoenix/server/api/mutations/api_key_mutations.py +15 -20
- phoenix/server/api/mutations/chat_mutations.py +106 -37
- phoenix/server/api/mutations/dataset_label_mutations.py +243 -0
- phoenix/server/api/mutations/dataset_mutations.py +21 -16
- phoenix/server/api/mutations/dataset_split_mutations.py +351 -0
- phoenix/server/api/mutations/experiment_mutations.py +2 -2
- phoenix/server/api/mutations/export_events_mutations.py +3 -3
- phoenix/server/api/mutations/model_mutations.py +11 -9
- phoenix/server/api/mutations/project_mutations.py +4 -4
- phoenix/server/api/mutations/project_session_annotations_mutations.py +158 -0
- phoenix/server/api/mutations/project_trace_retention_policy_mutations.py +8 -4
- phoenix/server/api/mutations/prompt_label_mutations.py +74 -65
- phoenix/server/api/mutations/prompt_mutations.py +65 -129
- phoenix/server/api/mutations/prompt_version_tag_mutations.py +11 -8
- phoenix/server/api/mutations/span_annotations_mutations.py +15 -10
- phoenix/server/api/mutations/trace_annotations_mutations.py +13 -8
- phoenix/server/api/mutations/trace_mutations.py +3 -3
- phoenix/server/api/mutations/user_mutations.py +55 -26
- phoenix/server/api/queries.py +501 -617
- phoenix/server/api/routers/__init__.py +2 -2
- phoenix/server/api/routers/auth.py +141 -87
- phoenix/server/api/routers/ldap.py +229 -0
- phoenix/server/api/routers/oauth2.py +349 -101
- phoenix/server/api/routers/v1/__init__.py +22 -4
- phoenix/server/api/routers/v1/annotation_configs.py +19 -30
- phoenix/server/api/routers/v1/annotations.py +455 -13
- phoenix/server/api/routers/v1/datasets.py +355 -68
- phoenix/server/api/routers/v1/documents.py +142 -0
- phoenix/server/api/routers/v1/evaluations.py +20 -28
- phoenix/server/api/routers/v1/experiment_evaluations.py +16 -6
- phoenix/server/api/routers/v1/experiment_runs.py +335 -59
- phoenix/server/api/routers/v1/experiments.py +475 -47
- phoenix/server/api/routers/v1/projects.py +16 -50
- phoenix/server/api/routers/v1/prompts.py +50 -39
- phoenix/server/api/routers/v1/sessions.py +108 -0
- phoenix/server/api/routers/v1/spans.py +156 -96
- phoenix/server/api/routers/v1/traces.py +51 -77
- phoenix/server/api/routers/v1/users.py +64 -24
- phoenix/server/api/routers/v1/utils.py +3 -7
- phoenix/server/api/subscriptions.py +257 -93
- phoenix/server/api/types/Annotation.py +90 -23
- phoenix/server/api/types/ApiKey.py +13 -17
- phoenix/server/api/types/AuthMethod.py +1 -0
- phoenix/server/api/types/ChatCompletionSubscriptionPayload.py +1 -0
- phoenix/server/api/types/Dataset.py +199 -72
- phoenix/server/api/types/DatasetExample.py +88 -18
- phoenix/server/api/types/DatasetExperimentAnnotationSummary.py +10 -0
- phoenix/server/api/types/DatasetLabel.py +57 -0
- phoenix/server/api/types/DatasetSplit.py +98 -0
- phoenix/server/api/types/DatasetVersion.py +49 -4
- phoenix/server/api/types/DocumentAnnotation.py +212 -0
- phoenix/server/api/types/Experiment.py +215 -68
- phoenix/server/api/types/ExperimentComparison.py +3 -9
- phoenix/server/api/types/ExperimentRepeatedRunGroup.py +155 -0
- phoenix/server/api/types/ExperimentRepeatedRunGroupAnnotationSummary.py +9 -0
- phoenix/server/api/types/ExperimentRun.py +120 -70
- phoenix/server/api/types/ExperimentRunAnnotation.py +158 -39
- phoenix/server/api/types/GenerativeModel.py +95 -42
- phoenix/server/api/types/GenerativeProvider.py +1 -1
- phoenix/server/api/types/ModelInterface.py +7 -2
- phoenix/server/api/types/PlaygroundModel.py +12 -2
- phoenix/server/api/types/Project.py +218 -185
- phoenix/server/api/types/ProjectSession.py +146 -29
- phoenix/server/api/types/ProjectSessionAnnotation.py +187 -0
- phoenix/server/api/types/ProjectTraceRetentionPolicy.py +1 -1
- phoenix/server/api/types/Prompt.py +119 -39
- phoenix/server/api/types/PromptLabel.py +42 -25
- phoenix/server/api/types/PromptVersion.py +11 -8
- phoenix/server/api/types/PromptVersionTag.py +65 -25
- phoenix/server/api/types/Span.py +130 -123
- phoenix/server/api/types/SpanAnnotation.py +189 -42
- phoenix/server/api/types/SystemApiKey.py +65 -1
- phoenix/server/api/types/Trace.py +184 -53
- phoenix/server/api/types/TraceAnnotation.py +149 -50
- phoenix/server/api/types/User.py +128 -33
- phoenix/server/api/types/UserApiKey.py +73 -26
- phoenix/server/api/types/node.py +10 -0
- phoenix/server/api/types/pagination.py +11 -2
- phoenix/server/app.py +154 -36
- phoenix/server/authorization.py +5 -4
- phoenix/server/bearer_auth.py +13 -5
- phoenix/server/cost_tracking/cost_model_lookup.py +42 -14
- phoenix/server/cost_tracking/model_cost_manifest.json +1085 -194
- phoenix/server/daemons/generative_model_store.py +61 -9
- phoenix/server/daemons/span_cost_calculator.py +10 -8
- phoenix/server/dml_event.py +13 -0
- phoenix/server/email/sender.py +29 -2
- phoenix/server/grpc_server.py +9 -9
- phoenix/server/jwt_store.py +8 -6
- phoenix/server/ldap.py +1449 -0
- phoenix/server/main.py +9 -3
- phoenix/server/oauth2.py +330 -12
- phoenix/server/prometheus.py +43 -6
- phoenix/server/rate_limiters.py +4 -9
- phoenix/server/retention.py +33 -20
- phoenix/server/session_filters.py +49 -0
- phoenix/server/static/.vite/manifest.json +51 -53
- phoenix/server/static/assets/components-BreFUQQa.js +6702 -0
- phoenix/server/static/assets/{index-BPCwGQr8.js → index-CTQoemZv.js} +42 -35
- phoenix/server/static/assets/pages-DBE5iYM3.js +9524 -0
- phoenix/server/static/assets/vendor-BGzfc4EU.css +1 -0
- phoenix/server/static/assets/vendor-DCE4v-Ot.js +920 -0
- phoenix/server/static/assets/vendor-codemirror-D5f205eT.js +25 -0
- phoenix/server/static/assets/{vendor-recharts-Bw30oz1A.js → vendor-recharts-V9cwpXsm.js} +7 -7
- phoenix/server/static/assets/{vendor-shiki-DZajAPeq.js → vendor-shiki-Do--csgv.js} +1 -1
- phoenix/server/static/assets/vendor-three-CmB8bl_y.js +3840 -0
- phoenix/server/templates/index.html +7 -1
- phoenix/server/thread_server.py +1 -2
- phoenix/server/utils.py +74 -0
- phoenix/session/client.py +55 -1
- phoenix/session/data_extractor.py +5 -0
- phoenix/session/evaluation.py +8 -4
- phoenix/session/session.py +44 -8
- phoenix/settings.py +2 -0
- phoenix/trace/attributes.py +80 -13
- phoenix/trace/dsl/query.py +2 -0
- phoenix/trace/projects.py +5 -0
- phoenix/utilities/template_formatters.py +1 -1
- phoenix/version.py +1 -1
- phoenix/server/api/types/Evaluation.py +0 -39
- phoenix/server/static/assets/components-D0DWAf0l.js +0 -5650
- phoenix/server/static/assets/pages-Creyamao.js +0 -8612
- phoenix/server/static/assets/vendor-CU36oj8y.js +0 -905
- phoenix/server/static/assets/vendor-CqDb5u4o.css +0 -1
- phoenix/server/static/assets/vendor-arizeai-Ctgw0e1G.js +0 -168
- phoenix/server/static/assets/vendor-codemirror-Cojjzqb9.js +0 -25
- phoenix/server/static/assets/vendor-three-BLWp5bic.js +0 -2998
- phoenix/utilities/deprecation.py +0 -31
- {arize_phoenix-11.23.1.dist-info → arize_phoenix-12.28.1.dist-info}/entry_points.txt +0 -0
- {arize_phoenix-11.23.1.dist-info → arize_phoenix-12.28.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-shiki-DZajAPeq.js","assets/vendor-CU36oj8y.js","assets/vendor-three-BLWp5bic.js","assets/vendor-CqDb5u4o.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{di as kf,dj as ut,dk as Cf,dl as Af,dm as Mf,dn as Ve,dp as Rt,dq as vr,dr as dn,ds as Ef,dt as xr,du as Tf,dv as Of,A as E,z as Df,dw as Pf,dx as Y,dy as wr,r as Ae,dz as Rf,dA as Bf,dB as ha,dC as Lf,dD as ds,dE as ca,dF as If,dG as Nf,dH as Ff,dI as fa,dJ as ua,dK as Vf,dL as da,dM as Hf}from"./vendor-CU36oj8y.js";import{c as Wf,f as $f}from"./vendor-shiki-DZajAPeq.js";var ps={},xo;function zf(){return xo||(xo=1,function(i){var e=kf();class t{lineAt(h){if(h<0||h>this.length)throw new RangeError(`Invalid position ${h} in document of length ${this.length}`);return this.lineInner(h,!1,1,0)}line(h){if(h<1||h>this.lines)throw new RangeError(`Invalid line number ${h} in ${this.lines}-line document`);return this.lineInner(h,!0,1,0)}replace(h,u,d){[h,u]=g(this,h,u);let m=[];return this.decompose(0,h,m,2),d.length&&d.decompose(0,d.length,m,3),this.decompose(u,this.length,m,1),s.from(m,this.length-(u-h)+d.length)}append(h){return this.replace(this.length,this.length,h)}slice(h,u=this.length){[h,u]=g(this,h,u);let d=[];return this.decompose(h,u,d,0),s.from(d,u-h)}eq(h){if(h==this)return!0;if(h.length!=this.length||h.lines!=this.lines)return!1;let u=this.scanIdentical(h,1),d=this.length-this.scanIdentical(h,-1),m=new a(this),b=new a(h);for(let S=u,w=u;;){if(m.next(S),b.next(S),S=0,m.lineBreak!=b.lineBreak||m.done!=b.done||m.value!=b.value)return!1;if(w+=m.value.length,m.done||w>=d)return!0}}iter(h=1){return new a(this,h)}iterRange(h,u=this.length){return new f(this,h,u)}iterLines(h,u){let d;if(h==null)d=this.iter();else{u==null&&(u=this.lines+1);let m=this.line(h).from;d=this.iterRange(m,Math.max(m,u==this.lines+1?this.length:u<=1?0:this.line(u-1).to))}return new c(d)}toString(){return this.sliceString(0)}toJSON(){let h=[];return this.flatten(h),h}constructor(){}static of(h){if(h.length==0)throw new RangeError("A document must have at least one line");return h.length==1&&!h[0]?t.empty:h.length<=32?new n(h):s.from(n.split(h,[]))}}class n extends t{constructor(h,u=r(h)){super(),this.text=h,this.length=u}get lines(){return this.text.length}get children(){return null}lineInner(h,u,d,m){for(let b=0;;b++){let S=this.text[b],w=m+S.length;if((u?d:w)>=h)return new p(m,w,d,S);m=w+1,d++}}decompose(h,u,d,m){let b=h<=0&&u>=this.length?this:new n(l(this.text,h,u),Math.min(u,this.length)-Math.max(0,h));if(m&1){let S=d.pop(),w=o(b.text,S.text.slice(),0,b.length);if(w.length<=32)d.push(new n(w,S.length+b.length));else{let A=w.length>>1;d.push(new n(w.slice(0,A)),new n(w.slice(A)))}}else d.push(b)}replace(h,u,d){if(!(d instanceof n))return super.replace(h,u,d);[h,u]=g(this,h,u);let m=o(this.text,o(d.text,l(this.text,0,h)),u),b=this.length+d.length-(u-h);return m.length<=32?new n(m,b):s.from(n.split(m,[]),b)}sliceString(h,u=this.length,d=`
|
|
3
|
-
`){[h,u]=g(this,h,u);let m="";for(let b=0,S=0;b<=u&&S<this.text.length;S++){let w=this.text[S],A=b+w.length;b>h&&S&&(m+=d),h<A&&u>b&&(m+=w.slice(Math.max(0,h-b),u-b)),b=A+1}return m}flatten(h){for(let u of this.text)h.push(u)}scanIdentical(){return 0}static split(h,u){let d=[],m=-1;for(let b of h)d.push(b),m+=b.length+1,d.length==32&&(u.push(new n(d,m)),d=[],m=-1);return m>-1&&u.push(new n(d,m)),u}}class s extends t{constructor(h,u){super(),this.children=h,this.length=u,this.lines=0;for(let d of h)this.lines+=d.lines}lineInner(h,u,d,m){for(let b=0;;b++){let S=this.children[b],w=m+S.length,A=d+S.lines-1;if((u?A:w)>=h)return S.lineInner(h,u,d,m);m=w+1,d=A+1}}decompose(h,u,d,m){for(let b=0,S=0;S<=u&&b<this.children.length;b++){let w=this.children[b],A=S+w.length;if(h<=A&&u>=S){let O=m&((S<=h?1:0)|(A>=u?2:0));S>=h&&A<=u&&!O?d.push(w):w.decompose(h-S,u-S,d,O)}S=A+1}}replace(h,u,d){if([h,u]=g(this,h,u),d.lines<this.lines)for(let m=0,b=0;m<this.children.length;m++){let S=this.children[m],w=b+S.length;if(h>=b&&u<=w){let A=S.replace(h-b,u-b,d),O=this.lines-S.lines+A.lines;if(A.lines<O>>4&&A.lines>O>>6){let D=this.children.slice();return D[m]=A,new s(D,this.length-(u-h)+d.length)}return super.replace(b,w,A)}b=w+1}return super.replace(h,u,d)}sliceString(h,u=this.length,d=`
|
|
4
|
-
`){[h,u]=g(this,h,u);let m="";for(let b=0,S=0;b<this.children.length&&S<=u;b++){let w=this.children[b],A=S+w.length;S>h&&b&&(m+=d),h<A&&u>S&&(m+=w.sliceString(h-S,u-S,d)),S=A+1}return m}flatten(h){for(let u of this.children)u.flatten(h)}scanIdentical(h,u){if(!(h instanceof s))return 0;let d=0,[m,b,S,w]=u>0?[0,0,this.children.length,h.children.length]:[this.children.length-1,h.children.length-1,-1,-1];for(;;m+=u,b+=u){if(m==S||b==w)return d;let A=this.children[m],O=h.children[b];if(A!=O)return d+A.scanIdentical(O,u);d+=A.length+1}}static from(h,u=h.reduce((d,m)=>d+m.length+1,-1)){let d=0;for(let $ of h)d+=$.lines;if(d<32){let $=[];for(let Z of h)Z.flatten($);return new n($,u)}let m=Math.max(32,d>>5),b=m<<1,S=m>>1,w=[],A=0,O=-1,D=[];function B($){let Z;if($.lines>b&&$ instanceof s)for(let Ke of $.children)B(Ke);else $.lines>S&&(A>S||!A)?(W(),w.push($)):$ instanceof n&&A&&(Z=D[D.length-1])instanceof n&&$.lines+Z.lines<=32?(A+=$.lines,O+=$.length+1,D[D.length-1]=new n(Z.text.concat($.text),Z.length+1+$.length)):(A+$.lines>m&&W(),A+=$.lines,O+=$.length+1,D.push($))}function W(){A!=0&&(w.push(D.length==1?D[0]:s.from(D,O)),O=-1,A=D.length=0)}for(let $ of h)B($);return W(),w.length==1?w[0]:new s(w,u)}}t.empty=new n([""],0);function r(x){let h=-1;for(let u of x)h+=u.length+1;return h}function o(x,h,u=0,d=1e9){for(let m=0,b=0,S=!0;b<x.length&&m<=d;b++){let w=x[b],A=m+w.length;A>=u&&(A>d&&(w=w.slice(0,d-m)),m<u&&(w=w.slice(u-m)),S?(h[h.length-1]+=w,S=!1):h.push(w)),m=A+1}return h}function l(x,h,u){return o(x,[""],h,u)}class a{constructor(h,u=1){this.dir=u,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[h],this.offsets=[u>0?1:(h instanceof n?h.text.length:h.children.length)<<1]}nextInner(h,u){for(this.done=this.lineBreak=!1;;){let d=this.nodes.length-1,m=this.nodes[d],b=this.offsets[d],S=b>>1,w=m instanceof n?m.text.length:m.children.length;if(S==(u>0?w:0)){if(d==0)return this.done=!0,this.value="",this;u>0&&this.offsets[d-1]++,this.nodes.pop(),this.offsets.pop()}else if((b&1)==(u>0?0:1)){if(this.offsets[d]+=u,h==0)return this.lineBreak=!0,this.value=`
|
|
5
|
-
`,this;h--}else if(m instanceof n){let A=m.text[S+(u<0?-1:0)];if(this.offsets[d]+=u,A.length>Math.max(0,h))return this.value=h==0?A:u>0?A.slice(h):A.slice(0,A.length-h),this;h-=A.length}else{let A=m.children[S+(u<0?-1:0)];h>A.length?(h-=A.length,this.offsets[d]+=u):(u<0&&this.offsets[d]--,this.nodes.push(A),this.offsets.push(u>0?1:(A instanceof n?A.text.length:A.children.length)<<1))}}}next(h=0){return h<0&&(this.nextInner(-h,-this.dir),h=this.value.length),this.nextInner(h,this.dir)}}class f{constructor(h,u,d){this.value="",this.done=!1,this.cursor=new a(h,u>d?-1:1),this.pos=u>d?h.length:0,this.from=Math.min(u,d),this.to=Math.max(u,d)}nextInner(h,u){if(u<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;h+=Math.max(0,u<0?this.pos-this.to:this.from-this.pos);let d=u<0?this.pos-this.from:this.to-this.pos;h>d&&(h=d),d-=h;let{value:m}=this.cursor.next(h);return this.pos+=(m.length+h)*u,this.value=m.length<=d?m:u<0?m.slice(m.length-d):m.slice(0,d),this.done=!this.value,this}next(h=0){return h<0?h=Math.max(h,this.from-this.pos):h>0&&(h=Math.min(h,this.to-this.pos)),this.nextInner(h,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class c{constructor(h){this.inner=h,this.afterBreak=!0,this.value="",this.done=!1}next(h=0){let{done:u,lineBreak:d,value:m}=this.inner.next(h);return u&&this.afterBreak?(this.value="",this.afterBreak=!1):u?(this.done=!0,this.value=""):d?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=m,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(t.prototype[Symbol.iterator]=function(){return this.iter()},a.prototype[Symbol.iterator]=f.prototype[Symbol.iterator]=c.prototype[Symbol.iterator]=function(){return this});class p{constructor(h,u,d,m){this.from=h,this.to=u,this.number=d,this.text=m}get length(){return this.to-this.from}}function g(x,h,u){return h=Math.max(0,Math.min(x.length,h)),[h,Math.max(h,Math.min(x.length,u))]}function v(x,h,u=!0,d=!0){return e.findClusterBreak(x,h,u,d)}function k(x){return x>=56320&&x<57344}function C(x){return x>=55296&&x<56320}function M(x,h){let u=x.charCodeAt(h);if(!C(u)||h+1==x.length)return u;let d=x.charCodeAt(h+1);return k(d)?(u-55296<<10)+(d-56320)+65536:u}function T(x){return x<=65535?String.fromCharCode(x):(x-=65536,String.fromCharCode((x>>10)+55296,(x&1023)+56320))}function P(x){return x<65536?1:2}const F=/\r\n?|\n/;i.MapMode=void 0,function(x){x[x.Simple=0]="Simple",x[x.TrackDel=1]="TrackDel",x[x.TrackBefore=2]="TrackBefore",x[x.TrackAfter=3]="TrackAfter"}(i.MapMode||(i.MapMode={}));class L{constructor(h){this.sections=h}get length(){let h=0;for(let u=0;u<this.sections.length;u+=2)h+=this.sections[u];return h}get newLength(){let h=0;for(let u=0;u<this.sections.length;u+=2){let d=this.sections[u+1];h+=d<0?this.sections[u]:d}return h}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(h){for(let u=0,d=0,m=0;u<this.sections.length;){let b=this.sections[u++],S=this.sections[u++];S<0?(h(d,m,b),m+=b):m+=S,d+=b}}iterChangedRanges(h,u=!1){U(this,h,u)}get invertedDesc(){let h=[];for(let u=0;u<this.sections.length;){let d=this.sections[u++],m=this.sections[u++];m<0?h.push(d,m):h.push(m,d)}return new L(h)}composeDesc(h){return this.empty?h:h.empty?this:me(this,h)}mapDesc(h,u=!1){return h.empty?this:_(this,h,u)}mapPos(h,u=-1,d=i.MapMode.Simple){let m=0,b=0;for(let S=0;S<this.sections.length;){let w=this.sections[S++],A=this.sections[S++],O=m+w;if(A<0){if(O>h)return b+(h-m);b+=w}else{if(d!=i.MapMode.Simple&&O>=h&&(d==i.MapMode.TrackDel&&m<h&&O>h||d==i.MapMode.TrackBefore&&m<h||d==i.MapMode.TrackAfter&&O>h))return null;if(O>h||O==h&&u<0&&!w)return h==m||u<0?b:b+A;b+=A}m=O}if(h>m)throw new RangeError(`Position ${h} is out of range for changeset of length ${m}`);return b}touchesRange(h,u=h){for(let d=0,m=0;d<this.sections.length&&m<=u;){let b=this.sections[d++],S=this.sections[d++],w=m+b;if(S>=0&&m<=u&&w>=h)return m<h&&w>u?"cover":!0;m=w}return!1}toString(){let h="";for(let u=0;u<this.sections.length;){let d=this.sections[u++],m=this.sections[u++];h+=(h?" ":"")+d+(m>=0?":"+m:"")}return h}toJSON(){return this.sections}static fromJSON(h){if(!Array.isArray(h)||h.length%2||h.some(u=>typeof u!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new L(h)}static create(h){return new L(h)}}class R extends L{constructor(h,u){super(h),this.inserted=u}apply(h){if(this.length!=h.length)throw new RangeError("Applying change set to a document with the wrong length");return U(this,(u,d,m,b,S)=>h=h.replace(m,m+(d-u),S),!1),h}mapDesc(h,u=!1){return _(this,h,u,!0)}invert(h){let u=this.sections.slice(),d=[];for(let m=0,b=0;m<u.length;m+=2){let S=u[m],w=u[m+1];if(w>=0){u[m]=w,u[m+1]=S;let A=m>>1;for(;d.length<A;)d.push(t.empty);d.push(S?h.slice(b,b+S):t.empty)}b+=S}return new R(u,d)}compose(h){return this.empty?h:h.empty?this:me(this,h,!0)}map(h,u=!1){return h.empty?this:_(this,h,u,!0)}iterChanges(h,u=!1){U(this,h,u)}get desc(){return L.create(this.sections)}filter(h){let u=[],d=[],m=[],b=new Ce(this);e:for(let S=0,w=0;;){let A=S==h.length?1e9:h[S++];for(;w<A||w==A&&b.len==0;){if(b.done)break e;let D=Math.min(b.len,A-w);I(m,D,-1);let B=b.ins==-1?-1:b.off==0?b.ins:0;I(u,D,B),B>0&&z(d,u,b.text),b.forward(D),w+=D}let O=h[S++];for(;w<O;){if(b.done)break e;let D=Math.min(b.len,O-w);I(u,D,-1),I(m,D,b.ins==-1?-1:b.off==0?b.ins:0),b.forward(D),w+=D}}return{changes:new R(u,d),filtered:L.create(m)}}toJSON(){let h=[];for(let u=0;u<this.sections.length;u+=2){let d=this.sections[u],m=this.sections[u+1];m<0?h.push(d):m==0?h.push([d]):h.push([d].concat(this.inserted[u>>1].toJSON()))}return h}static of(h,u,d){let m=[],b=[],S=0,w=null;function A(D=!1){if(!D&&!m.length)return;S<u&&I(m,u-S,-1);let B=new R(m,b);w=w?w.compose(B.map(w)):B,m=[],b=[],S=0}function O(D){if(Array.isArray(D))for(let B of D)O(B);else if(D instanceof R){if(D.length!=u)throw new RangeError(`Mismatched change set length (got ${D.length}, expected ${u})`);A(),w=w?w.compose(D.map(w)):D}else{let{from:B,to:W=B,insert:$}=D;if(B>W||B<0||W>u)throw new RangeError(`Invalid change range ${B} to ${W} (in doc of length ${u})`);let Z=$?typeof $=="string"?t.of($.split(d||F)):$:t.empty,Ke=Z.length;if(B==W&&Ke==0)return;B<S&&A(),B>S&&I(m,B-S,-1),I(m,W-B,Ke),z(b,m,Z),S=W}}return O(h),A(!w),w}static empty(h){return new R(h?[h,-1]:[],[])}static fromJSON(h){if(!Array.isArray(h))throw new RangeError("Invalid JSON representation of ChangeSet");let u=[],d=[];for(let m=0;m<h.length;m++){let b=h[m];if(typeof b=="number")u.push(b,-1);else{if(!Array.isArray(b)||typeof b[0]!="number"||b.some((S,w)=>w&&typeof S!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(b.length==1)u.push(b[0],0);else{for(;d.length<m;)d.push(t.empty);d[m]=t.of(b.slice(1)),u.push(b[0],d[m].length)}}}return new R(u,d)}static createSet(h,u){return new R(h,u)}}function I(x,h,u,d=!1){if(h==0&&u<=0)return;let m=x.length-2;m>=0&&u<=0&&u==x[m+1]?x[m]+=h:m>=0&&h==0&&x[m]==0?x[m+1]+=u:d?(x[m]+=h,x[m+1]+=u):x.push(h,u)}function z(x,h,u){if(u.length==0)return;let d=h.length-2>>1;if(d<x.length)x[x.length-1]=x[x.length-1].append(u);else{for(;x.length<d;)x.push(t.empty);x.push(u)}}function U(x,h,u){let d=x.inserted;for(let m=0,b=0,S=0;S<x.sections.length;){let w=x.sections[S++],A=x.sections[S++];if(A<0)m+=w,b+=w;else{let O=m,D=b,B=t.empty;for(;O+=w,D+=A,A&&d&&(B=B.append(d[S-2>>1])),!(u||S==x.sections.length||x.sections[S+1]<0);)w=x.sections[S++],A=x.sections[S++];h(m,O,b,D,B),m=O,b=D}}}function _(x,h,u,d=!1){let m=[],b=d?[]:null,S=new Ce(x),w=new Ce(h);for(let A=-1;;){if(S.done&&w.len||w.done&&S.len)throw new Error("Mismatched change set lengths");if(S.ins==-1&&w.ins==-1){let O=Math.min(S.len,w.len);I(m,O,-1),S.forward(O),w.forward(O)}else if(w.ins>=0&&(S.ins<0||A==S.i||S.off==0&&(w.len<S.len||w.len==S.len&&!u))){let O=w.len;for(I(m,w.ins,-1);O;){let D=Math.min(S.len,O);S.ins>=0&&A<S.i&&S.len<=D&&(I(m,0,S.ins),b&&z(b,m,S.text),A=S.i),S.forward(D),O-=D}w.next()}else if(S.ins>=0){let O=0,D=S.len;for(;D;)if(w.ins==-1){let B=Math.min(D,w.len);O+=B,D-=B,w.forward(B)}else if(w.ins==0&&w.len<D)D-=w.len,w.next();else break;I(m,O,A<S.i?S.ins:0),b&&A<S.i&&z(b,m,S.text),A=S.i,S.forward(S.len-D)}else{if(S.done&&w.done)return b?R.createSet(m,b):L.create(m);throw new Error("Mismatched change set lengths")}}}function me(x,h,u=!1){let d=[],m=u?[]:null,b=new Ce(x),S=new Ce(h);for(let w=!1;;){if(b.done&&S.done)return m?R.createSet(d,m):L.create(d);if(b.ins==0)I(d,b.len,0,w),b.next();else if(S.len==0&&!S.done)I(d,0,S.ins,w),m&&z(m,d,S.text),S.next();else{if(b.done||S.done)throw new Error("Mismatched change set lengths");{let A=Math.min(b.len2,S.len),O=d.length;if(b.ins==-1){let D=S.ins==-1?-1:S.off?0:S.ins;I(d,A,D,w),m&&D&&z(m,d,S.text)}else S.ins==-1?(I(d,b.off?0:b.len,A,w),m&&z(m,d,b.textBit(A))):(I(d,b.off?0:b.len,S.off?0:S.ins,w),m&&!S.off&&z(m,d,S.text));w=(b.ins>A||S.ins>=0&&S.len>A)&&(w||d.length>O),b.forward2(A),S.forward(A)}}}}class Ce{constructor(h){this.set=h,this.i=0,this.next()}next(){let{sections:h}=this.set;this.i<h.length?(this.len=h[this.i++],this.ins=h[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:h}=this.set,u=this.i-2>>1;return u>=h.length?t.empty:h[u]}textBit(h){let{inserted:u}=this.set,d=this.i-2>>1;return d>=u.length&&!h?t.empty:u[d].slice(this.off,h==null?void 0:this.off+h)}forward(h){h==this.len?this.next():(this.len-=h,this.off+=h)}forward2(h){this.ins==-1?this.forward(h):h==this.ins?this.next():(this.ins-=h,this.off+=h)}}class he{constructor(h,u,d){this.from=h,this.to=u,this.flags=d}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let h=this.flags&7;return h==7?null:h}get goalColumn(){let h=this.flags>>6;return h==16777215?void 0:h}map(h,u=-1){let d,m;return this.empty?d=m=h.mapPos(this.from,u):(d=h.mapPos(this.from,1),m=h.mapPos(this.to,-1)),d==this.from&&m==this.to?this:new he(d,m,this.flags)}extend(h,u=h){if(h<=this.anchor&&u>=this.anchor)return q.range(h,u);let d=Math.abs(h-this.anchor)>Math.abs(u-this.anchor)?h:u;return q.range(this.anchor,d)}eq(h,u=!1){return this.anchor==h.anchor&&this.head==h.head&&(!u||!this.empty||this.assoc==h.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(h){if(!h||typeof h.anchor!="number"||typeof h.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return q.range(h.anchor,h.head)}static create(h,u,d){return new he(h,u,d)}}class q{constructor(h,u){this.ranges=h,this.mainIndex=u}map(h,u=-1){return h.empty?this:q.create(this.ranges.map(d=>d.map(h,u)),this.mainIndex)}eq(h,u=!1){if(this.ranges.length!=h.ranges.length||this.mainIndex!=h.mainIndex)return!1;for(let d=0;d<this.ranges.length;d++)if(!this.ranges[d].eq(h.ranges[d],u))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new q([this.main],0)}addRange(h,u=!0){return q.create([h].concat(this.ranges),u?0:this.mainIndex+1)}replaceRange(h,u=this.mainIndex){let d=this.ranges.slice();return d[u]=h,q.create(d,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(h=>h.toJSON()),main:this.mainIndex}}static fromJSON(h){if(!h||!Array.isArray(h.ranges)||typeof h.main!="number"||h.main>=h.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new q(h.ranges.map(u=>he.fromJSON(u)),h.main)}static single(h,u=h){return new q([q.range(h,u)],0)}static create(h,u=0){if(h.length==0)throw new RangeError("A selection needs at least one range");for(let d=0,m=0;m<h.length;m++){let b=h[m];if(b.empty?b.from<=d:b.from<d)return q.normalized(h.slice(),u);d=b.to}return new q(h,u)}static cursor(h,u=0,d,m){return he.create(h,h,(u==0?0:u<0?8:16)|(d==null?7:Math.min(6,d))|(m??16777215)<<6)}static range(h,u,d,m){let b=(d??16777215)<<6|(m==null?7:Math.min(6,m));return u<h?he.create(u,h,48|b):he.create(h,u,(u>h?8:0)|b)}static normalized(h,u=0){let d=h[u];h.sort((m,b)=>m.from-b.from),u=h.indexOf(d);for(let m=1;m<h.length;m++){let b=h[m],S=h[m-1];if(b.empty?b.from<=S.to:b.from<S.to){let w=S.from,A=Math.max(b.to,S.to);m<=u&&u--,h.splice(--m,2,b.anchor>b.head?q.range(A,w):q.range(w,A))}}return new q(h,u)}}function ue(x,h){for(let u of x.ranges)if(u.to>h)throw new RangeError("Selection points outside of document")}let ge=0;class G{constructor(h,u,d,m,b){this.combine=h,this.compareInput=u,this.compare=d,this.isStatic=m,this.id=ge++,this.default=h([]),this.extensions=typeof b=="function"?b(this):b}get reader(){return this}static define(h={}){return new G(h.combine||(u=>u),h.compareInput||((u,d)=>u===d),h.compare||(h.combine?(u,d)=>u===d:ye),!!h.static,h.enables)}of(h){return new be([],this,0,h)}compute(h,u){if(this.isStatic)throw new Error("Can't compute a static facet");return new be(h,this,1,u)}computeN(h,u){if(this.isStatic)throw new Error("Can't compute a static facet");return new be(h,this,2,u)}from(h,u){return u||(u=d=>d),this.compute([h],d=>u(d.field(h)))}}function ye(x,h){return x==h||x.length==h.length&&x.every((u,d)=>u===h[d])}class be{constructor(h,u,d,m){this.dependencies=h,this.facet=u,this.type=d,this.value=m,this.id=ge++}dynamicSlot(h){var u;let d=this.value,m=this.facet.compareInput,b=this.id,S=h[b]>>1,w=this.type==2,A=!1,O=!1,D=[];for(let B of this.dependencies)B=="doc"?A=!0:B=="selection"?O=!0:(((u=h[B.id])!==null&&u!==void 0?u:1)&1)==0&&D.push(h[B.id]);return{create(B){return B.values[S]=d(B),1},update(B,W){if(A&&W.docChanged||O&&(W.docChanged||W.selection)||re(B,D)){let $=d(B);if(w?!ie($,B.values[S],m):!m($,B.values[S]))return B.values[S]=$,1}return 0},reconfigure:(B,W)=>{let $,Z=W.config.address[b];if(Z!=null){let Ke=_i(W,Z);if(this.dependencies.every(fe=>fe instanceof G?W.facet(fe)===B.facet(fe):fe instanceof gt?W.field(fe,!1)==B.field(fe,!1):!0)||(w?ie($=d(B),Ke,m):m($=d(B),Ke)))return B.values[S]=Ke,0}else $=d(B);return B.values[S]=$,1}}}}function ie(x,h,u){if(x.length!=h.length)return!1;for(let d=0;d<x.length;d++)if(!u(x[d],h[d]))return!1;return!0}function re(x,h){let u=!1;for(let d of h)si(x,d)&1&&(u=!0);return u}function tt(x,h,u){let d=u.map(A=>x[A.id]),m=u.map(A=>A.type),b=d.filter(A=>!(A&1)),S=x[h.id]>>1;function w(A){let O=[];for(let D=0;D<d.length;D++){let B=_i(A,d[D]);if(m[D]==2)for(let W of B)O.push(W);else O.push(B)}return h.combine(O)}return{create(A){for(let O of d)si(A,O);return A.values[S]=w(A),1},update(A,O){if(!re(A,b))return 0;let D=w(A);return h.compare(D,A.values[S])?0:(A.values[S]=D,1)},reconfigure(A,O){let D=re(A,d),B=O.config.facets[h.id],W=O.facet(h);if(B&&!D&&ye(u,B))return A.values[S]=W,0;let $=w(A);return h.compare($,W)?(A.values[S]=W,0):(A.values[S]=$,1)}}}const ot=G.define({static:!0});class gt{constructor(h,u,d,m,b){this.id=h,this.createF=u,this.updateF=d,this.compareF=m,this.spec=b,this.provides=void 0}static define(h){let u=new gt(ge++,h.create,h.update,h.compare||((d,m)=>d===m),h);return h.provide&&(u.provides=h.provide(u)),u}create(h){let u=h.facet(ot).find(d=>d.field==this);return((u==null?void 0:u.create)||this.createF)(h)}slot(h){let u=h[this.id]>>1;return{create:d=>(d.values[u]=this.create(d),1),update:(d,m)=>{let b=d.values[u],S=this.updateF(b,m);return this.compareF(b,S)?0:(d.values[u]=S,1)},reconfigure:(d,m)=>{let b=d.facet(ot),S=m.facet(ot),w;return(w=b.find(A=>A.field==this))&&w!=S.find(A=>A.field==this)?(d.values[u]=w.create(d),1):m.config.address[this.id]!=null?(d.values[u]=m.field(this),0):(d.values[u]=this.create(d),1)}}}init(h){return[this,ot.of({field:this,create:h})]}get extension(){return this}}const yt={lowest:4,low:3,default:2,high:1,highest:0};function ii(x){return h=>new ro(h,x)}const cf={highest:ii(yt.highest),high:ii(yt.high),default:ii(yt.default),low:ii(yt.low),lowest:ii(yt.lowest)};class ro{constructor(h,u){this.inner=h,this.prec=u}}class ni{of(h){return new ss(this,h)}reconfigure(h){return ni.reconfigure.of({compartment:this,extension:h})}get(h){return h.config.compartments.get(this)}}class ss{constructor(h,u){this.compartment=h,this.inner=u}}class ji{constructor(h,u,d,m,b,S){for(this.base=h,this.compartments=u,this.dynamicSlots=d,this.address=m,this.staticValues=b,this.facets=S,this.statusTemplate=[];this.statusTemplate.length<d.length;)this.statusTemplate.push(0)}staticFacet(h){let u=this.address[h.id];return u==null?h.default:this.staticValues[u>>1]}static resolve(h,u,d){let m=[],b=Object.create(null),S=new Map;for(let W of ff(h,u,S))W instanceof gt?m.push(W):(b[W.facet.id]||(b[W.facet.id]=[])).push(W);let w=Object.create(null),A=[],O=[];for(let W of m)w[W.id]=O.length<<1,O.push($=>W.slot($));let D=d==null?void 0:d.config.facets;for(let W in b){let $=b[W],Z=$[0].facet,Ke=D&&D[W]||[];if($.every(fe=>fe.type==0))if(w[Z.id]=A.length<<1|1,ye(Ke,$))A.push(d.facet(Z));else{let fe=Z.combine($.map(us=>us.value));A.push(d&&Z.compare(fe,d.facet(Z))?d.facet(Z):fe)}else{for(let fe of $)fe.type==0?(w[fe.id]=A.length<<1|1,A.push(fe.value)):(w[fe.id]=O.length<<1,O.push(us=>fe.dynamicSlot(us)));w[Z.id]=O.length<<1,O.push(fe=>tt(fe,Z,$))}}let B=O.map(W=>W(w));return new ji(h,S,B,w,A,b)}}function ff(x,h,u){let d=[[],[],[],[],[]],m=new Map;function b(S,w){let A=m.get(S);if(A!=null){if(A<=w)return;let O=d[A].indexOf(S);O>-1&&d[A].splice(O,1),S instanceof ss&&u.delete(S.compartment)}if(m.set(S,w),Array.isArray(S))for(let O of S)b(O,w);else if(S instanceof ss){if(u.has(S.compartment))throw new RangeError("Duplicate use of compartment in extensions");let O=h.get(S.compartment)||S.inner;u.set(S.compartment,O),b(O,w)}else if(S instanceof ro)b(S.inner,S.prec);else if(S instanceof gt)d[w].push(S),S.provides&&b(S.provides,w);else if(S instanceof be)d[w].push(S),S.facet.extensions&&b(S.facet.extensions,yt.default);else{let O=S.extension;if(!O)throw new Error(`Unrecognized extension value in extension set (${S}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);b(O,w)}}return b(x,yt.default),d.reduce((S,w)=>S.concat(w))}function si(x,h){if(h&1)return 2;let u=h>>1,d=x.status[u];if(d==4)throw new Error("Cyclic dependency between fields and/or facets");if(d&2)return d;x.status[u]=4;let m=x.computeSlot(x,x.config.dynamicSlots[u]);return x.status[u]=2|m}function _i(x,h){return h&1?x.config.staticValues[h>>1]:x.values[h>>1]}const oo=G.define(),rs=G.define({combine:x=>x.some(h=>h),static:!0}),lo=G.define({combine:x=>x.length?x[0]:void 0,static:!0}),ao=G.define(),ho=G.define(),co=G.define(),fo=G.define({combine:x=>x.length?x[0]:!1});class At{constructor(h,u){this.type=h,this.value=u}static define(){return new uo}}class uo{of(h){return new At(this,h)}}class po{constructor(h){this.map=h}of(h){return new Se(this,h)}}class Se{constructor(h,u){this.type=h,this.value=u}map(h){let u=this.type.map(this.value,h);return u===void 0?void 0:u==this.value?this:new Se(this.type,u)}is(h){return this.type==h}static define(h={}){return new po(h.map||(u=>u))}static mapEffects(h,u){if(!h.length)return h;let d=[];for(let m of h){let b=m.map(u);b&&d.push(b)}return d}}Se.reconfigure=Se.define(),Se.appendConfig=Se.define();class ve{constructor(h,u,d,m,b,S){this.startState=h,this.changes=u,this.selection=d,this.effects=m,this.annotations=b,this.scrollIntoView=S,this._doc=null,this._state=null,d&&ue(d,u.newLength),b.some(w=>w.type==ve.time)||(this.annotations=b.concat(ve.time.of(Date.now())))}static create(h,u,d,m,b,S){return new ve(h,u,d,m,b,S)}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(h){for(let u of this.annotations)if(u.type==h)return u.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(h){let u=this.annotation(ve.userEvent);return!!(u&&(u==h||u.length>h.length&&u.slice(0,h.length)==h&&u[h.length]=="."))}}ve.time=At.define(),ve.userEvent=At.define(),ve.addToHistory=At.define(),ve.remote=At.define();function uf(x,h){let u=[];for(let d=0,m=0;;){let b,S;if(d<x.length&&(m==h.length||h[m]>=x[d]))b=x[d++],S=x[d++];else if(m<h.length)b=h[m++],S=h[m++];else return u;!u.length||u[u.length-1]<b?u.push(b,S):u[u.length-1]<S&&(u[u.length-1]=S)}}function mo(x,h,u){var d;let m,b,S;return u?(m=h.changes,b=R.empty(h.changes.length),S=x.changes.compose(h.changes)):(m=h.changes.map(x.changes),b=x.changes.mapDesc(h.changes,!0),S=x.changes.compose(m)),{changes:S,selection:h.selection?h.selection.map(b):(d=x.selection)===null||d===void 0?void 0:d.map(m),effects:Se.mapEffects(x.effects,m).concat(Se.mapEffects(h.effects,b)),annotations:x.annotations.length?x.annotations.concat(h.annotations):h.annotations,scrollIntoView:x.scrollIntoView||h.scrollIntoView}}function os(x,h,u){let d=h.selection,m=Mt(h.annotations);return h.userEvent&&(m=m.concat(ve.userEvent.of(h.userEvent))),{changes:h.changes instanceof R?h.changes:R.of(h.changes||[],u,x.facet(lo)),selection:d&&(d instanceof q?d:q.single(d.anchor,d.head)),effects:Mt(h.effects),annotations:m,scrollIntoView:!!h.scrollIntoView}}function go(x,h,u){let d=os(x,h.length?h[0]:{},x.doc.length);h.length&&h[0].filter===!1&&(u=!1);for(let b=1;b<h.length;b++){h[b].filter===!1&&(u=!1);let S=!!h[b].sequential;d=mo(d,os(x,h[b],S?d.changes.newLength:x.doc.length),S)}let m=ve.create(x,d.changes,d.selection,d.effects,d.annotations,d.scrollIntoView);return pf(u?df(m):m)}function df(x){let h=x.startState,u=!0;for(let m of h.facet(ao)){let b=m(x);if(b===!1){u=!1;break}Array.isArray(b)&&(u=u===!0?b:uf(u,b))}if(u!==!0){let m,b;if(u===!1)b=x.changes.invertedDesc,m=R.empty(h.doc.length);else{let S=x.changes.filter(u);m=S.changes,b=S.filtered.mapDesc(S.changes).invertedDesc}x=ve.create(h,m,x.selection&&x.selection.map(b),Se.mapEffects(x.effects,b),x.annotations,x.scrollIntoView)}let d=h.facet(ho);for(let m=d.length-1;m>=0;m--){let b=d[m](x);b instanceof ve?x=b:Array.isArray(b)&&b.length==1&&b[0]instanceof ve?x=b[0]:x=go(h,Mt(b),!1)}return x}function pf(x){let h=x.startState,u=h.facet(co),d=x;for(let m=u.length-1;m>=0;m--){let b=u[m](x);b&&Object.keys(b).length&&(d=mo(d,os(h,b,x.changes.newLength),!0))}return d==x?x:ve.create(h,x.changes,x.selection,d.effects,d.annotations,d.scrollIntoView)}const mf=[];function Mt(x){return x==null?mf:Array.isArray(x)?x:[x]}i.CharCategory=void 0,function(x){x[x.Word=0]="Word",x[x.Space=1]="Space",x[x.Other=2]="Other"}(i.CharCategory||(i.CharCategory={}));const gf=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let ls;try{ls=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function yf(x){if(ls)return ls.test(x);for(let h=0;h<x.length;h++){let u=x[h];if(/\w/.test(u)||u>""&&(u.toUpperCase()!=u.toLowerCase()||gf.test(u)))return!0}return!1}function bf(x){return h=>{if(!/\S/.test(h))return i.CharCategory.Space;if(yf(h))return i.CharCategory.Word;for(let u=0;u<x.length;u++)if(h.indexOf(x[u])>-1)return i.CharCategory.Word;return i.CharCategory.Other}}class oe{constructor(h,u,d,m,b,S){this.config=h,this.doc=u,this.selection=d,this.values=m,this.status=h.statusTemplate.slice(),this.computeSlot=b,S&&(S._state=this);for(let w=0;w<this.config.dynamicSlots.length;w++)si(this,w<<1);this.computeSlot=null}field(h,u=!0){let d=this.config.address[h.id];if(d==null){if(u)throw new RangeError("Field is not present in this state");return}return si(this,d),_i(this,d)}update(...h){return go(this,h,!0)}applyTransaction(h){let u=this.config,{base:d,compartments:m}=u;for(let w of h.effects)w.is(ni.reconfigure)?(u&&(m=new Map,u.compartments.forEach((A,O)=>m.set(O,A)),u=null),m.set(w.value.compartment,w.value.extension)):w.is(Se.reconfigure)?(u=null,d=w.value):w.is(Se.appendConfig)&&(u=null,d=Mt(d).concat(w.value));let b;u?b=h.startState.values.slice():(u=ji.resolve(d,m,this),b=new oe(u,this.doc,this.selection,u.dynamicSlots.map(()=>null),(A,O)=>O.reconfigure(A,this),null).values);let S=h.startState.facet(rs)?h.newSelection:h.newSelection.asSingle();new oe(u,h.newDoc,S,b,(w,A)=>A.update(w,h),h)}replaceSelection(h){return typeof h=="string"&&(h=this.toText(h)),this.changeByRange(u=>({changes:{from:u.from,to:u.to,insert:h},range:q.cursor(u.from+h.length)}))}changeByRange(h){let u=this.selection,d=h(u.ranges[0]),m=this.changes(d.changes),b=[d.range],S=Mt(d.effects);for(let w=1;w<u.ranges.length;w++){let A=h(u.ranges[w]),O=this.changes(A.changes),D=O.map(m);for(let W=0;W<w;W++)b[W]=b[W].map(D);let B=m.mapDesc(O,!0);b.push(A.range.map(B)),m=m.compose(D),S=Se.mapEffects(S,D).concat(Se.mapEffects(Mt(A.effects),B))}return{changes:m,selection:q.create(b,u.mainIndex),effects:S}}changes(h=[]){return h instanceof R?h:R.of(h,this.doc.length,this.facet(oe.lineSeparator))}toText(h){return t.of(h.split(this.facet(oe.lineSeparator)||F))}sliceDoc(h=0,u=this.doc.length){return this.doc.sliceString(h,u,this.lineBreak)}facet(h){let u=this.config.address[h.id];return u==null?h.default:(si(this,u),_i(this,u))}toJSON(h){let u={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(h)for(let d in h){let m=h[d];m instanceof gt&&this.config.address[m.id]!=null&&(u[d]=m.spec.toJSON(this.field(h[d]),this))}return u}static fromJSON(h,u={},d){if(!h||typeof h.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let m=[];if(d){for(let b in d)if(Object.prototype.hasOwnProperty.call(h,b)){let S=d[b],w=h[b];m.push(S.init(A=>S.spec.fromJSON(w,A)))}}return oe.create({doc:h.doc,selection:q.fromJSON(h.selection),extensions:u.extensions?m.concat([u.extensions]):m})}static create(h={}){let u=ji.resolve(h.extensions||[],new Map),d=h.doc instanceof t?h.doc:t.of((h.doc||"").split(u.staticFacet(oe.lineSeparator)||F)),m=h.selection?h.selection instanceof q?h.selection:q.single(h.selection.anchor,h.selection.head):q.single(0);return ue(m,d.length),u.staticFacet(rs)||(m=m.asSingle()),new oe(u,d,m,u.dynamicSlots.map(()=>null),(b,S)=>S.create(b),null)}get tabSize(){return this.facet(oe.tabSize)}get lineBreak(){return this.facet(oe.lineSeparator)||`
|
|
6
|
-
`}get readOnly(){return this.facet(fo)}phrase(h,...u){for(let d of this.facet(oe.phrases))if(Object.prototype.hasOwnProperty.call(d,h)){h=d[h];break}return u.length&&(h=h.replace(/\$(\$|\d*)/g,(d,m)=>{if(m=="$")return"$";let b=+(m||1);return!b||b>u.length?d:u[b-1]})),h}languageDataAt(h,u,d=-1){let m=[];for(let b of this.facet(oo))for(let S of b(this,u,d))Object.prototype.hasOwnProperty.call(S,h)&&m.push(S[h]);return m}charCategorizer(h){return bf(this.languageDataAt("wordChars",h).join(""))}wordAt(h){let{text:u,from:d,length:m}=this.doc.lineAt(h),b=this.charCategorizer(h),S=h-d,w=h-d;for(;S>0;){let A=v(u,S,!1);if(b(u.slice(A,S))!=i.CharCategory.Word)break;S=A}for(;w<m;){let A=v(u,w);if(b(u.slice(w,A))!=i.CharCategory.Word)break;w=A}return S==w?null:q.range(S+d,w+d)}}oe.allowMultipleSelections=rs,oe.tabSize=G.define({combine:x=>x.length?x[0]:4}),oe.lineSeparator=lo,oe.readOnly=fo,oe.phrases=G.define({compare(x,h){let u=Object.keys(x),d=Object.keys(h);return u.length==d.length&&u.every(m=>x[m]==h[m])}}),oe.languageData=oo,oe.changeFilter=ao,oe.transactionFilter=ho,oe.transactionExtender=co,ni.reconfigure=Se.define();function Sf(x,h,u={}){let d={};for(let m of x)for(let b of Object.keys(m)){let S=m[b],w=d[b];if(w===void 0)d[b]=S;else if(!(w===S||S===void 0))if(Object.hasOwnProperty.call(u,b))d[b]=u[b](w,S);else throw new Error("Config merge conflict for field "+b)}for(let m in h)d[m]===void 0&&(d[m]=h[m]);return d}class ri{eq(h){return this==h}range(h,u=h){return Et.create(h,u,this)}}ri.prototype.startSide=ri.prototype.endSide=0,ri.prototype.point=!1,ri.prototype.mapMode=i.MapMode.TrackDel;class Et{constructor(h,u,d){this.from=h,this.to=u,this.value=d}static create(h,u,d){return new Et(h,u,d)}}function as(x,h){return x.from-h.from||x.value.startSide-h.value.startSide}class hs{constructor(h,u,d,m){this.from=h,this.to=u,this.value=d,this.maxPoint=m}get length(){return this.to[this.to.length-1]}findIndex(h,u,d,m=0){let b=d?this.to:this.from;for(let S=m,w=b.length;;){if(S==w)return S;let A=S+w>>1,O=b[A]-h||(d?this.value[A].endSide:this.value[A].startSide)-u;if(A==S)return O>=0?S:w;O>=0?w=A:S=A+1}}between(h,u,d,m){for(let b=this.findIndex(u,-1e9,!0),S=this.findIndex(d,1e9,!1,b);b<S;b++)if(m(this.from[b]+h,this.to[b]+h,this.value[b])===!1)return!1}map(h,u){let d=[],m=[],b=[],S=-1,w=-1;for(let A=0;A<this.value.length;A++){let O=this.value[A],D=this.from[A]+h,B=this.to[A]+h,W,$;if(D==B){let Z=u.mapPos(D,O.startSide,O.mapMode);if(Z==null||(W=$=Z,O.startSide!=O.endSide&&($=u.mapPos(D,O.endSide),$<W)))continue}else if(W=u.mapPos(D,O.startSide),$=u.mapPos(B,O.endSide),W>$||W==$&&O.startSide>0&&O.endSide<=0)continue;($-W||O.endSide-O.startSide)<0||(S<0&&(S=W),O.point&&(w=Math.max(w,$-W)),d.push(O),m.push(W-S),b.push($-S))}return{mapped:d.length?new hs(m,b,d,w):null,pos:S}}}class xe{constructor(h,u,d,m){this.chunkPos=h,this.chunk=u,this.nextLayer=d,this.maxPoint=m}static create(h,u,d,m){return new xe(h,u,d,m)}get length(){let h=this.chunk.length-1;return h<0?0:Math.max(this.chunkEnd(h),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let h=this.nextLayer.size;for(let u of this.chunk)h+=u.value.length;return h}chunkEnd(h){return this.chunkPos[h]+this.chunk[h].length}update(h){let{add:u=[],sort:d=!1,filterFrom:m=0,filterTo:b=this.length}=h,S=h.filter;if(u.length==0&&!S)return this;if(d&&(u=u.slice().sort(as)),this.isEmpty)return u.length?xe.of(u):this;let w=new bo(this,null,-1).goto(0),A=0,O=[],D=new oi;for(;w.value||A<u.length;)if(A<u.length&&(w.from-u[A].from||w.startSide-u[A].value.startSide)>=0){let B=u[A++];D.addInner(B.from,B.to,B.value)||O.push(B)}else w.rangeIndex==1&&w.chunkIndex<this.chunk.length&&(A==u.length||this.chunkEnd(w.chunkIndex)<u[A].from)&&(!S||m>this.chunkEnd(w.chunkIndex)||b<this.chunkPos[w.chunkIndex])&&D.addChunk(this.chunkPos[w.chunkIndex],this.chunk[w.chunkIndex])?w.nextChunk():((!S||m>w.to||b<w.from||S(w.from,w.to,w.value))&&(D.addInner(w.from,w.to,w.value)||O.push(Et.create(w.from,w.to,w.value))),w.next());return D.finishInner(this.nextLayer.isEmpty&&!O.length?xe.empty:this.nextLayer.update({add:O,filter:S,filterFrom:m,filterTo:b}))}map(h){if(h.empty||this.isEmpty)return this;let u=[],d=[],m=-1;for(let S=0;S<this.chunk.length;S++){let w=this.chunkPos[S],A=this.chunk[S],O=h.touchesRange(w,w+A.length);if(O===!1)m=Math.max(m,A.maxPoint),u.push(A),d.push(h.mapPos(w));else if(O===!0){let{mapped:D,pos:B}=A.map(w,h);D&&(m=Math.max(m,D.maxPoint),u.push(D),d.push(B))}}let b=this.nextLayer.map(h);return u.length==0?b:new xe(d,u,b||xe.empty,m)}between(h,u,d){if(!this.isEmpty){for(let m=0;m<this.chunk.length;m++){let b=this.chunkPos[m],S=this.chunk[m];if(u>=b&&h<=b+S.length&&S.between(b,h-b,u-b,d)===!1)return}this.nextLayer.between(h,u,d)}}iter(h=0){return li.from([this]).goto(h)}get isEmpty(){return this.nextLayer==this}static iter(h,u=0){return li.from(h).goto(u)}static compare(h,u,d,m,b=-1){let S=h.filter(B=>B.maxPoint>0||!B.isEmpty&&B.maxPoint>=b),w=u.filter(B=>B.maxPoint>0||!B.isEmpty&&B.maxPoint>=b),A=yo(S,w,d),O=new ai(S,A,b),D=new ai(w,A,b);d.iterGaps((B,W,$)=>So(O,B,D,W,$,m)),d.empty&&d.length==0&&So(O,0,D,0,0,m)}static eq(h,u,d=0,m){m==null&&(m=999999999);let b=h.filter(D=>!D.isEmpty&&u.indexOf(D)<0),S=u.filter(D=>!D.isEmpty&&h.indexOf(D)<0);if(b.length!=S.length)return!1;if(!b.length)return!0;let w=yo(b,S),A=new ai(b,w,0).goto(d),O=new ai(S,w,0).goto(d);for(;;){if(A.to!=O.to||!fs(A.active,O.active)||A.point&&(!O.point||!A.point.eq(O.point)))return!1;if(A.to>m)return!0;A.next(),O.next()}}static spans(h,u,d,m,b=-1){let S=new ai(h,null,b).goto(u),w=u,A=S.openStart;for(;;){let O=Math.min(S.to,d);if(S.point){let D=S.activeForPoint(S.to),B=S.pointFrom<u?D.length+1:S.point.startSide<0?D.length:Math.min(D.length,A);m.point(w,O,S.point,D,B,S.pointRank),A=Math.min(S.openEnd(O),D.length)}else O>w&&(m.span(w,O,S.active,A),A=S.openEnd(O));if(S.to>d)return A+(S.point&&S.to>d?1:0);w=S.to,S.next()}}static of(h,u=!1){let d=new oi;for(let m of h instanceof Et?[h]:u?vf(h):h)d.add(m.from,m.to,m.value);return d.finish()}static join(h){if(!h.length)return xe.empty;let u=h[h.length-1];for(let d=h.length-2;d>=0;d--)for(let m=h[d];m!=xe.empty;m=m.nextLayer)u=new xe(m.chunkPos,m.chunk,u,Math.max(m.maxPoint,u.maxPoint));return u}}xe.empty=new xe([],[],null,-1);function vf(x){if(x.length>1)for(let h=x[0],u=1;u<x.length;u++){let d=x[u];if(as(h,d)>0)return x.slice().sort(as);h=d}return x}xe.empty.nextLayer=xe.empty;class oi{finishChunk(h){this.chunks.push(new hs(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,h&&(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(h,u,d){this.addInner(h,u,d)||(this.nextLayer||(this.nextLayer=new oi)).add(h,u,d)}addInner(h,u,d){let m=h-this.lastTo||d.startSide-this.last.endSide;if(m<=0&&(h-this.lastFrom||d.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return m<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=h),this.from.push(h-this.chunkStart),this.to.push(u-this.chunkStart),this.last=d,this.lastFrom=h,this.lastTo=u,this.value.push(d),d.point&&(this.maxPoint=Math.max(this.maxPoint,u-h)),!0)}addChunk(h,u){if((h-this.lastTo||u.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,u.maxPoint),this.chunks.push(u),this.chunkPos.push(h);let d=u.value.length-1;return this.last=u.value[d],this.lastFrom=u.from[d]+h,this.lastTo=u.to[d]+h,!0}finish(){return this.finishInner(xe.empty)}finishInner(h){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return h;let u=xe.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(h):h,this.setMaxPoint);return this.from=null,u}}function yo(x,h,u){let d=new Map;for(let b of x)for(let S=0;S<b.chunk.length;S++)b.chunk[S].maxPoint<=0&&d.set(b.chunk[S],b.chunkPos[S]);let m=new Set;for(let b of h)for(let S=0;S<b.chunk.length;S++){let w=d.get(b.chunk[S]);w!=null&&(u?u.mapPos(w):w)==b.chunkPos[S]&&!(u!=null&&u.touchesRange(w,w+b.chunk[S].length))&&m.add(b.chunk[S])}return m}class bo{constructor(h,u,d,m=0){this.layer=h,this.skip=u,this.minPoint=d,this.rank=m}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(h,u=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(h,u,!1),this}gotoInner(h,u,d){for(;this.chunkIndex<this.layer.chunk.length;){let m=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(m)||this.layer.chunkEnd(this.chunkIndex)<h||m.maxPoint<this.minPoint))break;this.chunkIndex++,d=!1}if(this.chunkIndex<this.layer.chunk.length){let m=this.layer.chunk[this.chunkIndex].findIndex(h-this.layer.chunkPos[this.chunkIndex],u,!0);(!d||this.rangeIndex<m)&&this.setRangeIndex(m)}this.next()}forward(h,u){(this.to-h||this.endSide-u)<0&&this.gotoInner(h,u,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let h=this.layer.chunkPos[this.chunkIndex],u=this.layer.chunk[this.chunkIndex],d=h+u.from[this.rangeIndex];if(this.from=d,this.to=h+u.to[this.rangeIndex],this.value=u.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(h){if(h==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=h}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(h){return this.from-h.from||this.startSide-h.startSide||this.rank-h.rank||this.to-h.to||this.endSide-h.endSide}}class li{constructor(h){this.heap=h}static from(h,u=null,d=-1){let m=[];for(let b=0;b<h.length;b++)for(let S=h[b];!S.isEmpty;S=S.nextLayer)S.maxPoint>=d&&m.push(new bo(S,u,d,b));return m.length==1?m[0]:new li(m)}get startSide(){return this.value?this.value.startSide:0}goto(h,u=-1e9){for(let d of this.heap)d.goto(h,u);for(let d=this.heap.length>>1;d>=0;d--)cs(this.heap,d);return this.next(),this}forward(h,u){for(let d of this.heap)d.forward(h,u);for(let d=this.heap.length>>1;d>=0;d--)cs(this.heap,d);(this.to-h||this.value.endSide-u)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let h=this.heap[0];this.from=h.from,this.to=h.to,this.value=h.value,this.rank=h.rank,h.value&&h.next(),cs(this.heap,0)}}}function cs(x,h){for(let u=x[h];;){let d=(h<<1)+1;if(d>=x.length)break;let m=x[d];if(d+1<x.length&&m.compare(x[d+1])>=0&&(m=x[d+1],d++),u.compare(m)<0)break;x[d]=u,x[h]=m,h=d}}class ai{constructor(h,u,d){this.minPoint=d,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=li.from(h,u,d)}goto(h,u=-1e9){return this.cursor.goto(h,u),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=h,this.endSide=u,this.openStart=-1,this.next(),this}forward(h,u){for(;this.minActive>-1&&(this.activeTo[this.minActive]-h||this.active[this.minActive].endSide-u)<0;)this.removeActive(this.minActive);this.cursor.forward(h,u)}removeActive(h){Ki(this.active,h),Ki(this.activeTo,h),Ki(this.activeRank,h),this.minActive=vo(this.active,this.activeTo)}addActive(h){let u=0,{value:d,to:m,rank:b}=this.cursor;for(;u<this.activeRank.length&&(b-this.activeRank[u]||m-this.activeTo[u])>0;)u++;Ji(this.active,u,d),Ji(this.activeTo,u,m),Ji(this.activeRank,u,b),h&&Ji(h,u,this.cursor.from),this.minActive=vo(this.active,this.activeTo)}next(){let h=this.to,u=this.point;this.point=null;let d=this.openStart<0?[]:null;for(;;){let m=this.minActive;if(m>-1&&(this.activeTo[m]-this.cursor.from||this.active[m].endSide-this.cursor.startSide)<0){if(this.activeTo[m]>h){this.to=this.activeTo[m],this.endSide=this.active[m].endSide;break}this.removeActive(m),d&&Ki(d,m)}else if(this.cursor.value)if(this.cursor.from>h){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let b=this.cursor.value;if(!b.point)this.addActive(d),this.cursor.next();else if(u&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=b,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=b.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(d){this.openStart=0;for(let m=d.length-1;m>=0&&d[m]<h;m--)this.openStart++}}activeForPoint(h){if(!this.active.length)return this.active;let u=[];for(let d=this.active.length-1;d>=0&&!(this.activeRank[d]<this.pointRank);d--)(this.activeTo[d]>h||this.activeTo[d]==h&&this.active[d].endSide>=this.point.endSide)&&u.push(this.active[d]);return u.reverse()}openEnd(h){let u=0;for(let d=this.activeTo.length-1;d>=0&&this.activeTo[d]>h;d--)u++;return u}}function So(x,h,u,d,m,b){x.goto(h),u.goto(d);let S=d+m,w=d,A=d-h;for(;;){let O=x.to+A-u.to,D=O||x.endSide-u.endSide,B=D<0?x.to+A:u.to,W=Math.min(B,S);if(x.point||u.point?x.point&&u.point&&(x.point==u.point||x.point.eq(u.point))&&fs(x.activeForPoint(x.to),u.activeForPoint(u.to))||b.comparePoint(w,W,x.point,u.point):W>w&&!fs(x.active,u.active)&&b.compareRange(w,W,x.active,u.active),B>S)break;(O||x.openEnd!=u.openEnd)&&b.boundChange&&b.boundChange(B),w=B,D<=0&&x.next(),D>=0&&u.next()}}function fs(x,h){if(x.length!=h.length)return!1;for(let u=0;u<x.length;u++)if(x[u]!=h[u]&&!x[u].eq(h[u]))return!1;return!0}function Ki(x,h){for(let u=h,d=x.length-1;u<d;u++)x[u]=x[u+1];x.pop()}function Ji(x,h,u){for(let d=x.length-1;d>=h;d--)x[d+1]=x[d];x[h]=u}function vo(x,h){let u=-1,d=1e9;for(let m=0;m<h.length;m++)(h[m]-d||x[m].endSide-x[u].endSide)<0&&(u=m,d=h[m]);return u}function xf(x,h,u=x.length){let d=0;for(let m=0;m<u&&m<x.length;)x.charCodeAt(m)==9?(d+=h-d%h,m++):(d++,m=v(x,m));return d}function wf(x,h,u,d){for(let m=0,b=0;;){if(b>=h)return m;if(m==x.length)break;b+=x.charCodeAt(m)==9?u-b%u:1,m=v(x,m)}return d===!0?-1:x.length}i.Annotation=At,i.AnnotationType=uo,i.ChangeDesc=L,i.ChangeSet=R,i.Compartment=ni,i.EditorSelection=q,i.EditorState=oe,i.Facet=G,i.Line=p,i.Prec=cf,i.Range=Et,i.RangeSet=xe,i.RangeSetBuilder=oi,i.RangeValue=ri,i.SelectionRange=he,i.StateEffect=Se,i.StateEffectType=po,i.StateField=gt,i.Text=t,i.Transaction=ve,i.codePointAt=M,i.codePointSize=P,i.combineConfig=Sf,i.countColumn=xf,i.findClusterBreak=v,i.findColumn=wf,i.fromCodePoint=T}(ps)),ps}var y=zf();function xi(i){let e;return i.nodeType==11?e=i.getSelection?i:i.ownerDocument:e=i,e.getSelection()}function Ws(i,e){return e?i==e||i.contains(e.nodeType!=1?e.parentNode:e):!1}function pn(i,e){if(!e.anchorNode)return!1;try{return Ws(i,e.anchorNode)}catch{return!1}}function zt(i){return i.nodeType==3?wt(i,0,i.nodeValue.length).getClientRects():i.nodeType==1?i.getClientRects():[]}function yi(i,e,t,n){return t?wo(i,e,t,n,-1)||wo(i,e,t,n,1):!1}function xt(i){for(var e=0;;e++)if(i=i.previousSibling,!i)return e}function An(i){return i.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(i.nodeName)}function wo(i,e,t,n,s){for(;;){if(i==t&&e==n)return!0;if(e==(s<0?0:Ze(i))){if(i.nodeName=="DIV")return!1;let r=i.parentNode;if(!r||r.nodeType!=1)return!1;e=xt(i)+(s<0?0:1),i=r}else if(i.nodeType==1){if(i=i.childNodes[e+(s<0?-1:0)],i.nodeType==1&&i.contentEditable=="false")return!1;e=s<0?Ze(i):0}else return!1}}function Ze(i){return i.nodeType==3?i.nodeValue.length:i.childNodes.length}function Li(i,e){let t=e?i.left:i.right;return{left:t,right:t,top:i.top,bottom:i.bottom}}function qf(i){let e=i.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:i.innerWidth,top:0,bottom:i.innerHeight}}function pa(i,e){let t=e.width/i.offsetWidth,n=e.height/i.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-i.offsetWidth)<1)&&(t=1),(n>.995&&n<1.005||!isFinite(n)||Math.abs(e.height-i.offsetHeight)<1)&&(n=1),{scaleX:t,scaleY:n}}function jf(i,e,t,n,s,r,o,l){let a=i.ownerDocument,f=a.defaultView||window;for(let c=i,p=!1;c&&!p;)if(c.nodeType==1){let g,v=c==a.body,k=1,C=1;if(v)g=qf(f);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(p=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let P=c.getBoundingClientRect();({scaleX:k,scaleY:C}=pa(c,P)),g={left:P.left,right:P.left+c.clientWidth*k,top:P.top,bottom:P.top+c.clientHeight*C}}let M=0,T=0;if(s=="nearest")e.top<g.top?(T=e.top-(g.top+o),t>0&&e.bottom>g.bottom+T&&(T=e.bottom-g.bottom+o)):e.bottom>g.bottom&&(T=e.bottom-g.bottom+o,t<0&&e.top-T<g.top&&(T=e.top-(g.top+o)));else{let P=e.bottom-e.top,F=g.bottom-g.top;T=(s=="center"&&P<=F?e.top+P/2-F/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-F+o)-g.top}if(n=="nearest"?e.left<g.left?(M=e.left-(g.left+r),t>0&&e.right>g.right+M&&(M=e.right-g.right+r)):e.right>g.right&&(M=e.right-g.right+r,t<0&&e.left<g.left+M&&(M=e.left-(g.left+r))):M=(n=="center"?e.left+(e.right-e.left)/2-(g.right-g.left)/2:n=="start"==l?e.left-r:e.right-(g.right-g.left)+r)-g.left,M||T)if(v)f.scrollBy(M,T);else{let P=0,F=0;if(T){let L=c.scrollTop;c.scrollTop+=T/C,F=(c.scrollTop-L)*C}if(M){let L=c.scrollLeft;c.scrollLeft+=M/k,P=(c.scrollLeft-L)*k}e={left:e.left-P,top:e.top-F,right:e.right-P,bottom:e.bottom-F},P&&Math.abs(P-M)<1&&(n="nearest"),F&&Math.abs(F-T)<1&&(s="nearest")}if(v)break;(e.top<g.top||e.bottom>g.bottom||e.left<g.left||e.right>g.right)&&(e={left:Math.max(e.left,g.left),right:Math.min(e.right,g.right),top:Math.max(e.top,g.top),bottom:Math.min(e.bottom,g.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function _f(i){let e=i.ownerDocument,t,n;for(let s=i.parentNode;s&&!(s==e.body||t&&n);)if(s.nodeType==1)!n&&s.scrollHeight>s.clientHeight&&(n=s),!t&&s.scrollWidth>s.clientWidth&&(t=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:t,y:n}}class Kf{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:n}=e;this.set(t,Math.min(e.anchorOffset,t?Ze(t):0),n,Math.min(e.focusOffset,n?Ze(n):0))}set(e,t,n,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=s}}let Tt=null;function ma(i){if(i.setActive)return i.setActive();if(Tt)return i.focus(Tt);let e=[];for(let t=i;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(i.focus(Tt==null?{get preventScroll(){return Tt={preventScroll:!0},!0}}:void 0),!Tt){Tt=!1;for(let t=0;t<e.length;){let n=e[t++],s=e[t++],r=e[t++];n.scrollTop!=s&&(n.scrollTop=s),n.scrollLeft!=r&&(n.scrollLeft=r)}}}let ko;function wt(i,e,t=e){let n=ko||(ko=document.createRange());return n.setEnd(i,t),n.setStart(i,e),n}function Ft(i,e,t,n){let s={key:e,code:e,keyCode:t,which:t,cancelable:!0};n&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=n);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,i.dispatchEvent(r);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,i.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function Jf(i){for(;i;){if(i&&(i.nodeType==9||i.nodeType==11&&i.host))return i;i=i.assignedSlot||i.parentNode}return null}function ga(i){for(;i.attributes.length;)i.removeAttributeNode(i.attributes[0])}function Uf(i,e){let t=e.focusNode,n=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=n)return!1;for(n=Math.min(n,Ze(t));;)if(n){if(t.nodeType!=1)return!1;let s=t.childNodes[n-1];s.contentEditable=="false"?n--:(t=s,n=Ze(t))}else{if(t==i)return!0;n=xt(t),t=t.parentNode}}function ya(i){return i.scrollTop>Math.max(1,i.scrollHeight-i.clientHeight-4)}function ba(i,e){for(let t=i,n=e;;){if(t.nodeType==3&&n>0)return{node:t,offset:n};if(t.nodeType==1&&n>0){if(t.contentEditable=="false")return null;t=t.childNodes[n-1],n=Ze(t)}else if(t.parentNode&&!An(t))n=xt(t),t=t.parentNode;else return null}}function Sa(i,e){for(let t=i,n=e;;){if(t.nodeType==3&&n<t.nodeValue.length)return{node:t,offset:n};if(t.nodeType==1&&n<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[n],n=0}else if(t.parentNode&&!An(t))n=xt(t)+1,t=t.parentNode;else return null}}class we{constructor(e,t,n=!0){this.node=e,this.offset=t,this.precise=n}static before(e,t){return new we(e.parentNode,xt(e),t)}static after(e,t){return new we(e.parentNode,xt(e)+1,t)}}const kr=[];class J{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e){let t=this.posAtStart;for(let n of this.children){if(n==e)return t;t+=n.length+n.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}sync(e,t){if(this.flags&2){let n=this.dom,s=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=s?s.nextSibling:n.firstChild)){let l=J.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(e,t),o.flags&=-8}if(r=s?s.nextSibling:n.firstChild,t&&!t.written&&t.node==n&&r!=o.dom&&(t.written=!0),o.dom.parentNode==n)for(;r&&r!=o.dom;)r=Co(r);else n.insertBefore(o.dom,r);s=o.dom}for(r=s?s.nextSibling:n.firstChild,r&&t&&t.node==n&&(t.written=!0);r;)r=Co(r)}else if(this.flags&1)for(let n of this.children)n.flags&7&&(n.sync(e,t),n.flags&=-8)}reuseDOM(e){}localPosFromDOM(e,t){let n;if(e==this.dom)n=this.dom.childNodes[t];else{let s=Ze(e)==0?0:t==0?-1:1;for(;;){let r=e.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(e==r.firstChild?s=-1:s=1),e=r}s<0?n=e:n=e.nextSibling}if(n==this.dom.firstChild)return 0;for(;n&&!J.get(n);)n=n.nextSibling;if(!n)return this.length;for(let s=0,r=0;;s++){let o=this.children[s];if(o.dom==n)return r;r+=o.length+o.breakAfter}}domBoundsAround(e,t,n=0){let s=-1,r=-1,o=-1,l=-1;for(let a=0,f=n,c=n;a<this.children.length;a++){let p=this.children[a],g=f+p.length;if(f<e&&g>t)return p.domBoundsAround(e,t,f);if(g>=e&&s==-1&&(s=a,r=f),f>t&&p.dom.parentNode==this.dom){o=a,l=c;break}c=g,f=g+p.breakAfter}return{from:r,to:l<0?n+this.length:l,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(e=!1){this.flags|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.flags|=2),t.flags&1)return;t.flags|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.flags&7&&this.markParentsDirty(!0))}setDOM(e){this.dom!=e&&(this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this)}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,n=kr){this.markDirty();for(let s=e;s<t;s++){let r=this.children[s];r.parent==this&&n.indexOf(r)<0&&r.destroy()}n.length<250?this.children.splice(e,t-e,...n):this.children=[].concat(this.children.slice(0,e),n,this.children.slice(t));for(let s=0;s<n.length;s++)n[s].setParent(this)}ignoreMutation(e){return!1}ignoreEvent(e){return!1}childCursor(e=this.length){return new va(this.children,e,this.children.length)}childPos(e,t=1){return this.childCursor().findPos(e,t)}toString(){let e=this.constructor.name.replace("View","");return e+(this.children.length?"("+this.children.join()+")":this.length?"["+(e=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(e){return e.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(e,t,n,s,r,o){return!1}become(e){return!1}canReuseDOM(e){return e.constructor==this.constructor&&!((this.flags|e.flags)&8)}getSide(){return 0}destroy(){for(let e of this.children)e.parent==this&&e.destroy();this.parent=null}}J.prototype.breakAfter=0;function Co(i){let e=i.nextSibling;return i.parentNode.removeChild(i),e}class va{constructor(e,t,n){this.children=e,this.pos=t,this.i=n,this.off=0}findPos(e,t=1){for(;;){if(e>this.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let n=this.children[--this.i];this.pos-=n.length+n.breakAfter}}}function xa(i,e,t,n,s,r,o,l,a){let{children:f}=i,c=f.length?f[e]:null,p=r.length?r[r.length-1]:null,g=p?p.breakAfter:o;if(!(e==n&&c&&!o&&!g&&r.length<2&&c.merge(t,s,r.length?p:null,t==0,l,a))){if(n<f.length){let v=f[n];v&&(s<v.length||v.breakAfter&&(p!=null&&p.breakAfter))?(e==n&&(v=v.split(s),s=0),!g&&p&&v.merge(0,s,p,!0,0,a)?r[r.length-1]=v:((s||v.children.length&&!v.children[0].length)&&v.merge(0,s,null,!1,0,a),r.push(v))):v!=null&&v.breakAfter&&(p?p.breakAfter=1:o=1),n++}for(c&&(c.breakAfter=o,t>0&&(!o&&r.length&&c.merge(t,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(t<c.length||c.children.length&&c.children[c.children.length-1].length==0)&&c.merge(t,c.length,null,!1,l,0),e++));e<n&&r.length;)if(f[n-1].become(r[r.length-1]))n--,r.pop(),a=r.length?0:l;else if(f[e].become(r[0]))e++,r.shift(),l=r.length?0:a;else break;!r.length&&e&&n<f.length&&!f[e-1].breakAfter&&f[n].merge(0,0,f[e-1],!1,l,a)&&e--,(e<n||r.length)&&i.replaceChildren(e,n,r)}}function wa(i,e,t,n,s,r){let o=i.childCursor(),{i:l,off:a}=o.findPos(t,1),{i:f,off:c}=o.findPos(e,-1),p=e-t;for(let g of n)p+=g.length;i.length+=p,xa(i,f,c,l,a,n,0,s,r)}let Oe=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},$s=typeof document<"u"?document:{documentElement:{style:{}}};const zs=/Edge\/(\d+)/.exec(Oe.userAgent),ka=/MSIE \d/.test(Oe.userAgent),qs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Oe.userAgent),_n=!!(ka||qs||zs),Ao=!_n&&/gecko\/(\d+)/i.test(Oe.userAgent),ms=!_n&&/Chrome\/(\d+)/.exec(Oe.userAgent),Yf="webkitFontSmoothing"in $s.documentElement.style,Ca=!_n&&/Apple Computer/.test(Oe.vendor),Mo=Ca&&(/Mobile\/\w+/.test(Oe.userAgent)||Oe.maxTouchPoints>2);var V={mac:Mo||/Mac/.test(Oe.platform),windows:/Win/.test(Oe.platform),linux:/Linux|X11/.test(Oe.platform),ie:_n,ie_version:ka?$s.documentMode||6:qs?+qs[1]:zs?+zs[1]:0,gecko:Ao,gecko_version:Ao?+(/Firefox\/(\d+)/.exec(Oe.userAgent)||[0,0])[1]:0,chrome:!!ms,chrome_version:ms?+ms[1]:0,ios:Mo,android:/Android\b/.test(Oe.userAgent),safari:Ca,webkit_version:Yf?+(/\bAppleWebKit\/(\d+)/.exec(Oe.userAgent)||[0,0])[1]:0,tabSize:$s.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const Gf=256;class ze extends J{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e,t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,n){return this.flags&8||n&&(!(n instanceof ze)||this.length-(t-e)+n.length>Gf||n.flags&8)?!1:(this.text=this.text.slice(0,e)+(n?n.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new ze(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t.flags|=this.flags&8,t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new we(this.dom,e)}domBoundsAround(e,t,n){return{from:n,to:n+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return Xf(this.dom,e,t)}}class st extends J{constructor(e,t=[],n=0){super(),this.mark=e,this.children=t,this.length=n;for(let s of t)s.setParent(this)}setAttrs(e){if(ga(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}canReuseDOM(e){return super.canReuseDOM(e)&&!((this.flags|e.flags)&8)}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(e,t,n,s,r,o){return n&&(!(n instanceof st&&n.mark.eq(this.mark))||e&&r<=0||t<this.length&&o<=0)?!1:(wa(this,e,t,n?n.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(e){let t=[],n=0,s=-1,r=0;for(let l of this.children){let a=n+l.length;a>e&&t.push(n<e?l.split(e-n):l),s<0&&n>=e&&(s=r),n=a,r++}let o=this.length-e;return this.length=e,s>-1&&(this.children.length=s,this.markDirty()),new st(this.mark,t,o)}domAtPos(e){return Aa(this,e)}coordsAt(e,t){return Ea(this,e,t)}}function Xf(i,e,t){let n=i.nodeValue.length;e>n&&(e=n);let s=e,r=e,o=0;e==0&&t<0||e==n&&t>=0?V.chrome||V.gecko||(e?(s--,o=1):r<n&&(r++,o=-1)):t<0?s--:r<n&&r++;let l=wt(i,s,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return V.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,f=>f.width)||a),o?Li(a,o<0):a||null}class at extends J{static create(e,t,n){return new at(e,t,n)}constructor(e,t,n){super(),this.widget=e,this.length=t,this.side=n,this.prevWidget=null}split(e){let t=at.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(e,t,n,s,r,o){return n&&(!(n instanceof at)||!this.widget.compare(n.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(n?n.length:0)+(this.length-t),!0)}become(e){return e instanceof at&&e.side==this.side&&this.widget.constructor==e.widget.constructor?(this.widget.compare(e.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get overrideDOMText(){if(this.length==0)return y.Text.empty;let e=this;for(;e.parent;)e=e.parent;let{view:t}=e,n=t&&t.state.doc,s=this.posAtStart;return n?n.slice(s,s+this.length):y.Text.empty}domAtPos(e){return(this.length?e==0:this.side>0)?we.before(this.dom):we.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let n=this.widget.coordsAt(this.dom,e,t);if(n)return n;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let o=this.side?this.side<0:e>0;for(let l=o?s.length-1:0;r=s[l],!(e>0?l==0:l==s.length-1||r.top<r.bottom);l+=o?-1:1);return Li(r,!o)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class qt extends J{constructor(e){super(),this.side=e}get length(){return 0}merge(){return!1}become(e){return e instanceof qt&&e.side==this.side}split(){return new qt(this.side)}sync(){if(!this.dom){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),this.setDOM(e)}}getSide(){return this.side}domAtPos(e){return this.side>0?we.before(this.dom):we.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return y.Text.empty}get isHidden(){return!0}}ze.prototype.children=at.prototype.children=qt.prototype.children=kr;function Aa(i,e){let t=i.dom,{children:n}=i,s=0;for(let r=0;s<n.length;s++){let o=n[s],l=r+o.length;if(!(l==r&&o.getSide()<=0)){if(e>r&&e<l&&o.dom.parentNode==t)return o.domAtPos(e-r);if(e<=r)break;r=l}}for(let r=s;r>0;r--){let o=n[r-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let r=s;r<n.length;r++){let o=n[r];if(o.dom.parentNode==t)return o.domAtPos(0)}return new we(t,0)}function Ma(i,e,t){let n,{children:s}=i;t>0&&e instanceof st&&s.length&&(n=s[s.length-1])instanceof st&&n.mark.eq(e.mark)?Ma(n,e.children[0],t-1):(s.push(e),e.setParent(i)),i.length+=e.length}function Ea(i,e,t){let n=null,s=-1,r=null,o=-1;function l(f,c){for(let p=0,g=0;p<f.children.length&&g<=c;p++){let v=f.children[p],k=g+v.length;k>=c&&(v.children.length?l(v,c-g):(!r||r.isHidden&&(t>0||Zf(r,v)))&&(k>c||g==k&&v.getSide()>0)?(r=v,o=c-g):(g<c||g==k&&v.getSide()<0&&!v.isHidden)&&(n=v,s=c-g)),g=k}}l(i,e);let a=(t<0?n:r)||n||r;return a?a.coordsAt(Math.max(0,a==n?s:o),t):Qf(i)}function Qf(i){let e=i.dom.lastChild;if(!e)return i.dom.getBoundingClientRect();let t=zt(e);return t[t.length-1]||null}function Zf(i,e){let t=i.coordsAt(0,1),n=e.coordsAt(0,1);return t&&n&&n.top<t.bottom}function js(i,e){for(let t in i)t=="class"&&e.class?e.class+=" "+i.class:t=="style"&&e.style?e.style+=";"+i.style:e[t]=i[t];return e}const Eo=Object.create(null);function Mn(i,e,t){if(i==e)return!0;i||(i=Eo),e||(e=Eo);let n=Object.keys(i),s=Object.keys(e);if(n.length-(t&&n.indexOf(t)>-1?1:0)!=s.length-(t&&s.indexOf(t)>-1?1:0))return!1;for(let r of n)if(r!=t&&(s.indexOf(r)==-1||i[r]!==e[r]))return!1;return!0}function _s(i,e,t){let n=!1;if(e)for(let s in e)t&&s in t||(n=!0,s=="style"?i.style.cssText="":i.removeAttribute(s));if(t)for(let s in t)e&&e[s]==t[s]||(n=!0,s=="style"?i.style.cssText=t[s]:i.setAttribute(s,t[s]));return n}function eu(i){let e=Object.create(null);for(let t=0;t<i.attributes.length;t++){let n=i.attributes[t];e[n.name]=n.value}return e}class je{eq(e){return!1}updateDOM(e,t){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,n){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var Ee=function(i){return i[i.Text=0]="Text",i[i.WidgetBefore=1]="WidgetBefore",i[i.WidgetAfter=2]="WidgetAfter",i[i.WidgetRange=3]="WidgetRange",i}(Ee||(Ee={}));class H extends y.RangeValue{constructor(e,t,n,s){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=s}get heightRelevant(){return!1}static mark(e){return new Ii(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),n=!!e.block;return t+=n&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new dt(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,s;if(e.isBlockGap)n=-5e8,s=4e8;else{let{start:r,end:o}=Ta(e,t);n=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new dt(e,n,s,t,e.widget||null,!0)}static line(e){return new Ni(e)}static set(e,t=!1){return y.RangeSet.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}H.none=y.RangeSet.empty;class Ii extends H{constructor(e){let{start:t,end:n}=Ta(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){var t,n;return this==e||e instanceof Ii&&this.tagName==e.tagName&&(this.class||((t=this.attrs)===null||t===void 0?void 0:t.class))==(e.class||((n=e.attrs)===null||n===void 0?void 0:n.class))&&Mn(this.attrs,e.attrs,"class")}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}Ii.prototype.point=!1;class Ni extends H{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Ni&&this.spec.class==e.spec.class&&Mn(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}Ni.prototype.mapMode=y.MapMode.TrackBefore;Ni.prototype.point=!0;class dt extends H{constructor(e,t,n,s,r,o){super(t,n,r,e),this.block=s,this.isReplace=o,this.mapMode=s?t<=0?y.MapMode.TrackBefore:y.MapMode.TrackAfter:y.MapMode.TrackDel}get type(){return this.startSide!=this.endSide?Ee.WidgetRange:this.startSide<=0?Ee.WidgetBefore:Ee.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof dt&&tu(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}dt.prototype.point=!0;function Ta(i,e=!1){let{inclusiveStart:t,inclusiveEnd:n}=i;return t==null&&(t=i.inclusive),n==null&&(n=i.inclusive),{start:t??e,end:n??e}}function tu(i,e){return i==e||!!(i&&e&&i.compare(e))}function mn(i,e,t,n=0){let s=t.length-1;s>=0&&t[s]+n>=i?t[s]=Math.max(t[s],e):t.push(i,e)}class ce extends J{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,n,s,r,o){if(n){if(!(n instanceof ce))return!1;this.dom||n.transferDOM(this)}return s&&this.setDeco(n?n.attrs:null),wa(this,e,t,n?n.children.slice():[],r,o),!0}split(e){let t=new ce;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i:n,off:s}=this.childPos(e);s&&(t.append(this.children[n].split(s),0),this.children[n].merge(s,this.children[n].length,null,!1,0,0),n++);for(let r=n;r<this.children.length;r++)t.append(this.children[r],0);for(;n>0&&this.children[n-1].length==0;)this.children[--n].destroy();return this.children.length=n,this.markDirty(),this.length=e,t}transferDOM(e){this.dom&&(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){Mn(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Ma(this,e,t)}addLineDeco(e){let t=e.spec.attributes,n=e.spec.class;t&&(this.attrs=js(t,this.attrs||{})),n&&(this.attrs=js({class:n},this.attrs||{}))}domAtPos(e){return Aa(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.flags|=6)}sync(e,t){var n;this.dom?this.flags&4&&(ga(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(_s(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e,t);let s=this.dom.lastChild;for(;s&&J.get(s)instanceof st;)s=s.lastChild;if(!s||!this.length||s.nodeName!="BR"&&((n=J.get(s))===null||n===void 0?void 0:n.isEditable)==!1&&(!V.ios||!this.children.some(r=>r instanceof ze))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0,t;for(let n of this.children){if(!(n instanceof ze)||/[^ -~]/.test(n.text))return null;let s=zt(n.dom);if(s.length!=1)return null;e+=s[0].width,t=s[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(e,t){let n=Ea(this,e,t);if(!this.children.length&&n&&this.parent){let{heightOracle:s}=this.parent.view.viewState,r=n.bottom-n.top;if(Math.abs(r-s.lineHeight)<2&&s.textHeight<r){let o=(r-s.textHeight)/2;return{top:n.top+o,bottom:n.bottom-o,left:n.left,right:n.left}}}return n}become(e){return e instanceof ce&&this.children.length==0&&e.children.length==0&&Mn(this.attrs,e.attrs)&&this.breakAfter==e.breakAfter}covers(){return!0}static find(e,t){for(let n=0,s=0;n<e.children.length;n++){let r=e.children[n],o=s+r.length;if(o>=t){if(r instanceof ce)return r;if(o>t)break}s=o+r.breakAfter}return null}}class nt extends J{constructor(e,t,n){super(),this.widget=e,this.length=t,this.deco=n,this.breakAfter=0,this.prevWidget=null}merge(e,t,n,s,r,o){return n&&(!(n instanceof nt)||!this.widget.compare(n.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(n?n.length:0)+(this.length-t),!0)}domAtPos(e){return e==0?we.before(this.dom):we.after(this.dom,e==this.length)}split(e){let t=this.length-e;this.length=e;let n=new nt(this.widget,t,this.deco);return n.breakAfter=this.breakAfter,n}get children(){return kr}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):y.Text.empty}domBoundsAround(){return null}become(e){return e instanceof nt&&e.widget.constructor==this.widget.constructor?(e.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,this.deco=e.deco,this.breakAfter=e.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(e,t){let n=this.widget.coordsAt(this.dom,e,t);return n||(this.widget instanceof Ks?null:Li(this.dom.getBoundingClientRect(),this.length?e==0:t<=0))}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(e){let{startSide:t,endSide:n}=this.deco;return t==n?!1:e<0?t<0:n>0}}class Ks extends je{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}class bi{constructor(e,t,n,s){this.doc=e,this.pos=t,this.end=n,this.disallowBlockEffectsFor=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!(e.breakAfter||e instanceof nt&&e.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new ce),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Ui(new qt(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(e&&this.content.length&&this.content[this.content.length-1]instanceof nt)&&this.getLine()}buildText(e,t,n){for(;e>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-n)),this.getLine().append(Ui(new ze(this.text.slice(this.textOff,this.textOff+s)),t),n),this.atCursorPos=!0,this.textOff+=s,e-=s,n=0}}span(e,t,n,s){this.buildText(t-e,n,s),this.pos=t,this.openStart<0&&(this.openStart=s)}point(e,t,n,s,r,o){if(this.disallowBlockEffectsFor[o]&&n instanceof dt){if(n.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=t-e;if(n instanceof dt)if(n.block)n.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new nt(n.widget||jt.block,l,n));else{let a=at.create(n.widget||jt.inline,l,l?0:n.startSide),f=this.atCursorPos&&!a.isEditable&&r<=s.length&&(e<t||n.startSide>0),c=!a.isEditable&&(e<t||r>s.length||n.startSide<=0),p=this.getLine();this.pendingBuffer==2&&!f&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(s),f&&(p.append(Ui(new qt(1),s),r),r=s.length+Math.max(0,r-s.length)),p.append(Ui(a,s),r),this.atCursorPos=c,this.pendingBuffer=c?e<t||r>s.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=s.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(n);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=r)}static build(e,t,n,s,r){let o=new bi(e,t,n,r);return o.openEnd=y.RangeSet.spans(s,t,n,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Ui(i,e){for(let t of e)i=new st(t,[i],i.length);return i}class jt extends je{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}jt.inline=new jt("span");jt.block=new jt("div");var Q=function(i){return i[i.LTR=0]="LTR",i[i.RTL=1]="RTL",i}(Q||(Q={}));const kt=Q.LTR,Cr=Q.RTL;function Oa(i){let e=[];for(let t=0;t<i.length;t++)e.push(1<<+i[t]);return e}const iu=Oa("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),nu=Oa("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Js=Object.create(null),Je=[];for(let i of["()","[]","{}"]){let e=i.charCodeAt(0),t=i.charCodeAt(1);Js[e]=t,Js[t]=-e}function Da(i){return i<=247?iu[i]:1424<=i&&i<=1524?2:1536<=i&&i<=1785?nu[i-1536]:1774<=i&&i<=2220?4:8192<=i&&i<=8204?256:64336<=i&&i<=65023?4:1}const su=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class ht{get dir(){return this.level%2?Cr:kt}constructor(e,t,n){this.from=e,this.to=t,this.level=n}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,n,s){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==n)return o;(r<0||(s!=0?s<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Pa(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++){let n=i[t],s=e[t];if(n.from!=s.from||n.to!=s.to||n.direction!=s.direction||!Pa(n.inner,s.inner))return!1}return!0}const K=[];function ru(i,e,t,n,s){for(let r=0;r<=n.length;r++){let o=r?n[r-1].to:e,l=r<n.length?n[r].from:t,a=r?256:s;for(let f=o,c=a,p=a;f<l;f++){let g=Da(i.charCodeAt(f));g==512?g=c:g==8&&p==4&&(g=16),K[f]=g==4?2:g,g&7&&(p=g),c=g}for(let f=o,c=a,p=a;f<l;f++){let g=K[f];if(g==128)f<l-1&&c==K[f+1]&&c&24?g=K[f]=c:K[f]=256;else if(g==64){let v=f+1;for(;v<l&&K[v]==64;)v++;let k=f&&c==8||v<t&&K[v]==8?p==1?1:8:256;for(let C=f;C<v;C++)K[C]=k;f=v-1}else g==8&&p==1&&(K[f]=1);c=g,g&7&&(p=g)}}}function ou(i,e,t,n,s){let r=s==1?2:1;for(let o=0,l=0,a=0;o<=n.length;o++){let f=o?n[o-1].to:e,c=o<n.length?n[o].from:t;for(let p=f,g,v,k;p<c;p++)if(v=Js[g=i.charCodeAt(p)])if(v<0){for(let C=l-3;C>=0;C-=3)if(Je[C+1]==-v){let M=Je[C+2],T=M&2?s:M&4?M&1?r:s:0;T&&(K[p]=K[Je[C]]=T),l=C;break}}else{if(Je.length==189)break;Je[l++]=p,Je[l++]=g,Je[l++]=a}else if((k=K[p])==2||k==1){let C=k==s;a=C?0:1;for(let M=l-3;M>=0;M-=3){let T=Je[M+2];if(T&2)break;if(C)Je[M+2]|=2;else{if(T&4)break;Je[M+2]|=4}}}}}function lu(i,e,t,n){for(let s=0,r=n;s<=t.length;s++){let o=s?t[s-1].to:i,l=s<t.length?t[s].from:e;for(let a=o;a<l;){let f=K[a];if(f==256){let c=a+1;for(;;)if(c==l){if(s==t.length)break;c=t[s++].to,l=s<t.length?t[s].from:e}else if(K[c]==256)c++;else break;let p=r==1,g=(c<e?K[c]:n)==1,v=p==g?p?1:2:n;for(let k=c,C=s,M=C?t[C-1].to:i;k>a;)k==M&&(k=t[--C].from,M=C?t[C-1].to:i),K[--k]=v;a=c}else r=f,a++}}}function Us(i,e,t,n,s,r,o){let l=n%2?2:1;if(n%2==s%2)for(let a=e,f=0;a<t;){let c=!0,p=!1;if(f==r.length||a<r[f].from){let C=K[a];C!=l&&(c=!1,p=C==16)}let g=!c&&l==1?[]:null,v=c?n:n+1,k=a;e:for(;;)if(f<r.length&&k==r[f].from){if(p)break e;let C=r[f];if(!c)for(let M=C.to,T=f+1;;){if(M==t)break e;if(T<r.length&&r[T].from==M)M=r[T++].to;else{if(K[M]==l)break e;break}}if(f++,g)g.push(C);else{C.from>a&&o.push(new ht(a,C.from,v));let M=C.direction==kt!=!(v%2);Ys(i,M?n+1:n,s,C.inner,C.from,C.to,o),a=C.to}k=C.to}else{if(k==t||(c?K[k]!=l:K[k]==l))break;k++}g?Us(i,a,k,n+1,s,g,o):a<k&&o.push(new ht(a,k,v)),a=k}else for(let a=t,f=r.length;a>e;){let c=!0,p=!1;if(!f||a>r[f-1].to){let C=K[a-1];C!=l&&(c=!1,p=C==16)}let g=!c&&l==1?[]:null,v=c?n:n+1,k=a;e:for(;;)if(f&&k==r[f-1].to){if(p)break e;let C=r[--f];if(!c)for(let M=C.from,T=f;;){if(M==e)break e;if(T&&r[T-1].to==M)M=r[--T].from;else{if(K[M-1]==l)break e;break}}if(g)g.push(C);else{C.to<a&&o.push(new ht(C.to,a,v));let M=C.direction==kt!=!(v%2);Ys(i,M?n+1:n,s,C.inner,C.from,C.to,o),a=C.from}k=C.from}else{if(k==e||(c?K[k-1]!=l:K[k-1]==l))break;k--}g?Us(i,k,a,n+1,s,g,o):k<a&&o.push(new ht(k,a,v)),a=k}}function Ys(i,e,t,n,s,r,o){let l=e%2?2:1;ru(i,s,r,n,l),ou(i,s,r,n,l),lu(s,r,n,l),Us(i,s,r,e,t,n,o)}function au(i,e,t){if(!i)return[new ht(0,0,e==Cr?1:0)];if(e==kt&&!t.length&&!su.test(i))return Ra(i.length);if(t.length)for(;i.length>K.length;)K[K.length]=256;let n=[],s=e==kt?0:1;return Ys(i,s,s,t,0,i.length,n),n}function Ra(i){return[new ht(0,i,0)]}let Ba="";function hu(i,e,t,n,s){var r;let o=n.head-i.from,l=ht.find(e,o,(r=n.bidiLevel)!==null&&r!==void 0?r:-1,n.assoc),a=e[l],f=a.side(s,t);if(o==f){let g=l+=s?1:-1;if(g<0||g>=e.length)return null;a=e[l=g],o=a.side(!s,t),f=a.side(s,t)}let c=y.findClusterBreak(i.text,o,a.forward(s,t));(c<a.from||c>a.to)&&(c=f),Ba=i.text.slice(Math.min(o,c),Math.max(o,c));let p=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return p&&c==f&&p.level+(s?0:1)<a.level?y.EditorSelection.cursor(p.side(!s,t)+i.from,p.forward(s,t)?1:-1,p.level):y.EditorSelection.cursor(c+i.from,a.forward(s,t)?-1:1,a.level)}function cu(i,e,t){for(let n=e;n<t;n++){let s=Da(i.charCodeAt(n));if(s==1)return kt;if(s==2||s==4)return Cr}return kt}const La=y.Facet.define(),Ia=y.Facet.define(),Na=y.Facet.define(),Fa=y.Facet.define(),Gs=y.Facet.define(),Va=y.Facet.define(),Ha=y.Facet.define(),Ar=y.Facet.define(),Mr=y.Facet.define(),Wa=y.Facet.define({combine:i=>i.some(e=>e)}),$a=y.Facet.define({combine:i=>i.some(e=>e)}),za=y.Facet.define();class Vt{constructor(e,t="nearest",n="nearest",s=5,r=5,o=!1){this.range=e,this.y=t,this.x=n,this.yMargin=s,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new Vt(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new Vt(y.EditorSelection.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Yi=y.StateEffect.define({map:(i,e)=>i.map(e)}),qa=y.StateEffect.define();function Me(i,e,t){let n=i.facet(Fa);n.length?n[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const it=y.Facet.define({combine:i=>i.length?i[0]:!0});let fu=0;const Bt=y.Facet.define({combine(i){return i.filter((e,t)=>{for(let n=0;n<t;n++)if(i[n].plugin==e.plugin)return!1;return!0})}});class se{constructor(e,t,n,s,r){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=s,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(Bt.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Bt.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:n,eventObservers:s,provide:r,decorations:o}=t||{};return new se(fu++,e,n,s,l=>{let a=[];return o&&a.push(wi.of(f=>{let c=f.plugin(l);return c?o(c):H.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return se.define((n,s)=>new e(n,s),t)}}class gs{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(n){if(Me(t.state,n,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){Me(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(n){Me(e.state,n,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const ja=y.Facet.define(),Er=y.Facet.define(),wi=y.Facet.define(),_a=y.Facet.define(),Tr=y.Facet.define(),Ka=y.Facet.define();function To(i,e){let t=i.state.facet(Ka);if(!t.length)return t;let n=t.map(r=>r instanceof Function?r(i):r),s=[];return y.RangeSet.spans(n,e.from,e.to,{point(){},span(r,o,l,a){let f=r-e.from,c=o-e.from,p=s;for(let g=l.length-1;g>=0;g--,a--){let v=l[g].spec.bidiIsolate,k;if(v==null&&(v=cu(e.text,f,c)),a>0&&p.length&&(k=p[p.length-1]).to==f&&k.direction==v)k.to=c,p=k.inner;else{let C={from:f,to:c,direction:v,inner:[]};p.push(C),p=C.inner}}}}),s}const Ja=y.Facet.define();function Or(i){let e=0,t=0,n=0,s=0;for(let r of i.state.facet(Ja)){let o=r(i);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(n=Math.max(n,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:e,right:t,top:n,bottom:s}}const di=y.Facet.define();class Fe{constructor(e,t,n,s){this.fromA=e,this.toA=t,this.fromB=n,this.toB=s}join(e){return new Fe(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,n=this;for(;t>0;t--){let s=e[t-1];if(!(s.fromA>n.toA)){if(s.toA<n.fromA)break;n=n.join(s),e.splice(t-1,1)}}return e.splice(t,0,n),e}static extendWithRanges(e,t){if(t.length==0)return e;let n=[];for(let s=0,r=0,o=0,l=0;;s++){let a=s==e.length?null:e[s],f=o-l,c=a?a.fromB:1e9;for(;r<t.length&&t[r]<c;){let p=t[r],g=t[r+1],v=Math.max(l,p),k=Math.min(c,g);if(v<=k&&new Fe(v+f,k+f,v,k).addToSet(n),g>c)break;r+=2}if(!a)return n;new Fe(a.fromA,a.toA,a.fromB,a.toB).addToSet(n),o=a.toA,l=a.toB}}}class En{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=y.ChangeSet.empty(this.startState.doc.length);for(let r of n)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,o,l,a)=>s.push(new Fe(r,o,l,a))),this.changedRanges=s}static create(e,t,n){return new En(e,t,n)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class Oo extends J{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=H.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new ce],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Fe(0,0,0,e.state.doc.length)],0,null)}update(e){var t;let n=e.changedRanges;this.minWidth>0&&n.length&&(n.every(({fromA:f,toA:c})=>c<this.minWidthFrom||f>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?s=this.domChanged.newSel.head:!bu(e.changes,this.hasComposition)&&!e.selectionSet&&(s=e.state.selection.main.head));let r=s>-1?du(this.view,e.changes,s):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:f,to:c}=this.hasComposition;n=new Fe(f,c,e.changes.mapPos(f,-1),e.changes.mapPos(c,1)).addToSet(n.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(V.ie||V.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=gu(o,l,e.changes);return n=Fe.extendWithRanges(n,a),!(this.flags&7)&&n.length==0?!1:(this.updateInner(n,e.startState.doc.length,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,n){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,n);let{observer:s}=this.view;s.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=V.chrome||V.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||s.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.children)o instanceof nt&&o.widget instanceof Ks&&r.push(o.dom);s.updateGaps(r)}updateChildren(e,t,n){let s=n?n.range.addToSet(e.slice()):e,r=this.childCursor(t);for(let o=s.length-1;;o--){let l=o>=0?s[o]:null;if(!l)break;let{fromA:a,toA:f,fromB:c,toB:p}=l,g,v,k,C;if(n&&n.range.fromB<p&&n.range.toB>c){let L=bi.build(this.view.state.doc,c,n.range.fromB,this.decorations,this.dynamicDecorationMap),R=bi.build(this.view.state.doc,n.range.toB,p,this.decorations,this.dynamicDecorationMap);v=L.breakAtStart,k=L.openStart,C=R.openEnd;let I=this.compositionView(n);R.breakAtStart?I.breakAfter=1:R.content.length&&I.merge(I.length,I.length,R.content[0],!1,R.openStart,0)&&(I.breakAfter=R.content[0].breakAfter,R.content.shift()),L.content.length&&I.merge(0,0,L.content[L.content.length-1],!0,0,L.openEnd)&&L.content.pop(),g=L.content.concat(I).concat(R.content)}else({content:g,breakAtStart:v,openStart:k,openEnd:C}=bi.build(this.view.state.doc,c,p,this.decorations,this.dynamicDecorationMap));let{i:M,off:T}=r.findPos(f,1),{i:P,off:F}=r.findPos(a,-1);xa(this,P,F,M,T,g,v,k,C)}n&&this.fixCompositionDOM(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let n of t.effects)n.is(qa)&&(this.editContextFormatting=n.value)}compositionView(e){let t=new ze(e.text.nodeValue);t.flags|=8;for(let{deco:s}of e.marks)t=new st(s,[t],t.length);let n=new ce;return n.append(t,0),n}fixCompositionDOM(e){let t=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=J.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},n=this.childPos(e.range.fromB,1),s=this.children[n.i];t(e.line,s);for(let r=e.marks.length-1;r>=-1;r--)n=s.childPos(n.off,1),s=s.children[n.i],t(r>=0?e.marks[r].node:e.text,s)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let n=this.view.root.activeElement,s=n==this.dom,r=!s&&!(this.view.state.facet(it)||this.dom.tabIndex>-1)&&pn(this.dom,this.view.observer.selectionRange)&&!(n&&this.dom.contains(n));if(!(s||t||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(l.anchor)),f=l.empty?a:this.moveToLine(this.domAtPos(l.head));if(V.gecko&&l.empty&&!this.hasComposition&&uu(a)){let p=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(p,a.node.childNodes[a.offset]||null)),a=f=new we(p,0),o=!0}let c=this.view.observer.selectionRange;(o||!c.focusNode||(!yi(a.node,a.offset,c.anchorNode,c.anchorOffset)||!yi(f.node,f.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,l))&&(this.view.observer.ignore(()=>{V.android&&V.chrome&&this.dom.contains(c.focusNode)&&yu(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let p=xi(this.view.root);if(p)if(l.empty){if(V.gecko){let g=pu(a.node,a.offset);if(g&&g!=3){let v=(g==1?ba:Sa)(a.node,a.offset);v&&(a=new we(v.node,v.offset))}}p.collapse(a.node,a.offset),l.bidiLevel!=null&&p.caretBidiLevel!==void 0&&(p.caretBidiLevel=l.bidiLevel)}else if(p.extend){p.collapse(a.node,a.offset);try{p.extend(f.node,f.offset)}catch{}}else{let g=document.createRange();l.anchor>l.head&&([a,f]=[f,a]),g.setEnd(f.node,f.offset),g.setStart(a.node,a.offset),p.removeAllRanges(),p.addRange(g)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(a,f)),this.impreciseAnchor=a.precise?null:new we(c.anchorNode,c.anchorOffset),this.impreciseHead=f.precise?null:new we(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&yi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,n=xi(e.root),{anchorNode:s,anchorOffset:r}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let o=ce.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),f=this.coordsAt(t.head,1);if(!a||!f||a.bottom>f.top)return;let c=this.domAtPos(t.head+t.assoc);n.collapse(c.node,c.offset),n.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let p=e.observer.selectionRange;e.docView.posFromDOM(p.anchorNode,p.anchorOffset)!=t.from&&n.collapse(s,r)}moveToLine(e){let t=this.dom,n;if(e.node!=t)return e;for(let s=e.offset;!n&&s<t.childNodes.length;s++){let r=J.get(t.childNodes[s]);r instanceof ce&&(n=r.domAtPos(0))}for(let s=e.offset-1;!n&&s>=0;s--){let r=J.get(t.childNodes[s]);r instanceof ce&&(n=r.domAtPos(r.length))}return n?new we(n.node,n.offset,!0):e}nearest(e){for(let t=e;t;){let n=J.get(t);if(n&&n.rootView==this)return n;t=t.parentNode}return null}posFromDOM(e,t){let n=this.nearest(e);if(!n)throw new RangeError("Trying to find position for a DOM position outside of the document");return n.localPosFromDOM(e,t)+n.posAtStart}domAtPos(e){let{i:t,off:n}=this.childCursor().findPos(e,-1);for(;t<this.children.length-1;){let s=this.children[t];if(n<s.length||s instanceof ce)break;t++,n=0}return this.children[t].domAtPos(n)}coordsAt(e,t){let n=null,s=0;for(let r=this.length,o=this.children.length-1;o>=0;o--){let l=this.children[o],a=r-l.breakAfter,f=a-l.length;if(a<e)break;if(f<=e&&(f<e||l.covers(-1))&&(a>e||l.covers(1))&&(!n||l instanceof ce&&!(n instanceof ce&&t>=0)))n=l,s=f;else if(n&&f==e&&a==e&&l instanceof nt&&Math.abs(t)<2){if(l.deco.startSide<0)break;o&&(n=null)}r=f}return n?n.coordsAt(e-s,t):null}coordsForChar(e){let{i:t,off:n}=this.childPos(e,1),s=this.children[t];if(!(s instanceof ce))return null;for(;s.children.length;){let{i:l,off:a}=s.childPos(n,1);for(;;l++){if(l==s.children.length)return null;if((s=s.children[l]).length)break}n=a}if(!(s instanceof ze))return null;let r=y.findClusterBreak(s.text,n);if(r==n)return null;let o=wt(s.dom,n,r).getClientRects();for(let l=0;l<o.length;l++){let a=o[l];if(l==o.length-1||a.top<a.bottom&&a.left<a.right)return a}return null}measureVisibleLineHeights(e){let t=[],{from:n,to:s}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==Q.LTR;for(let f=0,c=0;c<this.children.length;c++){let p=this.children[c],g=f+p.length;if(g>s)break;if(f>=n){let v=p.dom.getBoundingClientRect();if(t.push(v.height),o){let k=p.dom.lastChild,C=k?zt(k):[];if(C.length){let M=C[C.length-1],T=a?M.right-v.left:v.right-M.left;T>l&&(l=T,this.minWidth=r,this.minWidthFrom=f,this.minWidthTo=g)}}}f=g+p.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?Q.RTL:Q.LTR}measureTextSize(){for(let r of this.children)if(r instanceof ce){let o=r.measureTextSize();if(o)return o}let e=document.createElement("div"),t,n,s;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let r=zt(e.firstChild)[0];t=e.getBoundingClientRect().height,n=r?r.width/27:7,s=r?r.height:t,e.remove()}),{lineHeight:t,charWidth:n,textHeight:s}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new va(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,s=0;;s++){let r=s==t.viewports.length?null:t.viewports[s],o=r?r.from-1:this.length;if(o>n){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(H.replace({widget:new Ks(l),block:!0,inclusive:!0,isBlockGap:!0}).range(n,o))}if(!r)break;n=r.to+1}return H.set(e)}updateDeco(){let e=1,t=this.view.state.facet(wi).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),n=!1,s=this.view.state.facet(_a).map((r,o)=>{let l=typeof r=="function";return l&&(n=!0),l?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[e++]=n,t.push(y.RangeSet.join(s))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;return this.decorations}scrollIntoView(e){if(e.isSnapshot){let f=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=f.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let f of this.view.state.facet(za))try{if(f(this.view,e.range,e))return!0}catch(c){Me(this.view.state,c,"scroll handler")}let{range:t}=e,n=this.coordsAt(t.head,t.empty?t.assoc:t.head>t.anchor?-1:1),s;if(!n)return;!t.empty&&(s=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,s.left),top:Math.min(n.top,s.top),right:Math.max(n.right,s.right),bottom:Math.max(n.bottom,s.bottom)});let r=Or(this.view),o={left:n.left-r.left,top:n.top-r.top,right:n.right+r.right,bottom:n.bottom+r.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;jf(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,l),-l),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==Q.LTR)}}function uu(i){return i.node.nodeType==1&&i.node.firstChild&&(i.offset==0||i.node.childNodes[i.offset-1].contentEditable=="false")&&(i.offset==i.node.childNodes.length||i.node.childNodes[i.offset].contentEditable=="false")}function Ua(i,e){let t=i.observer.selectionRange;if(!t.focusNode)return null;let n=ba(t.focusNode,t.focusOffset),s=Sa(t.focusNode,t.focusOffset),r=n||s;if(s&&n&&s.node!=n.node){let l=J.get(s.node);if(!l||l instanceof ze&&l.text!=s.node.nodeValue)r=s;else if(i.docView.lastCompositionAfterCursor){let a=J.get(n.node);!a||a instanceof ze&&a.text!=n.node.nodeValue||(r=s)}}if(i.docView.lastCompositionAfterCursor=r!=n,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function du(i,e,t){let n=Ua(i,t);if(!n)return null;let{node:s,from:r,to:o}=n,l=s.nodeValue;if(/[\n\r]/.test(l)||i.state.doc.sliceString(n.from,n.to)!=l)return null;let a=e.invertedDesc,f=new Fe(a.mapPos(r),a.mapPos(o),r,o),c=[];for(let p=s.parentNode;;p=p.parentNode){let g=J.get(p);if(g instanceof st)c.push({node:p,deco:g.mark});else{if(g instanceof ce||p.nodeName=="DIV"&&p.parentNode==i.contentDOM)return{range:f,text:s,marks:c,line:p};if(p!=i.contentDOM)c.push({node:p,deco:new Ii({inclusive:!0,attributes:eu(p),tagName:p.tagName.toLowerCase()})});else return null}}}function pu(i,e){return i.nodeType!=1?0:(e&&i.childNodes[e-1].contentEditable=="false"?1:0)|(e<i.childNodes.length&&i.childNodes[e].contentEditable=="false"?2:0)}let mu=class{constructor(){this.changes=[]}compareRange(e,t){mn(e,t,this.changes)}comparePoint(e,t){mn(e,t,this.changes)}boundChange(e){mn(e,e,this.changes)}};function gu(i,e,t){let n=new mu;return y.RangeSet.compare(i,e,t,n),n.changes}function yu(i,e){for(let t=i;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function bu(i,e){let t=!1;return e&&i.iterChangedRanges((n,s)=>{n<e.to&&s>e.from&&(t=!0)}),t}function Su(i,e,t=1){let n=i.charCategorizer(e),s=i.doc.lineAt(e),r=e-s.from;if(s.length==0)return y.EditorSelection.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=y.findClusterBreak(s.text,r,!1):l=y.findClusterBreak(s.text,r);let a=n(s.text.slice(o,l));for(;o>0;){let f=y.findClusterBreak(s.text,o,!1);if(n(s.text.slice(f,o))!=a)break;o=f}for(;l<s.length;){let f=y.findClusterBreak(s.text,l);if(n(s.text.slice(l,f))!=a)break;l=f}return y.EditorSelection.range(o+s.from,l+s.from)}function vu(i,e){return e.left>i?e.left-i:Math.max(0,i-e.right)}function xu(i,e){return e.top>i?e.top-i:Math.max(0,i-e.bottom)}function ys(i,e){return i.top<e.bottom-1&&i.bottom>e.top+1}function Do(i,e){return e<i.top?{top:e,left:i.left,right:i.right,bottom:i.bottom}:i}function Po(i,e){return e>i.bottom?{top:i.top,left:i.left,right:i.right,bottom:e}:i}function Xs(i,e,t){let n,s,r,o,l=!1,a,f,c,p;for(let k=i.firstChild;k;k=k.nextSibling){let C=zt(k);for(let M=0;M<C.length;M++){let T=C[M];s&&ys(s,T)&&(T=Do(Po(T,s.bottom),s.top));let P=vu(e,T),F=xu(t,T);if(P==0&&F==0)return k.nodeType==3?Ro(k,e,t):Xs(k,e,t);(!n||o>F||o==F&&r>P)&&(n=k,s=T,r=P,o=F,l=P?e<T.left?M>0:M<C.length-1:!0),P==0?t>T.bottom&&(!c||c.bottom<T.bottom)?(a=k,c=T):t<T.top&&(!p||p.top>T.top)&&(f=k,p=T):c&&ys(c,T)?c=Po(c,T.bottom):p&&ys(p,T)&&(p=Do(p,T.top))}}if(c&&c.bottom>=t?(n=a,s=c):p&&p.top<=t&&(n=f,s=p),!n)return{node:i,offset:0};let g=Math.max(s.left,Math.min(s.right,e));if(n.nodeType==3)return Ro(n,g,t);if(l&&n.contentEditable!="false")return Xs(n,g,t);let v=Array.prototype.indexOf.call(i.childNodes,n)+(e>=(s.left+s.right)/2?1:0);return{node:i,offset:v}}function Ro(i,e,t){let n=i.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;l<n;l++){let a=wt(i,l,l+1).getClientRects();for(let f=0;f<a.length;f++){let c=a[f];if(c.top==c.bottom)continue;o||(o=e-c.left);let p=(c.top>t?c.top-t:t-c.bottom)-1;if(c.left-1<=e&&c.right+1>=e&&p<r){let g=e>=(c.left+c.right)/2,v=g;if((V.chrome||V.gecko)&&wt(i,l).getBoundingClientRect().left==c.right&&(v=!g),p<=0)return{node:i,offset:l+(v?1:0)};s=l+(v?1:0),r=p}}}return{node:i,offset:s>-1?s:o>0?i.nodeValue.length:0}}function Ya(i,e,t,n=-1){var s,r;let o=i.contentDOM.getBoundingClientRect(),l=o.top+i.viewState.paddingTop,a,{docHeight:f}=i.viewState,{x:c,y:p}=e,g=p-l;if(g<0)return 0;if(g>f)return i.state.doc.length;for(let L=i.viewState.heightOracle.textHeight/2,R=!1;a=i.elementAtHeight(g),a.type!=Ee.Text;)for(;g=n>0?a.bottom+L:a.top-L,!(g>=0&&g<=f);){if(R)return t?null:0;R=!0,n=-n}p=l+g;let v=a.from;if(v<i.viewport.from)return i.viewport.from==0?0:t?null:Bo(i,o,a,c,p);if(v>i.viewport.to)return i.viewport.to==i.state.doc.length?i.state.doc.length:t?null:Bo(i,o,a,c,p);let k=i.dom.ownerDocument,C=i.root.elementFromPoint?i.root:k,M=C.elementFromPoint(c,p);M&&!i.contentDOM.contains(M)&&(M=null),M||(c=Math.max(o.left+1,Math.min(o.right-1,c)),M=C.elementFromPoint(c,p),M&&!i.contentDOM.contains(M)&&(M=null));let T,P=-1;if(M&&((s=i.docView.nearest(M))===null||s===void 0?void 0:s.isEditable)!=!1){if(k.caretPositionFromPoint){let L=k.caretPositionFromPoint(c,p);L&&({offsetNode:T,offset:P}=L)}else if(k.caretRangeFromPoint){let L=k.caretRangeFromPoint(c,p);L&&({startContainer:T,startOffset:P}=L,(!i.contentDOM.contains(T)||V.safari&&wu(T,P,c)||V.chrome&&ku(T,P,c))&&(T=void 0))}T&&(P=Math.min(Ze(T),P))}if(!T||!i.docView.dom.contains(T)){let L=ce.find(i.docView,v);if(!L)return g>a.top+a.height/2?a.to:a.from;({node:T,offset:P}=Xs(L.dom,c,p))}let F=i.docView.nearest(T);if(!F)return null;if(F.isWidget&&((r=F.dom)===null||r===void 0?void 0:r.nodeType)==1){let L=F.dom.getBoundingClientRect();return e.y<L.top||e.y<=L.bottom&&e.x<=(L.left+L.right)/2?F.posAtStart:F.posAtEnd}else return F.localPosFromDOM(T,P)+F.posAtStart}function Bo(i,e,t,n,s){let r=Math.round((n-e.left)*i.defaultCharacterWidth);if(i.lineWrapping&&t.height>i.defaultLineHeight*1.5){let l=i.viewState.heightOracle.textHeight,a=Math.floor((s-t.top-(i.defaultLineHeight-l)*.5)/l);r+=a*i.viewState.heightOracle.lineLength}let o=i.state.sliceDoc(t.from,t.to);return t.from+y.findColumn(o,r,i.state.tabSize)}function wu(i,e,t){let n,s=i;if(i.nodeType!=3||e!=(n=i.nodeValue.length))return!1;for(;;){let r=s.nextSibling;if(r){if(r.nodeName=="BR")break;return!1}else{let o=s.parentNode;if(!o||o.nodeName=="DIV")break;s=o}}return wt(i,n-1,n).getBoundingClientRect().right>t}function ku(i,e,t){if(e!=0)return!1;for(let s=i;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let n=i.nodeType==1?i.getBoundingClientRect():wt(i,0,Math.max(i.nodeValue.length,1)).getBoundingClientRect();return t-n.left>5}function Qs(i,e,t){let n=i.lineBlockAt(e);if(Array.isArray(n.type)){let s;for(let r of n.type){if(r.from>e)break;if(!(r.to<e)){if(r.from<e&&r.to>e)return r;(!s||r.type==Ee.Text&&(s.type!=r.type||(t<0?r.from<e:r.to>e)))&&(s=r)}}return s||n}return n}function Cu(i,e,t,n){let s=Qs(i,e.head,e.assoc||-1),r=!n||s.type!=Ee.Text||!(i.lineWrapping||s.widgetLineBreaks)?null:i.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let o=i.dom.getBoundingClientRect(),l=i.textDirectionAt(s.from),a=i.posAtCoords({x:t==(l==Q.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return y.EditorSelection.cursor(a,t?-1:1)}return y.EditorSelection.cursor(t?s.to:s.from,t?-1:1)}function Lo(i,e,t,n){let s=i.state.doc.lineAt(e.head),r=i.bidiSpans(s),o=i.textDirectionAt(s.from);for(let l=e,a=null;;){let f=hu(s,r,o,l,t),c=Ba;if(!f){if(s.number==(t?i.state.doc.lines:1))return l;c=`
|
|
7
|
-
`,s=i.state.doc.line(s.number+(t?1:-1)),r=i.bidiSpans(s),f=i.visualLineSide(s,!t)}if(a){if(!a(c))return l}else{if(!n)return f;a=n(c)}l=f}}function Au(i,e,t){let n=i.state.charCategorizer(e),s=n(t);return r=>{let o=n(r);return s==y.CharCategory.Space&&(s=o),s==o}}function Mu(i,e,t,n){let s=e.head,r=t?1:-1;if(s==(t?i.state.doc.length:0))return y.EditorSelection.cursor(s,e.assoc);let o=e.goalColumn,l,a=i.contentDOM.getBoundingClientRect(),f=i.coordsAtPos(s,e.assoc||-1),c=i.documentTop;if(f)o==null&&(o=f.left-a.left),l=r<0?f.top:f.bottom;else{let v=i.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,i.defaultCharacterWidth*(s-v.from))),l=(r<0?v.top:v.bottom)+c}let p=a.left+o,g=n??i.viewState.heightOracle.textHeight>>1;for(let v=0;;v+=10){let k=l+(g+v)*r,C=Ya(i,{x:p,y:k},!1,r);if(k<a.top||k>a.bottom||(r<0?C<s:C>s)){let M=i.docView.coordsForChar(C),T=!M||k<M.top?-1:1;return y.EditorSelection.cursor(C,T,void 0,o)}}}function gn(i,e,t){for(;;){let n=0;for(let s of i)s.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=n||t||(e-r<o-e?-1:1);e=a<0?r:o,n=a}});if(!n)return e}}function bs(i,e,t){let n=gn(i.state.facet(Tr).map(s=>s(i)),t.from,e.head>t.from?-1:1);return n==t.from?t:y.EditorSelection.cursor(n,n<t.from?1:-1)}const pi="";class Eu{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(y.EditorState.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=pi}readRange(e,t){if(!e)return this;let n=e.parentNode;for(let s=e;;){this.findPointBefore(n,s);let r=this.text.length;this.readNode(s);let o=s.nextSibling;if(o==t)break;let l=J.get(s),a=J.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:An(s))||An(o)&&(s.nodeName!="BR"||s.cmIgnore)&&this.text.length>r)&&this.lineBreak(),s=o}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,n),o=this.lineSeparator.length):(l=s.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(n,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);n=r+o}}readNode(e){if(e.cmIgnore)return;let t=J.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let s=n.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(e.nodeType==3?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(Tu(e,n.node,n.offset)?t:0))}}function Tu(i,e,t){for(;;){if(!e||t<Ze(e))return!1;if(e==i)return!0;t=xt(e)+1,e=e.parentNode}}class Io{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class Ou{constructor(e,t,n,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,n,0))){let l=r||o?[]:Ru(e),a=new Eu(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Bu(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!Ws(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),f=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!Ws(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),c=e.viewport;if((V.ios||V.chrome)&&e.state.selection.main.empty&&a!=f&&(c.from>0||c.to<e.state.doc.length)){let p=Math.min(a,f),g=Math.max(a,f),v=c.from-p,k=c.to-g;(v==0||v==1||p==0)&&(k==0||k==-1||g==e.state.doc.length)&&(a=0,f=e.state.doc.length)}this.newSel=y.EditorSelection.single(f,a)}}}function Ga(i,e){let t,{newSel:n}=e,s=i.state.selection.main,r=i.inputState.lastKeyTime>Date.now()-100?i.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=s.from,f=null;(r===8||V.android&&e.text.length<l-o)&&(a=s.to,f="end");let c=Pu(i.state.doc.sliceString(o,l,pi),e.text,a-o,f);c&&(V.chrome&&r==13&&c.toB==c.from+2&&e.text.slice(c.from,c.toB)==pi+pi&&c.toB--,t={from:o+c.from,to:o+c.toA,insert:y.Text.of(e.text.slice(c.from,c.toB).split(pi))})}else n&&(!i.hasFocus&&i.state.facet(it)||n.main.eq(s))&&(n=null);if(!t&&!n)return!1;if(!t&&e.typeOver&&!s.empty&&n&&n.main.empty?t={from:s.from,to:s.to,insert:i.state.doc.slice(s.from,s.to)}:(V.mac||V.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&i.contentDOM.getAttribute("autocorrect")=="off"?(n&&t.insert.length==2&&(n=y.EditorSelection.single(n.main.anchor-1,n.main.head-1)),t={from:t.from,to:t.to,insert:y.Text.of([t.insert.toString().replace("."," ")])}):t&&t.from>=s.from&&t.to<=s.to&&(t.from!=s.from||t.to!=s.to)&&s.to-s.from-(t.to-t.from)<=4?t={from:s.from,to:s.to,insert:i.state.doc.slice(s.from,t.from).append(t.insert).append(i.state.doc.slice(t.to,s.to))}:V.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
|
|
8
|
-
`&&i.lineWrapping&&(n&&(n=y.EditorSelection.single(n.main.anchor-1,n.main.head-1)),t={from:s.from,to:s.to,insert:y.Text.of([" "])}),t)return Dr(i,t,n,r);if(n&&!n.main.eq(s)){let o=!1,l="select";return i.inputState.lastSelectionTime>Date.now()-50&&(i.inputState.lastSelectionOrigin=="select"&&(o=!0),l=i.inputState.lastSelectionOrigin),i.dispatch({selection:n,scrollIntoView:o,userEvent:l}),!0}else return!1}function Dr(i,e,t,n=-1){if(V.ios&&i.inputState.flushIOSKey(e))return!0;let s=i.state.selection.main;if(V.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&i.state.sliceDoc(e.from,s.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Ft(i.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||n==8&&e.insert.length<e.to-e.from&&e.to>s.head)&&Ft(i.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&Ft(i.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();i.inputState.composing>=0&&i.inputState.composing++;let o,l=()=>o||(o=Du(i,e,t));return i.state.facet(Va).some(a=>a(i,e.from,e.to,r,l))||i.dispatch(l()),!0}function Du(i,e,t){let n,s=i.state,r=s.selection.main;if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&i.inputState.composing<0){let l=r.from<e.from?s.sliceDoc(r.from,e.from):"",a=r.to>e.to?s.sliceDoc(e.to,r.to):"";n=s.replaceSelection(i.state.toText(l+e.insert.sliceString(0,void 0,i.state.lineBreak)+a))}else{let l=s.changes(e),a=t&&t.main.to<=l.newLength?t.main:void 0;if(s.selection.ranges.length>1&&i.inputState.composing>=0&&e.to<=r.to&&e.to>=r.to-10){let f=i.state.sliceDoc(e.from,e.to),c,p=t&&Ua(i,t.main.head);if(p){let k=e.insert.length-(e.to-e.from);c={from:p.from,to:p.to-k}}else c=i.state.doc.lineAt(r.head);let g=r.to-e.to,v=r.to-r.from;n=s.changeByRange(k=>{if(k.from==r.from&&k.to==r.to)return{changes:l,range:a||k.map(l)};let C=k.to-g,M=C-f.length;if(k.to-k.from!=v||i.state.sliceDoc(M,C)!=f||k.to>=c.from&&k.from<=c.to)return{range:k};let T=s.changes({from:M,to:C,insert:e.insert}),P=k.to-r.to;return{changes:T,range:a?y.EditorSelection.range(Math.max(0,a.anchor+P),Math.max(0,a.head+P)):k.map(T)}})}else n={changes:l,selection:a&&s.selection.replaceRange(a)}}let o="input.type";return(i.composing||i.inputState.compositionPendingChange&&i.inputState.compositionEndedAt>Date.now()-50)&&(i.inputState.compositionPendingChange=!1,o+=".compose",i.inputState.compositionFirstChange&&(o+=".start",i.inputState.compositionFirstChange=!1)),s.update(n,{userEvent:o,scrollIntoView:!0})}function Pu(i,e,t,n){let s=Math.min(i.length,e.length),r=0;for(;r<s&&i.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==s&&i.length==e.length)return null;let o=i.length,l=e.length;for(;o>0&&l>0&&i.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(n=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&i.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function Ru(i){let e=[];if(i.root.activeElement!=i.contentDOM)return e;let{anchorNode:t,anchorOffset:n,focusNode:s,focusOffset:r}=i.observer.selectionRange;return t&&(e.push(new Io(t,n)),(s!=t||r!=n)&&e.push(new Io(s,r))),e}function Bu(i,e){if(i.length==0)return null;let t=i[0].pos,n=i.length==2?i[1].pos:t;return t>-1&&n>-1?y.EditorSelection.single(t+e,n+e):null}class Lu{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,V.safari&&e.contentDOM.addEventListener("input",()=>null),V.gecko&&Gu(e.contentDOM.ownerDocument)}handleEvent(e){!zu(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let n=this.handlers[e];if(n){for(let s of n.observers)s(this.view,t);for(let s of n.handlers){if(t.defaultPrevented)break;if(s(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Iu(e),n=this.handlers,s=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=n[r];l&&o!=!l.handlers.length&&(s.removeEventListener(r,this.handleEvent),l=null),l||s.addEventListener(r,this.handleEvent,{passive:o})}for(let r in n)r!="scroll"&&!t[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&Qa.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),V.android&&V.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return V.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=Xa.find(n=>n.keyCode==e.keyCode))&&!e.ctrlKey||Nu.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Ft(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:V.safari&&!V.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function No(i,e){return(t,n)=>{try{return e.call(i,n,t)}catch(s){Me(t.state,s)}}}function Iu(i){let e=Object.create(null);function t(n){return e[n]||(e[n]={observers:[],handlers:[]})}for(let n of i){let s=n.spec,r=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(r)for(let l in r){let a=r[l];a&&t(l).handlers.push(No(n.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(No(n.value,a))}}for(let n in qe)t(n).handlers.push(qe[n]);for(let n in He)t(n).observers.push(He[n]);return e}const Xa=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Nu="dthko",Qa=[16,17,18,20,91,92,224,225],Gi=6;function Xi(i){return Math.max(0,i)*.7+8}function Fu(i,e){return Math.max(Math.abs(i.clientX-e.clientX),Math.abs(i.clientY-e.clientY))}class Vu{constructor(e,t,n,s){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=_f(e.contentDOM),this.atoms=e.state.facet(Tr).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(y.EditorState.allowMultipleSelections)&&Hu(e,t),this.dragging=$u(e,t)&&th(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Fu(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,n=0,s=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=Or(this.view);e.clientX-a.left<=s+Gi?t=-Xi(s-e.clientX):e.clientX+a.right>=o-Gi&&(t=Xi(e.clientX-o)),e.clientY-a.top<=r+Gi?n=-Xi(r-e.clientY):e.clientY+a.bottom>=l-Gi&&(n=Xi(e.clientY-l)),this.setScrollSpeed(t,n)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let n=0;n<e.ranges.length;n++){let s=e.ranges[n],r=null;if(s.empty){let o=gn(this.atoms,s.from,0);o!=s.from&&(r=y.EditorSelection.cursor(o,-1))}else{let o=gn(this.atoms,s.from,-1),l=gn(this.atoms,s.to,1);(o!=s.from||l!=s.to)&&(r=y.EditorSelection.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}r&&(t||(t=e.ranges.slice()),t[n]=r)}return t?y.EditorSelection.create(t,e.mainIndex):e}select(e){let{view:t}=this,n=this.skipAtoms(this.style.get(e,this.extend,this.multiple));(this.mustSelect||!n.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:n,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Hu(i,e){let t=i.state.facet(La);return t.length?t[0](e):V.mac?e.metaKey:e.ctrlKey}function Wu(i,e){let t=i.state.facet(Ia);return t.length?t[0](e):V.mac?!e.altKey:!e.ctrlKey}function $u(i,e){let{main:t}=i.state.selection;if(t.empty)return!1;let n=xi(i.root);if(!n||n.rangeCount==0)return!0;let s=n.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function zu(i,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,n;t!=i.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(n=J.get(t))&&n.ignoreEvent(e))return!1;return!0}const qe=Object.create(null),He=Object.create(null),Za=V.ie&&V.ie_version<15||V.ios&&V.webkit_version<604;function qu(i){let e=i.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{i.focus(),t.remove(),eh(i,t.value)},50)}function Kn(i,e,t){for(let n of i.facet(e))t=n(t,i);return t}function eh(i,e){e=Kn(i.state,Ar,e);let{state:t}=i,n,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(Zs!=null&&t.selection.ranges.every(a=>a.empty)&&Zs==r.toString()){let a=-1;n=t.changeByRange(f=>{let c=t.doc.lineAt(f.from);if(c.from==a)return{range:f};a=c.from;let p=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:p},range:y.EditorSelection.cursor(f.from+p.length)}})}else o?n=t.changeByRange(a=>{let f=r.line(s++);return{changes:{from:a.from,to:a.to,insert:f.text},range:y.EditorSelection.cursor(a.from+f.length)}}):n=t.replaceSelection(r);i.dispatch(n,{userEvent:"input.paste",scrollIntoView:!0})}He.scroll=i=>{i.inputState.lastScrollTop=i.scrollDOM.scrollTop,i.inputState.lastScrollLeft=i.scrollDOM.scrollLeft};qe.keydown=(i,e)=>(i.inputState.setSelectionOrigin("select"),e.keyCode==27&&i.inputState.tabFocusMode!=0&&(i.inputState.tabFocusMode=Date.now()+2e3),!1);He.touchstart=(i,e)=>{i.inputState.lastTouchTime=Date.now(),i.inputState.setSelectionOrigin("select.pointer")};He.touchmove=i=>{i.inputState.setSelectionOrigin("select.pointer")};qe.mousedown=(i,e)=>{if(i.observer.flush(),i.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let n of i.state.facet(Na))if(t=n(i,e),t)break;if(!t&&e.button==0&&(t=Ku(i,e)),t){let n=!i.hasFocus;i.inputState.startMouseSelection(new Vu(i,e,t,n)),n&&i.observer.ignore(()=>{ma(i.contentDOM);let r=i.root.activeElement;r&&!r.contains(i.contentDOM)&&r.blur()});let s=i.inputState.mouseSelection;if(s)return s.start(e),s.dragging===!1}return!1};function Fo(i,e,t,n){if(n==1)return y.EditorSelection.cursor(e,t);if(n==2)return Su(i.state,e,t);{let s=ce.find(i.docView,e),r=i.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<i.state.doc.length&&l==r.to&&l++,y.EditorSelection.range(o,l)}}let Vo=(i,e,t)=>e>=t.top&&e<=t.bottom&&i>=t.left&&i<=t.right;function ju(i,e,t,n){let s=ce.find(i.docView,e);if(!s)return 1;let r=e-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&Vo(t,n,o))return-1;let l=s.coordsAt(r,1);return l&&Vo(t,n,l)?1:o&&o.bottom>=n?-1:1}function Ho(i,e){let t=i.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:ju(i,t,e.clientX,e.clientY)}}const _u=V.ie&&V.ie_version<=11;let Wo=null,$o=0,zo=0;function th(i){if(!_u)return i.detail;let e=Wo,t=zo;return Wo=i,zo=Date.now(),$o=!e||t>Date.now()-400&&Math.abs(e.clientX-i.clientX)<2&&Math.abs(e.clientY-i.clientY)<2?($o+1)%3:1}function Ku(i,e){let t=Ho(i,e),n=th(e),s=i.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),s=s.map(r.changes))},get(r,o,l){let a=Ho(i,r),f,c=Fo(i,a.pos,a.bias,n);if(t.pos!=a.pos&&!o){let p=Fo(i,t.pos,t.bias,n),g=Math.min(p.from,c.from),v=Math.max(p.to,c.to);c=g<c.from?y.EditorSelection.range(g,v):y.EditorSelection.range(v,g)}return o?s.replaceRange(s.main.extend(c.from,c.to)):l&&n==1&&s.ranges.length>1&&(f=Ju(s,a.pos))?f:l?s.addRange(c):y.EditorSelection.create([c])}}}function Ju(i,e){for(let t=0;t<i.ranges.length;t++){let{from:n,to:s}=i.ranges[t];if(n<=e&&s>=e)return y.EditorSelection.create(i.ranges.slice(0,t).concat(i.ranges.slice(t+1)),i.mainIndex==t?0:i.mainIndex-(i.mainIndex>t?1:0))}return null}qe.dragstart=(i,e)=>{let{selection:{main:t}}=i.state;if(e.target.draggable){let s=i.docView.nearest(e.target);if(s&&s.isWidget){let r=s.posAtStart,o=r+s.length;(r>=t.to||o<=t.from)&&(t=y.EditorSelection.range(r,o))}}let{inputState:n}=i;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Kn(i.state,Mr,i.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};qe.dragend=i=>(i.inputState.draggedContent=null,!1);function qo(i,e,t,n){if(t=Kn(i.state,Ar,t),!t)return;let s=i.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=i.inputState,o=n&&r&&Wu(i,e)?{from:r.from,to:r.to}:null,l={from:s,insert:t},a=i.state.changes(o?[o,l]:l);i.focus(),i.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),i.inputState.draggedContent=null}qe.drop=(i,e)=>{if(!e.dataTransfer)return!1;if(i.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let n=Array(t.length),s=0,r=()=>{++s==t.length&&qo(i,e,n.filter(o=>o!=null).join(i.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(n[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let n=e.dataTransfer.getData("Text");if(n)return qo(i,e,n,!0),!0}return!1};qe.paste=(i,e)=>{if(i.state.readOnly)return!0;i.observer.flush();let t=Za?null:e.clipboardData;return t?(eh(i,t.getData("text/plain")||t.getData("text/uri-list")),!0):(qu(i),!1)};function Uu(i,e){let t=i.dom.parentNode;if(!t)return;let n=t.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(),i.focus()},50)}function Yu(i){let e=[],t=[],n=!1;for(let s of i.selection.ranges)s.empty||(e.push(i.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of i.selection.ranges){let o=i.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(i.doc.length,o.to+1)})),s=o.number}n=!0}return{text:Kn(i,Mr,e.join(i.lineBreak)),ranges:t,linewise:n}}let Zs=null;qe.copy=qe.cut=(i,e)=>{let{text:t,ranges:n,linewise:s}=Yu(i.state);if(!t&&!s)return!1;Zs=s?t:null,e.type=="cut"&&!i.state.readOnly&&i.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let r=Za?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Uu(i,t),!1)};const ih=y.Annotation.define();function nh(i,e){let t=[];for(let n of i.facet(Ha)){let s=n(i,e);s&&t.push(s)}return t.length?i.update({effects:t,annotations:ih.of(!0)}):null}function sh(i){setTimeout(()=>{let e=i.hasFocus;if(e!=i.inputState.notifiedFocused){let t=nh(i.state,e);t?i.dispatch(t):i.update([])}},10)}He.focus=i=>{i.inputState.lastFocusTime=Date.now(),!i.scrollDOM.scrollTop&&(i.inputState.lastScrollTop||i.inputState.lastScrollLeft)&&(i.scrollDOM.scrollTop=i.inputState.lastScrollTop,i.scrollDOM.scrollLeft=i.inputState.lastScrollLeft),sh(i)};He.blur=i=>{i.observer.clearSelectionRange(),sh(i)};He.compositionstart=He.compositionupdate=i=>{i.observer.editContext||(i.inputState.compositionFirstChange==null&&(i.inputState.compositionFirstChange=!0),i.inputState.composing<0&&(i.inputState.composing=0))};He.compositionend=i=>{i.observer.editContext||(i.inputState.composing=-1,i.inputState.compositionEndedAt=Date.now(),i.inputState.compositionPendingKey=!0,i.inputState.compositionPendingChange=i.observer.pendingRecords().length>0,i.inputState.compositionFirstChange=null,V.chrome&&V.android?i.observer.flushSoon():i.inputState.compositionPendingChange?Promise.resolve().then(()=>i.observer.flush()):setTimeout(()=>{i.inputState.composing<0&&i.docView.hasComposition&&i.update([])},50))};He.contextmenu=i=>{i.inputState.lastContextMenu=Date.now()};qe.beforeinput=(i,e)=>{var t,n;if(e.inputType=="insertReplacementText"&&i.observer.editContext){let r=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(r&&o.length){let l=o[0],a=i.posAtDOM(l.startContainer,l.startOffset),f=i.posAtDOM(l.endContainer,l.endOffset);return Dr(i,{from:a,to:f,insert:i.state.toText(r)},null),!0}}let s;if(V.chrome&&V.android&&(s=Xa.find(r=>r.inputType==e.inputType))&&(i.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let r=((n=window.visualViewport)===null||n===void 0?void 0:n.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&i.hasFocus&&(i.contentDOM.blur(),i.focus())},100)}return V.ios&&e.inputType=="deleteContentForward"&&i.observer.flushSoon(),V.safari&&e.inputType=="insertText"&&i.inputState.composing>=0&&setTimeout(()=>He.compositionend(i,e),20),!1};const jo=new Set;function Gu(i){jo.has(i)||(jo.add(i),i.addEventListener("copy",()=>{}),i.addEventListener("cut",()=>{}))}const _o=["pre-wrap","normal","pre-line","break-spaces"];let _t=!1;function Ko(){_t=!1}class Xu{constructor(e){this.lineWrapping=e,this.doc=y.Text.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return _o.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n<e.length;n++){let s=e[n];s<0?n++:this.heightSamples[Math.floor(s*10)]||(t=!0,this.heightSamples[Math.floor(s*10)]=!0)}return t}refresh(e,t,n,s,r,o){let l=_o.indexOf(e)>-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=n,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let f=0;f<o.length;f++){let c=o[f];c<0?f++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class Qu{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Ye{constructor(e,t,n,s,r){this.from=e,this.length=t,this.top=n,this.height=s,this._content=r}get type(){return typeof this._content=="number"?Ee.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof dt?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Ye(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var X=function(i){return i[i.ByPos=0]="ByPos",i[i.ByHeight=1]="ByHeight",i[i.ByPosNoHeight=2]="ByPosNoHeight",i}(X||(X={}));const yn=.001;class Te{constructor(e,t,n=2){this.length=e,this.height=t,this.flags=n}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>yn&&(_t=!0),this.height=e)}replace(e,t,n){return Te.of(n)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,s){let r=this,o=n.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:f,fromB:c,toB:p}=s[l],g=r.lineAt(a,X.ByPosNoHeight,n.setDoc(t),0,0),v=g.to>=f?g:r.lineAt(f,X.ByPosNoHeight,n,0,0);for(p+=v.to-f,f=v.to;l>0&&g.from<=s[l-1].toA;)a=s[l-1].fromA,c=s[l-1].fromB,l--,a<g.from&&(g=r.lineAt(a,X.ByPosNoHeight,n,0,0));c+=g.from-a,a=g.from;let k=Pr.build(n.setDoc(o),e,c,p);r=Tn(r,r.replace(a,f,k))}return r.updateHeight(n,0)}static empty(){return new Be(0,0)}static of(e){if(e.length==1)return e[0];let t=0,n=e.length,s=0,r=0;for(;;)if(t==n)if(s>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),n+=1+l.break,s-=l.size}else if(r>s*2){let l=e[n];l.break?e.splice(n,1,l.left,null,l.right):e.splice(n,1,l.left,l.right),n+=2+l.break,r-=l.size}else break;else if(s<r){let l=e[t++];l&&(s+=l.size)}else{let l=e[--n];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,n++),new Zu(Te.of(e.slice(0,t)),o,Te.of(e.slice(n)))}}function Tn(i,e){return i==e?i:(i.constructor!=e.constructor&&(_t=!0),e)}Te.prototype.size=1;class rh extends Te{constructor(e,t,n){super(e,t),this.deco=n}blockAt(e,t,n,s){return new Ye(s,this.length,n,this.height,this.deco||0)}lineAt(e,t,n,s,r){return this.blockAt(0,n,s,r)}forEachLine(e,t,n,s,r,o){e<=r+this.length&&t>=r&&o(this.blockAt(0,n,s,r))}updateHeight(e,t=0,n=!1,s){return s&&s.from<=t&&s.more&&this.setHeight(s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Be extends rh{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,n,s){return new Ye(s,this.length,n,this.height,this.breaks)}replace(e,t,n){let s=n[0];return n.length==1&&(s instanceof Be||s instanceof de&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof de?s=new Be(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):Te.of(n)}updateHeight(e,t=0,n=!1,s){return s&&s.from<=t&&s.more?this.setHeight(s.heights[s.index++]):(n||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class de extends Te{constructor(e){super(e,0)}heightMetrics(e,t){let n=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-n+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:n,lastLine:s,perLine:o,perChar:l}}blockAt(e,t,n,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,s);if(t.lineWrapping){let f=s+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-n)/this.height))*this.length)),c=t.doc.lineAt(f),p=l+c.length*a,g=Math.max(n,e-p/2);return new Ye(c.from,c.length,g,p,0)}else{let f=Math.max(0,Math.min(o-r,Math.floor((e-n)/l))),{from:c,length:p}=t.doc.line(r+f);return new Ye(c,p,n+l*f,l,0)}}lineAt(e,t,n,s,r){if(t==X.ByHeight)return this.blockAt(e,n,s,r);if(t==X.ByPosNoHeight){let{from:v,to:k}=n.doc.lineAt(e);return new Ye(v,k-v,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(n,r),f=n.doc.lineAt(e),c=l+f.length*a,p=f.number-o,g=s+l*p+a*(f.from-r-p);return new Ye(f.from,f.length,Math.max(s,Math.min(g,s+this.height-c)),c,0)}forEachLine(e,t,n,s,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:f}=this.heightMetrics(n,r);for(let c=e,p=s;c<=t;){let g=n.doc.lineAt(c);if(c==e){let k=g.number-l;p+=a*k+f*(e-r-k)}let v=a+f*g.length;o(new Ye(g.from,g.length,p,v,0)),p+=v,c=g.to+1}}replace(e,t,n){let s=this.length-t;if(s>0){let r=n[n.length-1];r instanceof de?n[n.length-1]=new de(r.length+s):n.push(null,new de(s-1))}if(e>0){let r=n[0];r instanceof de?n[0]=new de(e+r.length):n.unshift(new de(e-1),null)}return Te.of(n)}decomposeLeft(e,t){t.push(new de(e-1),null)}decomposeRight(e,t){t.push(null,new de(this.length-e-1))}updateHeight(e,t=0,n=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1;for(s.from>t&&o.push(new de(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let p=s.heights[s.index++];a==-1?a=p:Math.abs(p-a)>=yn&&(a=-2);let g=new Be(c,p);g.outdated=!1,o.push(g),l+=c+1}l<=r&&o.push(null,new de(r-l).updateHeight(e,l));let f=Te.of(o);return(a<0||Math.abs(f.height-this.height)>=yn||Math.abs(a-this.heightMetrics(e,t).perLine)>=yn)&&(_t=!0),Tn(this,f)}else(n||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Zu extends Te{constructor(e,t,n){super(e.length+t+n.length,e.height+n.height,t|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return this.flags&1}blockAt(e,t,n,s){let r=n+this.left.height;return e<r?this.left.blockAt(e,t,n,s):this.right.blockAt(e,t,r,s+this.left.length+this.break)}lineAt(e,t,n,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=t==X.ByHeight?e<o:e<l,f=a?this.left.lineAt(e,t,n,s,r):this.right.lineAt(e,t,n,o,l);if(this.break||(a?f.to<l:f.from>l))return f;let c=t==X.ByPosNoHeight?X.ByPosNoHeight:X.ByPos;return a?f.join(this.right.lineAt(l,c,n,o,l)):this.left.lineAt(l,c,n,s,r).join(f)}forEachLine(e,t,n,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,n,s,r,o),t>=a&&this.right.forEachLine(e,t,n,l,a,o);else{let f=this.lineAt(a,X.ByPos,n,s,r);e<f.from&&this.left.forEachLine(e,f.from-1,n,s,r,o),f.to>=e&&f.from<=t&&o(f),t>f.to&&this.right.forEachLine(f.to+1,t,n,l,a,o)}}replace(e,t,n){let s=this.left.length+this.break;if(t<s)return this.balanced(this.left.replace(e,t,n),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,n));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of n)r.push(l);if(e>0&&Jo(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),Jo(r,l)}return Te.of(r)}decomposeLeft(e,t){let n=this.left.length;if(e<=n)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(n++,e>=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,s=n+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e<n&&this.left.decomposeRight(e,t),this.break&&e<s&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Te.of(this.break?[e,null,t]:[e,t]):(this.left=Tn(this.left,e),this.right=Tn(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,n=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,n,s):r.updateHeight(e,t,n),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,n,s):o.updateHeight(e,l,n),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Jo(i,e){let t,n;i[e]==null&&(t=i[e-1])instanceof de&&(n=i[e+1])instanceof de&&i.splice(e-1,3,new de(t.length+1+n.length))}const ed=5;class Pr{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let n=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof Be?s.length+=n-this.pos:(n>this.pos||!this.isCovered)&&this.nodes.push(new Be(n-this.pos,-1)),this.writtenTo=n,t>n&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e<t||n.heightRelevant){let s=n.widget?n.widget.estimatedHeight:0,r=n.widget?n.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=t-e;n.block?this.addBlock(new rh(o,s,n)):(o||r||s>=ed)&&this.addLineDeco(s,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Be(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let n=new de(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Be)return e;let t=new Be(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,n){let s=this.ensureLine();s.length+=n,s.collapsed+=n,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=t,this.writtenTo=this.pos=this.pos+n}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Be)&&!this.isCovered?this.nodes.push(new Be(0,-1)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let n=e;for(let s of this.nodes)s instanceof Be&&s.updateHeight(this.oracle,n),n+=s?s.length:1;return this.nodes}static build(e,t,n,s){let r=new Pr(n,e);return y.RangeSet.spans(t,n,s,r,0),r.finish(n)}}function td(i,e,t){let n=new id;return y.RangeSet.compare(i,e,t,n,0),n.changes}class id{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,n,s){(e<t||n&&n.heightRelevant||s&&s.heightRelevant)&&mn(e,t,this.changes,5)}}function nd(i,e){let t=i.getBoundingClientRect(),n=i.ownerDocument,s=n.defaultView||window,r=Math.max(0,t.left),o=Math.min(s.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(s.innerHeight,t.bottom);for(let f=i.parentNode;f&&f!=n.body;)if(f.nodeType==1){let c=f,p=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&p.overflow!="visible"){let g=c.getBoundingClientRect();r=Math.max(r,g.left),o=Math.min(o,g.right),l=Math.max(l,g.top),a=Math.min(f==i.parentNode?s.innerHeight:a,g.bottom)}f=p.position=="absolute"||p.position=="fixed"?c.offsetParent:c.parentNode}else if(f.nodeType==11)f=f.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function sd(i){let e=i.getBoundingClientRect(),t=i.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function rd(i,e){let t=i.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Ss{constructor(e,t,n,s){this.from=e,this.to=t,this.size=n,this.displaySize=s}static same(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let s=e[n],r=t[n];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(e,t){return H.replace({widget:new od(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class od extends je{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class Uo{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Yo,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Q.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(Er).some(n=>typeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new Xu(t),this.stateDeco=e.facet(wi).filter(n=>typeof n!="function"),this.heightMap=Te.empty().applyChanges(this.stateDeco,y.Text.empty,this.heightOracle.setDoc(e.doc),[new Fe(0,0,0,e.doc.length)]);for(let n=0;n<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());n++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=H.set(this.lineGaps.map(n=>n.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let n=0;n<=1;n++){let s=n?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new Qi(r,o))}}return this.viewports=e.sort((n,s)=>n.from-s.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Yo:new Rr(this.heightOracle,this.heightMap,this.viewports),e.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,e=>{this.viewportLines.push(mi(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=this.state.facet(wi).filter(c=>typeof c!="function");let s=e.changedRanges,r=Fe.extendWithRanges(s,td(n,this.stateDeco,e?e.changes:y.ChangeSet.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Ko(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||_t)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let f=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(f||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet($a)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,n=window.getComputedStyle(t),s=this.heightOracle,r=n.whiteSpace;this.defaultTextDirection=n.direction=="rtl"?Q.RTL:Q.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let f=0,c=0;if(l.width&&l.height){let{scaleX:L,scaleY:R}=pa(t,l);(L>.005&&Math.abs(this.scaleX-L)>.005||R>.005&&Math.abs(this.scaleY-R)>.005)&&(this.scaleX=L,this.scaleY=R,f|=16,o=a=!0)}let p=(parseInt(n.paddingTop)||0)*this.scaleY,g=(parseInt(n.paddingBottom)||0)*this.scaleY;(this.paddingTop!=p||this.paddingBottom!=g)&&(this.paddingTop=p,this.paddingBottom=g,f|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,f|=16);let v=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=v&&(this.scrollAnchorHeight=-1,this.scrollTop=v),this.scrolledToBottom=ya(e.scrollDOM);let k=(this.printing?rd:nd)(t,this.paddingTop),C=k.top-this.pixelViewport.top,M=k.bottom-this.pixelViewport.bottom;this.pixelViewport=k;let T=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(T!=this.inView&&(this.inView=T,T&&(a=!0)),!this.inView&&!this.scrollTarget&&!sd(e.dom))return 0;let P=l.width;if((this.contentDOMWidth!=P||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,f|=16),a){let L=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(L)&&(o=!0),o||s.lineWrapping&&Math.abs(P-this.contentDOMWidth)>s.charWidth){let{lineHeight:R,charWidth:I,textHeight:z}=e.docView.measureTextSize();o=R>0&&s.refresh(r,R,I,z,Math.max(5,P/I),L),o&&(e.docView.minWidth=0,f|=16)}C>0&&M>0?c=Math.max(C,M):C<0&&M<0&&(c=Math.min(C,M)),Ko();for(let R of this.viewports){let I=R.from==this.viewport.from?L:e.docView.measureVisibleLineHeights(R);this.heightMap=(o?Te.empty().applyChanges(this.stateDeco,y.Text.empty,this.heightOracle,[new Fe(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new Qu(R.from,I))}_t&&(f|=2)}let F=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return F&&(f&2&&(f|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),f|=this.updateForViewport()),(f&2||F)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),f|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),f}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Qi(s.lineAt(o-n*1e3,X.ByHeight,r,0,0).from,s.lineAt(l+(1-n)*1e3,X.ByHeight,r,0,0).to);if(t){let{head:f}=t.range;if(f<a.from||f>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),p=s.lineAt(f,X.ByPos,r,0,0),g;t.y=="center"?g=(p.top+p.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&f<a.from?g=p.top:g=p.bottom-c,a=new Qi(s.lineAt(g-1e3/2,X.ByHeight,r,0,0).from,s.lineAt(g+c+1e3/2,X.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let n=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new Qi(this.heightMap.lineAt(n,X.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,X.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},n=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,X.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,X.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||s<=o-Math.max(10,Math.min(-n,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(n,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let n=[];for(let s of e)t.touchesRange(s.from,s.to)||n.push(new Ss(t.mapPos(s.from),t.mapPos(s.to),s.size,s.displaySize));return n}ensureLineGaps(e,t){let n=this.heightOracle.lineWrapping,s=n?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=Q.LTR&&!n)return[];let l=[],a=(c,p,g,v)=>{if(p-c<r)return;let k=this.state.selection.main,C=[k.from];k.empty||C.push(k.to);for(let T of C)if(T>c&&T<p){a(c,T-10,g,v),a(T+10,p,g,v);return}let M=ad(e,T=>T.from>=g.from&&T.to<=g.to&&Math.abs(T.from-c)<r&&Math.abs(T.to-p)<r&&!C.some(P=>T.from<P&&T.to>P));if(!M){if(p<g.to&&t&&n&&t.visibleRanges.some(F=>F.from<=p&&F.to>=p)){let F=t.moveToLineBoundary(y.EditorSelection.cursor(p),!1,!0).head;F>c&&(p=F)}let T=this.gapSize(g,c,p,v),P=n||T<2e6?T:2e6;M=new Ss(c,p,T,P)}l.push(M)},f=c=>{if(c.length<o||c.type!=Ee.Text)return;let p=ld(c.from,c.to,this.stateDeco);if(p.total<o)return;let g=this.scrollTarget?this.scrollTarget.range.head:null,v,k;if(n){let C=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,M,T;if(g!=null){let P=en(p,g),F=((this.visibleBottom-this.visibleTop)/2+C)/c.height;M=P-F,T=P+F}else M=(this.visibleTop-c.top-C)/c.height,T=(this.visibleBottom-c.top+C)/c.height;v=Zi(p,M),k=Zi(p,T)}else{let C=p.total*this.heightOracle.charWidth,M=s*this.heightOracle.charWidth,T=0;if(C>2e6)for(let I of e)I.from>=c.from&&I.from<c.to&&I.size!=I.displaySize&&I.from*this.heightOracle.charWidth+T<this.pixelViewport.left&&(T=I.size-I.displaySize);let P=this.pixelViewport.left+T,F=this.pixelViewport.right+T,L,R;if(g!=null){let I=en(p,g),z=((F-P)/2+M)/C;L=I-z,R=I+z}else L=(P-M)/C,R=(F+M)/C;v=Zi(p,L),k=Zi(p,R)}v>c.from&&a(c.from,v,c,p),k<c.to&&a(k,c.to,c,p)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(f):f(c);return l}gapSize(e,t,n,s){let r=en(s,n)-en(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){Ss.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=H.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let n=[];y.RangeSet.spans(t,this.viewport.from,this.viewport.to,{span(r,o){n.push({from:r,to:o})},point(){}},20);let s=0;if(n.length!=this.visibleRanges.length)s=12;else for(let r=0;r<n.length&&!(s&8);r++){let o=this.visibleRanges[r],l=n[r];(o.from!=l.from||o.to!=l.to)&&(s|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(s|=8))}return this.visibleRanges=n,s}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||mi(this.heightMap.lineAt(e,X.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||mi(this.heightMap.lineAt(this.scaler.fromDOM(e),X.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return mi(this.heightMap.blockAt(this.scaler.fromDOM(e),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 Qi{constructor(e,t){this.from=e,this.to=t}}function ld(i,e,t){let n=[],s=i,r=0;return y.RangeSet.spans(t,i,e,{span(){},point(o,l){o>s&&(n.push({from:s,to:o}),r+=o-s),s=l}},20),s<e&&(n.push({from:s,to:e}),r+=e-s),{total:r,ranges:n}}function Zi({total:i,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let n=Math.floor(i*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(n<=l)return r+n;n-=l}}function en(i,e){let t=0;for(let{from:n,to:s}of i.ranges){if(e<=s){t+=e-n;break}t+=s-n}return t/i.total}function ad(i,e){for(let t of i)if(e(t))return t}const Yo={toDOM(i){return i},fromDOM(i){return i},scale:1,eq(i){return i==this}};class Rr{constructor(e,t,n){let s=0,r=0,o=0;this.viewports=n.map(({from:l,to:a})=>{let f=t.lineAt(l,X.ByPos,e,0,0).top,c=t.lineAt(a,X.ByPos,e,0,0).bottom;return s+=c-f,{from:l,to:a,top:f,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,n=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return s+(e-n)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);n=r.bottom,s=r.domBottom}}fromDOM(e){for(let t=0,n=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return n+(e-s)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);n=r.bottom,s=r.domBottom}}eq(e){return e instanceof Rr?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,n)=>t.from==e.viewports[n].from&&t.to==e.viewports[n].to):!1}}function mi(i,e){if(e.scale==1)return i;let t=e.toDOM(i.top),n=e.toDOM(i.bottom);return new Ye(i.from,i.length,t,n-t,Array.isArray(i._content)?i._content.map(s=>mi(s,e)):i._content)}const tn=y.Facet.define({combine:i=>i.join(" ")}),er=y.Facet.define({combine:i=>i.indexOf(!0)>-1}),tr=ut.newName(),oh=ut.newName(),lh=ut.newName(),ah={"&light":"."+oh,"&dark":"."+lh};function ir(i,e,t){return new ut(e,{finish(n){return/&/.test(n)?n.replace(/&\w*/,s=>{if(s=="&")return i;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):i+" "+n}})}const hd=ir("."+tr,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},ah),cd={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},vs=V.ie&&V.ie_version<=11;class fd{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Kf,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=e.contentDOM,this.observer=new MutationObserver(t=>{for(let n of t)this.queue.push(n);(V.ie&&V.ie_version<=11||V.ios&&e.composing)&&t.some(n=>n.type=="childList"&&n.removedNodes.length||n.type=="characterData"&&n.oldValue.length>n.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&V.android&&e.constructor.EDIT_CONTEXT!==!1&&!(V.chrome&&V.chrome_version<126)&&(this.editContext=new dd(e),e.state.facet(it)&&(e.contentDOM.editContext=this.editContext.editContext)),vs&&(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")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{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(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,n)=>t!=e[n]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:n}=this,s=this.selectionRange;if(n.state.facet(it)?n.root.activeElement!=this.dom:!pn(this.dom,s))return;let r=s.anchorNode&&n.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(V.ie&&V.ie_version<=11||V.android&&V.chrome)&&!n.state.selection.main.empty&&s.focusNode&&yi(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=xi(e.root);if(!t)return!1;let n=V.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&ud(this.view,t)||t;if(!n||this.selectionRange.eq(n))return!1;let s=pn(this.dom,n);return s&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Uf(this.dom,n)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(n),s&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let n=this.dom;n;)if(n.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==n?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let n of this.scrollTargets)n.removeEventListener("scroll",this.onScroll);for(let n of this.scrollTargets=t)n.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,cd),vs&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),vs&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var n;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Ft(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((n=this.delayedAndroidKey)===null||n===void 0)&&n.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,n=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:n}=o:(t=Math.min(o.from,t),n=Math.max(o.to,n)))}return{from:t,to:n,typeOver:s}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),s=this.selectionChanged&&pn(this.dom,this.selectionRange);if(e<0&&!s)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new Ou(this.view,e,t,n);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let n=this.view.state,s=Ga(this.view,t);return this.view.state==n&&(t.domChanged||t.newSel&&!t.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),s}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.flags|=4),e.type=="childList"){let n=Go(t,e.previousSibling||e.target.previousSibling,-1),s=Go(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:s?t.posBefore(s):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(it)!=e.state.facet(it)&&(e.view.contentDOM.editContext=e.state.facet(it)?this.editContext.editContext:null))}destroy(){var e,t,n;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(n=this.resizeScroll)===null||n===void 0||n.disconnect();for(let s of this.scrollTargets)s.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 Go(i,e,t){for(;e;){let n=J.get(e);if(n&&n.parent==i)return n;let s=e.parentNode;e=s!=i.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function Xo(i,e){let t=e.startContainer,n=e.startOffset,s=e.endContainer,r=e.endOffset,o=i.docView.domAtPos(i.state.selection.main.anchor);return yi(o.node,o.offset,s,r)&&([t,n,s,r]=[s,r,t,n]),{anchorNode:t,anchorOffset:n,focusNode:s,focusOffset:r}}function ud(i,e){if(e.getComposedRanges){let s=e.getComposedRanges(i.root)[0];if(s)return Xo(i,s)}let t=null;function n(s){s.preventDefault(),s.stopImmediatePropagation(),t=s.getTargetRanges()[0]}return i.contentDOM.addEventListener("beforeinput",n,!0),i.dom.ownerDocument.execCommand("indent"),i.contentDOM.removeEventListener("beforeinput",n,!0),t?Xo(i,t):null}class dd{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=n=>{let s=e.state.selection.main,{anchor:r,head:o}=s,l=this.toEditorPos(n.updateRangeStart),a=this.toEditorPos(n.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:n.updateRangeStart,editorBase:l,drifted:!1});let f={from:l,to:a,insert:y.Text.of(n.text.split(`
|
|
9
|
-
`))};if(f.from==this.from&&r<this.from?f.from=r:f.to==this.to&&r>this.to&&(f.to=r),f.from==f.to&&!f.insert.length){let c=y.EditorSelection.single(this.toEditorPos(n.selectionStart),this.toEditorPos(n.selectionEnd));c.main.eq(s)||e.dispatch({selection:c,userEvent:"select"});return}if((V.mac||V.android)&&f.from==o-1&&/^\. ?$/.test(n.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:y.Text.of([n.text.replace("."," ")])}),this.pendingContextChange=f,!e.state.readOnly){let c=this.to-this.from+(f.to-f.from+f.insert.length);Dr(e,f,y.EditorSelection.single(this.toEditorPos(n.selectionStart,c),this.toEditorPos(n.selectionEnd,c)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state))},this.handlers.characterboundsupdate=n=>{let s=[],r=null;for(let o=this.toEditorPos(n.rangeStart),l=this.toEditorPos(n.rangeEnd);o<l;o++){let a=e.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,s.push(r)}t.updateCharacterBounds(n.rangeStart,s)},this.handlers.textformatupdate=n=>{let s=[];for(let r of n.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(o!="None"&&l!="None"){let a=this.toEditorPos(r.rangeStart),f=this.toEditorPos(r.rangeEnd);if(a<f){let c=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${l=="Thin"?1:2}px`;s.push(H.mark({attributes:{style:c}}).range(a,f))}}}e.dispatch({effects:qa.of(H.set(s))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:n}=this.composing;this.composing=null,n&&this.reset(e.state)}};for(let n in this.handlers)t.addEventListener(n,this.handlers[n]);this.measureReq={read:n=>{this.editContext.updateControlBounds(n.contentDOM.getBoundingClientRect());let s=xi(n.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,n=!1,s=this.pendingContextChange;return e.changes.iterChanges((r,o,l,a,f)=>{if(n)return;let c=f.length-(o-r);if(s&&o>=s.to)if(s.from==r&&s.to==o&&s.insert.eq(f)){s=this.pendingContextChange=null,t+=c,this.to+=c;return}else s=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+f.length>3e4){n=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),f.toString()),this.to+=c}t+=c}),s&&!n&&this.revertPending(e.state),!n}update(e){let t=this.pendingContextChange,n=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(n.from,n.to)&&e.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,n=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),s=this.toContextPos(t.head);(this.editContext.selectionStart!=n||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(n,s)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let n=this.composing;return n&&n.drifted?n.editorBase+(e-n.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class N{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:n}=e;this.dispatchTransactions=e.dispatchTransactions||n&&(s=>s.forEach(r=>n(r,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Jf(e.parent)||document,this.viewState=new Uo(e.state||y.EditorState.create(e)),e.scrollTo&&e.scrollTo.is(Yi)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Bt).map(s=>new gs(s));for(let s of this.plugins)s.update(this);this.observer=new fd(this),this.inputState=new Lu(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Oo(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...e){let t=e.length==1&&e[0]instanceof y.Transaction?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,n=!1,s,r=this.state;for(let g of e){if(g.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=g.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(g=>g.annotation(ih))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=nh(r,o),a||(l=1));let f=this.observer.delayedAndroidKey,c=null;if(f?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(y.EditorState.phrases)!=this.state.facet(y.EditorState.phrases))return this.setState(r);s=En.create(this,r,e),s.flags|=l;let p=this.viewState.scrollTarget;try{this.updateState=2;for(let g of e){if(p&&(p=p.map(g.changes)),g.scrollIntoView){let{main:v}=g.state.selection;p=new Vt(v.empty?v:y.EditorSelection.cursor(v.head,v.head>v.anchor?-1:1))}for(let v of g.effects)v.is(Yi)&&(p=v.value.clip(this.state))}this.viewState.update(s,p),this.bidiCache=On.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(di)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(g=>g.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(tn)!=s.state.facet(tn)&&(this.viewState.mustMeasureContent=!0),(t||n||p||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!s.empty)for(let g of this.state.facet(Gs))try{g(s)}catch(v){Me(this.state,v,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!Ga(this,c)&&f.force&&Ft(this.contentDOM,f.key,f.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let n of this.plugins)n.destroy(this);this.viewState=new Uo(e),this.plugins=e.facet(Bt).map(n=>new gs(n)),this.pluginMap.clear();for(let n of this.plugins)n.update(this);this.docView.destroy(),this.docView=new Oo(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Bt),n=e.state.facet(Bt);if(t!=n){let s=[];for(let r of n){let o=t.indexOf(r);if(o<0)s.push(new gs(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);t!=n&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(n){Me(this.state,n,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,n=this.scrollDOM,s=n.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(ya(n))r=-1,o=this.viewState.heightMap.height;else{let v=this.viewState.scrollAnchorAt(s);r=v.from,o=v.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let f=[];a&4||([this.measureRequests,f]=[f,this.measureRequests]);let c=f.map(v=>{try{return v.read(this)}catch(k){return Me(this.state,k),Qo}}),p=En.create(this,this.state,[]),g=!1;p.flags|=a,t?t.flags|=a:t=p,this.updateState=2,p.empty||(this.updatePlugins(p),this.inputState.update(p),this.updateAttrs(),g=this.docView.update(p),g&&this.docViewUpdate());for(let v=0;v<f.length;v++)if(c[v]!=Qo)try{let k=f[v];k.write&&k.write(c[v],this)}catch(k){Me(this.state,k)}if(g&&this.docView.updateSelection(!0),!p.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let k=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o;if(k>1||k<-1){s=s+k,n.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(Gs))l(t)}get themeClasses(){return tr+" "+(this.state.facet(er)?lh:oh)+" "+this.state.facet(tn)}updateAttrs(){let e=Zo(this,ja,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(it)?"true":"false",class:"cm-content",style:`${V.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Zo(this,Er,t);let n=this.observer.ignore(()=>{let s=_s(this.contentDOM,this.contentAttrs,t),r=_s(this.dom,this.editorAttrs,e);return s||r});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(e){let t=!0;for(let n of e)for(let s of n.effects)if(s.is(N.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(di);let e=this.state.facet(N.cspNonce);ut.mount(this.root,this.styleModules.concat(hd).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(n=>n.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,n){return bs(this,e,Lo(this,e,t,n))}moveByGroup(e,t){return bs(this,e,Lo(this,e,t,n=>Au(this,e.head,n)))}visualLineSide(e,t){let n=this.bidiSpans(e),s=this.textDirectionAt(e.from),r=n[t?n.length-1:0];return y.EditorSelection.cursor(r.side(t,s)+e.from,r.forward(!t,s)?1:-1)}moveToLineBoundary(e,t,n=!0){return Cu(this,e,t,n)}moveVertically(e,t,n){return bs(this,e,Mu(this,e,t,n))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),Ya(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.docView.coordsAt(e,t);if(!n||n.left==n.right)return n;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[ht.find(r,e-s.from,-1,t)];return Li(n,o.dir==Q.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(Wa)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>pd)return Ra(e.length);let t=this.textDirectionAt(e.from),n;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Pa(r.isolates,n=To(this,e))))return r.order;n||(n=To(this,e));let s=au(e.text,t,n);return this.bidiCache.push(new On(e.from,e.to,t,n,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||V.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{ma(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return Yi.of(new Vt(typeof e=="number"?y.EditorSelection.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,n=this.viewState.scrollAnchorAt(e);return Yi.of(new Vt(y.EditorSelection.cursor(n.from),"start","start",n.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return se.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return se.define(()=>({}),{eventObservers:e})}static theme(e,t){let n=ut.newName(),s=[tn.of(n),di.of(ir(`.${n}`,e))];return t&&t.dark&&s.push(er.of(!0)),s}static baseTheme(e){return y.Prec.lowest(di.of(ir("."+tr,e,ah)))}static findFromDOM(e){var t;let n=e.querySelector(".cm-content"),s=n&&J.get(n)||J.get(e);return((t=s==null?void 0:s.rootView)===null||t===void 0?void 0:t.view)||null}}N.styleModule=di;N.inputHandler=Va;N.clipboardInputFilter=Ar;N.clipboardOutputFilter=Mr;N.scrollHandler=za;N.focusChangeEffect=Ha;N.perLineTextDirection=Wa;N.exceptionSink=Fa;N.updateListener=Gs;N.editable=it;N.mouseSelectionStyle=Na;N.dragMovesSelection=Ia;N.clickAddsSelectionRange=La;N.decorations=wi;N.outerDecorations=_a;N.atomicRanges=Tr;N.bidiIsolatedRanges=Ka;N.scrollMargins=Ja;N.darkTheme=er;N.cspNonce=y.Facet.define({combine:i=>i.length?i[0]:""});N.contentAttributes=Er;N.editorAttributes=ja;N.lineWrapping=N.contentAttributes.of({class:"cm-lineWrapping"});N.announce=y.StateEffect.define();const pd=4096,Qo={};class On{constructor(e,t,n,s,r,o){this.from=e,this.to=t,this.dir=n,this.isolates=s,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let n=[],s=e.length?e[e.length-1].dir:Q.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==s&&!t.touchesRange(o.from,o.to)&&n.push(new On(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return n}}function Zo(i,e,t){for(let n=i.state.facet(e),s=n.length-1;s>=0;s--){let r=n[s],o=typeof r=="function"?r(i):r;o&&js(o,t)}return t}const md=V.mac?"mac":V.windows?"win":V.linux?"linux":"key";function gd(i,e){const t=i.split(/-(?!$)/);let n=t[t.length-1];n=="Space"&&(n=" ");let s,r,o,l;for(let a=0;a<t.length-1;++a){const f=t[a];if(/^(cmd|meta|m)$/i.test(f))l=!0;else if(/^a(lt)?$/i.test(f))s=!0;else if(/^(c|ctrl|control)$/i.test(f))r=!0;else if(/^s(hift)?$/i.test(f))o=!0;else if(/^mod$/i.test(f))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+f)}return s&&(n="Alt-"+n),r&&(n="Ctrl-"+n),l&&(n="Meta-"+n),o&&(n="Shift-"+n),n}function nn(i,e,t){return e.altKey&&(i="Alt-"+i),e.ctrlKey&&(i="Ctrl-"+i),e.metaKey&&(i="Meta-"+i),t!==!1&&e.shiftKey&&(i="Shift-"+i),i}const yd=y.Prec.default(N.domEventHandlers({keydown(i,e){return ch(hh(e.state),i,e,"editor")}})),Gt=y.Facet.define({enables:yd}),el=new WeakMap;function hh(i){let e=i.facet(Gt),t=el.get(e);return t||el.set(e,t=vd(e.reduce((n,s)=>n.concat(s),[]))),t}function bd(i,e,t){return ch(hh(i.state),e,i,t)}let lt=null;const Sd=4e3;function vd(i,e=md){let t=Object.create(null),n=Object.create(null),s=(o,l)=>{let a=n[o];if(a==null)n[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,f,c)=>{var p,g;let v=t[o]||(t[o]=Object.create(null)),k=l.split(/ (?!$)/).map(T=>gd(T,e));for(let T=1;T<k.length;T++){let P=k.slice(0,T).join(" ");s(P,!0),v[P]||(v[P]={preventDefault:!0,stopPropagation:!1,run:[F=>{let L=lt={view:F,prefix:P,scope:o};return setTimeout(()=>{lt==L&&(lt=null)},Sd),!0}]})}let C=k.join(" ");s(C,!1);let M=v[C]||(v[C]={preventDefault:!1,stopPropagation:!1,run:((g=(p=v._any)===null||p===void 0?void 0:p.run)===null||g===void 0?void 0:g.slice())||[]});a&&M.run.push(a),f&&(M.preventDefault=!0),c&&(M.stopPropagation=!0)};for(let o of i){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let f of l){let c=t[f]||(t[f]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:p}=o;for(let g in c)c[g].run.push(v=>p(v,nr))}let a=o[e]||o.key;if(a)for(let f of l)r(f,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(f,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let nr=null;function ch(i,e,t,n){nr=e;let s=Cf(e),r=y.codePointAt(s,0),o=y.codePointSize(r)==s.length&&s!=" ",l="",a=!1,f=!1,c=!1;lt&<.view==t&<.scope==n&&(l=lt.prefix+" ",Qa.indexOf(e.keyCode)<0&&(f=!0,lt=null));let p=new Set,g=M=>{if(M){for(let T of M.run)if(!p.has(T)&&(p.add(T),T(t)))return M.stopPropagation&&(c=!0),!0;M.preventDefault&&(M.stopPropagation&&(c=!0),f=!0)}return!1},v=i[n],k,C;return v&&(g(v[l+nn(s,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(V.windows&&e.ctrlKey&&e.altKey)&&!(V.mac&&e.altKey&&!e.ctrlKey)&&(k=Af[e.keyCode])&&k!=s?(g(v[l+nn(k,e,!0)])||e.shiftKey&&(C=Mf[e.keyCode])!=s&&C!=k&&g(v[l+nn(C,e,!1)]))&&(a=!0):o&&e.shiftKey&&g(v[l+nn(s,e,!0)])&&(a=!0),!a&&g(v._any)&&(a=!0)),f&&(a=!0),a&&c&&e.stopPropagation(),nr=null,a}class Fi{constructor(e,t,n,s,r){this.className=e,this.left=t,this.top=n,this.width=s,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,n){if(n.empty){let s=e.coordsAtPos(n.head,n.assoc||1);if(!s)return[];let r=fh(e);return[new Fi(t,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return xd(e,t,n)}}function fh(i){let e=i.scrollDOM.getBoundingClientRect();return{left:(i.textDirection==Q.LTR?e.left:e.right-i.scrollDOM.clientWidth*i.scaleX)-i.scrollDOM.scrollLeft*i.scaleX,top:e.top-i.scrollDOM.scrollTop*i.scaleY}}function tl(i,e,t,n){let s=i.coordsAtPos(e,t*2);if(!s)return n;let r=i.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=i.posAtCoords({x:r.left+1,y:o}),a=i.posAtCoords({x:r.right-1,y:o});return l==null||a==null?n:{from:Math.max(n.from,Math.min(l,a)),to:Math.min(n.to,Math.max(l,a))}}function xd(i,e,t){if(t.to<=i.viewport.from||t.from>=i.viewport.to)return[];let n=Math.max(t.from,i.viewport.from),s=Math.min(t.to,i.viewport.to),r=i.textDirection==Q.LTR,o=i.contentDOM,l=o.getBoundingClientRect(),a=fh(i),f=o.querySelector(".cm-line"),c=f&&window.getComputedStyle(f),p=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),g=l.right-(c?parseInt(c.paddingRight):0),v=Qs(i,n,1),k=Qs(i,s,-1),C=v.type==Ee.Text?v:null,M=k.type==Ee.Text?k:null;if(C&&(i.lineWrapping||v.widgetLineBreaks)&&(C=tl(i,n,1,C)),M&&(i.lineWrapping||k.widgetLineBreaks)&&(M=tl(i,s,-1,M)),C&&M&&C.from==M.from&&C.to==M.to)return P(F(t.from,t.to,C));{let R=C?F(t.from,null,C):L(v,!1),I=M?F(null,t.to,M):L(k,!0),z=[];return(C||v).to<(M||k).from-(C&&M?1:0)||v.widgetLineBreaks>1&&R.bottom+i.defaultLineHeight/2<I.top?z.push(T(p,R.bottom,g,I.top)):R.bottom<I.top&&i.elementAtHeight((R.bottom+I.top)/2).type==Ee.Text&&(R.bottom=I.top=(R.bottom+I.top)/2),P(R).concat(z).concat(P(I))}function T(R,I,z,U){return new Fi(e,R-a.left,I-a.top,z-R,U-I)}function P({top:R,bottom:I,horizontal:z}){let U=[];for(let _=0;_<z.length;_+=2)U.push(T(z[_],R,z[_+1],I));return U}function F(R,I,z){let U=1e9,_=-1e9,me=[];function Ce(ue,ge,G,ye,be){let ie=i.coordsAtPos(ue,ue==z.to?-2:2),re=i.coordsAtPos(G,G==z.from?2:-2);!ie||!re||(U=Math.min(ie.top,re.top,U),_=Math.max(ie.bottom,re.bottom,_),be==Q.LTR?me.push(r&&ge?p:ie.left,r&&ye?g:re.right):me.push(!r&&ye?p:re.left,!r&&ge?g:ie.right))}let he=R??z.from,q=I??z.to;for(let ue of i.visibleRanges)if(ue.to>he&&ue.from<q)for(let ge=Math.max(ue.from,he),G=Math.min(ue.to,q);;){let ye=i.state.doc.lineAt(ge);for(let be of i.bidiSpans(ye)){let ie=be.from+ye.from,re=be.to+ye.from;if(ie>=G)break;re>ge&&Ce(Math.max(ie,ge),R==null&&ie<=he,Math.min(re,G),I==null&&re>=q,be.dir)}if(ge=ye.to+1,ge>=G)break}return me.length==0&&Ce(he,R==null,q,I==null,i.textDirection),{top:U,bottom:_,horizontal:me}}function L(R,I){let z=l.top+(I?R.top:R.bottom);return{top:z,bottom:z,horizontal:[]}}}function wd(i,e){return i.constructor==e.constructor&&i.eq(e)}class kd{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(bn)!=e.state.facet(bn)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,n=e.facet(bn);for(;t<n.length&&n[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,n)=>!wd(t,this.drawn[n]))){let t=this.dom.firstChild,n=0;for(let s of e)s.update&&t&&s.constructor&&this.drawn[n].constructor&&s.update(t,this.drawn[n])?(t=t.nextSibling,n++):this.dom.insertBefore(s.draw(),t);for(;t;){let s=t.nextSibling;t.remove(),t=s}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const bn=y.Facet.define();function uh(i){return[se.define(e=>new kd(e,i)),bn.of(i)]}const ki=y.Facet.define({combine(i){return y.combineConfig(i,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function Cd(i={}){return[ki.of(i),Ad,Md,Ed,$a.of(!0)]}function dh(i){return i.startState.facet(ki)!=i.state.facet(ki)}const Ad=uh({above:!0,markers(i){let{state:e}=i,t=e.facet(ki),n=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty||t.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:y.EditorSelection.cursor(s.head,s.head>s.anchor?-1:1);for(let a of Fi.forRange(i,o,l))n.push(a)}}return n},update(i,e){i.transactions.some(n=>n.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=dh(i);return t&&il(i.state,e),i.docChanged||i.selectionSet||t},mount(i,e){il(e.state,i)},class:"cm-cursorLayer"});function il(i,e){e.style.animationDuration=i.facet(ki).cursorBlinkRate+"ms"}const Md=uh({above:!1,markers(i){return i.state.selection.ranges.map(e=>e.empty?[]:Fi.forRange(i,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(i,e){return i.docChanged||i.selectionSet||i.viewportChanged||dh(i)},class:"cm-selectionLayer"}),Ed=y.Prec.highest(N.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"}}}})),ph=y.StateEffect.define({map(i,e){return i==null?null:e.mapPos(i)}}),gi=y.StateField.define({create(){return null},update(i,e){return i!=null&&(i=e.changes.mapPos(i)),e.effects.reduce((t,n)=>n.is(ph)?n.value:t,i)}}),Td=se.fromClass(class{constructor(i){this.view=i,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(i){var e;let t=i.state.field(gi);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(i.startState.field(gi)!=t||i.docChanged||i.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:i}=this,e=i.state.field(gi),t=e!=null&&i.coordsAtPos(e);if(!t)return null;let n=i.scrollDOM.getBoundingClientRect();return{left:t.left-n.left+i.scrollDOM.scrollLeft*i.scaleX,top:t.top-n.top+i.scrollDOM.scrollTop*i.scaleY,height:t.bottom-t.top}}drawCursor(i){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;i?(this.cursor.style.left=i.left/e+"px",this.cursor.style.top=i.top/t+"px",this.cursor.style.height=i.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(i){this.view.state.field(gi)!=i&&this.view.dispatch({effects:ph.of(i)})}},{eventObservers:{dragover(i){this.setDropPos(this.view.posAtCoords({x:i.clientX,y:i.clientY}))},dragleave(i){(i.target==this.view.contentDOM||!this.view.contentDOM.contains(i.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Od(){return[gi,Td]}function nl(i,e,t,n,s){e.lastIndex=0;for(let r=i.iterRange(t,n),o=t,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=e.exec(r.value);)s(o+l.index,l)}function Dd(i,e){let t=i.visibleRanges;if(t.length==1&&t[0].from==i.viewport.from&&t[0].to==i.viewport.to)return t;let n=[];for(let{from:s,to:r}of t)s=Math.max(i.state.doc.lineAt(s).from,s-e),r=Math.min(i.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}class Pd{constructor(e){const{regexp:t,decoration:n,decorate:s,boundary:r,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,s)this.addMatch=(l,a,f,c)=>s(c,f,f+l[0].length,l,a);else if(typeof n=="function")this.addMatch=(l,a,f,c)=>{let p=n(l,a,f);p&&c(f,f+l[0].length,p)};else if(n)this.addMatch=(l,a,f,c)=>c(f,f+l[0].length,n);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new y.RangeSetBuilder,n=t.add.bind(t);for(let{from:s,to:r}of Dd(e,this.maxLength))nl(e.state.doc,this.regexp,s,r,(o,l)=>this.addMatch(l,e,o,n));return t.finish()}updateDeco(e,t){let n=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>=e.view.viewport.from&&l<=e.view.viewport.to&&(n=Math.min(l,n),s=Math.max(a,s))}),e.viewportMoved||s-n>1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,t.map(e.changes),n,s):t}updateRange(e,t,n,s){for(let r of e.visibleRanges){let o=Math.max(r.from,n),l=Math.min(r.to,s);if(l>=o){let a=e.state.doc.lineAt(o),f=a.to<l?e.state.doc.lineAt(l):a,c=Math.max(r.from,a.from),p=Math.min(r.to,f.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){c=o;break}for(;l<f.to;l++)if(this.boundary.test(f.text[l-f.from])){p=l;break}}let g=[],v,k=(C,M,T)=>g.push(T.range(C,M));if(a==f)for(this.regexp.lastIndex=c-a.from;(v=this.regexp.exec(a.text))&&v.index<p-a.from;)this.addMatch(v,e,v.index+a.from,k);else nl(e.state.doc,this.regexp,c,p,(C,M)=>this.addMatch(M,e,C,k));t=t.update({filterFrom:c,filterTo:p,filter:(C,M)=>C<c||M>p,add:g})}}return t}}const sr=/x/.unicode!=null?"gu":"g",Rd=new RegExp(`[\0-\b
|
|
10
|
-
--\u2028\u2029\uFEFF-]`,sr),Bd={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 xs=null;function Ld(){var i;if(xs==null&&typeof document<"u"&&document.body){let e=document.body.style;xs=((i=e.tabSize)!==null&&i!==void 0?i:e.MozTabSize)!=null}return xs||!1}const Sn=y.Facet.define({combine(i){let e=y.combineConfig(i,{render:null,specialChars:Rd,addSpecialChars:null});return(e.replaceTabs=!Ld())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,sr)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,sr)),e}});function Id(i={}){return[Sn.of(i),Nd()]}let sl=null;function Nd(){return sl||(sl=se.fromClass(class{constructor(i){this.view=i,this.decorations=H.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(i.state.facet(Sn)),this.decorations=this.decorator.createDeco(i)}makeDecorator(i){return new Pd({regexp:i.specialChars,decoration:(e,t,n)=>{let{doc:s}=t.state,r=y.codePointAt(e[0],0);if(r==9){let o=s.lineAt(n),l=t.state.tabSize,a=y.countColumn(o.text,l,n-o.from);return H.replace({widget:new Wd((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=H.replace({widget:new Hd(i,r)}))},boundary:i.replaceTabs?void 0:/[^]/})}update(i){let e=i.state.facet(Sn);i.startState.facet(Sn)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(i.view)):this.decorations=this.decorator.updateDeco(i,this.decorations)}},{decorations:i=>i.decorations}))}const Fd="•";function Vd(i){return i>=32?Fd:i==10?"":String.fromCharCode(9216+i)}class Hd extends je{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=Vd(this.code),n=e.state.phrase("Control character")+" "+(Bd[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,n,t);if(s)return s;let r=document.createElement("span");return r.textContent=t,r.title=n,r.setAttribute("aria-label",n),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Wd extends je{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function $d(){return qd}const zd=H.line({class:"cm-activeLine"}),qd=se.fromClass(class{constructor(i){this.decorations=this.getDeco(i)}update(i){(i.docChanged||i.selectionSet)&&(this.decorations=this.getDeco(i.view))}getDeco(i){let e=-1,t=[];for(let n of i.state.selection.ranges){let s=i.lineBlockAt(n.head);s.from>e&&(t.push(zd.range(s.from)),e=s.from)}return H.set(t)}},{decorations:i=>i.decorations});class jd extends je{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),t.setAttribute("aria-hidden","true"),t}coordsAt(e){let t=e.firstChild?zt(e.firstChild):[];if(!t.length)return null;let n=window.getComputedStyle(e.parentNode),s=Li(t[0],n.direction!="rtl"),r=parseInt(n.lineHeight);return s.bottom-s.top>r*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function _d(i){let e=se.fromClass(class{constructor(t){this.view=t,this.placeholder=i?H.set([H.widget({widget:new jd(i),side:1}).range(0)]):H.none}get decorations(){return this.view.state.doc.length?H.none:this.placeholder}},{decorations:t=>t.decorations});return typeof i=="string"?[e,N.contentAttributes.of({"aria-placeholder":i})]:e}const rr=2e3;function Kd(i,e,t){let n=Math.min(e.line,t.line),s=Math.max(e.line,t.line),r=[];if(e.off>rr||t.off>rr||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=n;a<=s;a++){let f=i.doc.line(a);f.length<=l&&r.push(y.EditorSelection.range(f.from+o,f.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=n;a<=s;a++){let f=i.doc.line(a),c=y.findColumn(f.text,o,i.tabSize,!0);if(c<0)r.push(y.EditorSelection.cursor(f.to));else{let p=y.findColumn(f.text,l,i.tabSize);r.push(y.EditorSelection.range(f.from+c,f.from+p))}}}return r}function Jd(i,e){let t=i.coordsAtPos(i.viewport.from);return t?Math.round(Math.abs((t.left-e)/i.defaultCharacterWidth)):-1}function rl(i,e){let t=i.posAtCoords({x:e.clientX,y:e.clientY},!1),n=i.state.doc.lineAt(t),s=t-n.from,r=s>rr?-1:s==n.length?Jd(i,e.clientX):y.countColumn(n.text,i.state.tabSize,t-n.from);return{line:n.number,col:r,off:s}}function Ud(i,e){let t=rl(i,e),n=i.state.selection;return t?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(t.line).from),o=s.state.doc.lineAt(r);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},n=n.map(s.changes)}},get(s,r,o){let l=rl(i,s);if(!l)return n;let a=Kd(i.state,t,l);return a.length?o?y.EditorSelection.create(a.concat(n.ranges)):y.EditorSelection.create(a):n}}:null}function Yd(i){let e=t=>t.altKey&&t.button==0;return N.mouseSelectionStyle.of((t,n)=>e(n)?Ud(t,n):null)}const Gd={Alt:[18,i=>!!i.altKey],Control:[17,i=>!!i.ctrlKey],Shift:[16,i=>!!i.shiftKey],Meta:[91,i=>!!i.metaKey]},Xd={style:"cursor: crosshair"};function Qd(i={}){let[e,t]=Gd[i.key||"Alt"],n=se.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventObservers:{keydown(s){this.set(s.keyCode==e||t(s))},keyup(s){(s.keyCode==e||!t(s))&&this.set(!1)},mousemove(s){this.set(t(s))}}});return[n,N.contentAttributes.of(s=>{var r;return!((r=s.plugin(n))===null||r===void 0)&&r.isDown?Xd:null})]}const hi="-10000px";class mh{constructor(e,t,n,s){this.facet=t,this.createTooltipView=n,this.removeTooltipView=s,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=n(o,r))}update(e,t){var n;let s=e.state.facet(this.facet),r=s.filter(a=>a);if(s===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<r.length;a++){let f=r[a],c=-1;if(f){for(let p=0;p<this.tooltips.length;p++){let g=this.tooltips[p];g&&g.create==f.create&&(c=p)}if(c<0)o[a]=this.createTooltipView(f,a?o[a-1]:null),l&&(l[a]=!!f.above);else{let p=o[a]=this.tooltipViews[c];l&&(l[a]=t[c]),p.update&&p.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(n=a.destroy)===null||n===void 0||n.call(a));return t&&(l.forEach((a,f)=>t[f]=a),t.length=l.length),this.input=s,this.tooltips=r,this.tooltipViews=o,!0}}function Zd(i){let e=i.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const ws=y.Facet.define({combine:i=>{var e,t,n;return{position:V.ios?"absolute":((e=i.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=i.find(s=>s.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((n=i.find(s=>s.tooltipSpace))===null||n===void 0?void 0:n.tooltipSpace)||Zd}}}),ol=new WeakMap,Br=se.fromClass(class{constructor(i){this.view=i,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=i.state.facet(ws);this.position=e.position,this.parent=e.parent,this.classes=i.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new mh(i,Lr,(t,n)=>this.createTooltip(t,n),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),i.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 i of this.manager.tooltipViews)this.intersectionObserver.observe(i.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(i){i.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(i,this.above);e&&this.observeIntersection();let t=e||i.geometryChanged,n=i.state.facet(ws);if(n.position!=this.position&&!this.madeAbsolute){this.position=n.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;t=!0}if(n.parent!=this.parent){this.parent&&this.container.remove(),this.parent=n.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(i,e){let t=i.create(this.view),n=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),i.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",t.dom.appendChild(s)}return t.dom.style.position=this.position,t.dom.style.top=hi,t.dom.style.left="0px",this.container.insertBefore(t.dom,n),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var i,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let n of this.manager.tooltipViews)n.dom.remove(),(i=n.destroy)===null||i===void 0||i.call(n);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let i=1,e=1,t=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:r}=this.manager.tooltipViews[0];if(V.gecko)t=r.offsetParent!=this.container.ownerDocument.body;else if(r.style.top==hi&&r.style.left=="0px"){let o=r.getBoundingClientRect();t=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}}if(t||this.position=="absolute")if(this.parent){let r=this.parent.getBoundingClientRect();r.width&&r.height&&(i=r.width/this.parent.offsetWidth,e=r.height/this.parent.offsetHeight)}else({scaleX:i,scaleY:e}=this.view.viewState);let n=this.view.scrollDOM.getBoundingClientRect(),s=Or(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((r,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(r.pos):this.view.coordsAtPos(r.pos)}),size:this.manager.tooltipViews.map(({dom:r})=>r.getBoundingClientRect()),space:this.view.state.facet(ws).tooltipSpace(this.view),scaleX:i,scaleY:e,makeAbsolute:t}}writeMeasure(i){var e;if(i.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:n,scaleX:s,scaleY:r}=i,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],f=this.manager.tooltipViews[l],{dom:c}=f,p=i.pos[l],g=i.size[l];if(!p||a.clip!==!1&&(p.bottom<=Math.max(t.top,n.top)||p.top>=Math.min(t.bottom,n.bottom)||p.right<Math.max(t.left,n.left)-.1||p.left>Math.min(t.right,n.right)+.1)){c.style.top=hi;continue}let v=a.arrow?f.dom.querySelector(".cm-tooltip-arrow"):null,k=v?7:0,C=g.right-g.left,M=(e=ol.get(f))!==null&&e!==void 0?e:g.bottom-g.top,T=f.offset||tp,P=this.view.textDirection==Q.LTR,F=g.width>n.right-n.left?P?n.left:n.right-g.width:P?Math.max(n.left,Math.min(p.left-(v?14:0)+T.x,n.right-C)):Math.min(Math.max(n.left,p.left-C+(v?14:0)-T.x),n.right-C),L=this.above[l];!a.strictSide&&(L?p.top-M-k-T.y<n.top:p.bottom+M+k+T.y>n.bottom)&&L==n.bottom-p.bottom>p.top-n.top&&(L=this.above[l]=!L);let R=(L?p.top-n.top:n.bottom-p.bottom)-k;if(R<M&&f.resize!==!1){if(R<this.view.defaultLineHeight){c.style.top=hi;continue}ol.set(f,M),c.style.height=(M=R)/r+"px"}else c.style.height&&(c.style.height="");let I=L?p.top-M-k-T.y:p.bottom+k+T.y,z=F+C;if(f.overlap!==!0)for(let U of o)U.left<z&&U.right>F&&U.top<I+M&&U.bottom>I&&(I=L?U.top-M-2-k:U.bottom+k+2);if(this.position=="absolute"?(c.style.top=(I-i.parent.top)/r+"px",ll(c,(F-i.parent.left)/s)):(c.style.top=I/r+"px",ll(c,F/s)),v){let U=p.left+(P?T.x:-T.x)-(F+14-7);v.style.left=U/s+"px"}f.overlap!==!0&&o.push({left:F,top:I,right:z,bottom:I+M}),c.classList.toggle("cm-tooltip-above",L),c.classList.toggle("cm-tooltip-below",!L),f.positioned&&f.positioned(i.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 i of this.manager.tooltipViews)i.dom.style.top=hi}},{eventObservers:{scroll(){this.maybeMeasure()}}});function ll(i,e){let t=parseInt(i.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(i.style.left=e+"px")}const ep=N.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"}}}),tp={x:0,y:0},Lr=y.Facet.define({enables:[Br,ep]}),Dn=y.Facet.define({combine:i=>i.reduce((e,t)=>e.concat(t),[])});class Jn{static create(e){return new Jn(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new mh(e,Dn,(t,n)=>this.createHostedView(t,n),t=>t.dom.remove())}createHostedView(e,t){let n=e.create(this.view);return n.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(n.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&n.mount&&n.mount(this.view),n}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let n of this.manager.tooltipViews){let s=n[e];if(s!==void 0){if(t===void 0)t=s;else if(t!==s)return}}return t}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 ip=Lr.compute([Dn],i=>{let e=i.facet(Dn);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var n;return(n=t.end)!==null&&n!==void 0?n:t.pos})),create:Jn.create,above:e[0].above,arrow:e.some(t=>t.arrow)}});class np{constructor(e,t,n,s,r){this.view=e,this.source=t,this.field=n,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,n=e.docView.nearest(t.target);if(!n)return;let s,r=1;if(n instanceof at)s=n.posAtStart;else{if(s=e.posAtCoords(t),s==null)return;let l=e.coordsAtPos(s);if(!l||t.y<l.top||t.y>l.bottom||t.x<l.left-e.defaultCharacterWidth||t.x>l.right+e.defaultCharacterWidth)return;let a=e.bidiSpans(e.state.doc.lineAt(s)).find(c=>c.from<=s&&c.to>=s),f=a&&a.dir==Q.RTL?-1:1;r=t.x<l.left?-f:f}let o=this.source(e,s,r);if(o!=null&&o.then){let l=this.pending={pos:s};o.then(a=>{this.pending==l&&(this.pending=null,a&&!(Array.isArray(a)&&!a.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(a)?a:[a])}))},a=>Me(e.state,a,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let e=this.view.plugin(Br),t=e?e.manager.tooltips.findIndex(n=>n.create==Jn.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,n;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:r}=this;if(s.length&&r&&!sp(r.dom,e)||this.pending){let{pos:o}=s[0]||this.pending,l=(n=(t=s[0])===null||t===void 0?void 0:t.end)!==null&&n!==void 0?n:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!rp(this.view,o,l,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length){let{tooltip:n}=this;n&&n.dom.contains(e.relatedTarget)?this.watchTooltipLeave(n.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=n=>{e.removeEventListener("mouseleave",t),this.active.length&&!this.view.dom.contains(n.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const sn=4;function sp(i,e){let{left:t,right:n,top:s,bottom:r}=i.getBoundingClientRect(),o;if(o=i.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();s=Math.min(l.top,s),r=Math.max(l.bottom,r)}return e.clientX>=t-sn&&e.clientX<=n+sn&&e.clientY>=s-sn&&e.clientY<=r+sn}function rp(i,e,t,n,s,r){let o=i.scrollDOM.getBoundingClientRect(),l=i.documentTop+i.documentPadding.top+i.contentHeight;if(o.left>n||o.right<n||o.top>s||Math.min(o.bottom,l)<s)return!1;let a=i.posAtCoords({x:n,y:s},!1);return a>=e&&a<=t}function op(i,e={}){let t=y.StateEffect.define(),n=y.StateField.define({create(){return[]},update(s,r){if(s.length&&(e.hideOnChange&&(r.docChanged||r.selection)?s=[]:e.hideOn&&(s=s.filter(o=>!e.hideOn(r,o))),r.docChanged)){let o=[];for(let l of s){let a=r.changes.mapPos(l.pos,-1,y.MapMode.TrackDel);if(a!=null){let f=Object.assign(Object.create(null),l);f.pos=a,f.end!=null&&(f.end=r.changes.mapPos(f.end)),o.push(f)}}s=o}for(let o of r.effects)o.is(t)&&(s=o.value),o.is(lp)&&(s=[]);return s},provide:s=>Dn.from(s)});return{active:n,extension:[n,se.define(s=>new np(s,i,n,t,e.hoverTime||300)),ip]}}function gh(i,e){let t=i.plugin(Br);if(!t)return null;let n=t.manager.tooltips.indexOf(e);return n<0?null:t.manager.tooltipViews[n]}const lp=y.StateEffect.define(),al=y.Facet.define({combine(i){let e,t;for(let n of i)e=e||n.topContainer,t=t||n.bottomContainer;return{topContainer:e,bottomContainer:t}}});function Ci(i,e){let t=i.plugin(yh),n=t?t.specs.indexOf(e):-1;return n>-1?t.panels[n]:null}const yh=se.fromClass(class{constructor(i){this.input=i.state.facet(Ai),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(i));let e=i.state.facet(al);this.top=new rn(i,!0,e.topContainer),this.bottom=new rn(i,!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(i){let e=i.state.facet(al);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new rn(i.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new rn(i.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=i.state.facet(Ai);if(t!=this.input){let n=t.filter(a=>a),s=[],r=[],o=[],l=[];for(let a of n){let f=this.specs.indexOf(a),c;f<0?(c=a(i.view),l.push(c)):(c=this.panels[f],c.update&&c.update(i)),s.push(c),(c.top?r:o).push(c)}this.specs=n,this.panels=s,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let n of this.panels)n.update&&n.update(i)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:i=>N.scrollMargins.of(e=>{let t=e.plugin(i);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class rn{constructor(e,t,n){this.view=e,this.top=t,this.container=n,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",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 e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=hl(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=hl(e)}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 e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function hl(i){let e=i.nextSibling;return i.remove(),e}const Ai=y.Facet.define({enables:yh});class rt extends y.RangeValue{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}rt.prototype.elementClass="";rt.prototype.toDOM=void 0;rt.prototype.mapMode=y.MapMode.TrackBefore;rt.prototype.startSide=rt.prototype.endSide=-1;rt.prototype.point=!0;const vn=y.Facet.define(),ap=y.Facet.define(),hp={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>y.RangeSet.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Si=y.Facet.define();function cp(i){return[bh(),Si.of({...hp,...i})]}const cl=y.Facet.define({combine:i=>i.some(e=>e)});function bh(i){return[fp]}const fp=se.fromClass(class{constructor(i){this.view=i,this.domAfter=null,this.prevViewport=i.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=i.state.facet(Si).map(e=>new ul(i,e)),this.fixed=!i.state.facet(cl);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),i.scrollDOM.insertBefore(this.dom,i.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(i){if(this.updateGutters(i)){let e=this.prevViewport,t=i.view.viewport,n=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(n<(t.to-t.from)*.8)}if(i.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(cl)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=i.view.viewport}syncGutters(i){let e=this.dom.nextSibling;i&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=y.RangeSet.iter(this.view.state.facet(vn),this.view.viewport.from),n=[],s=this.gutters.map(r=>new up(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==Ee.Text&&o){or(t,n,l.from);for(let a of s)a.line(this.view,l,n);o=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(r.type==Ee.Text){or(t,n,r.from);for(let o of s)o.line(this.view,r,n)}else if(r.widget)for(let o of s)o.widget(this.view,r);for(let r of s)r.finish();i&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(i){let e=i.startState.facet(Si),t=i.state.facet(Si),n=i.docChanged||i.heightChanged||i.viewportChanged||!y.RangeSet.eq(i.startState.facet(vn),i.state.facet(vn),i.view.viewport.from,i.view.viewport.to);if(e==t)for(let s of this.gutters)s.update(i)&&(n=!0);else{n=!0;let s=[];for(let r of t){let o=e.indexOf(r);o<0?s.push(new ul(this.view,r)):(this.gutters[o].update(i),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=s}return n}destroy(){for(let i of this.gutters)i.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:i=>N.scrollMargins.of(e=>{let t=e.plugin(i);if(!t||t.gutters.length==0||!t.fixed)return null;let n=t.dom.offsetWidth*e.scaleX,s=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Q.LTR?{left:n,right:s}:{right:n,left:s}})});function fl(i){return Array.isArray(i)?i:[i]}function or(i,e,t){for(;i.value&&i.from<=t;)i.from==t&&e.push(i.value),i.next()}class up{constructor(e,t,n){this.gutter=e,this.height=n,this.i=0,this.cursor=y.RangeSet.iter(e.markers,t.from)}addElement(e,t,n){let{gutter:s}=this,r=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==s.elements.length){let l=new Sh(e,o,r,n);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(e,o,r,n);this.height=t.bottom,this.i++}line(e,t,n){let s=[];or(this.cursor,s,t.from),n.length&&(s=s.concat(n));let r=this.gutter.config.lineMarker(e,t,s);r&&s.unshift(r);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,s)}widget(e,t){let n=this.gutter.config.widgetMarker(e,t.widget,t),s=n?[n]:null;for(let r of e.state.facet(ap)){let o=r(e,t.widget,t);o&&(s||(s=[])).push(o)}s&&this.addElement(e,t,s)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class ul{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let n in t.domEventHandlers)this.dom.addEventListener(n,s=>{let r=s.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=s.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[n](e,l,s)&&s.preventDefault()});this.markers=fl(t.markers(e)),t.initialSpacer&&(this.spacer=new Sh(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=fl(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let n=e.view.viewport;return!y.RangeSet.eq(this.markers,t,n.from,n.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class Sh{constructor(e,t,n,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,n,s)}update(e,t,n,s){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=n&&(this.dom.style.marginTop=(this.above=n)?n+"px":""),dp(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,t){let n="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=r<t.length?t[r++]:null,f=!1;if(a){let c=a.elementClass;c&&(n+=" "+c);for(let p=o;p<this.markers.length;p++)if(this.markers[p].compare(a)){l=p,f=!0;break}}else l=this.markers.length;for(;o<l;){let c=this.markers[o++];if(c.toDOM){c.destroy(s);let p=s.nextSibling;s.remove(),s=p}}if(!a)break;a.toDOM&&(f?s=s.nextSibling:this.dom.insertBefore(a.toDOM(e),s)),f&&o++}this.dom.className=n,this.markers=t}destroy(){this.setMarkers(null,[])}}function dp(i,e){if(i.length!=e.length)return!1;for(let t=0;t<i.length;t++)if(!i[t].compare(e[t]))return!1;return!0}const pp=y.Facet.define(),mp=y.Facet.define(),Lt=y.Facet.define({combine(i){return y.combineConfig(i,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let n=Object.assign({},e);for(let s in t){let r=n[s],o=t[s];n[s]=r?(l,a,f)=>r(l,a,f)||o(l,a,f):o}return n}})}});class ks extends rt{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Cs(i,e){return i.state.facet(Lt).formatNumber(e,i.state)}const gp=Si.compute([Lt],i=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(pp)},lineMarker(e,t,n){return n.some(s=>s.toDOM)?null:new ks(Cs(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,n)=>{for(let s of e.state.facet(mp)){let r=s(e,t,n);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(Lt)!=e.state.facet(Lt),initialSpacer(e){return new ks(Cs(e,dl(e.state.doc.lines)))},updateSpacer(e,t){let n=Cs(t.view,dl(t.view.state.doc.lines));return n==e.number?e:new ks(n)},domEventHandlers:i.facet(Lt).domEventHandlers,side:"before"}));function yp(i={}){return[Lt.of(i),bh(),gp]}function dl(i){let e=9;for(;e<i;)e=e*10+9;return e}const bp=new class extends rt{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Sp=vn.compute(["selection"],i=>{let e=[],t=-1;for(let n of i.selection.ranges){let s=i.doc.lineAt(n.head).from;s>t&&(t=s,e.push(bp.range(s)))}return y.RangeSet.of(e)});function vp(){return Sp}var As;const It=new Ve;function vh(i){return y.Facet.define({combine:i?e=>e.concat(i):void 0})}const Ir=new Ve;class $e{constructor(e,t,n=[],s=""){this.data=e,this.name=s,y.EditorState.prototype.hasOwnProperty("tree")||Object.defineProperty(y.EditorState.prototype,"tree",{get(){return te(this)}}),this.parser=t,this.extension=[pt.of(this),y.EditorState.languageData.of((r,o,l)=>{let a=pl(r,o,l),f=a.type.prop(It);if(!f)return[];let c=r.facet(f),p=a.type.prop(Ir);if(p){let g=a.resolve(o-a.from,l);for(let v of p)if(v.test(g,r)){let k=r.facet(v.facet);return v.type=="replace"?k:k.concat(c)}}return c})].concat(n)}isActiveAt(e,t,n=-1){return pl(e,t,n).type.prop(It)==this.data}findRegions(e){let t=e.facet(pt);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],s=(r,o)=>{if(r.prop(It)==this.data){n.push({from:o,to:o+r.length});return}let l=r.prop(Ve.mounted);if(l){if(l.tree.prop(It)==this.data){if(l.overlay)for(let a of l.overlay)n.push({from:a.from+o,to:a.to+o});else n.push({from:o,to:o+r.length});return}else if(l.overlay){let a=n.length;if(s(l.tree,l.overlay[0].from+o),n.length>a)return}}for(let a=0;a<r.children.length;a++){let f=r.children[a];f instanceof Rt&&s(f,r.positions[a]+o)}};return s(te(e),0),n}get allowsNesting(){return!0}}$e.setState=y.StateEffect.define();function pl(i,e,t){let n=i.facet(pt),s=te(i).topNode;if(!n||n.allowsNesting)for(let r=s;r;r=r.enter(e,t,vr.ExcludeBuffers))r.type.isTop&&(s=r);return s}class Kt extends $e{constructor(e,t,n){super(e,t,[],n),this.parser=t}static define(e){let t=vh(e.languageData);return new Kt(t,e.parser.configure({props:[It.add(n=>n.isTop?t:void 0)]}),e.name)}configure(e,t){return new Kt(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function te(i){let e=i.field($e.state,!1);return e?e.tree:Rt.empty}class xp{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e<n||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}}let ci=null;class Pn{constructor(e,t,n=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=n,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new Pn(e,t,[],Rt.empty,0,n,[],null)}startParse(){return this.parser.startParse(new xp(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=Rt.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var n;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(dn.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(n=this.parse.stoppedAt)!==null&&n!==void 0?n:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(dn.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=ci;ci=this;try{return e()}finally{ci=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=ml(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((f,c,p,g)=>a.push({fromA:f,toA:c,fromB:p,toB:g})),n=dn.applyChanges(n,a),s=Rt.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let f of this.skipped){let c=e.mapPos(f.from,1),p=e.mapPos(f.to,-1);c<p&&l.push({from:c,to:p})}}}return new Pn(this.parser,t,n,s,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let n=0;n<this.skipped.length;n++){let{from:s,to:r}=this.skipped[n];s<e.to&&r>e.from&&(this.fragments=ml(this.fragments,s,r),this.skipped.splice(n--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends Ef{createParse(t,n,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=ci;if(a){for(let f of s)a.tempSkipped.push(f);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new Rt(xr.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return ci}}function ml(i,e,t){return dn.applyChanges(i,[{fromA:e,toA:t,fromB:e,toB:t}])}class Jt{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),n=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,n)||t.takeTree(),new Jt(t)}static init(e){let t=Math.min(3e3,e.doc.length),n=Pn.create(e.facet(pt).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new Jt(n)}}$e.state=y.StateField.define({create:Jt.init,update(i,e){for(let t of e.effects)if(t.is($e.setState))return t.value;return e.startState.facet(pt)!=e.state.facet(pt)?Jt.init(e.state):i.apply(e)}});let xh=i=>{let e=setTimeout(()=>i(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(xh=i=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(i,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Ms=typeof navigator<"u"&&(!((As=navigator.scheduling)===null||As===void 0)&&As.isInputPending)?()=>navigator.scheduling.isInputPending():null,wp=se.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field($e.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field($e.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=xh(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:n,viewport:{to:s}}=this.view,r=n.field($e.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Ms?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&n.doc.length>s+1e3,a=r.context.work(()=>Ms&&Ms()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:$e.setState.of(new Jt(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Me(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),pt=y.Facet.define({combine(i){return i.length?i[0]:null},enables:i=>[$e.state,wp,N.contentAttributes.compute([i],e=>{let t=e.facet(i);return t&&t.name?{"data-language":t.name}:{}})]});class Nr{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const kp=y.Facet.define(),Xt=y.Facet.define({combine:i=>{if(!i.length)return" ";let e=i[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(i[0]));return e}});function Rn(i){let e=i.facet(Xt);return e.charCodeAt(0)==9?i.tabSize*e.length:e.length}function Mi(i,e){let t="",n=i.tabSize,s=i.facet(Xt)[0];if(s==" "){for(;e>=n;)t+=" ",e-=n;s=" "}for(let r=0;r<e;r++)t+=s;return t}function Fr(i,e){i instanceof y.EditorState&&(i=new Un(i));for(let n of i.state.facet(kp)){let s=n(i,e);if(s!==void 0)return s}let t=te(i.state);return t.length>=e?Cp(i,t,e):null}class Un{constructor(e,t={}){this.state=e,this.options=t,this.unit=Rn(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=n.from&&s<=n.to?r&&s==e?{text:"",from:e}:(t<0?s<e:s<=e)?{text:n.text.slice(s-n.from),from:s}:{text:n.text.slice(0,s-n.from),from:n.from}:n}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:n,from:s}=this.lineAt(e,t);return n.slice(e-s,Math.min(n.length,e+100-s))}column(e,t=1){let{text:n,from:s}=this.lineAt(e,t),r=this.countColumn(n,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(r+=o-this.countColumn(n,n.search(/\S|$/))),r}countColumn(e,t=e.length){return y.countColumn(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:s}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(s);if(o>-1)return o}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Yn=new Ve;function Cp(i,e,t){let n=e.resolveStack(t),s=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(s!=n.node){let r=[];for(let o=s;o&&!(o.from<n.node.from||o.to>n.node.to||o.from==n.node.from&&o.type==n.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)n={node:r[o],next:n}}return wh(n,i,t)}function wh(i,e,t){for(let n=i;n;n=n.next){let s=Mp(n.node);if(s)return s(Vr.create(e,t,n))}return 0}function Ap(i){return i.pos==i.options.simulateBreak&&i.options.simulateDoubleBreak}function Mp(i){let e=i.type.prop(Yn);if(e)return e;let t=i.firstChild,n;if(t&&(n=t.type.prop(Ve.closedBy))){let s=i.lastChild,r=s&&n.indexOf(s.name)>-1;return o=>kh(o,!0,1,void 0,r&&!Ap(o)?s.from:void 0)}return i.parent==null?Ep:null}function Ep(){return 0}class Vr extends Un{constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.context=n}get node(){return this.context.node}static create(e,t,n){return new Vr(e,t,n)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let n=e.resolve(t.from);for(;n.parent&&n.parent.from==n.from;)n=n.parent;if(Tp(n,e))break;t=this.state.doc.lineAt(n.from)}return this.lineIndent(t.from)}continue(){return wh(this.context.next,this.base,this.pos)}}function Tp(i,e){for(let t=e;t;t=t.parent)if(i==t)return!0;return!1}function Op(i){let e=i.node,t=e.childAfter(e.from),n=e.lastChild;if(!t)return null;let s=i.options.simulateBreak,r=i.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==n)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let f=/^ */.exec(r.text.slice(t.to-r.from))[0].length;return{from:t.from,to:t.to+f}}l=a.to}}function xn({closing:i,align:e=!0,units:t=1}){return n=>kh(n,e,t,i)}function kh(i,e,t,n,s){let r=i.textAfter,o=r.match(/^\s*/)[0].length,l=n&&r.slice(o,o+n.length)==n||s==i.pos+o,a=e?Op(i):null;return a?l?i.column(a.from):i.column(a.to):i.baseIndent+(l?0:i.unit*t)}const Dp=i=>i.baseIndent;function vi({except:i,units:e=1}={}){return t=>{let n=i&&i.test(t.textAfter);return t.baseIndent+(n?0:e*t.unit)}}const Pp=200;function Rp(){return y.EditorState.transactionFilter.of(i=>{if(!i.docChanged||!i.isUserEvent("input.type")&&!i.isUserEvent("input.complete"))return i;let e=i.startState.languageDataAt("indentOnInput",i.startState.selection.main.head);if(!e.length)return i;let t=i.newDoc,{head:n}=i.newSelection.main,s=t.lineAt(n);if(n>s.from+Pp)return i;let r=t.sliceString(s.from,n);if(!e.some(f=>f.test(r)))return i;let{state:o}=i,l=-1,a=[];for(let{head:f}of o.selection.ranges){let c=o.doc.lineAt(f);if(c.from==l)continue;l=c.from;let p=Fr(o,c.from);if(p==null)continue;let g=/^\s*/.exec(c.text)[0],v=Mi(o,p);g!=v&&a.push({from:c.from,to:c.from+g.length,insert:v})}return a.length?[i,{changes:a,sequential:!0}]:i})}const Bp=y.Facet.define(),Gn=new Ve;function Hr(i){let e=i.firstChild,t=i.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?i.to:t.from}:null}function Lp(i,e,t){let n=te(i);if(n.length<t)return null;let s=n.resolveStack(t,1),r=null;for(let o=s;o;o=o.next){let l=o.node;if(l.to<=t||l.from>t)continue;if(r&&l.from<e)break;let a=l.type.prop(Gn);if(a&&(l.to<n.length-50||n.length==i.doc.length||!Ip(l))){let f=a(l,i);f&&f.from<=t&&f.from>=e&&f.to>t&&(r=f)}}return r}function Ip(i){let e=i.lastChild;return e&&e.to==i.to&&e.type.isError}function Bn(i,e,t){for(let n of i.facet(Bp)){let s=n(i,e,t);if(s)return s}return Lp(i,e,t)}function Ch(i,e){let t=e.mapPos(i.from,1),n=e.mapPos(i.to,-1);return t>=n?void 0:{from:t,to:n}}const Xn=y.StateEffect.define({map:Ch}),Vi=y.StateEffect.define({map:Ch});function Ah(i){let e=[];for(let{head:t}of i.state.selection.ranges)e.some(n=>n.from<=t&&n.to>=t)||e.push(i.lineBlockAt(t));return e}const Ct=y.StateField.define({create(){return H.none},update(i,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((t,n)=>i=gl(i,t,n)),i=i.map(e.changes);for(let t of e.effects)if(t.is(Xn)&&!Np(i,t.value.from,t.value.to)){let{preparePlaceholder:n}=e.state.facet(Th),s=n?H.replace({widget:new qp(n(e.state,t.value))}):yl;i=i.update({add:[s.range(t.value.from,t.value.to)]})}else t.is(Vi)&&(i=i.update({filter:(n,s)=>t.value.from!=n||t.value.to!=s,filterFrom:t.value.from,filterTo:t.value.to}));return e.selection&&(i=gl(i,e.selection.main.head)),i},provide:i=>N.decorations.from(i),toJSON(i,e){let t=[];return i.between(0,e.doc.length,(n,s)=>{t.push(n,s)}),t},fromJSON(i){if(!Array.isArray(i)||i.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<i.length;){let n=i[t++],s=i[t++];if(typeof n!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");e.push(yl.range(n,s))}return H.set(e,!0)}});function gl(i,e,t=e){let n=!1;return i.between(e,t,(s,r)=>{s<t&&r>e&&(n=!0)}),n?i.update({filterFrom:e,filterTo:t,filter:(s,r)=>s>=t||r<=e}):i}function Ln(i,e,t){var n;let s=null;return(n=i.field(Ct,!1))===null||n===void 0||n.between(e,t,(r,o)=>{(!s||s.from>r)&&(s={from:r,to:o})}),s}function Np(i,e,t){let n=!1;return i.between(e,e,(s,r)=>{s==e&&r==t&&(n=!0)}),n}function Mh(i,e){return i.field(Ct,!1)?e:e.concat(y.StateEffect.appendConfig.of(Oh()))}const Fp=i=>{for(let e of Ah(i)){let t=Bn(i.state,e.from,e.to);if(t)return i.dispatch({effects:Mh(i.state,[Xn.of(t),Eh(i,t)])}),!0}return!1},Vp=i=>{if(!i.state.field(Ct,!1))return!1;let e=[];for(let t of Ah(i)){let n=Ln(i.state,t.from,t.to);n&&e.push(Vi.of(n),Eh(i,n,!1))}return e.length&&i.dispatch({effects:e}),e.length>0};function Eh(i,e,t=!0){let n=i.state.doc.lineAt(e.from).number,s=i.state.doc.lineAt(e.to).number;return N.announce.of(`${i.state.phrase(t?"Folded lines":"Unfolded lines")} ${n} ${i.state.phrase("to")} ${s}.`)}const Hp=i=>{let{state:e}=i,t=[];for(let n=0;n<e.doc.length;){let s=i.lineBlockAt(n),r=Bn(e,s.from,s.to);r&&t.push(Xn.of(r)),n=(r?i.lineBlockAt(r.to):s).to+1}return t.length&&i.dispatch({effects:Mh(i.state,t)}),!!t.length},Wp=i=>{let e=i.state.field(Ct,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,i.state.doc.length,(n,s)=>{t.push(Vi.of({from:n,to:s}))}),i.dispatch({effects:t}),!0},$p=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:Fp},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:Vp},{key:"Ctrl-Alt-[",run:Hp},{key:"Ctrl-Alt-]",run:Wp}],zp={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Th=y.Facet.define({combine(i){return y.combineConfig(i,zp)}});function Oh(i){return[Ct,Kp]}function Dh(i,e){let{state:t}=i,n=t.facet(Th),s=o=>{let l=i.lineBlockAt(i.posAtDOM(o.target)),a=Ln(i.state,l.from,l.to);a&&i.dispatch({effects:Vi.of(a)}),o.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(i,s,e);let r=document.createElement("span");return r.textContent=n.placeholderText,r.setAttribute("aria-label",t.phrase("folded code")),r.title=t.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const yl=H.replace({widget:new class extends je{toDOM(i){return Dh(i,null)}}});class qp extends je{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return Dh(e,this.value)}}const jp={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class Es extends rt{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function _p(i={}){let e={...jp,...i},t=new Es(e,!0),n=new Es(e,!1),s=se.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(pt)!=o.state.facet(pt)||o.startState.field(Ct,!1)!=o.state.field(Ct,!1)||te(o.startState)!=te(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new y.RangeSetBuilder;for(let a of o.viewportLineBlocks){let f=Ln(o.state,a.from,a.to)?n:Bn(o.state,a.from,a.to)?t:null;f&&l.add(a.from,a.from,f)}return l.finish()}}),{domEventHandlers:r}=e;return[s,cp({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(s))===null||l===void 0?void 0:l.markers)||y.RangeSet.empty},initialSpacer(){return new Es(e,!1)},domEventHandlers:{...r,click:(o,l,a)=>{if(r.click&&r.click(o,l,a))return!0;let f=Ln(o.state,l.from,l.to);if(f)return o.dispatch({effects:Vi.of(f)}),!0;let c=Bn(o.state,l.from,l.to);return c?(o.dispatch({effects:Xn.of(c)}),!0):!1}}}),Oh()]}const Kp=N.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 Qt{constructor(e,t){this.specs=e;let n;function s(l){let a=ut.newName();return(n||(n=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof $e?l=>l.prop(It)==o.data:o?l=>l==o:void 0,this.style=Tf(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=n?new ut(n):null,this.themeType=t.themeType}static define(e,t){return new Qt(e,t||{})}}const lr=y.Facet.define(),Ph=y.Facet.define({combine(i){return i.length?[i[0]]:null}});function Ts(i){let e=i.facet(lr);return e.length?e:i.facet(Ph)}function Wr(i,e){let t=[Up],n;return i instanceof Qt&&(i.module&&t.push(N.styleModule.of(i.module)),n=i.themeType),e!=null&&e.fallback?t.push(Ph.of(i)):n?t.push(lr.computeN([N.darkTheme],s=>s.facet(N.darkTheme)==(n=="dark")?[i]:[])):t.push(lr.of(i)),t}class Jp{constructor(e){this.markCache=Object.create(null),this.tree=te(e.state),this.decorations=this.buildDeco(e,Ts(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=te(e.state),n=Ts(e.state),s=n!=Ts(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!s&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return H.none;let n=new y.RangeSetBuilder;for(let{from:s,to:r}of e.visibleRanges)Of(this.tree,t,(o,l,a)=>{n.add(o,l,this.markCache[a]||(this.markCache[a]=H.mark({class:a})))},s,r);return n.finish()}}const Up=y.Prec.high(se.fromClass(Jp,{decorations:i=>i.decorations})),Yp=Qt.define([{tag:E.meta,color:"#404740"},{tag:E.link,textDecoration:"underline"},{tag:E.heading,textDecoration:"underline",fontWeight:"bold"},{tag:E.emphasis,fontStyle:"italic"},{tag:E.strong,fontWeight:"bold"},{tag:E.strikethrough,textDecoration:"line-through"},{tag:E.keyword,color:"#708"},{tag:[E.atom,E.bool,E.url,E.contentSeparator,E.labelName],color:"#219"},{tag:[E.literal,E.inserted],color:"#164"},{tag:[E.string,E.deleted],color:"#a11"},{tag:[E.regexp,E.escape,E.special(E.string)],color:"#e40"},{tag:E.definition(E.variableName),color:"#00f"},{tag:E.local(E.variableName),color:"#30a"},{tag:[E.typeName,E.namespace],color:"#085"},{tag:E.className,color:"#167"},{tag:[E.special(E.variableName),E.macroName],color:"#256"},{tag:E.definition(E.propertyName),color:"#00c"},{tag:E.comment,color:"#940"},{tag:E.invalid,color:"#f00"}]),Gp=N.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Rh=1e4,Bh="()[]{}",Lh=y.Facet.define({combine(i){return y.combineConfig(i,{afterCursor:!0,brackets:Bh,maxScanDistance:Rh,renderMatch:Zp})}}),Xp=H.mark({class:"cm-matchingBracket"}),Qp=H.mark({class:"cm-nonmatchingBracket"});function Zp(i){let e=[],t=i.matched?Xp:Qp;return e.push(t.range(i.start.from,i.start.to)),i.end&&e.push(t.range(i.end.from,i.end.to)),e}const em=y.StateField.define({create(){return H.none},update(i,e){if(!e.docChanged&&!e.selection)return i;let t=[],n=e.state.facet(Lh);for(let s of e.state.selection.ranges){if(!s.empty)continue;let r=Ge(e.state,s.head,-1,n)||s.head>0&&Ge(e.state,s.head-1,1,n)||n.afterCursor&&(Ge(e.state,s.head,1,n)||s.head<e.state.doc.length&&Ge(e.state,s.head+1,-1,n));r&&(t=t.concat(n.renderMatch(r,e.state)))}return H.set(t,!0)},provide:i=>N.decorations.from(i)}),tm=[em,Gp];function im(i={}){return[Lh.of(i),tm]}const nm=new Ve;function ar(i,e,t){let n=i.prop(e<0?Ve.openedBy:Ve.closedBy);if(n)return n;if(i.name.length==1){let s=t.indexOf(i.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function hr(i){let e=i.type.prop(nm);return e?e(i.node):i}function Ge(i,e,t,n={}){let s=n.maxScanDistance||Rh,r=n.brackets||Bh,o=te(i),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let f=ar(a.type,t,r);if(f&&a.from<a.to){let c=hr(a);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return sm(i,e,t,a,c,f,r)}}return rm(i,e,t,o,l.type,s,r)}function sm(i,e,t,n,s,r,o){let l=n.parent,a={from:s.from,to:s.to},f=0,c=l==null?void 0:l.cursor();if(c&&(t<0?c.childBefore(n.from):c.childAfter(n.to)))do if(t<0?c.to<=n.from:c.from>=n.to){if(f==0&&r.indexOf(c.type.name)>-1&&c.from<c.to){let p=hr(c);return{start:a,end:p?{from:p.from,to:p.to}:void 0,matched:!0}}else if(ar(c.type,t,o))f++;else if(ar(c.type,-t,o)){if(f==0){let p=hr(c);return{start:a,end:p&&p.from<p.to?{from:p.from,to:p.to}:void 0,matched:!1}}f--}}while(t<0?c.prevSibling():c.nextSibling());return{start:a,matched:!1}}function rm(i,e,t,n,s,r,o){let l=t<0?i.sliceDoc(e-1,e):i.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let f={from:t<0?e-1:e,to:t>0?e+1:e},c=i.doc.iterRange(e,t>0?i.doc.length:0),p=0;for(let g=0;!c.next().done&&g<=r;){let v=c.value;t<0&&(g+=v.length);let k=e+g*t;for(let C=t>0?0:v.length-1,M=t>0?v.length:-1;C!=M;C+=t){let T=o.indexOf(v[C]);if(!(T<0||n.resolveInner(k+C,1).type!=s))if(T%2==0==t>0)p++;else{if(p==1)return{start:f,end:{from:k+C,to:k+C+1},matched:T>>1==a>>1};p--}}t>0&&(g+=v.length)}return c.done?{start:f,matched:!1}:null}const om=Object.create(null),bl=[xr.none],Sl=[],vl=Object.create(null),lm=Object.create(null);for(let[i,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])lm[i]=am(om,e);function Os(i,e){Sl.indexOf(i)>-1||(Sl.push(i),console.warn(e))}function am(i,e){let t=[];for(let l of e.split(" ")){let a=[];for(let f of l.split(".")){let c=i[f]||E[f];c?typeof c=="function"?a.length?a=a.map(c):Os(f,`Modifier ${f} used at start of tag`):a.length?Os(f,`Tag ${f} used as modifier`):a=Array.isArray(c)?c:[c]:Os(f,`Unknown highlighting tag ${f}`)}for(let f of a)t.push(f)}if(!t.length)return 0;let n=e.replace(/ /g,"_"),s=n+" "+t.map(l=>l.id),r=vl[s];if(r)return r.id;let o=vl[s]=xr.define({id:bl.length,name:n,props:[Df({[n]:t})]});return bl.push(o),o.id}Q.RTL,Q.LTR;const hm=i=>{let{state:e}=i,t=e.doc.lineAt(e.selection.main.from),n=zr(i.state,t.from);return n.line?cm(i):n.block?um(i):!1};function $r(i,e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let s=i(e,t);return s?(n(t.update(s)),!0):!1}}const cm=$r(mm,0),fm=$r(Ih,0),um=$r((i,e)=>Ih(i,e,pm(e)),0);function zr(i,e){let t=i.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const fi=50;function dm(i,{open:e,close:t},n,s){let r=i.sliceDoc(n-fi,n),o=i.sliceDoc(s,s+fi),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,f=r.length-l;if(r.slice(f-e.length,f)==e&&o.slice(a,a+t.length)==t)return{open:{pos:n-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let c,p;s-n<=2*fi?c=p=i.sliceDoc(n,s):(c=i.sliceDoc(n,n+fi),p=i.sliceDoc(s-fi,s));let g=/^\s*/.exec(c)[0].length,v=/\s*$/.exec(p)[0].length,k=p.length-v-t.length;return c.slice(g,g+e.length)==e&&p.slice(k,k+t.length)==t?{open:{pos:n+g+e.length,margin:/\s/.test(c.charAt(g+e.length))?1:0},close:{pos:s-v-t.length,margin:/\s/.test(p.charAt(k-1))?1:0}}:null}function pm(i){let e=[];for(let t of i.selection.ranges){let n=i.doc.lineAt(t.from),s=t.to<=n.to?n:i.doc.lineAt(t.to);s.from>n.from&&s.from==t.to&&(s=t.to==n.to+1?n:i.doc.lineAt(t.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}function Ih(i,e,t=e.selection.ranges){let n=t.map(r=>zr(e,r.from).block);if(!n.every(r=>r))return null;let s=t.map((r,o)=>dm(e,n[o],r.from,r.to));if(i!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:n[o].open+" "},{from:r.to,insert:" "+n[o].close}]))};if(i!=1&&s.some(r=>r)){let r=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let a=n[o],{open:f,close:c}=l;r.push({from:f.pos-a.open.length,to:f.pos+f.margin},{from:c.pos-c.margin,to:c.pos+a.close.length})}return{changes:r}}return null}function mm(i,e,t=e.selection.ranges){let n=[],s=-1;for(let{from:r,to:o}of t){let l=n.length,a=1e9,f=zr(e,r).line;if(f){for(let c=r;c<=o;){let p=e.doc.lineAt(c);if(p.from>s&&(r==o||o>p.from)){s=p.from;let g=/^\s*/.exec(p.text)[0].length,v=g==p.length,k=p.text.slice(g,g+f.length)==f?g:-1;g<p.text.length&&g<a&&(a=g),n.push({line:p,comment:k,token:f,indent:g,empty:v,single:!1})}c=p.to+1}if(a<1e9)for(let c=l;c<n.length;c++)n[c].indent<n[c].line.text.length&&(n[c].indent=a);n.length==l+1&&(n[l].single=!0)}}if(i!=2&&n.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:f,empty:c,single:p}of n)(p||!c)&&r.push({from:l.from+f,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(i!=1&&n.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of n)if(l>=0){let f=o.from+l,c=f+a.length;o.text[c-o.from]==" "&&c++,r.push({from:f,to:c})}return{changes:r}}return null}const cr=y.Annotation.define(),gm=y.Annotation.define(),ym=y.Facet.define(),Nh=y.Facet.define({combine(i){return y.combineConfig(i,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,s)=>e(n,s)||t(n,s)})}}),Fh=y.StateField.define({create(){return Xe.empty},update(i,e){let t=e.state.facet(Nh),n=e.annotation(cr);if(n){let a=Pe.fromTransaction(e,n.selection),f=n.side,c=f==0?i.undone:i.done;return a?c=In(c,c.length,t.minDepth,a):c=Wh(c,e.startState.selection),new Xe(f==0?n.rest:c,f==0?c:n.rest)}let s=e.annotation(gm);if((s=="full"||s=="before")&&(i=i.isolate()),e.annotation(y.Transaction.addToHistory)===!1)return e.changes.empty?i:i.addMapping(e.changes.desc);let r=Pe.fromTransaction(e),o=e.annotation(y.Transaction.time),l=e.annotation(y.Transaction.userEvent);return r?i=i.addChanges(r,o,l,t,e):e.selection&&(i=i.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(i=i.isolate()),i},toJSON(i){return{done:i.done.map(e=>e.toJSON()),undone:i.undone.map(e=>e.toJSON())}},fromJSON(i){return new Xe(i.done.map(Pe.fromJSON),i.undone.map(Pe.fromJSON))}});function bm(i={}){return[Fh,Nh.of(i),N.domEventHandlers({beforeinput(e,t){let n=e.inputType=="historyUndo"?Vh:e.inputType=="historyRedo"?fr:null;return n?(e.preventDefault(),n(t)):!1}})]}function Qn(i,e){return function({state:t,dispatch:n}){if(!e&&t.readOnly)return!1;let s=t.field(Fh,!1);if(!s)return!1;let r=s.pop(i,t,e);return r?(n(r),!0):!1}}const Vh=Qn(0,!1),fr=Qn(1,!1),Sm=Qn(0,!0),vm=Qn(1,!0);class Pe{constructor(e,t,n,s,r){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new Pe(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,n;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new Pe(e.changes&&y.ChangeSet.fromJSON(e.changes),[],e.mapped&&y.ChangeDesc.fromJSON(e.mapped),e.startSelection&&y.EditorSelection.fromJSON(e.startSelection),e.selectionsAfter.map(y.EditorSelection.fromJSON))}static fromTransaction(e,t){let n=Ne;for(let s of e.startState.facet(ym)){let r=s(e);r.length&&(n=n.concat(r))}return!n.length&&e.changes.empty?null:new Pe(e.changes.invert(e.startState.doc),n,void 0,t||e.startState.selection,Ne)}static selection(e){return new Pe(void 0,Ne,void 0,void 0,e)}}function In(i,e,t,n){let s=e+1>t+20?e-t-1:0,r=i.slice(s,e);return r.push(n),r}function xm(i,e){let t=[],n=!1;return i.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a<t.length;){let f=t[a++],c=t[a++];l>=f&&o<=c&&(n=!0)}}),n}function wm(i,e){return i.ranges.length==e.ranges.length&&i.ranges.filter((t,n)=>t.empty!=e.ranges[n].empty).length===0}function Hh(i,e){return i.length?e.length?i.concat(e):i:e}const Ne=[],km=200;function Wh(i,e){if(i.length){let t=i[i.length-1],n=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-km));return n.length&&n[n.length-1].eq(e)?i:(n.push(e),In(i,i.length-1,1e9,t.setSelAfter(n)))}else return[Pe.selection([e])]}function Cm(i){let e=i[i.length-1],t=i.slice();return t[i.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Ds(i,e){if(!i.length)return i;let t=i.length,n=Ne;for(;t;){let s=Am(i[t-1],e,n);if(s.changes&&!s.changes.empty||s.effects.length){let r=i.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,n=s.selectionsAfter}return n.length?[Pe.selection(n)]:Ne}function Am(i,e,t){let n=Hh(i.selectionsAfter.length?i.selectionsAfter.map(l=>l.map(e)):Ne,t);if(!i.changes)return Pe.selection(n);let s=i.changes.map(e),r=e.mapDesc(i.changes,!0),o=i.mapped?i.mapped.composeDesc(r):r;return new Pe(s,y.StateEffect.mapEffects(i.effects,e),o,i.startSelection.map(r),n)}const Mm=/^(input\.type|delete)($|\.)/;class Xe{constructor(e,t,n=0,s=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=s}isolate(){return this.prevTime?new Xe(this.done,this.undone):this}addChanges(e,t,n,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!n||Mm.test(n))&&(!l.selectionsAfter.length&&t-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,xm(l.changes,e.changes))||n=="input.type.compose")?o=In(o,o.length-1,s.minDepth,new Pe(e.changes.compose(l.changes),Hh(y.StateEffect.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Ne)):o=In(o,o.length,s.minDepth,e),new Xe(o,Ne,t,n)}addSelection(e,t,n,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Ne;return r.length>0&&t-this.prevTime<s&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&wm(r[r.length-1],e)?this:new Xe(Wh(this.done,e),this.undone,t,n)}addMapping(e){return new Xe(Ds(this.done,e),Ds(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,n){let s=e==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1],o=r.selectionsAfter[0]||t.selection;if(n&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:cr.of({side:e,rest:Cm(s),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=s.length==1?Ne:s.slice(0,s.length-1);return r.mapped&&(l=Ds(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:cr.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}Xe.empty=new Xe(Ne,Ne);const Em=[{key:"Mod-z",run:Vh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:fr,preventDefault:!0},{linux:"Ctrl-Shift-z",run:fr,preventDefault:!0},{key:"Mod-u",run:Sm,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:vm,preventDefault:!0}];function Zt(i,e){return y.EditorSelection.create(i.ranges.map(e),i.mainIndex)}function et(i,e){return i.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function _e({state:i,dispatch:e},t){let n=Zt(i.selection,t);return n.eq(i.selection,!0)?!1:(e(et(i,n)),!0)}function Zn(i,e){return y.EditorSelection.cursor(e?i.to:i.from)}function $h(i,e){return _e(i,t=>t.empty?i.moveByChar(t,e):Zn(t,e))}function ke(i){return i.textDirectionAt(i.state.selection.main.head)==Q.LTR}const zh=i=>$h(i,!ke(i)),qh=i=>$h(i,ke(i));function jh(i,e){return _e(i,t=>t.empty?i.moveByGroup(t,e):Zn(t,e))}const Tm=i=>jh(i,!ke(i)),Om=i=>jh(i,ke(i));function Dm(i,e,t){if(e.type.prop(t))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(i.sliceDoc(e.from,e.to)))||e.firstChild}function es(i,e,t){let n=te(i).resolveInner(e.head),s=t?Ve.closedBy:Ve.openedBy;for(let a=e.head;;){let f=t?n.childAfter(a):n.childBefore(a);if(!f)break;Dm(i,f,s)?n=f:a=t?f.to:f.from}let r=n.type.prop(s),o,l;return r&&(o=t?Ge(i,n.from,1):Ge(i,n.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?n.to:n.from,y.EditorSelection.cursor(l,t?-1:1)}const Pm=i=>_e(i,e=>es(i.state,e,!ke(i))),Rm=i=>_e(i,e=>es(i.state,e,ke(i)));function _h(i,e){return _e(i,t=>{if(!t.empty)return Zn(t,e);let n=i.moveVertically(t,e);return n.head!=t.head?n:i.moveToLineBoundary(t,e)})}const Kh=i=>_h(i,!1),Jh=i=>_h(i,!0);function Uh(i){let e=i.scrollDOM.clientHeight<i.scrollDOM.scrollHeight-2,t=0,n=0,s;if(e){for(let r of i.state.facet(N.scrollMargins)){let o=r(i);o!=null&&o.top&&(t=Math.max(o==null?void 0:o.top,t)),o!=null&&o.bottom&&(n=Math.max(o==null?void 0:o.bottom,n))}s=i.scrollDOM.clientHeight-t-n}else s=(i.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:n,selfScroll:e,height:Math.max(i.defaultLineHeight,s-5)}}function Yh(i,e){let t=Uh(i),{state:n}=i,s=Zt(n.selection,o=>o.empty?i.moveVertically(o,e,t.height):Zn(o,e));if(s.eq(n.selection))return!1;let r;if(t.selfScroll){let o=i.coordsAtPos(n.selection.main.head),l=i.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,f=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<f&&(r=N.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-a}))}return i.dispatch(et(n,s),{effects:r}),!0}const xl=i=>Yh(i,!1),ur=i=>Yh(i,!0);function mt(i,e,t){let n=i.lineBlockAt(e.head),s=i.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?n.to:n.from)&&(s=i.moveToLineBoundary(e,t,!1)),!t&&s.head==n.from&&n.length){let r=/^\s*/.exec(i.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;r&&e.head!=n.from+r&&(s=y.EditorSelection.cursor(n.from+r))}return s}const Bm=i=>_e(i,e=>mt(i,e,!0)),Lm=i=>_e(i,e=>mt(i,e,!1)),Im=i=>_e(i,e=>mt(i,e,!ke(i))),Nm=i=>_e(i,e=>mt(i,e,ke(i))),Fm=i=>_e(i,e=>y.EditorSelection.cursor(i.lineBlockAt(e.head).from,1)),Vm=i=>_e(i,e=>y.EditorSelection.cursor(i.lineBlockAt(e.head).to,-1));function Hm(i,e,t){let n=!1,s=Zt(i.selection,r=>{let o=Ge(i,r.head,-1)||Ge(i,r.head,1)||r.head>0&&Ge(i,r.head-1,1)||r.head<i.doc.length&&Ge(i,r.head+1,-1);if(!o||!o.end)return r;n=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return y.EditorSelection.cursor(l)});return n?(e(et(i,s)),!0):!1}const Wm=({state:i,dispatch:e})=>Hm(i,e);function We(i,e){let t=Zt(i.state.selection,n=>{let s=e(n);return y.EditorSelection.range(n.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return t.eq(i.state.selection)?!1:(i.dispatch(et(i.state,t)),!0)}function Gh(i,e){return We(i,t=>i.moveByChar(t,e))}const Xh=i=>Gh(i,!ke(i)),Qh=i=>Gh(i,ke(i));function Zh(i,e){return We(i,t=>i.moveByGroup(t,e))}const $m=i=>Zh(i,!ke(i)),zm=i=>Zh(i,ke(i)),qm=i=>We(i,e=>es(i.state,e,!ke(i))),jm=i=>We(i,e=>es(i.state,e,ke(i)));function ec(i,e){return We(i,t=>i.moveVertically(t,e))}const tc=i=>ec(i,!1),ic=i=>ec(i,!0);function nc(i,e){return We(i,t=>i.moveVertically(t,e,Uh(i).height))}const wl=i=>nc(i,!1),kl=i=>nc(i,!0),_m=i=>We(i,e=>mt(i,e,!0)),Km=i=>We(i,e=>mt(i,e,!1)),Jm=i=>We(i,e=>mt(i,e,!ke(i))),Um=i=>We(i,e=>mt(i,e,ke(i))),Ym=i=>We(i,e=>y.EditorSelection.cursor(i.lineBlockAt(e.head).from)),Gm=i=>We(i,e=>y.EditorSelection.cursor(i.lineBlockAt(e.head).to)),Cl=({state:i,dispatch:e})=>(e(et(i,{anchor:0})),!0),Al=({state:i,dispatch:e})=>(e(et(i,{anchor:i.doc.length})),!0),Ml=({state:i,dispatch:e})=>(e(et(i,{anchor:i.selection.main.anchor,head:0})),!0),El=({state:i,dispatch:e})=>(e(et(i,{anchor:i.selection.main.anchor,head:i.doc.length})),!0),Xm=({state:i,dispatch:e})=>(e(i.update({selection:{anchor:0,head:i.doc.length},userEvent:"select"})),!0),Qm=({state:i,dispatch:e})=>{let t=ts(i).map(({from:n,to:s})=>y.EditorSelection.range(n,Math.min(s+1,i.doc.length)));return e(i.update({selection:y.EditorSelection.create(t),userEvent:"select"})),!0},Zm=({state:i,dispatch:e})=>{let t=Zt(i.selection,n=>{let s=te(i),r=s.resolveStack(n.from,1);if(n.empty){let o=s.resolveStack(n.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<n.from&&l.to>=n.to||l.to>n.to&&l.from<=n.from)&&o.next)return y.EditorSelection.range(l.to,l.from)}return n});return t.eq(i.selection)?!1:(e(et(i,t)),!0)},eg=({state:i,dispatch:e})=>{let t=i.selection,n=null;return t.ranges.length>1?n=y.EditorSelection.create([t.main]):t.main.empty||(n=y.EditorSelection.create([y.EditorSelection.cursor(t.main.head)])),n?(e(et(i,n)),!0):!1};function Hi(i,e){if(i.state.readOnly)return!1;let t="delete.selection",{state:n}=i,s=n.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(r);a<o?(t="delete.backward",a=on(i,a,!1)):a>o&&(t="delete.forward",a=on(i,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=on(i,o,!1),l=on(i,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:y.EditorSelection.cursor(o,o<r.head?-1:1)}});return s.changes.empty?!1:(i.dispatch(n.update(s,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?N.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function on(i,e,t){if(i instanceof N)for(let n of i.state.facet(N.atomicRanges).map(s=>s(i)))n.between(e,e,(s,r)=>{s<e&&r>e&&(e=t?r:s)});return e}const sc=(i,e,t)=>Hi(i,n=>{let s=n.from,{state:r}=i,o=r.doc.lineAt(s),l,a;if(t&&!e&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,s-o.from))){if(l[l.length-1]==" ")return s-1;let f=y.countColumn(l,r.tabSize),c=f%Rn(r)||Rn(r);for(let p=0;p<c&&l[l.length-1-p]==" ";p++)s--;a=s}else a=y.findClusterBreak(o.text,s-o.from,e,e)+o.from,a==s&&o.number!=(e?r.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,s-o.from))&&(a=y.findClusterBreak(o.text,a-o.from,!1,!1)+o.from);return a}),dr=i=>sc(i,!1,!0),rc=i=>sc(i,!0,!1),oc=(i,e)=>Hi(i,t=>{let n=t.head,{state:s}=i,r=s.doc.lineAt(n),o=s.charCategorizer(n);for(let l=null;;){if(n==(e?r.to:r.from)){n==t.head&&r.number!=(e?s.doc.lines:1)&&(n+=e?1:-1);break}let a=y.findClusterBreak(r.text,n-r.from,e)+r.from,f=r.text.slice(Math.min(n,a)-r.from,Math.max(n,a)-r.from),c=o(f);if(l!=null&&c!=l)break;(f!=" "||n!=t.head)&&(l=c),n=a}return n}),lc=i=>oc(i,!1),tg=i=>oc(i,!0),ig=i=>Hi(i,e=>{let t=i.lineBlockAt(e.head).to;return e.head<t?t:Math.min(i.state.doc.length,e.head+1)}),ng=i=>Hi(i,e=>{let t=i.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),sg=i=>Hi(i,e=>{let t=i.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(i.state.doc.length,e.head+1)}),rg=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=i.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:y.Text.of(["",""])},range:y.EditorSelection.cursor(n.from)}));return e(i.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},og=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=i.changeByRange(n=>{if(!n.empty||n.from==0||n.from==i.doc.length)return{range:n};let s=n.from,r=i.doc.lineAt(s),o=s==r.from?s-1:y.findClusterBreak(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:y.findClusterBreak(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:i.doc.slice(s,l).append(i.doc.slice(o,s))},range:y.EditorSelection.cursor(l)}});return t.changes.empty?!1:(e(i.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function ts(i){let e=[],t=-1;for(let n of i.selection.ranges){let s=i.doc.lineAt(n.from),r=i.doc.lineAt(n.to);if(!n.empty&&n.to==r.from&&(r=i.doc.lineAt(n.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(n)}else e.push({from:s.from,to:r.to,ranges:[n]});t=r.number+1}return e}function ac(i,e,t){if(i.readOnly)return!1;let n=[],s=[];for(let r of ts(i)){if(t?r.to==i.doc.length:r.from==0)continue;let o=i.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){n.push({from:r.to,to:o.to},{from:r.from,insert:o.text+i.lineBreak});for(let a of r.ranges)s.push(y.EditorSelection.range(Math.min(i.doc.length,a.anchor+l),Math.min(i.doc.length,a.head+l)))}else{n.push({from:o.from,to:r.from},{from:r.to,insert:i.lineBreak+o.text});for(let a of r.ranges)s.push(y.EditorSelection.range(a.anchor-l,a.head-l))}}return n.length?(e(i.update({changes:n,scrollIntoView:!0,selection:y.EditorSelection.create(s,i.selection.mainIndex),userEvent:"move.line"})),!0):!1}const lg=({state:i,dispatch:e})=>ac(i,e,!1),ag=({state:i,dispatch:e})=>ac(i,e,!0);function hc(i,e,t){if(i.readOnly)return!1;let n=[];for(let s of ts(i))t?n.push({from:s.from,insert:i.doc.slice(s.from,s.to)+i.lineBreak}):n.push({from:s.to,insert:i.lineBreak+i.doc.slice(s.from,s.to)});return e(i.update({changes:n,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const hg=({state:i,dispatch:e})=>hc(i,e,!1),cg=({state:i,dispatch:e})=>hc(i,e,!0),fg=i=>{if(i.state.readOnly)return!1;let{state:e}=i,t=e.changes(ts(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),n=Zt(e.selection,s=>{let r;if(i.lineWrapping){let o=i.lineBlockAt(s.head),l=i.coordsAtPos(s.head,s.assoc||1);l&&(r=o.bottom+i.documentTop-l.bottom+i.defaultLineHeight/2)}return i.moveVertically(s,!0,r)}).map(t);return i.dispatch({changes:t,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function ug(i,e){if(/\(\)|\[\]|\{\}/.test(i.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=te(i).resolveInner(e),n=t.childBefore(e),s=t.childAfter(e),r;return n&&s&&n.to<=e&&s.from>=e&&(r=n.type.prop(Ve.closedBy))&&r.indexOf(s.name)>-1&&i.doc.lineAt(n.to).from==i.doc.lineAt(s.from).from&&!/\S/.test(i.sliceDoc(n.to,s.from))?{from:n.to,to:s.from}:null}const Tl=cc(!1),dg=cc(!0);function cc(i){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!i&&r==o&&ug(e,r);i&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let f=new Un(e,{simulateBreak:r,simulateDoubleBreak:!!a}),c=Fr(f,r);for(c==null&&(c=y.countColumn(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let p=["",Mi(e,c)];return a&&p.push(Mi(e,f.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:y.Text.of(p)},range:y.EditorSelection.cursor(r+1+p[1].length)}});return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function qr(i,e){let t=-1;return i.changeByRange(n=>{let s=[];for(let o=n.from;o<=n.to;){let l=i.doc.lineAt(o);l.number>t&&(n.empty||n.to>l.from)&&(e(l,s,n),t=l.number),o=l.to+1}let r=i.changes(s);return{changes:s,range:y.EditorSelection.range(r.mapPos(n.anchor,1),r.mapPos(n.head,1))}})}const pg=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let t=Object.create(null),n=new Un(i,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=qr(i,(r,o,l)=>{let a=Fr(n,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let f=/^\s*/.exec(r.text)[0],c=Mi(i,a);(f!=c||l.from<r.from+f.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+f.length,insert:c}))});return s.changes.empty||e(i.update(s,{userEvent:"indent"})),!0},fc=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(qr(i,(t,n)=>{n.push({from:t.from,insert:i.facet(Xt)})}),{userEvent:"input.indent"})),!0),uc=({state:i,dispatch:e})=>i.readOnly?!1:(e(i.update(qr(i,(t,n)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=y.countColumn(s,i.tabSize),o=0,l=Mi(i,Math.max(0,r-Rn(i)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;n.push({from:t.from+o,to:t.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),mg=i=>(i.setTabFocusMode(),!0),gg=[{key:"Ctrl-b",run:zh,shift:Xh,preventDefault:!0},{key:"Ctrl-f",run:qh,shift:Qh},{key:"Ctrl-p",run:Kh,shift:tc},{key:"Ctrl-n",run:Jh,shift:ic},{key:"Ctrl-a",run:Fm,shift:Ym},{key:"Ctrl-e",run:Vm,shift:Gm},{key:"Ctrl-d",run:rc},{key:"Ctrl-h",run:dr},{key:"Ctrl-k",run:ig},{key:"Ctrl-Alt-h",run:lc},{key:"Ctrl-o",run:rg},{key:"Ctrl-t",run:og},{key:"Ctrl-v",run:ur}],yg=[{key:"ArrowLeft",run:zh,shift:Xh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Tm,shift:$m,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Im,shift:Jm,preventDefault:!0},{key:"ArrowRight",run:qh,shift:Qh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Om,shift:zm,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Nm,shift:Um,preventDefault:!0},{key:"ArrowUp",run:Kh,shift:tc,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Cl,shift:Ml},{mac:"Ctrl-ArrowUp",run:xl,shift:wl},{key:"ArrowDown",run:Jh,shift:ic,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Al,shift:El},{mac:"Ctrl-ArrowDown",run:ur,shift:kl},{key:"PageUp",run:xl,shift:wl},{key:"PageDown",run:ur,shift:kl},{key:"Home",run:Lm,shift:Km,preventDefault:!0},{key:"Mod-Home",run:Cl,shift:Ml},{key:"End",run:Bm,shift:_m,preventDefault:!0},{key:"Mod-End",run:Al,shift:El},{key:"Enter",run:Tl,shift:Tl},{key:"Mod-a",run:Xm},{key:"Backspace",run:dr,shift:dr},{key:"Delete",run:rc},{key:"Mod-Backspace",mac:"Alt-Backspace",run:lc},{key:"Mod-Delete",mac:"Alt-Delete",run:tg},{mac:"Mod-Backspace",run:ng},{mac:"Mod-Delete",run:sg}].concat(gg.map(i=>({mac:i.key,run:i.run,shift:i.shift}))),bg=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Pm,shift:qm},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Rm,shift:jm},{key:"Alt-ArrowUp",run:lg},{key:"Shift-Alt-ArrowUp",run:hg},{key:"Alt-ArrowDown",run:ag},{key:"Shift-Alt-ArrowDown",run:cg},{key:"Escape",run:eg},{key:"Mod-Enter",run:dg},{key:"Alt-l",mac:"Ctrl-l",run:Qm},{key:"Mod-i",run:Zm,preventDefault:!0},{key:"Mod-[",run:uc},{key:"Mod-]",run:fc},{key:"Mod-Alt-\\",run:pg},{key:"Shift-Mod-k",run:fg},{key:"Shift-Mod-\\",run:Wm},{key:"Mod-/",run:hm},{key:"Alt-A",run:fm},{key:"Ctrl-m",mac:"Shift-Alt-m",run:mg}].concat(yg),Sg={key:"Tab",run:fc,shift:uc},Tb=()=>i=>{try{JSON.parse(i.state.doc.toString())}catch(e){if(!(e instanceof SyntaxError))throw e;const t=vg(e,i.state.doc);return[{from:t,message:e.message,severity:"error",to:t}]}return[]};function vg(i,e){let t;return(t=i.message.match(/at position (\d+)/))?Math.min(+t[1],e.length):(t=i.message.match(/at line (\d+) column (\d+)/))?Math.min(e.line(+t[1]).from+ +t[2]-1,e.length):0}const xg=Kt.define({name:"json",parser:Pf.configure({props:[Yn.add({Object:vi({except:/^\s*\}/}),Array:vi({except:/^\s*\]/})}),Gn.add({"Object Array":Hr})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function Ob(){return new Nr(xg)}class Ol{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}}class bt{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(e,t,n){let s=n.facet(Qe).markerFilter;s&&(e=s(e,n));let r=e.slice().sort((c,p)=>c.from-p.from||c.to-p.to),o=new y.RangeSetBuilder,l=[],a=0;for(let c=0;;){let p=c==r.length?null:r[c];if(!p&&!l.length)break;let g,v;for(l.length?(g=a,v=l.reduce((C,M)=>Math.min(C,M.to),p&&p.from>g?p.from:1e8)):(g=p.from,v=p.to,l.push(p),c++);c<r.length;){let C=r[c];if(C.from==g&&(C.to>C.from||C.to==g))l.push(C),c++,v=Math.min(C.to,v);else{v=Math.min(C.from,v);break}}let k=Ng(l);if(l.some(C=>C.from==C.to||C.from==C.to-1&&n.doc.lineAt(C.from).to==C.from))o.add(g,g,H.widget({widget:new Rg(k),diagnostics:l.slice()}));else{let C=l.reduce((M,T)=>T.markClass?M+" "+T.markClass:M,"");o.add(g,v,H.mark({class:"cm-lintRange cm-lintRange-"+k+C,diagnostics:l.slice(),inclusiveEnd:l.some(M=>M.to>v)}))}a=v;for(let C=0;C<l.length;C++)l[C].to<=a&&l.splice(C--,1)}let f=o.finish();return new bt(f,t,Ut(f))}}function Ut(i,e=null,t=0){let n=null;return i.between(t,1e9,(s,r,{spec:o})=>{if(!(e&&o.diagnostics.indexOf(e)<0))if(!n)n=new Ol(s,r,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(n.diagnostic)<0)return!1;n=new Ol(n.from,r,n.diagnostic)}}),n}function wg(i,e){let t=e.pos,n=e.end||t,s=i.state.facet(Qe).hideOn(i,t,n);if(s!=null)return s;let r=i.startState.doc.lineAt(e.pos);return!!(i.effects.some(o=>o.is(jr))||i.changes.touchesRange(r.from,Math.max(r.to,n)))}function dc(i,e){return i.field(Ie,!1)?e:e.concat(y.StateEffect.appendConfig.of(yc))}function kg(i,e){return{effects:dc(i,[jr.of(e)])}}const jr=y.StateEffect.define(),_r=y.StateEffect.define(),pc=y.StateEffect.define(),Ie=y.StateField.define({create(){return new bt(H.none,null,null)},update(i,e){if(e.docChanged&&i.diagnostics.size){let t=i.diagnostics.map(e.changes),n=null,s=i.panel;if(i.selected){let r=e.changes.mapPos(i.selected.from,1);n=Ut(t,i.selected.diagnostic,r)||Ut(t,null,r)}!t.size&&s&&e.state.facet(Qe).autoPanel&&(s=null),i=new bt(t,s,n)}for(let t of e.effects)if(t.is(jr)){let n=e.state.facet(Qe).autoPanel?t.value.length?Ei.open:null:i.panel;i=bt.init(t.value,n,e.state)}else t.is(_r)?i=new bt(i.diagnostics,t.value?Ei.open:null,i.selected):t.is(pc)&&(i=new bt(i.diagnostics,i.panel,t.value));return i},provide:i=>[Ai.from(i,e=>e.panel),N.decorations.from(i,e=>e.diagnostics)]}),Cg=H.mark({class:"cm-lintRange cm-lintRange-active"});function Ag(i,e,t){let{diagnostics:n}=i.state.field(Ie),s,r=-1,o=-1;n.between(e-(t<0?1:0),e+(t>0?1:0),(a,f,{spec:c})=>{if(e>=a&&e<=f&&(a==f||(e>a||t>0)&&(e<f||t<0)))return s=c.diagnostics,r=a,o=f,!1});let l=i.state.facet(Qe).tooltipFilter;return s&&l&&(s=l(s,i.state)),s?{pos:r,end:o,above:i.state.doc.lineAt(r).to<o,create(){return{dom:Mg(i,s)}}}:null}function Mg(i,e){return Y("ul",{class:"cm-tooltip-lint"},e.map(t=>gc(i,t,!1)))}const Eg=i=>{let e=i.state.field(Ie,!1);(!e||!e.panel)&&i.dispatch({effects:dc(i.state,[_r.of(!0)])});let t=Ci(i,Ei.open);return t&&t.dom.querySelector(".cm-panel-lint ul").focus(),!0},Dl=i=>{let e=i.state.field(Ie,!1);return!e||!e.panel?!1:(i.dispatch({effects:_r.of(!1)}),!0)},Tg=i=>{let e=i.state.field(Ie,!1);if(!e)return!1;let t=i.state.selection.main,n=e.diagnostics.iter(t.to+1);return!n.value&&(n=e.diagnostics.iter(0),!n.value||n.from==t.from&&n.to==t.to)?!1:(i.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),!0)},Og=[{key:"Mod-Shift-m",run:Eg,preventDefault:!0},{key:"F8",run:Tg}],Dg=se.fromClass(class{constructor(i){this.view=i,this.timeout=-1,this.set=!0;let{delay:e}=i.state.facet(Qe);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let i=Date.now();if(i<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-i);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(Qe);t.length&&Pg(t.map(n=>Promise.resolve(n(this.view))),n=>{this.view.state.doc==e.doc&&this.view.dispatch(kg(this.view.state,n.reduce((s,r)=>s.concat(r))))},n=>{Me(this.view.state,n)})}}update(i){let e=i.state.facet(Qe);(i.docChanged||e!=i.startState.facet(Qe)||e.needsRefresh&&e.needsRefresh(i))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function Pg(i,e,t){let n=[],s=-1;for(let r of i)r.then(o=>{n.push(o),clearTimeout(s),n.length==i.length?e(n):s=setTimeout(()=>e(n),200)},t)}const Qe=y.Facet.define({combine(i){return Object.assign({sources:i.map(e=>e.source).filter(e=>e!=null)},y.combineConfig(i.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(e,t)=>e?t?n=>e(n)||t(n):e:t}))}});function Db(i,e={}){return[Qe.of({source:i,config:e}),Dg,yc]}function mc(i){let e=[];if(i)e:for(let{name:t}of i){for(let n=0;n<t.length;n++){let s=t[n];if(/[a-zA-Z]/.test(s)&&!e.some(r=>r.toLowerCase()==s.toLowerCase())){e.push(s);continue e}}e.push("")}return e}function gc(i,e,t){var n;let s=t?mc(e.actions):[];return Y("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Y("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(i):e.message),(n=e.actions)===null||n===void 0?void 0:n.map((r,o)=>{let l=!1,a=g=>{if(g.preventDefault(),l)return;l=!0;let v=Ut(i.state.field(Ie).diagnostics,e);v&&r.apply(i,v.from,v.to)},{name:f}=r,c=s[o]?f.indexOf(s[o]):-1,p=c<0?f:[f.slice(0,c),Y("u",f.slice(c,c+1)),f.slice(c+1)];return Y("button",{type:"button",class:"cm-diagnosticAction",onclick:a,onmousedown:a,"aria-label":` Action: ${f}${c<0?"":` (access key "${s[o]})"`}.`},p)}),e.source&&Y("div",{class:"cm-diagnosticSource"},e.source))}class Rg extends je{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return Y("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class Pl{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=gc(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Ei{constructor(e){this.view=e,this.items=[];let t=s=>{if(s.keyCode==27)Dl(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=mc(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==s.keyCode){let a=Ut(this.view.state.field(Ie).diagnostics,r);a&&r.actions[l].apply(e,a.from,a.to)}}else return;s.preventDefault()},n=s=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(s.target)&&this.moveSelection(r)};this.list=Y("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:n}),this.dom=Y("div",{class:"cm-panel-lint"},this.list,Y("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Dl(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Ie).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Ie),n=0,s=!1,r=null,o=new Set;for(e.between(0,this.view.state.doc.length,(l,a,{spec:f})=>{for(let c of f.diagnostics){if(o.has(c))continue;o.add(c);let p=-1,g;for(let v=n;v<this.items.length;v++)if(this.items[v].diagnostic==c){p=v;break}p<0?(g=new Pl(this.view,c),this.items.splice(n,0,g),s=!0):(g=this.items[p],p>n&&(this.items.splice(n,p-n),s=!0)),t&&g.diagnostic==t.diagnostic?g.dom.hasAttribute("aria-selected")||(g.dom.setAttribute("aria-selected","true"),r=g):g.dom.hasAttribute("aria-selected")&&g.dom.removeAttribute("aria-selected"),n++}});n<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new Pl(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:a})=>{let f=a.height/this.list.offsetHeight;l.top<a.top?this.list.scrollTop-=(a.top-l.top)/f:l.bottom>a.bottom&&(this.list.scrollTop+=(l.bottom-a.bottom)/f)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function t(){let n=e;e=n.nextSibling,n.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;e!=n.dom;)t();e=n.dom.nextSibling}else this.list.insertBefore(n.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(Ie),n=Ut(t.diagnostics,this.items[e].diagnostic);n&&this.view.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0,effects:pc.of(n)})}static open(e){return new Ei(e)}}function Bg(i,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(i)}</svg>')`}function ln(i){return Bg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${i}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Lg=N.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:ln("#d11")},".cm-lintRange-warning":{backgroundImage:ln("orange")},".cm-lintRange-info":{backgroundImage:ln("#999")},".cm-lintRange-hint":{backgroundImage:ln("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function Ig(i){return i=="error"?4:i=="warning"?3:i=="info"?2:1}function Ng(i){let e="hint",t=1;for(let n of i){let s=Ig(n.severity);s>t&&(t=s,e=n.severity)}return e}const yc=[Ie,N.decorations.compute([Ie],i=>{let{selected:e,panel:t}=i.field(Ie);return!e||!t||e.from==e.to?H.none:H.set([Cg.range(e.from,e.to)])}),op(Ag,{hideOn:wg}),Lg];var bc=i=>{var{theme:e,settings:t={},styles:n=[]}=i,s={".cm-gutters":{}},r={};t.background&&(r.backgroundColor=t.background),t.backgroundImage&&(r.backgroundImage=t.backgroundImage),t.foreground&&(r.color=t.foreground),t.fontSize&&(r.fontSize=t.fontSize),(t.background||t.foreground)&&(s["&"]=r),t.fontFamily&&(s["&.cm-editor .cm-scroller"]={fontFamily:t.fontFamily}),t.gutterBackground&&(s[".cm-gutters"].backgroundColor=t.gutterBackground),t.gutterForeground&&(s[".cm-gutters"].color=t.gutterForeground),t.gutterBorder&&(s[".cm-gutters"].borderRightColor=t.gutterBorder),t.caret&&(s[".cm-content"]={caretColor:t.caret},s[".cm-cursor, .cm-dropCursor"]={borderLeftColor:t.caret});var o={};t.gutterActiveForeground&&(o.color=t.gutterActiveForeground),t.lineHighlight&&(s[".cm-activeLine"]={backgroundColor:t.lineHighlight},o.backgroundColor=t.lineHighlight),s[".cm-activeLineGutter"]=o,t.selection&&(s["&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection"]={background:t.selection+" !important"}),t.selectionMatch&&(s["& .cm-selectionMatch"]={backgroundColor:t.selectionMatch});var l=N.theme(s,{dark:e==="dark"}),a=Qt.define(n),f=[l,Wr(a)];return f},Fg={background:"#fff",foreground:"#24292e",selection:"#BBDFFF",selectionMatch:"#BBDFFF",gutterBackground:"#fff",gutterForeground:"#6e7781"},Vg=[{tag:[E.standard(E.tagName),E.tagName],color:"#116329"},{tag:[E.comment,E.bracket],color:"#6a737d"},{tag:[E.className,E.propertyName],color:"#6f42c1"},{tag:[E.variableName,E.attributeName,E.number,E.operator],color:"#005cc5"},{tag:[E.keyword,E.typeName,E.typeOperator,E.typeName],color:"#d73a49"},{tag:[E.string,E.meta,E.regexp],color:"#032f62"},{tag:[E.name,E.quote],color:"#22863a"},{tag:[E.heading,E.strong],color:"#24292e",fontWeight:"bold"},{tag:[E.emphasis],color:"#24292e",fontStyle:"italic"},{tag:[E.deleted],color:"#b31d28",backgroundColor:"ffeef0"},{tag:[E.atom,E.bool,E.special(E.variableName)],color:"#e36209"},{tag:[E.url,E.escape,E.regexp,E.link],color:"#032f62"},{tag:E.link,textDecoration:"underline"},{tag:E.strikethrough,textDecoration:"line-through"},{tag:E.invalid,color:"#cb2431"}],Hg=i=>{var{theme:e="light",settings:t={},styles:n=[]}={};return bc({theme:e,settings:wr({},Fg,t),styles:[...Vg,...n]})},Pb=Hg(),Wg={background:"#0d1117",foreground:"#c9d1d9",caret:"#c9d1d9",selection:"#003d73",selectionMatch:"#003d73",lineHighlight:"#36334280"},$g=[{tag:[E.standard(E.tagName),E.tagName],color:"#7ee787"},{tag:[E.comment,E.bracket],color:"#8b949e"},{tag:[E.className,E.propertyName],color:"#d2a8ff"},{tag:[E.variableName,E.attributeName,E.number,E.operator],color:"#79c0ff"},{tag:[E.keyword,E.typeName,E.typeOperator,E.typeName],color:"#ff7b72"},{tag:[E.string,E.meta,E.regexp],color:"#a5d6ff"},{tag:[E.name,E.quote],color:"#7ee787"},{tag:[E.heading,E.strong],color:"#d2a8ff",fontWeight:"bold"},{tag:[E.emphasis],color:"#d2a8ff",fontStyle:"italic"},{tag:[E.deleted],color:"#ffdcd7",backgroundColor:"ffeef0"},{tag:[E.atom,E.bool,E.special(E.variableName)],color:"#ffab70"},{tag:E.link,textDecoration:"underline"},{tag:E.strikethrough,textDecoration:"line-through"},{tag:E.invalid,color:"#f97583"}],zg=i=>{var{theme:e="dark",settings:t={},styles:n=[]}={};return bc({theme:e,settings:wr({},Wg,t),styles:[...$g,...n]})},Rb=zg();const Rl=typeof String.prototype.normalize=="function"?i=>i.normalize("NFKD"):i=>i;class Yt{constructor(e,t,n=0,s=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,s),this.bufferStart=n,this.normalize=r?l=>r(Rl(l)):Rl,this.query=this.normalize(t)}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 y.codePointAt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=y.fromCodePoint(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=y.codePointSize(e);let s=this.normalize(t);for(let r=0,o=n;;r++){let l=s.charCodeAt(r),a=this.match(l,o,this.bufferPos+this.bufferStart);if(r==s.length-1){if(a)return this.value=a,this;break}o==n&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t,n){let s=null;for(let r=0;r<this.matches.length;r+=2){let o=this.matches[r],l=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?s={from:this.matches[r+1],to:n}:(this.matches[r]++,l=!0)),l||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?s={from:t,to:n}:this.matches.push(1,t)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Yt.prototype[Symbol.iterator]=function(){return this});const Sc={from:-1,to:-1,match:/.*/.exec("")},Kr="gm"+(/x/.unicode==null?"":"u");class vc{constructor(e,t,n,s=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=Sc,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new xc(e,t,n,s,r);this.re=new RegExp(t,Kr+(n!=null&&n.ignoreCase?"i":"")),this.test=n==null?void 0:n.test,this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=Nn(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.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 e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,s=n+t[0].length;if(this.matchPos=Nn(this.text,s+(n==s?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<s||n>this.value.to)&&(!this.test||this.test(n,s,t)))return this.value={from:n,to:s,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const Ps=new WeakMap;class Ht{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,n){let s=Ps.get(e);if(!s||s.from>=n||s.to<=t){let l=new Ht(t,e.sliceString(t,n));return Ps.set(e,l),l}if(s.from==t&&s.to==n)return s;let{text:r,from:o}=s;return o>t&&(r=e.sliceString(t,o)+r,o=t),s.to<n&&(r+=e.sliceString(s.to,n)),Ps.set(e,new Ht(o,r)),new Ht(t,r.slice(t-o,n-o))}}class xc{constructor(e,t,n,s,r){this.text=e,this.to=r,this.done=!1,this.value=Sc,this.matchPos=Nn(e,s),this.re=new RegExp(t,Kr+(n!=null&&n.ignoreCase?"i":"")),this.test=n==null?void 0:n.test,this.flat=Ht.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let n=this.flat.from+t.index,s=n+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(n,s,t)))return this.value={from:n,to:s,match:t},this.matchPos=Nn(this.text,s+(n==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Ht.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(vc.prototype[Symbol.iterator]=xc.prototype[Symbol.iterator]=function(){return this});function qg(i){try{return new RegExp(i,Kr),!0}catch{return!1}}function Nn(i,e){if(e>=i.length)return e;let t=i.lineAt(e),n;for(;e<t.to&&(n=t.text.charCodeAt(e-t.from))>=56320&&n<57344;)e++;return e}function pr(i){let e=String(i.state.doc.lineAt(i.state.selection.main.head).number),t=Y("input",{class:"cm-textfield",name:"line",value:e}),n=Y("form",{class:"cm-gotoLine",onkeydown:r=>{r.keyCode==27?(r.preventDefault(),i.dispatch({effects:Fn.of(!1)}),i.focus()):r.keyCode==13&&(r.preventDefault(),s())},onsubmit:r=>{r.preventDefault(),s()}},Y("label",i.state.phrase("Go to line"),": ",t)," ",Y("button",{class:"cm-button",type:"submit"},i.state.phrase("go")));function s(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(t.value);if(!r)return;let{state:o}=i,l=o.doc.lineAt(o.selection.main.head),[,a,f,c,p]=r,g=c?+c.slice(1):0,v=f?+f:l.number;if(f&&p){let M=v/100;a&&(M=M*(a=="-"?-1:1)+l.number/o.doc.lines),v=Math.round(o.doc.lines*M)}else f&&a&&(v=v*(a=="-"?-1:1)+l.number);let k=o.doc.line(Math.max(1,Math.min(o.doc.lines,v))),C=y.EditorSelection.cursor(k.from+Math.max(0,Math.min(g,k.length)));i.dispatch({effects:[Fn.of(!1),N.scrollIntoView(C.from,{y:"center"})],selection:C}),i.focus()}return{dom:n}}const Fn=y.StateEffect.define(),Bl=y.StateField.define({create(){return!0},update(i,e){for(let t of e.effects)t.is(Fn)&&(i=t.value);return i},provide:i=>Ai.from(i,e=>e?pr:null)}),jg=i=>{let e=Ci(i,pr);if(!e){let t=[Fn.of(!0)];i.state.field(Bl,!1)==null&&t.push(y.StateEffect.appendConfig.of([Bl,_g])),i.dispatch({effects:t}),e=Ci(i,pr)}return e&&e.dom.querySelector("input").select(),!0},_g=N.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Kg={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Jg=y.Facet.define({combine(i){return y.combineConfig(i,Kg,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Ug(i){return[Zg,Qg]}const Yg=H.mark({class:"cm-selectionMatch"}),Gg=H.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Ll(i,e,t,n){return(t==0||i(e.sliceDoc(t-1,t))!=y.CharCategory.Word)&&(n==e.doc.length||i(e.sliceDoc(n,n+1))!=y.CharCategory.Word)}function Xg(i,e,t,n){return i(e.sliceDoc(t,t+1))==y.CharCategory.Word&&i(e.sliceDoc(n-1,n))==y.CharCategory.Word}const Qg=se.fromClass(class{constructor(i){this.decorations=this.getDeco(i)}update(i){(i.selectionSet||i.docChanged||i.viewportChanged)&&(this.decorations=this.getDeco(i.view))}getDeco(i){let e=i.state.facet(Jg),{state:t}=i,n=t.selection;if(n.ranges.length>1)return H.none;let s=n.main,r,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return H.none;let a=t.wordAt(s.head);if(!a)return H.none;o=t.charCategorizer(s.head),r=t.sliceDoc(a.from,a.to)}else{let a=s.to-s.from;if(a<e.minSelectionLength||a>200)return H.none;if(e.wholeWords){if(r=t.sliceDoc(s.from,s.to),o=t.charCategorizer(s.head),!(Ll(o,t,s.from,s.to)&&Xg(o,t,s.from,s.to)))return H.none}else if(r=t.sliceDoc(s.from,s.to),!r)return H.none}let l=[];for(let a of i.visibleRanges){let f=new Yt(t.doc,r,a.from,a.to);for(;!f.next().done;){let{from:c,to:p}=f.value;if((!o||Ll(o,t,c,p))&&(s.empty&&c<=s.from&&p>=s.to?l.push(Gg.range(c,p)):(c>=s.to||p<=s.from)&&l.push(Yg.range(c,p)),l.length>e.maxMatches))return H.none}}return H.set(l)}},{decorations:i=>i.decorations}),Zg=N.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),e0=({state:i,dispatch:e})=>{let{selection:t}=i,n=y.EditorSelection.create(t.ranges.map(s=>i.wordAt(s.head)||y.EditorSelection.cursor(s.head)),t.mainIndex);return n.eq(t)?!1:(e(i.update({selection:n})),!0)};function t0(i,e){let{main:t,ranges:n}=i.selection,s=i.wordAt(t.head),r=s&&s.from==t.from&&s.to==t.to;for(let o=!1,l=new Yt(i.doc,e,n[n.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Yt(i.doc,e,0,Math.max(0,n[n.length-1].from-1)),o=!0}else{if(o&&n.some(a=>a.from==l.value.from))continue;if(r){let a=i.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const i0=({state:i,dispatch:e})=>{let{ranges:t}=i.selection;if(t.some(r=>r.from===r.to))return e0({state:i,dispatch:e});let n=i.sliceDoc(t[0].from,t[0].to);if(i.selection.ranges.some(r=>i.sliceDoc(r.from,r.to)!=n))return!1;let s=t0(i,n);return s?(e(i.update({selection:i.selection.addRange(y.EditorSelection.range(s.from,s.to),!1),effects:N.scrollIntoView(s.to)})),!0):!1},ei=y.Facet.define({combine(i){return y.combineConfig(i,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new p0(e),scrollToMatch:e=>N.scrollIntoView(e)})}});class wc{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||qg(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,n)=>n=="n"?`
|
|
11
|
-
`:n=="r"?"\r":n=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new o0(this):new s0(this)}getCursor(e,t=0,n){let s=e.doc?e:y.EditorState.create({doc:e});return n==null&&(n=s.doc.length),this.regexp?Dt(this,s,t,n):Ot(this,s,t,n)}}class kc{constructor(e){this.spec=e}}function Ot(i,e,t,n){return new Yt(e.doc,i.unquoted,t,n,i.caseSensitive?void 0:s=>s.toLowerCase(),i.wholeWord?n0(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function n0(i,e){return(t,n,s,r)=>((r>t||r+s.length<n)&&(r=Math.max(0,t-2),s=i.sliceString(r,Math.min(i.length,n+2))),(e(Vn(s,t-r))!=y.CharCategory.Word||e(Hn(s,t-r))!=y.CharCategory.Word)&&(e(Hn(s,n-r))!=y.CharCategory.Word||e(Vn(s,n-r))!=y.CharCategory.Word))}class s0 extends kc{constructor(e){super(e)}nextMatch(e,t,n){let s=Ot(this.spec,e,n,e.doc.length).nextOverlapping();return s.done&&(s=Ot(this.spec,e,0,t).nextOverlapping()),s.done?null:s.value}prevMatchInRange(e,t,n){for(let s=n;;){let r=Math.max(t,s-1e4-this.spec.unquoted.length),o=Ot(this.spec,e,r,s),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;s-=1e4}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=Ot(this.spec,e,0,e.doc.length),s=[];for(;!n.next().done;){if(s.length>=t)return null;s.push(n.value)}return s}highlight(e,t,n,s){let r=Ot(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function Dt(i,e,t,n){return new vc(e.doc,i.search,{ignoreCase:!i.caseSensitive,test:i.wholeWord?r0(e.charCategorizer(e.selection.main.head)):void 0},t,n)}function Vn(i,e){return i.slice(y.findClusterBreak(i,e,!1),e)}function Hn(i,e){return i.slice(e,y.findClusterBreak(i,e))}function r0(i){return(e,t,n)=>!n[0].length||(i(Vn(n.input,n.index))!=y.CharCategory.Word||i(Hn(n.input,n.index))!=y.CharCategory.Word)&&(i(Hn(n.input,n.index+n[0].length))!=y.CharCategory.Word||i(Vn(n.input,n.index+n[0].length))!=y.CharCategory.Word)}class o0 extends kc{nextMatch(e,t,n){let s=Dt(this.spec,e,n,e.doc.length).next();return s.done&&(s=Dt(this.spec,e,0,t).next()),s.done?null:s.value}prevMatchInRange(e,t,n){for(let s=1;;s++){let r=Math.max(t,n-s*1e4),o=Dt(this.spec,e,r,n),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,(t,n)=>n=="$"?"$":n=="&"?e.match[0]:n!="0"&&+n<e.match.length?e.match[n]:t)}matchAll(e,t){let n=Dt(this.spec,e,0,e.doc.length),s=[];for(;!n.next().done;){if(s.length>=t)return null;s.push(n.value)}return s}highlight(e,t,n,s){let r=Dt(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const Ti=y.StateEffect.define(),Jr=y.StateEffect.define(),ct=y.StateField.define({create(i){return new Rs(mr(i).create(),null)},update(i,e){for(let t of e.effects)t.is(Ti)?i=new Rs(t.value.create(),i.panel):t.is(Jr)&&(i=new Rs(i.query,t.value?Ur:null));return i},provide:i=>Ai.from(i,e=>e.panel)});class Rs{constructor(e,t){this.query=e,this.panel=t}}const l0=H.mark({class:"cm-searchMatch"}),a0=H.mark({class:"cm-searchMatch cm-searchMatch-selected"}),h0=se.fromClass(class{constructor(i){this.view=i,this.decorations=this.highlight(i.state.field(ct))}update(i){let e=i.state.field(ct);(e!=i.startState.field(ct)||i.docChanged||i.selectionSet||i.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:i,panel:e}){if(!e||!i.spec.valid)return H.none;let{view:t}=this,n=new y.RangeSetBuilder;for(let s=0,r=t.visibleRanges,o=r.length;s<o;s++){let{from:l,to:a}=r[s];for(;s<o-1&&a>r[s+1].from-500;)a=r[++s].to;i.highlight(t.state,l,a,(f,c)=>{let p=t.state.selection.ranges.some(g=>g.from==f&&g.to==c);n.add(f,c,p?a0:l0)})}return n.finish()}},{decorations:i=>i.decorations});function Wi(i){return e=>{let t=e.state.field(ct,!1);return t&&t.query.spec.valid?i(e,t):Mc(e)}}const Wn=Wi((i,{query:e})=>{let{to:t}=i.state.selection.main,n=e.nextMatch(i.state,t,t);if(!n)return!1;let s=y.EditorSelection.single(n.from,n.to),r=i.state.facet(ei);return i.dispatch({selection:s,effects:[Yr(i,n),r.scrollToMatch(s.main,i)],userEvent:"select.search"}),Ac(i),!0}),$n=Wi((i,{query:e})=>{let{state:t}=i,{from:n}=t.selection.main,s=e.prevMatch(t,n,n);if(!s)return!1;let r=y.EditorSelection.single(s.from,s.to),o=i.state.facet(ei);return i.dispatch({selection:r,effects:[Yr(i,s),o.scrollToMatch(r.main,i)],userEvent:"select.search"}),Ac(i),!0}),c0=Wi((i,{query:e})=>{let t=e.matchAll(i.state,1e3);return!t||!t.length?!1:(i.dispatch({selection:y.EditorSelection.create(t.map(n=>y.EditorSelection.range(n.from,n.to))),userEvent:"select.search.matches"}),!0)}),f0=({state:i,dispatch:e})=>{let t=i.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:n,to:s}=t.main,r=[],o=0;for(let l=new Yt(i.doc,i.sliceDoc(n,s));!l.next().done;){if(r.length>1e3)return!1;l.value.from==n&&(o=r.length),r.push(y.EditorSelection.range(l.value.from,l.value.to))}return e(i.update({selection:y.EditorSelection.create(r,o),userEvent:"select.search.matches"})),!0},Il=Wi((i,{query:e})=>{let{state:t}=i,{from:n,to:s}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,n,n);if(!r)return!1;let o=[],l,a,f=[];if(r.from==n&&r.to==s&&(a=t.toText(e.getReplacement(r)),o.push({from:r.from,to:r.to,insert:a}),r=e.nextMatch(t,r.from,r.to),f.push(N.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(n).number)+"."))),r){let c=o.length==0||o[0].from>=r.to?0:r.to-r.from-a.length;l=y.EditorSelection.single(r.from-c,r.to-c),f.push(Yr(i,r)),f.push(t.facet(ei).scrollToMatch(l.main,i))}return i.dispatch({changes:o,selection:l,effects:f,userEvent:"input.replace"}),!0}),u0=Wi((i,{query:e})=>{if(i.state.readOnly)return!1;let t=e.matchAll(i.state,1e9).map(s=>{let{from:r,to:o}=s;return{from:r,to:o,insert:e.getReplacement(s)}});if(!t.length)return!1;let n=i.state.phrase("replaced $ matches",t.length)+".";return i.dispatch({changes:t,effects:N.announce.of(n),userEvent:"input.replace.all"}),!0});function Ur(i){return i.state.facet(ei).createPanel(i)}function mr(i,e){var t,n,s,r,o;let l=i.selection.main,a=l.empty||l.to>l.from+100?"":i.sliceDoc(l.from,l.to);if(e&&!a)return e;let f=i.facet(ei);return new wc({search:((t=e==null?void 0:e.literal)!==null&&t!==void 0?t:f.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(n=e==null?void 0:e.caseSensitive)!==null&&n!==void 0?n:f.caseSensitive,literal:(s=e==null?void 0:e.literal)!==null&&s!==void 0?s:f.literal,regexp:(r=e==null?void 0:e.regexp)!==null&&r!==void 0?r:f.regexp,wholeWord:(o=e==null?void 0:e.wholeWord)!==null&&o!==void 0?o:f.wholeWord})}function Cc(i){let e=Ci(i,Ur);return e&&e.dom.querySelector("[main-field]")}function Ac(i){let e=Cc(i);e&&e==i.root.activeElement&&e.select()}const Mc=i=>{let e=i.state.field(ct,!1);if(e&&e.panel){let t=Cc(i);if(t&&t!=i.root.activeElement){let n=mr(i.state,e.query.spec);n.valid&&i.dispatch({effects:Ti.of(n)}),t.focus(),t.select()}}else i.dispatch({effects:[Jr.of(!0),e?Ti.of(mr(i.state,e.query.spec)):y.StateEffect.appendConfig.of(g0)]});return!0},Ec=i=>{let e=i.state.field(ct,!1);if(!e||!e.panel)return!1;let t=Ci(i,Ur);return t&&t.dom.contains(i.root.activeElement)&&i.focus(),i.dispatch({effects:Jr.of(!1)}),!0},d0=[{key:"Mod-f",run:Mc,scope:"editor search-panel"},{key:"F3",run:Wn,shift:$n,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Wn,shift:$n,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Ec,scope:"editor search-panel"},{key:"Mod-Shift-l",run:f0},{key:"Mod-Alt-g",run:jg},{key:"Mod-d",run:i0,preventDefault:!0}];class p0{constructor(e){this.view=e;let t=this.query=e.state.field(ct).query.spec;this.commit=this.commit.bind(this),this.searchField=Y("input",{value:t.search,placeholder:Re(e,"Find"),"aria-label":Re(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Y("input",{value:t.replace,placeholder:Re(e,"Replace"),"aria-label":Re(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Y("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=Y("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=Y("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function n(s,r,o){return Y("button",{class:"cm-button",name:s,onclick:r,type:"button"},o)}this.dom=Y("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,n("next",()=>Wn(e),[Re(e,"next")]),n("prev",()=>$n(e),[Re(e,"previous")]),n("select",()=>c0(e),[Re(e,"all")]),Y("label",null,[this.caseField,Re(e,"match case")]),Y("label",null,[this.reField,Re(e,"regexp")]),Y("label",null,[this.wordField,Re(e,"by word")]),...e.state.readOnly?[]:[Y("br"),this.replaceField,n("replace",()=>Il(e),[Re(e,"replace")]),n("replaceAll",()=>u0(e),[Re(e,"replace all")])],Y("button",{name:"close",onclick:()=>Ec(e),"aria-label":Re(e,"close"),type:"button"},["×"])])}commit(){let e=new wc({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Ti.of(e)}))}keydown(e){bd(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?$n:Wn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Il(this.view))}update(e){for(let t of e.transactions)for(let n of t.effects)n.is(Ti)&&!n.value.eq(this.query)&&this.setQuery(n.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(ei).top}}function Re(i,e){return i.state.phrase(e)}const an=30,hn=/[\s\.,:;?!]/;function Yr(i,{from:e,to:t}){let n=i.state.doc.lineAt(e),s=i.state.doc.lineAt(t).to,r=Math.max(n.from,e-an),o=Math.min(s,t+an),l=i.state.sliceDoc(r,o);if(r!=n.from){for(let a=0;a<an;a++)if(!hn.test(l[a+1])&&hn.test(l[a])){l=l.slice(a);break}}if(o!=s){for(let a=l.length-1;a>l.length-an;a--)if(!hn.test(l[a-1])&&hn.test(l[a])){l=l.slice(0,a);break}}return N.announce.of(`${i.state.phrase("current match")}. ${l} ${i.state.phrase("on line")} ${n.number}.`)}const m0=N.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"}}),g0=[ct,y.Prec.low(h0),m0];class Tc{constructor(e,t,n){this.state=e,this.pos=t,this.explicit=n,this.abortListeners=[]}tokenBefore(e){let t=te(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),n=Math.max(t.from,this.pos-250),s=t.text.slice(n-t.from,this.pos-t.from),r=s.search(Dc(e,!1));return r<0?null:{from:n+r,to:this.pos,text:s.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t){e=="abort"&&this.abortListeners&&this.abortListeners.push(t)}}function Nl(i){let e=Object.keys(i).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function y0(i){let e=Object.create(null),t=Object.create(null);for(let{label:s}of i){e[s[0]]=!0;for(let r=1;r<s.length;r++)t[s[r]]=!0}let n=Nl(e)+Nl(t)+"*$";return[new RegExp("^"+n),new RegExp(n)]}function Gr(i){let e=i.map(s=>typeof s=="string"?{label:s}:s),[t,n]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:y0(e);return s=>{let r=s.matchBefore(n);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}function Oc(i,e){return t=>{for(let n=te(t.state).resolveInner(t.pos,-1);n;n=n.parent){if(i.indexOf(n.name)>-1)return null;if(n.type.isTop)break}return e(t)}}class Fl{constructor(e,t,n,s){this.completion=e,this.source=t,this.match=n,this.score=s}}function ft(i){return i.selection.main.from}function Dc(i,e){var t;let{source:n}=i,s=e&&n[0]!="^",r=n[n.length-1]!="$";return!s&&!r?i:new RegExp(`${s?"^":""}(?:${n})${r?"$":""}`,(t=i.flags)!==null&&t!==void 0?t:i.ignoreCase?"i":"")}const Pc=y.Annotation.define();function b0(i,e,t,n){let{main:s}=i.selection,r=t-s.from,o=n-s.from;return Object.assign(Object.assign({},i.changeByRange(l=>l!=s&&t!=n&&i.sliceDoc(l.from+r,l.from+o)!=i.sliceDoc(t,n)?{range:l}:{changes:{from:l.from+r,to:n==s.from?l.to:l.from+o,insert:e},range:y.EditorSelection.cursor(l.from+r+e.length)})),{scrollIntoView:!0,userEvent:"input.complete"})}const Vl=new WeakMap;function S0(i){if(!Array.isArray(i))return i;let e=Vl.get(i);return e||Vl.set(i,e=Gr(i)),e}const zn=y.StateEffect.define(),Oi=y.StateEffect.define();class v0{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let n=y.codePointAt(e,t),s=y.codePointSize(n);this.chars.push(n);let r=e.slice(t,t+s),o=r.toUpperCase();this.folded.push(y.codePointAt(o==r?r.toLowerCase():o,0)),t+=s}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,!0}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return!1;let{chars:t,folded:n,any:s,precise:r,byWord:o}=this;if(t.length==1){let P=y.codePointAt(e,0),F=y.codePointSize(P),L=F==e.length?0:-100;if(P!=t[0])if(P==n[0])L+=-200;else return!1;return this.ret(L,[0,F])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,f=0;if(l<0){for(let P=0,F=Math.min(e.length,200);P<F&&f<a;){let L=y.codePointAt(e,P);(L==t[f]||L==n[f])&&(s[f++]=P),P+=y.codePointSize(L)}if(f<a)return!1}let c=0,p=0,g=!1,v=0,k=-1,C=-1,M=/[a-z]/.test(e),T=!0;for(let P=0,F=Math.min(e.length,200),L=0;P<F&&p<a;){let R=y.codePointAt(e,P);l<0&&(c<a&&R==t[c]&&(r[c++]=P),v<a&&(R==t[v]||R==n[v]?(v==0&&(k=P),C=P+1,v++):v=0));let I,z=R<255?R>=48&&R<=57||R>=97&&R<=122?2:R>=65&&R<=90?1:0:(I=y.fromCodePoint(R))!=I.toLowerCase()?1:I!=I.toUpperCase()?2:0;(!P||z==1&&M||L==0&&z!=0)&&(t[p]==R||n[p]==R&&(g=!0)?o[p++]=P:o.length&&(T=!1)),L=z,P+=y.codePointSize(R)}return p==a&&o[0]==0&&T?this.result(-100+(g?-200:0),o,e):v==a&&k==0?this.ret(-200-e.length+(C==e.length?0:-100),[0,C]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):v==a?this.ret(-900-e.length,[k,C]):p==a?this.result(-100+(g?-200:0)+-700+(T?0:-1100),o,e):t.length==2?!1:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,n){let s=[],r=0;for(let o of t){let l=o+(this.astral?y.codePointSize(y.codePointAt(n,o)):1);r&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return this.ret(e-n.length,s)}}const pe=y.Facet.define({combine(i){return y.combineConfig(i,{activateOnTyping:!0,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:x0,compareCompletions:(e,t)=>e.label.localeCompare(t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>n=>Hl(e(n),t(n)),optionClass:(e,t)=>n=>Hl(e(n),t(n)),addToOptions:(e,t)=>e.concat(t)})}});function Hl(i,e){return i?e?i+" "+e:i:e}function x0(i,e,t,n,s,r){let o=i.textDirection==Q.RTL,l=o,a=!1,f="top",c,p,g=e.left-s.left,v=s.right-e.right,k=n.right-n.left,C=n.bottom-n.top;if(l&&g<Math.min(k,v)?l=!1:!l&&v<Math.min(k,g)&&(l=!0),k<=(l?g:v))c=Math.max(s.top,Math.min(t.top,s.bottom-C))-e.top,p=Math.min(400,l?g:v);else{a=!0,p=Math.min(400,(o?e.right:s.right-e.left)-30);let P=s.bottom-e.bottom;P>=C||P>e.top?c=t.bottom-e.top:(f="bottom",c=e.bottom-t.top)}let M=(e.bottom-e.top)/r.offsetHeight,T=(e.right-e.left)/r.offsetWidth;return{style:`${f}: ${c/M}px; max-width: ${p/T}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function w0(i){let e=i.addToOptions.slice();return i.icons&&e.push({render(t){let n=document.createElement("div");return n.classList.add("cm-completionIcon"),t.type&&n.classList.add(...t.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),n.setAttribute("aria-hidden","true"),n},position:20}),e.push({render(t,n,s,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let f=0;f<r.length;){let c=r[f++],p=r[f++];c>a&&o.appendChild(document.createTextNode(l.slice(a,c)));let g=o.appendChild(document.createElement("span"));g.appendChild(document.createTextNode(l.slice(c,p))),g.className="cm-completionMatchedText",a=p}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let n=document.createElement("span");return n.className="cm-completionDetail",n.textContent=t.detail,n},position:80}),e.sort((t,n)=>t.position-n.position).map(t=>t.render)}function Bs(i,e,t){if(i<=t)return{from:0,to:i};if(e<0&&(e=0),e<=i>>1){let s=Math.floor(e/t);return{from:s*t,to:(s+1)*t}}let n=Math.floor((i-e)/t);return{from:i-(n+1)*t,to:i-n*t}}class k0{constructor(e,t,n){this.view=e,this.stateField=t,this.applyCompletion=n,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let s=e.state.field(t),{options:r,selected:o}=s.open,l=e.state.facet(pe);this.optionContent=w0(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Bs(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:f}=e.state.field(t).open;for(let c=a.target,p;c&&c!=this.dom;c=c.parentNode)if(c.nodeName=="LI"&&(p=/-(\d+)$/.exec(c.id))&&+p[1]<f.length){this.applyCompletion(e,f[+p[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let f=e.state.field(this.stateField,!1);f&&f.tooltip&&e.state.facet(pe).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Oi.of(null)})}),this.showOptions(r,s.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let n=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),n!=s){let{options:r,selected:o,disabled:l}=n.open;(!s.open||s.open.options!=r)&&(this.range=Bs(r.length,o,e.state.facet(pe).maxRenderedOptions),this.showOptions(r,n.id)),this.updateSel(),l!=((t=s.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let n of this.currentClass.split(" "))n&&this.dom.classList.remove(n);for(let n of t.split(" "))n&&this.dom.classList.add(n);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;if((t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=Bs(t.options.length,t.selected,this.view.state.facet(pe).maxRenderedOptions),this.showOptions(t.options,e.id)),this.updateSelectedOption(t.selected)){this.destroyInfo();let{completion:n}=t.options[t.selected],{info:s}=n;if(!s)return;let r=typeof s=="string"?document.createTextNode(s):s(n);if(!r)return;"then"in r?r.then(o=>{o&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(o,n)}).catch(o=>Me(this.view.state,o,"completion info")):this.addInfoPane(r,n)}}addInfoPane(e,t){this.destroyInfo();let n=this.info=document.createElement("div");if(n.className="cm-tooltip cm-completionInfo",e.nodeType!=null)n.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:r}=e;n.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let n=this.list.firstChild,s=this.range.from;n;n=n.nextSibling,s++)n.nodeName!="LI"||!n.id?s--:s==e?n.hasAttribute("aria-selected")||(n.setAttribute("aria-selected","true"),t=n):n.hasAttribute("aria-selected")&&n.removeAttribute("aria-selected");return t&&A0(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),n=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.defaultView||window;r={left:0,top:0,right:o.innerWidth,bottom:o.innerHeight}}return s.top>Math.min(r.bottom,t.bottom)-10||s.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(pe).positionInfo(this.view,t,s,n,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,n){const s=document.createElement("ul");s.id=t,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions"));let r=null;for(let o=n.from;o<n.to;o++){let{completion:l,match:a}=e[o],{section:f}=l;if(f){let g=typeof f=="string"?f:f.name;if(g!=r&&(o>n.from||n.from==0))if(r=g,typeof f!="string"&&f.header)s.appendChild(f.header(f));else{let v=s.appendChild(document.createElement("completion-section"));v.textContent=g}}const c=s.appendChild(document.createElement("li"));c.id=t+"-"+o,c.setAttribute("role","option");let p=this.optionClass(l);p&&(c.className=p);for(let g of this.optionContent){let v=g(l,this.view.state,this.view,a);v&&c.appendChild(v)}}return n.from&&s.classList.add("cm-completionListIncompleteTop"),n.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function C0(i,e){return t=>new k0(t,i,e)}function A0(i,e){let t=i.getBoundingClientRect(),n=e.getBoundingClientRect(),s=t.height/i.offsetHeight;n.top<t.top?i.scrollTop-=(t.top-n.top)/s:n.bottom>t.bottom&&(i.scrollTop+=(n.bottom-t.bottom)/s)}function Wl(i){return(i.boost||0)*100+(i.apply?10:0)+(i.info?5:0)+(i.type?1:0)}function M0(i,e){let t=[],n=null,s=a=>{t.push(a);let{section:f}=a.completion;if(f){n||(n=[]);let c=typeof f=="string"?f:f.name;n.some(p=>p.name==c)||n.push(typeof f=="string"?{name:c}:f)}};for(let a of i)if(a.hasResult()){let f=a.result.getMatch;if(a.result.filter===!1)for(let c of a.result.options)s(new Fl(c,a.source,f?f(c):[],1e9-t.length));else{let c=new v0(e.sliceDoc(a.from,a.to));for(let p of a.result.options)if(c.match(p.label)){let g=p.displayLabel?f?f(p,c.matched):[]:c.matched;s(new Fl(p,a.source,g,c.score+(p.boost||0)))}}}if(n){let a=Object.create(null),f=0,c=(p,g)=>{var v,k;return((v=p.rank)!==null&&v!==void 0?v:1e9)-((k=g.rank)!==null&&k!==void 0?k:1e9)||(p.name<g.name?-1:1)};for(let p of n.sort(c))f-=1e5,a[p.name]=f;for(let p of t){let{section:g}=p.completion;g&&(p.score+=a[typeof g=="string"?g:g.name])}}let r=[],o=null,l=e.facet(pe).compareCompletions;for(let a of t.sort((f,c)=>c.score-f.score||l(f.completion,c.completion))){let f=a.completion;!o||o.label!=f.label||o.detail!=f.detail||o.type!=null&&f.type!=null&&o.type!=f.type||o.apply!=f.apply||o.boost!=f.boost?r.push(a):Wl(a.completion)>Wl(o)&&(r[r.length-1]=a),o=a.completion}return r}class Nt{constructor(e,t,n,s,r,o){this.options=e,this.attrs=t,this.tooltip=n,this.timestamp=s,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Nt(this.options,$l(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,n,s,r){let o=M0(e,t);if(!o.length)return s&&e.some(a=>a.state==1)?new Nt(s.options,s.attrs,s.tooltip,s.timestamp,s.selected,!0):null;let l=t.facet(pe).selectOnOpen?0:-1;if(s&&s.selected!=l&&s.selected!=-1){let a=s.options[s.selected].completion;for(let f=0;f<o.length;f++)if(o[f].completion==a){l=f;break}}return new Nt(o,$l(n,l),{pos:e.reduce((a,f)=>f.hasResult()?Math.min(a,f.from):a,1e8),create:P0,above:r.aboveCursor},s?s.timestamp:Date.now(),l,!1)}map(e){return new Nt(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:e.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class qn{constructor(e,t,n){this.active=e,this.id=t,this.open=n}static start(){return new qn(O0,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,n=t.facet(pe),r=(n.override||t.languageDataAt("autocomplete",ft(t)).map(S0)).map(l=>(this.active.find(f=>f.source==l)||new De(l,this.active.some(f=>f.state!=0)?1:0)).update(e,n));r.length==this.active.length&&r.every((l,a)=>l==this.active[a])&&(r=this.active);let o=this.open;o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!E0(r,this.active)?o=Nt.build(r,t,this.id,o,n):o&&o.disabled&&!r.some(l=>l.state==1)&&(o=null),!o&&r.every(l=>l.state!=1)&&r.some(l=>l.hasResult())&&(r=r.map(l=>l.hasResult()?new De(l.source,0):l));for(let l of e.effects)l.is(Bc)&&(o=o&&o.setSelected(l.value,this.id));return r==this.active&&o==this.open?this:new qn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:T0}}function E0(i,e){if(i==e)return!0;for(let t=0,n=0;;){for(;t<i.length&&!i[t].hasResult;)t++;for(;n<e.length&&!e[n].hasResult;)n++;let s=t==i.length,r=n==e.length;if(s||r)return s==r;if(i[t++].result!=e[n++].result)return!1}}const T0={"aria-autocomplete":"list"};function $l(i,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":i};return e>-1&&(t["aria-activedescendant"]=i+"-"+e),t}const O0=[];function gr(i){return i.isUserEvent("input.type")?"input":i.isUserEvent("delete.backward")?"delete":null}class De{constructor(e,t,n=-1){this.source=e,this.state=t,this.explicitPos=n}hasResult(){return!1}update(e,t){let n=gr(e),s=this;n?s=s.handleUserEvent(e,n,t):e.docChanged?s=s.handleChange(e):e.selection&&s.state!=0&&(s=new De(s.source,0));for(let r of e.effects)if(r.is(zn))s=new De(s.source,1,r.value?ft(e.state):-1);else if(r.is(Oi))s=new De(s.source,0);else if(r.is(Rc))for(let o of r.value)o.source==s.source&&(s=o);return s}handleUserEvent(e,t,n){return t=="delete"||!n.activateOnTyping?this.map(e.changes):new De(this.source,1)}handleChange(e){return e.changes.touchesRange(ft(e.startState))?new De(this.source,0):this.map(e.changes)}map(e){return e.empty||this.explicitPos<0?this:new De(this.source,this.state,e.mapPos(this.explicitPos))}}class Wt extends De{constructor(e,t,n,s,r){super(e,2,t),this.result=n,this.from=s,this.to=r}hasResult(){return!0}handleUserEvent(e,t,n){var s;let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=ft(e.state);if((this.explicitPos<0?l<=r:l<this.from)||l>o||t=="delete"&&ft(e.startState)==this.from)return new De(this.source,t=="input"&&n.activateOnTyping?1:0);let a=this.explicitPos<0?-1:e.changes.mapPos(this.explicitPos),f;return D0(this.result.validFor,e.state,r,o)?new Wt(this.source,a,this.result,r,o):this.result.update&&(f=this.result.update(this.result,r,o,new Tc(e.state,l,a>=0)))?new Wt(this.source,a,f,f.from,(s=f.to)!==null&&s!==void 0?s:ft(e.state)):new De(this.source,1,a)}handleChange(e){return e.changes.touchesRange(this.from,this.to)?new De(this.source,0):this.map(e.changes)}map(e){return e.empty?this:new Wt(this.source,this.explicitPos<0?-1:e.mapPos(this.explicitPos),this.result,e.mapPos(this.from),e.mapPos(this.to,1))}}function D0(i,e,t,n){if(!i)return!1;let s=e.sliceDoc(t,n);return typeof i=="function"?i(s,t,n,e):Dc(i,!0).test(s)}const Rc=y.StateEffect.define({map(i,e){return i.map(t=>t.map(e))}}),Bc=y.StateEffect.define(),Le=y.StateField.define({create(){return qn.start()},update(i,e){return i.update(e)},provide:i=>[Lr.from(i,e=>e.tooltip),N.contentAttributes.from(i,e=>e.attrs)]});function Lc(i,e){const t=e.completion.apply||e.completion.label;let n=i.state.field(Le).active.find(s=>s.source==e.source);return n instanceof Wt?(typeof t=="string"?i.dispatch(Object.assign(Object.assign({},b0(i.state,t,n.from,n.to)),{annotations:Pc.of(e.completion)})):t(i,e.completion,n.from,n.to),!0):!1}const P0=C0(Le,Lc);function cn(i,e="option"){return t=>{let n=t.state.field(Le,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp<t.state.facet(pe).interactionDelay)return!1;let s=1,r;e=="page"&&(r=gh(t,n.open.tooltip))&&(s=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:o}=n.open.options,l=n.open.selected>-1?n.open.selected+s*(i?1:-1):i?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:Bc.of(l)}),!0}}const R0=i=>{let e=i.state.field(Le,!1);return i.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<i.state.facet(pe).interactionDelay?!1:Lc(i,e.open.options[e.open.selected])},B0=i=>i.state.field(Le,!1)?(i.dispatch({effects:zn.of(!0)}),!0):!1,L0=i=>{let e=i.state.field(Le,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(i.dispatch({effects:Oi.of(null)}),!0)};class I0{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const N0=50,F0=1e3,V0=se.fromClass(class{constructor(i){this.view=i,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of i.state.field(Le).active)e.state==1&&this.startQuery(e)}update(i){let e=i.state.field(Le);if(!i.selectionSet&&!i.docChanged&&i.startState.field(Le)==e)return;let t=i.transactions.some(s=>(s.selection||s.docChanged)&&!gr(s));for(let s=0;s<this.running.length;s++){let r=this.running[s];if(t||r.updates.length+i.transactions.length>N0&&Date.now()-r.time>F0){for(let o of r.context.abortListeners)try{o()}catch(l){Me(this.view.state,l)}r.context.abortListeners=null,this.running.splice(s--,1)}else r.updates.push(...i.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),i.transactions.some(s=>s.effects.some(r=>r.is(zn)))&&(this.pendingStart=!0);let n=this.pendingStart?50:i.state.facet(pe).activateOnTypingDelay;if(this.debounceUpdate=e.active.some(s=>s.state==1&&!this.running.some(r=>r.active.source==s.source))?setTimeout(()=>this.startUpdate(),n):-1,this.composing!=0)for(let s of i.transactions)gr(s)=="input"?this.composing=2:this.composing==2&&s.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:i}=this.view,e=i.field(Le);for(let t of e.active)t.state==1&&!this.running.some(n=>n.active.source==t.source)&&this.startQuery(t)}startQuery(i){let{state:e}=this.view,t=ft(e),n=new Tc(e,t,i.explicitPos==t),s=new I0(i,n);this.running.push(s),Promise.resolve(i.source(n)).then(r=>{s.context.aborted||(s.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:Oi.of(null)}),Me(this.view.state,r)})}scheduleAccept(){this.running.every(i=>i.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(pe).updateSyncTime))}accept(){var i;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(pe);for(let n=0;n<this.running.length;n++){let s=this.running[n];if(s.done===void 0)continue;if(this.running.splice(n--,1),s.done){let o=new Wt(s.active.source,s.active.explicitPos,s.done,s.done.from,(i=s.done.to)!==null&&i!==void 0?i:ft(s.updates.length?s.updates[0].startState:this.view.state));for(let l of s.updates)o=o.update(l,t);if(o.hasResult()){e.push(o);continue}}let r=this.view.state.field(Le).active.find(o=>o.source==s.active.source);if(r&&r.state==1)if(s.done==null){let o=new De(s.active.source,0);for(let l of s.updates)o=o.update(l,t);o.state!=1&&e.push(o)}else this.startQuery(r)}e.length&&this.view.dispatch({effects:Rc.of(e)})}},{eventHandlers:{blur(i){let e=this.view.state.field(Le,!1);if(e&&e.tooltip&&this.view.state.facet(pe).closeOnBlur){let t=e.open&&gh(this.view,e.open.tooltip);(!t||!t.dom.contains(i.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Oi.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:zn.of(!1)}),20),this.composing=0}}}),Ic=N.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box"},".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"}}});let H0=class{constructor(e,t,n,s){this.field=e,this.line=t,this.from=n,this.to=s}},W0=class Nc{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(e){let t=e.mapPos(this.from,-1,y.MapMode.TrackDel),n=e.mapPos(this.to,1,y.MapMode.TrackDel);return t==null||n==null?null:new Nc(this.field,t,n)}},$0=class Fc{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],s=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(n.length){let f=o,c=/^\t*/.exec(a)[0].length;for(let p=0;p<c;p++)f+=e.facet(Xt);s.push(t+f.length-c),a=f+a.slice(c)}n.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new W0(a.field,s[a.line]+a.from,s[a.line]+a.to));return{text:n,ranges:l}}static parse(e){let t=[],n=[],s=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",f=-1;for(let c=0;c<t.length;c++)(l!=null?t[c].seq==l:a&&t[c].name==a)&&(f=c);if(f<0){let c=0;for(;c<t.length&&(l==null||t[c].seq!=null&&t[c].seq<l);)c++;t.splice(c,0,{seq:l,name:a}),f=c;for(let p of s)p.field>=f&&p.field++}s.push(new H0(f,n.length,r.index,r.index+a.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}for(let l;l=/\\([{}])/.exec(o);){o=o.slice(0,l.index)+l[1]+o.slice(l.index+l[0].length);for(let a of s)a.line==n.length&&a.from>l.index&&(a.from--,a.to--)}n.push(o)}return new Fc(n,s)}},z0=H.widget({widget:new class extends je{toDOM(){let i=document.createElement("span");return i.className="cm-snippetFieldPosition",i}ignoreEvent(){return!1}}}),q0=H.mark({class:"cm-snippetField"}),is=class Vc{constructor(e,t){this.ranges=e,this.active=t,this.deco=H.set(e.map(n=>(n.from==n.to?z0:q0).range(n.from,n.to)))}map(e){let t=[];for(let n of this.ranges){let s=n.map(e);if(!s)return null;t.push(s)}return new Vc(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(n=>n.field==this.active&&n.from<=t.from&&n.to>=t.to))}};const $i=y.StateEffect.define({map(i,e){return i&&i.map(e)}}),j0=y.StateEffect.define(),Di=y.StateField.define({create(){return null},update(i,e){for(let t of e.effects){if(t.is($i))return t.value;if(t.is(j0)&&i)return new is(i.ranges,t.value)}return i&&e.docChanged&&(i=i.map(e.changes)),i&&e.selection&&!i.selectionInsideField(e.selection)&&(i=null),i},provide:i=>N.decorations.from(i,e=>e?e.deco:H.none)});function Xr(i,e){return y.EditorSelection.create(i.filter(t=>t.field==e).map(t=>y.EditorSelection.range(t.from,t.to)))}function _0(i){let e=$0.parse(i);return(t,n,s,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,s),a={changes:{from:s,to:r,insert:y.Text.of(o)},scrollIntoView:!0,annotations:n?[Pc.of(n),y.Transaction.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=Xr(l,0)),l.some(f=>f.field>0)){let f=new is(l,0),c=a.effects=[$i.of(f)];t.state.field(Di,!1)===void 0&&c.push(y.StateEffect.appendConfig.of([Di,G0,X0,Ic]))}t.dispatch(t.state.update(a))}}function Hc(i){return({state:e,dispatch:t})=>{let n=e.field(Di,!1);if(!n||i<0&&n.active==0)return!1;let s=n.active+i,r=i>0&&!n.ranges.some(o=>o.field==s+i);return t(e.update({selection:Xr(n.ranges,s),effects:$i.of(r?null:new is(n.ranges,s)),scrollIntoView:!0})),!0}}const K0=({state:i,dispatch:e})=>i.field(Di,!1)?(e(i.update({effects:$i.of(null)})),!0):!1,J0=Hc(1),U0=Hc(-1),Y0=[{key:"Tab",run:J0,shift:U0},{key:"Escape",run:K0}],zl=y.Facet.define({combine(i){return i.length?i[0]:Y0}}),G0=y.Prec.highest(Gt.compute([zl],i=>i.facet(zl)));function ne(i,e){return Object.assign(Object.assign({},e),{apply:_0(i)})}const X0=N.domEventHandlers({mousedown(i,e){let t=e.state.field(Di,!1),n;if(!t||(n=e.posAtCoords({x:i.clientX,y:i.clientY}))==null)return!1;let s=t.ranges.find(r=>r.from<=n&&r.to>=n);return!s||s.field==t.active?!1:(e.dispatch({selection:Xr(t.ranges,s.field),effects:$i.of(t.ranges.some(r=>r.field>s.field)?new is(t.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Pi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},St=y.StateEffect.define({map(i,e){let t=e.mapPos(i,-1,y.MapMode.TrackAfter);return t??void 0}}),Qr=new class extends y.RangeValue{};Qr.startSide=1;Qr.endSide=-1;const Wc=y.StateField.define({create(){return y.RangeSet.empty},update(i,e){if(i=i.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);i=i.update({filter:n=>n>=t.from&&n<=t.to})}for(let t of e.effects)t.is(St)&&(i=i.update({add:[Qr.range(t.value,t.value+1)]}));return i}});function Q0(){return[ey,Wc]}const Ls="()[]{}<>";function $c(i){for(let e=0;e<Ls.length;e+=2)if(Ls.charCodeAt(e)==i)return Ls.charAt(e+1);return y.fromCodePoint(i<128?i:i+1)}function zc(i,e){return i.languageDataAt("closeBrackets",e)[0]||Pi}const Z0=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),ey=N.inputHandler.of((i,e,t,n)=>{if((Z0?i.composing:i.compositionStarted)||i.state.readOnly)return!1;let s=i.state.selection.main;if(n.length>2||n.length==2&&y.codePointSize(y.codePointAt(n,0))==1||e!=s.from||t!=s.to)return!1;let r=ny(i.state,n);return r?(i.dispatch(r),!0):!1}),ty=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let n=zc(i,i.selection.main.head).brackets||Pi.brackets,s=null,r=i.changeByRange(o=>{if(o.empty){let l=sy(i.doc,o.head);for(let a of n)if(a==l&&ns(i.doc,o.head)==$c(y.codePointAt(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:y.EditorSelection.cursor(o.head-a.length)}}return{range:s=o}});return s||e(i.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},iy=[{key:"Backspace",run:ty}];function ny(i,e){let t=zc(i,i.selection.main.head),n=t.brackets||Pi.brackets;for(let s of n){let r=$c(y.codePointAt(s,0));if(e==s)return r==s?ly(i,s,n.indexOf(s+s+s)>-1,t):ry(i,s,r,t.before||Pi.before);if(e==r&&qc(i,i.selection.main.from))return oy(i,s,r)}return null}function qc(i,e){let t=!1;return i.field(Wc).between(0,i.doc.length,n=>{n==e&&(t=!0)}),t}function ns(i,e){let t=i.sliceString(e,e+2);return t.slice(0,y.codePointSize(y.codePointAt(t,0)))}function sy(i,e){let t=i.sliceString(e-2,e);return y.codePointSize(y.codePointAt(t,0))==t.length?t:t.slice(1)}function ry(i,e,t,n){let s=null,r=i.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:St.of(o.to+e.length),range:y.EditorSelection.range(o.anchor+e.length,o.head+e.length)};let l=ns(i.doc,o.head);return!l||/\s/.test(l)||n.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:St.of(o.head+e.length),range:y.EditorSelection.cursor(o.head+e.length)}:{range:s=o}});return s?null:i.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function oy(i,e,t){let n=null,s=i.changeByRange(r=>r.empty&&ns(i.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:y.EditorSelection.cursor(r.head+t.length)}:n={range:r});return n?null:i.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function ly(i,e,t,n){let s=n.stringPrefixes||Pi.stringPrefixes,r=null,o=i.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:St.of(l.to+e.length),range:y.EditorSelection.range(l.anchor+e.length,l.head+e.length)};let a=l.head,f=ns(i.doc,a),c;if(f==e){if(ql(i,a))return{changes:{insert:e+e,from:a},effects:St.of(a+e.length),range:y.EditorSelection.cursor(a+e.length)};if(qc(i,a)){let g=t&&i.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+g.length,insert:g},range:y.EditorSelection.cursor(a+g.length)}}}else{if(t&&i.sliceDoc(a-2*e.length,a)==e+e&&(c=jl(i,a-2*e.length,s))>-1&&ql(i,c))return{changes:{insert:e+e+e+e,from:a},effects:St.of(a+e.length),range:y.EditorSelection.cursor(a+e.length)};if(i.charCategorizer(a)(f)!=y.CharCategory.Word&&jl(i,a,s)>-1&&!ay(i,a,e,s))return{changes:{insert:e+e,from:a},effects:St.of(a+e.length),range:y.EditorSelection.cursor(a+e.length)}}return{range:r=l}});return r?null:i.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function ql(i,e){let t=te(i).resolveInner(e+1);return t.parent&&t.from==e}function ay(i,e,t,n){let s=te(i).resolveInner(e,-1),r=n.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=i.sliceDoc(s.from,Math.min(s.to,s.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&n.indexOf(l.slice(0,a))>-1){let c=s.firstChild;for(;c&&c.from==s.from&&c.to-c.from>t.length+a;){if(i.sliceDoc(c.to-t.length,c.to)==t)return!1;c=c.firstChild}return!0}let f=s.to==e&&s.parent;if(!f)break;s=f}return!1}function jl(i,e,t){let n=i.charCategorizer(e);if(n(i.sliceDoc(e-1,e))!=y.CharCategory.Word)return e;for(let s of t){let r=e-s.length;if(i.sliceDoc(r,e)==s&&n(i.sliceDoc(r-1,r))!=y.CharCategory.Word)return r}return-1}function hy(i={}){return[Le,pe.of(i),V0,cy,Ic]}const jc=[{key:"Ctrl-Space",run:B0},{key:"Escape",run:L0},{key:"ArrowDown",run:cn(!0)},{key:"ArrowUp",run:cn(!1)},{key:"PageDown",run:cn(!0,"page")},{key:"PageUp",run:cn(!1,"page")},{key:"Enter",run:R0}],cy=y.Prec.highest(Gt.computeN([pe],i=>i.facet(pe).defaultKeymap?[jc]:[]));var _l=function(e){e===void 0&&(e={});var{crosshairCursor:t=!1}=e,n=[];e.closeBracketsKeymap!==!1&&(n=n.concat(iy)),e.defaultKeymap!==!1&&(n=n.concat(bg)),e.searchKeymap!==!1&&(n=n.concat(d0)),e.historyKeymap!==!1&&(n=n.concat(Em)),e.foldKeymap!==!1&&(n=n.concat($p)),e.completionKeymap!==!1&&(n=n.concat(jc)),e.lintKeymap!==!1&&(n=n.concat(Og));var s=[];return e.lineNumbers!==!1&&s.push(yp()),e.highlightActiveLineGutter!==!1&&s.push(vp()),e.highlightSpecialChars!==!1&&s.push(Id()),e.history!==!1&&s.push(bm()),e.foldGutter!==!1&&s.push(_p()),e.drawSelection!==!1&&s.push(Cd()),e.dropCursor!==!1&&s.push(Od()),e.allowMultipleSelections!==!1&&s.push(y.EditorState.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&s.push(Rp()),e.syntaxHighlighting!==!1&&s.push(Wr(Yp,{fallback:!0})),e.bracketMatching!==!1&&s.push(im()),e.closeBrackets!==!1&&s.push(Q0()),e.autocompletion!==!1&&s.push(hy()),e.rectangularSelection!==!1&&s.push(Yd()),t!==!1&&s.push(Qd()),e.highlightActiveLine!==!1&&s.push($d()),e.highlightSelectionMatches!==!1&&s.push(Ug()),e.tabSize&&typeof e.tabSize=="number"&&s.push(Xt.of(" ".repeat(e.tabSize))),s.concat([Gt.of(n.flat())]).filter(Boolean)};const fy="#e5c07b",Kl="#e06c75",uy="#56b6c2",dy="#ffffff",wn="#abb2bf",yr="#7d8799",py="#61afef",my="#98c379",Jl="#d19a66",gy="#c678dd",yy="#21252b",Ul="#2c313a",Yl="#282c34",Is="#353a42",by="#3E4451",Gl="#528bff",Sy=N.theme({"&":{color:wn,backgroundColor:Yl},".cm-content":{caretColor:Gl},".cm-cursor, .cm-dropCursor":{borderLeftColor:Gl},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:by},".cm-panels":{backgroundColor:yy,color:wn},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:Yl,color:yr,border:"none"},".cm-activeLineGutter":{backgroundColor:Ul},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:Is},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:Is,borderBottomColor:Is},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:Ul,color:wn}}},{dark:!0}),vy=Qt.define([{tag:E.keyword,color:gy},{tag:[E.name,E.deleted,E.character,E.propertyName,E.macroName],color:Kl},{tag:[E.function(E.variableName),E.labelName],color:py},{tag:[E.color,E.constant(E.name),E.standard(E.name)],color:Jl},{tag:[E.definition(E.name),E.separator],color:wn},{tag:[E.typeName,E.className,E.number,E.changed,E.annotation,E.modifier,E.self,E.namespace],color:fy},{tag:[E.operator,E.operatorKeyword,E.url,E.escape,E.regexp,E.link,E.special(E.string)],color:uy},{tag:[E.meta,E.comment],color:yr},{tag:E.strong,fontWeight:"bold"},{tag:E.emphasis,fontStyle:"italic"},{tag:E.strikethrough,textDecoration:"line-through"},{tag:E.link,color:yr,textDecoration:"underline"},{tag:E.heading,fontWeight:"bold",color:Kl},{tag:[E.atom,E.bool,E.special(E.variableName)],color:Jl},{tag:[E.processingInstruction,E.string,E.inserted],color:my},{tag:E.invalid,color:dy}]),xy=[Sy,Wr(vy)];var wy=N.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),ky=function(e){e===void 0&&(e={});var{indentWithTab:t=!0,editable:n=!0,readOnly:s=!1,theme:r="light",placeholder:o="",basicSetup:l=!0}=e,a=[];switch(t&&a.unshift(Gt.of([Sg])),l&&(typeof l=="boolean"?a.unshift(_l()):a.unshift(_l(l))),o&&a.unshift(_d(o)),r){case"light":a.push(wy);break;case"dark":a.push(xy);break;case"none":break;default:a.push(r);break}return n===!1&&a.push(N.editable.of(!1)),s&&a.push(y.EditorState.readOnly.of(!0)),[...a]},Cy=i=>({line:i.state.doc.lineAt(i.state.selection.main.from),lineCount:i.state.doc.lines,lineBreak:i.state.lineBreak,length:i.state.doc.length,readOnly:i.state.readOnly,tabSize:i.state.tabSize,selection:i.state.selection,selectionAsSingle:i.state.selection.asSingle().main,ranges:i.state.selection.ranges,selectionCode:i.state.sliceDoc(i.state.selection.main.from,i.state.selection.main.to),selections:i.state.selection.ranges.map(e=>i.state.sliceDoc(e.from,e.to)),selectedText:i.state.selection.ranges.some(e=>!e.empty)});class Ay{constructor(e,t){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=t,this.timeoutMS=t,this.callbacks.push(e)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var e=this.callbacks.slice();this.callbacks.length=0,e.forEach(t=>{try{t()}catch(n){console.error("TimeoutLatch callback error:",n)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}}class Xl{constructor(){this.interval=null,this.latches=new Set}add(e){this.latches.add(e),this.start()}remove(e){this.latches.delete(e),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(e=>{e.tick(),e.isDone&&this.remove(e)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}}var Ns=null,My=()=>typeof window>"u"?new Xl:(Ns||(Ns=new Xl),Ns),Ql=y.Annotation.define(),Ey=200,Ty=[];function Oy(i){var{value:e,selection:t,onChange:n,onStatistics:s,onCreateEditor:r,onUpdate:o,extensions:l=Ty,autoFocus:a,theme:f="light",height:c=null,minHeight:p=null,maxHeight:g=null,width:v=null,minWidth:k=null,maxWidth:C=null,placeholder:M="",editable:T=!0,readOnly:P=!1,indentWithTab:F=!0,basicSetup:L=!0,root:R,initialState:I}=i,[z,U]=Ae.useState(),[_,me]=Ae.useState(),[Ce,he]=Ae.useState(),q=Ae.useState(()=>({current:null}))[0],ue=Ae.useState(()=>({current:null}))[0],ge=N.theme({"&":{height:c,minHeight:p,maxHeight:g,width:v,minWidth:k,maxWidth:C},"& .cm-scroller":{height:"100% !important"}}),G=N.updateListener.of(ie=>{if(ie.docChanged&&typeof n=="function"&&!ie.transactions.some(ot=>ot.annotation(Ql))){q.current?q.current.reset():(q.current=new Ay(()=>{if(ue.current){var ot=ue.current;ue.current=null,ot()}q.current=null},Ey),My().add(q.current));var re=ie.state.doc,tt=re.toString();n(tt,ie)}s&&s(Cy(ie))}),ye=ky({theme:f,editable:T,readOnly:P,placeholder:M,indentWithTab:F,basicSetup:L}),be=[G,ge,...ye];return o&&typeof o=="function"&&be.push(N.updateListener.of(o)),be=be.concat(l),Ae.useLayoutEffect(()=>{if(z&&!Ce){var ie={doc:e,selection:t,extensions:be},re=I?y.EditorState.fromJSON(I.json,ie,I.fields):y.EditorState.create(ie);if(he(re),!_){var tt=new N({state:re,parent:z,root:R});me(tt),r&&r(tt,re)}}return()=>{_&&(he(void 0),me(void 0))}},[z,Ce]),Ae.useEffect(()=>{i.container&&U(i.container)},[i.container]),Ae.useEffect(()=>()=>{_&&(_.destroy(),me(void 0)),q.current&&(q.current.cancel(),q.current=null)},[_]),Ae.useEffect(()=>{a&&_&&_.focus()},[a,_]),Ae.useEffect(()=>{_&&_.dispatch({effects:y.StateEffect.reconfigure.of(be)})},[f,l,c,p,g,v,k,C,M,T,P,F,L,n,o]),Ae.useEffect(()=>{if(e!==void 0){var ie=_?_.state.doc.toString():"";if(_&&e!==ie){var re=q.current&&!q.current.isDone,tt=()=>{_&&e!==_.state.doc.toString()&&_.dispatch({changes:{from:0,to:_.state.doc.toString().length,insert:e||""},annotations:[Ql.of(!0)]})};re?ue.current=tt:tt()}}},[e,_]),{state:Ce,setState:he,view:_,setView:me,container:z,setContainer:U}}var Dy=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],Py=Ae.forwardRef((i,e)=>{var{className:t,value:n="",selection:s,extensions:r=[],onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:f,autoFocus:c,theme:p="light",height:g,minHeight:v,maxHeight:k,width:C,minWidth:M,maxWidth:T,basicSetup:P,placeholder:F,indentWithTab:L,editable:R,readOnly:I,root:z,initialState:U}=i,_=Rf(i,Dy),me=Ae.useRef(null),{state:Ce,view:he,container:q,setContainer:ue}=Oy({root:z,value:n,autoFocus:c,theme:p,height:g,minHeight:v,maxHeight:k,width:C,minWidth:M,maxWidth:T,basicSetup:P,placeholder:F,indentWithTab:L,editable:R,readOnly:I,selection:s,onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:f,extensions:r,initialState:U});Ae.useImperativeHandle(e,()=>({editor:me.current,state:Ce,view:he}),[me,q,Ce,he]);var ge=Ae.useCallback(ye=>{me.current=ye,ue(ye)},[ue]);if(typeof n!="string")throw new Error("value must be typeof string but got "+typeof n);var G=typeof p=="string"?"cm-theme-"+p:"cm-theme";return Bf.jsx("div",wr({ref:ge,className:""+G+(t?" "+t:"")},_))});Py.displayName="CodeMirror";const Ry=y.Annotation.define(),By=N.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Ly{constructor(e,t,n,s){this.field=e,this.line=t,this.from=n,this.to=s}}class Zr{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(e){let t=e.mapPos(this.from,-1,y.MapMode.TrackDel),n=e.mapPos(this.to,1,y.MapMode.TrackDel);return t==null||n==null?null:new Zr(this.field,t,n)}}class eo{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],s=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(n.length){let f=o,c=/^\t*/.exec(a)[0].length;for(let p=0;p<c;p++)f+=e.facet(Xt);s.push(t+f.length-c),a=f+a.slice(c)}n.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new Zr(a.field,s[a.line]+a.from,s[a.line]+a.to));return{text:n,ranges:l}}static parse(e){let t=[],n=[],s=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",f=-1,c=a.replace(/\\[{}]/g,p=>p[1]);for(let p=0;p<t.length;p++)(l!=null?t[p].seq==l:c&&t[p].name==c)&&(f=p);if(f<0){let p=0;for(;p<t.length&&(l==null||t[p].seq!=null&&t[p].seq<l);)p++;t.splice(p,0,{seq:l,name:c}),f=p;for(let g of s)g.field>=f&&g.field++}s.push(new Ly(f,n.length,r.index,r.index+c.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,a,f)=>{for(let c of s)c.line==n.length&&c.from>f&&(c.from--,c.to--);return a}),n.push(o)}return new eo(n,s)}}let Iy=H.widget({widget:new class extends je{toDOM(){let i=document.createElement("span");return i.className="cm-snippetFieldPosition",i}ignoreEvent(){return!1}}}),Ny=H.mark({class:"cm-snippetField"});class ti{constructor(e,t){this.ranges=e,this.active=t,this.deco=H.set(e.map(n=>(n.from==n.to?Iy:Ny).range(n.from,n.to)))}map(e){let t=[];for(let n of this.ranges){let s=n.map(e);if(!s)return null;t.push(s)}return new ti(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(n=>n.field==this.active&&n.from<=t.from&&n.to>=t.to))}}const zi=y.StateEffect.define({map(i,e){return i&&i.map(e)}}),Fy=y.StateEffect.define(),Ri=y.StateField.define({create(){return null},update(i,e){for(let t of e.effects){if(t.is(zi))return t.value;if(t.is(Fy)&&i)return new ti(i.ranges,t.value)}return i&&e.docChanged&&(i=i.map(e.changes)),i&&e.selection&&!i.selectionInsideField(e.selection)&&(i=null),i},provide:i=>N.decorations.from(i,e=>e?e.deco:H.none)});function to(i,e){return y.EditorSelection.create(i.filter(t=>t.field==e).map(t=>y.EditorSelection.range(t.from,t.to)))}function Vy(i){let e=eo.parse(i);return(t,n,s,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,s),{main:a}=t.state.selection,f={changes:{from:s,to:r==a.from?a.to:r,insert:y.Text.of(o)},scrollIntoView:!0,annotations:n?[Ry.of(n),y.Transaction.userEvent.of("input.complete")]:void 0};if(l.length&&(f.selection=to(l,0)),l.some(c=>c.field>0)){let c=new ti(l,0),p=f.effects=[zi.of(c)];t.state.field(Ri,!1)===void 0&&p.push(y.StateEffect.appendConfig.of([Ri,qy,_y,By]))}t.dispatch(t.state.update(f))}}function _c(i){return({state:e,dispatch:t})=>{let n=e.field(Ri,!1);if(!n||i<0&&n.active==0)return!1;let s=n.active+i,r=i>0&&!n.ranges.some(o=>o.field==s+i);return t(e.update({selection:to(n.ranges,s),effects:zi.of(r?null:new ti(n.ranges,s)),scrollIntoView:!0})),!0}}const Hy=({state:i,dispatch:e})=>i.field(Ri,!1)?(e(i.update({effects:zi.of(null)})),!0):!1,Wy=_c(1),$y=_c(-1),zy=[{key:"Tab",run:Wy,shift:$y},{key:"Escape",run:Hy}],Zl=y.Facet.define({combine(i){return i.length?i[0]:zy}}),qy=y.Prec.highest(Gt.compute([Zl],i=>i.facet(Zl)));function jy(i,e){return Object.assign(Object.assign({},e),{apply:Vy(i)})}const _y=N.domEventHandlers({mousedown(i,e){let t=e.state.field(Ri,!1),n;if(!t||(n=e.posAtCoords({x:i.clientX,y:i.clientY}))==null)return!1;let s=t.ranges.find(r=>r.from<=n&&r.to>=n);return!s||s.field==t.active?!1:(e.dispatch({selection:to(t.ranges,s.field),effects:zi.of(t.ranges.some(r=>r.field>s.field)?new ti(t.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Kc=new class extends y.RangeValue{};Kc.startSide=1;Kc.endSide=-1;ha.setLevel("silent");const le=ha,j={STRING:"String",NUMBER:"Number",TRUE:"True",FALSE:"False",NULL:"Null",OBJECT:"Object",ARRAY:"Array",PROPERTY:"Property",PROPERTY_NAME:"PropertyName",PROPERTY_COLON:"PropertyColon",ITEM:"Item",JSON_TEXT:"JsonText",INVALID:"⚠"},Ky={Pair:j.PROPERTY,Key:j.PROPERTY_NAME,BlockSequence:j.ARRAY,BlockMapping:j.OBJECT,FlowSequence:j.ARRAY,FlowMapping:j.OBJECT,QuotedLiteral:j.STRING,Literal:j.STRING,Stream:j.JSON_TEXT,Document:j.OBJECT},Jy={File:j.JSON_TEXT},io=[j.STRING,j.NUMBER,j.TRUE,j.FALSE,j.NULL],Jc=[j.OBJECT,j.ARRAY,j.ITEM],ee={JSON5:"json5",JSON:"json4",YAML:"yaml"},ae=(i,e)=>{var t,n;switch(e){case ee.YAML:return(t=Ky[i])!==null&&t!==void 0?t:i;case ee.JSON5:return(n=Jy[i])!==null&&n!==void 0?n:i;default:return i}};function Uc(i,e,t){const n=[];for(let s=e;s!=null&&s.parent;s=s.parent)switch(ae(s.parent.name,t)){case j.PROPERTY:{const r=br(s.parent,j.PROPERTY_NAME,t);r&&n.unshift(Pt(i,r).replace(/[/~]/g,o=>o==="~"?"~0":"~1"));break}case j.ARRAY:{if(Yy(s,t)){const r=Xc(s.parent,s,t);n.unshift(`${r}`)}break}}return n.unshift(""),n.join("/")}const Yc=(i,e,t=-1,n)=>Uc(i.doc,te(i).resolve(e,t),n),no=(i,e)=>{const t=te(i),n=new Map;return t.iterate({enter:s=>{var r,o,l,a,f,c,p,g;if([j.PROPERTY_NAME,j.OBJECT].includes(ae(s.name,e))){const v=Uc(i.doc,s.node,e),{from:k,to:C}=s.node;if(!(!((o=(r=s.node)===null||r===void 0?void 0:r.nextSibling)===null||o===void 0)&&o.node))return n.set(v,{keyFrom:k,keyTo:C}),!0;const M=e===ee.JSON?(a=(l=s.node)===null||l===void 0?void 0:l.nextSibling)===null||a===void 0?void 0:a.node:(g=(p=(c=(f=s.node)===null||f===void 0?void 0:f.nextSibling)===null||c===void 0?void 0:c.node)===null||p===void 0?void 0:p.nextSibling)===null||g===void 0?void 0:g.node;if(!M)return n.set(v,{keyFrom:k,keyTo:C}),!0;const{from:T,to:P}=M;return n.set(v,{keyFrom:k,keyTo:C,valueFrom:T,valueTo:P}),!0}}}),n},Fs=(i,e,t=-1)=>te(i).resolveInner(e,t),kn=i=>i.replace(/^"(.*)"$/,"$1").replace(/^'(.*)'$/,"$1"),Uy=i=>i.replace(/^"(.*)"$/,"'$1'"),Pt=(i,e,t=!0,n=!0)=>{const s=e?i.sliceString(e.from,e.to):"";return t?n?kn(s):s.replace(/(^["'])|(["']$)/g,""):s},Gc=(i,e)=>{var t,n,s,r;return ae(i.name,e)===j.INVALID&&(ae((n=(t=i.prevSibling)===null||t===void 0?void 0:t.name)!==null&&n!==void 0?n:"",e)===j.PROPERTY_NAME||ae((r=(s=i.prevSibling)===null||s===void 0?void 0:s.name)!==null&&r!==void 0?r:"",e)===j.PROPERTY_COLON)},Cn=(i,e)=>io.includes(ae(i.name,e))||Gc(i,e),Yy=(i,e)=>[...io,...Jc].includes(ae(i.name,e))||Gc(i,e),fn=(i,e)=>{var t,n,s,r,o,l;return ae(i.name,e)===j.PROPERTY_NAME||ae(i.name,e)===j.INVALID&&(ae((n=(t=i.prevSibling)===null||t===void 0?void 0:t.name)!==null&&n!==void 0?n:"",e)===j.PROPERTY||ae((r=(s=i.prevSibling)===null||s===void 0?void 0:s.name)!==null&&r!==void 0?r:"",e)==="{")||e===ee.YAML&&ae((l=(o=i.parent)===null||o===void 0?void 0:o.name)!==null&&l!==void 0?l:"",e)===j.OBJECT},qi=i=>{const e=[];let t=i.firstChild;for(;t;)t&&e.push(t),t=t==null?void 0:t.nextSibling;return e},Gy=(i,e,t)=>qi(i).filter(n=>ae(n.name,t)===e),br=(i,e,t)=>{var n;return(n=qi(i).find(s=>ae(s.name,t)===e))!==null&&n!==void 0?n:null},ea=(i,e)=>qi(i).find(t=>Cn(t,e)),Xy=(i,e)=>qi(i).filter(t=>io.includes(ae(t.name,e))||Jc.includes(ae(t.name,e))),Xc=(i,e,t)=>Xy(i,t).findIndex(n=>n.from===e.from&&n.to===e.to),ta=(i,e,t,n=1/0)=>{let s=i;for(;s&&n>0;){if(ae(s.name,t)===e)return s;s=s.parent,n--}return null},Qy=y.StateEffect.define(),jn=y.StateField.define({create(){},update(i,e){for(const t of e.effects)if(t.is(Qy))return t.value;return i}}),so=i=>i.field(jn),Lb=i=>[jn.init(()=>i)];function Ue(i,e,t=[]){const n=document.createElement(i);return Object.entries(e).forEach(([s,r])=>{if(s==="text"){n.innerText=r;return}if(s==="inner"){n.innerHTML=r;return}n.setAttribute(s,r)}),t.forEach(s=>n.appendChild(s)),n}const Sr=Lf({linkify:!0,typographer:!0});(async()=>{const i=await Wf({themes:[ds(()=>import("./vendor-shiki-DZajAPeq.js").then(e=>e.v),__vite__mapDeps([0,1,2,3])),ds(()=>import("./vendor-shiki-DZajAPeq.js").then(e=>e.a),__vite__mapDeps([0,1,2,3]))],langs:[ds(()=>import("./vendor-shiki-DZajAPeq.js").then(e=>e.j),__vite__mapDeps([0,1,2,3]))]});Sr.use($f(i,{themes:{light:"vitesse-light",dark:"vitesse-dark"}}))})();function $t(i,e=!0){return e?Sr.renderInline(i):Sr.render(i)}function Zy(i){let e=null;try{e=JSON.parse(i.doc.toString())}catch{try{e=ca.parse(i.doc.toString())}catch{}}const t=no(i,ee.JSON);return{data:e,pointers:t}}function eb(i){let e=null;try{e=If.parse(i.doc.toString())}catch{try{e=ca.parse(i.doc.toString())}catch{}}const t=no(i,ee.JSON5);return{data:e,pointers:t}}function tb(i){let e=null;try{e=Nf.parse(i.doc.toString())}catch{}const t=no(i,ee.YAML);return{data:e,pointers:t}}const Qc=i=>{switch(i){case ee.JSON:return Zy;case ee.JSON5:return eb;case ee.YAML:return tb}};class ib{constructor(){this.completions=new Map,this.reservedKeys=new Set}reserve(e){this.reservedKeys.add(e)}add(e){this.reservedKeys.has(e.label)||this.completions.set(e.label,e)}}class nb{constructor(e){var t,n,s;this.opts=e,this.schema=null,this.mode=ee.JSON,this.mode=(t=e.mode)!==null&&t!==void 0?t:ee.JSON,this.parser=(s=(n=this.opts)===null||n===void 0?void 0:n.jsonParser)!==null&&s!==void 0?s:Qc(this.mode)}doComplete(e){var t,n,s;const r=so(e.state);if(this.schema=(t=this.expandSchemaProperty(r,r))!==null&&t!==void 0?t:r,!this.schema)return[];const o={from:e.pos,to:e.pos,options:[],filter:!1},l=e.state.doc.sliceString(0);let a=Fs(e.state,e.pos),f=e.state.sliceDoc(a.from,e.pos).replace(/^(["'])/,"");if(le.log("xxx","node",a,"prefix",f,"ctx",e),!(Cn(a,this.mode)||fn(a,this.mode))&&!e.explicit)return le.log("xxx","no completions for non-word/primitive",a),o;const c=Pt(e.state.doc,a),p=Pt(e.state.doc,a,!1);if(a&&(Cn(a,this.mode)||fn(a,this.mode)))o.from=a.from,o.to=a.to;else{const C=e.matchBefore(/[A-Za-z0-9._]*/),M=e.pos-c.length;le.log("xxx","overwriteStart after",M,"ctx.pos",e.pos,"word",C,"currentWord",c,"=>",l[M-1],"..",l[M],"..",l),o.from=a.name===j.INVALID?(n=C==null?void 0:C.from)!==null&&n!==void 0?n:e.pos:M,o.to=e.pos}const g=new ib;let v=!0;const k=ta(a,j.PROPERTY_NAME,this.mode);if(k&&(le.log("xxx","closestPropertyNameNode",k,"node",a),a=k),fn(a,this.mode)){le.log("xxx","isPropertyNameNode",a);const C=a.parent;if(C){const M=ea(C,this.mode);v=!M||M.name===j.INVALID&&M.from-M.to===0||(M.parent?qi(M.parent).length<=1:!1),le.log("xxx","addValue",v,ea(C,this.mode),a),a=(s=ta(C,j.OBJECT,this.mode))!==null&&s!==void 0?s:null}}if(le.log("xxx",a,c,e,"node at pos",Fs(e.state,e.pos)),a&&[j.OBJECT,j.JSON_TEXT].includes(ae(a.name,this.mode))&&(fn(Fs(e.state,e.pos),this.mode)||k)){if(a.from===e.pos)return le.log("xxx","no completions for just before opening brace"),o;this.getPropertyCompletions(this.schema,e,a,g,v,p)}else{const C={},M=this.getValueCompletions(this.schema,e,C,g);le.log("xxx","getValueCompletions res",M)}return o.options=Array.from(g.completions.values()).filter(C=>kn(C.label).startsWith(f)),le.log("xxx","result",o,"prefix",f,"collector.completions",g.completions,"reservedKeys",g.reservedKeys),o}applySnippetCompletion(e){return jy(typeof e.apply!="string"?e.label:e.apply,e)}getPropertyCompletions(e,t,n,s,r,o){const l=Gy(n,j.PROPERTY,this.mode);le.log("xxx","getPropertyCompletions",n,t,l),l.forEach(f=>{const c=Pt(t.state.doc,br(f,j.PROPERTY_NAME,this.mode));s.reserve(kn(c))});const a=this.getSchemas(e,t);le.log("xxx","propertyCompletion schemas",a),a.forEach(f=>{if(typeof f!="object")return;const c=f.properties;c&&Object.entries(c).forEach(([g,v])=>{var k,C;if(typeof v=="object"){const M=(k=v.description)!==null&&k!==void 0?k:"",T=(C=v.type)!==null&&C!==void 0?C:"",P=Array.isArray(T)?T.toString():T,F={label:g,apply:this.getInsertTextForProperty(g,r,o,v),type:"property",detail:P,info:()=>Ue("div",{inner:$t(M)})};s.add(this.applySnippetCompletion(F))}});const p=f.propertyNames;if(typeof p=="object"&&(p.enum&&p.enum.forEach(g=>{const v=g==null?void 0:g.toString();if(v){const k={label:v,apply:this.getInsertTextForProperty(v,r,o),type:"property"};s.add(this.applySnippetCompletion(k))}}),p.const)){const g=p.const.toString(),v={label:g,apply:this.getInsertTextForProperty(g,r,o),type:"property"};s.add(this.applySnippetCompletion(v))}})}getInsertTextForProperty(e,t,n,s){s=s&&this.expandSchemaProperty(s,this.schema);let r=this.getInsertTextForPropertyName(e,n);if(!t)return r;r+=": ";let o,l=0;if(typeof s=="object"){if(typeof s.default<"u")o||(o=this.getInsertTextForGuessedValue(s.default,"")),l++;else if(s.enum&&(!o&&s.enum.length===1&&(o=this.getInsertTextForGuessedValue(s.enum[0],"")),l+=s.enum.length),typeof s.const<"u"&&(o||(o=this.getInsertTextForGuessedValue(s.const,"")),l++),Array.isArray(s.examples)&&s.examples.length&&(o||(o=this.getInsertTextForGuessedValue(s.examples[0],"")),l+=s.examples.length),o===void 0&&l===0){let a=Array.isArray(s.type)?s.type[0]:s.type;switch(a||(s.properties?a="object":s.items&&(a="array")),a){case"boolean":o="#{}";break;case"string":o=this.getInsertTextForString("");break;case"object":switch(this.mode){case ee.JSON5:o="{#{}}";break;case ee.YAML:o="#{}";break;default:o="{#{}}";break}break;case"array":o="[#{}]";break;case"number":case"integer":o="#{0}";break;case"null":o="#{null}";break;default:o="#{}";break}}}return(!o||l>1)&&(le.log("xxx","value",o,"nValueProposals",l,s),o="#{}"),r+o}getInsertTextForPropertyName(e,t){switch(this.mode){case ee.JSON5:case ee.YAML:return t.startsWith('"')?`"${e}"`:t.startsWith("'")?`'${e}'`:e;default:return`"${e}"`}}getInsertTextForString(e,t="#"){switch(this.mode){case ee.JSON5:return`'${t}{${e}}'`;case ee.YAML:return`${t}{${e}}`;default:return`"${t}{${e}}"`}}getInsertTextForGuessedValue(e,t=""){switch(typeof e){case"object":return e===null?"${null}"+t:this.getInsertTextForValue(e,t);case"string":{let n=JSON.stringify(e);return n=n.substr(1,n.length-2),n=this.getInsertTextForPlainText(n),this.getInsertTextForString(n,"$")+t}case"number":case"boolean":return"${"+JSON.stringify(e)+"}"+t}return this.getInsertTextForValue(e,t)}getInsertTextForPlainText(e){return e.replace(/[\\$}]/g,"\\$&")}getInsertTextForValue(e,t){const n=JSON.stringify(e,null," ");return n==="{}"?"{#{}}"+t:n==="[]"?"[#{}]"+t:this.getInsertTextForPlainText(n+t)}getValueCompletions(e,t,n,s){let r=te(t.state).resolveInner(t.pos,-1),o=null,l;if(le.log("xxx","getValueCompletions",r,t),r&&Cn(r,this.mode)&&(o=r,r=r.parent),!r){this.addSchemaValueCompletions(e,n,s);return}if(ae(r.name,this.mode)===j.PROPERTY){const f=br(r,j.PROPERTY_NAME,this.mode);f&&(l=Pt(t.state.doc,f),r=r.parent)}if(le.log("xxx","node",r,"parentKey",l),r&&(l!==void 0||ae(r.name,this.mode)===j.ARRAY)){const f=this.getSchemas(e,t);for(const c of f){if(typeof c!="object")return;if(ae(r.name,this.mode)===j.ARRAY&&c.items){let p=s;if(c.uniqueItems&&(p=Object.assign(Object.assign({},p),{add(g){p.completions.has(g.label)||s.add(g)},reserve(g){s.reserve(g)}})),Array.isArray(c.items)){let g=0;if(o){const k=Xc(r,o,this.mode);k>=0&&(g=k)}const v=c.items[g];v&&this.addSchemaValueCompletions(v,n,p)}else this.addSchemaValueCompletions(c.items,n,p)}if(l!==void 0){let p=!1;if(c.properties){const g=c.properties[l];g&&(p=!0,this.addSchemaValueCompletions(g,n,s))}if(c.patternProperties&&!p)for(const g of Object.keys(c.patternProperties)){const v=this.extendedRegExp(g);if(v!=null&&v.test(l)){p=!0;const k=c.patternProperties[g];k&&this.addSchemaValueCompletions(k,n,s)}}if(c.additionalProperties&&!p){const g=c.additionalProperties;this.addSchemaValueCompletions(g,n,s)}}n.boolean&&(this.addBooleanValueCompletion(!0,s),this.addBooleanValueCompletion(!1,s)),n.null&&this.addNullValueCompletion(s)}}return{valuePrefix:o?Pt(t.state.doc,o,!0,!1):""}}addSchemaValueCompletions(e,t,n){typeof e=="object"&&(this.addEnumValueCompletions(e,n),this.addDefaultValueCompletions(e,n),this.collectTypes(e,t),Array.isArray(e.allOf)&&e.allOf.forEach(s=>this.addSchemaValueCompletions(s,t,n)),Array.isArray(e.anyOf)&&e.anyOf.forEach(s=>this.addSchemaValueCompletions(s,t,n)),Array.isArray(e.oneOf)&&e.oneOf.forEach(s=>this.addSchemaValueCompletions(s,t,n)))}addDefaultValueCompletions(e,t,n=0){let s=!1;if(typeof e.default<"u"){let r=e.type,o=e.default;for(let a=n;a>0;a--)o=[o],r="array";const l=Object.assign(Object.assign({type:r==null?void 0:r.toString()},this.getAppliedValue(o)),{detail:"Default value"});t.add(l),s=!0}Array.isArray(e.examples)&&e.examples.forEach(r=>{let o=e.type,l=r;for(let a=n;a>0;a--)l=[l],o="array";t.add(Object.assign({type:o==null?void 0:o.toString()},this.getAppliedValue(l))),s=!0}),!s&&typeof e.items=="object"&&!Array.isArray(e.items)&&n<5&&this.addDefaultValueCompletions(e.items,t,n+1)}addEnumValueCompletions(e,t){var n,s;if(typeof e.const<"u"&&t.add(Object.assign(Object.assign({type:(n=e.type)===null||n===void 0?void 0:n.toString()},this.getAppliedValue(e.const)),{info:e.description})),Array.isArray(e.enum))for(let r=0,o=e.enum.length;r<o;r++){const l=e.enum[r];t.add(Object.assign(Object.assign({type:(s=e.type)===null||s===void 0?void 0:s.toString()},this.getAppliedValue(l)),{info:e.description}))}}addBooleanValueCompletion(e,t){t.add({type:"boolean",label:e?"true":"false"})}addNullValueCompletion(e){e.add({type:"null",label:"null"})}collectTypes(e,t){if(Array.isArray(e.enum)||typeof e.const<"u")return;const n=e.type;Array.isArray(n)?n.forEach(s=>t[s]=!0):n&&(t[n]=!0)}getSchemas(e,t){var n,s;const r=new Ff(this.schema);let o=Yc(t.state,t.pos,-1,this.mode);const{data:l}=this.parser(t.state);let a=r.getSchema({pointer:o,data:l??void 0});return le.log("xxxx","draft.getSchema",a,"data",l,"pointer",o),fa(a)&&(a=(n=a.data)===null||n===void 0?void 0:n.schema),(!a||a.name==="UnknownPropertyError"||a.enum||a.type==="undefined"||a.type==="null")&&(o=o.replace(/\/[^/]*$/,"/"),a=r.getSchema({pointer:o})),le.log("xxx","pointer..",JSON.stringify(o)),(!o||o==="/")&&(a=(s=this.expandSchemaProperty(e,e))!==null&&s!==void 0?s:e),le.log("xxx","subSchema..",a),a?Array.isArray(a.allOf)?[a,...a.allOf.map(f=>this.expandSchemaProperty(f,e))]:Array.isArray(a.oneOf)?[a,...a.oneOf.map(f=>this.expandSchemaProperty(f,e))]:Array.isArray(a.anyOf)?[a,...a.anyOf.map(f=>this.expandSchemaProperty(f,e))]:[a]:[]}expandSchemaProperty(e,t){if(typeof e=="object"&&e.$ref){const n=this.getReferenceSchema(t,e.$ref);if(typeof n=="object"){const s=Object.assign(Object.assign({},e),n);return Reflect.deleteProperty(s,"$ref"),s}}return e}getReferenceSchema(e,t){const n=t.split("/");let s=e;return n.forEach(r=>{if(r){if(r==="#"){s=e;return}typeof s=="object"&&(s=s[r])}}),s}getAppliedValue(e){const t=kn(JSON.stringify(e));switch(this.mode){case ee.JSON5:return{label:t,apply:Uy(JSON.stringify(e))};case ee.YAML:return{label:t,apply:t};default:return{label:t,apply:JSON.stringify(e)}}}getValueFromLabel(e){return JSON.parse(e)}extendedRegExp(e){let t="";e.startsWith("(?i)")&&(e=e.substring(4),t="i");try{return new RegExp(e,t+"u")}catch{try{return new RegExp(e,t)}catch{return}}}}function Ib(i={}){const e=new nb(i);return function(n){return e.doComplete(n)}}const Bi=(i,e)=>{const t=i.length>2;let n=i.map((s,r)=>{const o="`"+(e?e(s):s)+"`";return r===i.length-1?"or "+o:o});return t?n.join(", "):n.join(" ")},sb=i=>{var e,t,n;return!((e=i==null?void 0:i.data)===null||e===void 0)&&e.pointer&&((t=i==null?void 0:i.data)===null||t===void 0?void 0:t.pointer)!=="#"?i.data.pointer.slice(1):!((n=i==null?void 0:i.data)===null||n===void 0)&&n.property?`/${i.data.property}`:""},Nb=i=>i.startState.field(jn)!==i.state.field(jn);function Fb(i){const e=new ob(i);return t=>e.doValidation(t)}const rb=["NoAdditionalPropertiesError","RequiredPropertyError","InvalidPropertyNameError","ForbiddenPropertyError","UndefinedValueError"];class ob{constructor(e){var t,n,s,r;this.options=e,this.schema=null,this.mode=ee.JSON,this.rewriteError=o=>{var l,a,f,c,p;const g=o==null?void 0:o.data,v=g==null?void 0:g.errors;return o.code==="one-of-error"&&(v!=null&&v.length)?`Expected one of ${Bi(v,C=>C.data.expected)}`:o.code==="type-error"?`Expected \`${!((l=o==null?void 0:o.data)===null||l===void 0)&&l.expected&&Array.isArray((a=o==null?void 0:o.data)===null||a===void 0?void 0:a.expected)?Bi((f=o==null?void 0:o.data)===null||f===void 0?void 0:f.expected):(c=o==null?void 0:o.data)===null||c===void 0?void 0:c.expected}\` but received \`${(p=o==null?void 0:o.data)===null||p===void 0?void 0:p.received}\``:o.message.replaceAll("in `#` ","").replaceAll("at `#`","").replaceAll("/",".").replaceAll("#.","")},this.mode=(n=(t=this.options)===null||t===void 0?void 0:t.mode)!==null&&n!==void 0?n:ee.JSON,this.parser=(r=(s=this.options)===null||s===void 0?void 0:s.jsonParser)!==null&&r!==void 0?r:Qc(this.mode)}get schemaTitle(){var e,t,n;return(n=(t=(e=this.schema)===null||e===void 0?void 0:e.getSchema())===null||t===void 0?void 0:t.title)!==null&&n!==void 0?n:"json-schema"}doValidation(e){const t=so(e.state);if(!t)return[];if(this.schema=new ua(t),!this.schema)return[];const n=e.state.doc.toString();if(!(n!=null&&n.length))return[];const s=this.parser(e.state);let r=[];try{r=this.schema.validate(s.data)}catch{}return le.log("xxx","validation errors",r,s.data),r.length?r.reduce((o,l)=>{const a=()=>{const p=this.rewriteError(l);o.push({from:0,to:0,message:p,severity:"error",source:this.schemaTitle,renderMessage:()=>{const g=Ue("div",{});return g.innerHTML=$t(p),g}})},f=sb(l),c=s.pointers.get(f);if(l.name==="MaxPropertiesError"||l.name==="MinPropertiesError")a();else if(c){const p=rb.includes(l.name),g=this.rewriteError(l),v=p?c.keyFrom:c.valueFrom,k=p?c.keyTo:c.valueTo;k!==void 0&&v!==void 0&&o.push({from:v,to:k,message:g,renderMessage:()=>{const C=Ue("div",{});return C.innerHTML=$t(g),C},severity:"error",source:this.schemaTitle})}else a();return o},[]):[]}}function Vb(i){const e=new lb(i);return async function(n,s,r){return e.doHover(n,s,r)}}function ia(i){if(i.type)return i.$ref?`${i.$ref} (${i.type})`:i.type;if(i.$ref)return`${i.$ref}`}function Vs(i,e,t){return`${e}: ${Bi(i[e].map(n=>{try{const{data:s}=t.resolveRef({data:n,pointer:n.$ref});return ia(s||n)}catch{return n.type}}))}`}class lb{constructor(e){var t,n;this.opts=e,this.schema=null,this.mode=ee.JSON,this.opts=Object.assign({parser:JSON.parse},this.opts),this.mode=(n=(t=this.opts)===null||t===void 0?void 0:t.mode)!==null&&n!==void 0?n:ee.JSON}getDataForCursor(e,t,n){const s=so(e.state);if(!s)return null;this.schema=new ua(s);const r=Yc(e.state,t,n,this.mode);let o;try{o=this.opts.parser(e.state.doc.toString())}catch{}if(!r)return null;let l=this.schema.getSchema({pointer:r,data:o,withSchemaWarning:!0});return fa(l)&&(l!=null&&l.data.schema.$ref?l=this.schema.resolveRef(l):l=l==null?void 0:l.data.schema),{schema:l,pointer:r}}formatMessage(e){const{message:t,typeInfo:n}=e;return t?Ue("div",{class:"cm6-json-schema-hover"},[Ue("div",{class:"cm6-json-schema-hover--description",inner:$t(t,!1)}),Ue("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ue("div",{class:"cm6-json-schema-hover--code",inner:$t(n,!1)})])]):Ue("div",{class:"cm6-json-schema-hover"},[Ue("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ue("code",{class:"cm6-json-schema-hover--code",inner:$t(n,!1)})])])}getHoverTexts(e,t){let n="",s=null;const{schema:r}=e;return r.oneOf&&(n=Vs(r,"oneOf",t)),r.anyOf&&(n=Vs(r,"anyOf",t)),r.allOf&&(n=Vs(r,"allOf",t)),r.type&&(n=Array.isArray(r.type)?Bi(r.type):r.type),r.$ref&&(n=` Reference: ${r.$ref}`),r.enum&&(n=`\`enum\`: ${Bi(r.enum)}`),r.format&&(n+=`\`format\`: ${r.format}`),r.pattern&&(n+=`\`pattern\`: ${r.pattern}`),r.description&&(s=r.description),{message:s,typeInfo:n}}async doHover(e,t,n){var s,r,o,l;const a=t,f=t;try{const c=this.getDataForCursor(e,t,n);if(le.log("cursorData",c),!(c!=null&&c.schema))return null;const g=((r=(s=this.opts)===null||s===void 0?void 0:s.getHoverTexts)!==null&&r!==void 0?r:this.getHoverTexts)(c,this.schema),k=((l=(o=this.opts)===null||o===void 0?void 0:o.formatHover)!==null&&l!==void 0?l:this.formatMessage)(g);return{pos:a,end:f,arrow:!0,above:!0,create:C=>({dom:k})}}catch(c){return le.log(c),null}}}const na=new da,Zc=new Set(["Script","Body","FunctionDefinition","ClassDefinition","LambdaExpression","ForStatement","MatchClause"]);function un(i){return(e,t,n)=>{if(n)return!1;let s=e.node.getChild("VariableName");return s&&t(s,i),!0}}const ab={FunctionDefinition:un("function"),ClassDefinition:un("class"),ForStatement(i,e,t){if(t){for(let n=i.node.firstChild;n;n=n.nextSibling)if(n.name=="VariableName")e(n,"variable");else if(n.name=="in")break}},ImportStatement(i,e){var t,n;let{node:s}=i,r=((t=s.firstChild)===null||t===void 0?void 0:t.name)=="from";for(let o=s.getChild("import");o;o=o.nextSibling)o.name=="VariableName"&&((n=o.nextSibling)===null||n===void 0?void 0:n.name)!="as"&&e(o,r?"variable":"namespace")},AssignStatement(i,e){for(let t=i.node.firstChild;t;t=t.nextSibling)if(t.name=="VariableName")e(t,"variable");else if(t.name==":"||t.name=="AssignOp")break},ParamList(i,e){for(let t=null,n=i.node.firstChild;n;n=n.nextSibling)n.name=="VariableName"&&(!t||!/\*|AssignOp/.test(t.name))&&e(n,"variable"),t=n},CapturePattern:un("variable"),AsPattern:un("variable"),__proto__:null};function ef(i,e){let t=na.get(e);if(t)return t;let n=[],s=!0;function r(o,l){let a=i.sliceString(o.from,o.to);n.push({label:a,type:l})}return e.cursor(vr.IncludeAnonymous).iterate(o=>{if(o.name){let l=ab[o.name];if(l&&l(o,r,s)||!s&&Zc.has(o.name))return!1;s=!1}else if(o.to-o.from>8192){for(let l of ef(i,o.node))n.push(l);return!1}}),na.set(e,n),n}const sa=/^[\w\xa1-\uffff][\w\d\xa1-\uffff]*$/,tf=["String","FormatString","Comment","PropertyName"];function hb(i){let e=te(i.state).resolveInner(i.pos,-1);if(tf.indexOf(e.name)>-1)return null;let t=e.name=="VariableName"||e.to-e.from<20&&sa.test(i.state.sliceDoc(e.from,e.to));if(!t&&!i.explicit)return null;let n=[];for(let s=e;s;s=s.parent)Zc.has(s.name)&&(n=n.concat(ef(i.state.doc,s)));return{options:n,from:t?e.from:i.pos,validFor:sa}}const cb=["__annotations__","__builtins__","__debug__","__doc__","__import__","__name__","__loader__","__package__","__spec__","False","None","True"].map(i=>({label:i,type:"constant"})).concat(["ArithmeticError","AssertionError","AttributeError","BaseException","BlockingIOError","BrokenPipeError","BufferError","BytesWarning","ChildProcessError","ConnectionAbortedError","ConnectionError","ConnectionRefusedError","ConnectionResetError","DeprecationWarning","EOFError","Ellipsis","EncodingWarning","EnvironmentError","Exception","FileExistsError","FileNotFoundError","FloatingPointError","FutureWarning","GeneratorExit","IOError","ImportError","ImportWarning","IndentationError","IndexError","InterruptedError","IsADirectoryError","KeyError","KeyboardInterrupt","LookupError","MemoryError","ModuleNotFoundError","NameError","NotADirectoryError","NotImplemented","NotImplementedError","OSError","OverflowError","PendingDeprecationWarning","PermissionError","ProcessLookupError","RecursionError","ReferenceError","ResourceWarning","RuntimeError","RuntimeWarning","StopAsyncIteration","StopIteration","SyntaxError","SyntaxWarning","SystemError","SystemExit","TabError","TimeoutError","TypeError","UnboundLocalError","UnicodeDecodeError","UnicodeEncodeError","UnicodeError","UnicodeTranslateError","UnicodeWarning","UserWarning","ValueError","Warning","ZeroDivisionError"].map(i=>({label:i,type:"type"}))).concat(["bool","bytearray","bytes","classmethod","complex","float","frozenset","int","list","map","memoryview","object","range","set","staticmethod","str","super","tuple","type"].map(i=>({label:i,type:"class"}))).concat(["abs","aiter","all","anext","any","ascii","bin","breakpoint","callable","chr","compile","delattr","dict","dir","divmod","enumerate","eval","exec","exit","filter","format","getattr","globals","hasattr","hash","help","hex","id","input","isinstance","issubclass","iter","len","license","locals","max","min","next","oct","open","ord","pow","print","property","quit","repr","reversed","round","setattr","slice","sorted","sum","vars","zip"].map(i=>({label:i,type:"function"}))),fb=[ne("def ${name}(${params}):\n ${}",{label:"def",detail:"function",type:"keyword"}),ne("for ${name} in ${collection}:\n ${}",{label:"for",detail:"loop",type:"keyword"}),ne("while ${}:\n ${}",{label:"while",detail:"loop",type:"keyword"}),ne("try:\n ${}\nexcept ${error}:\n ${}",{label:"try",detail:"/ except block",type:"keyword"}),ne(`if \${}:
|
|
12
|
-
|
|
13
|
-
`,{label:"if",detail:"block",type:"keyword"}),ne("if ${}:\n ${}\nelse:\n ${}",{label:"if",detail:"/ else block",type:"keyword"}),ne("class ${name}:\n def __init__(self, ${params}):\n ${}",{label:"class",detail:"definition",type:"keyword"}),ne("import ${module}",{label:"import",detail:"statement",type:"keyword"}),ne("from ${module} import ${names}",{label:"from",detail:"import",type:"keyword"})],ub=Oc(tf,Gr(cb.concat(fb)));function ra(i,e){let t=i.baseIndentFor(e),n=i.lineAt(i.pos,-1),s=n.from+n.text.length;return/^\s*($|#)/.test(n.text)&&i.node.to<s+100&&!/\S/.test(i.state.sliceDoc(s,i.node.to))&&i.lineIndent(i.pos,-1)<=t||/^\s*(else:|elif |except |finally:)/.test(i.textAfter)&&i.lineIndent(i.pos,-1)>t?null:t+i.unit}const Hs=Kt.define({name:"python",parser:Vf.configure({props:[Yn.add({Body:i=>{var e;return(e=ra(i,i.node))!==null&&e!==void 0?e:i.continue()},IfStatement:i=>/^\s*(else:|elif )/.test(i.textAfter)?i.baseIndent:i.continue(),TryStatement:i=>/^\s*(except |finally:|else:)/.test(i.textAfter)?i.baseIndent:i.continue(),"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression":xn({closing:")"}),"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression":xn({closing:"}"}),"ArrayExpression ArrayComprehensionExpression":xn({closing:"]"}),"String FormatString":()=>null,Script:i=>{if(i.pos+/\s*/.exec(i.textAfter)[0].length>=i.node.to){let e=null;for(let t=i.node,n=t.to;t=t.lastChild,!(!t||t.to!=n);)t.type.name=="Body"&&(e=t);if(e){let t=ra(i,e);if(t!=null)return t}}return i.continue()}}),Gn.add({"ArrayExpression DictionaryExpression SetExpression TupleExpression":Hr,Body:(i,e)=>({from:i.from+1,to:i.to-(i.to==e.doc.length?0:1)})})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"'''",'"""'],stringPrefixes:["f","fr","rf","r","u","b","br","rb","F","FR","RF","R","U","B","BR","RB"]},commentTokens:{line:"#"},indentOnInput:/^\s*([\}\]\)]|else:|elif |except |finally:)$/}});function Hb(){return new Nr(Hs,[Hs.data.of({autocomplete:hb}),Hs.data.of({autocomplete:ub})])}const nf=[ne("function ${name}(${params}) {\n ${}\n}",{label:"function",detail:"definition",type:"keyword"}),ne("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n ${}\n}",{label:"for",detail:"loop",type:"keyword"}),ne("for (let ${name} of ${collection}) {\n ${}\n}",{label:"for",detail:"of loop",type:"keyword"}),ne("do {\n ${}\n} while (${})",{label:"do",detail:"loop",type:"keyword"}),ne("while (${}) {\n ${}\n}",{label:"while",detail:"loop",type:"keyword"}),ne(`try {
|
|
14
|
-
\${}
|
|
15
|
-
} catch (\${error}) {
|
|
16
|
-
\${}
|
|
17
|
-
}`,{label:"try",detail:"/ catch block",type:"keyword"}),ne("if (${}) {\n ${}\n}",{label:"if",detail:"block",type:"keyword"}),ne(`if (\${}) {
|
|
18
|
-
\${}
|
|
19
|
-
} else {
|
|
20
|
-
\${}
|
|
21
|
-
}`,{label:"if",detail:"/ else block",type:"keyword"}),ne(`class \${name} {
|
|
22
|
-
constructor(\${params}) {
|
|
23
|
-
\${}
|
|
24
|
-
}
|
|
25
|
-
}`,{label:"class",detail:"definition",type:"keyword"}),ne('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),ne('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],db=nf.concat([ne("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),ne("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),ne("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),oa=new da,sf=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function ui(i){return(e,t)=>{let n=e.node.getChild("VariableDefinition");return n&&t(n,i),!0}}const pb=["FunctionDeclaration"],mb={FunctionDeclaration:ui("function"),ClassDeclaration:ui("class"),ClassExpression:()=>!0,EnumDeclaration:ui("constant"),TypeAliasDeclaration:ui("type"),NamespaceDeclaration:ui("namespace"),VariableDefinition(i,e){i.matchContext(pb)||e(i,"variable")},TypeDefinition(i,e){e(i,"type")},__proto__:null};function rf(i,e){let t=oa.get(e);if(t)return t;let n=[],s=!0;function r(o,l){let a=i.sliceString(o.from,o.to);n.push({label:a,type:l})}return e.cursor(vr.IncludeAnonymous).iterate(o=>{if(s)s=!1;else if(o.name){let l=mb[o.name];if(l&&l(o,r)||sf.has(o.name))return!1}else if(o.to-o.from>8192){for(let l of rf(i,o.node))n.push(l);return!1}}),oa.set(e,n),n}const la=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,of=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function gb(i){let e=te(i.state).resolveInner(i.pos,-1);if(of.indexOf(e.name)>-1)return null;let t=e.name=="VariableName"||e.to-e.from<20&&la.test(i.state.sliceDoc(e.from,e.to));if(!t&&!i.explicit)return null;let n=[];for(let s=e;s;s=s.parent)sf.has(s.name)&&(n=n.concat(rf(i.state.doc,s)));return{options:n,from:t?e.from:i.pos,validFor:la}}const vt=Kt.define({name:"javascript",parser:Hf.configure({props:[Yn.add({IfStatement:vi({except:/^\s*({|else\b)/}),TryStatement:vi({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:Dp,SwitchBody:i=>{let e=i.textAfter,t=/^\s*\}/.test(e),n=/^\s*(case|default)\b/.test(e);return i.baseIndent+(t?0:n?1:2)*i.unit},Block:xn({closing:"}"}),ArrowFunction:i=>i.baseIndent+i.unit,"TemplateString BlockComment":()=>null,"Statement Property":vi({except:/^\s*{/}),JSXElement(i){let e=/^\s*<\//.test(i.textAfter);return i.lineIndent(i.node.from)+(e?0:i.unit)},JSXEscape(i){let e=/\s*\}/.test(i.textAfter);return i.lineIndent(i.node.from)+(e?0:i.unit)},"JSXOpenTag JSXSelfClosingTag"(i){return i.column(i.node.from)+i.unit}}),Gn.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":Hr,BlockComment(i){return{from:i.from+2,to:i.to-2}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),lf={test:i=>/^JSX/.test(i.name),facet:vh({commentTokens:{block:{open:"{/*",close:"*/}"}}})},yb=vt.configure({dialect:"ts"},"typescript"),bb=vt.configure({dialect:"jsx",props:[Ir.add(i=>i.isTop?[lf]:void 0)]}),Sb=vt.configure({dialect:"jsx ts",props:[Ir.add(i=>i.isTop?[lf]:void 0)]},"typescript");let af=i=>({label:i,type:"keyword"});const hf="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(af),vb=hf.concat(["declare","implements","private","protected","public"].map(af));function Wb(i={}){let e=i.jsx?i.typescript?Sb:bb:i.typescript?yb:vt,t=i.typescript?db.concat(vb):nf.concat(hf);return new Nr(e,[vt.data.of({autocomplete:Oc(of,Gr(t))}),vt.data.of({autocomplete:gb}),i.jsx?kb:[]])}function xb(i){for(;;){if(i.name=="JSXOpenTag"||i.name=="JSXSelfClosingTag"||i.name=="JSXFragmentTag")return i;if(i.name=="JSXEscape"||!i.parent)return null;i=i.parent}}function aa(i,e,t=i.length){for(let n=e==null?void 0:e.firstChild;n;n=n.nextSibling)if(n.name=="JSXIdentifier"||n.name=="JSXBuiltin"||n.name=="JSXNamespacedName"||n.name=="JSXMemberExpression")return i.sliceString(n.from,Math.min(n.to,t));return""}const wb=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),kb=N.inputHandler.of((i,e,t,n,s)=>{if((wb?i.composing:i.compositionStarted)||i.state.readOnly||e!=t||n!=">"&&n!="/"||!vt.isActiveAt(i.state,e,-1))return!1;let r=s(),{state:o}=r,l=o.changeByRange(a=>{var f;let{head:c}=a,p=te(o).resolveInner(c-1,-1),g;if(p.name=="JSXStartTag"&&(p=p.parent),!(o.doc.sliceString(c-1,c)!=n||p.name=="JSXAttributeValue"&&p.to>c)){if(n==">"&&p.name=="JSXFragmentTag")return{range:a,changes:{from:c,insert:"</>"}};if(n=="/"&&p.name=="JSXStartCloseTag"){let v=p.parent,k=v.parent;if(k&&v.from==c-2&&((g=aa(o.doc,k.firstChild,c))||((f=k.firstChild)===null||f===void 0?void 0:f.name)=="JSXFragmentTag")){let C=`${g}>`;return{range:y.EditorSelection.cursor(c+C.length,-1),changes:{from:c,insert:C}}}}else if(n==">"){let v=xb(p);if(v&&v.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(o.doc.sliceString(c,c+2))&&(g=aa(o.doc,v,c)))return{range:a,changes:{from:c,insert:`</${g}>`}}}}return{range:a}});return l.changes.empty?!1:(i.dispatch([r,o.update(l,{userEvent:"input.complete",scrollIntoView:!0})]),!0)});export{N as E,Kt as L,Py as R,Nr as a,Tb as b,Fb as c,bg as d,xg as e,Ib as f,op as g,Nb as h,Vb as i,Ob as j,Gt as k,Db as l,Pb as m,Rb as n,Wb as o,Hb as p,hy as q,Lb as s};
|