arize-phoenix 10.0.4__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.
Files changed (276) hide show
  1. {arize_phoenix-10.0.4.dist-info → arize_phoenix-12.28.1.dist-info}/METADATA +124 -72
  2. arize_phoenix-12.28.1.dist-info/RECORD +499 -0
  3. {arize_phoenix-10.0.4.dist-info → arize_phoenix-12.28.1.dist-info}/WHEEL +1 -1
  4. {arize_phoenix-10.0.4.dist-info → arize_phoenix-12.28.1.dist-info}/licenses/IP_NOTICE +1 -1
  5. phoenix/__generated__/__init__.py +0 -0
  6. phoenix/__generated__/classification_evaluator_configs/__init__.py +20 -0
  7. phoenix/__generated__/classification_evaluator_configs/_document_relevance_classification_evaluator_config.py +17 -0
  8. phoenix/__generated__/classification_evaluator_configs/_hallucination_classification_evaluator_config.py +17 -0
  9. phoenix/__generated__/classification_evaluator_configs/_models.py +18 -0
  10. phoenix/__generated__/classification_evaluator_configs/_tool_selection_classification_evaluator_config.py +17 -0
  11. phoenix/__init__.py +5 -4
  12. phoenix/auth.py +39 -2
  13. phoenix/config.py +1763 -91
  14. phoenix/datetime_utils.py +120 -2
  15. phoenix/db/README.md +595 -25
  16. phoenix/db/bulk_inserter.py +145 -103
  17. phoenix/db/engines.py +140 -33
  18. phoenix/db/enums.py +3 -12
  19. phoenix/db/facilitator.py +302 -35
  20. phoenix/db/helpers.py +1000 -65
  21. phoenix/db/iam_auth.py +64 -0
  22. phoenix/db/insertion/dataset.py +135 -2
  23. phoenix/db/insertion/document_annotation.py +9 -6
  24. phoenix/db/insertion/evaluation.py +2 -3
  25. phoenix/db/insertion/helpers.py +17 -2
  26. phoenix/db/insertion/session_annotation.py +176 -0
  27. phoenix/db/insertion/span.py +15 -11
  28. phoenix/db/insertion/span_annotation.py +3 -4
  29. phoenix/db/insertion/trace_annotation.py +3 -4
  30. phoenix/db/insertion/types.py +50 -20
  31. phoenix/db/migrations/versions/01a8342c9cdf_add_user_id_on_datasets.py +40 -0
  32. phoenix/db/migrations/versions/0df286449799_add_session_annotations_table.py +105 -0
  33. phoenix/db/migrations/versions/272b66ff50f8_drop_single_indices.py +119 -0
  34. phoenix/db/migrations/versions/58228d933c91_dataset_labels.py +67 -0
  35. phoenix/db/migrations/versions/699f655af132_experiment_tags.py +57 -0
  36. phoenix/db/migrations/versions/735d3d93c33e_add_composite_indices.py +41 -0
  37. phoenix/db/migrations/versions/a20694b15f82_cost.py +196 -0
  38. phoenix/db/migrations/versions/ab513d89518b_add_user_id_on_dataset_versions.py +40 -0
  39. phoenix/db/migrations/versions/d0690a79ea51_users_on_experiments.py +40 -0
  40. phoenix/db/migrations/versions/deb2c81c0bb2_dataset_splits.py +139 -0
  41. phoenix/db/migrations/versions/e76cbd66ffc3_add_experiments_dataset_examples.py +87 -0
  42. phoenix/db/models.py +669 -56
  43. phoenix/db/pg_config.py +10 -0
  44. phoenix/db/types/model_provider.py +4 -0
  45. phoenix/db/types/token_price_customization.py +29 -0
  46. phoenix/db/types/trace_retention.py +23 -15
  47. phoenix/experiments/evaluators/utils.py +3 -3
  48. phoenix/experiments/functions.py +160 -52
  49. phoenix/experiments/tracing.py +2 -2
  50. phoenix/experiments/types.py +1 -1
  51. phoenix/inferences/inferences.py +1 -2
  52. phoenix/server/api/auth.py +38 -7
  53. phoenix/server/api/auth_messages.py +46 -0
  54. phoenix/server/api/context.py +100 -4
  55. phoenix/server/api/dataloaders/__init__.py +79 -5
  56. phoenix/server/api/dataloaders/annotation_configs_by_project.py +31 -0
  57. phoenix/server/api/dataloaders/annotation_summaries.py +60 -8
  58. phoenix/server/api/dataloaders/average_experiment_repeated_run_group_latency.py +50 -0
  59. phoenix/server/api/dataloaders/average_experiment_run_latency.py +17 -24
  60. phoenix/server/api/dataloaders/cache/two_tier_cache.py +1 -2
  61. phoenix/server/api/dataloaders/dataset_dataset_splits.py +52 -0
  62. phoenix/server/api/dataloaders/dataset_example_revisions.py +0 -1
  63. phoenix/server/api/dataloaders/dataset_example_splits.py +40 -0
  64. phoenix/server/api/dataloaders/dataset_examples_and_versions_by_experiment_run.py +47 -0
  65. phoenix/server/api/dataloaders/dataset_labels.py +36 -0
  66. phoenix/server/api/dataloaders/document_evaluation_summaries.py +2 -2
  67. phoenix/server/api/dataloaders/document_evaluations.py +6 -9
  68. phoenix/server/api/dataloaders/experiment_annotation_summaries.py +88 -34
  69. phoenix/server/api/dataloaders/experiment_dataset_splits.py +43 -0
  70. phoenix/server/api/dataloaders/experiment_error_rates.py +21 -28
  71. phoenix/server/api/dataloaders/experiment_repeated_run_group_annotation_summaries.py +77 -0
  72. phoenix/server/api/dataloaders/experiment_repeated_run_groups.py +57 -0
  73. phoenix/server/api/dataloaders/experiment_runs_by_experiment_and_example.py +44 -0
  74. phoenix/server/api/dataloaders/last_used_times_by_generative_model_id.py +35 -0
  75. phoenix/server/api/dataloaders/latency_ms_quantile.py +40 -8
  76. phoenix/server/api/dataloaders/record_counts.py +37 -10
  77. phoenix/server/api/dataloaders/session_annotations_by_session.py +29 -0
  78. phoenix/server/api/dataloaders/span_cost_by_span.py +24 -0
  79. phoenix/server/api/dataloaders/span_cost_detail_summary_entries_by_generative_model.py +56 -0
  80. phoenix/server/api/dataloaders/span_cost_detail_summary_entries_by_project_session.py +57 -0
  81. phoenix/server/api/dataloaders/span_cost_detail_summary_entries_by_span.py +43 -0
  82. phoenix/server/api/dataloaders/span_cost_detail_summary_entries_by_trace.py +56 -0
  83. phoenix/server/api/dataloaders/span_cost_details_by_span_cost.py +27 -0
  84. phoenix/server/api/dataloaders/span_cost_summary_by_experiment.py +57 -0
  85. phoenix/server/api/dataloaders/span_cost_summary_by_experiment_repeated_run_group.py +64 -0
  86. phoenix/server/api/dataloaders/span_cost_summary_by_experiment_run.py +58 -0
  87. phoenix/server/api/dataloaders/span_cost_summary_by_generative_model.py +55 -0
  88. phoenix/server/api/dataloaders/span_cost_summary_by_project.py +152 -0
  89. phoenix/server/api/dataloaders/span_cost_summary_by_project_session.py +56 -0
  90. phoenix/server/api/dataloaders/span_cost_summary_by_trace.py +55 -0
  91. phoenix/server/api/dataloaders/span_costs.py +29 -0
  92. phoenix/server/api/dataloaders/table_fields.py +2 -2
  93. phoenix/server/api/dataloaders/token_prices_by_model.py +30 -0
  94. phoenix/server/api/dataloaders/trace_annotations_by_trace.py +27 -0
  95. phoenix/server/api/dataloaders/types.py +29 -0
  96. phoenix/server/api/exceptions.py +11 -1
  97. phoenix/server/api/helpers/dataset_helpers.py +5 -1
  98. phoenix/server/api/helpers/playground_clients.py +1243 -292
  99. phoenix/server/api/helpers/playground_registry.py +2 -2
  100. phoenix/server/api/helpers/playground_spans.py +8 -4
  101. phoenix/server/api/helpers/playground_users.py +26 -0
  102. phoenix/server/api/helpers/prompts/conversions/aws.py +83 -0
  103. phoenix/server/api/helpers/prompts/conversions/google.py +103 -0
  104. phoenix/server/api/helpers/prompts/models.py +205 -22
  105. phoenix/server/api/input_types/{SpanAnnotationFilter.py → AnnotationFilter.py} +22 -14
  106. phoenix/server/api/input_types/ChatCompletionInput.py +6 -2
  107. phoenix/server/api/input_types/CreateProjectInput.py +27 -0
  108. phoenix/server/api/input_types/CreateProjectSessionAnnotationInput.py +37 -0
  109. phoenix/server/api/input_types/DatasetFilter.py +17 -0
  110. phoenix/server/api/input_types/ExperimentRunSort.py +237 -0
  111. phoenix/server/api/input_types/GenerativeCredentialInput.py +9 -0
  112. phoenix/server/api/input_types/GenerativeModelInput.py +5 -0
  113. phoenix/server/api/input_types/ProjectSessionSort.py +161 -1
  114. phoenix/server/api/input_types/PromptFilter.py +14 -0
  115. phoenix/server/api/input_types/PromptVersionInput.py +52 -1
  116. phoenix/server/api/input_types/SpanSort.py +44 -7
  117. phoenix/server/api/input_types/TimeBinConfig.py +23 -0
  118. phoenix/server/api/input_types/UpdateAnnotationInput.py +34 -0
  119. phoenix/server/api/input_types/UserRoleInput.py +1 -0
  120. phoenix/server/api/mutations/__init__.py +10 -0
  121. phoenix/server/api/mutations/annotation_config_mutations.py +8 -8
  122. phoenix/server/api/mutations/api_key_mutations.py +19 -23
  123. phoenix/server/api/mutations/chat_mutations.py +154 -47
  124. phoenix/server/api/mutations/dataset_label_mutations.py +243 -0
  125. phoenix/server/api/mutations/dataset_mutations.py +21 -16
  126. phoenix/server/api/mutations/dataset_split_mutations.py +351 -0
  127. phoenix/server/api/mutations/experiment_mutations.py +2 -2
  128. phoenix/server/api/mutations/export_events_mutations.py +3 -3
  129. phoenix/server/api/mutations/model_mutations.py +210 -0
  130. phoenix/server/api/mutations/project_mutations.py +49 -10
  131. phoenix/server/api/mutations/project_session_annotations_mutations.py +158 -0
  132. phoenix/server/api/mutations/project_trace_retention_policy_mutations.py +8 -4
  133. phoenix/server/api/mutations/prompt_label_mutations.py +74 -65
  134. phoenix/server/api/mutations/prompt_mutations.py +65 -129
  135. phoenix/server/api/mutations/prompt_version_tag_mutations.py +11 -8
  136. phoenix/server/api/mutations/span_annotations_mutations.py +15 -10
  137. phoenix/server/api/mutations/trace_annotations_mutations.py +14 -10
  138. phoenix/server/api/mutations/trace_mutations.py +47 -3
  139. phoenix/server/api/mutations/user_mutations.py +66 -41
  140. phoenix/server/api/queries.py +768 -293
  141. phoenix/server/api/routers/__init__.py +2 -2
  142. phoenix/server/api/routers/auth.py +154 -88
  143. phoenix/server/api/routers/ldap.py +229 -0
  144. phoenix/server/api/routers/oauth2.py +369 -106
  145. phoenix/server/api/routers/v1/__init__.py +24 -4
  146. phoenix/server/api/routers/v1/annotation_configs.py +23 -31
  147. phoenix/server/api/routers/v1/annotations.py +481 -17
  148. phoenix/server/api/routers/v1/datasets.py +395 -81
  149. phoenix/server/api/routers/v1/documents.py +142 -0
  150. phoenix/server/api/routers/v1/evaluations.py +24 -31
  151. phoenix/server/api/routers/v1/experiment_evaluations.py +19 -8
  152. phoenix/server/api/routers/v1/experiment_runs.py +337 -59
  153. phoenix/server/api/routers/v1/experiments.py +479 -48
  154. phoenix/server/api/routers/v1/models.py +7 -0
  155. phoenix/server/api/routers/v1/projects.py +18 -49
  156. phoenix/server/api/routers/v1/prompts.py +54 -40
  157. phoenix/server/api/routers/v1/sessions.py +108 -0
  158. phoenix/server/api/routers/v1/spans.py +1091 -81
  159. phoenix/server/api/routers/v1/traces.py +132 -78
  160. phoenix/server/api/routers/v1/users.py +389 -0
  161. phoenix/server/api/routers/v1/utils.py +3 -7
  162. phoenix/server/api/subscriptions.py +305 -88
  163. phoenix/server/api/types/Annotation.py +90 -23
  164. phoenix/server/api/types/ApiKey.py +13 -17
  165. phoenix/server/api/types/AuthMethod.py +1 -0
  166. phoenix/server/api/types/ChatCompletionSubscriptionPayload.py +1 -0
  167. phoenix/server/api/types/CostBreakdown.py +12 -0
  168. phoenix/server/api/types/Dataset.py +226 -72
  169. phoenix/server/api/types/DatasetExample.py +88 -18
  170. phoenix/server/api/types/DatasetExperimentAnnotationSummary.py +10 -0
  171. phoenix/server/api/types/DatasetLabel.py +57 -0
  172. phoenix/server/api/types/DatasetSplit.py +98 -0
  173. phoenix/server/api/types/DatasetVersion.py +49 -4
  174. phoenix/server/api/types/DocumentAnnotation.py +212 -0
  175. phoenix/server/api/types/Experiment.py +264 -59
  176. phoenix/server/api/types/ExperimentComparison.py +5 -10
  177. phoenix/server/api/types/ExperimentRepeatedRunGroup.py +155 -0
  178. phoenix/server/api/types/ExperimentRepeatedRunGroupAnnotationSummary.py +9 -0
  179. phoenix/server/api/types/ExperimentRun.py +169 -65
  180. phoenix/server/api/types/ExperimentRunAnnotation.py +158 -39
  181. phoenix/server/api/types/GenerativeModel.py +245 -3
  182. phoenix/server/api/types/GenerativeProvider.py +70 -11
  183. phoenix/server/api/types/{Model.py → InferenceModel.py} +1 -1
  184. phoenix/server/api/types/ModelInterface.py +16 -0
  185. phoenix/server/api/types/PlaygroundModel.py +20 -0
  186. phoenix/server/api/types/Project.py +1278 -216
  187. phoenix/server/api/types/ProjectSession.py +188 -28
  188. phoenix/server/api/types/ProjectSessionAnnotation.py +187 -0
  189. phoenix/server/api/types/ProjectTraceRetentionPolicy.py +1 -1
  190. phoenix/server/api/types/Prompt.py +119 -39
  191. phoenix/server/api/types/PromptLabel.py +42 -25
  192. phoenix/server/api/types/PromptVersion.py +11 -8
  193. phoenix/server/api/types/PromptVersionTag.py +65 -25
  194. phoenix/server/api/types/ServerStatus.py +6 -0
  195. phoenix/server/api/types/Span.py +167 -123
  196. phoenix/server/api/types/SpanAnnotation.py +189 -42
  197. phoenix/server/api/types/SpanCostDetailSummaryEntry.py +10 -0
  198. phoenix/server/api/types/SpanCostSummary.py +10 -0
  199. phoenix/server/api/types/SystemApiKey.py +65 -1
  200. phoenix/server/api/types/TokenPrice.py +16 -0
  201. phoenix/server/api/types/TokenUsage.py +3 -3
  202. phoenix/server/api/types/Trace.py +223 -51
  203. phoenix/server/api/types/TraceAnnotation.py +149 -50
  204. phoenix/server/api/types/User.py +137 -32
  205. phoenix/server/api/types/UserApiKey.py +73 -26
  206. phoenix/server/api/types/node.py +10 -0
  207. phoenix/server/api/types/pagination.py +11 -2
  208. phoenix/server/app.py +290 -45
  209. phoenix/server/authorization.py +38 -3
  210. phoenix/server/bearer_auth.py +34 -24
  211. phoenix/server/cost_tracking/cost_details_calculator.py +196 -0
  212. phoenix/server/cost_tracking/cost_model_lookup.py +179 -0
  213. phoenix/server/cost_tracking/helpers.py +68 -0
  214. phoenix/server/cost_tracking/model_cost_manifest.json +3657 -830
  215. phoenix/server/cost_tracking/regex_specificity.py +397 -0
  216. phoenix/server/cost_tracking/token_cost_calculator.py +57 -0
  217. phoenix/server/daemons/__init__.py +0 -0
  218. phoenix/server/daemons/db_disk_usage_monitor.py +214 -0
  219. phoenix/server/daemons/generative_model_store.py +103 -0
  220. phoenix/server/daemons/span_cost_calculator.py +99 -0
  221. phoenix/server/dml_event.py +17 -0
  222. phoenix/server/dml_event_handler.py +5 -0
  223. phoenix/server/email/sender.py +56 -3
  224. phoenix/server/email/templates/db_disk_usage_notification.html +19 -0
  225. phoenix/server/email/types.py +11 -0
  226. phoenix/server/experiments/__init__.py +0 -0
  227. phoenix/server/experiments/utils.py +14 -0
  228. phoenix/server/grpc_server.py +11 -11
  229. phoenix/server/jwt_store.py +17 -15
  230. phoenix/server/ldap.py +1449 -0
  231. phoenix/server/main.py +26 -10
  232. phoenix/server/oauth2.py +330 -12
  233. phoenix/server/prometheus.py +66 -6
  234. phoenix/server/rate_limiters.py +4 -9
  235. phoenix/server/retention.py +33 -20
  236. phoenix/server/session_filters.py +49 -0
  237. phoenix/server/static/.vite/manifest.json +55 -51
  238. phoenix/server/static/assets/components-BreFUQQa.js +6702 -0
  239. phoenix/server/static/assets/{index-E0M82BdE.js → index-CTQoemZv.js} +140 -56
  240. phoenix/server/static/assets/pages-DBE5iYM3.js +9524 -0
  241. phoenix/server/static/assets/vendor-BGzfc4EU.css +1 -0
  242. phoenix/server/static/assets/vendor-DCE4v-Ot.js +920 -0
  243. phoenix/server/static/assets/vendor-codemirror-D5f205eT.js +25 -0
  244. phoenix/server/static/assets/vendor-recharts-V9cwpXsm.js +37 -0
  245. phoenix/server/static/assets/vendor-shiki-Do--csgv.js +5 -0
  246. phoenix/server/static/assets/vendor-three-CmB8bl_y.js +3840 -0
  247. phoenix/server/templates/index.html +40 -6
  248. phoenix/server/thread_server.py +1 -2
  249. phoenix/server/types.py +14 -4
  250. phoenix/server/utils.py +74 -0
  251. phoenix/session/client.py +56 -3
  252. phoenix/session/data_extractor.py +5 -0
  253. phoenix/session/evaluation.py +14 -5
  254. phoenix/session/session.py +45 -9
  255. phoenix/settings.py +5 -0
  256. phoenix/trace/attributes.py +80 -13
  257. phoenix/trace/dsl/helpers.py +90 -1
  258. phoenix/trace/dsl/query.py +8 -6
  259. phoenix/trace/projects.py +5 -0
  260. phoenix/utilities/template_formatters.py +1 -1
  261. phoenix/version.py +1 -1
  262. arize_phoenix-10.0.4.dist-info/RECORD +0 -405
  263. phoenix/server/api/types/Evaluation.py +0 -39
  264. phoenix/server/cost_tracking/cost_lookup.py +0 -255
  265. phoenix/server/static/assets/components-DULKeDfL.js +0 -4365
  266. phoenix/server/static/assets/pages-Cl0A-0U2.js +0 -7430
  267. phoenix/server/static/assets/vendor-WIZid84E.css +0 -1
  268. phoenix/server/static/assets/vendor-arizeai-Dy-0mSNw.js +0 -649
  269. phoenix/server/static/assets/vendor-codemirror-DBtifKNr.js +0 -33
  270. phoenix/server/static/assets/vendor-oB4u9zuV.js +0 -905
  271. phoenix/server/static/assets/vendor-recharts-D-T4KPz2.js +0 -59
  272. phoenix/server/static/assets/vendor-shiki-BMn4O_9F.js +0 -5
  273. phoenix/server/static/assets/vendor-three-C5WAXd5r.js +0 -2998
  274. phoenix/utilities/deprecation.py +0 -31
  275. {arize_phoenix-10.0.4.dist-info → arize_phoenix-12.28.1.dist-info}/entry_points.txt +0 -0
  276. {arize_phoenix-10.0.4.dist-info → arize_phoenix-12.28.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,33 +0,0 @@
1
- import{d2 as NS,d3 as Le,d4 as pg,d5 as gg,d6 as mg,d7 as qe,d8 as bi,d9 as Jl,da as Nn,db as bg,dc as Us,dd as yg,de as Sg,A as J,z as wg,df as xg,dg as FS,dh as IS,di as HS,dj as VS,dk as Ut,dl as Hc,r as mi,dm as $S,dn as WS,dp as zS,dq as qS,dr as vg,ds as KS,dt as jS,du as kg,dv as _S,dw as Cg,dx as GS}from"./vendor-oB4u9zuV.js";import{m as YS}from"./vendor-shiki-BMn4O_9F.js";var $a={},Id;function Vc(){return Id||(Id=1,function(n){var t=NS();class e{lineAt(b){if(b<0||b>this.length)throw new RangeError(`Invalid position ${b} in document of length ${this.length}`);return this.lineInner(b,!1,1,0)}line(b){if(b<1||b>this.lines)throw new RangeError(`Invalid line number ${b} in ${this.lines}-line document`);return this.lineInner(b,!0,1,0)}replace(b,w,C){[b,w]=x(this,b,w);let O=[];return this.decompose(0,b,O,2),C.length&&C.decompose(0,C.length,O,3),this.decompose(w,this.length,O,1),s.from(O,this.length-(w-b)+C.length)}append(b){return this.replace(this.length,this.length,b)}slice(b,w=this.length){[b,w]=x(this,b,w);let C=[];return this.decompose(b,w,C,0),s.from(C,w-b)}eq(b){if(b==this)return!0;if(b.length!=this.length||b.lines!=this.lines)return!1;let w=this.scanIdentical(b,1),C=this.length-this.scanIdentical(b,-1),O=new c(this),L=new c(b);for(let N=w,q=w;;){if(O.next(N),L.next(N),N=0,O.lineBreak!=L.lineBreak||O.done!=L.done||O.value!=L.value)return!1;if(q+=O.value.length,O.done||q>=C)return!0}}iter(b=1){return new c(this,b)}iterRange(b,w=this.length){return new g(this,b,w)}iterLines(b,w){let C;if(b==null)C=this.iter();else{w==null&&(w=this.lines+1);let O=this.line(b).from;C=this.iterRange(O,Math.max(O,w==this.lines+1?this.length:w<=1?0:this.line(w-1).to))}return new p(C)}toString(){return this.sliceString(0)}toJSON(){let b=[];return this.flatten(b),b}constructor(){}static of(b){if(b.length==0)throw new RangeError("A document must have at least one line");return b.length==1&&!b[0]?e.empty:b.length<=32?new i(b):s.from(i.split(b,[]))}}class i extends e{constructor(b,w=r(b)){super(),this.text=b,this.length=w}get lines(){return this.text.length}get children(){return null}lineInner(b,w,C,O){for(let L=0;;L++){let N=this.text[L],q=O+N.length;if((w?C:q)>=b)return new y(O,q,C,N);O=q+1,C++}}decompose(b,w,C,O){let L=b<=0&&w>=this.length?this:new i(h(this.text,b,w),Math.min(w,this.length)-Math.max(0,b));if(O&1){let N=C.pop(),q=l(L.text,N.text.slice(),0,L.length);if(q.length<=32)C.push(new i(q,N.length+L.length));else{let _=q.length>>1;C.push(new i(q.slice(0,_)),new i(q.slice(_)))}}else C.push(L)}replace(b,w,C){if(!(C instanceof i))return super.replace(b,w,C);[b,w]=x(this,b,w);let O=l(this.text,l(C.text,h(this.text,0,b)),w),L=this.length+C.length-(w-b);return O.length<=32?new i(O,L):s.from(i.split(O,[]),L)}sliceString(b,w=this.length,C=`
2
- `){[b,w]=x(this,b,w);let O="";for(let L=0,N=0;L<=w&&N<this.text.length;N++){let q=this.text[N],_=L+q.length;L>b&&N&&(O+=C),b<_&&w>L&&(O+=q.slice(Math.max(0,b-L),w-L)),L=_+1}return O}flatten(b){for(let w of this.text)b.push(w)}scanIdentical(){return 0}static split(b,w){let C=[],O=-1;for(let L of b)C.push(L),O+=L.length+1,C.length==32&&(w.push(new i(C,O)),C=[],O=-1);return O>-1&&w.push(new i(C,O)),w}}class s extends e{constructor(b,w){super(),this.children=b,this.length=w,this.lines=0;for(let C of b)this.lines+=C.lines}lineInner(b,w,C,O){for(let L=0;;L++){let N=this.children[L],q=O+N.length,_=C+N.lines-1;if((w?_:q)>=b)return N.lineInner(b,w,C,O);O=q+1,C=_+1}}decompose(b,w,C,O){for(let L=0,N=0;N<=w&&L<this.children.length;L++){let q=this.children[L],_=N+q.length;if(b<=_&&w>=N){let Z=O&((N<=b?1:0)|(_>=w?2:0));N>=b&&_<=w&&!Z?C.push(q):q.decompose(b-N,w-N,C,Z)}N=_+1}}replace(b,w,C){if([b,w]=x(this,b,w),C.lines<this.lines)for(let O=0,L=0;O<this.children.length;O++){let N=this.children[O],q=L+N.length;if(b>=L&&w<=q){let _=N.replace(b-L,w-L,C),Z=this.lines-N.lines+_.lines;if(_.lines<Z>>4&&_.lines>Z>>6){let lt=this.children.slice();return lt[O]=_,new s(lt,this.length-(w-b)+C.length)}return super.replace(L,q,_)}L=q+1}return super.replace(b,w,C)}sliceString(b,w=this.length,C=`
3
- `){[b,w]=x(this,b,w);let O="";for(let L=0,N=0;L<this.children.length&&N<=w;L++){let q=this.children[L],_=N+q.length;N>b&&L&&(O+=C),b<_&&w>N&&(O+=q.sliceString(b-N,w-N,C)),N=_+1}return O}flatten(b){for(let w of this.children)w.flatten(b)}scanIdentical(b,w){if(!(b instanceof s))return 0;let C=0,[O,L,N,q]=w>0?[0,0,this.children.length,b.children.length]:[this.children.length-1,b.children.length-1,-1,-1];for(;;O+=w,L+=w){if(O==N||L==q)return C;let _=this.children[O],Z=b.children[L];if(_!=Z)return C+_.scanIdentical(Z,w);C+=_.length+1}}static from(b,w=b.reduce((C,O)=>C+O.length+1,-1)){let C=0;for(let pt of b)C+=pt.lines;if(C<32){let pt=[];for(let It of b)It.flatten(pt);return new i(pt,w)}let O=Math.max(32,C>>5),L=O<<1,N=O>>1,q=[],_=0,Z=-1,lt=[];function ht(pt){let It;if(pt.lines>L&&pt instanceof s)for(let be of pt.children)ht(be);else pt.lines>N&&(_>N||!_)?(gt(),q.push(pt)):pt instanceof i&&_&&(It=lt[lt.length-1])instanceof i&&pt.lines+It.lines<=32?(_+=pt.lines,Z+=pt.length+1,lt[lt.length-1]=new i(It.text.concat(pt.text),It.length+1+pt.length)):(_+pt.lines>O&&gt(),_+=pt.lines,Z+=pt.length+1,lt.push(pt))}function gt(){_!=0&&(q.push(lt.length==1?lt[0]:s.from(lt,Z)),Z=-1,_=lt.length=0)}for(let pt of b)ht(pt);return gt(),q.length==1?q[0]:new s(q,w)}}e.empty=new i([""],0);function r(V){let b=-1;for(let w of V)b+=w.length+1;return b}function l(V,b,w=0,C=1e9){for(let O=0,L=0,N=!0;L<V.length&&O<=C;L++){let q=V[L],_=O+q.length;_>=w&&(_>C&&(q=q.slice(0,C-O)),O<w&&(q=q.slice(w-O)),N?(b[b.length-1]+=q,N=!1):b.push(q)),O=_+1}return b}function h(V,b,w){return l(V,[""],b,w)}class c{constructor(b,w=1){this.dir=w,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[b],this.offsets=[w>0?1:(b instanceof i?b.text.length:b.children.length)<<1]}nextInner(b,w){for(this.done=this.lineBreak=!1;;){let C=this.nodes.length-1,O=this.nodes[C],L=this.offsets[C],N=L>>1,q=O instanceof i?O.text.length:O.children.length;if(N==(w>0?q:0)){if(C==0)return this.done=!0,this.value="",this;w>0&&this.offsets[C-1]++,this.nodes.pop(),this.offsets.pop()}else if((L&1)==(w>0?0:1)){if(this.offsets[C]+=w,b==0)return this.lineBreak=!0,this.value=`
4
- `,this;b--}else if(O instanceof i){let _=O.text[N+(w<0?-1:0)];if(this.offsets[C]+=w,_.length>Math.max(0,b))return this.value=b==0?_:w>0?_.slice(b):_.slice(0,_.length-b),this;b-=_.length}else{let _=O.children[N+(w<0?-1:0)];b>_.length?(b-=_.length,this.offsets[C]+=w):(w<0&&this.offsets[C]--,this.nodes.push(_),this.offsets.push(w>0?1:(_ instanceof i?_.text.length:_.children.length)<<1))}}}next(b=0){return b<0&&(this.nextInner(-b,-this.dir),b=this.value.length),this.nextInner(b,this.dir)}}class g{constructor(b,w,C){this.value="",this.done=!1,this.cursor=new c(b,w>C?-1:1),this.pos=w>C?b.length:0,this.from=Math.min(w,C),this.to=Math.max(w,C)}nextInner(b,w){if(w<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;b+=Math.max(0,w<0?this.pos-this.to:this.from-this.pos);let C=w<0?this.pos-this.from:this.to-this.pos;b>C&&(b=C),C-=b;let{value:O}=this.cursor.next(b);return this.pos+=(O.length+b)*w,this.value=O.length<=C?O:w<0?O.slice(O.length-C):O.slice(0,C),this.done=!this.value,this}next(b=0){return b<0?b=Math.max(b,this.from-this.pos):b>0&&(b=Math.min(b,this.to-this.pos)),this.nextInner(b,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class p{constructor(b){this.inner=b,this.afterBreak=!0,this.value="",this.done=!1}next(b=0){let{done:w,lineBreak:C,value:O}=this.inner.next(b);return w&&this.afterBreak?(this.value="",this.afterBreak=!1):w?(this.done=!0,this.value=""):C?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=O,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(e.prototype[Symbol.iterator]=function(){return this.iter()},c.prototype[Symbol.iterator]=g.prototype[Symbol.iterator]=p.prototype[Symbol.iterator]=function(){return this});class y{constructor(b,w,C,O){this.from=b,this.to=w,this.number=C,this.text=O}get length(){return this.to-this.from}}function x(V,b,w){return b=Math.max(0,Math.min(V.length,b)),[b,Math.max(b,Math.min(V.length,w))]}function T(V,b,w=!0,C=!0){return t.findClusterBreak(V,b,w,C)}function P(V){return V>=56320&&V<57344}function I(V){return V>=55296&&V<56320}function z(V,b){let w=V.charCodeAt(b);if(!I(w)||b+1==V.length)return w;let C=V.charCodeAt(b+1);return P(C)?(w-55296<<10)+(C-56320)+65536:w}function W(V){return V<=65535?String.fromCharCode(V):(V-=65536,String.fromCharCode((V>>10)+55296,(V&1023)+56320))}function U(V){return V<65536?1:2}const ot=/\r\n?|\n/;n.MapMode=void 0,function(V){V[V.Simple=0]="Simple",V[V.TrackDel=1]="TrackDel",V[V.TrackBefore=2]="TrackBefore",V[V.TrackAfter=3]="TrackAfter"}(n.MapMode||(n.MapMode={}));class Q{constructor(b){this.sections=b}get length(){let b=0;for(let w=0;w<this.sections.length;w+=2)b+=this.sections[w];return b}get newLength(){let b=0;for(let w=0;w<this.sections.length;w+=2){let C=this.sections[w+1];b+=C<0?this.sections[w]:C}return b}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(b){for(let w=0,C=0,O=0;w<this.sections.length;){let L=this.sections[w++],N=this.sections[w++];N<0?(b(C,O,L),O+=L):O+=N,C+=L}}iterChangedRanges(b,w=!1){Pt(this,b,w)}get invertedDesc(){let b=[];for(let w=0;w<this.sections.length;){let C=this.sections[w++],O=this.sections[w++];O<0?b.push(C,O):b.push(O,C)}return new Q(b)}composeDesc(b){return this.empty?b:b.empty?this:le(this,b)}mapDesc(b,w=!1){return b.empty?this:Tt(this,b,w)}mapPos(b,w=-1,C=n.MapMode.Simple){let O=0,L=0;for(let N=0;N<this.sections.length;){let q=this.sections[N++],_=this.sections[N++],Z=O+q;if(_<0){if(Z>b)return L+(b-O);L+=q}else{if(C!=n.MapMode.Simple&&Z>=b&&(C==n.MapMode.TrackDel&&O<b&&Z>b||C==n.MapMode.TrackBefore&&O<b||C==n.MapMode.TrackAfter&&Z>b))return null;if(Z>b||Z==b&&w<0&&!q)return b==O||w<0?L:L+_;L+=_}O=Z}if(b>O)throw new RangeError(`Position ${b} is out of range for changeset of length ${O}`);return L}touchesRange(b,w=b){for(let C=0,O=0;C<this.sections.length&&O<=w;){let L=this.sections[C++],N=this.sections[C++],q=O+L;if(N>=0&&O<=w&&q>=b)return O<b&&q>w?"cover":!0;O=q}return!1}toString(){let b="";for(let w=0;w<this.sections.length;){let C=this.sections[w++],O=this.sections[w++];b+=(b?" ":"")+C+(O>=0?":"+O:"")}return b}toJSON(){return this.sections}static fromJSON(b){if(!Array.isArray(b)||b.length%2||b.some(w=>typeof w!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Q(b)}static create(b){return new Q(b)}}class st extends Q{constructor(b,w){super(b),this.inserted=w}apply(b){if(this.length!=b.length)throw new RangeError("Applying change set to a document with the wrong length");return Pt(this,(w,C,O,L,N)=>b=b.replace(O,O+(C-w),N),!1),b}mapDesc(b,w=!1){return Tt(this,b,w,!0)}invert(b){let w=this.sections.slice(),C=[];for(let O=0,L=0;O<w.length;O+=2){let N=w[O],q=w[O+1];if(q>=0){w[O]=q,w[O+1]=N;let _=O>>1;for(;C.length<_;)C.push(e.empty);C.push(N?b.slice(L,L+N):e.empty)}L+=N}return new st(w,C)}compose(b){return this.empty?b:b.empty?this:le(this,b,!0)}map(b,w=!1){return b.empty?this:Tt(this,b,w,!0)}iterChanges(b,w=!1){Pt(this,b,w)}get desc(){return Q.create(this.sections)}filter(b){let w=[],C=[],O=[],L=new ae(this);t:for(let N=0,q=0;;){let _=N==b.length?1e9:b[N++];for(;q<_||q==_&&L.len==0;){if(L.done)break t;let lt=Math.min(L.len,_-q);at(O,lt,-1);let ht=L.ins==-1?-1:L.off==0?L.ins:0;at(w,lt,ht),ht>0&&wt(C,w,L.text),L.forward(lt),q+=lt}let Z=b[N++];for(;q<Z;){if(L.done)break t;let lt=Math.min(L.len,Z-q);at(w,lt,-1),at(O,lt,L.ins==-1?-1:L.off==0?L.ins:0),L.forward(lt),q+=lt}}return{changes:new st(w,C),filtered:Q.create(O)}}toJSON(){let b=[];for(let w=0;w<this.sections.length;w+=2){let C=this.sections[w],O=this.sections[w+1];O<0?b.push(C):O==0?b.push([C]):b.push([C].concat(this.inserted[w>>1].toJSON()))}return b}static of(b,w,C){let O=[],L=[],N=0,q=null;function _(lt=!1){if(!lt&&!O.length)return;N<w&&at(O,w-N,-1);let ht=new st(O,L);q=q?q.compose(ht.map(q)):ht,O=[],L=[],N=0}function Z(lt){if(Array.isArray(lt))for(let ht of lt)Z(ht);else if(lt instanceof st){if(lt.length!=w)throw new RangeError(`Mismatched change set length (got ${lt.length}, expected ${w})`);_(),q=q?q.compose(lt.map(q)):lt}else{let{from:ht,to:gt=ht,insert:pt}=lt;if(ht>gt||ht<0||gt>w)throw new RangeError(`Invalid change range ${ht} to ${gt} (in doc of length ${w})`);let It=pt?typeof pt=="string"?e.of(pt.split(C||ot)):pt:e.empty,be=It.length;if(ht==gt&&be==0)return;ht<N&&_(),ht>N&&at(O,ht-N,-1),at(O,gt-ht,be),wt(L,O,It),N=gt}}return Z(b),_(!q),q}static empty(b){return new st(b?[b,-1]:[],[])}static fromJSON(b){if(!Array.isArray(b))throw new RangeError("Invalid JSON representation of ChangeSet");let w=[],C=[];for(let O=0;O<b.length;O++){let L=b[O];if(typeof L=="number")w.push(L,-1);else{if(!Array.isArray(L)||typeof L[0]!="number"||L.some((N,q)=>q&&typeof N!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(L.length==1)w.push(L[0],0);else{for(;C.length<O;)C.push(e.empty);C[O]=e.of(L.slice(1)),w.push(L[0],C[O].length)}}}return new st(w,C)}static createSet(b,w){return new st(b,w)}}function at(V,b,w,C=!1){if(b==0&&w<=0)return;let O=V.length-2;O>=0&&w<=0&&w==V[O+1]?V[O]+=b:O>=0&&b==0&&V[O]==0?V[O+1]+=w:C?(V[O]+=b,V[O+1]+=w):V.push(b,w)}function wt(V,b,w){if(w.length==0)return;let C=b.length-2>>1;if(C<V.length)V[V.length-1]=V[V.length-1].append(w);else{for(;V.length<C;)V.push(e.empty);V.push(w)}}function Pt(V,b,w){let C=V.inserted;for(let O=0,L=0,N=0;N<V.sections.length;){let q=V.sections[N++],_=V.sections[N++];if(_<0)O+=q,L+=q;else{let Z=O,lt=L,ht=e.empty;for(;Z+=q,lt+=_,_&&C&&(ht=ht.append(C[N-2>>1])),!(w||N==V.sections.length||V.sections[N+1]<0);)q=V.sections[N++],_=V.sections[N++];b(O,Z,L,lt,ht),O=Z,L=lt}}}function Tt(V,b,w,C=!1){let O=[],L=C?[]:null,N=new ae(V),q=new ae(b);for(let _=-1;;){if(N.done&&q.len||q.done&&N.len)throw new Error("Mismatched change set lengths");if(N.ins==-1&&q.ins==-1){let Z=Math.min(N.len,q.len);at(O,Z,-1),N.forward(Z),q.forward(Z)}else if(q.ins>=0&&(N.ins<0||_==N.i||N.off==0&&(q.len<N.len||q.len==N.len&&!w))){let Z=q.len;for(at(O,q.ins,-1);Z;){let lt=Math.min(N.len,Z);N.ins>=0&&_<N.i&&N.len<=lt&&(at(O,0,N.ins),L&&wt(L,O,N.text),_=N.i),N.forward(lt),Z-=lt}q.next()}else if(N.ins>=0){let Z=0,lt=N.len;for(;lt;)if(q.ins==-1){let ht=Math.min(lt,q.len);Z+=ht,lt-=ht,q.forward(ht)}else if(q.ins==0&&q.len<lt)lt-=q.len,q.next();else break;at(O,Z,_<N.i?N.ins:0),L&&_<N.i&&wt(L,O,N.text),_=N.i,N.forward(N.len-lt)}else{if(N.done&&q.done)return L?st.createSet(O,L):Q.create(O);throw new Error("Mismatched change set lengths")}}}function le(V,b,w=!1){let C=[],O=w?[]:null,L=new ae(V),N=new ae(b);for(let q=!1;;){if(L.done&&N.done)return O?st.createSet(C,O):Q.create(C);if(L.ins==0)at(C,L.len,0,q),L.next();else if(N.len==0&&!N.done)at(C,0,N.ins,q),O&&wt(O,C,N.text),N.next();else{if(L.done||N.done)throw new Error("Mismatched change set lengths");{let _=Math.min(L.len2,N.len),Z=C.length;if(L.ins==-1){let lt=N.ins==-1?-1:N.off?0:N.ins;at(C,_,lt,q),O&&lt&&wt(O,C,N.text)}else N.ins==-1?(at(C,L.off?0:L.len,_,q),O&&wt(O,C,L.textBit(_))):(at(C,L.off?0:L.len,N.off?0:N.ins,q),O&&!N.off&&wt(O,C,N.text));q=(L.ins>_||N.ins>=0&&N.len>_)&&(q||C.length>Z),L.forward2(_),N.forward(_)}}}}class ae{constructor(b){this.set=b,this.i=0,this.next()}next(){let{sections:b}=this.set;this.i<b.length?(this.len=b[this.i++],this.ins=b[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:b}=this.set,w=this.i-2>>1;return w>=b.length?e.empty:b[w]}textBit(b){let{inserted:w}=this.set,C=this.i-2>>1;return C>=w.length&&!b?e.empty:w[C].slice(this.off,b==null?void 0:this.off+b)}forward(b){b==this.len?this.next():(this.len-=b,this.off+=b)}forward2(b){this.ins==-1?this.forward(b):b==this.ins?this.next():(this.ins-=b,this.off+=b)}}class zt{constructor(b,w,C){this.from=b,this.to=w,this.flags=C}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 b=this.flags&7;return b==7?null:b}get goalColumn(){let b=this.flags>>6;return b==16777215?void 0:b}map(b,w=-1){let C,O;return this.empty?C=O=b.mapPos(this.from,w):(C=b.mapPos(this.from,1),O=b.mapPos(this.to,-1)),C==this.from&&O==this.to?this:new zt(C,O,this.flags)}extend(b,w=b){if(b<=this.anchor&&w>=this.anchor)return Ot.range(b,w);let C=Math.abs(b-this.anchor)>Math.abs(w-this.anchor)?b:w;return Ot.range(this.anchor,C)}eq(b,w=!1){return this.anchor==b.anchor&&this.head==b.head&&(!w||!this.empty||this.assoc==b.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(b){if(!b||typeof b.anchor!="number"||typeof b.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return Ot.range(b.anchor,b.head)}static create(b,w,C){return new zt(b,w,C)}}class Ot{constructor(b,w){this.ranges=b,this.mainIndex=w}map(b,w=-1){return b.empty?this:Ot.create(this.ranges.map(C=>C.map(b,w)),this.mainIndex)}eq(b,w=!1){if(this.ranges.length!=b.ranges.length||this.mainIndex!=b.mainIndex)return!1;for(let C=0;C<this.ranges.length;C++)if(!this.ranges[C].eq(b.ranges[C],w))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new Ot([this.main],0)}addRange(b,w=!0){return Ot.create([b].concat(this.ranges),w?0:this.mainIndex+1)}replaceRange(b,w=this.mainIndex){let C=this.ranges.slice();return C[w]=b,Ot.create(C,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(b=>b.toJSON()),main:this.mainIndex}}static fromJSON(b){if(!b||!Array.isArray(b.ranges)||typeof b.main!="number"||b.main>=b.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new Ot(b.ranges.map(w=>zt.fromJSON(w)),b.main)}static single(b,w=b){return new Ot([Ot.range(b,w)],0)}static create(b,w=0){if(b.length==0)throw new RangeError("A selection needs at least one range");for(let C=0,O=0;O<b.length;O++){let L=b[O];if(L.empty?L.from<=C:L.from<C)return Ot.normalized(b.slice(),w);C=L.to}return new Ot(b,w)}static cursor(b,w=0,C,O){return zt.create(b,b,(w==0?0:w<0?8:16)|(C==null?7:Math.min(6,C))|(O??16777215)<<6)}static range(b,w,C,O){let L=(C??16777215)<<6|(O==null?7:Math.min(6,O));return w<b?zt.create(w,b,48|L):zt.create(b,w,(w>b?8:0)|L)}static normalized(b,w=0){let C=b[w];b.sort((O,L)=>O.from-L.from),w=b.indexOf(C);for(let O=1;O<b.length;O++){let L=b[O],N=b[O-1];if(L.empty?L.from<=N.to:L.from<N.to){let q=N.from,_=Math.max(L.to,N.to);O<=w&&w--,b.splice(--O,2,L.anchor>L.head?Ot.range(_,q):Ot.range(q,_))}}return new Ot(b,w)}}function ne(V,b){for(let w of V.ranges)if(w.to>b)throw new RangeError("Selection points outside of document")}let Rt=0;class Bt{constructor(b,w,C,O,L){this.combine=b,this.compareInput=w,this.compare=C,this.isStatic=O,this.id=Rt++,this.default=b([]),this.extensions=typeof L=="function"?L(this):L}get reader(){return this}static define(b={}){return new Bt(b.combine||(w=>w),b.compareInput||((w,C)=>w===C),b.compare||(b.combine?(w,C)=>w===C:vt),!!b.static,b.enables)}of(b){return new Zt([],this,0,b)}compute(b,w){if(this.isStatic)throw new Error("Can't compute a static facet");return new Zt(b,this,1,w)}computeN(b,w){if(this.isStatic)throw new Error("Can't compute a static facet");return new Zt(b,this,2,w)}from(b,w){return w||(w=C=>C),this.compute([b],C=>w(C.field(b)))}}function vt(V,b){return V==b||V.length==b.length&&V.every((w,C)=>w===b[C])}class Zt{constructor(b,w,C,O){this.dependencies=b,this.facet=w,this.type=C,this.value=O,this.id=Rt++}dynamicSlot(b){var w;let C=this.value,O=this.facet.compareInput,L=this.id,N=b[L]>>1,q=this.type==2,_=!1,Z=!1,lt=[];for(let ht of this.dependencies)ht=="doc"?_=!0:ht=="selection"?Z=!0:(((w=b[ht.id])!==null&&w!==void 0?w:1)&1)==0&&lt.push(b[ht.id]);return{create(ht){return ht.values[N]=C(ht),1},update(ht,gt){if(_&&gt.docChanged||Z&&(gt.docChanged||gt.selection)||ue(ht,lt)){let pt=C(ht);if(q?!se(pt,ht.values[N],O):!O(pt,ht.values[N]))return ht.values[N]=pt,1}return 0},reconfigure:(ht,gt)=>{let pt,It=gt.config.address[L];if(It!=null){let be=ft(gt,It);if(this.dependencies.every(Gt=>Gt instanceof Bt?gt.facet(Gt)===ht.facet(Gt):Gt instanceof Qe?gt.field(Gt,!1)==ht.field(Gt,!1):!0)||(q?se(pt=C(ht),be,O):O(pt=C(ht),be)))return ht.values[N]=be,0}else pt=C(ht);return ht.values[N]=pt,1}}}}function se(V,b,w){if(V.length!=b.length)return!1;for(let C=0;C<V.length;C++)if(!w(V[C],b[C]))return!1;return!0}function ue(V,b){let w=!1;for(let C of b)Ii(V,C)&1&&(w=!0);return w}function qn(V,b,w){let C=w.map(_=>V[_.id]),O=w.map(_=>_.type),L=C.filter(_=>!(_&1)),N=V[b.id]>>1;function q(_){let Z=[];for(let lt=0;lt<C.length;lt++){let ht=ft(_,C[lt]);if(O[lt]==2)for(let gt of ht)Z.push(gt);else Z.push(ht)}return b.combine(Z)}return{create(_){for(let Z of C)Ii(_,Z);return _.values[N]=q(_),1},update(_,Z){if(!ue(_,L))return 0;let lt=q(_);return b.compare(lt,_.values[N])?0:(_.values[N]=lt,1)},reconfigure(_,Z){let lt=ue(_,C),ht=Z.config.facets[b.id],gt=Z.facet(b);if(ht&&!lt&&vt(w,ht))return _.values[N]=gt,0;let pt=q(_);return b.compare(pt,gt)?(_.values[N]=gt,0):(_.values[N]=pt,1)}}}const he=Bt.define({static:!0});class Qe{constructor(b,w,C,O,L){this.id=b,this.createF=w,this.updateF=C,this.compareF=O,this.spec=L,this.provides=void 0}static define(b){let w=new Qe(Rt++,b.create,b.update,b.compare||((C,O)=>C===O),b);return b.provide&&(w.provides=b.provide(w)),w}create(b){let w=b.facet(he).find(C=>C.field==this);return((w==null?void 0:w.create)||this.createF)(b)}slot(b){let w=b[this.id]>>1;return{create:C=>(C.values[w]=this.create(C),1),update:(C,O)=>{let L=C.values[w],N=this.updateF(L,O);return this.compareF(L,N)?0:(C.values[w]=N,1)},reconfigure:(C,O)=>{let L=C.facet(he),N=O.facet(he),q;return(q=L.find(_=>_.field==this))&&q!=N.find(_=>_.field==this)?(C.values[w]=q.create(C),1):O.config.address[this.id]!=null?(C.values[w]=O.field(this),0):(C.values[w]=this.create(C),1)}}}init(b){return[this,he.of({field:this,create:b})]}get extension(){return this}}const Ze={lowest:4,low:3,default:2,high:1,highest:0};function ti(V){return b=>new Zi(b,V)}const Kn={highest:ti(Ze.highest),high:ti(Ze.high),default:ti(Ze.default),low:ti(Ze.low),lowest:ti(Ze.lowest)};class Zi{constructor(b,w){this.inner=b,this.prec=w}}class Ni{of(b){return new Fi(this,b)}reconfigure(b){return Ni.reconfigure.of({compartment:this,extension:b})}get(b){return b.config.compartments.get(this)}}class Fi{constructor(b,w){this.compartment=b,this.inner=w}}class gn{constructor(b,w,C,O,L,N){for(this.base=b,this.compartments=w,this.dynamicSlots=C,this.address=O,this.staticValues=L,this.facets=N,this.statusTemplate=[];this.statusTemplate.length<C.length;)this.statusTemplate.push(0)}staticFacet(b){let w=this.address[b.id];return w==null?b.default:this.staticValues[w>>1]}static resolve(b,w,C){let O=[],L=Object.create(null),N=new Map;for(let gt of as(b,w,N))gt instanceof Qe?O.push(gt):(L[gt.facet.id]||(L[gt.facet.id]=[])).push(gt);let q=Object.create(null),_=[],Z=[];for(let gt of O)q[gt.id]=Z.length<<1,Z.push(pt=>gt.slot(pt));let lt=C==null?void 0:C.config.facets;for(let gt in L){let pt=L[gt],It=pt[0].facet,be=lt&&lt[gt]||[];if(pt.every(Gt=>Gt.type==0))if(q[It.id]=_.length<<1|1,vt(be,pt))_.push(C.facet(It));else{let Gt=It.combine(pt.map(rn=>rn.value));_.push(C&&It.compare(Gt,C.facet(It))?C.facet(It):Gt)}else{for(let Gt of pt)Gt.type==0?(q[Gt.id]=_.length<<1|1,_.push(Gt.value)):(q[Gt.id]=Z.length<<1,Z.push(rn=>Gt.dynamicSlot(rn)));q[It.id]=Z.length<<1,Z.push(Gt=>qn(Gt,It,pt))}}let ht=Z.map(gt=>gt(q));return new gn(b,N,ht,q,_,L)}}function as(V,b,w){let C=[[],[],[],[],[]],O=new Map;function L(N,q){let _=O.get(N);if(_!=null){if(_<=q)return;let Z=C[_].indexOf(N);Z>-1&&C[_].splice(Z,1),N instanceof Fi&&w.delete(N.compartment)}if(O.set(N,q),Array.isArray(N))for(let Z of N)L(Z,q);else if(N instanceof Fi){if(w.has(N.compartment))throw new RangeError("Duplicate use of compartment in extensions");let Z=b.get(N.compartment)||N.inner;w.set(N.compartment,Z),L(Z,q)}else if(N instanceof Zi)L(N.inner,N.prec);else if(N instanceof Qe)C[q].push(N),N.provides&&L(N.provides,q);else if(N instanceof Zt)C[q].push(N),N.facet.extensions&&L(N.facet.extensions,Ze.default);else{let Z=N.extension;if(!Z)throw new Error(`Unrecognized extension value in extension set (${N}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);L(Z,q)}}return L(V,Ze.default),C.reduce((N,q)=>N.concat(q))}function Ii(V,b){if(b&1)return 2;let w=b>>1,C=V.status[w];if(C==4)throw new Error("Cyclic dependency between fields and/or facets");if(C&2)return C;V.status[w]=4;let O=V.computeSlot(V,V.config.dynamicSlots[w]);return V.status[w]=2|O}function ft(V,b){return b&1?V.config.staticValues[b>>1]:V.values[b>>1]}const jn=Bt.define(),ye=Bt.define({combine:V=>V.some(b=>b),static:!0}),Ke=Bt.define({combine:V=>V.length?V[0]:void 0,static:!0}),hs=Bt.define(),ei=Bt.define(),De=Bt.define(),mn=Bt.define({combine:V=>V.length?V[0]:!1});class Oe{constructor(b,w){this.type=b,this.value=w}static define(){return new ii}}class ii{of(b){return new Oe(this,b)}}class bn{constructor(b){this.map=b}of(b){return new Ht(this,b)}}class Ht{constructor(b,w){this.type=b,this.value=w}map(b){let w=this.type.map(this.value,b);return w===void 0?void 0:w==this.value?this:new Ht(this.type,w)}is(b){return this.type==b}static define(b={}){return new bn(b.map||(w=>w))}static mapEffects(b,w){if(!b.length)return b;let C=[];for(let O of b){let L=O.map(w);L&&C.push(L)}return C}}Ht.reconfigure=Ht.define(),Ht.appendConfig=Ht.define();class ce{constructor(b,w,C,O,L,N){this.startState=b,this.changes=w,this.selection=C,this.effects=O,this.annotations=L,this.scrollIntoView=N,this._doc=null,this._state=null,C&&ne(C,w.newLength),L.some(q=>q.type==ce.time)||(this.annotations=L.concat(ce.time.of(Date.now())))}static create(b,w,C,O,L,N){return new ce(b,w,C,O,L,N)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(b){for(let w of this.annotations)if(w.type==b)return w.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(b){let w=this.annotation(ce.userEvent);return!!(w&&(w==b||w.length>b.length&&w.slice(0,b.length)==b&&w[b.length]=="."))}}ce.time=Oe.define(),ce.userEvent=Oe.define(),ce.addToHistory=Oe.define(),ce.remote=Oe.define();function di(V,b){let w=[];for(let C=0,O=0;;){let L,N;if(C<V.length&&(O==b.length||b[O]>=V[C]))L=V[C++],N=V[C++];else if(O<b.length)L=b[O++],N=b[O++];else return w;!w.length||w[w.length-1]<L?w.push(L,N):w[w.length-1]<N&&(w[w.length-1]=N)}}function yn(V,b,w){var C;let O,L,N;return w?(O=b.changes,L=st.empty(b.changes.length),N=V.changes.compose(b.changes)):(O=b.changes.map(V.changes),L=V.changes.mapDesc(b.changes,!0),N=V.changes.compose(O)),{changes:N,selection:b.selection?b.selection.map(L):(C=V.selection)===null||C===void 0?void 0:C.map(O),effects:Ht.mapEffects(V.effects,O).concat(Ht.mapEffects(b.effects,L)),annotations:V.annotations.length?V.annotations.concat(b.annotations):b.annotations,scrollIntoView:V.scrollIntoView||b.scrollIntoView}}function tn(V,b,w){let C=b.selection,O=Fe(b.annotations);return b.userEvent&&(O=O.concat(ce.userEvent.of(b.userEvent))),{changes:b.changes instanceof st?b.changes:st.of(b.changes||[],w,V.facet(Ke)),selection:C&&(C instanceof Ot?C:Ot.single(C.anchor,C.head)),effects:Fe(b.effects),annotations:O,scrollIntoView:!!b.scrollIntoView}}function _t(V,b,w){let C=tn(V,b.length?b[0]:{},V.doc.length);b.length&&b[0].filter===!1&&(w=!1);for(let L=1;L<b.length;L++){b[L].filter===!1&&(w=!1);let N=!!b[L].sequential;C=yn(C,tn(V,b[L],N?C.changes.newLength:V.doc.length),N)}let O=ce.create(V,C.changes,C.selection,C.effects,C.annotations,C.scrollIntoView);return _e(w?je(O):O)}function je(V){let b=V.startState,w=!0;for(let O of b.facet(hs)){let L=O(V);if(L===!1){w=!1;break}Array.isArray(L)&&(w=w===!0?L:di(w,L))}if(w!==!0){let O,L;if(w===!1)L=V.changes.invertedDesc,O=st.empty(b.doc.length);else{let N=V.changes.filter(w);O=N.changes,L=N.filtered.mapDesc(N.changes).invertedDesc}V=ce.create(b,O,V.selection&&V.selection.map(L),Ht.mapEffects(V.effects,L),V.annotations,V.scrollIntoView)}let C=b.facet(ei);for(let O=C.length-1;O>=0;O--){let L=C[O](V);L instanceof ce?V=L:Array.isArray(L)&&L.length==1&&L[0]instanceof ce?V=L[0]:V=_t(b,Fe(L),!1)}return V}function _e(V){let b=V.startState,w=b.facet(De),C=V;for(let O=w.length-1;O>=0;O--){let L=w[O](V);L&&Object.keys(L).length&&(C=yn(C,tn(b,L,V.changes.newLength),!0))}return C==V?V:ce.create(b,V.changes,V.selection,C.effects,C.annotations,C.scrollIntoView)}const Vt=[];function Fe(V){return V==null?Vt:Array.isArray(V)?V:[V]}n.CharCategory=void 0,function(V){V[V.Word=0]="Word",V[V.Space=1]="Space",V[V.Other=2]="Other"}(n.CharCategory||(n.CharCategory={}));const en=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Ge;try{Ge=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function cs(V){if(Ge)return Ge.test(V);for(let b=0;b<V.length;b++){let w=V[b];if(/\w/.test(w)||w>"€"&&(w.toUpperCase()!=w.toLowerCase()||en.test(w)))return!0}return!1}function er(V){return b=>{if(!/\S/.test(b))return n.CharCategory.Space;if(cs(b))return n.CharCategory.Word;for(let w=0;w<V.length;w++)if(b.indexOf(V[w])>-1)return n.CharCategory.Word;return n.CharCategory.Other}}class Wt{constructor(b,w,C,O,L,N){this.config=b,this.doc=w,this.selection=C,this.values=O,this.status=b.statusTemplate.slice(),this.computeSlot=L,N&&(N._state=this);for(let q=0;q<this.config.dynamicSlots.length;q++)Ii(this,q<<1);this.computeSlot=null}field(b,w=!0){let C=this.config.address[b.id];if(C==null){if(w)throw new RangeError("Field is not present in this state");return}return Ii(this,C),ft(this,C)}update(...b){return _t(this,b,!0)}applyTransaction(b){let w=this.config,{base:C,compartments:O}=w;for(let q of b.effects)q.is(Ni.reconfigure)?(w&&(O=new Map,w.compartments.forEach((_,Z)=>O.set(Z,_)),w=null),O.set(q.value.compartment,q.value.extension)):q.is(Ht.reconfigure)?(w=null,C=q.value):q.is(Ht.appendConfig)&&(w=null,C=Fe(C).concat(q.value));let L;w?L=b.startState.values.slice():(w=gn.resolve(C,O,this),L=new Wt(w,this.doc,this.selection,w.dynamicSlots.map(()=>null),(_,Z)=>Z.reconfigure(_,this),null).values);let N=b.startState.facet(ye)?b.newSelection:b.newSelection.asSingle();new Wt(w,b.newDoc,N,L,(q,_)=>_.update(q,b),b)}replaceSelection(b){return typeof b=="string"&&(b=this.toText(b)),this.changeByRange(w=>({changes:{from:w.from,to:w.to,insert:b},range:Ot.cursor(w.from+b.length)}))}changeByRange(b){let w=this.selection,C=b(w.ranges[0]),O=this.changes(C.changes),L=[C.range],N=Fe(C.effects);for(let q=1;q<w.ranges.length;q++){let _=b(w.ranges[q]),Z=this.changes(_.changes),lt=Z.map(O);for(let gt=0;gt<q;gt++)L[gt]=L[gt].map(lt);let ht=O.mapDesc(Z,!0);L.push(_.range.map(ht)),O=O.compose(lt),N=Ht.mapEffects(N,lt).concat(Ht.mapEffects(Fe(_.effects),ht))}return{changes:O,selection:Ot.create(L,w.mainIndex),effects:N}}changes(b=[]){return b instanceof st?b:st.of(b,this.doc.length,this.facet(Wt.lineSeparator))}toText(b){return e.of(b.split(this.facet(Wt.lineSeparator)||ot))}sliceDoc(b=0,w=this.doc.length){return this.doc.sliceString(b,w,this.lineBreak)}facet(b){let w=this.config.address[b.id];return w==null?b.default:(Ii(this,w),ft(this,w))}toJSON(b){let w={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(b)for(let C in b){let O=b[C];O instanceof Qe&&this.config.address[O.id]!=null&&(w[C]=O.spec.toJSON(this.field(b[C]),this))}return w}static fromJSON(b,w={},C){if(!b||typeof b.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let O=[];if(C){for(let L in C)if(Object.prototype.hasOwnProperty.call(b,L)){let N=C[L],q=b[L];O.push(N.init(_=>N.spec.fromJSON(q,_)))}}return Wt.create({doc:b.doc,selection:Ot.fromJSON(b.selection),extensions:w.extensions?O.concat([w.extensions]):O})}static create(b={}){let w=gn.resolve(b.extensions||[],new Map),C=b.doc instanceof e?b.doc:e.of((b.doc||"").split(w.staticFacet(Wt.lineSeparator)||ot)),O=b.selection?b.selection instanceof Ot?b.selection:Ot.single(b.selection.anchor,b.selection.head):Ot.single(0);return ne(O,C.length),w.staticFacet(ye)||(O=O.asSingle()),new Wt(w,C,O,w.dynamicSlots.map(()=>null),(L,N)=>N.create(L),null)}get tabSize(){return this.facet(Wt.tabSize)}get lineBreak(){return this.facet(Wt.lineSeparator)||`
5
- `}get readOnly(){return this.facet(mn)}phrase(b,...w){for(let C of this.facet(Wt.phrases))if(Object.prototype.hasOwnProperty.call(C,b)){b=C[b];break}return w.length&&(b=b.replace(/\$(\$|\d*)/g,(C,O)=>{if(O=="$")return"$";let L=+(O||1);return!L||L>w.length?C:w[L-1]})),b}languageDataAt(b,w,C=-1){let O=[];for(let L of this.facet(jn))for(let N of L(this,w,C))Object.prototype.hasOwnProperty.call(N,b)&&O.push(N[b]);return O}charCategorizer(b){return er(this.languageDataAt("wordChars",b).join(""))}wordAt(b){let{text:w,from:C,length:O}=this.doc.lineAt(b),L=this.charCategorizer(b),N=b-C,q=b-C;for(;N>0;){let _=T(w,N,!1);if(L(w.slice(_,N))!=n.CharCategory.Word)break;N=_}for(;q<O;){let _=T(w,q);if(L(w.slice(q,_))!=n.CharCategory.Word)break;q=_}return N==q?null:Ot.range(N+C,q+C)}}Wt.allowMultipleSelections=ye,Wt.tabSize=Bt.define({combine:V=>V.length?V[0]:4}),Wt.lineSeparator=Ke,Wt.readOnly=mn,Wt.phrases=Bt.define({compare(V,b){let w=Object.keys(V),C=Object.keys(b);return w.length==C.length&&w.every(O=>V[O]==b[O])}}),Wt.languageData=jn,Wt.changeFilter=hs,Wt.transactionFilter=ei,Wt.transactionExtender=De,Ni.reconfigure=Ht.define();function ki(V,b,w={}){let C={};for(let O of V)for(let L of Object.keys(O)){let N=O[L],q=C[L];if(q===void 0)C[L]=N;else if(!(q===N||N===void 0))if(Object.hasOwnProperty.call(w,L))C[L]=w[L](q,N);else throw new Error("Config merge conflict for field "+L)}for(let O in b)C[O]===void 0&&(C[O]=b[O]);return C}class ni{eq(b){return this==b}range(b,w=b){return Ee.create(b,w,this)}}ni.prototype.startSide=ni.prototype.endSide=0,ni.prototype.point=!1,ni.prototype.mapMode=n.MapMode.TrackDel;class Ee{constructor(b,w,C){this.from=b,this.to=w,this.value=C}static create(b,w,C){return new Ee(b,w,C)}}function si(V,b){return V.from-b.from||V.value.startSide-b.value.startSide}class nn{constructor(b,w,C,O){this.from=b,this.to=w,this.value=C,this.maxPoint=O}get length(){return this.to[this.to.length-1]}findIndex(b,w,C,O=0){let L=C?this.to:this.from;for(let N=O,q=L.length;;){if(N==q)return N;let _=N+q>>1,Z=L[_]-b||(C?this.value[_].endSide:this.value[_].startSide)-w;if(_==N)return Z>=0?N:q;Z>=0?q=_:N=_+1}}between(b,w,C,O){for(let L=this.findIndex(w,-1e9,!0),N=this.findIndex(C,1e9,!1,L);L<N;L++)if(O(this.from[L]+b,this.to[L]+b,this.value[L])===!1)return!1}map(b,w){let C=[],O=[],L=[],N=-1,q=-1;for(let _=0;_<this.value.length;_++){let Z=this.value[_],lt=this.from[_]+b,ht=this.to[_]+b,gt,pt;if(lt==ht){let It=w.mapPos(lt,Z.startSide,Z.mapMode);if(It==null||(gt=pt=It,Z.startSide!=Z.endSide&&(pt=w.mapPos(lt,Z.endSide),pt<gt)))continue}else if(gt=w.mapPos(lt,Z.startSide),pt=w.mapPos(ht,Z.endSide),gt>pt||gt==pt&&Z.startSide>0&&Z.endSide<=0)continue;(pt-gt||Z.endSide-Z.startSide)<0||(N<0&&(N=gt),Z.point&&(q=Math.max(q,pt-gt)),C.push(Z),O.push(gt-N),L.push(pt-N))}return{mapped:C.length?new nn(O,L,C,q):null,pos:N}}}class re{constructor(b,w,C,O){this.chunkPos=b,this.chunk=w,this.nextLayer=C,this.maxPoint=O}static create(b,w,C,O){return new re(b,w,C,O)}get length(){let b=this.chunk.length-1;return b<0?0:Math.max(this.chunkEnd(b),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let b=this.nextLayer.size;for(let w of this.chunk)b+=w.value.length;return b}chunkEnd(b){return this.chunkPos[b]+this.chunk[b].length}update(b){let{add:w=[],sort:C=!1,filterFrom:O=0,filterTo:L=this.length}=b,N=b.filter;if(w.length==0&&!N)return this;if(C&&(w=w.slice().sort(si)),this.isEmpty)return w.length?re.of(w):this;let q=new Se(this,null,-1).goto(0),_=0,Z=[],lt=new sn;for(;q.value||_<w.length;)if(_<w.length&&(q.from-w[_].from||q.startSide-w[_].value.startSide)>=0){let ht=w[_++];lt.addInner(ht.from,ht.to,ht.value)||Z.push(ht)}else q.rangeIndex==1&&q.chunkIndex<this.chunk.length&&(_==w.length||this.chunkEnd(q.chunkIndex)<w[_].from)&&(!N||O>this.chunkEnd(q.chunkIndex)||L<this.chunkPos[q.chunkIndex])&&lt.addChunk(this.chunkPos[q.chunkIndex],this.chunk[q.chunkIndex])?q.nextChunk():((!N||O>q.to||L<q.from||N(q.from,q.to,q.value))&&(lt.addInner(q.from,q.to,q.value)||Z.push(Ee.create(q.from,q.to,q.value))),q.next());return lt.finishInner(this.nextLayer.isEmpty&&!Z.length?re.empty:this.nextLayer.update({add:Z,filter:N,filterFrom:O,filterTo:L}))}map(b){if(b.empty||this.isEmpty)return this;let w=[],C=[],O=-1;for(let N=0;N<this.chunk.length;N++){let q=this.chunkPos[N],_=this.chunk[N],Z=b.touchesRange(q,q+_.length);if(Z===!1)O=Math.max(O,_.maxPoint),w.push(_),C.push(b.mapPos(q));else if(Z===!0){let{mapped:lt,pos:ht}=_.map(q,b);lt&&(O=Math.max(O,lt.maxPoint),w.push(lt),C.push(ht))}}let L=this.nextLayer.map(b);return w.length==0?L:new re(C,w,L||re.empty,O)}between(b,w,C){if(!this.isEmpty){for(let O=0;O<this.chunk.length;O++){let L=this.chunkPos[O],N=this.chunk[O];if(w>=L&&b<=L+N.length&&N.between(L,b-L,w-L,C)===!1)return}this.nextLayer.between(b,w,C)}}iter(b=0){return Ci.from([this]).goto(b)}get isEmpty(){return this.nextLayer==this}static iter(b,w=0){return Ci.from(b).goto(w)}static compare(b,w,C,O,L=-1){let N=b.filter(ht=>ht.maxPoint>0||!ht.isEmpty&&ht.maxPoint>=L),q=w.filter(ht=>ht.maxPoint>0||!ht.isEmpty&&ht.maxPoint>=L),_=ui(N,q,C),Z=new we(N,_,L),lt=new we(q,_,L);C.iterGaps((ht,gt,pt)=>_n(Z,ht,lt,gt,pt,O)),C.empty&&C.length==0&&_n(Z,0,lt,0,0,O)}static eq(b,w,C=0,O){O==null&&(O=999999999);let L=b.filter(lt=>!lt.isEmpty&&w.indexOf(lt)<0),N=w.filter(lt=>!lt.isEmpty&&b.indexOf(lt)<0);if(L.length!=N.length)return!1;if(!L.length)return!0;let q=ui(L,N),_=new we(L,q,0).goto(C),Z=new we(N,q,0).goto(C);for(;;){if(_.to!=Z.to||!Ft(_.active,Z.active)||_.point&&(!Z.point||!_.point.eq(Z.point)))return!1;if(_.to>O)return!0;_.next(),Z.next()}}static spans(b,w,C,O,L=-1){let N=new we(b,null,L).goto(w),q=w,_=N.openStart;for(;;){let Z=Math.min(N.to,C);if(N.point){let lt=N.activeForPoint(N.to),ht=N.pointFrom<w?lt.length+1:N.point.startSide<0?lt.length:Math.min(lt.length,_);O.point(q,Z,N.point,lt,ht,N.pointRank),_=Math.min(N.openEnd(Z),lt.length)}else Z>q&&(O.span(q,Z,N.active,_),_=N.openEnd(Z));if(N.to>C)return _+(N.point&&N.to>C?1:0);q=N.to,N.next()}}static of(b,w=!1){let C=new sn;for(let O of b instanceof Ee?[b]:w?ir(b):b)C.add(O.from,O.to,O.value);return C.finish()}static join(b){if(!b.length)return re.empty;let w=b[b.length-1];for(let C=b.length-2;C>=0;C--)for(let O=b[C];O!=re.empty;O=O.nextLayer)w=new re(O.chunkPos,O.chunk,w,Math.max(O.maxPoint,w.maxPoint));return w}}re.empty=new re([],[],null,-1);function ir(V){if(V.length>1)for(let b=V[0],w=1;w<V.length;w++){let C=V[w];if(si(b,C)>0)return V.slice().sort(si);b=C}return V}re.empty.nextLayer=re.empty;class sn{finishChunk(b){this.chunks.push(new nn(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,b&&(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(b,w,C){this.addInner(b,w,C)||(this.nextLayer||(this.nextLayer=new sn)).add(b,w,C)}addInner(b,w,C){let O=b-this.lastTo||C.startSide-this.last.endSide;if(O<=0&&(b-this.lastFrom||C.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return O<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=b),this.from.push(b-this.chunkStart),this.to.push(w-this.chunkStart),this.last=C,this.lastFrom=b,this.lastTo=w,this.value.push(C),C.point&&(this.maxPoint=Math.max(this.maxPoint,w-b)),!0)}addChunk(b,w){if((b-this.lastTo||w.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,w.maxPoint),this.chunks.push(w),this.chunkPos.push(b);let C=w.value.length-1;return this.last=w.value[C],this.lastFrom=w.from[C]+b,this.lastTo=w.to[C]+b,!0}finish(){return this.finishInner(re.empty)}finishInner(b){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return b;let w=re.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(b):b,this.setMaxPoint);return this.from=null,w}}function ui(V,b,w){let C=new Map;for(let L of V)for(let N=0;N<L.chunk.length;N++)L.chunk[N].maxPoint<=0&&C.set(L.chunk[N],L.chunkPos[N]);let O=new Set;for(let L of b)for(let N=0;N<L.chunk.length;N++){let q=C.get(L.chunk[N]);q!=null&&(w?w.mapPos(q):q)==L.chunkPos[N]&&!(w!=null&&w.touchesRange(q,q+L.chunk[N].length))&&O.add(L.chunk[N])}return O}class Se{constructor(b,w,C,O=0){this.layer=b,this.skip=w,this.minPoint=C,this.rank=O}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(b,w=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(b,w,!1),this}gotoInner(b,w,C){for(;this.chunkIndex<this.layer.chunk.length;){let O=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(O)||this.layer.chunkEnd(this.chunkIndex)<b||O.maxPoint<this.minPoint))break;this.chunkIndex++,C=!1}if(this.chunkIndex<this.layer.chunk.length){let O=this.layer.chunk[this.chunkIndex].findIndex(b-this.layer.chunkPos[this.chunkIndex],w,!0);(!C||this.rangeIndex<O)&&this.setRangeIndex(O)}this.next()}forward(b,w){(this.to-b||this.endSide-w)<0&&this.gotoInner(b,w,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let b=this.layer.chunkPos[this.chunkIndex],w=this.layer.chunk[this.chunkIndex],C=b+w.from[this.rangeIndex];if(this.from=C,this.to=b+w.to[this.rangeIndex],this.value=w.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(b){if(b==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=b}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(b){return this.from-b.from||this.startSide-b.startSide||this.rank-b.rank||this.to-b.to||this.endSide-b.endSide}}class Ci{constructor(b){this.heap=b}static from(b,w=null,C=-1){let O=[];for(let L=0;L<b.length;L++)for(let N=b[L];!N.isEmpty;N=N.nextLayer)N.maxPoint>=C&&O.push(new Se(N,w,C,L));return O.length==1?O[0]:new Ci(O)}get startSide(){return this.value?this.value.startSide:0}goto(b,w=-1e9){for(let C of this.heap)C.goto(b,w);for(let C=this.heap.length>>1;C>=0;C--)Hi(this.heap,C);return this.next(),this}forward(b,w){for(let C of this.heap)C.forward(b,w);for(let C=this.heap.length>>1;C>=0;C--)Hi(this.heap,C);(this.to-b||this.value.endSide-w)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let b=this.heap[0];this.from=b.from,this.to=b.to,this.value=b.value,this.rank=b.rank,b.value&&b.next(),Hi(this.heap,0)}}}function Hi(V,b){for(let w=V[b];;){let C=(b<<1)+1;if(C>=V.length)break;let O=V[C];if(C+1<V.length&&O.compare(V[C+1])>=0&&(O=V[C+1],C++),w.compare(O)<0)break;V[C]=w,V[b]=O,b=C}}class we{constructor(b,w,C){this.minPoint=C,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=Ci.from(b,w,C)}goto(b,w=-1e9){return this.cursor.goto(b,w),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=b,this.endSide=w,this.openStart=-1,this.next(),this}forward(b,w){for(;this.minActive>-1&&(this.activeTo[this.minActive]-b||this.active[this.minActive].endSide-w)<0;)this.removeActive(this.minActive);this.cursor.forward(b,w)}removeActive(b){Sn(this.active,b),Sn(this.activeTo,b),Sn(this.activeRank,b),this.minActive=fs(this.active,this.activeTo)}addActive(b){let w=0,{value:C,to:O,rank:L}=this.cursor;for(;w<this.activeRank.length&&(L-this.activeRank[w]||O-this.activeTo[w])>0;)w++;wn(this.active,w,C),wn(this.activeTo,w,O),wn(this.activeRank,w,L),b&&wn(b,w,this.cursor.from),this.minActive=fs(this.active,this.activeTo)}next(){let b=this.to,w=this.point;this.point=null;let C=this.openStart<0?[]:null;for(;;){let O=this.minActive;if(O>-1&&(this.activeTo[O]-this.cursor.from||this.active[O].endSide-this.cursor.startSide)<0){if(this.activeTo[O]>b){this.to=this.activeTo[O],this.endSide=this.active[O].endSide;break}this.removeActive(O),C&&Sn(C,O)}else if(this.cursor.value)if(this.cursor.from>b){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let L=this.cursor.value;if(!L.point)this.addActive(C),this.cursor.next();else if(w&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=L,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=L.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(C){this.openStart=0;for(let O=C.length-1;O>=0&&C[O]<b;O--)this.openStart++}}activeForPoint(b){if(!this.active.length)return this.active;let w=[];for(let C=this.active.length-1;C>=0&&!(this.activeRank[C]<this.pointRank);C--)(this.activeTo[C]>b||this.activeTo[C]==b&&this.active[C].endSide>=this.point.endSide)&&w.push(this.active[C]);return w.reverse()}openEnd(b){let w=0;for(let C=this.activeTo.length-1;C>=0&&this.activeTo[C]>b;C--)w++;return w}}function _n(V,b,w,C,O,L){V.goto(b),w.goto(C);let N=C+O,q=C,_=C-b;for(;;){let Z=V.to+_-w.to,lt=Z||V.endSide-w.endSide,ht=lt<0?V.to+_:w.to,gt=Math.min(ht,N);if(V.point||w.point?V.point&&w.point&&(V.point==w.point||V.point.eq(w.point))&&Ft(V.activeForPoint(V.to),w.activeForPoint(w.to))||L.comparePoint(q,gt,V.point,w.point):gt>q&&!Ft(V.active,w.active)&&L.compareRange(q,gt,V.active,w.active),ht>N)break;(Z||V.openEnd!=w.openEnd)&&L.boundChange&&L.boundChange(ht),q=ht,lt<=0&&V.next(),lt>=0&&w.next()}}function Ft(V,b){if(V.length!=b.length)return!1;for(let w=0;w<V.length;w++)if(V[w]!=b[w]&&!V[w].eq(b[w]))return!1;return!0}function Sn(V,b){for(let w=b,C=V.length-1;w<C;w++)V[w]=V[w+1];V.pop()}function wn(V,b,w){for(let C=V.length-1;C>=b;C--)V[C+1]=V[C];V[b]=w}function fs(V,b){let w=-1,C=1e9;for(let O=0;O<b.length;O++)(b[O]-C||V[O].endSide-V[w].endSide)<0&&(w=O,C=b[O]);return w}function xn(V,b,w=V.length){let C=0;for(let O=0;O<w&&O<V.length;)V.charCodeAt(O)==9?(C+=b-C%b,O++):(C++,O=T(V,O));return C}function vn(V,b,w,C){for(let O=0,L=0;;){if(L>=b)return O;if(O==V.length)break;L+=V.charCodeAt(O)==9?w-L%w:1,O=T(V,O)}return C===!0?-1:V.length}n.Annotation=Oe,n.AnnotationType=ii,n.ChangeDesc=Q,n.ChangeSet=st,n.Compartment=Ni,n.EditorSelection=Ot,n.EditorState=Wt,n.Facet=Bt,n.Line=y,n.Prec=Kn,n.Range=Ee,n.RangeSet=re,n.RangeSetBuilder=sn,n.RangeValue=ni,n.SelectionRange=zt,n.StateEffect=Ht,n.StateEffectType=bn,n.StateField=Qe,n.Text=e,n.Transaction=ce,n.codePointAt=z,n.codePointSize=U,n.combineConfig=ki,n.countColumn=xn,n.findClusterBreak=T,n.findColumn=vn,n.fromCodePoint=W}($a)),$a}var A=Vc();function Hr(n){let t;return n.nodeType==11?t=n.getSelection?n:n.ownerDocument:t=n,t.getSelection()}function Mh(n,t){return t?n==t||n.contains(t.nodeType!=1?t.parentNode:t):!1}function US(n){let t=n.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function cl(n,t){if(!t.anchorNode)return!1;try{return Mh(n,t.anchorNode)}catch{return!1}}function Is(n){return n.nodeType==3?is(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Br(n,t,e,i){return e?Hd(n,t,e,i,-1)||Hd(n,t,e,i,1):!1}function es(n){for(var t=0;;t++)if(n=n.previousSibling,!n)return t}function Tl(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function Hd(n,t,e,i,s){for(;;){if(n==e&&t==i)return!0;if(t==(s<0?0:dn(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;t=es(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[t+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;t=s<0?dn(n):0}else return!1}}function dn(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Ql(n,t){let e=t?n.left:n.right;return{left:e,right:e,top:n.top,bottom:n.bottom}}function XS(n){let t=n.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Mg(n,t){let e=t.width/n.offsetWidth,i=t.height/n.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-n.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-n.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function JS(n,t,e,i,s,r,l,h){let c=n.ownerDocument,g=c.defaultView||window;for(let p=n,y=!1;p&&!y;)if(p.nodeType==1){let x,T=p==c.body,P=1,I=1;if(T)x=XS(g);else{if(/^(fixed|sticky)$/.test(getComputedStyle(p).position)&&(y=!0),p.scrollHeight<=p.clientHeight&&p.scrollWidth<=p.clientWidth){p=p.assignedSlot||p.parentNode;continue}let U=p.getBoundingClientRect();({scaleX:P,scaleY:I}=Mg(p,U)),x={left:U.left,right:U.left+p.clientWidth*P,top:U.top,bottom:U.top+p.clientHeight*I}}let z=0,W=0;if(s=="nearest")t.top<x.top?(W=-(x.top-t.top+l),e>0&&t.bottom>x.bottom+W&&(W=t.bottom-x.bottom+W+l)):t.bottom>x.bottom&&(W=t.bottom-x.bottom+l,e<0&&t.top-W<x.top&&(W=-(x.top+W-t.top+l)));else{let U=t.bottom-t.top,ot=x.bottom-x.top;W=(s=="center"&&U<=ot?t.top+U/2-ot/2:s=="start"||s=="center"&&e<0?t.top-l:t.bottom-ot+l)-x.top}if(i=="nearest"?t.left<x.left?(z=-(x.left-t.left+r),e>0&&t.right>x.right+z&&(z=t.right-x.right+z+r)):t.right>x.right&&(z=t.right-x.right+r,e<0&&t.left<x.left+z&&(z=-(x.left+z-t.left+r))):z=(i=="center"?t.left+(t.right-t.left)/2-(x.right-x.left)/2:i=="start"==h?t.left-r:t.right-(x.right-x.left)+r)-x.left,z||W)if(T)g.scrollBy(z,W);else{let U=0,ot=0;if(W){let Q=p.scrollTop;p.scrollTop+=W/I,ot=(p.scrollTop-Q)*I}if(z){let Q=p.scrollLeft;p.scrollLeft+=z/P,U=(p.scrollLeft-Q)*P}t={left:t.left-U,top:t.top-ot,right:t.right-U,bottom:t.bottom-ot},U&&Math.abs(U-z)<1&&(i="nearest"),ot&&Math.abs(ot-W)<1&&(s="nearest")}if(T)break;p=p.assignedSlot||p.parentNode}else if(p.nodeType==11)p=p.host;else break}function QS(n){let t=n.ownerDocument,e,i;for(let s=n.parentNode;s&&!(s==t.body||e&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!e&&s.scrollWidth>s.clientWidth&&(e=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:e,y:i}}let ZS=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?dn(e):0),i,Math.min(t.focusOffset,i?dn(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}},xs=null;function Ag(n){if(n.setActive)return n.setActive();if(xs)return n.focus(xs);let t=[];for(let e=n;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(n.focus(xs==null?{get preventScroll(){return xs={preventScroll:!0},!0}}:void 0),!xs){xs=!1;for(let e=0;e<t.length;){let i=t[e++],s=t[e++],r=t[e++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Vd;function is(n,t,e=t){let i=Vd||(Vd=document.createRange());return i.setEnd(n,e),i.setStart(n,t),i}function Es(n,t,e,i){let s={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,n.dispatchEvent(r);let l=new KeyboardEvent("keyup",s);return l.synthetic=!0,n.dispatchEvent(l),r.defaultPrevented||l.defaultPrevented}function tw(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function Tg(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}function ew(n,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,dn(e));;)if(i){if(e.nodeType!=1)return!1;let s=e.childNodes[i-1];s.contentEditable=="false"?i--:(e=s,i=dn(e))}else{if(e==n)return!0;i=es(e),e=e.parentNode}}function Dg(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function Og(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=dn(e)}else if(e.parentNode&&!Tl(e))i=es(e),e=e.parentNode;else return null}}function Eg(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!Tl(e))i=es(e)+1,e=e.parentNode;else return null}}let ci=class Ah{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new Ah(t.parentNode,es(t),e)}static after(t,e){return new Ah(t.parentNode,es(t)+1,e)}};const $c=[];let ee=class Th{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(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(this.flags&2){let i=this.dom,s=null,r;for(let l of this.children){if(l.flags&7){if(!l.dom&&(r=s?s.nextSibling:i.firstChild)){let h=Th.get(r);(!h||!h.parent&&h.canReuseDOM(l))&&l.reuseDOM(r)}l.sync(t,e),l.flags&=-8}if(r=s?s.nextSibling:i.firstChild,e&&!e.written&&e.node==i&&r!=l.dom&&(e.written=!0),l.dom.parentNode==i)for(;r&&r!=l.dom;)r=$d(r);else i.insertBefore(l.dom,r);s=l.dom}for(r=s?s.nextSibling:i.firstChild,r&&e&&e.node==i&&(e.written=!0);r;)r=$d(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let s=dn(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?s=-1:s=1),t=r}s<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!Th.get(i);)i=i.nextSibling;if(!i)return this.length;for(let s=0,r=0;;s++){let l=this.children[s];if(l.dom==i)return r;r+=l.length+l.breakAfter}}domBoundsAround(t,e,i=0){let s=-1,r=-1,l=-1,h=-1;for(let c=0,g=i,p=i;c<this.children.length;c++){let y=this.children[c],x=g+y.length;if(g<t&&x>e)return y.domBoundsAround(t,e,g);if(x>=t&&s==-1&&(s=c,r=g),g>e&&y.dom.parentNode==this.dom){l=c,h=p;break}p=x,g=x+y.breakAfter}return{from:r,to:h<0?i+this.length:h,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:l<this.children.length&&l>=0?this.children[l].dom:null}}markDirty(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),e.flags&1)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.flags&7&&this.markParentsDirty(!0))}setDOM(t){this.dom!=t&&(this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this)}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=$c){this.markDirty();for(let s=t;s<e;s++){let r=this.children[s];r.parent==this&&i.indexOf(r)<0&&r.destroy()}this.children.splice(t,e-t,...i);for(let s=0;s<i.length;s++)i[s].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new Pg(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,s,r,l){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!((this.flags|t.flags)&8)}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}};ee.prototype.breakAfter=0;function $d(n){let t=n.nextSibling;return n.parentNode.removeChild(n),t}let Pg=class{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}};function Rg(n,t,e,i,s,r,l,h,c){let{children:g}=n,p=g.length?g[t]:null,y=r.length?r[r.length-1]:null,x=y?y.breakAfter:l;if(!(t==i&&p&&!l&&!x&&r.length<2&&p.merge(e,s,r.length?y:null,e==0,h,c))){if(i<g.length){let T=g[i];T&&(s<T.length||T.breakAfter&&(y!=null&&y.breakAfter))?(t==i&&(T=T.split(s),s=0),!x&&y&&T.merge(0,s,y,!0,0,c)?r[r.length-1]=T:((s||T.children.length&&!T.children[0].length)&&T.merge(0,s,null,!1,0,c),r.push(T))):T!=null&&T.breakAfter&&(y?y.breakAfter=1:l=1),i++}for(p&&(p.breakAfter=l,e>0&&(!l&&r.length&&p.merge(e,p.length,r[0],!1,h,0)?p.breakAfter=r.shift().breakAfter:(e<p.length||p.children.length&&p.children[p.children.length-1].length==0)&&p.merge(e,p.length,null,!1,h,0),t++));t<i&&r.length;)if(g[i-1].become(r[r.length-1]))i--,r.pop(),c=r.length?0:h;else if(g[t].become(r[0]))t++,r.shift(),h=r.length?0:c;else break;!r.length&&t&&i<g.length&&!g[t-1].breakAfter&&g[i].merge(0,0,g[t-1],!1,h,c)&&t--,(t<i||r.length)&&n.replaceChildren(t,i,r)}}function Bg(n,t,e,i,s,r){let l=n.childCursor(),{i:h,off:c}=l.findPos(e,1),{i:g,off:p}=l.findPos(t,-1),y=t-e;for(let x of i)y+=x.length;n.length+=y,Rg(n,g,p,h,c,i,0,s,r)}let Ye=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Dh=typeof document<"u"?document:{documentElement:{style:{}}};const Oh=/Edge\/(\d+)/.exec(Ye.userAgent),Lg=/MSIE \d/.test(Ye.userAgent),Eh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ye.userAgent),Zl=!!(Lg||Eh||Oh),Wd=!Zl&&/gecko\/(\d+)/i.test(Ye.userAgent),Wa=!Zl&&/Chrome\/(\d+)/.exec(Ye.userAgent),iw="webkitFontSmoothing"in Dh.documentElement.style,Ng=!Zl&&/Apple Computer/.test(Ye.vendor),zd=Ng&&(/Mobile\/\w+/.test(Ye.userAgent)||Ye.maxTouchPoints>2);var ut={mac:zd||/Mac/.test(Ye.platform),windows:/Win/.test(Ye.platform),linux:/Linux|X11/.test(Ye.platform),ie:Zl,ie_version:Lg?Dh.documentMode||6:Eh?+Eh[1]:Oh?+Oh[1]:0,gecko:Wd,gecko_version:Wd?+(/Firefox\/(\d+)/.exec(Ye.userAgent)||[0,0])[1]:0,chrome:!!Wa,chrome_version:Wa?+Wa[1]:0,ios:zd,android:/Android\b/.test(Ye.userAgent),safari:Ng,webkit_version:iw?+(/\bAppleWebKit\/(\d+)/.exec(Ye.userAgent)||[0,0])[1]:0,tabSize:Dh.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const nw=256;let Vn=class Ph extends ee{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return this.flags&8||i&&(!(i instanceof Ph)||this.length-(e-t)+i.length>nw||i.flags&8)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Ph(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=this.flags&8,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new ci(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return sw(this.dom,t,e)}},Hs=class Rh extends ee{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let s of e)s.setParent(this)}setAttrs(t){if(Tg(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!((this.flags|t.flags)&8)}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,s,r,l){return i&&(!(i instanceof Rh&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&l<=0)?!1:(Bg(this,t,e,i?i.children.slice():[],r-1,l-1),this.markDirty(),!0)}split(t){let e=[],i=0,s=-1,r=0;for(let h of this.children){let c=i+h.length;c>t&&e.push(i<t?h.split(t-i):h),s<0&&i>=t&&(s=r),i=c,r++}let l=this.length-t;return this.length=t,s>-1&&(this.children.length=s,this.markDirty()),new Rh(this.mark,e,l)}domAtPos(t){return Fg(this,t)}coordsAt(t,e){return Hg(this,t,e)}};function sw(n,t,e){let i=n.nodeValue.length;t>i&&(t=i);let s=t,r=t,l=0;t==0&&e<0||t==i&&e>=0?ut.chrome||ut.gecko||(t?(s--,l=1):r<i&&(r++,l=-1)):e<0?s--:r<i&&r++;let h=is(n,s,r).getClientRects();if(!h.length)return null;let c=h[(l?l<0:e>=0)?0:h.length-1];return ut.safari&&!l&&c.width==0&&(c=Array.prototype.find.call(h,g=>g.width)||c),l?Ql(c,l<0):c||null}let Wc=class xr extends ee{static create(t,e,i){return new xr(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=xr.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,s,r,l){return i&&(!(i instanceof xr)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&l<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof xr&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.compare(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return A.Text.empty;let t=this;for(;t.parent;)t=t.parent;let{view:e}=t,i=e&&e.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):A.Text.empty}domAtPos(t){return(this.length?t==0:this.side>0)?ci.before(this.dom):ci.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let l=this.side?this.side<0:t>0;for(let h=l?s.length-1:0;r=s[h],!(t>0?h==0:h==s.length-1||r.top<r.bottom);h+=l?-1:1);return Ql(r,!l)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}},Bh=class Lh extends ee{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof Lh&&t.side==this.side}split(){return new Lh(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?ci.before(this.dom):ci.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return A.Text.empty}get isHidden(){return!0}};Vn.prototype.children=Wc.prototype.children=Bh.prototype.children=$c;function Fg(n,t){let e=n.dom,{children:i}=n,s=0;for(let r=0;s<i.length;s++){let l=i[s],h=r+l.length;if(!(h==r&&l.getSide()<=0)){if(t>r&&t<h&&l.dom.parentNode==e)return l.domAtPos(t-r);if(t<=r)break;r=h}}for(let r=s;r>0;r--){let l=i[r-1];if(l.dom.parentNode==e)return l.domAtPos(l.length)}for(let r=s;r<i.length;r++){let l=i[r];if(l.dom.parentNode==e)return l.domAtPos(0)}return new ci(e,0)}function Ig(n,t,e){let i,{children:s}=n;e>0&&t instanceof Hs&&s.length&&(i=s[s.length-1])instanceof Hs&&i.mark.eq(t.mark)?Ig(i,t.children[0],e-1):(s.push(t),t.setParent(n)),n.length+=t.length}function Hg(n,t,e){let i=null,s=-1,r=null,l=-1;function h(g,p){for(let y=0,x=0;y<g.children.length&&x<=p;y++){let T=g.children[y],P=x+T.length;P>=p&&(T.children.length?h(T,p-x):(!r||r.isHidden&&e>0)&&(P>p||x==P&&T.getSide()>0)?(r=T,l=p-x):(x<p||x==P&&T.getSide()<0&&!T.isHidden)&&(i=T,s=p-x)),x=P}}h(n,t);let c=(e<0?i:r)||i||r;return c?c.coordsAt(Math.max(0,c==i?s:l),e):rw(n)}function rw(n){let t=n.dom.lastChild;if(!t)return n.dom.getBoundingClientRect();let e=Is(t);return e[e.length-1]||null}function Nh(n,t){for(let e in n)e=="class"&&t.class?t.class+=" "+n.class:e=="style"&&t.style?t.style+=";"+n.style:t[e]=n[e];return t}const qd=Object.create(null);function Dl(n,t,e){if(n==t)return!0;n||(n=qd),t||(t=qd);let i=Object.keys(n),s=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=s.length-(e&&s.indexOf(e)>-1?1:0))return!1;for(let r of i)if(r!=e&&(s.indexOf(r)==-1||n[r]!==t[r]))return!1;return!0}function Fh(n,t,e){let i=!1;if(t)for(let s in t)e&&s in e||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(e)for(let s in e)t&&t[s]==e[s]||(i=!0,s=="style"?n.style.cssText=e[s]:n.setAttribute(s,e[s]));return i}function ow(n){let t=Object.create(null);for(let e=0;e<n.attributes.length;e++){let i=n.attributes[e];t[i.name]=i.value}return t}let Ve=class vr extends ee{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,s,r,l){if(i){if(!(i instanceof vr))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Bg(this,t,e,i?i.children.slice():[],r,l),!0}split(t){let e=new vr;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:s}=this.childPos(t);s&&(e.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)e.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){Dl(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Ig(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Nh(e,this.attrs||{})),i&&(this.attrs=Nh({class:i},this.attrs||{}))}domAtPos(t){return Fg(this,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?this.flags&4&&(Tg(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&&(Fh(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let s=this.dom.lastChild;for(;s&&ee.get(s)instanceof Hs;)s=s.lastChild;if(!s||!this.length||s.nodeName!="BR"&&((i=ee.get(s))===null||i===void 0?void 0:i.isEditable)==!1&&(!ut.ios||!this.children.some(r=>r instanceof Vn))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let i of this.children){if(!(i instanceof Vn)||/[^ -~]/.test(i.text))return null;let s=Is(i.dom);if(s.length!=1)return null;t+=s[0].width,e=s[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let i=Hg(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:s}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-s.lineHeight)<2&&s.textHeight<r){let l=(r-s.textHeight)/2;return{top:i.top+l,bottom:i.bottom-l,left:i.left,right:i.left}}}return i}become(t){return t instanceof vr&&this.children.length==0&&t.children.length==0&&Dl(this.attrs,t.attrs)&&this.breakAfter==t.breakAfter}covers(){return!0}static find(t,e){for(let i=0,s=0;i<t.children.length;i++){let r=t.children[i],l=s+r.length;if(l>=e){if(r instanceof vr)return r;if(l>e)break}s=l+r.breakAfter}return null}},Lr=class fl extends ee{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,s,r,l){return i&&(!(i instanceof fl)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&l<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?ci.before(this.dom):ci.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new fl(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return $c}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):A.Text.empty}domBoundsAround(){return null}become(t){return t instanceof fl&&t.widget.constructor==this.widget.constructor?(t.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.deco=t.deco,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){return this.widget.coordsAt(this.dom,t,e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e==i?!1:t<0?e<0:i>0}},Bi=class{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}};var We=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(We||(We={}));let kt=class extends A.RangeValue{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new zc(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new Vs(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:l}=zg(t,e);i=(r?e?-3e8:-1:5e8)-1,s=(l?e?2e8:1:-6e8)+1}return new Vs(t,i,s,e,t.widget||null,!0)}static line(t){return new qc(t)}static set(t,e=!1){return A.RangeSet.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};kt.none=A.RangeSet.empty;let zc=class Vg extends kt{constructor(t){let{start:e,end:i}=zg(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof Vg&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((i=t.attrs)===null||i===void 0?void 0:i.class))&&Dl(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}};zc.prototype.point=!1;let qc=class $g extends kt{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof $g&&this.spec.class==t.spec.class&&Dl(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}};qc.prototype.mapMode=A.MapMode.TrackBefore;qc.prototype.point=!0;let Vs=class Wg extends kt{constructor(t,e,i,s,r,l){super(e,i,r,t),this.block=s,this.isReplace=l,this.mapMode=s?e<=0?A.MapMode.TrackBefore:A.MapMode.TrackAfter:A.MapMode.TrackDel}get type(){return this.startSide!=this.endSide?We.WidgetRange:this.startSide<=0?We.WidgetBefore:We.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof Wg&&lw(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}};Vs.prototype.point=!0;function zg(n,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=n;return e==null&&(e=n.inclusive),i==null&&(i=n.inclusive),{start:e??t,end:i??t}}function lw(n,t){return n==t||!!(n&&t&&n.compare(t))}function Ih(n,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=n?e[s]=Math.max(e[s],t):e.push(n,t)}let za=class qg{constructor(t,e,i,s){this.doc=t,this.pos=e,this.end=i,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=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof Lr&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new Ve),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Fo(new Bh(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(t&&this.content.length&&this.content[this.content.length-1]instanceof Lr)&&this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:l,done:h}=this.cursor.next(this.skip);if(this.skip=0,h)throw new Error("Ran out of text content when drawing inline views");if(l){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(Fo(new Vn(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=0}}span(t,e,i,s){this.buildText(e-t,i,s),this.pos=e,this.openStart<0&&(this.openStart=s)}point(t,e,i,s,r,l){if(this.disallowBlockEffectsFor[l]&&i instanceof Vs){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let h=e-t;if(i instanceof Vs)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Lr(i.widget||$s.block,h,i));else{let c=Wc.create(i.widget||$s.inline,h,h?0:i.startSide),g=this.atCursorPos&&!c.isEditable&&r<=s.length&&(t<e||i.startSide>0),p=!c.isEditable&&(t<e||r>s.length||i.startSide<=0),y=this.getLine();this.pendingBuffer==2&&!g&&!c.isEditable&&(this.pendingBuffer=0),this.flushBuffer(s),g&&(y.append(Fo(new Bh(1),s),r),r=s.length+Math.max(0,r-s.length)),y.append(Fo(c,s),r),this.atCursorPos=p,this.pendingBuffer=p?t<e||r>s.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=s.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);h&&(this.textOff+h<=this.text.length?this.textOff+=h:(this.skip+=h-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,s,r){let l=new qg(t,e,i,r);return l.openEnd=A.RangeSet.spans(s,e,i,l),l.openStart<0&&(l.openStart=l.openEnd),l.finish(l.openEnd),l}};function Fo(n,t){for(let e of t)n=new Hs(e,[n],n.length);return n}let $s=class extends Bi{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};$s.inline=new $s("span");$s.block=new $s("div");var Qt=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(Qt||(Qt={}));const ns=Qt.LTR,Kc=Qt.RTL;function Kg(n){let t=[];for(let e=0;e<n.length;e++)t.push(1<<+n[e]);return t}const aw=Kg("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),hw=Kg("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Hh=Object.create(null),$i=[];for(let n of["()","[]","{}"]){let t=n.charCodeAt(0),e=n.charCodeAt(1);Hh[t]=e,Hh[e]=-t}function jg(n){return n<=247?aw[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?hw[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const cw=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;let Bn=class{get dir(){return this.level%2?Kc:ns}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let r=-1;for(let l=0;l<t.length;l++){let h=t[l];if(h.from<=e&&h.to>=e){if(h.level==i)return l;(r<0||(s!=0?s<0?h.from<e:h.to>e:t[r].level>h.level))&&(r=l)}}if(r<0)throw new RangeError("Index out of range");return r}};function _g(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++){let i=n[e],s=t[e];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!_g(i.inner,s.inner))return!1}return!0}const qt=[];function fw(n,t,e,i,s){for(let r=0;r<=i.length;r++){let l=r?i[r-1].to:t,h=r<i.length?i[r].from:e,c=r?256:s;for(let g=l,p=c,y=c;g<h;g++){let x=jg(n.charCodeAt(g));x==512?x=p:x==8&&y==4&&(x=16),qt[g]=x==4?2:x,x&7&&(y=x),p=x}for(let g=l,p=c,y=c;g<h;g++){let x=qt[g];if(x==128)g<h-1&&p==qt[g+1]&&p&24?x=qt[g]=p:qt[g]=256;else if(x==64){let T=g+1;for(;T<h&&qt[T]==64;)T++;let P=g&&p==8||T<e&&qt[T]==8?y==1?1:8:256;for(let I=g;I<T;I++)qt[I]=P;g=T-1}else x==8&&y==1&&(qt[g]=1);p=x,x&7&&(y=x)}}}function dw(n,t,e,i,s){let r=s==1?2:1;for(let l=0,h=0,c=0;l<=i.length;l++){let g=l?i[l-1].to:t,p=l<i.length?i[l].from:e;for(let y=g,x,T,P;y<p;y++)if(T=Hh[x=n.charCodeAt(y)])if(T<0){for(let I=h-3;I>=0;I-=3)if($i[I+1]==-T){let z=$i[I+2],W=z&2?s:z&4?z&1?r:s:0;W&&(qt[y]=qt[$i[I]]=W),h=I;break}}else{if($i.length==189)break;$i[h++]=y,$i[h++]=x,$i[h++]=c}else if((P=qt[y])==2||P==1){let I=P==s;c=I?0:1;for(let z=h-3;z>=0;z-=3){let W=$i[z+2];if(W&2)break;if(I)$i[z+2]|=2;else{if(W&4)break;$i[z+2]|=4}}}}}function uw(n,t,e,i){for(let s=0,r=i;s<=e.length;s++){let l=s?e[s-1].to:n,h=s<e.length?e[s].from:t;for(let c=l;c<h;){let g=qt[c];if(g==256){let p=c+1;for(;;)if(p==h){if(s==e.length)break;p=e[s++].to,h=s<e.length?e[s].from:t}else if(qt[p]==256)p++;else break;let y=r==1,x=(p<t?qt[p]:i)==1,T=y==x?y?1:2:i;for(let P=p,I=s,z=I?e[I-1].to:n;P>c;)P==z&&(P=e[--I].from,z=I?e[I-1].to:n),qt[--P]=T;c=p}else r=g,c++}}}function Vh(n,t,e,i,s,r,l){let h=i%2?2:1;if(i%2==s%2)for(let c=t,g=0;c<e;){let p=!0,y=!1;if(g==r.length||c<r[g].from){let I=qt[c];I!=h&&(p=!1,y=I==16)}let x=!p&&h==1?[]:null,T=p?i:i+1,P=c;t:for(;;)if(g<r.length&&P==r[g].from){if(y)break t;let I=r[g];if(!p)for(let z=I.to,W=g+1;;){if(z==e)break t;if(W<r.length&&r[W].from==z)z=r[W++].to;else{if(qt[z]==h)break t;break}}if(g++,x)x.push(I);else{I.from>c&&l.push(new Bn(c,I.from,T));let z=I.direction==ns!=!(T%2);$h(n,z?i+1:i,s,I.inner,I.from,I.to,l),c=I.to}P=I.to}else{if(P==e||(p?qt[P]!=h:qt[P]==h))break;P++}x?Vh(n,c,P,i+1,s,x,l):c<P&&l.push(new Bn(c,P,T)),c=P}else for(let c=e,g=r.length;c>t;){let p=!0,y=!1;if(!g||c>r[g-1].to){let I=qt[c-1];I!=h&&(p=!1,y=I==16)}let x=!p&&h==1?[]:null,T=p?i:i+1,P=c;t:for(;;)if(g&&P==r[g-1].to){if(y)break t;let I=r[--g];if(!p)for(let z=I.from,W=g;;){if(z==t)break t;if(W&&r[W-1].to==z)z=r[--W].from;else{if(qt[z-1]==h)break t;break}}if(x)x.push(I);else{I.to<c&&l.push(new Bn(I.to,c,T));let z=I.direction==ns!=!(T%2);$h(n,z?i+1:i,s,I.inner,I.from,I.to,l),c=I.from}P=I.from}else{if(P==t||(p?qt[P-1]!=h:qt[P-1]==h))break;P--}x?Vh(n,P,c,i+1,s,x,l):P<c&&l.push(new Bn(P,c,T)),c=P}}function $h(n,t,e,i,s,r,l){let h=t%2?2:1;fw(n,s,r,i,h),dw(n,s,r,i,h),uw(s,r,i,h),Vh(n,s,r,t,e,i,l)}function pw(n,t,e){if(!n)return[new Bn(0,0,t==Kc?1:0)];if(t==ns&&!e.length&&!cw.test(n))return Gg(n.length);if(e.length)for(;n.length>qt.length;)qt[qt.length]=256;let i=[],s=t==ns?0:1;return $h(n,s,s,e,0,n.length,i),i}function Gg(n){return[new Bn(0,n,0)]}let Yg="";function gw(n,t,e,i,s){var r;let l=i.head-n.from,h=Bn.find(t,l,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),c=t[h],g=c.side(s,e);if(l==g){let x=h+=s?1:-1;if(x<0||x>=t.length)return null;c=t[h=x],l=c.side(!s,e),g=c.side(s,e)}let p=A.findClusterBreak(n.text,l,c.forward(s,e));(p<c.from||p>c.to)&&(p=g),Yg=n.text.slice(Math.min(l,p),Math.max(l,p));let y=h==(s?t.length-1:0)?null:t[h+(s?1:-1)];return y&&p==g&&y.level+(s?0:1)<c.level?A.EditorSelection.cursor(y.side(!s,e)+n.from,y.forward(s,e)?1:-1,y.level):A.EditorSelection.cursor(p+n.from,c.forward(s,e)?-1:1,c.level)}function mw(n,t,e){for(let i=t;i<e;i++){let s=jg(n.charCodeAt(i));if(s==1)return ns;if(s==2||s==4)return Kc}return ns}const Ug=A.Facet.define(),Xg=A.Facet.define(),Jg=A.Facet.define(),Qg=A.Facet.define(),Wh=A.Facet.define(),Zg=A.Facet.define(),tm=A.Facet.define(),em=A.Facet.define({combine:n=>n.some(t=>t)}),im=A.Facet.define({combine:n=>n.some(t=>t)}),nm=A.Facet.define();let qa=class zh{constructor(t,e="nearest",i="nearest",s=5,r=5,l=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=l}map(t){return t.empty?this:new zh(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new zh(A.EditorSelection.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}};const Io=A.StateEffect.define({map:(n,t)=>n.map(t)}),sm=A.StateEffect.define();function $e(n,t,e){let i=n.facet(Qg);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}const On=A.Facet.define({combine:n=>n.length?n[0]:!0});let bw=0;const kr=A.Facet.define();let Te=class qh{constructor(t,e,i,s,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:r,decorations:l}=e||{};return new qh(bw++,t,i,s,h=>{let c=[kr.of(h)];return l&&c.push(Vr.of(g=>{let p=g.plugin(h);return p?l(p):kt.none})),r&&c.push(r(h)),c})}static fromClass(t,e){return qh.define(i=>new t(i),e)}},Ka=class{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if($e(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){$e(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){$e(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}};const rm=A.Facet.define(),jc=A.Facet.define(),Vr=A.Facet.define(),om=A.Facet.define(),_c=A.Facet.define(),lm=A.Facet.define();function Kd(n,t){let e=n.state.facet(lm);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(n):r),s=[];return A.RangeSet.spans(i,t.from,t.to,{point(){},span(r,l,h,c){let g=r-t.from,p=l-t.from,y=s;for(let x=h.length-1;x>=0;x--,c--){let T=h[x].spec.bidiIsolate,P;if(T==null&&(T=mw(t.text,g,p)),c>0&&y.length&&(P=y[y.length-1]).to==g&&P.direction==T)P.to=p,y=P.inner;else{let I={from:g,to:p,direction:T,inner:[]};y.push(I),y=I.inner}}}}),s}const am=A.Facet.define();function hm(n){let t=0,e=0,i=0,s=0;for(let r of n.state.facet(am)){let l=r(n);l&&(l.left!=null&&(t=Math.max(t,l.left)),l.right!=null&&(e=Math.max(e,l.right)),l.top!=null&&(i=Math.max(i,l.top)),l.bottom!=null&&(s=Math.max(s,l.bottom)))}return{left:t,right:e,top:i,bottom:s}}const Cr=A.Facet.define();let Fn=class dl{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new dl(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,r=0,l=0,h=0;;s++){let c=s==t.length?null:t[s],g=l-h,p=c?c.fromB:1e9;for(;r<e.length&&e[r]<p;){let y=e[r],x=e[r+1],T=Math.max(h,y),P=Math.min(p,x);if(T<=P&&new dl(T+g,P+g,T,P).addToSet(i),x>p)break;r+=2}if(!c)return i;new dl(c.fromA,c.toA,c.fromB,c.toB).addToSet(i),l=c.toA,h=c.toB}}},jd=class cm{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=A.ChangeSet.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,l,h,c)=>s.push(new Fn(r,l,h,c))),this.changedRanges=s}static create(t,e,i){return new cm(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},_d=class extends ee{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=kt.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new Ve],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Fn(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:g,toA:p})=>p<this.minWidthFrom||g>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?s=this.domChanged.newSel.head:!Cw(t.changes,this.hasComposition)&&!t.selectionSet&&(s=t.state.selection.main.head));let r=s>-1?Sw(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:g,to:p}=this.hasComposition;i=new Fn(g,p,t.changes.mapPos(g,-1),t.changes.mapPos(p,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(ut.ie||ut.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let l=this.decorations,h=this.updateDeco(),c=vw(l,h,t.changes);return i=Fn.extendWithRanges(i,c),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);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 l=ut.chrome||ut.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,l),this.flags&=-8,l&&(l.written||s.selectionRange.focusNode!=l.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(l=>l.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let l of this.children)l instanceof Lr&&l.widget instanceof Gd&&r.push(l.dom);s.updateGaps(r)}updateChildren(t,e,i){let s=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let l=s.length-1;;l--){let h=l>=0?s[l]:null;if(!h)break;let{fromA:c,toA:g,fromB:p,toB:y}=h,x,T,P,I;if(i&&i.range.fromB<y&&i.range.toB>p){let Q=za.build(this.view.state.doc,p,i.range.fromB,this.decorations,this.dynamicDecorationMap),st=za.build(this.view.state.doc,i.range.toB,y,this.decorations,this.dynamicDecorationMap);T=Q.breakAtStart,P=Q.openStart,I=st.openEnd;let at=this.compositionView(i);st.breakAtStart?at.breakAfter=1:st.content.length&&at.merge(at.length,at.length,st.content[0],!1,st.openStart,0)&&(at.breakAfter=st.content[0].breakAfter,st.content.shift()),Q.content.length&&at.merge(0,0,Q.content[Q.content.length-1],!0,0,Q.openEnd)&&Q.content.pop(),x=Q.content.concat(at).concat(st.content)}else({content:x,breakAtStart:T,openStart:P,openEnd:I}=za.build(this.view.state.doc,p,y,this.decorations,this.dynamicDecorationMap));let{i:z,off:W}=r.findPos(g,1),{i:U,off:ot}=r.findPos(c,-1);Rg(this,U,ot,z,W,x,T,P,I)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(sm)&&(this.editContextFormatting=i.value)}compositionView(t){let e=new Vn(t.text.nodeValue);e.flags|=8;for(let{deco:s}of t.marks)e=new Hs(s,[e],e.length);let i=new Ve;return i.append(e,0),i}fixCompositionDOM(t){let e=(r,l)=>{l.flags|=8|(l.children.some(c=>c.flags&7)?1:0),this.markedForComposition.add(l);let h=ee.get(r);h&&h!=l&&(h.dom=null),l.setDOM(r)},i=this.childPos(t.range.fromB,1),s=this.children[i.i];e(t.line,s);for(let r=t.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],e(r>=0?t.marks[r].node:t.text,s)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&cl(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||e||r))return;let l=this.forceSelection;this.forceSelection=!1;let h=this.view.state.selection.main,c=this.moveToLine(this.domAtPos(h.anchor)),g=h.empty?c:this.moveToLine(this.domAtPos(h.head));if(ut.gecko&&h.empty&&!this.hasComposition&&yw(c)){let y=document.createTextNode("");this.view.observer.ignore(()=>c.node.insertBefore(y,c.node.childNodes[c.offset]||null)),c=g=new ci(y,0),l=!0}let p=this.view.observer.selectionRange;(l||!p.focusNode||(!Br(c.node,c.offset,p.anchorNode,p.anchorOffset)||!Br(g.node,g.offset,p.focusNode,p.focusOffset))&&!this.suppressWidgetCursorChange(p,h))&&(this.view.observer.ignore(()=>{ut.android&&ut.chrome&&this.dom.contains(p.focusNode)&&kw(p.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let y=Hr(this.view.root);if(y)if(h.empty){if(ut.gecko){let x=ww(c.node,c.offset);if(x&&x!=3){let T=(x==1?Og:Eg)(c.node,c.offset);T&&(c=new ci(T.node,T.offset))}}y.collapse(c.node,c.offset),h.bidiLevel!=null&&y.caretBidiLevel!==void 0&&(y.caretBidiLevel=h.bidiLevel)}else if(y.extend){y.collapse(c.node,c.offset);try{y.extend(g.node,g.offset)}catch{}}else{let x=document.createRange();h.anchor>h.head&&([c,g]=[g,c]),x.setEnd(g.node,g.offset),x.setStart(c.node,c.offset),y.removeAllRanges(),y.addRange(x)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(c,g)),this.impreciseAnchor=c.precise?null:new ci(p.anchorNode,p.anchorOffset),this.impreciseHead=g.precise?null:new ci(p.focusNode,p.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Br(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=Hr(t.root),{anchorNode:s,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let l=Ve.find(this,e.head);if(!l)return;let h=l.posAtStart;if(e.head==h||e.head==h+l.length)return;let c=this.coordsAt(e.head,-1),g=this.coordsAt(e.head,1);if(!c||!g||c.bottom>g.top)return;let p=this.domAtPos(e.head+e.assoc);i.collapse(p.node,p.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let y=t.observer.selectionRange;t.docView.posFromDOM(y.anchorNode,y.anchorOffset)!=e.from&&i.collapse(s,r)}moveToLine(t){let e=this.dom,i;if(t.node!=e)return t;for(let s=t.offset;!i&&s<e.childNodes.length;s++){let r=ee.get(e.childNodes[s]);r instanceof Ve&&(i=r.domAtPos(0))}for(let s=t.offset-1;!i&&s>=0;s--){let r=ee.get(e.childNodes[s]);r instanceof Ve&&(i=r.domAtPos(r.length))}return i?new ci(i.node,i.offset,!0):t}nearest(t){for(let e=t;e;){let i=ee.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let s=this.children[e];if(i<s.length||s instanceof Ve)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,s=0;for(let r=this.length,l=this.children.length-1;l>=0;l--){let h=this.children[l],c=r-h.breakAfter,g=c-h.length;if(c<t)break;if(g<=t&&(g<t||h.covers(-1))&&(c>t||h.covers(1))&&(!i||h instanceof Ve&&!(i instanceof Ve&&e>=0)))i=h,s=g;else if(i&&g==t&&c==t&&h instanceof Lr&&Math.abs(e)<2){if(h.deco.startSide<0)break;l&&(i=null)}r=g}return i?i.coordsAt(t-s,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),s=this.children[e];if(!(s instanceof Ve))return null;for(;s.children.length;){let{i:h,off:c}=s.childPos(i,1);for(;;h++){if(h==s.children.length)return null;if((s=s.children[h]).length)break}i=c}if(!(s instanceof Vn))return null;let r=A.findClusterBreak(s.text,i);if(r==i)return null;let l=is(s.dom,i,r).getClientRects();for(let h=0;h<l.length;h++){let c=l[h];if(h==l.length-1||c.top<c.bottom&&c.left<c.right)return c}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,l=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,h=-1,c=this.view.textDirection==Qt.LTR;for(let g=0,p=0;p<this.children.length;p++){let y=this.children[p],x=g+y.length;if(x>s)break;if(g>=i){let T=y.dom.getBoundingClientRect();if(e.push(T.height),l){let P=y.dom.lastChild,I=P?Is(P):[];if(I.length){let z=I[I.length-1],W=c?z.right-T.left:T.right-z.left;W>h&&(h=W,this.minWidth=r,this.minWidthFrom=g,this.minWidthTo=x)}}}g=x+y.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?Qt.RTL:Qt.LTR}measureTextSize(){for(let r of this.children)if(r instanceof Ve){let l=r.measureTextSize();if(l)return l}let t=document.createElement("div"),e,i,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(t);let r=Is(t.firstChild)[0];e=t.getBoundingClientRect().height,i=r?r.width/27:7,s=r?r.height:e,t.remove()}),{lineHeight:e,charWidth:i,textHeight:s}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new Pg(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],l=r?r.from-1:this.length;if(l>i){let h=(e.lineBlockAt(l).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(kt.replace({widget:new Gd(h),block:!0,inclusive:!0,isBlockGap:!0}).range(i,l))}if(!r)break;i=r.to+1}return kt.set(t)}updateDeco(){let t=1,e=this.view.state.facet(Vr).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,s=this.view.state.facet(om).map((r,l)=>{let h=typeof r=="function";return h&&(i=!0),h?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(A.RangeSet.join(s))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let g=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=g.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let g of this.view.state.facet(nm))try{if(g(this.view,t.range,t))return!0}catch(p){$e(this.view.state,p,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=hm(this.view),l={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:h,offsetHeight:c}=this.view.scrollDOM;JS(this.view.scrollDOM,l,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,h),-h),Math.max(Math.min(t.yMargin,c),-c),this.view.textDirection==Qt.LTR)}};function yw(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}let Gd=class extends Bi{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function fm(n,t){let e=n.observer.selectionRange;if(!e.focusNode)return null;let i=Og(e.focusNode,e.focusOffset),s=Eg(e.focusNode,e.focusOffset),r=i||s;if(s&&i&&s.node!=i.node){let h=ee.get(s.node);if(!h||h instanceof Vn&&h.text!=s.node.nodeValue)r=s;else if(n.docView.lastCompositionAfterCursor){let c=ee.get(i.node);!c||c instanceof Vn&&c.text!=i.node.nodeValue||(r=s)}}if(n.docView.lastCompositionAfterCursor=r!=i,!r)return null;let l=t-r.offset;return{from:l,to:l+r.node.nodeValue.length,node:r.node}}function Sw(n,t,e){let i=fm(n,e);if(!i)return null;let{node:s,from:r,to:l}=i,h=s.nodeValue;if(/[\n\r]/.test(h)||n.state.doc.sliceString(i.from,i.to)!=h)return null;let c=t.invertedDesc,g=new Fn(c.mapPos(r),c.mapPos(l),r,l),p=[];for(let y=s.parentNode;;y=y.parentNode){let x=ee.get(y);if(x instanceof Hs)p.push({node:y,deco:x.mark});else{if(x instanceof Ve||y.nodeName=="DIV"&&y.parentNode==n.contentDOM)return{range:g,text:s,marks:p,line:y};if(y!=n.contentDOM)p.push({node:y,deco:new zc({inclusive:!0,attributes:ow(y),tagName:y.tagName.toLowerCase()})});else return null}}}function ww(n,t){return n.nodeType!=1?0:(t&&n.childNodes[t-1].contentEditable=="false"?1:0)|(t<n.childNodes.length&&n.childNodes[t].contentEditable=="false"?2:0)}let xw=class{constructor(){this.changes=[]}compareRange(t,e){Ih(t,e,this.changes)}comparePoint(t,e){Ih(t,e,this.changes)}};function vw(n,t,e){let i=new xw;return A.RangeSet.compare(n,t,e,i),i.changes}function kw(n,t){for(let e=n;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function Cw(n,t){let e=!1;return t&&n.iterChangedRanges((i,s)=>{i<t.to&&s>t.from&&(e=!0)}),e}function Mw(n,t,e=1){let i=n.charCategorizer(t),s=n.doc.lineAt(t),r=t-s.from;if(s.length==0)return A.EditorSelection.cursor(t);r==0?e=1:r==s.length&&(e=-1);let l=r,h=r;e<0?l=A.findClusterBreak(s.text,r,!1):h=A.findClusterBreak(s.text,r);let c=i(s.text.slice(l,h));for(;l>0;){let g=A.findClusterBreak(s.text,l,!1);if(i(s.text.slice(g,l))!=c)break;l=g}for(;h<s.length;){let g=A.findClusterBreak(s.text,h);if(i(s.text.slice(h,g))!=c)break;h=g}return A.EditorSelection.range(l+s.from,h+s.from)}function Aw(n,t){return t.left>n?t.left-n:Math.max(0,n-t.right)}function Tw(n,t){return t.top>n?t.top-n:Math.max(0,n-t.bottom)}function ja(n,t){return n.top<t.bottom-1&&n.bottom>t.top+1}function Yd(n,t){return t<n.top?{top:t,left:n.left,right:n.right,bottom:n.bottom}:n}function Ud(n,t){return t>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:t}:n}function Kh(n,t,e){let i,s,r,l,h=!1,c,g,p,y;for(let P=n.firstChild;P;P=P.nextSibling){let I=Is(P);for(let z=0;z<I.length;z++){let W=I[z];s&&ja(s,W)&&(W=Yd(Ud(W,s.bottom),s.top));let U=Aw(t,W),ot=Tw(e,W);if(U==0&&ot==0)return P.nodeType==3?Xd(P,t,e):Kh(P,t,e);if(!i||l>ot||l==ot&&r>U){i=P,s=W,r=U,l=ot;let Q=ot?e<W.top?-1:1:U?t<W.left?-1:1:0;h=!Q||(Q>0?z<I.length-1:z>0)}U==0?e>W.bottom&&(!p||p.bottom<W.bottom)?(c=P,p=W):e<W.top&&(!y||y.top>W.top)&&(g=P,y=W):p&&ja(p,W)?p=Ud(p,W.bottom):y&&ja(y,W)&&(y=Yd(y,W.top))}}if(p&&p.bottom>=e?(i=c,s=p):y&&y.top<=e&&(i=g,s=y),!i)return{node:n,offset:0};let x=Math.max(s.left,Math.min(s.right,t));if(i.nodeType==3)return Xd(i,x,e);if(h&&i.contentEditable!="false")return Kh(i,x,e);let T=Array.prototype.indexOf.call(n.childNodes,i)+(t>=(s.left+s.right)/2?1:0);return{node:n,offset:T}}function Xd(n,t,e){let i=n.nodeValue.length,s=-1,r=1e9,l=0;for(let h=0;h<i;h++){let c=is(n,h,h+1).getClientRects();for(let g=0;g<c.length;g++){let p=c[g];if(p.top==p.bottom)continue;l||(l=t-p.left);let y=(p.top>e?p.top-e:e-p.bottom)-1;if(p.left-1<=t&&p.right+1>=t&&y<r){let x=t>=(p.left+p.right)/2,T=x;if((ut.chrome||ut.gecko)&&is(n,h).getBoundingClientRect().left==p.right&&(T=!x),y<=0)return{node:n,offset:h+(T?1:0)};s=h+(T?1:0),r=y}}}return{node:n,offset:s>-1?s:l>0?n.nodeValue.length:0}}function dm(n,t,e,i=-1){var s,r;let l=n.contentDOM.getBoundingClientRect(),h=l.top+n.viewState.paddingTop,c,{docHeight:g}=n.viewState,{x:p,y}=t,x=y-h;if(x<0)return 0;if(x>g)return n.state.doc.length;for(let Q=n.viewState.heightOracle.textHeight/2,st=!1;c=n.elementAtHeight(x),c.type!=We.Text;)for(;x=i>0?c.bottom+Q:c.top-Q,!(x>=0&&x<=g);){if(st)return e?null:0;st=!0,i=-i}y=h+x;let T=c.from;if(T<n.viewport.from)return n.viewport.from==0?0:e?null:Jd(n,l,c,p,y);if(T>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:e?null:Jd(n,l,c,p,y);let P=n.dom.ownerDocument,I=n.root.elementFromPoint?n.root:P,z=I.elementFromPoint(p,y);z&&!n.contentDOM.contains(z)&&(z=null),z||(p=Math.max(l.left+1,Math.min(l.right-1,p)),z=I.elementFromPoint(p,y),z&&!n.contentDOM.contains(z)&&(z=null));let W,U=-1;if(z&&((s=n.docView.nearest(z))===null||s===void 0?void 0:s.isEditable)!=!1){if(P.caretPositionFromPoint){let Q=P.caretPositionFromPoint(p,y);Q&&({offsetNode:W,offset:U}=Q)}else if(P.caretRangeFromPoint){let Q=P.caretRangeFromPoint(p,y);Q&&({startContainer:W,startOffset:U}=Q,(!n.contentDOM.contains(W)||ut.safari&&Dw(W,U,p)||ut.chrome&&Ow(W,U,p))&&(W=void 0))}}if(!W||!n.docView.dom.contains(W)){let Q=Ve.find(n.docView,T);if(!Q)return x>c.top+c.height/2?c.to:c.from;({node:W,offset:U}=Kh(Q.dom,p,y))}let ot=n.docView.nearest(W);if(!ot)return null;if(ot.isWidget&&((r=ot.dom)===null||r===void 0?void 0:r.nodeType)==1){let Q=ot.dom.getBoundingClientRect();return t.y<Q.top||t.y<=Q.bottom&&t.x<=(Q.left+Q.right)/2?ot.posAtStart:ot.posAtEnd}else return ot.localPosFromDOM(W,U)+ot.posAtStart}function Jd(n,t,e,i,s){let r=Math.round((i-t.left)*n.defaultCharacterWidth);if(n.lineWrapping&&e.height>n.defaultLineHeight*1.5){let h=n.viewState.heightOracle.textHeight,c=Math.floor((s-e.top-(n.defaultLineHeight-h)*.5)/h);r+=c*n.viewState.heightOracle.lineLength}let l=n.state.sliceDoc(e.from,e.to);return e.from+A.findColumn(l,r,n.state.tabSize)}function Dw(n,t,e){let i;if(n.nodeType!=3||t!=(i=n.nodeValue.length))return!1;for(let s=n.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return is(n,i-1,i).getBoundingClientRect().left>e}function Ow(n,t,e){if(t!=0)return!1;for(let s=n;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let i=n.nodeType==1?n.getBoundingClientRect():is(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function jh(n,t){let e=n.lineBlockAt(t);if(Array.isArray(e.type)){for(let i of e.type)if(i.to>t||i.to==t&&(i.to==e.to||i.type==We.Text))return i}return e}function Ew(n,t,e,i){let s=jh(n,t.head),r=!i||s.type!=We.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(r){let l=n.dom.getBoundingClientRect(),h=n.textDirectionAt(s.from),c=n.posAtCoords({x:e==(h==Qt.LTR)?l.right-1:l.left+1,y:(r.top+r.bottom)/2});if(c!=null)return A.EditorSelection.cursor(c,e?-1:1)}return A.EditorSelection.cursor(e?s.to:s.from,e?-1:1)}function Qd(n,t,e,i){let s=n.state.doc.lineAt(t.head),r=n.bidiSpans(s),l=n.textDirectionAt(s.from);for(let h=t,c=null;;){let g=gw(s,r,l,h,e),p=Yg;if(!g){if(s.number==(e?n.state.doc.lines:1))return h;p=`
6
- `,s=n.state.doc.line(s.number+(e?1:-1)),r=n.bidiSpans(s),g=n.visualLineSide(s,!e)}if(c){if(!c(p))return h}else{if(!i)return g;c=i(p)}h=g}}function Pw(n,t,e){let i=n.state.charCategorizer(t),s=i(e);return r=>{let l=i(r);return s==A.CharCategory.Space&&(s=l),s==l}}function Rw(n,t,e,i){let s=t.head,r=e?1:-1;if(s==(e?n.state.doc.length:0))return A.EditorSelection.cursor(s,t.assoc);let l=t.goalColumn,h,c=n.contentDOM.getBoundingClientRect(),g=n.coordsAtPos(s,t.assoc||-1),p=n.documentTop;if(g)l==null&&(l=g.left-c.left),h=r<0?g.top:g.bottom;else{let T=n.viewState.lineBlockAt(s);l==null&&(l=Math.min(c.right-c.left,n.defaultCharacterWidth*(s-T.from))),h=(r<0?T.top:T.bottom)+p}let y=c.left+l,x=i??n.viewState.heightOracle.textHeight>>1;for(let T=0;;T+=10){let P=h+(x+T)*r,I=dm(n,{x:y,y:P},!1,r);if(P<c.top||P>c.bottom||(r<0?I<s:I>s)){let z=n.docView.coordsForChar(I),W=!z||P<z.top?-1:1;return A.EditorSelection.cursor(I,W,void 0,l)}}}function ul(n,t,e){for(;;){let i=0;for(let s of n)s.between(t-1,t+1,(r,l,h)=>{if(t>r&&t<l){let c=i||e||(t-r<l-t?-1:1);t=c<0?r:l,i=c}});if(!i)return t}}function _a(n,t,e){let i=ul(n.state.facet(_c).map(s=>s(n)),e.from,t.head>e.from?-1:1);return i==e.from?e:A.EditorSelection.cursor(i,i<e.from?1:-1)}let Bw=class{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,ut.safari&&t.contentDOM.addEventListener("input",()=>null),ut.gecko&&Uw(t.contentDOM.ownerDocument)}handleEvent(t){!Ww(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||this.runHandlers(t.type,t)}runHandlers(t,e){let i=this.handlers[t];if(i){for(let s of i.observers)s(this.view,e);for(let s of i.handlers){if(e.defaultPrevented)break;if(s(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Lw(t),i=this.handlers,s=this.view.contentDOM;for(let r in e)if(r!="scroll"){let l=!e[r].handlers.length,h=i[r];h&&l!=!h.handlers.length&&(s.removeEventListener(r,this.handleEvent),h=null),h||s.addEventListener(r,this.handleEvent,{passive:l})}for(let r in i)r!="scroll"&&!e[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&pm.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),ut.android&&ut.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return ut.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=um.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||Nw.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,Es(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:ut.safari&&!ut.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function Zd(n,t){return(e,i)=>{try{return t.call(n,i,e)}catch(s){$e(e.state,s)}}}function Lw(n){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec;if(s&&s.domEventHandlers)for(let r in s.domEventHandlers){let l=s.domEventHandlers[r];l&&e(r).handlers.push(Zd(i.value,l))}if(s&&s.domEventObservers)for(let r in s.domEventObservers){let l=s.domEventObservers[r];l&&e(r).observers.push(Zd(i.value,l))}}for(let i in Ei)e(i).handlers.push(Ei[i]);for(let i in wi)e(i).observers.push(wi[i]);return t}const um=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Nw="dthko",pm=[16,17,18,20,91,92,224,225],Ho=6;function Vo(n){return Math.max(0,n)*.7+8}function Fw(n,t){return Math.max(Math.abs(n.clientX-t.clientX),Math.abs(n.clientY-t.clientY))}let Iw=class{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=QS(t.contentDOM),this.atoms=t.state.facet(_c).map(l=>l(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(A.EditorState.allowMultipleSelections)&&Hw(t,e),this.dragging=$w(t,e)&&bm(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Fw(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,s=0,r=0,l=this.view.win.innerWidth,h=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:h}=this.scrollParents.y.getBoundingClientRect());let c=hm(this.view);t.clientX-c.left<=s+Ho?e=-Vo(s-t.clientX):t.clientX+c.right>=l-Ho&&(e=Vo(t.clientX-l)),t.clientY-c.top<=r+Ho?i=-Vo(r-t.clientY):t.clientY+c.bottom>=h-Ho&&(i=Vo(t.clientY-h)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],r=null;if(s.empty){let l=ul(this.atoms,s.from,0);l!=s.from&&(r=A.EditorSelection.cursor(l,-1))}else{let l=ul(this.atoms,s.from,-1),h=ul(this.atoms,s.to,1);(l!=s.from||h!=s.to)&&(r=A.EditorSelection.range(s.from==s.anchor?l:h,s.from==s.head?l:h))}r&&(e||(e=t.ranges.slice()),e[i]=r)}return e?A.EditorSelection.create(e,t.mainIndex):t}select(t){let{view:e}=this,i=this.skipAtoms(this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}};function Hw(n,t){let e=n.state.facet(Ug);return e.length?e[0](t):ut.mac?t.metaKey:t.ctrlKey}function Vw(n,t){let e=n.state.facet(Xg);return e.length?e[0](t):ut.mac?!t.altKey:!t.ctrlKey}function $w(n,t){let{main:e}=n.state.selection;if(e.empty)return!1;let i=Hr(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let l=s[r];if(l.left<=t.clientX&&l.right>=t.clientX&&l.top<=t.clientY&&l.bottom>=t.clientY)return!0}return!1}function Ww(n,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=n.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=ee.get(e))&&i.ignoreEvent(t))return!1;return!0}const Ei=Object.create(null),wi=Object.create(null),gm=ut.ie&&ut.ie_version<15||ut.ios&&ut.webkit_version<604;function zw(n){let t=n.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{n.focus(),e.remove(),mm(n,e.value)},50)}function mm(n,t){let{state:e}=n,i,s=1,r=e.toText(t),l=r.lines==e.selection.ranges.length;if(_h!=null&&e.selection.ranges.every(c=>c.empty)&&_h==r.toString()){let c=-1;i=e.changeByRange(g=>{let p=e.doc.lineAt(g.from);if(p.from==c)return{range:g};c=p.from;let y=e.toText((l?r.line(s++).text:t)+e.lineBreak);return{changes:{from:p.from,insert:y},range:A.EditorSelection.cursor(g.from+y.length)}})}else l?i=e.changeByRange(c=>{let g=r.line(s++);return{changes:{from:c.from,to:c.to,insert:g.text},range:A.EditorSelection.cursor(c.from+g.length)}}):i=e.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}wi.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};Ei.keydown=(n,t)=>(n.inputState.setSelectionOrigin("select"),t.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);wi.touchstart=(n,t)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};wi.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Ei.mousedown=(n,t)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of n.state.facet(Jg))if(e=i(n,t),e)break;if(!e&&t.button==0&&(e=jw(n,t)),e){let i=!n.hasFocus;n.inputState.startMouseSelection(new Iw(n,t,e,i)),i&&n.observer.ignore(()=>{Ag(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(t),s.dragging===!1}return!1};function tu(n,t,e,i){if(i==1)return A.EditorSelection.cursor(t,e);if(i==2)return Mw(n.state,t,e);{let s=Ve.find(n.docView,t),r=n.state.doc.lineAt(s?s.posAtEnd:t),l=s?s.posAtStart:r.from,h=s?s.posAtEnd:r.to;return h<n.state.doc.length&&h==r.to&&h++,A.EditorSelection.range(l,h)}}let eu=(n,t,e)=>t>=e.top&&t<=e.bottom&&n>=e.left&&n<=e.right;function qw(n,t,e,i){let s=Ve.find(n.docView,t);if(!s)return 1;let r=t-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let l=s.coordsAt(r,-1);if(l&&eu(e,i,l))return-1;let h=s.coordsAt(r,1);return h&&eu(e,i,h)?1:l&&l.bottom>=i?-1:1}function iu(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:qw(n,e,t.clientX,t.clientY)}}const Kw=ut.ie&&ut.ie_version<=11;let nu=null,su=0,ru=0;function bm(n){if(!Kw)return n.detail;let t=nu,e=ru;return nu=n,ru=Date.now(),su=!t||e>Date.now()-400&&Math.abs(t.clientX-n.clientX)<2&&Math.abs(t.clientY-n.clientY)<2?(su+1)%3:1}function jw(n,t){let e=iu(n,t),i=bm(t),s=n.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),s=s.map(r.changes))},get(r,l,h){let c=iu(n,r),g,p=tu(n,c.pos,c.bias,i);if(e.pos!=c.pos&&!l){let y=tu(n,e.pos,e.bias,i),x=Math.min(y.from,p.from),T=Math.max(y.to,p.to);p=x<p.from?A.EditorSelection.range(x,T):A.EditorSelection.range(T,x)}return l?s.replaceRange(s.main.extend(p.from,p.to)):h&&i==1&&s.ranges.length>1&&(g=_w(s,c.pos))?g:h?s.addRange(p):A.EditorSelection.create([p])}}}function _w(n,t){for(let e=0;e<n.ranges.length;e++){let{from:i,to:s}=n.ranges[e];if(i<=t&&s>=t)return A.EditorSelection.create(n.ranges.slice(0,e).concat(n.ranges.slice(e+1)),n.mainIndex==e?0:n.mainIndex-(n.mainIndex>e?1:0))}return null}Ei.dragstart=(n,t)=>{let{selection:{main:e}}=n.state;if(t.target.draggable){let s=n.docView.nearest(t.target);if(s&&s.isWidget){let r=s.posAtStart,l=r+s.length;(r>=e.to||l<=e.from)&&(e=A.EditorSelection.range(r,l))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",n.state.sliceDoc(e.from,e.to)),t.dataTransfer.effectAllowed="copyMove"),!1};Ei.dragend=n=>(n.inputState.draggedContent=null,!1);function ou(n,t,e,i){if(!e)return;let s=n.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=n.inputState,l=i&&r&&Vw(n,t)?{from:r.from,to:r.to}:null,h={from:s,insert:e},c=n.state.changes(l?[l,h]:h);n.focus(),n.dispatch({changes:c,selection:{anchor:c.mapPos(s,-1),head:c.mapPos(s,1)},userEvent:l?"move.drop":"input.drop"}),n.inputState.draggedContent=null}Ei.drop=(n,t)=>{if(!t.dataTransfer)return!1;if(n.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),s=0,r=()=>{++s==e.length&&ou(n,t,i.filter(l=>l!=null).join(n.state.lineBreak),!1)};for(let l=0;l<e.length;l++){let h=new FileReader;h.onerror=r,h.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(h.result)||(i[l]=h.result),r()},h.readAsText(e[l])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return ou(n,t,i,!0),!0}return!1};Ei.paste=(n,t)=>{if(n.state.readOnly)return!0;n.observer.flush();let e=gm?null:t.clipboardData;return e?(mm(n,e.getData("text/plain")||e.getData("text/uri-list")),!0):(zw(n),!1)};function Gw(n,t){let e=n.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function Yw(n){let t=[],e=[],i=!1;for(let s of n.selection.ranges)s.empty||(t.push(n.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:r}of n.selection.ranges){let l=n.doc.lineAt(r);l.number>s&&(t.push(l.text),e.push({from:l.from,to:Math.min(n.doc.length,l.to+1)})),s=l.number}i=!0}return{text:t.join(n.lineBreak),ranges:e,linewise:i}}let _h=null;Ei.copy=Ei.cut=(n,t)=>{let{text:e,ranges:i,linewise:s}=Yw(n.state);if(!e&&!s)return!1;_h=s?e:null,t.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=gm?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(Gw(n,e),!1)};const ym=A.Annotation.define();function Sm(n,t){let e=[];for(let i of n.facet(tm)){let s=i(n,t);s&&e.push(s)}return e?n.update({effects:e,annotations:ym.of(!0)}):null}function wm(n){setTimeout(()=>{let t=n.hasFocus;if(t!=n.inputState.notifiedFocused){let e=Sm(n.state,t);e?n.dispatch(e):n.update([])}},10)}wi.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),wm(n)};wi.blur=n=>{n.observer.clearSelectionRange(),wm(n)};wi.compositionstart=wi.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};wi.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,ut.chrome&&ut.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};wi.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};Ei.beforeinput=(n,t)=>{var e;let i;if(ut.chrome&&ut.android&&(i=um.find(s=>s.inputType==t.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((e=window.visualViewport)===null||e===void 0?void 0:e.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return ut.ios&&t.inputType=="deleteContentForward"&&n.observer.flushSoon(),ut.safari&&t.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>wi.compositionend(n,t),20),!1};const lu=new Set;function Uw(n){lu.has(n)||(lu.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const au=["pre-wrap","normal","pre-line","break-spaces"];let Xw=class{constructor(t){this.lineWrapping=t,this.doc=A.Text.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return au.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,r,l){let h=au.indexOf(t)>-1,c=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=h;if(this.lineWrapping=h,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=r,c){this.heightSamples={};for(let g=0;g<l.length;g++){let p=l[g];p<0?g++:this.heightSamples[Math.floor(p*10)]=!0}}return c}},Jw=class{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}},En=class xm{constructor(t,e,i,s,r){this.from=t,this.length=e,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?We.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 Vs?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new xm(this.from,this.length+t.length,this.top,this.height+t.height,e)}};var Xt=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(Xt||(Xt={}));const pl=.001;let Oi=class gl{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>pl&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return gl.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let r=this,l=i.doc;for(let h=s.length-1;h>=0;h--){let{fromA:c,toA:g,fromB:p,toB:y}=s[h],x=r.lineAt(c,Xt.ByPosNoHeight,i.setDoc(e),0,0),T=x.to>=g?x:r.lineAt(g,Xt.ByPosNoHeight,i,0,0);for(y+=T.to-g,g=T.to;h>0&&x.from<=s[h-1].toA;)c=s[h-1].fromA,p=s[h-1].fromB,h--,c<x.from&&(x=r.lineAt(c,Xt.ByPosNoHeight,i,0,0));p+=x.from-c,c=x.from;let P=tx.build(i.setDoc(l),t,p,y);r=r.replace(c,g,P)}return r.updateHeight(i,0)}static empty(){return new zi(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,r=0;for(;;)if(e==i)if(s>r*2){let h=t[e-1];h.break?t.splice(--e,1,h.left,null,h.right):t.splice(--e,1,h.left,h.right),i+=1+h.break,s-=h.size}else if(r>s*2){let h=t[i];h.break?t.splice(i,1,h.left,null,h.right):t.splice(i,1,h.left,h.right),i+=2+h.break,r-=h.size}else break;else if(s<r){let h=t[e++];h&&(s+=h.size)}else{let h=t[--i];h&&(r+=h.size)}let l=0;return t[e-1]==null?(l=1,e--):t[e]==null&&(l=1,i++),new Qw(gl.of(t.slice(0,e)),l,gl.of(t.slice(i)))}};Oi.prototype.size=1;let vm=class extends Oi{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,s){return new En(s,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(t,e,i,s,r,l){t<=r+this.length&&e>=r&&l(this.blockAt(0,i,s,r))}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setHeight(t,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},zi=class Gh extends vm{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,s){return new En(s,this.length,i,this.height,this.breaks)}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof Gh||s instanceof Ps&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof Ps?s=new Gh(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):Oi.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setHeight(t,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},Ps=class Ti extends Oi{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-i+1,l,h=0;if(t.lineWrapping){let c=Math.min(this.height,t.lineHeight*r);l=c/r,this.length>r+1&&(h=(this.height-c)/(this.length-r-1))}else l=this.height/r;return{firstLine:i,lastLine:s,perLine:l,perChar:h}}blockAt(t,e,i,s){let{firstLine:r,lastLine:l,perLine:h,perChar:c}=this.heightMetrics(e,s);if(e.lineWrapping){let g=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),p=e.doc.lineAt(g),y=h+p.length*c,x=Math.max(i,t-y/2);return new En(p.from,p.length,x,y,0)}else{let g=Math.max(0,Math.min(l-r,Math.floor((t-i)/h))),{from:p,length:y}=e.doc.line(r+g);return new En(p,y,i+h*g,h,0)}}lineAt(t,e,i,s,r){if(e==Xt.ByHeight)return this.blockAt(t,i,s,r);if(e==Xt.ByPosNoHeight){let{from:T,to:P}=i.doc.lineAt(t);return new En(T,P-T,0,0,0)}let{firstLine:l,perLine:h,perChar:c}=this.heightMetrics(i,r),g=i.doc.lineAt(t),p=h+g.length*c,y=g.number-l,x=s+h*y+c*(g.from-r-y);return new En(g.from,g.length,Math.max(s,Math.min(x,s+this.height-p)),p,0)}forEachLine(t,e,i,s,r,l){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:h,perLine:c,perChar:g}=this.heightMetrics(i,r);for(let p=t,y=s;p<=e;){let x=i.doc.lineAt(p);if(p==t){let P=x.number-h;y+=c*P+g*(t-r-P)}let T=c+g*x.length;l(new En(x.from,x.length,y,T,0)),y+=T,p=x.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let r=i[i.length-1];r instanceof Ti?i[i.length-1]=new Ti(r.length+s):i.push(null,new Ti(s-1))}if(t>0){let r=i[0];r instanceof Ti?i[0]=new Ti(t+r.length):i.unshift(new Ti(t-1),null)}return Oi.of(i)}decomposeLeft(t,e){e.push(new Ti(t-1),null)}decomposeRight(t,e){e.push(null,new Ti(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let l=[],h=Math.max(e,s.from),c=-1;for(s.from>e&&l.push(new Ti(s.from-e-1).updateHeight(t,e));h<=r&&s.more;){let p=t.doc.lineAt(h).length;l.length&&l.push(null);let y=s.heights[s.index++];c==-1?c=y:Math.abs(y-c)>=pl&&(c=-2);let x=new zi(p,y);x.outdated=!1,l.push(x),h+=p+1}h<=r&&l.push(null,new Ti(r-h).updateHeight(t,h));let g=Oi.of(l);return(c<0||Math.abs(g.height-this.height)>=pl||Math.abs(c-this.heightMetrics(t,e).perLine)>=pl)&&(t.heightChanged=!0),g}else(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Qw=class extends Oi{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,s){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,r,s+this.left.length+this.break)}lineAt(t,e,i,s,r){let l=s+this.left.height,h=r+this.left.length+this.break,c=e==Xt.ByHeight?t<l:t<h,g=c?this.left.lineAt(t,e,i,s,r):this.right.lineAt(t,e,i,l,h);if(this.break||(c?g.to<h:g.from>h))return g;let p=e==Xt.ByPosNoHeight?Xt.ByPosNoHeight:Xt.ByPos;return c?g.join(this.right.lineAt(h,p,i,l,h)):this.left.lineAt(h,p,i,s,r).join(g)}forEachLine(t,e,i,s,r,l){let h=s+this.left.height,c=r+this.left.length+this.break;if(this.break)t<c&&this.left.forEachLine(t,e,i,s,r,l),e>=c&&this.right.forEachLine(t,e,i,h,c,l);else{let g=this.lineAt(c,Xt.ByPos,i,s,r);t<g.from&&this.left.forEachLine(t,g.from-1,i,s,r,l),g.to>=t&&g.from<=e&&l(g),e>g.to&&this.right.forEachLine(g.to+1,e,i,h,c,l)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let r=[];t>0&&this.decomposeLeft(t,r);let l=r.length;for(let h of i)r.push(h);if(t>0&&hu(r,l-1),e<this.length){let h=r.length;this.decomposeRight(e,r),hu(r,h)}return Oi.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?Oi.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=t.height+e.height,this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:r,right:l}=this,h=e+r.length+this.break,c=null;return s&&s.from<=e+r.length&&s.more?c=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=h+l.length&&s.more?c=l=l.updateHeight(t,h,i,s):l.updateHeight(t,h,i),c?this.balanced(r,l):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function hu(n,t){let e,i;n[t]==null&&(e=n[t-1])instanceof Ps&&(i=n[t+1])instanceof Ps&&n.splice(t-1,3,new Ps(e.length+1+i.length))}const Zw=5;let tx=class km{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof zi?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new zi(i-this.pos,-1)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let l=e-t;i.block?this.addBlock(new vm(l,s,i)):(l||r||s>=Zw)&&this.addLineDeco(s,r,l)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new zi(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new Ps(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof zi)return t;let e=new zi(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof zi)&&!this.isCovered?this.nodes.push(new zi(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof zi&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let r=new km(i,t);return A.RangeSet.spans(e,i,s,r,0),r.finish(i)}};function ex(n,t,e){let i=new ix;return A.RangeSet.compare(n,t,e,i,0),i.changes}let ix=class{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&Ih(t,e,this.changes,5)}};function nx(n,t){let e=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,e.left),l=Math.min(s.innerWidth,e.right),h=Math.max(0,e.top),c=Math.min(s.innerHeight,e.bottom);for(let g=n.parentNode;g&&g!=i.body;)if(g.nodeType==1){let p=g,y=window.getComputedStyle(p);if((p.scrollHeight>p.clientHeight||p.scrollWidth>p.clientWidth)&&y.overflow!="visible"){let x=p.getBoundingClientRect();r=Math.max(r,x.left),l=Math.min(l,x.right),h=Math.max(h,x.top),c=g==n.parentNode?x.bottom:Math.min(c,x.bottom)}g=y.position=="absolute"||y.position=="fixed"?p.offsetParent:p.parentNode}else if(g.nodeType==11)g=g.host;else break;return{left:r-e.left,right:Math.max(r,l)-e.left,top:h-(e.top+t),bottom:Math.max(h,c)-(e.top+t)}}function sx(n,t){let e=n.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}let Ga=class{constructor(t,e,i){this.from=t,this.to=e,this.size=i}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(t,e){return kt.replace({widget:new rx(this.size*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}},rx=class extends Bi{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}},cu=class{constructor(t){this.state=t,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=fu,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Qt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(jc).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new Xw(e),this.stateDeco=t.facet(Vr).filter(i=>typeof i!="function"),this.heightMap=Oi.empty().applyChanges(this.stateDeco,A.Text.empty,this.heightOracle.setDoc(t.doc),[new Fn(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=kt.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some(({from:r,to:l})=>s>=r&&s<=l)){let{from:r,to:l}=this.lineBlockAt(s);t.push(new $o(r,l))}}return this.viewports=t.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?fu:new ax(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(Mr(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Vr).filter(p=>typeof p!="function");let s=t.changedRanges,r=Fn.extendWithRanges(s,ex(i,this.stateDeco,t?t.changes:A.ChangeSet.empty(this.state.doc.length))),l=this.heightMap.height,h=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=l&&(t.flags|=2),h?(this.scrollAnchorPos=t.changes.mapPos(h.from,-1),this.scrollAnchorHeight=h.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let c=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<c.from||e.range.head>c.to)||!this.viewportIsAppropriate(c))&&(c=this.getViewport(0,e));let g=c.from!=this.viewport.from||c.to!=this.viewport.to;this.viewport=c,t.flags|=this.updateForViewport(),(g||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(im)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?Qt.RTL:Qt.LTR;let l=this.heightOracle.mustRefreshForWrapping(r),h=e.getBoundingClientRect(),c=l||this.mustMeasureContent||this.contentDOMHeight!=h.height;this.contentDOMHeight=h.height,this.mustMeasureContent=!1;let g=0,p=0;if(h.width&&h.height){let{scaleX:Q,scaleY:st}=Mg(e,h);(Q>.005&&Math.abs(this.scaleX-Q)>.005||st>.005&&Math.abs(this.scaleY-st)>.005)&&(this.scaleX=Q,this.scaleY=st,g|=8,l=c=!0)}let y=(parseInt(i.paddingTop)||0)*this.scaleY,x=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=y||this.paddingBottom!=x)&&(this.paddingTop=y,this.paddingBottom=x,g|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(c=!0),this.editorWidth=t.scrollDOM.clientWidth,g|=8);let T=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=T&&(this.scrollAnchorHeight=-1,this.scrollTop=T),this.scrolledToBottom=Dg(t.scrollDOM);let P=(this.printing?sx:nx)(e,this.paddingTop),I=P.top-this.pixelViewport.top,z=P.bottom-this.pixelViewport.bottom;this.pixelViewport=P;let W=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(W!=this.inView&&(this.inView=W,W&&(c=!0)),!this.inView&&!this.scrollTarget)return 0;let U=h.width;if((this.contentDOMWidth!=U||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=h.width,this.editorHeight=t.scrollDOM.clientHeight,g|=8),c){let Q=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(Q)&&(l=!0),l||s.lineWrapping&&Math.abs(U-this.contentDOMWidth)>s.charWidth){let{lineHeight:st,charWidth:at,textHeight:wt}=t.docView.measureTextSize();l=st>0&&s.refresh(r,st,at,wt,U/at,Q),l&&(t.docView.minWidth=0,g|=8)}I>0&&z>0?p=Math.max(I,z):I<0&&z<0&&(p=Math.min(I,z)),s.heightChanged=!1;for(let st of this.viewports){let at=st.from==this.viewport.from?Q:t.docView.measureVisibleLineHeights(st);this.heightMap=(l?Oi.empty().applyChanges(this.stateDeco,A.Text.empty,this.heightOracle,[new Fn(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,l,new Jw(st.from,at))}s.heightChanged&&(g|=2)}let ot=!this.viewportIsAppropriate(this.viewport,p)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return ot&&(g&2&&(g|=this.updateScaler()),this.viewport=this.getViewport(p,this.scrollTarget),g|=this.updateForViewport()),(g&2||ot)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(l?[]:this.lineGaps,t)),g|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),g}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:l,visibleBottom:h}=this,c=new $o(s.lineAt(l-i*1e3,Xt.ByHeight,r,0,0).from,s.lineAt(h+(1-i)*1e3,Xt.ByHeight,r,0,0).to);if(e){let{head:g}=e.range;if(g<c.from||g>c.to){let p=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),y=s.lineAt(g,Xt.ByPos,r,0,0),x;e.y=="center"?x=(y.top+y.bottom)/2-p/2:e.y=="start"||e.y=="nearest"&&g<c.from?x=y.top:x=y.bottom-p,c=new $o(s.lineAt(x-1e3/2,Xt.ByHeight,r,0,0).from,s.lineAt(x+p+1e3/2,Xt.ByHeight,r,0,0).to)}}return c}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new $o(this.heightMap.lineAt(i,Xt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,Xt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,Xt.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,Xt.ByPos,this.heightOracle,0,0),{visibleTop:l,visibleBottom:h}=this;return(t==0||s<=l-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=h+Math.max(10,Math.min(i,250)))&&s>l-2*1e3&&r<h+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new Ga(e.mapPos(s.from),e.mapPos(s.to),s.size));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,l=s<<1;if(this.defaultTextDirection!=Qt.LTR&&!i)return[];let h=[],c=(p,y,x,T)=>{if(y-p<r)return;let P=this.state.selection.main,I=[P.from];P.empty||I.push(P.to);for(let W of I)if(W>p&&W<y){c(p,W-10,x,T),c(W+10,y,x,T);return}let z=lx(t,W=>W.from>=x.from&&W.to<=x.to&&Math.abs(W.from-p)<r&&Math.abs(W.to-y)<r&&!I.some(U=>W.from<U&&W.to>U));if(!z){if(y<x.to&&e&&i&&e.visibleRanges.some(W=>W.from<=y&&W.to>=y)){let W=e.moveToLineBoundary(A.EditorSelection.cursor(y),!1,!0).head;W>p&&(y=W)}z=new Ga(p,y,this.gapSize(x,p,y,T))}h.push(z)},g=p=>{if(p.length<l||p.type!=We.Text)return;let y=ox(p.from,p.to,this.stateDeco);if(y.total<l)return;let x=this.scrollTarget?this.scrollTarget.range.head:null,T,P;if(i){let I=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,z,W;if(x!=null){let U=zo(y,x),ot=((this.visibleBottom-this.visibleTop)/2+I)/p.height;z=U-ot,W=U+ot}else z=(this.visibleTop-p.top-I)/p.height,W=(this.visibleBottom-p.top+I)/p.height;T=Wo(y,z),P=Wo(y,W)}else{let I=y.total*this.heightOracle.charWidth,z=s*this.heightOracle.charWidth,W,U;if(x!=null){let ot=zo(y,x),Q=((this.pixelViewport.right-this.pixelViewport.left)/2+z)/I;W=ot-Q,U=ot+Q}else W=(this.pixelViewport.left-z)/I,U=(this.pixelViewport.right+z)/I;T=Wo(y,W),P=Wo(y,U)}T>p.from&&c(p.from,T,p,y),P<p.to&&c(P,p.to,p,y)};for(let p of this.viewportLines)Array.isArray(p.type)?p.type.forEach(g):g(p);return h}gapSize(t,e,i,s){let r=zo(s,i)-zo(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){Ga.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=kt.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];A.RangeSet.spans(t,this.viewport.from,this.viewport.to,{span(s,r){e.push({from:s,to:r})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some((s,r)=>s.from!=e[r].from||s.to!=e[r].to);return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Mr(this.heightMap.lineAt(t,Xt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Mr(this.heightMap.lineAt(this.scaler.fromDOM(t),Xt.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Mr(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},$o=class{constructor(t,e){this.from=t,this.to=e}};function ox(n,t,e){let i=[],s=n,r=0;return A.RangeSet.spans(e,n,t,{span(){},point(l,h){l>s&&(i.push({from:s,to:l}),r+=l-s),s=h}},20),s<t&&(i.push({from:s,to:t}),r+=t-s),{total:r,ranges:i}}function Wo({total:n,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(n*e);for(let s=0;;s++){let{from:r,to:l}=t[s],h=l-r;if(i<=h)return r+i;i-=h}}function zo(n,t){let e=0;for(let{from:i,to:s}of n.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/n.total}function lx(n,t){for(let e of n)if(t(e))return e}const fu={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};let ax=class Cm{constructor(t,e,i){let s=0,r=0,l=0;this.viewports=i.map(({from:h,to:c})=>{let g=e.lineAt(h,Xt.ByPos,t,0,0).top,p=e.lineAt(c,Xt.ByPos,t,0,0).bottom;return s+=p-g,{from:h,to:c,top:g,bottom:p,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let h of this.viewports)h.domTop=l+(h.top-r)*this.scale,l=h.domBottom=h.domTop+(h.bottom-h.top),r=h.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return s+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,s=r.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-s)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,s=r.domBottom}}eq(t){return t instanceof Cm?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}};function Mr(n,t){if(t.scale==1)return n;let e=t.toDOM(n.top),i=t.toDOM(n.bottom);return new En(n.from,n.length,e,i-e,Array.isArray(n._content)?n._content.map(s=>Mr(s,t)):n._content)}const qo=A.Facet.define({combine:n=>n.join(" ")}),Yh=A.Facet.define({combine:n=>n.indexOf(!0)>-1}),Uh=Le.newName(),Mm=Le.newName(),Am=Le.newName(),Tm={"&light":"."+Mm,"&dark":"."+Am};function Xh(n,t,e){return new Le(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):n+" "+i}})}const hx=Xh("."+Uh,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,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:"#444"},".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",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".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"}},Tm),Ar="￿";let cx=class{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(A.EditorState.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Ar}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let l=s.nextSibling;if(l==e)break;let h=ee.get(s),c=ee.get(l);(h&&c?h.breakAfter:(h?h.breakAfter:Tl(s))||Tl(l)&&(s.nodeName!="BR"||s.cmIgnore)&&this.text.length>r)&&this.lineBreak(),s=l}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,l=1,h;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),l=this.lineSeparator.length):(h=s.exec(e))&&(r=h.index,l=h[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),l>1)for(let c of this.points)c.node==t&&c.pos>this.text.length&&(c.pos-=l-1);i=r+l}}readNode(t){if(t.cmIgnore)return;let e=ee.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(fx(t,i.node,i.offset)?e:0))}};function fx(n,t,e){for(;;){if(!t||e<dn(t))return!1;if(t==n)return!0;e=es(t)+1,t=t.parentNode}}let du=class{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}},dx=class{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:r,impreciseAnchor:l}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let h=r||l?[]:gx(t),c=new cx(h,t.state);c.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=c.text,this.newSel=mx(h,this.bounds.from)}else{let h=t.observer.selectionRange,c=r&&r.node==h.focusNode&&r.offset==h.focusOffset||!Mh(t.contentDOM,h.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(h.focusNode,h.focusOffset),g=l&&l.node==h.anchorNode&&l.offset==h.anchorOffset||!Mh(t.contentDOM,h.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(h.anchorNode,h.anchorOffset),p=t.viewport;if((ut.ios||ut.chrome)&&t.state.selection.main.empty&&c!=g&&(p.from>0||p.to<t.state.doc.length)){let y=Math.min(c,g),x=Math.max(c,g),T=p.from-y,P=p.to-x;(T==0||T==1||y==0)&&(P==0||P==-1||x==t.state.doc.length)&&(c=0,g=t.state.doc.length)}this.newSel=A.EditorSelection.single(g,c)}}};function Dm(n,t){let e,{newSel:i}=t,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(t.bounds){let{from:l,to:h}=t.bounds,c=s.from,g=null;(r===8||ut.android&&t.text.length<h-l)&&(c=s.to,g="end");let p=px(n.state.doc.sliceString(l,h,Ar),t.text,c-l,g);p&&(ut.chrome&&r==13&&p.toB==p.from+2&&t.text.slice(p.from,p.toB)==Ar+Ar&&p.toB--,e={from:l+p.from,to:l+p.toA,insert:A.Text.of(t.text.slice(p.from,p.toB).split(Ar))})}else i&&(!n.hasFocus&&n.state.facet(On)||i.main.eq(s))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!s.empty&&i&&i.main.empty?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:e&&e.from>=s.from&&e.to<=s.to&&(e.from!=s.from||e.to!=s.to)&&s.to-s.from-(e.to-e.from)<=4?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,e.from).append(e.insert).append(n.state.doc.slice(e.to,s.to))}:(ut.mac||ut.android)&&e&&e.from==e.to&&e.from==s.head-1&&/^\. ?$/.test(e.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=A.EditorSelection.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:A.Text.of([" "])}):ut.chrome&&e&&e.from==e.to&&e.from==s.head&&e.insert.toString()==`
7
- `&&n.lineWrapping&&(i&&(i=A.EditorSelection.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:A.Text.of([" "])}),e)return Om(n,e,i,r);if(i&&!i.main.eq(s)){let l=!1,h="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(l=!0),h=n.inputState.lastSelectionOrigin),n.dispatch({selection:i,scrollIntoView:l,userEvent:h}),!0}else return!1}function Om(n,t,e,i=-1){if(ut.ios&&n.inputState.flushIOSKey(t))return!0;let s=n.state.selection.main;if(ut.android&&(t.to==s.to&&(t.from==s.from||t.from==s.from-1&&n.state.sliceDoc(t.from,s.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&Es(n.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>s.head)&&Es(n.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&Es(n.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let l,h=()=>l||(l=ux(n,t,e));return n.state.facet(Zg).some(c=>c(n,t.from,t.to,r,h))||n.dispatch(h()),!0}function ux(n,t,e){let i,s=n.state,r=s.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&n.inputState.composing<0){let h=r.from<t.from?s.sliceDoc(r.from,t.from):"",c=r.to>t.to?s.sliceDoc(t.to,r.to):"";i=s.replaceSelection(n.state.toText(h+t.insert.sliceString(0,void 0,n.state.lineBreak)+c))}else{let h=s.changes(t),c=e&&e.main.to<=h.newLength?e.main:void 0;if(s.selection.ranges.length>1&&n.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let g=n.state.sliceDoc(t.from,t.to),p,y=e&&fm(n,e.main.head);if(y){let P=t.insert.length-(t.to-t.from);p={from:y.from,to:y.to-P}}else p=n.state.doc.lineAt(r.head);let x=r.to-t.to,T=r.to-r.from;i=s.changeByRange(P=>{if(P.from==r.from&&P.to==r.to)return{changes:h,range:c||P.map(h)};let I=P.to-x,z=I-g.length;if(P.to-P.from!=T||n.state.sliceDoc(z,I)!=g||P.to>=p.from&&P.from<=p.to)return{range:P};let W=s.changes({from:z,to:I,insert:t.insert}),U=P.to-r.to;return{changes:W,range:c?A.EditorSelection.range(Math.max(0,c.anchor+U),Math.max(0,c.head+U)):P.map(W)}})}else i={changes:h,selection:c&&s.selection.replaceRange(c)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function px(n,t,e,i){let s=Math.min(n.length,t.length),r=0;for(;r<s&&n.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==s&&n.length==t.length)return null;let l=n.length,h=t.length;for(;l>0&&h>0&&n.charCodeAt(l-1)==t.charCodeAt(h-1);)l--,h--;if(i=="end"){let c=Math.max(0,r-Math.min(l,h));e-=l+c-r}if(l<r&&n.length<t.length){let c=e<=r&&e>=l?r-e:0;r-=c,h=r+(h-l),l=r}else if(h<r){let c=e<=r&&e>=h?r-e:0;r-=c,l=r+(l-h),h=r}return{from:r,toA:l,toB:h}}function gx(n){let t=[];if(n.root.activeElement!=n.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return e&&(t.push(new du(e,i)),(s!=e||r!=i)&&t.push(new du(s,r))),t}function mx(n,t){if(n.length==0)return null;let e=n[0].pos,i=n.length==2?n[1].pos:e;return e>-1&&i>-1?A.EditorSelection.single(e+t,i+t):null}const bx={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Ya=ut.ie&&ut.ie_version<=11;let yx=class{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new ZS,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(ut.ie&&ut.ie_version<=11||ut.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&t.constructor.EDIT_CONTEXT!==!1&&!(ut.chrome&&ut.chrome_version<126)&&(this.editContext=new wx(t),t.state.facet(On)&&(t.contentDOM.editContext=this.editContext.editContext)),Ya&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.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 e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.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(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){t.type=="change"&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(On)?i.root.activeElement!=this.dom:!cl(i.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(ut.ie&&ut.ie_version<=11||ut.android&&ut.chrome)&&!i.state.selection.main.empty&&s.focusNode&&Br(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=Hr(t.root);if(!e)return!1;let i=ut.safari&&t.root.nodeType==11&&US(this.dom.ownerDocument)==this.dom&&Sx(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=cl(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&ew(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,bx),Ya&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Ya&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;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&&Es(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.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 t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let r of t){let l=this.readMutation(r);l&&(l.typeOver&&(s=!0),e==-1?{from:e,to:i}=l:(e=Math.min(l.from,e),i=Math.max(l.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&cl(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new dx(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=Dm(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.flags|=4),t.type=="childList"){let i=uu(e,t.previousSibling||t.target.previousSibling,-1),s=uu(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener("change",this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener("change",this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(On)!=t.state.facet(On)&&(t.view.contentDOM.editContext=t.state.facet(On)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.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 uu(n,t,e){for(;t;){let i=ee.get(t);if(i&&i.parent==n)return i;let s=t.parentNode;t=s!=n.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function pu(n,t){let e=t.startContainer,i=t.startOffset,s=t.endContainer,r=t.endOffset,l=n.docView.domAtPos(n.state.selection.main.anchor);return Br(l.node,l.offset,s,r)&&([e,i,s,r]=[s,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}}function Sx(n,t){if(t.getComposedRanges){let s=t.getComposedRanges(n.root)[0];if(s)return pu(n,s)}let e=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),e=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),e?pu(n,e):null}let wx=class{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let{anchor:s}=t.state.selection.main,r={from:this.toEditorPos(i.updateRangeStart),to:this.toEditorPos(i.updateRangeEnd),insert:A.Text.of(i.text.split(`
8
- `))};r.from==this.from&&s<this.from?r.from=s:r.to==this.to&&s>this.to&&(r.to=s),!(r.from==r.to&&!r.insert.length)&&(this.pendingContextChange=r,t.state.readOnly||Om(t,r,A.EditorSelection.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd))),this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)))},this.handlers.characterboundsupdate=i=>{let s=[],r=null;for(let l=this.toEditorPos(i.rangeStart),h=this.toEditorPos(i.rangeEnd);l<h;l++){let c=t.coordsForChar(l);r=c&&new DOMRect(c.left,c.top,c.right-c.left,c.bottom-c.top)||r||new DOMRect,s.push(r)}e.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let r of i.getTextFormats()){let l=r.underlineStyle,h=r.underlineThickness;if(l!="None"&&h!="None"){let c=`text-decoration: underline ${l=="Dashed"?"dashed ":l=="Squiggle"?"wavy ":""}${h=="Thin"?1:2}px`;s.push(kt.mark({attributes:{style:c}}).range(this.toEditorPos(r.rangeStart),this.toEditorPos(r.rangeEnd)))}}t.dispatch({effects:sm.of(kt.set(s))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{t.inputState.composing=-1,t.inputState.compositionFirstChange=null};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=Hr(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((r,l,h,c,g)=>{if(i)return;let p=g.length-(l-r);if(s&&l>=s.to)if(s.from==r&&s.to==l&&s.insert.eq(g)){s=this.pendingContextChange=null,e+=p,this.to+=p;return}else s=null,this.revertPending(t.state);if(r+=e,l+=e,l<=this.from)this.from+=p,this.to+=p;else if(r<this.to){if(r<this.from||l>this.to||this.to-this.from+g.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(l),g.toString()),this.to+=p}e+=p}),s&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange;!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.resetRange(t.state),this.editContext.updateText(0,this.editContext.text.length,t.state.doc.sliceString(this.from,this.to)),this.setSelection(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t){return t+this.from}toContextPos(t){return t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}},mt=class Jh{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:e}=t;this.dispatchTransactions=t.dispatchTransactions||e&&(i=>i.forEach(s=>e(s,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=t.root||tw(t.parent)||document,this.viewState=new cu(t.state||A.EditorState.create(t)),t.scrollTo&&t.scrollTo.is(Io)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(kr).map(i=>new Ka(i));for(let i of this.plugins)i.update(this);this.observer=new yx(this),this.inputState=new Bw(this),this.inputState.ensureHandlers(this.plugins),this.docView=new _d(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...t){let e=t.length==1&&t[0]instanceof A.Transaction?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,r=this.state;for(let x of t){if(x.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=x.state}if(this.destroyed){this.viewState.state=r;return}let l=this.hasFocus,h=0,c=null;t.some(x=>x.annotation(ym))?(this.inputState.notifiedFocused=l,h=1):l!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=l,c=Sm(r,l),c||(h=1));let g=this.observer.delayedAndroidKey,p=null;if(g?(this.observer.clearDelayedAndroidKey(),p=this.observer.readChange(),(p&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(p=null)):this.observer.clear(),r.facet(A.EditorState.phrases)!=this.state.facet(A.EditorState.phrases))return this.setState(r);s=jd.create(this,r,t),s.flags|=h;let y=this.viewState.scrollTarget;try{this.updateState=2;for(let x of t){if(y&&(y=y.map(x.changes)),x.scrollIntoView){let{main:T}=x.state.selection;y=new qa(T.empty?T:A.EditorSelection.cursor(T.head,T.head>T.anchor?-1:1))}for(let T of x.effects)T.is(Io)&&(y=T.value.clip(this.state))}this.viewState.update(s,y),this.bidiCache=mu.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(Cr)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(x=>x.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(qo)!=s.state.facet(qo)&&(this.viewState.mustMeasureContent=!0),(e||i||y||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!s.empty)for(let x of this.state.facet(Wh))try{x(s)}catch(T){$e(this.state,T,"update listener")}(c||p)&&Promise.resolve().then(()=>{c&&this.state==c.startState&&this.dispatch(c),p&&!Dm(this,p)&&g.force&&Es(this.contentDOM,g.key,g.keyCode)})}setState(t){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=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new cu(t),this.plugins=t.facet(kr).map(i=>new Ka(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new _d(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(kr),i=t.state.facet(kr);if(e!=i){let s=[];for(let r of i){let l=e.indexOf(r);if(l<0)s.push(new Ka(r));else{let h=this.plugins[l];h.mustUpdate=t,s.push(h)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){$e(this.state,i,"doc view update listener")}}}measure(t=!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,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:l}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(l=-1),this.viewState.scrollAnchorHeight=-1;try{for(let h=0;;h++){if(l<0)if(Dg(i))r=-1,l=this.viewState.heightMap.height;else{let T=this.viewState.scrollAnchorAt(s);r=T.from,l=T.top}this.updateState=1;let c=this.viewState.measure(this);if(!c&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(h>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let g=[];c&4||([this.measureRequests,g]=[g,this.measureRequests]);let p=g.map(T=>{try{return T.read(this)}catch(P){return $e(this.state,P),gu}}),y=jd.create(this,this.state,[]),x=!1;y.flags|=c,e?e.flags|=c:e=y,this.updateState=2,y.empty||(this.updatePlugins(y),this.inputState.update(y),this.updateAttrs(),x=this.docView.update(y),x&&this.docViewUpdate());for(let T=0;T<g.length;T++)if(p[T]!=gu)try{let P=g[T];P.write&&P.write(p[T],this)}catch(P){$e(this.state,P)}if(x&&this.docView.updateSelection(!0),!y.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,l=-1;continue}else{let P=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-l;if(P>1||P<-1){s=s+P,i.scrollTop=s/this.scaleY,l=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let h of this.state.facet(Wh))h(e)}get themeClasses(){return Uh+" "+(this.state.facet(Yh)?Am:Mm)+" "+this.state.facet(qo)}updateAttrs(){let t=bu(this,rm,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(On)?"true":"false",class:"cm-content",style:`${ut.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),bu(this,jc,e);let i=this.observer.ignore(()=>{let s=Fh(this.contentDOM,this.contentAttrs,e),r=Fh(this.dom,this.editorAttrs,t);return s||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(Jh.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Cr);let t=this.state.facet(Jh.cspNonce);Le.mount(this.root,this.styleModules.concat(hx).reverse(),t?{nonce:t}: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(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.spec==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return _a(this,t,Qd(this,t,e,i))}moveByGroup(t,e){return _a(this,t,Qd(this,t,e,i=>Pw(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return A.EditorSelection.cursor(r.side(e,s)+t.from,r.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return Ew(this,t,e,i)}moveVertically(t,e,i){return _a(this,t,Rw(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),dm(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),r=this.bidiSpans(s),l=r[Bn.find(r,t-s.from,-1,e)];return Ql(i,l.dir==Qt.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(em)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>xx)return Gg(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||_g(r.isolates,i=Kd(this,t))))return r.order;i||(i=Kd(this,t));let s=pw(t.text,e,i);return this.bidiCache.push(new mu(t.from,t.to,e,i,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||ut.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ag(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return Io.of(new qa(typeof t=="number"?A.EditorSelection.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Io.of(new qa(A.EditorSelection.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return Te.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return Te.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=Le.newName(),s=[qo.of(i),Cr.of(Xh(`.${i}`,t))];return e&&e.dark&&s.push(Yh.of(!0)),s}static baseTheme(t){return A.Prec.lowest(Cr.of(Xh("."+Uh,t,Tm)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&ee.get(i)||ee.get(t);return((e=s==null?void 0:s.rootView)===null||e===void 0?void 0:e.view)||null}};mt.styleModule=Cr;mt.inputHandler=Zg;mt.scrollHandler=nm;mt.focusChangeEffect=tm;mt.perLineTextDirection=em;mt.exceptionSink=Qg;mt.updateListener=Wh;mt.editable=On;mt.mouseSelectionStyle=Jg;mt.dragMovesSelection=Xg;mt.clickAddsSelectionRange=Ug;mt.decorations=Vr;mt.outerDecorations=om;mt.atomicRanges=_c;mt.bidiIsolatedRanges=lm;mt.scrollMargins=am;mt.darkTheme=Yh;mt.cspNonce=A.Facet.define({combine:n=>n.length?n[0]:""});mt.contentAttributes=jc;mt.editorAttributes=rm;mt.lineWrapping=mt.contentAttributes.of({class:"cm-lineWrapping"});mt.announce=A.StateEffect.define();const xx=4096,gu={};let mu=class Em{constructor(t,e,i,s,r,l){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=r,this.order=l}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:Qt.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let l=t[r];l.dir==s&&!e.touchesRange(l.from,l.to)&&i.push(new Em(e.mapPos(l.from,1),e.mapPos(l.to,-1),l.dir,l.isolates,!1,l.order))}return i}};function bu(n,t,e){for(let i=n.state.facet(t),s=i.length-1;s>=0;s--){let r=i[s],l=typeof r=="function"?r(n):r;l&&Nh(l,e)}return e}const vx=ut.mac?"mac":ut.windows?"win":ut.linux?"linux":"key";function kx(n,t){const e=n.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let s,r,l,h;for(let c=0;c<e.length-1;++c){const g=e[c];if(/^(cmd|meta|m)$/i.test(g))h=!0;else if(/^a(lt)?$/i.test(g))s=!0;else if(/^(c|ctrl|control)$/i.test(g))r=!0;else if(/^s(hift)?$/i.test(g))l=!0;else if(/^mod$/i.test(g))t=="mac"?h=!0:r=!0;else throw new Error("Unrecognized modifier name: "+g)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),h&&(i="Meta-"+i),l&&(i="Shift-"+i),i}function Ko(n,t,e){return t.altKey&&(n="Alt-"+n),t.ctrlKey&&(n="Ctrl-"+n),t.metaKey&&(n="Meta-"+n),e!==!1&&t.shiftKey&&(n="Shift-"+n),n}const Cx=A.Prec.default(mt.domEventHandlers({keydown(n,t){return Dx(Mx(t.state),n,t,"editor")}})),Xs=A.Facet.define({enables:Cx}),yu=new WeakMap;function Mx(n){let t=n.facet(Xs),e=yu.get(t);return e||yu.set(t,e=Tx(t.reduce((i,s)=>i.concat(s),[]))),e}let Pn=null;const Ax=4e3;function Tx(n,t=vx){let e=Object.create(null),i=Object.create(null),s=(l,h)=>{let c=i[l];if(c==null)i[l]=h;else if(c!=h)throw new Error("Key binding "+l+" is used both as a regular binding and as a multi-stroke prefix")},r=(l,h,c,g,p)=>{var y,x;let T=e[l]||(e[l]=Object.create(null)),P=h.split(/ (?!$)/).map(W=>kx(W,t));for(let W=1;W<P.length;W++){let U=P.slice(0,W).join(" ");s(U,!0),T[U]||(T[U]={preventDefault:!0,stopPropagation:!1,run:[ot=>{let Q=Pn={view:ot,prefix:U,scope:l};return setTimeout(()=>{Pn==Q&&(Pn=null)},Ax),!0}]})}let I=P.join(" ");s(I,!1);let z=T[I]||(T[I]={preventDefault:!1,stopPropagation:!1,run:((x=(y=T._any)===null||y===void 0?void 0:y.run)===null||x===void 0?void 0:x.slice())||[]});c&&z.run.push(c),g&&(z.preventDefault=!0),p&&(z.stopPropagation=!0)};for(let l of n){let h=l.scope?l.scope.split(" "):["editor"];if(l.any)for(let g of h){let p=e[g]||(e[g]=Object.create(null));p._any||(p._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:y}=l;for(let x in p)p[x].run.push(T=>y(T,Qh))}let c=l[t]||l.key;if(c)for(let g of h)r(g,c,l.run,l.preventDefault,l.stopPropagation),l.shift&&r(g,"Shift-"+c,l.shift,l.preventDefault,l.stopPropagation)}return e}let Qh=null;function Dx(n,t,e,i){Qh=t;let s=pg(t),r=A.codePointAt(s,0),l=A.codePointSize(r)==s.length&&s!=" ",h="",c=!1,g=!1,p=!1;Pn&&Pn.view==e&&Pn.scope==i&&(h=Pn.prefix+" ",pm.indexOf(t.keyCode)<0&&(g=!0,Pn=null));let y=new Set,x=z=>{if(z){for(let W of z.run)if(!y.has(W)&&(y.add(W),W(e)))return z.stopPropagation&&(p=!0),!0;z.preventDefault&&(z.stopPropagation&&(p=!0),g=!0)}return!1},T=n[i],P,I;return T&&(x(T[h+Ko(s,t,!l)])?c=!0:l&&(t.altKey||t.metaKey||t.ctrlKey)&&!(ut.windows&&t.ctrlKey&&t.altKey)&&(P=gg[t.keyCode])&&P!=s?(x(T[h+Ko(P,t,!0)])||t.shiftKey&&(I=mg[t.keyCode])!=s&&I!=P&&x(T[h+Ko(I,t,!1)]))&&(c=!0):l&&t.shiftKey&&x(T[h+Ko(s,t,!0)])&&(c=!0),!c&&x(T._any)&&(c=!0)),g&&(c=!0),c&&p&&t.stopPropagation(),Qh=null,c}class to{constructor(t,e,i,s,r){this.className=t,this.left=e,this.top=i,this.width=s,this.height=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=Pm(t);return[new to(e,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return Ox(t,e,i)}}function Pm(n){let t=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==Qt.LTR?t.left:t.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:t.top-n.scrollDOM.scrollTop*n.scaleY}}function Su(n,t,e,i){let s=n.coordsAtPos(t,e*2);if(!s)return i;let r=n.dom.getBoundingClientRect(),l=(s.top+s.bottom)/2,h=n.posAtCoords({x:r.left+1,y:l}),c=n.posAtCoords({x:r.right-1,y:l});return h==null||c==null?i:{from:Math.max(i.from,Math.min(h,c)),to:Math.min(i.to,Math.max(h,c))}}function Ox(n,t,e){if(e.to<=n.viewport.from||e.from>=n.viewport.to)return[];let i=Math.max(e.from,n.viewport.from),s=Math.min(e.to,n.viewport.to),r=n.textDirection==Qt.LTR,l=n.contentDOM,h=l.getBoundingClientRect(),c=Pm(n),g=l.querySelector(".cm-line"),p=g&&window.getComputedStyle(g),y=h.left+(p?parseInt(p.paddingLeft)+Math.min(0,parseInt(p.textIndent)):0),x=h.right-(p?parseInt(p.paddingRight):0),T=jh(n,i),P=jh(n,s),I=T.type==We.Text?T:null,z=P.type==We.Text?P:null;if(I&&(n.lineWrapping||T.widgetLineBreaks)&&(I=Su(n,i,1,I)),z&&(n.lineWrapping||P.widgetLineBreaks)&&(z=Su(n,s,-1,z)),I&&z&&I.from==z.from&&I.to==z.to)return U(ot(e.from,e.to,I));{let st=I?ot(e.from,null,I):Q(T,!1),at=z?ot(null,e.to,z):Q(P,!0),wt=[];return(I||T).to<(z||P).from-(I&&z?1:0)||T.widgetLineBreaks>1&&st.bottom+n.defaultLineHeight/2<at.top?wt.push(W(y,st.bottom,x,at.top)):st.bottom<at.top&&n.elementAtHeight((st.bottom+at.top)/2).type==We.Text&&(st.bottom=at.top=(st.bottom+at.top)/2),U(st).concat(wt).concat(U(at))}function W(st,at,wt,Pt){return new to(t,st-c.left,at-c.top-.01,wt-st,Pt-at+.01)}function U({top:st,bottom:at,horizontal:wt}){let Pt=[];for(let Tt=0;Tt<wt.length;Tt+=2)Pt.push(W(wt[Tt],st,wt[Tt+1],at));return Pt}function ot(st,at,wt){let Pt=1e9,Tt=-1e9,le=[];function ae(ne,Rt,Bt,vt,Zt){let se=n.coordsAtPos(ne,ne==wt.to?-2:2),ue=n.coordsAtPos(Bt,Bt==wt.from?2:-2);!se||!ue||(Pt=Math.min(se.top,ue.top,Pt),Tt=Math.max(se.bottom,ue.bottom,Tt),Zt==Qt.LTR?le.push(r&&Rt?y:se.left,r&&vt?x:ue.right):le.push(!r&&vt?y:ue.left,!r&&Rt?x:se.right))}let zt=st??wt.from,Ot=at??wt.to;for(let ne of n.visibleRanges)if(ne.to>zt&&ne.from<Ot)for(let Rt=Math.max(ne.from,zt),Bt=Math.min(ne.to,Ot);;){let vt=n.state.doc.lineAt(Rt);for(let Zt of n.bidiSpans(vt)){let se=Zt.from+vt.from,ue=Zt.to+vt.from;if(se>=Bt)break;ue>Rt&&ae(Math.max(se,Rt),st==null&&se<=zt,Math.min(ue,Bt),at==null&&ue>=Ot,Zt.dir)}if(Rt=vt.to+1,Rt>=Bt)break}return le.length==0&&ae(zt,st==null,Ot,at==null,n.textDirection),{top:Pt,bottom:Tt,horizontal:le}}function Q(st,at){let wt=h.top+(at?st.top:st.bottom);return{top:wt,bottom:wt,horizontal:[]}}}function Ex(n,t){return n.constructor==t.constructor&&n.eq(t)}class Px{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(ml)!=t.state.facet(ml)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(ml);for(;e<i.length&&i[e]!=this.layer;)e++;this.dom.style.zIndex=String((this.layer.above?150:-1)-e)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:e}=this.view;(t!=this.scaleX||e!=this.scaleY)&&(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some((e,i)=>!Ex(e,this.drawn[i]))){let e=this.dom.firstChild,i=0;for(let s of t)s.update&&e&&s.constructor&&this.drawn[i].constructor&&s.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(s.draw(),e);for(;e;){let s=e.nextSibling;e.remove(),e=s}this.drawn=t}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const ml=A.Facet.define();function Rm(n){return[Te.define(t=>new Px(t,n)),ml.of(n)]}const Bm=!ut.ios,$r=A.Facet.define({combine(n){return A.combineConfig(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function Rx(n={}){return[$r.of(n),Bx,Lx,Nx,im.of(!0)]}function Lm(n){return n.startState.facet($r)!=n.state.facet($r)}const Bx=Rm({above:!0,markers(n){let{state:t}=n,e=t.facet($r),i=[];for(let s of t.selection.ranges){let r=s==t.selection.main;if(s.empty?!r||Bm:e.drawRangeCursor){let l=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",h=s.empty?s:A.EditorSelection.cursor(s.head,s.head>s.anchor?-1:1);for(let c of to.forRange(n,l,h))i.push(c)}}return i},update(n,t){n.transactions.some(i=>i.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let e=Lm(n);return e&&wu(n.state,t),n.docChanged||n.selectionSet||e},mount(n,t){wu(t.state,n)},class:"cm-cursorLayer"});function wu(n,t){t.style.animationDuration=n.facet($r).cursorBlinkRate+"ms"}const Lx=Rm({above:!1,markers(n){return n.state.selection.ranges.map(t=>t.empty?[]:to.forRange(n,"cm-selectionBackground",t)).reduce((t,e)=>t.concat(e))},update(n,t){return n.docChanged||n.selectionSet||n.viewportChanged||Lm(n)},class:"cm-selectionLayer"}),Zh={".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"}},".cm-content":{"& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}};Bm&&(Zh[".cm-line"].caretColor=Zh[".cm-content"].caretColor="transparent !important");const Nx=A.Prec.highest(mt.theme(Zh)),Nm=A.StateEffect.define({map(n,t){return n==null?null:t.mapPos(n)}}),Tr=A.StateField.define({create(){return null},update(n,t){return n!=null&&(n=t.changes.mapPos(n)),t.effects.reduce((e,i)=>i.is(Nm)?i.value:e,n)}}),Fx=Te.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var t;let e=n.state.field(Tr);e==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(Tr)!=e||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,t=n.state.field(Tr),e=t!=null&&n.coordsAtPos(t);if(!e)return null;let i=n.scrollDOM.getBoundingClientRect();return{left:e.left-i.left+n.scrollDOM.scrollLeft*n.scaleX,top:e.top-i.top+n.scrollDOM.scrollTop*n.scaleY,height:e.bottom-e.top}}drawCursor(n){if(this.cursor){let{scaleX:t,scaleY:e}=this.view;n?(this.cursor.style.left=n.left/t+"px",this.cursor.style.top=n.top/e+"px",this.cursor.style.height=n.height/e+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(Tr)!=n&&this.view.dispatch({effects:Nm.of(n)})}},{eventObservers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Ix(){return[Tr,Fx]}function xu(n,t,e,i,s){t.lastIndex=0;for(let r=n.iterRange(e,i),l=e,h;!r.next().done;l+=r.value.length)if(!r.lineBreak)for(;h=t.exec(r.value);)s(l+h.index,h)}function Hx(n,t){let e=n.visibleRanges;if(e.length==1&&e[0].from==n.viewport.from&&e[0].to==n.viewport.to)return e;let i=[];for(let{from:s,to:r}of e)s=Math.max(n.state.doc.lineAt(s).from,s-t),r=Math.min(n.state.doc.lineAt(r).to,r+t),i.length&&i[i.length-1].to>=s?i[i.length-1].to=r:i.push({from:s,to:r});return i}class Vx{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:r,maxLength:l=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,s)this.addMatch=(h,c,g,p)=>s(p,g,g+h[0].length,h,c);else if(typeof i=="function")this.addMatch=(h,c,g,p)=>{let y=i(h,c,g);y&&p(g,g+h[0].length,y)};else if(i)this.addMatch=(h,c,g,p)=>p(g,g+h[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=l}createDeco(t){let e=new A.RangeSetBuilder,i=e.add.bind(e);for(let{from:s,to:r}of Hx(t,this.maxLength))xu(t.state.doc,this.regexp,s,r,(l,h)=>this.addMatch(h,t,l,i));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges((r,l,h,c)=>{c>t.view.viewport.from&&h<t.view.viewport.to&&(i=Math.min(h,i),s=Math.max(c,s))}),t.viewportChanged||s-i>1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let r of t.visibleRanges){let l=Math.max(r.from,i),h=Math.min(r.to,s);if(h>l){let c=t.state.doc.lineAt(l),g=c.to<h?t.state.doc.lineAt(h):c,p=Math.max(r.from,c.from),y=Math.min(r.to,g.to);if(this.boundary){for(;l>c.from;l--)if(this.boundary.test(c.text[l-1-c.from])){p=l;break}for(;h<g.to;h++)if(this.boundary.test(g.text[h-g.from])){y=h;break}}let x=[],T,P=(I,z,W)=>x.push(W.range(I,z));if(c==g)for(this.regexp.lastIndex=p-c.from;(T=this.regexp.exec(c.text))&&T.index<y-c.from;)this.addMatch(T,t,T.index+c.from,P);else xu(t.state.doc,this.regexp,p,y,(I,z)=>this.addMatch(z,t,I,P));e=e.update({filterFrom:p,filterTo:y,filter:(I,z)=>I<p||z>y,add:x})}}return e}}const tc=/x/.unicode!=null?"gu":"g",$x=new RegExp(`[\0-\b
9
- --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,tc),Wx={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 Ua=null;function zx(){var n;if(Ua==null&&typeof document<"u"&&document.body){let t=document.body.style;Ua=((n=t.tabSize)!==null&&n!==void 0?n:t.MozTabSize)!=null}return Ua||!1}const bl=A.Facet.define({combine(n){let t=A.combineConfig(n,{render:null,specialChars:$x,addSpecialChars:null});return(t.replaceTabs=!zx())&&(t.specialChars=new RegExp(" |"+t.specialChars.source,tc)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,tc)),t}});function qx(n={}){return[bl.of(n),Kx()]}let vu=null;function Kx(){return vu||(vu=Te.fromClass(class{constructor(n){this.view=n,this.decorations=kt.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(bl)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new Vx({regexp:n.specialChars,decoration:(t,e,i)=>{let{doc:s}=e.state,r=A.codePointAt(t[0],0);if(r==9){let l=s.lineAt(i),h=e.state.tabSize,c=A.countColumn(l.text,h,i-l.from);return kt.replace({widget:new Yx((h-c%h)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=kt.replace({widget:new Gx(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let t=n.state.facet(bl);n.startState.facet(bl)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}const jx="•";function _x(n){return n>=32?jx:n==10?"␤":String.fromCharCode(9216+n)}class Gx extends Bi{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=_x(this.code),i=t.state.phrase("Control character")+" "+(Wx[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let r=document.createElement("span");return r.textContent=e,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Yx extends Bi{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent=" ",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}function Ux(){return Jx}const Xx=kt.line({class:"cm-activeLine"}),Jx=Te.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let t=-1,e=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>t&&(e.push(Xx.range(s.from)),t=s.from)}return kt.set(e)}},{decorations:n=>n.decorations});class Qx extends Bi{constructor(t){super(),this.content=t}toDOM(){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):this.content),typeof this.content=="string"?t.setAttribute("aria-label","placeholder "+this.content):t.setAttribute("aria-hidden","true"),t}coordsAt(t){let e=t.firstChild?Is(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=Ql(e[0],i.direction!="rtl"),r=parseInt(i.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 Zx(n){return Te.fromClass(class{constructor(t){this.view=t,this.placeholder=n?kt.set([kt.widget({widget:new Qx(n),side:1}).range(0)]):kt.none}get decorations(){return this.view.state.doc.length?kt.none:this.placeholder}},{decorations:t=>t.decorations})}const ec=2e3;function tv(n,t,e){let i=Math.min(t.line,e.line),s=Math.max(t.line,e.line),r=[];if(t.off>ec||e.off>ec||t.col<0||e.col<0){let l=Math.min(t.off,e.off),h=Math.max(t.off,e.off);for(let c=i;c<=s;c++){let g=n.doc.line(c);g.length<=h&&r.push(A.EditorSelection.range(g.from+l,g.to+h))}}else{let l=Math.min(t.col,e.col),h=Math.max(t.col,e.col);for(let c=i;c<=s;c++){let g=n.doc.line(c),p=A.findColumn(g.text,l,n.tabSize,!0);if(p<0)r.push(A.EditorSelection.cursor(g.to));else{let y=A.findColumn(g.text,h,n.tabSize);r.push(A.EditorSelection.range(g.from+p,g.from+y))}}}return r}function ev(n,t){let e=n.coordsAtPos(n.viewport.from);return e?Math.round(Math.abs((e.left-t)/n.defaultCharacterWidth)):-1}function ku(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1),i=n.state.doc.lineAt(e),s=e-i.from,r=s>ec?-1:s==i.length?ev(n,t.clientX):A.countColumn(i.text,n.state.tabSize,e-i.from);return{line:i.number,col:r,off:s}}function iv(n,t){let e=ku(n,t),i=n.state.selection;return e?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(e.line).from),l=s.state.doc.lineAt(r);e={line:l.number,col:e.col,off:Math.min(e.off,l.length)},i=i.map(s.changes)}},get(s,r,l){let h=ku(n,s);if(!h)return i;let c=tv(n.state,e,h);return c.length?l?A.EditorSelection.create(c.concat(i.ranges)):A.EditorSelection.create(c):i}}:null}function nv(n){let t=e=>e.altKey&&e.button==0;return mt.mouseSelectionStyle.of((e,i)=>t(i)?iv(e,i):null)}const sv={Alt:[18,n=>!!n.altKey],Control:[17,n=>!!n.ctrlKey],Shift:[16,n=>!!n.shiftKey],Meta:[91,n=>!!n.metaKey]},rv={style:"cursor: crosshair"};function ov(n={}){let[t,e]=sv[n.key||"Alt"],i=Te.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==t||e(s))},keyup(s){(s.keyCode==t||!e(s))&&this.set(!1)},mousemove(s){this.set(e(s))}}});return[i,mt.contentAttributes.of(s=>{var r;return!((r=s.plugin(i))===null||r===void 0)&&r.isDown?rv:null})]}const mr="-10000px";class Fm{constructor(t,e,i,s){this.facet=e,this.createTooltipView=i,this.removeTooltipView=s,this.input=t.state.facet(e),this.tooltips=this.input.filter(l=>l);let r=null;this.tooltipViews=this.tooltips.map(l=>r=i(l,r))}update(t,e){var i;let s=t.state.facet(this.facet),r=s.filter(c=>c);if(s===this.input){for(let c of this.tooltipViews)c.update&&c.update(t);return!1}let l=[],h=e?[]:null;for(let c=0;c<r.length;c++){let g=r[c],p=-1;if(g){for(let y=0;y<this.tooltips.length;y++){let x=this.tooltips[y];x&&x.create==g.create&&(p=y)}if(p<0)l[c]=this.createTooltipView(g,c?l[c-1]:null),h&&(h[c]=!!g.above);else{let y=l[c]=this.tooltipViews[p];h&&(h[c]=e[p]),y.update&&y.update(t)}}}for(let c of this.tooltipViews)l.indexOf(c)<0&&(this.removeTooltipView(c),(i=c.destroy)===null||i===void 0||i.call(c));return e&&(h.forEach((c,g)=>e[g]=c),e.length=h.length),this.input=s,this.tooltips=r,this.tooltipViews=l,!0}}function lv(n){let{win:t}=n;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}const Xa=A.Facet.define({combine:n=>{var t,e,i;return{position:ut.ios?"absolute":((t=n.find(s=>s.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((e=n.find(s=>s.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||lv}}}),Cu=new WeakMap,Gc=Te.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=n.state.facet(Xa);this.position=t.position,this.parent=t.parent,this.classes=n.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 Fm(n,Yc,(e,i)=>this.createTooltip(e,i),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.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 n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(n,this.above);t&&this.observeIntersection();let e=t||n.geometryChanged,i=n.state.facet(Xa);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;e=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(n,t){let e=n.create(this.view),i=t?t.dom:null;if(e.dom.classList.add("cm-tooltip"),n.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",e.dom.appendChild(s)}return e.dom.style.position=this.position,e.dom.style.top=mr,e.dom.style.left="0px",this.container.insertBefore(e.dom,i),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var n,t,e;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);this.parent&&this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=this.view.dom.getBoundingClientRect(),t=1,e=1,i=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:s}=this.manager.tooltipViews[0];if(ut.gecko)i=s.offsetParent!=this.container.ownerDocument.body;else if(s.style.top==mr&&s.style.left=="0px"){let r=s.getBoundingClientRect();i=Math.abs(r.top+1e4)>1||Math.abs(r.left)>1}}if(i||this.position=="absolute")if(this.parent){let s=this.parent.getBoundingClientRect();s.width&&s.height&&(t=s.width/this.parent.offsetWidth,e=s.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);return{editor:n,parent:this.parent?this.container.getBoundingClientRect():n,pos:this.manager.tooltips.map((s,r)=>{let l=this.manager.tooltipViews[r];return l.getCoords?l.getCoords(s.pos):this.view.coordsAtPos(s.pos)}),size:this.manager.tooltipViews.map(({dom:s})=>s.getBoundingClientRect()),space:this.view.state.facet(Xa).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(n){var t;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let h of this.manager.tooltipViews)h.dom.style.position="absolute"}let{editor:e,space:i,scaleX:s,scaleY:r}=n,l=[];for(let h=0;h<this.manager.tooltips.length;h++){let c=this.manager.tooltips[h],g=this.manager.tooltipViews[h],{dom:p}=g,y=n.pos[h],x=n.size[h];if(!y||y.bottom<=Math.max(e.top,i.top)||y.top>=Math.min(e.bottom,i.bottom)||y.right<Math.max(e.left,i.left)-.1||y.left>Math.min(e.right,i.right)+.1){p.style.top=mr;continue}let T=c.arrow?g.dom.querySelector(".cm-tooltip-arrow"):null,P=T?7:0,I=x.right-x.left,z=(t=Cu.get(g))!==null&&t!==void 0?t:x.bottom-x.top,W=g.offset||hv,U=this.view.textDirection==Qt.LTR,ot=x.width>i.right-i.left?U?i.left:i.right-x.width:U?Math.max(i.left,Math.min(y.left-(T?14:0)+W.x,i.right-I)):Math.min(Math.max(i.left,y.left-I+(T?14:0)-W.x),i.right-I),Q=this.above[h];!c.strictSide&&(Q?y.top-(x.bottom-x.top)-W.y<i.top:y.bottom+(x.bottom-x.top)+W.y>i.bottom)&&Q==i.bottom-y.bottom>y.top-i.top&&(Q=this.above[h]=!Q);let st=(Q?y.top-i.top:i.bottom-y.bottom)-P;if(st<z&&g.resize!==!1){if(st<this.view.defaultLineHeight){p.style.top=mr;continue}Cu.set(g,z),p.style.height=(z=st)/r+"px"}else p.style.height&&(p.style.height="");let at=Q?y.top-z-P-W.y:y.bottom+P+W.y,wt=ot+I;if(g.overlap!==!0)for(let Pt of l)Pt.left<wt&&Pt.right>ot&&Pt.top<at+z&&Pt.bottom>at&&(at=Q?Pt.top-z-2-P:Pt.bottom+P+2);if(this.position=="absolute"?(p.style.top=(at-n.parent.top)/r+"px",p.style.left=(ot-n.parent.left)/s+"px"):(p.style.top=at/r+"px",p.style.left=ot/s+"px"),T){let Pt=y.left+(U?W.x:-W.x)-(ot+14-7);T.style.left=Pt/s+"px"}g.overlap!==!0&&l.push({left:ot,top:at,right:wt,bottom:at+z}),p.classList.toggle("cm-tooltip-above",Q),p.classList.toggle("cm-tooltip-below",!Q),g.positioned&&g.positioned(n.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 n of this.manager.tooltipViews)n.dom.style.top=mr}},{eventObservers:{scroll(){this.maybeMeasure()}}}),av=mt.baseTheme({".cm-tooltip":{zIndex:100,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:`${7*2}px`,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"}}}),hv={x:0,y:0},Yc=A.Facet.define({enables:[Gc,av]}),Ol=A.Facet.define({combine:n=>n.reduce((t,e)=>t.concat(e),[])});class ta{static create(t){return new ta(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Fm(t,Ol,(e,i)=>this.createHostedView(e,i),e=>e.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)(t=e.destroy)===null||t===void 0||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let s=i[t];if(s!==void 0){if(e===void 0)e=s;else if(e!==s)return}}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const cv=Yc.compute([Ol],n=>{let t=n.facet(Ol);return t.length===0?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var i;return(i=e.end)!==null&&i!==void 0?i:e.pos})),create:ta.create,above:t[0].above,arrow:t.some(e=>e.arrow)}});class fv{constructor(t,e,i,s,r){this.view=t,this.source=e,this.field=i,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;t<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:e}=this,i=t.docView.nearest(e.target);if(!i)return;let s,r=1;if(i instanceof Wc)s=i.posAtStart;else{if(s=t.posAtCoords(e),s==null)return;let h=t.coordsAtPos(s);if(!h||e.y<h.top||e.y>h.bottom||e.x<h.left-t.defaultCharacterWidth||e.x>h.right+t.defaultCharacterWidth)return;let c=t.bidiSpans(t.state.doc.lineAt(s)).find(p=>p.from<=s&&p.to>=s),g=c&&c.dir==Qt.RTL?-1:1;r=e.x<h.left?-g:g}let l=this.source(t,s,r);if(l!=null&&l.then){let h=this.pending={pos:s};l.then(c=>{this.pending==h&&(this.pending=null,c&&!(Array.isArray(c)&&!c.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(c)?c:[c])}))},c=>$e(t.state,c,"hover tooltip"))}else l&&!(Array.isArray(l)&&!l.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(l)?l:[l])})}get tooltip(){let t=this.view.plugin(Gc),e=t?t.manager.tooltips.findIndex(i=>i.create==ta.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:r}=this;if(s.length&&r&&!dv(r.dom,t)||this.pending){let{pos:l}=s[0]||this.pending,h=(i=(e=s[0])===null||e===void 0?void 0:e.end)!==null&&i!==void 0?i:l;(l==h?this.view.posAtCoords(this.lastMove)!=l:!uv(this.view,l,h,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:i}=this;i&&i.dom.contains(t.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const jo=4;function dv(n,t){let e=n.getBoundingClientRect();return t.clientX>=e.left-jo&&t.clientX<=e.right+jo&&t.clientY>=e.top-jo&&t.clientY<=e.bottom+jo}function uv(n,t,e,i,s,r){let l=n.scrollDOM.getBoundingClientRect(),h=n.documentTop+n.documentPadding.top+n.contentHeight;if(l.left>i||l.right<i||l.top>s||Math.min(l.bottom,h)<s)return!1;let c=n.posAtCoords({x:i,y:s},!1);return c>=t&&c<=e}function pv(n,t={}){let e=A.StateEffect.define(),i=A.StateField.define({create(){return[]},update(s,r){if(s.length&&(t.hideOnChange&&(r.docChanged||r.selection)?s=[]:t.hideOn&&(s=s.filter(l=>!t.hideOn(r,l))),r.docChanged)){let l=[];for(let h of s){let c=r.changes.mapPos(h.pos,-1,A.MapMode.TrackDel);if(c!=null){let g=Object.assign(Object.create(null),h);g.pos=c,g.end!=null&&(g.end=r.changes.mapPos(g.end)),l.push(g)}}s=l}for(let l of r.effects)l.is(e)&&(s=l.value),l.is(gv)&&(s=[]);return s},provide:s=>Ol.from(s)});return[i,Te.define(s=>new fv(s,n,i,e,t.hoverTime||300)),cv]}function Im(n,t){let e=n.plugin(Gc);if(!e)return null;let i=e.manager.tooltips.indexOf(t);return i<0?null:e.manager.tooltipViews[i]}const gv=A.StateEffect.define(),Mu=A.Facet.define({combine(n){let t,e;for(let i of n)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function mv(n,t){let e=n.plugin(Hm),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}const Hm=Te.fromClass(class{constructor(n){this.input=n.state.facet(ic),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(n));let t=n.state.facet(Mu);this.top=new _o(n,!0,t.topContainer),this.bottom=new _o(n,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(n){let t=n.state.facet(Mu);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new _o(n.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new _o(n.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=n.state.facet(ic);if(e!=this.input){let i=e.filter(c=>c),s=[],r=[],l=[],h=[];for(let c of i){let g=this.specs.indexOf(c),p;g<0?(p=c(n.view),h.push(p)):(p=this.panels[g],p.update&&p.update(n)),s.push(p),(p.top?r:l).push(p)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(l);for(let c of h)c.dom.classList.add("cm-panel"),c.mount&&c.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>mt.scrollMargins.of(t=>{let e=t.plugin(n);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});let _o=class{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(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 e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=Au(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Au(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}};function Au(n){let t=n.nextSibling;return n.remove(),t}const ic=A.Facet.define({enables:Hm});let un=class extends A.RangeValue{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}};un.prototype.elementClass="";un.prototype.toDOM=void 0;un.prototype.mapMode=A.MapMode.TrackBefore;un.prototype.startSide=un.prototype.endSide=-1;un.prototype.point=!0;const yl=A.Facet.define(),bv={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>A.RangeSet.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},Nr=A.Facet.define();function yv(n){return[Vm(),Nr.of(Object.assign(Object.assign({},bv),n))]}const Tu=A.Facet.define({combine:n=>n.some(t=>t)});function Vm(n){return[Sv]}const Sv=Te.fromClass(class{constructor(n){this.view=n,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(Nr).map(t=>new Ou(n,t));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!n.state.facet(Tu),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}update(n){if(this.updateGutters(n)){let t=this.prevViewport,e=n.view.viewport,i=Math.min(t.to,e.to)-Math.max(t.from,e.from);this.syncGutters(i<(e.to-e.from)*.8)}n.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px"),this.view.state.facet(Tu)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=n.view.viewport}syncGutters(n){let t=this.dom.nextSibling;n&&this.dom.remove();let e=A.RangeSet.iter(this.view.state.facet(yl),this.view.viewport.from),i=[],s=this.gutters.map(r=>new wv(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let l=!0;for(let h of r.type)if(h.type==We.Text&&l){nc(e,i,h.from);for(let c of s)c.line(this.view,h,i);l=!1}else if(h.widget)for(let c of s)c.widget(this.view,h)}else if(r.type==We.Text){nc(e,i,r.from);for(let l of s)l.line(this.view,r,i)}else if(r.widget)for(let l of s)l.widget(this.view,r);for(let r of s)r.finish();n&&this.view.scrollDOM.insertBefore(this.dom,t)}updateGutters(n){let t=n.startState.facet(Nr),e=n.state.facet(Nr),i=n.docChanged||n.heightChanged||n.viewportChanged||!A.RangeSet.eq(n.startState.facet(yl),n.state.facet(yl),n.view.viewport.from,n.view.viewport.to);if(t==e)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of e){let l=t.indexOf(r);l<0?s.push(new Ou(this.view,r)):(this.gutters[l].update(n),s.push(this.gutters[l]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove()}},{provide:n=>mt.scrollMargins.of(t=>{let e=t.plugin(n);return!e||e.gutters.length==0||!e.fixed?null:t.textDirection==Qt.LTR?{left:e.dom.offsetWidth*t.scaleX}:{right:e.dom.offsetWidth*t.scaleX}})});function Du(n){return Array.isArray(n)?n:[n]}function nc(n,t,e){for(;n.value&&n.from<=e;)n.from==e&&t.push(n.value),n.next()}class wv{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=A.RangeSet.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:s}=this,r=(e.top-this.height)/t.scaleY,l=e.height/t.scaleY;if(this.i==s.elements.length){let h=new $m(t,l,r,i);s.elements.push(h),s.dom.appendChild(h.dom)}else s.elements[this.i].update(t,l,r,i);this.height=e.bottom,this.i++}line(t,e,i){let s=[];nc(this.cursor,s,e.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(t,e,s);r&&s.unshift(r);let l=this.gutter;s.length==0&&!l.config.renderEmptyElements||this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e);i&&this.addElement(t,e,[i])}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Ou{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,s=>{let r=s.target,l;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let c=r.getBoundingClientRect();l=(c.top+c.bottom)/2}else l=s.clientY;let h=t.lineBlockAtHeight(l-t.documentTop);e.domEventHandlers[i](t,h,s)&&s.preventDefault()});this.markers=Du(e.markers(t)),e.initialSpacer&&(this.spacer=new $m(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=Du(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],t);s!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[s])}let i=t.view.viewport;return!A.RangeSet.eq(this.markers,e,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}}class $m{constructor(t,e,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,s)}update(t,e,i,s){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),xv(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,l=0;;){let h=l,c=r<e.length?e[r++]:null,g=!1;if(c){let p=c.elementClass;p&&(i+=" "+p);for(let y=l;y<this.markers.length;y++)if(this.markers[y].compare(c)){h=y,g=!0;break}}else h=this.markers.length;for(;l<h;){let p=this.markers[l++];if(p.toDOM){p.destroy(s);let y=s.nextSibling;s.remove(),s=y}}if(!c)break;c.toDOM&&(g?s=s.nextSibling:this.dom.insertBefore(c.toDOM(t),s)),g&&l++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}function xv(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++)if(!n[e].compare(t[e]))return!1;return!0}const vv=A.Facet.define(),Ts=A.Facet.define({combine(n){return A.combineConfig(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let s in e){let r=i[s],l=e[s];i[s]=r?(h,c,g)=>r(h,c,g)||l(h,c,g):l}return i}})}});class Ja extends un{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Qa(n,t){return n.state.facet(Ts).formatNumber(t,n.state)}const kv=Nr.compute([Ts],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(vv)},lineMarker(t,e,i){return i.some(s=>s.toDOM)?null:new Ja(Qa(t,t.state.doc.lineAt(e.from).number))},widgetMarker:()=>null,lineMarkerChange:t=>t.startState.facet(Ts)!=t.state.facet(Ts),initialSpacer(t){return new Ja(Qa(t,Eu(t.state.doc.lines)))},updateSpacer(t,e){let i=Qa(e.view,Eu(e.view.state.doc.lines));return i==t.number?t:new Ja(i)},domEventHandlers:n.facet(Ts).domEventHandlers}));function Cv(n={}){return[Ts.of(n),Vm(),kv]}function Eu(n){let t=9;for(;t<n;)t=t*10+9;return t}const Mv=new class extends un{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Av=yl.compute(["selection"],n=>{let t=[],e=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>e&&(e=s,t.push(Mv.range(s)))}return A.RangeSet.of(t)});function Tv(){return Av}var Za;const Ds=new qe;function Wm(n){return A.Facet.define({combine:n?t=>t.concat(n):void 0})}const Uc=new qe;let Di=class{constructor(t,e,i=[],s=""){this.data=t,this.name=s,A.EditorState.prototype.hasOwnProperty("tree")||Object.defineProperty(A.EditorState.prototype,"tree",{get(){return ie(this)}}),this.parser=e,this.extension=[$n.of(this),A.EditorState.languageData.of((r,l,h)=>{let c=Pu(r,l,h),g=c.type.prop(Ds);if(!g)return[];let p=r.facet(g),y=c.type.prop(Uc);if(y){let x=c.resolve(l-c.from,h);for(let T of y)if(T.test(x,r)){let P=r.facet(T.facet);return T.type=="replace"?P:P.concat(p)}}return p})].concat(i)}isActiveAt(t,e,i=-1){return Pu(t,e,i).type.prop(Ds)==this.data}findRegions(t){let e=t.facet($n);if((e==null?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],s=(r,l)=>{if(r.prop(Ds)==this.data){i.push({from:l,to:l+r.length});return}let h=r.prop(qe.mounted);if(h){if(h.tree.prop(Ds)==this.data){if(h.overlay)for(let c of h.overlay)i.push({from:c.from+l,to:c.to+l});else i.push({from:l,to:l+r.length});return}else if(h.overlay){let c=i.length;if(s(h.tree,h.overlay[0].from+l),i.length>c)return}}for(let c=0;c<r.children.length;c++){let g=r.children[c];g instanceof bi&&s(g,r.positions[c]+l)}};return s(ie(t),0),i}get allowsNesting(){return!0}};Di.setState=A.StateEffect.define();function Pu(n,t,e){let i=n.facet($n),s=ie(n).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(t,e,Jl.ExcludeBuffers))r.type.isTop&&(s=r);return s}class Wr extends Di{constructor(t,e,i){super(t,e,[],i),this.parser=e}static define(t){let e=Wm(t.languageData);return new Wr(e,t.parser.configure({props:[Ds.add(i=>i.isTop?e:void 0)]}),t.name)}configure(t,e){return new Wr(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function ie(n){let t=n.field(Di.state,!1);return t?t.tree:bi.empty}let Dv=class{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t<i||e>=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}},br=null,Ov=class sc{constructor(t,e,i=[],s,r,l,h,c){this.parser=t,this.state=e,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=l,this.skipped=h,this.scheduleOn=c,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new sc(t,e,[],bi.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Dv(this.state.doc),this.fragments)}work(t,e){return e!=null&&e>=this.state.doc.length&&(e=void 0),this.tree!=bi.empty&&this.isDone(e??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof t=="number"){let s=Date.now()+t;t=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),e!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(Nn.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(e??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(Nn.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=br;br=this;try{return t()}finally{br=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=Ru(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:s,treeLen:r,viewport:l,skipped:h}=this;if(this.takeTree(),!t.empty){let c=[];if(t.iterChangedRanges((g,p,y,x)=>c.push({fromA:g,toA:p,fromB:y,toB:x})),i=Nn.applyChanges(i,c),s=bi.empty,r=0,l={from:t.mapPos(l.from,-1),to:t.mapPos(l.to,1)},this.skipped.length){h=[];for(let g of this.skipped){let p=t.mapPos(g.from,1),y=t.mapPos(g.to,-1);p<y&&h.push({from:p,to:y})}}}return new sc(this.parser,e,i,s,r,l,h,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let e=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<t.to&&r>t.from&&(this.fragments=Ru(this.fragments,s,r),this.skipped.splice(i--,1))}return this.skipped.length>=e?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends bg{createParse(e,i,s){let r=s[0].from,l=s[s.length-1].to;return{parsedPos:r,advance(){let c=br;if(c){for(let g of s)c.tempSkipped.push(g);t&&(c.scheduleOn=c.scheduleOn?Promise.all([c.scheduleOn,t]):t)}return this.parsedPos=l,new bi(Us.none,[],[],l-r)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&e[0].from==0&&e[0].to>=t}static get(){return br}};function Ru(n,t,e){return Nn.applyChanges(n,[{fromA:t,toA:e,fromB:t,toB:e}])}let rc=class oc{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new oc(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Ov.create(t.facet($n).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new oc(i)}};Di.state=A.StateField.define({create:rc.init,update(n,t){for(let e of t.effects)if(e.is(Di.setState))return e.value;return t.startState.facet($n)!=t.state.facet($n)?rc.init(t.state):n.apply(t)}});let zm=n=>{let t=setTimeout(()=>n(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(zm=n=>{let t=-1,e=setTimeout(()=>{t=requestIdleCallback(n,{timeout:400})},100);return()=>t<0?clearTimeout(e):cancelIdleCallback(t)});const th=typeof navigator<"u"&&(!((Za=navigator.scheduling)===null||Za===void 0)&&Za.isInputPending)?()=>navigator.scheduling.isInputPending():null,Ev=Te.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(Di.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(Di.state);(e.tree!=e.context.tree||!e.context.isDone(t.doc.length))&&(this.working=zm(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(Di.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let l=Date.now()+Math.min(this.chunkBudget,100,t&&!th?Math.max(25,t.timeRemaining()-5):1e9),h=r.context.treeLen<s&&i.doc.length>s+1e3,c=r.context.work(()=>th&&th()||Date.now()>l,s+(h?0:1e5));this.chunkBudget-=Date.now()-e,(c||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Di.setState.of(new rc(r.context))})),this.chunkBudget>0&&!(c&&!h)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(e=>$e(this.view.state,e)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),$n=A.Facet.define({combine(n){return n.length?n[0]:null},enables:n=>[Di.state,Ev,mt.contentAttributes.compute([n],t=>{let e=t.facet(n);return e&&e.name?{"data-language":e.name}:{}})]});class qm{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const Pv=A.Facet.define(),Js=A.Facet.define({combine:n=>{if(!n.length)return" ";let t=n[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return t}});function El(n){let t=n.facet(Js);return t.charCodeAt(0)==9?n.tabSize*t.length:t.length}function zr(n,t){let e="",i=n.tabSize,s=n.facet(Js)[0];if(s==" "){for(;t>=i;)e+=" ",t-=i;s=" "}for(let r=0;r<t;r++)e+=s;return e}function Xc(n,t){n instanceof A.EditorState&&(n=new ea(n));for(let i of n.state.facet(Pv)){let s=i(n,t);if(s!==void 0)return s}let e=ie(n.state);return e.length>=t?Rv(n,e,t):null}class ea{constructor(t,e={}){this.state=t,this.options=e,this.unit=El(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==t?{text:"",from:t}:(e<0?s<t:s<=t)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(t,e=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(t,e);return i.slice(t-s,Math.min(i.length,t+100-s))}column(t,e=1){let{text:i,from:s}=this.lineAt(t,e),r=this.countColumn(i,t-s),l=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return l>-1&&(r+=l-this.countColumn(i,i.search(/\S|$/))),r}countColumn(t,e=t.length){return A.countColumn(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:s}=this.lineAt(t,e),r=this.options.overrideIndentation;if(r){let l=r(s);if(l>-1)return l}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Jc=new qe;function Rv(n,t,e){let i=t.resolveStack(e),s=i.node.enterUnfinishedNodesBefore(e);if(s!=i.node){let r=[];for(let l=s;l!=i.node;l=l.parent)r.push(l);for(let l=r.length-1;l>=0;l--)i={node:r[l],next:i}}return Km(i,n,e)}function Km(n,t,e){for(let i=n;i;i=i.next){let s=Lv(i.node);if(s)return s(Qc.create(t,e,i))}return 0}function Bv(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function Lv(n){let t=n.type.prop(Jc);if(t)return t;let e=n.firstChild,i;if(e&&(i=e.type.prop(qe.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return l=>jm(l,!0,1,void 0,r&&!Bv(l)?s.from:void 0)}return n.parent==null?Nv:null}function Nv(){return 0}class Qc extends ea{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new Qc(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(Fv(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return Km(this.context.next,this.base,this.pos)}}function Fv(n,t){for(let e=t;e;e=e.parent)if(n==e)return!0;return!1}function Iv(n){let t=n.node,e=t.childAfter(t.from),i=t.lastChild;if(!e)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(e.from),l=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let h=e.to;;){let c=t.childAfter(h);if(!c||c==i)return null;if(!c.type.isSkipped){if(c.from>=l)return null;let g=/^ */.exec(r.text.slice(e.to-r.from))[0].length;return{from:e.from,to:e.to+g}}h=c.to}}function Sl({closing:n,align:t=!0,units:e=1}){return i=>jm(i,t,e,n)}function jm(n,t,e,i,s){let r=n.textAfter,l=r.match(/^\s*/)[0].length,h=i&&r.slice(l,l+i.length)==i||s==n.pos+l,c=t?Iv(n):null;return c?h?n.column(c.from):n.column(c.to):n.baseIndent+(h?0:n.unit*e)}const Hv=n=>n.baseIndent;function eh({except:n,units:t=1}={}){return e=>{let i=n&&n.test(e.textAfter);return e.baseIndent+(i?0:t*e.unit)}}const Vv=200;function $v(){return A.EditorState.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let t=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!t.length)return n;let e=n.newDoc,{head:i}=n.newSelection.main,s=e.lineAt(i);if(i>s.from+Vv)return n;let r=e.sliceString(s.from,i);if(!t.some(g=>g.test(r)))return n;let{state:l}=n,h=-1,c=[];for(let{head:g}of l.selection.ranges){let p=l.doc.lineAt(g);if(p.from==h)continue;h=p.from;let y=Xc(l,p.from);if(y==null)continue;let x=/^\s*/.exec(p.text)[0],T=zr(l,y);x!=T&&c.push({from:p.from,to:p.from+x.length,insert:T})}return c.length?[n,{changes:c,sequential:!0}]:n})}const Wv=A.Facet.define(),Zc=new qe;function _m(n){let t=n.firstChild,e=n.lastChild;return t&&t.to<e.from?{from:t.to,to:e.type.isError?n.to:e.from}:null}function zv(n,t,e){let i=ie(n);if(i.length<e)return null;let s=i.resolveStack(e,1),r=null;for(let l=s;l;l=l.next){let h=l.node;if(h.to<=e||h.from>e)continue;if(r&&h.from<t)break;let c=h.type.prop(Zc);if(c&&(h.to<i.length-50||i.length==n.doc.length||!qv(h))){let g=c(h,n);g&&g.from<=e&&g.from>=t&&g.to>e&&(r=g)}}return r}function qv(n){let t=n.lastChild;return t&&t.to==n.to&&t.type.isError}function Pl(n,t,e){for(let i of n.facet(Wv)){let s=i(n,t,e);if(s)return s}return zv(n,t,e)}function Gm(n,t){let e=t.mapPos(n.from,1),i=t.mapPos(n.to,-1);return e>=i?void 0:{from:e,to:i}}const ia=A.StateEffect.define({map:Gm}),eo=A.StateEffect.define({map:Gm});function Ym(n){let t=[];for(let{head:e}of n.state.selection.ranges)t.some(i=>i.from<=e&&i.to>=e)||t.push(n.lineBlockAt(e));return t}const ss=A.StateField.define({create(){return kt.none},update(n,t){n=n.map(t.changes);for(let e of t.effects)if(e.is(ia)&&!Kv(n,e.value.from,e.value.to)){let{preparePlaceholder:i}=t.state.facet(Jm),s=i?kt.replace({widget:new Jv(i(t.state,e.value))}):Bu;n=n.update({add:[s.range(e.value.from,e.value.to)]})}else e.is(eo)&&(n=n.update({filter:(i,s)=>e.value.from!=i||e.value.to!=s,filterFrom:e.value.from,filterTo:e.value.to}));if(t.selection){let e=!1,{head:i}=t.selection.main;n.between(i,i,(s,r)=>{s<i&&r>i&&(e=!0)}),e&&(n=n.update({filterFrom:i,filterTo:i,filter:(s,r)=>r<=i||s>=i}))}return n},provide:n=>mt.decorations.from(n),toJSON(n,t){let e=[];return n.between(0,t.doc.length,(i,s)=>{e.push(i,s)}),e},fromJSON(n){if(!Array.isArray(n)||n.length%2)throw new RangeError("Invalid JSON for fold state");let t=[];for(let e=0;e<n.length;){let i=n[e++],s=n[e++];if(typeof i!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");t.push(Bu.range(i,s))}return kt.set(t,!0)}});function Rl(n,t,e){var i;let s=null;return(i=n.field(ss,!1))===null||i===void 0||i.between(t,e,(r,l)=>{(!s||s.from>r)&&(s={from:r,to:l})}),s}function Kv(n,t,e){let i=!1;return n.between(t,t,(s,r)=>{s==t&&r==e&&(i=!0)}),i}function Um(n,t){return n.field(ss,!1)?t:t.concat(A.StateEffect.appendConfig.of(Qm()))}const jv=n=>{for(let t of Ym(n)){let e=Pl(n.state,t.from,t.to);if(e)return n.dispatch({effects:Um(n.state,[ia.of(e),Xm(n,e)])}),!0}return!1},_v=n=>{if(!n.state.field(ss,!1))return!1;let t=[];for(let e of Ym(n)){let i=Rl(n.state,e.from,e.to);i&&t.push(eo.of(i),Xm(n,i,!1))}return t.length&&n.dispatch({effects:t}),t.length>0};function Xm(n,t,e=!0){let i=n.state.doc.lineAt(t.from).number,s=n.state.doc.lineAt(t.to).number;return mt.announce.of(`${n.state.phrase(e?"Folded lines":"Unfolded lines")} ${i} ${n.state.phrase("to")} ${s}.`)}const Gv=n=>{let{state:t}=n,e=[];for(let i=0;i<t.doc.length;){let s=n.lineBlockAt(i),r=Pl(t,s.from,s.to);r&&e.push(ia.of(r)),i=(r?n.lineBlockAt(r.to):s).to+1}return e.length&&n.dispatch({effects:Um(n.state,e)}),!!e.length},Yv=n=>{let t=n.state.field(ss,!1);if(!t||!t.size)return!1;let e=[];return t.between(0,n.state.doc.length,(i,s)=>{e.push(eo.of({from:i,to:s}))}),n.dispatch({effects:e}),!0},Uv=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:jv},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:_v},{key:"Ctrl-Alt-[",run:Gv},{key:"Ctrl-Alt-]",run:Yv}],Xv={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Jm=A.Facet.define({combine(n){return A.combineConfig(n,Xv)}});function Qm(n){return[ss,tk]}function Zm(n,t){let{state:e}=n,i=e.facet(Jm),s=l=>{let h=n.lineBlockAt(n.posAtDOM(l.target)),c=Rl(n.state,h.from,h.to);c&&n.dispatch({effects:eo.of(c)}),l.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(n,s,t);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",e.phrase("folded code")),r.title=e.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const Bu=kt.replace({widget:new class extends Bi{toDOM(n){return Zm(n,null)}}});class Jv extends Bi{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return Zm(t,this.value)}}const Qv={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class ih extends un{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}function Zv(n={}){let t=Object.assign(Object.assign({},Qv),n),e=new ih(t,!0),i=new ih(t,!1),s=Te.fromClass(class{constructor(l){this.from=l.viewport.from,this.markers=this.buildMarkers(l)}update(l){(l.docChanged||l.viewportChanged||l.startState.facet($n)!=l.state.facet($n)||l.startState.field(ss,!1)!=l.state.field(ss,!1)||ie(l.startState)!=ie(l.state)||t.foldingChanged(l))&&(this.markers=this.buildMarkers(l.view))}buildMarkers(l){let h=new A.RangeSetBuilder;for(let c of l.viewportLineBlocks){let g=Rl(l.state,c.from,c.to)?i:Pl(l.state,c.from,c.to)?e:null;g&&h.add(c.from,c.from,g)}return h.finish()}}),{domEventHandlers:r}=t;return[s,yv({class:"cm-foldGutter",markers(l){var h;return((h=l.plugin(s))===null||h===void 0?void 0:h.markers)||A.RangeSet.empty},initialSpacer(){return new ih(t,!1)},domEventHandlers:Object.assign(Object.assign({},r),{click:(l,h,c)=>{if(r.click&&r.click(l,h,c))return!0;let g=Rl(l.state,h.from,h.to);if(g)return l.dispatch({effects:eo.of(g)}),!0;let p=Pl(l.state,h.from,h.to);return p?(l.dispatch({effects:ia.of(p)}),!0):!1}})}),Qm()]}const tk=mt.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"}});let tf=class t0{constructor(t,e){this.specs=t;let i;function s(h){let c=Le.newName();return(i||(i=Object.create(null)))["."+c]=h,c}const r=typeof e.all=="string"?e.all:e.all?s(e.all):void 0,l=e.scope;this.scope=l instanceof Di?h=>h.prop(Ds)==l.data:l?h=>h==l:void 0,this.style=yg(t.map(h=>({tag:h.tag,class:h.class||s(Object.assign({},h,{tag:null}))})),{all:r}).style,this.module=i?new Le(i):null,this.themeType=e.themeType}static define(t,e){return new t0(t,e||{})}};const lc=A.Facet.define(),e0=A.Facet.define({combine(n){return n.length?[n[0]]:null}});function nh(n){let t=n.facet(lc);return t.length?t:n.facet(e0)}function i0(n,t){let e=[ik],i;return n instanceof tf&&(n.module&&e.push(mt.styleModule.of(n.module)),i=n.themeType),t!=null&&t.fallback?e.push(e0.of(n)):i?e.push(lc.computeN([mt.darkTheme],s=>s.facet(mt.darkTheme)==(i=="dark")?[n]:[])):e.push(lc.of(n)),e}let ek=class{constructor(t){this.markCache=Object.create(null),this.tree=ie(t.state),this.decorations=this.buildDeco(t,nh(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=ie(t.state),i=nh(t.state),s=i!=nh(t.startState),{viewport:r}=t.view,l=t.changes.mapPos(this.decoratedTo,1);e.length<r.to&&!s&&e.type==this.tree.type&&l>=r.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=l):(e!=this.tree||t.viewportChanged||s)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=r.to)}buildDeco(t,e){if(!e||!this.tree.length)return kt.none;let i=new A.RangeSetBuilder;for(let{from:s,to:r}of t.visibleRanges)Sg(this.tree,e,(l,h,c)=>{i.add(l,h,this.markCache[c]||(this.markCache[c]=kt.mark({class:c})))},s,r);return i.finish()}};const ik=A.Prec.high(Te.fromClass(ek,{decorations:n=>n.decorations})),nk=tf.define([{tag:J.meta,color:"#404740"},{tag:J.link,textDecoration:"underline"},{tag:J.heading,textDecoration:"underline",fontWeight:"bold"},{tag:J.emphasis,fontStyle:"italic"},{tag:J.strong,fontWeight:"bold"},{tag:J.strikethrough,textDecoration:"line-through"},{tag:J.keyword,color:"#708"},{tag:[J.atom,J.bool,J.url,J.contentSeparator,J.labelName],color:"#219"},{tag:[J.literal,J.inserted],color:"#164"},{tag:[J.string,J.deleted],color:"#a11"},{tag:[J.regexp,J.escape,J.special(J.string)],color:"#e40"},{tag:J.definition(J.variableName),color:"#00f"},{tag:J.local(J.variableName),color:"#30a"},{tag:[J.typeName,J.namespace],color:"#085"},{tag:J.className,color:"#167"},{tag:[J.special(J.variableName),J.macroName],color:"#256"},{tag:J.definition(J.propertyName),color:"#00c"},{tag:J.comment,color:"#940"},{tag:J.invalid,color:"#f00"}]),sk=mt.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),n0=1e4,s0="()[]{}",r0=A.Facet.define({combine(n){return A.combineConfig(n,{afterCursor:!0,brackets:s0,maxScanDistance:n0,renderMatch:lk})}}),rk=kt.mark({class:"cm-matchingBracket"}),ok=kt.mark({class:"cm-nonmatchingBracket"});function lk(n){let t=[],e=n.matched?rk:ok;return t.push(e.range(n.start.from,n.start.to)),n.end&&t.push(e.range(n.end.from,n.end.to)),t}const ak=A.StateField.define({create(){return kt.none},update(n,t){if(!t.docChanged&&!t.selection)return n;let e=[],i=t.state.facet(r0);for(let s of t.state.selection.ranges){if(!s.empty)continue;let r=Ki(t.state,s.head,-1,i)||s.head>0&&Ki(t.state,s.head-1,1,i)||i.afterCursor&&(Ki(t.state,s.head,1,i)||s.head<t.state.doc.length&&Ki(t.state,s.head+1,-1,i));r&&(e=e.concat(i.renderMatch(r,t.state)))}return kt.set(e,!0)},provide:n=>mt.decorations.from(n)}),hk=[ak,sk];function ck(n={}){return[r0.of(n),hk]}const fk=new qe;function ac(n,t,e){let i=n.prop(t<0?qe.openedBy:qe.closedBy);if(i)return i;if(n.name.length==1){let s=e.indexOf(n.name);if(s>-1&&s%2==(t<0?1:0))return[e[s+t]]}return null}function hc(n){let t=n.type.prop(fk);return t?t(n.node):n}function Ki(n,t,e,i={}){let s=i.maxScanDistance||n0,r=i.brackets||s0,l=ie(n),h=l.resolveInner(t,e);for(let c=h;c;c=c.parent){let g=ac(c.type,e,r);if(g&&c.from<c.to){let p=hc(c);if(p&&(e>0?t>=p.from&&t<p.to:t>p.from&&t<=p.to))return dk(n,t,e,c,p,g,r)}}return uk(n,t,e,l,h.type,s,r)}function dk(n,t,e,i,s,r,l){let h=i.parent,c={from:s.from,to:s.to},g=0,p=h==null?void 0:h.cursor();if(p&&(e<0?p.childBefore(i.from):p.childAfter(i.to)))do if(e<0?p.to<=i.from:p.from>=i.to){if(g==0&&r.indexOf(p.type.name)>-1&&p.from<p.to){let y=hc(p);return{start:c,end:y?{from:y.from,to:y.to}:void 0,matched:!0}}else if(ac(p.type,e,l))g++;else if(ac(p.type,-e,l)){if(g==0){let y=hc(p);return{start:c,end:y&&y.from<y.to?{from:y.from,to:y.to}:void 0,matched:!1}}g--}}while(e<0?p.prevSibling():p.nextSibling());return{start:c,matched:!1}}function uk(n,t,e,i,s,r,l){let h=e<0?n.sliceDoc(t-1,t):n.sliceDoc(t,t+1),c=l.indexOf(h);if(c<0||c%2==0!=e>0)return null;let g={from:e<0?t-1:t,to:e>0?t+1:t},p=n.doc.iterRange(t,e>0?n.doc.length:0),y=0;for(let x=0;!p.next().done&&x<=r;){let T=p.value;e<0&&(x+=T.length);let P=t+x*e;for(let I=e>0?0:T.length-1,z=e>0?T.length:-1;I!=z;I+=e){let W=l.indexOf(T[I]);if(!(W<0||i.resolveInner(P+I,1).type!=s))if(W%2==0==e>0)y++;else{if(y==1)return{start:g,end:{from:P+I,to:P+I+1},matched:W>>1==c>>1};y--}}e>0&&(x+=T.length)}return p.done?{start:g,matched:!1}:null}const pk=Object.create(null),Lu=[Us.none],Nu=[],Fu=Object.create(null),gk=Object.create(null);for(let[n,t]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"]])gk[n]=mk(pk,t);function sh(n,t){Nu.indexOf(n)>-1||(Nu.push(n),console.warn(t))}function mk(n,t){let e=[];for(let h of t.split(" ")){let c=[];for(let g of h.split(".")){let p=n[g]||J[g];p?typeof p=="function"?c.length?c=c.map(p):sh(g,`Modifier ${g} used at start of tag`):c.length?sh(g,`Tag ${g} used as modifier`):c=Array.isArray(p)?p:[p]:sh(g,`Unknown highlighting tag ${g}`)}for(let g of c)e.push(g)}if(!e.length)return 0;let i=t.replace(/ /g,"_"),s=i+" "+e.map(h=>h.id),r=Fu[s];if(r)return r.id;let l=Fu[s]=Us.define({id:Lu.length,name:i,props:[wg({[i]:e})]});return Lu.push(l),l.id}Qt.RTL,Qt.LTR;const bk=n=>{let{state:t}=n,e=t.doc.lineAt(t.selection.main.from),i=nf(n.state,e.from);return i.line?yk(n):i.block?wk(n):!1};function ef(n,t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let s=n(t,e);return s?(i(e.update(s)),!0):!1}}const yk=ef(kk,0),Sk=ef(o0,0),wk=ef((n,t)=>o0(n,t,vk(t)),0);function nf(n,t){let e=n.languageDataAt("commentTokens",t);return e.length?e[0]:{}}const yr=50;function xk(n,{open:t,close:e},i,s){let r=n.sliceDoc(i-yr,i),l=n.sliceDoc(s,s+yr),h=/\s*$/.exec(r)[0].length,c=/^\s*/.exec(l)[0].length,g=r.length-h;if(r.slice(g-t.length,g)==t&&l.slice(c,c+e.length)==e)return{open:{pos:i-h,margin:h&&1},close:{pos:s+c,margin:c&&1}};let p,y;s-i<=2*yr?p=y=n.sliceDoc(i,s):(p=n.sliceDoc(i,i+yr),y=n.sliceDoc(s-yr,s));let x=/^\s*/.exec(p)[0].length,T=/\s*$/.exec(y)[0].length,P=y.length-T-e.length;return p.slice(x,x+t.length)==t&&y.slice(P,P+e.length)==e?{open:{pos:i+x+t.length,margin:/\s/.test(p.charAt(x+t.length))?1:0},close:{pos:s-T-e.length,margin:/\s/.test(y.charAt(P-1))?1:0}}:null}function vk(n){let t=[];for(let e of n.selection.ranges){let i=n.doc.lineAt(e.from),s=e.to<=i.to?i:n.doc.lineAt(e.to);s.from>i.from&&s.from==e.to&&(s=e.to==i.to+1?i:n.doc.lineAt(e.to-1));let r=t.length-1;r>=0&&t[r].to>i.from?t[r].to=s.to:t.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return t}function o0(n,t,e=t.selection.ranges){let i=e.map(r=>nf(t,r.from).block);if(!i.every(r=>r))return null;let s=e.map((r,l)=>xk(t,i[l],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:t.changes(e.map((r,l)=>s[l]?[]:[{from:r.from,insert:i[l].open+" "},{from:r.to,insert:" "+i[l].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let l=0,h;l<s.length;l++)if(h=s[l]){let c=i[l],{open:g,close:p}=h;r.push({from:g.pos-c.open.length,to:g.pos+g.margin},{from:p.pos-p.margin,to:p.pos+c.close.length})}return{changes:r}}return null}function kk(n,t,e=t.selection.ranges){let i=[],s=-1;for(let{from:r,to:l}of e){let h=i.length,c=1e9,g=nf(t,r).line;if(g){for(let p=r;p<=l;){let y=t.doc.lineAt(p);if(y.from>s&&(r==l||l>y.from)){s=y.from;let x=/^\s*/.exec(y.text)[0].length,T=x==y.length,P=y.text.slice(x,x+g.length)==g?x:-1;x<y.text.length&&x<c&&(c=x),i.push({line:y,comment:P,token:g,indent:x,empty:T,single:!1})}p=y.to+1}if(c<1e9)for(let p=h;p<i.length;p++)i[p].indent<i[p].line.text.length&&(i[p].indent=c);i.length==h+1&&(i[h].single=!0)}}if(n!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:h,token:c,indent:g,empty:p,single:y}of i)(y||!p)&&r.push({from:h.from+g,insert:c+" "});let l=t.changes(r);return{changes:l,selection:t.selection.map(l,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:l,comment:h,token:c}of i)if(h>=0){let g=l.from+h,p=g+c.length;l.text[p-l.from]==" "&&p++,r.push({from:g,to:p})}return{changes:r}}return null}const cc=A.Annotation.define(),Ck=A.Annotation.define(),Mk=A.Facet.define(),l0=A.Facet.define({combine(n){return A.combineConfig(n,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,s)=>t(i,s)||e(i,s)})}}),a0=A.StateField.define({create(){return ji.empty},update(n,t){let e=t.state.facet(l0),i=t.annotation(cc);if(i){let c=Je.fromTransaction(t,i.selection),g=i.side,p=g==0?n.undone:n.done;return c?p=Bl(p,p.length,e.minDepth,c):p=f0(p,t.startState.selection),new ji(g==0?i.rest:p,g==0?p:i.rest)}let s=t.annotation(Ck);if((s=="full"||s=="before")&&(n=n.isolate()),t.annotation(A.Transaction.addToHistory)===!1)return t.changes.empty?n:n.addMapping(t.changes.desc);let r=Je.fromTransaction(t),l=t.annotation(A.Transaction.time),h=t.annotation(A.Transaction.userEvent);return r?n=n.addChanges(r,l,h,e,t):t.selection&&(n=n.addSelection(t.startState.selection,l,h,e.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(t=>t.toJSON()),undone:n.undone.map(t=>t.toJSON())}},fromJSON(n){return new ji(n.done.map(Je.fromJSON),n.undone.map(Je.fromJSON))}});function Ak(n={}){return[a0,l0.of(n),mt.domEventHandlers({beforeinput(t,e){let i=t.inputType=="historyUndo"?h0:t.inputType=="historyRedo"?fc:null;return i?(t.preventDefault(),i(e)):!1}})]}function na(n,t){return function({state:e,dispatch:i}){if(!t&&e.readOnly)return!1;let s=e.field(a0,!1);if(!s)return!1;let r=s.pop(n,e,t);return r?(i(r),!0):!1}}const h0=na(0,!1),fc=na(1,!1),Tk=na(0,!0),Dk=na(1,!0);class Je{constructor(t,e,i,s,r){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(t){return new Je(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(e=this.mapped)===null||e===void 0?void 0:e.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(t){return new Je(t.changes&&A.ChangeSet.fromJSON(t.changes),[],t.mapped&&A.ChangeDesc.fromJSON(t.mapped),t.startSelection&&A.EditorSelection.fromJSON(t.startSelection),t.selectionsAfter.map(A.EditorSelection.fromJSON))}static fromTransaction(t,e){let i=yi;for(let s of t.startState.facet(Mk)){let r=s(t);r.length&&(i=i.concat(r))}return!i.length&&t.changes.empty?null:new Je(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,yi)}static selection(t){return new Je(void 0,yi,void 0,void 0,t)}}function Bl(n,t,e,i){let s=t+1>e+20?t-e-1:0,r=n.slice(s,t);return r.push(i),r}function Ok(n,t){let e=[],i=!1;return n.iterChangedRanges((s,r)=>e.push(s,r)),t.iterChangedRanges((s,r,l,h)=>{for(let c=0;c<e.length;){let g=e[c++],p=e[c++];h>=g&&l<=p&&(i=!0)}}),i}function Ek(n,t){return n.ranges.length==t.ranges.length&&n.ranges.filter((e,i)=>e.empty!=t.ranges[i].empty).length===0}function c0(n,t){return n.length?t.length?n.concat(t):n:t}const yi=[],Pk=200;function f0(n,t){if(n.length){let e=n[n.length-1],i=e.selectionsAfter.slice(Math.max(0,e.selectionsAfter.length-Pk));return i.length&&i[i.length-1].eq(t)?n:(i.push(t),Bl(n,n.length-1,1e9,e.setSelAfter(i)))}else return[Je.selection([t])]}function Rk(n){let t=n[n.length-1],e=n.slice();return e[n.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),e}function rh(n,t){if(!n.length)return n;let e=n.length,i=yi;for(;e;){let s=Bk(n[e-1],t,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,e);return r[e-1]=s,r}else t=s.mapped,e--,i=s.selectionsAfter}return i.length?[Je.selection(i)]:yi}function Bk(n,t,e){let i=c0(n.selectionsAfter.length?n.selectionsAfter.map(h=>h.map(t)):yi,e);if(!n.changes)return Je.selection(i);let s=n.changes.map(t),r=t.mapDesc(n.changes,!0),l=n.mapped?n.mapped.composeDesc(r):r;return new Je(s,A.StateEffect.mapEffects(n.effects,t),l,n.startSelection.map(r),i)}const Lk=/^(input\.type|delete)($|\.)/;class ji{constructor(t,e,i=0,s=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new ji(this.done,this.undone):this}addChanges(t,e,i,s,r){let l=this.done,h=l[l.length-1];return h&&h.changes&&!h.changes.empty&&t.changes&&(!i||Lk.test(i))&&(!h.selectionsAfter.length&&e-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,Ok(h.changes,t.changes))||i=="input.type.compose")?l=Bl(l,l.length-1,s.minDepth,new Je(t.changes.compose(h.changes),c0(A.StateEffect.mapEffects(t.effects,h.changes),h.effects),h.mapped,h.startSelection,yi)):l=Bl(l,l.length,s.minDepth,t),new ji(l,yi,e,i)}addSelection(t,e,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:yi;return r.length>0&&e-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Ek(r[r.length-1],t)?this:new ji(f0(this.done,t),this.undone,e,i)}addMapping(t){return new ji(rh(this.done,t),rh(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let s=t==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1],l=r.selectionsAfter[0]||e.selection;if(i&&r.selectionsAfter.length)return e.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:cc.of({side:t,rest:Rk(s),selection:l}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let h=s.length==1?yi:s.slice(0,s.length-1);return r.mapped&&(h=rh(h,r.mapped)),e.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:cc.of({side:t,rest:h,selection:l}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}ji.empty=new ji(yi,yi);const Nk=[{key:"Mod-z",run:h0,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:fc,preventDefault:!0},{linux:"Ctrl-Shift-z",run:fc,preventDefault:!0},{key:"Mod-u",run:Tk,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Dk,preventDefault:!0}];function Qs(n,t){return A.EditorSelection.create(n.ranges.map(t),n.mainIndex)}function Qi(n,t){return n.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function Li({state:n,dispatch:t},e){let i=Qs(n.selection,e);return i.eq(n.selection,!0)?!1:(t(Qi(n,i)),!0)}function sa(n,t){return A.EditorSelection.cursor(t?n.to:n.from)}function d0(n,t){return Li(n,e=>e.empty?n.moveByChar(e,t):sa(e,t))}function Ne(n){return n.textDirectionAt(n.state.selection.main.head)==Qt.LTR}const u0=n=>d0(n,!Ne(n)),p0=n=>d0(n,Ne(n));function g0(n,t){return Li(n,e=>e.empty?n.moveByGroup(e,t):sa(e,t))}const Fk=n=>g0(n,!Ne(n)),Ik=n=>g0(n,Ne(n));function Hk(n,t,e){if(t.type.prop(e))return!0;let i=t.to-t.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(t.from,t.to)))||t.firstChild}function ra(n,t,e){let i=ie(n).resolveInner(t.head),s=e?qe.closedBy:qe.openedBy;for(let c=t.head;;){let g=e?i.childAfter(c):i.childBefore(c);if(!g)break;Hk(n,g,s)?i=g:c=e?g.to:g.from}let r=i.type.prop(s),l,h;return r&&(l=e?Ki(n,i.from,1):Ki(n,i.to,-1))&&l.matched?h=e?l.end.to:l.end.from:h=e?i.to:i.from,A.EditorSelection.cursor(h,e?-1:1)}const Vk=n=>Li(n,t=>ra(n.state,t,!Ne(n))),$k=n=>Li(n,t=>ra(n.state,t,Ne(n)));function m0(n,t){return Li(n,e=>{if(!e.empty)return sa(e,t);let i=n.moveVertically(e,t);return i.head!=e.head?i:n.moveToLineBoundary(e,t)})}const b0=n=>m0(n,!1),y0=n=>m0(n,!0);function S0(n){let t=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,e=0,i=0,s;if(t){for(let r of n.state.facet(mt.scrollMargins)){let l=r(n);l!=null&&l.top&&(e=Math.max(l==null?void 0:l.top,e)),l!=null&&l.bottom&&(i=Math.max(l==null?void 0:l.bottom,i))}s=n.scrollDOM.clientHeight-e-i}else s=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:e,marginBottom:i,selfScroll:t,height:Math.max(n.defaultLineHeight,s-5)}}function w0(n,t){let e=S0(n),{state:i}=n,s=Qs(i.selection,l=>l.empty?n.moveVertically(l,t,e.height):sa(l,t));if(s.eq(i.selection))return!1;let r;if(e.selfScroll){let l=n.coordsAtPos(i.selection.main.head),h=n.scrollDOM.getBoundingClientRect(),c=h.top+e.marginTop,g=h.bottom-e.marginBottom;l&&l.top>c&&l.bottom<g&&(r=mt.scrollIntoView(s.main.head,{y:"start",yMargin:l.top-c}))}return n.dispatch(Qi(i,s),{effects:r}),!0}const Iu=n=>w0(n,!1),dc=n=>w0(n,!0);function zn(n,t,e){let i=n.lineBlockAt(t.head),s=n.moveToLineBoundary(t,e);if(s.head==t.head&&s.head!=(e?i.to:i.from)&&(s=n.moveToLineBoundary(t,e,!1)),!e&&s.head==i.from&&i.length){let r=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&t.head!=i.from+r&&(s=A.EditorSelection.cursor(i.from+r))}return s}const Wk=n=>Li(n,t=>zn(n,t,!0)),zk=n=>Li(n,t=>zn(n,t,!1)),qk=n=>Li(n,t=>zn(n,t,!Ne(n))),Kk=n=>Li(n,t=>zn(n,t,Ne(n))),jk=n=>Li(n,t=>A.EditorSelection.cursor(n.lineBlockAt(t.head).from,1)),_k=n=>Li(n,t=>A.EditorSelection.cursor(n.lineBlockAt(t.head).to,-1));function Gk(n,t,e){let i=!1,s=Qs(n.selection,r=>{let l=Ki(n,r.head,-1)||Ki(n,r.head,1)||r.head>0&&Ki(n,r.head-1,1)||r.head<n.doc.length&&Ki(n,r.head+1,-1);if(!l||!l.end)return r;i=!0;let h=l.start.from==r.head?l.end.to:l.end.from;return A.EditorSelection.cursor(h)});return i?(t(Qi(n,s)),!0):!1}const Yk=({state:n,dispatch:t})=>Gk(n,t);function vi(n,t){let e=Qs(n.state.selection,i=>{let s=t(i);return A.EditorSelection.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return e.eq(n.state.selection)?!1:(n.dispatch(Qi(n.state,e)),!0)}function x0(n,t){return vi(n,e=>n.moveByChar(e,t))}const v0=n=>x0(n,!Ne(n)),k0=n=>x0(n,Ne(n));function C0(n,t){return vi(n,e=>n.moveByGroup(e,t))}const Uk=n=>C0(n,!Ne(n)),Xk=n=>C0(n,Ne(n)),Jk=n=>vi(n,t=>ra(n.state,t,!Ne(n))),Qk=n=>vi(n,t=>ra(n.state,t,Ne(n)));function M0(n,t){return vi(n,e=>n.moveVertically(e,t))}const A0=n=>M0(n,!1),T0=n=>M0(n,!0);function D0(n,t){return vi(n,e=>n.moveVertically(e,t,S0(n).height))}const Hu=n=>D0(n,!1),Vu=n=>D0(n,!0),Zk=n=>vi(n,t=>zn(n,t,!0)),tC=n=>vi(n,t=>zn(n,t,!1)),eC=n=>vi(n,t=>zn(n,t,!Ne(n))),iC=n=>vi(n,t=>zn(n,t,Ne(n))),nC=n=>vi(n,t=>A.EditorSelection.cursor(n.lineBlockAt(t.head).from)),sC=n=>vi(n,t=>A.EditorSelection.cursor(n.lineBlockAt(t.head).to)),$u=({state:n,dispatch:t})=>(t(Qi(n,{anchor:0})),!0),Wu=({state:n,dispatch:t})=>(t(Qi(n,{anchor:n.doc.length})),!0),zu=({state:n,dispatch:t})=>(t(Qi(n,{anchor:n.selection.main.anchor,head:0})),!0),qu=({state:n,dispatch:t})=>(t(Qi(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),rC=({state:n,dispatch:t})=>(t(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),oC=({state:n,dispatch:t})=>{let e=oa(n).map(({from:i,to:s})=>A.EditorSelection.range(i,Math.min(s+1,n.doc.length)));return t(n.update({selection:A.EditorSelection.create(e),userEvent:"select"})),!0},lC=({state:n,dispatch:t})=>{let e=Qs(n.selection,i=>{let s=ie(n),r=s.resolveStack(i.from,1);if(i.empty){let l=s.resolveStack(i.from,-1);l.node.from>=r.node.from&&l.node.to<=r.node.to&&(r=l)}for(let l=r;l;l=l.next){let{node:h}=l;if((h.from<i.from&&h.to>=i.to||h.to>i.to&&h.from<=i.from)&&l.next)return A.EditorSelection.range(h.to,h.from)}return i});return e.eq(n.selection)?!1:(t(Qi(n,e)),!0)},aC=({state:n,dispatch:t})=>{let e=n.selection,i=null;return e.ranges.length>1?i=A.EditorSelection.create([e.main]):e.main.empty||(i=A.EditorSelection.create([A.EditorSelection.cursor(e.main.head)])),i?(t(Qi(n,i)),!0):!1};function io(n,t){if(n.state.readOnly)return!1;let e="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:l,to:h}=r;if(l==h){let c=t(r);c<l?(e="delete.backward",c=Go(n,c,!1)):c>l&&(e="delete.forward",c=Go(n,c,!0)),l=Math.min(l,c),h=Math.max(h,c)}else l=Go(n,l,!1),h=Go(n,h,!0);return l==h?{range:r}:{changes:{from:l,to:h},range:A.EditorSelection.cursor(l,l<r.head?-1:1)}});return s.changes.empty?!1:(n.dispatch(i.update(s,{scrollIntoView:!0,userEvent:e,effects:e=="delete.selection"?mt.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Go(n,t,e){if(n instanceof mt)for(let i of n.state.facet(mt.atomicRanges).map(s=>s(n)))i.between(t,t,(s,r)=>{s<t&&r>t&&(t=e?r:s)});return t}const O0=(n,t,e)=>io(n,i=>{let s=i.from,{state:r}=n,l=r.doc.lineAt(s),h,c;if(e&&!t&&s>l.from&&s<l.from+200&&!/[^ \t]/.test(h=l.text.slice(0,s-l.from))){if(h[h.length-1]==" ")return s-1;let g=A.countColumn(h,r.tabSize),p=g%El(r)||El(r);for(let y=0;y<p&&h[h.length-1-y]==" ";y++)s--;c=s}else c=A.findClusterBreak(l.text,s-l.from,t,t)+l.from,c==s&&l.number!=(t?r.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(l.text.slice(c-l.from,s-l.from))&&(c=A.findClusterBreak(l.text,c-l.from,!1,!1)+l.from);return c}),uc=n=>O0(n,!1,!0),E0=n=>O0(n,!0,!1),P0=(n,t)=>io(n,e=>{let i=e.head,{state:s}=n,r=s.doc.lineAt(i),l=s.charCategorizer(i);for(let h=null;;){if(i==(t?r.to:r.from)){i==e.head&&r.number!=(t?s.doc.lines:1)&&(i+=t?1:-1);break}let c=A.findClusterBreak(r.text,i-r.from,t)+r.from,g=r.text.slice(Math.min(i,c)-r.from,Math.max(i,c)-r.from),p=l(g);if(h!=null&&p!=h)break;(g!=" "||i!=e.head)&&(h=p),i=c}return i}),R0=n=>P0(n,!1),hC=n=>P0(n,!0),cC=n=>io(n,t=>{let e=n.lineBlockAt(t.head).to;return t.head<e?e:Math.min(n.state.doc.length,t.head+1)}),fC=n=>io(n,t=>{let e=n.moveToLineBoundary(t,!1).head;return t.head>e?e:Math.max(0,t.head-1)}),dC=n=>io(n,t=>{let e=n.moveToLineBoundary(t,!0).head;return t.head<e?e:Math.min(n.state.doc.length,t.head+1)}),uC=({state:n,dispatch:t})=>{if(n.readOnly)return!1;let e=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:A.Text.of(["",""])},range:A.EditorSelection.cursor(i.from)}));return t(n.update(e,{scrollIntoView:!0,userEvent:"input"})),!0},pC=({state:n,dispatch:t})=>{if(n.readOnly)return!1;let e=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let s=i.from,r=n.doc.lineAt(s),l=s==r.from?s-1:A.findClusterBreak(r.text,s-r.from,!1)+r.from,h=s==r.to?s+1:A.findClusterBreak(r.text,s-r.from,!0)+r.from;return{changes:{from:l,to:h,insert:n.doc.slice(s,h).append(n.doc.slice(l,s))},range:A.EditorSelection.cursor(h)}});return e.changes.empty?!1:(t(n.update(e,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function oa(n){let t=[],e=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.from),r=n.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=n.doc.lineAt(i.to-1)),e>=s.number){let l=t[t.length-1];l.to=r.to,l.ranges.push(i)}else t.push({from:s.from,to:r.to,ranges:[i]});e=r.number+1}return t}function B0(n,t,e){if(n.readOnly)return!1;let i=[],s=[];for(let r of oa(n)){if(e?r.to==n.doc.length:r.from==0)continue;let l=n.doc.lineAt(e?r.to+1:r.from-1),h=l.length+1;if(e){i.push({from:r.to,to:l.to},{from:r.from,insert:l.text+n.lineBreak});for(let c of r.ranges)s.push(A.EditorSelection.range(Math.min(n.doc.length,c.anchor+h),Math.min(n.doc.length,c.head+h)))}else{i.push({from:l.from,to:r.from},{from:r.to,insert:n.lineBreak+l.text});for(let c of r.ranges)s.push(A.EditorSelection.range(c.anchor-h,c.head-h))}}return i.length?(t(n.update({changes:i,scrollIntoView:!0,selection:A.EditorSelection.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const gC=({state:n,dispatch:t})=>B0(n,t,!1),mC=({state:n,dispatch:t})=>B0(n,t,!0);function L0(n,t,e){if(n.readOnly)return!1;let i=[];for(let s of oa(n))e?i.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):i.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});return t(n.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const bC=({state:n,dispatch:t})=>L0(n,t,!1),yC=({state:n,dispatch:t})=>L0(n,t,!0),SC=n=>{if(n.state.readOnly)return!1;let{state:t}=n,e=t.changes(oa(t).map(({from:s,to:r})=>(s>0?s--:r<t.doc.length&&r++,{from:s,to:r}))),i=Qs(t.selection,s=>{let r;if(n.lineWrapping){let l=n.lineBlockAt(s.head),h=n.coordsAtPos(s.head,s.assoc||1);h&&(r=l.bottom+n.documentTop-h.bottom+n.defaultLineHeight/2)}return n.moveVertically(s,!0,r)}).map(e);return n.dispatch({changes:e,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function wC(n,t){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(t-1,t+1)))return{from:t,to:t};let e=ie(n).resolveInner(t),i=e.childBefore(t),s=e.childAfter(t),r;return i&&s&&i.to<=t&&s.from>=t&&(r=i.type.prop(qe.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from&&!/\S/.test(n.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}const Ku=N0(!1),xC=N0(!0);function N0(n){return({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange(s=>{let{from:r,to:l}=s,h=t.doc.lineAt(r),c=!n&&r==l&&wC(t,r);n&&(r=l=(l<=h.to?h:t.doc.lineAt(l)).to);let g=new ea(t,{simulateBreak:r,simulateDoubleBreak:!!c}),p=Xc(g,r);for(p==null&&(p=A.countColumn(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize));l<h.to&&/\s/.test(h.text[l-h.from]);)l++;c?{from:r,to:l}=c:r>h.from&&r<h.from+100&&!/\S/.test(h.text.slice(0,r))&&(r=h.from);let y=["",zr(t,p)];return c&&y.push(zr(t,g.lineIndent(h.from,-1))),{changes:{from:r,to:l,insert:A.Text.of(y)},range:A.EditorSelection.cursor(r+1+y[1].length)}});return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function sf(n,t){let e=-1;return n.changeByRange(i=>{let s=[];for(let l=i.from;l<=i.to;){let h=n.doc.lineAt(l);h.number>e&&(i.empty||i.to>h.from)&&(t(h,s,i),e=h.number),l=h.to+1}let r=n.changes(s);return{changes:s,range:A.EditorSelection.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const vC=({state:n,dispatch:t})=>{if(n.readOnly)return!1;let e=Object.create(null),i=new ea(n,{overrideIndentation:r=>{let l=e[r];return l??-1}}),s=sf(n,(r,l,h)=>{let c=Xc(i,r.from);if(c==null)return;/\S/.test(r.text)||(c=0);let g=/^\s*/.exec(r.text)[0],p=zr(n,c);(g!=p||h.from<r.from+g.length)&&(e[r.from]=c,l.push({from:r.from,to:r.from+g.length,insert:p}))});return s.changes.empty||t(n.update(s,{userEvent:"indent"})),!0},F0=({state:n,dispatch:t})=>n.readOnly?!1:(t(n.update(sf(n,(e,i)=>{i.push({from:e.from,insert:n.facet(Js)})}),{userEvent:"input.indent"})),!0),I0=({state:n,dispatch:t})=>n.readOnly?!1:(t(n.update(sf(n,(e,i)=>{let s=/^\s*/.exec(e.text)[0];if(!s)return;let r=A.countColumn(s,n.tabSize),l=0,h=zr(n,Math.max(0,r-El(n)));for(;l<s.length&&l<h.length&&s.charCodeAt(l)==h.charCodeAt(l);)l++;i.push({from:e.from+l,to:e.from+s.length,insert:h.slice(l)})}),{userEvent:"delete.dedent"})),!0),kC=n=>(n.setTabFocusMode(),!0),CC=[{key:"Ctrl-b",run:u0,shift:v0,preventDefault:!0},{key:"Ctrl-f",run:p0,shift:k0},{key:"Ctrl-p",run:b0,shift:A0},{key:"Ctrl-n",run:y0,shift:T0},{key:"Ctrl-a",run:jk,shift:nC},{key:"Ctrl-e",run:_k,shift:sC},{key:"Ctrl-d",run:E0},{key:"Ctrl-h",run:uc},{key:"Ctrl-k",run:cC},{key:"Ctrl-Alt-h",run:R0},{key:"Ctrl-o",run:uC},{key:"Ctrl-t",run:pC},{key:"Ctrl-v",run:dc}],MC=[{key:"ArrowLeft",run:u0,shift:v0,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Fk,shift:Uk,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:qk,shift:eC,preventDefault:!0},{key:"ArrowRight",run:p0,shift:k0,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Ik,shift:Xk,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Kk,shift:iC,preventDefault:!0},{key:"ArrowUp",run:b0,shift:A0,preventDefault:!0},{mac:"Cmd-ArrowUp",run:$u,shift:zu},{mac:"Ctrl-ArrowUp",run:Iu,shift:Hu},{key:"ArrowDown",run:y0,shift:T0,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Wu,shift:qu},{mac:"Ctrl-ArrowDown",run:dc,shift:Vu},{key:"PageUp",run:Iu,shift:Hu},{key:"PageDown",run:dc,shift:Vu},{key:"Home",run:zk,shift:tC,preventDefault:!0},{key:"Mod-Home",run:$u,shift:zu},{key:"End",run:Wk,shift:Zk,preventDefault:!0},{key:"Mod-End",run:Wu,shift:qu},{key:"Enter",run:Ku,shift:Ku},{key:"Mod-a",run:rC},{key:"Backspace",run:uc,shift:uc},{key:"Delete",run:E0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:R0},{key:"Mod-Delete",mac:"Alt-Delete",run:hC},{mac:"Mod-Backspace",run:fC},{mac:"Mod-Delete",run:dC}].concat(CC.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),AC=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Vk,shift:Jk},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:$k,shift:Qk},{key:"Alt-ArrowUp",run:gC},{key:"Shift-Alt-ArrowUp",run:bC},{key:"Alt-ArrowDown",run:mC},{key:"Shift-Alt-ArrowDown",run:yC},{key:"Escape",run:aC},{key:"Mod-Enter",run:xC},{key:"Alt-l",mac:"Ctrl-l",run:oC},{key:"Mod-i",run:lC,preventDefault:!0},{key:"Mod-[",run:I0},{key:"Mod-]",run:F0},{key:"Mod-Alt-\\",run:vC},{key:"Shift-Mod-k",run:SC},{key:"Shift-Mod-\\",run:Yk},{key:"Mod-/",run:bk},{key:"Alt-A",run:Sk},{key:"Ctrl-m",mac:"Shift-Alt-m",run:kC}].concat(MC),TC={key:"Tab",run:F0,shift:I0};var vs={},xt={},oh={},ju;function DC(){return ju||(ju=1,function(n){var t=Vc(),e=xg(),i=FS();function s(u){let o;return u.nodeType==11?o=u.getSelection?u:u.ownerDocument:o=u,o.getSelection()}function r(u,o){return o?u==o||u.contains(o.nodeType!=1?o.parentNode:o):!1}function l(u){let o=u.activeElement;for(;o&&o.shadowRoot;)o=o.shadowRoot.activeElement;return o}function h(u,o){if(!o.anchorNode)return!1;try{return r(u,o.anchorNode)}catch{return!1}}function c(u){return u.nodeType==3?wt(u,0,u.nodeValue.length).getClientRects():u.nodeType==1?u.getClientRects():[]}function g(u,o,a,f){return a?x(u,o,a,f,-1)||x(u,o,a,f,1):!1}function p(u){for(var o=0;;o++)if(u=u.previousSibling,!u)return o}function y(u){return u.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(u.nodeName)}function x(u,o,a,f,d){for(;;){if(u==a&&o==f)return!0;if(o==(d<0?0:T(u))){if(u.nodeName=="DIV")return!1;let m=u.parentNode;if(!m||m.nodeType!=1)return!1;o=p(u)+(d<0?0:1),u=m}else if(u.nodeType==1){if(u=u.childNodes[o+(d<0?-1:0)],u.nodeType==1&&u.contentEditable=="false")return!1;o=d<0?T(u):0}else return!1}}function T(u){return u.nodeType==3?u.nodeValue.length:u.childNodes.length}function P(u,o){let a=o?u.left:u.right;return{left:a,right:a,top:u.top,bottom:u.bottom}}function I(u){let o=u.visualViewport;return o?{left:0,right:o.width,top:0,bottom:o.height}:{left:0,right:u.innerWidth,top:0,bottom:u.innerHeight}}function z(u,o){let a=o.width/u.offsetWidth,f=o.height/u.offsetHeight;return(a>.995&&a<1.005||!isFinite(a)||Math.abs(o.width-u.offsetWidth)<1)&&(a=1),(f>.995&&f<1.005||!isFinite(f)||Math.abs(o.height-u.offsetHeight)<1)&&(f=1),{scaleX:a,scaleY:f}}function W(u,o,a,f,d,m,S,k){let M=u.ownerDocument,B=M.defaultView||window;for(let E=u,H=!1;E&&!H;)if(E.nodeType==1){let K,Y=E==M.body,X=1,it=1;if(Y)K=I(B);else{if(/^(fixed|sticky)$/.test(getComputedStyle(E).position)&&(H=!0),E.scrollHeight<=E.clientHeight&&E.scrollWidth<=E.clientWidth){E=E.assignedSlot||E.parentNode;continue}let bt=E.getBoundingClientRect();({scaleX:X,scaleY:it}=z(E,bt)),K={left:bt.left,right:bt.left+E.clientWidth*X,top:bt.top,bottom:bt.top+E.clientHeight*it}}let rt=0,nt=0;if(d=="nearest")o.top<K.top?(nt=-(K.top-o.top+S),a>0&&o.bottom>K.bottom+nt&&(nt=o.bottom-K.bottom+nt+S)):o.bottom>K.bottom&&(nt=o.bottom-K.bottom+S,a<0&&o.top-nt<K.top&&(nt=-(K.top+nt-o.top+S)));else{let bt=o.bottom-o.top,Ct=K.bottom-K.top;nt=(d=="center"&&bt<=Ct?o.top+bt/2-Ct/2:d=="start"||d=="center"&&a<0?o.top-S:o.bottom-Ct+S)-K.top}if(f=="nearest"?o.left<K.left?(rt=-(K.left-o.left+m),a>0&&o.right>K.right+rt&&(rt=o.right-K.right+rt+m)):o.right>K.right&&(rt=o.right-K.right+m,a<0&&o.left<K.left+rt&&(rt=-(K.left+rt-o.left+m))):rt=(f=="center"?o.left+(o.right-o.left)/2-(K.right-K.left)/2:f=="start"==k?o.left-m:o.right-(K.right-K.left)+m)-K.left,rt||nt)if(Y)B.scrollBy(rt,nt);else{let bt=0,Ct=0;if(nt){let St=E.scrollTop;E.scrollTop+=nt/it,Ct=(E.scrollTop-St)*it}if(rt){let St=E.scrollLeft;E.scrollLeft+=rt/X,bt=(E.scrollLeft-St)*X}o={left:o.left-bt,top:o.top-Ct,right:o.right-bt,bottom:o.bottom-Ct},bt&&Math.abs(bt-rt)<1&&(f="nearest"),Ct&&Math.abs(Ct-nt)<1&&(d="nearest")}if(Y)break;E=E.assignedSlot||E.parentNode}else if(E.nodeType==11)E=E.host;else break}function U(u){let o=u.ownerDocument,a,f;for(let d=u.parentNode;d&&!(d==o.body||a&&f);)if(d.nodeType==1)!f&&d.scrollHeight>d.clientHeight&&(f=d),!a&&d.scrollWidth>d.clientWidth&&(a=d),d=d.assignedSlot||d.parentNode;else if(d.nodeType==11)d=d.host;else break;return{x:a,y:f}}class ot{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(o){return this.anchorNode==o.anchorNode&&this.anchorOffset==o.anchorOffset&&this.focusNode==o.focusNode&&this.focusOffset==o.focusOffset}setRange(o){let{anchorNode:a,focusNode:f}=o;this.set(a,Math.min(o.anchorOffset,a?T(a):0),f,Math.min(o.focusOffset,f?T(f):0))}set(o,a,f,d){this.anchorNode=o,this.anchorOffset=a,this.focusNode=f,this.focusOffset=d}}let Q=null;function st(u){if(u.setActive)return u.setActive();if(Q)return u.focus(Q);let o=[];for(let a=u;a&&(o.push(a,a.scrollTop,a.scrollLeft),a!=a.ownerDocument);a=a.parentNode);if(u.focus(Q==null?{get preventScroll(){return Q={preventScroll:!0},!0}}:void 0),!Q){Q=!1;for(let a=0;a<o.length;){let f=o[a++],d=o[a++],m=o[a++];f.scrollTop!=d&&(f.scrollTop=d),f.scrollLeft!=m&&(f.scrollLeft=m)}}}let at;function wt(u,o,a=o){let f=at||(at=document.createRange());return f.setEnd(u,a),f.setStart(u,o),f}function Pt(u,o,a,f){let d={key:o,code:o,keyCode:a,which:a,cancelable:!0};f&&({altKey:d.altKey,ctrlKey:d.ctrlKey,shiftKey:d.shiftKey,metaKey:d.metaKey}=f);let m=new KeyboardEvent("keydown",d);m.synthetic=!0,u.dispatchEvent(m);let S=new KeyboardEvent("keyup",d);return S.synthetic=!0,u.dispatchEvent(S),m.defaultPrevented||S.defaultPrevented}function Tt(u){for(;u;){if(u&&(u.nodeType==9||u.nodeType==11&&u.host))return u;u=u.assignedSlot||u.parentNode}return null}function le(u){for(;u.attributes.length;)u.removeAttributeNode(u.attributes[0])}function ae(u,o){let a=o.focusNode,f=o.focusOffset;if(!a||o.anchorNode!=a||o.anchorOffset!=f)return!1;for(f=Math.min(f,T(a));;)if(f){if(a.nodeType!=1)return!1;let d=a.childNodes[f-1];d.contentEditable=="false"?f--:(a=d,f=T(a))}else{if(a==u)return!0;f=p(a),a=a.parentNode}}function zt(u){return u.scrollTop>Math.max(1,u.scrollHeight-u.clientHeight-4)}function Ot(u,o){for(let a=u,f=o;;){if(a.nodeType==3&&f>0)return{node:a,offset:f};if(a.nodeType==1&&f>0){if(a.contentEditable=="false")return null;a=a.childNodes[f-1],f=T(a)}else if(a.parentNode&&!y(a))f=p(a),a=a.parentNode;else return null}}function ne(u,o){for(let a=u,f=o;;){if(a.nodeType==3&&f<a.nodeValue.length)return{node:a,offset:f};if(a.nodeType==1&&f<a.childNodes.length){if(a.contentEditable=="false")return null;a=a.childNodes[f],f=0}else if(a.parentNode&&!y(a))f=p(a)+1,a=a.parentNode;else return null}}class Rt{constructor(o,a,f=!0){this.node=o,this.offset=a,this.precise=f}static before(o,a){return new Rt(o.parentNode,p(o),a)}static after(o,a){return new Rt(o.parentNode,p(o)+1,a)}}const Bt=[];class vt{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(o){let a=this.posAtStart;for(let f of this.children){if(f==o)return a;a+=f.length+f.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(o){return this.posBefore(o)+o.length}sync(o,a){if(this.flags&2){let f=this.dom,d=null,m;for(let S of this.children){if(S.flags&7){if(!S.dom&&(m=d?d.nextSibling:f.firstChild)){let k=vt.get(m);(!k||!k.parent&&k.canReuseDOM(S))&&S.reuseDOM(m)}S.sync(o,a),S.flags&=-8}if(m=d?d.nextSibling:f.firstChild,a&&!a.written&&a.node==f&&m!=S.dom&&(a.written=!0),S.dom.parentNode==f)for(;m&&m!=S.dom;)m=Zt(m);else f.insertBefore(S.dom,m);d=S.dom}for(m=d?d.nextSibling:f.firstChild,m&&a&&a.node==f&&(a.written=!0);m;)m=Zt(m)}else if(this.flags&1)for(let f of this.children)f.flags&7&&(f.sync(o,a),f.flags&=-8)}reuseDOM(o){}localPosFromDOM(o,a){let f;if(o==this.dom)f=this.dom.childNodes[a];else{let d=T(o)==0?0:a==0?-1:1;for(;;){let m=o.parentNode;if(m==this.dom)break;d==0&&m.firstChild!=m.lastChild&&(o==m.firstChild?d=-1:d=1),o=m}d<0?f=o:f=o.nextSibling}if(f==this.dom.firstChild)return 0;for(;f&&!vt.get(f);)f=f.nextSibling;if(!f)return this.length;for(let d=0,m=0;;d++){let S=this.children[d];if(S.dom==f)return m;m+=S.length+S.breakAfter}}domBoundsAround(o,a,f=0){let d=-1,m=-1,S=-1,k=-1;for(let M=0,B=f,E=f;M<this.children.length;M++){let H=this.children[M],K=B+H.length;if(B<o&&K>a)return H.domBoundsAround(o,a,B);if(K>=o&&d==-1&&(d=M,m=B),B>a&&H.dom.parentNode==this.dom){S=M,k=E;break}E=K,B=K+H.breakAfter}return{from:m,to:k<0?f+this.length:k,startDOM:(d?this.children[d-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:S<this.children.length&&S>=0?this.children[S].dom:null}}markDirty(o=!1){this.flags|=2,this.markParentsDirty(o)}markParentsDirty(o){for(let a=this.parent;a;a=a.parent){if(o&&(a.flags|=2),a.flags&1)return;a.flags|=1,o=!1}}setParent(o){this.parent!=o&&(this.parent=o,this.flags&7&&this.markParentsDirty(!0))}setDOM(o){this.dom!=o&&(this.dom&&(this.dom.cmView=null),this.dom=o,o.cmView=this)}get rootView(){for(let o=this;;){let a=o.parent;if(!a)return o;o=a}}replaceChildren(o,a,f=Bt){this.markDirty();for(let d=o;d<a;d++){let m=this.children[d];m.parent==this&&f.indexOf(m)<0&&m.destroy()}this.children.splice(o,a-o,...f);for(let d=0;d<f.length;d++)f[d].setParent(this)}ignoreMutation(o){return!1}ignoreEvent(o){return!1}childCursor(o=this.length){return new se(this.children,o,this.children.length)}childPos(o,a=1){return this.childCursor().findPos(o,a)}toString(){let o=this.constructor.name.replace("View","");return o+(this.children.length?"("+this.children.join()+")":this.length?"["+(o=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(o){return o.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(o,a,f,d,m,S){return!1}become(o){return!1}canReuseDOM(o){return o.constructor==this.constructor&&!((this.flags|o.flags)&8)}getSide(){return 0}destroy(){for(let o of this.children)o.parent==this&&o.destroy();this.parent=null}}vt.prototype.breakAfter=0;function Zt(u){let o=u.nextSibling;return u.parentNode.removeChild(u),o}class se{constructor(o,a,f){this.children=o,this.pos=a,this.i=f,this.off=0}findPos(o,a=1){for(;;){if(o>this.pos||o==this.pos&&(a>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=o-this.pos,this;let f=this.children[--this.i];this.pos-=f.length+f.breakAfter}}}function ue(u,o,a,f,d,m,S,k,M){let{children:B}=u,E=B.length?B[o]:null,H=m.length?m[m.length-1]:null,K=H?H.breakAfter:S;if(!(o==f&&E&&!S&&!K&&m.length<2&&E.merge(a,d,m.length?H:null,a==0,k,M))){if(f<B.length){let Y=B[f];Y&&(d<Y.length||Y.breakAfter&&(H!=null&&H.breakAfter))?(o==f&&(Y=Y.split(d),d=0),!K&&H&&Y.merge(0,d,H,!0,0,M)?m[m.length-1]=Y:((d||Y.children.length&&!Y.children[0].length)&&Y.merge(0,d,null,!1,0,M),m.push(Y))):Y!=null&&Y.breakAfter&&(H?H.breakAfter=1:S=1),f++}for(E&&(E.breakAfter=S,a>0&&(!S&&m.length&&E.merge(a,E.length,m[0],!1,k,0)?E.breakAfter=m.shift().breakAfter:(a<E.length||E.children.length&&E.children[E.children.length-1].length==0)&&E.merge(a,E.length,null,!1,k,0),o++));o<f&&m.length;)if(B[f-1].become(m[m.length-1]))f--,m.pop(),M=m.length?0:k;else if(B[o].become(m[0]))o++,m.shift(),k=m.length?0:M;else break;!m.length&&o&&f<B.length&&!B[o-1].breakAfter&&B[f].merge(0,0,B[o-1],!1,k,M)&&o--,(o<f||m.length)&&u.replaceChildren(o,f,m)}}function qn(u,o,a,f,d,m){let S=u.childCursor(),{i:k,off:M}=S.findPos(a,1),{i:B,off:E}=S.findPos(o,-1),H=o-a;for(let K of f)H+=K.length;u.length+=H,ue(u,B,E,k,M,f,0,d,m)}let he=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Qe=typeof document<"u"?document:{documentElement:{style:{}}};const Ze=/Edge\/(\d+)/.exec(he.userAgent),ti=/MSIE \d/.test(he.userAgent),Kn=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(he.userAgent),Zi=!!(ti||Kn||Ze),Ni=!Zi&&/gecko\/(\d+)/i.test(he.userAgent),Fi=!Zi&&/Chrome\/(\d+)/.exec(he.userAgent),gn="webkitFontSmoothing"in Qe.documentElement.style,as=!Zi&&/Apple Computer/.test(he.vendor),Ii=as&&(/Mobile\/\w+/.test(he.userAgent)||he.maxTouchPoints>2);var ft={mac:Ii||/Mac/.test(he.platform),windows:/Win/.test(he.platform),linux:/Linux|X11/.test(he.platform),ie:Zi,ie_version:ti?Qe.documentMode||6:Kn?+Kn[1]:Ze?+Ze[1]:0,gecko:Ni,gecko_version:Ni?+(/Firefox\/(\d+)/.exec(he.userAgent)||[0,0])[1]:0,chrome:!!Fi,chrome_version:Fi?+Fi[1]:0,ios:Ii,android:/Android\b/.test(he.userAgent),safari:as,webkit_version:gn?+(/\bAppleWebKit\/(\d+)/.exec(he.userAgent)||[0,0])[1]:0,tabSize:Qe.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const jn=256;class ye extends vt{constructor(o){super(),this.text=o}get length(){return this.text.length}createDOM(o){this.setDOM(o||document.createTextNode(this.text))}sync(o,a){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(a&&a.node==this.dom&&(a.written=!0),this.dom.nodeValue=this.text)}reuseDOM(o){o.nodeType==3&&this.createDOM(o)}merge(o,a,f){return this.flags&8||f&&(!(f instanceof ye)||this.length-(a-o)+f.length>jn||f.flags&8)?!1:(this.text=this.text.slice(0,o)+(f?f.text:"")+this.text.slice(a),this.markDirty(),!0)}split(o){let a=new ye(this.text.slice(o));return this.text=this.text.slice(0,o),this.markDirty(),a.flags|=this.flags&8,a}localPosFromDOM(o,a){return o==this.dom?a:a?this.text.length:0}domAtPos(o){return new Rt(this.dom,o)}domBoundsAround(o,a,f){return{from:f,to:f+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(o,a){return hs(this.dom,o,a)}}class Ke extends vt{constructor(o,a=[],f=0){super(),this.mark=o,this.children=a,this.length=f;for(let d of a)d.setParent(this)}setAttrs(o){if(le(o),this.mark.class&&(o.className=this.mark.class),this.mark.attrs)for(let a in this.mark.attrs)o.setAttribute(a,this.mark.attrs[a]);return o}canReuseDOM(o){return super.canReuseDOM(o)&&!((this.flags|o.flags)&8)}reuseDOM(o){o.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(o),this.flags|=6)}sync(o,a){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(o,a)}merge(o,a,f,d,m,S){return f&&(!(f instanceof Ke&&f.mark.eq(this.mark))||o&&m<=0||a<this.length&&S<=0)?!1:(qn(this,o,a,f?f.children.slice():[],m-1,S-1),this.markDirty(),!0)}split(o){let a=[],f=0,d=-1,m=0;for(let k of this.children){let M=f+k.length;M>o&&a.push(f<o?k.split(o-f):k),d<0&&f>=o&&(d=m),f=M,m++}let S=this.length-o;return this.length=o,d>-1&&(this.children.length=d,this.markDirty()),new Ke(this.mark,a,S)}domAtPos(o){return mn(this,o)}coordsAt(o,a){return ii(this,o,a)}}function hs(u,o,a){let f=u.nodeValue.length;o>f&&(o=f);let d=o,m=o,S=0;o==0&&a<0||o==f&&a>=0?ft.chrome||ft.gecko||(o?(d--,S=1):m<f&&(m++,S=-1)):a<0?d--:m<f&&m++;let k=wt(u,d,m).getClientRects();if(!k.length)return null;let M=k[(S?S<0:a>=0)?0:k.length-1];return ft.safari&&!S&&M.width==0&&(M=Array.prototype.find.call(k,B=>B.width)||M),S?P(M,S<0):M||null}class ei extends vt{static create(o,a,f){return new ei(o,a,f)}constructor(o,a,f){super(),this.widget=o,this.length=a,this.side=f,this.prevWidget=null}split(o){let a=ei.create(this.widget,this.length-o,this.side);return this.length-=o,a}sync(o){(!this.dom||!this.widget.updateDOM(this.dom,o))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(o)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(o,a,f,d,m,S){return f&&(!(f instanceof ei)||!this.widget.compare(f.widget)||o>0&&m<=0||a<this.length&&S<=0)?!1:(this.length=o+(f?f.length:0)+(this.length-a),!0)}become(o){return o instanceof ei&&o.side==this.side&&this.widget.constructor==o.widget.constructor?(this.widget.compare(o.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=o.widget,this.length=o.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(o){return this.widget.ignoreEvent(o)}get overrideDOMText(){if(this.length==0)return t.Text.empty;let o=this;for(;o.parent;)o=o.parent;let{view:a}=o,f=a&&a.state.doc,d=this.posAtStart;return f?f.slice(d,d+this.length):t.Text.empty}domAtPos(o){return(this.length?o==0:this.side>0)?Rt.before(this.dom):Rt.after(this.dom,o==this.length)}domBoundsAround(){return null}coordsAt(o,a){let f=this.widget.coordsAt(this.dom,o,a);if(f)return f;let d=this.dom.getClientRects(),m=null;if(!d.length)return null;let S=this.side?this.side<0:o>0;for(let k=S?d.length-1:0;m=d[k],!(o>0?k==0:k==d.length-1||m.top<m.bottom);k+=S?-1:1);return P(m,!S)}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 De extends vt{constructor(o){super(),this.side=o}get length(){return 0}merge(){return!1}become(o){return o instanceof De&&o.side==this.side}split(){return new De(this.side)}sync(){if(!this.dom){let o=document.createElement("img");o.className="cm-widgetBuffer",o.setAttribute("aria-hidden","true"),this.setDOM(o)}}getSide(){return this.side}domAtPos(o){return this.side>0?Rt.before(this.dom):Rt.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(o){return this.dom.getBoundingClientRect()}get overrideDOMText(){return t.Text.empty}get isHidden(){return!0}}ye.prototype.children=ei.prototype.children=De.prototype.children=Bt;function mn(u,o){let a=u.dom,{children:f}=u,d=0;for(let m=0;d<f.length;d++){let S=f[d],k=m+S.length;if(!(k==m&&S.getSide()<=0)){if(o>m&&o<k&&S.dom.parentNode==a)return S.domAtPos(o-m);if(o<=m)break;m=k}}for(let m=d;m>0;m--){let S=f[m-1];if(S.dom.parentNode==a)return S.domAtPos(S.length)}for(let m=d;m<f.length;m++){let S=f[m];if(S.dom.parentNode==a)return S.domAtPos(0)}return new Rt(a,0)}function Oe(u,o,a){let f,{children:d}=u;a>0&&o instanceof Ke&&d.length&&(f=d[d.length-1])instanceof Ke&&f.mark.eq(o.mark)?Oe(f,o.children[0],a-1):(d.push(o),o.setParent(u)),u.length+=o.length}function ii(u,o,a){let f=null,d=-1,m=null,S=-1;function k(B,E){for(let H=0,K=0;H<B.children.length&&K<=E;H++){let Y=B.children[H],X=K+Y.length;X>=E&&(Y.children.length?k(Y,E-K):(!m||m.isHidden&&a>0)&&(X>E||K==X&&Y.getSide()>0)?(m=Y,S=E-K):(K<E||K==X&&Y.getSide()<0&&!Y.isHidden)&&(f=Y,d=E-K)),K=X}}k(u,o);let M=(a<0?f:m)||f||m;return M?M.coordsAt(Math.max(0,M==f?d:S),a):bn(u)}function bn(u){let o=u.dom.lastChild;if(!o)return u.dom.getBoundingClientRect();let a=c(o);return a[a.length-1]||null}function Ht(u,o){for(let a in u)a=="class"&&o.class?o.class+=" "+u.class:a=="style"&&o.style?o.style+=";"+u.style:o[a]=u[a];return o}const ce=Object.create(null);function di(u,o,a){if(u==o)return!0;u||(u=ce),o||(o=ce);let f=Object.keys(u),d=Object.keys(o);if(f.length-(a&&f.indexOf(a)>-1?1:0)!=d.length-(a&&d.indexOf(a)>-1?1:0))return!1;for(let m of f)if(m!=a&&(d.indexOf(m)==-1||u[m]!==o[m]))return!1;return!0}function yn(u,o,a){let f=!1;if(o)for(let d in o)a&&d in a||(f=!0,d=="style"?u.style.cssText="":u.removeAttribute(d));if(a)for(let d in a)o&&o[d]==a[d]||(f=!0,d=="style"?u.style.cssText=a[d]:u.setAttribute(d,a[d]));return f}function tn(u){let o=Object.create(null);for(let a=0;a<u.attributes.length;a++){let f=u.attributes[a];o[f.name]=f.value}return o}class _t extends vt{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(o,a,f,d,m,S){if(f){if(!(f instanceof _t))return!1;this.dom||f.transferDOM(this)}return d&&this.setDeco(f?f.attrs:null),qn(this,o,a,f?f.children.slice():[],m,S),!0}split(o){let a=new _t;if(a.breakAfter=this.breakAfter,this.length==0)return a;let{i:f,off:d}=this.childPos(o);d&&(a.append(this.children[f].split(d),0),this.children[f].merge(d,this.children[f].length,null,!1,0,0),f++);for(let m=f;m<this.children.length;m++)a.append(this.children[m],0);for(;f>0&&this.children[f-1].length==0;)this.children[--f].destroy();return this.children.length=f,this.markDirty(),this.length=o,a}transferDOM(o){this.dom&&(this.markDirty(),o.setDOM(this.dom),o.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(o){di(this.attrs,o)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=o)}append(o,a){Oe(this,o,a)}addLineDeco(o){let a=o.spec.attributes,f=o.spec.class;a&&(this.attrs=Ht(a,this.attrs||{})),f&&(this.attrs=Ht({class:f},this.attrs||{}))}domAtPos(o){return mn(this,o)}reuseDOM(o){o.nodeName=="DIV"&&(this.setDOM(o),this.flags|=6)}sync(o,a){var f;this.dom?this.flags&4&&(le(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&&(yn(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(o,a);let d=this.dom.lastChild;for(;d&&vt.get(d)instanceof Ke;)d=d.lastChild;if(!d||!this.length||d.nodeName!="BR"&&((f=vt.get(d))===null||f===void 0?void 0:f.isEditable)==!1&&(!ft.ios||!this.children.some(m=>m instanceof ye))){let m=document.createElement("BR");m.cmIgnore=!0,this.dom.appendChild(m)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let o=0,a;for(let f of this.children){if(!(f instanceof ye)||/[^ -~]/.test(f.text))return null;let d=c(f.dom);if(d.length!=1)return null;o+=d[0].width,a=d[0].height}return o?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:o/this.length,textHeight:a}:null}coordsAt(o,a){let f=ii(this,o,a);if(!this.children.length&&f&&this.parent){let{heightOracle:d}=this.parent.view.viewState,m=f.bottom-f.top;if(Math.abs(m-d.lineHeight)<2&&d.textHeight<m){let S=(m-d.textHeight)/2;return{top:f.top+S,bottom:f.bottom-S,left:f.left,right:f.left}}}return f}become(o){return o instanceof _t&&this.children.length==0&&o.children.length==0&&di(this.attrs,o.attrs)&&this.breakAfter==o.breakAfter}covers(){return!0}static find(o,a){for(let f=0,d=0;f<o.children.length;f++){let m=o.children[f],S=d+m.length;if(S>=a){if(m instanceof _t)return m;if(S>a)break}d=S+m.breakAfter}return null}}class je extends vt{constructor(o,a,f){super(),this.widget=o,this.length=a,this.deco=f,this.breakAfter=0,this.prevWidget=null}merge(o,a,f,d,m,S){return f&&(!(f instanceof je)||!this.widget.compare(f.widget)||o>0&&m<=0||a<this.length&&S<=0)?!1:(this.length=o+(f?f.length:0)+(this.length-a),!0)}domAtPos(o){return o==0?Rt.before(this.dom):Rt.after(this.dom,o==this.length)}split(o){let a=this.length-o;this.length=o;let f=new je(this.widget,a,this.deco);return f.breakAfter=this.breakAfter,f}get children(){return Bt}sync(o){(!this.dom||!this.widget.updateDOM(this.dom,o))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(o)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):t.Text.empty}domBoundsAround(){return null}become(o){return o instanceof je&&o.widget.constructor==this.widget.constructor?(o.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=o.widget,this.length=o.length,this.deco=o.deco,this.breakAfter=o.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(o){return this.widget.ignoreEvent(o)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(o,a){return this.widget.coordsAt(this.dom,o,a)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(o){let{startSide:a,endSide:f}=this.deco;return a==f?!1:o<0?a<0:f>0}}class _e{eq(o){return!1}updateDOM(o,a){return!1}compare(o){return this==o||this.constructor==o.constructor&&this.eq(o)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(o){return!0}coordsAt(o,a,f){return null}get isHidden(){return!1}get editable(){return!1}destroy(o){}}n.BlockType=void 0,function(u){u[u.Text=0]="Text",u[u.WidgetBefore=1]="WidgetBefore",u[u.WidgetAfter=2]="WidgetAfter",u[u.WidgetRange=3]="WidgetRange"}(n.BlockType||(n.BlockType={}));class Vt extends t.RangeValue{constructor(o,a,f,d){super(),this.startSide=o,this.endSide=a,this.widget=f,this.spec=d}get heightRelevant(){return!1}static mark(o){return new Fe(o)}static widget(o){let a=Math.max(-1e4,Math.min(1e4,o.side||0)),f=!!o.block;return a+=f&&!o.inlineOrder?a>0?3e8:-4e8:a>0?1e8:-1e8,new Ge(o,a,a,f,o.widget||null,!1)}static replace(o){let a=!!o.block,f,d;if(o.isBlockGap)f=-5e8,d=4e8;else{let{start:m,end:S}=cs(o,a);f=(m?a?-3e8:-1:5e8)-1,d=(S?a?2e8:1:-6e8)+1}return new Ge(o,f,d,a,o.widget||null,!0)}static line(o){return new en(o)}static set(o,a=!1){return t.RangeSet.of(o,a)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}Vt.none=t.RangeSet.empty;class Fe extends Vt{constructor(o){let{start:a,end:f}=cs(o);super(a?-1:5e8,f?1:-6e8,null,o),this.tagName=o.tagName||"span",this.class=o.class||"",this.attrs=o.attributes||null}eq(o){var a,f;return this==o||o instanceof Fe&&this.tagName==o.tagName&&(this.class||((a=this.attrs)===null||a===void 0?void 0:a.class))==(o.class||((f=o.attrs)===null||f===void 0?void 0:f.class))&&di(this.attrs,o.attrs,"class")}range(o,a=o){if(o>=a)throw new RangeError("Mark decorations may not be empty");return super.range(o,a)}}Fe.prototype.point=!1;class en extends Vt{constructor(o){super(-2e8,-2e8,null,o)}eq(o){return o instanceof en&&this.spec.class==o.spec.class&&di(this.spec.attributes,o.spec.attributes)}range(o,a=o){if(a!=o)throw new RangeError("Line decoration ranges must be zero-length");return super.range(o,a)}}en.prototype.mapMode=t.MapMode.TrackBefore,en.prototype.point=!0;class Ge extends Vt{constructor(o,a,f,d,m,S){super(a,f,m,o),this.block=d,this.isReplace=S,this.mapMode=d?a<=0?t.MapMode.TrackBefore:t.MapMode.TrackAfter:t.MapMode.TrackDel}get type(){return this.startSide!=this.endSide?n.BlockType.WidgetRange:this.startSide<=0?n.BlockType.WidgetBefore:n.BlockType.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(o){return o instanceof Ge&&er(this.widget,o.widget)&&this.block==o.block&&this.startSide==o.startSide&&this.endSide==o.endSide}range(o,a=o){if(this.isReplace&&(o>a||o==a&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&a!=o)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(o,a)}}Ge.prototype.point=!0;function cs(u,o=!1){let{inclusiveStart:a,inclusiveEnd:f}=u;return a==null&&(a=u.inclusive),f==null&&(f=u.inclusive),{start:a??o,end:f??o}}function er(u,o){return u==o||!!(u&&o&&u.compare(o))}function Wt(u,o,a,f=0){let d=a.length-1;d>=0&&a[d]+f>=u?a[d]=Math.max(a[d],o):a.push(u,o)}class ki{constructor(o,a,f,d){this.doc=o,this.pos=a,this.end=f,this.disallowBlockEffectsFor=d,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=o.iter(),this.skip=a}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let o=this.content[this.content.length-1];return!(o.breakAfter||o instanceof je&&o.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new _t),this.atCursorPos=!0),this.curLine}flushBuffer(o=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(ni(new De(-1),o),o.length),this.pendingBuffer=0)}addBlockWidget(o){this.flushBuffer(),this.curLine=null,this.content.push(o)}finish(o){this.pendingBuffer&&o<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(o&&this.content.length&&this.content[this.content.length-1]instanceof je)&&this.getLine()}buildText(o,a,f){for(;o>0;){if(this.textOff==this.text.length){let{value:m,lineBreak:S,done:k}=this.cursor.next(this.skip);if(this.skip=0,k)throw new Error("Ran out of text content when drawing inline views");if(S){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,o--;continue}else this.text=m,this.textOff=0}let d=Math.min(this.text.length-this.textOff,o,512);this.flushBuffer(a.slice(a.length-f)),this.getLine().append(ni(new ye(this.text.slice(this.textOff,this.textOff+d)),a),f),this.atCursorPos=!0,this.textOff+=d,o-=d,f=0}}span(o,a,f,d){this.buildText(a-o,f,d),this.pos=a,this.openStart<0&&(this.openStart=d)}point(o,a,f,d,m,S){if(this.disallowBlockEffectsFor[S]&&f instanceof Ge){if(f.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let k=a-o;if(f instanceof Ge)if(f.block)f.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new je(f.widget||Ee.block,k,f));else{let M=ei.create(f.widget||Ee.inline,k,k?0:f.startSide),B=this.atCursorPos&&!M.isEditable&&m<=d.length&&(o<a||f.startSide>0),E=!M.isEditable&&(o<a||m>d.length||f.startSide<=0),H=this.getLine();this.pendingBuffer==2&&!B&&!M.isEditable&&(this.pendingBuffer=0),this.flushBuffer(d),B&&(H.append(ni(new De(1),d),m),m=d.length+Math.max(0,m-d.length)),H.append(ni(M,d),m),this.atCursorPos=E,this.pendingBuffer=E?o<a||m>d.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=d.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(f);k&&(this.textOff+k<=this.text.length?this.textOff+=k:(this.skip+=k-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=a),this.openStart<0&&(this.openStart=m)}static build(o,a,f,d,m){let S=new ki(o,a,f,m);return S.openEnd=t.RangeSet.spans(d,a,f,S),S.openStart<0&&(S.openStart=S.openEnd),S.finish(S.openEnd),S}}function ni(u,o){for(let a of o)u=new Ke(a,[u],u.length);return u}class Ee extends _e{constructor(o){super(),this.tag=o}eq(o){return o.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(o){return o.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}Ee.inline=new Ee("span"),Ee.block=new Ee("div"),n.Direction=void 0,function(u){u[u.LTR=0]="LTR",u[u.RTL=1]="RTL"}(n.Direction||(n.Direction={}));const si=n.Direction.LTR,nn=n.Direction.RTL;function re(u){let o=[];for(let a=0;a<u.length;a++)o.push(1<<+u[a]);return o}const ir=re("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),sn=re("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),ui=Object.create(null),Se=[];for(let u of["()","[]","{}"]){let o=u.charCodeAt(0),a=u.charCodeAt(1);ui[o]=a,ui[a]=-o}function Ci(u){return u<=247?ir[u]:1424<=u&&u<=1524?2:1536<=u&&u<=1785?sn[u-1536]:1774<=u&&u<=2220?4:8192<=u&&u<=8204?256:64336<=u&&u<=65023?4:1}const Hi=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class we{get dir(){return this.level%2?nn:si}constructor(o,a,f){this.from=o,this.to=a,this.level=f}side(o,a){return this.dir==a==o?this.to:this.from}forward(o,a){return o==(this.dir==a)}static find(o,a,f,d){let m=-1;for(let S=0;S<o.length;S++){let k=o[S];if(k.from<=a&&k.to>=a){if(k.level==f)return S;(m<0||(d!=0?d<0?k.from<a:k.to>a:o[m].level>k.level))&&(m=S)}}if(m<0)throw new RangeError("Index out of range");return m}}function _n(u,o){if(u.length!=o.length)return!1;for(let a=0;a<u.length;a++){let f=u[a],d=o[a];if(f.from!=d.from||f.to!=d.to||f.direction!=d.direction||!_n(f.inner,d.inner))return!1}return!0}const Ft=[];function Sn(u,o,a,f,d){for(let m=0;m<=f.length;m++){let S=m?f[m-1].to:o,k=m<f.length?f[m].from:a,M=m?256:d;for(let B=S,E=M,H=M;B<k;B++){let K=Ci(u.charCodeAt(B));K==512?K=E:K==8&&H==4&&(K=16),Ft[B]=K==4?2:K,K&7&&(H=K),E=K}for(let B=S,E=M,H=M;B<k;B++){let K=Ft[B];if(K==128)B<k-1&&E==Ft[B+1]&&E&24?K=Ft[B]=E:Ft[B]=256;else if(K==64){let Y=B+1;for(;Y<k&&Ft[Y]==64;)Y++;let X=B&&E==8||Y<a&&Ft[Y]==8?H==1?1:8:256;for(let it=B;it<Y;it++)Ft[it]=X;B=Y-1}else K==8&&H==1&&(Ft[B]=1);E=K,K&7&&(H=K)}}}function wn(u,o,a,f,d){let m=d==1?2:1;for(let S=0,k=0,M=0;S<=f.length;S++){let B=S?f[S-1].to:o,E=S<f.length?f[S].from:a;for(let H=B,K,Y,X;H<E;H++)if(Y=ui[K=u.charCodeAt(H)])if(Y<0){for(let it=k-3;it>=0;it-=3)if(Se[it+1]==-Y){let rt=Se[it+2],nt=rt&2?d:rt&4?rt&1?m:d:0;nt&&(Ft[H]=Ft[Se[it]]=nt),k=it;break}}else{if(Se.length==189)break;Se[k++]=H,Se[k++]=K,Se[k++]=M}else if((X=Ft[H])==2||X==1){let it=X==d;M=it?0:1;for(let rt=k-3;rt>=0;rt-=3){let nt=Se[rt+2];if(nt&2)break;if(it)Se[rt+2]|=2;else{if(nt&4)break;Se[rt+2]|=4}}}}}function fs(u,o,a,f){for(let d=0,m=f;d<=a.length;d++){let S=d?a[d-1].to:u,k=d<a.length?a[d].from:o;for(let M=S;M<k;){let B=Ft[M];if(B==256){let E=M+1;for(;;)if(E==k){if(d==a.length)break;E=a[d++].to,k=d<a.length?a[d].from:o}else if(Ft[E]==256)E++;else break;let H=m==1,K=(E<o?Ft[E]:f)==1,Y=H==K?H?1:2:f;for(let X=E,it=d,rt=it?a[it-1].to:u;X>M;)X==rt&&(X=a[--it].from,rt=it?a[it-1].to:u),Ft[--X]=Y;M=E}else m=B,M++}}}function xn(u,o,a,f,d,m,S){let k=f%2?2:1;if(f%2==d%2)for(let M=o,B=0;M<a;){let E=!0,H=!1;if(B==m.length||M<m[B].from){let it=Ft[M];it!=k&&(E=!1,H=it==16)}let K=!E&&k==1?[]:null,Y=E?f:f+1,X=M;t:for(;;)if(B<m.length&&X==m[B].from){if(H)break t;let it=m[B];if(!E)for(let rt=it.to,nt=B+1;;){if(rt==a)break t;if(nt<m.length&&m[nt].from==rt)rt=m[nt++].to;else{if(Ft[rt]==k)break t;break}}if(B++,K)K.push(it);else{it.from>M&&S.push(new we(M,it.from,Y));let rt=it.direction==si!=!(Y%2);vn(u,rt?f+1:f,d,it.inner,it.from,it.to,S),M=it.to}X=it.to}else{if(X==a||(E?Ft[X]!=k:Ft[X]==k))break;X++}K?xn(u,M,X,f+1,d,K,S):M<X&&S.push(new we(M,X,Y)),M=X}else for(let M=a,B=m.length;M>o;){let E=!0,H=!1;if(!B||M>m[B-1].to){let it=Ft[M-1];it!=k&&(E=!1,H=it==16)}let K=!E&&k==1?[]:null,Y=E?f:f+1,X=M;t:for(;;)if(B&&X==m[B-1].to){if(H)break t;let it=m[--B];if(!E)for(let rt=it.from,nt=B;;){if(rt==o)break t;if(nt&&m[nt-1].to==rt)rt=m[--nt].from;else{if(Ft[rt-1]==k)break t;break}}if(K)K.push(it);else{it.to<M&&S.push(new we(it.to,M,Y));let rt=it.direction==si!=!(Y%2);vn(u,rt?f+1:f,d,it.inner,it.from,it.to,S),M=it.from}X=it.from}else{if(X==o||(E?Ft[X-1]!=k:Ft[X-1]==k))break;X--}K?xn(u,X,M,f+1,d,K,S):X<M&&S.push(new we(X,M,Y)),M=X}}function vn(u,o,a,f,d,m,S){let k=o%2?2:1;Sn(u,d,m,f,k),wn(u,d,m,f,k),fs(d,m,f,k),xn(u,d,m,o,a,f,S)}function V(u,o,a){if(!u)return[new we(0,0,o==nn?1:0)];if(o==si&&!a.length&&!Hi.test(u))return b(u.length);if(a.length)for(;u.length>Ft.length;)Ft[Ft.length]=256;let f=[],d=o==si?0:1;return vn(u,d,d,a,0,u.length,f),f}function b(u){return[new we(0,u,0)]}let w="";function C(u,o,a,f,d){var m;let S=f.head-u.from,k=we.find(o,S,(m=f.bidiLevel)!==null&&m!==void 0?m:-1,f.assoc),M=o[k],B=M.side(d,a);if(S==B){let K=k+=d?1:-1;if(K<0||K>=o.length)return null;M=o[k=K],S=M.side(!d,a),B=M.side(d,a)}let E=t.findClusterBreak(u.text,S,M.forward(d,a));(E<M.from||E>M.to)&&(E=B),w=u.text.slice(Math.min(S,E),Math.max(S,E));let H=k==(d?o.length-1:0)?null:o[k+(d?1:-1)];return H&&E==B&&H.level+(d?0:1)<M.level?t.EditorSelection.cursor(H.side(!d,a)+u.from,H.forward(d,a)?1:-1,H.level):t.EditorSelection.cursor(E+u.from,M.forward(d,a)?-1:1,M.level)}function O(u,o,a){for(let f=o;f<a;f++){let d=Ci(u.charCodeAt(f));if(d==1)return si;if(d==2||d==4)return nn}return si}const L=t.Facet.define(),N=t.Facet.define(),q=t.Facet.define(),_=t.Facet.define(),Z=t.Facet.define(),lt=t.Facet.define(),ht=t.Facet.define(),gt=t.Facet.define({combine:u=>u.some(o=>o)}),pt=t.Facet.define({combine:u=>u.some(o=>o)}),It=t.Facet.define();class be{constructor(o,a="nearest",f="nearest",d=5,m=5,S=!1){this.range=o,this.y=a,this.x=f,this.yMargin=d,this.xMargin=m,this.isSnapshot=S}map(o){return o.empty?this:new be(this.range.map(o),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(o){return this.range.to<=o.doc.length?this:new be(t.EditorSelection.cursor(o.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Gt=t.StateEffect.define({map:(u,o)=>u.map(o)}),rn=t.StateEffect.define();function Ie(u,o,a){let f=u.facet(_);f.length?f[0](o):window.onerror?window.onerror(String(o),a,void 0,void 0,o):a?console.error(a+":",o):console.error(o)}const pi=t.Facet.define({combine:u=>u.length?u[0]:!0});let ho=0;const Gn=t.Facet.define();class pe{constructor(o,a,f,d,m){this.id=o,this.create=a,this.domEventHandlers=f,this.domEventObservers=d,this.extension=m(this)}static define(o,a){const{eventHandlers:f,eventObservers:d,provide:m,decorations:S}=a||{};return new pe(ho++,o,f,d,k=>{let M=[Gn.of(k)];return S&&M.push(Yn.of(B=>{let E=B.plugin(k);return E?S(E):Vt.none})),m&&M.push(m(k)),M})}static fromClass(o,a){return pe.define(f=>new o(f),a)}}class ds{constructor(o){this.spec=o,this.mustUpdate=null,this.value=null}update(o){if(this.value){if(this.mustUpdate){let a=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(a)}catch(f){if(Ie(a.state,f,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(o)}catch(a){Ie(o.state,a,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(o){var a;if(!((a=this.value)===null||a===void 0)&&a.destroy)try{this.value.destroy()}catch(f){Ie(o.state,f,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const us=t.Facet.define(),Vi=t.Facet.define(),Yn=t.Facet.define(),nr=t.Facet.define(),ps=t.Facet.define(),sr=t.Facet.define();function rr(u,o){let a=u.state.facet(sr);if(!a.length)return a;let f=a.map(m=>m instanceof Function?m(u):m),d=[];return t.RangeSet.spans(f,o.from,o.to,{point(){},span(m,S,k,M){let B=m-o.from,E=S-o.from,H=d;for(let K=k.length-1;K>=0;K--,M--){let Y=k[K].spec.bidiIsolate,X;if(Y==null&&(Y=O(o.text,B,E)),M>0&&H.length&&(X=H[H.length-1]).to==B&&X.direction==Y)X.to=E,H=X.inner;else{let it={from:B,to:E,direction:Y,inner:[]};H.push(it),H=it.inner}}}}),d}const co=t.Facet.define();function gs(u){let o=0,a=0,f=0,d=0;for(let m of u.state.facet(co)){let S=m(u);S&&(S.left!=null&&(o=Math.max(o,S.left)),S.right!=null&&(a=Math.max(a,S.right)),S.top!=null&&(f=Math.max(f,S.top)),S.bottom!=null&&(d=Math.max(d,S.bottom)))}return{left:o,right:a,top:f,bottom:d}}const kn=t.Facet.define();class He{constructor(o,a,f,d){this.fromA=o,this.toA=a,this.fromB=f,this.toB=d}join(o){return new He(Math.min(this.fromA,o.fromA),Math.max(this.toA,o.toA),Math.min(this.fromB,o.fromB),Math.max(this.toB,o.toB))}addToSet(o){let a=o.length,f=this;for(;a>0;a--){let d=o[a-1];if(!(d.fromA>f.toA)){if(d.toA<f.fromA)break;f=f.join(d),o.splice(a-1,1)}}return o.splice(a,0,f),o}static extendWithRanges(o,a){if(a.length==0)return o;let f=[];for(let d=0,m=0,S=0,k=0;;d++){let M=d==o.length?null:o[d],B=S-k,E=M?M.fromB:1e9;for(;m<a.length&&a[m]<E;){let H=a[m],K=a[m+1],Y=Math.max(k,H),X=Math.min(E,K);if(Y<=X&&new He(Y+B,X+B,Y,X).addToSet(f),K>E)break;m+=2}if(!M)return f;new He(M.fromA,M.toA,M.fromB,M.toB).addToSet(f),S=M.toA,k=M.toB}}}class Cn{constructor(o,a,f){this.view=o,this.state=a,this.transactions=f,this.flags=0,this.startState=o.state,this.changes=t.ChangeSet.empty(this.startState.doc.length);for(let m of f)this.changes=this.changes.compose(m.changes);let d=[];this.changes.iterChangedRanges((m,S,k,M)=>d.push(new He(m,S,k,M))),this.changedRanges=d}static create(o,a,f){return new Cn(o,a,f)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(o=>o.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class or extends vt{get length(){return this.view.state.doc.length}constructor(o){super(),this.view=o,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=Vt.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(o.contentDOM),this.children=[new _t],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new He(0,0,0,o.state.doc.length)],0,null)}update(o){var a;let f=o.changedRanges;this.minWidth>0&&f.length&&(f.every(({fromA:B,toA:E})=>E<this.minWidthFrom||B>this.minWidthTo)?(this.minWidthFrom=o.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=o.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(o);let d=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((a=this.domChanged)===null||a===void 0)&&a.newSel?d=this.domChanged.newSel.head:!v(o.changes,this.hasComposition)&&!o.selectionSet&&(d=o.state.selection.main.head));let m=d>-1?pa(this.view,o.changes,d):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:B,to:E}=this.hasComposition;f=new He(B,E,o.changes.mapPos(B,-1),o.changes.mapPos(E,1)).addToSet(f.slice())}this.hasComposition=m?{from:m.range.fromB,to:m.range.toB}:null,(ft.ie||ft.chrome)&&!m&&o&&o.state.doc.lines!=o.startState.doc.lines&&(this.forceSelection=!0);let S=this.decorations,k=this.updateDeco(),M=ma(S,k,o.changes);return f=He.extendWithRanges(f,M),!(this.flags&7)&&f.length==0?!1:(this.updateInner(f,o.startState.doc.length,m),o.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(o,a,f){this.view.viewState.mustMeasureContent=!0,this.updateChildren(o,a,f);let{observer:d}=this.view;d.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let S=ft.chrome||ft.ios?{node:d.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,S),this.flags&=-8,S&&(S.written||d.selectionRange.focusNode!=S.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(S=>S.flags&=-9);let m=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let S of this.children)S instanceof je&&S.widget instanceof ms&&m.push(S.dom);d.updateGaps(m)}updateChildren(o,a,f){let d=f?f.range.addToSet(o.slice()):o,m=this.childCursor(a);for(let S=d.length-1;;S--){let k=S>=0?d[S]:null;if(!k)break;let{fromA:M,toA:B,fromB:E,toB:H}=k,K,Y,X,it;if(f&&f.range.fromB<H&&f.range.toB>E){let St=ki.build(this.view.state.doc,E,f.range.fromB,this.decorations,this.dynamicDecorationMap),Mt=ki.build(this.view.state.doc,f.range.toB,H,this.decorations,this.dynamicDecorationMap);Y=St.breakAtStart,X=St.openStart,it=Mt.openEnd;let Et=this.compositionView(f);Mt.breakAtStart?Et.breakAfter=1:Mt.content.length&&Et.merge(Et.length,Et.length,Mt.content[0],!1,Mt.openStart,0)&&(Et.breakAfter=Mt.content[0].breakAfter,Mt.content.shift()),St.content.length&&Et.merge(0,0,St.content[St.content.length-1],!0,0,St.openEnd)&&St.content.pop(),K=St.content.concat(Et).concat(Mt.content)}else({content:K,breakAtStart:Y,openStart:X,openEnd:it}=ki.build(this.view.state.doc,E,H,this.decorations,this.dynamicDecorationMap));let{i:rt,off:nt}=m.findPos(B,1),{i:bt,off:Ct}=m.findPos(M,-1);ue(this,bt,Ct,rt,nt,K,Y,X,it)}f&&this.fixCompositionDOM(f)}updateEditContextFormatting(o){this.editContextFormatting=this.editContextFormatting.map(o.changes);for(let a of o.transactions)for(let f of a.effects)f.is(rn)&&(this.editContextFormatting=f.value)}compositionView(o){let a=new ye(o.text.nodeValue);a.flags|=8;for(let{deco:d}of o.marks)a=new Ke(d,[a],a.length);let f=new _t;return f.append(a,0),f}fixCompositionDOM(o){let a=(m,S)=>{S.flags|=8|(S.children.some(M=>M.flags&7)?1:0),this.markedForComposition.add(S);let k=vt.get(m);k&&k!=S&&(k.dom=null),S.setDOM(m)},f=this.childPos(o.range.fromB,1),d=this.children[f.i];a(o.line,d);for(let m=o.marks.length-1;m>=-1;m--)f=d.childPos(f.off,1),d=d.children[f.i],a(m>=0?o.marks[m].node:o.text,d)}updateSelection(o=!1,a=!1){(o||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let f=this.view.root.activeElement,d=f==this.dom,m=!d&&h(this.dom,this.view.observer.selectionRange)&&!(f&&this.dom.contains(f));if(!(d||a||m))return;let S=this.forceSelection;this.forceSelection=!1;let k=this.view.state.selection.main,M=this.moveToLine(this.domAtPos(k.anchor)),B=k.empty?M:this.moveToLine(this.domAtPos(k.head));if(ft.gecko&&k.empty&&!this.hasComposition&&ua(M)){let H=document.createTextNode("");this.view.observer.ignore(()=>M.node.insertBefore(H,M.node.childNodes[M.offset]||null)),M=B=new Rt(H,0),S=!0}let E=this.view.observer.selectionRange;(S||!E.focusNode||(!g(M.node,M.offset,E.anchorNode,E.anchorOffset)||!g(B.node,B.offset,E.focusNode,E.focusOffset))&&!this.suppressWidgetCursorChange(E,k))&&(this.view.observer.ignore(()=>{ft.android&&ft.chrome&&this.dom.contains(E.focusNode)&&R(E.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let H=s(this.view.root);if(H)if(k.empty){if(ft.gecko){let K=uo(M.node,M.offset);if(K&&K!=3){let Y=(K==1?Ot:ne)(M.node,M.offset);Y&&(M=new Rt(Y.node,Y.offset))}}H.collapse(M.node,M.offset),k.bidiLevel!=null&&H.caretBidiLevel!==void 0&&(H.caretBidiLevel=k.bidiLevel)}else if(H.extend){H.collapse(M.node,M.offset);try{H.extend(B.node,B.offset)}catch{}}else{let K=document.createRange();k.anchor>k.head&&([M,B]=[B,M]),K.setEnd(B.node,B.offset),K.setStart(M.node,M.offset),H.removeAllRanges(),H.addRange(K)}m&&this.view.root.activeElement==this.dom&&(this.dom.blur(),f&&f.focus())}),this.view.observer.setSelectionRange(M,B)),this.impreciseAnchor=M.precise?null:new Rt(E.anchorNode,E.anchorOffset),this.impreciseHead=B.precise?null:new Rt(E.focusNode,E.focusOffset)}suppressWidgetCursorChange(o,a){return this.hasComposition&&a.empty&&g(o.focusNode,o.focusOffset,o.anchorNode,o.anchorOffset)&&this.posFromDOM(o.focusNode,o.focusOffset)==a.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:o}=this,a=o.state.selection.main,f=s(o.root),{anchorNode:d,anchorOffset:m}=o.observer.selectionRange;if(!f||!a.empty||!a.assoc||!f.modify)return;let S=_t.find(this,a.head);if(!S)return;let k=S.posAtStart;if(a.head==k||a.head==k+S.length)return;let M=this.coordsAt(a.head,-1),B=this.coordsAt(a.head,1);if(!M||!B||M.bottom>B.top)return;let E=this.domAtPos(a.head+a.assoc);f.collapse(E.node,E.offset),f.modify("move",a.assoc<0?"forward":"backward","lineboundary"),o.observer.readSelectionRange();let H=o.observer.selectionRange;o.docView.posFromDOM(H.anchorNode,H.anchorOffset)!=a.from&&f.collapse(d,m)}moveToLine(o){let a=this.dom,f;if(o.node!=a)return o;for(let d=o.offset;!f&&d<a.childNodes.length;d++){let m=vt.get(a.childNodes[d]);m instanceof _t&&(f=m.domAtPos(0))}for(let d=o.offset-1;!f&&d>=0;d--){let m=vt.get(a.childNodes[d]);m instanceof _t&&(f=m.domAtPos(m.length))}return f?new Rt(f.node,f.offset,!0):o}nearest(o){for(let a=o;a;){let f=vt.get(a);if(f&&f.rootView==this)return f;a=a.parentNode}return null}posFromDOM(o,a){let f=this.nearest(o);if(!f)throw new RangeError("Trying to find position for a DOM position outside of the document");return f.localPosFromDOM(o,a)+f.posAtStart}domAtPos(o){let{i:a,off:f}=this.childCursor().findPos(o,-1);for(;a<this.children.length-1;){let d=this.children[a];if(f<d.length||d instanceof _t)break;a++,f=0}return this.children[a].domAtPos(f)}coordsAt(o,a){let f=null,d=0;for(let m=this.length,S=this.children.length-1;S>=0;S--){let k=this.children[S],M=m-k.breakAfter,B=M-k.length;if(M<o)break;if(B<=o&&(B<o||k.covers(-1))&&(M>o||k.covers(1))&&(!f||k instanceof _t&&!(f instanceof _t&&a>=0)))f=k,d=B;else if(f&&B==o&&M==o&&k instanceof je&&Math.abs(a)<2){if(k.deco.startSide<0)break;S&&(f=null)}m=B}return f?f.coordsAt(o-d,a):null}coordsForChar(o){let{i:a,off:f}=this.childPos(o,1),d=this.children[a];if(!(d instanceof _t))return null;for(;d.children.length;){let{i:k,off:M}=d.childPos(f,1);for(;;k++){if(k==d.children.length)return null;if((d=d.children[k]).length)break}f=M}if(!(d instanceof ye))return null;let m=t.findClusterBreak(d.text,f);if(m==f)return null;let S=wt(d.dom,f,m).getClientRects();for(let k=0;k<S.length;k++){let M=S[k];if(k==S.length-1||M.top<M.bottom&&M.left<M.right)return M}return null}measureVisibleLineHeights(o){let a=[],{from:f,to:d}=o,m=this.view.contentDOM.clientWidth,S=m>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,k=-1,M=this.view.textDirection==n.Direction.LTR;for(let B=0,E=0;E<this.children.length;E++){let H=this.children[E],K=B+H.length;if(K>d)break;if(B>=f){let Y=H.dom.getBoundingClientRect();if(a.push(Y.height),S){let X=H.dom.lastChild,it=X?c(X):[];if(it.length){let rt=it[it.length-1],nt=M?rt.right-Y.left:Y.right-rt.left;nt>k&&(k=nt,this.minWidth=m,this.minWidthFrom=B,this.minWidthTo=K)}}}B=K+H.breakAfter}return a}textDirectionAt(o){let{i:a}=this.childPos(o,1);return getComputedStyle(this.children[a].dom).direction=="rtl"?n.Direction.RTL:n.Direction.LTR}measureTextSize(){for(let m of this.children)if(m instanceof _t){let S=m.measureTextSize();if(S)return S}let o=document.createElement("div"),a,f,d;return o.className="cm-line",o.style.width="99999px",o.style.position="absolute",o.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(o);let m=c(o.firstChild)[0];a=o.getBoundingClientRect().height,f=m?m.width/27:7,d=m?m.height:a,o.remove()}),{lineHeight:a,charWidth:f,textHeight:d}}childCursor(o=this.length){let a=this.children.length;return a&&(o-=this.children[--a].length),new se(this.children,o,a)}computeBlockGapDeco(){let o=[],a=this.view.viewState;for(let f=0,d=0;;d++){let m=d==a.viewports.length?null:a.viewports[d],S=m?m.from-1:this.length;if(S>f){let k=(a.lineBlockAt(S).bottom-a.lineBlockAt(f).top)/this.view.scaleY;o.push(Vt.replace({widget:new ms(k),block:!0,inclusive:!0,isBlockGap:!0}).range(f,S))}if(!m)break;f=m.to+1}return Vt.set(o)}updateDeco(){let o=1,a=this.view.state.facet(Yn).map(m=>(this.dynamicDecorationMap[o++]=typeof m=="function")?m(this.view):m),f=!1,d=this.view.state.facet(nr).map((m,S)=>{let k=typeof m=="function";return k&&(f=!0),k?m(this.view):m});for(d.length&&(this.dynamicDecorationMap[o++]=f,a.push(t.RangeSet.join(d))),this.decorations=[this.editContextFormatting,...a,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];o<this.decorations.length;)this.dynamicDecorationMap[o++]=!1;return this.decorations}scrollIntoView(o){if(o.isSnapshot){let B=this.view.viewState.lineBlockAt(o.range.head);this.view.scrollDOM.scrollTop=B.top-o.yMargin,this.view.scrollDOM.scrollLeft=o.xMargin;return}for(let B of this.view.state.facet(It))try{if(B(this.view,o.range,o))return!0}catch(E){Ie(this.view.state,E,"scroll handler")}let{range:a}=o,f=this.coordsAt(a.head,a.empty?a.assoc:a.head>a.anchor?-1:1),d;if(!f)return;!a.empty&&(d=this.coordsAt(a.anchor,a.anchor>a.head?-1:1))&&(f={left:Math.min(f.left,d.left),top:Math.min(f.top,d.top),right:Math.max(f.right,d.right),bottom:Math.max(f.bottom,d.bottom)});let m=gs(this.view),S={left:f.left-m.left,top:f.top-m.top,right:f.right+m.right,bottom:f.bottom+m.bottom},{offsetWidth:k,offsetHeight:M}=this.view.scrollDOM;W(this.view.scrollDOM,S,a.head<a.anchor?-1:1,o.x,o.y,Math.max(Math.min(o.xMargin,k),-k),Math.max(Math.min(o.yMargin,M),-M),this.view.textDirection==n.Direction.LTR)}}function ua(u){return u.node.nodeType==1&&u.node.firstChild&&(u.offset==0||u.node.childNodes[u.offset-1].contentEditable=="false")&&(u.offset==u.node.childNodes.length||u.node.childNodes[u.offset].contentEditable=="false")}class ms extends _e{constructor(o){super(),this.height=o}toDOM(){let o=document.createElement("div");return o.className="cm-gap",this.updateDOM(o),o}eq(o){return o.height==this.height}updateDOM(o){return o.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function fo(u,o){let a=u.observer.selectionRange;if(!a.focusNode)return null;let f=Ot(a.focusNode,a.focusOffset),d=ne(a.focusNode,a.focusOffset),m=f||d;if(d&&f&&d.node!=f.node){let k=vt.get(d.node);if(!k||k instanceof ye&&k.text!=d.node.nodeValue)m=d;else if(u.docView.lastCompositionAfterCursor){let M=vt.get(f.node);!M||M instanceof ye&&M.text!=f.node.nodeValue||(m=d)}}if(u.docView.lastCompositionAfterCursor=m!=f,!m)return null;let S=o-m.offset;return{from:S,to:S+m.node.nodeValue.length,node:m.node}}function pa(u,o,a){let f=fo(u,a);if(!f)return null;let{node:d,from:m,to:S}=f,k=d.nodeValue;if(/[\n\r]/.test(k)||u.state.doc.sliceString(f.from,f.to)!=k)return null;let M=o.invertedDesc,B=new He(M.mapPos(m),M.mapPos(S),m,S),E=[];for(let H=d.parentNode;;H=H.parentNode){let K=vt.get(H);if(K instanceof Ke)E.push({node:H,deco:K.mark});else{if(K instanceof _t||H.nodeName=="DIV"&&H.parentNode==u.contentDOM)return{range:B,text:d,marks:E,line:H};if(H!=u.contentDOM)E.push({node:H,deco:new Fe({inclusive:!0,attributes:tn(H),tagName:H.tagName.toLowerCase()})});else return null}}}function uo(u,o){return u.nodeType!=1?0:(o&&u.childNodes[o-1].contentEditable=="false"?1:0)|(o<u.childNodes.length&&u.childNodes[o].contentEditable=="false"?2:0)}let ga=class{constructor(){this.changes=[]}compareRange(o,a){Wt(o,a,this.changes)}comparePoint(o,a){Wt(o,a,this.changes)}};function ma(u,o,a){let f=new ga;return t.RangeSet.compare(u,o,a,f),f.changes}function R(u,o){for(let a=u;a&&a!=o;a=a.assignedSlot||a.parentNode)if(a.nodeType==1&&a.contentEditable=="false")return!0;return!1}function v(u,o){let a=!1;return o&&u.iterChangedRanges((f,d)=>{f<o.to&&d>o.from&&(a=!0)}),a}function D(u,o,a=1){let f=u.charCategorizer(o),d=u.doc.lineAt(o),m=o-d.from;if(d.length==0)return t.EditorSelection.cursor(o);m==0?a=1:m==d.length&&(a=-1);let S=m,k=m;a<0?S=t.findClusterBreak(d.text,m,!1):k=t.findClusterBreak(d.text,m);let M=f(d.text.slice(S,k));for(;S>0;){let B=t.findClusterBreak(d.text,S,!1);if(f(d.text.slice(B,S))!=M)break;S=B}for(;k<d.length;){let B=t.findClusterBreak(d.text,k);if(f(d.text.slice(k,B))!=M)break;k=B}return t.EditorSelection.range(S+d.from,k+d.from)}function F(u,o){return o.left>u?o.left-u:Math.max(0,u-o.right)}function $(u,o){return o.top>u?o.top-u:Math.max(0,u-o.bottom)}function j(u,o){return u.top<o.bottom-1&&u.bottom>o.top+1}function G(u,o){return o<u.top?{top:o,left:u.left,right:u.right,bottom:u.bottom}:u}function tt(u,o){return o>u.bottom?{top:u.top,left:u.left,right:u.right,bottom:o}:u}function et(u,o,a){let f,d,m,S,k=!1,M,B,E,H;for(let X=u.firstChild;X;X=X.nextSibling){let it=c(X);for(let rt=0;rt<it.length;rt++){let nt=it[rt];d&&j(d,nt)&&(nt=G(tt(nt,d.bottom),d.top));let bt=F(o,nt),Ct=$(a,nt);if(bt==0&&Ct==0)return X.nodeType==3?ct(X,o,a):et(X,o,a);if(!f||S>Ct||S==Ct&&m>bt){f=X,d=nt,m=bt,S=Ct;let St=Ct?a<nt.top?-1:1:bt?o<nt.left?-1:1:0;k=!St||(St>0?rt<it.length-1:rt>0)}bt==0?a>nt.bottom&&(!E||E.bottom<nt.bottom)?(M=X,E=nt):a<nt.top&&(!H||H.top>nt.top)&&(B=X,H=nt):E&&j(E,nt)?E=tt(E,nt.bottom):H&&j(H,nt)&&(H=G(H,nt.top))}}if(E&&E.bottom>=a?(f=M,d=E):H&&H.top<=a&&(f=B,d=H),!f)return{node:u,offset:0};let K=Math.max(d.left,Math.min(d.right,o));if(f.nodeType==3)return ct(f,K,a);if(k&&f.contentEditable!="false")return et(f,K,a);let Y=Array.prototype.indexOf.call(u.childNodes,f)+(o>=(d.left+d.right)/2?1:0);return{node:u,offset:Y}}function ct(u,o,a){let f=u.nodeValue.length,d=-1,m=1e9,S=0;for(let k=0;k<f;k++){let M=wt(u,k,k+1).getClientRects();for(let B=0;B<M.length;B++){let E=M[B];if(E.top==E.bottom)continue;S||(S=o-E.left);let H=(E.top>a?E.top-a:a-E.bottom)-1;if(E.left-1<=o&&E.right+1>=o&&H<m){let K=o>=(E.left+E.right)/2,Y=K;if((ft.chrome||ft.gecko)&&wt(u,k).getBoundingClientRect().left==E.right&&(Y=!K),H<=0)return{node:u,offset:k+(Y?1:0)};d=k+(Y?1:0),m=H}}}return{node:u,offset:d>-1?d:S>0?u.nodeValue.length:0}}function yt(u,o,a,f=-1){var d,m;let S=u.contentDOM.getBoundingClientRect(),k=S.top+u.viewState.paddingTop,M,{docHeight:B}=u.viewState,{x:E,y:H}=o,K=H-k;if(K<0)return 0;if(K>B)return u.state.doc.length;for(let St=u.viewState.heightOracle.textHeight/2,Mt=!1;M=u.elementAtHeight(K),M.type!=n.BlockType.Text;)for(;K=f>0?M.bottom+St:M.top-St,!(K>=0&&K<=B);){if(Mt)return a?null:0;Mt=!0,f=-f}H=k+K;let Y=M.from;if(Y<u.viewport.from)return u.viewport.from==0?0:a?null:Lt(u,S,M,E,H);if(Y>u.viewport.to)return u.viewport.to==u.state.doc.length?u.state.doc.length:a?null:Lt(u,S,M,E,H);let X=u.dom.ownerDocument,it=u.root.elementFromPoint?u.root:X,rt=it.elementFromPoint(E,H);rt&&!u.contentDOM.contains(rt)&&(rt=null),rt||(E=Math.max(S.left+1,Math.min(S.right-1,E)),rt=it.elementFromPoint(E,H),rt&&!u.contentDOM.contains(rt)&&(rt=null));let nt,bt=-1;if(rt&&((d=u.docView.nearest(rt))===null||d===void 0?void 0:d.isEditable)!=!1){if(X.caretPositionFromPoint){let St=X.caretPositionFromPoint(E,H);St&&({offsetNode:nt,offset:bt}=St)}else if(X.caretRangeFromPoint){let St=X.caretRangeFromPoint(E,H);St&&({startContainer:nt,startOffset:bt}=St,(!u.contentDOM.contains(nt)||ft.safari&&Pe(nt,bt,E)||ft.chrome&&xe(nt,bt,E))&&(nt=void 0))}}if(!nt||!u.docView.dom.contains(nt)){let St=_t.find(u.docView,Y);if(!St)return K>M.top+M.height/2?M.to:M.from;({node:nt,offset:bt}=et(St.dom,E,H))}let Ct=u.docView.nearest(nt);if(!Ct)return null;if(Ct.isWidget&&((m=Ct.dom)===null||m===void 0?void 0:m.nodeType)==1){let St=Ct.dom.getBoundingClientRect();return o.y<St.top||o.y<=St.bottom&&o.x<=(St.left+St.right)/2?Ct.posAtStart:Ct.posAtEnd}else return Ct.localPosFromDOM(nt,bt)+Ct.posAtStart}function Lt(u,o,a,f,d){let m=Math.round((f-o.left)*u.defaultCharacterWidth);if(u.lineWrapping&&a.height>u.defaultLineHeight*1.5){let k=u.viewState.heightOracle.textHeight,M=Math.floor((d-a.top-(u.defaultLineHeight-k)*.5)/k);m+=M*u.viewState.heightOracle.lineLength}let S=u.state.sliceDoc(a.from,a.to);return a.from+t.findColumn(S,m,u.state.tabSize)}function Pe(u,o,a){let f;if(u.nodeType!=3||o!=(f=u.nodeValue.length))return!1;for(let d=u.nextSibling;d;d=d.nextSibling)if(d.nodeType!=1||d.nodeName!="BR")return!1;return wt(u,f-1,f).getBoundingClientRect().left>a}function xe(u,o,a){if(o!=0)return!1;for(let d=u;;){let m=d.parentNode;if(!m||m.nodeType!=1||m.firstChild!=d)return!1;if(m.classList.contains("cm-line"))break;d=m}let f=u.nodeType==1?u.getBoundingClientRect():wt(u,0,Math.max(u.nodeValue.length,1)).getBoundingClientRect();return a-f.left>5}function ri(u,o){let a=u.lineBlockAt(o);if(Array.isArray(a.type)){for(let f of a.type)if(f.to>o||f.to==o&&(f.to==a.to||f.type==n.BlockType.Text))return f}return a}function Mn(u,o,a,f){let d=ri(u,o.head),m=!f||d.type!=n.BlockType.Text||!(u.lineWrapping||d.widgetLineBreaks)?null:u.coordsAtPos(o.assoc<0&&o.head>d.from?o.head-1:o.head);if(m){let S=u.dom.getBoundingClientRect(),k=u.textDirectionAt(d.from),M=u.posAtCoords({x:a==(k==n.Direction.LTR)?S.right-1:S.left+1,y:(m.top+m.bottom)/2});if(M!=null)return t.EditorSelection.cursor(M,a?-1:1)}return t.EditorSelection.cursor(a?d.to:d.from,a?-1:1)}function po(u,o,a,f){let d=u.state.doc.lineAt(o.head),m=u.bidiSpans(d),S=u.textDirectionAt(d.from);for(let k=o,M=null;;){let B=C(d,m,S,k,a),E=w;if(!B){if(d.number==(a?u.state.doc.lines:1))return k;E=`
10
- `,d=u.state.doc.line(d.number+(a?1:-1)),m=u.bidiSpans(d),B=u.visualLineSide(d,!a)}if(M){if(!M(E))return k}else{if(!f)return B;M=f(E)}k=B}}function lr(u,o,a){let f=u.state.charCategorizer(o),d=f(a);return m=>{let S=f(m);return d==t.CharCategory.Space&&(d=S),d==S}}function By(u,o,a,f){let d=o.head,m=a?1:-1;if(d==(a?u.state.doc.length:0))return t.EditorSelection.cursor(d,o.assoc);let S=o.goalColumn,k,M=u.contentDOM.getBoundingClientRect(),B=u.coordsAtPos(d,o.assoc||-1),E=u.documentTop;if(B)S==null&&(S=B.left-M.left),k=m<0?B.top:B.bottom;else{let Y=u.viewState.lineBlockAt(d);S==null&&(S=Math.min(M.right-M.left,u.defaultCharacterWidth*(d-Y.from))),k=(m<0?Y.top:Y.bottom)+E}let H=M.left+S,K=f??u.viewState.heightOracle.textHeight>>1;for(let Y=0;;Y+=10){let X=k+(K+Y)*m,it=yt(u,{x:H,y:X},!1,m);if(X<M.top||X>M.bottom||(m<0?it<d:it>d)){let rt=u.docView.coordsForChar(it),nt=!rt||X<rt.top?-1:1;return t.EditorSelection.cursor(it,nt,void 0,S)}}}function go(u,o,a){for(;;){let f=0;for(let d of u)d.between(o-1,o+1,(m,S,k)=>{if(o>m&&o<S){let M=f||a||(o-m<S-o?-1:1);o=M<0?m:S,f=M}});if(!f)return o}}function ba(u,o,a){let f=go(u.state.facet(ps).map(d=>d(u)),a.from,o.head>a.from?-1:1);return f==a.from?a:t.EditorSelection.cursor(f,f<a.from?1:-1)}class Ly{setSelectionOrigin(o){this.lastSelectionOrigin=o,this.lastSelectionTime=Date.now()}constructor(o){this.view=o,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=o.hasFocus,ft.safari&&o.contentDOM.addEventListener("input",()=>null),ft.gecko&&Xy(o.contentDOM.ownerDocument)}handleEvent(o){!zy(this.view,o)||this.ignoreDuringComposition(o)||o.type=="keydown"&&this.keydown(o)||this.runHandlers(o.type,o)}runHandlers(o,a){let f=this.handlers[o];if(f){for(let d of f.observers)d(this.view,a);for(let d of f.handlers){if(a.defaultPrevented)break;if(d(this.view,a)){a.preventDefault();break}}}}ensureHandlers(o){let a=Ny(o),f=this.handlers,d=this.view.contentDOM;for(let m in a)if(m!="scroll"){let S=!a[m].handlers.length,k=f[m];k&&S!=!k.handlers.length&&(d.removeEventListener(m,this.handleEvent),k=null),k||d.addEventListener(m,this.handleEvent,{passive:S})}for(let m in f)m!="scroll"&&!a[m]&&d.removeEventListener(m,this.handleEvent);this.handlers=a}keydown(o){if(this.lastKeyCode=o.keyCode,this.lastKeyTime=Date.now(),o.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&o.keyCode!=27&&Rf.indexOf(o.keyCode)<0&&(this.tabFocusMode=-1),ft.android&&ft.chrome&&!o.synthetic&&(o.keyCode==13||o.keyCode==8))return this.view.observer.delayAndroidKey(o.key,o.keyCode),!0;let a;return ft.ios&&!o.synthetic&&!o.altKey&&!o.metaKey&&((a=Pf.find(f=>f.keyCode==o.keyCode))&&!o.ctrlKey||Fy.indexOf(o.key)>-1&&o.ctrlKey&&!o.shiftKey)?(this.pendingIOSKey=a||o,setTimeout(()=>this.flushIOSKey(),250),!0):(o.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(o){let a=this.pendingIOSKey;return!a||a.key=="Enter"&&o&&o.from<o.to&&/^\S+$/.test(o.insert.toString())?!1:(this.pendingIOSKey=void 0,Pt(this.view.contentDOM,a.key,a.keyCode,a instanceof KeyboardEvent?a:void 0))}ignoreDuringComposition(o){return/^key/.test(o.type)?this.composing>0?!0:ft.safari&&!ft.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(o){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=o}update(o){this.view.observer.update(o),this.mouseSelection&&this.mouseSelection.update(o),this.draggedContent&&o.docChanged&&(this.draggedContent=this.draggedContent.map(o.changes)),o.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Ef(u,o){return(a,f)=>{try{return o.call(u,f,a)}catch(d){Ie(a.state,d)}}}function Ny(u){let o=Object.create(null);function a(f){return o[f]||(o[f]={observers:[],handlers:[]})}for(let f of u){let d=f.spec;if(d&&d.domEventHandlers)for(let m in d.domEventHandlers){let S=d.domEventHandlers[m];S&&a(m).handlers.push(Ef(f.value,S))}if(d&&d.domEventObservers)for(let m in d.domEventObservers){let S=d.domEventObservers[m];S&&a(m).observers.push(Ef(f.value,S))}}for(let f in Mi)a(f).handlers.push(Mi[f]);for(let f in gi)a(f).observers.push(gi[f]);return o}const Pf=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Fy="dthko",Rf=[16,17,18,20,91,92,224,225],mo=6;function bo(u){return Math.max(0,u)*.7+8}function Iy(u,o){return Math.max(Math.abs(u.clientX-o.clientX),Math.abs(u.clientY-o.clientY))}class Hy{constructor(o,a,f,d){this.view=o,this.startEvent=a,this.style=f,this.mustSelect=d,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=a,this.scrollParents=U(o.contentDOM),this.atoms=o.state.facet(ps).map(S=>S(o));let m=o.contentDOM.ownerDocument;m.addEventListener("mousemove",this.move=this.move.bind(this)),m.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=a.shiftKey,this.multiple=o.state.facet(t.EditorState.allowMultipleSelections)&&Vy(o,a),this.dragging=Wy(o,a)&&Wf(a)==1?null:!1}start(o){this.dragging===!1&&this.select(o)}move(o){if(o.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Iy(this.startEvent,o)<10)return;this.select(this.lastEvent=o);let a=0,f=0,d=0,m=0,S=this.view.win.innerWidth,k=this.view.win.innerHeight;this.scrollParents.x&&({left:d,right:S}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:m,bottom:k}=this.scrollParents.y.getBoundingClientRect());let M=gs(this.view);o.clientX-M.left<=d+mo?a=-bo(d-o.clientX):o.clientX+M.right>=S-mo&&(a=bo(o.clientX-S)),o.clientY-M.top<=m+mo?f=-bo(m-o.clientY):o.clientY+M.bottom>=k-mo&&(f=bo(o.clientY-k)),this.setScrollSpeed(a,f)}up(o){this.dragging==null&&this.select(this.lastEvent),this.dragging||o.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let o=this.view.contentDOM.ownerDocument;o.removeEventListener("mousemove",this.move),o.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(o,a){this.scrollSpeed={x:o,y:a},o||a?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:o,y:a}=this.scrollSpeed;o&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=o,o=0),a&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=a,a=0),(o||a)&&this.view.win.scrollBy(o,a),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(o){let a=null;for(let f=0;f<o.ranges.length;f++){let d=o.ranges[f],m=null;if(d.empty){let S=go(this.atoms,d.from,0);S!=d.from&&(m=t.EditorSelection.cursor(S,-1))}else{let S=go(this.atoms,d.from,-1),k=go(this.atoms,d.to,1);(S!=d.from||k!=d.to)&&(m=t.EditorSelection.range(d.from==d.anchor?S:k,d.from==d.head?S:k))}m&&(a||(a=o.ranges.slice()),a[f]=m)}return a?t.EditorSelection.create(a,o.mainIndex):o}select(o){let{view:a}=this,f=this.skipAtoms(this.style.get(o,this.extend,this.multiple));(this.mustSelect||!f.eq(a.state.selection,this.dragging===!1))&&this.view.dispatch({selection:f,userEvent:"select.pointer"}),this.mustSelect=!1}update(o){o.transactions.some(a=>a.isUserEvent("input.type"))?this.destroy():this.style.update(o)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Vy(u,o){let a=u.state.facet(L);return a.length?a[0](o):ft.mac?o.metaKey:o.ctrlKey}function $y(u,o){let a=u.state.facet(N);return a.length?a[0](o):ft.mac?!o.altKey:!o.ctrlKey}function Wy(u,o){let{main:a}=u.state.selection;if(a.empty)return!1;let f=s(u.root);if(!f||f.rangeCount==0)return!0;let d=f.getRangeAt(0).getClientRects();for(let m=0;m<d.length;m++){let S=d[m];if(S.left<=o.clientX&&S.right>=o.clientX&&S.top<=o.clientY&&S.bottom>=o.clientY)return!0}return!1}function zy(u,o){if(!o.bubbles)return!0;if(o.defaultPrevented)return!1;for(let a=o.target,f;a!=u.contentDOM;a=a.parentNode)if(!a||a.nodeType==11||(f=vt.get(a))&&f.ignoreEvent(o))return!1;return!0}const Mi=Object.create(null),gi=Object.create(null),Bf=ft.ie&&ft.ie_version<15||ft.ios&&ft.webkit_version<604;function qy(u){let o=u.dom.parentNode;if(!o)return;let a=o.appendChild(document.createElement("textarea"));a.style.cssText="position: fixed; left: -10000px; top: 10px",a.focus(),setTimeout(()=>{u.focus(),a.remove(),Lf(u,a.value)},50)}function Lf(u,o){let{state:a}=u,f,d=1,m=a.toText(o),S=m.lines==a.selection.ranges.length;if(ya!=null&&a.selection.ranges.every(M=>M.empty)&&ya==m.toString()){let M=-1;f=a.changeByRange(B=>{let E=a.doc.lineAt(B.from);if(E.from==M)return{range:B};M=E.from;let H=a.toText((S?m.line(d++).text:o)+a.lineBreak);return{changes:{from:E.from,insert:H},range:t.EditorSelection.cursor(B.from+H.length)}})}else S?f=a.changeByRange(M=>{let B=m.line(d++);return{changes:{from:M.from,to:M.to,insert:B.text},range:t.EditorSelection.cursor(M.from+B.length)}}):f=a.replaceSelection(m);u.dispatch(f,{userEvent:"input.paste",scrollIntoView:!0})}gi.scroll=u=>{u.inputState.lastScrollTop=u.scrollDOM.scrollTop,u.inputState.lastScrollLeft=u.scrollDOM.scrollLeft},Mi.keydown=(u,o)=>(u.inputState.setSelectionOrigin("select"),o.keyCode==27&&u.inputState.tabFocusMode!=0&&(u.inputState.tabFocusMode=Date.now()+2e3),!1),gi.touchstart=(u,o)=>{u.inputState.lastTouchTime=Date.now(),u.inputState.setSelectionOrigin("select.pointer")},gi.touchmove=u=>{u.inputState.setSelectionOrigin("select.pointer")},Mi.mousedown=(u,o)=>{if(u.observer.flush(),u.inputState.lastTouchTime>Date.now()-2e3)return!1;let a=null;for(let f of u.state.facet(q))if(a=f(u,o),a)break;if(!a&&o.button==0&&(a=_y(u,o)),a){let f=!u.hasFocus;u.inputState.startMouseSelection(new Hy(u,o,a,f)),f&&u.observer.ignore(()=>{st(u.contentDOM);let m=u.root.activeElement;m&&!m.contains(u.contentDOM)&&m.blur()});let d=u.inputState.mouseSelection;if(d)return d.start(o),d.dragging===!1}return!1};function Nf(u,o,a,f){if(f==1)return t.EditorSelection.cursor(o,a);if(f==2)return D(u.state,o,a);{let d=_t.find(u.docView,o),m=u.state.doc.lineAt(d?d.posAtEnd:o),S=d?d.posAtStart:m.from,k=d?d.posAtEnd:m.to;return k<u.state.doc.length&&k==m.to&&k++,t.EditorSelection.range(S,k)}}let Ff=(u,o,a)=>o>=a.top&&o<=a.bottom&&u>=a.left&&u<=a.right;function Ky(u,o,a,f){let d=_t.find(u.docView,o);if(!d)return 1;let m=o-d.posAtStart;if(m==0)return 1;if(m==d.length)return-1;let S=d.coordsAt(m,-1);if(S&&Ff(a,f,S))return-1;let k=d.coordsAt(m,1);return k&&Ff(a,f,k)?1:S&&S.bottom>=f?-1:1}function If(u,o){let a=u.posAtCoords({x:o.clientX,y:o.clientY},!1);return{pos:a,bias:Ky(u,a,o.clientX,o.clientY)}}const jy=ft.ie&&ft.ie_version<=11;let Hf=null,Vf=0,$f=0;function Wf(u){if(!jy)return u.detail;let o=Hf,a=$f;return Hf=u,$f=Date.now(),Vf=!o||a>Date.now()-400&&Math.abs(o.clientX-u.clientX)<2&&Math.abs(o.clientY-u.clientY)<2?(Vf+1)%3:1}function _y(u,o){let a=If(u,o),f=Wf(o),d=u.state.selection;return{update(m){m.docChanged&&(a.pos=m.changes.mapPos(a.pos),d=d.map(m.changes))},get(m,S,k){let M=If(u,m),B,E=Nf(u,M.pos,M.bias,f);if(a.pos!=M.pos&&!S){let H=Nf(u,a.pos,a.bias,f),K=Math.min(H.from,E.from),Y=Math.max(H.to,E.to);E=K<E.from?t.EditorSelection.range(K,Y):t.EditorSelection.range(Y,K)}return S?d.replaceRange(d.main.extend(E.from,E.to)):k&&f==1&&d.ranges.length>1&&(B=Gy(d,M.pos))?B:k?d.addRange(E):t.EditorSelection.create([E])}}}function Gy(u,o){for(let a=0;a<u.ranges.length;a++){let{from:f,to:d}=u.ranges[a];if(f<=o&&d>=o)return t.EditorSelection.create(u.ranges.slice(0,a).concat(u.ranges.slice(a+1)),u.mainIndex==a?0:u.mainIndex-(u.mainIndex>a?1:0))}return null}Mi.dragstart=(u,o)=>{let{selection:{main:a}}=u.state;if(o.target.draggable){let d=u.docView.nearest(o.target);if(d&&d.isWidget){let m=d.posAtStart,S=m+d.length;(m>=a.to||S<=a.from)&&(a=t.EditorSelection.range(m,S))}}let{inputState:f}=u;return f.mouseSelection&&(f.mouseSelection.dragging=!0),f.draggedContent=a,o.dataTransfer&&(o.dataTransfer.setData("Text",u.state.sliceDoc(a.from,a.to)),o.dataTransfer.effectAllowed="copyMove"),!1},Mi.dragend=u=>(u.inputState.draggedContent=null,!1);function zf(u,o,a,f){if(!a)return;let d=u.posAtCoords({x:o.clientX,y:o.clientY},!1),{draggedContent:m}=u.inputState,S=f&&m&&$y(u,o)?{from:m.from,to:m.to}:null,k={from:d,insert:a},M=u.state.changes(S?[S,k]:k);u.focus(),u.dispatch({changes:M,selection:{anchor:M.mapPos(d,-1),head:M.mapPos(d,1)},userEvent:S?"move.drop":"input.drop"}),u.inputState.draggedContent=null}Mi.drop=(u,o)=>{if(!o.dataTransfer)return!1;if(u.state.readOnly)return!0;let a=o.dataTransfer.files;if(a&&a.length){let f=Array(a.length),d=0,m=()=>{++d==a.length&&zf(u,o,f.filter(S=>S!=null).join(u.state.lineBreak),!1)};for(let S=0;S<a.length;S++){let k=new FileReader;k.onerror=m,k.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(k.result)||(f[S]=k.result),m()},k.readAsText(a[S])}return!0}else{let f=o.dataTransfer.getData("Text");if(f)return zf(u,o,f,!0),!0}return!1},Mi.paste=(u,o)=>{if(u.state.readOnly)return!0;u.observer.flush();let a=Bf?null:o.clipboardData;return a?(Lf(u,a.getData("text/plain")||a.getData("text/uri-list")),!0):(qy(u),!1)};function Yy(u,o){let a=u.dom.parentNode;if(!a)return;let f=a.appendChild(document.createElement("textarea"));f.style.cssText="position: fixed; left: -10000px; top: 10px",f.value=o,f.focus(),f.selectionEnd=o.length,f.selectionStart=0,setTimeout(()=>{f.remove(),u.focus()},50)}function Uy(u){let o=[],a=[],f=!1;for(let d of u.selection.ranges)d.empty||(o.push(u.sliceDoc(d.from,d.to)),a.push(d));if(!o.length){let d=-1;for(let{from:m}of u.selection.ranges){let S=u.doc.lineAt(m);S.number>d&&(o.push(S.text),a.push({from:S.from,to:Math.min(u.doc.length,S.to+1)})),d=S.number}f=!0}return{text:o.join(u.lineBreak),ranges:a,linewise:f}}let ya=null;Mi.copy=Mi.cut=(u,o)=>{let{text:a,ranges:f,linewise:d}=Uy(u.state);if(!a&&!d)return!1;ya=d?a:null,o.type=="cut"&&!u.state.readOnly&&u.dispatch({changes:f,scrollIntoView:!0,userEvent:"delete.cut"});let m=Bf?null:o.clipboardData;return m?(m.clearData(),m.setData("text/plain",a),!0):(Yy(u,a),!1)};const qf=t.Annotation.define();function Kf(u,o){let a=[];for(let f of u.facet(ht)){let d=f(u,o);d&&a.push(d)}return a?u.update({effects:a,annotations:qf.of(!0)}):null}function jf(u){setTimeout(()=>{let o=u.hasFocus;if(o!=u.inputState.notifiedFocused){let a=Kf(u.state,o);a?u.dispatch(a):u.update([])}},10)}gi.focus=u=>{u.inputState.lastFocusTime=Date.now(),!u.scrollDOM.scrollTop&&(u.inputState.lastScrollTop||u.inputState.lastScrollLeft)&&(u.scrollDOM.scrollTop=u.inputState.lastScrollTop,u.scrollDOM.scrollLeft=u.inputState.lastScrollLeft),jf(u)},gi.blur=u=>{u.observer.clearSelectionRange(),jf(u)},gi.compositionstart=gi.compositionupdate=u=>{u.observer.editContext||(u.inputState.compositionFirstChange==null&&(u.inputState.compositionFirstChange=!0),u.inputState.composing<0&&(u.inputState.composing=0))},gi.compositionend=u=>{u.observer.editContext||(u.inputState.composing=-1,u.inputState.compositionEndedAt=Date.now(),u.inputState.compositionPendingKey=!0,u.inputState.compositionPendingChange=u.observer.pendingRecords().length>0,u.inputState.compositionFirstChange=null,ft.chrome&&ft.android?u.observer.flushSoon():u.inputState.compositionPendingChange?Promise.resolve().then(()=>u.observer.flush()):setTimeout(()=>{u.inputState.composing<0&&u.docView.hasComposition&&u.update([])},50))},gi.contextmenu=u=>{u.inputState.lastContextMenu=Date.now()},Mi.beforeinput=(u,o)=>{var a;let f;if(ft.chrome&&ft.android&&(f=Pf.find(d=>d.inputType==o.inputType))&&(u.observer.delayAndroidKey(f.key,f.keyCode),f.key=="Backspace"||f.key=="Delete")){let d=((a=window.visualViewport)===null||a===void 0?void 0:a.height)||0;setTimeout(()=>{var m;(((m=window.visualViewport)===null||m===void 0?void 0:m.height)||0)>d+10&&u.hasFocus&&(u.contentDOM.blur(),u.focus())},100)}return ft.ios&&o.inputType=="deleteContentForward"&&u.observer.flushSoon(),ft.safari&&o.inputType=="insertText"&&u.inputState.composing>=0&&setTimeout(()=>gi.compositionend(u,o),20),!1};const _f=new Set;function Xy(u){_f.has(u)||(_f.add(u),u.addEventListener("copy",()=>{}),u.addEventListener("cut",()=>{}))}const Gf=["pre-wrap","normal","pre-line","break-spaces"];class Yf{constructor(o){this.lineWrapping=o,this.doc=t.Text.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(o,a){let f=this.doc.lineAt(a).number-this.doc.lineAt(o).number+1;return this.lineWrapping&&(f+=Math.max(0,Math.ceil((a-o-f*this.lineLength*.5)/this.lineLength))),this.lineHeight*f}heightForLine(o){return this.lineWrapping?(1+Math.max(0,Math.ceil((o-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(o){return this.doc=o,this}mustRefreshForWrapping(o){return Gf.indexOf(o)>-1!=this.lineWrapping}mustRefreshForHeights(o){let a=!1;for(let f=0;f<o.length;f++){let d=o[f];d<0?f++:this.heightSamples[Math.floor(d*10)]||(a=!0,this.heightSamples[Math.floor(d*10)]=!0)}return a}refresh(o,a,f,d,m,S){let k=Gf.indexOf(o)>-1,M=Math.round(a)!=Math.round(this.lineHeight)||this.lineWrapping!=k;if(this.lineWrapping=k,this.lineHeight=a,this.charWidth=f,this.textHeight=d,this.lineLength=m,M){this.heightSamples={};for(let B=0;B<S.length;B++){let E=S[B];E<0?B++:this.heightSamples[Math.floor(E*10)]=!0}}return M}}class Uf{constructor(o,a){this.from=o,this.heights=a,this.index=0}get more(){return this.index<this.heights.length}}class Ai{constructor(o,a,f,d,m){this.from=o,this.length=a,this.top=f,this.height=d,this._content=m}get type(){return typeof this._content=="number"?n.BlockType.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 Ge?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(o){let a=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(o._content)?o._content:[o]);return new Ai(this.from,this.length+o.length,this.top,this.height+o.height,a)}}var Yt;(function(u){u[u.ByPos=0]="ByPos",u[u.ByHeight=1]="ByHeight",u[u.ByPosNoHeight=2]="ByPosNoHeight"})(Yt||(Yt={}));const yo=.001;class Re{constructor(o,a,f=2){this.length=o,this.height=a,this.flags=f}get outdated(){return(this.flags&2)>0}set outdated(o){this.flags=(o?2:0)|this.flags&-3}setHeight(o,a){this.height!=a&&(Math.abs(this.height-a)>yo&&(o.heightChanged=!0),this.height=a)}replace(o,a,f){return Re.of(f)}decomposeLeft(o,a){a.push(this)}decomposeRight(o,a){a.push(this)}applyChanges(o,a,f,d){let m=this,S=f.doc;for(let k=d.length-1;k>=0;k--){let{fromA:M,toA:B,fromB:E,toB:H}=d[k],K=m.lineAt(M,Yt.ByPosNoHeight,f.setDoc(a),0,0),Y=K.to>=B?K:m.lineAt(B,Yt.ByPosNoHeight,f,0,0);for(H+=Y.to-B,B=Y.to;k>0&&K.from<=d[k-1].toA;)M=d[k-1].fromA,E=d[k-1].fromB,k--,M<K.from&&(K=m.lineAt(M,Yt.ByPosNoHeight,f,0,0));E+=K.from-M,M=K.from;let X=Sa.build(f.setDoc(S),o,E,H);m=m.replace(M,B,X)}return m.updateHeight(f,0)}static empty(){return new oi(0,0)}static of(o){if(o.length==1)return o[0];let a=0,f=o.length,d=0,m=0;for(;;)if(a==f)if(d>m*2){let k=o[a-1];k.break?o.splice(--a,1,k.left,null,k.right):o.splice(--a,1,k.left,k.right),f+=1+k.break,d-=k.size}else if(m>d*2){let k=o[f];k.break?o.splice(f,1,k.left,null,k.right):o.splice(f,1,k.left,k.right),f+=2+k.break,m-=k.size}else break;else if(d<m){let k=o[a++];k&&(d+=k.size)}else{let k=o[--f];k&&(m+=k.size)}let S=0;return o[a-1]==null?(S=1,a--):o[a]==null&&(S=1,f++),new Jy(Re.of(o.slice(0,a)),S,Re.of(o.slice(f)))}}Re.prototype.size=1;class Xf extends Re{constructor(o,a,f){super(o,a),this.deco=f}blockAt(o,a,f,d){return new Ai(d,this.length,f,this.height,this.deco||0)}lineAt(o,a,f,d,m){return this.blockAt(0,f,d,m)}forEachLine(o,a,f,d,m,S){o<=m+this.length&&a>=m&&S(this.blockAt(0,f,d,m))}updateHeight(o,a=0,f=!1,d){return d&&d.from<=a&&d.more&&this.setHeight(o,d.heights[d.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class oi extends Xf{constructor(o,a){super(o,a,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(o,a,f,d){return new Ai(d,this.length,f,this.height,this.breaks)}replace(o,a,f){let d=f[0];return f.length==1&&(d instanceof oi||d instanceof ve&&d.flags&4)&&Math.abs(this.length-d.length)<10?(d instanceof ve?d=new oi(d.length,this.height):d.height=this.height,this.outdated||(d.outdated=!1),d):Re.of(f)}updateHeight(o,a=0,f=!1,d){return d&&d.from<=a&&d.more?this.setHeight(o,d.heights[d.index++]):(f||this.outdated)&&this.setHeight(o,Math.max(this.widgetHeight,o.heightForLine(this.length-this.collapsed))+this.breaks*o.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ve extends Re{constructor(o){super(o,0)}heightMetrics(o,a){let f=o.doc.lineAt(a).number,d=o.doc.lineAt(a+this.length).number,m=d-f+1,S,k=0;if(o.lineWrapping){let M=Math.min(this.height,o.lineHeight*m);S=M/m,this.length>m+1&&(k=(this.height-M)/(this.length-m-1))}else S=this.height/m;return{firstLine:f,lastLine:d,perLine:S,perChar:k}}blockAt(o,a,f,d){let{firstLine:m,lastLine:S,perLine:k,perChar:M}=this.heightMetrics(a,d);if(a.lineWrapping){let B=d+(o<a.lineHeight?0:Math.round(Math.max(0,Math.min(1,(o-f)/this.height))*this.length)),E=a.doc.lineAt(B),H=k+E.length*M,K=Math.max(f,o-H/2);return new Ai(E.from,E.length,K,H,0)}else{let B=Math.max(0,Math.min(S-m,Math.floor((o-f)/k))),{from:E,length:H}=a.doc.line(m+B);return new Ai(E,H,f+k*B,k,0)}}lineAt(o,a,f,d,m){if(a==Yt.ByHeight)return this.blockAt(o,f,d,m);if(a==Yt.ByPosNoHeight){let{from:Y,to:X}=f.doc.lineAt(o);return new Ai(Y,X-Y,0,0,0)}let{firstLine:S,perLine:k,perChar:M}=this.heightMetrics(f,m),B=f.doc.lineAt(o),E=k+B.length*M,H=B.number-S,K=d+k*H+M*(B.from-m-H);return new Ai(B.from,B.length,Math.max(d,Math.min(K,d+this.height-E)),E,0)}forEachLine(o,a,f,d,m,S){o=Math.max(o,m),a=Math.min(a,m+this.length);let{firstLine:k,perLine:M,perChar:B}=this.heightMetrics(f,m);for(let E=o,H=d;E<=a;){let K=f.doc.lineAt(E);if(E==o){let X=K.number-k;H+=M*X+B*(o-m-X)}let Y=M+B*K.length;S(new Ai(K.from,K.length,H,Y,0)),H+=Y,E=K.to+1}}replace(o,a,f){let d=this.length-a;if(d>0){let m=f[f.length-1];m instanceof ve?f[f.length-1]=new ve(m.length+d):f.push(null,new ve(d-1))}if(o>0){let m=f[0];m instanceof ve?f[0]=new ve(o+m.length):f.unshift(new ve(o-1),null)}return Re.of(f)}decomposeLeft(o,a){a.push(new ve(o-1),null)}decomposeRight(o,a){a.push(null,new ve(this.length-o-1))}updateHeight(o,a=0,f=!1,d){let m=a+this.length;if(d&&d.from<=a+this.length&&d.more){let S=[],k=Math.max(a,d.from),M=-1;for(d.from>a&&S.push(new ve(d.from-a-1).updateHeight(o,a));k<=m&&d.more;){let E=o.doc.lineAt(k).length;S.length&&S.push(null);let H=d.heights[d.index++];M==-1?M=H:Math.abs(H-M)>=yo&&(M=-2);let K=new oi(E,H);K.outdated=!1,S.push(K),k+=E+1}k<=m&&S.push(null,new ve(m-k).updateHeight(o,k));let B=Re.of(S);return(M<0||Math.abs(B.height-this.height)>=yo||Math.abs(M-this.heightMetrics(o,a).perLine)>=yo)&&(o.heightChanged=!0),B}else(f||this.outdated)&&(this.setHeight(o,o.heightForGap(a,a+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Jy extends Re{constructor(o,a,f){super(o.length+a+f.length,o.height+f.height,a|(o.outdated||f.outdated?2:0)),this.left=o,this.right=f,this.size=o.size+f.size}get break(){return this.flags&1}blockAt(o,a,f,d){let m=f+this.left.height;return o<m?this.left.blockAt(o,a,f,d):this.right.blockAt(o,a,m,d+this.left.length+this.break)}lineAt(o,a,f,d,m){let S=d+this.left.height,k=m+this.left.length+this.break,M=a==Yt.ByHeight?o<S:o<k,B=M?this.left.lineAt(o,a,f,d,m):this.right.lineAt(o,a,f,S,k);if(this.break||(M?B.to<k:B.from>k))return B;let E=a==Yt.ByPosNoHeight?Yt.ByPosNoHeight:Yt.ByPos;return M?B.join(this.right.lineAt(k,E,f,S,k)):this.left.lineAt(k,E,f,d,m).join(B)}forEachLine(o,a,f,d,m,S){let k=d+this.left.height,M=m+this.left.length+this.break;if(this.break)o<M&&this.left.forEachLine(o,a,f,d,m,S),a>=M&&this.right.forEachLine(o,a,f,k,M,S);else{let B=this.lineAt(M,Yt.ByPos,f,d,m);o<B.from&&this.left.forEachLine(o,B.from-1,f,d,m,S),B.to>=o&&B.from<=a&&S(B),a>B.to&&this.right.forEachLine(B.to+1,a,f,k,M,S)}}replace(o,a,f){let d=this.left.length+this.break;if(a<d)return this.balanced(this.left.replace(o,a,f),this.right);if(o>this.left.length)return this.balanced(this.left,this.right.replace(o-d,a-d,f));let m=[];o>0&&this.decomposeLeft(o,m);let S=m.length;for(let k of f)m.push(k);if(o>0&&Jf(m,S-1),a<this.length){let k=m.length;this.decomposeRight(a,m),Jf(m,k)}return Re.of(m)}decomposeLeft(o,a){let f=this.left.length;if(o<=f)return this.left.decomposeLeft(o,a);a.push(this.left),this.break&&(f++,o>=f&&a.push(null)),o>f&&this.right.decomposeLeft(o-f,a)}decomposeRight(o,a){let f=this.left.length,d=f+this.break;if(o>=d)return this.right.decomposeRight(o-d,a);o<f&&this.left.decomposeRight(o,a),this.break&&o<d&&a.push(null),a.push(this.right)}balanced(o,a){return o.size>2*a.size||a.size>2*o.size?Re.of(this.break?[o,null,a]:[o,a]):(this.left=o,this.right=a,this.height=o.height+a.height,this.outdated=o.outdated||a.outdated,this.size=o.size+a.size,this.length=o.length+this.break+a.length,this)}updateHeight(o,a=0,f=!1,d){let{left:m,right:S}=this,k=a+m.length+this.break,M=null;return d&&d.from<=a+m.length&&d.more?M=m=m.updateHeight(o,a,f,d):m.updateHeight(o,a,f),d&&d.from<=k+S.length&&d.more?M=S=S.updateHeight(o,k,f,d):S.updateHeight(o,k,f),M?this.balanced(m,S):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Jf(u,o){let a,f;u[o]==null&&(a=u[o-1])instanceof ve&&(f=u[o+1])instanceof ve&&u.splice(o-1,3,new ve(a.length+1+f.length))}const Qy=5;class Sa{constructor(o,a){this.pos=o,this.oracle=a,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=o}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(o,a){if(this.lineStart>-1){let f=Math.min(a,this.lineEnd),d=this.nodes[this.nodes.length-1];d instanceof oi?d.length+=f-this.pos:(f>this.pos||!this.isCovered)&&this.nodes.push(new oi(f-this.pos,-1)),this.writtenTo=f,a>f&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=a}point(o,a,f){if(o<a||f.heightRelevant){let d=f.widget?f.widget.estimatedHeight:0,m=f.widget?f.widget.lineBreaks:0;d<0&&(d=this.oracle.lineHeight);let S=a-o;f.block?this.addBlock(new Xf(S,d,f)):(S||m||d>=Qy)&&this.addLineDeco(d,m,S)}else a>o&&this.span(o,a);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:o,to:a}=this.oracle.doc.lineAt(this.pos);this.lineStart=o,this.lineEnd=a,this.writtenTo<o&&((this.writtenTo<o-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,o-1)),this.nodes.push(null)),this.pos>o&&this.nodes.push(new oi(this.pos-o,-1)),this.writtenTo=this.pos}blankContent(o,a){let f=new ve(a-o);return this.oracle.doc.lineAt(o).to==a&&(f.flags|=4),f}ensureLine(){this.enterLine();let o=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(o instanceof oi)return o;let a=new oi(0,-1);return this.nodes.push(a),a}addBlock(o){this.enterLine();let a=o.deco;a&&a.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(o),this.writtenTo=this.pos=this.pos+o.length,a&&a.endSide>0&&(this.covering=o)}addLineDeco(o,a,f){let d=this.ensureLine();d.length+=f,d.collapsed+=f,d.widgetHeight=Math.max(d.widgetHeight,o),d.breaks+=a,this.writtenTo=this.pos=this.pos+f}finish(o){let a=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(a instanceof oi)&&!this.isCovered?this.nodes.push(new oi(0,-1)):(this.writtenTo<this.pos||a==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let f=o;for(let d of this.nodes)d instanceof oi&&d.updateHeight(this.oracle,f),f+=d?d.length:1;return this.nodes}static build(o,a,f,d){let m=new Sa(f,o);return t.RangeSet.spans(a,f,d,m,0),m.finish(f)}}function Zy(u,o,a){let f=new t1;return t.RangeSet.compare(u,o,a,f,0),f.changes}class t1{constructor(){this.changes=[]}compareRange(){}comparePoint(o,a,f,d){(o<a||f&&f.heightRelevant||d&&d.heightRelevant)&&Wt(o,a,this.changes,5)}}function e1(u,o){let a=u.getBoundingClientRect(),f=u.ownerDocument,d=f.defaultView||window,m=Math.max(0,a.left),S=Math.min(d.innerWidth,a.right),k=Math.max(0,a.top),M=Math.min(d.innerHeight,a.bottom);for(let B=u.parentNode;B&&B!=f.body;)if(B.nodeType==1){let E=B,H=window.getComputedStyle(E);if((E.scrollHeight>E.clientHeight||E.scrollWidth>E.clientWidth)&&H.overflow!="visible"){let K=E.getBoundingClientRect();m=Math.max(m,K.left),S=Math.min(S,K.right),k=Math.max(k,K.top),M=B==u.parentNode?K.bottom:Math.min(M,K.bottom)}B=H.position=="absolute"||H.position=="fixed"?E.offsetParent:E.parentNode}else if(B.nodeType==11)B=B.host;else break;return{left:m-a.left,right:Math.max(m,S)-a.left,top:k-(a.top+o),bottom:Math.max(k,M)-(a.top+o)}}function i1(u,o){let a=u.getBoundingClientRect();return{left:0,right:a.right-a.left,top:o,bottom:a.bottom-(a.top+o)}}class wa{constructor(o,a,f){this.from=o,this.to=a,this.size=f}static same(o,a){if(o.length!=a.length)return!1;for(let f=0;f<o.length;f++){let d=o[f],m=a[f];if(d.from!=m.from||d.to!=m.to||d.size!=m.size)return!1}return!0}draw(o,a){return Vt.replace({widget:new n1(this.size*(a?o.scaleY:o.scaleX),a)}).range(this.from,this.to)}}class n1 extends _e{constructor(o,a){super(),this.size=o,this.vertical=a}eq(o){return o.size==this.size&&o.vertical==this.vertical}toDOM(){let o=document.createElement("div");return this.vertical?o.style.height=this.size+"px":(o.style.width=this.size+"px",o.style.height="2px",o.style.display="inline-block"),o}get estimatedHeight(){return this.vertical?this.size:-1}}class Qf{constructor(o){this.state=o,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=Zf,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=n.Direction.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let a=o.facet(Vi).some(f=>typeof f!="function"&&f.class=="cm-lineWrapping");this.heightOracle=new Yf(a),this.stateDeco=o.facet(Yn).filter(f=>typeof f!="function"),this.heightMap=Re.empty().applyChanges(this.stateDeco,t.Text.empty,this.heightOracle.setDoc(o.doc),[new He(0,0,0,o.doc.length)]);for(let f=0;f<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());f++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Vt.set(this.lineGaps.map(f=>f.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let o=[this.viewport],{main:a}=this.state.selection;for(let f=0;f<=1;f++){let d=f?a.head:a.anchor;if(!o.some(({from:m,to:S})=>d>=m&&d<=S)){let{from:m,to:S}=this.lineBlockAt(d);o.push(new So(m,S))}}return this.viewports=o.sort((f,d)=>f.from-d.from),this.updateScaler()}updateScaler(){let o=this.scaler;return this.scaler=this.heightMap.height<=7e6?Zf:new xa(this.heightOracle,this.heightMap,this.viewports),o.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,o=>{this.viewportLines.push(ar(o,this.scaler))})}update(o,a=null){this.state=o.state;let f=this.stateDeco;this.stateDeco=this.state.facet(Yn).filter(E=>typeof E!="function");let d=o.changedRanges,m=He.extendWithRanges(d,Zy(f,this.stateDeco,o?o.changes:t.ChangeSet.empty(this.state.doc.length))),S=this.heightMap.height,k=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,o.startState.doc,this.heightOracle.setDoc(this.state.doc),m),this.heightMap.height!=S&&(o.flags|=2),k?(this.scrollAnchorPos=o.changes.mapPos(k.from,-1),this.scrollAnchorHeight=k.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let M=m.length?this.mapViewport(this.viewport,o.changes):this.viewport;(a&&(a.range.head<M.from||a.range.head>M.to)||!this.viewportIsAppropriate(M))&&(M=this.getViewport(0,a));let B=M.from!=this.viewport.from||M.to!=this.viewport.to;this.viewport=M,o.flags|=this.updateForViewport(),(B||!o.changes.empty||o.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,o.changes))),o.flags|=this.computeVisibleRanges(),a&&(this.scrollTarget=a),!this.mustEnforceCursorAssoc&&o.selectionSet&&o.view.lineWrapping&&o.state.selection.main.empty&&o.state.selection.main.assoc&&!o.state.facet(pt)&&(this.mustEnforceCursorAssoc=!0)}measure(o){let a=o.contentDOM,f=window.getComputedStyle(a),d=this.heightOracle,m=f.whiteSpace;this.defaultTextDirection=f.direction=="rtl"?n.Direction.RTL:n.Direction.LTR;let S=this.heightOracle.mustRefreshForWrapping(m),k=a.getBoundingClientRect(),M=S||this.mustMeasureContent||this.contentDOMHeight!=k.height;this.contentDOMHeight=k.height,this.mustMeasureContent=!1;let B=0,E=0;if(k.width&&k.height){let{scaleX:St,scaleY:Mt}=z(a,k);(St>.005&&Math.abs(this.scaleX-St)>.005||Mt>.005&&Math.abs(this.scaleY-Mt)>.005)&&(this.scaleX=St,this.scaleY=Mt,B|=8,S=M=!0)}let H=(parseInt(f.paddingTop)||0)*this.scaleY,K=(parseInt(f.paddingBottom)||0)*this.scaleY;(this.paddingTop!=H||this.paddingBottom!=K)&&(this.paddingTop=H,this.paddingBottom=K,B|=10),this.editorWidth!=o.scrollDOM.clientWidth&&(d.lineWrapping&&(M=!0),this.editorWidth=o.scrollDOM.clientWidth,B|=8);let Y=o.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=Y&&(this.scrollAnchorHeight=-1,this.scrollTop=Y),this.scrolledToBottom=zt(o.scrollDOM);let X=(this.printing?i1:e1)(a,this.paddingTop),it=X.top-this.pixelViewport.top,rt=X.bottom-this.pixelViewport.bottom;this.pixelViewport=X;let nt=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(nt!=this.inView&&(this.inView=nt,nt&&(M=!0)),!this.inView&&!this.scrollTarget)return 0;let bt=k.width;if((this.contentDOMWidth!=bt||this.editorHeight!=o.scrollDOM.clientHeight)&&(this.contentDOMWidth=k.width,this.editorHeight=o.scrollDOM.clientHeight,B|=8),M){let St=o.docView.measureVisibleLineHeights(this.viewport);if(d.mustRefreshForHeights(St)&&(S=!0),S||d.lineWrapping&&Math.abs(bt-this.contentDOMWidth)>d.charWidth){let{lineHeight:Mt,charWidth:Et,textHeight:fe}=o.docView.measureTextSize();S=Mt>0&&d.refresh(m,Mt,Et,fe,bt/Et,St),S&&(o.docView.minWidth=0,B|=8)}it>0&&rt>0?E=Math.max(it,rt):it<0&&rt<0&&(E=Math.min(it,rt)),d.heightChanged=!1;for(let Mt of this.viewports){let Et=Mt.from==this.viewport.from?St:o.docView.measureVisibleLineHeights(Mt);this.heightMap=(S?Re.empty().applyChanges(this.stateDeco,t.Text.empty,this.heightOracle,[new He(0,0,0,o.state.doc.length)]):this.heightMap).updateHeight(d,0,S,new Uf(Mt.from,Et))}d.heightChanged&&(B|=2)}let Ct=!this.viewportIsAppropriate(this.viewport,E)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return Ct&&(B&2&&(B|=this.updateScaler()),this.viewport=this.getViewport(E,this.scrollTarget),B|=this.updateForViewport()),(B&2||Ct)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(S?[]:this.lineGaps,o)),B|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,o.docView.enforceCursorAssoc()),B}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(o,a){let f=.5-Math.max(-.5,Math.min(.5,o/1e3/2)),d=this.heightMap,m=this.heightOracle,{visibleTop:S,visibleBottom:k}=this,M=new So(d.lineAt(S-f*1e3,Yt.ByHeight,m,0,0).from,d.lineAt(k+(1-f)*1e3,Yt.ByHeight,m,0,0).to);if(a){let{head:B}=a.range;if(B<M.from||B>M.to){let E=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),H=d.lineAt(B,Yt.ByPos,m,0,0),K;a.y=="center"?K=(H.top+H.bottom)/2-E/2:a.y=="start"||a.y=="nearest"&&B<M.from?K=H.top:K=H.bottom-E,M=new So(d.lineAt(K-1e3/2,Yt.ByHeight,m,0,0).from,d.lineAt(K+E+1e3/2,Yt.ByHeight,m,0,0).to)}}return M}mapViewport(o,a){let f=a.mapPos(o.from,-1),d=a.mapPos(o.to,1);return new So(this.heightMap.lineAt(f,Yt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(d,Yt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:o,to:a},f=0){if(!this.inView)return!0;let{top:d}=this.heightMap.lineAt(o,Yt.ByPos,this.heightOracle,0,0),{bottom:m}=this.heightMap.lineAt(a,Yt.ByPos,this.heightOracle,0,0),{visibleTop:S,visibleBottom:k}=this;return(o==0||d<=S-Math.max(10,Math.min(-f,250)))&&(a==this.state.doc.length||m>=k+Math.max(10,Math.min(f,250)))&&d>S-2*1e3&&m<k+2*1e3}mapLineGaps(o,a){if(!o.length||a.empty)return o;let f=[];for(let d of o)a.touchesRange(d.from,d.to)||f.push(new wa(a.mapPos(d.from),a.mapPos(d.to),d.size));return f}ensureLineGaps(o,a){let f=this.heightOracle.lineWrapping,d=f?1e4:2e3,m=d>>1,S=d<<1;if(this.defaultTextDirection!=n.Direction.LTR&&!f)return[];let k=[],M=(E,H,K,Y)=>{if(H-E<m)return;let X=this.state.selection.main,it=[X.from];X.empty||it.push(X.to);for(let nt of it)if(nt>E&&nt<H){M(E,nt-10,K,Y),M(nt+10,H,K,Y);return}let rt=r1(o,nt=>nt.from>=K.from&&nt.to<=K.to&&Math.abs(nt.from-E)<m&&Math.abs(nt.to-H)<m&&!it.some(bt=>nt.from<bt&&nt.to>bt));if(!rt){if(H<K.to&&a&&f&&a.visibleRanges.some(nt=>nt.from<=H&&nt.to>=H)){let nt=a.moveToLineBoundary(t.EditorSelection.cursor(H),!1,!0).head;nt>E&&(H=nt)}rt=new wa(E,H,this.gapSize(K,E,H,Y))}k.push(rt)},B=E=>{if(E.length<S||E.type!=n.BlockType.Text)return;let H=s1(E.from,E.to,this.stateDeco);if(H.total<S)return;let K=this.scrollTarget?this.scrollTarget.range.head:null,Y,X;if(f){let it=d/this.heightOracle.lineLength*this.heightOracle.lineHeight,rt,nt;if(K!=null){let bt=xo(H,K),Ct=((this.visibleBottom-this.visibleTop)/2+it)/E.height;rt=bt-Ct,nt=bt+Ct}else rt=(this.visibleTop-E.top-it)/E.height,nt=(this.visibleBottom-E.top+it)/E.height;Y=wo(H,rt),X=wo(H,nt)}else{let it=H.total*this.heightOracle.charWidth,rt=d*this.heightOracle.charWidth,nt,bt;if(K!=null){let Ct=xo(H,K),St=((this.pixelViewport.right-this.pixelViewport.left)/2+rt)/it;nt=Ct-St,bt=Ct+St}else nt=(this.pixelViewport.left-rt)/it,bt=(this.pixelViewport.right+rt)/it;Y=wo(H,nt),X=wo(H,bt)}Y>E.from&&M(E.from,Y,E,H),X<E.to&&M(X,E.to,E,H)};for(let E of this.viewportLines)Array.isArray(E.type)?E.type.forEach(B):B(E);return k}gapSize(o,a,f,d){let m=xo(d,f)-xo(d,a);return this.heightOracle.lineWrapping?o.height*m:d.total*this.heightOracle.charWidth*m}updateLineGaps(o){wa.same(o,this.lineGaps)||(this.lineGaps=o,this.lineGapDeco=Vt.set(o.map(a=>a.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let o=this.stateDeco;this.lineGaps.length&&(o=o.concat(this.lineGapDeco));let a=[];t.RangeSet.spans(o,this.viewport.from,this.viewport.to,{span(d,m){a.push({from:d,to:m})},point(){}},20);let f=a.length!=this.visibleRanges.length||this.visibleRanges.some((d,m)=>d.from!=a[m].from||d.to!=a[m].to);return this.visibleRanges=a,f?4:0}lineBlockAt(o){return o>=this.viewport.from&&o<=this.viewport.to&&this.viewportLines.find(a=>a.from<=o&&a.to>=o)||ar(this.heightMap.lineAt(o,Yt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(o){return o>=this.viewportLines[0].top&&o<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(a=>a.top<=o&&a.bottom>=o)||ar(this.heightMap.lineAt(this.scaler.fromDOM(o),Yt.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(o){let a=this.lineBlockAtHeight(o+8);return a.from>=this.viewport.from||this.viewportLines[0].top-o>200?a:this.viewportLines[0]}elementAtHeight(o){return ar(this.heightMap.blockAt(this.scaler.fromDOM(o),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 So{constructor(o,a){this.from=o,this.to=a}}function s1(u,o,a){let f=[],d=u,m=0;return t.RangeSet.spans(a,u,o,{span(){},point(S,k){S>d&&(f.push({from:d,to:S}),m+=S-d),d=k}},20),d<o&&(f.push({from:d,to:o}),m+=o-d),{total:m,ranges:f}}function wo({total:u,ranges:o},a){if(a<=0)return o[0].from;if(a>=1)return o[o.length-1].to;let f=Math.floor(u*a);for(let d=0;;d++){let{from:m,to:S}=o[d],k=S-m;if(f<=k)return m+f;f-=k}}function xo(u,o){let a=0;for(let{from:f,to:d}of u.ranges){if(o<=d){a+=o-f;break}a+=d-f}return a/u.total}function r1(u,o){for(let a of u)if(o(a))return a}const Zf={toDOM(u){return u},fromDOM(u){return u},scale:1,eq(u){return u==this}};class xa{constructor(o,a,f){let d=0,m=0,S=0;this.viewports=f.map(({from:k,to:M})=>{let B=a.lineAt(k,Yt.ByPos,o,0,0).top,E=a.lineAt(M,Yt.ByPos,o,0,0).bottom;return d+=E-B,{from:k,to:M,top:B,bottom:E,domTop:0,domBottom:0}}),this.scale=(7e6-d)/(a.height-d);for(let k of this.viewports)k.domTop=S+(k.top-m)*this.scale,S=k.domBottom=k.domTop+(k.bottom-k.top),m=k.bottom}toDOM(o){for(let a=0,f=0,d=0;;a++){let m=a<this.viewports.length?this.viewports[a]:null;if(!m||o<m.top)return d+(o-f)*this.scale;if(o<=m.bottom)return m.domTop+(o-m.top);f=m.bottom,d=m.domBottom}}fromDOM(o){for(let a=0,f=0,d=0;;a++){let m=a<this.viewports.length?this.viewports[a]:null;if(!m||o<m.domTop)return f+(o-d)/this.scale;if(o<=m.domBottom)return m.top+(o-m.domTop);f=m.bottom,d=m.domBottom}}eq(o){return o instanceof xa?this.scale==o.scale&&this.viewports.length==o.viewports.length&&this.viewports.every((a,f)=>a.from==o.viewports[f].from&&a.to==o.viewports[f].to):!1}}function ar(u,o){if(o.scale==1)return u;let a=o.toDOM(u.top),f=o.toDOM(u.bottom);return new Ai(u.from,u.length,a,f-a,Array.isArray(u._content)?u._content.map(d=>ar(d,o)):u._content)}const vo=t.Facet.define({combine:u=>u.join(" ")}),va=t.Facet.define({combine:u=>u.indexOf(!0)>-1}),ka=e.StyleModule.newName(),td=e.StyleModule.newName(),ed=e.StyleModule.newName(),id={"&light":"."+td,"&dark":"."+ed};function Ca(u,o,a){return new e.StyleModule(o,{finish(f){return/&/.test(f)?f.replace(/&\w*/,d=>{if(d=="&")return u;if(!a||!a[d])throw new RangeError(`Unsupported selector: ${d}`);return a[d]}):u+" "+f}})}const o1=Ca("."+ka,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,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:"#444"},".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",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".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"}},id),hr="￿";class l1{constructor(o,a){this.points=o,this.text="",this.lineSeparator=a.facet(t.EditorState.lineSeparator)}append(o){this.text+=o}lineBreak(){this.text+=hr}readRange(o,a){if(!o)return this;let f=o.parentNode;for(let d=o;;){this.findPointBefore(f,d);let m=this.text.length;this.readNode(d);let S=d.nextSibling;if(S==a)break;let k=vt.get(d),M=vt.get(S);(k&&M?k.breakAfter:(k?k.breakAfter:y(d))||y(S)&&(d.nodeName!="BR"||d.cmIgnore)&&this.text.length>m)&&this.lineBreak(),d=S}return this.findPointBefore(f,a),this}readTextNode(o){let a=o.nodeValue;for(let f of this.points)f.node==o&&(f.pos=this.text.length+Math.min(f.offset,a.length));for(let f=0,d=this.lineSeparator?null:/\r\n?|\n/g;;){let m=-1,S=1,k;if(this.lineSeparator?(m=a.indexOf(this.lineSeparator,f),S=this.lineSeparator.length):(k=d.exec(a))&&(m=k.index,S=k[0].length),this.append(a.slice(f,m<0?a.length:m)),m<0)break;if(this.lineBreak(),S>1)for(let M of this.points)M.node==o&&M.pos>this.text.length&&(M.pos-=S-1);f=m+S}}readNode(o){if(o.cmIgnore)return;let a=vt.get(o),f=a&&a.overrideDOMText;if(f!=null){this.findPointInside(o,f.length);for(let d=f.iter();!d.next().done;)d.lineBreak?this.lineBreak():this.append(d.value)}else o.nodeType==3?this.readTextNode(o):o.nodeName=="BR"?o.nextSibling&&this.lineBreak():o.nodeType==1&&this.readRange(o.firstChild,null)}findPointBefore(o,a){for(let f of this.points)f.node==o&&o.childNodes[f.offset]==a&&(f.pos=this.text.length)}findPointInside(o,a){for(let f of this.points)(o.nodeType==3?f.node==o:o.contains(f.node))&&(f.pos=this.text.length+(a1(o,f.node,f.offset)?a:0))}}function a1(u,o,a){for(;;){if(!o||a<T(o))return!1;if(o==u)return!0;a=p(o)+1,o=o.parentNode}}class nd{constructor(o,a){this.node=o,this.offset=a,this.pos=-1}}class h1{constructor(o,a,f,d){this.typeOver=d,this.bounds=null,this.text="",this.domChanged=a>-1;let{impreciseHead:m,impreciseAnchor:S}=o.docView;if(o.state.readOnly&&a>-1)this.newSel=null;else if(a>-1&&(this.bounds=o.docView.domBoundsAround(a,f,0))){let k=m||S?[]:d1(o),M=new l1(k,o.state);M.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=M.text,this.newSel=u1(k,this.bounds.from)}else{let k=o.observer.selectionRange,M=m&&m.node==k.focusNode&&m.offset==k.focusOffset||!r(o.contentDOM,k.focusNode)?o.state.selection.main.head:o.docView.posFromDOM(k.focusNode,k.focusOffset),B=S&&S.node==k.anchorNode&&S.offset==k.anchorOffset||!r(o.contentDOM,k.anchorNode)?o.state.selection.main.anchor:o.docView.posFromDOM(k.anchorNode,k.anchorOffset),E=o.viewport;if((ft.ios||ft.chrome)&&o.state.selection.main.empty&&M!=B&&(E.from>0||E.to<o.state.doc.length)){let H=Math.min(M,B),K=Math.max(M,B),Y=E.from-H,X=E.to-K;(Y==0||Y==1||H==0)&&(X==0||X==-1||K==o.state.doc.length)&&(M=0,B=o.state.doc.length)}this.newSel=t.EditorSelection.single(B,M)}}}function sd(u,o){let a,{newSel:f}=o,d=u.state.selection.main,m=u.inputState.lastKeyTime>Date.now()-100?u.inputState.lastKeyCode:-1;if(o.bounds){let{from:S,to:k}=o.bounds,M=d.from,B=null;(m===8||ft.android&&o.text.length<k-S)&&(M=d.to,B="end");let E=f1(u.state.doc.sliceString(S,k,hr),o.text,M-S,B);E&&(ft.chrome&&m==13&&E.toB==E.from+2&&o.text.slice(E.from,E.toB)==hr+hr&&E.toB--,a={from:S+E.from,to:S+E.toA,insert:t.Text.of(o.text.slice(E.from,E.toB).split(hr))})}else f&&(!u.hasFocus&&u.state.facet(pi)||f.main.eq(d))&&(f=null);if(!a&&!f)return!1;if(!a&&o.typeOver&&!d.empty&&f&&f.main.empty?a={from:d.from,to:d.to,insert:u.state.doc.slice(d.from,d.to)}:a&&a.from>=d.from&&a.to<=d.to&&(a.from!=d.from||a.to!=d.to)&&d.to-d.from-(a.to-a.from)<=4?a={from:d.from,to:d.to,insert:u.state.doc.slice(d.from,a.from).append(a.insert).append(u.state.doc.slice(a.to,d.to))}:(ft.mac||ft.android)&&a&&a.from==a.to&&a.from==d.head-1&&/^\. ?$/.test(a.insert.toString())&&u.contentDOM.getAttribute("autocorrect")=="off"?(f&&a.insert.length==2&&(f=t.EditorSelection.single(f.main.anchor-1,f.main.head-1)),a={from:d.from,to:d.to,insert:t.Text.of([" "])}):ft.chrome&&a&&a.from==a.to&&a.from==d.head&&a.insert.toString()==`
11
- `&&u.lineWrapping&&(f&&(f=t.EditorSelection.single(f.main.anchor-1,f.main.head-1)),a={from:d.from,to:d.to,insert:t.Text.of([" "])}),a)return rd(u,a,f,m);if(f&&!f.main.eq(d)){let S=!1,k="select";return u.inputState.lastSelectionTime>Date.now()-50&&(u.inputState.lastSelectionOrigin=="select"&&(S=!0),k=u.inputState.lastSelectionOrigin),u.dispatch({selection:f,scrollIntoView:S,userEvent:k}),!0}else return!1}function rd(u,o,a,f=-1){if(ft.ios&&u.inputState.flushIOSKey(o))return!0;let d=u.state.selection.main;if(ft.android&&(o.to==d.to&&(o.from==d.from||o.from==d.from-1&&u.state.sliceDoc(o.from,d.from)==" ")&&o.insert.length==1&&o.insert.lines==2&&Pt(u.contentDOM,"Enter",13)||(o.from==d.from-1&&o.to==d.to&&o.insert.length==0||f==8&&o.insert.length<o.to-o.from&&o.to>d.head)&&Pt(u.contentDOM,"Backspace",8)||o.from==d.from&&o.to==d.to+1&&o.insert.length==0&&Pt(u.contentDOM,"Delete",46)))return!0;let m=o.insert.toString();u.inputState.composing>=0&&u.inputState.composing++;let S,k=()=>S||(S=c1(u,o,a));return u.state.facet(lt).some(M=>M(u,o.from,o.to,m,k))||u.dispatch(k()),!0}function c1(u,o,a){let f,d=u.state,m=d.selection.main;if(o.from>=m.from&&o.to<=m.to&&o.to-o.from>=(m.to-m.from)/3&&(!a||a.main.empty&&a.main.from==o.from+o.insert.length)&&u.inputState.composing<0){let k=m.from<o.from?d.sliceDoc(m.from,o.from):"",M=m.to>o.to?d.sliceDoc(o.to,m.to):"";f=d.replaceSelection(u.state.toText(k+o.insert.sliceString(0,void 0,u.state.lineBreak)+M))}else{let k=d.changes(o),M=a&&a.main.to<=k.newLength?a.main:void 0;if(d.selection.ranges.length>1&&u.inputState.composing>=0&&o.to<=m.to&&o.to>=m.to-10){let B=u.state.sliceDoc(o.from,o.to),E,H=a&&fo(u,a.main.head);if(H){let X=o.insert.length-(o.to-o.from);E={from:H.from,to:H.to-X}}else E=u.state.doc.lineAt(m.head);let K=m.to-o.to,Y=m.to-m.from;f=d.changeByRange(X=>{if(X.from==m.from&&X.to==m.to)return{changes:k,range:M||X.map(k)};let it=X.to-K,rt=it-B.length;if(X.to-X.from!=Y||u.state.sliceDoc(rt,it)!=B||X.to>=E.from&&X.from<=E.to)return{range:X};let nt=d.changes({from:rt,to:it,insert:o.insert}),bt=X.to-m.to;return{changes:nt,range:M?t.EditorSelection.range(Math.max(0,M.anchor+bt),Math.max(0,M.head+bt)):X.map(nt)}})}else f={changes:k,selection:M&&d.selection.replaceRange(M)}}let S="input.type";return(u.composing||u.inputState.compositionPendingChange&&u.inputState.compositionEndedAt>Date.now()-50)&&(u.inputState.compositionPendingChange=!1,S+=".compose",u.inputState.compositionFirstChange&&(S+=".start",u.inputState.compositionFirstChange=!1)),d.update(f,{userEvent:S,scrollIntoView:!0})}function f1(u,o,a,f){let d=Math.min(u.length,o.length),m=0;for(;m<d&&u.charCodeAt(m)==o.charCodeAt(m);)m++;if(m==d&&u.length==o.length)return null;let S=u.length,k=o.length;for(;S>0&&k>0&&u.charCodeAt(S-1)==o.charCodeAt(k-1);)S--,k--;if(f=="end"){let M=Math.max(0,m-Math.min(S,k));a-=S+M-m}if(S<m&&u.length<o.length){let M=a<=m&&a>=S?m-a:0;m-=M,k=m+(k-S),S=m}else if(k<m){let M=a<=m&&a>=k?m-a:0;m-=M,S=m+(S-k),k=m}return{from:m,toA:S,toB:k}}function d1(u){let o=[];if(u.root.activeElement!=u.contentDOM)return o;let{anchorNode:a,anchorOffset:f,focusNode:d,focusOffset:m}=u.observer.selectionRange;return a&&(o.push(new nd(a,f)),(d!=a||m!=f)&&o.push(new nd(d,m))),o}function u1(u,o){if(u.length==0)return null;let a=u[0].pos,f=u.length==2?u[1].pos:a;return a>-1&&f>-1?t.EditorSelection.single(a+o,f+o):null}const p1={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Ma=ft.ie&&ft.ie_version<=11;class g1{constructor(o){this.view=o,this.active=!1,this.editContext=null,this.selectionRange=new ot,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=o.contentDOM,this.observer=new MutationObserver(a=>{for(let f of a)this.queue.push(f);(ft.ie&&ft.ie_version<=11||ft.ios&&o.composing)&&a.some(f=>f.type=="childList"&&f.removedNodes.length||f.type=="characterData"&&f.oldValue.length>f.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&o.constructor.EDIT_CONTEXT!==!1&&!(ft.chrome&&ft.chrome_version<126)&&(this.editContext=new b1(o),o.state.facet(pi)&&(o.contentDOM.editContext=this.editContext.editContext)),Ma&&(this.onCharData=a=>{this.queue.push({target:a.target,type:"characterData",oldValue:a.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 a;((a=this.view.docView)===null||a===void 0?void 0:a.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(o.scrollDOM)),this.addWindowListeners(this.win=o.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(a=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),a.length>0&&a[a.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(a=>{a.length>0&&a[a.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(o){this.view.inputState.runHandlers("scroll",o),this.intersecting&&this.view.measure()}onScroll(o){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(o)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(o){o.type=="change"&&!o.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(o){if(this.gapIntersection&&(o.length!=this.gaps.length||this.gaps.some((a,f)=>a!=o[f]))){this.gapIntersection.disconnect();for(let a of o)this.gapIntersection.observe(a);this.gaps=o}}onSelectionChange(o){let a=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:f}=this,d=this.selectionRange;if(f.state.facet(pi)?f.root.activeElement!=this.dom:!h(f.dom,d))return;let m=d.anchorNode&&f.docView.nearest(d.anchorNode);if(m&&m.ignoreEvent(o)){a||(this.selectionChanged=!1);return}(ft.ie&&ft.ie_version<=11||ft.android&&ft.chrome)&&!f.state.selection.main.empty&&d.focusNode&&g(d.focusNode,d.focusOffset,d.anchorNode,d.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:o}=this,a=s(o.root);if(!a)return!1;let f=ft.safari&&o.root.nodeType==11&&l(this.dom.ownerDocument)==this.dom&&m1(this.view,a)||a;if(!f||this.selectionRange.eq(f))return!1;let d=h(this.dom,f);return d&&!this.selectionChanged&&o.inputState.lastFocusTime>Date.now()-200&&o.inputState.lastTouchTime<Date.now()-300&&ae(this.dom,f)?(this.view.inputState.lastFocusTime=0,o.docView.updateSelection(),!1):(this.selectionRange.setRange(f),d&&(this.selectionChanged=!0),!0)}setSelectionRange(o,a){this.selectionRange.set(o.node,o.offset,a.node,a.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let o=0,a=null;for(let f=this.dom;f;)if(f.nodeType==1)!a&&o<this.scrollTargets.length&&this.scrollTargets[o]==f?o++:a||(a=this.scrollTargets.slice(0,o)),a&&a.push(f),f=f.assignedSlot||f.parentNode;else if(f.nodeType==11)f=f.host;else break;if(o<this.scrollTargets.length&&!a&&(a=this.scrollTargets.slice(0,o)),a){for(let f of this.scrollTargets)f.removeEventListener("scroll",this.onScroll);for(let f of this.scrollTargets=a)f.addEventListener("scroll",this.onScroll)}}ignore(o){if(!this.active)return o();try{return this.stop(),o()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,p1),Ma&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Ma&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(o,a){var f;if(!this.delayedAndroidKey){let d=()=>{let m=this.delayedAndroidKey;m&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=m.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&m.force&&Pt(this.dom,m.key,m.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(d)}(!this.delayedAndroidKey||o=="Enter")&&(this.delayedAndroidKey={key:o,keyCode:a,force:this.lastChange<Date.now()-50||!!(!((f=this.delayedAndroidKey)===null||f===void 0)&&f.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 o of this.observer.takeRecords())this.queue.push(o);return this.queue}processRecords(){let o=this.pendingRecords();o.length&&(this.queue=[]);let a=-1,f=-1,d=!1;for(let m of o){let S=this.readMutation(m);S&&(S.typeOver&&(d=!0),a==-1?{from:a,to:f}=S:(a=Math.min(S.from,a),f=Math.max(S.to,f)))}return{from:a,to:f,typeOver:d}}readChange(){let{from:o,to:a,typeOver:f}=this.processRecords(),d=this.selectionChanged&&h(this.dom,this.selectionRange);if(o<0&&!d)return null;o>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let m=new h1(this.view,o,a,f);return this.view.docView.domChanged={newSel:m.newSel?m.newSel.main:null},m}flush(o=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;o&&this.readSelectionRange();let a=this.readChange();if(!a)return this.view.requestMeasure(),!1;let f=this.view.state,d=sd(this.view,a);return this.view.state==f&&(a.domChanged||a.newSel&&!a.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),d}readMutation(o){let a=this.view.docView.nearest(o.target);if(!a||a.ignoreMutation(o))return null;if(a.markDirty(o.type=="attributes"),o.type=="attributes"&&(a.flags|=4),o.type=="childList"){let f=od(a,o.previousSibling||o.target.previousSibling,-1),d=od(a,o.nextSibling||o.target.nextSibling,1);return{from:f?a.posAfter(f):a.posAtStart,to:d?a.posBefore(d):a.posAtEnd,typeOver:!1}}else return o.type=="characterData"?{from:a.posAtStart,to:a.posAtEnd,typeOver:o.target.nodeValue==o.oldValue}:null}setWindow(o){o!=this.win&&(this.removeWindowListeners(this.win),this.win=o,this.addWindowListeners(this.win))}addWindowListeners(o){o.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener("change",this.onPrint):o.addEventListener("beforeprint",this.onPrint),o.addEventListener("scroll",this.onScroll),o.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(o){o.removeEventListener("scroll",this.onScroll),o.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener("change",this.onPrint):o.removeEventListener("beforeprint",this.onPrint),o.document.removeEventListener("selectionchange",this.onSelectionChange)}update(o){this.editContext&&(this.editContext.update(o),o.startState.facet(pi)!=o.state.facet(pi)&&(o.view.contentDOM.editContext=o.state.facet(pi)?this.editContext.editContext:null))}destroy(){var o,a,f;this.stop(),(o=this.intersection)===null||o===void 0||o.disconnect(),(a=this.gapIntersection)===null||a===void 0||a.disconnect(),(f=this.resizeScroll)===null||f===void 0||f.disconnect();for(let d of this.scrollTargets)d.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 od(u,o,a){for(;o;){let f=vt.get(o);if(f&&f.parent==u)return f;let d=o.parentNode;o=d!=u.dom?d:a>0?o.nextSibling:o.previousSibling}return null}function ld(u,o){let a=o.startContainer,f=o.startOffset,d=o.endContainer,m=o.endOffset,S=u.docView.domAtPos(u.state.selection.main.anchor);return g(S.node,S.offset,d,m)&&([a,f,d,m]=[d,m,a,f]),{anchorNode:a,anchorOffset:f,focusNode:d,focusOffset:m}}function m1(u,o){if(o.getComposedRanges){let d=o.getComposedRanges(u.root)[0];if(d)return ld(u,d)}let a=null;function f(d){d.preventDefault(),d.stopImmediatePropagation(),a=d.getTargetRanges()[0]}return u.contentDOM.addEventListener("beforeinput",f,!0),u.dom.ownerDocument.execCommand("indent"),u.contentDOM.removeEventListener("beforeinput",f,!0),a?ld(u,a):null}class b1{constructor(o){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(o.state);let a=this.editContext=new window.EditContext({text:o.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,o.state.selection.main.anchor))),selectionEnd:this.toContextPos(o.state.selection.main.head)});this.handlers.textupdate=f=>{let{anchor:d}=o.state.selection.main,m={from:this.toEditorPos(f.updateRangeStart),to:this.toEditorPos(f.updateRangeEnd),insert:t.Text.of(f.text.split(`
12
- `))};m.from==this.from&&d<this.from?m.from=d:m.to==this.to&&d>this.to&&(m.to=d),!(m.from==m.to&&!m.insert.length)&&(this.pendingContextChange=m,o.state.readOnly||rd(o,m,t.EditorSelection.single(this.toEditorPos(f.selectionStart),this.toEditorPos(f.selectionEnd))),this.pendingContextChange&&(this.revertPending(o.state),this.setSelection(o.state)))},this.handlers.characterboundsupdate=f=>{let d=[],m=null;for(let S=this.toEditorPos(f.rangeStart),k=this.toEditorPos(f.rangeEnd);S<k;S++){let M=o.coordsForChar(S);m=M&&new DOMRect(M.left,M.top,M.right-M.left,M.bottom-M.top)||m||new DOMRect,d.push(m)}a.updateCharacterBounds(f.rangeStart,d)},this.handlers.textformatupdate=f=>{let d=[];for(let m of f.getTextFormats()){let S=m.underlineStyle,k=m.underlineThickness;if(S!="None"&&k!="None"){let M=`text-decoration: underline ${S=="Dashed"?"dashed ":S=="Squiggle"?"wavy ":""}${k=="Thin"?1:2}px`;d.push(Vt.mark({attributes:{style:M}}).range(this.toEditorPos(m.rangeStart),this.toEditorPos(m.rangeEnd)))}}o.dispatch({effects:rn.of(Vt.set(d))})},this.handlers.compositionstart=()=>{o.inputState.composing<0&&(o.inputState.composing=0,o.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{o.inputState.composing=-1,o.inputState.compositionFirstChange=null};for(let f in this.handlers)a.addEventListener(f,this.handlers[f]);this.measureReq={read:f=>{this.editContext.updateControlBounds(f.contentDOM.getBoundingClientRect());let d=s(f.root);d&&d.rangeCount&&this.editContext.updateSelectionBounds(d.getRangeAt(0).getBoundingClientRect())}}}applyEdits(o){let a=0,f=!1,d=this.pendingContextChange;return o.changes.iterChanges((m,S,k,M,B)=>{if(f)return;let E=B.length-(S-m);if(d&&S>=d.to)if(d.from==m&&d.to==S&&d.insert.eq(B)){d=this.pendingContextChange=null,a+=E,this.to+=E;return}else d=null,this.revertPending(o.state);if(m+=a,S+=a,S<=this.from)this.from+=E,this.to+=E;else if(m<this.to){if(m<this.from||S>this.to||this.to-this.from+B.length>3e4){f=!0;return}this.editContext.updateText(this.toContextPos(m),this.toContextPos(S),B.toString()),this.to+=E}a+=E}),d&&!f&&this.revertPending(o.state),!f}update(o){let a=this.pendingContextChange;!this.applyEdits(o)||!this.rangeIsValid(o.state)?(this.pendingContextChange=null,this.resetRange(o.state),this.editContext.updateText(0,this.editContext.text.length,o.state.doc.sliceString(this.from,this.to)),this.setSelection(o.state)):(o.docChanged||o.selectionSet||a)&&this.setSelection(o.state),(o.geometryChanged||o.docChanged||o.selectionSet)&&o.view.requestMeasure(this.measureReq)}resetRange(o){let{head:a}=o.selection.main;this.from=Math.max(0,a-1e4),this.to=Math.min(o.doc.length,a+1e4)}revertPending(o){let a=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(a.from),this.toContextPos(a.from+a.insert.length),o.doc.sliceString(a.from,a.to))}setSelection(o){let{main:a}=o.selection,f=this.toContextPos(Math.max(this.from,Math.min(this.to,a.anchor))),d=this.toContextPos(a.head);(this.editContext.selectionStart!=f||this.editContext.selectionEnd!=d)&&this.editContext.updateSelection(f,d)}rangeIsValid(o){let{head:a}=o.selection.main;return!(this.from>0&&a-this.from<500||this.to<o.doc.length&&this.to-a<500||this.to-this.from>1e4*3)}toEditorPos(o){return o+this.from}toContextPos(o){return o-this.from}destroy(){for(let o in this.handlers)this.editContext.removeEventListener(o,this.handlers[o])}}class Nt{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(o={}){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),o.parent&&o.parent.appendChild(this.dom);let{dispatch:a}=o;this.dispatchTransactions=o.dispatchTransactions||a&&(f=>f.forEach(d=>a(d,this)))||(f=>this.update(f)),this.dispatch=this.dispatch.bind(this),this._root=o.root||Tt(o.parent)||document,this.viewState=new Qf(o.state||t.EditorState.create(o)),o.scrollTo&&o.scrollTo.is(Gt)&&(this.viewState.scrollTarget=o.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Gn).map(f=>new ds(f));for(let f of this.plugins)f.update(this);this.observer=new g1(this),this.inputState=new Ly(this),this.inputState.ensureHandlers(this.plugins),this.docView=new or(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...o){let a=o.length==1&&o[0]instanceof t.Transaction?o:o.length==1&&Array.isArray(o[0])?o[0]:[this.state.update(...o)];this.dispatchTransactions(a,this)}update(o){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let a=!1,f=!1,d,m=this.state;for(let K of o){if(K.startState!=m)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");m=K.state}if(this.destroyed){this.viewState.state=m;return}let S=this.hasFocus,k=0,M=null;o.some(K=>K.annotation(qf))?(this.inputState.notifiedFocused=S,k=1):S!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=S,M=Kf(m,S),M||(k=1));let B=this.observer.delayedAndroidKey,E=null;if(B?(this.observer.clearDelayedAndroidKey(),E=this.observer.readChange(),(E&&!this.state.doc.eq(m.doc)||!this.state.selection.eq(m.selection))&&(E=null)):this.observer.clear(),m.facet(t.EditorState.phrases)!=this.state.facet(t.EditorState.phrases))return this.setState(m);d=Cn.create(this,m,o),d.flags|=k;let H=this.viewState.scrollTarget;try{this.updateState=2;for(let K of o){if(H&&(H=H.map(K.changes)),K.scrollIntoView){let{main:Y}=K.state.selection;H=new be(Y.empty?Y:t.EditorSelection.cursor(Y.head,Y.head>Y.anchor?-1:1))}for(let Y of K.effects)Y.is(Gt)&&(H=Y.value.clip(this.state))}this.viewState.update(d,H),this.bidiCache=ko.update(this.bidiCache,d.changes),d.empty||(this.updatePlugins(d),this.inputState.update(d)),a=this.docView.update(d),this.state.facet(kn)!=this.styleModules&&this.mountStyles(),f=this.updateAttrs(),this.showAnnouncements(o),this.docView.updateSelection(a,o.some(K=>K.isUserEvent("select.pointer")))}finally{this.updateState=0}if(d.startState.facet(vo)!=d.state.facet(vo)&&(this.viewState.mustMeasureContent=!0),(a||f||H||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),a&&this.docViewUpdate(),!d.empty)for(let K of this.state.facet(Z))try{K(d)}catch(Y){Ie(this.state,Y,"update listener")}(M||E)&&Promise.resolve().then(()=>{M&&this.state==M.startState&&this.dispatch(M),E&&!sd(this,E)&&B.force&&Pt(this.contentDOM,B.key,B.keyCode)})}setState(o){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=o;return}this.updateState=2;let a=this.hasFocus;try{for(let f of this.plugins)f.destroy(this);this.viewState=new Qf(o),this.plugins=o.facet(Gn).map(f=>new ds(f)),this.pluginMap.clear();for(let f of this.plugins)f.update(this);this.docView.destroy(),this.docView=new or(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}a&&this.focus(),this.requestMeasure()}updatePlugins(o){let a=o.startState.facet(Gn),f=o.state.facet(Gn);if(a!=f){let d=[];for(let m of f){let S=a.indexOf(m);if(S<0)d.push(new ds(m));else{let k=this.plugins[S];k.mustUpdate=o,d.push(k)}}for(let m of this.plugins)m.mustUpdate!=o&&m.destroy(this);this.plugins=d,this.pluginMap.clear()}else for(let d of this.plugins)d.mustUpdate=o;for(let d=0;d<this.plugins.length;d++)this.plugins[d].update(this);a!=f&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let o of this.plugins){let a=o.value;if(a&&a.docViewUpdate)try{a.docViewUpdate(this)}catch(f){Ie(this.state,f,"doc view update listener")}}}measure(o=!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,o&&this.observer.forceFlush();let a=null,f=this.scrollDOM,d=f.scrollTop*this.scaleY,{scrollAnchorPos:m,scrollAnchorHeight:S}=this.viewState;Math.abs(d-this.viewState.scrollTop)>1&&(S=-1),this.viewState.scrollAnchorHeight=-1;try{for(let k=0;;k++){if(S<0)if(zt(f))m=-1,S=this.viewState.heightMap.height;else{let Y=this.viewState.scrollAnchorAt(d);m=Y.from,S=Y.top}this.updateState=1;let M=this.viewState.measure(this);if(!M&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(k>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let B=[];M&4||([this.measureRequests,B]=[B,this.measureRequests]);let E=B.map(Y=>{try{return Y.read(this)}catch(X){return Ie(this.state,X),ad}}),H=Cn.create(this,this.state,[]),K=!1;H.flags|=M,a?a.flags|=M:a=H,this.updateState=2,H.empty||(this.updatePlugins(H),this.inputState.update(H),this.updateAttrs(),K=this.docView.update(H),K&&this.docViewUpdate());for(let Y=0;Y<B.length;Y++)if(E[Y]!=ad)try{let X=B[Y];X.write&&X.write(E[Y],this)}catch(X){Ie(this.state,X)}if(K&&this.docView.updateSelection(!0),!H.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,S=-1;continue}else{let X=(m<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(m).top)-S;if(X>1||X<-1){d=d+X,f.scrollTop=d/this.scaleY,S=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(a&&!a.empty)for(let k of this.state.facet(Z))k(a)}get themeClasses(){return ka+" "+(this.state.facet(va)?ed:td)+" "+this.state.facet(vo)}updateAttrs(){let o=hd(this,us,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),a={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(pi)?"true":"false",class:"cm-content",style:`${ft.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(a["aria-readonly"]="true"),hd(this,Vi,a);let f=this.observer.ignore(()=>{let d=yn(this.contentDOM,this.contentAttrs,a),m=yn(this.dom,this.editorAttrs,o);return d||m});return this.editorAttrs=o,this.contentAttrs=a,f}showAnnouncements(o){let a=!0;for(let f of o)for(let d of f.effects)if(d.is(Nt.announce)){a&&(this.announceDOM.textContent=""),a=!1;let m=this.announceDOM.appendChild(document.createElement("div"));m.textContent=d.value}}mountStyles(){this.styleModules=this.state.facet(kn);let o=this.state.facet(Nt.cspNonce);e.StyleModule.mount(this.root,this.styleModules.concat(o1).reverse(),o?{nonce:o}: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(o){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),o){if(this.measureRequests.indexOf(o)>-1)return;if(o.key!=null){for(let a=0;a<this.measureRequests.length;a++)if(this.measureRequests[a].key===o.key){this.measureRequests[a]=o;return}}this.measureRequests.push(o)}}plugin(o){let a=this.pluginMap.get(o);return(a===void 0||a&&a.spec!=o)&&this.pluginMap.set(o,a=this.plugins.find(f=>f.spec==o)||null),a&&a.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(o){return this.readMeasured(),this.viewState.elementAtHeight(o)}lineBlockAtHeight(o){return this.readMeasured(),this.viewState.lineBlockAtHeight(o)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(o){return this.viewState.lineBlockAt(o)}get contentHeight(){return this.viewState.contentHeight}moveByChar(o,a,f){return ba(this,o,po(this,o,a,f))}moveByGroup(o,a){return ba(this,o,po(this,o,a,f=>lr(this,o.head,f)))}visualLineSide(o,a){let f=this.bidiSpans(o),d=this.textDirectionAt(o.from),m=f[a?f.length-1:0];return t.EditorSelection.cursor(m.side(a,d)+o.from,m.forward(!a,d)?1:-1)}moveToLineBoundary(o,a,f=!0){return Mn(this,o,a,f)}moveVertically(o,a,f){return ba(this,o,By(this,o,a,f))}domAtPos(o){return this.docView.domAtPos(o)}posAtDOM(o,a=0){return this.docView.posFromDOM(o,a)}posAtCoords(o,a=!0){return this.readMeasured(),yt(this,o,a)}coordsAtPos(o,a=1){this.readMeasured();let f=this.docView.coordsAt(o,a);if(!f||f.left==f.right)return f;let d=this.state.doc.lineAt(o),m=this.bidiSpans(d),S=m[we.find(m,o-d.from,-1,a)];return P(f,S.dir==n.Direction.LTR==a>0)}coordsForChar(o){return this.readMeasured(),this.docView.coordsForChar(o)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(o){return!this.state.facet(gt)||o<this.viewport.from||o>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(o))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(o){if(o.length>y1)return b(o.length);let a=this.textDirectionAt(o.from),f;for(let m of this.bidiCache)if(m.from==o.from&&m.dir==a&&(m.fresh||_n(m.isolates,f=rr(this,o))))return m.order;f||(f=rr(this,o));let d=V(o.text,a,f);return this.bidiCache.push(new ko(o.from,o.to,a,f,!0,d)),d}get hasFocus(){var o;return(this.dom.ownerDocument.hasFocus()||ft.safari&&((o=this.inputState)===null||o===void 0?void 0:o.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{st(this.contentDOM),this.docView.updateSelection()})}setRoot(o){this._root!=o&&(this._root=o,this.observer.setWindow((o.nodeType==9?o:o.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let o of this.plugins)o.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(o,a={}){return Gt.of(new be(typeof o=="number"?t.EditorSelection.cursor(o):o,a.y,a.x,a.yMargin,a.xMargin))}scrollSnapshot(){let{scrollTop:o,scrollLeft:a}=this.scrollDOM,f=this.viewState.scrollAnchorAt(o);return Gt.of(new be(t.EditorSelection.cursor(f.from),"start","start",f.top-o,a,!0))}setTabFocusMode(o){o==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof o=="boolean"?this.inputState.tabFocusMode=o?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+o)}static domEventHandlers(o){return pe.define(()=>({}),{eventHandlers:o})}static domEventObservers(o){return pe.define(()=>({}),{eventObservers:o})}static theme(o,a){let f=e.StyleModule.newName(),d=[vo.of(f),kn.of(Ca(`.${f}`,o))];return a&&a.dark&&d.push(va.of(!0)),d}static baseTheme(o){return t.Prec.lowest(kn.of(Ca("."+ka,o,id)))}static findFromDOM(o){var a;let f=o.querySelector(".cm-content"),d=f&&vt.get(f)||vt.get(o);return((a=d==null?void 0:d.rootView)===null||a===void 0?void 0:a.view)||null}}Nt.styleModule=kn,Nt.inputHandler=lt,Nt.scrollHandler=It,Nt.focusChangeEffect=ht,Nt.perLineTextDirection=gt,Nt.exceptionSink=_,Nt.updateListener=Z,Nt.editable=pi,Nt.mouseSelectionStyle=q,Nt.dragMovesSelection=N,Nt.clickAddsSelectionRange=L,Nt.decorations=Yn,Nt.outerDecorations=nr,Nt.atomicRanges=ps,Nt.bidiIsolatedRanges=sr,Nt.scrollMargins=co,Nt.darkTheme=va,Nt.cspNonce=t.Facet.define({combine:u=>u.length?u[0]:""}),Nt.contentAttributes=Vi,Nt.editorAttributes=us,Nt.lineWrapping=Nt.contentAttributes.of({class:"cm-lineWrapping"}),Nt.announce=t.StateEffect.define();const y1=4096,ad={};class ko{constructor(o,a,f,d,m,S){this.from=o,this.to=a,this.dir=f,this.isolates=d,this.fresh=m,this.order=S}static update(o,a){if(a.empty&&!o.some(m=>m.fresh))return o;let f=[],d=o.length?o[o.length-1].dir:n.Direction.LTR;for(let m=Math.max(0,o.length-10);m<o.length;m++){let S=o[m];S.dir==d&&!a.touchesRange(S.from,S.to)&&f.push(new ko(a.mapPos(S.from,1),a.mapPos(S.to,-1),S.dir,S.isolates,!1,S.order))}return f}}function hd(u,o,a){for(let f=u.state.facet(o),d=f.length-1;d>=0;d--){let m=f[d],S=typeof m=="function"?m(u):m;S&&Ht(S,a)}return a}const S1=ft.mac?"mac":ft.windows?"win":ft.linux?"linux":"key";function w1(u,o){const a=u.split(/-(?!$)/);let f=a[a.length-1];f=="Space"&&(f=" ");let d,m,S,k;for(let M=0;M<a.length-1;++M){const B=a[M];if(/^(cmd|meta|m)$/i.test(B))k=!0;else if(/^a(lt)?$/i.test(B))d=!0;else if(/^(c|ctrl|control)$/i.test(B))m=!0;else if(/^s(hift)?$/i.test(B))S=!0;else if(/^mod$/i.test(B))o=="mac"?k=!0:m=!0;else throw new Error("Unrecognized modifier name: "+B)}return d&&(f="Alt-"+f),m&&(f="Ctrl-"+f),k&&(f="Meta-"+f),S&&(f="Shift-"+f),f}function Co(u,o,a){return o.altKey&&(u="Alt-"+u),o.ctrlKey&&(u="Ctrl-"+u),o.metaKey&&(u="Meta-"+u),a!==!1&&o.shiftKey&&(u="Shift-"+u),u}const x1=t.Prec.default(Nt.domEventHandlers({keydown(u,o){return ud(dd(o.state),u,o,"editor")}})),cd=t.Facet.define({enables:x1}),fd=new WeakMap;function dd(u){let o=u.facet(cd),a=fd.get(o);return a||fd.set(o,a=C1(o.reduce((f,d)=>f.concat(d),[]))),a}function v1(u,o,a){return ud(dd(u.state),o,u,a)}let An=null;const k1=4e3;function C1(u,o=S1){let a=Object.create(null),f=Object.create(null),d=(S,k)=>{let M=f[S];if(M==null)f[S]=k;else if(M!=k)throw new Error("Key binding "+S+" is used both as a regular binding and as a multi-stroke prefix")},m=(S,k,M,B,E)=>{var H,K;let Y=a[S]||(a[S]=Object.create(null)),X=k.split(/ (?!$)/).map(nt=>w1(nt,o));for(let nt=1;nt<X.length;nt++){let bt=X.slice(0,nt).join(" ");d(bt,!0),Y[bt]||(Y[bt]={preventDefault:!0,stopPropagation:!1,run:[Ct=>{let St=An={view:Ct,prefix:bt,scope:S};return setTimeout(()=>{An==St&&(An=null)},k1),!0}]})}let it=X.join(" ");d(it,!1);let rt=Y[it]||(Y[it]={preventDefault:!1,stopPropagation:!1,run:((K=(H=Y._any)===null||H===void 0?void 0:H.run)===null||K===void 0?void 0:K.slice())||[]});M&&rt.run.push(M),B&&(rt.preventDefault=!0),E&&(rt.stopPropagation=!0)};for(let S of u){let k=S.scope?S.scope.split(" "):["editor"];if(S.any)for(let B of k){let E=a[B]||(a[B]=Object.create(null));E._any||(E._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:H}=S;for(let K in E)E[K].run.push(Y=>H(Y,Aa))}let M=S[o]||S.key;if(M)for(let B of k)m(B,M,S.run,S.preventDefault,S.stopPropagation),S.shift&&m(B,"Shift-"+M,S.shift,S.preventDefault,S.stopPropagation)}return a}let Aa=null;function ud(u,o,a,f){Aa=o;let d=i.keyName(o),m=t.codePointAt(d,0),S=t.codePointSize(m)==d.length&&d!=" ",k="",M=!1,B=!1,E=!1;An&&An.view==a&&An.scope==f&&(k=An.prefix+" ",Rf.indexOf(o.keyCode)<0&&(B=!0,An=null));let H=new Set,K=rt=>{if(rt){for(let nt of rt.run)if(!H.has(nt)&&(H.add(nt),nt(a)))return rt.stopPropagation&&(E=!0),!0;rt.preventDefault&&(rt.stopPropagation&&(E=!0),B=!0)}return!1},Y=u[f],X,it;return Y&&(K(Y[k+Co(d,o,!S)])?M=!0:S&&(o.altKey||o.metaKey||o.ctrlKey)&&!(ft.windows&&o.ctrlKey&&o.altKey)&&(X=i.base[o.keyCode])&&X!=d?(K(Y[k+Co(X,o,!0)])||o.shiftKey&&(it=i.shift[o.keyCode])!=d&&it!=X&&K(Y[k+Co(it,o,!1)]))&&(M=!0):S&&o.shiftKey&&K(Y[k+Co(d,o,!0)])&&(M=!0),!M&&K(Y._any)&&(M=!0)),B&&(M=!0),M&&E&&o.stopPropagation(),Aa=null,M}class bs{constructor(o,a,f,d,m){this.className=o,this.left=a,this.top=f,this.width=d,this.height=m}draw(){let o=document.createElement("div");return o.className=this.className,this.adjust(o),o}update(o,a){return a.className!=this.className?!1:(this.adjust(o),!0)}adjust(o){o.style.left=this.left+"px",o.style.top=this.top+"px",this.width!=null&&(o.style.width=this.width+"px"),o.style.height=this.height+"px"}eq(o){return this.left==o.left&&this.top==o.top&&this.width==o.width&&this.height==o.height&&this.className==o.className}static forRange(o,a,f){if(f.empty){let d=o.coordsAtPos(f.head,f.assoc||1);if(!d)return[];let m=pd(o);return[new bs(a,d.left-m.left,d.top-m.top,null,d.bottom-d.top)]}else return M1(o,a,f)}}function pd(u){let o=u.scrollDOM.getBoundingClientRect();return{left:(u.textDirection==n.Direction.LTR?o.left:o.right-u.scrollDOM.clientWidth*u.scaleX)-u.scrollDOM.scrollLeft*u.scaleX,top:o.top-u.scrollDOM.scrollTop*u.scaleY}}function gd(u,o,a,f){let d=u.coordsAtPos(o,a*2);if(!d)return f;let m=u.dom.getBoundingClientRect(),S=(d.top+d.bottom)/2,k=u.posAtCoords({x:m.left+1,y:S}),M=u.posAtCoords({x:m.right-1,y:S});return k==null||M==null?f:{from:Math.max(f.from,Math.min(k,M)),to:Math.min(f.to,Math.max(k,M))}}function M1(u,o,a){if(a.to<=u.viewport.from||a.from>=u.viewport.to)return[];let f=Math.max(a.from,u.viewport.from),d=Math.min(a.to,u.viewport.to),m=u.textDirection==n.Direction.LTR,S=u.contentDOM,k=S.getBoundingClientRect(),M=pd(u),B=S.querySelector(".cm-line"),E=B&&window.getComputedStyle(B),H=k.left+(E?parseInt(E.paddingLeft)+Math.min(0,parseInt(E.textIndent)):0),K=k.right-(E?parseInt(E.paddingRight):0),Y=ri(u,f),X=ri(u,d),it=Y.type==n.BlockType.Text?Y:null,rt=X.type==n.BlockType.Text?X:null;if(it&&(u.lineWrapping||Y.widgetLineBreaks)&&(it=gd(u,f,1,it)),rt&&(u.lineWrapping||X.widgetLineBreaks)&&(rt=gd(u,d,-1,rt)),it&&rt&&it.from==rt.from&&it.to==rt.to)return bt(Ct(a.from,a.to,it));{let Mt=it?Ct(a.from,null,it):St(Y,!1),Et=rt?Ct(null,a.to,rt):St(X,!0),fe=[];return(it||Y).to<(rt||X).from-(it&&rt?1:0)||Y.widgetLineBreaks>1&&Mt.bottom+u.defaultLineHeight/2<Et.top?fe.push(nt(H,Mt.bottom,K,Et.top)):Mt.bottom<Et.top&&u.elementAtHeight((Mt.bottom+Et.top)/2).type==n.BlockType.Text&&(Mt.bottom=Et.top=(Mt.bottom+Et.top)/2),bt(Mt).concat(fe).concat(bt(Et))}function nt(Mt,Et,fe,ke){return new bs(o,Mt-M.left,Et-M.top-.01,fe-Mt,ke-Et+.01)}function bt({top:Mt,bottom:Et,horizontal:fe}){let ke=[];for(let Tn=0;Tn<fe.length;Tn+=2)ke.push(nt(fe[Tn],Mt,fe[Tn+1],Et));return ke}function Ct(Mt,Et,fe){let ke=1e9,Tn=-1e9,Bo=[];function Fd(Un,Dn,ws,Xn,gr){let ln=u.coordsAtPos(Un,Un==fe.to?-2:2),an=u.coordsAtPos(ws,ws==fe.from?2:-2);!ln||!an||(ke=Math.min(ln.top,an.top,ke),Tn=Math.max(ln.bottom,an.bottom,Tn),gr==n.Direction.LTR?Bo.push(m&&Dn?H:ln.left,m&&Xn?K:an.right):Bo.push(!m&&Xn?H:an.left,!m&&Dn?K:ln.right))}let Lo=Mt??fe.from,No=Et??fe.to;for(let Un of u.visibleRanges)if(Un.to>Lo&&Un.from<No)for(let Dn=Math.max(Un.from,Lo),ws=Math.min(Un.to,No);;){let Xn=u.state.doc.lineAt(Dn);for(let gr of u.bidiSpans(Xn)){let ln=gr.from+Xn.from,an=gr.to+Xn.from;if(ln>=ws)break;an>Dn&&Fd(Math.max(ln,Dn),Mt==null&&ln<=Lo,Math.min(an,ws),Et==null&&an>=No,gr.dir)}if(Dn=Xn.to+1,Dn>=ws)break}return Bo.length==0&&Fd(Lo,Mt==null,No,Et==null,u.textDirection),{top:ke,bottom:Tn,horizontal:Bo}}function St(Mt,Et){let fe=k.top+(Et?Mt.top:Mt.bottom);return{top:fe,bottom:fe,horizontal:[]}}}function A1(u,o){return u.constructor==o.constructor&&u.eq(o)}class T1{constructor(o,a){this.view=o,this.layer=a,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=o.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),a.above&&this.dom.classList.add("cm-layer-above"),a.class&&this.dom.classList.add(a.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(o.state),o.requestMeasure(this.measureReq),a.mount&&a.mount(this.dom,o)}update(o){o.startState.facet(Mo)!=o.state.facet(Mo)&&this.setOrder(o.state),(this.layer.update(o,this.dom)||o.geometryChanged)&&(this.scale(),o.view.requestMeasure(this.measureReq))}docViewUpdate(o){this.layer.updateOnDocViewUpdate!==!1&&o.requestMeasure(this.measureReq)}setOrder(o){let a=0,f=o.facet(Mo);for(;a<f.length&&f[a]!=this.layer;)a++;this.dom.style.zIndex=String((this.layer.above?150:-1)-a)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:o,scaleY:a}=this.view;(o!=this.scaleX||a!=this.scaleY)&&(this.scaleX=o,this.scaleY=a,this.dom.style.transform=`scale(${1/o}, ${1/a})`)}draw(o){if(o.length!=this.drawn.length||o.some((a,f)=>!A1(a,this.drawn[f]))){let a=this.dom.firstChild,f=0;for(let d of o)d.update&&a&&d.constructor&&this.drawn[f].constructor&&d.update(a,this.drawn[f])?(a=a.nextSibling,f++):this.dom.insertBefore(d.draw(),a);for(;a;){let d=a.nextSibling;a.remove(),a=d}this.drawn=o}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Mo=t.Facet.define();function Ta(u){return[pe.define(o=>new T1(o,u)),Mo.of(u)]}const md=!ft.ios,ys=t.Facet.define({combine(u){return t.combineConfig(u,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(o,a)=>Math.min(o,a),drawRangeCursor:(o,a)=>o||a})}});function D1(u={}){return[ys.of(u),E1,P1,R1,pt.of(!0)]}function O1(u){return u.facet(ys)}function bd(u){return u.startState.facet(ys)!=u.state.facet(ys)}const E1=Ta({above:!0,markers(u){let{state:o}=u,a=o.facet(ys),f=[];for(let d of o.selection.ranges){let m=d==o.selection.main;if(d.empty?!m||md:a.drawRangeCursor){let S=m?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",k=d.empty?d:t.EditorSelection.cursor(d.head,d.head>d.anchor?-1:1);for(let M of bs.forRange(u,S,k))f.push(M)}}return f},update(u,o){u.transactions.some(f=>f.selection)&&(o.style.animationName=o.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let a=bd(u);return a&&yd(u.state,o),u.docChanged||u.selectionSet||a},mount(u,o){yd(o.state,u)},class:"cm-cursorLayer"});function yd(u,o){o.style.animationDuration=u.facet(ys).cursorBlinkRate+"ms"}const P1=Ta({above:!1,markers(u){return u.state.selection.ranges.map(o=>o.empty?[]:bs.forRange(u,"cm-selectionBackground",o)).reduce((o,a)=>o.concat(a))},update(u,o){return u.docChanged||u.selectionSet||u.viewportChanged||bd(u)},class:"cm-selectionLayer"}),Da={".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"}},".cm-content":{"& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}};md&&(Da[".cm-line"].caretColor=Da[".cm-content"].caretColor="transparent !important");const R1=t.Prec.highest(Nt.theme(Da)),Sd=t.StateEffect.define({map(u,o){return u==null?null:o.mapPos(u)}}),cr=t.StateField.define({create(){return null},update(u,o){return u!=null&&(u=o.changes.mapPos(u)),o.effects.reduce((a,f)=>f.is(Sd)?f.value:a,u)}}),B1=pe.fromClass(class{constructor(u){this.view=u,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(u){var o;let a=u.state.field(cr);a==null?this.cursor!=null&&((o=this.cursor)===null||o===void 0||o.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(u.startState.field(cr)!=a||u.docChanged||u.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:u}=this,o=u.state.field(cr),a=o!=null&&u.coordsAtPos(o);if(!a)return null;let f=u.scrollDOM.getBoundingClientRect();return{left:a.left-f.left+u.scrollDOM.scrollLeft*u.scaleX,top:a.top-f.top+u.scrollDOM.scrollTop*u.scaleY,height:a.bottom-a.top}}drawCursor(u){if(this.cursor){let{scaleX:o,scaleY:a}=this.view;u?(this.cursor.style.left=u.left/o+"px",this.cursor.style.top=u.top/a+"px",this.cursor.style.height=u.height/a+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(u){this.view.state.field(cr)!=u&&this.view.dispatch({effects:Sd.of(u)})}},{eventObservers:{dragover(u){this.setDropPos(this.view.posAtCoords({x:u.clientX,y:u.clientY}))},dragleave(u){(u.target==this.view.contentDOM||!this.view.contentDOM.contains(u.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function L1(){return[cr,B1]}function wd(u,o,a,f,d){o.lastIndex=0;for(let m=u.iterRange(a,f),S=a,k;!m.next().done;S+=m.value.length)if(!m.lineBreak)for(;k=o.exec(m.value);)d(S+k.index,k)}function N1(u,o){let a=u.visibleRanges;if(a.length==1&&a[0].from==u.viewport.from&&a[0].to==u.viewport.to)return a;let f=[];for(let{from:d,to:m}of a)d=Math.max(u.state.doc.lineAt(d).from,d-o),m=Math.min(u.state.doc.lineAt(m).to,m+o),f.length&&f[f.length-1].to>=d?f[f.length-1].to=m:f.push({from:d,to:m});return f}class Ao{constructor(o){const{regexp:a,decoration:f,decorate:d,boundary:m,maxLength:S=1e3}=o;if(!a.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=a,d)this.addMatch=(k,M,B,E)=>d(E,B,B+k[0].length,k,M);else if(typeof f=="function")this.addMatch=(k,M,B,E)=>{let H=f(k,M,B);H&&E(B,B+k[0].length,H)};else if(f)this.addMatch=(k,M,B,E)=>E(B,B+k[0].length,f);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=m,this.maxLength=S}createDeco(o){let a=new t.RangeSetBuilder,f=a.add.bind(a);for(let{from:d,to:m}of N1(o,this.maxLength))wd(o.state.doc,this.regexp,d,m,(S,k)=>this.addMatch(k,o,S,f));return a.finish()}updateDeco(o,a){let f=1e9,d=-1;return o.docChanged&&o.changes.iterChanges((m,S,k,M)=>{M>o.view.viewport.from&&k<o.view.viewport.to&&(f=Math.min(k,f),d=Math.max(M,d))}),o.viewportChanged||d-f>1e3?this.createDeco(o.view):d>-1?this.updateRange(o.view,a.map(o.changes),f,d):a}updateRange(o,a,f,d){for(let m of o.visibleRanges){let S=Math.max(m.from,f),k=Math.min(m.to,d);if(k>S){let M=o.state.doc.lineAt(S),B=M.to<k?o.state.doc.lineAt(k):M,E=Math.max(m.from,M.from),H=Math.min(m.to,B.to);if(this.boundary){for(;S>M.from;S--)if(this.boundary.test(M.text[S-1-M.from])){E=S;break}for(;k<B.to;k++)if(this.boundary.test(B.text[k-B.from])){H=k;break}}let K=[],Y,X=(it,rt,nt)=>K.push(nt.range(it,rt));if(M==B)for(this.regexp.lastIndex=E-M.from;(Y=this.regexp.exec(M.text))&&Y.index<H-M.from;)this.addMatch(Y,o,Y.index+M.from,X);else wd(o.state.doc,this.regexp,E,H,(it,rt)=>this.addMatch(rt,o,it,X));a=a.update({filterFrom:E,filterTo:H,filter:(it,rt)=>it<E||rt>H,add:K})}}return a}}const Oa=/x/.unicode!=null?"gu":"g",F1=new RegExp(`[\0-\b
13
- --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,Oa),I1={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 Ea=null;function H1(){var u;if(Ea==null&&typeof document<"u"&&document.body){let o=document.body.style;Ea=((u=o.tabSize)!==null&&u!==void 0?u:o.MozTabSize)!=null}return Ea||!1}const To=t.Facet.define({combine(u){let o=t.combineConfig(u,{render:null,specialChars:F1,addSpecialChars:null});return(o.replaceTabs=!H1())&&(o.specialChars=new RegExp(" |"+o.specialChars.source,Oa)),o.addSpecialChars&&(o.specialChars=new RegExp(o.specialChars.source+"|"+o.addSpecialChars.source,Oa)),o}});function V1(u={}){return[To.of(u),$1()]}let xd=null;function $1(){return xd||(xd=pe.fromClass(class{constructor(u){this.view=u,this.decorations=Vt.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(u.state.facet(To)),this.decorations=this.decorator.createDeco(u)}makeDecorator(u){return new Ao({regexp:u.specialChars,decoration:(o,a,f)=>{let{doc:d}=a.state,m=t.codePointAt(o[0],0);if(m==9){let S=d.lineAt(f),k=a.state.tabSize,M=t.countColumn(S.text,k,f-S.from);return Vt.replace({widget:new K1((k-M%k)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[m]||(this.decorationCache[m]=Vt.replace({widget:new q1(u,m)}))},boundary:u.replaceTabs?void 0:/[^]/})}update(u){let o=u.state.facet(To);u.startState.facet(To)!=o?(this.decorator=this.makeDecorator(o),this.decorations=this.decorator.createDeco(u.view)):this.decorations=this.decorator.updateDeco(u,this.decorations)}},{decorations:u=>u.decorations}))}const W1="•";function z1(u){return u>=32?W1:u==10?"␤":String.fromCharCode(9216+u)}class q1 extends _e{constructor(o,a){super(),this.options=o,this.code=a}eq(o){return o.code==this.code}toDOM(o){let a=z1(this.code),f=o.state.phrase("Control character")+" "+(I1[this.code]||"0x"+this.code.toString(16)),d=this.options.render&&this.options.render(this.code,f,a);if(d)return d;let m=document.createElement("span");return m.textContent=a,m.title=f,m.setAttribute("aria-label",f),m.className="cm-specialChar",m}ignoreEvent(){return!1}}class K1 extends _e{constructor(o){super(),this.width=o}eq(o){return o.width==this.width}toDOM(){let o=document.createElement("span");return o.textContent=" ",o.className="cm-tab",o.style.width=this.width+"px",o}ignoreEvent(){return!1}}const vd=pe.fromClass(class{constructor(){this.height=1e3,this.attrs={style:"padding-bottom: 1000px"}}update(u){let{view:o}=u,a=o.viewState.editorHeight-o.defaultLineHeight-o.documentPadding.top-.5;a>=0&&a!=this.height&&(this.height=a,this.attrs={style:`padding-bottom: ${a}px`})}});function j1(){return[vd,Vi.of(u=>{var o;return((o=u.plugin(vd))===null||o===void 0?void 0:o.attrs)||null})]}function _1(){return Y1}const G1=Vt.line({class:"cm-activeLine"}),Y1=pe.fromClass(class{constructor(u){this.decorations=this.getDeco(u)}update(u){(u.docChanged||u.selectionSet)&&(this.decorations=this.getDeco(u.view))}getDeco(u){let o=-1,a=[];for(let f of u.state.selection.ranges){let d=u.lineBlockAt(f.head);d.from>o&&(a.push(G1.range(d.from)),o=d.from)}return Vt.set(a)}},{decorations:u=>u.decorations});class U1 extends _e{constructor(o){super(),this.content=o}toDOM(){let o=document.createElement("span");return o.className="cm-placeholder",o.style.pointerEvents="none",o.appendChild(typeof this.content=="string"?document.createTextNode(this.content):this.content),typeof this.content=="string"?o.setAttribute("aria-label","placeholder "+this.content):o.setAttribute("aria-hidden","true"),o}coordsAt(o){let a=o.firstChild?c(o.firstChild):[];if(!a.length)return null;let f=window.getComputedStyle(o.parentNode),d=P(a[0],f.direction!="rtl"),m=parseInt(f.lineHeight);return d.bottom-d.top>m*1.5?{left:d.left,right:d.right,top:d.top,bottom:d.top+m}:d}ignoreEvent(){return!1}}function X1(u){return pe.fromClass(class{constructor(o){this.view=o,this.placeholder=u?Vt.set([Vt.widget({widget:new U1(u),side:1}).range(0)]):Vt.none}get decorations(){return this.view.state.doc.length?Vt.none:this.placeholder}},{decorations:o=>o.decorations})}const Pa=2e3;function J1(u,o,a){let f=Math.min(o.line,a.line),d=Math.max(o.line,a.line),m=[];if(o.off>Pa||a.off>Pa||o.col<0||a.col<0){let S=Math.min(o.off,a.off),k=Math.max(o.off,a.off);for(let M=f;M<=d;M++){let B=u.doc.line(M);B.length<=k&&m.push(t.EditorSelection.range(B.from+S,B.to+k))}}else{let S=Math.min(o.col,a.col),k=Math.max(o.col,a.col);for(let M=f;M<=d;M++){let B=u.doc.line(M),E=t.findColumn(B.text,S,u.tabSize,!0);if(E<0)m.push(t.EditorSelection.cursor(B.to));else{let H=t.findColumn(B.text,k,u.tabSize);m.push(t.EditorSelection.range(B.from+E,B.from+H))}}}return m}function Q1(u,o){let a=u.coordsAtPos(u.viewport.from);return a?Math.round(Math.abs((a.left-o)/u.defaultCharacterWidth)):-1}function kd(u,o){let a=u.posAtCoords({x:o.clientX,y:o.clientY},!1),f=u.state.doc.lineAt(a),d=a-f.from,m=d>Pa?-1:d==f.length?Q1(u,o.clientX):t.countColumn(f.text,u.state.tabSize,a-f.from);return{line:f.number,col:m,off:d}}function Z1(u,o){let a=kd(u,o),f=u.state.selection;return a?{update(d){if(d.docChanged){let m=d.changes.mapPos(d.startState.doc.line(a.line).from),S=d.state.doc.lineAt(m);a={line:S.number,col:a.col,off:Math.min(a.off,S.length)},f=f.map(d.changes)}},get(d,m,S){let k=kd(u,d);if(!k)return f;let M=J1(u.state,a,k);return M.length?S?t.EditorSelection.create(M.concat(f.ranges)):t.EditorSelection.create(M):f}}:null}function tS(u){let o=(u==null?void 0:u.eventFilter)||(a=>a.altKey&&a.button==0);return Nt.mouseSelectionStyle.of((a,f)=>o(f)?Z1(a,f):null)}const eS={Alt:[18,u=>!!u.altKey],Control:[17,u=>!!u.ctrlKey],Shift:[16,u=>!!u.shiftKey],Meta:[91,u=>!!u.metaKey]},iS={style:"cursor: crosshair"};function nS(u={}){let[o,a]=eS[u.key||"Alt"],f=pe.fromClass(class{constructor(d){this.view=d,this.isDown=!1}set(d){this.isDown!=d&&(this.isDown=d,this.view.update([]))}},{eventObservers:{keydown(d){this.set(d.keyCode==o||a(d))},keyup(d){(d.keyCode==o||!a(d))&&this.set(!1)},mousemove(d){this.set(a(d))}}});return[f,Nt.contentAttributes.of(d=>{var m;return!((m=d.plugin(f))===null||m===void 0)&&m.isDown?iS:null})]}const fr="-10000px";class Cd{constructor(o,a,f,d){this.facet=a,this.createTooltipView=f,this.removeTooltipView=d,this.input=o.state.facet(a),this.tooltips=this.input.filter(S=>S);let m=null;this.tooltipViews=this.tooltips.map(S=>m=f(S,m))}update(o,a){var f;let d=o.state.facet(this.facet),m=d.filter(M=>M);if(d===this.input){for(let M of this.tooltipViews)M.update&&M.update(o);return!1}let S=[],k=a?[]:null;for(let M=0;M<m.length;M++){let B=m[M],E=-1;if(B){for(let H=0;H<this.tooltips.length;H++){let K=this.tooltips[H];K&&K.create==B.create&&(E=H)}if(E<0)S[M]=this.createTooltipView(B,M?S[M-1]:null),k&&(k[M]=!!B.above);else{let H=S[M]=this.tooltipViews[E];k&&(k[M]=a[E]),H.update&&H.update(o)}}}for(let M of this.tooltipViews)S.indexOf(M)<0&&(this.removeTooltipView(M),(f=M.destroy)===null||f===void 0||f.call(M));return a&&(k.forEach((M,B)=>a[B]=M),a.length=k.length),this.input=d,this.tooltips=m,this.tooltipViews=S,!0}}function sS(u={}){return Do.of(u)}function rS(u){let{win:o}=u;return{top:0,left:0,bottom:o.innerHeight,right:o.innerWidth}}const Do=t.Facet.define({combine:u=>{var o,a,f;return{position:ft.ios?"absolute":((o=u.find(d=>d.position))===null||o===void 0?void 0:o.position)||"fixed",parent:((a=u.find(d=>d.parent))===null||a===void 0?void 0:a.parent)||null,tooltipSpace:((f=u.find(d=>d.tooltipSpace))===null||f===void 0?void 0:f.tooltipSpace)||rS}}}),Md=new WeakMap,Oo=pe.fromClass(class{constructor(u){this.view=u,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let o=u.state.facet(Do);this.position=o.position,this.parent=o.parent,this.classes=u.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 Cd(u,Ra,(a,f)=>this.createTooltip(a,f),a=>{this.resizeObserver&&this.resizeObserver.unobserve(a.dom),a.dom.remove()}),this.above=this.manager.tooltips.map(a=>!!a.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(a=>{Date.now()>this.lastTransaction-50&&a.length>0&&a[a.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),u.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 u of this.manager.tooltipViews)this.intersectionObserver.observe(u.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(u){u.transactions.length&&(this.lastTransaction=Date.now());let o=this.manager.update(u,this.above);o&&this.observeIntersection();let a=o||u.geometryChanged,f=u.state.facet(Do);if(f.position!=this.position&&!this.madeAbsolute){this.position=f.position;for(let d of this.manager.tooltipViews)d.dom.style.position=this.position;a=!0}if(f.parent!=this.parent){this.parent&&this.container.remove(),this.parent=f.parent,this.createContainer();for(let d of this.manager.tooltipViews)this.container.appendChild(d.dom);a=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);a&&this.maybeMeasure()}createTooltip(u,o){let a=u.create(this.view),f=o?o.dom:null;if(a.dom.classList.add("cm-tooltip"),u.arrow&&!a.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let d=document.createElement("div");d.className="cm-tooltip-arrow",a.dom.appendChild(d)}return a.dom.style.position=this.position,a.dom.style.top=fr,a.dom.style.left="0px",this.container.insertBefore(a.dom,f),a.mount&&a.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(a.dom),a}destroy(){var u,o,a;this.view.win.removeEventListener("resize",this.measureSoon);for(let f of this.manager.tooltipViews)f.dom.remove(),(u=f.destroy)===null||u===void 0||u.call(f);this.parent&&this.container.remove(),(o=this.resizeObserver)===null||o===void 0||o.disconnect(),(a=this.intersectionObserver)===null||a===void 0||a.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let u=this.view.dom.getBoundingClientRect(),o=1,a=1,f=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:d}=this.manager.tooltipViews[0];if(ft.gecko)f=d.offsetParent!=this.container.ownerDocument.body;else if(d.style.top==fr&&d.style.left=="0px"){let m=d.getBoundingClientRect();f=Math.abs(m.top+1e4)>1||Math.abs(m.left)>1}}if(f||this.position=="absolute")if(this.parent){let d=this.parent.getBoundingClientRect();d.width&&d.height&&(o=d.width/this.parent.offsetWidth,a=d.height/this.parent.offsetHeight)}else({scaleX:o,scaleY:a}=this.view.viewState);return{editor:u,parent:this.parent?this.container.getBoundingClientRect():u,pos:this.manager.tooltips.map((d,m)=>{let S=this.manager.tooltipViews[m];return S.getCoords?S.getCoords(d.pos):this.view.coordsAtPos(d.pos)}),size:this.manager.tooltipViews.map(({dom:d})=>d.getBoundingClientRect()),space:this.view.state.facet(Do).tooltipSpace(this.view),scaleX:o,scaleY:a,makeAbsolute:f}}writeMeasure(u){var o;if(u.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let k of this.manager.tooltipViews)k.dom.style.position="absolute"}let{editor:a,space:f,scaleX:d,scaleY:m}=u,S=[];for(let k=0;k<this.manager.tooltips.length;k++){let M=this.manager.tooltips[k],B=this.manager.tooltipViews[k],{dom:E}=B,H=u.pos[k],K=u.size[k];if(!H||H.bottom<=Math.max(a.top,f.top)||H.top>=Math.min(a.bottom,f.bottom)||H.right<Math.max(a.left,f.left)-.1||H.left>Math.min(a.right,f.right)+.1){E.style.top=fr;continue}let Y=M.arrow?B.dom.querySelector(".cm-tooltip-arrow"):null,X=Y?7:0,it=K.right-K.left,rt=(o=Md.get(B))!==null&&o!==void 0?o:K.bottom-K.top,nt=B.offset||lS,bt=this.view.textDirection==n.Direction.LTR,Ct=K.width>f.right-f.left?bt?f.left:f.right-K.width:bt?Math.max(f.left,Math.min(H.left-(Y?14:0)+nt.x,f.right-it)):Math.min(Math.max(f.left,H.left-it+(Y?14:0)-nt.x),f.right-it),St=this.above[k];!M.strictSide&&(St?H.top-(K.bottom-K.top)-nt.y<f.top:H.bottom+(K.bottom-K.top)+nt.y>f.bottom)&&St==f.bottom-H.bottom>H.top-f.top&&(St=this.above[k]=!St);let Mt=(St?H.top-f.top:f.bottom-H.bottom)-X;if(Mt<rt&&B.resize!==!1){if(Mt<this.view.defaultLineHeight){E.style.top=fr;continue}Md.set(B,rt),E.style.height=(rt=Mt)/m+"px"}else E.style.height&&(E.style.height="");let Et=St?H.top-rt-X-nt.y:H.bottom+X+nt.y,fe=Ct+it;if(B.overlap!==!0)for(let ke of S)ke.left<fe&&ke.right>Ct&&ke.top<Et+rt&&ke.bottom>Et&&(Et=St?ke.top-rt-2-X:ke.bottom+X+2);if(this.position=="absolute"?(E.style.top=(Et-u.parent.top)/m+"px",E.style.left=(Ct-u.parent.left)/d+"px"):(E.style.top=Et/m+"px",E.style.left=Ct/d+"px"),Y){let ke=H.left+(bt?nt.x:-nt.x)-(Ct+14-7);Y.style.left=ke/d+"px"}B.overlap!==!0&&S.push({left:Ct,top:Et,right:fe,bottom:Et+rt}),E.classList.toggle("cm-tooltip-above",St),E.classList.toggle("cm-tooltip-below",!St),B.positioned&&B.positioned(u.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 u of this.manager.tooltipViews)u.dom.style.top=fr}},{eventObservers:{scroll(){this.maybeMeasure()}}}),oS=Nt.baseTheme({".cm-tooltip":{zIndex:100,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:`${7*2}px`,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"}}}),lS={x:0,y:0},Ra=t.Facet.define({enables:[Oo,oS]}),dr=t.Facet.define({combine:u=>u.reduce((o,a)=>o.concat(a),[])});class Eo{static create(o){return new Eo(o)}constructor(o){this.view=o,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Cd(o,dr,(a,f)=>this.createHostedView(a,f),a=>a.dom.remove())}createHostedView(o,a){let f=o.create(this.view);return f.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(f.dom,a?a.dom.nextSibling:this.dom.firstChild),this.mounted&&f.mount&&f.mount(this.view),f}mount(o){for(let a of this.manager.tooltipViews)a.mount&&a.mount(o);this.mounted=!0}positioned(o){for(let a of this.manager.tooltipViews)a.positioned&&a.positioned(o)}update(o){this.manager.update(o)}destroy(){var o;for(let a of this.manager.tooltipViews)(o=a.destroy)===null||o===void 0||o.call(a)}passProp(o){let a;for(let f of this.manager.tooltipViews){let d=f[o];if(d!==void 0){if(a===void 0)a=d;else if(a!==d)return}}return a}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 aS=Ra.compute([dr],u=>{let o=u.facet(dr);return o.length===0?null:{pos:Math.min(...o.map(a=>a.pos)),end:Math.max(...o.map(a=>{var f;return(f=a.end)!==null&&f!==void 0?f:a.pos})),create:Eo.create,above:o[0].above,arrow:o.some(a=>a.arrow)}});class hS{constructor(o,a,f,d,m){this.view=o,this.source=a,this.field=f,this.setHover=d,this.hoverTime=m,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:o.dom,time:0},this.checkHover=this.checkHover.bind(this),o.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),o.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 o=Date.now()-this.lastMove.time;o<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-o):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:o,lastMove:a}=this,f=o.docView.nearest(a.target);if(!f)return;let d,m=1;if(f instanceof ei)d=f.posAtStart;else{if(d=o.posAtCoords(a),d==null)return;let k=o.coordsAtPos(d);if(!k||a.y<k.top||a.y>k.bottom||a.x<k.left-o.defaultCharacterWidth||a.x>k.right+o.defaultCharacterWidth)return;let M=o.bidiSpans(o.state.doc.lineAt(d)).find(E=>E.from<=d&&E.to>=d),B=M&&M.dir==n.Direction.RTL?-1:1;m=a.x<k.left?-B:B}let S=this.source(o,d,m);if(S!=null&&S.then){let k=this.pending={pos:d};S.then(M=>{this.pending==k&&(this.pending=null,M&&!(Array.isArray(M)&&!M.length)&&o.dispatch({effects:this.setHover.of(Array.isArray(M)?M:[M])}))},M=>Ie(o.state,M,"hover tooltip"))}else S&&!(Array.isArray(S)&&!S.length)&&o.dispatch({effects:this.setHover.of(Array.isArray(S)?S:[S])})}get tooltip(){let o=this.view.plugin(Oo),a=o?o.manager.tooltips.findIndex(f=>f.create==Eo.create):-1;return a>-1?o.manager.tooltipViews[a]:null}mousemove(o){var a,f;this.lastMove={x:o.clientX,y:o.clientY,target:o.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:d,tooltip:m}=this;if(d.length&&m&&!cS(m.dom,o)||this.pending){let{pos:S}=d[0]||this.pending,k=(f=(a=d[0])===null||a===void 0?void 0:a.end)!==null&&f!==void 0?f:S;(S==k?this.view.posAtCoords(this.lastMove)!=S:!fS(this.view,S,k,o.clientX,o.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(o){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:a}=this;if(a.length){let{tooltip:f}=this;f&&f.dom.contains(o.relatedTarget)?this.watchTooltipLeave(f.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(o){let a=f=>{o.removeEventListener("mouseleave",a),this.active.length&&!this.view.dom.contains(f.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};o.addEventListener("mouseleave",a)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Po=4;function cS(u,o){let a=u.getBoundingClientRect();return o.clientX>=a.left-Po&&o.clientX<=a.right+Po&&o.clientY>=a.top-Po&&o.clientY<=a.bottom+Po}function fS(u,o,a,f,d,m){let S=u.scrollDOM.getBoundingClientRect(),k=u.documentTop+u.documentPadding.top+u.contentHeight;if(S.left>f||S.right<f||S.top>d||Math.min(S.bottom,k)<d)return!1;let M=u.posAtCoords({x:f,y:d},!1);return M>=o&&M<=a}function dS(u,o={}){let a=t.StateEffect.define(),f=t.StateField.define({create(){return[]},update(d,m){if(d.length&&(o.hideOnChange&&(m.docChanged||m.selection)?d=[]:o.hideOn&&(d=d.filter(S=>!o.hideOn(m,S))),m.docChanged)){let S=[];for(let k of d){let M=m.changes.mapPos(k.pos,-1,t.MapMode.TrackDel);if(M!=null){let B=Object.assign(Object.create(null),k);B.pos=M,B.end!=null&&(B.end=m.changes.mapPos(B.end)),S.push(B)}}d=S}for(let S of m.effects)S.is(a)&&(d=S.value),S.is(Ad)&&(d=[]);return d},provide:d=>dr.from(d)});return[f,pe.define(d=>new hS(d,u,f,a,o.hoverTime||300)),aS]}function uS(u,o){let a=u.plugin(Oo);if(!a)return null;let f=a.manager.tooltips.indexOf(o);return f<0?null:a.manager.tooltipViews[f]}function pS(u){return u.facet(dr).some(o=>o)}const Ad=t.StateEffect.define(),gS=Ad.of(null);function mS(u){let o=u.plugin(Oo);o&&o.maybeMeasure()}const Ba=t.Facet.define({combine(u){let o,a;for(let f of u)o=o||f.topContainer,a=a||f.bottomContainer;return{topContainer:o,bottomContainer:a}}});function bS(u){return u?[Ba.of(u)]:[]}function yS(u,o){let a=u.plugin(Td),f=a?a.specs.indexOf(o):-1;return f>-1?a.panels[f]:null}const Td=pe.fromClass(class{constructor(u){this.input=u.state.facet(La),this.specs=this.input.filter(a=>a),this.panels=this.specs.map(a=>a(u));let o=u.state.facet(Ba);this.top=new Ro(u,!0,o.topContainer),this.bottom=new Ro(u,!1,o.bottomContainer),this.top.sync(this.panels.filter(a=>a.top)),this.bottom.sync(this.panels.filter(a=>!a.top));for(let a of this.panels)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}update(u){let o=u.state.facet(Ba);this.top.container!=o.topContainer&&(this.top.sync([]),this.top=new Ro(u.view,!0,o.topContainer)),this.bottom.container!=o.bottomContainer&&(this.bottom.sync([]),this.bottom=new Ro(u.view,!1,o.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let a=u.state.facet(La);if(a!=this.input){let f=a.filter(M=>M),d=[],m=[],S=[],k=[];for(let M of f){let B=this.specs.indexOf(M),E;B<0?(E=M(u.view),k.push(E)):(E=this.panels[B],E.update&&E.update(u)),d.push(E),(E.top?m:S).push(E)}this.specs=f,this.panels=d,this.top.sync(m),this.bottom.sync(S);for(let M of k)M.dom.classList.add("cm-panel"),M.mount&&M.mount()}else for(let f of this.panels)f.update&&f.update(u)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:u=>Nt.scrollMargins.of(o=>{let a=o.plugin(u);return a&&{top:a.top.scrollMargin(),bottom:a.bottom.scrollMargin()}})});class Ro{constructor(o,a,f){this.view=o,this.top=a,this.container=f,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(o){for(let a of this.panels)a.destroy&&o.indexOf(a)<0&&a.destroy();this.panels=o,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 a=this.container||this.view.dom;a.insertBefore(this.dom,this.top?a.firstChild:null)}let o=this.dom.firstChild;for(let a of this.panels)if(a.dom.parentNode==this.dom){for(;o!=a.dom;)o=Dd(o);o=o.nextSibling}else this.dom.insertBefore(a.dom,o);for(;o;)o=Dd(o)}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 o of this.classes.split(" "))o&&this.container.classList.remove(o);for(let o of(this.classes=this.view.themeClasses).split(" "))o&&this.container.classList.add(o)}}}function Dd(u){let o=u.nextSibling;return u.remove(),o}const La=t.Facet.define({enables:Td});class on extends t.RangeValue{compare(o){return this==o||this.constructor==o.constructor&&this.eq(o)}eq(o){return!1}destroy(o){}}on.prototype.elementClass="",on.prototype.toDOM=void 0,on.prototype.mapMode=t.MapMode.TrackBefore,on.prototype.startSide=on.prototype.endSide=-1,on.prototype.point=!0;const ur=t.Facet.define(),SS={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>t.RangeSet.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},pr=t.Facet.define();function wS(u){return[Fa(),pr.of(Object.assign(Object.assign({},SS),u))]}const Na=t.Facet.define({combine:u=>u.some(o=>o)});function Fa(u){let o=[xS];return u&&u.fixed===!1&&o.push(Na.of(!0)),o}const xS=pe.fromClass(class{constructor(u){this.view=u,this.prevViewport=u.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=u.state.facet(pr).map(o=>new Ed(u,o));for(let o of this.gutters)this.dom.appendChild(o.dom);this.fixed=!u.state.facet(Na),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),u.scrollDOM.insertBefore(this.dom,u.contentDOM)}update(u){if(this.updateGutters(u)){let o=this.prevViewport,a=u.view.viewport,f=Math.min(o.to,a.to)-Math.max(o.from,a.from);this.syncGutters(f<(a.to-a.from)*.8)}u.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px"),this.view.state.facet(Na)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=u.view.viewport}syncGutters(u){let o=this.dom.nextSibling;u&&this.dom.remove();let a=t.RangeSet.iter(this.view.state.facet(ur),this.view.viewport.from),f=[],d=this.gutters.map(m=>new vS(m,this.view.viewport,-this.view.documentPadding.top));for(let m of this.view.viewportLineBlocks)if(f.length&&(f=[]),Array.isArray(m.type)){let S=!0;for(let k of m.type)if(k.type==n.BlockType.Text&&S){Ia(a,f,k.from);for(let M of d)M.line(this.view,k,f);S=!1}else if(k.widget)for(let M of d)M.widget(this.view,k)}else if(m.type==n.BlockType.Text){Ia(a,f,m.from);for(let S of d)S.line(this.view,m,f)}else if(m.widget)for(let S of d)S.widget(this.view,m);for(let m of d)m.finish();u&&this.view.scrollDOM.insertBefore(this.dom,o)}updateGutters(u){let o=u.startState.facet(pr),a=u.state.facet(pr),f=u.docChanged||u.heightChanged||u.viewportChanged||!t.RangeSet.eq(u.startState.facet(ur),u.state.facet(ur),u.view.viewport.from,u.view.viewport.to);if(o==a)for(let d of this.gutters)d.update(u)&&(f=!0);else{f=!0;let d=[];for(let m of a){let S=o.indexOf(m);S<0?d.push(new Ed(this.view,m)):(this.gutters[S].update(u),d.push(this.gutters[S]))}for(let m of this.gutters)m.dom.remove(),d.indexOf(m)<0&&m.destroy();for(let m of d)this.dom.appendChild(m.dom);this.gutters=d}return f}destroy(){for(let u of this.gutters)u.destroy();this.dom.remove()}},{provide:u=>Nt.scrollMargins.of(o=>{let a=o.plugin(u);return!a||a.gutters.length==0||!a.fixed?null:o.textDirection==n.Direction.LTR?{left:a.dom.offsetWidth*o.scaleX}:{right:a.dom.offsetWidth*o.scaleX}})});function Od(u){return Array.isArray(u)?u:[u]}function Ia(u,o,a){for(;u.value&&u.from<=a;)u.from==a&&o.push(u.value),u.next()}class vS{constructor(o,a,f){this.gutter=o,this.height=f,this.i=0,this.cursor=t.RangeSet.iter(o.markers,a.from)}addElement(o,a,f){let{gutter:d}=this,m=(a.top-this.height)/o.scaleY,S=a.height/o.scaleY;if(this.i==d.elements.length){let k=new Pd(o,S,m,f);d.elements.push(k),d.dom.appendChild(k.dom)}else d.elements[this.i].update(o,S,m,f);this.height=a.bottom,this.i++}line(o,a,f){let d=[];Ia(this.cursor,d,a.from),f.length&&(d=d.concat(f));let m=this.gutter.config.lineMarker(o,a,d);m&&d.unshift(m);let S=this.gutter;d.length==0&&!S.config.renderEmptyElements||this.addElement(o,a,d)}widget(o,a){let f=this.gutter.config.widgetMarker(o,a.widget,a);f&&this.addElement(o,a,[f])}finish(){let o=this.gutter;for(;o.elements.length>this.i;){let a=o.elements.pop();o.dom.removeChild(a.dom),a.destroy()}}}class Ed{constructor(o,a){this.view=o,this.config=a,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let f in a.domEventHandlers)this.dom.addEventListener(f,d=>{let m=d.target,S;if(m!=this.dom&&this.dom.contains(m)){for(;m.parentNode!=this.dom;)m=m.parentNode;let M=m.getBoundingClientRect();S=(M.top+M.bottom)/2}else S=d.clientY;let k=o.lineBlockAtHeight(S-o.documentTop);a.domEventHandlers[f](o,k,d)&&d.preventDefault()});this.markers=Od(a.markers(o)),a.initialSpacer&&(this.spacer=new Pd(o,0,0,[a.initialSpacer(o)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(o){let a=this.markers;if(this.markers=Od(this.config.markers(o.view)),this.spacer&&this.config.updateSpacer){let d=this.config.updateSpacer(this.spacer.markers[0],o);d!=this.spacer.markers[0]&&this.spacer.update(o.view,0,0,[d])}let f=o.view.viewport;return!t.RangeSet.eq(this.markers,a,f.from,f.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(o):!1)}destroy(){for(let o of this.elements)o.destroy()}}class Pd{constructor(o,a,f,d){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(o,a,f,d)}update(o,a,f,d){this.height!=a&&(this.height=a,this.dom.style.height=a+"px"),this.above!=f&&(this.dom.style.marginTop=(this.above=f)?f+"px":""),kS(this.markers,d)||this.setMarkers(o,d)}setMarkers(o,a){let f="cm-gutterElement",d=this.dom.firstChild;for(let m=0,S=0;;){let k=S,M=m<a.length?a[m++]:null,B=!1;if(M){let E=M.elementClass;E&&(f+=" "+E);for(let H=S;H<this.markers.length;H++)if(this.markers[H].compare(M)){k=H,B=!0;break}}else k=this.markers.length;for(;S<k;){let E=this.markers[S++];if(E.toDOM){E.destroy(d);let H=d.nextSibling;d.remove(),d=H}}if(!M)break;M.toDOM&&(B?d=d.nextSibling:this.dom.insertBefore(M.toDOM(o),d)),B&&S++}this.dom.className=f,this.markers=a}destroy(){this.setMarkers(null,[])}}function kS(u,o){if(u.length!=o.length)return!1;for(let a=0;a<u.length;a++)if(!u[a].compare(o[a]))return!1;return!0}const Rd=t.Facet.define(),Ss=t.Facet.define({combine(u){return t.combineConfig(u,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(o,a){let f=Object.assign({},o);for(let d in a){let m=f[d],S=a[d];f[d]=m?(k,M,B)=>m(k,M,B)||S(k,M,B):S}return f}})}});class Ha extends on{constructor(o){super(),this.number=o}eq(o){return this.number==o.number}toDOM(){return document.createTextNode(this.number)}}function Va(u,o){return u.state.facet(Ss).formatNumber(o,u.state)}const CS=pr.compute([Ss],u=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(o){return o.state.facet(Rd)},lineMarker(o,a,f){return f.some(d=>d.toDOM)?null:new Ha(Va(o,o.state.doc.lineAt(a.from).number))},widgetMarker:()=>null,lineMarkerChange:o=>o.startState.facet(Ss)!=o.state.facet(Ss),initialSpacer(o){return new Ha(Va(o,Bd(o.state.doc.lines)))},updateSpacer(o,a){let f=Va(a.view,Bd(a.view.state.doc.lines));return f==o.number?o:new Ha(f)},domEventHandlers:u.facet(Ss).domEventHandlers}));function MS(u={}){return[Ss.of(u),Fa(),CS]}function Bd(u){let o=9;for(;o<u;)o=o*10+9;return o}const AS=new class extends on{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},TS=ur.compute(["selection"],u=>{let o=[],a=-1;for(let f of u.selection.ranges){let d=u.doc.lineAt(f.head).from;d>a&&(a=d,o.push(AS.range(d)))}return t.RangeSet.of(o)});function DS(){return TS}const Ld=new Map;function OS(u){let o=Ld.get(u);return o||Ld.set(u,o=Vt.mark({attributes:u===" "?{class:"cm-highlightTab"}:{class:"cm-highlightSpace","data-display":u.replace(/ /g,"·")}})),o}function Nd(u){return pe.define(o=>({decorations:u.createDeco(o),update(a){this.decorations=u.updateDeco(a,this.decorations)}}),{decorations:o=>o.decorations})}const ES=Nd(new Ao({regexp:/\t| +/g,decoration:u=>OS(u[0]),boundary:/\S/}));function PS(){return ES}const RS=Nd(new Ao({regexp:/\s+$/g,decoration:Vt.mark({class:"cm-trailingSpace"}),boundary:/\S/}));function BS(){return RS}const LS={HeightMap:Re,HeightOracle:Yf,MeasuredHeights:Uf,QueryType:Yt,ChangedRange:He,computeOrder:V,moveVisually:C};n.BidiSpan=we,n.BlockInfo=Ai,n.Decoration=Vt,n.EditorView=Nt,n.GutterMarker=on,n.MatchDecorator=Ao,n.RectangleMarker=bs,n.ViewPlugin=pe,n.ViewUpdate=Cn,n.WidgetType=_e,n.__test=LS,n.closeHoverTooltips=gS,n.crosshairCursor=nS,n.drawSelection=D1,n.dropCursor=L1,n.getDrawSelectionConfig=O1,n.getPanel=yS,n.getTooltip=uS,n.gutter=wS,n.gutterLineClass=ur,n.gutters=Fa,n.hasHoverTooltips=pS,n.highlightActiveLine=_1,n.highlightActiveLineGutter=DS,n.highlightSpecialChars=V1,n.highlightTrailingWhitespace=BS,n.highlightWhitespace=PS,n.hoverTooltip=dS,n.keymap=cd,n.layer=Ta,n.lineNumberMarkers=Rd,n.lineNumbers=MS,n.logException=Ie,n.panels=bS,n.placeholder=X1,n.rectangularSelection=tS,n.repositionTooltips=mS,n.runScopeHandlers=v1,n.scrollPastEnd=j1,n.showPanel=La,n.showTooltip=Ra,n.tooltips=sS}(oh)),oh}var _u;function OC(){if(_u)return xt;_u=1;var n=IS(),t=Vc(),e=DC(),i=HS(),s=xg(),r;const l=new n.NodeProp;function h(R){return t.Facet.define({combine:R?v=>v.concat(R):void 0})}const c=new n.NodeProp;class g{constructor(v,D,F=[],$=""){this.data=v,this.name=$,t.EditorState.prototype.hasOwnProperty("tree")||Object.defineProperty(t.EditorState.prototype,"tree",{get(){return x(this)}}),this.parser=D,this.extension=[Tt.of(this),t.EditorState.languageData.of((j,G,tt)=>{let et=p(j,G,tt),ct=et.type.prop(l);if(!ct)return[];let yt=j.facet(ct),Lt=et.type.prop(c);if(Lt){let Pe=et.resolve(G-et.from,tt);for(let xe of Lt)if(xe.test(Pe,j)){let ri=j.facet(xe.facet);return xe.type=="replace"?ri:ri.concat(yt)}}return yt})].concat(F)}isActiveAt(v,D,F=-1){return p(v,D,F).type.prop(l)==this.data}findRegions(v){let D=v.facet(Tt);if((D==null?void 0:D.data)==this.data)return[{from:0,to:v.doc.length}];if(!D||!D.allowsNesting)return[];let F=[],$=(j,G)=>{if(j.prop(l)==this.data){F.push({from:G,to:G+j.length});return}let tt=j.prop(n.NodeProp.mounted);if(tt){if(tt.tree.prop(l)==this.data){if(tt.overlay)for(let et of tt.overlay)F.push({from:et.from+G,to:et.to+G});else F.push({from:G,to:G+j.length});return}else if(tt.overlay){let et=F.length;if($(tt.tree,tt.overlay[0].from+G),F.length>et)return}}for(let et=0;et<j.children.length;et++){let ct=j.children[et];ct instanceof n.Tree&&$(ct,j.positions[et]+G)}};return $(x(v),0),F}get allowsNesting(){return!0}}g.setState=t.StateEffect.define();function p(R,v,D){let F=R.facet(Tt),$=x(R).topNode;if(!F||F.allowsNesting)for(let j=$;j;j=j.enter(v,D,n.IterMode.ExcludeBuffers))j.type.isTop&&($=j);return $}class y extends g{constructor(v,D,F){super(v,D,[],F),this.parser=D}static define(v){let D=h(v.languageData);return new y(D,v.parser.configure({props:[l.add(F=>F.isTop?D:void 0)]}),v.name)}configure(v,D){return new y(this.data,this.parser.configure(v),D||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function x(R){let v=R.field(g.state,!1);return v?v.tree:n.Tree.empty}function T(R,v,D=50){var F;let $=(F=R.field(g.state,!1))===null||F===void 0?void 0:F.context;if(!$)return null;let j=$.viewport;$.updateViewport({from:0,to:v});let G=$.isDone(v)||$.work(D,v)?$.tree:null;return $.updateViewport(j),G}function P(R,v=R.doc.length){var D;return((D=R.field(g.state,!1))===null||D===void 0?void 0:D.context.isDone(v))||!1}function I(R,v=R.viewport.to,D=100){let F=T(R.state,v,D);return F!=x(R.state)&&R.dispatch({}),!!F}function z(R){var v;return((v=R.plugin(Pt))===null||v===void 0?void 0:v.isWorking())||!1}class W{constructor(v){this.doc=v,this.cursorPos=0,this.string="",this.cursor=v.iter()}get length(){return this.doc.length}syncTo(v){return this.string=this.cursor.next(v-this.cursorPos).value,this.cursorPos=v+this.string.length,this.cursorPos-this.string.length}chunk(v){return this.syncTo(v),this.string}get lineChunks(){return!0}read(v,D){let F=this.cursorPos-this.string.length;return v<F||D>=this.cursorPos?this.doc.sliceString(v,D):this.string.slice(v-F,D-F)}}let U=null;class ot{constructor(v,D,F=[],$,j,G,tt,et){this.parser=v,this.state=D,this.fragments=F,this.tree=$,this.treeLen=j,this.viewport=G,this.skipped=tt,this.scheduleOn=et,this.parse=null,this.tempSkipped=[]}static create(v,D,F){return new ot(v,D,[],n.Tree.empty,0,F,[],null)}startParse(){return this.parser.startParse(new W(this.state.doc),this.fragments)}work(v,D){return D!=null&&D>=this.state.doc.length&&(D=void 0),this.tree!=n.Tree.empty&&this.isDone(D??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var F;if(typeof v=="number"){let $=Date.now()+v;v=()=>Date.now()>$}for(this.parse||(this.parse=this.startParse()),D!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>D)&&D<this.state.doc.length&&this.parse.stopAt(D);;){let $=this.parse.advance();if($)if(this.fragments=this.withoutTempSkipped(n.TreeFragment.addTree($,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(F=this.parse.stoppedAt)!==null&&F!==void 0?F:this.state.doc.length,this.tree=$,this.parse=null,this.treeLen<(D??this.state.doc.length))this.parse=this.startParse();else return!0;if(v())return!1}})}takeTree(){let v,D;this.parse&&(v=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>v)&&this.parse.stopAt(v),this.withContext(()=>{for(;!(D=this.parse.advance()););}),this.treeLen=v,this.tree=D,this.fragments=this.withoutTempSkipped(n.TreeFragment.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(v){let D=U;U=this;try{return v()}finally{U=D}}withoutTempSkipped(v){for(let D;D=this.tempSkipped.pop();)v=Q(v,D.from,D.to);return v}changes(v,D){let{fragments:F,tree:$,treeLen:j,viewport:G,skipped:tt}=this;if(this.takeTree(),!v.empty){let et=[];if(v.iterChangedRanges((ct,yt,Lt,Pe)=>et.push({fromA:ct,toA:yt,fromB:Lt,toB:Pe})),F=n.TreeFragment.applyChanges(F,et),$=n.Tree.empty,j=0,G={from:v.mapPos(G.from,-1),to:v.mapPos(G.to,1)},this.skipped.length){tt=[];for(let ct of this.skipped){let yt=v.mapPos(ct.from,1),Lt=v.mapPos(ct.to,-1);yt<Lt&&tt.push({from:yt,to:Lt})}}}return new ot(this.parser,D,F,$,j,G,tt,this.scheduleOn)}updateViewport(v){if(this.viewport.from==v.from&&this.viewport.to==v.to)return!1;this.viewport=v;let D=this.skipped.length;for(let F=0;F<this.skipped.length;F++){let{from:$,to:j}=this.skipped[F];$<v.to&&j>v.from&&(this.fragments=Q(this.fragments,$,j),this.skipped.splice(F--,1))}return this.skipped.length>=D?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(v,D){this.skipped.push({from:v,to:D})}static getSkippingParser(v){return new class extends n.Parser{createParse(D,F,$){let j=$[0].from,G=$[$.length-1].to;return{parsedPos:j,advance(){let et=U;if(et){for(let ct of $)et.tempSkipped.push(ct);v&&(et.scheduleOn=et.scheduleOn?Promise.all([et.scheduleOn,v]):v)}return this.parsedPos=G,new n.Tree(n.NodeType.none,[],[],G-j)},stoppedAt:null,stopAt(){}}}}}isDone(v){v=Math.min(v,this.state.doc.length);let D=this.fragments;return this.treeLen>=v&&D.length&&D[0].from==0&&D[0].to>=v}static get(){return U}}function Q(R,v,D){return n.TreeFragment.applyChanges(R,[{fromA:v,toA:D,fromB:v,toB:D}])}class st{constructor(v){this.context=v,this.tree=v.tree}apply(v){if(!v.docChanged&&this.tree==this.context.tree)return this;let D=this.context.changes(v.changes,v.state),F=this.context.treeLen==v.startState.doc.length?void 0:Math.max(v.changes.mapPos(this.context.treeLen),D.viewport.to);return D.work(20,F)||D.takeTree(),new st(D)}static init(v){let D=Math.min(3e3,v.doc.length),F=ot.create(v.facet(Tt).parser,v,{from:0,to:D});return F.work(20,D)||F.takeTree(),new st(F)}}g.state=t.StateField.define({create:st.init,update(R,v){for(let D of v.effects)if(D.is(g.setState))return D.value;return v.startState.facet(Tt)!=v.state.facet(Tt)?st.init(v.state):R.apply(v)}});let at=R=>{let v=setTimeout(()=>R(),500);return()=>clearTimeout(v)};typeof requestIdleCallback<"u"&&(at=R=>{let v=-1,D=setTimeout(()=>{v=requestIdleCallback(R,{timeout:400})},100);return()=>v<0?clearTimeout(D):cancelIdleCallback(v)});const wt=typeof navigator<"u"&&(!((r=navigator.scheduling)===null||r===void 0)&&r.isInputPending)?()=>navigator.scheduling.isInputPending():null,Pt=e.ViewPlugin.fromClass(class{constructor(v){this.view=v,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(v){let D=this.view.state.field(g.state).context;(D.updateViewport(v.view.viewport)||this.view.viewport.to>D.treeLen)&&this.scheduleWork(),(v.docChanged||v.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(D)}scheduleWork(){if(this.working)return;let{state:v}=this.view,D=v.field(g.state);(D.tree!=D.context.tree||!D.context.isDone(v.doc.length))&&(this.working=at(this.work))}work(v){this.working=null;let D=Date.now();if(this.chunkEnd<D&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=D+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:F,viewport:{to:$}}=this.view,j=F.field(g.state);if(j.tree==j.context.tree&&j.context.isDone($+1e5))return;let G=Date.now()+Math.min(this.chunkBudget,100,v&&!wt?Math.max(25,v.timeRemaining()-5):1e9),tt=j.context.treeLen<$&&F.doc.length>$+1e3,et=j.context.work(()=>wt&&wt()||Date.now()>G,$+(tt?0:1e5));this.chunkBudget-=Date.now()-D,(et||this.chunkBudget<=0)&&(j.context.takeTree(),this.view.dispatch({effects:g.setState.of(new st(j.context))})),this.chunkBudget>0&&!(et&&!tt)&&this.scheduleWork(),this.checkAsyncSchedule(j.context)}checkAsyncSchedule(v){v.scheduleOn&&(this.workScheduled++,v.scheduleOn.then(()=>this.scheduleWork()).catch(D=>e.logException(this.view.state,D)).then(()=>this.workScheduled--),v.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Tt=t.Facet.define({combine(R){return R.length?R[0]:null},enables:R=>[g.state,Pt,e.EditorView.contentAttributes.compute([R],v=>{let D=v.facet(R);return D&&D.name?{"data-language":D.name}:{}})]});class le{constructor(v,D=[]){this.language=v,this.support=D,this.extension=[v,D]}}class ae{constructor(v,D,F,$,j,G=void 0){this.name=v,this.alias=D,this.extensions=F,this.filename=$,this.loadFunc=j,this.support=G,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(v=>this.support=v,v=>{throw this.loading=null,v}))}static of(v){let{load:D,support:F}=v;if(!D){if(!F)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");D=()=>Promise.resolve(F)}return new ae(v.name,(v.alias||[]).concat(v.name).map($=>$.toLowerCase()),v.extensions||[],v.filename,D,F)}static matchFilename(v,D){for(let $ of v)if($.filename&&$.filename.test(D))return $;let F=/\.([^.]+)$/.exec(D);if(F){for(let $ of v)if($.extensions.indexOf(F[1])>-1)return $}return null}static matchLanguageName(v,D,F=!0){D=D.toLowerCase();for(let $ of v)if($.alias.some(j=>j==D))return $;if(F)for(let $ of v)for(let j of $.alias){let G=D.indexOf(j);if(G>-1&&(j.length>2||!/\w/.test(D[G-1])&&!/\w/.test(D[G+j.length])))return $}return null}}const zt=t.Facet.define(),Ot=t.Facet.define({combine:R=>{if(!R.length)return" ";let v=R[0];if(!v||/\S/.test(v)||Array.from(v).some(D=>D!=v[0]))throw new Error("Invalid indent unit: "+JSON.stringify(R[0]));return v}});function ne(R){let v=R.facet(Ot);return v.charCodeAt(0)==9?R.tabSize*v.length:v.length}function Rt(R,v){let D="",F=R.tabSize,$=R.facet(Ot)[0];if($==" "){for(;v>=F;)D+=" ",v-=F;$=" "}for(let j=0;j<v;j++)D+=$;return D}function Bt(R,v){R instanceof t.EditorState&&(R=new Zt(R));for(let F of R.state.facet(zt)){let $=F(R,v);if($!==void 0)return $}let D=x(R.state);return D.length>=v?ue(R,D,v):null}function vt(R,v,D){let F=Object.create(null),$=new Zt(R,{overrideIndentation:G=>{var tt;return(tt=F[G])!==null&&tt!==void 0?tt:-1}}),j=[];for(let G=v;G<=D;){let tt=R.doc.lineAt(G);G=tt.to+1;let et=Bt($,tt.from);if(et==null)continue;/\S/.test(tt.text)||(et=0);let ct=/^\s*/.exec(tt.text)[0],yt=Rt(R,et);ct!=yt&&(F[tt.from]=et,j.push({from:tt.from,to:tt.from+ct.length,insert:yt}))}return R.changes(j)}class Zt{constructor(v,D={}){this.state=v,this.options=D,this.unit=ne(v)}lineAt(v,D=1){let F=this.state.doc.lineAt(v),{simulateBreak:$,simulateDoubleBreak:j}=this.options;return $!=null&&$>=F.from&&$<=F.to?j&&$==v?{text:"",from:v}:(D<0?$<v:$<=v)?{text:F.text.slice($-F.from),from:$}:{text:F.text.slice(0,$-F.from),from:F.from}:F}textAfterPos(v,D=1){if(this.options.simulateDoubleBreak&&v==this.options.simulateBreak)return"";let{text:F,from:$}=this.lineAt(v,D);return F.slice(v-$,Math.min(F.length,v+100-$))}column(v,D=1){let{text:F,from:$}=this.lineAt(v,D),j=this.countColumn(F,v-$),G=this.options.overrideIndentation?this.options.overrideIndentation($):-1;return G>-1&&(j+=G-this.countColumn(F,F.search(/\S|$/))),j}countColumn(v,D=v.length){return t.countColumn(v,this.state.tabSize,D)}lineIndent(v,D=1){let{text:F,from:$}=this.lineAt(v,D),j=this.options.overrideIndentation;if(j){let G=j($);if(G>-1)return G}return this.countColumn(F,F.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const se=new n.NodeProp;function ue(R,v,D){let F=v.resolveStack(D),$=F.node.enterUnfinishedNodesBefore(D);if($!=F.node){let j=[];for(let G=$;G!=F.node;G=G.parent)j.push(G);for(let G=j.length-1;G>=0;G--)F={node:j[G],next:F}}return qn(F,R,D)}function qn(R,v,D){for(let F=R;F;F=F.next){let $=Qe(F.node);if($)return $(ti.create(v,D,F))}return 0}function he(R){return R.pos==R.options.simulateBreak&&R.options.simulateDoubleBreak}function Qe(R){let v=R.type.prop(se);if(v)return v;let D=R.firstChild,F;if(D&&(F=D.type.prop(n.NodeProp.closedBy))){let $=R.lastChild,j=$&&F.indexOf($.name)>-1;return G=>Fi(G,!0,1,void 0,j&&!he(G)?$.from:void 0)}return R.parent==null?Ze:null}function Ze(){return 0}class ti extends Zt{constructor(v,D,F){super(v.state,v.options),this.base=v,this.pos=D,this.context=F}get node(){return this.context.node}static create(v,D,F){return new ti(v,D,F)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(v){let D=this.state.doc.lineAt(v.from);for(;;){let F=v.resolve(D.from);for(;F.parent&&F.parent.from==F.from;)F=F.parent;if(Kn(F,v))break;D=this.state.doc.lineAt(F.from)}return this.lineIndent(D.from)}continue(){return qn(this.context.next,this.base,this.pos)}}function Kn(R,v){for(let D=v;D;D=D.parent)if(R==D)return!0;return!1}function Zi(R){let v=R.node,D=v.childAfter(v.from),F=v.lastChild;if(!D)return null;let $=R.options.simulateBreak,j=R.state.doc.lineAt(D.from),G=$==null||$<=j.from?j.to:Math.min(j.to,$);for(let tt=D.to;;){let et=v.childAfter(tt);if(!et||et==F)return null;if(!et.type.isSkipped){if(et.from>=G)return null;let ct=/^ */.exec(j.text.slice(D.to-j.from))[0].length;return{from:D.from,to:D.to+ct}}tt=et.to}}function Ni({closing:R,align:v=!0,units:D=1}){return F=>Fi(F,v,D,R)}function Fi(R,v,D,F,$){let j=R.textAfter,G=j.match(/^\s*/)[0].length,tt=F&&j.slice(G,G+F.length)==F||$==R.pos+G,et=v?Zi(R):null;return et?tt?R.column(et.from):R.column(et.to):R.baseIndent+(tt?0:R.unit*D)}const gn=R=>R.baseIndent;function as({except:R,units:v=1}={}){return D=>{let F=R&&R.test(D.textAfter);return D.baseIndent+(F?0:v*D.unit)}}const Ii=200;function ft(){return t.EditorState.transactionFilter.of(R=>{if(!R.docChanged||!R.isUserEvent("input.type")&&!R.isUserEvent("input.complete"))return R;let v=R.startState.languageDataAt("indentOnInput",R.startState.selection.main.head);if(!v.length)return R;let D=R.newDoc,{head:F}=R.newSelection.main,$=D.lineAt(F);if(F>$.from+Ii)return R;let j=D.sliceString($.from,F);if(!v.some(ct=>ct.test(j)))return R;let{state:G}=R,tt=-1,et=[];for(let{head:ct}of G.selection.ranges){let yt=G.doc.lineAt(ct);if(yt.from==tt)continue;tt=yt.from;let Lt=Bt(G,yt.from);if(Lt==null)continue;let Pe=/^\s*/.exec(yt.text)[0],xe=Rt(G,Lt);Pe!=xe&&et.push({from:yt.from,to:yt.from+Pe.length,insert:xe})}return et.length?[R,{changes:et,sequential:!0}]:R})}const jn=t.Facet.define(),ye=new n.NodeProp;function Ke(R){let v=R.firstChild,D=R.lastChild;return v&&v.to<D.from?{from:v.to,to:D.type.isError?R.to:D.from}:null}function hs(R,v,D){let F=x(R);if(F.length<D)return null;let $=F.resolveStack(D,1),j=null;for(let G=$;G;G=G.next){let tt=G.node;if(tt.to<=D||tt.from>D)continue;if(j&&tt.from<v)break;let et=tt.type.prop(ye);if(et&&(tt.to<F.length-50||F.length==R.doc.length||!ei(tt))){let ct=et(tt,R);ct&&ct.from<=D&&ct.from>=v&&ct.to>D&&(j=ct)}}return j}function ei(R){let v=R.lastChild;return v&&v.to==R.to&&v.type.isError}function De(R,v,D){for(let F of R.facet(jn)){let $=F(R,v,D);if($)return $}return hs(R,v,D)}function mn(R,v){let D=v.mapPos(R.from,1),F=v.mapPos(R.to,-1);return D>=F?void 0:{from:D,to:F}}const Oe=t.StateEffect.define({map:mn}),ii=t.StateEffect.define({map:mn});function bn(R){let v=[];for(let{head:D}of R.state.selection.ranges)v.some(F=>F.from<=D&&F.to>=D)||v.push(R.lineBlockAt(D));return v}const Ht=t.StateField.define({create(){return e.Decoration.none},update(R,v){R=R.map(v.changes);for(let D of v.effects)if(D.is(Oe)&&!yn(R,D.value.from,D.value.to)){let{preparePlaceholder:F}=v.state.facet(Wt),$=F?e.Decoration.replace({widget:new si(F(v.state,D.value))}):Ee;R=R.update({add:[$.range(D.value.from,D.value.to)]})}else D.is(ii)&&(R=R.update({filter:(F,$)=>D.value.from!=F||D.value.to!=$,filterFrom:D.value.from,filterTo:D.value.to}));if(v.selection){let D=!1,{head:F}=v.selection.main;R.between(F,F,($,j)=>{$<F&&j>F&&(D=!0)}),D&&(R=R.update({filterFrom:F,filterTo:F,filter:($,j)=>j<=F||$>=F}))}return R},provide:R=>e.EditorView.decorations.from(R),toJSON(R,v){let D=[];return R.between(0,v.doc.length,(F,$)=>{D.push(F,$)}),D},fromJSON(R){if(!Array.isArray(R)||R.length%2)throw new RangeError("Invalid JSON for fold state");let v=[];for(let D=0;D<R.length;){let F=R[D++],$=R[D++];if(typeof F!="number"||typeof $!="number")throw new RangeError("Invalid JSON for fold state");v.push(Ee.range(F,$))}return e.Decoration.set(v,!0)}});function ce(R){return R.field(Ht,!1)||t.RangeSet.empty}function di(R,v,D){var F;let $=null;return(F=R.field(Ht,!1))===null||F===void 0||F.between(v,D,(j,G)=>{(!$||$.from>j)&&($={from:j,to:G})}),$}function yn(R,v,D){let F=!1;return R.between(v,v,($,j)=>{$==v&&j==D&&(F=!0)}),F}function tn(R,v){return R.field(Ht,!1)?v:v.concat(t.StateEffect.appendConfig.of(ki()))}const _t=R=>{for(let v of bn(R)){let D=De(R.state,v.from,v.to);if(D)return R.dispatch({effects:tn(R.state,[Oe.of(D),_e(R,D)])}),!0}return!1},je=R=>{if(!R.state.field(Ht,!1))return!1;let v=[];for(let D of bn(R)){let F=di(R.state,D.from,D.to);F&&v.push(ii.of(F),_e(R,F,!1))}return v.length&&R.dispatch({effects:v}),v.length>0};function _e(R,v,D=!0){let F=R.state.doc.lineAt(v.from).number,$=R.state.doc.lineAt(v.to).number;return e.EditorView.announce.of(`${R.state.phrase(D?"Folded lines":"Unfolded lines")} ${F} ${R.state.phrase("to")} ${$}.`)}const Vt=R=>{let{state:v}=R,D=[];for(let F=0;F<v.doc.length;){let $=R.lineBlockAt(F),j=De(v,$.from,$.to);j&&D.push(Oe.of(j)),F=(j?R.lineBlockAt(j.to):$).to+1}return D.length&&R.dispatch({effects:tn(R.state,D)}),!!D.length},Fe=R=>{let v=R.state.field(Ht,!1);if(!v||!v.size)return!1;let D=[];return v.between(0,R.state.doc.length,(F,$)=>{D.push(ii.of({from:F,to:$}))}),R.dispatch({effects:D}),!0};function en(R,v){for(let D=v;;){let F=De(R.state,D.from,D.to);if(F&&F.to>v.from)return F;if(!D.from)return null;D=R.lineBlockAt(D.from-1)}}const Ge=R=>{let v=[];for(let D of bn(R)){let F=di(R.state,D.from,D.to);if(F)v.push(ii.of(F),_e(R,F,!1));else{let $=en(R,D);$&&v.push(Oe.of($),_e(R,$))}}return v.length>0&&R.dispatch({effects:tn(R.state,v)}),!!v.length},cs=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:_t},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:je},{key:"Ctrl-Alt-[",run:Vt},{key:"Ctrl-Alt-]",run:Fe}],er={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Wt=t.Facet.define({combine(R){return t.combineConfig(R,er)}});function ki(R){let v=[Ht,sn];return R&&v.push(Wt.of(R)),v}function ni(R,v){let{state:D}=R,F=D.facet(Wt),$=G=>{let tt=R.lineBlockAt(R.posAtDOM(G.target)),et=di(R.state,tt.from,tt.to);et&&R.dispatch({effects:ii.of(et)}),G.preventDefault()};if(F.placeholderDOM)return F.placeholderDOM(R,$,v);let j=document.createElement("span");return j.textContent=F.placeholderText,j.setAttribute("aria-label",D.phrase("folded code")),j.title=D.phrase("unfold"),j.className="cm-foldPlaceholder",j.onclick=$,j}const Ee=e.Decoration.replace({widget:new class extends e.WidgetType{toDOM(R){return ni(R,null)}}});class si extends e.WidgetType{constructor(v){super(),this.value=v}eq(v){return this.value==v.value}toDOM(v){return ni(v,this.value)}}const nn={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class re extends e.GutterMarker{constructor(v,D){super(),this.config=v,this.open=D}eq(v){return this.config==v.config&&this.open==v.open}toDOM(v){if(this.config.markerDOM)return this.config.markerDOM(this.open);let D=document.createElement("span");return D.textContent=this.open?this.config.openText:this.config.closedText,D.title=v.state.phrase(this.open?"Fold line":"Unfold line"),D}}function ir(R={}){let v=Object.assign(Object.assign({},nn),R),D=new re(v,!0),F=new re(v,!1),$=e.ViewPlugin.fromClass(class{constructor(G){this.from=G.viewport.from,this.markers=this.buildMarkers(G)}update(G){(G.docChanged||G.viewportChanged||G.startState.facet(Tt)!=G.state.facet(Tt)||G.startState.field(Ht,!1)!=G.state.field(Ht,!1)||x(G.startState)!=x(G.state)||v.foldingChanged(G))&&(this.markers=this.buildMarkers(G.view))}buildMarkers(G){let tt=new t.RangeSetBuilder;for(let et of G.viewportLineBlocks){let ct=di(G.state,et.from,et.to)?F:De(G.state,et.from,et.to)?D:null;ct&&tt.add(et.from,et.from,ct)}return tt.finish()}}),{domEventHandlers:j}=v;return[$,e.gutter({class:"cm-foldGutter",markers(G){var tt;return((tt=G.plugin($))===null||tt===void 0?void 0:tt.markers)||t.RangeSet.empty},initialSpacer(){return new re(v,!1)},domEventHandlers:Object.assign(Object.assign({},j),{click:(G,tt,et)=>{if(j.click&&j.click(G,tt,et))return!0;let ct=di(G.state,tt.from,tt.to);if(ct)return G.dispatch({effects:ii.of(ct)}),!0;let yt=De(G.state,tt.from,tt.to);return yt?(G.dispatch({effects:Oe.of(yt)}),!0):!1}})}),ki()]}const sn=e.EditorView.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 ui{constructor(v,D){this.specs=v;let F;function $(tt){let et=s.StyleModule.newName();return(F||(F=Object.create(null)))["."+et]=tt,et}const j=typeof D.all=="string"?D.all:D.all?$(D.all):void 0,G=D.scope;this.scope=G instanceof g?tt=>tt.prop(l)==G.data:G?tt=>tt==G:void 0,this.style=i.tagHighlighter(v.map(tt=>({tag:tt.tag,class:tt.class||$(Object.assign({},tt,{tag:null}))})),{all:j}).style,this.module=F?new s.StyleModule(F):null,this.themeType=D.themeType}static define(v,D){return new ui(v,D||{})}}const Se=t.Facet.define(),Ci=t.Facet.define({combine(R){return R.length?[R[0]]:null}});function Hi(R){let v=R.facet(Se);return v.length?v:R.facet(Ci)}function we(R,v){let D=[Sn],F;return R instanceof ui&&(R.module&&D.push(e.EditorView.styleModule.of(R.module)),F=R.themeType),v!=null&&v.fallback?D.push(Ci.of(R)):F?D.push(Se.computeN([e.EditorView.darkTheme],$=>$.facet(e.EditorView.darkTheme)==(F=="dark")?[R]:[])):D.push(Se.of(R)),D}function _n(R,v,D){let F=Hi(R),$=null;if(F){for(let j of F)if(!j.scope||D&&j.scope(D)){let G=j.style(v);G&&($=$?$+" "+G:G)}}return $}class Ft{constructor(v){this.markCache=Object.create(null),this.tree=x(v.state),this.decorations=this.buildDeco(v,Hi(v.state)),this.decoratedTo=v.viewport.to}update(v){let D=x(v.state),F=Hi(v.state),$=F!=Hi(v.startState),{viewport:j}=v.view,G=v.changes.mapPos(this.decoratedTo,1);D.length<j.to&&!$&&D.type==this.tree.type&&G>=j.to?(this.decorations=this.decorations.map(v.changes),this.decoratedTo=G):(D!=this.tree||v.viewportChanged||$)&&(this.tree=D,this.decorations=this.buildDeco(v.view,F),this.decoratedTo=j.to)}buildDeco(v,D){if(!D||!this.tree.length)return e.Decoration.none;let F=new t.RangeSetBuilder;for(let{from:$,to:j}of v.visibleRanges)i.highlightTree(this.tree,D,(G,tt,et)=>{F.add(G,tt,this.markCache[et]||(this.markCache[et]=e.Decoration.mark({class:et})))},$,j);return F.finish()}}const Sn=t.Prec.high(e.ViewPlugin.fromClass(Ft,{decorations:R=>R.decorations})),wn=ui.define([{tag:i.tags.meta,color:"#404740"},{tag:i.tags.link,textDecoration:"underline"},{tag:i.tags.heading,textDecoration:"underline",fontWeight:"bold"},{tag:i.tags.emphasis,fontStyle:"italic"},{tag:i.tags.strong,fontWeight:"bold"},{tag:i.tags.strikethrough,textDecoration:"line-through"},{tag:i.tags.keyword,color:"#708"},{tag:[i.tags.atom,i.tags.bool,i.tags.url,i.tags.contentSeparator,i.tags.labelName],color:"#219"},{tag:[i.tags.literal,i.tags.inserted],color:"#164"},{tag:[i.tags.string,i.tags.deleted],color:"#a11"},{tag:[i.tags.regexp,i.tags.escape,i.tags.special(i.tags.string)],color:"#e40"},{tag:i.tags.definition(i.tags.variableName),color:"#00f"},{tag:i.tags.local(i.tags.variableName),color:"#30a"},{tag:[i.tags.typeName,i.tags.namespace],color:"#085"},{tag:i.tags.className,color:"#167"},{tag:[i.tags.special(i.tags.variableName),i.tags.macroName],color:"#256"},{tag:i.tags.definition(i.tags.propertyName),color:"#00c"},{tag:i.tags.comment,color:"#940"},{tag:i.tags.invalid,color:"#f00"}]),fs=e.EditorView.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),xn=1e4,vn="()[]{}",V=t.Facet.define({combine(R){return t.combineConfig(R,{afterCursor:!0,brackets:vn,maxScanDistance:xn,renderMatch:C})}}),b=e.Decoration.mark({class:"cm-matchingBracket"}),w=e.Decoration.mark({class:"cm-nonmatchingBracket"});function C(R){let v=[],D=R.matched?b:w;return v.push(D.range(R.start.from,R.start.to)),R.end&&v.push(D.range(R.end.from,R.end.to)),v}const L=[t.StateField.define({create(){return e.Decoration.none},update(R,v){if(!v.docChanged&&!v.selection)return R;let D=[],F=v.state.facet(V);for(let $ of v.state.selection.ranges){if(!$.empty)continue;let j=lt(v.state,$.head,-1,F)||$.head>0&&lt(v.state,$.head-1,1,F)||F.afterCursor&&(lt(v.state,$.head,1,F)||$.head<v.state.doc.length&&lt(v.state,$.head+1,-1,F));j&&(D=D.concat(F.renderMatch(j,v.state)))}return e.Decoration.set(D,!0)},provide:R=>e.EditorView.decorations.from(R)}),fs];function N(R={}){return[V.of(R),L]}const q=new n.NodeProp;function _(R,v,D){let F=R.prop(v<0?n.NodeProp.openedBy:n.NodeProp.closedBy);if(F)return F;if(R.name.length==1){let $=D.indexOf(R.name);if($>-1&&$%2==(v<0?1:0))return[D[$+v]]}return null}function Z(R){let v=R.type.prop(q);return v?v(R.node):R}function lt(R,v,D,F={}){let $=F.maxScanDistance||xn,j=F.brackets||vn,G=x(R),tt=G.resolveInner(v,D);for(let et=tt;et;et=et.parent){let ct=_(et.type,D,j);if(ct&&et.from<et.to){let yt=Z(et);if(yt&&(D>0?v>=yt.from&&v<yt.to:v>yt.from&&v<=yt.to))return ht(R,v,D,et,yt,ct,j)}}return gt(R,v,D,G,tt.type,$,j)}function ht(R,v,D,F,$,j,G){let tt=F.parent,et={from:$.from,to:$.to},ct=0,yt=tt==null?void 0:tt.cursor();if(yt&&(D<0?yt.childBefore(F.from):yt.childAfter(F.to)))do if(D<0?yt.to<=F.from:yt.from>=F.to){if(ct==0&&j.indexOf(yt.type.name)>-1&&yt.from<yt.to){let Lt=Z(yt);return{start:et,end:Lt?{from:Lt.from,to:Lt.to}:void 0,matched:!0}}else if(_(yt.type,D,G))ct++;else if(_(yt.type,-D,G)){if(ct==0){let Lt=Z(yt);return{start:et,end:Lt&&Lt.from<Lt.to?{from:Lt.from,to:Lt.to}:void 0,matched:!1}}ct--}}while(D<0?yt.prevSibling():yt.nextSibling());return{start:et,matched:!1}}function gt(R,v,D,F,$,j,G){let tt=D<0?R.sliceDoc(v-1,v):R.sliceDoc(v,v+1),et=G.indexOf(tt);if(et<0||et%2==0!=D>0)return null;let ct={from:D<0?v-1:v,to:D>0?v+1:v},yt=R.doc.iterRange(v,D>0?R.doc.length:0),Lt=0;for(let Pe=0;!yt.next().done&&Pe<=j;){let xe=yt.value;D<0&&(Pe+=xe.length);let ri=v+Pe*D;for(let Mn=D>0?0:xe.length-1,po=D>0?xe.length:-1;Mn!=po;Mn+=D){let lr=G.indexOf(xe[Mn]);if(!(lr<0||F.resolveInner(ri+Mn,1).type!=$))if(lr%2==0==D>0)Lt++;else{if(Lt==1)return{start:ct,end:{from:ri+Mn,to:ri+Mn+1},matched:lr>>1==et>>1};Lt--}}D>0&&(Pe+=xe.length)}return yt.done?{start:ct,matched:!1}:null}function pt(R,v,D,F=0,$=0){v==null&&(v=R.search(/[^\s\u00a0]/),v==-1&&(v=R.length));let j=$;for(let G=F;G<v;G++)R.charCodeAt(G)==9?j+=D-j%D:j++;return j}class It{constructor(v,D,F,$){this.string=v,this.tabSize=D,this.indentUnit=F,this.overrideIndent=$,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(v){let D=this.string.charAt(this.pos),F;if(typeof v=="string"?F=D==v:F=D&&(v instanceof RegExp?v.test(D):v(D)),F)return++this.pos,D}eatWhile(v){let D=this.pos;for(;this.eat(v););return this.pos>D}eatSpace(){let v=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>v}skipToEnd(){this.pos=this.string.length}skipTo(v){let D=this.string.indexOf(v,this.pos);if(D>-1)return this.pos=D,!0}backUp(v){this.pos-=v}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=pt(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var v;return(v=this.overrideIndent)!==null&&v!==void 0?v:pt(this.string,null,this.tabSize)}match(v,D,F){if(typeof v=="string"){let $=G=>F?G.toLowerCase():G,j=this.string.substr(this.pos,v.length);return $(j)==$(v)?(D!==!1&&(this.pos+=v.length),!0):null}else{let $=this.string.slice(this.pos).match(v);return $&&$.index>0?null:($&&D!==!1&&(this.pos+=$[0].length),$)}}current(){return this.string.slice(this.start,this.pos)}}function be(R){return{name:R.name||"",token:R.token,blankLine:R.blankLine||(()=>{}),startState:R.startState||(()=>!0),copyState:R.copyState||Gt,indent:R.indent||(()=>null),languageData:R.languageData||{},tokenTable:R.tokenTable||us}}function Gt(R){if(typeof R!="object")return R;let v={};for(let D in R){let F=R[D];v[D]=F instanceof Array?F.slice():F}return v}const rn=new WeakMap;class Ie extends g{constructor(v){let D=h(v.languageData),F=be(v),$,j=new class extends n.Parser{createParse(G,tt,et){return new pe($,G,tt,et)}};super(D,j,[zt.of((G,tt)=>this.getIndent(G,tt))],v.name),this.topNode=He(D),$=this,this.streamParser=F,this.stateAfter=new n.NodeProp({perNode:!0}),this.tokenTable=v.tokenTable?new rr(F.tokenTable):co}static define(v){return new Ie(v)}getIndent(v,D){let F=x(v.state),$=F.resolve(D);for(;$&&$.type!=this.topNode;)$=$.parent;if(!$)return null;let j,{overrideIndentation:G}=v.options;G&&(j=rn.get(v.state),j!=null&&j<D-1e4&&(j=void 0));let tt=pi(this,F,0,$.from,j??D),et,ct;if(tt?(ct=tt.state,et=tt.pos+1):(ct=this.streamParser.startState(v.unit),et=0),D-et>1e4)return null;for(;et<D;){let Lt=v.state.doc.lineAt(et),Pe=Math.min(D,Lt.to);if(Lt.length){let xe=G?G(Lt.from):-1,ri=new It(Lt.text,v.state.tabSize,v.unit,xe<0?void 0:xe);for(;ri.pos<Pe-Lt.from;)ds(this.streamParser.token,ri,ct)}else this.streamParser.blankLine(ct,v.unit);if(Pe==D)break;et=Lt.to+1}let yt=v.lineAt(D);return G&&j==null&&rn.set(v.state,yt.from),this.streamParser.indent(ct,/^\s*(.*)/.exec(yt.text)[1],v)}get allowsNesting(){return!1}}function pi(R,v,D,F,$){let j=D>=F&&D+v.length<=$&&v.prop(R.stateAfter);if(j)return{state:R.streamParser.copyState(j),pos:D+v.length};for(let G=v.children.length-1;G>=0;G--){let tt=v.children[G],et=D+v.positions[G],ct=tt instanceof n.Tree&&et<$&&pi(R,tt,et,F,$);if(ct)return ct}return null}function ho(R,v,D,F,$){if($&&D<=0&&F>=v.length)return v;!$&&v.type==R.topNode&&($=!0);for(let j=v.children.length-1;j>=0;j--){let G=v.positions[j],tt=v.children[j],et;if(G<F&&tt instanceof n.Tree){if(!(et=ho(R,tt,D-G,F-G,$)))break;return $?new n.Tree(v.type,v.children.slice(0,j).concat(et),v.positions.slice(0,j+1),G+et.length):et}}return null}function Gn(R,v,D,F){for(let $ of v){let j=$.from+($.openStart?25:0),G=$.to-($.openEnd?25:0),tt=j<=D&&G>D&&pi(R,$.tree,0-$.offset,D,G),et;if(tt&&(et=ho(R,$.tree,D+$.offset,tt.pos+$.offset,!1)))return{state:tt.state,tree:et}}return{state:R.streamParser.startState(F?ne(F):4),tree:n.Tree.empty}}class pe{constructor(v,D,F,$){this.lang=v,this.input=D,this.fragments=F,this.ranges=$,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=$[$.length-1].to;let j=ot.get(),G=$[0].from,{state:tt,tree:et}=Gn(v,F,G,j==null?void 0:j.state);this.state=tt,this.parsedPos=this.chunkStart=G+et.length;for(let ct=0;ct<et.children.length;ct++)this.chunks.push(et.children[ct]),this.chunkPos.push(et.positions[ct]);j&&this.parsedPos<j.viewport.from-1e5&&(this.state=this.lang.streamParser.startState(ne(j.state)),j.skipUntilInView(this.parsedPos,j.viewport.from),this.parsedPos=j.viewport.from),this.moveRangeIndex()}advance(){let v=ot.get(),D=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),F=Math.min(D,this.chunkStart+2048);for(v&&(F=Math.min(F,v.viewport.to));this.parsedPos<F;)this.parseLine(v);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=D?this.finish():v&&this.parsedPos>=v.viewport.to?(v.skipUntilInView(this.parsedPos,D),this.finish()):null}stopAt(v){this.stoppedAt=v}lineAfter(v){let D=this.input.chunk(v);if(this.input.lineChunks)D==`
14
- `&&(D="");else{let F=D.indexOf(`
15
- `);F>-1&&(D=D.slice(0,F))}return v+D.length<=this.to?D:D.slice(0,this.to-v)}nextLine(){let v=this.parsedPos,D=this.lineAfter(v),F=v+D.length;for(let $=this.rangeIndex;;){let j=this.ranges[$].to;if(j>=F||(D=D.slice(0,j-(F-D.length)),$++,$==this.ranges.length))break;let G=this.ranges[$].from,tt=this.lineAfter(G);D+=tt,F=G+tt.length}return{line:D,end:F}}skipGapsTo(v,D,F){for(;;){let $=this.ranges[this.rangeIndex].to,j=v+D;if(F>0?$>j:$>=j)break;let G=this.ranges[++this.rangeIndex].from;D+=G-$}return D}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(v,D,F,$,j){if(this.ranges.length>1){j=this.skipGapsTo(D,j,1),D+=j;let G=this.chunk.length;j=this.skipGapsTo(F,j,-1),F+=j,$+=this.chunk.length-G}return this.chunk.push(v,D,F,$),j}parseLine(v){let{line:D,end:F}=this.nextLine(),$=0,{streamParser:j}=this.lang,G=new It(D,v?v.state.tabSize:4,v?ne(v.state):2);if(G.eol())j.blankLine(this.state,G.indentUnit);else for(;!G.eol();){let tt=ds(j.token,G,this.state);if(tt&&($=this.emitToken(this.lang.tokenTable.resolve(tt),this.parsedPos+G.start,this.parsedPos+G.pos,4,$)),G.start>1e4)break}this.parsedPos=F,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let v=n.Tree.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Yn,topID:0,maxBufferLength:2048,reused:this.chunkReused});v=new n.Tree(v.type,v.children,v.positions,v.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(v),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new n.Tree(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function ds(R,v,D){v.start=v.pos;for(let F=0;F<10;F++){let $=R(v,D);if(v.pos>v.start)return $}throw new Error("Stream parser failed to advance stream.")}const us=Object.create(null),Vi=[n.NodeType.none],Yn=new n.NodeSet(Vi),nr=[],ps=Object.create(null),sr=Object.create(null);for(let[R,v]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"]])sr[R]=kn(us,v);class rr{constructor(v){this.extra=v,this.table=Object.assign(Object.create(null),sr)}resolve(v){return v?this.table[v]||(this.table[v]=kn(this.extra,v)):0}}const co=new rr(us);function gs(R,v){nr.indexOf(R)>-1||(nr.push(R),console.warn(v))}function kn(R,v){let D=[];for(let tt of v.split(" ")){let et=[];for(let ct of tt.split(".")){let yt=R[ct]||i.tags[ct];yt?typeof yt=="function"?et.length?et=et.map(yt):gs(ct,`Modifier ${ct} used at start of tag`):et.length?gs(ct,`Tag ${ct} used as modifier`):et=Array.isArray(yt)?yt:[yt]:gs(ct,`Unknown highlighting tag ${ct}`)}for(let ct of et)D.push(ct)}if(!D.length)return 0;let F=v.replace(/ /g,"_"),$=F+" "+D.map(tt=>tt.id),j=ps[$];if(j)return j.id;let G=ps[$]=n.NodeType.define({id:Vi.length,name:F,props:[i.styleTags({[F]:D})]});return Vi.push(G),G.id}function He(R){let v=n.NodeType.define({id:Vi.length,name:"Document",props:[l.add(()=>R)],top:!0});return Vi.push(v),v}function Cn(R){return R.length<=4096&&/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/.test(R)}function or(R){for(let v=R.iter();!v.next().done;)if(Cn(v.value))return!0;return!1}function ua(R){let v=!1;return R.iterChanges((D,F,$,j,G)=>{!v&&or(G)&&(v=!0)}),v}const ms=t.Facet.define({combine:R=>R.some(v=>v)});function fo(R={}){let v=[pa];return R.alwaysIsolate&&v.push(ms.of(!0)),v}const pa=e.ViewPlugin.fromClass(class{constructor(R){this.always=R.state.facet(ms)||R.textDirection!=e.Direction.LTR||R.state.facet(e.EditorView.perLineTextDirection),this.hasRTL=!this.always&&or(R.state.doc),this.tree=x(R.state),this.decorations=this.always||this.hasRTL?uo(R,this.tree,this.always):e.Decoration.none}update(R){let v=R.state.facet(ms)||R.view.textDirection!=e.Direction.LTR||R.state.facet(e.EditorView.perLineTextDirection);if(!v&&!this.hasRTL&&ua(R.changes)&&(this.hasRTL=!0),!v&&!this.hasRTL)return;let D=x(R.state);(v!=this.always||D!=this.tree||R.docChanged||R.viewportChanged)&&(this.tree=D,this.always=v,this.decorations=uo(R.view,D,v))}},{provide:R=>{function v(D){var F,$;return($=(F=D.plugin(R))===null||F===void 0?void 0:F.decorations)!==null&&$!==void 0?$:e.Decoration.none}return[e.EditorView.outerDecorations.of(v),t.Prec.lowest(e.EditorView.bidiIsolatedRanges.of(v))]}});function uo(R,v,D){let F=new t.RangeSetBuilder,$=R.visibleRanges;D||($=ga($,R.state.doc));for(let{from:j,to:G}of $)v.iterate({enter:tt=>{let et=tt.type.prop(n.NodeProp.isolate);et&&F.add(tt.from,tt.to,ma[et])},from:j,to:G});return F.finish()}function ga(R,v){let D=v.iter(),F=0,$=[],j=null;for(let{from:G,to:tt}of R)if(!(j&&j.to>G&&(G=j.to,G>=tt)))for(F+D.value.length<G&&(D.next(G-(F+D.value.length)),F=G);;){let et=F,ct=F+D.value.length;if(!D.lineBreak&&Cn(D.value)&&(j&&j.to>et-10?j.to=Math.min(tt,ct):$.push(j={from:et,to:Math.min(tt,ct)})),ct>=tt)break;F=ct,D.next()}return $}const ma={rtl:e.Decoration.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"rtl"},bidiIsolate:e.Direction.RTL}),ltr:e.Decoration.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"ltr"},bidiIsolate:e.Direction.LTR}),auto:e.Decoration.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"auto"},bidiIsolate:null})};return xt.DocInput=W,xt.HighlightStyle=ui,xt.IndentContext=Zt,xt.LRLanguage=y,xt.Language=g,xt.LanguageDescription=ae,xt.LanguageSupport=le,xt.ParseContext=ot,xt.StreamLanguage=Ie,xt.StringStream=It,xt.TreeIndentContext=ti,xt.bidiIsolates=fo,xt.bracketMatching=N,xt.bracketMatchingHandle=q,xt.codeFolding=ki,xt.continuedIndent=as,xt.defaultHighlightStyle=wn,xt.defineLanguageFacet=h,xt.delimitedIndent=Ni,xt.ensureSyntaxTree=T,xt.flatIndent=gn,xt.foldAll=Vt,xt.foldCode=_t,xt.foldEffect=Oe,xt.foldGutter=ir,xt.foldInside=Ke,xt.foldKeymap=cs,xt.foldNodeProp=ye,xt.foldService=jn,xt.foldState=Ht,xt.foldable=De,xt.foldedRanges=ce,xt.forceParsing=I,xt.getIndentUnit=ne,xt.getIndentation=Bt,xt.highlightingFor=_n,xt.indentNodeProp=se,xt.indentOnInput=ft,xt.indentRange=vt,xt.indentService=zt,xt.indentString=Rt,xt.indentUnit=Ot,xt.language=Tt,xt.languageDataProp=l,xt.matchBrackets=lt,xt.sublanguageProp=c,xt.syntaxHighlighting=we,xt.syntaxParserRunning=z,xt.syntaxTree=x,xt.syntaxTreeAvailable=P,xt.toggleFold=Ge,xt.unfoldAll=Fe,xt.unfoldCode=je,xt.unfoldEffect=ii,xt}var Gu;function EC(){if(Gu)return vs;Gu=1,Object.defineProperty(vs,"__esModule",{value:!0});var n=VS(),t=OC();const e=()=>l=>{try{JSON.parse(l.state.doc.toString())}catch(h){if(!(h instanceof SyntaxError))throw h;const c=i(h,l.state.doc);return[{from:c,message:h.message,severity:"error",to:c}]}return[]};function i(l,h){let c;return(c=l.message.match(/at position (\d+)/))?Math.min(+c[1],h.length):(c=l.message.match(/at line (\d+) column (\d+)/))?Math.min(h.line(+c[1]).from+ +c[2]-1,h.length):0}const s=t.LRLanguage.define({name:"json",parser:n.parser.configure({props:[t.indentNodeProp.add({Object:t.continuedIndent({except:/^\s*\}/}),Array:t.continuedIndent({except:/^\s*\]/})}),t.foldNodeProp.add({"Object Array":t.foldInside})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function r(){return new t.LanguageSupport(s)}return vs.json=r,vs.jsonLanguage=s,vs.jsonParseLinter=e,vs}var tE=EC();class PC{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class Jn{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let s=t,r=i.facet(_i).markerFilter;r&&(s=r(s,i));let l=kt.set(s.map(h=>h.from==h.to||h.from==h.to-1&&i.doc.lineAt(h.from).to==h.from?kt.widget({widget:new WC(h),diagnostic:h}).range(h.from):kt.mark({attributes:{class:"cm-lintRange cm-lintRange-"+h.severity+(h.markClass?" "+h.markClass:"")},diagnostic:h}).range(h.from,h.to)),!0);return new Jn(l,e,Ws(l))}}function Ws(n,t=null,e=0){let i=null;return n.between(e,1e9,(s,r,{spec:l})=>{if(!(t&&l.diagnostic!=t))return i=new PC(s,r,l.diagnostic),!1}),i}function RC(n,t){let e=t.pos,i=t.end||e,s=n.state.facet(_i).hideOn(n,e,i);if(s!=null)return s;let r=n.startState.doc.lineAt(t.pos);return!!(n.effects.some(l=>l.is(rf))||n.changes.touchesRange(r.from,Math.max(r.to,i)))}function H0(n,t){return n.field(fi,!1)?t:t.concat(A.StateEffect.appendConfig.of(z0))}function BC(n,t){return{effects:H0(n,[rf.of(t)])}}const rf=A.StateEffect.define(),of=A.StateEffect.define(),V0=A.StateEffect.define(),fi=A.StateField.define({create(){return new Jn(kt.none,null,null)},update(n,t){if(t.docChanged&&n.diagnostics.size){let e=n.diagnostics.map(t.changes),i=null,s=n.panel;if(n.selected){let r=t.changes.mapPos(n.selected.from,1);i=Ws(e,n.selected.diagnostic,r)||Ws(e,null,r)}!e.size&&s&&t.state.facet(_i).autoPanel&&(s=null),n=new Jn(e,s,i)}for(let e of t.effects)if(e.is(rf)){let i=t.state.facet(_i).autoPanel?e.value.length?qr.open:null:n.panel;n=Jn.init(e.value,i,t.state)}else e.is(of)?n=new Jn(n.diagnostics,e.value?qr.open:null,n.selected):e.is(V0)&&(n=new Jn(n.diagnostics,n.panel,e.value));return n},provide:n=>[ic.from(n,t=>t.panel),mt.decorations.from(n,t=>t.diagnostics)]}),LC=kt.mark({class:"cm-lintRange cm-lintRange-active"});function NC(n,t,e){let{diagnostics:i}=n.state.field(fi),s=[],r=2e8,l=0;i.between(t-(e<0?1:0),t+(e>0?1:0),(c,g,{spec:p})=>{t>=c&&t<=g&&(c==g||(t>c||e>0)&&(t<g||e<0))&&(s.push(p.diagnostic),r=Math.min(c,r),l=Math.max(g,l))});let h=n.state.facet(_i).tooltipFilter;return h&&(s=h(s,n.state)),s.length?{pos:r,end:l,above:n.state.doc.lineAt(r).to<l,create(){return{dom:FC(n,s)}}}:null}function FC(n,t){return Ut("ul",{class:"cm-tooltip-lint"},t.map(e=>W0(n,e,!1)))}const IC=n=>{let t=n.state.field(fi,!1);(!t||!t.panel)&&n.dispatch({effects:H0(n.state,[of.of(!0)])});let e=mv(n,qr.open);return e&&e.dom.querySelector(".cm-panel-lint ul").focus(),!0},Yu=n=>{let t=n.state.field(fi,!1);return!t||!t.panel?!1:(n.dispatch({effects:of.of(!1)}),!0)},HC=n=>{let t=n.state.field(fi,!1);if(!t)return!1;let e=n.state.selection.main,i=t.diagnostics.iter(e.to+1);return!i.value&&(i=t.diagnostics.iter(0),!i.value||i.from==e.from&&i.to==e.to)?!1:(n.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),!0)},VC=[{key:"Mod-Shift-m",run:IC,preventDefault:!0},{key:"F8",run:HC}],$C=Te.fromClass(class{constructor(n){this.view=n,this.timeout=-1,this.set=!0;let{delay:t}=n.state.facet(_i);this.lintTime=Date.now()+t,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,t)}run(){clearTimeout(this.timeout);let n=Date.now();if(n<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-n);else{this.set=!1;let{state:t}=this.view,{sources:e}=t.facet(_i);e.length&&Promise.all(e.map(i=>Promise.resolve(i(this.view)))).then(i=>{let s=i.reduce((r,l)=>r.concat(l));this.view.state.doc==t.doc&&this.view.dispatch(BC(this.view.state,s))},i=>{$e(this.view.state,i)})}}update(n){let t=n.state.facet(_i);(n.docChanged||t!=n.startState.facet(_i)||t.needsRefresh&&t.needsRefresh(n))&&(this.lintTime=Date.now()+t.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,t.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}}),_i=A.Facet.define({combine(n){return Object.assign({sources:n.map(t=>t.source).filter(t=>t!=null)},A.combineConfig(n.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e}))}});function eE(n,t={}){return[_i.of({source:n,config:t}),$C,z0]}function $0(n){let t=[];if(n)t:for(let{name:e}of n){for(let i=0;i<e.length;i++){let s=e[i];if(/[a-zA-Z]/.test(s)&&!t.some(r=>r.toLowerCase()==s.toLowerCase())){t.push(s);continue t}}t.push("")}return t}function W0(n,t,e){var i;let s=e?$0(t.actions):[];return Ut("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},Ut("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(n):t.message),(i=t.actions)===null||i===void 0?void 0:i.map((r,l)=>{let h=!1,c=x=>{if(x.preventDefault(),h)return;h=!0;let T=Ws(n.state.field(fi).diagnostics,t);T&&r.apply(n,T.from,T.to)},{name:g}=r,p=s[l]?g.indexOf(s[l]):-1,y=p<0?g:[g.slice(0,p),Ut("u",g.slice(p,p+1)),g.slice(p+1)];return Ut("button",{type:"button",class:"cm-diagnosticAction",onclick:c,onmousedown:c,"aria-label":` Action: ${g}${p<0?"":` (access key "${s[l]})"`}.`},y)}),t.source&&Ut("div",{class:"cm-diagnosticSource"},t.source))}class WC extends Bi{constructor(t){super(),this.diagnostic=t}eq(t){return t.diagnostic==this.diagnostic}toDOM(){return Ut("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class Uu{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=W0(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class qr{constructor(t){this.view=t,this.items=[];let e=s=>{if(s.keyCode==27)Yu(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],l=$0(r.actions);for(let h=0;h<l.length;h++)if(l[h].toUpperCase().charCodeAt(0)==s.keyCode){let c=Ws(this.view.state.field(fi).diagnostics,r);c&&r.actions[h].apply(t,c.from,c.to)}}else return;s.preventDefault()},i=s=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(s.target)&&this.moveSelection(r)};this.list=Ut("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e,onclick:i}),this.dom=Ut("div",{class:"cm-panel-lint"},this.list,Ut("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Yu(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(fi).selected;if(!t)return-1;for(let e=0;e<this.items.length;e++)if(this.items[e].diagnostic==t.diagnostic)return e;return-1}update(){let{diagnostics:t,selected:e}=this.view.state.field(fi),i=0,s=!1,r=null;for(t.between(0,this.view.state.doc.length,(l,h,{spec:c})=>{let g=-1,p;for(let y=i;y<this.items.length;y++)if(this.items[y].diagnostic==c.diagnostic){g=y;break}g<0?(p=new Uu(this.view,c.diagnostic),this.items.splice(i,0,p),s=!0):(p=this.items[g],g>i&&(this.items.splice(i,g-i),s=!0)),e&&p.diagnostic==e.diagnostic?p.dom.hasAttribute("aria-selected")||(p.dom.setAttribute("aria-selected","true"),r=p):p.dom.hasAttribute("aria-selected")&&p.dom.removeAttribute("aria-selected"),i++});i<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 Uu(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:h})=>{let c=h.height/this.list.offsetHeight;l.top<h.top?this.list.scrollTop-=(h.top-l.top)/c:l.bottom>h.bottom&&(this.list.scrollTop+=(l.bottom-h.bottom)/c)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let t=this.list.firstChild;function e(){let i=t;t=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=this.view.state.field(fi),i=Ws(e.diagnostics,this.items[t].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:V0.of(i)})}static open(t){return new qr(t)}}function zC(n,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(n)}</svg>')`}function Yo(n){return zC(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${n}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const qC=mt.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:Yo("#d11")},".cm-lintRange-warning":{backgroundImage:Yo("orange")},".cm-lintRange-info":{backgroundImage:Yo("#999")},".cm-lintRange-hint":{backgroundImage:Yo("#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}}}),z0=[fi,mt.decorations.compute([fi],n=>{let{selected:t,panel:e}=n.field(fi);return!t||!e||t.from==t.to?kt.none:kt.set([LC.range(t.from,t.to)])}),pv(NC,{hideOn:RC}),qC];var q0=n=>{var{theme:t,settings:e={},styles:i=[]}=n,s={".cm-gutters":{}},r={};e.background&&(r.backgroundColor=e.background),e.backgroundImage&&(r.backgroundImage=e.backgroundImage),e.foreground&&(r.color=e.foreground),e.fontSize&&(r.fontSize=e.fontSize),(e.background||e.foreground)&&(s["&"]=r),e.fontFamily&&(s["&.cm-editor .cm-scroller"]={fontFamily:e.fontFamily}),e.gutterBackground&&(s[".cm-gutters"].backgroundColor=e.gutterBackground),e.gutterForeground&&(s[".cm-gutters"].color=e.gutterForeground),e.gutterBorder&&(s[".cm-gutters"].borderRightColor=e.gutterBorder),e.caret&&(s[".cm-content"]={caretColor:e.caret},s[".cm-cursor, .cm-dropCursor"]={borderLeftColor:e.caret});var l={};e.gutterActiveForeground&&(l.color=e.gutterActiveForeground),e.lineHighlight&&(s[".cm-activeLine"]={backgroundColor:e.lineHighlight},l.backgroundColor=e.lineHighlight),s[".cm-activeLineGutter"]=l,e.selection&&(s["&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection"]={background:e.selection+" !important"}),e.selectionMatch&&(s["& .cm-selectionMatch"]={backgroundColor:e.selectionMatch});var h=mt.theme(s,{dark:t==="dark"}),c=tf.define(i),g=[h,i0(c)];return g},KC={background:"#fff",foreground:"#24292e",selection:"#BBDFFF",selectionMatch:"#BBDFFF",gutterBackground:"#fff",gutterForeground:"#6e7781"},jC=[{tag:[J.standard(J.tagName),J.tagName],color:"#116329"},{tag:[J.comment,J.bracket],color:"#6a737d"},{tag:[J.className,J.propertyName],color:"#6f42c1"},{tag:[J.variableName,J.attributeName,J.number,J.operator],color:"#005cc5"},{tag:[J.keyword,J.typeName,J.typeOperator,J.typeName],color:"#d73a49"},{tag:[J.string,J.meta,J.regexp],color:"#032f62"},{tag:[J.name,J.quote],color:"#22863a"},{tag:[J.heading,J.strong],color:"#24292e",fontWeight:"bold"},{tag:[J.emphasis],color:"#24292e",fontStyle:"italic"},{tag:[J.deleted],color:"#b31d28",backgroundColor:"ffeef0"},{tag:[J.atom,J.bool,J.special(J.variableName)],color:"#e36209"},{tag:[J.url,J.escape,J.regexp,J.link],color:"#032f62"},{tag:J.link,textDecoration:"underline"},{tag:J.strikethrough,textDecoration:"line-through"},{tag:J.invalid,color:"#cb2431"}],_C=n=>{var{theme:t="light",settings:e={},styles:i=[]}={};return q0({theme:t,settings:Hc({},KC,e),styles:[...jC,...i]})},iE=_C(),GC={background:"#0d1117",foreground:"#c9d1d9",caret:"#c9d1d9",selection:"#003d73",selectionMatch:"#003d73",lineHighlight:"#36334280"},YC=[{tag:[J.standard(J.tagName),J.tagName],color:"#7ee787"},{tag:[J.comment,J.bracket],color:"#8b949e"},{tag:[J.className,J.propertyName],color:"#d2a8ff"},{tag:[J.variableName,J.attributeName,J.number,J.operator],color:"#79c0ff"},{tag:[J.keyword,J.typeName,J.typeOperator,J.typeName],color:"#ff7b72"},{tag:[J.string,J.meta,J.regexp],color:"#a5d6ff"},{tag:[J.name,J.quote],color:"#7ee787"},{tag:[J.heading,J.strong],color:"#d2a8ff",fontWeight:"bold"},{tag:[J.emphasis],color:"#d2a8ff",fontStyle:"italic"},{tag:[J.deleted],color:"#ffdcd7",backgroundColor:"ffeef0"},{tag:[J.atom,J.bool,J.special(J.variableName)],color:"#ffab70"},{tag:J.link,textDecoration:"underline"},{tag:J.strikethrough,textDecoration:"line-through"},{tag:J.invalid,color:"#f97583"}],UC=n=>{var{theme:t="dark",settings:e={},styles:i=[]}={};return q0({theme:t,settings:Hc({},GC,e),styles:[...YC,...i]})},nE=UC();function Kr(n){let t;return n.nodeType==11?t=n.getSelection?n:n.ownerDocument:t=n,t.getSelection()}function pc(n,t){return t?n==t||n.contains(t.nodeType!=1?t.parentNode:t):!1}function wl(n,t){if(!t.anchorNode)return!1;try{return pc(n,t.anchorNode)}catch{return!1}}function jr(n){return n.nodeType==3?os(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Fr(n,t,e,i){return e?Xu(n,t,e,i,-1)||Xu(n,t,e,i,1):!1}function rs(n){for(var t=0;;t++)if(n=n.previousSibling,!n)return t}function Ll(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function Xu(n,t,e,i,s){for(;;){if(n==e&&t==i)return!0;if(t==(s<0?0:Xi(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;t=rs(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[t+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;t=s<0?Xi(n):0}else return!1}}function Xi(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function la(n,t){let e=t?n.left:n.right;return{left:e,right:e,top:n.top,bottom:n.bottom}}function XC(n){let t=n.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function K0(n,t){let e=t.width/n.offsetWidth,i=t.height/n.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-n.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-n.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function JC(n,t,e,i,s,r,l,h){let c=n.ownerDocument,g=c.defaultView||window;for(let p=n,y=!1;p&&!y;)if(p.nodeType==1){let x,T=p==c.body,P=1,I=1;if(T)x=XC(g);else{if(/^(fixed|sticky)$/.test(getComputedStyle(p).position)&&(y=!0),p.scrollHeight<=p.clientHeight&&p.scrollWidth<=p.clientWidth){p=p.assignedSlot||p.parentNode;continue}let U=p.getBoundingClientRect();({scaleX:P,scaleY:I}=K0(p,U)),x={left:U.left,right:U.left+p.clientWidth*P,top:U.top,bottom:U.top+p.clientHeight*I}}let z=0,W=0;if(s=="nearest")t.top<x.top?(W=t.top-(x.top+l),e>0&&t.bottom>x.bottom+W&&(W=t.bottom-x.bottom+l)):t.bottom>x.bottom&&(W=t.bottom-x.bottom+l,e<0&&t.top-W<x.top&&(W=t.top-(x.top+l)));else{let U=t.bottom-t.top,ot=x.bottom-x.top;W=(s=="center"&&U<=ot?t.top+U/2-ot/2:s=="start"||s=="center"&&e<0?t.top-l:t.bottom-ot+l)-x.top}if(i=="nearest"?t.left<x.left?(z=t.left-(x.left+r),e>0&&t.right>x.right+z&&(z=t.right-x.right+r)):t.right>x.right&&(z=t.right-x.right+r,e<0&&t.left<x.left+z&&(z=t.left-(x.left+r))):z=(i=="center"?t.left+(t.right-t.left)/2-(x.right-x.left)/2:i=="start"==h?t.left-r:t.right-(x.right-x.left)+r)-x.left,z||W)if(T)g.scrollBy(z,W);else{let U=0,ot=0;if(W){let Q=p.scrollTop;p.scrollTop+=W/I,ot=(p.scrollTop-Q)*I}if(z){let Q=p.scrollLeft;p.scrollLeft+=z/P,U=(p.scrollLeft-Q)*P}t={left:t.left-U,top:t.top-ot,right:t.right-U,bottom:t.bottom-ot},U&&Math.abs(U-z)<1&&(i="nearest"),ot&&Math.abs(ot-W)<1&&(s="nearest")}if(T)break;(t.top<x.top||t.bottom>x.bottom||t.left<x.left||t.right>x.right)&&(t={left:Math.max(t.left,x.left),right:Math.min(t.right,x.right),top:Math.max(t.top,x.top),bottom:Math.min(t.bottom,x.bottom)}),p=p.assignedSlot||p.parentNode}else if(p.nodeType==11)p=p.host;else break}function QC(n){let t=n.ownerDocument,e,i;for(let s=n.parentNode;s&&!(s==t.body||e&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!e&&s.scrollWidth>s.clientWidth&&(e=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:e,y:i}}class ZC{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?Xi(e):0),i,Math.min(t.focusOffset,i?Xi(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let ks=null;function j0(n){if(n.setActive)return n.setActive();if(ks)return n.focus(ks);let t=[];for(let e=n;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(n.focus(ks==null?{get preventScroll(){return ks={preventScroll:!0},!0}}:void 0),!ks){ks=!1;for(let e=0;e<t.length;){let i=t[e++],s=t[e++],r=t[e++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Ju;function os(n,t,e=t){let i=Ju||(Ju=document.createRange());return i.setEnd(n,e),i.setStart(n,t),i}function Rs(n,t,e,i){let s={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,n.dispatchEvent(r);let l=new KeyboardEvent("keyup",s);return l.synthetic=!0,n.dispatchEvent(l),r.defaultPrevented||l.defaultPrevented}function tM(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function _0(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}function eM(n,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,Xi(e));;)if(i){if(e.nodeType!=1)return!1;let s=e.childNodes[i-1];s.contentEditable=="false"?i--:(e=s,i=Xi(e))}else{if(e==n)return!0;i=rs(e),e=e.parentNode}}function G0(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function Y0(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=Xi(e)}else if(e.parentNode&&!Ll(e))i=rs(e),e=e.parentNode;else return null}}function U0(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!Ll(e))i=rs(e)+1,e=e.parentNode;else return null}}class Be{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new Be(t.parentNode,rs(t),e)}static after(t,e){return new Be(t.parentNode,rs(t)+1,e)}}const lf=[];class jt{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(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(this.flags&2){let i=this.dom,s=null,r;for(let l of this.children){if(l.flags&7){if(!l.dom&&(r=s?s.nextSibling:i.firstChild)){let h=jt.get(r);(!h||!h.parent&&h.canReuseDOM(l))&&l.reuseDOM(r)}l.sync(t,e),l.flags&=-8}if(r=s?s.nextSibling:i.firstChild,e&&!e.written&&e.node==i&&r!=l.dom&&(e.written=!0),l.dom.parentNode==i)for(;r&&r!=l.dom;)r=Qu(r);else i.insertBefore(l.dom,r);s=l.dom}for(r=s?s.nextSibling:i.firstChild,r&&e&&e.node==i&&(e.written=!0);r;)r=Qu(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let s=Xi(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?s=-1:s=1),t=r}s<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!jt.get(i);)i=i.nextSibling;if(!i)return this.length;for(let s=0,r=0;;s++){let l=this.children[s];if(l.dom==i)return r;r+=l.length+l.breakAfter}}domBoundsAround(t,e,i=0){let s=-1,r=-1,l=-1,h=-1;for(let c=0,g=i,p=i;c<this.children.length;c++){let y=this.children[c],x=g+y.length;if(g<t&&x>e)return y.domBoundsAround(t,e,g);if(x>=t&&s==-1&&(s=c,r=g),g>e&&y.dom.parentNode==this.dom){l=c,h=p;break}p=x,g=x+y.breakAfter}return{from:r,to:h<0?i+this.length:h,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:l<this.children.length&&l>=0?this.children[l].dom:null}}markDirty(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),e.flags&1)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.flags&7&&this.markParentsDirty(!0))}setDOM(t){this.dom!=t&&(this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this)}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=lf){this.markDirty();for(let s=t;s<e;s++){let r=this.children[s];r.parent==this&&i.indexOf(r)<0&&r.destroy()}i.length<250?this.children.splice(t,e-t,...i):this.children=[].concat(this.children.slice(0,t),i,this.children.slice(e));for(let s=0;s<i.length;s++)i[s].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new X0(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,s,r,l){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!((this.flags|t.flags)&8)}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}}jt.prototype.breakAfter=0;function Qu(n){let t=n.nextSibling;return n.parentNode.removeChild(n),t}class X0{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function J0(n,t,e,i,s,r,l,h,c){let{children:g}=n,p=g.length?g[t]:null,y=r.length?r[r.length-1]:null,x=y?y.breakAfter:l;if(!(t==i&&p&&!l&&!x&&r.length<2&&p.merge(e,s,r.length?y:null,e==0,h,c))){if(i<g.length){let T=g[i];T&&(s<T.length||T.breakAfter&&(y!=null&&y.breakAfter))?(t==i&&(T=T.split(s),s=0),!x&&y&&T.merge(0,s,y,!0,0,c)?r[r.length-1]=T:((s||T.children.length&&!T.children[0].length)&&T.merge(0,s,null,!1,0,c),r.push(T))):T!=null&&T.breakAfter&&(y?y.breakAfter=1:l=1),i++}for(p&&(p.breakAfter=l,e>0&&(!l&&r.length&&p.merge(e,p.length,r[0],!1,h,0)?p.breakAfter=r.shift().breakAfter:(e<p.length||p.children.length&&p.children[p.children.length-1].length==0)&&p.merge(e,p.length,null,!1,h,0),t++));t<i&&r.length;)if(g[i-1].become(r[r.length-1]))i--,r.pop(),c=r.length?0:h;else if(g[t].become(r[0]))t++,r.shift(),h=r.length?0:c;else break;!r.length&&t&&i<g.length&&!g[t-1].breakAfter&&g[i].merge(0,0,g[t-1],!1,h,c)&&t--,(t<i||r.length)&&n.replaceChildren(t,i,r)}}function Q0(n,t,e,i,s,r){let l=n.childCursor(),{i:h,off:c}=l.findPos(e,1),{i:g,off:p}=l.findPos(t,-1),y=t-e;for(let x of i)y+=x.length;n.length+=y,J0(n,g,p,h,c,i,0,s,r)}let Ue=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},gc=typeof document<"u"?document:{documentElement:{style:{}}};const mc=/Edge\/(\d+)/.exec(Ue.userAgent),Z0=/MSIE \d/.test(Ue.userAgent),bc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ue.userAgent),aa=!!(Z0||bc||mc),Zu=!aa&&/gecko\/(\d+)/i.test(Ue.userAgent),lh=!aa&&/Chrome\/(\d+)/.exec(Ue.userAgent),tp="webkitFontSmoothing"in gc.documentElement.style,tb=!aa&&/Apple Computer/.test(Ue.vendor),ep=tb&&(/Mobile\/\w+/.test(Ue.userAgent)||Ue.maxTouchPoints>2);var dt={mac:ep||/Mac/.test(Ue.platform),windows:/Win/.test(Ue.platform),linux:/Linux|X11/.test(Ue.platform),ie:aa,ie_version:Z0?gc.documentMode||6:bc?+bc[1]:mc?+mc[1]:0,gecko:Zu,gecko_version:Zu?+(/Firefox\/(\d+)/.exec(Ue.userAgent)||[0,0])[1]:0,chrome:!!lh,chrome_version:lh?+lh[1]:0,ios:ep,android:/Android\b/.test(Ue.userAgent),webkit:tp,safari:tb,webkit_version:tp?+(/\bAppleWebKit\/(\d+)/.exec(Ue.userAgent)||[0,0])[1]:0,tabSize:gc.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const iM=256;class Pi extends jt{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return this.flags&8||i&&(!(i instanceof Pi)||this.length-(e-t)+i.length>iM||i.flags&8)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Pi(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=this.flags&8,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new Be(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return nM(this.dom,t,e)}}class pn extends jt{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let s of e)s.setParent(this)}setAttrs(t){if(_0(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!((this.flags|t.flags)&8)}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,s,r,l){return i&&(!(i instanceof pn&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&l<=0)?!1:(Q0(this,t,e,i?i.children.slice():[],r-1,l-1),this.markDirty(),!0)}split(t){let e=[],i=0,s=-1,r=0;for(let h of this.children){let c=i+h.length;c>t&&e.push(i<t?h.split(t-i):h),s<0&&i>=t&&(s=r),i=c,r++}let l=this.length-t;return this.length=t,s>-1&&(this.children.length=s,this.markDirty()),new pn(this.mark,e,l)}domAtPos(t){return eb(this,t)}coordsAt(t,e){return nb(this,t,e)}}function nM(n,t,e){let i=n.nodeValue.length;t>i&&(t=i);let s=t,r=t,l=0;t==0&&e<0||t==i&&e>=0?dt.chrome||dt.gecko||(t?(s--,l=1):r<i&&(r++,l=-1)):e<0?s--:r<i&&r++;let h=os(n,s,r).getClientRects();if(!h.length)return null;let c=h[(l?l<0:e>=0)?0:h.length-1];return dt.safari&&!l&&c.width==0&&(c=Array.prototype.find.call(h,g=>g.width)||c),l?la(c,l<0):c||null}class Qn extends jt{static create(t,e,i){return new Qn(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=Qn.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,s,r,l){return i&&(!(i instanceof Qn)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&l<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof Qn&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.compare(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return A.Text.empty;let t=this;for(;t.parent;)t=t.parent;let{view:e}=t,i=e&&e.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):A.Text.empty}domAtPos(t){return(this.length?t==0:this.side>0)?Be.before(this.dom):Be.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let l=this.side?this.side<0:t>0;for(let h=l?s.length-1:0;r=s[h],!(t>0?h==0:h==s.length-1||r.top<r.bottom);h+=l?-1:1);return la(r,!l)}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 zs extends jt{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof zs&&t.side==this.side}split(){return new zs(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?Be.before(this.dom):Be.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return A.Text.empty}get isHidden(){return!0}}Pi.prototype.children=Qn.prototype.children=zs.prototype.children=lf;function eb(n,t){let e=n.dom,{children:i}=n,s=0;for(let r=0;s<i.length;s++){let l=i[s],h=r+l.length;if(!(h==r&&l.getSide()<=0)){if(t>r&&t<h&&l.dom.parentNode==e)return l.domAtPos(t-r);if(t<=r)break;r=h}}for(let r=s;r>0;r--){let l=i[r-1];if(l.dom.parentNode==e)return l.domAtPos(l.length)}for(let r=s;r<i.length;r++){let l=i[r];if(l.dom.parentNode==e)return l.domAtPos(0)}return new Be(e,0)}function ib(n,t,e){let i,{children:s}=n;e>0&&t instanceof pn&&s.length&&(i=s[s.length-1])instanceof pn&&i.mark.eq(t.mark)?ib(i,t.children[0],e-1):(s.push(t),t.setParent(n)),n.length+=t.length}function nb(n,t,e){let i=null,s=-1,r=null,l=-1;function h(g,p){for(let y=0,x=0;y<g.children.length&&x<=p;y++){let T=g.children[y],P=x+T.length;P>=p&&(T.children.length?h(T,p-x):(!r||r.isHidden&&e>0)&&(P>p||x==P&&T.getSide()>0)?(r=T,l=p-x):(x<p||x==P&&T.getSide()<0&&!T.isHidden)&&(i=T,s=p-x)),x=P}}h(n,t);let c=(e<0?i:r)||i||r;return c?c.coordsAt(Math.max(0,c==i?s:l),e):sM(n)}function sM(n){let t=n.dom.lastChild;if(!t)return n.dom.getBoundingClientRect();let e=jr(t);return e[e.length-1]||null}function yc(n,t){for(let e in n)e=="class"&&t.class?t.class+=" "+n.class:e=="style"&&t.style?t.style+=";"+n.style:t[e]=n[e];return t}const ip=Object.create(null);function Nl(n,t,e){if(n==t)return!0;n||(n=ip),t||(t=ip);let i=Object.keys(n),s=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=s.length-(e&&s.indexOf(e)>-1?1:0))return!1;for(let r of i)if(r!=e&&(s.indexOf(r)==-1||n[r]!==t[r]))return!1;return!0}function Sc(n,t,e){let i=!1;if(t)for(let s in t)e&&s in e||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(e)for(let s in e)t&&t[s]==e[s]||(i=!0,s=="style"?n.style.cssText=e[s]:n.setAttribute(s,e[s]));return i}function rM(n){let t=Object.create(null);for(let e=0;e<n.attributes.length;e++){let i=n.attributes[e];t[i.name]=i.value}return t}class af{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}var Ui=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(Ui||(Ui={}));class $t extends A.RangeValue{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new no(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new Wn(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:l}=sb(t,e);i=(r?e?-3e8:-1:5e8)-1,s=(l?e?2e8:1:-6e8)+1}return new Wn(t,i,s,e,t.widget||null,!0)}static line(t){return new so(t)}static set(t,e=!1){return A.RangeSet.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}$t.none=A.RangeSet.empty;class no extends $t{constructor(t){let{start:e,end:i}=sb(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof no&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((i=t.attrs)===null||i===void 0?void 0:i.class))&&Nl(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}no.prototype.point=!1;class so extends $t{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof so&&this.spec.class==t.spec.class&&Nl(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}so.prototype.mapMode=A.MapMode.TrackBefore;so.prototype.point=!0;class Wn extends $t{constructor(t,e,i,s,r,l){super(e,i,r,t),this.block=s,this.isReplace=l,this.mapMode=s?e<=0?A.MapMode.TrackBefore:A.MapMode.TrackAfter:A.MapMode.TrackDel}get type(){return this.startSide!=this.endSide?Ui.WidgetRange:this.startSide<=0?Ui.WidgetBefore:Ui.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof Wn&&oM(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}Wn.prototype.point=!0;function sb(n,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=n;return e==null&&(e=n.inclusive),i==null&&(i=n.inclusive),{start:e??t,end:i??t}}function oM(n,t){return n==t||!!(n&&t&&n.compare(t))}function xl(n,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=n?e[s]=Math.max(e[s],t):e.push(n,t)}class me extends jt{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,s,r,l){if(i){if(!(i instanceof me))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Q0(this,t,e,i?i.children.slice():[],r,l),!0}split(t){let e=new me;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:s}=this.childPos(t);s&&(e.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)e.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){Nl(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){ib(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=yc(e,this.attrs||{})),i&&(this.attrs=yc({class:i},this.attrs||{}))}domAtPos(t){return eb(this,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?this.flags&4&&(_0(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&&(Sc(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let s=this.dom.lastChild;for(;s&&jt.get(s)instanceof pn;)s=s.lastChild;if(!s||!this.length||s.nodeName!="BR"&&((i=jt.get(s))===null||i===void 0?void 0:i.isEditable)==!1&&(!dt.ios||!this.children.some(r=>r instanceof Pi))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let i of this.children){if(!(i instanceof Pi)||/[^ -~]/.test(i.text))return null;let s=jr(i.dom);if(s.length!=1)return null;t+=s[0].width,e=s[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let i=nb(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:s}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-s.lineHeight)<2&&s.textHeight<r){let l=(r-s.textHeight)/2;return{top:i.top+l,bottom:i.bottom-l,left:i.left,right:i.left}}}return i}become(t){return t instanceof me&&this.children.length==0&&t.children.length==0&&Nl(this.attrs,t.attrs)&&this.breakAfter==t.breakAfter}covers(){return!0}static find(t,e){for(let i=0,s=0;i<t.children.length;i++){let r=t.children[i],l=s+r.length;if(l>=e){if(r instanceof me)return r;if(l>e)break}s=l+r.breakAfter}return null}}class fn extends jt{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,s,r,l){return i&&(!(i instanceof fn)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&l<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?Be.before(this.dom):Be.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new fn(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return lf}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):A.Text.empty}domBoundsAround(){return null}become(t){return t instanceof fn&&t.widget.constructor==this.widget.constructor?(t.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.deco=t.deco,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);return i||(this.widget instanceof wc?null:la(this.dom.getBoundingClientRect(),this.length?t==0:e<=0))}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e==i?!1:t<0?e<0:i>0}}class wc extends af{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}class Ir{constructor(t,e,i,s){this.doc=t,this.pos=e,this.end=i,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=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof fn&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new me),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Uo(new zs(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(t&&this.content.length&&this.content[this.content.length-1]instanceof fn)&&this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:l,done:h}=this.cursor.next(this.skip);if(this.skip=0,h)throw new Error("Ran out of text content when drawing inline views");if(l){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(Uo(new Pi(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=0}}span(t,e,i,s){this.buildText(e-t,i,s),this.pos=e,this.openStart<0&&(this.openStart=s)}point(t,e,i,s,r,l){if(this.disallowBlockEffectsFor[l]&&i instanceof Wn){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let h=e-t;if(i instanceof Wn)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new fn(i.widget||qs.block,h,i));else{let c=Qn.create(i.widget||qs.inline,h,h?0:i.startSide),g=this.atCursorPos&&!c.isEditable&&r<=s.length&&(t<e||i.startSide>0),p=!c.isEditable&&(t<e||r>s.length||i.startSide<=0),y=this.getLine();this.pendingBuffer==2&&!g&&!c.isEditable&&(this.pendingBuffer=0),this.flushBuffer(s),g&&(y.append(Uo(new zs(1),s),r),r=s.length+Math.max(0,r-s.length)),y.append(Uo(c,s),r),this.atCursorPos=p,this.pendingBuffer=p?t<e||r>s.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=s.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);h&&(this.textOff+h<=this.text.length?this.textOff+=h:(this.skip+=h-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,s,r){let l=new Ir(t,e,i,r);return l.openEnd=A.RangeSet.spans(s,e,i,l),l.openStart<0&&(l.openStart=l.openEnd),l.finish(l.openEnd),l}}function Uo(n,t){for(let e of t)n=new pn(e,[n],n.length);return n}class qs extends af{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}qs.inline=new qs("span");qs.block=new qs("div");var Ae=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(Ae||(Ae={}));const ls=Ae.LTR,hf=Ae.RTL;function rb(n){let t=[];for(let e=0;e<n.length;e++)t.push(1<<+n[e]);return t}const lM=rb("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),aM=rb("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),xc=Object.create(null),Wi=[];for(let n of["()","[]","{}"]){let t=n.charCodeAt(0),e=n.charCodeAt(1);xc[t]=e,xc[e]=-t}function ob(n){return n<=247?lM[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?aM[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const hM=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Ln{get dir(){return this.level%2?hf:ls}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let r=-1;for(let l=0;l<t.length;l++){let h=t[l];if(h.from<=e&&h.to>=e){if(h.level==i)return l;(r<0||(s!=0?s<0?h.from<e:h.to>e:t[r].level>h.level))&&(r=l)}}if(r<0)throw new RangeError("Index out of range");return r}}function lb(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++){let i=n[e],s=t[e];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!lb(i.inner,s.inner))return!1}return!0}const Kt=[];function cM(n,t,e,i,s){for(let r=0;r<=i.length;r++){let l=r?i[r-1].to:t,h=r<i.length?i[r].from:e,c=r?256:s;for(let g=l,p=c,y=c;g<h;g++){let x=ob(n.charCodeAt(g));x==512?x=p:x==8&&y==4&&(x=16),Kt[g]=x==4?2:x,x&7&&(y=x),p=x}for(let g=l,p=c,y=c;g<h;g++){let x=Kt[g];if(x==128)g<h-1&&p==Kt[g+1]&&p&24?x=Kt[g]=p:Kt[g]=256;else if(x==64){let T=g+1;for(;T<h&&Kt[T]==64;)T++;let P=g&&p==8||T<e&&Kt[T]==8?y==1?1:8:256;for(let I=g;I<T;I++)Kt[I]=P;g=T-1}else x==8&&y==1&&(Kt[g]=1);p=x,x&7&&(y=x)}}}function fM(n,t,e,i,s){let r=s==1?2:1;for(let l=0,h=0,c=0;l<=i.length;l++){let g=l?i[l-1].to:t,p=l<i.length?i[l].from:e;for(let y=g,x,T,P;y<p;y++)if(T=xc[x=n.charCodeAt(y)])if(T<0){for(let I=h-3;I>=0;I-=3)if(Wi[I+1]==-T){let z=Wi[I+2],W=z&2?s:z&4?z&1?r:s:0;W&&(Kt[y]=Kt[Wi[I]]=W),h=I;break}}else{if(Wi.length==189)break;Wi[h++]=y,Wi[h++]=x,Wi[h++]=c}else if((P=Kt[y])==2||P==1){let I=P==s;c=I?0:1;for(let z=h-3;z>=0;z-=3){let W=Wi[z+2];if(W&2)break;if(I)Wi[z+2]|=2;else{if(W&4)break;Wi[z+2]|=4}}}}}function dM(n,t,e,i){for(let s=0,r=i;s<=e.length;s++){let l=s?e[s-1].to:n,h=s<e.length?e[s].from:t;for(let c=l;c<h;){let g=Kt[c];if(g==256){let p=c+1;for(;;)if(p==h){if(s==e.length)break;p=e[s++].to,h=s<e.length?e[s].from:t}else if(Kt[p]==256)p++;else break;let y=r==1,x=(p<t?Kt[p]:i)==1,T=y==x?y?1:2:i;for(let P=p,I=s,z=I?e[I-1].to:n;P>c;)P==z&&(P=e[--I].from,z=I?e[I-1].to:n),Kt[--P]=T;c=p}else r=g,c++}}}function vc(n,t,e,i,s,r,l){let h=i%2?2:1;if(i%2==s%2)for(let c=t,g=0;c<e;){let p=!0,y=!1;if(g==r.length||c<r[g].from){let I=Kt[c];I!=h&&(p=!1,y=I==16)}let x=!p&&h==1?[]:null,T=p?i:i+1,P=c;t:for(;;)if(g<r.length&&P==r[g].from){if(y)break t;let I=r[g];if(!p)for(let z=I.to,W=g+1;;){if(z==e)break t;if(W<r.length&&r[W].from==z)z=r[W++].to;else{if(Kt[z]==h)break t;break}}if(g++,x)x.push(I);else{I.from>c&&l.push(new Ln(c,I.from,T));let z=I.direction==ls!=!(T%2);kc(n,z?i+1:i,s,I.inner,I.from,I.to,l),c=I.to}P=I.to}else{if(P==e||(p?Kt[P]!=h:Kt[P]==h))break;P++}x?vc(n,c,P,i+1,s,x,l):c<P&&l.push(new Ln(c,P,T)),c=P}else for(let c=e,g=r.length;c>t;){let p=!0,y=!1;if(!g||c>r[g-1].to){let I=Kt[c-1];I!=h&&(p=!1,y=I==16)}let x=!p&&h==1?[]:null,T=p?i:i+1,P=c;t:for(;;)if(g&&P==r[g-1].to){if(y)break t;let I=r[--g];if(!p)for(let z=I.from,W=g;;){if(z==t)break t;if(W&&r[W-1].to==z)z=r[--W].from;else{if(Kt[z-1]==h)break t;break}}if(x)x.push(I);else{I.to<c&&l.push(new Ln(I.to,c,T));let z=I.direction==ls!=!(T%2);kc(n,z?i+1:i,s,I.inner,I.from,I.to,l),c=I.from}P=I.from}else{if(P==t||(p?Kt[P-1]!=h:Kt[P-1]==h))break;P--}x?vc(n,P,c,i+1,s,x,l):P<c&&l.push(new Ln(P,c,T)),c=P}}function kc(n,t,e,i,s,r,l){let h=t%2?2:1;cM(n,s,r,i,h),fM(n,s,r,i,h),dM(s,r,i,h),vc(n,s,r,t,e,i,l)}function uM(n,t,e){if(!n)return[new Ln(0,0,t==hf?1:0)];if(t==ls&&!e.length&&!hM.test(n))return ab(n.length);if(e.length)for(;n.length>Kt.length;)Kt[Kt.length]=256;let i=[],s=t==ls?0:1;return kc(n,s,s,e,0,n.length,i),i}function ab(n){return[new Ln(0,n,0)]}let hb="";function pM(n,t,e,i,s){var r;let l=i.head-n.from,h=Ln.find(t,l,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),c=t[h],g=c.side(s,e);if(l==g){let x=h+=s?1:-1;if(x<0||x>=t.length)return null;c=t[h=x],l=c.side(!s,e),g=c.side(s,e)}let p=A.findClusterBreak(n.text,l,c.forward(s,e));(p<c.from||p>c.to)&&(p=g),hb=n.text.slice(Math.min(l,p),Math.max(l,p));let y=h==(s?t.length-1:0)?null:t[h+(s?1:-1)];return y&&p==g&&y.level+(s?0:1)<c.level?A.EditorSelection.cursor(y.side(!s,e)+n.from,y.forward(s,e)?1:-1,y.level):A.EditorSelection.cursor(p+n.from,c.forward(s,e)?-1:1,c.level)}function gM(n,t,e){for(let i=t;i<e;i++){let s=ob(n.charCodeAt(i));if(s==1)return ls;if(s==2||s==4)return hf}return ls}const cb=A.Facet.define(),fb=A.Facet.define(),db=A.Facet.define(),ub=A.Facet.define(),Cc=A.Facet.define(),pb=A.Facet.define(),gb=A.Facet.define(),cf=A.Facet.define(),ff=A.Facet.define(),mb=A.Facet.define({combine:n=>n.some(t=>t)}),mM=A.Facet.define({combine:n=>n.some(t=>t)}),bb=A.Facet.define();class Bs{constructor(t,e="nearest",i="nearest",s=5,r=5,l=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=l}map(t){return t.empty?this:new Bs(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Bs(A.EditorSelection.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Xo=A.StateEffect.define({map:(n,t)=>n.map(t)}),yb=A.StateEffect.define();function Gi(n,t,e){let i=n.facet(ub);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}const cn=A.Facet.define({combine:n=>n.length?n[0]:!0});let bM=0;const Dr=A.Facet.define();class Ji{constructor(t,e,i,s,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:r,decorations:l}=e||{};return new Ji(bM++,t,i,s,h=>{let c=[Dr.of(h)];return l&&c.push(_r.of(g=>{let p=g.plugin(h);return p?l(p):$t.none})),r&&c.push(r(h)),c})}static fromClass(t,e){return Ji.define(i=>new t(i),e)}}class ah{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(Gi(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){Gi(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){Gi(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Sb=A.Facet.define(),df=A.Facet.define(),_r=A.Facet.define(),wb=A.Facet.define(),uf=A.Facet.define(),xb=A.Facet.define();function np(n,t){let e=n.state.facet(xb);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(n):r),s=[];return A.RangeSet.spans(i,t.from,t.to,{point(){},span(r,l,h,c){let g=r-t.from,p=l-t.from,y=s;for(let x=h.length-1;x>=0;x--,c--){let T=h[x].spec.bidiIsolate,P;if(T==null&&(T=gM(t.text,g,p)),c>0&&y.length&&(P=y[y.length-1]).to==g&&P.direction==T)P.to=p,y=P.inner;else{let I={from:g,to:p,direction:T,inner:[]};y.push(I),y=I.inner}}}}),s}const vb=A.Facet.define();function kb(n){let t=0,e=0,i=0,s=0;for(let r of n.state.facet(vb)){let l=r(n);l&&(l.left!=null&&(t=Math.max(t,l.left)),l.right!=null&&(e=Math.max(e,l.right)),l.top!=null&&(i=Math.max(i,l.top)),l.bottom!=null&&(s=Math.max(s,l.bottom)))}return{left:t,right:e,top:i,bottom:s}}const Or=A.Facet.define();class Si{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new Si(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,r=0,l=0,h=0;;s++){let c=s==t.length?null:t[s],g=l-h,p=c?c.fromB:1e9;for(;r<e.length&&e[r]<p;){let y=e[r],x=e[r+1],T=Math.max(h,y),P=Math.min(p,x);if(T<=P&&new Si(T+g,P+g,T,P).addToSet(i),x>p)break;r+=2}if(!c)return i;new Si(c.fromA,c.toA,c.fromB,c.toB).addToSet(i),l=c.toA,h=c.toB}}}class Fl{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=A.ChangeSet.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,l,h,c)=>s.push(new Si(r,l,h,c))),this.changedRanges=s}static create(t,e,i){return new Fl(t,e,i)}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(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class sp extends jt{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=$t.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new me],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Si(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:g,toA:p})=>p<this.minWidthFrom||g>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?s=this.domChanged.newSel.head:!CM(t.changes,this.hasComposition)&&!t.selectionSet&&(s=t.state.selection.main.head));let r=s>-1?SM(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:g,to:p}=this.hasComposition;i=new Si(g,p,t.changes.mapPos(g,-1),t.changes.mapPos(p,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(dt.ie||dt.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let l=this.decorations,h=this.updateDeco(),c=vM(l,h,t.changes);return i=Si.extendWithRanges(i,c),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);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 l=dt.chrome||dt.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,l),this.flags&=-8,l&&(l.written||s.selectionRange.focusNode!=l.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(l=>l.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let l of this.children)l instanceof fn&&l.widget instanceof wc&&r.push(l.dom);s.updateGaps(r)}updateChildren(t,e,i){let s=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let l=s.length-1;;l--){let h=l>=0?s[l]:null;if(!h)break;let{fromA:c,toA:g,fromB:p,toB:y}=h,x,T,P,I;if(i&&i.range.fromB<y&&i.range.toB>p){let Q=Ir.build(this.view.state.doc,p,i.range.fromB,this.decorations,this.dynamicDecorationMap),st=Ir.build(this.view.state.doc,i.range.toB,y,this.decorations,this.dynamicDecorationMap);T=Q.breakAtStart,P=Q.openStart,I=st.openEnd;let at=this.compositionView(i);st.breakAtStart?at.breakAfter=1:st.content.length&&at.merge(at.length,at.length,st.content[0],!1,st.openStart,0)&&(at.breakAfter=st.content[0].breakAfter,st.content.shift()),Q.content.length&&at.merge(0,0,Q.content[Q.content.length-1],!0,0,Q.openEnd)&&Q.content.pop(),x=Q.content.concat(at).concat(st.content)}else({content:x,breakAtStart:T,openStart:P,openEnd:I}=Ir.build(this.view.state.doc,p,y,this.decorations,this.dynamicDecorationMap));let{i:z,off:W}=r.findPos(g,1),{i:U,off:ot}=r.findPos(c,-1);J0(this,U,ot,z,W,x,T,P,I)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(yb)&&(this.editContextFormatting=i.value)}compositionView(t){let e=new Pi(t.text.nodeValue);e.flags|=8;for(let{deco:s}of t.marks)e=new pn(s,[e],e.length);let i=new me;return i.append(e,0),i}fixCompositionDOM(t){let e=(r,l)=>{l.flags|=8|(l.children.some(c=>c.flags&7)?1:0),this.markedForComposition.add(l);let h=jt.get(r);h&&h!=l&&(h.dom=null),l.setDOM(r)},i=this.childPos(t.range.fromB,1),s=this.children[i.i];e(t.line,s);for(let r=t.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],e(r>=0?t.marks[r].node:t.text,s)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&!(this.view.state.facet(cn)||this.dom.tabIndex>-1)&&wl(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||e||r))return;let l=this.forceSelection;this.forceSelection=!1;let h=this.view.state.selection.main,c=this.moveToLine(this.domAtPos(h.anchor)),g=h.empty?c:this.moveToLine(this.domAtPos(h.head));if(dt.gecko&&h.empty&&!this.hasComposition&&yM(c)){let y=document.createTextNode("");this.view.observer.ignore(()=>c.node.insertBefore(y,c.node.childNodes[c.offset]||null)),c=g=new Be(y,0),l=!0}let p=this.view.observer.selectionRange;(l||!p.focusNode||(!Fr(c.node,c.offset,p.anchorNode,p.anchorOffset)||!Fr(g.node,g.offset,p.focusNode,p.focusOffset))&&!this.suppressWidgetCursorChange(p,h))&&(this.view.observer.ignore(()=>{dt.android&&dt.chrome&&this.dom.contains(p.focusNode)&&kM(p.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let y=Kr(this.view.root);if(y)if(h.empty){if(dt.gecko){let x=wM(c.node,c.offset);if(x&&x!=3){let T=(x==1?Y0:U0)(c.node,c.offset);T&&(c=new Be(T.node,T.offset))}}y.collapse(c.node,c.offset),h.bidiLevel!=null&&y.caretBidiLevel!==void 0&&(y.caretBidiLevel=h.bidiLevel)}else if(y.extend){y.collapse(c.node,c.offset);try{y.extend(g.node,g.offset)}catch{}}else{let x=document.createRange();h.anchor>h.head&&([c,g]=[g,c]),x.setEnd(g.node,g.offset),x.setStart(c.node,c.offset),y.removeAllRanges(),y.addRange(x)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(c,g)),this.impreciseAnchor=c.precise?null:new Be(p.anchorNode,p.anchorOffset),this.impreciseHead=g.precise?null:new Be(p.focusNode,p.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Fr(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=Kr(t.root),{anchorNode:s,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let l=me.find(this,e.head);if(!l)return;let h=l.posAtStart;if(e.head==h||e.head==h+l.length)return;let c=this.coordsAt(e.head,-1),g=this.coordsAt(e.head,1);if(!c||!g||c.bottom>g.top)return;let p=this.domAtPos(e.head+e.assoc);i.collapse(p.node,p.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let y=t.observer.selectionRange;t.docView.posFromDOM(y.anchorNode,y.anchorOffset)!=e.from&&i.collapse(s,r)}moveToLine(t){let e=this.dom,i;if(t.node!=e)return t;for(let s=t.offset;!i&&s<e.childNodes.length;s++){let r=jt.get(e.childNodes[s]);r instanceof me&&(i=r.domAtPos(0))}for(let s=t.offset-1;!i&&s>=0;s--){let r=jt.get(e.childNodes[s]);r instanceof me&&(i=r.domAtPos(r.length))}return i?new Be(i.node,i.offset,!0):t}nearest(t){for(let e=t;e;){let i=jt.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let s=this.children[e];if(i<s.length||s instanceof me)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,s=0;for(let r=this.length,l=this.children.length-1;l>=0;l--){let h=this.children[l],c=r-h.breakAfter,g=c-h.length;if(c<t)break;if(g<=t&&(g<t||h.covers(-1))&&(c>t||h.covers(1))&&(!i||h instanceof me&&!(i instanceof me&&e>=0)))i=h,s=g;else if(i&&g==t&&c==t&&h instanceof fn&&Math.abs(e)<2){if(h.deco.startSide<0)break;l&&(i=null)}r=g}return i?i.coordsAt(t-s,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),s=this.children[e];if(!(s instanceof me))return null;for(;s.children.length;){let{i:h,off:c}=s.childPos(i,1);for(;;h++){if(h==s.children.length)return null;if((s=s.children[h]).length)break}i=c}if(!(s instanceof Pi))return null;let r=A.findClusterBreak(s.text,i);if(r==i)return null;let l=os(s.dom,i,r).getClientRects();for(let h=0;h<l.length;h++){let c=l[h];if(h==l.length-1||c.top<c.bottom&&c.left<c.right)return c}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,l=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,h=-1,c=this.view.textDirection==Ae.LTR;for(let g=0,p=0;p<this.children.length;p++){let y=this.children[p],x=g+y.length;if(x>s)break;if(g>=i){let T=y.dom.getBoundingClientRect();if(e.push(T.height),l){let P=y.dom.lastChild,I=P?jr(P):[];if(I.length){let z=I[I.length-1],W=c?z.right-T.left:T.right-z.left;W>h&&(h=W,this.minWidth=r,this.minWidthFrom=g,this.minWidthTo=x)}}}g=x+y.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?Ae.RTL:Ae.LTR}measureTextSize(){for(let r of this.children)if(r instanceof me){let l=r.measureTextSize();if(l)return l}let t=document.createElement("div"),e,i,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(t);let r=jr(t.firstChild)[0];e=t.getBoundingClientRect().height,i=r?r.width/27:7,s=r?r.height:e,t.remove()}),{lineHeight:e,charWidth:i,textHeight:s}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new X0(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],l=r?r.from-1:this.length;if(l>i){let h=(e.lineBlockAt(l).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push($t.replace({widget:new wc(h),block:!0,inclusive:!0,isBlockGap:!0}).range(i,l))}if(!r)break;i=r.to+1}return $t.set(t)}updateDeco(){let t=1,e=this.view.state.facet(_r).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,s=this.view.state.facet(wb).map((r,l)=>{let h=typeof r=="function";return h&&(i=!0),h?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(A.RangeSet.join(s))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let g=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=g.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let g of this.view.state.facet(bb))try{if(g(this.view,t.range,t))return!0}catch(p){Gi(this.view.state,p,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=kb(this.view),l={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:h,offsetHeight:c}=this.view.scrollDOM;JC(this.view.scrollDOM,l,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,h),-h),Math.max(Math.min(t.yMargin,c),-c),this.view.textDirection==Ae.LTR)}}function yM(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function Cb(n,t){let e=n.observer.selectionRange;if(!e.focusNode)return null;let i=Y0(e.focusNode,e.focusOffset),s=U0(e.focusNode,e.focusOffset),r=i||s;if(s&&i&&s.node!=i.node){let h=jt.get(s.node);if(!h||h instanceof Pi&&h.text!=s.node.nodeValue)r=s;else if(n.docView.lastCompositionAfterCursor){let c=jt.get(i.node);!c||c instanceof Pi&&c.text!=i.node.nodeValue||(r=s)}}if(n.docView.lastCompositionAfterCursor=r!=i,!r)return null;let l=t-r.offset;return{from:l,to:l+r.node.nodeValue.length,node:r.node}}function SM(n,t,e){let i=Cb(n,e);if(!i)return null;let{node:s,from:r,to:l}=i,h=s.nodeValue;if(/[\n\r]/.test(h)||n.state.doc.sliceString(i.from,i.to)!=h)return null;let c=t.invertedDesc,g=new Si(c.mapPos(r),c.mapPos(l),r,l),p=[];for(let y=s.parentNode;;y=y.parentNode){let x=jt.get(y);if(x instanceof pn)p.push({node:y,deco:x.mark});else{if(x instanceof me||y.nodeName=="DIV"&&y.parentNode==n.contentDOM)return{range:g,text:s,marks:p,line:y};if(y!=n.contentDOM)p.push({node:y,deco:new no({inclusive:!0,attributes:rM(y),tagName:y.tagName.toLowerCase()})});else return null}}}function wM(n,t){return n.nodeType!=1?0:(t&&n.childNodes[t-1].contentEditable=="false"?1:0)|(t<n.childNodes.length&&n.childNodes[t].contentEditable=="false"?2:0)}let xM=class{constructor(){this.changes=[]}compareRange(t,e){xl(t,e,this.changes)}comparePoint(t,e){xl(t,e,this.changes)}boundChange(t){xl(t,t,this.changes)}};function vM(n,t,e){let i=new xM;return A.RangeSet.compare(n,t,e,i),i.changes}function kM(n,t){for(let e=n;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function CM(n,t){let e=!1;return t&&n.iterChangedRanges((i,s)=>{i<t.to&&s>t.from&&(e=!0)}),e}function MM(n,t,e=1){let i=n.charCategorizer(t),s=n.doc.lineAt(t),r=t-s.from;if(s.length==0)return A.EditorSelection.cursor(t);r==0?e=1:r==s.length&&(e=-1);let l=r,h=r;e<0?l=A.findClusterBreak(s.text,r,!1):h=A.findClusterBreak(s.text,r);let c=i(s.text.slice(l,h));for(;l>0;){let g=A.findClusterBreak(s.text,l,!1);if(i(s.text.slice(g,l))!=c)break;l=g}for(;h<s.length;){let g=A.findClusterBreak(s.text,h);if(i(s.text.slice(h,g))!=c)break;h=g}return A.EditorSelection.range(l+s.from,h+s.from)}function AM(n,t){return t.left>n?t.left-n:Math.max(0,n-t.right)}function TM(n,t){return t.top>n?t.top-n:Math.max(0,n-t.bottom)}function hh(n,t){return n.top<t.bottom-1&&n.bottom>t.top+1}function rp(n,t){return t<n.top?{top:t,left:n.left,right:n.right,bottom:n.bottom}:n}function op(n,t){return t>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:t}:n}function Mc(n,t,e){let i,s,r,l,h=!1,c,g,p,y;for(let P=n.firstChild;P;P=P.nextSibling){let I=jr(P);for(let z=0;z<I.length;z++){let W=I[z];s&&hh(s,W)&&(W=rp(op(W,s.bottom),s.top));let U=AM(t,W),ot=TM(e,W);if(U==0&&ot==0)return P.nodeType==3?lp(P,t,e):Mc(P,t,e);if(!i||l>ot||l==ot&&r>U){i=P,s=W,r=U,l=ot;let Q=ot?e<W.top?-1:1:U?t<W.left?-1:1:0;h=!Q||(Q>0?z<I.length-1:z>0)}U==0?e>W.bottom&&(!p||p.bottom<W.bottom)?(c=P,p=W):e<W.top&&(!y||y.top>W.top)&&(g=P,y=W):p&&hh(p,W)?p=op(p,W.bottom):y&&hh(y,W)&&(y=rp(y,W.top))}}if(p&&p.bottom>=e?(i=c,s=p):y&&y.top<=e&&(i=g,s=y),!i)return{node:n,offset:0};let x=Math.max(s.left,Math.min(s.right,t));if(i.nodeType==3)return lp(i,x,e);if(h&&i.contentEditable!="false")return Mc(i,x,e);let T=Array.prototype.indexOf.call(n.childNodes,i)+(t>=(s.left+s.right)/2?1:0);return{node:n,offset:T}}function lp(n,t,e){let i=n.nodeValue.length,s=-1,r=1e9,l=0;for(let h=0;h<i;h++){let c=os(n,h,h+1).getClientRects();for(let g=0;g<c.length;g++){let p=c[g];if(p.top==p.bottom)continue;l||(l=t-p.left);let y=(p.top>e?p.top-e:e-p.bottom)-1;if(p.left-1<=t&&p.right+1>=t&&y<r){let x=t>=(p.left+p.right)/2,T=x;if((dt.chrome||dt.gecko)&&os(n,h).getBoundingClientRect().left==p.right&&(T=!x),y<=0)return{node:n,offset:h+(T?1:0)};s=h+(T?1:0),r=y}}}return{node:n,offset:s>-1?s:l>0?n.nodeValue.length:0}}function Mb(n,t,e,i=-1){var s,r;let l=n.contentDOM.getBoundingClientRect(),h=l.top+n.viewState.paddingTop,c,{docHeight:g}=n.viewState,{x:p,y}=t,x=y-h;if(x<0)return 0;if(x>g)return n.state.doc.length;for(let Q=n.viewState.heightOracle.textHeight/2,st=!1;c=n.elementAtHeight(x),c.type!=Ui.Text;)for(;x=i>0?c.bottom+Q:c.top-Q,!(x>=0&&x<=g);){if(st)return e?null:0;st=!0,i=-i}y=h+x;let T=c.from;if(T<n.viewport.from)return n.viewport.from==0?0:e?null:ap(n,l,c,p,y);if(T>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:e?null:ap(n,l,c,p,y);let P=n.dom.ownerDocument,I=n.root.elementFromPoint?n.root:P,z=I.elementFromPoint(p,y);z&&!n.contentDOM.contains(z)&&(z=null),z||(p=Math.max(l.left+1,Math.min(l.right-1,p)),z=I.elementFromPoint(p,y),z&&!n.contentDOM.contains(z)&&(z=null));let W,U=-1;if(z&&((s=n.docView.nearest(z))===null||s===void 0?void 0:s.isEditable)!=!1){if(P.caretPositionFromPoint){let Q=P.caretPositionFromPoint(p,y);Q&&({offsetNode:W,offset:U}=Q)}else if(P.caretRangeFromPoint){let Q=P.caretRangeFromPoint(p,y);Q&&({startContainer:W,startOffset:U}=Q,(!n.contentDOM.contains(W)||dt.safari&&DM(W,U,p)||dt.chrome&&OM(W,U,p))&&(W=void 0))}W&&(U=Math.min(Xi(W),U))}if(!W||!n.docView.dom.contains(W)){let Q=me.find(n.docView,T);if(!Q)return x>c.top+c.height/2?c.to:c.from;({node:W,offset:U}=Mc(Q.dom,p,y))}let ot=n.docView.nearest(W);if(!ot)return null;if(ot.isWidget&&((r=ot.dom)===null||r===void 0?void 0:r.nodeType)==1){let Q=ot.dom.getBoundingClientRect();return t.y<Q.top||t.y<=Q.bottom&&t.x<=(Q.left+Q.right)/2?ot.posAtStart:ot.posAtEnd}else return ot.localPosFromDOM(W,U)+ot.posAtStart}function ap(n,t,e,i,s){let r=Math.round((i-t.left)*n.defaultCharacterWidth);if(n.lineWrapping&&e.height>n.defaultLineHeight*1.5){let h=n.viewState.heightOracle.textHeight,c=Math.floor((s-e.top-(n.defaultLineHeight-h)*.5)/h);r+=c*n.viewState.heightOracle.lineLength}let l=n.state.sliceDoc(e.from,e.to);return e.from+A.findColumn(l,r,n.state.tabSize)}function DM(n,t,e){let i;if(n.nodeType!=3||t!=(i=n.nodeValue.length))return!1;for(let s=n.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return os(n,i-1,i).getBoundingClientRect().left>e}function OM(n,t,e){if(t!=0)return!1;for(let s=n;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let i=n.nodeType==1?n.getBoundingClientRect():os(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function EM(n,t){let e=n.lineBlockAt(t);if(Array.isArray(e.type)){for(let i of e.type)if(i.to>t||i.to==t&&(i.to==e.to||i.type==Ui.Text))return i}return e}function PM(n,t,e,i){let s=EM(n,t.head),r=!i||s.type!=Ui.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(r){let l=n.dom.getBoundingClientRect(),h=n.textDirectionAt(s.from),c=n.posAtCoords({x:e==(h==Ae.LTR)?l.right-1:l.left+1,y:(r.top+r.bottom)/2});if(c!=null)return A.EditorSelection.cursor(c,e?-1:1)}return A.EditorSelection.cursor(e?s.to:s.from,e?-1:1)}function hp(n,t,e,i){let s=n.state.doc.lineAt(t.head),r=n.bidiSpans(s),l=n.textDirectionAt(s.from);for(let h=t,c=null;;){let g=pM(s,r,l,h,e),p=hb;if(!g){if(s.number==(e?n.state.doc.lines:1))return h;p=`
16
- `,s=n.state.doc.line(s.number+(e?1:-1)),r=n.bidiSpans(s),g=n.visualLineSide(s,!e)}if(c){if(!c(p))return h}else{if(!i)return g;c=i(p)}h=g}}function RM(n,t,e){let i=n.state.charCategorizer(t),s=i(e);return r=>{let l=i(r);return s==A.CharCategory.Space&&(s=l),s==l}}function BM(n,t,e,i){let s=t.head,r=e?1:-1;if(s==(e?n.state.doc.length:0))return A.EditorSelection.cursor(s,t.assoc);let l=t.goalColumn,h,c=n.contentDOM.getBoundingClientRect(),g=n.coordsAtPos(s,t.assoc||-1),p=n.documentTop;if(g)l==null&&(l=g.left-c.left),h=r<0?g.top:g.bottom;else{let T=n.viewState.lineBlockAt(s);l==null&&(l=Math.min(c.right-c.left,n.defaultCharacterWidth*(s-T.from))),h=(r<0?T.top:T.bottom)+p}let y=c.left+l,x=i??n.viewState.heightOracle.textHeight>>1;for(let T=0;;T+=10){let P=h+(x+T)*r,I=Mb(n,{x:y,y:P},!1,r);if(P<c.top||P>c.bottom||(r<0?I<s:I>s)){let z=n.docView.coordsForChar(I),W=!z||P<z.top?-1:1;return A.EditorSelection.cursor(I,W,void 0,l)}}}function vl(n,t,e){for(;;){let i=0;for(let s of n)s.between(t-1,t+1,(r,l,h)=>{if(t>r&&t<l){let c=i||e||(t-r<l-t?-1:1);t=c<0?r:l,i=c}});if(!i)return t}}function ch(n,t,e){let i=vl(n.state.facet(uf).map(s=>s(n)),e.from,t.head>e.from?-1:1);return i==e.from?e:A.EditorSelection.cursor(i,i<e.from?1:-1)}const Er="￿";class LM{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(A.EditorState.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Er}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let l=s.nextSibling;if(l==e)break;let h=jt.get(s),c=jt.get(l);(h&&c?h.breakAfter:(h?h.breakAfter:Ll(s))||Ll(l)&&(s.nodeName!="BR"||s.cmIgnore)&&this.text.length>r)&&this.lineBreak(),s=l}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,l=1,h;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),l=this.lineSeparator.length):(h=s.exec(e))&&(r=h.index,l=h[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),l>1)for(let c of this.points)c.node==t&&c.pos>this.text.length&&(c.pos-=l-1);i=r+l}}readNode(t){if(t.cmIgnore)return;let e=jt.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(NM(t,i.node,i.offset)?e:0))}}function NM(n,t,e){for(;;){if(!t||e<Xi(t))return!1;if(t==n)return!0;e=rs(t)+1,t=t.parentNode}}class cp{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class FM{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:r,impreciseAnchor:l}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let h=r||l?[]:VM(t),c=new LM(h,t.state);c.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=c.text,this.newSel=$M(h,this.bounds.from)}else{let h=t.observer.selectionRange,c=r&&r.node==h.focusNode&&r.offset==h.focusOffset||!pc(t.contentDOM,h.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(h.focusNode,h.focusOffset),g=l&&l.node==h.anchorNode&&l.offset==h.anchorOffset||!pc(t.contentDOM,h.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(h.anchorNode,h.anchorOffset),p=t.viewport;if((dt.ios||dt.chrome)&&t.state.selection.main.empty&&c!=g&&(p.from>0||p.to<t.state.doc.length)){let y=Math.min(c,g),x=Math.max(c,g),T=p.from-y,P=p.to-x;(T==0||T==1||y==0)&&(P==0||P==-1||x==t.state.doc.length)&&(c=0,g=t.state.doc.length)}this.newSel=A.EditorSelection.single(g,c)}}}function Ab(n,t){let e,{newSel:i}=t,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(t.bounds){let{from:l,to:h}=t.bounds,c=s.from,g=null;(r===8||dt.android&&t.text.length<h-l)&&(c=s.to,g="end");let p=HM(n.state.doc.sliceString(l,h,Er),t.text,c-l,g);p&&(dt.chrome&&r==13&&p.toB==p.from+2&&t.text.slice(p.from,p.toB)==Er+Er&&p.toB--,e={from:l+p.from,to:l+p.toA,insert:A.Text.of(t.text.slice(p.from,p.toB).split(Er))})}else i&&(!n.hasFocus&&n.state.facet(cn)||i.main.eq(s))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!s.empty&&i&&i.main.empty?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:(dt.mac||dt.android)&&e&&e.from==e.to&&e.from==s.head-1&&/^\. ?$/.test(e.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=A.EditorSelection.single(i.main.anchor-1,i.main.head-1)),e={from:e.from,to:e.to,insert:A.Text.of([e.insert.toString().replace("."," ")])}):e&&e.from>=s.from&&e.to<=s.to&&(e.from!=s.from||e.to!=s.to)&&s.to-s.from-(e.to-e.from)<=4?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,e.from).append(e.insert).append(n.state.doc.slice(e.to,s.to))}:dt.chrome&&e&&e.from==e.to&&e.from==s.head&&e.insert.toString()==`
17
- `&&n.lineWrapping&&(i&&(i=A.EditorSelection.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:A.Text.of([" "])}),e)return pf(n,e,i,r);if(i&&!i.main.eq(s)){let l=!1,h="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(l=!0),h=n.inputState.lastSelectionOrigin),n.dispatch({selection:i,scrollIntoView:l,userEvent:h}),!0}else return!1}function pf(n,t,e,i=-1){if(dt.ios&&n.inputState.flushIOSKey(t))return!0;let s=n.state.selection.main;if(dt.android&&(t.to==s.to&&(t.from==s.from||t.from==s.from-1&&n.state.sliceDoc(t.from,s.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&Rs(n.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>s.head)&&Rs(n.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&Rs(n.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let l,h=()=>l||(l=IM(n,t,e));return n.state.facet(pb).some(c=>c(n,t.from,t.to,r,h))||n.dispatch(h()),!0}function IM(n,t,e){let i,s=n.state,r=s.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&n.inputState.composing<0){let h=r.from<t.from?s.sliceDoc(r.from,t.from):"",c=r.to>t.to?s.sliceDoc(t.to,r.to):"";i=s.replaceSelection(n.state.toText(h+t.insert.sliceString(0,void 0,n.state.lineBreak)+c))}else{let h=s.changes(t),c=e&&e.main.to<=h.newLength?e.main:void 0;if(s.selection.ranges.length>1&&n.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let g=n.state.sliceDoc(t.from,t.to),p,y=e&&Cb(n,e.main.head);if(y){let P=t.insert.length-(t.to-t.from);p={from:y.from,to:y.to-P}}else p=n.state.doc.lineAt(r.head);let x=r.to-t.to,T=r.to-r.from;i=s.changeByRange(P=>{if(P.from==r.from&&P.to==r.to)return{changes:h,range:c||P.map(h)};let I=P.to-x,z=I-g.length;if(P.to-P.from!=T||n.state.sliceDoc(z,I)!=g||P.to>=p.from&&P.from<=p.to)return{range:P};let W=s.changes({from:z,to:I,insert:t.insert}),U=P.to-r.to;return{changes:W,range:c?A.EditorSelection.range(Math.max(0,c.anchor+U),Math.max(0,c.head+U)):P.map(W)}})}else i={changes:h,selection:c&&s.selection.replaceRange(c)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function HM(n,t,e,i){let s=Math.min(n.length,t.length),r=0;for(;r<s&&n.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==s&&n.length==t.length)return null;let l=n.length,h=t.length;for(;l>0&&h>0&&n.charCodeAt(l-1)==t.charCodeAt(h-1);)l--,h--;if(i=="end"){let c=Math.max(0,r-Math.min(l,h));e-=l+c-r}if(l<r&&n.length<t.length){let c=e<=r&&e>=l?r-e:0;r-=c,h=r+(h-l),l=r}else if(h<r){let c=e<=r&&e>=h?r-e:0;r-=c,l=r+(l-h),h=r}return{from:r,toA:l,toB:h}}function VM(n){let t=[];if(n.root.activeElement!=n.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return e&&(t.push(new cp(e,i)),(s!=e||r!=i)&&t.push(new cp(s,r))),t}function $M(n,t){if(n.length==0)return null;let e=n[0].pos,i=n.length==2?n[1].pos:e;return e>-1&&i>-1?A.EditorSelection.single(e+t,i+t):null}class WM{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,dt.safari&&t.contentDOM.addEventListener("input",()=>null),dt.gecko&&nA(t.contentDOM.ownerDocument)}handleEvent(t){!UM(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let s of i.observers)s(this.view,e);for(let s of i.handlers){if(e.defaultPrevented)break;if(s(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=zM(t),i=this.handlers,s=this.view.contentDOM;for(let r in e)if(r!="scroll"){let l=!e[r].handlers.length,h=i[r];h&&l!=!h.handlers.length&&(s.removeEventListener(r,this.handleEvent),h=null),h||s.addEventListener(r,this.handleEvent,{passive:l})}for(let r in i)r!="scroll"&&!e[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&Db.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),dt.android&&dt.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return dt.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=Tb.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||qM.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,Rs(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:dt.safari&&!dt.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function fp(n,t){return(e,i)=>{try{return t.call(n,i,e)}catch(s){Gi(e.state,s)}}}function zM(n){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec;if(s&&s.domEventHandlers)for(let r in s.domEventHandlers){let l=s.domEventHandlers[r];l&&e(r).handlers.push(fp(i.value,l))}if(s&&s.domEventObservers)for(let r in s.domEventObservers){let l=s.domEventObservers[r];l&&e(r).observers.push(fp(i.value,l))}}for(let i in Ri)e(i).handlers.push(Ri[i]);for(let i in xi)e(i).observers.push(xi[i]);return t}const Tb=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],qM="dthko",Db=[16,17,18,20,91,92,224,225],Jo=6;function Qo(n){return Math.max(0,n)*.7+8}function KM(n,t){return Math.max(Math.abs(n.clientX-t.clientX),Math.abs(n.clientY-t.clientY))}class jM{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=QC(t.contentDOM),this.atoms=t.state.facet(uf).map(l=>l(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(A.EditorState.allowMultipleSelections)&&_M(t,e),this.dragging=YM(t,e)&&Pb(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&KM(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,s=0,r=0,l=this.view.win.innerWidth,h=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:h}=this.scrollParents.y.getBoundingClientRect());let c=kb(this.view);t.clientX-c.left<=s+Jo?e=-Qo(s-t.clientX):t.clientX+c.right>=l-Jo&&(e=Qo(t.clientX-l)),t.clientY-c.top<=r+Jo?i=-Qo(r-t.clientY):t.clientY+c.bottom>=h-Jo&&(i=Qo(t.clientY-h)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],r=null;if(s.empty){let l=vl(this.atoms,s.from,0);l!=s.from&&(r=A.EditorSelection.cursor(l,-1))}else{let l=vl(this.atoms,s.from,-1),h=vl(this.atoms,s.to,1);(l!=s.from||h!=s.to)&&(r=A.EditorSelection.range(s.from==s.anchor?l:h,s.from==s.head?l:h))}r&&(e||(e=t.ranges.slice()),e[i]=r)}return e?A.EditorSelection.create(e,t.mainIndex):t}select(t){let{view:e}=this,i=this.skipAtoms(this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function _M(n,t){let e=n.state.facet(cb);return e.length?e[0](t):dt.mac?t.metaKey:t.ctrlKey}function GM(n,t){let e=n.state.facet(fb);return e.length?e[0](t):dt.mac?!t.altKey:!t.ctrlKey}function YM(n,t){let{main:e}=n.state.selection;if(e.empty)return!1;let i=Kr(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let l=s[r];if(l.left<=t.clientX&&l.right>=t.clientX&&l.top<=t.clientY&&l.bottom>=t.clientY)return!0}return!1}function UM(n,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=n.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=jt.get(e))&&i.ignoreEvent(t))return!1;return!0}const Ri=Object.create(null),xi=Object.create(null),Ob=dt.ie&&dt.ie_version<15||dt.ios&&dt.webkit_version<604;function XM(n){let t=n.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{n.focus(),e.remove(),Eb(n,e.value)},50)}function ha(n,t,e){for(let i of n.facet(t))e=i(e,n);return e}function Eb(n,t){t=ha(n.state,cf,t);let{state:e}=n,i,s=1,r=e.toText(t),l=r.lines==e.selection.ranges.length;if(Ac!=null&&e.selection.ranges.every(c=>c.empty)&&Ac==r.toString()){let c=-1;i=e.changeByRange(g=>{let p=e.doc.lineAt(g.from);if(p.from==c)return{range:g};c=p.from;let y=e.toText((l?r.line(s++).text:t)+e.lineBreak);return{changes:{from:p.from,insert:y},range:A.EditorSelection.cursor(g.from+y.length)}})}else l?i=e.changeByRange(c=>{let g=r.line(s++);return{changes:{from:c.from,to:c.to,insert:g.text},range:A.EditorSelection.cursor(c.from+g.length)}}):i=e.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}xi.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};Ri.keydown=(n,t)=>(n.inputState.setSelectionOrigin("select"),t.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);xi.touchstart=(n,t)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};xi.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Ri.mousedown=(n,t)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of n.state.facet(db))if(e=i(n,t),e)break;if(!e&&t.button==0&&(e=ZM(n,t)),e){let i=!n.hasFocus;n.inputState.startMouseSelection(new jM(n,t,e,i)),i&&n.observer.ignore(()=>{j0(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(t),s.dragging===!1}return!1};function dp(n,t,e,i){if(i==1)return A.EditorSelection.cursor(t,e);if(i==2)return MM(n.state,t,e);{let s=me.find(n.docView,t),r=n.state.doc.lineAt(s?s.posAtEnd:t),l=s?s.posAtStart:r.from,h=s?s.posAtEnd:r.to;return h<n.state.doc.length&&h==r.to&&h++,A.EditorSelection.range(l,h)}}let up=(n,t,e)=>t>=e.top&&t<=e.bottom&&n>=e.left&&n<=e.right;function JM(n,t,e,i){let s=me.find(n.docView,t);if(!s)return 1;let r=t-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let l=s.coordsAt(r,-1);if(l&&up(e,i,l))return-1;let h=s.coordsAt(r,1);return h&&up(e,i,h)?1:l&&l.bottom>=i?-1:1}function pp(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:JM(n,e,t.clientX,t.clientY)}}const QM=dt.ie&&dt.ie_version<=11;let gp=null,mp=0,bp=0;function Pb(n){if(!QM)return n.detail;let t=gp,e=bp;return gp=n,bp=Date.now(),mp=!t||e>Date.now()-400&&Math.abs(t.clientX-n.clientX)<2&&Math.abs(t.clientY-n.clientY)<2?(mp+1)%3:1}function ZM(n,t){let e=pp(n,t),i=Pb(t),s=n.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),s=s.map(r.changes))},get(r,l,h){let c=pp(n,r),g,p=dp(n,c.pos,c.bias,i);if(e.pos!=c.pos&&!l){let y=dp(n,e.pos,e.bias,i),x=Math.min(y.from,p.from),T=Math.max(y.to,p.to);p=x<p.from?A.EditorSelection.range(x,T):A.EditorSelection.range(T,x)}return l?s.replaceRange(s.main.extend(p.from,p.to)):h&&i==1&&s.ranges.length>1&&(g=tA(s,c.pos))?g:h?s.addRange(p):A.EditorSelection.create([p])}}}function tA(n,t){for(let e=0;e<n.ranges.length;e++){let{from:i,to:s}=n.ranges[e];if(i<=t&&s>=t)return A.EditorSelection.create(n.ranges.slice(0,e).concat(n.ranges.slice(e+1)),n.mainIndex==e?0:n.mainIndex-(n.mainIndex>e?1:0))}return null}Ri.dragstart=(n,t)=>{let{selection:{main:e}}=n.state;if(t.target.draggable){let s=n.docView.nearest(t.target);if(s&&s.isWidget){let r=s.posAtStart,l=r+s.length;(r>=e.to||l<=e.from)&&(e=A.EditorSelection.range(r,l))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",ha(n.state,ff,n.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};Ri.dragend=n=>(n.inputState.draggedContent=null,!1);function yp(n,t,e,i){if(e=ha(n.state,cf,e),!e)return;let s=n.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=n.inputState,l=i&&r&&GM(n,t)?{from:r.from,to:r.to}:null,h={from:s,insert:e},c=n.state.changes(l?[l,h]:h);n.focus(),n.dispatch({changes:c,selection:{anchor:c.mapPos(s,-1),head:c.mapPos(s,1)},userEvent:l?"move.drop":"input.drop"}),n.inputState.draggedContent=null}Ri.drop=(n,t)=>{if(!t.dataTransfer)return!1;if(n.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),s=0,r=()=>{++s==e.length&&yp(n,t,i.filter(l=>l!=null).join(n.state.lineBreak),!1)};for(let l=0;l<e.length;l++){let h=new FileReader;h.onerror=r,h.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(h.result)||(i[l]=h.result),r()},h.readAsText(e[l])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return yp(n,t,i,!0),!0}return!1};Ri.paste=(n,t)=>{if(n.state.readOnly)return!0;n.observer.flush();let e=Ob?null:t.clipboardData;return e?(Eb(n,e.getData("text/plain")||e.getData("text/uri-list")),!0):(XM(n),!1)};function eA(n,t){let e=n.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function iA(n){let t=[],e=[],i=!1;for(let s of n.selection.ranges)s.empty||(t.push(n.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:r}of n.selection.ranges){let l=n.doc.lineAt(r);l.number>s&&(t.push(l.text),e.push({from:l.from,to:Math.min(n.doc.length,l.to+1)})),s=l.number}i=!0}return{text:ha(n,ff,t.join(n.lineBreak)),ranges:e,linewise:i}}let Ac=null;Ri.copy=Ri.cut=(n,t)=>{let{text:e,ranges:i,linewise:s}=iA(n.state);if(!e&&!s)return!1;Ac=s?e:null,t.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Ob?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(eA(n,e),!1)};const Rb=A.Annotation.define();function Bb(n,t){let e=[];for(let i of n.facet(gb)){let s=i(n,t);s&&e.push(s)}return e?n.update({effects:e,annotations:Rb.of(!0)}):null}function Lb(n){setTimeout(()=>{let t=n.hasFocus;if(t!=n.inputState.notifiedFocused){let e=Bb(n.state,t);e?n.dispatch(e):n.update([])}},10)}xi.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Lb(n)};xi.blur=n=>{n.observer.clearSelectionRange(),Lb(n)};xi.compositionstart=xi.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};xi.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,dt.chrome&&dt.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};xi.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};Ri.beforeinput=(n,t)=>{var e,i;if(t.inputType=="insertReplacementText"&&n.observer.editContext){let r=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),l=t.getTargetRanges();if(r&&l.length){let h=l[0],c=n.posAtDOM(h.startContainer,h.startOffset),g=n.posAtDOM(h.endContainer,h.endOffset);return pf(n,{from:c,to:g,insert:n.state.toText(r)},null),!0}}let s;if(dt.chrome&&dt.android&&(s=Tb.find(r=>r.inputType==t.inputType))&&(n.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let r=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var l;(((l=window.visualViewport)===null||l===void 0?void 0:l.height)||0)>r+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return dt.ios&&t.inputType=="deleteContentForward"&&n.observer.flushSoon(),dt.safari&&t.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>xi.compositionend(n,t),20),!1};const Sp=new Set;function nA(n){Sp.has(n)||(Sp.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const wp=["pre-wrap","normal","pre-line","break-spaces"];let Ks=!1;function xp(){Ks=!1}class sA{constructor(t){this.lineWrapping=t,this.doc=A.Text.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return wp.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,r,l){let h=wp.indexOf(t)>-1,c=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=h;if(this.lineWrapping=h,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=r,c){this.heightSamples={};for(let g=0;g<l.length;g++){let p=l[g];p<0?g++:this.heightSamples[Math.floor(p*10)]=!0}}return c}}class rA{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class qi{constructor(t,e,i,s,r){this.from=t,this.length=e,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?Ui.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 Wn?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new qi(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var Jt=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(Jt||(Jt={}));const kl=.001;class ze{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>kl&&(Ks=!0),this.height=t)}replace(t,e,i){return ze.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let r=this,l=i.doc;for(let h=s.length-1;h>=0;h--){let{fromA:c,toA:g,fromB:p,toB:y}=s[h],x=r.lineAt(c,Jt.ByPosNoHeight,i.setDoc(e),0,0),T=x.to>=g?x:r.lineAt(g,Jt.ByPosNoHeight,i,0,0);for(y+=T.to-g,g=T.to;h>0&&x.from<=s[h-1].toA;)c=s[h-1].fromA,p=s[h-1].fromB,h--,c<x.from&&(x=r.lineAt(c,Jt.ByPosNoHeight,i,0,0));p+=x.from-c,c=x.from;let P=gf.build(i.setDoc(l),t,p,y);r=Il(r,r.replace(c,g,P))}return r.updateHeight(i,0)}static empty(){return new ai(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,r=0;for(;;)if(e==i)if(s>r*2){let h=t[e-1];h.break?t.splice(--e,1,h.left,null,h.right):t.splice(--e,1,h.left,h.right),i+=1+h.break,s-=h.size}else if(r>s*2){let h=t[i];h.break?t.splice(i,1,h.left,null,h.right):t.splice(i,1,h.left,h.right),i+=2+h.break,r-=h.size}else break;else if(s<r){let h=t[e++];h&&(s+=h.size)}else{let h=t[--i];h&&(r+=h.size)}let l=0;return t[e-1]==null?(l=1,e--):t[e]==null&&(l=1,i++),new oA(ze.of(t.slice(0,e)),l,ze.of(t.slice(i)))}}function Il(n,t){return n==t?n:(n.constructor!=t.constructor&&(Ks=!0),t)}ze.prototype.size=1;class Nb extends ze{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,s){return new qi(s,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(t,e,i,s,r,l){t<=r+this.length&&e>=r&&l(this.blockAt(0,i,s,r))}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setHeight(s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class ai extends Nb{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,s){return new qi(s,this.length,i,this.height,this.breaks)}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof ai||s instanceof Ce&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof Ce?s=new ai(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):ze.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setHeight(s.heights[s.index++]):(i||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Ce extends ze{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-i+1,l,h=0;if(t.lineWrapping){let c=Math.min(this.height,t.lineHeight*r);l=c/r,this.length>r+1&&(h=(this.height-c)/(this.length-r-1))}else l=this.height/r;return{firstLine:i,lastLine:s,perLine:l,perChar:h}}blockAt(t,e,i,s){let{firstLine:r,lastLine:l,perLine:h,perChar:c}=this.heightMetrics(e,s);if(e.lineWrapping){let g=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),p=e.doc.lineAt(g),y=h+p.length*c,x=Math.max(i,t-y/2);return new qi(p.from,p.length,x,y,0)}else{let g=Math.max(0,Math.min(l-r,Math.floor((t-i)/h))),{from:p,length:y}=e.doc.line(r+g);return new qi(p,y,i+h*g,h,0)}}lineAt(t,e,i,s,r){if(e==Jt.ByHeight)return this.blockAt(t,i,s,r);if(e==Jt.ByPosNoHeight){let{from:T,to:P}=i.doc.lineAt(t);return new qi(T,P-T,0,0,0)}let{firstLine:l,perLine:h,perChar:c}=this.heightMetrics(i,r),g=i.doc.lineAt(t),p=h+g.length*c,y=g.number-l,x=s+h*y+c*(g.from-r-y);return new qi(g.from,g.length,Math.max(s,Math.min(x,s+this.height-p)),p,0)}forEachLine(t,e,i,s,r,l){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:h,perLine:c,perChar:g}=this.heightMetrics(i,r);for(let p=t,y=s;p<=e;){let x=i.doc.lineAt(p);if(p==t){let P=x.number-h;y+=c*P+g*(t-r-P)}let T=c+g*x.length;l(new qi(x.from,x.length,y,T,0)),y+=T,p=x.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let r=i[i.length-1];r instanceof Ce?i[i.length-1]=new Ce(r.length+s):i.push(null,new Ce(s-1))}if(t>0){let r=i[0];r instanceof Ce?i[0]=new Ce(t+r.length):i.unshift(new Ce(t-1),null)}return ze.of(i)}decomposeLeft(t,e){e.push(new Ce(t-1),null)}decomposeRight(t,e){e.push(null,new Ce(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let l=[],h=Math.max(e,s.from),c=-1;for(s.from>e&&l.push(new Ce(s.from-e-1).updateHeight(t,e));h<=r&&s.more;){let p=t.doc.lineAt(h).length;l.length&&l.push(null);let y=s.heights[s.index++];c==-1?c=y:Math.abs(y-c)>=kl&&(c=-2);let x=new ai(p,y);x.outdated=!1,l.push(x),h+=p+1}h<=r&&l.push(null,new Ce(r-h).updateHeight(t,h));let g=ze.of(l);return(c<0||Math.abs(g.height-this.height)>=kl||Math.abs(c-this.heightMetrics(t,e).perLine)>=kl)&&(Ks=!0),Il(this,g)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class oA extends ze{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,s){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,r,s+this.left.length+this.break)}lineAt(t,e,i,s,r){let l=s+this.left.height,h=r+this.left.length+this.break,c=e==Jt.ByHeight?t<l:t<h,g=c?this.left.lineAt(t,e,i,s,r):this.right.lineAt(t,e,i,l,h);if(this.break||(c?g.to<h:g.from>h))return g;let p=e==Jt.ByPosNoHeight?Jt.ByPosNoHeight:Jt.ByPos;return c?g.join(this.right.lineAt(h,p,i,l,h)):this.left.lineAt(h,p,i,s,r).join(g)}forEachLine(t,e,i,s,r,l){let h=s+this.left.height,c=r+this.left.length+this.break;if(this.break)t<c&&this.left.forEachLine(t,e,i,s,r,l),e>=c&&this.right.forEachLine(t,e,i,h,c,l);else{let g=this.lineAt(c,Jt.ByPos,i,s,r);t<g.from&&this.left.forEachLine(t,g.from-1,i,s,r,l),g.to>=t&&g.from<=e&&l(g),e>g.to&&this.right.forEachLine(g.to+1,e,i,h,c,l)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let r=[];t>0&&this.decomposeLeft(t,r);let l=r.length;for(let h of i)r.push(h);if(t>0&&vp(r,l-1),e<this.length){let h=r.length;this.decomposeRight(e,r),vp(r,h)}return ze.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?ze.of(this.break?[t,null,e]:[t,e]):(this.left=Il(this.left,t),this.right=Il(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:r,right:l}=this,h=e+r.length+this.break,c=null;return s&&s.from<=e+r.length&&s.more?c=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=h+l.length&&s.more?c=l=l.updateHeight(t,h,i,s):l.updateHeight(t,h,i),c?this.balanced(r,l):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function vp(n,t){let e,i;n[t]==null&&(e=n[t-1])instanceof Ce&&(i=n[t+1])instanceof Ce&&n.splice(t-1,3,new Ce(e.length+1+i.length))}const lA=5;class gf{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof ai?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new ai(i-this.pos,-1)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let l=e-t;i.block?this.addBlock(new Nb(l,s,i)):(l||r||s>=lA)&&this.addLineDeco(s,r,l)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new ai(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new Ce(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof ai)return t;let e=new ai(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof ai)&&!this.isCovered?this.nodes.push(new ai(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof ai&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let r=new gf(i,t);return A.RangeSet.spans(e,i,s,r,0),r.finish(i)}}function aA(n,t,e){let i=new hA;return A.RangeSet.compare(n,t,e,i,0),i.changes}class hA{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&xl(t,e,this.changes,5)}}function cA(n,t){let e=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,e.left),l=Math.min(s.innerWidth,e.right),h=Math.max(0,e.top),c=Math.min(s.innerHeight,e.bottom);for(let g=n.parentNode;g&&g!=i.body;)if(g.nodeType==1){let p=g,y=window.getComputedStyle(p);if((p.scrollHeight>p.clientHeight||p.scrollWidth>p.clientWidth)&&y.overflow!="visible"){let x=p.getBoundingClientRect();r=Math.max(r,x.left),l=Math.min(l,x.right),h=Math.max(h,x.top),c=Math.min(g==n.parentNode?s.innerHeight:c,x.bottom)}g=y.position=="absolute"||y.position=="fixed"?p.offsetParent:p.parentNode}else if(g.nodeType==11)g=g.host;else break;return{left:r-e.left,right:Math.max(r,l)-e.left,top:h-(e.top+t),bottom:Math.max(h,c)-(e.top+t)}}function fA(n){let t=n.getBoundingClientRect(),e=n.ownerDocument.defaultView||window;return t.left<e.innerWidth&&t.right>0&&t.top<e.innerHeight&&t.bottom>0}function dA(n,t){let e=n.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class fh{constructor(t,e,i,s){this.from=t,this.to=e,this.size=i,this.displaySize=s}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(t,e){return $t.replace({widget:new uA(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class uA extends af{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class kp{constructor(t){this.state=t,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=Cp,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Ae.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(df).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new sA(e),this.stateDeco=t.facet(_r).filter(i=>typeof i!="function"),this.heightMap=ze.empty().applyChanges(this.stateDeco,A.Text.empty,this.heightOracle.setDoc(t.doc),[new Si(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=$t.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some(({from:r,to:l})=>s>=r&&s<=l)){let{from:r,to:l}=this.lineBlockAt(s);t.push(new Zo(r,l))}}return this.viewports=t.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Cp:new mf(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(Pr(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(_r).filter(p=>typeof p!="function");let s=t.changedRanges,r=Si.extendWithRanges(s,aA(i,this.stateDeco,t?t.changes:A.ChangeSet.empty(this.state.doc.length))),l=this.heightMap.height,h=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);xp(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=l||Ks)&&(t.flags|=2),h?(this.scrollAnchorPos=t.changes.mapPos(h.from,-1),this.scrollAnchorHeight=h.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let c=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<c.from||e.range.head>c.to)||!this.viewportIsAppropriate(c))&&(c=this.getViewport(0,e));let g=c.from!=this.viewport.from||c.to!=this.viewport.to;this.viewport=c,t.flags|=this.updateForViewport(),(g||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(mM)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?Ae.RTL:Ae.LTR;let l=this.heightOracle.mustRefreshForWrapping(r),h=e.getBoundingClientRect(),c=l||this.mustMeasureContent||this.contentDOMHeight!=h.height;this.contentDOMHeight=h.height,this.mustMeasureContent=!1;let g=0,p=0;if(h.width&&h.height){let{scaleX:Q,scaleY:st}=K0(e,h);(Q>.005&&Math.abs(this.scaleX-Q)>.005||st>.005&&Math.abs(this.scaleY-st)>.005)&&(this.scaleX=Q,this.scaleY=st,g|=16,l=c=!0)}let y=(parseInt(i.paddingTop)||0)*this.scaleY,x=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=y||this.paddingBottom!=x)&&(this.paddingTop=y,this.paddingBottom=x,g|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(c=!0),this.editorWidth=t.scrollDOM.clientWidth,g|=16);let T=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=T&&(this.scrollAnchorHeight=-1,this.scrollTop=T),this.scrolledToBottom=G0(t.scrollDOM);let P=(this.printing?dA:cA)(e,this.paddingTop),I=P.top-this.pixelViewport.top,z=P.bottom-this.pixelViewport.bottom;this.pixelViewport=P;let W=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(W!=this.inView&&(this.inView=W,W&&(c=!0)),!this.inView&&!this.scrollTarget&&!fA(t.dom))return 0;let U=h.width;if((this.contentDOMWidth!=U||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=h.width,this.editorHeight=t.scrollDOM.clientHeight,g|=16),c){let Q=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(Q)&&(l=!0),l||s.lineWrapping&&Math.abs(U-this.contentDOMWidth)>s.charWidth){let{lineHeight:st,charWidth:at,textHeight:wt}=t.docView.measureTextSize();l=st>0&&s.refresh(r,st,at,wt,U/at,Q),l&&(t.docView.minWidth=0,g|=16)}I>0&&z>0?p=Math.max(I,z):I<0&&z<0&&(p=Math.min(I,z)),xp();for(let st of this.viewports){let at=st.from==this.viewport.from?Q:t.docView.measureVisibleLineHeights(st);this.heightMap=(l?ze.empty().applyChanges(this.stateDeco,A.Text.empty,this.heightOracle,[new Si(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,l,new rA(st.from,at))}Ks&&(g|=2)}let ot=!this.viewportIsAppropriate(this.viewport,p)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return ot&&(g&2&&(g|=this.updateScaler()),this.viewport=this.getViewport(p,this.scrollTarget),g|=this.updateForViewport()),(g&2||ot)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(l?[]:this.lineGaps,t)),g|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),g}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:l,visibleBottom:h}=this,c=new Zo(s.lineAt(l-i*1e3,Jt.ByHeight,r,0,0).from,s.lineAt(h+(1-i)*1e3,Jt.ByHeight,r,0,0).to);if(e){let{head:g}=e.range;if(g<c.from||g>c.to){let p=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),y=s.lineAt(g,Jt.ByPos,r,0,0),x;e.y=="center"?x=(y.top+y.bottom)/2-p/2:e.y=="start"||e.y=="nearest"&&g<c.from?x=y.top:x=y.bottom-p,c=new Zo(s.lineAt(x-1e3/2,Jt.ByHeight,r,0,0).from,s.lineAt(x+p+1e3/2,Jt.ByHeight,r,0,0).to)}}return c}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new Zo(this.heightMap.lineAt(i,Jt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,Jt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,Jt.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,Jt.ByPos,this.heightOracle,0,0),{visibleTop:l,visibleBottom:h}=this;return(t==0||s<=l-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=h+Math.max(10,Math.min(i,250)))&&s>l-2*1e3&&r<h+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new fh(e.mapPos(s.from),e.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,l=s<<1;if(this.defaultTextDirection!=Ae.LTR&&!i)return[];let h=[],c=(p,y,x,T)=>{if(y-p<r)return;let P=this.state.selection.main,I=[P.from];P.empty||I.push(P.to);for(let W of I)if(W>p&&W<y){c(p,W-10,x,T),c(W+10,y,x,T);return}let z=gA(t,W=>W.from>=x.from&&W.to<=x.to&&Math.abs(W.from-p)<r&&Math.abs(W.to-y)<r&&!I.some(U=>W.from<U&&W.to>U));if(!z){if(y<x.to&&e&&i&&e.visibleRanges.some(ot=>ot.from<=y&&ot.to>=y)){let ot=e.moveToLineBoundary(A.EditorSelection.cursor(y),!1,!0).head;ot>p&&(y=ot)}let W=this.gapSize(x,p,y,T),U=i||W<2e6?W:2e6;z=new fh(p,y,W,U)}h.push(z)},g=p=>{if(p.length<l||p.type!=Ui.Text)return;let y=pA(p.from,p.to,this.stateDeco);if(y.total<l)return;let x=this.scrollTarget?this.scrollTarget.range.head:null,T,P;if(i){let I=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,z,W;if(x!=null){let U=el(y,x),ot=((this.visibleBottom-this.visibleTop)/2+I)/p.height;z=U-ot,W=U+ot}else z=(this.visibleTop-p.top-I)/p.height,W=(this.visibleBottom-p.top+I)/p.height;T=tl(y,z),P=tl(y,W)}else{let I=y.total*this.heightOracle.charWidth,z=s*this.heightOracle.charWidth,W=0;if(I>2e6)for(let at of t)at.from>=p.from&&at.from<p.to&&at.size!=at.displaySize&&at.from*this.heightOracle.charWidth+W<this.pixelViewport.left&&(W=at.size-at.displaySize);let U=this.pixelViewport.left+W,ot=this.pixelViewport.right+W,Q,st;if(x!=null){let at=el(y,x),wt=((ot-U)/2+z)/I;Q=at-wt,st=at+wt}else Q=(U-z)/I,st=(ot+z)/I;T=tl(y,Q),P=tl(y,st)}T>p.from&&c(p.from,T,p,y),P<p.to&&c(P,p.to,p,y)};for(let p of this.viewportLines)Array.isArray(p.type)?p.type.forEach(g):g(p);return h}gapSize(t,e,i,s){let r=el(s,i)-el(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){fh.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=$t.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];A.RangeSet.spans(e,this.viewport.from,this.viewport.to,{span(r,l){i.push({from:r,to:l})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let r=0;r<i.length&&!(s&8);r++){let l=this.visibleRanges[r],h=i[r];(l.from!=h.from||l.to!=h.to)&&(s|=4,t&&t.mapPos(l.from,-1)==h.from&&t.mapPos(l.to,1)==h.to||(s|=8))}return this.visibleRanges=i,s}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Pr(this.heightMap.lineAt(t,Jt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Pr(this.heightMap.lineAt(this.scaler.fromDOM(t),Jt.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Pr(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Zo{constructor(t,e){this.from=t,this.to=e}}function pA(n,t,e){let i=[],s=n,r=0;return A.RangeSet.spans(e,n,t,{span(){},point(l,h){l>s&&(i.push({from:s,to:l}),r+=l-s),s=h}},20),s<t&&(i.push({from:s,to:t}),r+=t-s),{total:r,ranges:i}}function tl({total:n,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(n*e);for(let s=0;;s++){let{from:r,to:l}=t[s],h=l-r;if(i<=h)return r+i;i-=h}}function el(n,t){let e=0;for(let{from:i,to:s}of n.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/n.total}function gA(n,t){for(let e of n)if(t(e))return e}const Cp={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};class mf{constructor(t,e,i){let s=0,r=0,l=0;this.viewports=i.map(({from:h,to:c})=>{let g=e.lineAt(h,Jt.ByPos,t,0,0).top,p=e.lineAt(c,Jt.ByPos,t,0,0).bottom;return s+=p-g,{from:h,to:c,top:g,bottom:p,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let h of this.viewports)h.domTop=l+(h.top-r)*this.scale,l=h.domBottom=h.domTop+(h.bottom-h.top),r=h.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return s+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,s=r.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-s)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,s=r.domBottom}}eq(t){return t instanceof mf?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function Pr(n,t){if(t.scale==1)return n;let e=t.toDOM(n.top),i=t.toDOM(n.bottom);return new qi(n.from,n.length,e,i-e,Array.isArray(n._content)?n._content.map(s=>Pr(s,t)):n._content)}const il=A.Facet.define({combine:n=>n.join(" ")}),Tc=A.Facet.define({combine:n=>n.indexOf(!0)>-1}),Dc=Le.newName(),Fb=Le.newName(),Ib=Le.newName(),Hb={"&light":"."+Fb,"&dark":"."+Ib};function Oc(n,t,e){return new Le(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):n+" "+i}})}const mA=Oc("."+Dc,{"&":{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",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,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-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-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"}},Hb),bA={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},dh=dt.ie&&dt.ie_version<=11;class yA{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new ZC,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(dt.ie&&dt.ie_version<=11||dt.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&t.constructor.EDIT_CONTEXT!==!1&&!(dt.chrome&&dt.chrome_version<126)&&(this.editContext=new wA(t),t.state.facet(cn)&&(t.contentDOM.editContext=this.editContext.editContext)),dh&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.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 e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.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(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(cn)?i.root.activeElement!=this.dom:!wl(this.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(dt.ie&&dt.ie_version<=11||dt.android&&dt.chrome)&&!i.state.selection.main.empty&&s.focusNode&&Fr(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=Kr(t.root);if(!e)return!1;let i=dt.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&SA(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=wl(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&eM(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,bA),dh&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),dh&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;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&&Rs(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.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 t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let r of t){let l=this.readMutation(r);l&&(l.typeOver&&(s=!0),e==-1?{from:e,to:i}=l:(e=Math.min(l.from,e),i=Math.max(l.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&wl(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new FM(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=Ab(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.flags|=4),t.type=="childList"){let i=Mp(e,t.previousSibling||t.target.previousSibling,-1),s=Mp(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(cn)!=t.state.facet(cn)&&(t.view.contentDOM.editContext=t.state.facet(cn)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.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 Mp(n,t,e){for(;t;){let i=jt.get(t);if(i&&i.parent==n)return i;let s=t.parentNode;t=s!=n.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function Ap(n,t){let e=t.startContainer,i=t.startOffset,s=t.endContainer,r=t.endOffset,l=n.docView.domAtPos(n.state.selection.main.anchor);return Fr(l.node,l.offset,s,r)&&([e,i,s,r]=[s,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}}function SA(n,t){if(t.getComposedRanges){let s=t.getComposedRanges(n.root)[0];if(s)return Ap(n,s)}let e=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),e=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),e?Ap(n,e):null}class wA{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let s=t.state.selection.main,{anchor:r,head:l}=s,h=this.toEditorPos(i.updateRangeStart),c=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:h,drifted:!1});let g={from:h,to:c,insert:A.Text.of(i.text.split(`
18
- `))};if(g.from==this.from&&r<this.from?g.from=r:g.to==this.to&&r>this.to&&(g.to=r),g.from==g.to&&!g.insert.length){let p=A.EditorSelection.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));p.main.eq(s)||t.dispatch({selection:p,userEvent:"select"});return}if((dt.mac||dt.android)&&g.from==l-1&&/^\. ?$/.test(i.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(g={from:h,to:c,insert:A.Text.of([i.text.replace("."," ")])}),this.pendingContextChange=g,!t.state.readOnly){let p=this.to-this.from+(g.to-g.from+g.insert.length);pf(t,g,A.EditorSelection.single(this.toEditorPos(i.selectionStart,p),this.toEditorPos(i.selectionEnd,p)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state))},this.handlers.characterboundsupdate=i=>{let s=[],r=null;for(let l=this.toEditorPos(i.rangeStart),h=this.toEditorPos(i.rangeEnd);l<h;l++){let c=t.coordsForChar(l);r=c&&new DOMRect(c.left,c.top,c.right-c.left,c.bottom-c.top)||r||new DOMRect,s.push(r)}e.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let r of i.getTextFormats()){let l=r.underlineStyle,h=r.underlineThickness;if(l!="None"&&h!="None"){let c=this.toEditorPos(r.rangeStart),g=this.toEditorPos(r.rangeEnd);if(c<g){let p=`text-decoration: underline ${l=="Dashed"?"dashed ":l=="Squiggle"?"wavy ":""}${h=="Thin"?1:2}px`;s.push($t.mark({attributes:{style:p}}).range(c,g))}}}t.dispatch({effects:yb.of($t.set(s))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(t.state)}};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=Kr(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((r,l,h,c,g)=>{if(i)return;let p=g.length-(l-r);if(s&&l>=s.to)if(s.from==r&&s.to==l&&s.insert.eq(g)){s=this.pendingContextChange=null,e+=p,this.to+=p;return}else s=null,this.revertPending(t.state);if(r+=e,l+=e,l<=this.from)this.from+=p,this.to+=p;else if(r<this.to){if(r<this.from||l>this.to||this.to-this.from+g.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(l),g.toString()),this.to+=p}e+=p}),s&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class At{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(s=>s.forEach(r=>i(r,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=t.root||tM(t.parent)||document,this.viewState=new kp(t.state||A.EditorState.create(t)),t.scrollTo&&t.scrollTo.is(Xo)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Dr).map(s=>new ah(s));for(let s of this.plugins)s.update(this);this.observer=new yA(this),this.inputState=new WM(this),this.inputState.ensureHandlers(this.plugins),this.docView=new sp(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...t){let e=t.length==1&&t[0]instanceof A.Transaction?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,r=this.state;for(let x of t){if(x.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=x.state}if(this.destroyed){this.viewState.state=r;return}let l=this.hasFocus,h=0,c=null;t.some(x=>x.annotation(Rb))?(this.inputState.notifiedFocused=l,h=1):l!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=l,c=Bb(r,l),c||(h=1));let g=this.observer.delayedAndroidKey,p=null;if(g?(this.observer.clearDelayedAndroidKey(),p=this.observer.readChange(),(p&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(p=null)):this.observer.clear(),r.facet(A.EditorState.phrases)!=this.state.facet(A.EditorState.phrases))return this.setState(r);s=Fl.create(this,r,t),s.flags|=h;let y=this.viewState.scrollTarget;try{this.updateState=2;for(let x of t){if(y&&(y=y.map(x.changes)),x.scrollIntoView){let{main:T}=x.state.selection;y=new Bs(T.empty?T:A.EditorSelection.cursor(T.head,T.head>T.anchor?-1:1))}for(let T of x.effects)T.is(Xo)&&(y=T.value.clip(this.state))}this.viewState.update(s,y),this.bidiCache=Hl.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(Or)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(x=>x.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(il)!=s.state.facet(il)&&(this.viewState.mustMeasureContent=!0),(e||i||y||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!s.empty)for(let x of this.state.facet(Cc))try{x(s)}catch(T){Gi(this.state,T,"update listener")}(c||p)&&Promise.resolve().then(()=>{c&&this.state==c.startState&&this.dispatch(c),p&&!Ab(this,p)&&g.force&&Rs(this.contentDOM,g.key,g.keyCode)})}setState(t){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=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new kp(t),this.plugins=t.facet(Dr).map(i=>new ah(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new sp(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(Dr),i=t.state.facet(Dr);if(e!=i){let s=[];for(let r of i){let l=e.indexOf(r);if(l<0)s.push(new ah(r));else{let h=this.plugins[l];h.mustUpdate=t,s.push(h)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){Gi(this.state,i,"doc view update listener")}}}measure(t=!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,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:l}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(l=-1),this.viewState.scrollAnchorHeight=-1;try{for(let h=0;;h++){if(l<0)if(G0(i))r=-1,l=this.viewState.heightMap.height;else{let T=this.viewState.scrollAnchorAt(s);r=T.from,l=T.top}this.updateState=1;let c=this.viewState.measure(this);if(!c&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(h>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let g=[];c&4||([this.measureRequests,g]=[g,this.measureRequests]);let p=g.map(T=>{try{return T.read(this)}catch(P){return Gi(this.state,P),Tp}}),y=Fl.create(this,this.state,[]),x=!1;y.flags|=c,e?e.flags|=c:e=y,this.updateState=2,y.empty||(this.updatePlugins(y),this.inputState.update(y),this.updateAttrs(),x=this.docView.update(y),x&&this.docViewUpdate());for(let T=0;T<g.length;T++)if(p[T]!=Tp)try{let P=g[T];P.write&&P.write(p[T],this)}catch(P){Gi(this.state,P)}if(x&&this.docView.updateSelection(!0),!y.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,l=-1;continue}else{let P=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-l;if(P>1||P<-1){s=s+P,i.scrollTop=s/this.scaleY,l=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let h of this.state.facet(Cc))h(e)}get themeClasses(){return Dc+" "+(this.state.facet(Tc)?Ib:Fb)+" "+this.state.facet(il)}updateAttrs(){let t=Dp(this,Sb,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(cn)?"true":"false",class:"cm-content",style:`${dt.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),Dp(this,df,e);let i=this.observer.ignore(()=>{let s=Sc(this.contentDOM,this.contentAttrs,e),r=Sc(this.dom,this.editorAttrs,t);return s||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(At.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Or);let t=this.state.facet(At.cspNonce);Le.mount(this.root,this.styleModules.concat(mA).reverse(),t?{nonce:t}: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(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.spec==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return ch(this,t,hp(this,t,e,i))}moveByGroup(t,e){return ch(this,t,hp(this,t,e,i=>RM(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return A.EditorSelection.cursor(r.side(e,s)+t.from,r.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return PM(this,t,e,i)}moveVertically(t,e,i){return ch(this,t,BM(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),Mb(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),r=this.bidiSpans(s),l=r[Ln.find(r,t-s.from,-1,e)];return la(i,l.dir==Ae.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(mb)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>xA)return ab(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||lb(r.isolates,i=np(this,t))))return r.order;i||(i=np(this,t));let s=uM(t.text,e,i);return this.bidiCache.push(new Hl(t.from,t.to,e,i,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||dt.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{j0(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return Xo.of(new Bs(typeof t=="number"?A.EditorSelection.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Xo.of(new Bs(A.EditorSelection.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return Ji.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return Ji.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=Le.newName(),s=[il.of(i),Or.of(Oc(`.${i}`,t))];return e&&e.dark&&s.push(Tc.of(!0)),s}static baseTheme(t){return A.Prec.lowest(Or.of(Oc("."+Dc,t,Hb)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&jt.get(i)||jt.get(t);return((e=s==null?void 0:s.rootView)===null||e===void 0?void 0:e.view)||null}}At.styleModule=Or;At.inputHandler=pb;At.clipboardInputFilter=cf;At.clipboardOutputFilter=ff;At.scrollHandler=bb;At.focusChangeEffect=gb;At.perLineTextDirection=mb;At.exceptionSink=ub;At.updateListener=Cc;At.editable=cn;At.mouseSelectionStyle=db;At.dragMovesSelection=fb;At.clickAddsSelectionRange=cb;At.decorations=_r;At.outerDecorations=wb;At.atomicRanges=uf;At.bidiIsolatedRanges=xb;At.scrollMargins=vb;At.darkTheme=Tc;At.cspNonce=A.Facet.define({combine:n=>n.length?n[0]:""});At.contentAttributes=df;At.editorAttributes=Sb;At.lineWrapping=At.contentAttributes.of({class:"cm-lineWrapping"});At.announce=A.StateEffect.define();const xA=4096,Tp={};class Hl{constructor(t,e,i,s,r,l){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=r,this.order=l}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:Ae.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let l=t[r];l.dir==s&&!e.touchesRange(l.from,l.to)&&i.push(new Hl(e.mapPos(l.from,1),e.mapPos(l.to,-1),l.dir,l.isolates,!1,l.order))}return i}}function Dp(n,t,e){for(let i=n.state.facet(t),s=i.length-1;s>=0;s--){let r=i[s],l=typeof r=="function"?r(n):r;l&&yc(l,e)}return e}const vA=dt.mac?"mac":dt.windows?"win":dt.linux?"linux":"key";function kA(n,t){const e=n.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let s,r,l,h;for(let c=0;c<e.length-1;++c){const g=e[c];if(/^(cmd|meta|m)$/i.test(g))h=!0;else if(/^a(lt)?$/i.test(g))s=!0;else if(/^(c|ctrl|control)$/i.test(g))r=!0;else if(/^s(hift)?$/i.test(g))l=!0;else if(/^mod$/i.test(g))t=="mac"?h=!0:r=!0;else throw new Error("Unrecognized modifier name: "+g)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),h&&(i="Meta-"+i),l&&(i="Shift-"+i),i}function nl(n,t,e){return t.altKey&&(n="Alt-"+n),t.ctrlKey&&(n="Ctrl-"+n),t.metaKey&&(n="Meta-"+n),e!==!1&&t.shiftKey&&(n="Shift-"+n),n}const CA=A.Prec.default(At.domEventHandlers({keydown(n,t){return $b(Vb(t.state),n,t,"editor")}})),MA=A.Facet.define({enables:CA}),Op=new WeakMap;function Vb(n){let t=n.facet(MA),e=Op.get(t);return e||Op.set(t,e=DA(t.reduce((i,s)=>i.concat(s),[]))),e}function AA(n,t,e){return $b(Vb(n.state),t,n,e)}let Rn=null;const TA=4e3;function DA(n,t=vA){let e=Object.create(null),i=Object.create(null),s=(l,h)=>{let c=i[l];if(c==null)i[l]=h;else if(c!=h)throw new Error("Key binding "+l+" is used both as a regular binding and as a multi-stroke prefix")},r=(l,h,c,g,p)=>{var y,x;let T=e[l]||(e[l]=Object.create(null)),P=h.split(/ (?!$)/).map(W=>kA(W,t));for(let W=1;W<P.length;W++){let U=P.slice(0,W).join(" ");s(U,!0),T[U]||(T[U]={preventDefault:!0,stopPropagation:!1,run:[ot=>{let Q=Rn={view:ot,prefix:U,scope:l};return setTimeout(()=>{Rn==Q&&(Rn=null)},TA),!0}]})}let I=P.join(" ");s(I,!1);let z=T[I]||(T[I]={preventDefault:!1,stopPropagation:!1,run:((x=(y=T._any)===null||y===void 0?void 0:y.run)===null||x===void 0?void 0:x.slice())||[]});c&&z.run.push(c),g&&(z.preventDefault=!0),p&&(z.stopPropagation=!0)};for(let l of n){let h=l.scope?l.scope.split(" "):["editor"];if(l.any)for(let g of h){let p=e[g]||(e[g]=Object.create(null));p._any||(p._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:y}=l;for(let x in p)p[x].run.push(T=>y(T,Ec))}let c=l[t]||l.key;if(c)for(let g of h)r(g,c,l.run,l.preventDefault,l.stopPropagation),l.shift&&r(g,"Shift-"+c,l.shift,l.preventDefault,l.stopPropagation)}return e}let Ec=null;function $b(n,t,e,i){Ec=t;let s=pg(t),r=A.codePointAt(s,0),l=A.codePointSize(r)==s.length&&s!=" ",h="",c=!1,g=!1,p=!1;Rn&&Rn.view==e&&Rn.scope==i&&(h=Rn.prefix+" ",Db.indexOf(t.keyCode)<0&&(g=!0,Rn=null));let y=new Set,x=z=>{if(z){for(let W of z.run)if(!y.has(W)&&(y.add(W),W(e)))return z.stopPropagation&&(p=!0),!0;z.preventDefault&&(z.stopPropagation&&(p=!0),g=!0)}return!1},T=n[i],P,I;return T&&(x(T[h+nl(s,t,!l)])?c=!0:l&&(t.altKey||t.metaKey||t.ctrlKey)&&!(dt.windows&&t.ctrlKey&&t.altKey)&&(P=gg[t.keyCode])&&P!=s?(x(T[h+nl(P,t,!0)])||t.shiftKey&&(I=mg[t.keyCode])!=s&&I!=P&&x(T[h+nl(I,t,!1)]))&&(c=!0):l&&t.shiftKey&&x(T[h+nl(s,t,!0)])&&(c=!0),!c&&x(T._any)&&(c=!0)),g&&(c=!0),c&&p&&t.stopPropagation(),Ec=null,c}const OA=!(dt.ios&&dt.webkit&&dt.webkit_version<534),Ep={".cm-line":{},".cm-content":{}};OA&&(Ep[".cm-line"].caretColor=Ep[".cm-content"].caretColor="transparent !important");const Pp=A.Facet.define({combine(n){let t,e;for(let i of n)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function Vl(n,t){let e=n.plugin(Wb),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}const Wb=Ji.fromClass(class{constructor(n){this.input=n.state.facet($l),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(n));let t=n.state.facet(Pp);this.top=new sl(n,!0,t.topContainer),this.bottom=new sl(n,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(n){let t=n.state.facet(Pp);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new sl(n.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new sl(n.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=n.state.facet($l);if(e!=this.input){let i=e.filter(c=>c),s=[],r=[],l=[],h=[];for(let c of i){let g=this.specs.indexOf(c),p;g<0?(p=c(n.view),h.push(p)):(p=this.panels[g],p.update&&p.update(n)),s.push(p),(p.top?r:l).push(p)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(l);for(let c of h)c.dom.classList.add("cm-panel"),c.mount&&c.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>At.scrollMargins.of(t=>{let e=t.plugin(n);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});class sl{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(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 e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=Rp(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Rp(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function Rp(n){let t=n.nextSibling;return n.remove(),t}const $l=A.Facet.define({enables:Wb});class js extends A.RangeValue{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}js.prototype.elementClass="";js.prototype.toDOM=void 0;js.prototype.mapMode=A.MapMode.TrackBefore;js.prototype.startSide=js.prototype.endSide=-1;js.prototype.point=!0;const Bp=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class _s{constructor(t,e,i=0,s=t.length,r,l){this.test=l,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,s),this.bufferStart=i,this.normalize=r?h=>r(Bp(h)):Bp,this.query=this.normalize(e)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return A.codePointAt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=A.fromCodePoint(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=A.codePointSize(t);let s=this.normalize(e);for(let r=0,l=i;;r++){let h=s.charCodeAt(r),c=this.match(h,l,this.bufferPos+this.bufferStart);if(r==s.length-1){if(c)return this.value=c,this;break}l==i&&r<e.length&&e.charCodeAt(r)==h&&l++}}}match(t,e,i){let s=null;for(let r=0;r<this.matches.length;r+=2){let l=this.matches[r],h=!1;this.query.charCodeAt(l)==t&&(l==this.query.length-1?s={from:this.matches[r+1],to:i}:(this.matches[r]++,h=!0)),h||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?s={from:e,to:i}:this.matches.push(1,e)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(_s.prototype[Symbol.iterator]=function(){return this});const zb={from:-1,to:-1,match:/.*/.exec("")},bf="gm"+(/x/.unicode==null?"":"u");class qb{constructor(t,e,i,s=0,r=t.length){if(this.text=t,this.to=r,this.curLine="",this.done=!1,this.value=zb,/\\[sWDnr]|\n|\r|\[\^/.test(e))return new Kb(t,e,i,s,r);this.re=new RegExp(e,bf+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.iter=t.iter();let l=t.lineAt(s);this.curLineStart=l.from,this.matchPos=Wl(t,s),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),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 t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,s=i+e[0].length;if(this.matchPos=Wl(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,e)))return this.value={from:i,to:s,match:e},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const uh=new WeakMap;class Ls{constructor(t,e){this.from=t,this.text=e}get to(){return this.from+this.text.length}static get(t,e,i){let s=uh.get(t);if(!s||s.from>=i||s.to<=e){let h=new Ls(e,t.sliceString(e,i));return uh.set(t,h),h}if(s.from==e&&s.to==i)return s;let{text:r,from:l}=s;return l>e&&(r=t.sliceString(e,l)+r,l=e),s.to<i&&(r+=t.sliceString(s.to,i)),uh.set(t,new Ls(l,r)),new Ls(e,r.slice(e-l,i-l))}}class Kb{constructor(t,e,i,s,r){this.text=t,this.to=r,this.done=!1,this.value=zb,this.matchPos=Wl(t,s),this.re=new RegExp(e,bf+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=Ls.get(t,s,this.chunkEnd(s+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e){let i=this.flat.from+e.index,s=i+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,s,e)))return this.value={from:i,to:s,match:e},this.matchPos=Wl(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Ls.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(qb.prototype[Symbol.iterator]=Kb.prototype[Symbol.iterator]=function(){return this});function EA(n){try{return new RegExp(n,bf),!0}catch{return!1}}function Wl(n,t){if(t>=n.length)return t;let e=n.lineAt(t),i;for(;t<e.to&&(i=e.text.charCodeAt(t-e.from))>=56320&&i<57344;)t++;return t}function Pc(n){let t=String(n.state.doc.lineAt(n.state.selection.main.head).number),e=Ut("input",{class:"cm-textfield",name:"line",value:t}),i=Ut("form",{class:"cm-gotoLine",onkeydown:r=>{r.keyCode==27?(r.preventDefault(),n.dispatch({effects:zl.of(!1)}),n.focus()):r.keyCode==13&&(r.preventDefault(),s())},onsubmit:r=>{r.preventDefault(),s()}},Ut("label",n.state.phrase("Go to line"),": ",e)," ",Ut("button",{class:"cm-button",type:"submit"},n.state.phrase("go")));function s(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!r)return;let{state:l}=n,h=l.doc.lineAt(l.selection.main.head),[,c,g,p,y]=r,x=p?+p.slice(1):0,T=g?+g:h.number;if(g&&y){let z=T/100;c&&(z=z*(c=="-"?-1:1)+h.number/l.doc.lines),T=Math.round(l.doc.lines*z)}else g&&c&&(T=T*(c=="-"?-1:1)+h.number);let P=l.doc.line(Math.max(1,Math.min(l.doc.lines,T))),I=A.EditorSelection.cursor(P.from+Math.max(0,Math.min(x,P.length)));n.dispatch({effects:[zl.of(!1),At.scrollIntoView(I.from,{y:"center"})],selection:I}),n.focus()}return{dom:i}}const zl=A.StateEffect.define(),Lp=A.StateField.define({create(){return!0},update(n,t){for(let e of t.effects)e.is(zl)&&(n=e.value);return n},provide:n=>$l.from(n,t=>t?Pc:null)}),PA=n=>{let t=Vl(n,Pc);if(!t){let e=[zl.of(!0)];n.state.field(Lp,!1)==null&&e.push(A.StateEffect.appendConfig.of([Lp,RA])),n.dispatch({effects:e}),t=Vl(n,Pc)}return t&&t.dom.querySelector("input").select(),!0},RA=At.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),BA={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},LA=A.Facet.define({combine(n){return A.combineConfig(n,BA,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})}});function NA(n){return[$A,VA]}const FA=$t.mark({class:"cm-selectionMatch"}),IA=$t.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Np(n,t,e,i){return(e==0||n(t.sliceDoc(e-1,e))!=A.CharCategory.Word)&&(i==t.doc.length||n(t.sliceDoc(i,i+1))!=A.CharCategory.Word)}function HA(n,t,e,i){return n(t.sliceDoc(e,e+1))==A.CharCategory.Word&&n(t.sliceDoc(i-1,i))==A.CharCategory.Word}const VA=Ji.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.selectionSet||n.docChanged||n.viewportChanged)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let t=n.state.facet(LA),{state:e}=n,i=e.selection;if(i.ranges.length>1)return $t.none;let s=i.main,r,l=null;if(s.empty){if(!t.highlightWordAroundCursor)return $t.none;let c=e.wordAt(s.head);if(!c)return $t.none;l=e.charCategorizer(s.head),r=e.sliceDoc(c.from,c.to)}else{let c=s.to-s.from;if(c<t.minSelectionLength||c>200)return $t.none;if(t.wholeWords){if(r=e.sliceDoc(s.from,s.to),l=e.charCategorizer(s.head),!(Np(l,e,s.from,s.to)&&HA(l,e,s.from,s.to)))return $t.none}else if(r=e.sliceDoc(s.from,s.to),!r)return $t.none}let h=[];for(let c of n.visibleRanges){let g=new _s(e.doc,r,c.from,c.to);for(;!g.next().done;){let{from:p,to:y}=g.value;if((!l||Np(l,e,p,y))&&(s.empty&&p<=s.from&&y>=s.to?h.push(IA.range(p,y)):(p>=s.to||y<=s.from)&&h.push(FA.range(p,y)),h.length>t.maxMatches))return $t.none}}return $t.set(h)}},{decorations:n=>n.decorations}),$A=At.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),WA=({state:n,dispatch:t})=>{let{selection:e}=n,i=A.EditorSelection.create(e.ranges.map(s=>n.wordAt(s.head)||A.EditorSelection.cursor(s.head)),e.mainIndex);return i.eq(e)?!1:(t(n.update({selection:i})),!0)};function zA(n,t){let{main:e,ranges:i}=n.selection,s=n.wordAt(e.head),r=s&&s.from==e.from&&s.to==e.to;for(let l=!1,h=new _s(n.doc,t,i[i.length-1].to);;)if(h.next(),h.done){if(l)return null;h=new _s(n.doc,t,0,Math.max(0,i[i.length-1].from-1)),l=!0}else{if(l&&i.some(c=>c.from==h.value.from))continue;if(r){let c=n.wordAt(h.value.from);if(!c||c.from!=h.value.from||c.to!=h.value.to)continue}return h.value}}const qA=({state:n,dispatch:t})=>{let{ranges:e}=n.selection;if(e.some(r=>r.from===r.to))return WA({state:n,dispatch:t});let i=n.sliceDoc(e[0].from,e[0].to);if(n.selection.ranges.some(r=>n.sliceDoc(r.from,r.to)!=i))return!1;let s=zA(n,i);return s?(t(n.update({selection:n.selection.addRange(A.EditorSelection.range(s.from,s.to),!1),effects:At.scrollIntoView(s.to)})),!0):!1},Zs=A.Facet.define({combine(n){return A.combineConfig(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new eT(t),scrollToMatch:t=>At.scrollIntoView(t)})}});class jb{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||EA(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(e,i)=>i=="n"?`
19
- `:i=="r"?"\r":i=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord}create(){return this.regexp?new GA(this):new jA(this)}getCursor(t,e=0,i){let s=t.doc?t:A.EditorState.create({doc:t});return i==null&&(i=s.doc.length),this.regexp?Ms(this,s,e,i):Cs(this,s,e,i)}}class _b{constructor(t){this.spec=t}}function Cs(n,t,e,i){return new _s(t.doc,n.unquoted,e,i,n.caseSensitive?void 0:s=>s.toLowerCase(),n.wholeWord?KA(t.doc,t.charCategorizer(t.selection.main.head)):void 0)}function KA(n,t){return(e,i,s,r)=>((r>e||r+s.length<i)&&(r=Math.max(0,e-2),s=n.sliceString(r,Math.min(n.length,i+2))),(t(ql(s,e-r))!=A.CharCategory.Word||t(Kl(s,e-r))!=A.CharCategory.Word)&&(t(Kl(s,i-r))!=A.CharCategory.Word||t(ql(s,i-r))!=A.CharCategory.Word))}class jA extends _b{constructor(t){super(t)}nextMatch(t,e,i){let s=Cs(this.spec,t,i,t.doc.length).nextOverlapping();return s.done&&(s=Cs(this.spec,t,0,e).nextOverlapping()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=i;;){let r=Math.max(e,s-1e4-this.spec.unquoted.length),l=Cs(this.spec,t,r,s),h=null;for(;!l.nextOverlapping().done;)h=l.value;if(h)return h;if(r==e)return null;s-=1e4}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,e){let i=Cs(this.spec,t,0,t.doc.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=Cs(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function Ms(n,t,e,i){return new qb(t.doc,n.search,{ignoreCase:!n.caseSensitive,test:n.wholeWord?_A(t.charCategorizer(t.selection.main.head)):void 0},e,i)}function ql(n,t){return n.slice(A.findClusterBreak(n,t,!1),t)}function Kl(n,t){return n.slice(t,A.findClusterBreak(n,t))}function _A(n){return(t,e,i)=>!i[0].length||(n(ql(i.input,i.index))!=A.CharCategory.Word||n(Kl(i.input,i.index))!=A.CharCategory.Word)&&(n(Kl(i.input,i.index+i[0].length))!=A.CharCategory.Word||n(ql(i.input,i.index+i[0].length))!=A.CharCategory.Word)}class GA extends _b{nextMatch(t,e,i){let s=Ms(this.spec,t,i,t.doc.length).next();return s.done&&(s=Ms(this.spec,t,0,e).next()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=1;;s++){let r=Math.max(e,i-s*1e4),l=Ms(this.spec,t,r,i),h=null;for(;!l.next().done;)h=l.value;if(h&&(r==e||h.from>r+10))return h;if(r==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,(e,i)=>i=="$"?"$":i=="&"?t.match[0]:i!="0"&&+i<t.match.length?t.match[i]:e)}matchAll(t,e){let i=Ms(this.spec,t,0,t.doc.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=Ms(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const Gr=A.StateEffect.define(),yf=A.StateEffect.define(),In=A.StateField.define({create(n){return new ph(Rc(n).create(),null)},update(n,t){for(let e of t.effects)e.is(Gr)?n=new ph(e.value.create(),n.panel):e.is(yf)&&(n=new ph(n.query,e.value?Sf:null));return n},provide:n=>$l.from(n,t=>t.panel)});class ph{constructor(t,e){this.query=t,this.panel=e}}const YA=$t.mark({class:"cm-searchMatch"}),UA=$t.mark({class:"cm-searchMatch cm-searchMatch-selected"}),XA=Ji.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(In))}update(n){let t=n.state.field(In);(t!=n.startState.field(In)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:n,panel:t}){if(!t||!n.spec.valid)return $t.none;let{view:e}=this,i=new A.RangeSetBuilder;for(let s=0,r=e.visibleRanges,l=r.length;s<l;s++){let{from:h,to:c}=r[s];for(;s<l-1&&c>r[s+1].from-2*250;)c=r[++s].to;n.highlight(e.state,h,c,(g,p)=>{let y=e.state.selection.ranges.some(x=>x.from==g&&x.to==p);i.add(g,p,y?UA:YA)})}return i.finish()}},{decorations:n=>n.decorations});function ro(n){return t=>{let e=t.state.field(In,!1);return e&&e.query.spec.valid?n(t,e):Ub(t)}}const jl=ro((n,{query:t})=>{let{to:e}=n.state.selection.main,i=t.nextMatch(n.state,e,e);if(!i)return!1;let s=A.EditorSelection.single(i.from,i.to),r=n.state.facet(Zs);return n.dispatch({selection:s,effects:[wf(n,i),r.scrollToMatch(s.main,n)],userEvent:"select.search"}),Yb(n),!0}),_l=ro((n,{query:t})=>{let{state:e}=n,{from:i}=e.selection.main,s=t.prevMatch(e,i,i);if(!s)return!1;let r=A.EditorSelection.single(s.from,s.to),l=n.state.facet(Zs);return n.dispatch({selection:r,effects:[wf(n,s),l.scrollToMatch(r.main,n)],userEvent:"select.search"}),Yb(n),!0}),JA=ro((n,{query:t})=>{let e=t.matchAll(n.state,1e3);return!e||!e.length?!1:(n.dispatch({selection:A.EditorSelection.create(e.map(i=>A.EditorSelection.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),QA=({state:n,dispatch:t})=>{let e=n.selection;if(e.ranges.length>1||e.main.empty)return!1;let{from:i,to:s}=e.main,r=[],l=0;for(let h=new _s(n.doc,n.sliceDoc(i,s));!h.next().done;){if(r.length>1e3)return!1;h.value.from==i&&(l=r.length),r.push(A.EditorSelection.range(h.value.from,h.value.to))}return t(n.update({selection:A.EditorSelection.create(r,l),userEvent:"select.search.matches"})),!0},Fp=ro((n,{query:t})=>{let{state:e}=n,{from:i,to:s}=e.selection.main;if(e.readOnly)return!1;let r=t.nextMatch(e,i,i);if(!r)return!1;let l=[],h,c,g=[];if(r.from==i&&r.to==s&&(c=e.toText(t.getReplacement(r)),l.push({from:r.from,to:r.to,insert:c}),r=t.nextMatch(e,r.from,r.to),g.push(At.announce.of(e.phrase("replaced match on line $",e.doc.lineAt(i).number)+"."))),r){let p=l.length==0||l[0].from>=r.to?0:r.to-r.from-c.length;h=A.EditorSelection.single(r.from-p,r.to-p),g.push(wf(n,r)),g.push(e.facet(Zs).scrollToMatch(h.main,n))}return n.dispatch({changes:l,selection:h,effects:g,userEvent:"input.replace"}),!0}),ZA=ro((n,{query:t})=>{if(n.state.readOnly)return!1;let e=t.matchAll(n.state,1e9).map(s=>{let{from:r,to:l}=s;return{from:r,to:l,insert:t.getReplacement(s)}});if(!e.length)return!1;let i=n.state.phrase("replaced $ matches",e.length)+".";return n.dispatch({changes:e,effects:At.announce.of(i),userEvent:"input.replace.all"}),!0});function Sf(n){return n.state.facet(Zs).createPanel(n)}function Rc(n,t){var e,i,s,r,l;let h=n.selection.main,c=h.empty||h.to>h.from+100?"":n.sliceDoc(h.from,h.to);if(t&&!c)return t;let g=n.facet(Zs);return new jb({search:((e=t==null?void 0:t.literal)!==null&&e!==void 0?e:g.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(i=t==null?void 0:t.caseSensitive)!==null&&i!==void 0?i:g.caseSensitive,literal:(s=t==null?void 0:t.literal)!==null&&s!==void 0?s:g.literal,regexp:(r=t==null?void 0:t.regexp)!==null&&r!==void 0?r:g.regexp,wholeWord:(l=t==null?void 0:t.wholeWord)!==null&&l!==void 0?l:g.wholeWord})}function Gb(n){let t=Vl(n,Sf);return t&&t.dom.querySelector("[main-field]")}function Yb(n){let t=Gb(n);t&&t==n.root.activeElement&&t.select()}const Ub=n=>{let t=n.state.field(In,!1);if(t&&t.panel){let e=Gb(n);if(e&&e!=n.root.activeElement){let i=Rc(n.state,t.query.spec);i.valid&&n.dispatch({effects:Gr.of(i)}),e.focus(),e.select()}}else n.dispatch({effects:[yf.of(!0),t?Gr.of(Rc(n.state,t.query.spec)):A.StateEffect.appendConfig.of(nT)]});return!0},Xb=n=>{let t=n.state.field(In,!1);if(!t||!t.panel)return!1;let e=Vl(n,Sf);return e&&e.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:yf.of(!1)}),!0},tT=[{key:"Mod-f",run:Ub,scope:"editor search-panel"},{key:"F3",run:jl,shift:_l,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:jl,shift:_l,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Xb,scope:"editor search-panel"},{key:"Mod-Shift-l",run:QA},{key:"Mod-Alt-g",run:PA},{key:"Mod-d",run:qA,preventDefault:!0}];class eT{constructor(t){this.view=t;let e=this.query=t.state.field(In).query.spec;this.commit=this.commit.bind(this),this.searchField=Ut("input",{value:e.search,placeholder:li(t,"Find"),"aria-label":li(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Ut("input",{value:e.replace,placeholder:li(t,"Replace"),"aria-label":li(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Ut("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=Ut("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=Ut("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit});function i(s,r,l){return Ut("button",{class:"cm-button",name:s,onclick:r,type:"button"},l)}this.dom=Ut("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>jl(t),[li(t,"next")]),i("prev",()=>_l(t),[li(t,"previous")]),i("select",()=>JA(t),[li(t,"all")]),Ut("label",null,[this.caseField,li(t,"match case")]),Ut("label",null,[this.reField,li(t,"regexp")]),Ut("label",null,[this.wordField,li(t,"by word")]),...t.state.readOnly?[]:[Ut("br"),this.replaceField,i("replace",()=>Fp(t),[li(t,"replace")]),i("replaceAll",()=>ZA(t),[li(t,"replace all")])],Ut("button",{name:"close",onclick:()=>Xb(t),"aria-label":li(t,"close"),type:"button"},["×"])])}commit(){let t=new jb({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:Gr.of(t)}))}keydown(t){AA(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?_l:jl)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),Fp(this.view))}update(t){for(let e of t.transactions)for(let i of e.effects)i.is(Gr)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Zs).top}}function li(n,t){return n.state.phrase(t)}const rl=30,ol=/[\s\.,:;?!]/;function wf(n,{from:t,to:e}){let i=n.state.doc.lineAt(t),s=n.state.doc.lineAt(e).to,r=Math.max(i.from,t-rl),l=Math.min(s,e+rl),h=n.state.sliceDoc(r,l);if(r!=i.from){for(let c=0;c<rl;c++)if(!ol.test(h[c+1])&&ol.test(h[c])){h=h.slice(c);break}}if(l!=s){for(let c=h.length-1;c>h.length-rl;c--)if(!ol.test(h[c-1])&&ol.test(h[c])){h=h.slice(0,c);break}}return At.announce.of(`${n.state.phrase("current match")}. ${h} ${n.state.phrase("on line")} ${i.number}.`)}const iT=At.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"}}),nT=[In,A.Prec.low(XA),iT];class Jb{constructor(t,e,i){this.state=t,this.pos=e,this.explicit=i,this.abortListeners=[]}tokenBefore(t){let e=ie(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),s=e.text.slice(i-e.from,this.pos-e.from),r=s.search(Zb(t,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(t,e){t=="abort"&&this.abortListeners&&this.abortListeners.push(e)}}function Ip(n){let t=Object.keys(n).join(""),e=/\w/.test(t);return e&&(t=t.replace(/\w/g,"")),`[${e?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function sT(n){let t=Object.create(null),e=Object.create(null);for(let{label:s}of n){t[s[0]]=!0;for(let r=1;r<s.length;r++)e[s[r]]=!0}let i=Ip(t)+Ip(e)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function xf(n){let t=n.map(s=>typeof s=="string"?{label:s}:s),[e,i]=t.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:sT(t);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:t,validFor:e}:null}}function Qb(n,t){return e=>{for(let i=ie(e.state).resolveInner(e.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return t(e)}}class Hp{constructor(t,e,i,s){this.completion=t,this.source=e,this.match=i,this.score=s}}function Hn(n){return n.selection.main.from}function Zb(n,t){var e;let{source:i}=n,s=t&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(e=n.flags)!==null&&e!==void 0?e:n.ignoreCase?"i":"")}const ty=A.Annotation.define();function rT(n,t,e,i){let{main:s}=n.selection,r=e-s.from,l=i-s.from;return Object.assign(Object.assign({},n.changeByRange(h=>h!=s&&e!=i&&n.sliceDoc(h.from+r,h.from+l)!=n.sliceDoc(e,i)?{range:h}:{changes:{from:h.from+r,to:i==s.from?h.to:h.from+l,insert:t},range:A.EditorSelection.cursor(h.from+r+t.length)})),{scrollIntoView:!0,userEvent:"input.complete"})}const Vp=new WeakMap;function oT(n){if(!Array.isArray(n))return n;let t=Vp.get(n);return t||Vp.set(n,t=xf(n)),t}const Gl=A.StateEffect.define(),Yr=A.StateEffect.define();class lT{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e<t.length;){let i=A.codePointAt(t,e),s=A.codePointSize(i);this.chars.push(i);let r=t.slice(e,e+s),l=r.toUpperCase();this.folded.push(A.codePointAt(l==r?r.toLowerCase():l,0)),e+=s}this.astral=t.length!=this.chars.length}ret(t,e){return this.score=t,this.matched=e,!0}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return!1;let{chars:e,folded:i,any:s,precise:r,byWord:l}=this;if(e.length==1){let U=A.codePointAt(t,0),ot=A.codePointSize(U),Q=ot==t.length?0:-100;if(U!=e[0])if(U==i[0])Q+=-200;else return!1;return this.ret(Q,[0,ot])}let h=t.indexOf(this.pattern);if(h==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=e.length,g=0;if(h<0){for(let U=0,ot=Math.min(t.length,200);U<ot&&g<c;){let Q=A.codePointAt(t,U);(Q==e[g]||Q==i[g])&&(s[g++]=U),U+=A.codePointSize(Q)}if(g<c)return!1}let p=0,y=0,x=!1,T=0,P=-1,I=-1,z=/[a-z]/.test(t),W=!0;for(let U=0,ot=Math.min(t.length,200),Q=0;U<ot&&y<c;){let st=A.codePointAt(t,U);h<0&&(p<c&&st==e[p]&&(r[p++]=U),T<c&&(st==e[T]||st==i[T]?(T==0&&(P=U),I=U+1,T++):T=0));let at,wt=st<255?st>=48&&st<=57||st>=97&&st<=122?2:st>=65&&st<=90?1:0:(at=A.fromCodePoint(st))!=at.toLowerCase()?1:at!=at.toUpperCase()?2:0;(!U||wt==1&&z||Q==0&&wt!=0)&&(e[y]==st||i[y]==st&&(x=!0)?l[y++]=U:l.length&&(W=!1)),Q=wt,U+=A.codePointSize(st)}return y==c&&l[0]==0&&W?this.result(-100+(x?-200:0),l,t):T==c&&P==0?this.ret(-200-t.length+(I==t.length?0:-100),[0,I]):h>-1?this.ret(-700-t.length,[h,h+this.pattern.length]):T==c?this.ret(-900-t.length,[P,I]):y==c?this.result(-100+(x?-200:0)+-700+(W?0:-1100),l,t):e.length==2?!1:this.result((s[0]?-700:0)+-200+-1100,s,t)}result(t,e,i){let s=[],r=0;for(let l of e){let h=l+(this.astral?A.codePointSize(A.codePointAt(i,l)):1);r&&s[r-1]==l?s[r-1]=h:(s[r++]=l,s[r++]=h)}return this.ret(t-i.length,s)}}const Me=A.Facet.define({combine(n){return A.combineConfig(n,{activateOnTyping:!0,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:aT,compareCompletions:(t,e)=>t.label.localeCompare(e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>$p(t(i),e(i)),optionClass:(t,e)=>i=>$p(t(i),e(i)),addToOptions:(t,e)=>t.concat(e)})}});function $p(n,t){return n?t?n+" "+t:n:t}function aT(n,t,e,i,s,r){let l=n.textDirection==Qt.RTL,h=l,c=!1,g="top",p,y,x=t.left-s.left,T=s.right-t.right,P=i.right-i.left,I=i.bottom-i.top;if(h&&x<Math.min(P,T)?h=!1:!h&&T<Math.min(P,x)&&(h=!0),P<=(h?x:T))p=Math.max(s.top,Math.min(e.top,s.bottom-I))-t.top,y=Math.min(400,h?x:T);else{c=!0,y=Math.min(400,(l?t.right:s.right-t.left)-30);let U=s.bottom-t.bottom;U>=I||U>t.top?p=e.bottom-t.top:(g="bottom",p=t.bottom-e.top)}let z=(t.bottom-t.top)/r.offsetHeight,W=(t.right-t.left)/r.offsetWidth;return{style:`${g}: ${p/z}px; max-width: ${y/W}px`,class:"cm-completionInfo-"+(c?l?"left-narrow":"right-narrow":h?"left":"right")}}function hT(n){let t=n.addToOptions.slice();return n.icons&&t.push({render(e){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),e.type&&i.classList.add(...e.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),i.setAttribute("aria-hidden","true"),i},position:20}),t.push({render(e,i,s,r){let l=document.createElement("span");l.className="cm-completionLabel";let h=e.displayLabel||e.label,c=0;for(let g=0;g<r.length;){let p=r[g++],y=r[g++];p>c&&l.appendChild(document.createTextNode(h.slice(c,p)));let x=l.appendChild(document.createElement("span"));x.appendChild(document.createTextNode(h.slice(p,y))),x.className="cm-completionMatchedText",c=y}return c<h.length&&l.appendChild(document.createTextNode(h.slice(c))),l},position:50},{render(e){if(!e.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=e.detail,i},position:80}),t.sort((e,i)=>e.position-i.position).map(e=>e.render)}function gh(n,t,e){if(n<=e)return{from:0,to:n};if(t<0&&(t=0),t<=n>>1){let s=Math.floor(t/e);return{from:s*e,to:(s+1)*e}}let i=Math.floor((n-t)/e);return{from:n-(i+1)*e,to:n-i*e}}class cT{constructor(t,e,i){this.view=t,this.stateField=e,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:c=>this.placeInfo(c),key:this},this.space=null,this.currentClass="";let s=t.state.field(e),{options:r,selected:l}=s.open,h=t.state.facet(Me);this.optionContent=hT(h),this.optionClass=h.optionClass,this.tooltipClass=h.tooltipClass,this.range=gh(r.length,l,h.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",c=>{let{options:g}=t.state.field(e).open;for(let p=c.target,y;p&&p!=this.dom;p=p.parentNode)if(p.nodeName=="LI"&&(y=/-(\d+)$/.exec(p.id))&&+y[1]<g.length){this.applyCompletion(t,g[+y[1]]),c.preventDefault();return}}),this.dom.addEventListener("focusout",c=>{let g=t.state.field(this.stateField,!1);g&&g.tooltip&&t.state.facet(Me).closeOnBlur&&c.relatedTarget!=t.contentDOM&&t.dispatch({effects:Yr.of(null)})}),this.showOptions(r,s.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),s=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=s){let{options:r,selected:l,disabled:h}=i.open;(!s.open||s.open.options!=r)&&(this.range=gh(r.length,l,t.state.facet(Me).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),h!=((e=s.open)===null||e===void 0?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!h)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of e.split(" "))i&&this.dom.classList.add(i);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected>-1&&e.selected<this.range.from||e.selected>=this.range.to)&&(this.range=gh(e.options.length,e.selected,this.view.state.facet(Me).maxRenderedOptions),this.showOptions(e.options,t.id)),this.updateSelectedOption(e.selected)){this.destroyInfo();let{completion:i}=e.options[e.selected],{info:s}=i;if(!s)return;let r=typeof s=="string"?document.createTextNode(s):s(i);if(!r)return;"then"in r?r.then(l=>{l&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(l,i)}).catch(l=>$e(this.view.state,l,"completion info")):this.addInfoPane(r,i)}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",t.nodeType!=null)i.appendChild(t),this.infoDestroy=null;else{let{dom:s,destroy:r}=t;i.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)i.nodeName!="LI"||!i.id?s--:s==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return e&&dT(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=t.getBoundingClientRect(),r=this.space;if(!r){let l=this.dom.ownerDocument.defaultView||window;r={left:0,top:0,right:l.innerWidth,bottom:l.innerHeight}}return s.top>Math.min(r.bottom,e.bottom)-10||s.bottom<Math.max(r.top,e.top)+10?null:this.view.state.facet(Me).positionInfo(this.view,e,s,i,r,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,e,i){const s=document.createElement("ul");s.id=e,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions"));let r=null;for(let l=i.from;l<i.to;l++){let{completion:h,match:c}=t[l],{section:g}=h;if(g){let x=typeof g=="string"?g:g.name;if(x!=r&&(l>i.from||i.from==0))if(r=x,typeof g!="string"&&g.header)s.appendChild(g.header(g));else{let T=s.appendChild(document.createElement("completion-section"));T.textContent=x}}const p=s.appendChild(document.createElement("li"));p.id=e+"-"+l,p.setAttribute("role","option");let y=this.optionClass(h);y&&(p.className=y);for(let x of this.optionContent){let T=x(h,this.view.state,this.view,c);T&&p.appendChild(T)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<t.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function fT(n,t){return e=>new cT(e,n,t)}function dT(n,t){let e=n.getBoundingClientRect(),i=t.getBoundingClientRect(),s=e.height/n.offsetHeight;i.top<e.top?n.scrollTop-=(e.top-i.top)/s:i.bottom>e.bottom&&(n.scrollTop+=(i.bottom-e.bottom)/s)}function Wp(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function uT(n,t){let e=[],i=null,s=c=>{e.push(c);let{section:g}=c.completion;if(g){i||(i=[]);let p=typeof g=="string"?g:g.name;i.some(y=>y.name==p)||i.push(typeof g=="string"?{name:p}:g)}};for(let c of n)if(c.hasResult()){let g=c.result.getMatch;if(c.result.filter===!1)for(let p of c.result.options)s(new Hp(p,c.source,g?g(p):[],1e9-e.length));else{let p=new lT(t.sliceDoc(c.from,c.to));for(let y of c.result.options)if(p.match(y.label)){let x=y.displayLabel?g?g(y,p.matched):[]:p.matched;s(new Hp(y,c.source,x,p.score+(y.boost||0)))}}}if(i){let c=Object.create(null),g=0,p=(y,x)=>{var T,P;return((T=y.rank)!==null&&T!==void 0?T:1e9)-((P=x.rank)!==null&&P!==void 0?P:1e9)||(y.name<x.name?-1:1)};for(let y of i.sort(p))g-=1e5,c[y.name]=g;for(let y of e){let{section:x}=y.completion;x&&(y.score+=c[typeof x=="string"?x:x.name])}}let r=[],l=null,h=t.facet(Me).compareCompletions;for(let c of e.sort((g,p)=>p.score-g.score||h(g.completion,p.completion))){let g=c.completion;!l||l.label!=g.label||l.detail!=g.detail||l.type!=null&&g.type!=null&&l.type!=g.type||l.apply!=g.apply||l.boost!=g.boost?r.push(c):Wp(c.completion)>Wp(l)&&(r[r.length-1]=c),l=c.completion}return r}class Os{constructor(t,e,i,s,r,l){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=l}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new Os(this.options,zp(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,s,r){let l=uT(t,e);if(!l.length)return s&&t.some(c=>c.state==1)?new Os(s.options,s.attrs,s.tooltip,s.timestamp,s.selected,!0):null;let h=e.facet(Me).selectOnOpen?0:-1;if(s&&s.selected!=h&&s.selected!=-1){let c=s.options[s.selected].completion;for(let g=0;g<l.length;g++)if(l[g].completion==c){h=g;break}}return new Os(l,zp(i,h),{pos:t.reduce((c,g)=>g.hasResult()?Math.min(c,g.from):c,1e8),create:yT,above:r.aboveCursor},s?s.timestamp:Date.now(),h,!1)}map(t){return new Os(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class Yl{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new Yl(mT,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:e}=t,i=e.facet(Me),r=(i.override||e.languageDataAt("autocomplete",Hn(e)).map(oT)).map(h=>(this.active.find(g=>g.source==h)||new Xe(h,this.active.some(g=>g.state!=0)?1:0)).update(t,i));r.length==this.active.length&&r.every((h,c)=>h==this.active[c])&&(r=this.active);let l=this.open;l&&t.docChanged&&(l=l.map(t.changes)),t.selection||r.some(h=>h.hasResult()&&t.changes.touchesRange(h.from,h.to))||!pT(r,this.active)?l=Os.build(r,e,this.id,l,i):l&&l.disabled&&!r.some(h=>h.state==1)&&(l=null),!l&&r.every(h=>h.state!=1)&&r.some(h=>h.hasResult())&&(r=r.map(h=>h.hasResult()?new Xe(h.source,0):h));for(let h of t.effects)h.is(iy)&&(l=l&&l.setSelected(h.value,this.id));return r==this.active&&l==this.open?this:new Yl(r,this.id,l)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:gT}}function pT(n,t){if(n==t)return!0;for(let e=0,i=0;;){for(;e<n.length&&!n[e].hasResult;)e++;for(;i<t.length&&!t[i].hasResult;)i++;let s=e==n.length,r=i==t.length;if(s||r)return s==r;if(n[e++].result!=t[i++].result)return!1}}const gT={"aria-autocomplete":"list"};function zp(n,t){let e={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return t>-1&&(e["aria-activedescendant"]=n+"-"+t),e}const mT=[];function Bc(n){return n.isUserEvent("input.type")?"input":n.isUserEvent("delete.backward")?"delete":null}class Xe{constructor(t,e,i=-1){this.source=t,this.state=e,this.explicitPos=i}hasResult(){return!1}update(t,e){let i=Bc(t),s=this;i?s=s.handleUserEvent(t,i,e):t.docChanged?s=s.handleChange(t):t.selection&&s.state!=0&&(s=new Xe(s.source,0));for(let r of t.effects)if(r.is(Gl))s=new Xe(s.source,1,r.value?Hn(t.state):-1);else if(r.is(Yr))s=new Xe(s.source,0);else if(r.is(ey))for(let l of r.value)l.source==s.source&&(s=l);return s}handleUserEvent(t,e,i){return e=="delete"||!i.activateOnTyping?this.map(t.changes):new Xe(this.source,1)}handleChange(t){return t.changes.touchesRange(Hn(t.startState))?new Xe(this.source,0):this.map(t.changes)}map(t){return t.empty||this.explicitPos<0?this:new Xe(this.source,this.state,t.mapPos(this.explicitPos))}}class Ns extends Xe{constructor(t,e,i,s,r){super(t,2,e),this.result=i,this.from=s,this.to=r}hasResult(){return!0}handleUserEvent(t,e,i){var s;let r=t.changes.mapPos(this.from),l=t.changes.mapPos(this.to,1),h=Hn(t.state);if((this.explicitPos<0?h<=r:h<this.from)||h>l||e=="delete"&&Hn(t.startState)==this.from)return new Xe(this.source,e=="input"&&i.activateOnTyping?1:0);let c=this.explicitPos<0?-1:t.changes.mapPos(this.explicitPos),g;return bT(this.result.validFor,t.state,r,l)?new Ns(this.source,c,this.result,r,l):this.result.update&&(g=this.result.update(this.result,r,l,new Jb(t.state,h,c>=0)))?new Ns(this.source,c,g,g.from,(s=g.to)!==null&&s!==void 0?s:Hn(t.state)):new Xe(this.source,1,c)}handleChange(t){return t.changes.touchesRange(this.from,this.to)?new Xe(this.source,0):this.map(t.changes)}map(t){return t.empty?this:new Ns(this.source,this.explicitPos<0?-1:t.mapPos(this.explicitPos),this.result,t.mapPos(this.from),t.mapPos(this.to,1))}}function bT(n,t,e,i){if(!n)return!1;let s=t.sliceDoc(e,i);return typeof n=="function"?n(s,e,i,t):Zb(n,!0).test(s)}const ey=A.StateEffect.define({map(n,t){return n.map(e=>e.map(t))}}),iy=A.StateEffect.define(),hi=A.StateField.define({create(){return Yl.start()},update(n,t){return n.update(t)},provide:n=>[Yc.from(n,t=>t.tooltip),mt.contentAttributes.from(n,t=>t.attrs)]});function ny(n,t){const e=t.completion.apply||t.completion.label;let i=n.state.field(hi).active.find(s=>s.source==t.source);return i instanceof Ns?(typeof e=="string"?n.dispatch(Object.assign(Object.assign({},rT(n.state,e,i.from,i.to)),{annotations:ty.of(t.completion)})):e(n,t.completion,i.from,i.to),!0):!1}const yT=fT(hi,ny);function ll(n,t="option"){return e=>{let i=e.state.field(hi,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<e.state.facet(Me).interactionDelay)return!1;let s=1,r;t=="page"&&(r=Im(e,i.open.tooltip))&&(s=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:l}=i.open.options,h=i.open.selected>-1?i.open.selected+s*(n?1:-1):n?0:l-1;return h<0?h=t=="page"?0:l-1:h>=l&&(h=t=="page"?l-1:0),e.dispatch({effects:iy.of(h)}),!0}}const ST=n=>{let t=n.state.field(hi,!1);return n.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<n.state.facet(Me).interactionDelay?!1:ny(n,t.open.options[t.open.selected])},wT=n=>n.state.field(hi,!1)?(n.dispatch({effects:Gl.of(!0)}),!0):!1,xT=n=>{let t=n.state.field(hi,!1);return!t||!t.active.some(e=>e.state!=0)?!1:(n.dispatch({effects:Yr.of(null)}),!0)};class vT{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const kT=50,CT=1e3,MT=Te.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of n.state.field(hi).active)t.state==1&&this.startQuery(t)}update(n){let t=n.state.field(hi);if(!n.selectionSet&&!n.docChanged&&n.startState.field(hi)==t)return;let e=n.transactions.some(s=>(s.selection||s.docChanged)&&!Bc(s));for(let s=0;s<this.running.length;s++){let r=this.running[s];if(e||r.updates.length+n.transactions.length>kT&&Date.now()-r.time>CT){for(let l of r.context.abortListeners)try{l()}catch(h){$e(this.view.state,h)}r.context.abortListeners=null,this.running.splice(s--,1)}else r.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(s=>s.effects.some(r=>r.is(Gl)))&&(this.pendingStart=!0);let i=this.pendingStart?50:n.state.facet(Me).activateOnTypingDelay;if(this.debounceUpdate=t.active.some(s=>s.state==1&&!this.running.some(r=>r.active.source==s.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let s of n.transactions)Bc(s)=="input"?this.composing=2:this.composing==2&&s.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:n}=this.view,t=n.field(hi);for(let e of t.active)e.state==1&&!this.running.some(i=>i.active.source==e.source)&&this.startQuery(e)}startQuery(n){let{state:t}=this.view,e=Hn(t),i=new Jb(t,e,n.explicitPos==e),s=new vT(n,i);this.running.push(s),Promise.resolve(n.source(i)).then(r=>{s.context.aborted||(s.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:Yr.of(null)}),$e(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Me).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],e=this.view.state.facet(Me);for(let i=0;i<this.running.length;i++){let s=this.running[i];if(s.done===void 0)continue;if(this.running.splice(i--,1),s.done){let l=new Ns(s.active.source,s.active.explicitPos,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:Hn(s.updates.length?s.updates[0].startState:this.view.state));for(let h of s.updates)l=l.update(h,e);if(l.hasResult()){t.push(l);continue}}let r=this.view.state.field(hi).active.find(l=>l.source==s.active.source);if(r&&r.state==1)if(s.done==null){let l=new Xe(s.active.source,0);for(let h of s.updates)l=l.update(h,e);l.state!=1&&t.push(l)}else this.startQuery(r)}t.length&&this.view.dispatch({effects:ey.of(t)})}},{eventHandlers:{blur(n){let t=this.view.state.field(hi,!1);if(t&&t.tooltip&&this.view.state.facet(Me).closeOnBlur){let e=t.open&&Im(this.view,t.open.tooltip);(!e||!e.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Yr.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Gl.of(!1)}),20),this.composing=0}}}),sy=mt.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 AT=class{constructor(t,e,i,s){this.field=t,this.line=e,this.from=i,this.to=s}},TT=class ry{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,A.MapMode.TrackDel),i=t.mapPos(this.to,1,A.MapMode.TrackDel);return e==null||i==null?null:new ry(this.field,e,i)}},DT=class oy{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],s=[e],r=t.doc.lineAt(e),l=/^\s*/.exec(r.text)[0];for(let c of this.lines){if(i.length){let g=l,p=/^\t*/.exec(c)[0].length;for(let y=0;y<p;y++)g+=t.facet(Js);s.push(e+g.length-p),c=g+c.slice(p)}i.push(c),e+=c.length+1}let h=this.fieldPositions.map(c=>new TT(c.field,s[c.line]+c.from,s[c.line]+c.to));return{text:i,ranges:h}}static parse(t){let e=[],i=[],s=[],r;for(let l of t.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(l);){let h=r[1]?+r[1]:null,c=r[2]||r[3]||"",g=-1;for(let p=0;p<e.length;p++)(h!=null?e[p].seq==h:c&&e[p].name==c)&&(g=p);if(g<0){let p=0;for(;p<e.length&&(h==null||e[p].seq!=null&&e[p].seq<h);)p++;e.splice(p,0,{seq:h,name:c}),g=p;for(let y of s)y.field>=g&&y.field++}s.push(new AT(g,i.length,r.index,r.index+c.length)),l=l.slice(0,r.index)+c+l.slice(r.index+r[0].length)}for(let h;h=/\\([{}])/.exec(l);){l=l.slice(0,h.index)+h[1]+l.slice(h.index+h[0].length);for(let c of s)c.line==i.length&&c.from>h.index&&(c.from--,c.to--)}i.push(l)}return new oy(i,s)}},OT=kt.widget({widget:new class extends Bi{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),ET=kt.mark({class:"cm-snippetField"}),ca=class ly{constructor(t,e){this.ranges=t,this.active=e,this.deco=kt.set(t.map(i=>(i.from==i.to?OT:ET).range(i.from,i.to)))}map(t){let e=[];for(let i of this.ranges){let s=i.map(t);if(!s)return null;e.push(s)}return new ly(e,this.active)}selectionInsideField(t){return t.ranges.every(e=>this.ranges.some(i=>i.field==this.active&&i.from<=e.from&&i.to>=e.to))}};const oo=A.StateEffect.define({map(n,t){return n&&n.map(t)}}),PT=A.StateEffect.define(),Ur=A.StateField.define({create(){return null},update(n,t){for(let e of t.effects){if(e.is(oo))return e.value;if(e.is(PT)&&n)return new ca(n.ranges,e.value)}return n&&t.docChanged&&(n=n.map(t.changes)),n&&t.selection&&!n.selectionInsideField(t.selection)&&(n=null),n},provide:n=>mt.decorations.from(n,t=>t?t.deco:kt.none)});function vf(n,t){return A.EditorSelection.create(n.filter(e=>e.field==t).map(e=>A.EditorSelection.range(e.from,e.to)))}function RT(n){let t=DT.parse(n);return(e,i,s,r)=>{let{text:l,ranges:h}=t.instantiate(e.state,s),c={changes:{from:s,to:r,insert:A.Text.of(l)},scrollIntoView:!0,annotations:i?[ty.of(i),A.Transaction.userEvent.of("input.complete")]:void 0};if(h.length&&(c.selection=vf(h,0)),h.some(g=>g.field>0)){let g=new ca(h,0),p=c.effects=[oo.of(g)];e.state.field(Ur,!1)===void 0&&p.push(A.StateEffect.appendConfig.of([Ur,IT,HT,sy]))}e.dispatch(e.state.update(c))}}function ay(n){return({state:t,dispatch:e})=>{let i=t.field(Ur,!1);if(!i||n<0&&i.active==0)return!1;let s=i.active+n,r=n>0&&!i.ranges.some(l=>l.field==s+n);return e(t.update({selection:vf(i.ranges,s),effects:oo.of(r?null:new ca(i.ranges,s)),scrollIntoView:!0})),!0}}const BT=({state:n,dispatch:t})=>n.field(Ur,!1)?(t(n.update({effects:oo.of(null)})),!0):!1,LT=ay(1),NT=ay(-1),FT=[{key:"Tab",run:LT,shift:NT},{key:"Escape",run:BT}],qp=A.Facet.define({combine(n){return n.length?n[0]:FT}}),IT=A.Prec.highest(Xs.compute([qp],n=>n.facet(qp)));function oe(n,t){return Object.assign(Object.assign({},t),{apply:RT(n)})}const HT=mt.domEventHandlers({mousedown(n,t){let e=t.state.field(Ur,!1),i;if(!e||(i=t.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let s=e.ranges.find(r=>r.from<=i&&r.to>=i);return!s||s.field==e.active?!1:(t.dispatch({selection:vf(e.ranges,s.field),effects:oo.of(e.ranges.some(r=>r.field>s.field)?new ca(e.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Xr={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Zn=A.StateEffect.define({map(n,t){let e=t.mapPos(n,-1,A.MapMode.TrackAfter);return e??void 0}}),kf=new class extends A.RangeValue{};kf.startSide=1;kf.endSide=-1;const hy=A.StateField.define({create(){return A.RangeSet.empty},update(n,t){if(n=n.map(t.changes),t.selection){let e=t.state.doc.lineAt(t.selection.main.head);n=n.update({filter:i=>i>=e.from&&i<=e.to})}for(let e of t.effects)e.is(Zn)&&(n=n.update({add:[kf.range(e.value,e.value+1)]}));return n}});function VT(){return[WT,hy]}const mh="()[]{}<>";function cy(n){for(let t=0;t<mh.length;t+=2)if(mh.charCodeAt(t)==n)return mh.charAt(t+1);return A.fromCodePoint(n<128?n:n+1)}function fy(n,t){return n.languageDataAt("closeBrackets",t)[0]||Xr}const $T=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),WT=mt.inputHandler.of((n,t,e,i)=>{if(($T?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&A.codePointSize(A.codePointAt(i,0))==1||t!=s.from||e!=s.to)return!1;let r=KT(n.state,i);return r?(n.dispatch(r),!0):!1}),zT=({state:n,dispatch:t})=>{if(n.readOnly)return!1;let i=fy(n,n.selection.main.head).brackets||Xr.brackets,s=null,r=n.changeByRange(l=>{if(l.empty){let h=jT(n.doc,l.head);for(let c of i)if(c==h&&fa(n.doc,l.head)==cy(A.codePointAt(c,0)))return{changes:{from:l.head-c.length,to:l.head+c.length},range:A.EditorSelection.cursor(l.head-c.length)}}return{range:s=l}});return s||t(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},qT=[{key:"Backspace",run:zT}];function KT(n,t){let e=fy(n,n.selection.main.head),i=e.brackets||Xr.brackets;for(let s of i){let r=cy(A.codePointAt(s,0));if(t==s)return r==s?YT(n,s,i.indexOf(s+s+s)>-1,e):_T(n,s,r,e.before||Xr.before);if(t==r&&dy(n,n.selection.main.from))return GT(n,s,r)}return null}function dy(n,t){let e=!1;return n.field(hy).between(0,n.doc.length,i=>{i==t&&(e=!0)}),e}function fa(n,t){let e=n.sliceString(t,t+2);return e.slice(0,A.codePointSize(A.codePointAt(e,0)))}function jT(n,t){let e=n.sliceString(t-2,t);return A.codePointSize(A.codePointAt(e,0))==e.length?e:e.slice(1)}function _T(n,t,e,i){let s=null,r=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:e,from:l.to}],effects:Zn.of(l.to+t.length),range:A.EditorSelection.range(l.anchor+t.length,l.head+t.length)};let h=fa(n.doc,l.head);return!h||/\s/.test(h)||i.indexOf(h)>-1?{changes:{insert:t+e,from:l.head},effects:Zn.of(l.head+t.length),range:A.EditorSelection.cursor(l.head+t.length)}:{range:s=l}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function GT(n,t,e){let i=null,s=n.changeByRange(r=>r.empty&&fa(n.doc,r.head)==e?{changes:{from:r.head,to:r.head+e.length,insert:e},range:A.EditorSelection.cursor(r.head+e.length)}:i={range:r});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function YT(n,t,e,i){let s=i.stringPrefixes||Xr.stringPrefixes,r=null,l=n.changeByRange(h=>{if(!h.empty)return{changes:[{insert:t,from:h.from},{insert:t,from:h.to}],effects:Zn.of(h.to+t.length),range:A.EditorSelection.range(h.anchor+t.length,h.head+t.length)};let c=h.head,g=fa(n.doc,c),p;if(g==t){if(Kp(n,c))return{changes:{insert:t+t,from:c},effects:Zn.of(c+t.length),range:A.EditorSelection.cursor(c+t.length)};if(dy(n,c)){let x=e&&n.sliceDoc(c,c+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:c,to:c+x.length,insert:x},range:A.EditorSelection.cursor(c+x.length)}}}else{if(e&&n.sliceDoc(c-2*t.length,c)==t+t&&(p=jp(n,c-2*t.length,s))>-1&&Kp(n,p))return{changes:{insert:t+t+t+t,from:c},effects:Zn.of(c+t.length),range:A.EditorSelection.cursor(c+t.length)};if(n.charCategorizer(c)(g)!=A.CharCategory.Word&&jp(n,c,s)>-1&&!UT(n,c,t,s))return{changes:{insert:t+t,from:c},effects:Zn.of(c+t.length),range:A.EditorSelection.cursor(c+t.length)}}return{range:r=h}});return r?null:n.update(l,{scrollIntoView:!0,userEvent:"input.type"})}function Kp(n,t){let e=ie(n).resolveInner(t+1);return e.parent&&e.from==t}function UT(n,t,e,i){let s=ie(n).resolveInner(t,-1),r=i.reduce((l,h)=>Math.max(l,h.length),0);for(let l=0;l<5;l++){let h=n.sliceDoc(s.from,Math.min(s.to,s.from+e.length+r)),c=h.indexOf(e);if(!c||c>-1&&i.indexOf(h.slice(0,c))>-1){let p=s.firstChild;for(;p&&p.from==s.from&&p.to-p.from>e.length+c;){if(n.sliceDoc(p.to-e.length,p.to)==e)return!1;p=p.firstChild}return!0}let g=s.to==t&&s.parent;if(!g)break;s=g}return!1}function jp(n,t,e){let i=n.charCategorizer(t);if(i(n.sliceDoc(t-1,t))!=A.CharCategory.Word)return t;for(let s of e){let r=t-s.length;if(n.sliceDoc(r,t)==s&&i(n.sliceDoc(r-1,r))!=A.CharCategory.Word)return r}return-1}function XT(n={}){return[hi,Me.of(n),MT,JT,sy]}const uy=[{key:"Ctrl-Space",run:wT},{key:"Escape",run:xT},{key:"ArrowDown",run:ll(!0)},{key:"ArrowUp",run:ll(!1)},{key:"PageDown",run:ll(!0,"page")},{key:"PageUp",run:ll(!1,"page")},{key:"Enter",run:ST}],JT=A.Prec.highest(Xs.computeN([Me],n=>n.facet(Me).defaultKeymap?[uy]:[]));var _p=function(t){t===void 0&&(t={});var{crosshairCursor:e=!1}=t,i=[];t.closeBracketsKeymap!==!1&&(i=i.concat(qT)),t.defaultKeymap!==!1&&(i=i.concat(AC)),t.searchKeymap!==!1&&(i=i.concat(tT)),t.historyKeymap!==!1&&(i=i.concat(Nk)),t.foldKeymap!==!1&&(i=i.concat(Uv)),t.completionKeymap!==!1&&(i=i.concat(uy)),t.lintKeymap!==!1&&(i=i.concat(VC));var s=[];return t.lineNumbers!==!1&&s.push(Cv()),t.highlightActiveLineGutter!==!1&&s.push(Tv()),t.highlightSpecialChars!==!1&&s.push(qx()),t.history!==!1&&s.push(Ak()),t.foldGutter!==!1&&s.push(Zv()),t.drawSelection!==!1&&s.push(Rx()),t.dropCursor!==!1&&s.push(Ix()),t.allowMultipleSelections!==!1&&s.push(A.EditorState.allowMultipleSelections.of(!0)),t.indentOnInput!==!1&&s.push($v()),t.syntaxHighlighting!==!1&&s.push(i0(nk,{fallback:!0})),t.bracketMatching!==!1&&s.push(ck()),t.closeBrackets!==!1&&s.push(VT()),t.autocompletion!==!1&&s.push(XT()),t.rectangularSelection!==!1&&s.push(nv()),e!==!1&&s.push(ov()),t.highlightActiveLine!==!1&&s.push(Ux()),t.highlightSelectionMatches!==!1&&s.push(NA()),t.tabSize&&typeof t.tabSize=="number"&&s.push(Js.of(" ".repeat(t.tabSize))),s.concat([Xs.of(i.flat())]).filter(Boolean)},bh;const Rr=new qe,QT=new qe;class Yi{constructor(t,e,i=[],s=""){this.data=t,this.name=s,A.EditorState.prototype.hasOwnProperty("tree")||Object.defineProperty(A.EditorState.prototype,"tree",{get(){return Jr(this)}}),this.parser=e,this.extension=[Ys.of(this),A.EditorState.languageData.of((r,l,h)=>{let c=Gp(r,l,h),g=c.type.prop(Rr);if(!g)return[];let p=r.facet(g),y=c.type.prop(QT);if(y){let x=c.resolve(l-c.from,h);for(let T of y)if(T.test(x,r)){let P=r.facet(T.facet);return T.type=="replace"?P:P.concat(p)}}return p})].concat(i)}isActiveAt(t,e,i=-1){return Gp(t,e,i).type.prop(Rr)==this.data}findRegions(t){let e=t.facet(Ys);if((e==null?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],s=(r,l)=>{if(r.prop(Rr)==this.data){i.push({from:l,to:l+r.length});return}let h=r.prop(qe.mounted);if(h){if(h.tree.prop(Rr)==this.data){if(h.overlay)for(let c of h.overlay)i.push({from:c.from+l,to:c.to+l});else i.push({from:l,to:l+r.length});return}else if(h.overlay){let c=i.length;if(s(h.tree,h.overlay[0].from+l),i.length>c)return}}for(let c=0;c<r.children.length;c++){let g=r.children[c];g instanceof bi&&s(g,r.positions[c]+l)}};return s(Jr(t),0),i}get allowsNesting(){return!0}}Yi.setState=A.StateEffect.define();function Gp(n,t,e){let i=n.facet(Ys),s=Jr(n).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(t,e,Jl.ExcludeBuffers))r.type.isTop&&(s=r);return s}function Jr(n){let t=n.field(Yi.state,!1);return t?t.tree:bi.empty}class ZT{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t<i||e>=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let Sr=null;class Ul{constructor(t,e,i=[],s,r,l,h,c){this.parser=t,this.state=e,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=l,this.skipped=h,this.scheduleOn=c,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new Ul(t,e,[],bi.empty,0,i,[],null)}startParse(){return this.parser.startParse(new ZT(this.state.doc),this.fragments)}work(t,e){return e!=null&&e>=this.state.doc.length&&(e=void 0),this.tree!=bi.empty&&this.isDone(e??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof t=="number"){let s=Date.now()+t;t=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),e!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(Nn.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(e??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(Nn.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Sr;Sr=this;try{return t()}finally{Sr=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=Yp(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:s,treeLen:r,viewport:l,skipped:h}=this;if(this.takeTree(),!t.empty){let c=[];if(t.iterChangedRanges((g,p,y,x)=>c.push({fromA:g,toA:p,fromB:y,toB:x})),i=Nn.applyChanges(i,c),s=bi.empty,r=0,l={from:t.mapPos(l.from,-1),to:t.mapPos(l.to,1)},this.skipped.length){h=[];for(let g of this.skipped){let p=t.mapPos(g.from,1),y=t.mapPos(g.to,-1);p<y&&h.push({from:p,to:y})}}}return new Ul(this.parser,e,i,s,r,l,h,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let e=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<t.to&&r>t.from&&(this.fragments=Yp(this.fragments,s,r),this.skipped.splice(i--,1))}return this.skipped.length>=e?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends bg{createParse(e,i,s){let r=s[0].from,l=s[s.length-1].to;return{parsedPos:r,advance(){let c=Sr;if(c){for(let g of s)c.tempSkipped.push(g);t&&(c.scheduleOn=c.scheduleOn?Promise.all([c.scheduleOn,t]):t)}return this.parsedPos=l,new bi(Us.none,[],[],l-r)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&e[0].from==0&&e[0].to>=t}static get(){return Sr}}function Yp(n,t,e){return Nn.applyChanges(n,[{fromA:t,toA:e,fromB:t,toB:e}])}class Gs{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Gs(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Ul.create(t.facet(Ys).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Gs(i)}}Yi.state=A.StateField.define({create:Gs.init,update(n,t){for(let e of t.effects)if(e.is(Yi.setState))return e.value;return t.startState.facet(Ys)!=t.state.facet(Ys)?Gs.init(t.state):n.apply(t)}});let py=n=>{let t=setTimeout(()=>n(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(py=n=>{let t=-1,e=setTimeout(()=>{t=requestIdleCallback(n,{timeout:400})},100);return()=>t<0?clearTimeout(e):cancelIdleCallback(t)});const yh=typeof navigator<"u"&&(!((bh=navigator.scheduling)===null||bh===void 0)&&bh.isInputPending)?()=>navigator.scheduling.isInputPending():null,tD=Ji.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(Yi.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(Yi.state);(e.tree!=e.context.tree||!e.context.isDone(t.doc.length))&&(this.working=py(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(Yi.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let l=Date.now()+Math.min(this.chunkBudget,100,t&&!yh?Math.max(25,t.timeRemaining()-5):1e9),h=r.context.treeLen<s&&i.doc.length>s+1e3,c=r.context.work(()=>yh&&yh()||Date.now()>l,s+(h?0:1e5));this.chunkBudget-=Date.now()-e,(c||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Yi.setState.of(new Gs(r.context))})),this.chunkBudget>0&&!(c&&!h)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(e=>Gi(this.view.state,e)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ys=A.Facet.define({combine(n){return n.length?n[0]:null},enables:n=>[Yi.state,tD,At.contentAttributes.compute([n],t=>{let e=t.facet(n);return e&&e.name?{"data-language":e.name}:{}})]});class da{constructor(t,e){this.specs=t;let i;function s(h){let c=Le.newName();return(i||(i=Object.create(null)))["."+c]=h,c}const r=typeof e.all=="string"?e.all:e.all?s(e.all):void 0,l=e.scope;this.scope=l instanceof Yi?h=>h.prop(Rr)==l.data:l?h=>h==l:void 0,this.style=yg(t.map(h=>({tag:h.tag,class:h.class||s(Object.assign({},h,{tag:null}))})),{all:r}).style,this.module=i?new Le(i):null,this.themeType=e.themeType}static define(t,e){return new da(t,e||{})}}const Lc=A.Facet.define(),eD=A.Facet.define({combine(n){return n.length?[n[0]]:null}});function Sh(n){let t=n.facet(Lc);return t.length?t:n.facet(eD)}function iD(n,t){let e=[sD],i;return n instanceof da&&(n.module&&e.push(At.styleModule.of(n.module)),i=n.themeType),i?e.push(Lc.computeN([At.darkTheme],s=>s.facet(At.darkTheme)==(i=="dark")?[n]:[])):e.push(Lc.of(n)),e}class nD{constructor(t){this.markCache=Object.create(null),this.tree=Jr(t.state),this.decorations=this.buildDeco(t,Sh(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=Jr(t.state),i=Sh(t.state),s=i!=Sh(t.startState),{viewport:r}=t.view,l=t.changes.mapPos(this.decoratedTo,1);e.length<r.to&&!s&&e.type==this.tree.type&&l>=r.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=l):(e!=this.tree||t.viewportChanged||s)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=r.to)}buildDeco(t,e){if(!e||!this.tree.length)return $t.none;let i=new A.RangeSetBuilder;for(let{from:s,to:r}of t.visibleRanges)Sg(this.tree,e,(l,h,c)=>{i.add(l,h,this.markCache[c]||(this.markCache[c]=$t.mark({class:c})))},s,r);return i.finish()}}const sD=A.Prec.high(Ji.fromClass(nD,{decorations:n=>n.decorations})),rD=Object.create(null),Up=[Us.none],Xp=[],Jp=Object.create(null),oD=Object.create(null);for(let[n,t]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"]])oD[n]=lD(rD,t);function wh(n,t){Xp.indexOf(n)>-1||(Xp.push(n),console.warn(t))}function lD(n,t){let e=[];for(let h of t.split(" ")){let c=[];for(let g of h.split(".")){let p=n[g]||J[g];p?typeof p=="function"?c.length?c=c.map(p):wh(g,`Modifier ${g} used at start of tag`):c.length?wh(g,`Tag ${g} used as modifier`):c=Array.isArray(p)?p:[p]:wh(g,`Unknown highlighting tag ${g}`)}for(let g of c)e.push(g)}if(!e.length)return 0;let i=t.replace(/ /g,"_"),s=i+" "+e.map(h=>h.id),r=Jp[s];if(r)return r.id;let l=Jp[s]=Us.define({id:Up.length,name:i,props:[wg({[i]:e})]});return Up.push(l),l.id}Ae.RTL,Ae.LTR;const aD="#e5c07b",Qp="#e06c75",hD="#56b6c2",cD="#ffffff",Cl="#abb2bf",Nc="#7d8799",fD="#61afef",dD="#98c379",Zp="#d19a66",uD="#c678dd",pD="#21252b",tg="#2c313a",eg="#282c34",xh="#353a42",gD="#3E4451",ig="#528bff",mD=At.theme({"&":{color:Cl,backgroundColor:eg},".cm-content":{caretColor:ig},".cm-cursor, .cm-dropCursor":{borderLeftColor:ig},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:gD},".cm-panels":{backgroundColor:pD,color:Cl},".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:eg,color:Nc,border:"none"},".cm-activeLineGutter":{backgroundColor:tg},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:xh},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:xh,borderBottomColor:xh},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:tg,color:Cl}}},{dark:!0}),bD=da.define([{tag:J.keyword,color:uD},{tag:[J.name,J.deleted,J.character,J.propertyName,J.macroName],color:Qp},{tag:[J.function(J.variableName),J.labelName],color:fD},{tag:[J.color,J.constant(J.name),J.standard(J.name)],color:Zp},{tag:[J.definition(J.name),J.separator],color:Cl},{tag:[J.typeName,J.className,J.number,J.changed,J.annotation,J.modifier,J.self,J.namespace],color:aD},{tag:[J.operator,J.operatorKeyword,J.url,J.escape,J.regexp,J.link,J.special(J.string)],color:hD},{tag:[J.meta,J.comment],color:Nc},{tag:J.strong,fontWeight:"bold"},{tag:J.emphasis,fontStyle:"italic"},{tag:J.strikethrough,textDecoration:"line-through"},{tag:J.link,color:Nc,textDecoration:"underline"},{tag:J.heading,fontWeight:"bold",color:Qp},{tag:[J.atom,J.bool,J.special(J.variableName)],color:Zp},{tag:[J.processingInstruction,J.string,J.inserted],color:dD},{tag:J.invalid,color:cD}]),yD=[mD,iD(bD)];var SD=mt.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),wD=function(t){t===void 0&&(t={});var{indentWithTab:e=!0,editable:i=!0,readOnly:s=!1,theme:r="light",placeholder:l="",basicSetup:h=!0}=t,c=[];switch(e&&c.unshift(Xs.of([TC])),h&&(typeof h=="boolean"?c.unshift(_p()):c.unshift(_p(h))),l&&c.unshift(Zx(l)),r){case"light":c.push(SD);break;case"dark":c.push(yD);break;case"none":break;default:c.push(r);break}return i===!1&&c.push(mt.editable.of(!1)),s&&c.push(A.EditorState.readOnly.of(!0)),[...c]},xD=n=>({line:n.state.doc.lineAt(n.state.selection.main.from),lineCount:n.state.doc.lines,lineBreak:n.state.lineBreak,length:n.state.doc.length,readOnly:n.state.readOnly,tabSize:n.state.tabSize,selection:n.state.selection,selectionAsSingle:n.state.selection.asSingle().main,ranges:n.state.selection.ranges,selectionCode:n.state.sliceDoc(n.state.selection.main.from,n.state.selection.main.to),selections:n.state.selection.ranges.map(t=>n.state.sliceDoc(t.from,t.to)),selectedText:n.state.selection.ranges.some(t=>!t.empty)}),ng=A.Annotation.define(),vD=[];function kD(n){var{value:t,selection:e,onChange:i,onStatistics:s,onCreateEditor:r,onUpdate:l,extensions:h=vD,autoFocus:c,theme:g="light",height:p=null,minHeight:y=null,maxHeight:x=null,width:T=null,minWidth:P=null,maxWidth:I=null,placeholder:z="",editable:W=!0,readOnly:U=!1,indentWithTab:ot=!0,basicSetup:Q=!0,root:st,initialState:at}=n,[wt,Pt]=mi.useState(),[Tt,le]=mi.useState(),[ae,zt]=mi.useState(),Ot=mt.theme({"&":{height:p,minHeight:y,maxHeight:x,width:T,minWidth:P,maxWidth:I},"& .cm-scroller":{height:"100% !important"}}),ne=mt.updateListener.of(vt=>{if(vt.docChanged&&typeof i=="function"&&!vt.transactions.some(ue=>ue.annotation(ng))){var Zt=vt.state.doc,se=Zt.toString();i(se,vt)}s&&s(xD(vt))}),Rt=wD({theme:g,editable:W,readOnly:U,placeholder:z,indentWithTab:ot,basicSetup:Q}),Bt=[ne,Ot,...Rt];return l&&typeof l=="function"&&Bt.push(mt.updateListener.of(l)),Bt=Bt.concat(h),mi.useEffect(()=>{if(wt&&!ae){var vt={doc:t,selection:e,extensions:Bt},Zt=at?A.EditorState.fromJSON(at.json,vt,at.fields):A.EditorState.create(vt);if(zt(Zt),!Tt){var se=new mt({state:Zt,parent:wt,root:st});le(se),r&&r(se,Zt)}}return()=>{Tt&&(zt(void 0),le(void 0))}},[wt,ae]),mi.useEffect(()=>Pt(n.container),[n.container]),mi.useEffect(()=>()=>{Tt&&(Tt.destroy(),le(void 0))},[Tt]),mi.useEffect(()=>{c&&Tt&&Tt.focus()},[c,Tt]),mi.useEffect(()=>{Tt&&Tt.dispatch({effects:A.StateEffect.reconfigure.of(Bt)})},[g,h,p,y,x,T,P,I,z,W,U,ot,Q,i,l]),mi.useEffect(()=>{if(t!==void 0){var vt=Tt?Tt.state.doc.toString():"";Tt&&t!==vt&&Tt.dispatch({changes:{from:0,to:vt.length,insert:t||""},annotations:[ng.of(!0)]})}},[t,Tt]),{state:ae,setState:zt,view:Tt,setView:le,container:wt,setContainer:Pt}}var CD=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],MD=mi.forwardRef((n,t)=>{var{className:e,value:i="",selection:s,extensions:r=[],onChange:l,onStatistics:h,onCreateEditor:c,onUpdate:g,autoFocus:p,theme:y="light",height:x,minHeight:T,maxHeight:P,width:I,minWidth:z,maxWidth:W,basicSetup:U,placeholder:ot,indentWithTab:Q,editable:st,readOnly:at,root:wt,initialState:Pt}=n,Tt=$S(n,CD),le=mi.useRef(null),{state:ae,view:zt,container:Ot}=kD({container:le.current,root:wt,value:i,autoFocus:p,theme:y,height:x,minHeight:T,maxHeight:P,width:I,minWidth:z,maxWidth:W,basicSetup:U,placeholder:ot,indentWithTab:Q,editable:st,readOnly:at,selection:s,onChange:l,onStatistics:h,onCreateEditor:c,onUpdate:g,extensions:r,initialState:Pt});if(mi.useImperativeHandle(t,()=>({editor:le.current,state:ae,view:zt}),[le,Ot,ae,zt]),typeof i!="string")throw new Error("value must be typeof string but got "+typeof i);var ne=typeof y=="string"?"cm-theme-"+y:"cm-theme";return WS.jsx("div",Hc({ref:le,className:""+ne+(e?" "+e:"")},Tt))});MD.displayName="CodeMirror";const AD=A.Annotation.define(),TD=mt.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 DD{constructor(t,e,i,s){this.field=t,this.line=e,this.from=i,this.to=s}}class Cf{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,A.MapMode.TrackDel),i=t.mapPos(this.to,1,A.MapMode.TrackDel);return e==null||i==null?null:new Cf(this.field,e,i)}}class Mf{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],s=[e],r=t.doc.lineAt(e),l=/^\s*/.exec(r.text)[0];for(let c of this.lines){if(i.length){let g=l,p=/^\t*/.exec(c)[0].length;for(let y=0;y<p;y++)g+=t.facet(Js);s.push(e+g.length-p),c=g+c.slice(p)}i.push(c),e+=c.length+1}let h=this.fieldPositions.map(c=>new Cf(c.field,s[c.line]+c.from,s[c.line]+c.to));return{text:i,ranges:h}}static parse(t){let e=[],i=[],s=[],r;for(let l of t.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(l);){let h=r[1]?+r[1]:null,c=r[2]||r[3]||"",g=-1,p=c.replace(/\\[{}]/g,y=>y[1]);for(let y=0;y<e.length;y++)(h!=null?e[y].seq==h:p&&e[y].name==p)&&(g=y);if(g<0){let y=0;for(;y<e.length&&(h==null||e[y].seq!=null&&e[y].seq<h);)y++;e.splice(y,0,{seq:h,name:p}),g=y;for(let x of s)x.field>=g&&x.field++}s.push(new DD(g,i.length,r.index,r.index+p.length)),l=l.slice(0,r.index)+c+l.slice(r.index+r[0].length)}l=l.replace(/\\([{}])/g,(h,c,g)=>{for(let p of s)p.line==i.length&&p.from>g&&(p.from--,p.to--);return c}),i.push(l)}return new Mf(i,s)}}let OD=kt.widget({widget:new class extends Bi{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),ED=kt.mark({class:"cm-snippetField"});class tr{constructor(t,e){this.ranges=t,this.active=e,this.deco=kt.set(t.map(i=>(i.from==i.to?OD:ED).range(i.from,i.to)))}map(t){let e=[];for(let i of this.ranges){let s=i.map(t);if(!s)return null;e.push(s)}return new tr(e,this.active)}selectionInsideField(t){return t.ranges.every(e=>this.ranges.some(i=>i.field==this.active&&i.from<=e.from&&i.to>=e.to))}}const lo=A.StateEffect.define({map(n,t){return n&&n.map(t)}}),PD=A.StateEffect.define(),Qr=A.StateField.define({create(){return null},update(n,t){for(let e of t.effects){if(e.is(lo))return e.value;if(e.is(PD)&&n)return new tr(n.ranges,e.value)}return n&&t.docChanged&&(n=n.map(t.changes)),n&&t.selection&&!n.selectionInsideField(t.selection)&&(n=null),n},provide:n=>mt.decorations.from(n,t=>t?t.deco:kt.none)});function Af(n,t){return A.EditorSelection.create(n.filter(e=>e.field==t).map(e=>A.EditorSelection.range(e.from,e.to)))}function RD(n){let t=Mf.parse(n);return(e,i,s,r)=>{let{text:l,ranges:h}=t.instantiate(e.state,s),c={changes:{from:s,to:r,insert:A.Text.of(l)},scrollIntoView:!0,annotations:i?[AD.of(i),A.Transaction.userEvent.of("input.complete")]:void 0};if(h.length&&(c.selection=Af(h,0)),h.some(g=>g.field>0)){let g=new tr(h,0),p=c.effects=[lo.of(g)];e.state.field(Qr,!1)===void 0&&p.push(A.StateEffect.appendConfig.of([Qr,ID,VD,TD]))}e.dispatch(e.state.update(c))}}function gy(n){return({state:t,dispatch:e})=>{let i=t.field(Qr,!1);if(!i||n<0&&i.active==0)return!1;let s=i.active+n,r=n>0&&!i.ranges.some(l=>l.field==s+n);return e(t.update({selection:Af(i.ranges,s),effects:lo.of(r?null:new tr(i.ranges,s)),scrollIntoView:!0})),!0}}const BD=({state:n,dispatch:t})=>n.field(Qr,!1)?(t(n.update({effects:lo.of(null)})),!0):!1,LD=gy(1),ND=gy(-1),FD=[{key:"Tab",run:LD,shift:ND},{key:"Escape",run:BD}],sg=A.Facet.define({combine(n){return n.length?n[0]:FD}}),ID=A.Prec.highest(Xs.compute([sg],n=>n.facet(sg)));function HD(n,t){return Object.assign(Object.assign({},t),{apply:RD(n)})}const VD=mt.domEventHandlers({mousedown(n,t){let e=t.state.field(Qr,!1),i;if(!e||(i=t.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let s=e.ranges.find(r=>r.from<=i&&r.to>=i);return!s||s.field==e.active?!1:(t.dispatch({selection:Af(e.ranges,s.field),effects:lo.of(e.ranges.some(r=>r.field>s.field)?new tr(e.ranges,s.field):null),scrollIntoView:!0}),!0)}}),my=new class extends A.RangeValue{};my.startSide=1;my.endSide=-1;const ge={log:(...n)=>{},warn:(...n)=>{}},Dt={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:"⚠"},$D={Pair:Dt.PROPERTY,Key:Dt.PROPERTY_NAME,BlockSequence:Dt.ARRAY,BlockMapping:Dt.OBJECT,FlowSequence:Dt.ARRAY,FlowMapping:Dt.OBJECT,QuotedLiteral:Dt.STRING,Literal:Dt.STRING,Stream:Dt.JSON_TEXT,Document:Dt.OBJECT},WD={File:Dt.JSON_TEXT},Tf=[Dt.STRING,Dt.NUMBER,Dt.TRUE,Dt.FALSE,Dt.NULL],by=[Dt.OBJECT,Dt.ARRAY,Dt.ITEM],te={JSON5:"json5",JSON:"json4",YAML:"yaml"},de=(n,t)=>{var e,i;switch(t){case te.YAML:return(e=$D[n])!==null&&e!==void 0?e:n;case te.JSON5:return(i=WD[n])!==null&&i!==void 0?i:n;default:return n}};function yy(n,t,e){const i=[];for(let s=t;s!=null&&s.parent;s=s.parent)switch(de(s.parent.name,e)){case Dt.PROPERTY:{const r=Fc(s.parent,Dt.PROPERTY_NAME,e);r&&i.unshift(As(n,r).replace(/[/~]/g,l=>l==="~"?"~0":"~1"));break}case Dt.ARRAY:{if(qD(s,e)){const r=xy(s.parent,s,e);i.unshift(`${r}`)}break}}return i.unshift(""),i.join("/")}const Sy=(n,t,e=-1,i)=>yy(n.doc,ie(n).resolve(t,e),i),Df=(n,t)=>{const e=ie(n),i=new Map;return e.iterate({enter:s=>{var r,l,h,c,g,p,y,x;if([Dt.PROPERTY_NAME,Dt.OBJECT].includes(de(s.name,t))){const T=yy(n.doc,s.node,t),{from:P,to:I}=s.node;if(!(!((l=(r=s.node)===null||r===void 0?void 0:r.nextSibling)===null||l===void 0)&&l.node))return i.set(T,{keyFrom:P,keyTo:I}),!0;const z=t===te.JSON?(c=(h=s.node)===null||h===void 0?void 0:h.nextSibling)===null||c===void 0?void 0:c.node:(x=(y=(p=(g=s.node)===null||g===void 0?void 0:g.nextSibling)===null||p===void 0?void 0:p.node)===null||y===void 0?void 0:y.nextSibling)===null||x===void 0?void 0:x.node;if(!z)return i.set(T,{keyFrom:P,keyTo:I}),!0;const{from:W,to:U}=z;return i.set(T,{keyFrom:P,keyTo:I,valueFrom:W,valueTo:U}),!0}}}),i},vh=(n,t,e=-1)=>ie(n).resolveInner(t,e),Ml=n=>n.replace(/^"(.*)"$/,"$1").replace(/^'(.*)'$/,"$1"),zD=n=>n.replace(/^"(.*)"$/,"'$1'"),As=(n,t,e=!0,i=!0)=>{const s=t?n.sliceString(t.from,t.to):"";return e?i?Ml(s):s.replace(/(^["'])|(["']$)/g,""):s},wy=(n,t)=>{var e,i,s,r;return de(n.name,t)===Dt.INVALID&&(de((i=(e=n.prevSibling)===null||e===void 0?void 0:e.name)!==null&&i!==void 0?i:"",t)===Dt.PROPERTY_NAME||de((r=(s=n.prevSibling)===null||s===void 0?void 0:s.name)!==null&&r!==void 0?r:"",t)===Dt.PROPERTY_COLON)},Al=(n,t)=>Tf.includes(de(n.name,t))||wy(n,t),qD=(n,t)=>[...Tf,...by].includes(de(n.name,t))||wy(n,t),al=(n,t)=>{var e,i,s,r,l,h;return de(n.name,t)===Dt.PROPERTY_NAME||de(n.name,t)===Dt.INVALID&&(de((i=(e=n.prevSibling)===null||e===void 0?void 0:e.name)!==null&&i!==void 0?i:"",t)===Dt.PROPERTY||de((r=(s=n.prevSibling)===null||s===void 0?void 0:s.name)!==null&&r!==void 0?r:"",t)==="{")||t===te.YAML&&de((h=(l=n.parent)===null||l===void 0?void 0:l.name)!==null&&h!==void 0?h:"",t)===Dt.OBJECT},ao=n=>{const t=[];let e=n.firstChild;for(;e;)e&&t.push(e),e=e==null?void 0:e.nextSibling;return t},KD=(n,t,e)=>ao(n).filter(i=>de(i.name,e)===t),Fc=(n,t,e)=>{var i;return(i=ao(n).find(s=>de(s.name,e)===t))!==null&&i!==void 0?i:null},rg=(n,t)=>ao(n).find(e=>Al(e,t)),jD=(n,t)=>ao(n).filter(e=>Tf.includes(de(e.name,t))||by.includes(de(e.name,t))),xy=(n,t,e)=>jD(n,e).findIndex(i=>i.from===t.from&&i.to===t.to),og=(n,t,e,i=1/0)=>{let s=n;for(;s&&i>0;){if(de(s.name,e)===t)return s;s=s.parent,i--}return null},_D=A.StateEffect.define(),Xl=A.StateField.define({create(){},update(n,t){for(const e of t.effects)if(e.is(_D))return e.value;return n}}),Of=n=>n.field(Xl),lE=n=>[Xl.init(()=>n)],Ic=zS({linkify:!0,typographer:!0});(async()=>{const n=await YS({themes:{light:"vitesse-light",dark:"vitesse-dark"}});Ic.use(n)})();function Fs(n,t=!0){return t?Ic.renderInline(n):Ic.render(n)}class GD{constructor(){this.completions=new Map,this.reservedKeys=new Set}reserve(t){this.reservedKeys.add(t)}add(t){this.reservedKeys.has(t.label)||this.completions.set(t.label,t)}}class YD{constructor(t){var e;this.opts=t,this.schema=null,this.mode=te.JSON,this.mode=(e=t.mode)!==null&&e!==void 0?e:te.JSON}doComplete(t){var e,i,s;const r=Of(t.state);if(this.schema=(e=this.expandSchemaProperty(r,r))!==null&&e!==void 0?e:r,!this.schema)return[];const l={from:t.pos,to:t.pos,options:[],filter:!1},h=t.state.doc.sliceString(0);let c=vh(t.state,t.pos),g=t.state.sliceDoc(c.from,t.pos).replace(/^(["'])/,"");if(ge.log("xxx","node",c,"prefix",g,"ctx",t),!(Al(c,this.mode)||al(c,this.mode))&&!t.explicit)return ge.log("xxx","no completions for non-word/primitive",c),l;const p=As(t.state.doc,c),y=As(t.state.doc,c,!1);if(c&&(Al(c,this.mode)||al(c,this.mode)))l.from=c.from,l.to=c.to;else{const I=t.matchBefore(/[A-Za-z0-9._]*/),z=t.pos-p.length;ge.log("xxx","overwriteStart after",z,"ctx.pos",t.pos,"word",I,"currentWord",p,"=>",h[z-1],"..",h[z],"..",h),l.from=c.name===Dt.INVALID?(i=I==null?void 0:I.from)!==null&&i!==void 0?i:t.pos:z,l.to=t.pos}const x=new GD;let T=!0;const P=og(c,Dt.PROPERTY_NAME,this.mode);if(P&&(ge.log("xxx","closestPropertyNameNode",P,"node",c),c=P),al(c,this.mode)){ge.log("xxx","isPropertyNameNode",c);const I=c.parent;if(I){const z=rg(I,this.mode);T=!z||z.name===Dt.INVALID&&z.from-z.to===0||(z.parent?ao(z.parent).length<=1:!1),ge.log("xxx","addValue",T,rg(I,this.mode),c),c=(s=og(I,Dt.OBJECT,this.mode))!==null&&s!==void 0?s:null}}if(ge.log("xxx",c,p,t,"node at pos",vh(t.state,t.pos)),c&&[Dt.OBJECT,Dt.JSON_TEXT].includes(de(c.name,this.mode))&&(al(vh(t.state,t.pos),this.mode)||P)){if(c.from===t.pos)return ge.log("xxx","no completions for just before opening brace"),l;this.getPropertyCompletions(this.schema,t,c,x,T,y)}else{const I={},z=this.getValueCompletions(this.schema,t,I,x);ge.log("xxx","getValueCompletions res",z)}return l.options=Array.from(x.completions.values()).filter(I=>Ml(I.label).startsWith(g)),ge.log("xxx","result",l,"prefix",g,"collector.completions",x.completions,"reservedKeys",x.reservedKeys),l}applySnippetCompletion(t){return HD(typeof t.apply!="string"?t.label:t.apply,t)}getPropertyCompletions(t,e,i,s,r,l){const h=KD(i,Dt.PROPERTY,this.mode);ge.log("xxx","getPropertyCompletions",i,e,h),h.forEach(g=>{const p=As(e.state.doc,Fc(g,Dt.PROPERTY_NAME,this.mode));s.reserve(Ml(p))});const c=this.getSchemas(t,e);ge.log("xxx","propertyCompletion schemas",c),c.forEach(g=>{if(typeof g!="object")return;const p=g.properties;p&&Object.entries(p).forEach(([x,T])=>{var P,I;if(typeof T=="object"){const z=(P=T.description)!==null&&P!==void 0?P:"",W=(I=T.type)!==null&&I!==void 0?I:"",U=Array.isArray(W)?W.toString():W,ot={label:x,apply:this.getInsertTextForProperty(x,r,l,T),type:"property",detail:U,info:Fs(z)};s.add(this.applySnippetCompletion(ot))}});const y=g.propertyNames;if(typeof y=="object"&&(y.enum&&y.enum.forEach(x=>{const T=x==null?void 0:x.toString();if(T){const P={label:T,apply:this.getInsertTextForProperty(T,r,l),type:"property"};s.add(this.applySnippetCompletion(P))}}),y.const)){const x=y.const.toString(),T={label:x,apply:this.getInsertTextForProperty(x,r,l),type:"property"};s.add(this.applySnippetCompletion(T))}})}getInsertTextForProperty(t,e,i,s){s=s&&this.expandSchemaProperty(s,this.schema);let r=this.getInsertTextForPropertyName(t,i);if(!e)return r;r+=": ";let l,h=0;if(typeof s=="object"){if(typeof s.default<"u")l||(l=this.getInsertTextForGuessedValue(s.default,"")),h++;else if(s.enum&&(!l&&s.enum.length===1&&(l=this.getInsertTextForGuessedValue(s.enum[0],"")),h+=s.enum.length),typeof s.const<"u"&&(l||(l=this.getInsertTextForGuessedValue(s.const,"")),h++),Array.isArray(s.examples)&&s.examples.length&&(l||(l=this.getInsertTextForGuessedValue(s.examples[0],"")),h+=s.examples.length),l===void 0&&h===0){let c=Array.isArray(s.type)?s.type[0]:s.type;switch(c||(s.properties?c="object":s.items&&(c="array")),c){case"boolean":l="#{}";break;case"string":l=this.getInsertTextForString("");break;case"object":switch(this.mode){case te.JSON5:l="{#{}}";break;case te.YAML:l="#{}";break;default:l="{#{}}";break}break;case"array":l="[#{}]";break;case"number":case"integer":l="#{0}";break;case"null":l="#{null}";break;default:l="#{}";break}}}return(!l||h>1)&&(ge.log("xxx","value",l,"nValueProposals",h,s),l="#{}"),r+l}getInsertTextForPropertyName(t,e){switch(this.mode){case te.JSON5:case te.YAML:return e.startsWith('"')?`"${t}"`:e.startsWith("'")?`'${t}'`:t;default:return`"${t}"`}}getInsertTextForString(t,e="#"){switch(this.mode){case te.JSON5:return`'${e}{${t}}'`;case te.YAML:return`${e}{${t}}`;default:return`"${e}{${t}}"`}}getInsertTextForGuessedValue(t,e=""){switch(typeof t){case"object":return t===null?"${null}"+e:this.getInsertTextForValue(t,e);case"string":{let i=JSON.stringify(t);return i=i.substr(1,i.length-2),i=this.getInsertTextForPlainText(i),this.getInsertTextForString(i,"$")+e}case"number":case"boolean":return"${"+JSON.stringify(t)+"}"+e}return this.getInsertTextForValue(t,e)}getInsertTextForPlainText(t){return t.replace(/[\\$}]/g,"\\$&")}getInsertTextForValue(t,e){const i=JSON.stringify(t,null," ");return i==="{}"?"{#{}}"+e:i==="[]"?"[#{}]"+e:this.getInsertTextForPlainText(i+e)}getValueCompletions(t,e,i,s){let r=ie(e.state).resolveInner(e.pos,-1),l=null,h;if(ge.log("xxx","getValueCompletions",r,e),r&&Al(r,this.mode)&&(l=r,r=r.parent),!r){this.addSchemaValueCompletions(t,i,s);return}if(de(r.name,this.mode)===Dt.PROPERTY){const g=Fc(r,Dt.PROPERTY_NAME,this.mode);g&&(h=As(e.state.doc,g),r=r.parent)}if(ge.log("xxx","node",r,"parentKey",h),r&&(h!==void 0||de(r.name,this.mode)===Dt.ARRAY)){const g=this.getSchemas(t,e);for(const p of g){if(typeof p!="object")return;if(de(r.name,this.mode)===Dt.ARRAY&&p.items){let y=s;if(p.uniqueItems&&(y=Object.assign(Object.assign({},y),{add(x){y.completions.has(x.label)||s.add(x)},reserve(x){s.reserve(x)}})),Array.isArray(p.items)){let x=0;if(l){const P=xy(r,l,this.mode);P>=0&&(x=P)}const T=p.items[x];T&&this.addSchemaValueCompletions(T,i,y)}else this.addSchemaValueCompletions(p.items,i,y)}if(h!==void 0){let y=!1;if(p.properties){const x=p.properties[h];x&&(y=!0,this.addSchemaValueCompletions(x,i,s))}if(p.patternProperties&&!y)for(const x of Object.keys(p.patternProperties)){const T=this.extendedRegExp(x);if(T!=null&&T.test(h)){y=!0;const P=p.patternProperties[x];P&&this.addSchemaValueCompletions(P,i,s)}}if(p.additionalProperties&&!y){const x=p.additionalProperties;this.addSchemaValueCompletions(x,i,s)}}i.boolean&&(this.addBooleanValueCompletion(!0,s),this.addBooleanValueCompletion(!1,s)),i.null&&this.addNullValueCompletion(s)}}return{valuePrefix:l?As(e.state.doc,l,!0,!1):""}}addSchemaValueCompletions(t,e,i){typeof t=="object"&&(this.addEnumValueCompletions(t,i),this.addDefaultValueCompletions(t,i),this.collectTypes(t,e),Array.isArray(t.allOf)&&t.allOf.forEach(s=>this.addSchemaValueCompletions(s,e,i)),Array.isArray(t.anyOf)&&t.anyOf.forEach(s=>this.addSchemaValueCompletions(s,e,i)),Array.isArray(t.oneOf)&&t.oneOf.forEach(s=>this.addSchemaValueCompletions(s,e,i)))}addDefaultValueCompletions(t,e,i=0){let s=!1;if(typeof t.default<"u"){let r=t.type,l=t.default;for(let c=i;c>0;c--)l=[l],r="array";const h=Object.assign(Object.assign({type:r==null?void 0:r.toString()},this.getAppliedValue(l)),{detail:"Default value"});e.add(h),s=!0}Array.isArray(t.examples)&&t.examples.forEach(r=>{let l=t.type,h=r;for(let c=i;c>0;c--)h=[h],l="array";e.add(Object.assign({type:l==null?void 0:l.toString()},this.getAppliedValue(h))),s=!0}),!s&&typeof t.items=="object"&&!Array.isArray(t.items)&&i<5&&this.addDefaultValueCompletions(t.items,e,i+1)}addEnumValueCompletions(t,e){var i,s;if(typeof t.const<"u"&&e.add(Object.assign(Object.assign({type:(i=t.type)===null||i===void 0?void 0:i.toString()},this.getAppliedValue(t.const)),{info:t.description})),Array.isArray(t.enum))for(let r=0,l=t.enum.length;r<l;r++){const h=t.enum[r];e.add(Object.assign(Object.assign({type:(s=t.type)===null||s===void 0?void 0:s.toString()},this.getAppliedValue(h)),{info:t.description}))}}addBooleanValueCompletion(t,e){e.add({type:"boolean",label:t?"true":"false"})}addNullValueCompletion(t){t.add({type:"null",label:"null"})}collectTypes(t,e){if(Array.isArray(t.enum)||typeof t.const<"u")return;const i=t.type;Array.isArray(i)?i.forEach(s=>e[s]=!0):i&&(e[i]=!0)}getSchemas(t,e){var i,s;const r=new qS(this.schema);let l=Sy(e.state,e.pos,-1,this.mode),h=r.getSchema({pointer:l});return vg(h)&&(h=(i=h.data)===null||i===void 0?void 0:i.schema),(!h||h.name==="UnknownPropertyError"||h.enum||h.type==="undefined")&&(l=l.replace(/\/[^/]*$/,"/"),h=r.getSchema({pointer:l})),ge.log("xxx","pointer..",JSON.stringify(l)),(!l||l==="/")&&(h=(s=this.expandSchemaProperty(t,t))!==null&&s!==void 0?s:t),ge.log("xxx","subSchema..",h),h?Array.isArray(h.allOf)?[h,...h.allOf.map(c=>this.expandSchemaProperty(c,t))]:Array.isArray(h.oneOf)?[h,...h.oneOf.map(c=>this.expandSchemaProperty(c,t))]:Array.isArray(h.anyOf)?[h,...h.anyOf.map(c=>this.expandSchemaProperty(c,t))]:[h]:[]}expandSchemaProperty(t,e){if(typeof t=="object"&&t.$ref){const i=this.getReferenceSchema(e,t.$ref);if(typeof i=="object"){const s=Object.assign(Object.assign({},t),i);return Reflect.deleteProperty(s,"$ref"),s}}return t}getReferenceSchema(t,e){const i=e.split("/");let s=t;return i.forEach(r=>{if(r){if(r==="#"){s=t;return}typeof s=="object"&&(s=s[r])}}),s}getAppliedValue(t){const e=Ml(JSON.stringify(t));switch(this.mode){case te.JSON5:return{label:e,apply:zD(JSON.stringify(t))};case te.YAML:return{label:e,apply:e};default:return{label:e,apply:JSON.stringify(t)}}}getValueFromLabel(t){return JSON.parse(t)}extendedRegExp(t){let e="";t.startsWith("(?i)")&&(t=t.substring(4),e="i");try{return new RegExp(t,e+"u")}catch{try{return new RegExp(t,e)}catch{return}}}}function aE(n={}){const t=new YD(n);return function(i){return t.doComplete(i)}}const Zr=(n,t)=>{const e=n.length>2;let i=n.map((s,r)=>{const l="`"+(t?t(s):s)+"`";return r===n.length-1?"or "+l:l});return e?i.join(", "):i.join(" ")};function vy(n){let t=null;try{t=JSON.parse(n.doc.toString())}catch{}const e=Df(n,te.JSON);return{data:t,pointers:e}}function hn(n,t,e=[]){const i=document.createElement(n);return Object.entries(t).forEach(([s,r])=>{if(s==="text"){i.innerText=r;return}if(s==="inner"){i.innerHTML=r;return}i.setAttribute(s,r)}),e.forEach(s=>i.appendChild(s)),i}function UD(n){let t=null;try{t=KS.parse(n.doc.toString())}catch{}const e=Df(n,te.YAML);return{data:t,pointers:e}}function XD(n){let t=null;try{t=jS.parse(n.doc.toString())}catch{}const e=Df(n,te.JSON5);return{data:t,pointers:e}}const JD=n=>{switch(n){case te.JSON:return vy;case te.JSON5:return XD;case te.YAML:return UD}},QD=n=>{var t,e,i;return!((t=n==null?void 0:n.data)===null||t===void 0)&&t.pointer&&((e=n==null?void 0:n.data)===null||e===void 0?void 0:e.pointer)!=="#"?n.data.pointer.slice(1):!((i=n==null?void 0:n.data)===null||i===void 0)&&i.property?`/${n.data.property}`:""},hE=n=>n.startState.field(Xl)!==n.state.field(Xl);function cE(n){const t=new tO(n);return e=>t.doValidation(e)}const ZD=["NoAdditionalPropertiesError","RequiredPropertyError","InvalidPropertyNameError","ForbiddenPropertyError","UndefinedValueError"];class tO{constructor(t){var e,i,s,r;this.options=t,this.schema=null,this.mode=te.JSON,this.parser=vy,this.rewriteError=l=>{var h,c,g,p,y;const x=l==null?void 0:l.data,T=x==null?void 0:x.errors;return l.code==="one-of-error"&&(T!=null&&T.length)?`Expected one of ${Zr(T,I=>I.data.expected)}`:l.code==="type-error"?`Expected \`${!((h=l==null?void 0:l.data)===null||h===void 0)&&h.expected&&Array.isArray((c=l==null?void 0:l.data)===null||c===void 0?void 0:c.expected)?Zr((g=l==null?void 0:l.data)===null||g===void 0?void 0:g.expected):(p=l==null?void 0:l.data)===null||p===void 0?void 0:p.expected}\` but received \`${(y=l==null?void 0:l.data)===null||y===void 0?void 0:y.received}\``:l.message.replaceAll("in `#` ","").replaceAll("at `#`","").replaceAll("/",".").replaceAll("#.","")},this.mode=(i=(e=this.options)===null||e===void 0?void 0:e.mode)!==null&&i!==void 0?i:te.JSON,this.parser=(r=(s=this.options)===null||s===void 0?void 0:s.jsonParser)!==null&&r!==void 0?r:JD(this.mode)}get schemaTitle(){var t,e,i;return(i=(e=(t=this.schema)===null||t===void 0?void 0:t.getSchema())===null||e===void 0?void 0:e.title)!==null&&i!==void 0?i:"json-schema"}doValidation(t){const e=Of(t.state);if(!e)return[];if(this.schema=new kg(e),!this.schema)return[];const i=t.state.doc.toString();if(!(i!=null&&i.length))return[];const s=this.parser(t.state);let r=[];try{r=this.schema.validate(s.data)}catch{}return ge.log("xxx","validation errors",r,s.data),r.length?r.reduce((l,h)=>{const c=()=>{const y=this.rewriteError(h);l.push({from:0,to:0,message:y,severity:"error",source:this.schemaTitle,renderMessage:()=>{const x=hn("div",{});return x.innerHTML=Fs(y),x}})},g=QD(h),p=s.pointers.get(g);if(h.name==="MaxPropertiesError"||h.name==="MinPropertiesError")c();else if(p){const y=ZD.includes(h.name),x=this.rewriteError(h),T=y?p.keyFrom:p.valueFrom,P=y?p.keyTo:p.valueTo;P!==void 0&&T!==void 0&&l.push({from:T,to:P,message:x,renderMessage:()=>{const I=hn("div",{});return I.innerHTML=Fs(x),I},severity:"error",source:this.schemaTitle})}else c();return l},[]):[]}}function fE(n){const t=new eO(n);return async function(i,s,r){return t.doHover(i,s,r)}}function lg(n){if(n.type)return n.$ref?`${n.$ref} (${n.type})`:n.type;if(n.$ref)return`${n.$ref}`}function kh(n,t,e){return`${t}: ${Zr(n[t].map(i=>{try{const{data:s}=e.resolveRef({data:i,pointer:i.$ref});return lg(s||i)}catch{return i.type}}))}`}class eO{constructor(t){var e,i;this.opts=t,this.schema=null,this.mode=te.JSON,this.opts=Object.assign({parser:JSON.parse},this.opts),this.mode=(i=(e=this.opts)===null||e===void 0?void 0:e.mode)!==null&&i!==void 0?i:te.JSON}getDataForCursor(t,e,i){const s=Of(t.state);if(!s)return null;this.schema=new kg(s);const r=Sy(t.state,e,i,this.mode);let l;try{l=this.opts.parser(t.state.doc.toString())}catch{}if(!r)return null;let h=this.schema.getSchema({pointer:r,data:l,withSchemaWarning:!0});return vg(h)&&(h!=null&&h.data.schema.$ref?h=this.schema.resolveRef(h):h=h==null?void 0:h.data.schema),{schema:h,pointer:r}}formatMessage(t){const{message:e,typeInfo:i}=t;return e?hn("div",{class:"cm6-json-schema-hover"},[hn("div",{class:"cm6-json-schema-hover--description",inner:Fs(e,!1)}),hn("div",{class:"cm6-json-schema-hover--code-wrapper"},[hn("div",{class:"cm6-json-schema-hover--code",inner:Fs(i,!1)})])]):hn("div",{class:"cm6-json-schema-hover"},[hn("div",{class:"cm6-json-schema-hover--code-wrapper"},[hn("code",{class:"cm6-json-schema-hover--code",inner:Fs(i,!1)})])])}getHoverTexts(t,e){let i="",s=null;const{schema:r}=t;return r.oneOf&&(i=kh(r,"oneOf",e)),r.anyOf&&(i=kh(r,"anyOf",e)),r.allOf&&(i=kh(r,"allOf",e)),r.type&&(i=Array.isArray(r.type)?Zr(r.type):r.type),r.$ref&&(i=` Reference: ${r.$ref}`),r.enum&&(i=`\`enum\`: ${Zr(r.enum)}`),r.format&&(i+=`\`format\`: ${r.format}`),r.pattern&&(i+=`\`pattern\`: ${r.pattern}`),r.description&&(s=r.description),{message:s,typeInfo:i}}async doHover(t,e,i){var s,r,l,h;const c=e,g=e;try{const p=this.getDataForCursor(t,e,i);if(ge.log("cursorData",p),!(p!=null&&p.schema))return null;const x=((r=(s=this.opts)===null||s===void 0?void 0:s.getHoverTexts)!==null&&r!==void 0?r:this.getHoverTexts)(p,this.schema),P=((h=(l=this.opts)===null||l===void 0?void 0:l.formatHover)!==null&&h!==void 0?h:this.formatMessage)(x);return{pos:c,end:g,arrow:!0,above:!0,create:I=>({dom:P})}}catch(p){return ge.log(p),null}}}const ag=new Cg,ky=new Set(["Script","Body","FunctionDefinition","ClassDefinition","LambdaExpression","ForStatement","MatchClause"]);function hl(n){return(t,e,i)=>{if(i)return!1;let s=t.node.getChild("VariableName");return s&&e(s,n),!0}}const iO={FunctionDefinition:hl("function"),ClassDefinition:hl("class"),ForStatement(n,t,e){if(e){for(let i=n.node.firstChild;i;i=i.nextSibling)if(i.name=="VariableName")t(i,"variable");else if(i.name=="in")break}},ImportStatement(n,t){var e,i;let{node:s}=n,r=((e=s.firstChild)===null||e===void 0?void 0:e.name)=="from";for(let l=s.getChild("import");l;l=l.nextSibling)l.name=="VariableName"&&((i=l.nextSibling)===null||i===void 0?void 0:i.name)!="as"&&t(l,r?"variable":"namespace")},AssignStatement(n,t){for(let e=n.node.firstChild;e;e=e.nextSibling)if(e.name=="VariableName")t(e,"variable");else if(e.name==":"||e.name=="AssignOp")break},ParamList(n,t){for(let e=null,i=n.node.firstChild;i;i=i.nextSibling)i.name=="VariableName"&&(!e||!/\*|AssignOp/.test(e.name))&&t(i,"variable"),e=i},CapturePattern:hl("variable"),AsPattern:hl("variable"),__proto__:null};function Cy(n,t){let e=ag.get(t);if(e)return e;let i=[],s=!0;function r(l,h){let c=n.sliceString(l.from,l.to);i.push({label:c,type:h})}return t.cursor(Jl.IncludeAnonymous).iterate(l=>{if(l.name){let h=iO[l.name];if(h&&h(l,r,s)||!s&&ky.has(l.name))return!1;s=!1}else if(l.to-l.from>8192){for(let h of Cy(n,l.node))i.push(h);return!1}}),ag.set(t,i),i}const hg=/^[\w\xa1-\uffff][\w\d\xa1-\uffff]*$/,My=["String","FormatString","Comment","PropertyName"];function nO(n){let t=ie(n.state).resolveInner(n.pos,-1);if(My.indexOf(t.name)>-1)return null;let e=t.name=="VariableName"||t.to-t.from<20&&hg.test(n.state.sliceDoc(t.from,t.to));if(!e&&!n.explicit)return null;let i=[];for(let s=t;s;s=s.parent)ky.has(s.name)&&(i=i.concat(Cy(n.state.doc,s)));return{options:i,from:e?t.from:n.pos,validFor:hg}}const sO=["__annotations__","__builtins__","__debug__","__doc__","__import__","__name__","__loader__","__package__","__spec__","False","None","True"].map(n=>({label:n,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(n=>({label:n,type:"type"}))).concat(["bool","bytearray","bytes","classmethod","complex","float","frozenset","int","list","map","memoryview","object","range","set","staticmethod","str","super","tuple","type"].map(n=>({label:n,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(n=>({label:n,type:"function"}))),rO=[oe("def ${name}(${params}):\n ${}",{label:"def",detail:"function",type:"keyword"}),oe("for ${name} in ${collection}:\n ${}",{label:"for",detail:"loop",type:"keyword"}),oe("while ${}:\n ${}",{label:"while",detail:"loop",type:"keyword"}),oe("try:\n ${}\nexcept ${error}:\n ${}",{label:"try",detail:"/ except block",type:"keyword"}),oe(`if \${}:
20
-
21
- `,{label:"if",detail:"block",type:"keyword"}),oe("if ${}:\n ${}\nelse:\n ${}",{label:"if",detail:"/ else block",type:"keyword"}),oe("class ${name}:\n def __init__(self, ${params}):\n ${}",{label:"class",detail:"definition",type:"keyword"}),oe("import ${module}",{label:"import",detail:"statement",type:"keyword"}),oe("from ${module} import ${names}",{label:"from",detail:"import",type:"keyword"})],oO=Qb(My,xf(sO.concat(rO)));function cg(n,t){let e=n.baseIndentFor(t),i=n.lineAt(n.pos,-1),s=i.from+i.text.length;return/^\s*($|#)/.test(i.text)&&n.node.to<s+100&&!/\S/.test(n.state.sliceDoc(s,n.node.to))&&n.lineIndent(n.pos,-1)<=e||/^\s*(else:|elif |except |finally:)/.test(n.textAfter)&&n.lineIndent(n.pos,-1)>e?null:e+n.unit}const Ch=Wr.define({name:"python",parser:_S.configure({props:[Jc.add({Body:n=>{var t;return(t=cg(n,n.node))!==null&&t!==void 0?t:n.continue()},IfStatement:n=>/^\s*(else:|elif )/.test(n.textAfter)?n.baseIndent:n.continue(),TryStatement:n=>/^\s*(except |finally:|else:)/.test(n.textAfter)?n.baseIndent:n.continue(),"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression":Sl({closing:")"}),"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression":Sl({closing:"}"}),"ArrayExpression ArrayComprehensionExpression":Sl({closing:"]"}),"String FormatString":()=>null,Script:n=>{if(n.pos+/\s*/.exec(n.textAfter)[0].length>=n.node.to){let t=null;for(let e=n.node,i=e.to;e=e.lastChild,!(!e||e.to!=i);)e.type.name=="Body"&&(t=e);if(t){let e=cg(n,t);if(e!=null)return e}}return n.continue()}}),Zc.add({"ArrayExpression DictionaryExpression SetExpression TupleExpression":_m,Body:(n,t)=>({from:n.from+1,to:n.to-(n.to==t.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 dE(){return new qm(Ch,[Ch.data.of({autocomplete:nO}),Ch.data.of({autocomplete:oO})])}const Ay=[oe("function ${name}(${params}) {\n ${}\n}",{label:"function",detail:"definition",type:"keyword"}),oe("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n ${}\n}",{label:"for",detail:"loop",type:"keyword"}),oe("for (let ${name} of ${collection}) {\n ${}\n}",{label:"for",detail:"of loop",type:"keyword"}),oe("do {\n ${}\n} while (${})",{label:"do",detail:"loop",type:"keyword"}),oe("while (${}) {\n ${}\n}",{label:"while",detail:"loop",type:"keyword"}),oe(`try {
22
- \${}
23
- } catch (\${error}) {
24
- \${}
25
- }`,{label:"try",detail:"/ catch block",type:"keyword"}),oe("if (${}) {\n ${}\n}",{label:"if",detail:"block",type:"keyword"}),oe(`if (\${}) {
26
- \${}
27
- } else {
28
- \${}
29
- }`,{label:"if",detail:"/ else block",type:"keyword"}),oe(`class \${name} {
30
- constructor(\${params}) {
31
- \${}
32
- }
33
- }`,{label:"class",detail:"definition",type:"keyword"}),oe('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),oe('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],lO=Ay.concat([oe("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),oe("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),oe("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),fg=new Cg,Ty=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function wr(n){return(t,e)=>{let i=t.node.getChild("VariableDefinition");return i&&e(i,n),!0}}const aO=["FunctionDeclaration"],hO={FunctionDeclaration:wr("function"),ClassDeclaration:wr("class"),ClassExpression:()=>!0,EnumDeclaration:wr("constant"),TypeAliasDeclaration:wr("type"),NamespaceDeclaration:wr("namespace"),VariableDefinition(n,t){n.matchContext(aO)||t(n,"variable")},TypeDefinition(n,t){t(n,"type")},__proto__:null};function Dy(n,t){let e=fg.get(t);if(e)return e;let i=[],s=!0;function r(l,h){let c=n.sliceString(l.from,l.to);i.push({label:c,type:h})}return t.cursor(Jl.IncludeAnonymous).iterate(l=>{if(s)s=!1;else if(l.name){let h=hO[l.name];if(h&&h(l,r)||Ty.has(l.name))return!1}else if(l.to-l.from>8192){for(let h of Dy(n,l.node))i.push(h);return!1}}),fg.set(t,i),i}const dg=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,Oy=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName",".","?."];function cO(n){let t=ie(n.state).resolveInner(n.pos,-1);if(Oy.indexOf(t.name)>-1)return null;let e=t.name=="VariableName"||t.to-t.from<20&&dg.test(n.state.sliceDoc(t.from,t.to));if(!e&&!n.explicit)return null;let i=[];for(let s=t;s;s=s.parent)Ty.has(s.name)&&(i=i.concat(Dy(n.state.doc,s)));return{options:i,from:e?t.from:n.pos,validFor:dg}}const ts=Wr.define({name:"javascript",parser:GS.configure({props:[Jc.add({IfStatement:eh({except:/^\s*({|else\b)/}),TryStatement:eh({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:Hv,SwitchBody:n=>{let t=n.textAfter,e=/^\s*\}/.test(t),i=/^\s*(case|default)\b/.test(t);return n.baseIndent+(e?0:i?1:2)*n.unit},Block:Sl({closing:"}"}),ArrowFunction:n=>n.baseIndent+n.unit,"TemplateString BlockComment":()=>null,"Statement Property":eh({except:/^{/}),JSXElement(n){let t=/^\s*<\//.test(n.textAfter);return n.lineIndent(n.node.from)+(t?0:n.unit)},JSXEscape(n){let t=/\s*\}/.test(n.textAfter);return n.lineIndent(n.node.from)+(t?0:n.unit)},"JSXOpenTag JSXSelfClosingTag"(n){return n.column(n.node.from)+n.unit}}),Zc.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":_m,BlockComment(n){return{from:n.from+2,to:n.to-2}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),Ey={test:n=>/^JSX/.test(n.name),facet:Wm({commentTokens:{block:{open:"{/*",close:"*/}"}}})},fO=ts.configure({dialect:"ts"},"typescript"),dO=ts.configure({dialect:"jsx",props:[Uc.add(n=>n.isTop?[Ey]:void 0)]}),uO=ts.configure({dialect:"jsx ts",props:[Uc.add(n=>n.isTop?[Ey]:void 0)]},"typescript");let Py=n=>({label:n,type:"keyword"});const Ry="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(Py),pO=Ry.concat(["declare","implements","private","protected","public"].map(Py));function uE(n={}){let t=n.jsx?n.typescript?uO:dO:n.typescript?fO:ts,e=n.typescript?lO.concat(pO):Ay.concat(Ry);return new qm(t,[ts.data.of({autocomplete:Qb(Oy,xf(e))}),ts.data.of({autocomplete:cO}),n.jsx?bO:[]])}function gO(n){for(;;){if(n.name=="JSXOpenTag"||n.name=="JSXSelfClosingTag"||n.name=="JSXFragmentTag")return n;if(n.name=="JSXEscape"||!n.parent)return null;n=n.parent}}function ug(n,t,e=n.length){for(let i=t==null?void 0:t.firstChild;i;i=i.nextSibling)if(i.name=="JSXIdentifier"||i.name=="JSXBuiltin"||i.name=="JSXNamespacedName"||i.name=="JSXMemberExpression")return n.sliceString(i.from,Math.min(i.to,e));return""}const mO=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),bO=mt.inputHandler.of((n,t,e,i,s)=>{if((mO?n.composing:n.compositionStarted)||n.state.readOnly||t!=e||i!=">"&&i!="/"||!ts.isActiveAt(n.state,t,-1))return!1;let r=s(),{state:l}=r,h=l.changeByRange(c=>{var g;let{head:p}=c,y=ie(l).resolveInner(p-1,-1),x;if(y.name=="JSXStartTag"&&(y=y.parent),!(l.doc.sliceString(p-1,p)!=i||y.name=="JSXAttributeValue"&&y.to>p)){if(i==">"&&y.name=="JSXFragmentTag")return{range:c,changes:{from:p,insert:"</>"}};if(i=="/"&&y.name=="JSXStartCloseTag"){let T=y.parent,P=T.parent;if(P&&T.from==p-2&&((x=ug(l.doc,P.firstChild,p))||((g=P.firstChild)===null||g===void 0?void 0:g.name)=="JSXFragmentTag")){let I=`${x}>`;return{range:A.EditorSelection.cursor(p+I.length,-1),changes:{from:p,insert:I}}}}else if(i==">"){let T=gO(y);if(T&&T.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(l.doc.sliceString(p,p+2))&&(x=ug(l.doc,T,p)))return{range:c,changes:{from:p,insert:`</${x}>`}}}}return{range:c}});return h.changes.empty?!1:(n.dispatch([r,l.update(h,{userEvent:"input.complete",scrollIntoView:!0})]),!0)});export{mt as E,Wr as L,MD as R,qm as a,AC as b,aE as c,tE as d,pv as e,fE as f,iE as g,hE as h,nE as i,cE as j,Xs as k,eE as l,uE as m,XT as n,dE as p,lE as s};