@openchamber/web 1.18.4 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-DAvopJvy.js} +1 -1
  3. package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-D9cV-qR9.js} +1 -1
  4. package/dist/assets/{DiagramEditor-jnG3Hbxg.js → DiagramEditor-B9NCadU7.js} +1 -1
  5. package/dist/assets/DiagramView-LKGBwf4G.js +1 -0
  6. package/dist/assets/{DiffView-DZIoOnV7.js → DiffView-BWNq-0ov.js} +2 -2
  7. package/dist/assets/FilesView-DB-Q0Gkz.js +14 -0
  8. package/dist/assets/{GitView-DBFrDDBv.js → GitView-DsWXqWx3.js} +3 -3
  9. package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-h4dHASlq.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +12 -0
  12. package/dist/assets/OnboardingScreen-CDjgzxEe.js +1 -0
  13. package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-jPKTJje5.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-BHm4Yr0X.js → PierreDiffViewer-D_Gt4A_6.js} +1 -1
  15. package/dist/assets/PlanView-UvuxIl9-.js +4 -0
  16. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +1 -0
  17. package/dist/assets/SettingsView-3B9VN6Ys.js +28 -0
  18. package/dist/assets/SettingsWindow-CqQNDKNd.js +1 -0
  19. package/dist/assets/{ToolOutputDialog-Za6V4VMJ.js → ToolOutputDialog-PmjlAxVE.js} +6 -6
  20. package/dist/assets/{ToolPartDiffPreview-BL-9ixyC.js → ToolPartDiffPreview-B34Xw9wq.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-CwGocYQd.js → VirtualizedFileDiff-B37yB9jZ.js} +3 -3
  22. package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-Bxun3k66.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DYFv_yZS.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +1 -0
  25. package/dist/assets/de-DbV6CLxv.js +9 -0
  26. package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
  27. package/dist/assets/es-CVDlyzZ4.js +15 -0
  28. package/dist/assets/fr-Czc-p0g-.js +13 -0
  29. package/dist/assets/index-1OhiMDBz.css +1 -0
  30. package/dist/assets/index-BSvmTvZl.js +1 -0
  31. package/dist/assets/index-DzriVon2.js +7 -0
  32. package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-DwHKxDYc.js} +1 -1
  33. package/dist/assets/{isFilePlainText-gTibdNIe.js → isFilePlainText-Dwq6ILxo.js} +1 -1
  34. package/dist/assets/ja-dwc9NM_S.js +15 -0
  35. package/dist/assets/ko-Ds1DZ8FX.js +15 -0
  36. package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
  37. package/dist/assets/main-BF51IOVF.js +921 -0
  38. package/dist/assets/{main-D7UcL3VQ.js → main-D7UPARut.js} +2 -2
  39. package/dist/assets/markdownCore-BgeBDwD3.js +2 -0
  40. package/dist/assets/{miniChat-O_GVoEbc.js → miniChat-BISXSGOo.js} +2 -2
  41. package/dist/assets/mobile-BnYxVuvw.js +2 -0
  42. package/dist/assets/{patchFileDiff-KNkxM1C1.js → patchFileDiff-BEDPDypx.js} +2 -2
  43. package/dist/assets/pl-CLiTO7i-.js +15 -0
  44. package/dist/assets/pt-BR-GIimJgpK.js +15 -0
  45. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +2 -0
  46. package/dist/assets/{renderMobileApp-toj9cXoh.js → renderMobileApp-BiMbzPq9.js} +7 -7
  47. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +15 -0
  48. package/dist/assets/scheduledTasksApi-01zzfzqH.js +1 -0
  49. package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DXYW46vW.js} +1 -1
  50. package/dist/assets/uk-DLfgD1ki.js +15 -0
  51. package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-CbzHzFop.js} +139 -142
  52. package/dist/assets/{useInlineCommentController-CYPvYJDt.js → useInlineCommentController-CegKdDXi.js} +2 -2
  53. package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-BYlZTzrw.js} +1 -1
  54. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
  55. package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
  56. package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
  60. package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
  61. package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
  62. package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
  63. package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
  67. package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
  68. package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
  77. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
  78. package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-CiAYDJXN.js} +2 -2
  79. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
  80. package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
  81. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
  82. package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
  83. package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
  84. package/dist/assets/vendor-zod-adaMkgkm.js +39 -0
  85. package/dist/assets/{web-components-GMc3oR3i.js → web-components-DCLjCO9n.js} +1 -1
  86. package/dist/assets/zh-CN-DkeP5awK.js +15 -0
  87. package/dist/assets/zh-TW-BocaFm3d.js +15 -0
  88. package/dist/index.html +4 -4
  89. package/dist/mini-chat.html +3 -3
  90. package/dist/mobile.html +3 -3
  91. package/package.json +1 -1
  92. package/server/index.js +116 -3
  93. package/server/lib/agent-memory/actions.js +243 -0
  94. package/server/lib/agent-memory/actions.test.js +343 -0
  95. package/server/lib/agent-memory/feature-flag.js +19 -0
  96. package/server/lib/agent-memory/feature-flag.test.js +38 -0
  97. package/server/lib/agent-memory/project-resolution.js +56 -0
  98. package/server/lib/agent-memory/project-resolution.test.js +85 -0
  99. package/server/lib/agent-memory/routes.http.test.js +270 -0
  100. package/server/lib/agent-memory/routes.js +169 -0
  101. package/server/lib/agent-memory/runtime.js +427 -0
  102. package/server/lib/agent-memory/runtime.test.js +344 -0
  103. package/server/lib/agent-memory/threat-patterns.js +61 -0
  104. package/server/lib/agent-memory/threat-patterns.test.js +61 -0
  105. package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
  106. package/server/lib/agent-tool/runtime.js +63 -13
  107. package/server/lib/agent-tool/runtime.test.js +85 -2
  108. package/server/lib/context-obligatory/runtime.js +34 -3
  109. package/server/lib/context-obligatory/runtime.test.js +114 -0
  110. package/server/lib/fs/DOCUMENTATION.md +3 -0
  111. package/server/lib/fs/routes.js +149 -32
  112. package/server/lib/fs/routes.test.js +225 -0
  113. package/server/lib/git/DOCUMENTATION.md +8 -0
  114. package/server/lib/git/service.js +121 -67
  115. package/server/lib/git/service.test.js +129 -0
  116. package/server/lib/github/DOCUMENTATION.md +14 -3
  117. package/server/lib/github/pr-status.js +188 -83
  118. package/server/lib/github/pr-status.test.js +182 -0
  119. package/server/lib/github/routes.js +36 -30
  120. package/server/lib/notifications/template-runtime.js +2 -3
  121. package/server/lib/openchamber-control/action-resolution.test.js +65 -0
  122. package/server/lib/openchamber-control/actions.js +78 -0
  123. package/server/lib/openchamber-control/service.js +7 -0
  124. package/server/lib/openchamber-sessions/routes.js +14 -0
  125. package/server/lib/opencode/DOCUMENTATION.md +6 -4
  126. package/server/lib/opencode/claude-cli-auth.js +60 -0
  127. package/server/lib/opencode/claude-cli-auth.test.js +54 -0
  128. package/server/lib/opencode/feature-routes-runtime.js +11 -0
  129. package/server/lib/opencode/plugins.js +12 -3
  130. package/server/lib/opencode/plugins.test.js +18 -0
  131. package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
  132. package/server/lib/opencode/proxy.js +116 -6
  133. package/server/lib/opencode/proxy.test.js +158 -1
  134. package/server/lib/opencode/routes.js +4 -1
  135. package/server/lib/opencode/settings-helpers.js +11 -0
  136. package/server/lib/opencode/settings-helpers.test.js +35 -0
  137. package/server/lib/opencode/settings-runtime.js +51 -0
  138. package/server/lib/opencode/shared.js +120 -16
  139. package/server/lib/opencode/shared.test.js +185 -1
  140. package/server/lib/project-context/DOCUMENTATION.md +158 -0
  141. package/server/lib/project-context/routes.http.test.js +264 -0
  142. package/server/lib/project-context/routes.js +237 -0
  143. package/server/lib/project-context/runtime.js +667 -0
  144. package/server/lib/project-context/runtime.test.js +498 -0
  145. package/server/lib/quota/DOCUMENTATION.md +16 -1
  146. package/server/lib/quota/providers/claude/auth.js +113 -0
  147. package/server/lib/quota/providers/claude/auth.test.js +117 -0
  148. package/server/lib/quota/providers/claude/index.js +151 -0
  149. package/server/lib/quota/providers/claude/index.test.js +147 -0
  150. package/server/lib/quota/providers/claude/transforms.js +127 -0
  151. package/server/lib/quota/providers/claude/transforms.test.js +82 -0
  152. package/server/lib/quota/providers/command-code.js +90 -0
  153. package/server/lib/quota/providers/command-code.test.js +72 -0
  154. package/server/lib/quota/providers/index.js +22 -2
  155. package/server/lib/quota/providers/index.test.js +10 -1
  156. package/server/lib/quota/utils/formatters.js +2 -1
  157. package/server/lib/scheduled-tasks/runtime.js +21 -2
  158. package/server/lib/session-knowledge/DOCUMENTATION.md +87 -0
  159. package/server/lib/session-knowledge/routes.js +107 -0
  160. package/server/lib/session-knowledge/runtime.js +331 -0
  161. package/server/lib/session-knowledge/runtime.test.js +275 -0
  162. package/server/lib/skills-catalog/DOCUMENTATION.md +22 -22
  163. package/server/lib/skills-catalog/curated-sources.js +1 -1
  164. package/server/lib/skills-catalog/curated-sources.test.js +10 -0
  165. package/server/lib/small-model/index.js +8 -0
  166. package/server/lib/small-model/index.test.js +31 -1
  167. package/server/lib/small-model/routes.js +3 -1
  168. package/dist/assets/DiagramView-CFXxgg_a.js +0 -1
  169. package/dist/assets/FilesView-BKL6YlKG.js +0 -14
  170. package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
  171. package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
  172. package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
  173. package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
  174. package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
  175. package/dist/assets/SettingsView-5RmswFZe.js +0 -28
  176. package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
  177. package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
  178. package/dist/assets/de-u7gSnqWs.js +0 -9
  179. package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
  180. package/dist/assets/es-T9O7aAOr.js +0 -15
  181. package/dist/assets/fr-Oor7ewbE.js +0 -13
  182. package/dist/assets/index-BzIpNlNE.css +0 -1
  183. package/dist/assets/index-C0yNhuZw.js +0 -1
  184. package/dist/assets/index-DRpChWux.js +0 -7
  185. package/dist/assets/ja-DHpqbVmr.js +0 -15
  186. package/dist/assets/ko-CwLkS3nx.js +0 -15
  187. package/dist/assets/main-DPMd2iKS.js +0 -915
  188. package/dist/assets/markdownCore-DDrHVneM.js +0 -2
  189. package/dist/assets/mobile-Br4TtAqc.js +0 -2
  190. package/dist/assets/pl-CcZILN8q.js +0 -15
  191. package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
  192. package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
  193. package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
  194. package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
  195. package/dist/assets/uk-BA2kZR38.js +0 -15
  196. package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
  197. package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
  198. package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
  199. package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
  200. package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
  201. package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
  202. package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
  203. package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
  204. package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
  205. package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
  206. package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
  207. package/server/lib/quota/providers/claude.js +0 -107
@@ -0,0 +1,4 @@
1
+ import{E as Wt,T as en,a as v,P as ti,b as K,C as Ui,R as E,S as Bt,F as k,A as sn,c as ei,f as ct,d as nn,e as Qi,M as Ht,g as rn,h as on,i as ln,j as an}from"./vendor-codemirror-state-C9awkmn-.js";import{S as At}from"./vendor-style-mod-NZ5MEPvj.js";import{k as hn,b as cn,s as fn}from"./vendor-w3c-keyname-Vcq4gwWv.js";import{c as wt}from"./vendor-crelt-C8TCjufn.js";let P=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},We=typeof document<"u"?document:{documentElement:{style:{}}};const He=/Edge\/(\d+)/.exec(P.userAgent),Ji=/MSIE \d/.test(P.userAgent),Pe=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(P.userAgent),be=!!(Ji||Pe||He),ui=!be&&/gecko\/(\d+)/i.test(P.userAgent),ve=!be&&/Chrome\/(\d+)/.exec(P.userAgent),pi="webkitFontSmoothing"in We.documentElement.style,Ne=!be&&/Apple Computer/.test(P.vendor),gi=Ne&&(/Mobile\/\w+/.test(P.userAgent)||P.maxTouchPoints>2);var y={mac:gi||/Mac/.test(P.platform),windows:/Win/.test(P.platform),linux:/Linux|X11/.test(P.platform),ie:be,ie_version:Ji?We.documentMode||6:Pe?+Pe[1]:He?+He[1]:0,gecko:ui,gecko_version:ui?+(/Firefox\/(\d+)/.exec(P.userAgent)||[0,0])[1]:0,chrome:!!ve,chrome_version:ve?+ve[1]:0,ios:gi,android:/Android\b/.test(P.userAgent),webkit:pi,webkit_version:pi?+(/\bAppleWebKit\/(\d+)/.exec(P.userAgent)||[0,0])[1]:0,safari:Ne,safari_version:Ne?+(/\bVersion\/(\d+(\.\d+)?)/.exec(P.userAgent)||[0,0])[1]:0,tabSize:We.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function ii(n,t){for(let e in n)e=="class"&&t.class?t.class+=" "+n.class:e=="style"&&t.style?t.style+=";"+n.style:t[e]=n[e];return t}const he=Object.create(null);function si(n,t,e){if(n==t)return!0;n||(n=he),t||(t=he);let i=Object.keys(n),s=Object.keys(t);if(i.length-0!=s.length-0)return!1;for(let r of i)if(r!=e&&(s.indexOf(r)==-1||n[r]!==t[r]))return!1;return!0}function dn(n,t){for(let e=n.attributes.length-1;e>=0;e--){let i=n.attributes[e].name;t[i]==null&&n.removeAttribute(i)}for(let e in t){let i=t[e];e=="style"?n.style.cssText=i:n.getAttribute(e)!=i&&n.setAttribute(e,i)}}function mi(n,t,e){let i=!1;if(t)for(let s in t)e&&s in e||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(e)for(let s in e)t&&t[s]==e[s]||(i=!0,s=="style"?n.style.cssText=e[s]:n.setAttribute(s,e[s]));return i}function un(n){let t=Object.create(null);for(let e=0;e<n.attributes.length;e++){let i=n.attributes[e];t[i.name]=i.value}return t}class jt{eq(t){return!1}updateDOM(t,e,i){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}var H=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(H||(H={}));class R extends ei{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new Gt(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new ut(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=Zi(t,e);i=(r?e?-3e8:-1:5e8)-1,s=(o?e?2e8:1:-6e8)+1}return new ut(t,i,s,e,t.widget||null,!0)}static line(t){return new _t(t)}static set(t,e=!1){return E.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}R.none=E.empty;class Gt extends R{constructor(t){let{start:e,end:i}=Zi(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.attrs=t.class&&t.attributes?ii(t.attributes,{class:t.class}):t.class?{class:t.class}:t.attributes||he}eq(t){return this==t||t instanceof Gt&&this.tagName==t.tagName&&si(this.attrs,t.attrs)}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}Gt.prototype.point=!1;class _t extends R{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof _t&&this.spec.class==t.spec.class&&si(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)}}_t.prototype.mapMode=Ht.TrackBefore;_t.prototype.point=!0;class ut extends R{constructor(t,e,i,s,r,o){super(e,i,r,t),this.block=s,this.isReplace=o,this.mapMode=s?e<=0?Ht.TrackBefore:Ht.TrackAfter:Ht.TrackDel}get type(){return this.startSide!=this.endSide?H.WidgetRange:this.startSide<=0?H.WidgetBefore:H.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof ut&&pn(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)}}ut.prototype.point=!0;function Zi(n,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=n;return e==null&&(e=n.inclusive),i==null&&(i=n.inclusive),{start:e??t,end:i??t}}function pn(n,t){return n==t||!!(n&&t&&n.compare(t))}function Ct(n,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=n?e[s]=Math.max(e[s],t):e.push(n,t)}class It extends ei{constructor(t,e,i){super(),this.tagName=t,this.attributes=e,this.rank=i}eq(t){return t==this||t instanceof It&&this.tagName==t.tagName&&si(this.attributes,t.attributes)}static create(t){return new It(t.tagName,t.attributes||he,t.rank==null?50:Math.max(0,Math.min(t.rank,100)))}static set(t,e=!1){return E.of(t,e)}}It.prototype.startSide=It.prototype.endSide=-1;function Kt(n){let t;return n.nodeType==11?t=n.getSelection?n:n.ownerDocument:t=n,t.getSelection()}function Ve(n,t){return t?n==t||n.contains(t.nodeType!=1?t.parentNode:t):!1}function Pt(n,t){if(!t.anchorNode)return!1;try{return Ve(n,t.anchorNode)}catch{return!1}}function Nt(n){return n.nodeType==3?qt(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Vt(n,t,e,i){return e?bi(n,t,e,i,-1)||bi(n,t,e,i,1):!1}function ot(n){for(var t=0;;t++)if(n=n.previousSibling,!n)return t}function ce(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function bi(n,t,e,i,s){for(;;){if(n==e&&t==i)return!0;if(t==(s<0?0:et(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;t=ot(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[t+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;t=s<0?et(n):0}else return!1}}function et(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function zt(n,t){let{left:e,right:i}=n;if(e==i)return n;let s=t?e:i;return{left:s,right:s,top:n.top,bottom:n.bottom}}function gn(n){let t=n.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function ts(n,t){let e=t.width/n.offsetWidth,i=t.height/n.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-n.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-n.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function mn(n,t,e,i,s,r,o,l){let a=n.ownerDocument,h=a.defaultView||window;for(let c=n,f=!1;c&&!f;)if(c.nodeType==1){let d,u=c==a.body,p=1,g=1;if(u)d=gn(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(f=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let w=c.getBoundingClientRect();({scaleX:p,scaleY:g}=ts(c,w)),d={left:w.left,right:w.left+c.clientWidth*p,top:w.top,bottom:w.top+c.clientHeight*g}}let m=0,b=0;if(s=="nearest")t.top<d.top+o?(b=t.top-(d.top+o),e>0&&t.bottom>d.bottom+b&&(b=t.bottom-d.bottom+o)):t.bottom>d.bottom-o&&(b=t.bottom-d.bottom+o,e<0&&t.top-b<d.top&&(b=t.top-(d.top+o)));else{let w=t.bottom-t.top,x=d.bottom-d.top;b=(s=="center"&&w<=x?t.top+w/2-x/2:s=="start"||s=="center"&&e<0?t.top-o:t.bottom-x+o)-d.top}if(i=="nearest"?t.left<d.left+r?(m=t.left-(d.left+r),e>0&&t.right>d.right+m&&(m=t.right-d.right+r)):t.right>d.right-r&&(m=t.right-d.right+r,e<0&&t.left<d.left+m&&(m=t.left-(d.left+r))):m=(i=="center"?t.left+(t.right-t.left)/2-(d.right-d.left)/2:i=="start"==l?t.left-r:t.right-(d.right-d.left)+r)-d.left,m||b)if(u)h.scrollBy(m,b);else{let w=0,x=0;if(b){let O=c.scrollTop;c.scrollTop+=b/g,x=(c.scrollTop-O)*g}if(m){let O=c.scrollLeft;c.scrollLeft+=m/p,w=(c.scrollLeft-O)*p}t={left:t.left-w,top:t.top-x,right:t.right-w,bottom:t.bottom-x},w&&Math.abs(w-m)<1&&(i="nearest"),x&&Math.abs(x-b)<1&&(s="nearest")}if(u)break;(t.top<d.top||t.bottom>d.bottom||t.left<d.left||t.right>d.right)&&(t={left:Math.max(t.left,d.left),right:Math.min(t.right,d.right),top:Math.max(t.top,d.top),bottom:Math.min(t.bottom,d.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function es(n,t=!0){let e=n.ownerDocument,i=null,s=null;for(let r=n.parentNode;r&&!(r==e.body||(!t||i)&&s);)if(r.nodeType==1)!s&&r.scrollHeight>r.clientHeight&&(s=r),t&&!i&&r.scrollWidth>r.clientWidth&&(i=r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;return{x:i,y:s}}class bn{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?et(e):0),i,Math.min(t.focusOffset,i?et(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}function is(n){let t=[];for(let e=n;e;e=e.nodeType==11?e.host:e.parentNode)e.nodeType==1&&t.push({node:e,left:e.scrollLeft,top:e.scrollTop});return t}function ss(n,t=!0){for(let{node:e,left:i,top:s}of n)t&&e.scrollTop!=s&&(e.scrollTop=s),e.scrollLeft!=i&&(e.scrollLeft=i)}let ht=null;y.safari&&y.safari_version>=26&&(ht=!1);function ns(n){if(n.setActive)return n.setActive();if(ht)return n.focus(ht);let t=is(n);n.focus(ht==null?{get preventScroll(){return ht={preventScroll:!0},!0}}:void 0),ht||(ht=!1,ss(t))}let yi;function qt(n,t,e=t){let i=yi||(yi=document.createRange());return i.setEnd(n,e),i.setStart(n,t),i}function kt(n,t,e,i){let s={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,n.dispatchEvent(r);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,n.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function yn(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function wn(n,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,et(e));;)if(i){if(e.nodeType!=1)return!1;let s=e.childNodes[i-1];s.contentEditable=="false"?i--:(e=s,i=et(e))}else{if(e==n)return!0;i=ot(e),e=e.parentNode}}function rs(n){return n instanceof Window?n.pageYOffset>Math.max(0,n.document.documentElement.scrollHeight-n.innerHeight-4):n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function os(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=et(e)}else if(e.parentNode&&!ce(e))i=ot(e),e=e.parentNode;else return null}}function ls(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!ce(e))i=ot(e)+1,e=e.parentNode;else return null}}class j{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new j(t.parentNode,ot(t),e)}static after(t,e){return new j(t.parentNode,ot(t)+1,e)}}var L=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(L||(L={}));const pt=L.LTR,ni=L.RTL;function as(n){let t=[];for(let e=0;e<n.length;e++)t.push(1<<+n[e]);return t}const xn=as("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Sn=as("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Fe=Object.create(null),Y=[];for(let n of["()","[]","{}"]){let t=n.charCodeAt(0),e=n.charCodeAt(1);Fe[t]=e,Fe[e]=-t}function hs(n){return n<=247?xn[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?Sn[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const vn=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class ${get dir(){return this.level%2?ni:pt}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let r=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<e:l.to>e:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function cs(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++){let i=n[e],s=t[e];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!cs(i.inner,s.inner))return!1}return!0}const A=[];function Cn(n,t,e,i,s){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:t,l=r<i.length?i[r].from:e,a=r?256:s;for(let h=o,c=a,f=a;h<l;h++){let d=hs(n.charCodeAt(h));d==512?d=c:d==8&&f==4&&(d=16),A[h]=d==4?2:d,d&7&&(f=d),c=d}for(let h=o,c=a,f=a;h<l;h++){let d=A[h];if(d==128)h<l-1&&c==A[h+1]&&c&24?d=A[h]=c:A[h]=256;else if(d==64){let u=h+1;for(;u<l&&A[u]==64;)u++;let p=h&&c==8||u<e&&A[u]==8?f==1?1:8:256;for(let g=h;g<u;g++)A[g]=p;h=u-1}else d==8&&f==1&&(A[h]=1);c=d,d&7&&(f=d)}}}function kn(n,t,e,i,s){let r=s==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let h=o?i[o-1].to:t,c=o<i.length?i[o].from:e;for(let f=h,d,u,p;f<c;f++)if(u=Fe[d=n.charCodeAt(f)])if(u<0){for(let g=l-3;g>=0;g-=3)if(Y[g+1]==-u){let m=Y[g+2],b=m&2?s:m&4?m&1?r:s:0;b&&(A[f]=A[Y[g]]=b),l=g;break}}else{if(Y.length==189)break;Y[l++]=f,Y[l++]=d,Y[l++]=a}else if((p=A[f])==2||p==1){let g=p==s;a=g?0:1;for(let m=l-3;m>=0;m-=3){let b=Y[m+2];if(b&2)break;if(g)Y[m+2]|=2;else{if(b&4)break;Y[m+2]|=4}}}}}function Mn(n,t,e,i){for(let s=0,r=i;s<=e.length;s++){let o=s?e[s-1].to:n,l=s<e.length?e[s].from:t;for(let a=o;a<l;){let h=A[a];if(h==256){let c=a+1;for(;;)if(c==l){if(s==e.length)break;c=e[s++].to,l=s<e.length?e[s].from:t}else if(A[c]==256)c++;else break;let f=r==1,d=(c<t?A[c]:i)==1,u=f==d?f?1:2:i;for(let p=c,g=s,m=g?e[g-1].to:n;p>a;)p==m&&(p=e[--g].from,m=g?e[g-1].to:n),A[--p]=u;a=c}else r=h,a++}}}function Ie(n,t,e,i,s,r,o){let l=i%2?2:1;if(i%2==s%2)for(let a=t,h=0;a<e;){let c=!0,f=!1;if(h==r.length||a<r[h].from){let g=A[a];g!=l&&(c=!1,f=g==16)}let d=!c&&l==1?[]:null,u=c?i:i+1,p=a;t:for(;;)if(h<r.length&&p==r[h].from){if(f)break t;let g=r[h];if(!c)for(let m=g.to,b=h+1;;){if(m==e)break t;if(b<r.length&&r[b].from==m)m=r[b++].to;else{if(A[m]==l)break t;break}}if(h++,d)d.push(g);else{g.from>a&&o.push(new $(a,g.from,u));let m=g.direction==pt!=!(u%2);Ke(n,m?i+1:i,s,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==e||(c?A[p]!=l:A[p]==l))break;p++}d?Ie(n,a,p,i+1,s,d,o):a<p&&o.push(new $(a,p,u)),a=p}else for(let a=e,h=r.length;a>t;){let c=!0,f=!1;if(!h||a>r[h-1].to){let g=A[a-1];g!=l&&(c=!1,f=g==16)}let d=!c&&l==1?[]:null,u=c?i:i+1,p=a;t:for(;;)if(h&&p==r[h-1].to){if(f)break t;let g=r[--h];if(!c)for(let m=g.from,b=h;;){if(m==t)break t;if(b&&r[b-1].to==m)m=r[--b].from;else{if(A[m-1]==l)break t;break}}if(d)d.push(g);else{g.to<a&&o.push(new $(g.to,a,u));let m=g.direction==pt!=!(u%2);Ke(n,m?i+1:i,s,g.inner,g.from,g.to,o),a=g.from}p=g.from}else{if(p==t||(c?A[p-1]!=l:A[p-1]==l))break;p--}d?Ie(n,p,a,i+1,s,d,o):p<a&&o.push(new $(p,a,u)),a=p}}function Ke(n,t,e,i,s,r,o){let l=t%2?2:1;Cn(n,s,r,i,l),kn(n,s,r,i,l),Mn(s,r,i,l),Ie(n,s,r,t,e,i,o)}function An(n,t,e){if(!n)return[new $(0,0,t==ni?1:0)];if(t==pt&&!e.length&&!vn.test(n))return fs(n.length);if(e.length)for(;n.length>A.length;)A[A.length]=256;let i=[],s=t==pt?0:1;return Ke(n,s,s,e,0,n.length,i),i}function fs(n){return[new $(0,n,0)]}let ds="";function Dn(n,t,e,i,s){var r;let o=i.head-n.from,l=$.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=t[l],h=a.side(s,e);if(o==h){let d=l+=s?1:-1;if(d<0||d>=t.length)return null;a=t[l=d],o=a.side(!s,e),h=a.side(s,e)}let c=ct(n.text,o,a.forward(s,e));(c<a.from||c>a.to)&&(c=h),ds=n.text.slice(Math.min(o,c),Math.max(o,c));let f=l==(s?t.length-1:0)?null:t[l+(s?1:-1)];return f&&c==h&&f.level+(s?0:1)<a.level?v.cursor(f.side(!s,e)+n.from,f.forward(s,e)?1:-1,f.level):v.cursor(c+n.from,a.forward(s,e)?-1:1,a.level)}function On(n,t,e){for(let i=t;i<e;i++){let s=hs(n.charCodeAt(i));if(s==1)return pt;if(s==2||s==4)return ni}return pt}const us=k.define(),ps=k.define(),gs=k.define(),ms=k.define(),ze=k.define(),bs=k.define(),ys=k.define(),ri=k.define(),oi=k.define(),ws=k.define({combine:n=>n.some(t=>t)}),xs=k.define({combine:n=>n.some(t=>t)}),Ss=k.define();class Mt{constructor(t,e,i,s,r,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=o}map(t){return t.empty?this:new Mt(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 Mt(v.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Qt=Bt.define({map:(n,t)=>n.map(t)}),vs=Bt.define();function Z(n,t,e){let i=n.facet(ms);i.length?i[0](t):window.onerror&&window.onerror(String(t),e,void 0,void 0,t)||(e?console.error(e+":",t):console.error(t))}const J=k.define({combine:n=>n.length?n[0]:!0});let Tn=0;const St=k.define({combine(n){return n.filter((t,e)=>{for(let i=0;i<e;i++)if(n[i].plugin==t.plugin)return!1;return!0})}});class it{constructor(t,e,i,s,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(St.of({plugin:this,arg:void 0}))}of(t){return this.baseExtensions.concat(St.of({plugin:this,arg:t}))}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:r,decorations:o}=e||{};return new it(Tn++,t,i,s,l=>{let a=[];return o&&a.push(ye.of(h=>{let c=h.plugin(l);return c?o(c):R.none})),r&&a.push(r(l)),a})}static fromClass(t,e){return it.define((i,s)=>new t(i,s),e)}}class Ce{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(Z(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(t,this.spec.arg)}catch(e){Z(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){Z(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Cs=k.define(),li=k.define(),ye=k.define(),ks=k.define(),ai=k.define(),Yt=k.define(),Ms=k.define();function wi(n,t){let e=n.state.facet(Ms);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(n):r),s=[];return E.spans(i,t.from,t.to,{point(){},span(r,o,l,a){let h=r-t.from,c=o-t.from,f=s;for(let d=l.length-1;d>=0;d--,a--){let u=l[d].spec.bidiIsolate,p;if(u==null&&(u=On(t.text,h,c)),a>0&&f.length&&(p=f[f.length-1]).to==h&&p.direction==u)p.to=c,f=p.inner;else{let g={from:h,to:c,direction:u,inner:[]};f.push(g),f=g.inner}}}}),s}const As=k.define();function Ds(n){let t=0,e=0,i=0,s=0;for(let r of n.state.facet(As)){let o=r(n);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:t,right:e,top:i,bottom:s}}const Rt=k.define();class z{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new z(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,r=0,o=0;;){let l=s<t.length?t[s].fromB:1e9,a=r<e.length?e[r]:1e9,h=Math.min(l,a);if(h==1e9)break;let c=h+o,f=h,d=c;for(;;)if(r<e.length&&e[r]<=f){let u=e[r+1];r+=2,f=Math.max(f,u);for(let p=s;p<t.length&&t[p].fromB<=f;p++)o=t[p].toA-t[p].toB;d=Math.max(d,u+o)}else if(s<t.length&&t[s].fromB<=f){let u=t[s++];f=Math.max(f,u.toB),d=Math.max(d,u.toA),o=u.toA-u.toB}else break;i.push(new z(c,d,h,f))}return i}}class fe{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=Ui.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,o,l,a)=>s.push(new z(r,o,l,a))),this.changedRanges=s}static create(t,e,i){return new fe(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const Bn=[];class B{constructor(t,e,i=0){this.dom=t,this.length=e,this.flags=i,this.parent=null,t.cmTile=this}get breakAfter(){return this.flags&1}get children(){return Bn}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(t){if(this.flags|=2,this.flags&4){this.flags&=-5;let e=this.domAttrs;e&&dn(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(t){this.dom=t,t.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t,e=this.posAtStart){let i=e;for(let s of this.children){if(s==t)return i;i+=s.length+s.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}covers(t){return!0}coordsIn(t,e,i){return null}domPosFor(t,e){let i=ot(this.dom),s=this.length?t>0:e>0;return new j(this.parent.dom,i+(s?1:0),t==0||t==this.length)}markDirty(t){this.flags&=-3,t&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let t=this;t;t=t.parent)if(t instanceof xe)return t;return null}static get(t){return t.cmTile}}class we extends B{constructor(t){super(t,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(t){this.children.push(t),t.parent=this}sync(t){if(this.flags&2)return;super.sync(t);let e=this.dom,i=null,s,r=t?.node==e?t:null,o=0;for(let l of this.children){if(l.sync(t),o+=l.length+l.breakAfter,s=i?i.nextSibling:e.firstChild,r&&s!=l.dom&&(r.written=!0),l.dom.parentNode==e)for(;s&&s!=l.dom;)s=xi(s);else e.insertBefore(l.dom,s);i=l.dom}for(s=i?i.nextSibling:e.firstChild,r&&s&&(r.written=!0);s;)s=xi(s);this.length=o}}function xi(n){let t=n.nextSibling;return n.parentNode.removeChild(n),t}class xe extends we{constructor(t,e){super(e),this.view=t}owns(t){for(;t;t=t.parent)if(t==this)return!0;return!1}isBlock(){return!0}nearest(t){for(;;){if(!t)return null;let e=B.get(t);if(e&&this.owns(e))return e;t=t.parentNode}}blockTiles(t){for(let e=[],i=this,s=0,r=0;;)if(s==i.children.length){if(!e.length)return;i=i.parent,i.breakAfter&&r++,s=e.pop()}else{let o=i.children[s++];if(o instanceof tt)e.push(s),i=o,s=0;else{let l=r+o.length,a=t(o,r);if(a!==void 0)return a;r=l+o.breakAfter}}}resolveBlock(t,e){let i,s=-1,r,o=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(t>=a&&t<=h){if(l.isWidget()&&e>=-1&&e<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(a<t||t==h&&(e<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,s=t-a),(h>t||t==a&&(e>1?l.length:l.covers(-1)))&&(!r||!l.isWidget()&&r.isWidget())&&(r=l,o=t-a)}}),!i&&!r)throw new Error("No tile at position "+t);return i&&e<0||!r?{tile:i,offset:s}:{tile:r,offset:o}}}class tt extends we{constructor(t,e){super(t),this.wrapper=e}isBlock(){return!0}covers(t){return this.children.length?t<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(t,e){let i=new tt(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class Dt extends we{constructor(t,e){super(t),this.attrs=e}isLine(){return!0}static start(t,e,i){let s=new Dt(e||document.createElement("div"),t);return(!e||!i)&&(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(t,e,i){let s=null,r=-1,o=null,l=-1;function a(c,f){for(let d=0,u=0;d<c.children.length&&u<=f;d++){let p=c.children[d],g=u+p.length;g>=f&&(p.isComposite()?a(p,f-u):(!o||o.isHidden&&(e>0&&!(o.flags&32)||i&&Rn(o,p)))&&(g>f||p.flags&32&&e<=1)?(o=p,l=f-u):(u<f||p.flags&16&&!p.isHidden&&e>=-1)&&(s=p,r=f-u)),u=g}}a(this,t);let h=(e<0?s:o)||s||o;return h?{tile:h,offset:h==s?r:l}:null}coordsIn(t,e,i){let s=this.resolveInline(t,e,!0);return s?s.tile.coordsIn(Math.max(0,s.offset),e,i):Ln(this)}domIn(t,e){let i=this.resolveInline(t,e);if(i){let{tile:s,offset:r}=i;if(this.dom.contains(s.dom))return s.isText()?new j(s.dom,Math.min(s.dom.nodeValue.length,r)):s.domPosFor(r,s.flags&16?1:s.flags&32?-1:e);let o=i.tile.parent,l=!1;for(let a of o.children){if(l)return new j(a.dom,0);a==i.tile&&(l=!0)}}return new j(this.dom,0)}}function Ln(n){let t=n.dom.lastChild;if(!t)return n.dom.getBoundingClientRect();let e=Nt(t);return e[e.length-1]||null}function Rn(n,t){let e=n.coordsIn(0,1),i=t.coordsIn(0,1);return e&&i&&i.top<e.bottom}class F extends we{constructor(t,e){super(t),this.mark=e}get domAttrs(){return this.mark.attrs}static of(t,e){let i=new F(e||document.createElement(t.tagName),t);return e||(i.flags|=4),i}}class ft extends B{constructor(t,e){super(t,e.length),this.text=e}sync(t){this.flags&2||(super.sync(t),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(t,e,i){let s=this.dom.nodeValue.length;t>s&&(t=s);let r=t,o=t,l=0;t==0&&e<0||t==s&&e>=0?y.chrome||y.gecko||(t?(r--,l=1):o<s&&(o++,l=-1)):e<0?r--:o<s&&o++;let a=qt(this.dom,r,o).getClientRects();if(!a.length)return null;let h=a[(l?l<0:e>=0)?0:a.length-1];return y.safari&&!l&&h.width==0&&(h=Array.prototype.find.call(a,c=>c.width)||h),i==null?h:zt(h,(l?l>0:e<0)==i)}static of(t,e){let i=new ft(e||document.createTextNode(t),t);return e||(i.flags|=2),i}}class gt extends B{constructor(t,e,i,s){super(t,e,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(t){return this.flags&48?!1:(this.flags&(t<0?64:128))>0}coordsIn(t,e){return this.coordsInWidget(t,e,!1)}coordsInWidget(t,e,i){let s=this.widget.coordsAt(this.dom,t,e);if(s)return s;if(i)return zt(this.dom.getBoundingClientRect(),this.length?t==0:e<=0);{let r=this.dom.getClientRects(),o=null;if(!r.length)return null;let l=this.flags&16?!0:this.flags&32?!1:t>0;for(let a=l?r.length-1:0;o=r[a],!(t>0?a==0:a==r.length-1||o.top<o.bottom);a+=l?-1:1);return zt(o,!l)}}get overrideDOMText(){if(!this.length)return K.empty;let{root:t}=this;if(!t)return K.empty;let e=this.posAtStart;return t.view.state.doc.slice(e,e+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,e,i,s,r){return r||(r=t.toDOM(e),t.editable||(r.contentEditable="false")),new gt(r,i,t,s)}}class de extends B{constructor(t){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),super(e,0,t)}get isHidden(){return!0}get overrideDOMText(){return K.empty}coordsIn(t,e,i){let s=this.dom.getBoundingClientRect();return i==null?s:zt(s,e>0==i)}}class En{constructor(t){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=t}advance(t,e,i){let{tile:s,index:r,beforeBreak:o,parents:l}=this;for(;t||e>0;)if(s.isComposite())if(o){if(!t)break;i&&i.break(),t--,o=!1}else if(r==s.children.length){if(!t&&!l.length)break;i&&i.leave(s),o=!!s.breakAfter,{tile:s,index:r}=l.pop(),r++}else{let a=s.children[r],h=a.breakAfter;(e>0?a.length<=t:a.length<t)&&(!i||i.skip(a,0,a.length)!==!1||!a.isComposite)?(o=!!h,r++,t-=a.length):(l.push({tile:s,index:r}),s=a,r=0,i&&a.isComposite()&&i.enter(a))}else{let a=s.length;if(r<a&&t){let h=Math.min(t,a-r);i&&i.skip(s,r,r+h),t-=h,r+=h}if(r==a)o=!!s.breakAfter,{tile:s,index:r}=l.pop(),r++;else if(!t)break}return this.tile=s,this.index=r,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class Wn{constructor(t,e,i,s){this.from=t,this.to=e,this.wrapper=i,this.rank=s}}class Hn{constructor(t,e,i){this.cache=t,this.root=e,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(t,e,i,s){var r;this.flushBuffer();let o=this.ensureMarks(e,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+t.length<512){this.cache.reused.set(l,2);let a=o.children[o.children.length-1]=new ft(l.dom,l.text+t);a.parent=o}else o.append(s||ft.of(t,(r=this.cache.find(ft))===null||r===void 0?void 0:r.dom));this.pos+=t.length,this.afterWidget=null}addComposition(t,e){let i=this.curLine;i.dom!=e.line.dom&&(i.setDOM(this.cache.reused.has(e.line)?ke(e.line.dom):e.line.dom),this.cache.reused.set(e.line,2));let s=i;for(let l=e.marks.length-1;l>=0;l--){let a=e.marks[l],h=s.lastChild;if(h instanceof F&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM(ke(a.dom)),s=h;else{if(this.cache.reused.get(a)){let f=B.get(a.dom);f&&f.setDOM(ke(a.dom))}let c=F.of(a.mark,a.dom);s.append(c),s=c}this.cache.reused.set(a,2)}let r=B.get(t.text);r&&this.cache.reused.set(r,2);let o=new ft(t.text,t.text.nodeValue);o.flags|=8,this.pos=t.range.toB,s.append(o)}addInlineWidget(t,e,i){let s=this.afterWidget&&t.flags&48&&(this.afterWidget.flags&48)==(t.flags&48);s||this.flushBuffer();let r=this.ensureMarks(e,i);!s&&!(t.flags&16)&&r.append(this.getBuffer(1)),r.append(t),this.pos+=t.length,this.afterWidget=t}addMark(t,e,i){this.flushBuffer(),this.ensureMarks(e,i).append(t),this.pos+=t.length,this.afterWidget=null}addBlockWidget(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}continueWidget(t){let e=this.afterWidget||this.lastBlock;e.length+=t,this.pos+=t}addLineStart(t,e){var i;t||(t=Os);let s=Dt.start(t,e||((i=this.cache.find(Dt))===null||i===void 0?void 0:i.dom),!!e);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(t){this.getBlockPos().append(t),this.pos+=t.length,this.lastBlock=t,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(t){this.blockPosCovered()||this.addLineStart(t)}ensureLine(t){this.curLine||this.addLineStart(t)}ensureMarks(t,e){var i;let s=this.curLine;for(let r=t.length-1;r>=0;r--){let o=t[r],l;if(e>0&&(l=s.lastChild)&&l instanceof F&&l.mark.eq(o))s=l,e--;else{let a=F.of(o,(i=this.cache.find(F,h=>h.mark.eq(o)))===null||i===void 0?void 0:i.dom);s.append(a),s=a,e=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let t=this.curLine.lastChild;(!t||!Si(this.curLine,!1)||t.dom.nodeName!="BR"&&t.isWidget()&&!(y.ios&&Si(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Me,0,32)||new gt(Me.toDOM(),0,Me,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let t=this.wrappers.length-1;t>=0;t--)this.wrappers[t].to<this.pos&&this.wrappers.splice(t,1);for(let t=this.blockWrappers;t.value&&t.from<=this.pos;t.next())if(t.to>=this.pos){let e=t.rank*102+t.value.rank,i=new Wn(t.from,t.to,t.value,e),s=this.wrappers.length;for(;s>0&&(this.wrappers[s-1].rank-i.rank||this.wrappers[s-1].to-i.to)<0;)s--;this.wrappers.splice(s,0,i)}this.wrapperPos=this.pos}getBlockPos(){var t;this.updateBlockWrappers();let e=this.root;for(let i of this.wrappers){let s=e.lastChild;if(i.from<this.pos&&s instanceof tt&&s.wrapper.eq(i.wrapper))e=s;else{let r=tt.of(i.wrapper,(t=this.cache.find(tt,o=>o.wrapper.eq(i.wrapper)))===null||t===void 0?void 0:t.dom);e.append(r),e=r}}return e}blockPosCovered(){let t=this.lastBlock;return t!=null&&!t.breakAfter&&(!t.isWidget()||(t.flags&160)>0)}getBuffer(t){let e=2|(t<0?16:32),i=this.cache.find(de,void 0,1);return i&&(i.flags=e),i||new de(e)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class Pn{constructor(t){this.skipCount=0,this.text="",this.textOff=0,this.cursor=t.iter()}skip(t){this.textOff+t<=this.text.length?this.textOff+=t:(this.skipCount+=t-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(t){if(this.textOff==this.text.length){let{value:s,lineBreak:r,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=s;let l=this.textOff=Math.min(t,s.length);return r?null:s.slice(0,l)}let e=Math.min(this.text.length,this.textOff+t),i=this.text.slice(this.textOff,e);return this.textOff=e,i}}const ue=[gt,Dt,ft,F,de,tt,xe];for(let n=0;n<ue.length;n++)ue[n].bucket=n;class Nn{constructor(t){this.view=t,this.buckets=ue.map(()=>[]),this.index=ue.map(()=>0),this.reused=new Map}add(t){let e=t.constructor.bucket,i=this.buckets[e];i.length<6?i.push(t):i[this.index[e]=(this.index[e]+1)%6]=t}find(t,e,i=2){let s=t.bucket,r=this.buckets[s],o=this.index[s];for(let l=0;l<r.length;l++){let a=(l+o)%r.length,h=r[a];if((!e||e(h))&&!this.reused.has(h))return r.splice(a,1),a<o&&this.index[s]--,this.reused.set(h,i),h}return null}findWidget(t,e,i){let s=this.buckets[0];if(s.length)for(let r=0,o=0;;r++){if(r==s.length){if(o)return null;o=1,r=0}let l=s[r];if(!this.reused.has(l)&&(o==0?l.widget.compare(t):l.widget.constructor==t.constructor&&t.updateDOM(l.dom,this.view,l.widget)))return s.splice(r,1),r<this.index[0]&&this.index[0]--,l.widget==t&&l.length==e&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new gt(l.dom,e,t,l.flags&-498|i))}}reuse(t){return this.reused.set(t,1),t}maybeReuse(t,e=2){if(!this.reused.has(t))return this.reused.set(t,e),t.dom}clear(){for(let t=0;t<this.buckets.length;t++)this.buckets[t].length=this.index[t]=0}}class Vn{constructor(t,e,i,s,r){this.view=t,this.decorations=s,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new Nn(t),this.text=new Pn(t.state.doc),this.builder=new Hn(this.cache,new xe(t,t.contentDOM),E.iter(i)),this.cache.reused.set(e,2),this.old=new En(e),this.reuseWalker={skip:(o,l,a)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(t,e){let i=e&&this.getCompositionContext(e.text);for(let s=0,r=0,o=0;;){let l=o<t.length?t[o++]:null,a=l?l.fromA:this.old.root.length;if(a>s){let h=a-s;this.preserve(h,!o,!l),s=a,r+=h}if(!l)break;e&&l.fromA<=e.range.fromA&&l.toA>=e.range.toA?(this.forward(l.fromA,e.range.fromA,e.range.fromA<e.range.toA?1:-1),this.emit(r,e.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(e,i),this.text.skip(e.range.toB-e.range.fromB),this.forward(e.range.fromA,l.toA),this.emit(e.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(r,l.toB)),r=l.toB,s=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(t,e,i){let s=Kn(this.old),r=this.openMarks;this.old.advance(t,i?1:-1,{skip:(o,l,a)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<o.length?gt.of(o.widget,this.view,a-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,s,r),r=s.length)}else if(o.isText())this.builder.ensureLine(null),!l&&a==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,s,r,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,a),s,r)),r=s.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof de)this.cache.add(o);else if(o instanceof F)this.builder.ensureLine(null),this.builder.addMark(o,s,r),this.cache.reused.set(o,1),r=s.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof F&&s.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?s.length&&(s.length=r=0):o instanceof F&&(s.shift(),r=Math.min(r,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(t)}emit(t,e){let i=null,s=this.builder,r=-1,o=E.spans(this.decorations,t,e,{point:(l,a,h,c,f,d)=>{if(h instanceof ut){if(this.disallowBlockEffectsFor[d]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=c.length,f>c.length)s.continueWidget(a-l);else{let u=h.widget||(h.block?Ot.block:Ot.inline),p=Fn(h),g=this.cache.findWidget(u,a-l,p)||gt.of(u,this.view,a-l,p);h.block?(h.startSide>0&&s.addLineStartIfNotCovered(i),s.addBlockWidget(g)):(s.ensureLine(i),s.addInlineWidget(g,c,f))}i=null}else i=In(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let f=l;f<a;){let d=this.text.next(Math.min(512,a-f));d==null?(s.addLineStartIfNotCovered(i),s.addBreak(),f++):(s.ensureLine(i),s.addText(d,h,f==l?c:h.length),f+=d.length),i=null}r=h.length}});r>-1&&(this.openWidget=o>r),this.openWidget||s.addLineStartIfNotCovered(i),this.openMarks=o}forward(t,e,i=1){e-t<=10?this.old.advance(e-t,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(e-t-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(t){let e=[],i=null;for(let s=t.parentNode;;s=s.parentNode){let r=B.get(s);if(s==this.view.contentDOM)break;r instanceof F?e.push(r):r?.isLine()?i=r:r instanceof tt||(s.nodeName=="DIV"&&!i&&s!=this.view.contentDOM?i=new Dt(s,Os):i||e.push(F.of(new Gt({tagName:s.nodeName.toLowerCase(),attributes:un(s)}),s)))}return{line:i,marks:e}}}function Si(n,t){let e=i=>{for(let s of i.children)if((t?s.isText():s.length)||e(s))return!0;return!1};return e(n)}function Fn(n){let t=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(t|=256),t}const Os={class:"cm-line"};function In(n,t){let e=t.spec.attributes,i=t.spec.class;return!e&&!i||(n||(n={class:"cm-line"}),e&&ii(e,n),i&&(n.class+=" "+i)),n}function Kn(n){let t=[];for(let e=n.parents.length;e>1;e--){let i=e==n.parents.length?n.tile:n.parents[e].tile;i instanceof F&&t.push(i.mark)}return t}function ke(n){let t=B.get(n);return t&&t.setDOM(n.cloneNode()),n}class Ot extends jt{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}}Ot.inline=new Ot("span");Ot.block=new Ot("div");const Me=new class extends jt{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class vi{constructor(t){this.view=t,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=R.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new xe(t,t.contentDOM),this.updateInner([new z(0,0,0,t.state.doc.length)],null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:f})=>f<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?s=this.domChanged.newSel.head:!Un(t.changes,this.hasComposition)&&!t.selectionSet&&(s=t.state.selection.main.head));let r=s>-1?qn(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:f}=this.hasComposition;i=new z(c,f,t.changes.mapPos(c,-1),t.changes.mapPos(f,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(y.ie||y.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let a=_n(o,this.decorations,t.changes);a.length&&(i=z.extendWithRanges(i,a));let h=Xn(l,this.blockWrappers,t.changes);return h.length&&(i=z.extendWithRanges(i,h)),r&&!i.some(c=>c.fromA<=r.range.fromA&&c.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(e||t.length){let o=this.tile,l=new Vn(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);e&&B.get(e.text)&&l.cache.reused.set(B.get(e.text),2),this.tile=l.run(t,e),qe(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let r=y.chrome||y.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.tile.children)r.isWidget()&&r.widget instanceof Ae&&s.push(r.dom);i.updateGaps(s)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(vs)&&(this.editContextFormatting=i.value)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,r=s==i,o=!r&&!(this.view.state.facet(J)||i.tabIndex>-1)&&Pt(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(r||e||o))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),y.gecko&&a.empty&&!this.hasComposition&&zn(h)){let d=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(d,h.node.childNodes[h.offset]||null)),h=c=new j(d,0),l=!0}let f=this.view.observer.selectionRange;(l||!f.focusNode||(!Vt(h.node,h.offset,f.anchorNode,f.anchorOffset)||!Vt(c.node,c.offset,f.focusNode,f.focusOffset))&&!this.suppressWidgetCursorChange(f,a))&&(this.view.observer.ignore(()=>{y.android&&y.chrome&&i.contains(f.focusNode)&&$n(f.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let d=Kt(this.view.root);if(d)if(a.empty){if(y.gecko){let u=jn(h.node,h.offset);if(u&&u!=3){let p=(u==1?os:ls)(h.node,h.offset);p&&(h=new j(p.node,p.offset))}}d.collapse(h.node,h.offset),a.bidiLevel!=null&&d.caretBidiLevel!==void 0&&(d.caretBidiLevel=a.bidiLevel)}else if(d.extend){d.collapse(h.node,h.offset);try{d.extend(c.node,c.offset)}catch{}}else{let u=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),u.setEnd(c.node,c.offset),u.setStart(h.node,h.offset),d.removeAllRanges(),d.addRange(u)}o&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new j(f.anchorNode,f.anchorOffset),this.impreciseHead=c.precise?null:new j(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&Vt(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=Kt(t.root),{anchorNode:s,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=this.lineAt(e.head,e.assoc);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 c=this.domAtPos(e.head+e.assoc,e.assoc);i.collapse(c.node,c.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(s,r)}posFromDOM(t,e){let i=this.tile.nearest(t);if(!i)return this.tile.dom.compareDocumentPosition(t)&2?0:this.view.state.doc.length;let s=i.posAtStart;if(i.isComposite()){let r;if(t==i.dom)r=i.dom.childNodes[e];else{let o=et(t)==0?0:e==0?-1:1;for(;;){let l=t.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(t==l.firstChild?o=-1:o=1),t=l}o<0?r=t:r=t.nextSibling}if(r==i.dom.firstChild)return s;for(;r&&!B.get(r);)r=r.nextSibling;if(!r)return s+i.length;for(let o=0,l=s;;o++){let a=i.children[o];if(a.dom==r)return l;l+=a.length+a.breakAfter}}else return i.isText()?t==i.dom?s+e:s+(e?i.length:0):s}domAtPos(t,e){let{tile:i,offset:s}=this.tile.resolveBlock(t,e);return i.isWidget()?i.domPosFor(s,e):i.domIn(s,e)}inlineDOMNearPos(t,e){let i,s=-1,r=!1,o,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=t)return!0;h.flags&16&&(r=!0)}else{let f=c+h.length;if(c<=t&&(i=h,s=t-c,r=f<t),f>=t&&!o&&(o=h,l=t-c,a=c>t),c>t&&o)return!0}}),!i&&!o?this.domAtPos(t,e):(r&&o?i=null:a&&i&&(o=null),i&&e<0||!o?i.domIn(s,e):o.domIn(l,e))}coordsAt(t,e,i){let{tile:s,offset:r}=this.tile.resolveBlock(t,e);return s.isWidget()?s.widget instanceof Ae?null:s.coordsInWidget(r,e,!0):s.coordsIn(r,e,i)}lineAt(t,e){let{tile:i}=this.tile.resolveBlock(t,e);return i.isLine()?i:null}coordsForChar(t){let{tile:e,offset:i}=this.tile.resolveBlock(t,1);if(!e.isLine())return null;function s(r,o){if(r.isComposite())for(let l of r.children){if(l.length>=o){let a=s(l,o);if(a)return a}if(o-=l.length,o<0)break}else if(r.isText()&&o<r.length){let l=ct(r.text,o);if(l==o)return null;let a=qt(r.dom,o,l).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(h==a.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return s(e,i)}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==L.LTR,h=0,c=(f,d,u)=>{for(let p=0;p<f.children.length&&!(d>s);p++){let g=f.children[p],m=d+g.length,b=g.dom.getBoundingClientRect(),{height:w}=b;if(u&&!p&&(h+=b.top-u.top),g instanceof tt)m>i&&c(g,d,b);else if(d>=i&&(h>0&&e.push(-h),e.push(w+h),h=0,o)){let x=g.dom.lastChild,O=x?Nt(x):[];if(O.length){let C=O[O.length-1],S=a?C.right-b.left:b.right-C.left;S>l&&(l=S,this.minWidth=r,this.minWidthFrom=d,this.minWidthTo=m)}}u&&p==f.children.length-1&&(h+=u.bottom-b.bottom),d=m+g.breakAfter}};return c(this.tile,0,null),e}textDirectionAt(t){let{tile:e}=this.tile.resolveBlock(t,1);return getComputedStyle(e.dom).direction=="rtl"?L.RTL:L.LTR}measureTextSize(){let t=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,a;for(let h of o.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=Nt(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:a}}});if(t)return t;let e=document.createElement("div"),i,s,r;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(e);let o=Nt(e.firstChild)[0];i=e.getBoundingClientRect().height,s=o&&o.width?o.width/27:7,r=o&&o.height?o.height:i,e.remove()}),{lineHeight:i,charWidth:s,textHeight:r}}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],o=r?r.from-1:this.view.state.doc.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(R.replace({widget:new Ae(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return R.set(t)}updateDeco(){let t=1,e=this.view.state.facet(ye).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,s=this.view.state.facet(ai).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(E.join(s))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;this.blockWrappers=this.view.state.facet(ks).map(r=>typeof r=="function"?r(this.view):r)}scrollIntoView(t){if(t.isSnapshot){let h=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=h.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let h of this.view.state.facet(Ss))try{if(h(this.view,t.range,t))return!0}catch(c){Z(this.view.state,c,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.assoc||(e.head>e.anchor?-1:1)),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=Ds(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;if(mn(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,a),-a),this.view.textDirection==L.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(i.top>window.visualViewport.offsetTop+window.visualViewport.height||i.bottom<window.visualViewport.offsetTop)){let h=this.view.docView.lineAt(e.head,1);if(h){let c=is(h.dom);h.dom.scrollIntoView({block:"nearest"}),ss(c,!1)}}}lineHasWidget(t){let e=i=>i.isWidget()||i.children.some(e);return e(this.tile.resolveBlock(t,1).tile)}destroy(){qe(this.tile)}}function qe(n,t){let e=t?.get(n);if(e!=1){e==null&&n.destroy();for(let i of n.children)qe(i,t)}}function zn(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function Ts(n,t){let e=n.observer.selectionRange;if(!e.focusNode)return null;let i=os(e.focusNode,e.focusOffset),s=ls(e.focusNode,e.focusOffset),r=i||s;if(s&&i&&s.node!=i.node){let l=B.get(s.node);if(!l||l.isText()&&l.text!=s.node.nodeValue)r=s;else if(n.docView.lastCompositionAfterCursor){let a=B.get(i.node);!a||a.isText()&&a.text!=i.node.nodeValue||(r=s)}}if(n.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=t-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function qn(n,t,e){let i=Ts(n,e);if(!i)return null;let{node:s,from:r,to:o}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=t.invertedDesc;return{range:new z(a.mapPos(r),a.mapPos(o),r,o),text:s}}function jn(n,t){return n.nodeType!=1?0:(t&&n.childNodes[t-1].contentEditable=="false"?1:0)|(t<n.childNodes.length&&n.childNodes[t].contentEditable=="false"?2:0)}let Gn=class{constructor(){this.changes=[]}compareRange(t,e){Ct(t,e,this.changes)}comparePoint(t,e){Ct(t,e,this.changes)}boundChange(t){Ct(t,t,this.changes)}};function _n(n,t,e){let i=new Gn;return E.compare(n,t,e,i),i.changes}class Yn{constructor(){this.changes=[]}compareRange(t,e){Ct(t,e,this.changes)}comparePoint(){}boundChange(t){Ct(t,t,this.changes)}}function Xn(n,t,e){let i=new Yn;return E.compare(n,t,e,i),i.changes}function $n(n,t){for(let e=n;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function Un(n,t){let e=!1;return t&&n.iterChangedRanges((i,s)=>{i<t.to&&s>t.from&&(e=!0)}),e}class Ae extends jt{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Qn(n,t,e=1){let i=n.charCategorizer(t),s=n.doc.lineAt(t),r=t-s.from;if(s.length==0)return v.cursor(t);r==0?e=1:r==s.length&&(e=-1);let o=r,l=r;e<0?o=ct(s.text,r,!1):l=ct(s.text,r);let a=i(s.text.slice(o,l));for(;o>0;){let h=ct(s.text,o,!1);if(i(s.text.slice(h,o))!=a)break;o=h}for(;l<s.length;){let h=ct(s.text,l);if(i(s.text.slice(l,h))!=a)break;l=h}return v.undirectionalRange(o+s.from,l+s.from)}function Jn(n,t,e,i,s){let r=Math.round((i-t.left)*n.defaultCharacterWidth);if(n.lineWrapping&&e.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-e.top-(n.defaultLineHeight-l)*.5)/l);r+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(e.from,e.to);return e.from+nn(o,r,n.state.tabSize)}function je(n,t,e){let i=n.lineBlockAt(t);if(Array.isArray(i.type)){let s;for(let r of i.type){if(r.from>t)break;if(!(r.to<t)){if(r.from<t&&r.to>t)return r;(!s||r.type==H.Text&&(s.type!=r.type||(e<0?r.from<t:r.to>t)))&&(s=r)}}return s||i}return i}function Zn(n,t,e,i){let s=je(n,t.head,t.assoc||-1),r=!i||s.type!=H.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:e==(l==L.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return v.cursor(a,e?-1:1)}return v.cursor(e?s.to:s.from,e?-1:1)}function Ci(n,t,e,i){let s=n.state.doc.lineAt(t.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=t,a=null;;){let h=Dn(s,r,o,l,e),c=ds;if(!h){if(s.number==(e?n.state.doc.lines:1))return l;c=`
2
+ `,s=n.state.doc.line(s.number+(e?1:-1)),r=n.bidiSpans(s),h=n.visualLineSide(s,!e)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function tr(n,t,e){let i=n.state.charCategorizer(t),s=i(e);return r=>{let o=i(r);return s==an.Space&&(s=o),s==o}}function er(n,t,e,i){let s=t.head,r=e?1:-1;if(s==(e?n.state.doc.length:0))return v.cursor(s,t.assoc);let o=t.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s,t.assoc||((t.empty?e:t.head==t.from)?1:-1)),c=n.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let p=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-p.from))),l=(r<0?p.top:p.bottom)+c}let f=a.left+o,d=n.viewState.heightOracle.textHeight>>1,u=i??d;for(let p=0;;p+=d){let g=l+(u+p)*r,m=Ge(n,{x:f,y:g},!1,r);if(e?g>a.bottom:g<a.top)return v.cursor(m.pos,m.assoc);let b=n.coordsAtPos(m.pos,m.assoc),w=b?(b.top+b.bottom)/2:0;if(!b||(e?w>l:w<l))return v.cursor(m.pos,m.assoc,void 0,o)}}function Ft(n,t,e){for(;;){let i=0;for(let s of n)s.between(t-1,t+1,(r,o,l)=>{if(t>r&&t<o){let a=i||e||(t-r<o-t?-1:1);t=a<0?r:o,i=a}});if(!i)return t}}function Bs(n,t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],r=null;if(s.empty){let o=Ft(n,s.from,0);o!=s.from&&(r=v.cursor(o,-1))}else{let o=Ft(n,s.from,-1),l=Ft(n,s.to,1);(o!=s.from||l!=s.to)&&(s.undirectional?r=v.undirectionalRange(s.from,s.to):r=v.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}r&&(e||(e=t.ranges.slice()),e[i]=r)}return e?v.create(e,t.mainIndex):t}function De(n,t,e){let i=Ft(n.state.facet(Yt).map(s=>s(n)),e.from,t.head>e.from?-1:1);return i==e.from?e:v.cursor(i,i<e.from?1:-1)}class X{constructor(t,e){this.pos=t,this.assoc=e}}function Ge(n,t,e,i){let s=n.contentDOM.getBoundingClientRect(),r=s.top+n.viewState.paddingTop,{x:o,y:l}=t,a=l-r,h;for(;;){if(a<0)return new X(0,1);if(a>n.viewState.docHeight)return new X(n.state.doc.length,-1);if(h=n.elementAtHeight(a),i==null)break;if(h.type==H.Text){if(i<0?h.to<n.viewport.from:h.from>n.viewport.to)break;let d=n.docView.coordsAt(i<0?h.from:h.to,i>0?-1:1);if(d&&(i<0?d.top<=a+r:d.bottom>=a+r))break}let f=n.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+f:h.top-f}if(n.viewport.from>=h.to||n.viewport.to<=h.from){if(e)return null;if(h.type==H.Text){let f=Jn(n,s,h,o,l);return new X(f,f==h.from?1:-1)}}if(h.type!=H.Text)return a<(h.top+h.bottom)/2?new X(h.from,1):new X(h.to,-1);let c=n.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=n.docView.lineAt(h.from,-2)),new ir(n,o,l,n.textDirectionAt(h.from)).scanTile(c,h.from)}class ir{constructor(t,e,i,s){this.view=t,this.x=e,this.y=i,this.baseDir=s,this.line=null,this.spans=null}bidiSpansAt(t){return(!this.line||this.line.from>t||this.line.to<t)&&(this.line=this.view.state.doc.lineAt(t),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(t,e){let{line:i,spans:s}=this.bidiSpansAt(t);return s[$.find(s,t-i.from,-1,e)].level==this.baseDir}dirAt(t,e){let{line:i,spans:s}=this.bidiSpansAt(t);return s[$.find(s,t-i.from,-1,e)].dir}bidiIn(t,e){let{spans:i,line:s}=this.bidiSpansAt(t);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+s.from<e)}scan(t,e,i=!1){let s=0,r=t.length-1,o=new Set,l=this.bidiIn(t[0],t[r]),a,h,c=-1,f=1e9,d;t:for(;s<r;){let p=r-s,g=s+r>>1;e:if(o.has(g)){for(let w=1;w<p;w++){let x=g+w;if(x>=r&&(x-=p),!o.has(x)){g=x;break e}}break t}o.add(g);let m=e(g),b=0;if(m)for(let w=0;w<m.length;w++){let x=m[w];if(!(x.width==0&&m.length>1))if(x.bottom<this.y)(!a||a.bottom<x.bottom)&&(a=x),b=1;else if(x.top>this.y)(!h||h.top>x.top)&&(h=x),b=-1;else{let O=x.left>this.x?this.x-x.left:x.right<this.x?this.x-x.right:0,C=Math.abs(O);C<f&&(c=g,f=C,d=x),O&&(b=O<0==(this.baseDir==L.LTR)?-1:1)}}b==-1&&(!l||this.baseDirAt(t[g],1))?r=g:b==1&&(!l||this.baseDirAt(t[g+1],-1))&&(s=g+1)}if(!d){if(!h&&!a)return{i:t[0],after:!1};let p=a&&(!h||this.y-a.bottom<h.top-this.y)?a:h;return this.y=(p.top+p.bottom)/2,this.scan(t,e,!0)}if(f&&!i){let{top:p,bottom:g}=d;if(a&&a.bottom>(p+p+g)/3)return this.y=a.bottom-1,this.scan(t,e,!0);if(h&&h.top<(p+g+g)/3)return this.y=h.top+1,this.scan(t,e,!0)}let u=(l?this.dirAt(t[c],1):this.baseDir)==L.LTR;return{i:c,after:this.x>(d.left+d.right)/2==u}}scanText(t,e){let i=[];for(let r=0;r<t.length;r=ct(t.text,r))i.push(e+r);i.push(e+t.length);let s=this.scan(i,r=>{let o=i[r]-e,l=i[r+1]-e;return qt(t.dom,o,l).getClientRects()});return s.after?new X(i[s.i+1],-1):new X(i[s.i],1)}scanTile(t,e){if(!t.length)return new X(e,1);if(t.children.length==1){let l=t.children[0];if(l.isText())return this.scanText(l,e);if(l.isComposite())return this.scanTile(l,e)}let i=[e];for(let l=0,a=e;l<t.children.length;l++)i.push(a+=t.children[l].length);let s=this.scan(i,l=>{let a=t.children[l];return a.flags&48?null:(a.dom.nodeType==1?a.dom:qt(a.dom,0,a.length)).getClientRects()}),r=t.children[s.i],o=i[s.i];return r.isText()?this.scanText(r,o):r.isComposite()?this.scanTile(r,o):s.after?new X(i[s.i+1],-1):new X(o,1)}}const xt="￿";class sr{constructor(t,e){this.points=t,this.view=e,this.text="",this.lineSeparator=e.state.facet(Wt.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=xt}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let o=B.get(s),l=s.nextSibling;if(l==e){o?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=B.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:ce(s))||ce(l)&&(s.nodeName!="BR"||o?.isWidget())&&this.text.length>r)&&!rr(l,e)&&this.lineBreak(),s=l}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<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);i=r+o}}readNode(t){let e=B.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(nr(t,i.node,i.offset)?e:0))}}function nr(n,t,e){for(;;){if(!t||e<et(t))return!1;if(t==n)return!0;e=ot(t)+1,t=t.parentNode}}function rr(n,t){let e;for(;!(n==t||!n);n=n.nextSibling){let i=B.get(n);if(!i?.isWidget())return!1;i&&(e||(e=[])).push(i)}if(e)for(let i of e){let s=i.overrideDOMText;if(s?.length)return!1}return!0}class ki{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class or{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:r,impreciseAnchor:o}=t.docView,l=t.state.selection;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=Ls(t.docView.tile,e,i,0))){let a=r||o?[]:ar(t),h=new sr(a,t);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=hr(a,this.bounds.from)}else{let a=t.observer.selectionRange,h=r&&r.node==a.focusNode&&r.offset==a.focusOffset||!Ve(t.contentDOM,a.focusNode)?l.main.head:t.docView.posFromDOM(a.focusNode,a.focusOffset),c=o&&o.node==a.anchorNode&&o.offset==a.anchorOffset||!Ve(t.contentDOM,a.anchorNode)?l.main.anchor:t.docView.posFromDOM(a.anchorNode,a.anchorOffset),f=t.viewport;if((y.ios||y.chrome)&&h!=c&&Math.min(h,c)<=l.main.from&&Math.max(h,c)>=l.main.to&&(f.from>0||f.to<t.state.doc.length)){let d=Math.min(h,c),u=Math.max(h,c),p=f.from-d,g=f.to-u;(p==0||p==1||d==0)&&(g==0||g==-1||u==t.state.doc.length)&&(h=0,c=t.state.doc.length)}if(t.inputState.composing>-1&&l.ranges.length>1)this.newSel=l.replaceRange(v.range(c,h));else if(t.lineWrapping&&c==h&&!(l.main.empty&&l.main.head==h)&&t.inputState.lastTouchTime>Date.now()-100){let d=t.coordsAtPos(h,-1),u=0;d&&(u=t.inputState.lastTouchY<=d.bottom?-1:1),this.newSel=v.create([v.cursor(h,u)])}else this.newSel=v.single(c,h)}}}function Ls(n,t,e,i){if(n.isComposite()){let s=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,c=i;a<n.children.length;a++){let f=n.children[a],d=h+f.length;if(h<t&&d>e)return Ls(f,t,e,h);if(d>=t&&s==-1&&(s=a,r=h),h>e&&f.dom.parentNode==n.dom){o=a,l=c;break}c=d,h=d+f.breakAfter}return{from:r,to:l<0?i+n.length:l,startDOM:(s?n.children[s-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:o<n.children.length&&o>=0?n.children[o].dom:null}}else return n.isText()?{from:i,to:i+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function Rs(n,t){let e,{newSel:i}=t,{state:s}=n,r=s.selection.main,o=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(t.bounds){let{from:l,to:a}=t.bounds,h=r.from,c=null;(o===8||y.android&&t.text.length<a-l)&&(h=r.to,c="end");let f=s.doc.sliceString(l,a,xt),d,u;!r.empty&&r.from>=l&&r.to<=a&&(t.typeOver||f!=t.text)&&f.slice(0,r.from-l)==t.text.slice(0,r.from-l)&&f.slice(r.to-l)==t.text.slice(d=t.text.length-(f.length-(r.to-l)))?e={from:r.from,to:r.to,insert:K.of(t.text.slice(r.from-l,d).split(xt))}:(u=Es(f,t.text,h-l,c))&&(y.chrome&&o==13&&u.toB==u.from+2&&t.text.slice(u.from,u.toB)==xt+xt&&u.toB--,e={from:l+u.from,to:l+u.toA,insert:K.of(t.text.slice(u.from,u.toB).split(xt))})}else i&&(!n.hasFocus&&s.facet(J)||pe(i,r))&&(i=null);if(!e&&!i)return!1;if((y.mac||y.android)&&e&&e.from==e.to&&e.from==r.head-1&&/^\. ?$/.test(e.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=v.single(i.main.anchor-1,i.main.head-1)),e={from:e.from,to:e.to,insert:K.of([e.insert.toString().replace("."," ")])}):s.doc.lineAt(r.from).to<r.to&&n.docView.lineHasWidget(r.to)&&n.inputState.insertingTextAt>Date.now()-50?e={from:r.from,to:r.to,insert:s.toText(n.inputState.insertingText)}:y.chrome&&e&&e.from==e.to&&e.from==r.head&&e.insert.toString()==`
3
+ `&&n.lineWrapping&&(i&&(i=v.single(i.main.anchor-1,i.main.head-1)),e={from:r.from,to:r.to,insert:K.of([" "])}),e)return hi(n,e,i,o);if(i&&!pe(i,r)){let l=!1,a="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(l=!0),a=n.inputState.lastSelectionOrigin,a=="select.pointer"&&(i=Bs(s.facet(Yt).map(h=>h(n)),i))),n.dispatch({selection:i,scrollIntoView:l,userEvent:a}),!0}else return!1}function hi(n,t,e,i=-1){if(y.ios&&n.inputState.flushIOSKey(t))return!0;let s=n.state.selection.main;if(y.android&&(t.to==s.to&&(t.from==s.from||t.from==s.from-1&&n.state.sliceDoc(t.from,s.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&kt(n.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>s.head)&&kt(n.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&kt(n.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=lr(n,t,e));return n.state.facet(bs).some(a=>a(n,t.from,t.to,r,l))||n.dispatch(l()),!0}function lr(n,t,e){let i,s=n.state,r=s.selection.main,o=-1;if(t.from==t.to&&t.from<r.from||t.from>r.to){let a=t.from<r.from?-1:1,h=a<0?r.from:r.to,c=Ft(s.facet(Yt).map(f=>f(n)),h,a);t.from==c&&(o=c)}if(o>-1)i={changes:t,selection:v.cursor(t.from+t.insert.length,-1)};else if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&n.inputState.composing<0){let a=r.from<t.from?s.sliceDoc(r.from,t.from):"",h=r.to>t.to?s.sliceDoc(t.to,r.to):"";i=s.replaceSelection(n.state.toText(a+t.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let a=s.changes(t),h=e&&e.main.to<=a.newLength?e.main:void 0;if(s.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&t.to<=r.to+10&&t.to>=r.to-10){let c=n.state.sliceDoc(t.from,t.to),f,d=e&&Ts(n,e.main.head);if(d){let p=t.insert.length-(t.to-t.from);f={from:d.from,to:d.to-p}}else f=n.state.doc.lineAt(r.head);let u=r.to-t.to;i=s.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:a,range:h||p.map(a)};let g=p.to-u,m=g-c.length;if(n.state.sliceDoc(m,g)!=c||g>=f.from&&m<=f.to)return{range:p};let b=s.changes({from:m,to:g,insert:t.insert}),w=p.to-r.to;return{changes:b,range:h?v.range(Math.max(0,h.anchor+w),Math.max(0,h.head+w)):p.map(b)}})}else i={changes:a,selection:h&&s.selection.replaceRange(h)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function Es(n,t,e,i){let s=Math.min(n.length,t.length),r=0;for(;r<s&&n.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==s&&n.length==t.length)return null;let o=n.length,l=t.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));e-=o+a-r}if(o<r&&n.length<t.length){let a=e<=r&&e>=o?r-e:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=e<=r&&e>=l?r-e:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function ar(n){let t=[];if(n.root.activeElement!=n.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return e&&(t.push(new ki(e,i)),(s!=e||r!=i)&&t.push(new ki(s,r))),t}function hr(n,t){if(n.length==0)return null;let e=n[0].pos,i=n.length==2?n[1].pos:e;return e>-1&&i>-1?v.single(e+t,i+t):null}function pe(n,t){return t.head==n.main.head&&t.anchor==n.main.anchor}class cr{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,y.safari&&t.contentDOM.addEventListener("input",()=>null),y.gecko&&Ar(t.contentDOM.ownerDocument)}handleEvent(t){!wr(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(t.type,t)):this.runHandlers(t.type,t))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let s of i.observers)s(this.view,e);for(let s of i.handlers){if(e.defaultPrevented)break;if(s(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=dr(t),i=this.handlers,s=this.view.contentDOM;for(let r in e)if(r!="scroll"){let o=!e[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(s.removeEventListener(r,this.handleEvent),l=null),l||s.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!e[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&Hs.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),y.android&&y.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;if(y.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&(Ws.some(e=>e.keyCode==t.keyCode)&&!t.ctrlKey||ur.indexOf(t.key)>-1&&t.ctrlKey)){let e={ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey,shiftKey:t.shiftKey};return e.shiftKey&&y.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&fr(this.view.win)&&(e.shiftKey=!1),this.pendingIOSKey={key:t.key,keyCode:t.keyCode,mods:e},setTimeout(()=>this.flushIOSKey(),250),!0}return t.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,kt(this.view.contentDOM,e.key,e.keyCode,e.mods))}ignoreDuringComposition(t){return!/^key/.test(t.type)||t.synthetic?!1:this.composing>0?!0:y.safari&&!y.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function fr(n){return n.visualViewport?n.visualViewport.height*n.visualViewport.scale/n.document.documentElement.clientHeight<.85:!1}function Mi(n,t){return(e,i)=>{try{return t.call(n,i,e)}catch(s){Z(e.state,s)}}}function dr(n){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec,r=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(r)for(let l in r){let a=r[l];a&&e(l).handlers.push(Mi(i.value,a))}if(o)for(let l in o){let a=o[l];a&&e(l).observers.push(Mi(i.value,a))}}for(let i in G)e(i).handlers.push(G[i]);for(let i in V)e(i).observers.push(V[i]);return t}const Ws=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],ur="dthko",Hs=[16,17,18,20,91,92,224,225],Jt=6;function Zt(n){return Math.max(0,n)*.7+8}function pr(n,t){return Math.max(Math.abs(n.clientX-t.clientX),Math.abs(n.clientY-t.clientY))}class gr{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=es(t.contentDOM),this.atoms=t.state.facet(Yt).map(o=>o(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(Wt.allowMultipleSelections)&&mr(t,e),this.dragging=yr(t,e)&&Vs(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&pr(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,s=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=Ds(this.view);t.clientX-a.left<=s+Jt?e=-Zt(s-t.clientX):t.clientX+a.right>=o-Jt&&(e=Zt(t.clientX-o)),t.clientY-a.top<=r+Jt?i=-Zt(r-t.clientY):t.clientY+a.bottom>=l-Jt&&(i=Zt(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}select(t){let{view:e}=this,i=Bs(this.atoms,this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function mr(n,t){let e=n.state.facet(us);return e.length?e[0](t):y.mac?t.metaKey:t.ctrlKey}function br(n,t){let e=n.state.facet(ps);return e.length?e[0](t):y.mac?!t.altKey:!t.ctrlKey}function yr(n,t){let{main:e}=n.state.selection;if(e.empty)return!1;let i=Kt(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function wr(n,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=n.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=B.get(e))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(t))return!1;return!0}const G=Object.create(null),V=Object.create(null),Ps=y.ie&&y.ie_version<15||y.ios&&y.webkit_version<604;function xr(n){let t=n.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{n.focus(),e.remove(),Ns(n,e.value)},50)}function Se(n,t,e){for(let i of n.facet(t))e=i(e,n);return e}function Ns(n,t){t=Se(n.state,ri,t);let{state:e}=n,i,s=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(_e!=null&&e.selection.ranges.every(a=>a.empty)&&_e==r.toString()){let a=-1;i=e.changeByRange(h=>{let c=e.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=e.toText((o?r.line(s++).text:t)+e.lineBreak);return{changes:{from:c.from,insert:f},range:v.cursor(h.from+f.length)}})}else o?i=e.changeByRange(a=>{let h=r.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:v.cursor(a.from+h.length)}}):i=e.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}V.scroll=n=>{let t=n.inputState;t.lastScrollTop=n.scrollDOM.scrollTop,t.lastScrollLeft=n.scrollDOM.scrollLeft,y.ios&&!t.touchActive&&(t.lastIOSMomentumScroll=Date.now())};V.wheel=V.mousewheel=n=>{n.inputState.lastWheelEvent=Date.now()};G.keydown=(n,t)=>(n.inputState.setSelectionOrigin("select"),t.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);V.touchstart=(n,t)=>{let e=n.inputState,i=t.targetTouches[0];e.touchActive=!0,e.lastTouchTime=Date.now(),i&&(e.lastTouchX=i.clientX,e.lastTouchY=i.clientY),e.setSelectionOrigin("select.pointer")};V.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};V.touchend=(n,t)=>{n.inputState.touchActive=!1};G.mousedown=(n,t)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of n.state.facet(gs))if(e=i(n,t),e)break;if(!e&&t.button==0&&(e=vr(n,t)),e){let i=!n.hasFocus;n.inputState.startMouseSelection(new gr(n,t,e,i)),i&&n.observer.ignore(()=>{ns(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(t),s.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Ai(n,t,e,i){if(i==1)return v.cursor(t,e);if(i==2)return Qn(n.state,t,e);{let s=n.docView.lineAt(t,e),r=n.state.doc.lineAt(s?s.posAtEnd:t),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<n.state.doc.length&&l==r.to&&l++,v.undirectionalRange(o,l)}}const Sr=y.ie&&y.ie_version<=11;let Di=null,Oi=0,Ti=0;function Vs(n){if(!Sr)return n.detail;let t=Di,e=Ti;return Di=n,Ti=Date.now(),Oi=!t||e>Date.now()-400&&Math.abs(t.clientX-n.clientX)<2&&Math.abs(t.clientY-n.clientY)<2?(Oi+1)%3:1}function vr(n,t){let e=n.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),i=Vs(t),s=n.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),s=s.map(r.changes))},get(r,o,l){let a=n.posAndSideAtCoords({x:r.clientX,y:r.clientY},!1),h,c=Ai(n,a.pos,a.assoc,i);if(e.pos!=a.pos&&!o){let f=Ai(n,e.pos,e.assoc,i),d=Math.min(f.from,c.from),u=Math.max(f.to,c.to);c=d<c.from?v.range(d,u,c.assoc):v.range(u,d,c.assoc)}return o?s.replaceRange(s.main.extend(c.from,c.to,c.assoc)):l&&i==1&&s.ranges.length>1&&(h=Cr(s,a.pos))?h:l?s.addRange(c):v.create([c])}}}function Cr(n,t){for(let e=0;e<n.ranges.length;e++){let{from:i,to:s}=n.ranges[e];if(i<=t&&s>=t)return v.create(n.ranges.slice(0,e).concat(n.ranges.slice(e+1)),n.mainIndex==e?0:n.mainIndex-(n.mainIndex>e?1:0))}return null}G.dragstart=(n,t)=>{let{selection:{main:e}}=n.state;if(t.target.draggable){let s=n.docView.tile.nearest(t.target);if(s&&s.isWidget()){let r=s.posAtStart,o=r+s.length;(r>=e.to||o<=e.from)&&(e=v.undirectionalRange(r,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",Se(n.state,oi,n.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};G.dragend=n=>(n.inputState.draggedContent=null,!1);function Bi(n,t,e,i){if(e=Se(n.state,ri,e),!e)return;let s=n.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=n.inputState,o=i&&r&&br(n,t)?{from:r.from,to:r.to}:null,l={from:s,insert:e},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}G.drop=(n,t)=>{if(!t.dataTransfer)return!1;if(n.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),s=0,r=()=>{++s==e.length&&Bi(n,t,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<e.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return Bi(n,t,i,!0),!0}return!1};G.paste=(n,t)=>{if(n.state.readOnly)return!0;n.observer.flush();let e=Ps?null:t.clipboardData;return e?(Ns(n,e.getData("text/plain")||e.getData("text/uri-list")),!0):(xr(n),!1)};function kr(n,t){let e=n.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function Mr(n){let t=[],e=[],i=!1;for(let s of n.selection.ranges)s.empty||(t.push(n.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(t.push(o.text),e.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:Se(n,oi,t.join(n.lineBreak)),ranges:e,linewise:i}}let _e=null;G.copy=G.cut=(n,t)=>{if(!Pt(n.contentDOM,n.observer.selectionRange))return!1;let{text:e,ranges:i,linewise:s}=Mr(n.state);if(!e&&!s)return!1;_e=s?e:null,t.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Ps?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(kr(n,e),!1)};const Fs=sn.define();function Is(n,t){let e=[];for(let i of n.facet(ys)){let s=i(n,t);s&&e.push(s)}return e.length?n.update({effects:e,annotations:Fs.of(!0)}):null}function Ks(n){setTimeout(()=>{let t=n.hasFocus;if(t!=n.inputState.notifiedFocused){let e=Is(n.state,t);e?n.dispatch(e):n.update([])}},10)}V.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Ks(n)};V.blur=n=>{n.observer.clearSelectionRange(),Ks(n)};V.compositionstart=V.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};V.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,y.chrome&&y.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};V.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};G.beforeinput=(n,t)=>{var e,i;if((t.inputType=="insertText"||t.inputType=="insertCompositionText")&&(n.inputState.insertingText=t.data,n.inputState.insertingTextAt=Date.now()),t.inputType=="insertReplacementText"&&n.observer.editContext){let r=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),o=t.getTargetRanges();if(r&&o.length){let l=o[0],a=n.posAtDOM(l.startContainer,l.startOffset),h=n.posAtDOM(l.endContainer,l.endOffset);return hi(n,{from:a,to:h,insert:n.state.toText(r)},null),!0}}let s;if(y.chrome&&y.android&&(s=Ws.find(r=>r.inputType==t.inputType))&&(n.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let r=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return y.ios&&t.inputType=="deleteContentForward"&&n.observer.flushSoon(),y.safari&&t.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>V.compositionend(n,t),20),!1};const Li=new Set;function Ar(n){Li.has(n)||(Li.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Ri=["pre-wrap","normal","pre-line","break-spaces"];let Tt=!1;function Ei(){Tt=!1}class Dr{constructor(t){this.lineWrapping=t,this.doc=K.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return Ri.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,r,o){let l=Ri.indexOf(t)>-1,a=Math.abs(e-this.lineHeight)>.3||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let h=0;h<o.length;h++){let c=o[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class Or{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class q{constructor(t,e,i,s,r){this.from=t,this.length=e,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?H.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof ut?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new q(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var D=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(D||(D={}));const oe=.001;class N{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>oe&&(Tt=!0),this.height=t)}replace(t,e,i){return N.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=s[l],d=r.lineAt(a,D.ByPosNoHeight,i.setDoc(e),0,0),u=d.to>=h?d:r.lineAt(h,D.ByPosNoHeight,i,0,0);for(f+=u.to-h,h=u.to;l>0&&d.from<=s[l-1].toA;)a=s[l-1].fromA,c=s[l-1].fromB,l--,a<d.from&&(d=r.lineAt(a,D.ByPosNoHeight,i,0,0));c+=d.from-a,a=d.from;let p=ci.build(i.setDoc(o),t,c,f);r=ge(r,r.replace(a,h,p))}return r.updateHeight(i,0)}static empty(){return new I(0,0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,r=0;for(;;)if(e==i)if(s>r*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=t[e++];l&&(s+=l.size)}else{let l=t[--i];l&&(r+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new Br(N.of(t.slice(0,e)),o,N.of(t.slice(i)))}}function ge(n,t){return n==t?n:(n.constructor!=t.constructor&&(Tt=!0),t)}N.prototype.size=1;const Tr=R.replace({});class zs extends N{constructor(t,e,i){super(t,e),this.deco=i,this.spaceAbove=0}mainBlock(t,e){return new q(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(t,e,i,s){return this.spaceAbove&&t<i+this.spaceAbove?new q(s,0,i,this.spaceAbove,Tr):this.mainBlock(i,s)}lineAt(t,e,i,s,r){let o=this.mainBlock(s,r);return this.spaceAbove?this.blockAt(0,i,s,r).join(o):o}forEachLine(t,e,i,s,r,o){t<=r+this.length&&e>=r&&o(this.lineAt(0,D.ByPos,i,s,r))}setMeasuredHeight(t){let e=t.heights[t.index++];e<0?(this.spaceAbove=-e,e=t.heights[t.index++]):this.spaceAbove=0,this.setHeight(e)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class I extends zs{constructor(t,e,i){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(t,e){return new q(e,this.length,t+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof I||s instanceof W&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof W?s=new I(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):N.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class W extends N{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-i+1,o,l=0;if(t.lineWrapping){let a=Math.min(this.height,t.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(t,e,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(e,s);if(e.lineWrapping){let h=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),c=e.doc.lineAt(h),f=l+c.length*a,d=Math.max(i,t-f/2);return new q(c.from,c.length,d,f,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((t-i)/l))),{from:c,length:f}=e.doc.line(r+h);return new q(c,f,i+l*h,l,0)}}lineAt(t,e,i,s,r){if(e==D.ByHeight)return this.blockAt(t,i,s,r);if(e==D.ByPosNoHeight){let{from:u,to:p}=i.doc.lineAt(t);return new q(u,p-u,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(t),c=l+h.length*a,f=h.number-o,d=s+l*f+a*(h.from-r-f);return new q(h.from,h.length,Math.max(s,Math.min(d,s+this.height-c)),c,0)}forEachLine(t,e,i,s,r,o){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let c=t,f=s;c<=e;){let d=i.doc.lineAt(c);if(c==t){let p=d.number-l;f+=a*p+h*(t-r-p)}let u=a+h*d.length;o(new q(d.from,d.length,f,u,0)),f+=u,c=d.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let r=i[i.length-1];r instanceof W?i[i.length-1]=new W(r.length+s):i.push(null,new W(s-1))}if(t>0){let r=i[0];r instanceof W?i[0]=new W(t+r.length):i.unshift(new W(t-1),null)}return N.of(i)}decomposeLeft(t,e){e.push(new W(t-1),null)}decomposeRight(t,e){e.push(null,new W(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let o=[],l=Math.max(e,s.from),a=-1;for(s.from>e&&o.push(new W(s.from-e-1).updateHeight(t,e));l<=r&&s.more;){let c=t.doc.lineAt(l).length;o.length&&o.push(null);let f=s.heights[s.index++],d=0;f<0&&(d=-f,f=s.heights[s.index++]),a==-1?a=f:Math.abs(f-a)>=oe&&(a=-2);let u=new I(c,f,d);u.outdated=!1,o.push(u),l+=c+1}l<=r&&o.push(null,new W(r-l).updateHeight(t,l));let h=N.of(o);return(a<0||Math.abs(h.height-this.height)>=oe||Math.abs(a-this.heightMetrics(t,e).perLine)>=oe)&&(Tt=!0),ge(this,h)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Br extends N{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,s){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,r,s+this.left.length+this.break)}lineAt(t,e,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=e==D.ByHeight?t<o:t<l,h=a?this.left.lineAt(t,e,i,s,r):this.right.lineAt(t,e,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=e==D.ByPosNoHeight?D.ByPosNoHeight:D.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,s,r).join(h)}forEachLine(t,e,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)t<a&&this.left.forEachLine(t,e,i,s,r,o),e>=a&&this.right.forEachLine(t,e,i,l,a,o);else{let h=this.lineAt(a,D.ByPos,i,s,r);t<h.from&&this.left.forEachLine(t,h.from-1,i,s,r,o),h.to>=t&&h.from<=e&&o(h),e>h.to&&this.right.forEachLine(h.to+1,e,i,l,a,o)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&Wi(r,o-1),e<this.length){let l=r.length;this.decomposeRight(e,r),Wi(r,l)}return N.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?N.of(this.break?[t,null,e]:[t,e]):(this.left=ge(this.left,t),this.right=ge(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:r,right:o}=this,l=e+r.length+this.break,a=null;return s&&s.from<=e+r.length&&s.more?a=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(t,l,i,s):o.updateHeight(t,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Wi(n,t){let e,i;n[t]==null&&(e=n[t-1])instanceof W&&(i=n[t+1])instanceof W&&n.splice(t-1,3,new W(e.length+1+i.length))}const Lr=5;class ci{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof I?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new I(i-this.pos,-1,0)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=e-t;i.block?this.addBlock(new zs(o,s,i)):(o||r||s>=Lr)&&this.addLineDeco(s,r,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new I(this.pos-t,-1,0)),this.writtenTo=this.pos}blankContent(t,e){let i=new W(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof I)return t;let e=new I(0,-1,0);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof I)&&!this.isCovered?this.nodes.push(new I(0,-1,0)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof I&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let r=new ci(i,t);return E.spans(e,i,s,r,0),r.finish(i)}}function Rr(n,t,e){let i=new Er;return E.compare(n,t,e,i,0),i.changes}class Er{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&Ct(t,e,this.changes,5)}}function Wr(n,t){let e=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,e.left),o=Math.min(s.innerWidth,e.right),l=Math.max(0,e.top),a=Math.min(s.innerHeight,e.bottom);for(let h=n.parentNode;h&&h!=i.body;)if(h.nodeType==1){let c=h,f=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&f.overflow!="visible"){let d=c.getBoundingClientRect();r=Math.max(r,d.left),o=Math.min(o,d.right),l=Math.max(l,d.top),a=Math.min(h==n.parentNode?s.innerHeight:a,d.bottom)}h=f.position=="absolute"||f.position=="fixed"?c.offsetParent:c.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:r-e.left,right:Math.max(r,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,a)-(e.top+t)}}function Hr(n){let t=n.getBoundingClientRect(),e=n.ownerDocument.defaultView||window;return t.left<e.innerWidth&&t.right>0&&t.top<e.innerHeight&&t.bottom>0}function Pr(n,t){let e=n.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class Oe{constructor(t,e,i,s){this.from=t,this.to=e,this.size=i,this.displaySize=s}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(t,e){return R.replace({widget:new Nr(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class Nr extends jt{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class Hi{constructor(t,e){this.view=t,this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Pi,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=L.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=e.facet(li).some(s=>typeof s!="function"&&s.class=="cm-lineWrapping");this.heightOracle=new Dr(i),this.stateDeco=Ni(e),this.heightMap=N.empty().applyChanges(this.stateDeco,K.empty,this.heightOracle.setDoc(e.doc),[new z(0,0,0,e.doc.length)]);for(let s=0;s<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());s++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=R.set(this.lineGaps.map(s=>s.draw(this,!1))),this.scrollParent=t.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);t.push(new te(r,o))}}return this.viewports=t.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Pi:new fi(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(Et(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=Ni(this.state);let s=t.changedRanges,r=z.extendWithRanges(s,Rr(i,this.stateDeco,t?t.changes:Ui.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);Ei(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||Tt)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<a.from||e.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,e));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,t.flags|=this.updateForViewport(),(h||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(t.changes),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&(t.selectionSet||t.focusChanged)&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(xs)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:t}=this,e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?L.RTL:L.LTR;let o=this.heightOracle.mustRefreshForWrapping(r)||this.mustMeasureContent==="refresh",l=e.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:C,scaleY:S}=ts(e,l);(C>.005&&Math.abs(this.scaleX-C)>.005||S>.005&&Math.abs(this.scaleY-S)>.005)&&(this.scaleX=C,this.scaleY=S,h|=16,o=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,d=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=d)&&(this.paddingTop=f,this.paddingBottom=d,h|=18),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=t.scrollDOM.clientWidth,h|=16);let u=es(this.view.contentDOM,!1).y;u!=this.scrollParent&&(this.scrollParent=u,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=rs(this.scrollParent||t.win);let g=(this.printing?Pr:Wr)(e,this.paddingTop),m=g.top-this.pixelViewport.top,b=g.bottom-this.pixelViewport.bottom;this.pixelViewport=g;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(a=!0)),!this.inView&&!this.scrollTarget&&!Hr(t.dom))return 0;let x=l.width;if((this.contentDOMWidth!=x||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,h|=16),a){let C=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(C)&&(o=!0),o||s.lineWrapping&&Math.abs(x-this.contentDOMWidth)>s.charWidth){let{lineHeight:S,charWidth:T,textHeight:_}=t.docView.measureTextSize();o=S>0&&s.refresh(r,S,T,_,Math.max(5,x/T),C),o&&(t.docView.minWidth=0,h|=16)}m>0&&b>0?c=Math.max(m,b):m<0&&b<0&&(c=Math.min(m,b)),Ei();for(let S of this.viewports){let T=S.from==this.viewport.from?C:t.docView.measureVisibleLineHeights(S);this.heightMap=(o?N.empty().applyChanges(this.stateDeco,K.empty,this.heightOracle,[new z(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new Or(S.from,T))}Tt&&(h|=2)}let O=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return O&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||O)&&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 i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new te(s.lineAt(o-i*1e3,D.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,D.ByHeight,r,0,0).to);if(e){let{head:h}=e.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(h,D.ByPos,r,0,0),d;e.y=="center"?d=(f.top+f.bottom)/2-c/2:e.y=="start"||e.y=="nearest"&&h<a.from?d=f.top:d=f.bottom-c,a=new te(s.lineAt(d-1e3/2,D.ByHeight,r,0,0).from,s.lineAt(d+c+1e3/2,D.ByHeight,r,0,0).to)}}return a}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new te(this.heightMap.lineAt(i,D.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,D.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,D.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,D.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||s<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new Oe(e.mapPos(s.from),e.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=L.LTR&&!i)return[];let l=[],a=(c,f,d,u)=>{if(f-c<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let b of g)if(b>c&&b<f){a(c,b-10,d,u),a(b+10,f,d,u);return}let m=Fr(t,b=>b.from>=d.from&&b.to<=d.to&&Math.abs(b.from-c)<r&&Math.abs(b.to-f)<r&&!g.some(w=>b.from<w&&b.to>w));if(!m){if(f<d.to&&e&&i&&e.visibleRanges.some(x=>x.from<=f&&x.to>=f)){let x=e.moveToLineBoundary(v.cursor(f),!1,!0).head;x>c&&(f=x)}let b=this.gapSize(d,c,f,u),w=i||b<2e6?b:2e6;m=new Oe(c,f,b,w)}l.push(m)},h=c=>{if(c.length<o||c.type!=H.Text)return;let f=Vr(c.from,c.to,this.stateDeco);if(f.total<o)return;let d=this.scrollTarget?this.scrollTarget.range.head:null,u,p;if(i){let g=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,b;if(d!=null){let w=ie(f,d),x=((this.visibleBottom-this.visibleTop)/2+g)/c.height;m=w-x,b=w+x}else m=(this.visibleTop-c.top-g)/c.height,b=(this.visibleBottom-c.top+g)/c.height;u=ee(f,m),p=ee(f,b)}else{let g=f.total*this.heightOracle.charWidth,m=s*this.heightOracle.charWidth,b=0;if(g>2e6)for(let S of t)S.from>=c.from&&S.from<c.to&&S.size!=S.displaySize&&S.from*this.heightOracle.charWidth+b<this.pixelViewport.left&&(b=S.size-S.displaySize);let w=this.pixelViewport.left+b,x=this.pixelViewport.right+b,O,C;if(d!=null){let S=ie(f,d),T=((x-w)/2+m)/g;O=S-T,C=S+T}else O=(w-m)/g,C=(x+m)/g;u=ee(f,O),p=ee(f,C)}u>c.from&&a(c.from,u,c,f),p<c.to&&a(p,c.to,c,f)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(h):h(c);return l}gapSize(t,e,i,s){let r=ie(s,i)-ie(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){Oe.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=R.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(t){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let i=[];E.spans(e,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let r=0;r<i.length&&!(s&8);r++){let o=this.visibleRanges[r],l=i[r];(o.from!=l.from||o.to!=l.to)&&(s|=4,t&&t.mapPos(o.from,-1)==l.from&&t.mapPos(o.to,1)==l.to||(s|=8))}return this.visibleRanges=i,s}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||Et(this.heightMap.lineAt(t,D.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||Et(this.heightMap.lineAt(this.scaler.fromDOM(t),D.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return Et(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class te{constructor(t,e){this.from=t,this.to=e}}function Vr(n,t,e){let i=[],s=n,r=0;return E.spans(e,n,t,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<t&&(i.push({from:s,to:t}),r+=t-s),{total:r,ranges:i}}function ee({total:n,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(n*e);for(let s=0;;s++){let{from:r,to:o}=t[s],l=o-r;if(i<=l)return r+i;i-=l}}function ie(n,t){let e=0;for(let{from:i,to:s}of n.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/n.total}function Fr(n,t){for(let e of n)if(t(e))return e}const Pi={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function Ni(n){let t=n.facet(ye).filter(i=>typeof i!="function"),e=n.facet(ai).filter(i=>typeof i!="function");return e.length&&t.push(E.join(e)),t}class fi{constructor(t,e,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=e.lineAt(l,D.ByPos,t,0,0).top,c=e.lineAt(a,D.ByPos,t,0,0).bottom;return s+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return s+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,s=r.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-s)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,s=r.domBottom}}eq(t){return t instanceof fi?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function Et(n,t){if(t.scale==1)return n;let e=t.toDOM(n.top),i=t.toDOM(n.bottom);return new q(n.from,n.length,e,i-e,Array.isArray(n._content)?n._content.map(s=>Et(s,t)):n._content)}const se=k.define({combine:n=>n.join(" ")}),Ye=k.define({combine:n=>n.indexOf(!0)>-1}),Xe=At.newName(),qs=At.newName(),js=At.newName(),Gs={"&light":"."+qs,"&dark":"."+js};function $e(n,t,e){return new At(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):n+" "+i}})}const Ir=$e("."+Xe,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Gs),Kr={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Te=y.ie&&y.ie_version<=11;class zr{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new bn,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(y.ie&&y.ie_version<=11||y.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&y.android&&t.constructor.EDIT_CONTEXT!==!1&&!(y.chrome&&y.chrome_version<126)&&(this.editContext=new jr(t),t.state.facet(J)&&(t.contentDOM.editContext=this.editContext.editContext)),Te&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(J)?i.root.activeElement!=this.dom:!Pt(this.dom,s))return;let r=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(r&&r.isWidget()&&r.widget.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(y.ie&&y.ie_version<=11||y.android&&y.chrome)&&!i.state.selection.main.empty&&s.focusNode&&Vt(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=Kt(t.root);if(!e)return!1;let i=y.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&qr(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=Pt(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&wn(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Kr),Te&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Te&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){var i;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&kt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let r of t){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&Pt(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new or(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=Rs(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!pe(this.view.state.selection,e.newSel.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.tile.nearest(t.target);if(!e||e.isWidget())return null;if(e.markDirty(t.type=="attributes"),t.type=="childList"){let i=Vi(e,t.previousSibling||t.target.previousSibling,-1),s=Vi(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(J)!=t.state.facet(J)&&(t.view.contentDOM.editContext=t.state.facet(J)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function Vi(n,t,e){for(;t;){let i=B.get(t);if(i&&i.parent==n)return i;let s=t.parentNode;t=s!=n.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function Fi(n,t){let e=t.startContainer,i=t.startOffset,s=t.endContainer,r=t.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return Vt(o.node,o.offset,s,r)&&([e,i,s,r]=[s,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}}function qr(n,t){if(t.getComposedRanges){let s=t.getComposedRanges(n.root)[0];if(s)return Fi(n,s)}let e=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),e=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),e?Fi(n,e):null}class jr{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let s=t.state.selection.main,{anchor:r,head:o}=s,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);t.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>i.text.length;l==this.from&&r<this.from?l=r:a==this.to&&r>this.to&&(a=r);let c=Es(t.state.sliceDoc(l,a),i.text,(h?s.from:s.to)-l,h?"end":null);if(!c){let d=v.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));pe(d,s)||t.dispatch({selection:d,userEvent:"select"});return}let f={from:c.from+l,to:c.toA+l,insert:K.of(i.text.slice(c.from,c.toB).split(`
4
+ `))};if((y.mac||y.android)&&f.from==o-1&&/^\. ?$/.test(i.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:a,insert:K.of([i.text.replace("."," ")])}),this.pendingContextChange=f,!t.state.readOnly){let d=this.to-this.from+(f.to-f.from+f.insert.length);hi(t,f,v.single(this.toEditorPos(i.selectionStart,d),this.toEditorPos(i.selectionEnd,d)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),f.from<f.to&&!f.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(e.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(e.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=t.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,s.push(r)}e.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(r.rangeStart),h=this.toEditorPos(r.rangeEnd);if(a<h){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;s.push(R.mark({attributes:{style:c}}).range(a,h))}}}t.dispatch({effects:vs.of(R.set(s))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(t.state)}};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{let s=Kt(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((r,o,l,a,h)=>{if(i)return;let c=h.length-(o-r);if(s&&o>=s.to)if(s.from==r&&s.to==o&&s.insert.eq(h)){s=this.pendingContextChange=null,e+=c,this.to+=c;return}else s=null,this.revertPending(t.state);if(r+=e,o+=e,o<=this.from)this.from+=c,this.to+=c;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=c}e+=c}),s&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange,i=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(i.from,i.to)&&t.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t,e=this.to-this.from){t=Math.min(t,e);let i=this.composing;return i&&i.drifted?i.editorBase+(t-i.contextBase):t+this.from}toContextPos(t){let e=this.composing;return e&&e.drifted?e.contextBase+(t-e.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class M{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var e;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(s=>s.forEach(r=>i(r,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=t.root||yn(t.parent)||document,this.viewState=new Hi(this,t.state||Wt.create(t)),t.scrollTo&&t.scrollTo.is(Qt)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(St).map(s=>new Ce(s));for(let s of this.plugins)s.update(this);this.observer=new zr(this),this.inputState=new cr(this),this.inputState.ensureHandlers(this.plugins),this.docView=new vi(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...t){let e=t.length==1&&t[0]instanceof en?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,r=this.state;for(let d of t){if(d.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=d.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;t.some(d=>d.annotation(Fs))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Is(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(Wt.phrases)!=this.state.facet(Wt.phrases))return this.setState(r);s=fe.create(this,r,t),s.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let d of t){if(f&&(f=f.map(d.changes)),d.scrollIntoView){let{main:u}=d.state.selection,{x:p,y:g}=this.state.facet(M.cursorScrollMargin);f=new Mt(u.empty?u:v.cursor(u.head,u.head>u.anchor?-1:1),"nearest","nearest",g,p)}for(let u of d.effects)u.is(Qt)&&(f=u.value.clip(this.state))}this.viewState.update(s,f),this.bidiCache=me.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(Rt)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(d=>d.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(se)!=s.state.facet(se)&&(this.viewState.mustMeasureContent=!0),(e||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!s.empty)for(let d of this.state.facet(ze))try{d(s)}catch(u){Z(this.state,u,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!Rs(this,c)&&h.force&&kt(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 i of this.plugins)i.destroy(this);this.viewState=new Hi(this,t),this.plugins=t.facet(St).map(i=>new Ce(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new vi(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(St),i=t.state.facet(St);if(e!=i){let s=[];for(let r of i){let o=e.indexOf(r);if(o<0)s.push(new Ce(r));else{let l=this.plugins[o];l.mustUpdate=t,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){Z(this.state,i,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.viewState.scrollParent,s=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(rs(i||this.win))r=-1,o=this.viewState.heightMap.height;else{let u=this.viewState.scrollAnchorAt(s);r=u.from,o=u.top}this.updateState=1;let a=this.viewState.measure();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 c=h.map(u=>{try{return u.read(this)}catch(p){return Z(this.state,p),Ii}}),f=fe.create(this,this.state,[]),d=!1;f.flags|=a,e?e.flags|=a:e=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),d=this.docView.update(f),d&&this.docViewUpdate());for(let u=0;u<h.length;u++)if(c[u]!=Ii)try{let p=h[u];p.write&&p.write(c[u],this)}catch(p){Z(this.state,p)}if(d&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=((r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o)/this.scaleY;if((p>1||p<-1)&&!(y.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){s=s+p,i?r<0?i.scrollTop=i.scrollHeight:i.scrollTop+=p:this.win.scrollBy(0,p),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(ze))l(e)}get themeClasses(){return Xe+" "+(this.state.facet(Ye)?js:qs)+" "+this.state.facet(se)}updateAttrs(){let t=Ki(this,Cs,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(J)?"true":"false",class:"cm-content",style:`${y.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),Ki(this,li,e);let i=this.observer.ignore(()=>{let s=mi(this.contentDOM,this.contentAttrs,e),r=mi(this.dom,this.editorAttrs,t);return s||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(M.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Rt);let t=this.state.facet(M.cspNonce);At.mount(this.root,this.styleModules.concat(Ir).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.plugin!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.plugin==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return De(this,t,Ci(this,t,e,i))}moveByGroup(t,e){return De(this,t,Ci(this,t,e,i=>tr(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return v.cursor(r.side(e,s)+t.from,r.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return Zn(this,t,e,i)}moveVertically(t,e,i){return De(this,t,er(this,t,e,i))}domAtPos(t,e=1){return this.docView.domAtPos(t,e)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){this.readMeasured();let i=Ge(this,t,e);return i&&i.pos}posAndSideAtCoords(t,e=!0){return this.readMeasured(),Ge(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.state.doc.lineAt(t),s=this.bidiSpans(i),r=s[$.find(s,t-i.from,-1,e)];return this.docView.coordsAt(t,e,r.dir==L.RTL)}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(ws)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>Gr)return fs(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||cs(r.isolates,i=wi(this,t))))return r.order;i||(i=wi(this,t));let s=An(t.text,e,i);return this.bidiCache.push(new me(t.from,t.to,e,i,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||y.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{ns(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){var i,s,r,o;return Qt.of(new Mt(typeof t=="number"?v.cursor(t):t,(i=e.y)!==null&&i!==void 0?i:"nearest",(s=e.x)!==null&&s!==void 0?s:"nearest",(r=e.yMargin)!==null&&r!==void 0?r:5,(o=e.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Qt.of(new Mt(v.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return it.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return it.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=At.newName(),s=[se.of(i),Rt.of($e(`.${i}`,t))];return e&&e.dark&&s.push(Ye.of(!0)),s}static baseTheme(t){return ti.lowest(Rt.of($e("."+Xe,t,Gs)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&B.get(i)||B.get(t);return((e=s?.root)===null||e===void 0?void 0:e.view)||null}}M.styleModule=Rt;M.inputHandler=bs;M.clipboardInputFilter=ri;M.clipboardOutputFilter=oi;M.scrollHandler=Ss;M.focusChangeEffect=ys;M.perLineTextDirection=ws;M.exceptionSink=ms;M.updateListener=ze;M.editable=J;M.mouseSelectionStyle=gs;M.dragMovesSelection=ps;M.clickAddsSelectionRange=us;M.decorations=ye;M.blockWrappers=ks;M.outerDecorations=ai;M.atomicRanges=Yt;M.bidiIsolatedRanges=Ms;M.cursorScrollMargin=k.define({combine:n=>{let t=5,e=5;for(let i of n)typeof i=="number"?t=e=i:{x:t,y:e}=i;return{x:t,y:e}}});M.scrollMargins=As;M.darkTheme=Ye;M.cspNonce=k.define({combine:n=>n.length?n[0]:""});M.contentAttributes=li;M.editorAttributes=Cs;M.lineWrapping=M.contentAttributes.of({class:"cm-lineWrapping"});M.announce=Bt.define();const Gr=4096,Ii={};class me{constructor(t,e,i,s,r,o){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:L.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let o=t[r];o.dir==s&&!e.touchesRange(o.from,o.to)&&i.push(new me(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function Ki(n,t,e){for(let i=n.state.facet(t),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&ii(o,e)}return e}const _r=y.mac?"mac":y.windows?"win":y.linux?"linux":"key";function Yr(n,t){const e=n.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;a<e.length-1;++a){const h=e[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))s=!0;else if(/^(c|ctrl|control)$/i.test(h))r=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))t=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+h)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function ne(n,t,e){return t.altKey&&(n="Alt-"+n),t.ctrlKey&&(n="Ctrl-"+n),t.metaKey&&(n="Meta-"+n),e!==!1&&t.shiftKey&&(n="Shift-"+n),n}const Xr=ti.default(M.domEventHandlers({keydown(n,t){return Ys(_s(t.state),n,t,"editor")}})),$r=k.define({enables:Xr}),zi=new WeakMap;function _s(n){let t=n.facet($r),e=zi.get(t);return e||zi.set(t,e=Qr(t.reduce((i,s)=>i.concat(s),[]))),e}function So(n,t,e){return Ys(_s(n.state),t,n,e)}let rt=null;const Ur=4e3;function Qr(n,t=_r){let e=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h,c)=>{var f,d;let u=e[o]||(e[o]=Object.create(null)),p=l.split(/ (?!$)/).map(b=>Yr(b,t));for(let b=1;b<p.length;b++){let w=p.slice(0,b).join(" ");s(w,!0),u[w]||(u[w]={preventDefault:!0,stopPropagation:!1,run:[x=>{let O=rt={view:x,prefix:w,scope:o};return setTimeout(()=>{rt==O&&(rt=null)},Ur),!0}]})}let g=p.join(" ");s(g,!1);let m=u[g]||(u[g]={preventDefault:!1,stopPropagation:!1,run:((d=(f=u._any)===null||f===void 0?void 0:f.run)===null||d===void 0?void 0:d.slice())||[]});a&&m.run.push(a),h&&(m.preventDefault=!0),c&&(m.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=e[h]||(e[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let d in c)c[d].run.push(u=>f(u,Ue))}let a=o[t]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return e}let Ue=null;function Ys(n,t,e,i){Ue=t;let s=hn(t),r=rn(s,0),o=on(r)==s.length&&s!=" ",l="",a=!1,h=!1,c=!1;rt&&rt.view==e&&rt.scope==i&&(l=rt.prefix+" ",Hs.indexOf(t.keyCode)<0&&(h=!0,rt=null));let f=new Set,d=m=>{if(m){for(let b of m.run)if(!f.has(b)&&(f.add(b),b(e)))return m.stopPropagation&&(c=!0),!0;m.preventDefault&&(m.stopPropagation&&(c=!0),h=!0)}return!1},u=n[i],p,g;return u&&(d(u[l+ne(s,t,!o)])?a=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(y.windows&&t.ctrlKey&&t.altKey)&&!(y.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(p=cn[t.keyCode])&&p!=s?(d(u[l+ne(p,t,!0)])||t.shiftKey&&(g=fn[t.keyCode])!=s&&g!=p&&d(u[l+ne(g,t,!1)]))&&(a=!0):o&&t.shiftKey&&d(u[l+ne(s,t,!0)])&&(a=!0),!a&&d(u._any)&&(a=!0)),h&&(a=!0),a&&c&&t.stopPropagation(),Ue=null,a}class dt{constructor(t,e,i,s,r){this.className=t,this.left=e,this.top=i,this.width=s,this.height=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=Xs(t);return[new dt(e,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return Jr(t,e,i)}}function Xs(n){let t=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==L.LTR?t.left:t.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:t.top-n.scrollDOM.scrollTop*n.scaleY}}function qi(n,t,e,i){let s=n.coordsAtPos(t,e*2);if(!s)return i;let r=n.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=n.posAtCoords({x:r.left+1,y:o}),a=n.posAtCoords({x:r.right-1,y:o});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function Jr(n,t,e){if(e.to<=n.viewport.from||e.from>=n.viewport.to)return[];let i=Math.max(e.from,n.viewport.from),s=Math.min(e.to,n.viewport.to),r=n.textDirection==L.LTR,o=n.contentDOM,l=o.getBoundingClientRect(),a=Xs(n),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),d=l.right-(c?parseInt(c.paddingRight):0),u=je(n,i,1),p=je(n,s,-1),g=u.type==H.Text?u:null,m=p.type==H.Text?p:null;if(g&&(n.lineWrapping||u.widgetLineBreaks)&&(g=qi(n,i,1,g)),m&&(n.lineWrapping||p.widgetLineBreaks)&&(m=qi(n,s,-1,m)),g&&m&&g.from==m.from&&g.to==m.to)return w(x(e.from,e.to,g));{let C=g?x(e.from,null,g):O(u,!1),S=m?x(null,e.to,m):O(p,!0),T=[];return(g||u).to<(m||p).from-(g&&m?1:0)||u.widgetLineBreaks>1&&C.bottom+n.defaultLineHeight/2<S.top?T.push(b(f,C.bottom,d,S.top)):C.bottom<S.top&&n.elementAtHeight((C.bottom+S.top)/2).type==H.Text&&(C.bottom=S.top=(C.bottom+S.top)/2),w(C).concat(T).concat(w(S))}function b(C,S,T,_){return new dt(t,C-a.left,S-a.top,Math.max(0,T-C),_-S)}function w({top:C,bottom:S,horizontal:T}){let _=[];for(let st=0;st<T.length;st+=2)_.push(b(T[st],C,T[st+1],S));return _}function x(C,S,T){let _=1e9,st=-1e9,Xt=[];function di(lt,nt,yt,at,Lt){let U=n.coordsAtPos(lt,lt==T.to?-2:2),Q=n.coordsAtPos(yt,yt==T.from?2:-2);!U||!Q||(_=Math.min(U.top,Q.top,_),st=Math.max(U.bottom,Q.bottom,st),Lt==L.LTR?Xt.push(r&&nt?f:U.left,r&&at?d:Q.right):Xt.push(!r&&at?f:Q.left,!r&&nt?d:U.right))}let $t=C??T.from,Ut=S??T.to;for(let lt of n.visibleRanges)if(lt.to>$t&&lt.from<Ut)for(let nt=Math.max(lt.from,$t),yt=Math.min(lt.to,Ut);;){let at=n.state.doc.lineAt(nt);for(let Lt of n.bidiSpans(at)){let U=Lt.from+at.from,Q=Lt.to+at.from;if(U>=yt)break;Q>nt&&di(Math.max(U,nt),C==null&&U<=$t,Math.min(Q,yt),S==null&&Q>=Ut,Lt.dir)}if(nt=at.to+1,nt>=yt)break}return Xt.length==0&&di($t,C==null,Ut,S==null,n.textDirection),{top:_,bottom:st,horizontal:Xt}}function O(C,S){let T=l.top+(S?C.top:C.bottom);return{top:T,bottom:T,horizontal:[]}}}function Zr(n,t){return n.constructor==t.constructor&&n.eq(t)}class to{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(le)!=t.state.facet(le)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(le);for(;e<i.length&&i[e]!=this.layer;)e++;this.dom.style.zIndex=String((this.layer.above?150:-1)-e)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:e}=this.view;(t!=this.scaleX||e!=this.scaleY)&&(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some((e,i)=>!Zr(e,this.drawn[i]))){let e=this.dom.firstChild,i=0;for(let s of t)s.update&&e&&s.constructor&&this.drawn[i].constructor&&s.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(s.draw(),e);for(;e;){let s=e.nextSibling;e.remove(),e=s}this.drawn=t,y.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const le=k.define();function $s(n){return[it.define(t=>new to(t,n)),le.of(n)]}const mt=k.define({combine(n){return Qi(n,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function vo(n={}){return[mt.of(n),eo,io,no,xs.of(!0)]}function Co(n){return n.facet(mt)}function Us(n){return n.startState.facet(mt)!=n.state.facet(mt)}const eo=$s({above:!0,markers(n){let{state:t}=n,e=t.facet(mt),i=[];for(let s of t.selection.ranges){let r=s==t.selection.main;if(s.empty||e.drawRangeCursor&&!(r&&y.ios&&e.iosSelectionHandles)){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:v.cursor(s.head,s.assoc);for(let a of dt.forRange(n,o,l))i.push(a)}}return i},update(n,t){n.transactions.some(i=>i.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let e=Us(n);return e&&ji(n.state,t),n.docChanged||n.selectionSet||e},mount(n,t){ji(t.state,n)},class:"cm-cursorLayer"});function ji(n,t){t.style.animationDuration=n.facet(mt).cursorBlinkRate+"ms"}const io=$s({above:!1,markers(n){let t=[],{main:e,ranges:i}=n.state.selection;for(let s of i)if(!s.empty)for(let r of dt.forRange(n,"cm-selectionBackground",s))t.push(r);if(y.ios&&!e.empty&&n.state.facet(mt).iosSelectionHandles){for(let s of dt.forRange(n,"cm-selectionHandle cm-selectionHandle-start",v.cursor(e.from,1)))t.push(s);for(let s of dt.forRange(n,"cm-selectionHandle cm-selectionHandle-end",v.cursor(e.to,1)))t.push(s)}return t},update(n,t){return n.docChanged||n.selectionSet||n.viewportChanged||Us(n)},class:"cm-selectionLayer"}),so=y.gecko&&y.gecko_version==153?"#ffffff01":"transparent",no=ti.highest(M.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:`${so} !important`},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}}));class ro extends jt{constructor(t){super(),this.content=t}toDOM(t){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(t):this.content.cloneNode(!0)),e.setAttribute("aria-hidden","true"),e}coordsAt(t){let e=t.firstChild?Nt(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=zt(e[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return s.bottom-s.top>r*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function ko(n){let t=it.fromClass(class{constructor(e){this.view=e,this.placeholder=n?R.set([R.widget({widget:new ro(n),side:1}).range(0)]):R.none}get decorations(){return this.view.state.doc.length?R.none:this.placeholder}},{decorations:e=>e.decorations});return typeof n=="string"?[t,M.contentAttributes.of({"aria-placeholder":n})]:t}const Gi=k.define({combine(n){let t,e;for(let i of n)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function Mo(n,t){let e=n.plugin(Qs),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}const Qs=it.fromClass(class{constructor(n){this.input=n.state.facet(Qe),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(n));let t=n.state.facet(Gi);this.top=new re(n,!0,t.topContainer),this.bottom=new re(n,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(n){let t=n.state.facet(Gi);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new re(n.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new re(n.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=n.state.facet(Qe);if(e!=this.input){let i=e.filter(a=>a),s=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(n.view),l.push(c)):(c=this.panels[h],c.update&&c.update(n)),s.push(c),(c.top?r:o).push(c)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>M.scrollMargins.of(t=>{let e=t.plugin(n);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});class re{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom";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=_i(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=_i(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 _i(n){let t=n.nextSibling;return n.remove(),t}const Qe=k.define({enables:Qs});function Ao(n,t){let e,i=new Promise(o=>e=o),s=o=>oo(o,t,e);n.state.field(Be,!1)?n.dispatch({effects:Js.of(s)}):n.dispatch({effects:Bt.appendConfig.of(Be.init(()=>[s]))});let r=Zs.of(s);return{close:r,result:i.then(o=>((n.win.queueMicrotask||(a=>n.win.setTimeout(a,10)))(()=>{n.state.field(Be).indexOf(s)>-1&&n.dispatch({effects:r})}),o))}}const Be=ln.define({create(){return[]},update(n,t){for(let e of t.effects)e.is(Js)?n=[e.value].concat(n):e.is(Zs)&&(n=n.filter(i=>i!=e.value));return n},provide:n=>Qe.computeN([n],t=>t.field(n))}),Js=Bt.define(),Zs=Bt.define();function oo(n,t,e){let i=t.content?t.content(n,()=>o(null)):null;if(!i){if(i=wt("form"),t.input){let l=wt("input",t.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild(wt("label",(t.label||"")+": ",l))}else i.appendChild(document.createTextNode(t.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(wt("button",{class:"cm-button",type:"submit"},t.submitLabel||"OK"))}let s=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l<s.length;l++){let a=s[l];a.addEventListener("keydown",h=>{h.keyCode==27?(h.preventDefault(),o(null)):h.keyCode==13&&(h.preventDefault(),o(a))}),a.addEventListener("submit",h=>{h.preventDefault(),o(a)})}let r=wt("div",i,wt("button",{onclick:()=>o(null),"aria-label":n.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));t.class&&(r.className=t.class),r.classList.add("cm-dialog");function o(l){r.contains(r.ownerDocument.activeElement)&&n.focus(),e(l)}return{dom:r,top:t.top,mount:()=>{if(t.focus){let l;typeof t.focus=="string"?l=i.querySelector(t.focus):l=i.querySelector("input")||i.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class bt extends ei{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}bt.prototype.elementClass="";bt.prototype.toDOM=void 0;bt.prototype.mapMode=Ht.TrackBefore;bt.prototype.startSide=bt.prototype.endSide=-1;bt.prototype.point=!0;const Le=k.define(),lo=k.define(),ae=k.define(),Je=k.define({combine:n=>n.some(t=>t)});function ao(n){let t=[ho];return n&&n.fixed===!1&&t.push(Je.of(!0)),t}const ho=it.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(ae).map(t=>new Xi(n,t)),this.fixed=!n.state.facet(Je);for(let t of this.gutters)t.config.side=="after"?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let t=this.prevViewport,e=n.view.viewport,i=Math.min(t.to,e.to)-Math.max(t.from,e.from);this.syncGutters(i<(e.to-e.from)*.8)}if(n.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Je)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let t=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let e=E.iter(this.view.state.facet(Le),this.view.viewport.from),i=[],s=this.gutters.map(r=>new co(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==H.Text&&o){Ze(e,i,l.from);for(let a of s)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(r.type==H.Text){Ze(e,i,r.from);for(let o of s)o.line(this.view,r,i)}else if(r.widget)for(let o of s)o.widget(this.view,r);for(let r of s)r.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,t),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let t=n.startState.facet(ae),e=n.state.facet(ae),i=n.docChanged||n.heightChanged||n.viewportChanged||!E.eq(n.startState.facet(Le),n.state.facet(Le),n.view.viewport.from,n.view.viewport.to);if(t==e)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of e){let o=t.indexOf(r);o<0?s.push(new Xi(this.view,r)):(this.gutters[o].update(n),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>M.scrollMargins.of(t=>{let e=t.plugin(n);if(!e||e.gutters.length==0||!e.fixed)return null;let i=e.dom.offsetWidth*t.scaleX,s=e.domAfter?e.domAfter.offsetWidth*t.scaleX:0;return t.textDirection==L.LTR?{left:i,right:s}:{right:i,left:s}})});function Yi(n){return Array.isArray(n)?n:[n]}function Ze(n,t,e){for(;n.value&&n.from<=e;)n.from==e&&t.push(n.value),n.next()}class co{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=E.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:s}=this,r=(e.top-this.height)/t.scaleY,o=e.height/t.scaleY;if(this.i==s.elements.length){let l=new tn(t,o,r,i);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(t,o,r,i);this.height=e.bottom,this.i++}line(t,e,i){let s=[];Ze(this.cursor,s,e.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(t,e,s);r&&s.unshift(r);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e),s=i?[i]:null;for(let r of t.state.facet(lo)){let o=r(t,e.widget,e);o&&(s||(s=[])).push(o)}s&&this.addElement(t,e,s)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Xi{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,s=>{let r=s.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=s.clientY;let l=t.lineBlockAtHeight(o-t.documentTop);e.domEventHandlers[i](t,l,s)&&s.preventDefault()});this.markers=Yi(e.markers(t)),e.initialSpacer&&(this.spacer=new tn(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=Yi(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],t);s!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[s])}let i=t.view.viewport;return!E.eq(this.markers,e,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}}class tn{constructor(t,e,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,s)}update(t,e,i,s){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),fo(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=r<e.length?e[r++]:null,h=!1;if(a){let c=a.elementClass;c&&(i+=" "+c);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,h=!0;break}}else l=this.markers.length;for(;o<l;){let c=this.markers[o++];if(c.toDOM){c.destroy(s);let f=s.nextSibling;s.remove(),s=f}}if(!a)break;a.toDOM&&(h?s=s.nextSibling:this.dom.insertBefore(a.toDOM(t),s)),h&&o++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}function fo(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++)if(!n[e].compare(t[e]))return!1;return!0}const uo=k.define(),po=k.define(),vt=k.define({combine(n){return Qi(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let s in e){let r=i[s],o=e[s];i[s]=r?(l,a,h)=>r(l,a,h)||o(l,a,h):o}return i}})}});class Re extends bt{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Ee(n,t){return n.state.facet(vt).formatNumber(t,n.state)}const go=ae.compute([vt],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(uo)},lineMarker(t,e,i){return i.some(s=>s.toDOM)?null:new Re(Ee(t,t.state.doc.lineAt(e.from).number))},widgetMarker:(t,e,i)=>{for(let s of t.state.facet(po)){let r=s(t,e,i);if(r)return r}return null},lineMarkerChange:t=>t.startState.facet(vt)!=t.state.facet(vt),initialSpacer(t){return new Re(Ee(t,$i(t.state.doc.lines)))},updateSpacer(t,e){let i=Ee(e.view,$i(e.view.state.doc.lines));return i==t.number?t:new Re(i)},domEventHandlers:n.facet(vt).domEventHandlers,side:"before"}));function Do(n={}){return[vt.of(n),ao(),go]}function $i(n){let t=9;for(;t<n;)t=t*10+9;return t}export{R as D,M as E,it as V,jt as W,L as a,Ao as b,Co as c,vo as d,ao as e,Do as f,Mo as g,$r as k,Z as l,ko as p,So as r,Qe as s};
@@ -0,0 +1,6 @@
1
+ import{i as Z}from"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import{k as tt,P as et,i as it,a as M,M as K,S as st}from"./vendor-codemirror-state-C9awkmn-.js";import{u as nt,r as I,i as V,v as W,w as rt}from"./vendor-codemirror-language-BgPj_McA.js";import{s as z,E as P,V as at,D as T,c as ot,a as lt,r as L}from"./vendor-codemirror-view-CiLROUVV.js";import{s as B,S as ct,R as ht}from"./vendor-codemirror-search-BmS-GmcX.js";import{i as ut,a as ft,c as dt,b as mt,d as vt,e as gt,f as pt,g as yt,t as Ct,u as St,r as Ot}from"./vendor-codemirror-commands-B7H_j0iU.js";function C(i,t){var e=t.ch,s=t.line+1;s<1&&(s=1,e=0),s>i.lines&&(s=i.lines,e=Number.MAX_VALUE);var n=i.line(s);return Math.min(n.from+Math.max(0,e),n.to)}function O(i,t){let e=i.lineAt(t);return{line:e.number-1,ch:t-e.from}}class w{constructor(t,e){this.line=t,this.ch=e}}function U(i,t,e){if(i.addEventListener)i.addEventListener(t,e,!1);else{var s=i._handlers||(i._handlers={});s[t]=(s[t]||[]).concat(e)}}function q(i,t,e){if(i.removeEventListener)i.removeEventListener(t,e,!1);else{var s=i._handlers,n=s&&s[t];if(n){var r=n.indexOf(e);r>-1&&(s[t]=n.slice(0,r).concat(n.slice(r+1)))}}}function Q(i,t,...e){var s,n=(s=i._handlers)===null||s===void 0?void 0:s[t];if(n)for(var r=0;r<n.length;++r)n[r](...e)}function _(i,...t){if(i)for(var e=0;e<i.length;++e)i[e](...t)}let R;try{R=new RegExp("[\\w\\p{Alphabetic}\\p{Number}_]","u")}catch{R=/[\w]/}function N(i,t){var e=i.cm6;if(!e.state.readOnly){var s="input.type.compose";if(i.curOp&&(i.curOp.lastChange||(s="input.type.compose.start")),t.annotations)try{t.annotations.some(function(n){n.value=="input"&&(n.value=s)})}catch(n){console.error(n)}else t.userEvent=s;return e.dispatch(t)}}function H(i,t){var e;i.curOp&&(i.curOp.$changeStart=void 0),(t?St:Ot)(i.cm6);let s=(e=i.curOp)===null||e===void 0?void 0:e.$changeStart;s!=null&&i.cm6.dispatch({selection:{anchor:s}})}var Mt={Left:i=>L(i.cm6,{key:"Left"},"editor"),Right:i=>L(i.cm6,{key:"Right"},"editor"),Up:i=>L(i.cm6,{key:"Up"},"editor"),Down:i=>L(i.cm6,{key:"Down"},"editor"),Backspace:i=>L(i.cm6,{key:"Backspace"},"editor"),Delete:i=>L(i.cm6,{key:"Delete"},"editor")};class c{openDialog(t,e,s){return xt(this,t,e,s)}openNotification(t,e){return kt(this,t,e)}constructor(t){this.state={},this.marks=Object.create(null),this.$mid=0,this.options={},this._handlers={},this.$lastChangeEndOffset=0,this.virtualSelection=null,this.cm6=t,this.onChange=this.onChange.bind(this),this.onSelectionChange=this.onSelectionChange.bind(this)}on(t,e){U(this,t,e)}off(t,e){q(this,t,e)}signal(t,e,s){Q(this,t,e,s)}indexFromPos(t){return C(this.cm6.state.doc,t)}posFromIndex(t){return O(this.cm6.state.doc,t)}foldCode(t){let e=this.cm6,s=e.state.selection.ranges,n=this.cm6.state.doc,r=C(n,t),a=M.create([M.range(r,r)],0).ranges;e.state.selection.ranges=a,nt(e),e.state.selection.ranges=s}firstLine(){return 0}lastLine(){return this.cm6.state.doc.lines-1}lineCount(){return this.cm6.state.doc.lines}setCursor(t,e){typeof t=="object"&&(e=t.ch,t=t.line);var s=C(this.cm6.state.doc,{line:t,ch:e||0});this.cm6.dispatch({selection:{anchor:s}},{scrollIntoView:!this.curOp}),this.curOp&&!this.curOp.isVimOp&&this.onBeforeEndOperation()}getCursor(t){var e=this.cm6.state.selection.main,s=t=="head"||!t?e.head:t=="anchor"?e.anchor:t=="start"?e.from:t=="end"?e.to:null;if(s==null)throw new Error("Invalid cursor type");return this.posFromIndex(s)}listSelections(){var t=this.cm6.state.doc;return this.cm6.state.selection.ranges.map(e=>({anchor:O(t,e.anchor),head:O(t,e.head)}))}setSelections(t,e){var s=this.cm6.state.doc,n=t.map(r=>{var a=C(s,r.head),l=C(s,r.anchor);return a==l?M.cursor(a,1):M.range(l,a)});this.cm6.dispatch({selection:M.create(n,e)})}setSelection(t,e,s){this.setSelections([{anchor:t,head:e}],0),s&&s.origin=="*mouse"&&this.onBeforeEndOperation()}getLine(t){var e=this.cm6.state.doc;return t<0||t>=e.lines?"":this.cm6.state.doc.line(t+1).text}getLineHandle(t){return this.$lineHandleChanges||(this.$lineHandleChanges=[]),{row:t,index:this.indexFromPos(new w(t,0))}}getLineNumber(t){var e=this.$lineHandleChanges;if(!e)return null;for(var s=t.index,n=0;n<e.length;n++)if(s=e[n].changes.mapPos(s,1,K.TrackAfter),s==null)return null;var r=this.posFromIndex(s);return r.ch==0?r.line:null}releaseLineHandles(){this.$lineHandleChanges=void 0}getRange(t,e){var s=this.cm6.state.doc;return this.cm6.state.sliceDoc(C(s,t),C(s,e))}replaceRange(t,e,s,n){s||(s=e);var r=this.cm6.state.doc,a=C(r,e),l=C(r,s);N(this,{changes:{from:a,to:l,insert:t}})}replaceSelection(t){N(this,this.cm6.state.replaceSelection(t))}replaceSelections(t){var e=this.cm6.state.selection.ranges,s=e.map((n,r)=>({from:n.from,to:n.to,insert:t[r]||""}));N(this,{changes:s})}getSelection(){return this.getSelections().join(`
2
+ `)}getSelections(){var t=this.cm6;return t.state.selection.ranges.map(e=>t.state.sliceDoc(e.from,e.to))}somethingSelected(){return this.cm6.state.selection.ranges.some(t=>!t.empty)}getInputField(){return this.cm6.contentDOM}clipPos(t){var e=this.cm6.state.doc,s=t.ch,n=t.line+1;n<1&&(n=1,s=0),n>e.lines&&(n=e.lines,s=Number.MAX_VALUE);var r=e.line(n);return s=Math.min(Math.max(0,s),r.to-r.from),new w(n-1,s)}getValue(){return this.cm6.state.doc.toString()}setValue(t){var e=this.cm6;return e.dispatch({changes:{from:0,to:e.state.doc.length,insert:t},selection:M.range(0,0)})}focus(){return this.cm6.focus()}blur(){return this.cm6.contentDOM.blur()}defaultTextHeight(){return this.cm6.defaultLineHeight}findMatchingBracket(t,e){var s=this.cm6.state,n=C(s.doc,t),r=I(s,n+1,-1);return r&&r.end?{to:O(s.doc,r.end.from)}:(r=I(s,n,1),r&&r.end?{to:O(s.doc,r.end.from)}:{to:void 0})}scanForBracket(t,e,s,n){return Et(this,t,e,s,n)}indentLine(t,e){e?this.indentMore():this.indentLess()}indentMore(){ut(this.cm6)}indentLess(){ft(this.cm6)}execCommand(t){if(c.commands.hasOwnProperty(t))c.commands[t](this);else if(t=="goLineLeft")dt(this.cm6);else if(t=="goLineRight"){mt(this.cm6);let e=this.cm6.state,s=e.selection.main.head;s<e.doc.length&&e.sliceDoc(s,s+1)!==`
3
+ `&&vt(this.cm6)}else console.log(t+" is not implemented")}setBookmark(t,e){var s=e?.insertLeft?1:-1,n=this.indexFromPos(t),r=new Nt(this,n,s);return r}addOverlay({query:t}){let e=new ct({regexp:!0,search:t.source,caseSensitive:!/i/.test(t.flags)});if(e.valid){e.forVim=!0,this.cm6Query=e;let s=B.of(e);return this.cm6.dispatch({effects:s}),e}}removeOverlay(t){if(!this.cm6Query)return;this.cm6Query.forVim=!1;let e=B.of(this.cm6Query);this.cm6.dispatch({effects:e})}getSearchCursor(t,e){var s=this,n=null,r=null,a=!1;e.ch==null&&(e.ch=Number.MAX_VALUE);var l=C(s.cm6.state.doc,e),o=t.source.replace(/(\\.|{(?:\d+(?:,\d*)?|,\d+)})|[{}]/g,function(h,u){return u||"\\"+h});function d(h,u=0,g=h.length){return new ht(h,o,{ignoreCase:t.ignoreCase},u,g)}function f(h){var u=s.cm6.state.doc;if(h>u.length)return null;let g=d(u,h).next();return g.done?null:g.value}var m=1e4;function p(h,u){var g=s.cm6.state.doc;for(let v=1;;v++){let y=Math.max(h,u-v*m),k=d(g,y,u),x=null;for(;!k.next().done;)x=k.value;if(x&&(y==h||x.from>y+10))return x;if(y==h)return null}}return{findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(h){var u=s.cm6.state.doc;if(h){let g=n?a?n.to-1:n.from:l;n=p(0,g)}else{let g=n?a?n.to+1:n.to:l;n=f(g)}return r=n&&{from:O(u,n.from),to:O(u,n.to),match:n.match},a=n?n.from==n.to:!1,n&&n.match},from:function(){return r?.from},to:function(){return r?.to},replace:function(h){n&&(N(s,{changes:{from:n.from,to:n.to,insert:h}}),n.to=n.from+h.length,r&&(r.to=O(s.cm6.state.doc,n.to)))},get match(){return r&&r.match}}}findPosV(t,e,s,n){let{cm6:r}=this;const a=r.state.doc;let l=s=="page"?r.dom.clientHeight:0;const o=C(a,t);let d=M.cursor(o,1,void 0,n),f=Math.round(Math.abs(e));for(let p=0;p<f;p++)s=="page"?d=r.moveVertically(d,e>0,l):s=="line"&&(d=r.moveVertically(d,e>0));let m=O(a,d.head);return(e<0&&d.head==0&&n!=0&&t.line==0&&t.ch!=0||e>0&&d.head==a.length&&m.ch!=n&&t.line==m.line)&&(m.hitSide=!0),m}charCoords(t,e){var s=this.cm6.contentDOM.getBoundingClientRect(),n=C(this.cm6.state.doc,t),r=this.cm6.coordsAtPos(n),a=-s.top;return{left:(r?.left||0)-s.left,top:(r?.top||0)+a,bottom:(r?.bottom||0)+a}}coordsChar(t,e){var s=this.cm6.contentDOM.getBoundingClientRect(),n=this.cm6.posAtCoords({x:t.left+s.left,y:t.top+s.top})||0;return O(this.cm6.state.doc,n)}getScrollInfo(){var t=this.cm6.scrollDOM;return{left:t.scrollLeft,top:t.scrollTop,height:t.scrollHeight,width:t.scrollWidth,clientHeight:t.clientHeight,clientWidth:t.clientWidth}}scrollTo(t,e){t!=null&&(this.cm6.scrollDOM.scrollLeft=t),e!=null&&(this.cm6.scrollDOM.scrollTop=e)}scrollIntoView(t,e){if(t){var s=this.indexFromPos(t);this.cm6.dispatch({effects:P.scrollIntoView(s)})}else this.cm6.dispatch({scrollIntoView:!0,userEvent:"scroll"})}getWrapperElement(){return this.cm6.dom}getMode(){return{name:this.getOption("mode")}}setSize(t,e){this.cm6.dom.style.width=t+4+"px",this.cm6.dom.style.height=e+"px",this.refresh()}refresh(){this.cm6.measure()}destroy(){this.removeOverlay()}getLastEditEnd(){return this.posFromIndex(this.$lastChangeEndOffset)}onChange(t){this.$lineHandleChanges&&this.$lineHandleChanges.push(t);for(let s in this.marks)this.marks[s].update(t.changes);this.virtualSelection&&(this.virtualSelection.ranges=this.virtualSelection.ranges.map(s=>s.map(t.changes)));var e=this.curOp=this.curOp||{};t.changes.iterChanges((s,n,r,a,l)=>{(e.$changeStart==null||e.$changeStart>r)&&(e.$changeStart=r),this.$lastChangeEndOffset=a;var o={text:l.toJSON()};e.lastChange?e.lastChange.next=e.lastChange=o:e.lastChange=e.change=o},!0),e.changeHandlers||(e.changeHandlers=this._handlers.change&&this._handlers.change.slice())}onSelectionChange(){var t=this.curOp=this.curOp||{};t.cursorActivityHandlers||(t.cursorActivityHandlers=this._handlers.cursorActivity&&this._handlers.cursorActivity.slice()),this.curOp.cursorActivity=!0}operation(t,e){this.curOp||(this.curOp={$d:0}),this.curOp.$d++;try{var s=t()}finally{this.curOp&&(this.curOp.$d--,this.curOp.$d||this.onBeforeEndOperation())}return s}onBeforeEndOperation(){var t=this.curOp,e=!1;t&&(t.change&&_(t.changeHandlers,this,t.change),t&&t.cursorActivity&&(_(t.cursorActivityHandlers,this,null),t.isVimOp&&(e=!0)),this.curOp=null),e&&this.scrollIntoView()}moveH(t,e){if(e=="char"){var s=this.getCursor();this.setCursor(s.line,s.ch+t)}}setOption(t,e){switch(t){case"keyMap":this.state.keyMap=e;break;case"textwidth":this.state.textwidth=e;break}}getOption(t){switch(t){case"firstLineNumber":return 1;case"tabSize":return this.cm6.state.tabSize||4;case"readOnly":return this.cm6.state.readOnly;case"indentWithTabs":return this.cm6.state.facet(V)==" ";case"indentUnit":return this.cm6.state.facet(V).length||2;case"textwidth":return this.state.textwidth;case"keyMap":return this.state.keyMap||"vim"}}toggleOverwrite(t){this.state.overwrite=t}getTokenTypeAt(t){var e,s=this.indexFromPos(t),n=W(this.cm6.state,s),r=n?.resolve(s),a=((e=r?.type)===null||e===void 0?void 0:e.name)||"";return/comment/i.test(a)?"comment":/string/i.test(a)?"string":""}overWriteSelection(t){var e=this.cm6.state.doc,s=this.cm6.state.selection,n=s.ranges.map(r=>{if(r.empty){var a=r.to<e.length?e.sliceString(r.from,r.to+1):"";if(a&&!/\n/.test(a))return M.range(r.from,r.to+1)}return r});this.cm6.dispatch({selection:M.create(n,s.mainIndex)}),this.replaceSelection(t)}isInMultiSelectMode(){return this.cm6.state.selection.ranges.length>1}virtualSelectionMode(){return!!this.virtualSelection}forEachSelection(t){var e=this.cm6.state.selection;this.virtualSelection=M.create(e.ranges,e.mainIndex);for(var s=0;s<this.virtualSelection.ranges.length;s++){var n=this.virtualSelection.ranges[s];n&&(this.cm6.dispatch({selection:M.create([n])}),t(),this.virtualSelection.ranges[s]=this.cm6.state.selection.ranges[0])}this.cm6.dispatch({selection:this.virtualSelection}),this.virtualSelection=null}hardWrap(t){return Pt(this,t)}}c.isMac=typeof navigator<"u"&&/Mac/.test(navigator.platform);c.Pos=w;c.StringStream=rt;c.commands={toggleLineComment:function(i){Ct(i.cm6)},cursorCharLeft:function(i){yt(i.cm6)},redo:function(i){H(i,!1)},undo:function(i){H(i,!0)},newlineAndIndent:function(i){pt({state:i.cm6.state,dispatch:t=>N(i,t)})},indentAuto:function(i){gt(i.cm6)},newlineAndIndentContinueComment:void 0,save:void 0};c.isWordChar=function(i){return R.test(i)};c.keys=Mt;c.addClass=function(i,t){};c.rmClass=function(i,t){};c.e_preventDefault=function(i){i.preventDefault()};c.e_stop=function(i){var t,e;(t=i?.stopPropagation)===null||t===void 0||t.call(i),(e=i?.preventDefault)===null||e===void 0||e.call(i)};c.lookupKey=function(t,e,s){var n=c.keys[t];!n&&/^Arrow/.test(t)&&(n=c.keys[t.slice(5)]),n&&s(n)};c.on=U;c.off=q;c.signal=Q;c.findMatchingTag=Dt;c.findEnclosingTag=Lt;c.keyName=void 0;function X(i,t,e){var s=document.createElement("div");return s.appendChild(t),s}function j(i,t){i.state.currentNotificationClose&&i.state.currentNotificationClose(),i.state.currentNotificationClose=t}function kt(i,t,e){j(i,l);var s=X(i,t,e&&e.bottom),n=!1,r,a=e&&typeof e.duration<"u"?e.duration:5e3;function l(){n||(n=!0,clearTimeout(r),s.remove(),G(i,s))}return s.onclick=function(o){o.preventDefault(),l()},Y(i,s),a&&(r=setTimeout(l,a)),l}function Y(i,t){var e=i.state.dialog;i.state.dialog=t,t.style.flex="1",t&&e!==t&&(e&&e.contains(document.activeElement)&&i.focus(),e&&e.parentElement?e.parentElement.replaceChild(t,e):e&&e.remove(),c.signal(i,"dialog"))}function G(i,t){i.state.dialog==t&&(i.state.dialog=null,c.signal(i,"dialog"))}function xt(i,t,e,s){s||(s={}),j(i,void 0);var n=X(i,t,s.bottom),r=!1;Y(i,n);function a(o){if(typeof o=="string")l.value=o;else{if(r)return;r=!0,G(i,n),i.state.dialog||i.focus(),s.onClose&&s.onClose(n)}}var l=n.getElementsByTagName("input")[0];return l&&(s.value&&(l.value=s.value,s.selectValueOnOpen!==!1&&l.select()),s.onInput&&c.on(l,"input",function(o){s.onInput(o,l.value,a)}),s.onKeyUp&&c.on(l,"keyup",function(o){s.onKeyUp(o,l.value,a)}),c.on(l,"keydown",function(o){s&&s.onKeyDown&&s.onKeyDown(o,l.value,a)||(o.keyCode==13&&e&&e(l.value),(o.keyCode==27||s.closeOnEnter!==!1&&o.keyCode==13)&&(l.blur(),c.e_stop(o),a()))}),s.closeOnBlur!==!1&&c.on(l,"blur",function(){setTimeout(function(){document.activeElement!==l&&a()})}),l.focus()),a}var bt={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<","<":">>",">":"<<"};function wt(i){return i&&i.bracketRegex||/[(){}[\]]/}function Et(i,t,e,s,n){for(var r=n&&n.maxScanLineLength||1e4,a=n&&n.maxScanLines||1e3,l=[],o=wt(n),d=e>0?Math.min(t.line+a,i.lastLine()+1):Math.max(i.firstLine()-1,t.line-a),f=t.line;f!=d;f+=e){var m=i.getLine(f);if(m){var p=e>0?0:m.length-1,h=e>0?m.length:-1;if(!(m.length>r))for(f==t.line&&(p=t.ch-(e<0?1:0));p!=h;p+=e){var u=m.charAt(p);if(o.test(u)){var g=bt[u];if(g&&g.charAt(1)==">"==e>0)l.push(u);else if(l.length)l.pop();else return{pos:new w(f,p),ch:u}}}}}return f-e==(e>0?i.lastLine():i.firstLine())?!1:null}function Dt(i,t){return null}function Lt(i,t){var e,s,n=i.cm6.state,r=i.indexFromPos(t);if(r<n.doc.length){var a=n.sliceDoc(r,r+1);a=="<"&&r++}for(var l=W(n,r),o=l?.resolve(r)||null;o;){if(((e=o.firstChild)===null||e===void 0?void 0:e.type.name)=="OpenTag"&&((s=o.lastChild)===null||s===void 0?void 0:s.type.name)=="CloseTag")return{open:$(n.doc,o.firstChild),close:$(n.doc,o.lastChild)};o=o.parent}}function $(i,t){return{from:O(i,t.from),to:O(i,t.to)}}class Nt{constructor(t,e,s){this.cm=t,this.id=t.$mid++,this.offset=e,this.assoc=s,t.marks[this.id]=this}clear(){delete this.cm.marks[this.id]}find(){return this.offset==null?null:this.cm.posFromIndex(this.offset)}update(t){this.offset!=null&&(this.offset=t.mapPos(this.offset,this.assoc,K.TrackDel))}}function Pt(i,t){for(var e,s=t.column||i.getOption("textwidth")||80,n=t.allowMerge!=!1,r=Math.min(t.from,t.to),a=Math.max(t.from,t.to);r<=a;){var l=i.getLine(r);if(l.length>s){var o=u(l,s,5);if(o){var d=(e=/^\s*/.exec(l))===null||e===void 0?void 0:e[0];i.replaceRange(`
4
+ `+d,new w(r,o.start),new w(r,o.end))}a++}else if(n&&/\S/.test(l)&&r!=a){var f=i.getLine(r+1);if(f&&/\S/.test(f)){var m=l.replace(/\s+$/,""),p=f.replace(/^\s+/,""),h=m+" "+p,o=u(h,s,5);o&&o.start>m.length||h.length<s?(i.replaceRange(" ",new w(r,m.length),new w(r+1,f.length-p.length)),r--,a--):m.length<l.length&&i.replaceRange("",new w(r,m.length),new w(r,l.length))}}r++}return r;function u(g,v,y){if(!(g.length<v)){var k=g.slice(0,v),x=g.slice(v),b=/^(?:(\s+)|(\S+)(\s+))/.exec(x),S=/(?:(\s+)|(\s+)(\S+))$/.exec(k),E=0,F=0;if(S&&!S[2]&&(E=v-S[1].length,F=v),b&&!b[2]&&(E||(E=v),F=v+b[1].length),E)return{start:E,end:F};if(S&&S[2]&&S.index>y)return{start:S.index,end:S.index+S[2].length};if(b&&b[2])return E=v+b[2].length,{start:E,end:E+b[3].length}}}}let A=ot||(function(){let i={cursorBlinkRate:1200};return function(){return i}})();class Ft{constructor(t,e,s,n,r,a,l,o,d,f){this.left=t,this.top=e,this.height=s,this.fontFamily=n,this.fontSize=r,this.fontWeight=a,this.color=l,this.className=o,this.letter=d,this.partial=f}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",t.style.height=this.height+"px",t.style.lineHeight=this.height+"px",t.style.fontFamily=this.fontFamily,t.style.fontSize=this.fontSize,t.style.fontWeight=this.fontWeight,t.style.color=this.partial?"transparent":this.color,t.className=this.className,t.textContent=this.letter}eq(t){return this.left==t.left&&this.top==t.top&&this.height==t.height&&this.fontFamily==t.fontFamily&&this.fontSize==t.fontSize&&this.fontWeight==t.fontWeight&&this.color==t.color&&this.className==t.className&&this.letter==t.letter}}class Tt{constructor(t,e){this.view=t,this.rangePieces=[],this.cursors=[],this.cm=e,this.measureReq={read:this.readPos.bind(this),write:this.drawSel.bind(this)},this.cursorLayer=t.scrollDOM.appendChild(document.createElement("div")),this.cursorLayer.className="cm-cursorLayer cm-vimCursorLayer",this.cursorLayer.setAttribute("aria-hidden","true"),t.requestMeasure(this.measureReq),this.setBlinkRate()}setBlinkRate(){let e=A(this.cm.cm6.state).cursorBlinkRate;this.cursorLayer.style.animationDuration=e+"ms"}update(t){(t.selectionSet||t.geometryChanged||t.viewportChanged)&&(this.view.requestMeasure(this.measureReq),this.cursorLayer.style.animationName=this.cursorLayer.style.animationName=="cm-blink"?"cm-blink2":"cm-blink"),Bt(t)&&this.setBlinkRate()}scheduleRedraw(){this.view.requestMeasure(this.measureReq)}readPos(){let{state:t}=this.view,e=[];for(let s of t.selection.ranges){let n=s==t.selection.main,r=Vt(this.cm,this.view,s,n);r&&e.push(r)}return{cursors:e}}drawSel({cursors:t}){if(t.length!=this.cursors.length||t.some((e,s)=>!e.eq(this.cursors[s]))){let e=this.cursorLayer.children;if(e.length!==t.length){this.cursorLayer.textContent="";for(const s of t)this.cursorLayer.appendChild(s.draw())}else t.forEach((s,n)=>s.adjust(e[n]));this.cursors=t}}destroy(){this.cursorLayer.remove()}}function Bt(i){return A(i.startState)!=A(i.state)}const Rt={".cm-vimMode .cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-fat-cursor":{position:"absolute",background:"#ff9696",border:"none",whiteSpace:"pre"},"&:not(.cm-focused) .cm-fat-cursor":{background:"none",outline:"solid 1px #ff9696",color:"transparent !important"}},At=et.highest(P.theme(Rt));function It(i){let t=i.scrollDOM.getBoundingClientRect();return{left:(i.textDirection==lt.LTR?t.left:t.right-i.scrollDOM.clientWidth)-i.scrollDOM.scrollLeft*i.scaleX,top:t.top-i.scrollDOM.scrollTop*i.scaleY}}function Vt(i,t,e,s){var n,r,a,l;let o=e.head,d=!1,f=1,m=i.state.vim;if(m&&(!m.insertMode||i.state.overwrite)){if(d=!0,m.visualBlock&&!s)return null;e.anchor<e.head&&(o<t.state.doc.length&&t.state.sliceDoc(o,o+1))!=`
5
+ `&&o--,i.state.overwrite?f=.2:m.status&&(f=.5)}if(d){let h=o<t.state.doc.length&&t.state.sliceDoc(o,o+1);h&&/[\uDC00-\uDFFF]/.test(h)&&o>1&&(o--,h=t.state.sliceDoc(o,o+1));let u=t.coordsAtPos(o,1);if(!u)return null;let g=It(t),v=t.domAtPos(o),y=v?v.node:t.contentDOM;for(y instanceof Text&&v.offset>=y.data.length&&!((n=y.parentElement)===null||n===void 0)&&n.nextSibling&&(y=(r=y.parentElement)===null||r===void 0?void 0:r.nextSibling,v={node:y,offset:0});v&&v.node instanceof HTMLElement;)y=v.node,v={node:v.node.childNodes[v.offset],offset:0};if(!(y instanceof HTMLElement)){if(!y.parentNode)return null;y=y.parentNode}let k=getComputedStyle(y),x=u.left,b=(l=(a=t).coordsForChar)===null||l===void 0?void 0:l.call(a,o);if(b&&(x=b.left),!h||h==`
6
+ `||h=="\r")h=" ";else if(h==" "){h=" ";var p=t.coordsAtPos(o+1,-1);p&&(x=p.left-(p.left-u.left)/parseInt(k.tabSize))}else/[\uD800-\uDBFF]/.test(h)&&o<t.state.doc.length-1&&(h+=t.state.sliceDoc(o+1,o+2));let S=u.bottom-u.top;return new Ft((x-g.left)/t.scaleX,(u.top-g.top+S*(1-f))/t.scaleY,S*f/t.scaleY,k.fontFamily,k.fontSize,k.fontWeight,k.color,s?"cm-fat-cursor cm-cursor-primary":"cm-fat-cursor cm-cursor-secondary",h,f!=1)}else return null}var _t=typeof navigator<"u"&&/linux/i.test(navigator.platform)&&/ Gecko\/\d+/.exec(navigator.userAgent);const D=Z(c),Ht=250,$t=P.baseTheme({".cm-vimMode .cm-cursorLayer:not(.cm-vimCursorLayer)":{display:"none"},".cm-vim-panel":{padding:"0px 10px",fontFamily:"monospace",minHeight:"1.3em",display:"flex"},".cm-vim-panel input":{border:"none",outline:"none",backgroundColor:"inherit"},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"}}),Kt=at.fromClass(class{constructor(i){this.status="",this.query=null,this.decorations=T.none,this.waitForCopy=!1,this.lastKeydown="",this.useNextTextInput=!1,this.compositionText="",this.view=i;const t=this.cm=new c(i);D.enterVimMode(this.cm),this.view.cm=this.cm,this.cm.state.vimPlugin=this,this.blockCursor=new Tt(i,t),this.updateClass(),this.cm.on("vim-command-done",()=>{t.state.vim&&(t.state.vim.status=""),this.blockCursor.scheduleRedraw(),this.updateStatus()}),this.cm.on("vim-mode-change",e=>{t.state.vim&&(t.state.vim.mode=e.mode,e.subMode&&(t.state.vim.mode+=e.subMode==="linewise"?" line":" block"),t.state.vim.status="",this.blockCursor.scheduleRedraw(),this.updateClass(),this.updateStatus())}),this.cm.on("dialog",()=>{this.cm.state.statusbar?this.updateStatus():i.dispatch({effects:J.of(!!this.cm.state.dialog)})}),this.dom=document.createElement("span"),this.spacer=document.createElement("span"),this.spacer.style.flex="1",this.statusButton=document.createElement("span"),this.statusButton.onclick=e=>{D.handleKey(this.cm,"<Esc>","user"),this.cm.focus()},this.statusButton.style.cssText="cursor: pointer"}update(i){var t;if((i.viewportChanged||i.docChanged)&&this.query&&this.highlight(this.query),i.docChanged&&this.cm.onChange(i),i.selectionSet&&this.cm.onSelectionChange(),i.viewportChanged,this.cm.curOp&&!this.cm.curOp.isVimOp&&this.cm.onBeforeEndOperation(),i.transactions){for(let e of i.transactions)for(let s of e.effects)if(s.is(B))if(!((t=s.value)===null||t===void 0?void 0:t.forVim))this.highlight(null);else{let r=s.value.create();this.highlight(r)}}this.blockCursor.update(i)}updateClass(){const i=this.cm.state;!i.vim||i.vim.insertMode&&!i.overwrite?this.view.scrollDOM.classList.remove("cm-vimMode"):this.view.scrollDOM.classList.add("cm-vimMode")}updateStatus(){let i=this.cm.state.statusbar,t=this.cm.state.vim;if(!i||!t)return;let e=this.cm.state.dialog;if(e)e.parentElement!=i&&(i.textContent="",i.appendChild(e));else{i.textContent="";var s=(t.mode||"normal").toUpperCase();t.insertModeReturn&&(s+="(C-O)"),this.statusButton.textContent=`--${s}--`,i.appendChild(this.statusButton),i.appendChild(this.spacer)}this.dom.textContent=t.status,i.appendChild(this.dom)}destroy(){D.leaveVimMode(this.cm),this.updateClass(),this.blockCursor.destroy(),delete this.view.cm}highlight(i){if(this.query=i,!i)return this.decorations=T.none;let{view:t}=this,e=new tt;for(let s=0,n=t.visibleRanges,r=n.length;s<r;s++){let{from:a,to:l}=n[s];for(;s<r-1&&l>n[s+1].from-2*Ht;)l=n[++s].to;i.highlight(t.state,a,l,(o,d)=>{e.add(o,d,zt)})}return this.decorations=e.finish()}handleKey(i,t){const e=this.cm;let s=e.state.vim;if(!s)return;const n=D.vimKeyFromEvent(i,s);if(c.signal(this.cm,"inputEvent",{type:"handleKey",key:n}),!n)return;if(n=="<Esc>"&&!s.insertMode&&!s.visualMode&&this.query){const l=s.searchState_;l&&(e.removeOverlay(l.getOverlay()),l.setOverlay(null))}if(n==="<C-c>"&&!c.isMac&&e.somethingSelected())return this.waitForCopy=!0,!0;s.status=(s.status||"")+n;let a=D.multiSelectHandleKey(e,n,"user");return s=D.maybeInitVimState_(e),!a&&s.insertMode&&e.state.overwrite&&(i.key&&i.key.length==1&&!/\n/.test(i.key)?(a=!0,e.overWriteSelection(i.key)):i.key=="Backspace"&&(a=!0,c.commands.cursorCharLeft(e))),a&&(c.signal(this.cm,"vim-keypress",n),i.preventDefault(),i.stopPropagation(),this.blockCursor.scheduleRedraw()),this.updateStatus(),!!a}},{eventHandlers:{copy:function(i,t){this.waitForCopy&&(this.waitForCopy=!1,Promise.resolve().then(()=>{var e=this.cm,s=e.state.vim;s&&(s.insertMode?e.setSelection(e.getCursor(),e.getCursor()):e.operation(()=>{e.curOp&&(e.curOp.isVimOp=!0),D.handleKey(e,"<Esc>","user")}))}))},compositionstart:function(i,t){this.useNextTextInput=!0,c.signal(this.cm,"inputEvent",i)},compositionupdate:function(i,t){c.signal(this.cm,"inputEvent",i)},compositionend:function(i,t){c.signal(this.cm,"inputEvent",i)},keypress:function(i,t){c.signal(this.cm,"inputEvent",i),this.lastKeydown=="Dead"&&this.handleKey(i,t)},keydown:function(i,t){c.signal(this.cm,"inputEvent",i),this.lastKeydown=i.key,this.lastKeydown=="Unidentified"||this.lastKeydown=="Process"||this.lastKeydown=="Dead"?this.useNextTextInput=!0:(this.useNextTextInput=!1,this.handleKey(i,t))}},provide:()=>[P.inputHandler.of((i,t,e,s)=>{var n,r,a=Xt(i);if(!a)return!1;var l=(n=a.state)===null||n===void 0?void 0:n.vim,o=a.state.vimPlugin;if(l&&!l.insertMode&&!(!((r=a.curOp)===null||r===void 0)&&r.isVimOp)){if(s==="\0\0")return!0;if(c.signal(a,"inputEvent",{type:"text",text:s,from:t,to:e}),s.length==1&&o.useNextTextInput){if(l.expectLiteralNext&&i.composing)return o.compositionText=s,!1;if(o.compositionText){var d=o.compositionText;o.compositionText="";var f=i.state.selection.main.head,m=i.state.sliceDoc(f-d.length,f);if(d===m){var p=a.getCursor();a.replaceRange("",a.posFromIndex(f-d.length),p)}}return o.handleKey({key:s,preventDefault:()=>{},stopPropagation:()=>{}}),Wt(i),!0}}return!1})],decorations:i=>i.decorations});function Wt(i){var t=i.scrollDOM.parentElement;if(t){if(_t){i.contentDOM.textContent="\0\0",i.contentDOM.dispatchEvent(new CustomEvent("compositionend"));return}var e=i.scrollDOM.nextSibling,s=window.getSelection(),n=s&&{anchorNode:s.anchorNode,anchorOffset:s.anchorOffset,focusNode:s.focusNode,focusOffset:s.focusOffset};i.scrollDOM.remove(),t.insertBefore(i.scrollDOM,e);try{n&&s&&(s.setPosition(n.anchorNode,n.anchorOffset),n.focusNode&&s.extend(n.focusNode,n.focusOffset))}catch(r){console.error(r)}i.focus(),i.contentDOM.dispatchEvent(new CustomEvent("compositionend"))}}const zt=T.mark({class:"cm-searchMatch"}),J=st.define(),Ut=it.define({create:()=>!1,update(i,t){for(let e of t.effects)e.is(J)&&(i=e.value);return i},provide:i=>z.from(i,t=>t?qt:null)});function qt(i){let t=document.createElement("div");t.className="cm-vim-panel";let e=i.cm;return e.state.dialog&&t.appendChild(e.state.dialog),{top:!1,dom:t}}function Qt(i){let t=document.createElement("div");t.className="cm-vim-panel";let e=i.cm;return e.state.statusbar=t,e.state.vimPlugin.updateStatus(),{dom:t}}function ee(i={}){return[$t,Kt,At,i.status?z.of(Qt):Ut]}function Xt(i){return i.cm||null}export{Xt as g,ee as v};