diff --git a/docs/requirements.txt b/docs/requirements.txt
index 0ab737a..555c4a2 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -1,3 +1,5 @@
+ipython
+ipykernel
sphinx
nbsphinx
sphinx-material
diff --git a/docs/src/check.ipynb b/docs/src/check.ipynb
index 9c86666..8b1bcdb 100644
--- a/docs/src/check.ipynb
+++ b/docs/src/check.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
- "id": "dac2ffd0-6144-4f07-b050-4895018d20fe",
+ "id": "0",
"metadata": {},
"source": [
"# Writing checks"
@@ -10,7 +10,7 @@
},
{
"cell_type": "markdown",
- "id": "af868249-e96e-44f1-8ed4-1f8bb9b632b6",
+ "id": "1",
"metadata": {},
"source": [
"Checks intention is to give students a way to validate their code solution. The student's code can be validated by providing a list of inputs and references comparing the output of the student's code with the references, or by directy testing certain functional behavior of the code. In cases when reference outputs need to be obfuscated the outputs that are compared can be passed through a _fingerprint_ function. This notebook goes through each of these features and presents an example."
@@ -18,8 +18,8 @@
},
{
"cell_type": "code",
- "execution_count": 1,
- "id": "d0fb3494-ef99-4872-bbfd-fb6bb277aae4",
+ "execution_count": 2,
+ "id": "2",
"metadata": {
"tags": []
},
@@ -32,7 +32,7 @@
},
{
"cell_type": "markdown",
- "id": "9ba29257-5b8e-4b57-a397-bfc169b799e9",
+ "id": "3",
"metadata": {},
"source": [
"Similar as for the `ExerciseRegistry` we need to define a `CheckRegistry` that registers the checks for each exercise."
@@ -40,8 +40,8 @@
},
{
"cell_type": "code",
- "execution_count": 2,
- "id": "9b1a451b-5aac-4b14-9c19-c103d55fcda5",
+ "execution_count": 3,
+ "id": "4",
"metadata": {
"tags": []
},
@@ -52,7 +52,7 @@
},
{
"cell_type": "markdown",
- "id": "2e42e747-0b38-4849-a380-630eb77a1570",
+ "id": "5",
"metadata": {},
"source": [
"## Checks using inputs and output references"
@@ -60,17 +60,16 @@
},
{
"cell_type": "code",
- "execution_count": 3,
- "id": "e440765f-66f9-4505-83f3-18396729ab2c",
+ "execution_count": 4,
+ "id": "6",
"metadata": {
- "scrolled": true,
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "e729b5426a374e23a69a9452e2155448",
+ "model_id": "5885830d34fa4f9492d864ed95515eab",
"version_major": 2,
"version_minor": 0
},
@@ -78,7 +77,7 @@
"CodeExercise(children=(CssStyle(value='\",n=i.attributes.function_body_id;console.log(\"theTextareaId = %s\",n);let s=document.createElement(\"textArea\");t.appendChild(s),s.outerHTML=r+'';function o(l,a){let h=new T({state:Y.create({doc:l.value,extensions:a})});return l.parentNode.insertBefore(h.dom,l),l.style.display=\"none\",l.form&&l.form.addEventListener(\"submit\",()=>{l.value=h.state.doc.toString()}),h}ll(()=>{var l=new pe,a=new pe,h=new pe,f=new pe;let c=o(document.getElementById(n+\"-signature\"),[Y.readOnly.of(!0),ui(),ke.of(\" \"),mo(),Ls(),Vs(),Y.allowMultipleSelections.of(!0),Te(eo,{fallback:!0}),io(),ao(),co(),qa(),Ws(),eg(),a.of(Hn),Fe.of([...ho,...So,...Zo,...Oo,...to,...hn,...Mo])]);c.dom.classList.add(\"widget-code-input-signature\");var u=o(document.getElementById(n+\"-docstring\"),[ui(),Y.readOnly.of(!0),T.editorAttributes.of({class:\"widget-code-input-docstring\"}),_r({class:\"forced-indent\"}),l.of(ui()),mo(),Ls(),Vs(),Y.allowMultipleSelections.of(!0),Te(eo,{fallback:!0}),io(),ao(),co(),qa(),Ws(),Fe.of([...ho,...So,...Zo,...Oo,...to,...hn,...Mo]),Hh(),ke.of(\" \"),h.of(Hn)]);c.dom.classList.add(\"widget-code-input-signature\");var d=new pe,m=o(document.getElementById(n+\"-body\"),[l.of(ui()),_r({class:\"forced-indent\"}),d.of([]),mo(),Ls(),Vs(),Y.allowMultipleSelections.of(!0),Te(eo,{fallback:!0}),io(),ao(),co(),Ws(),Fe.of([...ho,...So,...Zo,...Oo,...to,...hn,...Mo]),Hh(),ke.of(\" \"),f.of(Hn)]);m.dom.classList.add(\"widget-code-input-body\");let O=T.updateListener.of(y=>{y.docChanged&&(i.set(\"function_body\",m.state.doc.toString()),i.save_changes(),console.log(\"BodyChange event registered.\"))});m.dispatch({effects:d.reconfigure(O)});function g(){let y=\"def \"+i.get(\"function_name\")+\"(\"+i.get(\"function_parameters\")+\"):\";y!==c.state.doc.toString()&&c.dispatch({changes:{from:0,to:c.state.doc.length,insert:y}})}function x(){let y=c.state.doc.toString().split(`\n`).length,k=u.state.doc.toString().split(`\n`).length;u.dispatch({effects:l.reconfigure(ui({formatNumber:w=>y+w}))}),m.dispatch({effects:l.reconfigure(ui({formatNumber:w=>y+k+w}))})}function S(){console.log(\"updating docstring\");let y='\"\"\"'+i.get(\"docstring\")+'\"\"\"';y!==u.state.doc.toString()&&u.dispatch({changes:{from:0,to:u.state.doc.length,insert:y}}),x()}function C(){i.get(\"function_body\")!==m.state.doc.toString()&&m.dispatch({changes:{from:0,to:m.state.doc.length,insert:i.get(\"function_body\")}})}function v(){var y,k=i.get(\"code_theme\"),w={nord:Kg,solarizedLight:rO,basicLight:Hn};if(k in w)y=w[k];else throw new Error(\"Specified code theme is not supported.\");console.log(\"theme changed, theme= %s\",k),c.dispatch({effects:a.reconfigure(y)}),u.dispatch({effects:h.reconfigure(y)}),m.dispatch({effects:f.reconfigure(y)}),c.dom.classList.add(\"widget-code-input-signature\"),m.dom.classList.add(\"widget-code-input-body\")}g(),S(),C(),v(),i.on(\"change:docstring\",()=>{console.log(\"docstring changed\"),S()}),i.on(\"change:function_body\",()=>{C()}),i.on(\"change:code_theme\",()=>{console.log(\"theme change event\"),v()})})}};export{hq as default};\n",
- "_model_module": "anywidget",
- "_model_module_version": "~0.9.*",
- "_model_name": "AnyModel",
- "_view_module": "anywidget",
- "_view_module_version": "~0.9.*",
- "_view_name": "AnyView",
- "code_theme": "basicLight",
- "docstring": "\n",
- "function_body": "import numpy as np\nreturn np.cos(arr) # oops! wrong solution\n",
- "function_name": "sin",
- "function_parameters": "arr",
- "layout": "IPY_MODEL_2bde408380a94636a1a3272ad8e733ce",
- "name": "",
- "widget_instance_count_trait": "0"
- }
- },
- "41e0bfcb0b594f9ab8d810fe0210c8e9": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "ButtonStyleModel",
- "state": {
- "font_family": null,
- "font_size": null,
- "font_style": null,
- "font_variant": null,
- "font_weight": null,
- "text_color": null,
- "text_decoration": null
- }
- },
- "433bb630da464ff9bca86daae245bb95": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "BoxModel",
- "state": {
- "layout": "IPY_MODEL_589a8579563d4fa190578e92d42c70ed"
- }
- },
- "4377476c1c4341059b5f64a4fdb4a5a4": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "ButtonStyleModel",
- "state": {
- "font_family": null,
- "font_size": null,
- "font_style": null,
- "font_variant": null,
- "font_weight": null,
- "text_color": null,
- "text_decoration": null
- }
- },
- "43ef27be9b79499e9b6f4c09b4b71254": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "HBoxModel",
- "state": {
- "children": [
- "IPY_MODEL_221c767641da43cf8397cc1acbf39358",
- "IPY_MODEL_10d2616145d0495fab9305c66d97c8e9"
- ],
- "layout": "IPY_MODEL_733df51db84a415a83e8765547fb7c3c"
- }
- },
- "44695f8c538142d2af32de53ddc069d4": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "VBoxModel",
- "state": {
- "_dom_classes": [
- "scwidget-check-cue-box"
- ],
- "children": [
- "IPY_MODEL_3f6e71fbcbc443a2aac9753b1ba51f44"
- ],
- "layout": "IPY_MODEL_466ffdf6a8e74db8b76e92ac5a732eb3"
- }
- },
- "4580593cf2ea41dc99f75f7de2e8ddd8": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "ButtonModel",
- "state": {
- "_dom_classes": [
- "scwidget-update-reset-cue-button--cue",
- "scwidget-update-reset-cue-button"
- ],
- "description": "Run Code",
- "layout": "IPY_MODEL_696d1bd96b1243679f7b14b194f29b13",
- "style": "IPY_MODEL_4a4a240012f24af6842d1caba331fd59",
- "tooltip": null
- }
- },
- "466db0a2a5114b5a95394b87003e03bc": {
- "model_module": "@jupyter-widgets/output",
- "model_module_version": "1.0.0",
- "model_name": "OutputModel",
- "state": {
- "_dom_classes": [
- "scwidget-cue-output"
- ],
- "layout": "IPY_MODEL_50d21651d2d64a07a50354cb065bcba6",
- "outputs": [
- {
- "ename": "CodeValidationError",
- "evalue": "Oops!",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
- "File \u001b[0;32m~/code/scicode-widgets/src/scwidgets/code/_widget_code_input.py:183\u001b[0m, in \u001b[0;36mCodeInput.get_function_object..catch_exceptions..wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 182\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 183\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 184\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n",
- "File \u001b[0;32mscwidgets.code._widget_code_input:4\u001b[0m, in \u001b[0;36merror\u001b[0;34m(arr)\u001b[0m\n",
- "\u001b[0;31mValueError\u001b[0m: Oops!",
- "\nThe above exception was the direct cause of the following exception:\n",
- "\u001b[0;31mCodeValidationError\u001b[0m Traceback (most recent call last)",
- "File \u001b[0;32m~/code/scicode-widgets/src/scwidgets/exercise/_widget_code_exercise.py:605\u001b[0m, in \u001b[0;36mCodeExercise.handle_checks_result\u001b[0;34m(self, results)\u001b[0m\n\u001b[1;32m 603\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m result \u001b[38;5;129;01min\u001b[39;00m results:\n\u001b[1;32m 604\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(result, \u001b[38;5;167;01mException\u001b[39;00m):\n\u001b[0;32m--> 605\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m result\n\u001b[1;32m 606\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(result, CheckResult):\n\u001b[1;32m 607\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m result\u001b[38;5;241m.\u001b[39msuccessful:\n",
- "File \u001b[0;32m~/code/scicode-widgets/src/scwidgets/check/_widget_check_registry.py:246\u001b[0m, in \u001b[0;36mCheckRegistry.check_widget\u001b[0;34m(self, widget)\u001b[0m\n\u001b[1;32m 244\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 245\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m check \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_checks[widget]:\n\u001b[0;32m--> 246\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mcheck\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcheck_function\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 247\u001b[0m checks_result\u001b[38;5;241m.\u001b[39mappend(result)\n\u001b[1;32m 248\u001b[0m widget\u001b[38;5;241m.\u001b[39mhandle_checks_result(checks_result)\n",
- "File \u001b[0;32m~/code/scicode-widgets/src/scwidgets/check/_check.py:228\u001b[0m, in \u001b[0;36mCheck.check_function\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 225\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m check_result\n\u001b[1;32m 227\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, input_parameters \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_inputs_parameters):\n\u001b[0;32m--> 228\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_function_to_check\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minput_parameters\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 229\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (\u001b[38;5;28misinstance\u001b[39m(output, \u001b[38;5;28mtuple\u001b[39m)):\n\u001b[1;32m 230\u001b[0m output \u001b[38;5;241m=\u001b[39m (output,)\n",
- "File \u001b[0;32m~/code/scicode-widgets/src/scwidgets/exercise/_widget_code_exercise.py:598\u001b[0m, in \u001b[0;36mCodeExercise.compute_output_to_check\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 597\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcompute_output_to_check\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Check\u001b[38;5;241m.\u001b[39mFunOutParamsT:\n\u001b[0;32m--> 598\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_code\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[0;32m~/code/scicode-widgets/src/scwidgets/exercise/_widget_code_exercise.py:716\u001b[0m, in \u001b[0;36mCodeExercise.run_code\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 714\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_code\u001b[38;5;241m.\u001b[39mrun(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 715\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m CodeValidationError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m--> 716\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m 717\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 718\u001b[0m \u001b[38;5;66;03m# we give the student the additional information that this is most likely\u001b[39;00m\n\u001b[1;32m 719\u001b[0m \u001b[38;5;66;03m# not because of his code\u001b[39;00m\n\u001b[1;32m 720\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m python_version() \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m3.11\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n",
- "File \u001b[0;32m~/code/scicode-widgets/src/scwidgets/exercise/_widget_code_exercise.py:714\u001b[0m, in \u001b[0;36mCodeExercise.run_code\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 710\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_code \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 711\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 712\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrun_code was invoked, but no code was given on initializaion\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 713\u001b[0m )\n\u001b[0;32m--> 714\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_code\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 715\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m CodeValidationError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 716\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n",
- "File \u001b[0;32m~/code/scicode-widgets/src/scwidgets/code/_widget_code_input.py:96\u001b[0m, in \u001b[0;36mCodeInput.run\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 95\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mrun\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Check\u001b[38;5;241m.\u001b[39mFunOutParamsT:\n\u001b[0;32m---> 96\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_function_object\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[0;32m~/code/scicode-widgets/src/scwidgets/code/_widget_code_input.py:186\u001b[0m, in \u001b[0;36mCodeInput.get_function_object..catch_exceptions..wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 184\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n\u001b[1;32m 185\u001b[0m err_msg \u001b[38;5;241m=\u001b[39m format_generic_error_msg(exc, code_widget\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m)\n\u001b[0;32m--> 186\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m CodeValidationError(err_msg, orig_exc\u001b[38;5;241m=\u001b[39mexc) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mexc\u001b[39;00m\n",
- "\u001b[0;31mCodeValidationError\u001b[0m: Oops!"
- ]
- }
- ]
- }
- },
- "466ffdf6a8e74db8b76e92ac5a732eb3": {
- "model_module": "@jupyter-widgets/base",
- "model_module_version": "2.0.0",
- "model_name": "LayoutModel",
- "state": {}
- },
- "46e23c72045b46e1a9e8831719d8591f": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "ButtonModel",
- "state": {
- "_dom_classes": [
- "scwidget-update-reset-cue-button--cue",
- "scwidget-update-reset-cue-button"
- ],
- "description": "Run Code",
- "layout": "IPY_MODEL_c73eebb402f14d05bfa5f173a08bd91e",
- "style": "IPY_MODEL_55f1aaedb8834ca8a51e8e9e2c5bff20",
- "tooltip": null
- }
- },
- "481b47d792324002bc663bba879bb144": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "VBoxModel",
- "state": {
- "children": [
- "IPY_MODEL_2ff34c41202e4d4fbaa00c4aff90bbed",
- "IPY_MODEL_d8a5315c617643319e1f0ad2e9568454"
- ],
- "layout": "IPY_MODEL_71ad7b23d9c64a55871fcb1010dadfdc"
- }
- },
- "493cc835cb304c58ab517e5e13cedbb2": {
- "model_module": "@jupyter-widgets/base",
- "model_module_version": "2.0.0",
- "model_name": "LayoutModel",
- "state": {}
- },
- "496ad00ff7f84a6ba032fe894a762853": {
- "model_module": "@jupyter-widgets/base",
- "model_module_version": "2.0.0",
- "model_name": "LayoutModel",
- "state": {}
- },
- "4a4a240012f24af6842d1caba331fd59": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "ButtonStyleModel",
- "state": {
- "font_family": null,
- "font_size": null,
- "font_style": null,
- "font_variant": null,
- "font_weight": null,
- "text_color": null,
- "text_decoration": null
- }
- },
- "4df9d96b536b407b86d9cca0e0592c3f": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "ButtonModel",
- "state": {
- "_dom_classes": [
- "scwidget-check-reset-cue-button"
- ],
- "description": "Check Code",
- "layout": "IPY_MODEL_fd84cedfaa694eaf8ac3b1d33a6974a7",
- "style": "IPY_MODEL_41e0bfcb0b594f9ab8d810fe0210c8e9",
- "tooltip": null
- }
- },
- "4e04b3a6d754476492f0241f50540e35": {
- "model_module": "@jupyter-widgets/base",
- "model_module_version": "2.0.0",
- "model_name": "LayoutModel",
- "state": {
- "height": "auto",
- "width": "98%"
- }
- },
- "4e6e13dbf4e34a7e935d809814ce52eb": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "BoxModel",
- "state": {
- "layout": "IPY_MODEL_d1a60bd51f8d489f91843d472de4301f"
- }
- },
- "50d21651d2d64a07a50354cb065bcba6": {
- "model_module": "@jupyter-widgets/base",
- "model_module_version": "2.0.0",
- "model_name": "LayoutModel",
- "state": {}
- },
- "51c3f8e31b5f493f93487d29001d0833": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "VBoxModel",
- "state": {
- "_dom_classes": [
- "scwidget-check-cue-box"
- ],
- "children": [
- "IPY_MODEL_5fcfe503ae514e3aa4b0f1dca07a9a40"
- ],
- "layout": "IPY_MODEL_d2f739cc8d7845baa1b885e6ba99e971"
- }
- },
- "51f3e350b5684d9cb19536e536f3e880": {
- "model_module": "@jupyter-widgets/base",
- "model_module_version": "2.0.0",
- "model_name": "LayoutModel",
- "state": {}
- },
- "52dcae1ea61a4d0d80b57f01f299c2c3": {
- "model_module": "@jupyter-widgets/base",
- "model_module_version": "2.0.0",
- "model_name": "LayoutModel",
- "state": {}
- },
- "55f1aaedb8834ca8a51e8e9e2c5bff20": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "ButtonStyleModel",
- "state": {
- "font_family": null,
- "font_size": null,
- "font_style": null,
- "font_variant": null,
- "font_weight": null,
- "text_color": null,
- "text_decoration": null
- }
- },
- "577ee11e411f4d37ae823d5212a4e2cb": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "ButtonStyleModel",
- "state": {
- "font_family": null,
- "font_size": null,
- "font_style": null,
- "font_variant": null,
- "font_weight": null,
- "text_color": null,
- "text_decoration": null
- }
- },
- "589a8579563d4fa190578e92d42c70ed": {
- "model_module": "@jupyter-widgets/base",
- "model_module_version": "2.0.0",
- "model_name": "LayoutModel",
- "state": {}
- },
- "5af82ea6570841aaaf370f78bed416c4": {
- "model_module": "@jupyter-widgets/controls",
- "model_module_version": "2.0.0",
- "model_name": "VBoxModel",
- "state": {
- "children": [
- "IPY_MODEL_fa01047fd83c4eef941430a987639762",
- "IPY_MODEL_94a080c3594942958cfbe1be2c1cf21e",
- "IPY_MODEL_7f0642279f664162a1e020bfbd4fa9df",
- "IPY_MODEL_466db0a2a5114b5a95394b87003e03bc"
- ],
- "layout": "IPY_MODEL_6279ce1cf3c442579fc5efade187ceb9"
- }
- },
- "5c94c6779781453badd89780ac751951": {
- "model_module": "@jupyter-widgets/output",
- "model_module_version": "1.0.0",
- "model_name": "OutputModel",
- "state": {
- "_dom_classes": [
- "scwidget-cue-output"
- ],
- "layout": "IPY_MODEL_cb7fcdad52f4419bbd65471779179eb4",
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": "\u001b[1m\u001b[31mCheck failed\u001b[0m\n\u001b[1m\u001b[31m------------\u001b[0m\n\u001b[92massert_type passed\u001b[0m\u001b[92m for input\n\u001b[0m \u001b[94marr\u001b[0m: array([0. , 0.78539816, 1.57079633, 2.35619449, 3.14159265])\n\u001b[92massert_shape passed\u001b[0m\u001b[92m for input\n\u001b[0m \u001b[94marr\u001b[0m: array([0. , 0.78539816, 1.57079633, 2.35619449, 3.14159265])\n\u001b[91massert_numpy_allclose failed\u001b[0m\u001b[91m for\n\u001b[0m\u001b[91m|\u001b[0m \u001b[94marr\u001b[0m: array([0. , 0.78539816, 1.57079633, 2.35619449, 3.14159265])\n\u001b[91m|\u001b[0m \u001b[94m> output 0: \u001b[0m[ 1.00000000e+00 7.07106784e-01 -3.20510345e-09 -7.07106781e-01\n\u001b[91m|\u001b[0m -1.00000000e+00]\n\u001b[91m|\u001b[0m \u001b[91mOutput is not close to reference absolute difference is 4.414213567844548, relative difference is 5.000000006794897.\u001b[0m\n"
- }
- ]
- }
- },
- "5fcfe503ae514e3aa4b0f1dca07a9a40": {
- "model_module": "anywidget",
- "model_module_version": "~0.9.*",
- "model_name": "AnyModel",
- "state": {
- "_anywidget_id": "scwidgets.code._widget_code_input.CodeInput",
- "_css": ".forced-indent{width:4em}.CodeMirror{border:1px solid #fff;height:auto}.CodeMirror.widget-code-input-signature{border-bottom:0px}.CodeMirror.widget-code-input-docstring,.CodeMirror.widget-code-input-body{border-top:0px}\n",
- "_esm": "var cO=Object.defineProperty;var uO=(i,t)=>{for(var e in t)cO(i,e,{get:t[e],enumerable:!0})};var V=class i{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,r){[t,e]=Li(this,t,e);let n=[];return this.decompose(0,t,n,2),r.length&&r.decompose(0,r.length,n,3),this.decompose(e,this.length,n,1),qi.from(n,this.length-(e-t)+r.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=Li(this,t,e);let r=[];return this.decompose(t,e,r,0),qi.from(r,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),r=this.length-this.scanIdentical(t,-1),n=new oi(this),s=new oi(t);for(let o=e,l=e;;){if(n.next(o),s.next(o),o=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(l+=n.value.length,n.done||l>=r)return!0}}iter(t=1){return new oi(this,t)}iterRange(t,e=this.length){return new ts(this,t,e)}iterLines(t,e){let r;if(t==null)r=this.iter();else{e==null&&(e=this.lines+1);let n=this.line(t).from;r=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new es(r)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(t.length==0)throw new RangeError(\"A document must have at least one line\");return t.length==1&&!t[0]?i.empty:t.length<=32?new Xt(t):qi.from(Xt.split(t,[]))}},Xt=class i extends V{constructor(t,e=dO(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,r,n){for(let s=0;;s++){let o=this.text[s],l=n+o.length;if((e?r:l)>=t)return new bl(n,l,r,o);n=l+1,r++}}decompose(t,e,r,n){let s=t<=0&&e>=this.length?this:new i(Ec(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(n&1){let o=r.pop(),l=Jn(s.text,o.text.slice(),0,s.length);if(l.length<=32)r.push(new i(l,o.length+s.length));else{let a=l.length>>1;r.push(new i(l.slice(0,a)),new i(l.slice(a)))}}else r.push(s)}replace(t,e,r){if(!(r instanceof i))return super.replace(t,e,r);[t,e]=Li(this,t,e);let n=Jn(this.text,Jn(r.text,Ec(this.text,0,t)),e),s=this.length+r.length-(e-t);return n.length<=32?new i(n,s):qi.from(i.split(n,[]),s)}sliceString(t,e=this.length,r=`\n`){[t,e]=Li(this,t,e);let n=\"\";for(let s=0,o=0;s<=e&&ot&&o&&(n+=r),ts&&(n+=l.slice(Math.max(0,t-s),e-s)),s=a+1}return n}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let r=[],n=-1;for(let s of t)r.push(s),n+=s.length+1,r.length==32&&(e.push(new i(r,n)),r=[],n=-1);return n>-1&&e.push(new i(r,n)),e}},qi=class i extends V{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let r of t)this.lines+=r.lines}lineInner(t,e,r,n){for(let s=0;;s++){let o=this.children[s],l=n+o.length,a=r+o.lines-1;if((e?a:l)>=t)return o.lineInner(t,e,r,n);n=l+1,r=a+1}}decompose(t,e,r,n){for(let s=0,o=0;o<=e&&s=o){let h=n&((o<=t?1:0)|(a>=e?2:0));o>=t&&a<=e&&!h?r.push(l):l.decompose(t-o,e-o,r,h)}o=a+1}}replace(t,e,r){if([t,e]=Li(this,t,e),r.lines=s&&e<=l){let a=o.replace(t-s,e-s,r),h=this.lines-o.lines+a.lines;if(a.lines>4&&a.lines>h>>6){let f=this.children.slice();return f[n]=a,new i(f,this.length-(e-t)+r.length)}return super.replace(s,l,a)}s=l+1}return super.replace(t,e,r)}sliceString(t,e=this.length,r=`\n`){[t,e]=Li(this,t,e);let n=\"\";for(let s=0,o=0;st&&s&&(n+=r),to&&(n+=l.sliceString(t-o,e-o,r)),o=a+1}return n}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof i))return 0;let r=0,[n,s,o,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,s+=e){if(n==o||s==l)return r;let a=this.children[n],h=t.children[s];if(a!=h)return r+a.scanIdentical(h,e);r+=a.length+1}}static from(t,e=t.reduce((r,n)=>r+n.length+1,-1)){let r=0;for(let d of t)r+=d.lines;if(r<32){let d=[];for(let m of t)m.flatten(d);return new Xt(d,e)}let n=Math.max(32,r>>5),s=n<<1,o=n>>1,l=[],a=0,h=-1,f=[];function c(d){let m;if(d.lines>s&&d instanceof i)for(let O of d.children)c(O);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof Xt&&a&&(m=f[f.length-1])instanceof Xt&&d.lines+m.lines<=32?(a+=d.lines,h+=d.length+1,f[f.length-1]=new Xt(m.text.concat(d.text),m.length+1+d.length)):(a+d.lines>n&&u(),a+=d.lines,h+=d.length+1,f.push(d))}function u(){a!=0&&(l.push(f.length==1?f[0]:i.from(f,h)),h=-1,a=f.length=0)}for(let d of t)c(d);return u(),l.length==1?l[0]:new i(l,e)}};V.empty=new Xt([\"\"],0);function dO(i){let t=-1;for(let e of i)t+=e.length+1;return t}function Jn(i,t,e=0,r=1e9){for(let n=0,s=0,o=!0;s=e&&(a>r&&(l=l.slice(0,r-n)),n0?1:(t instanceof Xt?t.text.length:t.children.length)<<1]}nextInner(t,e){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,n=this.nodes[r],s=this.offsets[r],o=s>>1,l=n instanceof Xt?n.text.length:n.children.length;if(o==(e>0?l:0)){if(r==0)return this.done=!0,this.value=\"\",this;e>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(e>0?0:1)){if(this.offsets[r]+=e,t==0)return this.lineBreak=!0,this.value=`\n`,this;t--}else if(n instanceof Xt){let a=n.text[o+(e<0?-1:0)];if(this.offsets[r]+=e,a.length>Math.max(0,t))return this.value=t==0?a:e>0?a.slice(t):a.slice(0,a.length-t),this;t-=a.length}else{let a=n.children[o+(e<0?-1:0)];t>a.length?(t-=a.length,this.offsets[r]+=e):(e<0&&this.offsets[r]--,this.nodes.push(a),this.offsets.push(e>0?1:(a instanceof Xt?a.text.length:a.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}},ts=class{constructor(t,e,r){this.value=\"\",this.done=!1,this.cursor=new oi(t,e>r?-1:1),this.pos=e>r?t.length:0,this.from=Math.min(e,r),this.to=Math.max(e,r)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value=\"\",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let r=e<0?this.pos-this.from:this.to-this.pos;t>r&&(t=r),r-=t;let{value:n}=this.cursor.next(t);return this.pos+=(n.length+t)*e,this.value=n.length<=r?n:e<0?n.slice(n.length-r):n.slice(0,r),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=\"\"}},es=class{constructor(t){this.inner=t,this.afterBreak=!0,this.value=\"\",this.done=!1}next(t=0){let{done:e,lineBreak:r,value:n}=this.inner.next(t);return e&&this.afterBreak?(this.value=\"\",this.afterBreak=!1):e?(this.done=!0,this.value=\"\"):r?this.afterBreak?this.value=\"\":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<\"u\"&&(V.prototype[Symbol.iterator]=function(){return this.iter()},oi.prototype[Symbol.iterator]=ts.prototype[Symbol.iterator]=es.prototype[Symbol.iterator]=function(){return this});var bl=class{constructor(t,e,r,n){this.from=t,this.to=e,this.number=r,this.text=n}get length(){return this.to-this.from}};function Li(i,t,e){return t=Math.max(0,Math.min(i.length,t)),[t,Math.max(t,Math.min(i.length,e))]}var Di=\"lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o\".split(\",\").map(i=>i?parseInt(i,36):1);for(let i=1;ii)return Di[t-1]<=i;return!1}function $c(i){return i>=127462&&i<=127487}var qc=8205;function at(i,t,e=!0,r=!0){return(e?Wc:mO)(i,t,r)}function Wc(i,t,e){if(t==i.length)return t;t&&Ic(i.charCodeAt(t))&&Nc(i.charCodeAt(t-1))&&t--;let r=dt(i,t);for(t+=wt(r);t=0&&$c(dt(i,o));)s++,o-=2;if(s%2==0)break;t+=2}else break}return t}function mO(i,t,e){for(;t>0;){let r=Wc(i,t-2,e);if(r=56320&&i<57344}function Nc(i){return i>=55296&&i<56320}function dt(i,t){let e=i.charCodeAt(t);if(!Nc(e)||t+1==i.length)return e;let r=i.charCodeAt(t+1);return Ic(r)?(e-55296<<10)+(r-56320)+65536:e}function vr(i){return i<=65535?String.fromCharCode(i):(i-=65536,String.fromCharCode((i>>10)+55296,(i&1023)+56320))}function wt(i){return i<65536?1:2}var Sl=/\\r\\n?|\\n/,ut=function(i){return i[i.Simple=0]=\"Simple\",i[i.TrackDel=1]=\"TrackDel\",i[i.TrackBefore=2]=\"TrackBefore\",i[i.TrackAfter=3]=\"TrackAfter\",i}(ut||(ut={})),Me=class i{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return s+(t-n);s+=l}else{if(r!=ut.Simple&&h>=t&&(r==ut.TrackDel&&nt||r==ut.TrackBefore&&nt))return null;if(h>t||h==t&&e<0&&!l)return t==n||e<0?s:s+a;s+=a}n=h}if(t>n)throw new RangeError(`Position ${t} is out of range for changeset of length ${n}`);return s}touchesRange(t,e=t){for(let r=0,n=0;r=0&&n<=e&&l>=t)return ne?\"cover\":!0;n=l}return!1}toString(){let t=\"\";for(let e=0;e=0?\":\"+n:\"\")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=\"number\"))throw new RangeError(\"Invalid JSON representation of ChangeDesc\");return new i(t)}static create(t){return new i(t)}},vt=class i extends Me{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError(\"Applying change set to a document with the wrong length\");return wl(this,(e,r,n,s,o)=>t=t.replace(n,n+(r-e),o),!1),t}mapDesc(t,e=!1){return vl(this,t,e,!0)}invert(t){let e=this.sections.slice(),r=[];for(let n=0,s=0;n=0){e[n]=l,e[n+1]=o;let a=n>>1;for(;r.length0&&Ve(r,e,s.text),s.forward(f),l+=f}let h=t[o++];for(;l>1].toJSON()))}return t}static of(t,e,r){let n=[],s=[],o=0,l=null;function a(f=!1){if(!f&&!n.length)return;ou||c<0||u>e)throw new RangeError(`Invalid change range ${c} to ${u} (in doc of length ${e})`);let m=d?typeof d==\"string\"?V.of(d.split(r||Sl)):d:V.empty,O=m.length;if(c==u&&O==0)return;co&&yt(n,c-o,-1),yt(n,u-c,O),Ve(s,n,m),o=u}}return h(t),a(!l),l}static empty(t){return new i(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError(\"Invalid JSON representation of ChangeSet\");let e=[],r=[];for(let n=0;nl&&typeof o!=\"string\"))throw new RangeError(\"Invalid JSON representation of ChangeSet\");if(s.length==1)e.push(s[0],0);else{for(;r.length=0&&e<=0&&e==i[n+1]?i[n]+=t:t==0&&i[n]==0?i[n+1]+=e:r?(i[n]+=t,i[n+1]+=e):i.push(t,e)}function Ve(i,t,e){if(e.length==0)return;let r=t.length-2>>1;if(r>1])),!(e||o==i.sections.length||i.sections[o+1]<0);)l=i.sections[o++],a=i.sections[o++];t(n,h,s,f,c),n=h,s=f}}}function vl(i,t,e,r=!1){let n=[],s=r?[]:null,o=new li(i),l=new li(t);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);yt(n,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len=0&&a=0){let h=0,f=o.len;for(;f;)if(l.ins==-1){let c=Math.min(f,l.len);h+=c,f-=c,l.forward(c)}else if(l.ins==0&&l.lena||o.ins>=0&&o.len>a)&&(l||r.length>h),s.forward2(a),o.forward(a)}}}}var li=class{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return e>=t.length?V.empty:t[e]}textBit(t){let{inserted:e}=this.set,r=this.i-2>>1;return r>=e.length&&!t?V.empty:e[r].slice(this.off,t==null?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){this.ins==-1?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}},$i=class i{constructor(t,e,r){this.from=t,this.to=e,this.flags=r}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 t=this.flags&7;return t==7?null:t}get goalColumn(){let t=this.flags>>6;return t==16777215?void 0:t}map(t,e=-1){let r,n;return this.empty?r=n=t.mapPos(this.from,e):(r=t.mapPos(this.from,1),n=t.mapPos(this.to,-1)),r==this.from&&n==this.to?this:new i(r,n,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return b.range(t,e);let r=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return b.range(this.anchor,r)}eq(t,e=!1){return this.anchor==t.anchor&&this.head==t.head&&(!e||!this.empty||this.assoc==t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||typeof t.anchor!=\"number\"||typeof t.head!=\"number\")throw new RangeError(\"Invalid JSON representation for SelectionRange\");return b.range(t.anchor,t.head)}static create(t,e,r){return new i(t,e,r)}},b=class i{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:i.create(this.ranges.map(r=>r.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let r=0;rt.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=\"number\"||t.main>=t.ranges.length)throw new RangeError(\"Invalid JSON representation for EditorSelection\");return new i(t.ranges.map(e=>$i.fromJSON(e)),t.main)}static single(t,e=t){return new i([i.range(t,e)],0)}static create(t,e=0){if(t.length==0)throw new RangeError(\"A selection needs at least one range\");for(let r=0,n=0;nt?8:0)|s)}static normalized(t,e=0){let r=t[e];t.sort((n,s)=>n.from-s.from),e=t.indexOf(r);for(let n=1;ns.head?i.range(a,l):i.range(l,a))}}return new i(t,e)}};function zc(i,t){for(let e of i.ranges)if(e.to>t)throw new RangeError(\"Selection points outside of document\")}var $l=0,A=class i{constructor(t,e,r,n,s){this.combine=t,this.compareInput=e,this.compare=r,this.isStatic=n,this.id=$l++,this.default=t([]),this.extensions=typeof s==\"function\"?s(this):s}get reader(){return this}static define(t={}){return new i(t.combine||(e=>e),t.compareInput||((e,r)=>e===r),t.compare||(t.combine?(e,r)=>e===r:ql),!!t.static,t.enables)}of(t){return new Bi([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error(\"Can't compute a static facet\");return new Bi(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error(\"Can't compute a static facet\");return new Bi(t,this,2,e)}from(t,e){return e||(e=r=>r),this.compute([t],r=>e(r.field(t)))}};function ql(i,t){return i==t||i.length==t.length&&i.every((e,r)=>e===t[r])}var Bi=class{constructor(t,e,r,n){this.dependencies=t,this.facet=e,this.type=r,this.value=n,this.id=$l++}dynamicSlot(t){var e;let r=this.value,n=this.facet.compareInput,s=this.id,o=t[s]>>1,l=this.type==2,a=!1,h=!1,f=[];for(let c of this.dependencies)c==\"doc\"?a=!0:c==\"selection\"?h=!0:((e=t[c.id])!==null&&e!==void 0?e:1)&1||f.push(t[c.id]);return{create(c){return c.values[o]=r(c),1},update(c,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||kl(c,f)){let d=r(c);if(l?!Dc(d,c.values[o],n):!n(d,c.values[o]))return c.values[o]=d,1}return 0},reconfigure:(c,u)=>{let d,m=u.config.address[s];if(m!=null){let O=ns(u,m);if(this.dependencies.every(g=>g instanceof A?u.facet(g)===c.facet(g):g instanceof it?u.field(g,!1)==c.field(g,!1):!0)||(l?Dc(d=r(c),O,n):n(d=r(c),O)))return c.values[o]=O,0}else d=r(c);return c.values[o]=d,1}}}};function Dc(i,t,e){if(i.length!=t.length)return!1;for(let r=0;ri[a.id]),n=e.map(a=>a.type),s=r.filter(a=>!(a&1)),o=i[t.id]>>1;function l(a){let h=[];for(let f=0;fr===n),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(Bc).find(r=>r.field==this);return(e?.create||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:r=>(r.values[e]=this.create(r),1),update:(r,n)=>{let s=r.values[e],o=this.updateF(s,n);return this.compareF(s,o)?0:(r.values[e]=o,1)},reconfigure:(r,n)=>n.config.address[this.id]!=null?(r.values[e]=n.field(this),0):(r.values[e]=this.create(r),1)}}init(t){return[this,Bc.of({field:this,create:t})]}get extension(){return this}},ni={lowest:4,low:3,default:2,high:1,highest:0};function xr(i){return t=>new is(t,i)}var ie={highest:xr(ni.highest),high:xr(ni.high),default:xr(ni.default),low:xr(ni.low),lowest:xr(ni.lowest)},is=class{constructor(t,e){this.inner=t,this.prec=e}},pe=class i{of(t){return new br(this,t)}reconfigure(t){return i.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}},br=class{constructor(t,e){this.compartment=t,this.inner=e}},rs=class i{constructor(t,e,r,n,s,o){for(this.base=t,this.compartments=e,this.dynamicSlots=r,this.address=n,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(t,e,r){let n=[],s=Object.create(null),o=new Map;for(let u of OO(t,e,o))u instanceof it?n.push(u):(s[u.facet.id]||(s[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of n)l[u.id]=h.length<<1,h.push(d=>u.slot(d));let f=r?.config.facets;for(let u in s){let d=s[u],m=d[0].facet,O=f&&f[u]||[];if(d.every(g=>g.type==0))if(l[m.id]=a.length<<1|1,ql(O,d))a.push(r.facet(m));else{let g=m.combine(d.map(x=>x.value));a.push(r&&m.compare(g,r.facet(m))?r.facet(m):g)}else{for(let g of d)g.type==0?(l[g.id]=a.length<<1|1,a.push(g.value)):(l[g.id]=h.length<<1,h.push(x=>g.dynamicSlot(x)));l[m.id]=h.length<<1,h.push(g=>gO(g,m,d))}}let c=h.map(u=>u(l));return new i(t,o,c,l,a,s)}};function OO(i,t,e){let r=[[],[],[],[],[]],n=new Map;function s(o,l){let a=n.get(o);if(a!=null){if(a<=l)return;let h=r[a].indexOf(o);h>-1&&r[a].splice(h,1),o instanceof br&&e.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let h of o)s(h,l);else if(o instanceof br){if(e.has(o.compartment))throw new RangeError(\"Duplicate use of compartment in extensions\");let h=t.get(o.compartment)||o.inner;e.set(o.compartment,h),s(h,l)}else if(o instanceof is)s(o.inner,o.prec);else if(o instanceof it)r[l].push(o),o.provides&&s(o.provides,l);else if(o instanceof Bi)r[l].push(o),o.facet.extensions&&s(o.facet.extensions,ni.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(h,l)}}return s(i,ni.default),r.reduce((o,l)=>o.concat(l))}function yr(i,t){if(t&1)return 2;let e=t>>1,r=i.status[e];if(r==4)throw new Error(\"Cyclic dependency between fields and/or facets\");if(r&2)return r;i.status[e]=4;let n=i.computeSlot(i,i.config.dynamicSlots[e]);return i.status[e]=2|n}function ns(i,t){return t&1?i.config.staticValues[t>>1]:i.values[t>>1]}var Zc=A.define(),Tl=A.define({combine:i=>i.some(t=>t),static:!0}),Fc=A.define({combine:i=>i.length?i[0]:void 0,static:!0}),_c=A.define(),Gc=A.define(),Hc=A.define(),Uc=A.define({combine:i=>i.length?i[0]:!1}),Et=class{constructor(t,e){this.type=t,this.value=e}static define(){return new Pl}},Pl=class{of(t){return new Et(this,t)}},Cl=class{constructor(t){this.map=t}of(t){return new M(this,t)}},M=class i{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return e===void 0?void 0:e==this.value?this:new i(this.type,e)}is(t){return this.type==t}static define(t={}){return new Cl(t.map||(e=>e))}static mapEffects(t,e){if(!t.length)return t;let r=[];for(let n of t){let s=n.map(e);s&&r.push(s)}return r}};M.reconfigure=M.define();M.appendConfig=M.define();var lt=class i{constructor(t,e,r,n,s,o){this.startState=t,this.changes=e,this.selection=r,this.effects=n,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,r&&zc(r,e.newLength),s.some(l=>l.type==i.time)||(this.annotations=s.concat(i.time.of(Date.now())))}static create(t,e,r,n,s,o){return new i(t,e,r,n,s,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(i.userEvent);return!!(e&&(e==t||e.length>t.length&&e.slice(0,t.length)==t&&e[t.length]==\".\"))}};lt.time=Et.define();lt.userEvent=Et.define();lt.addToHistory=Et.define();lt.remote=Et.define();function xO(i,t){let e=[];for(let r=0,n=0;;){let s,o;if(r=i[r]))s=i[r++],o=i[r++];else if(n=0;n--){let s=r[n](i);s instanceof lt?i=s:Array.isArray(s)&&s.length==1&&s[0]instanceof lt?i=s[0]:i=Kc(t,Xi(s),!1)}return i}function bO(i){let t=i.startState,e=t.facet(Hc),r=i;for(let n=e.length-1;n>=0;n--){let s=e[n](i);s&&Object.keys(s).length&&(r=jc(r,Al(t,s,i.changes.newLength),!0))}return r==i?i:lt.create(t,i.changes,i.selection,r.effects,r.annotations,r.scrollIntoView)}var SO=[];function Xi(i){return i==null?SO:Array.isArray(i)?i:[i]}var F=function(i){return i[i.Word=0]=\"Word\",i[i.Space=1]=\"Space\",i[i.Other=2]=\"Other\",i}(F||(F={})),wO=/[\\u00df\\u0587\\u0590-\\u05f4\\u0600-\\u06ff\\u3040-\\u309f\\u30a0-\\u30ff\\u3400-\\u4db5\\u4e00-\\u9fcc\\uac00-\\ud7af]/,Ql;try{Ql=new RegExp(\"[\\\\p{Alphabetic}\\\\p{Number}_]\",\"u\")}catch{}function vO(i){if(Ql)return Ql.test(i);for(let t=0;t\"\\x80\"&&(e.toUpperCase()!=e.toLowerCase()||wO.test(e)))return!0}return!1}function kO(i){return t=>{if(!/\\S/.test(t))return F.Space;if(vO(t))return F.Word;for(let e=0;e-1)return F.Word;return F.Other}}var Y=class i{constructor(t,e,r,n,s,o){this.config=t,this.doc=e,this.selection=r,this.values=n,this.status=t.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let l=0;ln.set(h,a)),e=null),n.set(l.value.compartment,l.value.extension)):l.is(M.reconfigure)?(e=null,r=l.value):l.is(M.appendConfig)&&(e=null,r=Xi(r).concat(l.value));let s;e?s=t.startState.values.slice():(e=rs.resolve(r,n,this),s=new i(e,this.doc,this.selection,e.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=t.startState.facet(Tl)?t.newSelection:t.newSelection.asSingle();new i(e,t.newDoc,o,s,(l,a)=>a.update(l,t),t)}replaceSelection(t){return typeof t==\"string\"&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:b.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,r=t(e.ranges[0]),n=this.changes(r.changes),s=[r.range],o=Xi(r.effects);for(let l=1;lo.spec.fromJSON(l,a)))}}return i.create({doc:t.doc,selection:b.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(t={}){let e=rs.resolve(t.extensions||[],new Map),r=t.doc instanceof V?t.doc:V.of((t.doc||\"\").split(e.staticFacet(i.lineSeparator)||Sl)),n=t.selection?t.selection instanceof b?t.selection:b.single(t.selection.anchor,t.selection.head):b.single(0);return zc(n,r.length),e.staticFacet(Tl)||(n=n.asSingle()),new i(e,r,n,e.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(i.tabSize)}get lineBreak(){return this.facet(i.lineSeparator)||`\n`}get readOnly(){return this.facet(Uc)}phrase(t,...e){for(let r of this.facet(i.phrases))if(Object.prototype.hasOwnProperty.call(r,t)){t=r[t];break}return e.length&&(t=t.replace(/\\$(\\$|\\d*)/g,(r,n)=>{if(n==\"$\")return\"$\";let s=+(n||1);return!s||s>e.length?r:e[s-1]})),t}languageDataAt(t,e,r=-1){let n=[];for(let s of this.facet(Zc))for(let o of s(this,e,r))Object.prototype.hasOwnProperty.call(o,t)&&n.push(o[t]);return n}charCategorizer(t){return kO(this.languageDataAt(\"wordChars\",t).join(\"\"))}wordAt(t){let{text:e,from:r,length:n}=this.doc.lineAt(t),s=this.charCategorizer(t),o=t-r,l=t-r;for(;o>0;){let a=at(e,o,!1);if(s(e.slice(a,o))!=F.Word)break;o=a}for(;li.length?i[0]:4});Y.lineSeparator=Fc;Y.readOnly=Uc;Y.phrases=A.define({compare(i,t){let e=Object.keys(i),r=Object.keys(t);return e.length==r.length&&e.every(n=>i[n]==t[n])}});Y.languageData=Zc;Y.changeFilter=_c;Y.transactionFilter=Gc;Y.transactionExtender=Hc;pe.reconfigure=M.define();function kt(i,t,e={}){let r={};for(let n of i)for(let s of Object.keys(n)){let o=n[s],l=r[s];if(l===void 0)r[s]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(e,s))r[s]=e[s](l,o);else throw new Error(\"Config merge conflict for field \"+s)}for(let n in t)r[n]===void 0&&(r[n]=t[n]);return r}var ee=class{eq(t){return this==t}range(t,e=t){return Sr.create(t,e,this)}};ee.prototype.startSide=ee.prototype.endSide=0;ee.prototype.point=!1;ee.prototype.mapMode=ut.TrackDel;var Sr=class i{constructor(t,e,r){this.from=t,this.to=e,this.value=r}static create(t,e,r){return new i(t,e,r)}};function Rl(i,t){return i.from-t.from||i.value.startSide-t.value.startSide}var Ml=class i{constructor(t,e,r,n){this.from=t,this.to=e,this.value=r,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(t,e,r,n=0){let s=r?this.to:this.from;for(let o=n,l=s.length;;){if(o==l)return o;let a=o+l>>1,h=s[a]-t||(r?this.value[a].endSide:this.value[a].startSide)-e;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(t,e,r,n){for(let s=this.findIndex(e,-1e9,!0),o=this.findIndex(r,1e9,!1,s);sd||u==d&&h.startSide>0&&h.endSide<=0)continue;(d-u||h.endSide-h.startSide)<0||(o<0&&(o=u),h.point&&(l=Math.max(l,d-u)),r.push(h),n.push(u-o),s.push(d-o))}return{mapped:r.length?new i(n,s,r,l):null,pos:o}}},_=class i{constructor(t,e,r,n){this.chunkPos=t,this.chunk=e,this.nextLayer=r,this.maxPoint=n}static create(t,e,r,n){return new i(t,e,r,n)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:r=!1,filterFrom:n=0,filterTo:s=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(r&&(e=e.slice().sort(Rl)),this.isEmpty)return e.length?i.of(e):this;let l=new ss(this,null,-1).goto(0),a=0,h=[],f=new Ee;for(;l.value||a=0){let c=e[a++];f.addInner(c.from,c.to,c.value)||h.push(c)}else l.rangeIndex==1&&l.chunkIndexthis.chunkEnd(l.chunkIndex)||sl.to||s=s&&t<=s+o.length&&o.between(s,t-s,e-s,r)===!1)return}this.nextLayer.between(t,e,r)}}iter(t=0){return wr.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return wr.from(t).goto(e)}static compare(t,e,r,n,s=-1){let o=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=s),l=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=s),a=Xc(o,l,r),h=new si(o,a,s),f=new si(l,a,s);r.iterGaps((c,u,d)=>Lc(h,c,f,u,d,n)),r.empty&&r.length==0&&Lc(h,0,f,0,0,n)}static eq(t,e,r=0,n){n==null&&(n=999999999);let s=t.filter(f=>!f.isEmpty&&e.indexOf(f)<0),o=e.filter(f=>!f.isEmpty&&t.indexOf(f)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let l=Xc(s,o),a=new si(s,l,0).goto(r),h=new si(o,l,0).goto(r);for(;;){if(a.to!=h.to||!El(a.active,h.active)||a.point&&(!h.point||!a.point.eq(h.point)))return!1;if(a.to>n)return!0;a.next(),h.next()}}static spans(t,e,r,n,s=-1){let o=new si(t,null,s).goto(e),l=e,a=o.openStart;for(;;){let h=Math.min(o.to,r);if(o.point){let f=o.activeForPoint(o.to),c=o.pointFroml&&(n.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>r)return a+(o.point&&o.to>r?1:0);l=o.to,o.next()}}static of(t,e=!1){let r=new Ee;for(let n of t instanceof Sr?[t]:e?TO(t):t)r.add(n.from,n.to,n.value);return r.finish()}static join(t){if(!t.length)return i.empty;let e=t[t.length-1];for(let r=t.length-2;r>=0;r--)for(let n=t[r];n!=i.empty;n=n.nextLayer)e=new i(n.chunkPos,n.chunk,e,Math.max(n.maxPoint,e.maxPoint));return e}};_.empty=new _([],[],null,-1);function TO(i){if(i.length>1)for(let t=i[0],e=1;e0)return i.slice().sort(Rl);t=r}return i}_.empty.nextLayer=_.empty;var Ee=class i{finishChunk(t){this.chunks.push(new Ml(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,r){this.addInner(t,e,r)||(this.nextLayer||(this.nextLayer=new i)).add(t,e,r)}addInner(t,e,r){let n=t-this.lastTo||r.startSide-this.last.endSide;if(n<=0&&(t-this.lastFrom||r.startSide-this.last.startSide)<0)throw new Error(\"Ranges must be added sorted by `from` position and `startSide`\");return n<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=r,this.lastFrom=t,this.lastTo=e,this.value.push(r),r.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let r=e.value.length-1;return this.last=e.value[r],this.lastFrom=e.from[r]+t,this.lastTo=e.to[r]+t,!0}finish(){return this.finishInner(_.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=_.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}};function Xc(i,t,e){let r=new Map;for(let s of i)for(let o=0;o=this.minPoint)break}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=r&&n.push(new ss(o,e,r,s));return n.length==1?n[0]:new i(n)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let r of this.heap)r.goto(t,e);for(let r=this.heap.length>>1;r>=0;r--)yl(this.heap,r);return this.next(),this}forward(t,e){for(let r of this.heap)r.forward(t,e);for(let r=this.heap.length>>1;r>=0;r--)yl(this.heap,r);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),yl(this.heap,0)}}};function yl(i,t){for(let e=i[t];;){let r=(t<<1)+1;if(r>=i.length)break;let n=i[r];if(r+1=0&&(n=i[r+1],r++),e.compare(n)<0)break;i[r]=e,i[t]=n,t=r}}var si=class{constructor(t,e,r){this.minPoint=r,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=wr.from(t,e,r)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){jn(this.active,t),jn(this.activeTo,t),jn(this.activeRank,t),this.minActive=Vc(this.active,this.activeTo)}addActive(t){let e=0,{value:r,to:n,rank:s}=this.cursor;for(;e0;)e++;Kn(this.active,e,r),Kn(this.activeTo,e,n),Kn(this.activeRank,e,s),t&&Kn(t,e,this.cursor.from),this.minActive=Vc(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let r=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>t){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),r&&jn(r,n)}else if(this.cursor.value)if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(r),this.cursor.next();else if(e&&this.cursor.to==this.to&&this.cursor.from=0&&r[n]=0&&!(this.activeRank[r]t||this.activeTo[r]==t&&this.active[r].endSide>=this.point.endSide)&&e.push(this.active[r]);return e.reverse()}openEnd(t){let e=0;for(let r=this.activeTo.length-1;r>=0&&this.activeTo[r]>t;r--)e++;return e}};function Lc(i,t,e,r,n,s){i.goto(t),e.goto(r);let o=r+n,l=r,a=r-t;for(;;){let h=i.to+a-e.to||i.endSide-e.endSide,f=h<0?i.to+a:e.to,c=Math.min(f,o);if(i.point||e.point?i.point&&e.point&&(i.point==e.point||i.point.eq(e.point))&&El(i.activeForPoint(i.to),e.activeForPoint(e.to))||s.comparePoint(l,c,i.point,e.point):c>l&&!El(i.active,e.active)&&s.compareRange(l,c,i.active,e.active),f>o)break;l=f,h<=0&&i.next(),h>=0&&e.next()}}function El(i,t){if(i.length!=t.length)return!1;for(let e=0;e=t;r--)i[r+1]=i[r];i[t]=e}function Vc(i,t){let e=-1,r=1e9;for(let n=0;n=t)return n;if(n==i.length)break;s+=i.charCodeAt(n)==9?e-s%e:1,n=at(i,n)}return r===!0?-1:i.length}var Dl=\"\\u037C\",Jc=typeof Symbol>\"u\"?\"__\"+Dl:Symbol.for(Dl),Bl=typeof Symbol>\"u\"?\"__styleSet\"+Math.floor(Math.random()*1e8):Symbol(\"styleSet\"),tu=typeof globalThis<\"u\"?globalThis:typeof window<\"u\"?window:{},Gt=class{constructor(t,e){this.rules=[];let{finish:r}=e||{};function n(o){return/^@/.test(o)?[o]:o.split(/,\\s*/)}function s(o,l,a,h){let f=[],c=/^@(\\w+)\\b/.exec(o[0]),u=c&&c[1]==\"keyframes\";if(c&&l==null)return a.push(o[0]+\";\");for(let d in l){let m=l[d];if(/&/.test(d))s(d.split(/,\\s*/).map(O=>o.map(g=>O.replace(/&/,g))).reduce((O,g)=>O.concat(g)),m,a);else if(m&&typeof m==\"object\"){if(!c)throw new RangeError(\"The value of a property (\"+d+\") should be a primitive value.\");s(n(d),m,f,u)}else m!=null&&f.push(d.replace(/_.*/,\"\").replace(/[A-Z]/g,O=>\"-\"+O.toLowerCase())+\": \"+m+\";\")}(f.length||u)&&a.push((r&&!c&&!h?o.map(r):o).join(\", \")+\" {\"+f.join(\" \")+\"}\")}for(let o in t)s(n(o),t[o],this.rules)}getRules(){return this.rules.join(`\n`)}static newName(){let t=tu[Jc]||1;return tu[Jc]=t+1,Dl+t.toString(36)}static mount(t,e,r){let n=t[Bl],s=r&&r.nonce;n?s&&n.setNonce(s):n=new Xl(t,s),n.mount(Array.isArray(e)?e:[e])}},eu=new Map,Xl=class{constructor(t,e){let r=t.ownerDocument||t,n=r.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let s=eu.get(r);if(s)return t.adoptedStyleSheets=[s.sheet,...t.adoptedStyleSheets],t[Bl]=s;this.sheet=new n.CSSStyleSheet,t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets],eu.set(r,this)}else{this.styleTag=r.createElement(\"style\"),e&&this.styleTag.setAttribute(\"nonce\",e);let s=t.head||t;s.insertBefore(this.styleTag,s.firstChild)}this.modules=[],t[Bl]=this}mount(t){let e=this.sheet,r=0,n=0;for(let s=0;s-1&&(this.modules.splice(l,1),n--,l=-1),l==-1){if(this.modules.splice(n++,0,o),e)for(let a=0;a\",191:\"?\",192:\"~\",219:\"{\",220:\"|\",221:\"}\",222:'\"'},PO=typeof navigator<\"u\"&&/Mac/.test(navigator.platform),CO=typeof navigator<\"u\"&&/MSIE \\d|Trident\\/(?:[7-9]|\\d{2,})\\..*rv:(\\d+)/.exec(navigator.userAgent);for(ht=0;ht<10;ht++)$e[48+ht]=$e[96+ht]=String(ht);var ht;for(ht=1;ht<=24;ht++)$e[ht+111]=\"F\"+ht;var ht;for(ht=65;ht<=90;ht++)$e[ht]=String.fromCharCode(ht+32),Vi[ht]=String.fromCharCode(ht);var ht;for(ls in $e)Vi.hasOwnProperty(ls)||(Vi[ls]=$e[ls]);var ls;function iu(i){var t=PO&&i.metaKey&&i.shiftKey&&!i.ctrlKey&&!i.altKey||CO&&i.shiftKey&&i.key&&i.key.length==1||i.key==\"Unidentified\",e=!t&&i.key||(i.shiftKey?Vi:$e)[i.keyCode]||i.key||\"Unidentified\";return e==\"Esc\"&&(e=\"Escape\"),e==\"Del\"&&(e=\"Delete\"),e==\"Left\"&&(e=\"ArrowLeft\"),e==\"Up\"&&(e=\"ArrowUp\"),e==\"Right\"&&(e=\"ArrowRight\"),e==\"Down\"&&(e=\"ArrowDown\"),e}function Ss(i){let t;return i.nodeType==11?t=i.getSelection?i:i.ownerDocument:t=i,t.getSelection()}function Zl(i,t){return t?i==t||i.contains(t.nodeType!=1?t.parentNode:t):!1}function AO(i){let t=i.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function Os(i,t){if(!t.anchorNode)return!1;try{return Zl(i,t.anchorNode)}catch{return!1}}function Xr(i){return i.nodeType==3?ai(i,0,i.nodeValue.length).getClientRects():i.nodeType==1?i.getClientRects():[]}function Rr(i,t,e,r){return e?ru(i,t,e,r,-1)||ru(i,t,e,r,1):!1}function Lr(i){for(var t=0;;t++)if(i=i.previousSibling,!i)return t}function ru(i,t,e,r,n){for(;;){if(i==e&&t==r)return!0;if(t==(n<0?0:qe(i))){if(i.nodeName==\"DIV\")return!1;let s=i.parentNode;if(!s||s.nodeType!=1)return!1;t=Lr(i)+(n<0?0:1),i=s}else if(i.nodeType==1){if(i=i.childNodes[t+(n<0?-1:0)],i.nodeType==1&&i.contentEditable==\"false\")return!1;t=n<0?qe(i):0}else return!1}}function qe(i){return i.nodeType==3?i.nodeValue.length:i.childNodes.length}function Aa(i,t){let e=t?i.left:i.right;return{left:e,right:e,top:i.top,bottom:i.bottom}}function QO(i){return{left:0,right:i.innerWidth,top:0,bottom:i.innerHeight}}function Iu(i,t){let e=t.width/i.offsetWidth,r=t.height/i.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-i.offsetWidth)<1)&&(e=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(t.height-i.offsetHeight)<1)&&(r=1),{scaleX:e,scaleY:r}}function RO(i,t,e,r,n,s,o,l){let a=i.ownerDocument,h=a.defaultView||window;for(let f=i,c=!1;f&&!c;)if(f.nodeType==1){let u,d=f==a.body,m=1,O=1;if(d)u=QO(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(c=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let S=f.getBoundingClientRect();({scaleX:m,scaleY:O}=Iu(f,S)),u={left:S.left,right:S.left+f.clientWidth*m,top:S.top,bottom:S.top+f.clientHeight*O}}let g=0,x=0;if(n==\"nearest\")t.top0&&t.bottom>u.bottom+x&&(x=t.bottom-u.bottom+x+o)):t.bottom>u.bottom&&(x=t.bottom-u.bottom+o,e<0&&t.top-x0&&t.right>u.right+g&&(g=t.right-u.right+g+s)):t.right>u.right&&(g=t.right-u.right+s,e<0&&t.lefte.clientHeight||e.scrollWidth>e.clientWidth)return e;e=e.assignedSlot||e.parentNode}else if(e.nodeType==11)e=e.host;else break;return null}var Fl=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:r}=t;this.set(e,Math.min(t.anchorOffset,e?qe(e):0),r,Math.min(t.focusOffset,r?qe(r):0))}set(t,e,r,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=r,this.focusOffset=n}},Wi=null;function Nu(i){if(i.setActive)return i.setActive();if(Wi)return i.focus(Wi);let t=[];for(let e=i;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(i.focus(Wi==null?{get preventScroll(){return Wi={preventScroll:!0},!0}}:void 0),!Wi){Wi=!1;for(let e=0;eMath.max(1,i.scrollHeight-i.clientHeight-4)}var Tt=class i{constructor(t,e,r=!0){this.node=t,this.offset=e,this.precise=r}static before(t,e){return new i(t.parentNode,Lr(t),e)}static after(t,e){return new i(t.parentNode,Lr(t)+1,e)}},Qa=[],rt=class i{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 r of this.children){if(r==t)return e;e+=r.length+r.breakAfter}throw new RangeError(\"Invalid child in posBefore\")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(this.flags&2){let r=this.dom,n=null,s;for(let o of this.children){if(o.flags&7){if(!o.dom&&(s=n?n.nextSibling:r.firstChild)){let l=i.get(s);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(s)}o.sync(t,e),o.flags&=-8}if(s=n?n.nextSibling:r.firstChild,e&&!e.written&&e.node==r&&s!=o.dom&&(e.written=!0),o.dom.parentNode==r)for(;s&&s!=o.dom;)s=su(s);else r.insertBefore(o.dom,s);n=o.dom}for(s=n?n.nextSibling:r.firstChild,s&&e&&e.node==r&&(e.written=!0);s;)s=su(s)}else if(this.flags&1)for(let r of this.children)r.flags&7&&(r.sync(t,e),r.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let r;if(t==this.dom)r=this.dom.childNodes[e];else{let n=qe(t)==0?0:e==0?-1:1;for(;;){let s=t.parentNode;if(s==this.dom)break;n==0&&s.firstChild!=s.lastChild&&(t==s.firstChild?n=-1:n=1),t=s}n<0?r=t:r=t.nextSibling}if(r==this.dom.firstChild)return 0;for(;r&&!i.get(r);)r=r.nextSibling;if(!r)return this.length;for(let n=0,s=0;;n++){let o=this.children[n];if(o.dom==r)return s;s+=o.length+o.breakAfter}}domBoundsAround(t,e,r=0){let n=-1,s=-1,o=-1,l=-1;for(let a=0,h=r,f=r;ae)return c.domBoundsAround(t,e,h);if(u>=t&&n==-1&&(n=a,s=h),h>e&&c.dom.parentNode==this.dom){o=a,l=f;break}f=u,h=u+c.breakAfter}return{from:s,to:l<0?r+this.length:l,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o=0?this.children[o].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,r=Qa){this.markDirty();for(let n=t;nthis.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let r=this.children[--this.i];this.pos-=r.length+r.breakAfter}}};function Zu(i,t,e,r,n,s,o,l,a){let{children:h}=i,f=h.length?h[t]:null,c=s.length?s[s.length-1]:null,u=c?c.breakAfter:o;if(!(t==r&&f&&!o&&!u&&s.length<2&&f.merge(e,n,s.length?c:null,e==0,l,a))){if(r0&&(!o&&s.length&&f.merge(e,f.length,s[0],!1,l,0)?f.breakAfter=s.shift().breakAfter:(e2),Q={mac:au||/Mac/.test(Lt.platform),windows:/Win/.test(Lt.platform),linux:/Linux|X11/.test(Lt.platform),ie:Bs,ie_version:_u?_l.documentMode||6:Hl?+Hl[1]:Gl?+Gl[1]:0,gecko:ou,gecko_version:ou?+(/Firefox\\/(\\d+)/.exec(Lt.userAgent)||[0,0])[1]:0,chrome:!!Ll,chrome_version:Ll?+Ll[1]:0,ios:au,android:/Android\\b/.test(Lt.userAgent),webkit:lu,safari:Gu,webkit_version:lu?+(/\\bAppleWebKit\\/(\\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:_l.documentElement.style.tabSize!=null?\"tab-size\":\"-moz-tab-size\"},qO=256,Ye=class i extends rt{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,r){return this.flags&8||r&&(!(r instanceof i)||this.length-(e-t)+r.length>qO||r.flags&8)?!1:(this.text=this.text.slice(0,t)+(r?r.text:\"\")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new i(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 Tt(this.dom,t)}domBoundsAround(t,e,r){return{from:r,to:r+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return DO(this.dom,t,e)}},ze=class i extends rt{constructor(t,e=[],r=0){super(),this.mark=t,this.children=e,this.length=r;for(let n of e)n.setParent(this)}setAttrs(t){if(Yu(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,r,n,s,o){return r&&(!(r instanceof i&&r.mark.eq(this.mark))||t&&s<=0||et&&e.push(r=t&&(n=s),r=a,s++}let o=this.length-t;return this.length=t,n>-1&&(this.children.length=n,this.markDirty()),new i(this.mark,e,o)}domAtPos(t){return Hu(this,t)}coordsAt(t,e){return ju(this,t,e)}};function DO(i,t,e){let r=i.nodeValue.length;t>r&&(t=r);let n=t,s=t,o=0;t==0&&e<0||t==r&&e>=0?Q.chrome||Q.gecko||(t?(n--,o=1):s=0)?0:l.length-1];return Q.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?Aa(a,o<0):a||null}var Vr=class i extends rt{static create(t,e,r){return new i(t,e,r)}constructor(t,e,r){super(),this.widget=t,this.length=e,this.side=r,this.prevWidget=null}split(t){let e=i.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,r,n,s,o){return r&&(!(r instanceof i)||!this.widget.compare(r.widget)||t>0&&s<=0||e0)?Tt.before(this.dom):Tt.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let r=this.widget.coordsAt(this.dom,t,e);if(r)return r;let n=this.dom.getClientRects(),s=null;if(!n.length)return null;let o=this.side?this.side<0:t>0;for(let l=o?n.length-1:0;s=n[l],!(t>0?l==0:l==n.length-1||s.top0?Tt.before(this.dom):Tt.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return V.empty}get isHidden(){return!0}};Ye.prototype.children=Vr.prototype.children=Wr.prototype.children=Qa;function Hu(i,t){let e=i.dom,{children:r}=i,n=0;for(let s=0;ns&&t0;s--){let o=r[s-1];if(o.dom.parentNode==e)return o.domAtPos(o.length)}for(let s=n;s0&&t instanceof ze&&n.length&&(r=n[n.length-1])instanceof ze&&r.mark.eq(t.mark)?Uu(r,t.children[0],e-1):(n.push(t),t.setParent(i)),i.length+=t.length}function ju(i,t,e){let r=null,n=-1,s=null,o=-1;function l(h,f){for(let c=0,u=0;c=f&&(d.children.length?l(d,f-u):(!s||s.isHidden&&e>0)&&(m>f||u==m&&d.getSide()>0)?(s=d,o=f-u):(u-1?1:0)!=n.length-(e&&n.indexOf(e)>-1?1:0))return!1;for(let s of r)if(s!=e&&(n.indexOf(s)==-1||i[s]!==t[s]))return!1;return!0}function jl(i,t,e){let r=!1;if(t)for(let n in t)e&&n in e||(r=!0,n==\"style\"?i.style.cssText=\"\":i.removeAttribute(n));if(e)for(let n in e)t&&t[n]==e[n]||(r=!0,n==\"style\"?i.style.cssText=e[n]:i.setAttribute(n,e[n]));return r}function XO(i){let t=Object.create(null);for(let e=0;e0&&this.children[r-1].length==0;)this.children[--r].destroy();return this.children.length=r,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){Ra(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Uu(this,t,e)}addLineDeco(t){let e=t.spec.attributes,r=t.spec.class;e&&(this.attrs=Ul(e,this.attrs||{})),r&&(this.attrs=Ul({class:r},this.attrs||{}))}domAtPos(t){return Hu(this,t)}reuseDOM(t){t.nodeName==\"DIV\"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var r;this.dom?this.flags&4&&(Yu(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&&(jl(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add(\"cm-line\"),this.prevAttrs=void 0),super.sync(t,e);let n=this.dom.lastChild;for(;n&&rt.get(n)instanceof ze;)n=n.lastChild;if(!n||!this.length||n.nodeName!=\"BR\"&&((r=rt.get(n))===null||r===void 0?void 0:r.isEditable)==!1&&(!Q.ios||!this.children.some(s=>s instanceof Ye))){let s=document.createElement(\"BR\");s.cmIgnore=!0,this.dom.appendChild(s)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let r of this.children){if(!(r instanceof Ye)||/[^ -~]/.test(r.text))return null;let n=Xr(r.dom);if(n.length!=1)return null;t+=n[0].width,e=n[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let r=ju(this,t,e);if(!this.children.length&&r&&this.parent){let{heightOracle:n}=this.parent.view.viewState,s=r.bottom-r.top;if(Math.abs(s-n.lineHeight)<2&&n.textHeight=e){if(s instanceof i)return s;if(o>e)break}n=o+s.breakAfter}return null}},Zi=class i extends rt{constructor(t,e,r){super(),this.widget=t,this.length=e,this.deco=r,this.breakAfter=0,this.prevWidget=null}merge(t,e,r,n,s,o){return r&&(!(r instanceof i)||!this.widget.compare(r.widget)||t>0&&s<=0||e0}},Ut=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,r){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}},Pt=function(i){return i[i.Text=0]=\"Text\",i[i.WidgetBefore=1]=\"WidgetBefore\",i[i.WidgetAfter=2]=\"WidgetAfter\",i[i.WidgetRange=3]=\"WidgetRange\",i}(Pt||(Pt={})),R=class extends ee{constructor(t,e,r,n){super(),this.startSide=t,this.endSide=e,this.widget=r,this.spec=n}get heightRelevant(){return!1}static mark(t){return new Ir(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),r=!!t.block;return e+=r&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new Ze(t,e,e,r,t.widget||null,!1)}static replace(t){let e=!!t.block,r,n;if(t.isBlockGap)r=-5e8,n=4e8;else{let{start:s,end:o}=Ku(t,e);r=(s?e?-3e8:-1:5e8)-1,n=(o?e?2e8:1:-6e8)+1}return new Ze(t,r,n,e,t.widget||null,!0)}static line(t){return new Nr(t)}static set(t,e=!1){return _.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};R.none=_.empty;var Ir=class i extends R{constructor(t){let{start:e,end:r}=Ku(t);super(e?-1:5e8,r?1:-6e8,null,t),this.tagName=t.tagName||\"span\",this.class=t.class||\"\",this.attrs=t.attributes||null}eq(t){var e,r;return this==t||t instanceof i&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((r=t.attrs)===null||r===void 0?void 0:r.class))&&Ra(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)}};Ir.prototype.point=!1;var Nr=class i extends R{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof i&&this.spec.class==t.spec.class&&Ra(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)}};Nr.prototype.mapMode=ut.TrackBefore;Nr.prototype.point=!0;var Ze=class i extends R{constructor(t,e,r,n,s,o){super(e,r,s,t),this.block=n,this.isReplace=o,this.mapMode=n?e<=0?ut.TrackBefore:ut.TrackAfter:ut.TrackDel}get type(){return this.startSide!=this.endSide?Pt.WidgetRange:this.startSide<=0?Pt.WidgetBefore:Pt.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof i&&LO(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)}};Ze.prototype.point=!0;function Ku(i,t=!1){let{inclusiveStart:e,inclusiveEnd:r}=i;return e==null&&(e=i.inclusive),r==null&&(r=i.inclusive),{start:e??t,end:r??t}}function LO(i,t){return i==t||!!(i&&t&&i.compare(t))}function Kl(i,t,e,r=0){let n=e.length-1;n>=0&&e[n]+r>=i?e[n]=Math.max(e[n],t):e.push(i,t)}var Mr=class i{constructor(t,e,r,n){this.doc=t,this.pos=e,this.end=r,this.disallowBlockEffectsFor=n,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text=\"\",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(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 Zi&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new mt),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(as(new Wr(-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 Zi)&&this.getLine()}buildText(t,e,r){for(;t>0;){if(this.textOff==this.text.length){let{value:s,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error(\"Ran out of text content when drawing inline views\");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}else this.text=s,this.textOff=0}let n=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-r)),this.getLine().append(as(new Ye(this.text.slice(this.textOff,this.textOff+n)),e),r),this.atCursorPos=!0,this.textOff+=n,t-=n,r=0}}span(t,e,r,n){this.buildText(e-t,r,n),this.pos=e,this.openStart<0&&(this.openStart=n)}point(t,e,r,n,s,o){if(this.disallowBlockEffectsFor[o]&&r instanceof Ze){if(r.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 l=e-t;if(r instanceof Ze)if(r.block)r.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Zi(r.widget||new vs(\"div\"),l,r));else{let a=Vr.create(r.widget||new vs(\"span\"),l,l?0:r.startSide),h=this.atCursorPos&&!a.isEditable&&s<=n.length&&(t0),f=!a.isEditable&&(tn.length||r.startSide<=0),c=this.getLine();this.pendingBuffer==2&&!h&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(n),h&&(c.append(as(new Wr(1),n),s),s=n.length+Math.max(0,s-n.length)),c.append(as(a,n),s),this.atCursorPos=f,this.pendingBuffer=f?tn.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=n.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(r);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text=\"\",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=s)}static build(t,e,r,n,s){let o=new i(t,e,r,s);return o.openEnd=_.spans(n,e,r,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}};function as(i,t){for(let e of t)i=new ze(e,[i],i.length);return i}var vs=class extends Ut{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}},G=function(i){return i[i.LTR=0]=\"LTR\",i[i.RTL=1]=\"RTL\",i}(G||(G={})),hi=G.LTR,Ma=G.RTL;function Ju(i){let t=[];for(let e=0;e=e){if(l.level==r)return o;(s<0||(n!=0?n<0?l.frome:t[s].level>l.level))&&(s=o)}}if(s<0)throw new RangeError(\"Index out of range\");return s}};function ed(i,t){if(i.length!=t.length)return!1;for(let e=0;e=0;O-=3)if(me[O+1]==-d){let g=me[O+2],x=g&2?n:g&4?g&1?s:n:0;x&&(j[c]=j[me[O]]=x),l=O;break}}else{if(me.length==189)break;me[l++]=c,me[l++]=u,me[l++]=a}else if((m=j[c])==2||m==1){let O=m==n;a=O?0:1;for(let g=l-3;g>=0;g-=3){let x=me[g+2];if(x&2)break;if(O)me[g+2]|=2;else{if(x&4)break;me[g+2]|=4}}}}}function zO(i,t,e,r){for(let n=0,s=r;n<=e.length;n++){let o=n?e[n-1].to:i,l=na;)m==g&&(m=e[--O].from,g=O?e[O-1].to:i),j[--m]=d;a=f}else s=h,a++}}}function ta(i,t,e,r,n,s,o){let l=r%2?2:1;if(r%2==n%2)for(let a=t,h=0;aa&&o.push(new Oe(a,O.from,d));let g=O.direction==hi!=!(d%2);ea(i,g?r+1:r,n,O.inner,O.from,O.to,o),a=O.to}m=O.to}else{if(m==e||(f?j[m]!=l:j[m]==l))break;m++}u?ta(i,a,m,r+1,n,u,o):at;){let f=!0,c=!1;if(!h||a>s[h-1].to){let O=j[a-1];O!=l&&(f=!1,c=O==16)}let u=!f&&l==1?[]:null,d=f?r:r+1,m=a;t:for(;;)if(h&&m==s[h-1].to){if(c)break t;let O=s[--h];if(!f)for(let g=O.from,x=h;;){if(g==t)break t;if(x&&s[x-1].to==g)g=s[--x].from;else{if(j[g-1]==l)break t;break}}if(u)u.push(O);else{O.toj.length;)j[j.length]=256;let r=[],n=t==hi?0:1;return ea(i,n,n,e,0,i.length,r),r}function id(i){return[new Oe(0,i,0)]}var rd=\"\";function FO(i,t,e,r,n){var s;let o=r.head-i.from,l=Oe.find(t,o,(s=r.bidiLevel)!==null&&s!==void 0?s:-1,r.assoc),a=t[l],h=a.side(n,e);if(o==h){let u=l+=n?1:-1;if(u<0||u>=t.length)return null;a=t[l=u],o=a.side(!n,e),h=a.side(n,e)}let f=at(i.text,o,a.forward(n,e));(fa.to)&&(f=h),rd=i.text.slice(Math.min(o,f),Math.max(o,f));let c=l==(n?t.length-1:0)?null:t[l+(n?1:-1)];return c&&f==h&&c.level+(n?0:1)i.some(t=>t)}),cd=A.define({combine:i=>i.some(t=>t)}),Er=class i{constructor(t,e=\"nearest\",r=\"nearest\",n=5,s=5,o=!1){this.range=t,this.y=e,this.x=r,this.yMargin=n,this.xMargin=s,this.isSnapshot=o}map(t){return t.empty?this:new i(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 i(b.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},hs=M.define({map:(i,t)=>i.map(t)});function Ct(i,t,e){let r=i.facet(ld);r.length?r[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+\":\",t):console.error(t)}var Xs=A.define({combine:i=>i.length?i[0]:!0}),GO=0,Tr=A.define(),ft=class i{constructor(t,e,r,n,s){this.id=t,this.create=e,this.domEventHandlers=r,this.domEventObservers=n,this.extension=s(this)}static define(t,e){let{eventHandlers:r,eventObservers:n,provide:s,decorations:o}=e||{};return new i(GO++,t,r,n,l=>{let a=[Tr.of(l)];return o&&a.push(Yr.of(h=>{let f=h.plugin(l);return f?o(f):R.none})),s&&a.push(s(l)),a})}static fromClass(t,e){return i.define(r=>new t(r),e)}},$r=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(r){if(Ct(e.state,r,\"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){Ct(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(r){Ct(t.state,r,\"CodeMirror plugin crashed\")}}deactivate(){this.spec=this.value=null}},ud=A.define(),Ea=A.define(),Yr=A.define(),dd=A.define(),$a=A.define(),pd=A.define();function fu(i,t){let e=i.state.facet(pd);if(!e.length)return e;let r=e.map(s=>s instanceof Function?s(i):s),n=[];return _.spans(r,t.from,t.to,{point(){},span(s,o,l,a){let h=s-t.from,f=o-t.from,c=n;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,m;if(d==null&&(d=_O(t.text,h,f)),a>0&&c.length&&(m=c[c.length-1]).to==h&&m.direction==d)m.to=f,c=m.inner;else{let O={from:h,to:f,direction:d,inner:[]};c.push(O),c=O.inner}}}}),n}var md=A.define();function gd(i){let t=0,e=0,r=0,n=0;for(let s of i.state.facet(md)){let o=s(i);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(r=Math.max(r,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:t,right:e,top:r,bottom:n}}var Pr=A.define(),xe=class i{constructor(t,e,r,n){this.fromA=t,this.toA=e,this.fromB=r,this.toB=n}join(t){return new i(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,r=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>r.toA)){if(n.toAf)break;s+=2}if(!a)return r;new i(a.fromA,a.toA,a.fromB,a.toB).addToSet(r),o=a.toA,l=a.toB}}},ks=class i{constructor(t,e,r){this.view=t,this.state=e,this.transactions=r,this.flags=0,this.startState=t.state,this.changes=vt.empty(this.startState.doc.length);for(let s of r)this.changes=this.changes.compose(s.changes);let n=[];this.changes.iterChangedRanges((s,o,l,a)=>n.push(new xe(s,o,l,a))),this.changedRanges=n}static create(t,e,r){return new i(t,e,r)}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}},Ts=class extends rt{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,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 mt],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new xe(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let r=t.changedRanges;this.minWidth>0&&r.length&&(r.every(({fromA:h,toA:f})=>fthis.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0);let n=-1;this.view.inputState.composing>=0&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?n=this.domChanged.newSel.head:!e0(t.changes,this.hasComposition)&&!t.selectionSet&&(n=t.state.selection.main.head));let s=n>-1?UO(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:h,to:f}=this.hasComposition;r=new xe(h,f,t.changes.mapPos(h,-1),t.changes.mapPos(f,1)).addToSet(r.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(Q.ie||Q.chrome)&&!s&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=JO(o,l,t.changes);return r=xe.extendWithRanges(r,a),!(this.flags&7)&&r.length==0?!1:(this.updateInner(r,t.startState.doc.length,s),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,r){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,r);let{observer:n}=this.view;n.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+\"px\",this.dom.style.flexBasis=this.minWidth?this.minWidth+\"px\":\"\";let o=Q.chrome||Q.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||n.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=\"\"}),this.markedForComposition.forEach(o=>o.flags&=-9);let s=[];if(this.view.viewport.from||this.view.viewport.to=0?n[o]:null;if(!l)break;let{fromA:a,toA:h,fromB:f,toB:c}=l,u,d,m,O;if(r&&r.range.fromBf){let v=Mr.build(this.view.state.doc,f,r.range.fromB,this.decorations,this.dynamicDecorationMap),y=Mr.build(this.view.state.doc,r.range.toB,c,this.decorations,this.dynamicDecorationMap);d=v.breakAtStart,m=v.openStart,O=y.openEnd;let k=this.compositionView(r);y.breakAtStart?k.breakAfter=1:y.content.length&&k.merge(k.length,k.length,y.content[0],!1,y.openStart,0)&&(k.breakAfter=y.content[0].breakAfter,y.content.shift()),v.content.length&&k.merge(0,0,v.content[v.content.length-1],!0,0,v.openEnd)&&v.content.pop(),u=v.content.concat(k).concat(y.content)}else({content:u,breakAtStart:d,openStart:m,openEnd:O}=Mr.build(this.view.state.doc,f,c,this.decorations,this.dynamicDecorationMap));let{i:g,off:x}=s.findPos(h,1),{i:S,off:C}=s.findPos(a,-1);Zu(this,S,C,g,x,u,d,m,O)}r&&this.fixCompositionDOM(r)}compositionView(t){let e=new Ye(t.text.nodeValue);e.flags|=8;for(let{deco:n}of t.marks)e=new ze(n,[e],e.length);let r=new mt;return r.append(e,0),r}fixCompositionDOM(t){let e=(s,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=rt.get(s);l&&l!=o&&(l.dom=null),o.setDOM(s)},r=this.childPos(t.range.fromB,1),n=this.children[r.i];e(t.line,n);for(let s=t.marks.length-1;s>=-1;s--)r=n.childPos(r.off,1),n=n.children[r.i],e(s>=0?t.marks[s].node:t.text,n)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let r=this.view.root.activeElement,n=r==this.dom,s=!n&&Os(this.dom,this.view.observer.selectionRange)&&!(r&&this.dom.contains(r));if(!(n||e||s))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(l.anchor)),h=l.empty?a:this.moveToLine(this.domAtPos(l.head));if(Q.gecko&&l.empty&&!this.hasComposition&&HO(a)){let c=document.createTextNode(\"\");this.view.observer.ignore(()=>a.node.insertBefore(c,a.node.childNodes[a.offset]||null)),a=h=new Tt(c,0),o=!0}let f=this.view.observer.selectionRange;(o||!f.focusNode||(!Rr(a.node,a.offset,f.anchorNode,f.anchorOffset)||!Rr(h.node,h.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,l))&&(this.view.observer.ignore(()=>{Q.android&&Q.chrome&&this.dom.contains(f.focusNode)&&t0(f.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let c=Ss(this.view.root);if(c)if(l.empty){if(Q.gecko){let u=jO(a.node,a.offset);if(u&&u!=3){let d=xd(a.node,a.offset,u==1?1:-1);d&&(a=new Tt(d.node,d.offset))}}c.collapse(a.node,a.offset),l.bidiLevel!=null&&c.caretBidiLevel!==void 0&&(c.caretBidiLevel=l.bidiLevel)}else if(c.extend){c.collapse(a.node,a.offset);try{c.extend(h.node,h.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([a,h]=[h,a]),u.setEnd(h.node,h.offset),u.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(u)}s&&this.view.root.activeElement==this.dom&&(this.dom.blur(),r&&r.focus())}),this.view.observer.setSelectionRange(a,h)),this.impreciseAnchor=a.precise?null:new Tt(f.anchorNode,f.anchorOffset),this.impreciseHead=h.precise?null:new Tt(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Rr(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,r=Ss(t.root),{anchorNode:n,anchorOffset:s}=t.observer.selectionRange;if(!r||!e.empty||!e.assoc||!r.modify)return;let o=mt.find(this,e.head);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let a=this.coordsAt(e.head,-1),h=this.coordsAt(e.head,1);if(!a||!h||a.bottom>h.top)return;let f=this.domAtPos(e.head+e.assoc);r.collapse(f.node,f.offset),r.modify(\"move\",e.assoc<0?\"forward\":\"backward\",\"lineboundary\"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&r.collapse(n,s)}moveToLine(t){let e=this.dom,r;if(t.node!=e)return t;for(let n=t.offset;!r&&n=0;n--){let s=rt.get(e.childNodes[n]);s instanceof mt&&(r=s.domAtPos(s.length))}return r?new Tt(r.node,r.offset,!0):t}nearest(t){for(let e=t;e;){let r=rt.get(e);if(r&&r.rootView==this)return r;e=e.parentNode}return null}posFromDOM(t,e){let r=this.nearest(t);if(!r)throw new RangeError(\"Trying to find position for a DOM position outside of the document\");return r.localPosFromDOM(t,e)+r.posAtStart}domAtPos(t){let{i:e,off:r}=this.childCursor().findPos(t,-1);for(;e=0;o--){let l=this.children[o],a=s-l.breakAfter,h=a-l.length;if(at||l.covers(1))&&(!r||l instanceof mt&&!(r instanceof mt&&e>=0))&&(r=l,n=h),s=h}return r?r.coordsAt(t-n,e):null}coordsForChar(t){let{i:e,off:r}=this.childPos(t,1),n=this.children[e];if(!(n instanceof mt))return null;for(;n.children.length;){let{i:l,off:a}=n.childPos(r,1);for(;;l++){if(l==n.children.length)return null;if((n=n.children[l]).length)break}r=a}if(!(n instanceof Ye))return null;let s=at(n.text,r);if(s==r)return null;let o=ai(n.dom,r,s).getClientRects();for(let l=0;lMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==G.LTR;for(let h=0,f=0;fn)break;if(h>=r){let d=c.dom.getBoundingClientRect();if(e.push(d.height),o){let m=c.dom.lastChild,O=m?Xr(m):[];if(O.length){let g=O[O.length-1],x=a?g.right-d.left:d.right-g.left;x>l&&(l=x,this.minWidth=s,this.minWidthFrom=h,this.minWidthTo=u)}}}h=u+c.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction==\"rtl\"?G.RTL:G.LTR}measureTextSize(){for(let s of this.children)if(s instanceof mt){let o=s.measureTextSize();if(o)return o}let t=document.createElement(\"div\"),e,r,n;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 s=Xr(t.firstChild)[0];e=t.getBoundingClientRect().height,r=s?s.width/27:7,n=s?s.height:e,t.remove()}),{lineHeight:e,charWidth:r,textHeight:n}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new ws(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let r=0,n=0;;n++){let s=n==e.viewports.length?null:e.viewports[n],o=s?s.from-1:this.length;if(o>r){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(r).top)/this.view.scaleY;t.push(R.replace({widget:new Ps(l),block:!0,inclusive:!0,isBlockGap:!0}).range(r,o))}if(!s)break;r=s.to+1}return R.set(t)}updateDeco(){let t=this.view.state.facet(Yr).map((n,s)=>(this.dynamicDecorationMap[s]=typeof n==\"function\")?n(this.view):n),e=!1,r=this.view.state.facet(dd).map((n,s)=>{let o=typeof n==\"function\";return o&&(e=!0),o?n(this.view):n});r.length&&(this.dynamicDecorationMap[t.length]=e,t.push(_.join(r)));for(let n=t.length;ne.anchor?-1:1),n;if(!r)return;!e.empty&&(n=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(r={left:Math.min(r.left,n.left),top:Math.min(r.top,n.top),right:Math.max(r.right,n.right),bottom:Math.max(r.bottom,n.bottom)});let s=gd(this.view),o={left:r.left-s.left,top:r.top-s.top,right:r.right+s.right,bottom:r.bottom+s.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;RO(this.view.scrollDOM,o,e.head0)r=r.childNodes[n-1],n=qe(r);else break}if(e>=0)for(let r=i,n=t;;){if(r.nodeType==3)return{node:r,offset:n};if(r.nodeType==1&&n=0)r=r.childNodes[n],n=0;else break}return null}function jO(i,t){return i.nodeType!=1?0:(t&&i.childNodes[t-1].contentEditable==\"false\"?1:0)|(t{rt.from&&(e=!0)}),e}function i0(i,t,e=1){let r=i.charCategorizer(t),n=i.doc.lineAt(t),s=t-n.from;if(n.length==0)return b.cursor(t);s==0?e=1:s==n.length&&(e=-1);let o=s,l=s;e<0?o=at(n.text,s,!1):l=at(n.text,s);let a=r(n.text.slice(o,l));for(;o>0;){let h=at(n.text,o,!1);if(r(n.text.slice(h,o))!=a)break;o=h}for(;li?t.left-i:Math.max(0,i-t.right)}function n0(i,t){return t.top>i?t.top-i:Math.max(0,i-t.bottom)}function Vl(i,t){return i.topt.top+1}function cu(i,t){return ti.bottom?{top:i.top,left:i.left,right:i.right,bottom:t}:i}function ra(i,t,e){let r,n,s,o,l=!1,a,h,f,c;for(let m=i.firstChild;m;m=m.nextSibling){let O=Xr(m);for(let g=0;gC||o==C&&s>S){r=m,n=x,s=S,o=C;let v=C?e0?g0)}S==0?e>x.bottom&&(!f||f.bottomx.top)&&(h=m,c=x):f&&Vl(f,x)?f=uu(f,x.bottom):c&&Vl(c,x)&&(c=cu(c,x.top))}}if(f&&f.bottom>=e?(r=a,n=f):c&&c.top<=e&&(r=h,n=c),!r)return{node:i,offset:0};let u=Math.max(n.left,Math.min(n.right,t));if(r.nodeType==3)return du(r,u,e);if(l&&r.contentEditable!=\"false\")return ra(r,u,e);let d=Array.prototype.indexOf.call(i.childNodes,r)+(t>=(n.left+n.right)/2?1:0);return{node:i,offset:d}}function du(i,t,e){let r=i.nodeValue.length,n=-1,s=1e9,o=0;for(let l=0;le?f.top-e:e-f.bottom)-1;if(f.left-1<=t&&f.right+1>=t&&c=(f.left+f.right)/2,d=u;if((Q.chrome||Q.gecko)&&ai(i,l).getBoundingClientRect().left==f.right&&(d=!u),c<=0)return{node:i,offset:l+(d?1:0)};n=l+(d?1:0),s=c}}}return{node:i,offset:n>-1?n:o>0?i.nodeValue.length:0}}function yd(i,t,e,r=-1){var n,s;let o=i.contentDOM.getBoundingClientRect(),l=o.top+i.viewState.paddingTop,a,{docHeight:h}=i.viewState,{x:f,y:c}=t,u=c-l;if(u<0)return 0;if(u>h)return i.state.doc.length;for(let v=i.viewState.heightOracle.textHeight/2,y=!1;a=i.elementAtHeight(u),a.type!=Pt.Text;)for(;u=r>0?a.bottom+v:a.top-v,!(u>=0&&u<=h);){if(y)return e?null:0;y=!0,r=-r}c=l+u;let d=a.from;if(di.viewport.to)return i.viewport.to==i.state.doc.length?i.state.doc.length:e?null:pu(i,o,a,f,c);let m=i.dom.ownerDocument,O=i.root.elementFromPoint?i.root:m,g=O.elementFromPoint(f,c);g&&!i.contentDOM.contains(g)&&(g=null),g||(f=Math.max(o.left+1,Math.min(o.right-1,f)),g=O.elementFromPoint(f,c),g&&!i.contentDOM.contains(g)&&(g=null));let x,S=-1;if(g&&((n=i.docView.nearest(g))===null||n===void 0?void 0:n.isEditable)!=!1){if(m.caretPositionFromPoint){let v=m.caretPositionFromPoint(f,c);v&&({offsetNode:x,offset:S}=v)}else if(m.caretRangeFromPoint){let v=m.caretRangeFromPoint(f,c);v&&({startContainer:x,startOffset:S}=v,(!i.contentDOM.contains(x)||Q.safari&&s0(x,S,f)||Q.chrome&&o0(x,S,f))&&(x=void 0))}}if(!x||!i.docView.dom.contains(x)){let v=mt.find(i.docView,d);if(!v)return u>a.top+a.height/2?a.to:a.from;({node:x,offset:S}=ra(v.dom,f,c))}let C=i.docView.nearest(x);if(!C)return null;if(C.isWidget&&((s=C.dom)===null||s===void 0?void 0:s.nodeType)==1){let v=C.dom.getBoundingClientRect();return t.yi.defaultLineHeight*1.5){let l=i.viewState.heightOracle.textHeight,a=Math.floor((n-e.top-(i.defaultLineHeight-l)*.5)/l);s+=a*i.viewState.heightOracle.lineLength}let o=i.state.sliceDoc(e.from,e.to);return e.from+os(o,s,i.state.tabSize)}function s0(i,t,e){let r;if(i.nodeType!=3||t!=(r=i.nodeValue.length))return!1;for(let n=i.nextSibling;n;n=n.nextSibling)if(n.nodeType!=1||n.nodeName!=\"BR\")return!1;return ai(i,r-1,r).getBoundingClientRect().left>e}function o0(i,t,e){if(t!=0)return!1;for(let n=i;;){let s=n.parentNode;if(!s||s.nodeType!=1||s.firstChild!=n)return!1;if(s.classList.contains(\"cm-line\"))break;n=s}let r=i.nodeType==1?i.getBoundingClientRect():ai(i,0,Math.max(i.nodeValue.length,1)).getBoundingClientRect();return e-r.left>5}function na(i,t){let e=i.lineBlockAt(t);if(Array.isArray(e.type)){for(let r of e.type)if(r.to>t||r.to==t&&(r.to==e.to||r.type==Pt.Text))return r}return e}function l0(i,t,e,r){let n=na(i,t.head),s=!r||n.type!=Pt.Text||!(i.lineWrapping||n.widgetLineBreaks)?null:i.coordsAtPos(t.assoc<0&&t.head>n.from?t.head-1:t.head);if(s){let o=i.dom.getBoundingClientRect(),l=i.textDirectionAt(n.from),a=i.posAtCoords({x:e==(l==G.LTR)?o.right-1:o.left+1,y:(s.top+s.bottom)/2});if(a!=null)return b.cursor(a,e?-1:1)}return b.cursor(e?n.to:n.from,e?-1:1)}function mu(i,t,e,r){let n=i.state.doc.lineAt(t.head),s=i.bidiSpans(n),o=i.textDirectionAt(n.from);for(let l=t,a=null;;){let h=FO(n,s,o,l,e),f=rd;if(!h){if(n.number==(e?i.state.doc.lines:1))return l;f=`\n`,n=i.state.doc.line(n.number+(e?1:-1)),s=i.bidiSpans(n),h=i.visualLineSide(n,!e)}if(a){if(!a(f))return l}else{if(!r)return h;a=r(f)}l=h}}function a0(i,t,e){let r=i.state.charCategorizer(t),n=r(e);return s=>{let o=r(s);return n==F.Space&&(n=o),n==o}}function h0(i,t,e,r){let n=t.head,s=e?1:-1;if(n==(e?i.state.doc.length:0))return b.cursor(n,t.assoc);let o=t.goalColumn,l,a=i.contentDOM.getBoundingClientRect(),h=i.coordsAtPos(n,t.assoc||-1),f=i.documentTop;if(h)o==null&&(o=h.left-a.left),l=s<0?h.top:h.bottom;else{let d=i.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,i.defaultCharacterWidth*(n-d.from))),l=(s<0?d.top:d.bottom)+f}let c=a.left+o,u=r??i.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let m=l+(u+d)*s,O=yd(i,{x:c,y:m},!1,s);if(ma.bottom||(s<0?On)){let g=i.docView.coordsForChar(O),x=!g||m{if(t>s&&tn(i)),e.from,t.head>e.from?-1:1);return r==e.from?e:b.cursor(r,rnull),Q.gecko&&k0(t.contentDOM.ownerDocument)}handleEvent(t){!g0(this.view,t)||this.ignoreDuringComposition(t)||t.type==\"keydown\"&&this.keydown(t)||this.runHandlers(t.type,t)}runHandlers(t,e){let r=this.handlers[t];if(r){for(let n of r.observers)n(this.view,e);for(let n of r.handlers){if(e.defaultPrevented)break;if(n(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=f0(t),r=this.handlers,n=this.view.contentDOM;for(let s in e)if(s!=\"scroll\"){let o=!e[s].handlers.length,l=r[s];l&&o!=!l.handlers.length&&(n.removeEventListener(s,this.handleEvent),l=null),l||n.addEventListener(s,this.handleEvent,{passive:o})}for(let s in r)s!=\"scroll\"&&!e[s]&&n.removeEventListener(s,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&Date.now()r.keyCode==t.keyCode))&&!t.ctrlKey||c0.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(){let t=this.pendingIOSKey;return t?(this.pendingIOSKey=void 0,zi(this.view.contentDOM,t.key,t.keyCode)):!1}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:Q.safari&&!Q.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.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 gu(i,t){return(e,r)=>{try{return t.call(i,r,e)}catch(n){Ct(e.state,n)}}}function f0(i){let t=Object.create(null);function e(r){return t[r]||(t[r]={observers:[],handlers:[]})}for(let r of i){let n=r.spec;if(n&&n.domEventHandlers)for(let s in n.domEventHandlers){let o=n.domEventHandlers[s];o&&e(s).handlers.push(gu(r.value,o))}if(n&&n.domEventObservers)for(let s in n.domEventObservers){let o=n.domEventObservers[s];o&&e(s).observers.push(gu(r.value,o))}}for(let r in re)e(r).handlers.push(re[r]);for(let r in ne)e(r).observers.push(ne[r]);return t}var bd=[{key:\"Backspace\",keyCode:8,inputType:\"deleteContentBackward\"},{key:\"Enter\",keyCode:13,inputType:\"insertParagraph\"},{key:\"Enter\",keyCode:13,inputType:\"insertLineBreak\"},{key:\"Delete\",keyCode:46,inputType:\"deleteContentForward\"}],c0=\"dthko\",Sd=[16,17,18,20,91,92,224,225],fs=6;function cs(i){return Math.max(0,i)*.7+8}function u0(i,t){return Math.max(Math.abs(i.clientX-t.clientX),Math.abs(i.clientY-t.clientY))}var oa=class{constructor(t,e,r,n){this.view=t,this.startEvent=e,this.style=r,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParent=MO(t.contentDOM),this.atoms=t.state.facet($a).map(o=>o(t));let s=t.contentDOM.ownerDocument;s.addEventListener(\"mousemove\",this.move=this.move.bind(this)),s.addEventListener(\"mouseup\",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(Y.allowMultipleSelections)&&d0(t,e),this.dragging=m0(t,e)&&Td(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){var e;if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&u0(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let r=0,n=0,s=((e=this.scrollParent)===null||e===void 0?void 0:e.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},o=gd(this.view);t.clientX-o.left<=s.left+fs?r=-cs(s.left-t.clientX):t.clientX+o.right>=s.right-fs&&(r=cs(t.clientX-s.right)),t.clientY-o.top<=s.top+fs?n=-cs(s.top-t.clientY):t.clientY+o.bottom>=s.bottom-fs&&(n=cs(t.clientY-s.bottom)),this.setScrollSpeed(r,n)}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(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let r=0;rthis.select(this.lastEvent),20)}};function d0(i,t){let e=i.state.facet(nd);return e.length?e[0](t):Q.mac?t.metaKey:t.ctrlKey}function p0(i,t){let e=i.state.facet(sd);return e.length?e[0](t):Q.mac?!t.altKey:!t.ctrlKey}function m0(i,t){let{main:e}=i.state.selection;if(e.empty)return!1;let r=Ss(i.root);if(!r||r.rangeCount==0)return!0;let n=r.getRangeAt(0).getClientRects();for(let s=0;s=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function g0(i,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,r;e!=i.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(r=rt.get(e))&&r.ignoreEvent(t))return!1;return!0}var re=Object.create(null),ne=Object.create(null),wd=Q.ie&&Q.ie_version<15||Q.ios&&Q.webkit_version<604;function O0(i){let t=i.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement(\"textarea\"));e.style.cssText=\"position: fixed; left: -10000px; top: 10px\",e.focus(),setTimeout(()=>{i.focus(),e.remove(),vd(i,e.value)},50)}function vd(i,t){let{state:e}=i,r,n=1,s=e.toText(t),o=s.lines==e.selection.ranges.length;if(la!=null&&e.selection.ranges.every(a=>a.empty)&&la==s.toString()){let a=-1;r=e.changeByRange(h=>{let f=e.doc.lineAt(h.from);if(f.from==a)return{range:h};a=f.from;let c=e.toText((o?s.line(n++).text:t)+e.lineBreak);return{changes:{from:f.from,insert:c},range:b.cursor(h.from+c.length)}})}else o?r=e.changeByRange(a=>{let h=s.line(n++);return{changes:{from:a.from,to:a.to,insert:h.text},range:b.cursor(a.from+h.length)}}):r=e.replaceSelection(s);i.dispatch(r,{userEvent:\"input.paste\",scrollIntoView:!0})}ne.scroll=i=>{i.inputState.lastScrollTop=i.scrollDOM.scrollTop,i.inputState.lastScrollLeft=i.scrollDOM.scrollLeft};re.keydown=(i,t)=>(i.inputState.setSelectionOrigin(\"select\"),t.keyCode==27&&(i.inputState.lastEscPress=Date.now()),!1);ne.touchstart=(i,t)=>{i.inputState.lastTouchTime=Date.now(),i.inputState.setSelectionOrigin(\"select.pointer\")};ne.touchmove=i=>{i.inputState.setSelectionOrigin(\"select.pointer\")};re.mousedown=(i,t)=>{if(i.observer.flush(),i.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let r of i.state.facet(od))if(e=r(i,t),e)break;if(!e&&t.button==0&&(e=b0(i,t)),e){let r=!i.hasFocus;i.inputState.startMouseSelection(new oa(i,t,e,r)),r&&i.observer.ignore(()=>Nu(i.contentDOM));let n=i.inputState.mouseSelection;if(n)return n.start(t),n.dragging===!1}return!1};function Ou(i,t,e,r){if(r==1)return b.cursor(t,e);if(r==2)return i0(i.state,t,e);{let n=mt.find(i.docView,t),s=i.state.doc.lineAt(n?n.posAtEnd:t),o=n?n.posAtStart:s.from,l=n?n.posAtEnd:s.to;return li>=t.top&&i<=t.bottom,xu=(i,t,e)=>kd(t,e)&&i>=e.left&&i<=e.right;function x0(i,t,e,r){let n=mt.find(i.docView,t);if(!n)return 1;let s=t-n.posAtStart;if(s==0)return 1;if(s==n.length)return-1;let o=n.coordsAt(s,-1);if(o&&xu(e,r,o))return-1;let l=n.coordsAt(s,1);return l&&xu(e,r,l)?1:o&&kd(r,o)?-1:1}function yu(i,t){let e=i.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:x0(i,e,t.clientX,t.clientY)}}var y0=Q.ie&&Q.ie_version<=11,bu=null,Su=0,wu=0;function Td(i){if(!y0)return i.detail;let t=bu,e=wu;return bu=i,wu=Date.now(),Su=!t||e>Date.now()-400&&Math.abs(t.clientX-i.clientX)<2&&Math.abs(t.clientY-i.clientY)<2?(Su+1)%3:1}function b0(i,t){let e=yu(i,t),r=Td(t),n=i.state.selection;return{update(s){s.docChanged&&(e.pos=s.changes.mapPos(e.pos),n=n.map(s.changes))},get(s,o,l){let a=yu(i,s),h,f=Ou(i,a.pos,a.bias,r);if(e.pos!=a.pos&&!o){let c=Ou(i,e.pos,e.bias,r),u=Math.min(c.from,f.from),d=Math.max(c.to,f.to);f=u1&&(h=S0(n,a.pos))?h:l?n.addRange(f):b.create([f])}}}function S0(i,t){for(let e=0;e=t)return b.create(i.ranges.slice(0,e).concat(i.ranges.slice(e+1)),i.mainIndex==e?0:i.mainIndex-(i.mainIndex>e?1:0))}return null}re.dragstart=(i,t)=>{let{selection:{main:e}}=i.state;if(t.target.draggable){let n=i.docView.nearest(t.target);if(n&&n.isWidget){let s=n.posAtStart,o=s+n.length;(s>=e.to||o<=e.from)&&(e=b.range(s,o))}}let{inputState:r}=i;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData(\"Text\",i.state.sliceDoc(e.from,e.to)),t.dataTransfer.effectAllowed=\"copyMove\"),!1};re.dragend=i=>(i.inputState.draggedContent=null,!1);function vu(i,t,e,r){if(!e)return;let n=i.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:s}=i.inputState,o=r&&s&&p0(i,t)?{from:s.from,to:s.to}:null,l={from:n,insert:e},a=i.state.changes(o?[o,l]:l);i.focus(),i.dispatch({changes:a,selection:{anchor:a.mapPos(n,-1),head:a.mapPos(n,1)},userEvent:o?\"move.drop\":\"input.drop\"}),i.inputState.draggedContent=null}re.drop=(i,t)=>{if(!t.dataTransfer)return!1;if(i.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let r=Array(e.length),n=0,s=()=>{++n==e.length&&vu(i,t,r.filter(o=>o!=null).join(i.state.lineBreak),!1)};for(let o=0;o{/[\\x00-\\x08\\x0e-\\x1f]{2}/.test(l.result)||(r[o]=l.result),s()},l.readAsText(e[o])}return!0}else{let r=t.dataTransfer.getData(\"Text\");if(r)return vu(i,t,r,!0),!0}return!1};re.paste=(i,t)=>{if(i.state.readOnly)return!0;i.observer.flush();let e=wd?null:t.clipboardData;return e?(vd(i,e.getData(\"text/plain\")||e.getData(\"text/uri-text\")),!0):(O0(i),!1)};function w0(i,t){let e=i.dom.parentNode;if(!e)return;let r=e.appendChild(document.createElement(\"textarea\"));r.style.cssText=\"position: fixed; left: -10000px; top: 10px\",r.value=t,r.focus(),r.selectionEnd=t.length,r.selectionStart=0,setTimeout(()=>{r.remove(),i.focus()},50)}function v0(i){let t=[],e=[],r=!1;for(let n of i.selection.ranges)n.empty||(t.push(i.sliceDoc(n.from,n.to)),e.push(n));if(!t.length){let n=-1;for(let{from:s}of i.selection.ranges){let o=i.doc.lineAt(s);o.number>n&&(t.push(o.text),e.push({from:o.from,to:Math.min(i.doc.length,o.to+1)})),n=o.number}r=!0}return{text:t.join(i.lineBreak),ranges:e,linewise:r}}var la=null;re.copy=re.cut=(i,t)=>{let{text:e,ranges:r,linewise:n}=v0(i.state);if(!e&&!n)return!1;la=n?e:null,t.type==\"cut\"&&!i.state.readOnly&&i.dispatch({changes:r,scrollIntoView:!0,userEvent:\"delete.cut\"});let s=wd?null:t.clipboardData;return s?(s.clearData(),s.setData(\"text/plain\",e),!0):(w0(i,e),!1)};var Pd=Et.define();function Cd(i,t){let e=[];for(let r of i.facet(hd)){let n=r(i,t);n&&e.push(n)}return e?i.update({effects:e,annotations:Pd.of(!0)}):null}function Ad(i){setTimeout(()=>{let t=i.hasFocus;if(t!=i.inputState.notifiedFocused){let e=Cd(i.state,t);e?i.dispatch(e):i.update([])}},10)}ne.focus=i=>{i.inputState.lastFocusTime=Date.now(),!i.scrollDOM.scrollTop&&(i.inputState.lastScrollTop||i.inputState.lastScrollLeft)&&(i.scrollDOM.scrollTop=i.inputState.lastScrollTop,i.scrollDOM.scrollLeft=i.inputState.lastScrollLeft),Ad(i)};ne.blur=i=>{i.observer.clearSelectionRange(),Ad(i)};ne.compositionstart=ne.compositionupdate=i=>{i.inputState.compositionFirstChange==null&&(i.inputState.compositionFirstChange=!0),i.inputState.composing<0&&(i.inputState.composing=0)};ne.compositionend=i=>{i.inputState.composing=-1,i.inputState.compositionEndedAt=Date.now(),i.inputState.compositionPendingKey=!0,i.inputState.compositionPendingChange=i.observer.pendingRecords().length>0,i.inputState.compositionFirstChange=null,Q.chrome&&Q.android?i.observer.flushSoon():i.inputState.compositionPendingChange?Promise.resolve().then(()=>i.observer.flush()):setTimeout(()=>{i.inputState.composing<0&&i.docView.hasComposition&&i.update([])},50)};ne.contextmenu=i=>{i.inputState.lastContextMenu=Date.now()};re.beforeinput=(i,t)=>{var e;let r;if(Q.chrome&&Q.android&&(r=bd.find(n=>n.inputType==t.inputType))&&(i.observer.delayAndroidKey(r.key,r.keyCode),r.key==\"Backspace\"||r.key==\"Delete\")){let n=((e=window.visualViewport)===null||e===void 0?void 0:e.height)||0;setTimeout(()=>{var s;(((s=window.visualViewport)===null||s===void 0?void 0:s.height)||0)>n+10&&i.hasFocus&&(i.contentDOM.blur(),i.focus())},100)}return!1};var ku=new Set;function k0(i){ku.has(i)||(ku.add(i),i.addEventListener(\"copy\",()=>{}),i.addEventListener(\"cut\",()=>{}))}var Tu=[\"pre-wrap\",\"normal\",\"pre-line\",\"break-spaces\"],aa=class{constructor(t){this.lineWrapping=t,this.doc=V.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let r=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((e-t-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}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 Tu.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let r=0;r-1,a=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=r,this.textHeight=n,this.lineLength=s,a){this.heightSamples={};for(let h=0;h0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>ys&&(t.heightChanged=!0),this.height=e)}replace(t,e,r){return i.of(r)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,r,n){let s=this,o=r.doc;for(let l=n.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:f,toB:c}=n[l],u=s.lineAt(a,et.ByPosNoHeight,r.setDoc(e),0,0),d=u.to>=h?u:s.lineAt(h,et.ByPosNoHeight,r,0,0);for(c+=d.to-h,h=d.to;l>0&&u.from<=n[l-1].toA;)a=n[l-1].fromA,f=n[l-1].fromB,l--,as*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),r+=1+l.break,n-=l.size}else if(s>n*2){let l=t[r];l.break?t.splice(r,1,l.left,null,l.right):t.splice(r,1,l.left,l.right),r+=2+l.break,s-=l.size}else break;else if(n=s&&o(this.blockAt(0,r,n,s))}updateHeight(t,e=0,r=!1,n){return n&&n.from<=e&&n.more&&this.setHeight(t,n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},Ht=class i extends Cs{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,r,n){return new ge(n,this.length,r,this.height,this.breaks)}replace(t,e,r){let n=r[0];return r.length==1&&(n instanceof i||n instanceof Ne&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof Ne?n=new i(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):Vt.of(r)}updateHeight(t,e=0,r=!1,n){return n&&n.from<=e&&n.more?this.setHeight(t,n.heights[n.index++]):(r||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:\"\"})`}},Ne=class i extends Vt{constructor(t){super(t,0)}heightMetrics(t,e){let r=t.doc.lineAt(e).number,n=t.doc.lineAt(e+this.length).number,s=n-r+1,o,l=0;if(t.lineWrapping){let a=Math.min(this.height,t.lineHeight*s);o=a/s,this.length>s+1&&(l=(this.height-a)/(this.length-s-1))}else o=this.height/s;return{firstLine:r,lastLine:n,perLine:o,perChar:l}}blockAt(t,e,r,n){let{firstLine:s,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(e,n);if(e.lineWrapping){let h=n+Math.round(Math.max(0,Math.min(1,(t-r)/this.height))*this.length),f=e.doc.lineAt(h),c=l+f.length*a,u=Math.max(r,t-c/2);return new ge(f.from,f.length,u,c,0)}else{let h=Math.max(0,Math.min(o-s,Math.floor((t-r)/l))),{from:f,length:c}=e.doc.line(s+h);return new ge(f,c,r+l*h,l,0)}}lineAt(t,e,r,n,s){if(e==et.ByHeight)return this.blockAt(t,r,n,s);if(e==et.ByPosNoHeight){let{from:d,to:m}=r.doc.lineAt(t);return new ge(d,m-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(r,s),h=r.doc.lineAt(t),f=l+h.length*a,c=h.number-o,u=n+l*c+a*(h.from-s-c);return new ge(h.from,h.length,Math.max(n,Math.min(u,n+this.height-f)),f,0)}forEachLine(t,e,r,n,s,o){t=Math.max(t,s),e=Math.min(e,s+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(r,s);for(let f=t,c=n;f<=e;){let u=r.doc.lineAt(f);if(f==t){let m=u.number-l;c+=a*m+h*(t-s-m)}let d=a+h*u.length;o(new ge(u.from,u.length,c,d,0)),c+=d,f=u.to+1}}replace(t,e,r){let n=this.length-e;if(n>0){let s=r[r.length-1];s instanceof i?r[r.length-1]=new i(s.length+n):r.push(null,new i(n-1))}if(t>0){let s=r[0];s instanceof i?r[0]=new i(t+s.length):r.unshift(new i(t-1),null)}return Vt.of(r)}decomposeLeft(t,e){e.push(new i(t-1),null)}decomposeRight(t,e){e.push(null,new i(this.length-t-1))}updateHeight(t,e=0,r=!1,n){let s=e+this.length;if(n&&n.from<=e+this.length&&n.more){let o=[],l=Math.max(e,n.from),a=-1;for(n.from>e&&o.push(new i(n.from-e-1).updateHeight(t,e));l<=s&&n.more;){let f=t.doc.lineAt(l).length;o.length&&o.push(null);let c=n.heights[n.index++];a==-1?a=c:Math.abs(c-a)>=ys&&(a=-2);let u=new Ht(f,c);u.outdated=!1,o.push(u),l+=f+1}l<=s&&o.push(null,new i(s-l).updateHeight(t,l));let h=Vt.of(o);return(a<0||Math.abs(h.height-this.height)>=ys||Math.abs(a-this.heightMetrics(t,e).perLine)>=ys)&&(t.heightChanged=!0),h}else(r||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},fa=class extends Vt{constructor(t,e,r){super(t.length+e+r.length,t.height+r.height,e|(t.outdated||r.outdated?2:0)),this.left=t,this.right=r,this.size=t.size+r.size}get break(){return this.flags&1}blockAt(t,e,r,n){let s=r+this.left.height;return tl))return h;let f=e==et.ByPosNoHeight?et.ByPosNoHeight:et.ByPos;return a?h.join(this.right.lineAt(l,f,r,o,l)):this.left.lineAt(l,f,r,n,s).join(h)}forEachLine(t,e,r,n,s,o){let l=n+this.left.height,a=s+this.left.length+this.break;if(this.break)t=a&&this.right.forEachLine(t,e,r,l,a,o);else{let h=this.lineAt(a,et.ByPos,r,n,s);t=t&&h.from<=e&&o(h),e>h.to&&this.right.forEachLine(h.to+1,e,r,l,a,o)}}replace(t,e,r){let n=this.left.length+this.break;if(ethis.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,r));let s=[];t>0&&this.decomposeLeft(t,s);let o=s.length;for(let l of r)s.push(l);if(t>0&&Pu(s,o-1),e=r&&e.push(null)),t>r&&this.right.decomposeLeft(t-r,e)}decomposeRight(t,e){let r=this.left.length,n=r+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t2*e.size||e.size>2*t.size?Vt.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,r=!1,n){let{left:s,right:o}=this,l=e+s.length+this.break,a=null;return n&&n.from<=e+s.length&&n.more?a=s=s.updateHeight(t,e,r,n):s.updateHeight(t,e,r),n&&n.from<=l+o.length&&n.more?a=o=o.updateHeight(t,l,r,n):o.updateHeight(t,l,r),a?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?\" \":\"-\")+this.right}};function Pu(i,t){let e,r;i[t]==null&&(e=i[t-1])instanceof Ne&&(r=i[t+1])instanceof Ne&&i.splice(t-1,3,new Ne(e.length+1+r.length))}var T0=5,ca=class i{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 r=Math.min(e,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof Ht?n.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new Ht(r-this.pos,-1)),this.writtenTo=r,e>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,r){if(t=T0)&&this.addLineDeco(n,s,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTot&&this.nodes.push(new Ht(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let r=new Ne(e-t);return this.oracle.doc.lineAt(t).to==e&&(r.flags|=4),r}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof Ht)return t;let e=new Ht(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,r){let n=this.ensureLine();n.length+=r,n.collapsed+=r,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+r}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof Ht)&&!this.isCovered?this.nodes.push(new Ht(0,-1)):(this.writtenTof.clientHeight||f.scrollWidth>f.clientWidth)&&c.overflow!=\"visible\"){let u=f.getBoundingClientRect();s=Math.max(s,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=h==i.parentNode?u.bottom:Math.min(a,u.bottom)}h=c.position==\"absolute\"||c.position==\"fixed\"?f.offsetParent:f.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:s-e.left,right:Math.max(s,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,a)-(e.top+t)}}function A0(i,t){let e=i.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}var qr=class{constructor(t,e,r){this.from=t,this.to=e,this.size=r}static same(t,e){if(t.length!=e.length)return!1;for(let r=0;rtypeof r!=\"function\"&&r.class==\"cm-lineWrapping\");this.heightOracle=new aa(e),this.stateDeco=t.facet(Yr).filter(r=>typeof r!=\"function\"),this.heightMap=Vt.empty().applyChanges(this.stateDeco,V.empty,this.heightOracle.setDoc(t.doc),[new xe(0,0,0,t.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=R.set(this.lineGaps.map(r=>r.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let r=0;r<=1;r++){let n=r?e.head:e.anchor;if(!t.some(({from:s,to:o})=>n>=s&&n<=o)){let{from:s,to:o}=this.lineBlockAt(n);t.push(new Ii(s,o))}}this.viewports=t.sort((r,n)=>r.from-n.from),this.scaler=this.heightMap.height<=7e6?Cu:new pa(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(this.scaler.scale==1?t:Cr(t,this.scaler))})}update(t,e=null){this.state=t.state;let r=this.stateDeco;this.stateDeco=this.state.facet(Yr).filter(f=>typeof f!=\"function\");let n=t.changedRanges,s=xe.extendWithRanges(n,P0(r,this.stateDeco,t?t.changes:vt.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),s),this.heightMap.height!=o&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=s.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.heada.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,e));let h=!t.changes.empty||t.flags&2||a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,this.updateForViewport(),h&&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(cd)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,r=window.getComputedStyle(e),n=this.heightOracle,s=r.whiteSpace;this.defaultTextDirection=r.direction==\"rtl\"?G.RTL:G.LTR;let o=this.heightOracle.mustRefreshForWrapping(s),l=e.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,f=0;if(l.width&&l.height){let{scaleX:v,scaleY:y}=Iu(e,l);(this.scaleX!=v||this.scaleY!=y)&&(this.scaleX=v,this.scaleY=y,h|=8,o=a=!0)}let c=(parseInt(r.paddingTop)||0)*this.scaleY,u=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,h|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=t.scrollDOM.clientWidth,h|=8);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=zu(t.scrollDOM);let m=(this.printing?A0:C0)(e,this.paddingTop),O=m.top-this.pixelViewport.top,g=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let x=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(x!=this.inView&&(this.inView=x,x&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let S=l.width;if((this.contentDOMWidth!=S||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,h|=8),a){let v=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(v)&&(o=!0),o||n.lineWrapping&&Math.abs(S-this.contentDOMWidth)>n.charWidth){let{lineHeight:y,charWidth:k,textHeight:w}=t.docView.measureTextSize();o=y>0&&n.refresh(s,y,k,w,S/k,v),o&&(t.docView.minWidth=0,h|=8)}O>0&&g>0?f=Math.max(O,g):O<0&&g<0&&(f=Math.min(O,g)),n.heightChanged=!1;for(let y of this.viewports){let k=y.from==this.viewport.from?v:t.docView.measureVisibleLineHeights(y);this.heightMap=(o?Vt.empty().applyChanges(this.stateDeco,V.empty,this.heightOracle,[new xe(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new ha(y.from,k))}n.heightChanged&&(h|=2)}let C=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return C&&(this.viewport=this.getViewport(f,this.scrollTarget)),this.updateForViewport(),(h&2||C)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let r=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Ii(n.lineAt(o-r*1e3,et.ByHeight,s,0,0).from,n.lineAt(l+(1-r)*1e3,et.ByHeight,s,0,0).to);if(e){let{head:h}=e.range;if(ha.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=n.lineAt(h,et.ByPos,s,0,0),u;e.y==\"center\"?u=(c.top+c.bottom)/2-f/2:e.y==\"start\"||e.y==\"nearest\"&&h=l+Math.max(10,Math.min(r,250)))&&n>o-2*1e3&&s>1,o=n<<1;if(this.defaultTextDirection!=G.LTR&&!r)return[];let l=[],a=(h,f,c,u)=>{if(f-hh&&gg.from>=c.from&&g.to<=c.to&&Math.abs(g.from-h)g.fromx));if(!O){if(fg.from<=f&&g.to>=f)){let g=e.moveToLineBoundary(b.cursor(f),!1,!0).head;g>h&&(f=g)}O=new qr(h,f,this.gapSize(c,h,f,u))}l.push(O)};for(let h of this.viewportLines){if(h.lengthh.from&&a(h.from,u,h,f),de.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];_.spans(t,this.viewport.from,this.viewport.to,{span(n,s){e.push({from:n,to:s})},point(){}},20);let r=e.length!=this.visibleRanges.length||this.visibleRanges.some((n,s)=>n.from!=e[s].from||n.to!=e[s].to);return this.visibleRanges=e,r?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Cr(this.heightMap.lineAt(t,et.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return Cr(this.heightMap.lineAt(this.scaler.fromDOM(t),et.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 Cr(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}},Ii=class{constructor(t,e){this.from=t,this.to=e}};function Q0(i,t,e){let r=[],n=i,s=0;return _.spans(e,i,t,{span(){},point(o,l){o>n&&(r.push({from:n,to:o}),s+=o-n),n=l}},20),n=1)return t[t.length-1].to;let r=Math.floor(i*e);for(let n=0;;n++){let{from:s,to:o}=t[n],l=o-s;if(r<=l)return s+r;r-=l}}function ds(i,t){let e=0;for(let{from:r,to:n}of i.ranges){if(t<=n){e+=t-r;break}e+=n-r}return e/i.total}function R0(i,t){for(let e of i)if(t(e))return e}var Cu={toDOM(i){return i},fromDOM(i){return i},scale:1},pa=class{constructor(t,e,r){let n=0,s=0,o=0;this.viewports=r.map(({from:l,to:a})=>{let h=e.lineAt(l,et.ByPos,t,0,0).top,f=e.lineAt(a,et.ByPos,t,0,0).bottom;return n+=f-h,{from:l,to:a,top:h,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.height-n);for(let l of this.viewports)l.domTop=o+(l.top-s)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),s=l.bottom}toDOM(t){for(let e=0,r=0,n=0;;e++){let s=eCr(n,t)):i._content)}var ps=A.define({combine:i=>i.join(\" \")}),ma=A.define({combine:i=>i.indexOf(!0)>-1}),ga=Gt.newName(),Qd=Gt.newName(),Rd=Gt.newName(),Md={\"&light\":\".\"+Qd,\"&dark\":\".\"+Rd};function Oa(i,t,e){return new Gt(t,{finish(r){return/&/.test(r)?r.replace(/&\\w*/,n=>{if(n==\"&\")return i;if(!e||!e[n])throw new RangeError(`Unsupported selector: ${n}`);return e[n]}):i+\" \"+r}})}var M0=Oa(\".\"+ga,{\"&\":{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,')`,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\"}},Md),Ar=\"\\uFFFF\",xa=class{constructor(t,e){this.points=t,this.text=\"\",this.lineSeparator=e.facet(Y.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Ar}readRange(t,e){if(!t)return this;let r=t.parentNode;for(let n=t;;){this.findPointBefore(r,n);let s=this.text.length;this.readNode(n);let o=n.nextSibling;if(o==e)break;let l=rt.get(n),a=rt.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:Au(n))||Au(o)&&(n.nodeName!=\"BR\"||n.cmIgnore)&&this.text.length>s)&&this.lineBreak(),n=o}return this.findPointBefore(r,e),this}readTextNode(t){let e=t.nodeValue;for(let r of this.points)r.node==t&&(r.pos=this.text.length+Math.min(r.offset,e.length));for(let r=0,n=this.lineSeparator?null:/\\r\\n?|\\n/g;;){let s=-1,o=1,l;if(this.lineSeparator?(s=e.indexOf(this.lineSeparator,r),o=this.lineSeparator.length):(l=n.exec(e))&&(s=l.index,o=l[0].length),this.append(e.slice(r,s<0?e.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==t&&a.pos>this.text.length&&(a.pos-=o-1);r=s+o}}readNode(t){if(t.cmIgnore)return;let e=rt.get(t),r=e&&e.overrideDOMText;if(r!=null){this.findPointInside(t,r.length);for(let n=r.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.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 r of this.points)r.node==t&&t.childNodes[r.offset]==e&&(r.pos=this.text.length)}findPointInside(t,e){for(let r of this.points)(t.nodeType==3?r.node==t:t.contains(r.node))&&(r.pos=this.text.length+(E0(t,r.node,r.offset)?e:0))}};function E0(i,t,e){for(;;){if(!t||e-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,r,0))){let l=s||o?[]:D0(t),a=new xa(l,t.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=B0(l,this.bounds.from)}else{let l=t.observer.selectionRange,a=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!Zl(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),h=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!Zl(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),f=t.viewport;if((Q.ios||Q.chrome)&&t.state.selection.main.empty&&a!=h&&(f.from>0||f.toDate.now()-100?i.inputState.lastKeyCode:-1;if(t.bounds){let{from:o,to:l}=t.bounds,a=n.from,h=null;(s===8||Q.android&&t.text.length=n.from&&e.to<=n.to&&(e.from!=n.from||e.to!=n.to)&&n.to-n.from-(e.to-e.from)<=4?e={from:n.from,to:n.to,insert:i.state.doc.slice(n.from,e.from).append(e.insert).append(i.state.doc.slice(e.to,n.to))}:(Q.mac||Q.android)&&e&&e.from==e.to&&e.from==n.head-1&&/^\\. ?$/.test(e.insert.toString())&&i.contentDOM.getAttribute(\"autocorrect\")==\"off\"?(r&&e.insert.length==2&&(r=b.single(r.main.anchor-1,r.main.head-1)),e={from:n.from,to:n.to,insert:V.of([\" \"])}):Q.chrome&&e&&e.from==e.to&&e.from==n.head&&e.insert.toString()==`\n `&&i.lineWrapping&&(r&&(r=b.single(r.main.anchor-1,r.main.head-1)),e={from:n.from,to:n.to,insert:V.of([\" \"])}),e){if(Q.ios&&i.inputState.flushIOSKey()||Q.android&&(e.from==n.from&&e.to==n.to&&e.insert.length==1&&e.insert.lines==2&&zi(i.contentDOM,\"Enter\",13)||(e.from==n.from-1&&e.to==n.to&&e.insert.length==0||s==8&&e.insert.lengthn.head)&&zi(i.contentDOM,\"Backspace\",8)||e.from==n.from&&e.to==n.to+1&&e.insert.length==0&&zi(i.contentDOM,\"Delete\",46)))return!0;let o=e.insert.toString();i.inputState.composing>=0&&i.inputState.composing++;let l,a=()=>l||(l=$0(i,e,r));return i.state.facet(ad).some(h=>h(i,e.from,e.to,o,a))||i.dispatch(a()),!0}else if(r&&!r.main.eq(n)){let o=!1,l=\"select\";return i.inputState.lastSelectionTime>Date.now()-50&&(i.inputState.lastSelectionOrigin==\"select\"&&(o=!0),l=i.inputState.lastSelectionOrigin),i.dispatch({selection:r,scrollIntoView:o,userEvent:l}),!0}else return!1}function $0(i,t,e){let r,n=i.state,s=n.selection.main;if(t.from>=s.from&&t.to<=s.to&&t.to-t.from>=(s.to-s.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&i.inputState.composing<0){let l=s.fromt.to?n.sliceDoc(t.to,s.to):\"\";r=n.replaceSelection(i.state.toText(l+t.insert.sliceString(0,void 0,i.state.lineBreak)+a))}else{let l=n.changes(t),a=e&&e.main.to<=l.newLength?e.main:void 0;if(n.selection.ranges.length>1&&i.inputState.composing>=0&&t.to<=s.to&&t.to>=s.to-10){let h=i.state.sliceDoc(t.from,t.to),f,c=e&&Od(i,e.main.head);if(c){let m=t.insert.length-(t.to-t.from);f={from:c.from,to:c.to-m}}else f=i.state.doc.lineAt(s.head);let u=s.to-t.to,d=s.to-s.from;r=n.changeByRange(m=>{if(m.from==s.from&&m.to==s.to)return{changes:l,range:a||m.map(l)};let O=m.to-u,g=O-h.length;if(m.to-m.from!=d||i.state.sliceDoc(g,O)!=h||m.to>=f.from&&m.from<=f.to)return{range:m};let x=n.changes({from:g,to:O,insert:t.insert}),S=m.to-s.to;return{changes:x,range:a?b.range(Math.max(0,a.anchor+S),Math.max(0,a.head+S)):m.map(x)}})}else r={changes:l,selection:a&&n.selection.replaceRange(a)}}let o=\"input.type\";return(i.composing||i.inputState.compositionPendingChange&&i.inputState.compositionEndedAt>Date.now()-50)&&(i.inputState.compositionPendingChange=!1,o+=\".compose\",i.inputState.compositionFirstChange&&(o+=\".start\",i.inputState.compositionFirstChange=!1)),n.update(r,{userEvent:o,scrollIntoView:!0})}function q0(i,t,e,r){let n=Math.min(i.length,t.length),s=0;for(;s0&&l>0&&i.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(r==\"end\"){let a=Math.max(0,s-Math.min(o,l));e-=o+a-s}if(o=o?s-e:0;s-=a,l=s+(l-o),o=s}else if(l=l?s-e:0;s-=a,o=s+(o-l),l=s}return{from:s,toA:o,toB:l}}function D0(i){let t=[];if(i.root.activeElement!=i.contentDOM)return t;let{anchorNode:e,anchorOffset:r,focusNode:n,focusOffset:s}=i.observer.selectionRange;return e&&(t.push(new Qs(e,r)),(n!=e||s!=r)&&t.push(new Qs(n,s))),t}function B0(i,t){if(i.length==0)return null;let e=i[0].pos,r=i.length==2?i[1].pos:e;return e>-1&&r>-1?b.single(e+t,r+t):null}var X0={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Il=Q.ie&&Q.ie_version<=11,ba=class{constructor(t){this.view=t,this.active=!1,this.selectionRange=new Fl,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.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let r of e)this.queue.push(r);(Q.ie&&Q.ie_version<=11||Q.ios&&t.composing)&&e.some(r=>r.type==\"childList\"&&r.removedNodes.length||r.type==\"characterData\"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),Il&&(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),typeof ResizeObserver==\"function\"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate){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.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(){this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500)}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,r)=>e!=t[r]))){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:r}=this,n=this.selectionRange;if(r.state.facet(Xs)?r.root.activeElement!=this.dom:!Os(r.dom,n))return;let s=n.anchorNode&&r.docView.nearest(n.anchorNode);if(s&&s.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(Q.ie&&Q.ie_version<=11||Q.android&&Q.chrome)&&!r.state.selection.main.empty&&n.focusNode&&Rr(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=Q.safari&&t.root.nodeType==11&&AO(this.dom.ownerDocument)==this.dom&&L0(this.view)||Ss(t.root);if(!e||this.selectionRange.eq(e))return!1;let r=Os(this.dom,e);return r&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&zi(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||t==\"Enter\")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,r=-1,n=!1;for(let s of t){let o=this.readMutation(s);o&&(o.typeOver&&(n=!0),e==-1?{from:e,to:r}=o:(e=Math.min(o.from,e),r=Math.max(o.to,r)))}return{from:e,to:r,typeOver:n}}readChange(){let{from:t,to:e,typeOver:r}=this.processRecords(),n=this.selectionChanged&&Os(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new ya(this.view,t,e,r);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let r=this.view.state,n=Ed(this.view,e);return this.view.state==r&&this.view.update([]),n}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 r=Qu(e,t.previousSibling||t.target.previousSibling,-1),n=Qu(e,t.nextSibling||t.target.nextSibling,1);return{from:r?e.posAfter(r):e.posAtStart,to:n?e.posBefore(n):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),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),t.removeEventListener(\"beforeprint\",this.onPrint),t.document.removeEventListener(\"selectionchange\",this.onSelectionChange)}destroy(){var t,e,r;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let n of this.scrollTargets)n.removeEventListener(\"scroll\",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}};function Qu(i,t,e){for(;t;){let r=rt.get(t);if(r&&r.parent==i)return r;let n=t.parentNode;t=n!=i.dom?n:e>0?t.nextSibling:t.previousSibling}return null}function L0(i){let t=null;function e(a){a.preventDefault(),a.stopImmediatePropagation(),t=a.getTargetRanges()[0]}if(i.contentDOM.addEventListener(\"beforeinput\",e,!0),i.dom.ownerDocument.execCommand(\"indent\"),i.contentDOM.removeEventListener(\"beforeinput\",e,!0),!t)return null;let r=t.startContainer,n=t.startOffset,s=t.endContainer,o=t.endOffset,l=i.docView.domAtPos(i.state.selection.main.anchor);return Rr(l.node,l.offset,s,o)&&([r,n,s,o]=[s,o,r,n]),{anchorNode:r,anchorOffset:n,focusNode:s,focusOffset:o}}var T=class i{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&&(r=>r.forEach(n=>e(n,this)))||(r=>this.update(r)),this.dispatch=this.dispatch.bind(this),this._root=t.root||EO(t.parent)||document,this.viewState=new As(t.state||Y.create(t)),t.scrollTo&&t.scrollTo.is(hs)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Tr).map(r=>new $r(r));for(let r of this.plugins)r.update(this);this.observer=new ba(this),this.inputState=new sa(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Ts(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...t){let e=t.length==1&&t[0]instanceof lt?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,r=!1,n,s=this.state;for(let u of t){if(u.startState!=s)throw new RangeError(\"Trying to update state with a transaction that doesn't start from the previous state.\");s=u.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,l=0,a=null;t.some(u=>u.annotation(Pd))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Cd(s,o),a||(l=1));let h=this.observer.delayedAndroidKey,f=null;if(h?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(f=null)):this.observer.clear(),s.facet(Y.phrases)!=this.state.facet(Y.phrases))return this.setState(s);n=ks.create(this,s,t),n.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of t){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;c=new Er(d.empty?d:b.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(hs)&&(c=d.value.clip(this.state))}this.viewState.update(n,c),this.bidiCache=Rs.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),e=this.docView.update(n),this.state.facet(Pr)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(u=>u.isUserEvent(\"select.pointer\")))}finally{this.updateState=0}if(n.startState.facet(ps)!=n.state.facet(ps)&&(this.viewState.mustMeasureContent=!0),(e||r||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!n.empty)for(let u of this.state.facet(ia))try{u(n)}catch(d){Ct(this.state,d,\"update listener\")}(a||f)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),f&&!Ed(this,f)&&h.force&&zi(this.contentDOM,h.key,h.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 r of this.plugins)r.destroy(this);this.viewState=new As(t),this.plugins=t.facet(Tr).map(r=>new $r(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new Ts(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(Tr),r=t.state.facet(Tr);if(e!=r){let n=[];for(let s of r){let o=e.indexOf(s);if(o<0)n.push(new $r(s));else{let l=this.plugins[o];l.mustUpdate=t,n.push(l)}}for(let s of this.plugins)s.mustUpdate!=t&&s.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=t;for(let n=0;n-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,r=this.scrollDOM,n=r.scrollTop*this.scaleY,{scrollAnchorPos:s,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(zu(r))s=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(n);s=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?\"Measure loop restarted more than 5 times\":\"Viewport failed to stabilize\");break}let h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let f=h.map(d=>{try{return d.read(this)}catch(m){return Ct(this.state,m),Ru}}),c=ks.create(this,this.state,[]),u=!1;c.flags|=a,e?e.flags|=a:e=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c));for(let d=0;d1||m<-1){n=n+m,r.scrollTop=n/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(ia))l(e)}get themeClasses(){return ga+\" \"+(this.state.facet(ma)?Rd:Qd)+\" \"+this.state.facet(ps)}updateAttrs(){let t=Mu(this,ud,{class:\"cm-editor\"+(this.hasFocus?\" cm-focused \":\" \")+this.themeClasses}),e={spellcheck:\"false\",autocorrect:\"off\",autocapitalize:\"off\",translate:\"no\",contenteditable:this.state.facet(Xs)?\"true\":\"false\",class:\"cm-content\",style:`${Q.tabSize}: ${this.state.tabSize}`,role:\"textbox\",\"aria-multiline\":\"true\"};this.state.readOnly&&(e[\"aria-readonly\"]=\"true\"),Mu(this,Ea,e);let r=this.observer.ignore(()=>{let n=jl(this.contentDOM,this.contentAttrs,e),s=jl(this.dom,this.editorAttrs,t);return n||s});return this.editorAttrs=t,this.contentAttrs=e,r}showAnnouncements(t){let e=!0;for(let r of t)for(let n of r.effects)if(n.is(i.announce)){e&&(this.announceDOM.textContent=\"\"),e=!1;let s=this.announceDOM.appendChild(document.createElement(\"div\"));s.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(Pr);let t=this.state.facet(i.cspNonce);Gt.mount(this.root,this.styleModules.concat(M0).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;er.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,r){return Wl(this,t,mu(this,t,e,r))}moveByGroup(t,e){return Wl(this,t,mu(this,t,e,r=>a0(this,t.head,r)))}visualLineSide(t,e){let r=this.bidiSpans(t),n=this.textDirectionAt(t.from),s=r[e?r.length-1:0];return b.cursor(s.side(e,n)+t.from,s.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,r=!0){return l0(this,t,e,r)}moveVertically(t,e,r){return Wl(this,t,h0(this,t,e,r))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),yd(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let r=this.docView.coordsAt(t,e);if(!r||r.left==r.right)return r;let n=this.state.doc.lineAt(t),s=this.bidiSpans(n),o=s[Oe.find(s,t-n.from,-1,e)];return Aa(r,o.dir==G.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(fd)||tthis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>V0)return id(t.length);let e=this.textDirectionAt(t.from),r;for(let s of this.bidiCache)if(s.from==t.from&&s.dir==e&&(s.fresh||ed(s.isolates,r=fu(this,t))))return s.order;r||(r=fu(this,t));let n=ZO(t.text,e,r);return this.bidiCache.push(new Rs(t.from,t.to,e,r,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||Q.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Nu(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(){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 hs.of(new Er(typeof t==\"number\"?b.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,r=this.viewState.scrollAnchorAt(t);return hs.of(new Er(b.cursor(r.from),\"start\",\"start\",r.top-t,e,!0))}static domEventHandlers(t){return ft.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return ft.define(()=>({}),{eventObservers:t})}static theme(t,e){let r=Gt.newName(),n=[ps.of(r),Pr.of(Oa(`.${r}`,t))];return e&&e.dark&&n.push(ma.of(!0)),n}static baseTheme(t){return ie.lowest(Pr.of(Oa(\".\"+ga,t,Md)))}static findFromDOM(t){var e;let r=t.querySelector(\".cm-content\"),n=r&&rt.get(r)||rt.get(t);return((e=n?.rootView)===null||e===void 0?void 0:e.view)||null}};T.styleModule=Pr;T.inputHandler=ad;T.focusChangeEffect=hd;T.perLineTextDirection=fd;T.exceptionSink=ld;T.updateListener=ia;T.editable=Xs;T.mouseSelectionStyle=od;T.dragMovesSelection=sd;T.clickAddsSelectionRange=nd;T.decorations=Yr;T.outerDecorations=dd;T.atomicRanges=$a;T.bidiIsolatedRanges=pd;T.scrollMargins=md;T.darkTheme=ma;T.cspNonce=A.define({combine:i=>i.length?i[0]:\"\"});T.contentAttributes=Ea;T.editorAttributes=ud;T.lineWrapping=T.contentAttributes.of({class:\"cm-lineWrapping\"});T.announce=M.define();var V0=4096,Ru={},Rs=class i{constructor(t,e,r,n,s,o){this.from=t,this.to=e,this.dir=r,this.isolates=n,this.fresh=s,this.order=o}static update(t,e){if(e.empty&&!t.some(s=>s.fresh))return t;let r=[],n=t.length?t[t.length-1].dir:G.LTR;for(let s=Math.max(0,t.length-10);s=0;n--){let s=r[n],o=typeof s==\"function\"?s(i):s;o&&Ul(o,e)}return e}var W0=Q.mac?\"mac\":Q.windows?\"win\":Q.linux?\"linux\":\"key\";function I0(i,t){let e=i.split(/-(?!$)/),r=e[e.length-1];r==\"Space\"&&(r=\" \");let n,s,o,l;for(let a=0;ar.concat(n),[]))),e}function qd(i,t,e){return Dd($d(i.state),t,i,e)}var Ie=null,Y0=4e3;function z0(i,t=W0){let e=Object.create(null),r=Object.create(null),n=(o,l)=>{let a=r[o];if(a==null)r[o]=l;else if(a!=l)throw new Error(\"Key binding \"+o+\" is used both as a regular binding and as a multi-stroke prefix\")},s=(o,l,a,h,f)=>{var c,u;let d=e[o]||(e[o]=Object.create(null)),m=l.split(/ (?!$)/).map(x=>I0(x,t));for(let x=1;x{let v=Ie={view:C,prefix:S,scope:o};return setTimeout(()=>{Ie==v&&(Ie=null)},Y0),!0}]})}let O=m.join(\" \");n(O,!1);let g=d[O]||(d[O]={preventDefault:!1,stopPropagation:!1,run:((u=(c=d._any)===null||c===void 0?void 0:c.run)===null||u===void 0?void 0:u.slice())||[]});a&&g.run.push(a),h&&(g.preventDefault=!0),f&&(g.stopPropagation=!0)};for(let o of i){let l=o.scope?o.scope.split(\" \"):[\"editor\"];if(o.any)for(let h of l){let f=e[h]||(e[h]=Object.create(null));f._any||(f._any={preventDefault:!1,stopPropagation:!1,run:[]});for(let c in f)f[c].run.push(o.any)}let a=o[t]||o.key;if(a)for(let h of l)s(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&s(h,\"Shift-\"+a,o.shift,o.preventDefault,o.stopPropagation)}return e}function Dd(i,t,e,r){let n=iu(t),s=dt(n,0),o=wt(s)==n.length&&n!=\" \",l=\"\",a=!1,h=!1,f=!1;Ie&&Ie.view==e&&Ie.scope==r&&(l=Ie.prefix+\" \",Sd.indexOf(t.keyCode)<0&&(h=!0,Ie=null));let c=new Set,u=g=>{if(g){for(let x of g.run)if(!c.has(x)&&(c.add(x),x(e,t)))return g.stopPropagation&&(f=!0),!0;g.preventDefault&&(g.stopPropagation&&(f=!0),h=!0)}return!1},d=i[r],m,O;return d&&(u(d[l+ms(n,t,!o)])?a=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(Q.windows&&t.ctrlKey&&t.altKey)&&(m=$e[t.keyCode])&&m!=n?(u(d[l+ms(m,t,!0)])||t.shiftKey&&(O=Vi[t.keyCode])!=n&&O!=m&&u(d[l+ms(O,t,!1)]))&&(a=!0):o&&t.shiftKey&&u(d[l+ms(n,t,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&f&&t.stopPropagation(),a}var zr=class i{constructor(t,e,r,n,s){this.className=t,this.left=e,this.top=r,this.width=n,this.height=s}draw(){let t=document.createElement(\"div\");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className!=this.className?!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,r){if(r.empty){let n=t.coordsAtPos(r.head,r.assoc||1);if(!n)return[];let s=Bd(t);return[new i(e,n.left-s.left,n.top-s.top,null,n.bottom-n.top)]}else return Z0(t,e,r)}};function Bd(i){let t=i.scrollDOM.getBoundingClientRect();return{left:(i.textDirection==G.LTR?t.left:t.right-i.scrollDOM.clientWidth*i.scaleX)-i.scrollDOM.scrollLeft*i.scaleX,top:t.top-i.scrollDOM.scrollTop*i.scaleY}}function $u(i,t,e){let r=b.cursor(t);return{from:Math.max(e.from,i.moveToLineBoundary(r,!1,!0).from),to:Math.min(e.to,i.moveToLineBoundary(r,!0,!0).from),type:Pt.Text}}function Z0(i,t,e){if(e.to<=i.viewport.from||e.from>=i.viewport.to)return[];let r=Math.max(e.from,i.viewport.from),n=Math.min(e.to,i.viewport.to),s=i.textDirection==G.LTR,o=i.contentDOM,l=o.getBoundingClientRect(),a=Bd(i),h=o.querySelector(\".cm-line\"),f=h&&window.getComputedStyle(h),c=l.left+(f?parseInt(f.paddingLeft)+Math.min(0,parseInt(f.textIndent)):0),u=l.right-(f?parseInt(f.paddingRight):0),d=na(i,r),m=na(i,n),O=d.type==Pt.Text?d:null,g=m.type==Pt.Text?m:null;if(O&&(i.lineWrapping||d.widgetLineBreaks)&&(O=$u(i,r,O)),g&&(i.lineWrapping||m.widgetLineBreaks)&&(g=$u(i,n,g)),O&&g&&O.from==g.from)return S(C(e.from,e.to,O));{let y=O?C(e.from,null,O):v(d,!1),k=g?C(null,e.to,g):v(m,!0),w=[];return(O||d).to<(g||m).from-(O&&g?1:0)||d.widgetLineBreaks>1&&y.bottom+i.defaultLineHeight/2D&&N.from=Rt)break;ct>nt&&B(Math.max(Ft,nt),y==null&&Ft<=D,Math.min(ct,Rt),k==null&&ct>=U,Bt.dir)}if(nt=Mt.to+1,nt>=Rt)break}return W.length==0&&B(D,y==null,U,k==null,i.textDirection),{top:q,bottom:L,horizontal:W}}function v(y,k){let w=l.top+(k?y.top:y.bottom);return{top:w,bottom:w,horizontal:[]}}}function F0(i,t){return i.constructor==t.constructor&&i.eq(t)}var Sa=class{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(bs)!=t.state.facet(bs)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}setOrder(t){let e=0,r=t.facet(bs);for(;e!F0(e,this.drawn[r]))){let e=this.dom.firstChild,r=0;for(let n of t)n.update&&e&&n.constructor&&this.drawn[r].constructor&&n.update(e,this.drawn[r])?(e=e.nextSibling,r++):this.dom.insertBefore(n.draw(),e);for(;e;){let n=e.nextSibling;e.remove(),e=n}this.drawn=t}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},bs=A.define();function Xd(i){return[ft.define(t=>new Sa(t,i)),bs.of(i)]}var Ld=!Q.ios,Zr=A.define({combine(i){return kt(i,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function Ls(i={}){return[Zr.of(i),_0,G0,H0,cd.of(!0)]}function Vd(i){return i.startState.facet(Zr)!=i.state.facet(Zr)}var _0=Xd({above:!0,markers(i){let{state:t}=i,e=t.facet(Zr),r=[];for(let n of t.selection.ranges){let s=n==t.selection.main;if(n.empty?!s||Ld:e.drawRangeCursor){let o=s?\"cm-cursor cm-cursor-primary\":\"cm-cursor cm-cursor-secondary\",l=n.empty?n:b.cursor(n.head,n.head>n.anchor?-1:1);for(let a of zr.forRange(i,o,l))r.push(a)}}return r},update(i,t){i.transactions.some(r=>r.selection)&&(t.style.animationName=t.style.animationName==\"cm-blink\"?\"cm-blink2\":\"cm-blink\");let e=Vd(i);return e&&qu(i.state,t),i.docChanged||i.selectionSet||e},mount(i,t){qu(t.state,i)},class:\"cm-cursorLayer\"});function qu(i,t){t.style.animationDuration=i.facet(Zr).cursorBlinkRate+\"ms\"}var G0=Xd({above:!1,markers(i){return i.state.selection.ranges.map(t=>t.empty?[]:zr.forRange(i,\"cm-selectionBackground\",t)).reduce((t,e)=>t.concat(e))},update(i,t){return i.docChanged||i.selectionSet||i.viewportChanged||Vd(i)},class:\"cm-selectionLayer\"}),wa={\".cm-line\":{\"& ::selection\":{backgroundColor:\"transparent !important\"},\"&::selection\":{backgroundColor:\"transparent !important\"}}};Ld&&(wa[\".cm-line\"].caretColor=\"transparent !important\",wa[\".cm-content\"]={caretColor:\"transparent !important\"});var H0=ie.highest(T.theme(wa)),Wd=M.define({map(i,t){return i==null?null:t.mapPos(i)}}),Qr=it.define({create(){return null},update(i,t){return i!=null&&(i=t.changes.mapPos(i)),t.effects.reduce((e,r)=>r.is(Wd)?r.value:e,i)}}),U0=ft.fromClass(class{constructor(i){this.view=i,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(i){var t;let e=i.state.field(Qr);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\"),(i.startState.field(Qr)!=e||i.docChanged||i.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:i}=this,t=i.state.field(Qr),e=t!=null&&i.coordsAtPos(t);if(!e)return null;let r=i.scrollDOM.getBoundingClientRect();return{left:e.left-r.left+i.scrollDOM.scrollLeft*i.scaleX,top:e.top-r.top+i.scrollDOM.scrollTop*i.scaleY,height:e.bottom-e.top}}drawCursor(i){if(this.cursor){let{scaleX:t,scaleY:e}=this.view;i?(this.cursor.style.left=i.left/t+\"px\",this.cursor.style.top=i.top/e+\"px\",this.cursor.style.height=i.height/e+\"px\"):this.cursor.style.left=\"-100000px\"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(i){this.view.state.field(Qr)!=i&&this.view.dispatch({effects:Wd.of(i)})}},{eventObservers:{dragover(i){this.setDropPos(this.view.posAtCoords({x:i.clientX,y:i.clientY}))},dragleave(i){(i.target==this.view.contentDOM||!this.view.contentDOM.contains(i.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Vs(){return[Qr,U0]}var Aw=/x/.unicode!=null?\"gu\":\"g\";var va=2e3;function j0(i,t,e){let r=Math.min(t.line,e.line),n=Math.max(t.line,e.line),s=[];if(t.off>va||e.off>va||t.col<0||e.col<0){let o=Math.min(t.off,e.off),l=Math.max(t.off,e.off);for(let a=r;a<=n;a++){let h=i.doc.line(a);h.length<=l&&s.push(b.range(h.from+o,h.to+l))}}else{let o=Math.min(t.col,e.col),l=Math.max(t.col,e.col);for(let a=r;a<=n;a++){let h=i.doc.line(a),f=os(h.text,o,i.tabSize,!0);if(f<0)s.push(b.cursor(h.to));else{let c=os(h.text,l,i.tabSize);s.push(b.range(h.from+f,h.from+c))}}}return s}function K0(i,t){let e=i.coordsAtPos(i.viewport.from);return e?Math.round(Math.abs((e.left-t)/i.defaultCharacterWidth)):-1}function Du(i,t){let e=i.posAtCoords({x:t.clientX,y:t.clientY},!1),r=i.state.doc.lineAt(e),n=e-r.from,s=n>va?-1:n==r.length?K0(i,t.clientX):We(r.text,i.state.tabSize,e-r.from);return{line:r.number,col:s,off:n}}function J0(i,t){let e=Du(i,t),r=i.state.selection;return e?{update(n){if(n.docChanged){let s=n.changes.mapPos(n.startState.doc.line(e.line).from),o=n.state.doc.lineAt(s);e={line:o.number,col:e.col,off:Math.min(e.off,o.length)},r=r.map(n.changes)}},get(n,s,o){let l=Du(i,n);if(!l)return r;let a=j0(i.state,e,l);return a.length?o?b.create(a.concat(r.ranges)):b.create(a):r}}:null}function qa(i){let t=i?.eventFilter||(e=>e.altKey&&e.button==0);return T.mouseSelectionStyle.of((e,r)=>t(r)?J0(e,r):null)}var tx={Alt:[18,i=>!!i.altKey],Control:[17,i=>!!i.ctrlKey],Shift:[16,i=>!!i.shiftKey],Meta:[91,i=>!!i.metaKey]},ex={style:\"cursor: crosshair\"};function Ws(i={}){let[t,e]=tx[i.key||\"Alt\"],r=ft.fromClass(class{constructor(n){this.view=n,this.isDown=!1}set(n){this.isDown!=n&&(this.isDown=n,this.view.update([]))}},{eventObservers:{keydown(n){this.set(n.keyCode==t||e(n))},keyup(n){(n.keyCode==t||!e(n))&&this.set(!1)},mousemove(n){this.set(e(n))}}});return[r,T.contentAttributes.of(n=>{var s;return!((s=n.plugin(r))===null||s===void 0)&&s.isDown?ex:null})]}var kr=\"-10000px\",Ms=class{constructor(t,e,r,n){this.facet=e,this.createTooltipView=r,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(o=>o);let s=null;this.tooltipViews=this.tooltips.map(o=>s=r(o,s))}update(t,e){var r;let n=t.state.facet(this.facet),s=n.filter(a=>a);if(n===this.input){for(let a of this.tooltipViews)a.update&&a.update(t);return!1}let o=[],l=e?[]:null;for(let a=0;ae[h]=a),e.length=l.length),this.input=n,this.tooltips=s,this.tooltipViews=o,!0}};function ix(i){let{win:t}=i;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}var Nl=A.define({combine:i=>{var t,e,r;return{position:Q.ios?\"absolute\":((t=i.find(n=>n.position))===null||t===void 0?void 0:t.position)||\"fixed\",parent:((e=i.find(n=>n.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((r=i.find(n=>n.tooltipSpace))===null||r===void 0?void 0:r.tooltipSpace)||ix}}}),Bu=new WeakMap,Da=ft.fromClass(class{constructor(i){this.view=i,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=i.state.facet(Nl);this.position=t.position,this.parent=t.parent,this.classes=i.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver==\"function\"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new Ms(i,Fr,(e,r)=>this.createTooltip(e,r),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(),i.win.addEventListener(\"resize\",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement(\"div\"),this.container.style.position=\"relative\",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let i of this.manager.tooltipViews)this.intersectionObserver.observe(i.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(i){i.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(i,this.above);t&&this.observeIntersection();let e=t||i.geometryChanged,r=i.state.facet(Nl);if(r.position!=this.position&&!this.madeAbsolute){this.position=r.position;for(let n of this.manager.tooltipViews)n.dom.style.position=this.position;e=!0}if(r.parent!=this.parent){this.parent&&this.container.remove(),this.parent=r.parent,this.createContainer();for(let n of this.manager.tooltipViews)this.container.appendChild(n.dom);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(i,t){let e=i.create(this.view),r=t?t.dom:null;if(e.dom.classList.add(\"cm-tooltip\"),i.arrow&&!e.dom.querySelector(\".cm-tooltip > .cm-tooltip-arrow\")){let n=document.createElement(\"div\");n.className=\"cm-tooltip-arrow\",e.dom.insertBefore(n,r)}return e.dom.style.position=this.position,e.dom.style.top=kr,e.dom.style.left=\"0px\",this.container.insertBefore(e.dom,r),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var i,t,e;this.view.win.removeEventListener(\"resize\",this.measureSoon);for(let r of this.manager.tooltipViews)r.dom.remove(),(i=r.destroy)===null||i===void 0||i.call(r);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 i=this.view.dom.getBoundingClientRect(),t=1,e=1,r=!1;if(this.position==\"fixed\"&&this.manager.tooltipViews.length){let{dom:n}=this.manager.tooltipViews[0];if(Q.gecko)r=n.offsetParent!=this.container.ownerDocument.body;else if(n.style.top==kr&&n.style.left==\"0px\"){let s=n.getBoundingClientRect();r=Math.abs(s.top+1e4)>1||Math.abs(s.left)>1}}if(r||this.position==\"absolute\")if(this.parent){let n=this.parent.getBoundingClientRect();n.width&&n.height&&(t=n.width/this.parent.offsetWidth,e=n.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);return{editor:i,parent:this.parent?this.container.getBoundingClientRect():i,pos:this.manager.tooltips.map((n,s)=>{let o=this.manager.tooltipViews[s];return o.getCoords?o.getCoords(n.pos):this.view.coordsAtPos(n.pos)}),size:this.manager.tooltipViews.map(({dom:n})=>n.getBoundingClientRect()),space:this.view.state.facet(Nl).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:r}}writeMeasure(i){var t;if(i.makeAbsolute){this.madeAbsolute=!0,this.position=\"absolute\";for(let l of this.manager.tooltipViews)l.dom.style.position=\"absolute\"}let{editor:e,space:r,scaleX:n,scaleY:s}=i,o=[];for(let l=0;l=Math.min(e.bottom,r.bottom)||c.rightMath.min(e.right,r.right)+.1){f.style.top=kr;continue}let d=a.arrow?h.dom.querySelector(\".cm-tooltip-arrow\"):null,m=d?7:0,O=u.right-u.left,g=(t=Bu.get(h))!==null&&t!==void 0?t:u.bottom-u.top,x=h.offset||nx,S=this.view.textDirection==G.LTR,C=u.width>r.right-r.left?S?r.left:r.right-u.width:S?Math.min(c.left-(d?14:0)+x.x,r.right-O):Math.max(r.left,c.left-O+(d?14:0)-x.x),v=this.above[l];!a.strictSide&&(v?c.top-(u.bottom-u.top)-x.yr.bottom)&&v==r.bottom-c.bottom>c.top-r.top&&(v=this.above[l]=!v);let y=(v?c.top-r.top:r.bottom-c.bottom)-m;if(yC&&q.topk&&(k=v?q.top-g-2-m:q.bottom+m+2);if(this.position==\"absolute\"?(f.style.top=(k-i.parent.top)/s+\"px\",f.style.left=(C-i.parent.left)/n+\"px\"):(f.style.top=k/s+\"px\",f.style.left=C/n+\"px\"),d){let q=c.left+(S?x.x:-x.x)-(C+14-7);d.style.left=q/n+\"px\"}h.overlap!==!0&&o.push({left:C,top:k,right:w,bottom:k+g}),f.classList.toggle(\"cm-tooltip-above\",v),f.classList.toggle(\"cm-tooltip-below\",!v),h.positioned&&h.positioned(i.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let i of this.manager.tooltipViews)i.dom.style.top=kr}},{eventObservers:{scroll(){this.maybeMeasure()}}}),rx=T.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\"}}}),nx={x:0,y:0},Fr=A.define({enables:[Da,rx]}),Es=A.define({combine:i=>i.reduce((t,e)=>t.concat(e),[])}),$s=class i{static create(t){return new i(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement(\"div\"),this.dom.classList.add(\"cm-tooltip-hover\"),this.manager=new Ms(t,Es,(e,r)=>this.createHostedView(e,r),e=>e.dom.remove())}createHostedView(t,e){let r=t.create(this.view);return r.dom.classList.add(\"cm-tooltip-section\"),this.dom.insertBefore(r.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&r.mount&&r.mount(this.view),r}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 r of this.manager.tooltipViews){let n=r[t];if(n!==void 0){if(e===void 0)e=n;else if(e!==n)return}}return e}get offset(){return this.passProp(\"offset\")}get getCoords(){return this.passProp(\"getCoords\")}get overlap(){return this.passProp(\"overlap\")}get resize(){return this.passProp(\"resize\")}},sx=Fr.compute([Es],i=>{let t=i.facet(Es);return t.length===0?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var r;return(r=e.end)!==null&&r!==void 0?r:e.pos})),create:$s.create,above:t[0].above,arrow:t.some(e=>e.arrow)}}),ka=class{constructor(t,e,r,n,s){this.view=t,this.source=e,this.field=r,this.setHover=n,this.hoverTime=s,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener(\"mouseleave\",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener(\"mousemove\",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;tl.bottom||e.xl.right+t.defaultCharacterWidth)return;let a=t.bidiSpans(t.state.doc.lineAt(n)).find(f=>f.from<=n&&f.to>=n),h=a&&a.dir==G.RTL?-1:1;s=e.x{this.pending==l&&(this.pending=null,a&&!(Array.isArray(a)&&!a.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(a)?a:[a])}))},a=>Ct(t.state,a,\"hover tooltip\"))}else o&&!(Array.isArray(o)&&!o.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let t=this.view.plugin(Da),e=t?t.manager.tooltips.findIndex(r=>r.create==$s.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,r;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:s}=this;if(n.length&&s&&!ox(s.dom,t)||this.pending){let{pos:o}=n[0]||this.pending,l=(r=(e=n[0])===null||e===void 0?void 0:e.end)!==null&&r!==void 0?r:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!lx(this.view,o,l,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:r}=this;r&&r.dom.contains(t.relatedTarget)?this.watchTooltipLeave(r.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=r=>{t.removeEventListener(\"mouseleave\",e),this.active.length&&!this.view.dom.contains(r.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)}},gs=4;function ox(i,t){let e=i.getBoundingClientRect();return t.clientX>=e.left-gs&&t.clientX<=e.right+gs&&t.clientY>=e.top-gs&&t.clientY<=e.bottom+gs}function lx(i,t,e,r,n,s){let o=i.scrollDOM.getBoundingClientRect(),l=i.documentTop+i.documentPadding.top+i.contentHeight;if(o.left>r||o.rightn||Math.min(o.bottom,l)=t&&a<=e}function Id(i,t={}){let e=M.define(),r=it.define({create(){return[]},update(n,s){if(n.length&&(t.hideOnChange&&(s.docChanged||s.selection)?n=[]:t.hideOn&&(n=n.filter(o=>!t.hideOn(s,o))),s.docChanged)){let o=[];for(let l of n){let a=s.changes.mapPos(l.pos,-1,ut.TrackDel);if(a!=null){let h=Object.assign(Object.create(null),l);h.pos=a,h.end!=null&&(h.end=s.changes.mapPos(h.end)),o.push(h)}}n=o}for(let o of s.effects)o.is(e)&&(n=o.value),o.is(ax)&&(n=[]);return n},provide:n=>Es.from(n)});return[r,ft.define(n=>new ka(n,i,r,e,t.hoverTime||300)),sx]}function Ba(i,t){let e=i.plugin(Da);if(!e)return null;let r=e.manager.tooltips.indexOf(t);return r<0?null:e.manager.tooltipViews[r]}var ax=M.define();var Xu=A.define({combine(i){let t,e;for(let r of i)t=t||r.topContainer,e=e||r.bottomContainer;return{topContainer:t,bottomContainer:e}}});function ci(i,t){let e=i.plugin(Nd),r=e?e.specs.indexOf(t):-1;return r>-1?e.panels[r]:null}var Nd=ft.fromClass(class{constructor(i){this.input=i.state.facet(fi),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(i));let t=i.state.facet(Xu);this.top=new Ni(i,!0,t.topContainer),this.bottom=new Ni(i,!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(i){let t=i.state.facet(Xu);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new Ni(i.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new Ni(i.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=i.state.facet(fi);if(e!=this.input){let r=e.filter(a=>a),n=[],s=[],o=[],l=[];for(let a of r){let h=this.specs.indexOf(a),f;h<0?(f=a(i.view),l.push(f)):(f=this.panels[h],f.update&&f.update(i)),n.push(f),(f.top?s:o).push(f)}this.specs=r,this.panels=n,this.top.sync(s),this.bottom.sync(o);for(let a of l)a.dom.classList.add(\"cm-panel\"),a.mount&&a.mount()}else for(let r of this.panels)r.update&&r.update(i)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:i=>T.scrollMargins.of(t=>{let e=t.plugin(i);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})}),Ni=class{constructor(t,e,r){this.view=t,this.top=e,this.container=r,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=Lu(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Lu(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 Lu(i){let t=i.nextSibling;return i.remove(),t}var fi=A.define({enables:Nd}),se=class extends ee{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}};se.prototype.elementClass=\"\";se.prototype.toDOM=void 0;se.prototype.mapMode=ut.TrackBefore;se.prototype.startSide=se.prototype.endSide=-1;se.prototype.point=!0;var Yl=A.define(),hx={class:\"\",renderEmptyElements:!1,elementStyle:\"\",markers:()=>_.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},Dr=A.define();function _r(i){return[Yd(),Dr.of(Object.assign(Object.assign({},hx),i))]}var Ta=A.define({combine:i=>i.some(t=>t)});function Yd(i){let t=[fx];return i&&i.fixed===!1&&t.push(Ta.of(!0)),t}var fx=ft.fromClass(class{constructor(i){this.view=i,this.prevViewport=i.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=i.state.facet(Dr).map(t=>new qs(i,t));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!i.state.facet(Ta),this.fixed&&(this.dom.style.position=\"sticky\"),this.syncGutters(!1),i.scrollDOM.insertBefore(this.dom,i.contentDOM)}update(i){if(this.updateGutters(i)){let t=this.prevViewport,e=i.view.viewport,r=Math.min(t.to,e.to)-Math.max(t.from,e.from);this.syncGutters(r<(e.to-e.from)*.8)}i.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+\"px\"),this.view.state.facet(Ta)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?\"sticky\":\"\"),this.prevViewport=i.view.viewport}syncGutters(i){let t=this.dom.nextSibling;i&&this.dom.remove();let e=_.iter(this.view.state.facet(Yl),this.view.viewport.from),r=[],n=this.gutters.map(s=>new Ca(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(s.type)){let o=!0;for(let l of s.type)if(l.type==Pt.Text&&o){Pa(e,r,l.from);for(let a of n)a.line(this.view,l,r);o=!1}else if(l.widget)for(let a of n)a.widget(this.view,l)}else if(s.type==Pt.Text){Pa(e,r,s.from);for(let o of n)o.line(this.view,s,r)}else if(s.widget)for(let o of n)o.widget(this.view,s);for(let s of n)s.finish();i&&this.view.scrollDOM.insertBefore(this.dom,t)}updateGutters(i){let t=i.startState.facet(Dr),e=i.state.facet(Dr),r=i.docChanged||i.heightChanged||i.viewportChanged||!_.eq(i.startState.facet(Yl),i.state.facet(Yl),i.view.viewport.from,i.view.viewport.to);if(t==e)for(let n of this.gutters)n.update(i)&&(r=!0);else{r=!0;let n=[];for(let s of e){let o=t.indexOf(s);o<0?n.push(new qs(this.view,s)):(this.gutters[o].update(i),n.push(this.gutters[o]))}for(let s of this.gutters)s.dom.remove(),n.indexOf(s)<0&&s.destroy();for(let s of n)this.dom.appendChild(s.dom);this.gutters=n}return r}destroy(){for(let i of this.gutters)i.destroy();this.dom.remove()}},{provide:i=>T.scrollMargins.of(t=>{let e=t.plugin(i);return!e||e.gutters.length==0||!e.fixed?null:t.textDirection==G.LTR?{left:e.dom.offsetWidth*t.scaleX}:{right:e.dom.offsetWidth*t.scaleX}})});function Vu(i){return Array.isArray(i)?i:[i]}function Pa(i,t,e){for(;i.value&&i.from<=e;)i.from==e&&t.push(i.value),i.next()}var Ca=class{constructor(t,e,r){this.gutter=t,this.height=r,this.i=0,this.cursor=_.iter(t.markers,e.from)}addElement(t,e,r){let{gutter:n}=this,s=(e.top-this.height)/t.scaleY,o=e.height/t.scaleY;if(this.i==n.elements.length){let l=new Ds(t,o,s,r);n.elements.push(l),n.dom.appendChild(l.dom)}else n.elements[this.i].update(t,o,s,r);this.height=e.bottom,this.i++}line(t,e,r){let n=[];Pa(this.cursor,n,e.from),r.length&&(n=n.concat(r));let s=this.gutter.config.lineMarker(t,e,n);s&&n.unshift(s);let o=this.gutter;n.length==0&&!o.config.renderEmptyElements||this.addElement(t,e,n)}widget(t,e){let r=this.gutter.config.widgetMarker(t,e.widget,e);r&&this.addElement(t,e,[r])}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}},qs=class{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 r in e.domEventHandlers)this.dom.addEventListener(r,n=>{let s=n.target,o;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let a=s.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=n.clientY;let l=t.lineBlockAtHeight(o-t.documentTop);e.domEventHandlers[r](t,l,n)&&n.preventDefault()});this.markers=Vu(e.markers(t)),e.initialSpacer&&(this.spacer=new Ds(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=Vu(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let n=this.config.updateSpacer(this.spacer.markers[0],t);n!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[n])}let r=t.view.viewport;return!_.eq(this.markers,e,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}},Ds=class{constructor(t,e,r,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement(\"div\"),this.dom.className=\"cm-gutterElement\",this.update(t,e,r,n)}update(t,e,r,n){this.height!=e&&(this.height=e,this.dom.style.height=e+\"px\"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+\"px\":\"\"),cx(this.markers,n)||this.setMarkers(t,n)}setMarkers(t,e){let r=\"cm-gutterElement\",n=this.dom.firstChild;for(let s=0,o=0;;){let l=o,a=ss(l,a,h)||o(l,a,h):o}return r}})}}),Br=class extends se{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}};function zl(i,t){return i.state.facet(Yi).formatNumber(t,i.state)}var dx=Dr.compute([Yi],i=>({class:\"cm-lineNumbers\",renderEmptyElements:!1,markers(t){return t.state.facet(ux)},lineMarker(t,e,r){return r.some(n=>n.toDOM)?null:new Br(zl(t,t.state.doc.lineAt(e.from).number))},widgetMarker:()=>null,lineMarkerChange:t=>t.startState.facet(Yi)!=t.state.facet(Yi),initialSpacer(t){return new Br(zl(t,Wu(t.state.doc.lines)))},updateSpacer(t,e){let r=zl(e.view,Wu(e.view.state.doc.lines));return r==t.number?t:new Br(r)},domEventHandlers:i.facet(Yi).domEventHandlers}));function ui(i={}){return[Yi.of(i),Yd(),dx]}function Wu(i){let t=9;for(;t{throw new Error(\"This node type doesn't define a deserialize function\")})}add(t){if(this.perNode)throw new RangeError(\"Can't add per-node props to node types\");return typeof t!=\"function\"&&(t=bt.match(t)),e=>{let r=t(e);return r===void 0?null:[this,r]}}};E.closedBy=new E({deserialize:i=>i.split(\" \")});E.openedBy=new E({deserialize:i=>i.split(\" \")});E.group=new E({deserialize:i=>i.split(\" \")});E.isolate=new E({deserialize:i=>{if(i&&i!=\"rtl\"&&i!=\"ltr\"&&i!=\"auto\")throw new RangeError(\"Invalid value for isolate: \"+i);return i||\"auto\"}});E.contextHash=new E({perNode:!0});E.lookAhead=new E({perNode:!0});E.mounted=new E({perNode:!0});var Fi=class{constructor(t,e,r){this.tree=t,this.overlay=e,this.parser=r}static get(t){return t&&t.props&&t.props[E.mounted.id]}},mx=Object.create(null),bt=class i{constructor(t,e,r,n=0){this.name=t,this.props=e,this.id=r,this.flags=n}static define(t){let e=t.props&&t.props.length?Object.create(null):mx,r=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),n=new i(t.name||\"\",e,t.id,r);if(t.props){for(let s of t.props)if(Array.isArray(s)||(s=s(n)),s){if(s[0].perNode)throw new RangeError(\"Can't store a per-node prop on a node type\");e[s[0].id]=s[1]}}return n}prop(t){return this.props[t.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(t){if(typeof t==\"string\"){if(this.name==t)return!0;let e=this.prop(E.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let r in t)for(let n of r.split(\" \"))e[n]=t[r];return r=>{for(let n=r.prop(E.group),s=-1;s<(n?n.length:0);s++){let o=e[s<0?r.name:n[s]];if(o)return o}}}};bt.none=new bt(\"\",Object.create(null),0,8);var Hr=class i{constructor(t){this.types=t;for(let e=0;e0;for(let a=this.cursor(o|st.IncludeAnonymous);;){let h=!1;if(a.from<=s&&a.to>=n&&(!l&&a.type.isAnonymous||e(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&r&&(l||!a.type.isAnonymous)&&r(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Ya(bt.none,this.children,this.positions,0,this.children.length,0,this.length,(e,r,n)=>new i(this.type,e,r,n,this.propValues),t.makeTree||((e,r,n)=>new i(bt.none,e,r,n)))}static build(t){return Ox(t)}};ot.empty=new ot(bt.none,[],[],0);var Xa=class i{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new i(this.buffer,this.index)}},_e=class i{constructor(t,e,r){this.buffer=t,this.length=e,this.set=r}get type(){return bt.none}toString(){let t=[];for(let e=0;e0));a=o[a+3]);return l}slice(t,e,r){let n=this.buffer,s=new Uint16Array(e-t),o=0;for(let l=t,a=0;l=t&&et;case 1:return e<=t&&r>t;case 2:return r>t;case 4:return!0}}function Ur(i,t,e,r){for(var n;i.from==i.to||(e<1?i.from>=t:i.from>t)||(e>-1?i.to<=t:i.to0?l.length:-1;t!=h;t+=e){let f=l[t],c=a[t]+o.from;if(_d(n,r,c,c+f.length)){if(f instanceof _e){if(s&st.ExcludeBuffers)continue;let u=f.findChild(0,f.buffer.length,e,r-c,n);if(u>-1)return new di(new Va(o,f,t,c),null,u)}else if(s&st.IncludeAnonymous||!f.type.isAnonymous||Na(f)){let u;if(!(s&st.IgnoreMounts)&&(u=Fi.get(f))&&!u.overlay)return new i(u.tree,c,t,o);let d=new i(f,c,t,o);return s&st.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(e<0?f.children.length-1:0,e,r,n)}}}if(s&st.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+e:t=e<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,r=0){let n;if(!(r&st.IgnoreOverlays)&&(n=Fi.get(this._tree))&&n.overlay){let s=t-this.from;for(let{from:o,to:l}of n.overlay)if((e>0?o<=s:o=s:l>s))return new i(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,r)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function Zd(i,t,e,r){let n=i.cursor(),s=[];if(!n.firstChild())return s;if(e!=null){for(let o=!1;!o;)if(o=n.type.is(e),!n.nextSibling())return s}for(;;){if(r!=null&&n.type.is(r))return s;if(n.type.is(t)&&s.push(n.node),!n.nextSibling())return r==null?s:[]}}function La(i,t,e=t.length-1){for(let r=i.parent;e>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[e]&&t[e]!=r.name)return!1;e--}}return!0}var Va=class{constructor(t,e,r,n){this.parent=t,this.buffer=e,this.index=r,this.start=n}},di=class i extends Ys{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,r){super(),this.context=t,this._parent=e,this.index=r,this.type=t.buffer.set.types[t.buffer.buffer[r]]}child(t,e,r){let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.context.start,r);return s<0?null:new i(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,r=0){if(r&st.ExcludeBuffers)return null;let{buffer:n}=this.context,s=n.findChild(this.index+4,n.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return s<0?null:new i(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new i(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new i(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:r}=this.context,n=this.index+4,s=r.buffer[this.index+3];if(s>n){let o=r.buffer[this.index+1];t.push(r.slice(n,s,o)),e.push(0)}return new ot(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function Gd(i){if(!i.length)return null;let t=0,e=i[0];for(let s=1;se.from||o.to=t){let l=new jt(o.tree,o.overlay[0].from+s.from,-1,s);(n||(n=[r])).push(Ur(l,t,e,!1))}}return n?Gd(n):r}var jr=class{get name(){return this.type.name}constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof jt)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let r=t._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:r,buffer:n}=this.buffer;return this.type=e||n.set.types[n.buffer[t]],this.from=r+n.buffer[t+1],this.to=r+n.buffer[t+2],!0}yield(t){return t?t instanceof jt?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,r){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,r,this.mode));let{buffer:n}=this.buffer,s=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.buffer.start,r);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,r=this.mode){return this.buffer?r&st.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&st.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&st.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,r=this.stack.length-1;if(t<0){let n=r<0?0:this.stack[r]+4;if(this.index!=n)return this.yieldBuf(e.findChild(n,this.index,-1,0,4))}else{let n=e.buffer[this.index+3];if(n<(r<0?e.buffer.length:e.buffer[this.stack[r]+3]))return this.yieldBuf(n)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,r,{buffer:n}=this;if(n){if(t>0){if(this.index-1)for(let s=e+t,o=t<0?-1:r._tree.children.length;s!=o;s+=t){let l=r._tree.children[s];if(this.mode&st.IncludeAnonymous||l instanceof _e||!l.type.isAnonymous||Na(l))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to=0;){for(let o=t;o;o=o._parent)if(o.index==n){if(n==this.index)return o;e=o,r=s+1;break t}n=this.stack[--s]}for(let n=r;n=0;s--){if(s<0)return La(this.node,t,n);let o=r[e.buffer[this.stack[s]]];if(!o.isAnonymous){if(t[n]&&t[n]!=o.name)return!1;n--}}return!0}};function Na(i){return i.children.some(t=>t instanceof _e||!t.type.isAnonymous||Na(t))}function Ox(i){var t;let{buffer:e,nodeSet:r,maxBufferLength:n=1024,reused:s=[],minRepeatType:o=r.types.length}=i,l=Array.isArray(e)?new Xa(e,e.length):e,a=r.types,h=0,f=0;function c(y,k,w,q,L,W){let{id:B,start:D,end:U,size:N}=l,nt=f;for(;N<0;)if(l.next(),N==-1){let ct=s[B];w.push(ct),q.push(D-y);return}else if(N==-3){h=B;return}else if(N==-4){f=B;return}else throw new RangeError(`Unrecognized record size: ${N}`);let Rt=a[B],Mt,Bt,Ft=D-y;if(U-D<=n&&(Bt=g(l.pos-k,L))){let ct=new Uint16Array(Bt.size-Bt.skip),_t=l.pos-Bt.size,de=ct.length;for(;l.pos>_t;)de=x(Bt.start,ct,de);Mt=new _e(ct,U-Bt.start,r),Ft=Bt.start-y}else{let ct=l.pos-N;l.next();let _t=[],de=[],ri=B>=o?B:-1,Ei=0,Un=U;for(;l.pos>ct;)ri>=0&&l.id==ri&&l.size>=0?(l.end<=Un-n&&(m(_t,de,D,Ei,l.end,Un,ri,nt),Ei=_t.length,Un=l.end),l.next()):W>2500?u(D,ct,_t,de):c(D,ct,_t,de,ri,W+1);if(ri>=0&&Ei>0&&Ei<_t.length&&m(_t,de,D,Ei,D,Un,ri,nt),_t.reverse(),de.reverse(),ri>-1&&Ei>0){let Mc=d(Rt);Mt=Ya(Rt,_t,de,0,_t.length,0,U-D,Mc,Mc)}else Mt=O(Rt,_t,de,U-D,nt-U)}w.push(Mt),q.push(Ft)}function u(y,k,w,q){let L=[],W=0,B=-1;for(;l.pos>k;){let{id:D,start:U,end:N,size:nt}=l;if(nt>4)l.next();else{if(B>-1&&U=0;N-=3)D[nt++]=L[N],D[nt++]=L[N+1]-U,D[nt++]=L[N+2]-U,D[nt++]=nt;w.push(new _e(D,L[2]-U,r)),q.push(U-y)}}function d(y){return(k,w,q)=>{let L=0,W=k.length-1,B,D;if(W>=0&&(B=k[W])instanceof ot){if(!W&&B.type==y&&B.length==q)return B;(D=B.prop(E.lookAhead))&&(L=w[W]+B.length+D)}return O(y,k,w,q,L)}}function m(y,k,w,q,L,W,B,D){let U=[],N=[];for(;y.length>q;)U.push(y.pop()),N.push(k.pop()+w-L);y.push(O(r.types[B],U,N,W-L,D-W)),k.push(L-w)}function O(y,k,w,q,L=0,W){if(h){let B=[E.contextHash,h];W=W?[B].concat(W):[B]}if(L>25){let B=[E.lookAhead,L];W=W?[B].concat(W):[B]}return new ot(y,k,w,q,W)}function g(y,k){let w=l.fork(),q=0,L=0,W=0,B=w.end-n,D={size:0,start:0,skip:0};t:for(let U=w.pos-y;w.pos>U;){let N=w.size;if(w.id==k&&N>=0){D.size=q,D.start=L,D.skip=W,W+=4,q+=4,w.next();continue}let nt=w.pos-N;if(N<0||nt=o?4:0,Mt=w.start;for(w.next();w.pos>nt;){if(w.size<0)if(w.size==-3)Rt+=4;else break t;else w.id>=o&&(Rt+=4);w.next()}L=Mt,q+=N,W+=Rt}return(k<0||q==y)&&(D.size=q,D.start=L,D.skip=W),D.size>4?D:void 0}function x(y,k,w){let{id:q,start:L,end:W,size:B}=l;if(l.next(),B>=0&&q4){let U=l.pos-(B-4);for(;l.pos>U;)w=x(y,k,w)}k[--w]=D,k[--w]=W-y,k[--w]=L-y,k[--w]=q}else B==-3?h=q:B==-4&&(f=q);return w}let S=[],C=[];for(;l.pos>0;)c(i.start||0,i.bufferStart||0,S,C,-1,0);let v=(t=i.length)!==null&&t!==void 0?t:S.length?C[0]+S[0].length:0;return new ot(a[i.topID],S.reverse(),C.reverse(),v)}var Fd=new WeakMap;function Ns(i,t){if(!i.isAnonymous||t instanceof _e||t.type!=i)return 1;let e=Fd.get(t);if(e==null){e=1;for(let r of t.children){if(r.type!=i||!(r instanceof ot)){e=1;break}e+=Ns(i,r)}Fd.set(t,e)}return e}function Ya(i,t,e,r,n,s,o,l,a){let h=0;for(let m=r;m=f)break;k+=w}if(C==v+1){if(k>f){let w=m[v];d(w.children,w.positions,0,w.children.length,O[v]+S);continue}c.push(m[v])}else{let w=O[C-1]+m[C-1].length-y;c.push(Ya(i,m,O,v,C,y,w,null,a))}u.push(y+S-s)}}return d(t,e,r,n,0),(l||a)(c,u,o)}var zs=class{constructor(){this.map=new WeakMap}setBuffer(t,e,r){let n=this.map.get(t);n||this.map.set(t,n=new Map),n.set(e,r)}getBuffer(t,e){let r=this.map.get(t);return r&&r.get(e)}set(t,e){t instanceof di?this.setBuffer(t.context.buffer,t.index,e):t instanceof jt&&this.map.set(t.tree,e)}get(t){return t instanceof di?this.getBuffer(t.context.buffer,t.index):t instanceof jt?this.map.get(t.tree):void 0}cursorSet(t,e){t.buffer?this.setBuffer(t.buffer.buffer,t.index,e):this.map.set(t.tree,e)}cursorGet(t){return t.buffer?this.getBuffer(t.buffer.buffer,t.index):this.map.get(t.tree)}},pi=class i{constructor(t,e,r,n,s=!1,o=!1){this.from=t,this.to=e,this.tree=r,this.offset=n,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,e=[],r=!1){let n=[new i(0,t.length,t,0,!1,r)];for(let s of e)s.to>t.length&&n.push(s);return n}static applyChanges(t,e,r=128){if(!e.length)return t;let n=[],s=1,o=t.length?t[0]:null;for(let l=0,a=0,h=0;;l++){let f=l=r)for(;o&&o.from=u.from||c<=u.to||h){let d=Math.max(u.from,a)-h,m=Math.min(u.to,c)-h;u=d>=m?null:new i(d,m,u.tree,u.offset+h,l>0,!!f)}if(u&&n.push(u),o.to>c)break;o=snew Gr(n.from,n.to)):[new Gr(0,0)]:[new Gr(0,t.length)],this.createParse(t,e||[],r)}parse(t,e,r){let n=this.startParse(t,e,r);for(;;){let s=n.advance();if(s)return s}}},Ia=class{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}};var Dw=new E({perNode:!0});var xx=0,we=class i{constructor(t,e,r){this.set=t,this.base=e,this.modified=r,this.id=xx++}static define(t){if(t?.base)throw new Error(\"Can not derive from a modified tag\");let e=new i([],null,[]);if(e.set.push(e),t)for(let r of t.set)e.set.push(r);return e}static defineModifier(){let t=new Gs;return e=>e.modified.indexOf(t)>-1?e:Gs.get(e.base||e,e.modified.concat(t).sort((r,n)=>r.id-n.id))}},yx=0,Gs=class i{constructor(){this.instances=[],this.id=yx++}static get(t,e){if(!e.length)return t;let r=e[0].instances.find(l=>l.base==t&&bx(e,l.modified));if(r)return r;let n=[],s=new we(n,t,e);for(let l of e)l.instances.push(s);let o=Sx(e);for(let l of t.set)if(!l.modified.length)for(let a of o)n.push(i.get(l,a));return s}};function bx(i,t){return i.length==t.length&&i.every((e,r)=>e==t[r])}function Sx(i){let t=[[]];for(let e=0;er.length-e.length)}function Hs(i){let t=Object.create(null);for(let e in i){let r=i[e];Array.isArray(r)||(r=[r]);for(let n of e.split(\" \"))if(n){let s=[],o=2,l=n;for(let c=0;;){if(l==\"...\"&&c>0&&c+3==n.length){o=1;break}let u=/^\"(?:[^\"\\\\]|\\\\.)*?\"|[^\\/!]+/.exec(l);if(!u)throw new RangeError(\"Invalid path: \"+n);if(s.push(u[0]==\"*\"?\"\":u[0][0]=='\"'?JSON.parse(u[0]):u[0]),c+=u[0].length,c==n.length)break;let d=n[c++];if(c==n.length&&d==\"!\"){o=0;break}if(d!=\"/\")throw new RangeError(\"Invalid path: \"+n);l=n.slice(c)}let a=s.length-1,h=s[a];if(!h)throw new RangeError(\"Invalid path: \"+n);let f=new Gi(r,o,a>0?s.slice(0,a):null);t[h]=f.sort(t[h])}}return jd.add(t)}var jd=new E,Gi=class{constructor(t,e,r,n){this.tags=t,this.mode=e,this.context=r,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth{let o=n;for(let l of s)for(let a of l.set){let h=e[a.id];if(h){o=o?o+\" \"+h:h;break}}return o},scope:r}}function wx(i,t){let e=null;for(let r of i){let n=r.style(t);n&&(e=e?e+\" \"+n:n)}return e}function Kd(i,t,e,r=0,n=i.length){let s=new Za(r,Array.isArray(t)?t:[t],e);s.highlightRange(i.cursor(),r,n,\"\",s.highlighters),s.flush(n)}var Za=class{constructor(t,e,r){this.at=t,this.highlighters=e,this.span=r,this.class=\"\"}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,r,n,s){let{type:o,from:l,to:a}=t;if(l>=r||a<=e)return;o.isTop&&(s=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=n,f=vx(t)||Gi.empty,c=wx(s,f.tags);if(c&&(h&&(h+=\" \"),h+=c,f.mode==1&&(n+=(n?\" \":\"\")+c)),this.startSpan(Math.max(e,l),h),f.opaque)return;let u=t.tree&&t.tree.prop(E.mounted);if(u&&u.overlay){let d=t.node.enter(u.overlay[0].from+l,1),m=this.highlighters.filter(g=>!g.scope||g.scope(u.tree.type)),O=t.firstChild();for(let g=0,x=l;;g++){let S=g=C||!t.nextSibling())););if(!S||C>r)break;x=S.to+l,x>e&&(this.highlightRange(d.cursor(),Math.max(e,S.from+l),Math.min(r,x),\"\",m),this.startSpan(Math.min(r,x),h))}O&&t.parent()}else if(t.firstChild()){u&&(n=\"\");do if(!(t.to<=e)){if(t.from>=r)break;this.highlightRange(t,e,r,n,s),this.startSpan(Math.min(r,t.to),h)}while(t.nextSibling());t.parent()}}};function vx(i){let t=i.type.prop(jd);for(;t&&t.context&&!i.matchContext(t.context);)t=t.next;return t||null}var P=we.define,Zs=P(),Ge=P(),Hd=P(Ge),Ud=P(Ge),He=P(),Fs=P(He),za=P(He),Se=P(),mi=P(Se),ye=P(),be=P(),Fa=P(),Kr=P(Fa),_s=P(),p={comment:Zs,lineComment:P(Zs),blockComment:P(Zs),docComment:P(Zs),name:Ge,variableName:P(Ge),typeName:Hd,tagName:P(Hd),propertyName:Ud,attributeName:P(Ud),className:P(Ge),labelName:P(Ge),namespace:P(Ge),macroName:P(Ge),literal:He,string:Fs,docString:P(Fs),character:P(Fs),attributeValue:P(Fs),number:za,integer:P(za),float:P(za),bool:P(He),regexp:P(He),escape:P(He),color:P(He),url:P(He),keyword:ye,self:P(ye),null:P(ye),atom:P(ye),unit:P(ye),modifier:P(ye),operatorKeyword:P(ye),controlKeyword:P(ye),definitionKeyword:P(ye),moduleKeyword:P(ye),operator:be,derefOperator:P(be),arithmeticOperator:P(be),logicOperator:P(be),bitwiseOperator:P(be),compareOperator:P(be),updateOperator:P(be),definitionOperator:P(be),typeOperator:P(be),controlOperator:P(be),punctuation:Fa,separator:P(Fa),bracket:Kr,angleBracket:P(Kr),squareBracket:P(Kr),paren:P(Kr),brace:P(Kr),content:Se,heading:mi,heading1:P(mi),heading2:P(mi),heading3:P(mi),heading4:P(mi),heading5:P(mi),heading6:P(mi),contentSeparator:P(Se),list:P(Se),quote:P(Se),emphasis:P(Se),strong:P(Se),link:P(Se),monospace:P(Se),strikethrough:P(Se),inserted:P(),deleted:P(),changed:P(),invalid:P(),meta:_s,documentMeta:P(_s),annotation:P(_s),processingInstruction:P(_s),definition:we.defineModifier(),constant:we.defineModifier(),function:we.defineModifier(),standard:we.defineModifier(),local:we.defineModifier(),special:we.defineModifier()},Lw=_a([{tag:p.link,class:\"tok-link\"},{tag:p.heading,class:\"tok-heading\"},{tag:p.emphasis,class:\"tok-emphasis\"},{tag:p.strong,class:\"tok-strong\"},{tag:p.keyword,class:\"tok-keyword\"},{tag:p.atom,class:\"tok-atom\"},{tag:p.bool,class:\"tok-bool\"},{tag:p.url,class:\"tok-url\"},{tag:p.labelName,class:\"tok-labelName\"},{tag:p.inserted,class:\"tok-inserted\"},{tag:p.deleted,class:\"tok-deleted\"},{tag:p.literal,class:\"tok-literal\"},{tag:p.string,class:\"tok-string\"},{tag:p.number,class:\"tok-number\"},{tag:[p.regexp,p.escape,p.special(p.string)],class:\"tok-string2\"},{tag:p.variableName,class:\"tok-variableName\"},{tag:p.local(p.variableName),class:\"tok-variableName tok-local\"},{tag:p.definition(p.variableName),class:\"tok-variableName tok-definition\"},{tag:p.special(p.variableName),class:\"tok-variableName2\"},{tag:p.definition(p.propertyName),class:\"tok-propertyName tok-definition\"},{tag:p.typeName,class:\"tok-typeName\"},{tag:p.namespace,class:\"tok-namespace\"},{tag:p.className,class:\"tok-className\"},{tag:p.macroName,class:\"tok-macroName\"},{tag:p.propertyName,class:\"tok-propertyName\"},{tag:p.operator,class:\"tok-operator\"},{tag:p.comment,class:\"tok-comment\"},{tag:p.meta,class:\"tok-meta\"},{tag:p.invalid,class:\"tok-invalid\"},{tag:p.punctuation,class:\"tok-punctuation\"}]);var Ga,Hi=new E;function kx(i){return A.define({combine:i?t=>t.concat(i):void 0})}var Tx=new E,Wt=class{constructor(t,e,r=[],n=\"\"){this.data=t,this.name=n,Y.prototype.hasOwnProperty(\"tree\")||Object.defineProperty(Y.prototype,\"tree\",{get(){return pt(this)}}),this.parser=e,this.extension=[Ui.of(this),Y.languageData.of((s,o,l)=>{let a=Jd(s,o,l),h=a.type.prop(Hi);if(!h)return[];let f=s.facet(h),c=a.type.prop(Tx);if(c){let u=a.resolve(o-a.from,l);for(let d of c)if(d.test(u,s)){let m=s.facet(d.facet);return d.type==\"replace\"?m:m.concat(f)}}return f})].concat(r)}isActiveAt(t,e,r=-1){return Jd(t,e,r).type.prop(Hi)==this.data}findRegions(t){let e=t.facet(Ui);if(e?.data==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let r=[],n=(s,o)=>{if(s.prop(Hi)==this.data){r.push({from:o,to:o+s.length});return}let l=s.prop(E.mounted);if(l){if(l.tree.prop(Hi)==this.data){if(l.overlay)for(let a of l.overlay)r.push({from:a.from+o,to:a.to+o});else r.push({from:o,to:o+s.length});return}else if(l.overlay){let a=r.length;if(n(l.tree,l.overlay[0].from+o),r.length>a)return}}for(let a=0;ar.isTop?e:void 0)]}),t.name)}configure(t,e){return new i(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}};function pt(i){let t=i.field(Wt.state,!1);return t?t.tree:ot.empty}var Ka=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 r=this.cursorPos-this.string.length;return t=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-r,e-r)}},Jr=null,Ja=class i{constructor(t,e,r=[],n,s,o,l,a){this.parser=t,this.state=e,this.fragments=r,this.tree=n,this.treeLen=s,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(t,e,r){return new i(t,e,[],ot.empty,0,r,[],null)}startParse(){return this.parser.startParse(new Ka(this.state.doc),this.fragments)}work(t,e){return e!=null&&e>=this.state.doc.length&&(e=void 0),this.tree!=ot.empty&&this.isDone(e??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof t==\"number\"){let n=Date.now()+t;t=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),e!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&e=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(pi.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Jr;Jr=this;try{return t()}finally{Jr=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=tp(t,e.from,e.to);return t}changes(t,e){let{fragments:r,tree:n,treeLen:s,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let a=[];if(t.iterChangedRanges((h,f,c,u)=>a.push({fromA:h,toA:f,fromB:c,toB:u})),r=pi.applyChanges(r,a),n=ot.empty,s=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let f=t.mapPos(h.from,1),c=t.mapPos(h.to,-1);ft.from&&(this.fragments=tp(this.fragments,n,s),this.skipped.splice(r--,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 _i{createParse(e,r,n){let s=n[0].from,o=n[n.length-1].to;return{parsedPos:s,advance(){let a=Jr;if(a){for(let h of n)a.tempSkipped.push(h);t&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,t]):t)}return this.parsedPos=o,new ot(bt.none,[],[],o-s)},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 Jr}};function tp(i,t,e){return pi.applyChanges(i,[{fromA:t,toA:e,fromB:t,toB:e}])}var tn=class i{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),r=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,r)||e.takeTree(),new i(e)}static init(t){let e=Math.min(3e3,t.doc.length),r=Ja.create(t.facet(Ui).parser,t,{from:0,to:e});return r.work(20,e)||r.takeTree(),new i(r)}};Wt.state=it.define({create:tn.init,update(i,t){for(let e of t.effects)if(e.is(Wt.setState))return e.value;return t.startState.facet(Ui)!=t.state.facet(Ui)?tn.init(t.state):i.apply(t)}});var sp=i=>{let t=setTimeout(()=>i(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<\"u\"&&(sp=i=>{let t=-1,e=setTimeout(()=>{t=requestIdleCallback(i,{timeout:400})},100);return()=>t<0?clearTimeout(e):cancelIdleCallback(t)});var Ha=typeof navigator<\"u\"&&(!((Ga=navigator.scheduling)===null||Ga===void 0)&&Ga.isInputPending)?()=>navigator.scheduling.isInputPending():null,Px=ft.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(Wt.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(Wt.state);(e.tree!=e.context.tree||!e.context.isDone(t.doc.length))&&(this.working=sp(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEndn+1e3,a=s.context.work(()=>Ha&&Ha()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-e,(a||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Wt.setState.of(new tn(s.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(e=>Ct(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()}}}),Ui=A.define({combine(i){return i.length?i[0]:null},enables:i=>[Wt.state,Px,T.contentAttributes.compute([i],t=>{let e=t.facet(i);return e&&e.name?{\"data-language\":e.name}:{}})]}),js=class{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}};var Cx=A.define(),ke=A.define({combine:i=>{if(!i.length)return\" \";let t=i[0];if(!t||/\\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw new Error(\"Invalid indent unit: \"+JSON.stringify(i[0]));return t}});function en(i){let t=i.facet(ke);return t.charCodeAt(0)==9?i.tabSize*t.length:t.length}function rn(i,t){let e=\"\",r=i.tabSize,n=i.facet(ke)[0];if(n==\"\t\"){for(;t>=r;)e+=\"\t\",t-=r;n=\" \"}for(let s=0;s=t?Ax(i,e,t):null}var gi=class{constructor(t,e={}){this.state=t,this.options=e,this.unit=en(t)}lineAt(t,e=1){let r=this.state.doc.lineAt(t),{simulateBreak:n,simulateDoubleBreak:s}=this.options;return n!=null&&n>=r.from&&n<=r.to?s&&n==t?{text:\"\",from:t}:(e<0?n-1&&(s+=o-this.countColumn(r,r.search(/\\S|$/))),s}countColumn(t,e=t.length){return We(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:r,from:n}=this.lineAt(t,e),s=this.options.overrideIndentation;if(s){let o=s(n);if(o>-1)return o}return this.countColumn(r,r.search(/\\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},lh=new E;function Ax(i,t,e){let r=t.resolveStack(e),n=r.node.enterUnfinishedNodesBefore(e);if(n!=r.node){let s=[];for(let o=n;o!=r.node;o=o.parent)s.push(o);for(let o=s.length-1;o>=0;o--)r={node:s[o],next:r}}return op(r,i,e)}function op(i,t,e){for(let r=i;r;r=r.next){let n=Rx(r.node);if(n)return n(th.create(t,e,r))}return 0}function Qx(i){return i.pos==i.options.simulateBreak&&i.options.simulateDoubleBreak}function Rx(i){let t=i.type.prop(lh);if(t)return t;let e=i.firstChild,r;if(e&&(r=e.type.prop(E.closedBy))){let n=i.lastChild,s=n&&r.indexOf(n.name)>-1;return o=>lp(o,!0,1,void 0,s&&!Qx(o)?n.from:void 0)}return i.parent==null?Mx:null}function Mx(){return 0}var th=class i extends gi{constructor(t,e,r){super(t.state,t.options),this.base=t,this.pos=e,this.context=r}get node(){return this.context.node}static create(t,e,r){return new i(t,e,r)}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 r=t.resolve(e.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(Ex(r,t))break;e=this.state.doc.lineAt(r.from)}return this.lineIndent(e.from)}continue(){return op(this.context.next,this.base,this.pos)}};function Ex(i,t){for(let e=t;e;e=e.parent)if(i==e)return!0;return!1}function $x(i){let t=i.node,e=t.childAfter(t.from),r=t.lastChild;if(!e)return null;let n=i.options.simulateBreak,s=i.state.doc.lineAt(e.from),o=n==null||n<=s.from?s.to:Math.min(s.to,n);for(let l=e.to;;){let a=t.childAfter(l);if(!a||a==r)return null;if(!a.type.isSkipped)return a.fromlp(r,t,e,i)}function lp(i,t,e,r,n){let s=i.textAfter,o=s.match(/^\\s*/)[0].length,l=r&&s.slice(o,o+r.length)==r||n==i.pos+o,a=t?$x(i):null;return a?l?i.column(a.from):i.column(a.to):i.baseIndent+(l?0:i.unit*e)}var qx=A.define(),ah=new E;function ap(i){let t=i.firstChild,e=i.lastChild;return t&&t.toe)continue;if(s&&l.from=t&&h.to>e&&(s=h)}}return s}function Bx(i){let t=i.lastChild;return t&&t.to==i.to&&t.type.isError}function hp(i,t,e){for(let r of i.facet(qx)){let n=r(i,t,e);if(n)return n}return Dx(i,t,e)}function fp(i,t){let e=t.mapPos(i.from,1),r=t.mapPos(i.to,-1);return e>=r?void 0:{from:e,to:r}}var hh=M.define({map:fp}),Js=M.define({map:fp});function cp(i){let t=[];for(let{head:e}of i.state.selection.ranges)t.some(r=>r.from<=e&&r.to>=e)||t.push(i.lineBlockAt(e));return t}var nn=it.define({create(){return R.none},update(i,t){i=i.map(t.changes);for(let e of t.effects)if(e.is(hh)&&!Xx(i,e.value.from,e.value.to)){let{preparePlaceholder:r}=t.state.facet(fh),n=r?R.replace({widget:new eh(r(t.state,e.value))}):ep;i=i.update({add:[n.range(e.value.from,e.value.to)]})}else e.is(Js)&&(i=i.update({filter:(r,n)=>e.value.from!=r||e.value.to!=n,filterFrom:e.value.from,filterTo:e.value.to}));if(t.selection){let e=!1,{head:r}=t.selection.main;i.between(r,r,(n,s)=>{nr&&(e=!0)}),e&&(i=i.update({filterFrom:r,filterTo:r,filter:(n,s)=>s<=r||n>=r}))}return i},provide:i=>T.decorations.from(i),toJSON(i,t){let e=[];return i.between(0,t.doc.length,(r,n)=>{e.push(r,n)}),e},fromJSON(i){if(!Array.isArray(i)||i.length%2)throw new RangeError(\"Invalid JSON for fold state\");let t=[];for(let e=0;e{(!n||n.from>s)&&(n={from:s,to:o})}),n}function Xx(i,t,e){let r=!1;return i.between(t,t,(n,s)=>{n==t&&s==e&&(r=!0)}),r}function dp(i,t){return i.field(nn,!1)?t:t.concat(M.appendConfig.of(Yx()))}var Lx=i=>{for(let t of cp(i)){let e=hp(i.state,t.from,t.to);if(e)return i.dispatch({effects:dp(i.state,[hh.of(e),pp(i,e)])}),!0}return!1},Vx=i=>{if(!i.state.field(nn,!1))return!1;let t=[];for(let e of cp(i)){let r=up(i.state,e.from,e.to);r&&t.push(Js.of(r),pp(i,r,!1))}return t.length&&i.dispatch({effects:t}),t.length>0};function pp(i,t,e=!0){let r=i.state.doc.lineAt(t.from).number,n=i.state.doc.lineAt(t.to).number;return T.announce.of(`${i.state.phrase(e?\"Folded lines\":\"Unfolded lines\")} ${r} ${i.state.phrase(\"to\")} ${n}.`)}var Wx=i=>{let{state:t}=i,e=[];for(let r=0;r{let t=i.state.field(nn,!1);if(!t||!t.size)return!1;let e=[];return t.between(0,i.state.doc.length,(r,n)=>{e.push(Js.of({from:r,to:n}))}),i.dispatch({effects:e}),!0};var to=[{key:\"Ctrl-Shift-[\",mac:\"Cmd-Alt-[\",run:Lx},{key:\"Ctrl-Shift-]\",mac:\"Cmd-Alt-]\",run:Vx},{key:\"Ctrl-Alt-[\",run:Wx},{key:\"Ctrl-Alt-]\",run:Ix}],Nx={placeholderDOM:null,preparePlaceholder:null,placeholderText:\"\\u2026\"},fh=A.define({combine(i){return kt(i,Nx)}});function Yx(i){let t=[nn,zx];return i&&t.push(fh.of(i)),t}function mp(i,t){let{state:e}=i,r=e.facet(fh),n=o=>{let l=i.lineBlockAt(i.posAtDOM(o.target)),a=up(i.state,l.from,l.to);a&&i.dispatch({effects:Js.of(a)}),o.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(i,n,t);let s=document.createElement(\"span\");return s.textContent=r.placeholderText,s.setAttribute(\"aria-label\",e.phrase(\"folded code\")),s.title=e.phrase(\"unfold\"),s.className=\"cm-foldPlaceholder\",s.onclick=n,s}var ep=R.replace({widget:new class extends Ut{toDOM(i){return mp(i,null)}}}),eh=class extends Ut{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return mp(t,this.value)}};var zx=T.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\"}}),ve=class i{constructor(t,e){this.specs=t;let r;function n(l){let a=Gt.newName();return(r||(r=Object.create(null)))[\".\"+a]=l,a}let s=typeof e.all==\"string\"?e.all:e.all?n(e.all):void 0,o=e.scope;this.scope=o instanceof Wt?l=>l.prop(Hi)==o.data:o?l=>l==o:void 0,this.style=_a(t.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:s}).style,this.module=r?new Gt(r):null,this.themeType=e.themeType}static define(t,e){return new i(t,e||{})}},ih=A.define(),gp=A.define({combine(i){return i.length?[i[0]]:null}});function Ua(i){let t=i.facet(ih);return t.length?t:i.facet(gp)}function Te(i,t){let e=[Zx],r;return i instanceof ve&&(i.module&&e.push(T.styleModule.of(i.module)),r=i.themeType),t?.fallback?e.push(gp.of(i)):r?e.push(ih.computeN([T.darkTheme],n=>n.facet(T.darkTheme)==(r==\"dark\")?[i]:[])):e.push(ih.of(i)),e}var rh=class{constructor(t){this.markCache=Object.create(null),this.tree=pt(t.state),this.decorations=this.buildDeco(t,Ua(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=pt(t.state),r=Ua(t.state),n=r!=Ua(t.startState),{viewport:s}=t.view,o=t.changes.mapPos(this.decoratedTo,1);e.length=s.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(e!=this.tree||t.viewportChanged||n)&&(this.tree=e,this.decorations=this.buildDeco(t.view,r),this.decoratedTo=s.to)}buildDeco(t,e){if(!e||!this.tree.length)return R.none;let r=new Ee;for(let{from:n,to:s}of t.visibleRanges)Kd(this.tree,e,(o,l,a)=>{r.add(o,l,this.markCache[a]||(this.markCache[a]=R.mark({class:a})))},n,s);return r.finish()}},Zx=ie.high(ft.fromClass(rh,{decorations:i=>i.decorations})),eo=ve.define([{tag:p.meta,color:\"#404740\"},{tag:p.link,textDecoration:\"underline\"},{tag:p.heading,textDecoration:\"underline\",fontWeight:\"bold\"},{tag:p.emphasis,fontStyle:\"italic\"},{tag:p.strong,fontWeight:\"bold\"},{tag:p.strikethrough,textDecoration:\"line-through\"},{tag:p.keyword,color:\"#708\"},{tag:[p.atom,p.bool,p.url,p.contentSeparator,p.labelName],color:\"#219\"},{tag:[p.literal,p.inserted],color:\"#164\"},{tag:[p.string,p.deleted],color:\"#a11\"},{tag:[p.regexp,p.escape,p.special(p.string)],color:\"#e40\"},{tag:p.definition(p.variableName),color:\"#00f\"},{tag:p.local(p.variableName),color:\"#30a\"},{tag:[p.typeName,p.namespace],color:\"#085\"},{tag:p.className,color:\"#167\"},{tag:[p.special(p.variableName),p.macroName],color:\"#256\"},{tag:p.definition(p.propertyName),color:\"#00c\"},{tag:p.comment,color:\"#940\"},{tag:p.invalid,color:\"#f00\"}]),Fx=T.baseTheme({\"&.cm-focused .cm-matchingBracket\":{backgroundColor:\"#328c8252\"},\"&.cm-focused .cm-nonmatchingBracket\":{backgroundColor:\"#bb555544\"}}),Op=1e4,xp=\"()[]{}\",yp=A.define({combine(i){return kt(i,{afterCursor:!0,brackets:xp,maxScanDistance:Op,renderMatch:Hx})}}),_x=R.mark({class:\"cm-matchingBracket\"}),Gx=R.mark({class:\"cm-nonmatchingBracket\"});function Hx(i){let t=[],e=i.matched?_x:Gx;return t.push(e.range(i.start.from,i.start.to)),i.end&&t.push(e.range(i.end.from,i.end.to)),t}var Ux=it.define({create(){return R.none},update(i,t){if(!t.docChanged&&!t.selection)return i;let e=[],r=t.state.facet(yp);for(let n of t.state.selection.ranges){if(!n.empty)continue;let s=oe(t.state,n.head,-1,r)||n.head>0&&oe(t.state,n.head-1,1,r)||r.afterCursor&&(oe(t.state,n.head,1,r)||n.headT.decorations.from(i)}),jx=[Ux,Fx];function io(i={}){return[yp.of(i),jx]}var Kx=new E;function nh(i,t,e){let r=i.prop(t<0?E.openedBy:E.closedBy);if(r)return r;if(i.name.length==1){let n=e.indexOf(i.name);if(n>-1&&n%2==(t<0?1:0))return[e[n+t]]}return null}function sh(i){let t=i.type.prop(Kx);return t?t(i.node):i}function oe(i,t,e,r={}){let n=r.maxScanDistance||Op,s=r.brackets||xp,o=pt(i),l=o.resolveInner(t,e);for(let a=l;a;a=a.parent){let h=nh(a.type,e,s);if(h&&a.from0?t>=f.from&&tf.from&&t<=f.to))return Jx(i,t,e,a,f,h,s)}}return t1(i,t,e,o,l.type,n,s)}function Jx(i,t,e,r,n,s,o){let l=r.parent,a={from:n.from,to:n.to},h=0,f=l?.cursor();if(f&&(e<0?f.childBefore(r.from):f.childAfter(r.to)))do if(e<0?f.to<=r.from:f.from>=r.to){if(h==0&&s.indexOf(f.type.name)>-1&&f.from0)return null;let h={from:e<0?t-1:t,to:e>0?t+1:t},f=i.doc.iterRange(t,e>0?i.doc.length:0),c=0;for(let u=0;!f.next().done&&u<=s;){let d=f.value;e<0&&(u+=d.length);let m=t+u*e;for(let O=e>0?0:d.length-1,g=e>0?d.length:-1;O!=g;O+=e){let x=o.indexOf(d[O]);if(!(x<0||r.resolveInner(m+O,1).type!=n))if(x%2==0==e>0)c++;else{if(c==1)return{start:h,end:{from:m+O,to:m+O+1},matched:x>>1==a>>1};c--}}e>0&&(u+=d.length)}return f.done?{start:h,matched:!1}:null}var e1=Object.create(null),ip=[bt.none];var rp=[],np=Object.create(null),i1=Object.create(null);for(let[i,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\"]])i1[i]=r1(e1,t);function ja(i,t){rp.indexOf(i)>-1||(rp.push(i),console.warn(t))}function r1(i,t){let e=[];for(let l of t.split(\" \")){let a=[];for(let h of l.split(\".\")){let f=i[h]||p[h];f?typeof f==\"function\"?a.length?a=a.map(f):ja(h,`Modifier ${h} used at start of tag`):a.length?ja(h,`Tag ${h} used as modifier`):a=Array.isArray(f)?f:[f]:ja(h,`Unknown highlighting tag ${h}`)}for(let h of a)e.push(h)}if(!e.length)return 0;let r=t.replace(/ /g,\"_\"),n=r+\" \"+e.map(l=>l.id),s=np[n];if(s)return s.id;let o=np[n]=bt.define({id:ip.length,name:r,props:[Hs({[r]:e})]});return ip.push(o),o.id}var Fw={rtl:R.mark({class:\"cm-iso\",inclusive:!0,attributes:{dir:\"rtl\"},bidiIsolate:G.RTL}),ltr:R.mark({class:\"cm-iso\",inclusive:!0,attributes:{dir:\"ltr\"},bidiIsolate:G.LTR}),auto:R.mark({class:\"cm-iso\",inclusive:!0,attributes:{dir:\"auto\"},bidiIsolate:null})};var no=class{constructor(t,e,r){this.state=t,this.pos=e,this.explicit=r,this.abortListeners=[]}tokenBefore(t){let e=pt(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),r=Math.max(e.from,this.pos-250),n=e.text.slice(r-e.from,this.pos-e.from),s=n.search(Qp(t,!1));return s<0?null:{from:r+s,to:this.pos,text:n.slice(s)}}get aborted(){return this.abortListeners==null}addEventListener(t,e){t==\"abort\"&&this.abortListeners&&this.abortListeners.push(e)}};function bp(i){let t=Object.keys(i).join(\"\"),e=/\\w/.test(t);return e&&(t=t.replace(/\\w/g,\"\")),`[${e?\"\\\\w\":\"\"}${t.replace(/[^\\w\\s]/g,\"\\\\$&\")}]`}function n1(i){let t=Object.create(null),e=Object.create(null);for(let{label:n}of i){t[n[0]]=!0;for(let s=1;stypeof n==\"string\"?{label:n}:n),[e,r]=t.every(n=>/^\\w+$/.test(n.label))?[/\\w*$/,/\\w+$/]:n1(t);return n=>{let s=n.matchBefore(r);return s||n.explicit?{from:s?s.from:n.pos,options:t,validFor:e}:null}}function Ap(i,t){return e=>{for(let r=pt(e.state).resolveInner(e.pos,-1);r;r=r.parent){if(i.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return t(e)}}var so=class{constructor(t,e,r,n){this.completion=t,this.source=e,this.match=r,this.score=n}};function Ue(i){return i.selection.main.from}function Qp(i,t){var e;let{source:r}=i,n=t&&r[0]!=\"^\",s=r[r.length-1]!=\"$\";return!n&&!s?i:new RegExp(`${n?\"^\":\"\"}(?:${r})${s?\"$\":\"\"}`,(e=i.flags)!==null&&e!==void 0?e:i.ignoreCase?\"i\":\"\")}var Rp=Et.define();function s1(i,t,e,r){let{main:n}=i.selection,s=e-n.from,o=r-n.from;return Object.assign(Object.assign({},i.changeByRange(l=>l!=n&&e!=r&&i.sliceDoc(l.from+s,l.from+o)!=i.sliceDoc(e,r)?{range:l}:{changes:{from:l.from+s,to:r==n.from?l.to:l.from+o,insert:t},range:b.cursor(l.from+s+t.length)})),{scrollIntoView:!0,userEvent:\"input.complete\"})}var Sp=new WeakMap;function o1(i){if(!Array.isArray(i))return i;let t=Sp.get(i);return t||Sp.set(i,t=wh(i)),t}var oo=M.define(),sn=M.define(),dh=class{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e=48&&y<=57||y>=97&&y<=122?2:y>=65&&y<=90?1:0:(k=vr(y))!=k.toLowerCase()?1:k!=k.toUpperCase()?2:0;(!S||w==1&&g||v==0&&w!=0)&&(e[c]==y||r[c]==y&&(u=!0)?o[c++]=S:o.length&&(x=!1)),v=w,S+=wt(y)}return c==a&&o[0]==0&&x?this.result(-100+(u?-200:0),o,t):d==a&&m==0?this.ret(-200-t.length+(O==t.length?0:-100),[0,O]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):d==a?this.ret(-900-t.length,[m,O]):c==a?this.result(-100+(u?-200:0)+-700+(x?0:-1100),o,t):e.length==2?!1:this.result((n[0]?-700:0)+-200+-1100,n,t)}result(t,e,r){let n=[],s=0;for(let o of e){let l=o+(this.astral?wt(dt(r,o)):1);s&&n[s-1]==o?n[s-1]=l:(n[s++]=o,n[s++]=l)}return this.ret(t-r.length,n)}},gt=A.define({combine(i){return kt(i,{activateOnTyping:!0,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>\"\",optionClass:()=>\"\",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:l1,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)=>r=>wp(t(r),e(r)),optionClass:(t,e)=>r=>wp(t(r),e(r)),addToOptions:(t,e)=>t.concat(e)})}});function wp(i,t){return i?t?i+\" \"+t:i:t}function l1(i,t,e,r,n,s){let o=i.textDirection==G.RTL,l=o,a=!1,h=\"top\",f,c,u=t.left-n.left,d=n.right-t.right,m=r.right-r.left,O=r.bottom-r.top;if(l&&u=O||S>t.top?f=e.bottom-t.top:(h=\"bottom\",f=t.bottom-e.top)}let g=(t.bottom-t.top)/s.offsetHeight,x=(t.right-t.left)/s.offsetWidth;return{style:`${h}: ${f/g}px; max-width: ${c/x}px`,class:\"cm-completionInfo-\"+(a?o?\"left-narrow\":\"right-narrow\":l?\"left\":\"right\")}}function a1(i){let t=i.addToOptions.slice();return i.icons&&t.push({render(e){let r=document.createElement(\"div\");return r.classList.add(\"cm-completionIcon\"),e.type&&r.classList.add(...e.type.split(/\\s+/g).map(n=>\"cm-completionIcon-\"+n)),r.setAttribute(\"aria-hidden\",\"true\"),r},position:20}),t.push({render(e,r,n,s){let o=document.createElement(\"span\");o.className=\"cm-completionLabel\";let l=e.displayLabel||e.label,a=0;for(let h=0;ha&&o.appendChild(document.createTextNode(l.slice(a,f)));let u=o.appendChild(document.createElement(\"span\"));u.appendChild(document.createTextNode(l.slice(f,c))),u.className=\"cm-completionMatchedText\",a=c}return ae.position-r.position).map(e=>e.render)}function ch(i,t,e){if(i<=e)return{from:0,to:i};if(t<0&&(t=0),t<=i>>1){let n=Math.floor(t/e);return{from:n*e,to:(n+1)*e}}let r=Math.floor((i-t)/e);return{from:i-(r+1)*e,to:i-r*e}}var ph=class{constructor(t,e,r){this.view=t,this.stateField=e,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass=\"\";let n=t.state.field(e),{options:s,selected:o}=n.open,l=t.state.facet(gt);this.optionContent=a1(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=ch(s.length,o,l.maxRenderedOptions),this.dom=document.createElement(\"div\"),this.dom.className=\"cm-tooltip-autocomplete\",this.updateTooltipClass(t.state),this.dom.addEventListener(\"mousedown\",a=>{let{options:h}=t.state.field(e).open;for(let f=a.target,c;f&&f!=this.dom;f=f.parentNode)if(f.nodeName==\"LI\"&&(c=/-(\\d+)$/.exec(f.id))&&+c[1]{let h=t.state.field(this.stateField,!1);h&&h.tooltip&&t.state.facet(gt).closeOnBlur&&a.relatedTarget!=t.contentDOM&&t.dispatch({effects:sn.of(null)})}),this.showOptions(s,n.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener(\"scroll\",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let r=t.state.field(this.stateField),n=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),r!=n){let{options:s,selected:o,disabled:l}=r.open;(!n.open||n.open.options!=s)&&(this.range=ch(s.length,o,t.state.facet(gt).maxRenderedOptions),this.showOptions(s,r.id)),this.updateSel(),l!=((e=n.open)===null||e===void 0?void 0:e.disabled)&&this.dom.classList.toggle(\"cm-tooltip-autocomplete-disabled\",!!l)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let r of this.currentClass.split(\" \"))r&&this.dom.classList.remove(r);for(let r of e.split(\" \"))r&&this.dom.classList.add(r);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected>-1&&e.selected=this.range.to)&&(this.range=ch(e.options.length,e.selected,this.view.state.facet(gt).maxRenderedOptions),this.showOptions(e.options,t.id)),this.updateSelectedOption(e.selected)){this.destroyInfo();let{completion:r}=e.options[e.selected],{info:n}=r;if(!n)return;let s=typeof n==\"string\"?document.createTextNode(n):n(r);if(!s)return;\"then\"in s?s.then(o=>{o&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(o,r)}).catch(o=>Ct(this.view.state,o,\"completion info\")):this.addInfoPane(s,r)}}addInfoPane(t,e){this.destroyInfo();let r=this.info=document.createElement(\"div\");if(r.className=\"cm-tooltip cm-completionInfo\",t.nodeType!=null)r.appendChild(t),this.infoDestroy=null;else{let{dom:n,destroy:s}=t;r.appendChild(n),this.infoDestroy=s||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let r=this.list.firstChild,n=this.range.from;r;r=r.nextSibling,n++)r.nodeName!=\"LI\"||!r.id?n--:n==t?r.hasAttribute(\"aria-selected\")||(r.setAttribute(\"aria-selected\",\"true\"),e=r):r.hasAttribute(\"aria-selected\")&&r.removeAttribute(\"aria-selected\");return e&&f1(this.list,e),e}measureInfo(){let t=this.dom.querySelector(\"[aria-selected]\");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),n=t.getBoundingClientRect(),s=this.space;if(!s){let o=this.dom.ownerDocument.defaultView||window;s={left:0,top:0,right:o.innerWidth,bottom:o.innerHeight}}return n.top>Math.min(s.bottom,e.bottom)-10||n.bottomr.from||r.from==0))if(s=u,typeof h!=\"string\"&&h.header)n.appendChild(h.header(h));else{let d=n.appendChild(document.createElement(\"completion-section\"));d.textContent=u}}let f=n.appendChild(document.createElement(\"li\"));f.id=e+\"-\"+o,f.setAttribute(\"role\",\"option\");let c=this.optionClass(l);c&&(f.className=c);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&f.appendChild(d)}}return r.from&&n.classList.add(\"cm-completionListIncompleteTop\"),r.tonew ph(e,i,t)}function f1(i,t){let e=i.getBoundingClientRect(),r=t.getBoundingClientRect(),n=e.height/i.offsetHeight;r.tope.bottom&&(i.scrollTop+=(r.bottom-e.bottom)/n)}function vp(i){return(i.boost||0)*100+(i.apply?10:0)+(i.info?5:0)+(i.type?1:0)}function c1(i,t){let e=[],r=null,n=a=>{e.push(a);let{section:h}=a.completion;if(h){r||(r=[]);let f=typeof h==\"string\"?h:h.name;r.some(c=>c.name==f)||r.push(typeof h==\"string\"?{name:f}:h)}};for(let a of i)if(a.hasResult()){let h=a.result.getMatch;if(a.result.filter===!1)for(let f of a.result.options)n(new so(f,a.source,h?h(f):[],1e9-e.length));else{let f=new dh(t.sliceDoc(a.from,a.to));for(let c of a.result.options)if(f.match(c.label)){let u=c.displayLabel?h?h(c,f.matched):[]:f.matched;n(new so(c,a.source,u,f.score+(c.boost||0)))}}}if(r){let a=Object.create(null),h=0,f=(c,u)=>{var d,m;return((d=c.rank)!==null&&d!==void 0?d:1e9)-((m=u.rank)!==null&&m!==void 0?m:1e9)||(c.namef.score-h.score||l(h.completion,f.completion))){let h=a.completion;!o||o.label!=h.label||o.detail!=h.detail||o.type!=null&&h.type!=null&&o.type!=h.type||o.apply!=h.apply||o.boost!=h.boost?s.push(a):vp(a.completion)>vp(o)&&(s[s.length-1]=a),o=a.completion}return s}var mh=class i{constructor(t,e,r,n,s,o){this.options=t,this.attrs=e,this.tooltip=r,this.timestamp=n,this.selected=s,this.disabled=o}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new i(this.options,kp(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,r,n,s){let o=c1(t,e);if(!o.length)return n&&t.some(a=>a.state==1)?new i(n.options,n.attrs,n.tooltip,n.timestamp,n.selected,!0):null;let l=e.facet(gt).selectOnOpen?0:-1;if(n&&n.selected!=l&&n.selected!=-1){let a=n.options[n.selected].completion;for(let h=0;hh.hasResult()?Math.min(a,h.from):a,1e8),create:g1,above:s.aboveCursor},n?n.timestamp:Date.now(),l,!1)}map(t){return new i(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}},gh=class i{constructor(t,e,r){this.active=t,this.id=e,this.open=r}static start(){return new i(p1,\"cm-ac-\"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:e}=t,r=e.facet(gt),s=(r.override||e.languageDataAt(\"autocomplete\",Ue(e)).map(o1)).map(l=>(this.active.find(h=>h.source==l)||new De(l,this.active.some(h=>h.state!=0)?1:0)).update(t,r));s.length==this.active.length&&s.every((l,a)=>l==this.active[a])&&(s=this.active);let o=this.open;o&&t.docChanged&&(o=o.map(t.changes)),t.selection||s.some(l=>l.hasResult()&&t.changes.touchesRange(l.from,l.to))||!u1(s,this.active)?o=mh.build(s,e,this.id,o,r):o&&o.disabled&&!s.some(l=>l.state==1)&&(o=null),!o&&s.every(l=>l.state!=1)&&s.some(l=>l.hasResult())&&(s=s.map(l=>l.hasResult()?new De(l.source,0):l));for(let l of t.effects)l.is(Ep)&&(o=o&&o.setSelected(l.value,this.id));return s==this.active&&o==this.open?this:new i(s,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:d1}};function u1(i,t){if(i==t)return!0;for(let e=0,r=0;;){for(;e-1&&(e[\"aria-activedescendant\"]=i+\"-\"+t),e}var p1=[];function Oh(i){return i.isUserEvent(\"input.type\")?\"input\":i.isUserEvent(\"delete.backward\")?\"delete\":null}var De=class i{constructor(t,e,r=-1){this.source=t,this.state=e,this.explicitPos=r}hasResult(){return!1}update(t,e){let r=Oh(t),n=this;r?n=n.handleUserEvent(t,r,e):t.docChanged?n=n.handleChange(t):t.selection&&n.state!=0&&(n=new i(n.source,0));for(let s of t.effects)if(s.is(oo))n=new i(n.source,1,s.value?Ue(t.state):-1);else if(s.is(sn))n=new i(n.source,0);else if(s.is(Mp))for(let o of s.value)o.source==n.source&&(n=o);return n}handleUserEvent(t,e,r){return e==\"delete\"||!r.activateOnTyping?this.map(t.changes):new i(this.source,1)}handleChange(t){return t.changes.touchesRange(Ue(t.startState))?new i(this.source,0):this.map(t.changes)}map(t){return t.empty||this.explicitPos<0?this:new i(this.source,this.state,t.mapPos(this.explicitPos))}},lo=class i extends De{constructor(t,e,r,n,s){super(t,2,e),this.result=r,this.from=n,this.to=s}hasResult(){return!0}handleUserEvent(t,e,r){var n;let s=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=Ue(t.state);if((this.explicitPos<0?l<=s:lo||e==\"delete\"&&Ue(t.startState)==this.from)return new De(this.source,e==\"input\"&&r.activateOnTyping?1:0);let a=this.explicitPos<0?-1:t.changes.mapPos(this.explicitPos),h;return m1(this.result.validFor,t.state,s,o)?new i(this.source,a,this.result,s,o):this.result.update&&(h=this.result.update(this.result,s,o,new no(t.state,l,a>=0)))?new i(this.source,a,h,h.from,(n=h.to)!==null&&n!==void 0?n:Ue(t.state)):new De(this.source,1,a)}handleChange(t){return t.changes.touchesRange(this.from,this.to)?new De(this.source,0):this.map(t.changes)}map(t){return t.empty?this:new i(this.source,this.explicitPos<0?-1:t.mapPos(this.explicitPos),this.result,t.mapPos(this.from),t.mapPos(this.to,1))}};function m1(i,t,e,r){if(!i)return!1;let n=t.sliceDoc(e,r);return typeof i==\"function\"?i(n,e,r,t):Qp(i,!0).test(n)}var Mp=M.define({map(i,t){return i.map(e=>e.map(t))}}),Ep=M.define(),It=it.define({create(){return gh.start()},update(i,t){return i.update(t)},provide:i=>[Fr.from(i,t=>t.tooltip),T.contentAttributes.from(i,t=>t.attrs)]});function $p(i,t){let e=t.completion.apply||t.completion.label,r=i.state.field(It).active.find(n=>n.source==t.source);return r instanceof lo?(typeof e==\"string\"?i.dispatch(Object.assign(Object.assign({},s1(i.state,e,r.from,r.to)),{annotations:Rp.of(t.completion)})):e(i,t.completion,r.from,r.to),!0):!1}var g1=h1(It,$p);function ro(i,t=\"option\"){return e=>{let r=e.state.field(It,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp-1?r.open.selected+n*(i?1:-1):i?0:o-1;return l<0?l=t==\"page\"?0:o-1:l>=o&&(l=t==\"page\"?o-1:0),e.dispatch({effects:Ep.of(l)}),!0}}var O1=i=>{let t=i.state.field(It,!1);return i.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestampi.state.field(It,!1)?(i.dispatch({effects:oo.of(!0)}),!0):!1,y1=i=>{let t=i.state.field(It,!1);return!t||!t.active.some(e=>e.state!=0)?!1:(i.dispatch({effects:sn.of(null)}),!0)},xh=class{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}},b1=50,S1=1e3,w1=ft.fromClass(class{constructor(i){this.view=i,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of i.state.field(It).active)t.state==1&&this.startQuery(t)}update(i){let t=i.state.field(It);if(!i.selectionSet&&!i.docChanged&&i.startState.field(It)==t)return;let e=i.transactions.some(n=>(n.selection||n.docChanged)&&!Oh(n));for(let n=0;nb1&&Date.now()-s.time>S1){for(let o of s.context.abortListeners)try{o()}catch(l){Ct(this.view.state,l)}s.context.abortListeners=null,this.running.splice(n--,1)}else s.updates.push(...i.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),i.transactions.some(n=>n.effects.some(s=>s.is(oo)))&&(this.pendingStart=!0);let r=this.pendingStart?50:i.state.facet(gt).activateOnTypingDelay;if(this.debounceUpdate=t.active.some(n=>n.state==1&&!this.running.some(s=>s.active.source==n.source))?setTimeout(()=>this.startUpdate(),r):-1,this.composing!=0)for(let n of i.transactions)Oh(n)==\"input\"?this.composing=2:this.composing==2&&n.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:i}=this.view,t=i.field(It);for(let e of t.active)e.state==1&&!this.running.some(r=>r.active.source==e.source)&&this.startQuery(e)}startQuery(i){let{state:t}=this.view,e=Ue(t),r=new no(t,e,i.explicitPos==e),n=new xh(i,r);this.running.push(n),Promise.resolve(i.source(r)).then(s=>{n.context.aborted||(n.done=s||null,this.scheduleAccept())},s=>{this.view.dispatch({effects:sn.of(null)}),Ct(this.view.state,s)})}scheduleAccept(){this.running.every(i=>i.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(gt).updateSyncTime))}accept(){var i;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],e=this.view.state.facet(gt);for(let r=0;r