groove-dev 0.15.1 → 0.16.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 (330) hide show
  1. package/docs/FILE-EDITOR-PLAN.md +253 -0
  2. package/node_modules/@codemirror/autocomplete/.github/workflows/dispatch.yml +16 -0
  3. package/node_modules/@codemirror/autocomplete/CHANGELOG.md +639 -0
  4. package/node_modules/@codemirror/autocomplete/LICENSE +21 -0
  5. package/node_modules/@codemirror/autocomplete/README.md +43 -0
  6. package/node_modules/@codemirror/autocomplete/dist/index.cjs +2151 -0
  7. package/node_modules/@codemirror/autocomplete/dist/index.d.cts +648 -0
  8. package/node_modules/@codemirror/autocomplete/dist/index.d.ts +648 -0
  9. package/node_modules/@codemirror/autocomplete/dist/index.js +2120 -0
  10. package/node_modules/@codemirror/autocomplete/package.json +41 -0
  11. package/node_modules/@codemirror/commands/.github/workflows/dispatch.yml +16 -0
  12. package/node_modules/@codemirror/commands/CHANGELOG.md +386 -0
  13. package/node_modules/@codemirror/commands/LICENSE +21 -0
  14. package/node_modules/@codemirror/commands/README.md +35 -0
  15. package/node_modules/@codemirror/commands/dist/index.cjs +1909 -0
  16. package/node_modules/@codemirror/commands/dist/index.d.cts +650 -0
  17. package/node_modules/@codemirror/commands/dist/index.d.ts +650 -0
  18. package/node_modules/@codemirror/commands/dist/index.js +1795 -0
  19. package/node_modules/@codemirror/commands/package.json +42 -0
  20. package/node_modules/@codemirror/lang-css/.github/workflows/dispatch.yml +16 -0
  21. package/node_modules/@codemirror/lang-css/CHANGELOG.md +106 -0
  22. package/node_modules/@codemirror/lang-css/LICENSE +21 -0
  23. package/node_modules/@codemirror/lang-css/README.md +50 -0
  24. package/node_modules/@codemirror/lang-css/dist/index.cjs +269 -0
  25. package/node_modules/@codemirror/lang-css/dist/index.d.cts +28 -0
  26. package/node_modules/@codemirror/lang-css/dist/index.d.ts +28 -0
  27. package/node_modules/@codemirror/lang-css/dist/index.js +264 -0
  28. package/node_modules/@codemirror/lang-css/package.json +42 -0
  29. package/node_modules/@codemirror/lang-html/.github/workflows/dispatch.yml +16 -0
  30. package/node_modules/@codemirror/lang-html/CHANGELOG.md +210 -0
  31. package/node_modules/@codemirror/lang-html/LICENSE +21 -0
  32. package/node_modules/@codemirror/lang-html/README.md +147 -0
  33. package/node_modules/@codemirror/lang-html/dist/index.cjs +667 -0
  34. package/node_modules/@codemirror/lang-html/dist/index.d.cts +115 -0
  35. package/node_modules/@codemirror/lang-html/dist/index.d.ts +115 -0
  36. package/node_modules/@codemirror/lang-html/dist/index.js +661 -0
  37. package/node_modules/@codemirror/lang-html/package.json +46 -0
  38. package/node_modules/@codemirror/lang-javascript/.github/workflows/dispatch.yml +16 -0
  39. package/node_modules/@codemirror/lang-javascript/CHANGELOG.md +206 -0
  40. package/node_modules/@codemirror/lang-javascript/LICENSE +21 -0
  41. package/node_modules/@codemirror/lang-javascript/README.md +125 -0
  42. package/node_modules/@codemirror/lang-javascript/dist/index.cjs +526 -0
  43. package/node_modules/@codemirror/lang-javascript/dist/index.d.cts +93 -0
  44. package/node_modules/@codemirror/lang-javascript/dist/index.d.ts +93 -0
  45. package/node_modules/@codemirror/lang-javascript/dist/index.js +513 -0
  46. package/node_modules/@codemirror/lang-javascript/package.json +45 -0
  47. package/node_modules/@codemirror/lang-json/.github/workflows/dispatch.yml +16 -0
  48. package/node_modules/@codemirror/lang-json/CHANGELOG.md +59 -0
  49. package/node_modules/@codemirror/lang-json/LICENSE +21 -0
  50. package/node_modules/@codemirror/lang-json/README.md +56 -0
  51. package/node_modules/@codemirror/lang-json/dist/index.cjs +68 -0
  52. package/node_modules/@codemirror/lang-json/dist/index.d.cts +22 -0
  53. package/node_modules/@codemirror/lang-json/dist/index.d.ts +22 -0
  54. package/node_modules/@codemirror/lang-json/dist/index.js +64 -0
  55. package/node_modules/@codemirror/lang-json/package.json +39 -0
  56. package/node_modules/@codemirror/lang-markdown/.github/workflows/dispatch.yml +16 -0
  57. package/node_modules/@codemirror/lang-markdown/CHANGELOG.md +246 -0
  58. package/node_modules/@codemirror/lang-markdown/LICENSE +21 -0
  59. package/node_modules/@codemirror/lang-markdown/README.md +162 -0
  60. package/node_modules/@codemirror/lang-markdown/dist/index.cjs +501 -0
  61. package/node_modules/@codemirror/lang-markdown/dist/index.d.cts +124 -0
  62. package/node_modules/@codemirror/lang-markdown/dist/index.d.ts +124 -0
  63. package/node_modules/@codemirror/lang-markdown/dist/index.js +492 -0
  64. package/node_modules/@codemirror/lang-markdown/package.json +44 -0
  65. package/node_modules/@codemirror/lang-python/.github/workflows/dispatch.yml +16 -0
  66. package/node_modules/@codemirror/lang-python/CHANGELOG.md +174 -0
  67. package/node_modules/@codemirror/lang-python/LICENSE +21 -0
  68. package/node_modules/@codemirror/lang-python/README.md +61 -0
  69. package/node_modules/@codemirror/lang-python/dist/index.cjs +313 -0
  70. package/node_modules/@codemirror/lang-python/dist/index.d.cts +26 -0
  71. package/node_modules/@codemirror/lang-python/dist/index.d.ts +26 -0
  72. package/node_modules/@codemirror/lang-python/dist/index.js +308 -0
  73. package/node_modules/@codemirror/lang-python/package.json +42 -0
  74. package/node_modules/@codemirror/language/.github/workflows/dispatch.yml +16 -0
  75. package/node_modules/@codemirror/language/CHANGELOG.md +412 -0
  76. package/node_modules/@codemirror/language/LICENSE +21 -0
  77. package/node_modules/@codemirror/language/README.md +66 -0
  78. package/node_modules/@codemirror/language/dist/index.cjs +2742 -0
  79. package/node_modules/@codemirror/language/dist/index.d.cts +1220 -0
  80. package/node_modules/@codemirror/language/dist/index.d.ts +1220 -0
  81. package/node_modules/@codemirror/language/dist/index.js +2687 -0
  82. package/node_modules/@codemirror/language/package.json +44 -0
  83. package/node_modules/@codemirror/lint/.github/workflows/dispatch.yml +16 -0
  84. package/node_modules/@codemirror/lint/CHANGELOG.md +318 -0
  85. package/node_modules/@codemirror/lint/LICENSE +21 -0
  86. package/node_modules/@codemirror/lint/README.md +18 -0
  87. package/node_modules/@codemirror/lint/dist/index.cjs +958 -0
  88. package/node_modules/@codemirror/lint/dist/index.d.cts +195 -0
  89. package/node_modules/@codemirror/lint/dist/index.d.ts +195 -0
  90. package/node_modules/@codemirror/lint/dist/index.js +945 -0
  91. package/node_modules/@codemirror/lint/package.json +40 -0
  92. package/node_modules/@codemirror/search/.github/workflows/dispatch.yml +16 -0
  93. package/node_modules/@codemirror/search/CHANGELOG.md +324 -0
  94. package/node_modules/@codemirror/search/LICENSE +21 -0
  95. package/node_modules/@codemirror/search/README.md +18 -0
  96. package/node_modules/@codemirror/search/dist/index.cjs +1237 -0
  97. package/node_modules/@codemirror/search/dist/index.d.cts +385 -0
  98. package/node_modules/@codemirror/search/dist/index.d.ts +385 -0
  99. package/node_modules/@codemirror/search/dist/index.js +1217 -0
  100. package/node_modules/@codemirror/search/package.json +40 -0
  101. package/node_modules/@codemirror/state/.github/workflows/dispatch.yml +16 -0
  102. package/node_modules/@codemirror/state/CHANGELOG.md +308 -0
  103. package/node_modules/@codemirror/state/LICENSE +21 -0
  104. package/node_modules/@codemirror/state/README.md +18 -0
  105. package/node_modules/@codemirror/state/dist/index.cjs +3922 -0
  106. package/node_modules/@codemirror/state/dist/index.d.cts +1713 -0
  107. package/node_modules/@codemirror/state/dist/index.d.ts +1713 -0
  108. package/node_modules/@codemirror/state/dist/index.js +3892 -0
  109. package/node_modules/@codemirror/state/package.json +38 -0
  110. package/node_modules/@codemirror/theme-one-dark/.github/workflows/dispatch.yml +16 -0
  111. package/node_modules/@codemirror/theme-one-dark/CHANGELOG.md +97 -0
  112. package/node_modules/@codemirror/theme-one-dark/LICENSE +21 -0
  113. package/node_modules/@codemirror/theme-one-dark/README.md +46 -0
  114. package/node_modules/@codemirror/theme-one-dark/dist/index.cjs +139 -0
  115. package/node_modules/@codemirror/theme-one-dark/dist/index.d.cts +39 -0
  116. package/node_modules/@codemirror/theme-one-dark/dist/index.d.ts +39 -0
  117. package/node_modules/@codemirror/theme-one-dark/dist/index.js +134 -0
  118. package/node_modules/@codemirror/theme-one-dark/package.json +41 -0
  119. package/node_modules/@codemirror/view/.github/workflows/dispatch.yml +16 -0
  120. package/node_modules/@codemirror/view/CHANGELOG.md +2284 -0
  121. package/node_modules/@codemirror/view/LICENSE +21 -0
  122. package/node_modules/@codemirror/view/README.md +37 -0
  123. package/node_modules/@codemirror/view/dist/index.cjs +11796 -0
  124. package/node_modules/@codemirror/view/dist/index.d.cts +2389 -0
  125. package/node_modules/@codemirror/view/dist/index.d.ts +2389 -0
  126. package/node_modules/@codemirror/view/dist/index.js +11745 -0
  127. package/node_modules/@codemirror/view/package.json +41 -0
  128. package/node_modules/@groove-dev/daemon/src/api.js +147 -2
  129. package/node_modules/@groove-dev/daemon/src/filewatcher.js +59 -0
  130. package/node_modules/@groove-dev/daemon/src/index.js +28 -1
  131. package/node_modules/@groove-dev/gui/dist/assets/index-Dxg9hdf3.js +103 -0
  132. package/node_modules/@groove-dev/gui/dist/index.html +1 -1
  133. package/node_modules/@groove-dev/gui/package.json +15 -2
  134. package/node_modules/@groove-dev/gui/src/App.jsx +3 -0
  135. package/node_modules/@groove-dev/gui/src/components/CodeEditor.jsx +143 -0
  136. package/node_modules/@groove-dev/gui/src/components/EditorTabs.jsx +83 -0
  137. package/node_modules/@groove-dev/gui/src/components/FileTree.jsx +193 -0
  138. package/node_modules/@groove-dev/gui/src/stores/groove.js +158 -1
  139. package/node_modules/@groove-dev/gui/src/views/FileEditor.jsx +142 -0
  140. package/node_modules/@lezer/common/LICENSE +21 -0
  141. package/node_modules/@lezer/common/README.md +14 -0
  142. package/node_modules/@lezer/common/dist/index.cjs +2209 -0
  143. package/node_modules/@lezer/common/dist/index.d.cts +1174 -0
  144. package/node_modules/@lezer/common/dist/index.d.ts +1174 -0
  145. package/node_modules/@lezer/common/dist/index.js +2196 -0
  146. package/node_modules/@lezer/common/package.json +32 -0
  147. package/node_modules/@lezer/css/CHANGELOG.md +307 -0
  148. package/node_modules/@lezer/css/LICENSE +21 -0
  149. package/node_modules/@lezer/css/README.md +6 -0
  150. package/node_modules/@lezer/css/dist/index.cjs +151 -0
  151. package/node_modules/@lezer/css/dist/index.d.cts +3 -0
  152. package/node_modules/@lezer/css/dist/index.d.ts +3 -0
  153. package/node_modules/@lezer/css/dist/index.js +147 -0
  154. package/node_modules/@lezer/css/package.json +36 -0
  155. package/node_modules/@lezer/css/rollup.config.js +16 -0
  156. package/node_modules/@lezer/css/src/css.grammar +290 -0
  157. package/node_modules/@lezer/css/src/highlight.js +36 -0
  158. package/node_modules/@lezer/css/src/parser.js +31 -0
  159. package/node_modules/@lezer/css/src/parser.terms.js +63 -0
  160. package/node_modules/@lezer/css/src/tokens.js +75 -0
  161. package/node_modules/@lezer/css/test/declarations.txt +241 -0
  162. package/node_modules/@lezer/css/test/selector.txt +178 -0
  163. package/node_modules/@lezer/css/test/statements.txt +227 -0
  164. package/node_modules/@lezer/css/test/test-css.js +16 -0
  165. package/node_modules/@lezer/highlight/LICENSE +21 -0
  166. package/node_modules/@lezer/highlight/README.md +14 -0
  167. package/node_modules/@lezer/highlight/dist/index.cjs +936 -0
  168. package/node_modules/@lezer/highlight/dist/index.d.cts +623 -0
  169. package/node_modules/@lezer/highlight/dist/index.d.ts +623 -0
  170. package/node_modules/@lezer/highlight/dist/index.js +927 -0
  171. package/node_modules/@lezer/highlight/package.json +31 -0
  172. package/node_modules/@lezer/html/CHANGELOG.md +303 -0
  173. package/node_modules/@lezer/html/LICENSE +21 -0
  174. package/node_modules/@lezer/html/README.md +37 -0
  175. package/node_modules/@lezer/html/dist/index.cjs +354 -0
  176. package/node_modules/@lezer/html/dist/index.d.cts +14 -0
  177. package/node_modules/@lezer/html/dist/index.d.ts +14 -0
  178. package/node_modules/@lezer/html/dist/index.js +349 -0
  179. package/node_modules/@lezer/html/package.json +37 -0
  180. package/node_modules/@lezer/html/rollup.config.js +16 -0
  181. package/node_modules/@lezer/html/src/.tern-port +1 -0
  182. package/node_modules/@lezer/html/src/content.js +87 -0
  183. package/node_modules/@lezer/html/src/highlight.js +15 -0
  184. package/node_modules/@lezer/html/src/html.grammar +181 -0
  185. package/node_modules/@lezer/html/src/index.js +2 -0
  186. package/node_modules/@lezer/html/src/parser.js +27 -0
  187. package/node_modules/@lezer/html/src/parser.terms.js +53 -0
  188. package/node_modules/@lezer/html/src/tokens.js +199 -0
  189. package/node_modules/@lezer/html/test/mixed.txt +69 -0
  190. package/node_modules/@lezer/html/test/tags.txt +370 -0
  191. package/node_modules/@lezer/html/test/test-html.js +29 -0
  192. package/node_modules/@lezer/html/test/test-incremental.js +97 -0
  193. package/node_modules/@lezer/html/test/vue.txt +56 -0
  194. package/node_modules/@lezer/javascript/CHANGELOG.md +485 -0
  195. package/node_modules/@lezer/javascript/LICENSE +21 -0
  196. package/node_modules/@lezer/javascript/README.md +14 -0
  197. package/node_modules/@lezer/javascript/dist/index.cjs +196 -0
  198. package/node_modules/@lezer/javascript/dist/index.d.cts +3 -0
  199. package/node_modules/@lezer/javascript/dist/index.d.ts +3 -0
  200. package/node_modules/@lezer/javascript/dist/index.js +192 -0
  201. package/node_modules/@lezer/javascript/package.json +36 -0
  202. package/node_modules/@lezer/javascript/rollup.config.js +16 -0
  203. package/node_modules/@lezer/javascript/src/highlight.js +62 -0
  204. package/node_modules/@lezer/javascript/src/javascript.grammar +735 -0
  205. package/node_modules/@lezer/javascript/src/parser.js +33 -0
  206. package/node_modules/@lezer/javascript/src/parser.terms.js +177 -0
  207. package/node_modules/@lezer/javascript/src/tokens.js +87 -0
  208. package/node_modules/@lezer/javascript/test/decorator.txt +64 -0
  209. package/node_modules/@lezer/javascript/test/expression.txt +686 -0
  210. package/node_modules/@lezer/javascript/test/jsx.txt +79 -0
  211. package/node_modules/@lezer/javascript/test/semicolon.txt +77 -0
  212. package/node_modules/@lezer/javascript/test/statement.txt +404 -0
  213. package/node_modules/@lezer/javascript/test/test-javascript.js +17 -0
  214. package/node_modules/@lezer/javascript/test/typescript.txt +401 -0
  215. package/node_modules/@lezer/json/CHANGELOG.md +79 -0
  216. package/node_modules/@lezer/json/LICENSE +21 -0
  217. package/node_modules/@lezer/json/README.md +7 -0
  218. package/node_modules/@lezer/json/dist/index.cjs +41 -0
  219. package/node_modules/@lezer/json/dist/index.d.cts +3 -0
  220. package/node_modules/@lezer/json/dist/index.d.ts +3 -0
  221. package/node_modules/@lezer/json/dist/index.js +37 -0
  222. package/node_modules/@lezer/json/package.json +36 -0
  223. package/node_modules/@lezer/json/rollup.config.js +15 -0
  224. package/node_modules/@lezer/json/src/highlight.js +12 -0
  225. package/node_modules/@lezer/json/src/json.grammar +38 -0
  226. package/node_modules/@lezer/json/src/parser.js +23 -0
  227. package/node_modules/@lezer/json/src/parser.terms.js +12 -0
  228. package/node_modules/@lezer/json/test/arrays.txt +34 -0
  229. package/node_modules/@lezer/json/test/literals.txt +23 -0
  230. package/node_modules/@lezer/json/test/numbers.txt +87 -0
  231. package/node_modules/@lezer/json/test/objects.txt +34 -0
  232. package/node_modules/@lezer/json/test/strings.txt +50 -0
  233. package/node_modules/@lezer/json/test/test-json.js +17 -0
  234. package/node_modules/@lezer/lr/LICENSE +21 -0
  235. package/node_modules/@lezer/lr/README.md +25 -0
  236. package/node_modules/@lezer/lr/dist/constants.d.ts +45 -0
  237. package/node_modules/@lezer/lr/dist/constants.js +5 -0
  238. package/node_modules/@lezer/lr/dist/index.cjs +1891 -0
  239. package/node_modules/@lezer/lr/dist/index.d.cts +303 -0
  240. package/node_modules/@lezer/lr/dist/index.d.ts +303 -0
  241. package/node_modules/@lezer/lr/dist/index.js +1884 -0
  242. package/node_modules/@lezer/lr/package.json +32 -0
  243. package/node_modules/@lezer/markdown/CHANGELOG.md +279 -0
  244. package/node_modules/@lezer/markdown/LICENSE +21 -0
  245. package/node_modules/@lezer/markdown/README.md +725 -0
  246. package/node_modules/@lezer/markdown/bin/build-readme.cjs +39 -0
  247. package/node_modules/@lezer/markdown/build.js +16 -0
  248. package/node_modules/@lezer/markdown/dist/index.cjs +2352 -0
  249. package/node_modules/@lezer/markdown/dist/index.d.cts +600 -0
  250. package/node_modules/@lezer/markdown/dist/index.d.ts +600 -0
  251. package/node_modules/@lezer/markdown/dist/index.js +2335 -0
  252. package/node_modules/@lezer/markdown/package.json +37 -0
  253. package/node_modules/@lezer/markdown/src/README.md +83 -0
  254. package/node_modules/@lezer/markdown/src/extension.ts +301 -0
  255. package/node_modules/@lezer/markdown/src/index.ts +5 -0
  256. package/node_modules/@lezer/markdown/src/markdown.ts +1961 -0
  257. package/node_modules/@lezer/markdown/src/nest.ts +46 -0
  258. package/node_modules/@lezer/markdown/test/compare-tree.ts +14 -0
  259. package/node_modules/@lezer/markdown/test/spec.ts +79 -0
  260. package/node_modules/@lezer/markdown/test/test-extension.ts +269 -0
  261. package/node_modules/@lezer/markdown/test/test-incremental.ts +265 -0
  262. package/node_modules/@lezer/markdown/test/test-markdown.ts +3574 -0
  263. package/node_modules/@lezer/markdown/test/test-nesting.ts +86 -0
  264. package/node_modules/@lezer/markdown/test/tsconfig.json +12 -0
  265. package/node_modules/@lezer/markdown/tsconfig.json +14 -0
  266. package/node_modules/@lezer/python/CHANGELOG.md +243 -0
  267. package/node_modules/@lezer/python/LICENSE +21 -0
  268. package/node_modules/@lezer/python/README.md +6 -0
  269. package/node_modules/@lezer/python/dist/index.cjs +330 -0
  270. package/node_modules/@lezer/python/dist/index.d.cts +3 -0
  271. package/node_modules/@lezer/python/dist/index.d.ts +3 -0
  272. package/node_modules/@lezer/python/dist/index.js +326 -0
  273. package/node_modules/@lezer/python/package.json +36 -0
  274. package/node_modules/@lezer/python/rollup.config.js +16 -0
  275. package/node_modules/@lezer/python/src/highlight.js +35 -0
  276. package/node_modules/@lezer/python/src/python.grammar +381 -0
  277. package/node_modules/@lezer/python/src/tokens.js +224 -0
  278. package/node_modules/@lezer/python/test/expression.txt +231 -0
  279. package/node_modules/@lezer/python/test/statement.txt +442 -0
  280. package/node_modules/@lezer/python/test/test-incremental.js +33 -0
  281. package/node_modules/@lezer/python/test/test-python.js +17 -0
  282. package/node_modules/@marijn/find-cluster-break/LICENSE +21 -0
  283. package/node_modules/@marijn/find-cluster-break/README.md +28 -0
  284. package/node_modules/@marijn/find-cluster-break/dist/index.cjs +85 -0
  285. package/node_modules/@marijn/find-cluster-break/dist/index.d.cts +15 -0
  286. package/node_modules/@marijn/find-cluster-break/package.json +35 -0
  287. package/node_modules/@marijn/find-cluster-break/rollup.config.js +7 -0
  288. package/node_modules/@marijn/find-cluster-break/src/index.d.ts +15 -0
  289. package/node_modules/@marijn/find-cluster-break/src/index.js +87 -0
  290. package/node_modules/@marijn/find-cluster-break/test/test-cluster.js +30 -0
  291. package/node_modules/crelt/LICENSE +19 -0
  292. package/node_modules/crelt/README.md +23 -0
  293. package/node_modules/crelt/dist/index.cjs +31 -0
  294. package/node_modules/crelt/dist/index.d.cts +4 -0
  295. package/node_modules/crelt/index.d.ts +4 -0
  296. package/node_modules/crelt/index.js +28 -0
  297. package/node_modules/crelt/package.json +35 -0
  298. package/node_modules/crelt/rollup.config.js +13 -0
  299. package/node_modules/style-mod/LICENSE +19 -0
  300. package/node_modules/style-mod/README.md +98 -0
  301. package/node_modules/style-mod/dist/style-mod.cjs +165 -0
  302. package/node_modules/style-mod/dist/style-mod.d.cts +16 -0
  303. package/node_modules/style-mod/package.json +39 -0
  304. package/node_modules/style-mod/src/README.md +34 -0
  305. package/node_modules/style-mod/src/style-mod.d.ts +16 -0
  306. package/node_modules/style-mod/src/style-mod.js +172 -0
  307. package/node_modules/style-mod/test/test-style-mod.js +104 -0
  308. package/node_modules/w3c-keyname/.tern-port +1 -0
  309. package/node_modules/w3c-keyname/LICENSE +19 -0
  310. package/node_modules/w3c-keyname/README.md +18 -0
  311. package/node_modules/w3c-keyname/index.cjs +127 -0
  312. package/node_modules/w3c-keyname/index.d.cts +5 -0
  313. package/node_modules/w3c-keyname/index.d.ts +5 -0
  314. package/node_modules/w3c-keyname/index.js +119 -0
  315. package/node_modules/w3c-keyname/package.json +37 -0
  316. package/package.json +1 -1
  317. package/packages/daemon/src/api.js +147 -2
  318. package/packages/daemon/src/filewatcher.js +59 -0
  319. package/packages/daemon/src/index.js +28 -1
  320. package/packages/gui/dist/assets/index-Dxg9hdf3.js +103 -0
  321. package/packages/gui/dist/index.html +1 -1
  322. package/packages/gui/package.json +15 -2
  323. package/packages/gui/src/App.jsx +3 -0
  324. package/packages/gui/src/components/CodeEditor.jsx +143 -0
  325. package/packages/gui/src/components/EditorTabs.jsx +83 -0
  326. package/packages/gui/src/components/FileTree.jsx +193 -0
  327. package/packages/gui/src/stores/groove.js +158 -1
  328. package/packages/gui/src/views/FileEditor.jsx +142 -0
  329. package/node_modules/@groove-dev/gui/dist/assets/index-8Kqi_LVo.js +0 -74
  330. package/packages/gui/dist/assets/index-8Kqi_LVo.js +0 -74
@@ -0,0 +1,2742 @@
1
+ 'use strict';
2
+
3
+ var common = require('@lezer/common');
4
+ var state = require('@codemirror/state');
5
+ var view = require('@codemirror/view');
6
+ var highlight = require('@lezer/highlight');
7
+ var styleMod = require('style-mod');
8
+
9
+ var _a;
10
+ /**
11
+ Node prop stored in a parser's top syntax node to provide the
12
+ facet that stores language-specific data for that language.
13
+ */
14
+ const languageDataProp = new common.NodeProp();
15
+ /**
16
+ Helper function to define a facet (to be added to the top syntax
17
+ node(s) for a language via
18
+ [`languageDataProp`](https://codemirror.net/6/docs/ref/#language.languageDataProp)), that will be
19
+ used to associate language data with the language. You
20
+ probably only need this when subclassing
21
+ [`Language`](https://codemirror.net/6/docs/ref/#language.Language).
22
+ */
23
+ function defineLanguageFacet(baseData) {
24
+ return state.Facet.define({
25
+ combine: baseData ? values => values.concat(baseData) : undefined
26
+ });
27
+ }
28
+ /**
29
+ Syntax node prop used to register sublanguages. Should be added to
30
+ the top level node type for the language.
31
+ */
32
+ const sublanguageProp = new common.NodeProp();
33
+ /**
34
+ A language object manages parsing and per-language
35
+ [metadata](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). Parse data is
36
+ managed as a [Lezer](https://lezer.codemirror.net) tree. The class
37
+ can be used directly, via the [`LRLanguage`](https://codemirror.net/6/docs/ref/#language.LRLanguage)
38
+ subclass for [Lezer](https://lezer.codemirror.net/) LR parsers, or
39
+ via the [`StreamLanguage`](https://codemirror.net/6/docs/ref/#language.StreamLanguage) subclass
40
+ for stream parsers.
41
+ */
42
+ class Language {
43
+ /**
44
+ Construct a language object. If you need to invoke this
45
+ directly, first define a data facet with
46
+ [`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet), and then
47
+ configure your parser to [attach](https://codemirror.net/6/docs/ref/#language.languageDataProp) it
48
+ to the language's outer syntax node.
49
+ */
50
+ constructor(
51
+ /**
52
+ The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
53
+ used for this language.
54
+ */
55
+ data, parser, extraExtensions = [],
56
+ /**
57
+ A language name.
58
+ */
59
+ name = "") {
60
+ this.data = data;
61
+ this.name = name;
62
+ // Kludge to define EditorState.tree as a debugging helper,
63
+ // without the EditorState package actually knowing about
64
+ // languages and lezer trees.
65
+ if (!state.EditorState.prototype.hasOwnProperty("tree"))
66
+ Object.defineProperty(state.EditorState.prototype, "tree", { get() { return syntaxTree(this); } });
67
+ this.parser = parser;
68
+ this.extension = [
69
+ language.of(this),
70
+ state.EditorState.languageData.of((state, pos, side) => {
71
+ let top = topNodeAt(state, pos, side), data = top.type.prop(languageDataProp);
72
+ if (!data)
73
+ return [];
74
+ let base = state.facet(data), sub = top.type.prop(sublanguageProp);
75
+ if (sub) {
76
+ let innerNode = top.resolve(pos - top.from, side);
77
+ for (let sublang of sub)
78
+ if (sublang.test(innerNode, state)) {
79
+ let data = state.facet(sublang.facet);
80
+ return sublang.type == "replace" ? data : data.concat(base);
81
+ }
82
+ }
83
+ return base;
84
+ })
85
+ ].concat(extraExtensions);
86
+ }
87
+ /**
88
+ Query whether this language is active at the given position.
89
+ */
90
+ isActiveAt(state, pos, side = -1) {
91
+ return topNodeAt(state, pos, side).type.prop(languageDataProp) == this.data;
92
+ }
93
+ /**
94
+ Find the document regions that were parsed using this language.
95
+ The returned regions will _include_ any nested languages rooted
96
+ in this language, when those exist.
97
+ */
98
+ findRegions(state) {
99
+ let lang = state.facet(language);
100
+ if ((lang === null || lang === void 0 ? void 0 : lang.data) == this.data)
101
+ return [{ from: 0, to: state.doc.length }];
102
+ if (!lang || !lang.allowsNesting)
103
+ return [];
104
+ let result = [];
105
+ let explore = (tree, from) => {
106
+ if (tree.prop(languageDataProp) == this.data) {
107
+ result.push({ from, to: from + tree.length });
108
+ return;
109
+ }
110
+ let mount = tree.prop(common.NodeProp.mounted);
111
+ if (mount) {
112
+ if (mount.tree.prop(languageDataProp) == this.data) {
113
+ if (mount.overlay)
114
+ for (let r of mount.overlay)
115
+ result.push({ from: r.from + from, to: r.to + from });
116
+ else
117
+ result.push({ from: from, to: from + tree.length });
118
+ return;
119
+ }
120
+ else if (mount.overlay) {
121
+ let size = result.length;
122
+ explore(mount.tree, mount.overlay[0].from + from);
123
+ if (result.length > size)
124
+ return;
125
+ }
126
+ }
127
+ for (let i = 0; i < tree.children.length; i++) {
128
+ let ch = tree.children[i];
129
+ if (ch instanceof common.Tree)
130
+ explore(ch, tree.positions[i] + from);
131
+ }
132
+ };
133
+ explore(syntaxTree(state), 0);
134
+ return result;
135
+ }
136
+ /**
137
+ Indicates whether this language allows nested languages. The
138
+ default implementation returns true.
139
+ */
140
+ get allowsNesting() { return true; }
141
+ }
142
+ /**
143
+ @internal
144
+ */
145
+ Language.setState = state.StateEffect.define();
146
+ function topNodeAt(state, pos, side) {
147
+ let topLang = state.facet(language), tree = syntaxTree(state).topNode;
148
+ if (!topLang || topLang.allowsNesting) {
149
+ for (let node = tree; node; node = node.enter(pos, side, common.IterMode.ExcludeBuffers | common.IterMode.EnterBracketed))
150
+ if (node.type.isTop)
151
+ tree = node;
152
+ }
153
+ return tree;
154
+ }
155
+ /**
156
+ A subclass of [`Language`](https://codemirror.net/6/docs/ref/#language.Language) for use with Lezer
157
+ [LR parsers](https://lezer.codemirror.net/docs/ref#lr.LRParser)
158
+ parsers.
159
+ */
160
+ class LRLanguage extends Language {
161
+ constructor(data, parser, name) {
162
+ super(data, parser, [], name);
163
+ this.parser = parser;
164
+ }
165
+ /**
166
+ Define a language from a parser.
167
+ */
168
+ static define(spec) {
169
+ let data = defineLanguageFacet(spec.languageData);
170
+ return new LRLanguage(data, spec.parser.configure({
171
+ props: [languageDataProp.add(type => type.isTop ? data : undefined)]
172
+ }), spec.name);
173
+ }
174
+ /**
175
+ Create a new instance of this language with a reconfigured
176
+ version of its parser and optionally a new name.
177
+ */
178
+ configure(options, name) {
179
+ return new LRLanguage(this.data, this.parser.configure(options), name || this.name);
180
+ }
181
+ get allowsNesting() { return this.parser.hasWrappers(); }
182
+ }
183
+ /**
184
+ Get the syntax tree for a state, which is the current (possibly
185
+ incomplete) parse tree of the active
186
+ [language](https://codemirror.net/6/docs/ref/#language.Language), or the empty tree if there is no
187
+ language available.
188
+ */
189
+ function syntaxTree(state) {
190
+ let field = state.field(Language.state, false);
191
+ return field ? field.tree : common.Tree.empty;
192
+ }
193
+ /**
194
+ Try to get a parse tree that spans at least up to `upto`. The
195
+ method will do at most `timeout` milliseconds of work to parse
196
+ up to that point if the tree isn't already available.
197
+ */
198
+ function ensureSyntaxTree(state, upto, timeout = 50) {
199
+ var _a;
200
+ let parse = (_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context;
201
+ if (!parse)
202
+ return null;
203
+ let oldVieport = parse.viewport;
204
+ parse.updateViewport({ from: 0, to: upto });
205
+ let result = parse.isDone(upto) || parse.work(timeout, upto) ? parse.tree : null;
206
+ parse.updateViewport(oldVieport);
207
+ return result;
208
+ }
209
+ /**
210
+ Queries whether there is a full syntax tree available up to the
211
+ given document position. If there isn't, the background parse
212
+ process _might_ still be working and update the tree further, but
213
+ there is no guarantee of that—the parser will [stop
214
+ working](https://codemirror.net/6/docs/ref/#language.syntaxParserRunning) when it has spent a
215
+ certain amount of time or has moved beyond the visible viewport.
216
+ Always returns false if no language has been enabled.
217
+ */
218
+ function syntaxTreeAvailable(state, upto = state.doc.length) {
219
+ var _a;
220
+ return ((_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context.isDone(upto)) || false;
221
+ }
222
+ /**
223
+ Move parsing forward, and update the editor state afterwards to
224
+ reflect the new tree. Will work for at most `timeout`
225
+ milliseconds. Returns true if the parser managed get to the given
226
+ position in that time.
227
+ */
228
+ function forceParsing(view, upto = view.viewport.to, timeout = 100) {
229
+ let success = ensureSyntaxTree(view.state, upto, timeout);
230
+ if (success != syntaxTree(view.state))
231
+ view.dispatch({});
232
+ return !!success;
233
+ }
234
+ /**
235
+ Tells you whether the language parser is planning to do more
236
+ parsing work (in a `requestIdleCallback` pseudo-thread) or has
237
+ stopped running, either because it parsed the entire document,
238
+ because it spent too much time and was cut off, or because there
239
+ is no language parser enabled.
240
+ */
241
+ function syntaxParserRunning(view) {
242
+ var _a;
243
+ return ((_a = view.plugin(parseWorker)) === null || _a === void 0 ? void 0 : _a.isWorking()) || false;
244
+ }
245
+ /**
246
+ Lezer-style
247
+ [`Input`](https://lezer.codemirror.net/docs/ref#common.Input)
248
+ object for a [`Text`](https://codemirror.net/6/docs/ref/#state.Text) object.
249
+ */
250
+ class DocInput {
251
+ /**
252
+ Create an input object for the given document.
253
+ */
254
+ constructor(doc) {
255
+ this.doc = doc;
256
+ this.cursorPos = 0;
257
+ this.string = "";
258
+ this.cursor = doc.iter();
259
+ }
260
+ get length() { return this.doc.length; }
261
+ syncTo(pos) {
262
+ this.string = this.cursor.next(pos - this.cursorPos).value;
263
+ this.cursorPos = pos + this.string.length;
264
+ return this.cursorPos - this.string.length;
265
+ }
266
+ chunk(pos) {
267
+ this.syncTo(pos);
268
+ return this.string;
269
+ }
270
+ get lineChunks() { return true; }
271
+ read(from, to) {
272
+ let stringStart = this.cursorPos - this.string.length;
273
+ if (from < stringStart || to >= this.cursorPos)
274
+ return this.doc.sliceString(from, to);
275
+ else
276
+ return this.string.slice(from - stringStart, to - stringStart);
277
+ }
278
+ }
279
+ let currentContext = null;
280
+ /**
281
+ A parse context provided to parsers working on the editor content.
282
+ */
283
+ class ParseContext {
284
+ constructor(parser,
285
+ /**
286
+ The current editor state.
287
+ */
288
+ state,
289
+ /**
290
+ Tree fragments that can be reused by incremental re-parses.
291
+ */
292
+ fragments = [],
293
+ /**
294
+ @internal
295
+ */
296
+ tree,
297
+ /**
298
+ @internal
299
+ */
300
+ treeLen,
301
+ /**
302
+ The current editor viewport (or some overapproximation
303
+ thereof). Intended to be used for opportunistically avoiding
304
+ work (in which case
305
+ [`skipUntilInView`](https://codemirror.net/6/docs/ref/#language.ParseContext.skipUntilInView)
306
+ should be called to make sure the parser is restarted when the
307
+ skipped region becomes visible).
308
+ */
309
+ viewport,
310
+ /**
311
+ @internal
312
+ */
313
+ skipped,
314
+ /**
315
+ This is where skipping parsers can register a promise that,
316
+ when resolved, will schedule a new parse. It is cleared when
317
+ the parse worker picks up the promise. @internal
318
+ */
319
+ scheduleOn) {
320
+ this.parser = parser;
321
+ this.state = state;
322
+ this.fragments = fragments;
323
+ this.tree = tree;
324
+ this.treeLen = treeLen;
325
+ this.viewport = viewport;
326
+ this.skipped = skipped;
327
+ this.scheduleOn = scheduleOn;
328
+ this.parse = null;
329
+ /**
330
+ @internal
331
+ */
332
+ this.tempSkipped = [];
333
+ }
334
+ /**
335
+ @internal
336
+ */
337
+ static create(parser, state, viewport) {
338
+ return new ParseContext(parser, state, [], common.Tree.empty, 0, viewport, [], null);
339
+ }
340
+ startParse() {
341
+ return this.parser.startParse(new DocInput(this.state.doc), this.fragments);
342
+ }
343
+ /**
344
+ @internal
345
+ */
346
+ work(until, upto) {
347
+ if (upto != null && upto >= this.state.doc.length)
348
+ upto = undefined;
349
+ if (this.tree != common.Tree.empty && this.isDone(upto !== null && upto !== void 0 ? upto : this.state.doc.length)) {
350
+ this.takeTree();
351
+ return true;
352
+ }
353
+ return this.withContext(() => {
354
+ var _a;
355
+ if (typeof until == "number") {
356
+ let endTime = Date.now() + until;
357
+ until = () => Date.now() > endTime;
358
+ }
359
+ if (!this.parse)
360
+ this.parse = this.startParse();
361
+ if (upto != null && (this.parse.stoppedAt == null || this.parse.stoppedAt > upto) &&
362
+ upto < this.state.doc.length)
363
+ this.parse.stopAt(upto);
364
+ for (;;) {
365
+ let done = this.parse.advance();
366
+ if (done) {
367
+ this.fragments = this.withoutTempSkipped(common.TreeFragment.addTree(done, this.fragments, this.parse.stoppedAt != null));
368
+ this.treeLen = (_a = this.parse.stoppedAt) !== null && _a !== void 0 ? _a : this.state.doc.length;
369
+ this.tree = done;
370
+ this.parse = null;
371
+ if (this.treeLen < (upto !== null && upto !== void 0 ? upto : this.state.doc.length))
372
+ this.parse = this.startParse();
373
+ else
374
+ return true;
375
+ }
376
+ if (until())
377
+ return false;
378
+ }
379
+ });
380
+ }
381
+ /**
382
+ @internal
383
+ */
384
+ takeTree() {
385
+ let pos, tree;
386
+ if (this.parse && (pos = this.parse.parsedPos) >= this.treeLen) {
387
+ if (this.parse.stoppedAt == null || this.parse.stoppedAt > pos)
388
+ this.parse.stopAt(pos);
389
+ this.withContext(() => { while (!(tree = this.parse.advance())) { } });
390
+ this.treeLen = pos;
391
+ this.tree = tree;
392
+ this.fragments = this.withoutTempSkipped(common.TreeFragment.addTree(this.tree, this.fragments, true));
393
+ this.parse = null;
394
+ }
395
+ }
396
+ withContext(f) {
397
+ let prev = currentContext;
398
+ currentContext = this;
399
+ try {
400
+ return f();
401
+ }
402
+ finally {
403
+ currentContext = prev;
404
+ }
405
+ }
406
+ withoutTempSkipped(fragments) {
407
+ for (let r; r = this.tempSkipped.pop();)
408
+ fragments = cutFragments(fragments, r.from, r.to);
409
+ return fragments;
410
+ }
411
+ /**
412
+ @internal
413
+ */
414
+ changes(changes, newState) {
415
+ let { fragments, tree, treeLen, viewport, skipped } = this;
416
+ this.takeTree();
417
+ if (!changes.empty) {
418
+ let ranges = [];
419
+ changes.iterChangedRanges((fromA, toA, fromB, toB) => ranges.push({ fromA, toA, fromB, toB }));
420
+ fragments = common.TreeFragment.applyChanges(fragments, ranges);
421
+ tree = common.Tree.empty;
422
+ treeLen = 0;
423
+ viewport = { from: changes.mapPos(viewport.from, -1), to: changes.mapPos(viewport.to, 1) };
424
+ if (this.skipped.length) {
425
+ skipped = [];
426
+ for (let r of this.skipped) {
427
+ let from = changes.mapPos(r.from, 1), to = changes.mapPos(r.to, -1);
428
+ if (from < to)
429
+ skipped.push({ from, to });
430
+ }
431
+ }
432
+ }
433
+ return new ParseContext(this.parser, newState, fragments, tree, treeLen, viewport, skipped, this.scheduleOn);
434
+ }
435
+ /**
436
+ @internal
437
+ */
438
+ updateViewport(viewport) {
439
+ if (this.viewport.from == viewport.from && this.viewport.to == viewport.to)
440
+ return false;
441
+ this.viewport = viewport;
442
+ let startLen = this.skipped.length;
443
+ for (let i = 0; i < this.skipped.length; i++) {
444
+ let { from, to } = this.skipped[i];
445
+ if (from < viewport.to && to > viewport.from) {
446
+ this.fragments = cutFragments(this.fragments, from, to);
447
+ this.skipped.splice(i--, 1);
448
+ }
449
+ }
450
+ if (this.skipped.length >= startLen)
451
+ return false;
452
+ this.reset();
453
+ return true;
454
+ }
455
+ /**
456
+ @internal
457
+ */
458
+ reset() {
459
+ if (this.parse) {
460
+ this.takeTree();
461
+ this.parse = null;
462
+ }
463
+ }
464
+ /**
465
+ Notify the parse scheduler that the given region was skipped
466
+ because it wasn't in view, and the parse should be restarted
467
+ when it comes into view.
468
+ */
469
+ skipUntilInView(from, to) {
470
+ this.skipped.push({ from, to });
471
+ }
472
+ /**
473
+ Returns a parser intended to be used as placeholder when
474
+ asynchronously loading a nested parser. It'll skip its input and
475
+ mark it as not-really-parsed, so that the next update will parse
476
+ it again.
477
+
478
+ When `until` is given, a reparse will be scheduled when that
479
+ promise resolves.
480
+ */
481
+ static getSkippingParser(until) {
482
+ return new class extends common.Parser {
483
+ createParse(input, fragments, ranges) {
484
+ let from = ranges[0].from, to = ranges[ranges.length - 1].to;
485
+ let parser = {
486
+ parsedPos: from,
487
+ advance() {
488
+ let cx = currentContext;
489
+ if (cx) {
490
+ for (let r of ranges)
491
+ cx.tempSkipped.push(r);
492
+ if (until)
493
+ cx.scheduleOn = cx.scheduleOn ? Promise.all([cx.scheduleOn, until]) : until;
494
+ }
495
+ this.parsedPos = to;
496
+ return new common.Tree(common.NodeType.none, [], [], to - from);
497
+ },
498
+ stoppedAt: null,
499
+ stopAt() { }
500
+ };
501
+ return parser;
502
+ }
503
+ };
504
+ }
505
+ /**
506
+ @internal
507
+ */
508
+ isDone(upto) {
509
+ upto = Math.min(upto, this.state.doc.length);
510
+ let frags = this.fragments;
511
+ return this.treeLen >= upto && frags.length && frags[0].from == 0 && frags[0].to >= upto;
512
+ }
513
+ /**
514
+ Get the context for the current parse, or `null` if no editor
515
+ parse is in progress.
516
+ */
517
+ static get() { return currentContext; }
518
+ }
519
+ function cutFragments(fragments, from, to) {
520
+ return common.TreeFragment.applyChanges(fragments, [{ fromA: from, toA: to, fromB: from, toB: to }]);
521
+ }
522
+ class LanguageState {
523
+ constructor(
524
+ // A mutable parse state that is used to preserve work done during
525
+ // the lifetime of a state when moving to the next state.
526
+ context) {
527
+ this.context = context;
528
+ this.tree = context.tree;
529
+ }
530
+ apply(tr) {
531
+ if (!tr.docChanged && this.tree == this.context.tree)
532
+ return this;
533
+ let newCx = this.context.changes(tr.changes, tr.state);
534
+ // If the previous parse wasn't done, go forward only up to its
535
+ // end position or the end of the viewport, to avoid slowing down
536
+ // state updates with parse work beyond the viewport.
537
+ let upto = this.context.treeLen == tr.startState.doc.length ? undefined
538
+ : Math.max(tr.changes.mapPos(this.context.treeLen), newCx.viewport.to);
539
+ if (!newCx.work(20 /* Work.Apply */, upto))
540
+ newCx.takeTree();
541
+ return new LanguageState(newCx);
542
+ }
543
+ static init(state) {
544
+ let vpTo = Math.min(3000 /* Work.InitViewport */, state.doc.length);
545
+ let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
546
+ if (!parseState.work(20 /* Work.Apply */, vpTo))
547
+ parseState.takeTree();
548
+ return new LanguageState(parseState);
549
+ }
550
+ }
551
+ Language.state = state.StateField.define({
552
+ create: LanguageState.init,
553
+ update(value, tr) {
554
+ for (let e of tr.effects)
555
+ if (e.is(Language.setState))
556
+ return e.value;
557
+ if (tr.startState.facet(language) != tr.state.facet(language))
558
+ return LanguageState.init(tr.state);
559
+ return value.apply(tr);
560
+ }
561
+ });
562
+ let requestIdle = (callback) => {
563
+ let timeout = setTimeout(() => callback(), 500 /* Work.MaxPause */);
564
+ return () => clearTimeout(timeout);
565
+ };
566
+ if (typeof requestIdleCallback != "undefined")
567
+ requestIdle = (callback) => {
568
+ let idle = -1, timeout = setTimeout(() => {
569
+ idle = requestIdleCallback(callback, { timeout: 500 /* Work.MaxPause */ - 100 /* Work.MinPause */ });
570
+ }, 100 /* Work.MinPause */);
571
+ return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
572
+ };
573
+ const isInputPending = typeof navigator != "undefined" && ((_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending)
574
+ ? () => navigator.scheduling.isInputPending() : null;
575
+ const parseWorker = view.ViewPlugin.fromClass(class ParseWorker {
576
+ constructor(view) {
577
+ this.view = view;
578
+ this.working = null;
579
+ this.workScheduled = 0;
580
+ // End of the current time chunk
581
+ this.chunkEnd = -1;
582
+ // Milliseconds of budget left for this chunk
583
+ this.chunkBudget = -1;
584
+ this.work = this.work.bind(this);
585
+ this.scheduleWork();
586
+ }
587
+ update(update) {
588
+ let cx = this.view.state.field(Language.state).context;
589
+ if (cx.updateViewport(update.view.viewport) || this.view.viewport.to > cx.treeLen)
590
+ this.scheduleWork();
591
+ if (update.docChanged || update.selectionSet) {
592
+ if (this.view.hasFocus)
593
+ this.chunkBudget += 50 /* Work.ChangeBonus */;
594
+ this.scheduleWork();
595
+ }
596
+ this.checkAsyncSchedule(cx);
597
+ }
598
+ scheduleWork() {
599
+ if (this.working)
600
+ return;
601
+ let { state } = this.view, field = state.field(Language.state);
602
+ if (field.tree != field.context.tree || !field.context.isDone(state.doc.length))
603
+ this.working = requestIdle(this.work);
604
+ }
605
+ work(deadline) {
606
+ this.working = null;
607
+ let now = Date.now();
608
+ if (this.chunkEnd < now && (this.chunkEnd < 0 || this.view.hasFocus)) { // Start a new chunk
609
+ this.chunkEnd = now + 30000 /* Work.ChunkTime */;
610
+ this.chunkBudget = 3000 /* Work.ChunkBudget */;
611
+ }
612
+ if (this.chunkBudget <= 0)
613
+ return; // No more budget
614
+ let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
615
+ if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /* Work.MaxParseAhead */))
616
+ return;
617
+ let endTime = Date.now() + Math.min(this.chunkBudget, 100 /* Work.Slice */, deadline && !isInputPending ? Math.max(25 /* Work.MinSlice */, deadline.timeRemaining() - 5) : 1e9);
618
+ let viewportFirst = field.context.treeLen < vpTo && state.doc.length > vpTo + 1000;
619
+ let done = field.context.work(() => {
620
+ return isInputPending && isInputPending() || Date.now() > endTime;
621
+ }, vpTo + (viewportFirst ? 0 : 100000 /* Work.MaxParseAhead */));
622
+ this.chunkBudget -= Date.now() - now;
623
+ if (done || this.chunkBudget <= 0) {
624
+ field.context.takeTree();
625
+ this.view.dispatch({ effects: Language.setState.of(new LanguageState(field.context)) });
626
+ }
627
+ if (this.chunkBudget > 0 && !(done && !viewportFirst))
628
+ this.scheduleWork();
629
+ this.checkAsyncSchedule(field.context);
630
+ }
631
+ checkAsyncSchedule(cx) {
632
+ if (cx.scheduleOn) {
633
+ this.workScheduled++;
634
+ cx.scheduleOn
635
+ .then(() => this.scheduleWork())
636
+ .catch(err => view.logException(this.view.state, err))
637
+ .then(() => this.workScheduled--);
638
+ cx.scheduleOn = null;
639
+ }
640
+ }
641
+ destroy() {
642
+ if (this.working)
643
+ this.working();
644
+ }
645
+ isWorking() {
646
+ return !!(this.working || this.workScheduled > 0);
647
+ }
648
+ }, {
649
+ eventHandlers: { focus() { this.scheduleWork(); } }
650
+ });
651
+ /**
652
+ The facet used to associate a language with an editor state. Used
653
+ by `Language` object's `extension` property (so you don't need to
654
+ manually wrap your languages in this). Can be used to access the
655
+ current language on a state.
656
+ */
657
+ const language = state.Facet.define({
658
+ combine(languages) { return languages.length ? languages[0] : null; },
659
+ enables: language => [
660
+ Language.state,
661
+ parseWorker,
662
+ view.EditorView.contentAttributes.compute([language], state => {
663
+ let lang = state.facet(language);
664
+ return lang && lang.name ? { "data-language": lang.name } : {};
665
+ })
666
+ ]
667
+ });
668
+ /**
669
+ This class bundles a [language](https://codemirror.net/6/docs/ref/#language.Language) with an
670
+ optional set of supporting extensions. Language packages are
671
+ encouraged to export a function that optionally takes a
672
+ configuration object and returns a `LanguageSupport` instance, as
673
+ the main way for client code to use the package.
674
+ */
675
+ class LanguageSupport {
676
+ /**
677
+ Create a language support object.
678
+ */
679
+ constructor(
680
+ /**
681
+ The language object.
682
+ */
683
+ language,
684
+ /**
685
+ An optional set of supporting extensions. When nesting a
686
+ language in another language, the outer language is encouraged
687
+ to include the supporting extensions for its inner languages
688
+ in its own set of support extensions.
689
+ */
690
+ support = []) {
691
+ this.language = language;
692
+ this.support = support;
693
+ this.extension = [language, support];
694
+ }
695
+ }
696
+ /**
697
+ Language descriptions are used to store metadata about languages
698
+ and to dynamically load them. Their main role is finding the
699
+ appropriate language for a filename or dynamically loading nested
700
+ parsers.
701
+ */
702
+ class LanguageDescription {
703
+ constructor(
704
+ /**
705
+ The name of this language.
706
+ */
707
+ name,
708
+ /**
709
+ Alternative names for the mode (lowercased, includes `this.name`).
710
+ */
711
+ alias,
712
+ /**
713
+ File extensions associated with this language.
714
+ */
715
+ extensions,
716
+ /**
717
+ Optional filename pattern that should be associated with this
718
+ language.
719
+ */
720
+ filename, loadFunc,
721
+ /**
722
+ If the language has been loaded, this will hold its value.
723
+ */
724
+ support = undefined) {
725
+ this.name = name;
726
+ this.alias = alias;
727
+ this.extensions = extensions;
728
+ this.filename = filename;
729
+ this.loadFunc = loadFunc;
730
+ this.support = support;
731
+ this.loading = null;
732
+ }
733
+ /**
734
+ Start loading the the language. Will return a promise that
735
+ resolves to a [`LanguageSupport`](https://codemirror.net/6/docs/ref/#language.LanguageSupport)
736
+ object when the language successfully loads.
737
+ */
738
+ load() {
739
+ return this.loading || (this.loading = this.loadFunc().then(support => this.support = support, err => { this.loading = null; throw err; }));
740
+ }
741
+ /**
742
+ Create a language description.
743
+ */
744
+ static of(spec) {
745
+ let { load, support } = spec;
746
+ if (!load) {
747
+ if (!support)
748
+ throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");
749
+ load = () => Promise.resolve(support);
750
+ }
751
+ return new LanguageDescription(spec.name, (spec.alias || []).concat(spec.name).map(s => s.toLowerCase()), spec.extensions || [], spec.filename, load, support);
752
+ }
753
+ /**
754
+ Look for a language in the given array of descriptions that
755
+ matches the filename. Will first match
756
+ [`filename`](https://codemirror.net/6/docs/ref/#language.LanguageDescription.filename) patterns,
757
+ and then [extensions](https://codemirror.net/6/docs/ref/#language.LanguageDescription.extensions),
758
+ and return the first language that matches.
759
+ */
760
+ static matchFilename(descs, filename) {
761
+ for (let d of descs)
762
+ if (d.filename && d.filename.test(filename))
763
+ return d;
764
+ let ext = /\.([^.]+)$/.exec(filename);
765
+ if (ext)
766
+ for (let d of descs)
767
+ if (d.extensions.indexOf(ext[1]) > -1)
768
+ return d;
769
+ return null;
770
+ }
771
+ /**
772
+ Look for a language whose name or alias matches the the given
773
+ name (case-insensitively). If `fuzzy` is true, and no direct
774
+ matchs is found, this'll also search for a language whose name
775
+ or alias occurs in the string (for names shorter than three
776
+ characters, only when surrounded by non-word characters).
777
+ */
778
+ static matchLanguageName(descs, name, fuzzy = true) {
779
+ name = name.toLowerCase();
780
+ for (let d of descs)
781
+ if (d.alias.some(a => a == name))
782
+ return d;
783
+ if (fuzzy)
784
+ for (let d of descs)
785
+ for (let a of d.alias) {
786
+ let found = name.indexOf(a);
787
+ if (found > -1 && (a.length > 2 || !/\w/.test(name[found - 1]) && !/\w/.test(name[found + a.length])))
788
+ return d;
789
+ }
790
+ return null;
791
+ }
792
+ }
793
+
794
+ /**
795
+ Facet that defines a way to provide a function that computes the
796
+ appropriate indentation depth, as a column number (see
797
+ [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)), at the start of a given
798
+ line. A return value of `null` indicates no indentation can be
799
+ determined, and the line should inherit the indentation of the one
800
+ above it. A return value of `undefined` defers to the next indent
801
+ service.
802
+ */
803
+ const indentService = state.Facet.define();
804
+ /**
805
+ Facet for overriding the unit by which indentation happens. Should
806
+ be a string consisting entirely of the same whitespace character.
807
+ When not set, this defaults to 2 spaces.
808
+ */
809
+ const indentUnit = state.Facet.define({
810
+ combine: values => {
811
+ if (!values.length)
812
+ return " ";
813
+ let unit = values[0];
814
+ if (!unit || /\S/.test(unit) || Array.from(unit).some(e => e != unit[0]))
815
+ throw new Error("Invalid indent unit: " + JSON.stringify(values[0]));
816
+ return unit;
817
+ }
818
+ });
819
+ /**
820
+ Return the _column width_ of an indent unit in the state.
821
+ Determined by the [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit)
822
+ facet, and [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) when that
823
+ contains tabs.
824
+ */
825
+ function getIndentUnit(state) {
826
+ let unit = state.facet(indentUnit);
827
+ return unit.charCodeAt(0) == 9 ? state.tabSize * unit.length : unit.length;
828
+ }
829
+ /**
830
+ Create an indentation string that covers columns 0 to `cols`.
831
+ Will use tabs for as much of the columns as possible when the
832
+ [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit) facet contains
833
+ tabs.
834
+ */
835
+ function indentString(state, cols) {
836
+ let result = "", ts = state.tabSize, ch = state.facet(indentUnit)[0];
837
+ if (ch == "\t") {
838
+ while (cols >= ts) {
839
+ result += "\t";
840
+ cols -= ts;
841
+ }
842
+ ch = " ";
843
+ }
844
+ for (let i = 0; i < cols; i++)
845
+ result += ch;
846
+ return result;
847
+ }
848
+ /**
849
+ Get the indentation, as a column number, at the given position.
850
+ Will first consult any [indent services](https://codemirror.net/6/docs/ref/#language.indentService)
851
+ that are registered, and if none of those return an indentation,
852
+ this will check the syntax tree for the [indent node
853
+ prop](https://codemirror.net/6/docs/ref/#language.indentNodeProp) and use that if found. Returns a
854
+ number when an indentation could be determined, and null
855
+ otherwise.
856
+ */
857
+ function getIndentation(context, pos) {
858
+ if (context instanceof state.EditorState)
859
+ context = new IndentContext(context);
860
+ for (let service of context.state.facet(indentService)) {
861
+ let result = service(context, pos);
862
+ if (result !== undefined)
863
+ return result;
864
+ }
865
+ let tree = syntaxTree(context.state);
866
+ return tree.length >= pos ? syntaxIndentation(context, tree, pos) : null;
867
+ }
868
+ /**
869
+ Create a change set that auto-indents all lines touched by the
870
+ given document range.
871
+ */
872
+ function indentRange(state, from, to) {
873
+ let updated = Object.create(null);
874
+ let context = new IndentContext(state, { overrideIndentation: start => { var _a; return (_a = updated[start]) !== null && _a !== void 0 ? _a : -1; } });
875
+ let changes = [];
876
+ for (let pos = from; pos <= to;) {
877
+ let line = state.doc.lineAt(pos);
878
+ pos = line.to + 1;
879
+ let indent = getIndentation(context, line.from);
880
+ if (indent == null)
881
+ continue;
882
+ if (!/\S/.test(line.text))
883
+ indent = 0;
884
+ let cur = /^\s*/.exec(line.text)[0];
885
+ let norm = indentString(state, indent);
886
+ if (cur != norm) {
887
+ updated[line.from] = indent;
888
+ changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
889
+ }
890
+ }
891
+ return state.changes(changes);
892
+ }
893
+ /**
894
+ Indentation contexts are used when calling [indentation
895
+ services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
896
+ useful in indentation logic, and can selectively override the
897
+ indentation reported for some lines.
898
+ */
899
+ class IndentContext {
900
+ /**
901
+ Create an indent context.
902
+ */
903
+ constructor(
904
+ /**
905
+ The editor state.
906
+ */
907
+ state,
908
+ /**
909
+ @internal
910
+ */
911
+ options = {}) {
912
+ this.state = state;
913
+ this.options = options;
914
+ this.unit = getIndentUnit(state);
915
+ }
916
+ /**
917
+ Get a description of the line at the given position, taking
918
+ [simulated line
919
+ breaks](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
920
+ into account. If there is such a break at `pos`, the `bias`
921
+ argument determines whether the part of the line line before or
922
+ after the break is used.
923
+ */
924
+ lineAt(pos, bias = 1) {
925
+ let line = this.state.doc.lineAt(pos);
926
+ let { simulateBreak, simulateDoubleBreak } = this.options;
927
+ if (simulateBreak != null && simulateBreak >= line.from && simulateBreak <= line.to) {
928
+ if (simulateDoubleBreak && simulateBreak == pos)
929
+ return { text: "", from: pos };
930
+ else if (bias < 0 ? simulateBreak < pos : simulateBreak <= pos)
931
+ return { text: line.text.slice(simulateBreak - line.from), from: simulateBreak };
932
+ else
933
+ return { text: line.text.slice(0, simulateBreak - line.from), from: line.from };
934
+ }
935
+ return line;
936
+ }
937
+ /**
938
+ Get the text directly after `pos`, either the entire line
939
+ or the next 100 characters, whichever is shorter.
940
+ */
941
+ textAfterPos(pos, bias = 1) {
942
+ if (this.options.simulateDoubleBreak && pos == this.options.simulateBreak)
943
+ return "";
944
+ let { text, from } = this.lineAt(pos, bias);
945
+ return text.slice(pos - from, Math.min(text.length, pos + 100 - from));
946
+ }
947
+ /**
948
+ Find the column for the given position.
949
+ */
950
+ column(pos, bias = 1) {
951
+ let { text, from } = this.lineAt(pos, bias);
952
+ let result = this.countColumn(text, pos - from);
953
+ let override = this.options.overrideIndentation ? this.options.overrideIndentation(from) : -1;
954
+ if (override > -1)
955
+ result += override - this.countColumn(text, text.search(/\S|$/));
956
+ return result;
957
+ }
958
+ /**
959
+ Find the column position (taking tabs into account) of the given
960
+ position in the given string.
961
+ */
962
+ countColumn(line, pos = line.length) {
963
+ return state.countColumn(line, this.state.tabSize, pos);
964
+ }
965
+ /**
966
+ Find the indentation column of the line at the given point.
967
+ */
968
+ lineIndent(pos, bias = 1) {
969
+ let { text, from } = this.lineAt(pos, bias);
970
+ let override = this.options.overrideIndentation;
971
+ if (override) {
972
+ let overriden = override(from);
973
+ if (overriden > -1)
974
+ return overriden;
975
+ }
976
+ return this.countColumn(text, text.search(/\S|$/));
977
+ }
978
+ /**
979
+ Returns the [simulated line
980
+ break](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
981
+ for this context, if any.
982
+ */
983
+ get simulatedBreak() {
984
+ return this.options.simulateBreak || null;
985
+ }
986
+ }
987
+ /**
988
+ A syntax tree node prop used to associate indentation strategies
989
+ with node types. Such a strategy is a function from an indentation
990
+ context to a column number (see also
991
+ [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)) or null, where null
992
+ indicates that no definitive indentation can be determined.
993
+ */
994
+ const indentNodeProp = new common.NodeProp();
995
+ // Compute the indentation for a given position from the syntax tree.
996
+ function syntaxIndentation(cx, ast, pos) {
997
+ let stack = ast.resolveStack(pos);
998
+ let inner = ast.resolveInner(pos, -1).resolve(pos, 0).enterUnfinishedNodesBefore(pos);
999
+ if (inner != stack.node) {
1000
+ let add = [];
1001
+ for (let cur = inner; cur && !(cur.from < stack.node.from || cur.to > stack.node.to ||
1002
+ cur.from == stack.node.from && cur.type == stack.node.type); cur = cur.parent)
1003
+ add.push(cur);
1004
+ for (let i = add.length - 1; i >= 0; i--)
1005
+ stack = { node: add[i], next: stack };
1006
+ }
1007
+ return indentFor(stack, cx, pos);
1008
+ }
1009
+ function indentFor(stack, cx, pos) {
1010
+ for (let cur = stack; cur; cur = cur.next) {
1011
+ let strategy = indentStrategy(cur.node);
1012
+ if (strategy)
1013
+ return strategy(TreeIndentContext.create(cx, pos, cur));
1014
+ }
1015
+ return 0;
1016
+ }
1017
+ function ignoreClosed(cx) {
1018
+ return cx.pos == cx.options.simulateBreak && cx.options.simulateDoubleBreak;
1019
+ }
1020
+ function indentStrategy(tree) {
1021
+ let strategy = tree.type.prop(indentNodeProp);
1022
+ if (strategy)
1023
+ return strategy;
1024
+ let first = tree.firstChild, close;
1025
+ if (first && (close = first.type.prop(common.NodeProp.closedBy))) {
1026
+ let last = tree.lastChild, closed = last && close.indexOf(last.name) > -1;
1027
+ return cx => delimitedStrategy(cx, true, 1, undefined, closed && !ignoreClosed(cx) ? last.from : undefined);
1028
+ }
1029
+ return tree.parent == null ? topIndent : null;
1030
+ }
1031
+ function topIndent() { return 0; }
1032
+ /**
1033
+ Objects of this type provide context information and helper
1034
+ methods to indentation functions registered on syntax nodes.
1035
+ */
1036
+ class TreeIndentContext extends IndentContext {
1037
+ constructor(base,
1038
+ /**
1039
+ The position at which indentation is being computed.
1040
+ */
1041
+ pos,
1042
+ /**
1043
+ @internal
1044
+ */
1045
+ context) {
1046
+ super(base.state, base.options);
1047
+ this.base = base;
1048
+ this.pos = pos;
1049
+ this.context = context;
1050
+ }
1051
+ /**
1052
+ The syntax tree node to which the indentation strategy
1053
+ applies.
1054
+ */
1055
+ get node() { return this.context.node; }
1056
+ /**
1057
+ @internal
1058
+ */
1059
+ static create(base, pos, context) {
1060
+ return new TreeIndentContext(base, pos, context);
1061
+ }
1062
+ /**
1063
+ Get the text directly after `this.pos`, either the entire line
1064
+ or the next 100 characters, whichever is shorter.
1065
+ */
1066
+ get textAfter() {
1067
+ return this.textAfterPos(this.pos);
1068
+ }
1069
+ /**
1070
+ Get the indentation at the reference line for `this.node`, which
1071
+ is the line on which it starts, unless there is a node that is
1072
+ _not_ a parent of this node covering the start of that line. If
1073
+ so, the line at the start of that node is tried, again skipping
1074
+ on if it is covered by another such node.
1075
+ */
1076
+ get baseIndent() {
1077
+ return this.baseIndentFor(this.node);
1078
+ }
1079
+ /**
1080
+ Get the indentation for the reference line of the given node
1081
+ (see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
1082
+ */
1083
+ baseIndentFor(node) {
1084
+ let line = this.state.doc.lineAt(node.from);
1085
+ // Skip line starts that are covered by a sibling (or cousin, etc)
1086
+ for (;;) {
1087
+ let atBreak = node.resolve(line.from);
1088
+ while (atBreak.parent && atBreak.parent.from == atBreak.from)
1089
+ atBreak = atBreak.parent;
1090
+ if (isParent(atBreak, node))
1091
+ break;
1092
+ line = this.state.doc.lineAt(atBreak.from);
1093
+ }
1094
+ return this.lineIndent(line.from);
1095
+ }
1096
+ /**
1097
+ Continue looking for indentations in the node's parent nodes,
1098
+ and return the result of that.
1099
+ */
1100
+ continue() {
1101
+ return indentFor(this.context.next, this.base, this.pos);
1102
+ }
1103
+ }
1104
+ function isParent(parent, of) {
1105
+ for (let cur = of; cur; cur = cur.parent)
1106
+ if (parent == cur)
1107
+ return true;
1108
+ return false;
1109
+ }
1110
+ // Check whether a delimited node is aligned (meaning there are
1111
+ // non-skipped nodes on the same line as the opening delimiter). And
1112
+ // if so, return the opening token.
1113
+ function bracketedAligned(context) {
1114
+ let tree = context.node;
1115
+ let openToken = tree.childAfter(tree.from), last = tree.lastChild;
1116
+ if (!openToken)
1117
+ return null;
1118
+ let sim = context.options.simulateBreak;
1119
+ let openLine = context.state.doc.lineAt(openToken.from);
1120
+ let lineEnd = sim == null || sim <= openLine.from ? openLine.to : Math.min(openLine.to, sim);
1121
+ for (let pos = openToken.to;;) {
1122
+ let next = tree.childAfter(pos);
1123
+ if (!next || next == last)
1124
+ return null;
1125
+ if (!next.type.isSkipped) {
1126
+ if (next.from >= lineEnd)
1127
+ return null;
1128
+ let space = /^ */.exec(openLine.text.slice(openToken.to - openLine.from))[0].length;
1129
+ return { from: openToken.from, to: openToken.to + space };
1130
+ }
1131
+ pos = next.to;
1132
+ }
1133
+ }
1134
+ /**
1135
+ An indentation strategy for delimited (usually bracketed) nodes.
1136
+ Will, by default, indent one unit more than the parent's base
1137
+ indent unless the line starts with a closing token. When `align`
1138
+ is true and there are non-skipped nodes on the node's opening
1139
+ line, the content of the node will be aligned with the end of the
1140
+ opening node, like this:
1141
+
1142
+ foo(bar,
1143
+ baz)
1144
+ */
1145
+ function delimitedIndent({ closing, align = true, units = 1 }) {
1146
+ return (context) => delimitedStrategy(context, align, units, closing);
1147
+ }
1148
+ function delimitedStrategy(context, align, units, closing, closedAt) {
1149
+ let after = context.textAfter, space = after.match(/^\s*/)[0].length;
1150
+ let closed = closing && after.slice(space, space + closing.length) == closing || closedAt == context.pos + space;
1151
+ let aligned = align ? bracketedAligned(context) : null;
1152
+ if (aligned)
1153
+ return closed ? context.column(aligned.from) : context.column(aligned.to);
1154
+ return context.baseIndent + (closed ? 0 : context.unit * units);
1155
+ }
1156
+ /**
1157
+ An indentation strategy that aligns a node's content to its base
1158
+ indentation.
1159
+ */
1160
+ const flatIndent = (context) => context.baseIndent;
1161
+ /**
1162
+ Creates an indentation strategy that, by default, indents
1163
+ continued lines one unit more than the node's base indentation.
1164
+ You can provide `except` to prevent indentation of lines that
1165
+ match a pattern (for example `/^else\b/` in `if`/`else`
1166
+ constructs), and you can change the amount of units used with the
1167
+ `units` option.
1168
+ */
1169
+ function continuedIndent({ except, units = 1 } = {}) {
1170
+ return (context) => {
1171
+ let matchExcept = except && except.test(context.textAfter);
1172
+ return context.baseIndent + (matchExcept ? 0 : units * context.unit);
1173
+ };
1174
+ }
1175
+ const DontIndentBeyond = 200;
1176
+ /**
1177
+ Enables reindentation on input. When a language defines an
1178
+ `indentOnInput` field in its [language
1179
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt), which must hold a regular
1180
+ expression, the line at the cursor will be reindented whenever new
1181
+ text is typed and the input from the start of the line up to the
1182
+ cursor matches that regexp.
1183
+
1184
+ To avoid unneccesary reindents, it is recommended to start the
1185
+ regexp with `^` (usually followed by `\s*`), and end it with `$`.
1186
+ For example, `/^\s*\}$/` will reindent when a closing brace is
1187
+ added at the start of a line.
1188
+ */
1189
+ function indentOnInput() {
1190
+ return state.EditorState.transactionFilter.of(tr => {
1191
+ if (!tr.docChanged || !tr.isUserEvent("input.type") && !tr.isUserEvent("input.complete"))
1192
+ return tr;
1193
+ let rules = tr.startState.languageDataAt("indentOnInput", tr.startState.selection.main.head);
1194
+ if (!rules.length)
1195
+ return tr;
1196
+ let doc = tr.newDoc, { head } = tr.newSelection.main, line = doc.lineAt(head);
1197
+ if (head > line.from + DontIndentBeyond)
1198
+ return tr;
1199
+ let lineStart = doc.sliceString(line.from, head);
1200
+ if (!rules.some(r => r.test(lineStart)))
1201
+ return tr;
1202
+ let { state } = tr, last = -1, changes = [];
1203
+ for (let { head } of state.selection.ranges) {
1204
+ let line = state.doc.lineAt(head);
1205
+ if (line.from == last)
1206
+ continue;
1207
+ last = line.from;
1208
+ let indent = getIndentation(state, line.from);
1209
+ if (indent == null)
1210
+ continue;
1211
+ let cur = /^\s*/.exec(line.text)[0];
1212
+ let norm = indentString(state, indent);
1213
+ if (cur != norm)
1214
+ changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
1215
+ }
1216
+ return changes.length ? [tr, { changes, sequential: true }] : tr;
1217
+ });
1218
+ }
1219
+
1220
+ /**
1221
+ A facet that registers a code folding service. When called with
1222
+ the extent of a line, such a function should return a foldable
1223
+ range that starts on that line (but continues beyond it), if one
1224
+ can be found.
1225
+ */
1226
+ const foldService = state.Facet.define();
1227
+ /**
1228
+ This node prop is used to associate folding information with
1229
+ syntax node types. Given a syntax node, it should check whether
1230
+ that tree is foldable and return the range that can be collapsed
1231
+ when it is.
1232
+ */
1233
+ const foldNodeProp = new common.NodeProp();
1234
+ /**
1235
+ [Fold](https://codemirror.net/6/docs/ref/#language.foldNodeProp) function that folds everything but
1236
+ the first and the last child of a syntax node. Useful for nodes
1237
+ that start and end with delimiters.
1238
+ */
1239
+ function foldInside(node) {
1240
+ let first = node.firstChild, last = node.lastChild;
1241
+ return first && first.to < last.from ? { from: first.to, to: last.type.isError ? node.to : last.from } : null;
1242
+ }
1243
+ function syntaxFolding(state, start, end) {
1244
+ let tree = syntaxTree(state);
1245
+ if (tree.length < end)
1246
+ return null;
1247
+ let stack = tree.resolveStack(end, 1);
1248
+ let found = null;
1249
+ for (let iter = stack; iter; iter = iter.next) {
1250
+ let cur = iter.node;
1251
+ if (cur.to <= end || cur.from > end)
1252
+ continue;
1253
+ if (found && cur.from < start)
1254
+ break;
1255
+ let prop = cur.type.prop(foldNodeProp);
1256
+ if (prop && (cur.to < tree.length - 50 || tree.length == state.doc.length || !isUnfinished(cur))) {
1257
+ let value = prop(cur, state);
1258
+ if (value && value.from <= end && value.from >= start && value.to > end)
1259
+ found = value;
1260
+ }
1261
+ }
1262
+ return found;
1263
+ }
1264
+ function isUnfinished(node) {
1265
+ let ch = node.lastChild;
1266
+ return ch && ch.to == node.to && ch.type.isError;
1267
+ }
1268
+ /**
1269
+ Check whether the given line is foldable. First asks any fold
1270
+ services registered through
1271
+ [`foldService`](https://codemirror.net/6/docs/ref/#language.foldService), and if none of them return
1272
+ a result, tries to query the [fold node
1273
+ prop](https://codemirror.net/6/docs/ref/#language.foldNodeProp) of syntax nodes that cover the end
1274
+ of the line.
1275
+ */
1276
+ function foldable(state, lineStart, lineEnd) {
1277
+ for (let service of state.facet(foldService)) {
1278
+ let result = service(state, lineStart, lineEnd);
1279
+ if (result)
1280
+ return result;
1281
+ }
1282
+ return syntaxFolding(state, lineStart, lineEnd);
1283
+ }
1284
+ function mapRange(range, mapping) {
1285
+ let from = mapping.mapPos(range.from, 1), to = mapping.mapPos(range.to, -1);
1286
+ return from >= to ? undefined : { from, to };
1287
+ }
1288
+ /**
1289
+ State effect that can be attached to a transaction to fold the
1290
+ given range. (You probably only need this in exceptional
1291
+ circumstances—usually you'll just want to let
1292
+ [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode) and the [fold
1293
+ gutter](https://codemirror.net/6/docs/ref/#language.foldGutter) create the transactions.)
1294
+ */
1295
+ const foldEffect = state.StateEffect.define({ map: mapRange });
1296
+ /**
1297
+ State effect that unfolds the given range (if it was folded).
1298
+ */
1299
+ const unfoldEffect = state.StateEffect.define({ map: mapRange });
1300
+ function selectedLines(view) {
1301
+ let lines = [];
1302
+ for (let { head } of view.state.selection.ranges) {
1303
+ if (lines.some(l => l.from <= head && l.to >= head))
1304
+ continue;
1305
+ lines.push(view.lineBlockAt(head));
1306
+ }
1307
+ return lines;
1308
+ }
1309
+ /**
1310
+ The state field that stores the folded ranges (as a [decoration
1311
+ set](https://codemirror.net/6/docs/ref/#view.DecorationSet)). Can be passed to
1312
+ [`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) and
1313
+ [`fromJSON`](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) to serialize the fold
1314
+ state.
1315
+ */
1316
+ const foldState = state.StateField.define({
1317
+ create() {
1318
+ return view.Decoration.none;
1319
+ },
1320
+ update(folded, tr) {
1321
+ if (tr.isUserEvent("delete"))
1322
+ tr.changes.iterChangedRanges((fromA, toA) => folded = clearTouchedFolds(folded, fromA, toA));
1323
+ folded = folded.map(tr.changes);
1324
+ for (let e of tr.effects) {
1325
+ if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) {
1326
+ let { preparePlaceholder } = tr.state.facet(foldConfig);
1327
+ let widget = !preparePlaceholder ? foldWidget :
1328
+ view.Decoration.replace({ widget: new PreparedFoldWidget(preparePlaceholder(tr.state, e.value)) });
1329
+ folded = folded.update({ add: [widget.range(e.value.from, e.value.to)] });
1330
+ }
1331
+ else if (e.is(unfoldEffect)) {
1332
+ folded = folded.update({ filter: (from, to) => e.value.from != from || e.value.to != to,
1333
+ filterFrom: e.value.from, filterTo: e.value.to });
1334
+ }
1335
+ }
1336
+ // Clear folded ranges that cover the selection head
1337
+ if (tr.selection)
1338
+ folded = clearTouchedFolds(folded, tr.selection.main.head);
1339
+ return folded;
1340
+ },
1341
+ provide: f => view.EditorView.decorations.from(f),
1342
+ toJSON(folded, state) {
1343
+ let ranges = [];
1344
+ folded.between(0, state.doc.length, (from, to) => { ranges.push(from, to); });
1345
+ return ranges;
1346
+ },
1347
+ fromJSON(value) {
1348
+ if (!Array.isArray(value) || value.length % 2)
1349
+ throw new RangeError("Invalid JSON for fold state");
1350
+ let ranges = [];
1351
+ for (let i = 0; i < value.length;) {
1352
+ let from = value[i++], to = value[i++];
1353
+ if (typeof from != "number" || typeof to != "number")
1354
+ throw new RangeError("Invalid JSON for fold state");
1355
+ ranges.push(foldWidget.range(from, to));
1356
+ }
1357
+ return view.Decoration.set(ranges, true);
1358
+ }
1359
+ });
1360
+ function clearTouchedFolds(folded, from, to = from) {
1361
+ let touched = false;
1362
+ folded.between(from, to, (a, b) => { if (a < to && b > from)
1363
+ touched = true; });
1364
+ return !touched ? folded : folded.update({
1365
+ filterFrom: from,
1366
+ filterTo: to,
1367
+ filter: (a, b) => a >= to || b <= from
1368
+ });
1369
+ }
1370
+ /**
1371
+ Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
1372
+ in the given state.
1373
+ */
1374
+ function foldedRanges(state$1) {
1375
+ return state$1.field(foldState, false) || state.RangeSet.empty;
1376
+ }
1377
+ function findFold(state, from, to) {
1378
+ var _a;
1379
+ let found = null;
1380
+ (_a = state.field(foldState, false)) === null || _a === void 0 ? void 0 : _a.between(from, to, (from, to) => {
1381
+ if (!found || found.from > from)
1382
+ found = { from, to };
1383
+ });
1384
+ return found;
1385
+ }
1386
+ function foldExists(folded, from, to) {
1387
+ let found = false;
1388
+ folded.between(from, from, (a, b) => { if (a == from && b == to)
1389
+ found = true; });
1390
+ return found;
1391
+ }
1392
+ function maybeEnable(state$1, other) {
1393
+ return state$1.field(foldState, false) ? other : other.concat(state.StateEffect.appendConfig.of(codeFolding()));
1394
+ }
1395
+ /**
1396
+ Fold the lines that are selected, if possible.
1397
+ */
1398
+ const foldCode = view => {
1399
+ for (let line of selectedLines(view)) {
1400
+ let range = foldable(view.state, line.from, line.to);
1401
+ if (range) {
1402
+ view.dispatch({ effects: maybeEnable(view.state, [foldEffect.of(range), announceFold(view, range)]) });
1403
+ return true;
1404
+ }
1405
+ }
1406
+ return false;
1407
+ };
1408
+ /**
1409
+ Unfold folded ranges on selected lines.
1410
+ */
1411
+ const unfoldCode = view => {
1412
+ if (!view.state.field(foldState, false))
1413
+ return false;
1414
+ let effects = [];
1415
+ for (let line of selectedLines(view)) {
1416
+ let folded = findFold(view.state, line.from, line.to);
1417
+ if (folded)
1418
+ effects.push(unfoldEffect.of(folded), announceFold(view, folded, false));
1419
+ }
1420
+ if (effects.length)
1421
+ view.dispatch({ effects });
1422
+ return effects.length > 0;
1423
+ };
1424
+ function announceFold(view$1, range, fold = true) {
1425
+ let lineFrom = view$1.state.doc.lineAt(range.from).number, lineTo = view$1.state.doc.lineAt(range.to).number;
1426
+ return view.EditorView.announce.of(`${view$1.state.phrase(fold ? "Folded lines" : "Unfolded lines")} ${lineFrom} ${view$1.state.phrase("to")} ${lineTo}.`);
1427
+ }
1428
+ /**
1429
+ Fold all top-level foldable ranges. Note that, in most cases,
1430
+ folding information will depend on the [syntax
1431
+ tree](https://codemirror.net/6/docs/ref/#language.syntaxTree), and folding everything may not work
1432
+ reliably when the document hasn't been fully parsed (either
1433
+ because the editor state was only just initialized, or because the
1434
+ document is so big that the parser decided not to parse it
1435
+ entirely).
1436
+ */
1437
+ const foldAll = view => {
1438
+ let { state } = view, effects = [];
1439
+ for (let pos = 0; pos < state.doc.length;) {
1440
+ let line = view.lineBlockAt(pos), range = foldable(state, line.from, line.to);
1441
+ if (range)
1442
+ effects.push(foldEffect.of(range));
1443
+ pos = (range ? view.lineBlockAt(range.to) : line).to + 1;
1444
+ }
1445
+ if (effects.length)
1446
+ view.dispatch({ effects: maybeEnable(view.state, effects) });
1447
+ return !!effects.length;
1448
+ };
1449
+ /**
1450
+ Unfold all folded code.
1451
+ */
1452
+ const unfoldAll = view => {
1453
+ let field = view.state.field(foldState, false);
1454
+ if (!field || !field.size)
1455
+ return false;
1456
+ let effects = [];
1457
+ field.between(0, view.state.doc.length, (from, to) => { effects.push(unfoldEffect.of({ from, to })); });
1458
+ view.dispatch({ effects });
1459
+ return true;
1460
+ };
1461
+ // Find the foldable region containing the given line, if one exists
1462
+ function foldableContainer(view, lineBlock) {
1463
+ // Look backwards through line blocks until we find a foldable region that
1464
+ // intersects with the line
1465
+ for (let line = lineBlock;;) {
1466
+ let foldableRegion = foldable(view.state, line.from, line.to);
1467
+ if (foldableRegion && foldableRegion.to > lineBlock.from)
1468
+ return foldableRegion;
1469
+ if (!line.from)
1470
+ return null;
1471
+ line = view.lineBlockAt(line.from - 1);
1472
+ }
1473
+ }
1474
+ /**
1475
+ Toggle folding at cursors. Unfolds if there is an existing fold
1476
+ starting in that line, tries to find a foldable range around it
1477
+ otherwise.
1478
+ */
1479
+ const toggleFold = (view) => {
1480
+ let effects = [];
1481
+ for (let line of selectedLines(view)) {
1482
+ let folded = findFold(view.state, line.from, line.to);
1483
+ if (folded) {
1484
+ effects.push(unfoldEffect.of(folded), announceFold(view, folded, false));
1485
+ }
1486
+ else {
1487
+ let foldRange = foldableContainer(view, line);
1488
+ if (foldRange)
1489
+ effects.push(foldEffect.of(foldRange), announceFold(view, foldRange));
1490
+ }
1491
+ }
1492
+ if (effects.length > 0)
1493
+ view.dispatch({ effects: maybeEnable(view.state, effects) });
1494
+ return !!effects.length;
1495
+ };
1496
+ /**
1497
+ Default fold-related key bindings.
1498
+
1499
+ - Ctrl-Shift-[ (Cmd-Alt-[ on macOS): [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode).
1500
+ - Ctrl-Shift-] (Cmd-Alt-] on macOS): [`unfoldCode`](https://codemirror.net/6/docs/ref/#language.unfoldCode).
1501
+ - Ctrl-Alt-[: [`foldAll`](https://codemirror.net/6/docs/ref/#language.foldAll).
1502
+ - Ctrl-Alt-]: [`unfoldAll`](https://codemirror.net/6/docs/ref/#language.unfoldAll).
1503
+ */
1504
+ const foldKeymap = [
1505
+ { key: "Ctrl-Shift-[", mac: "Cmd-Alt-[", run: foldCode },
1506
+ { key: "Ctrl-Shift-]", mac: "Cmd-Alt-]", run: unfoldCode },
1507
+ { key: "Ctrl-Alt-[", run: foldAll },
1508
+ { key: "Ctrl-Alt-]", run: unfoldAll }
1509
+ ];
1510
+ const defaultConfig = {
1511
+ placeholderDOM: null,
1512
+ preparePlaceholder: null,
1513
+ placeholderText: "…"
1514
+ };
1515
+ const foldConfig = state.Facet.define({
1516
+ combine(values) { return state.combineConfig(values, defaultConfig); }
1517
+ });
1518
+ /**
1519
+ Create an extension that configures code folding.
1520
+ */
1521
+ function codeFolding(config) {
1522
+ let result = [foldState, baseTheme$1];
1523
+ if (config)
1524
+ result.push(foldConfig.of(config));
1525
+ return result;
1526
+ }
1527
+ function widgetToDOM(view, prepared) {
1528
+ let { state } = view, conf = state.facet(foldConfig);
1529
+ let onclick = (event) => {
1530
+ let line = view.lineBlockAt(view.posAtDOM(event.target));
1531
+ let folded = findFold(view.state, line.from, line.to);
1532
+ if (folded)
1533
+ view.dispatch({ effects: unfoldEffect.of(folded) });
1534
+ event.preventDefault();
1535
+ };
1536
+ if (conf.placeholderDOM)
1537
+ return conf.placeholderDOM(view, onclick, prepared);
1538
+ let element = document.createElement("span");
1539
+ element.textContent = conf.placeholderText;
1540
+ element.setAttribute("aria-label", state.phrase("folded code"));
1541
+ element.title = state.phrase("unfold");
1542
+ element.className = "cm-foldPlaceholder";
1543
+ element.onclick = onclick;
1544
+ return element;
1545
+ }
1546
+ const foldWidget = view.Decoration.replace({ widget: new class extends view.WidgetType {
1547
+ toDOM(view) { return widgetToDOM(view, null); }
1548
+ } });
1549
+ class PreparedFoldWidget extends view.WidgetType {
1550
+ constructor(value) {
1551
+ super();
1552
+ this.value = value;
1553
+ }
1554
+ eq(other) { return this.value == other.value; }
1555
+ toDOM(view) { return widgetToDOM(view, this.value); }
1556
+ }
1557
+ const foldGutterDefaults = {
1558
+ openText: "⌄",
1559
+ closedText: "›",
1560
+ markerDOM: null,
1561
+ domEventHandlers: {},
1562
+ foldingChanged: () => false
1563
+ };
1564
+ class FoldMarker extends view.GutterMarker {
1565
+ constructor(config, open) {
1566
+ super();
1567
+ this.config = config;
1568
+ this.open = open;
1569
+ }
1570
+ eq(other) { return this.config == other.config && this.open == other.open; }
1571
+ toDOM(view) {
1572
+ if (this.config.markerDOM)
1573
+ return this.config.markerDOM(this.open);
1574
+ let span = document.createElement("span");
1575
+ span.textContent = this.open ? this.config.openText : this.config.closedText;
1576
+ span.title = view.state.phrase(this.open ? "Fold line" : "Unfold line");
1577
+ return span;
1578
+ }
1579
+ }
1580
+ /**
1581
+ Create an extension that registers a fold gutter, which shows a
1582
+ fold status indicator before foldable lines (which can be clicked
1583
+ to fold or unfold the line).
1584
+ */
1585
+ function foldGutter(config = {}) {
1586
+ let fullConfig = { ...foldGutterDefaults, ...config };
1587
+ let canFold = new FoldMarker(fullConfig, true), canUnfold = new FoldMarker(fullConfig, false);
1588
+ let markers = view.ViewPlugin.fromClass(class {
1589
+ constructor(view) {
1590
+ this.from = view.viewport.from;
1591
+ this.markers = this.buildMarkers(view);
1592
+ }
1593
+ update(update) {
1594
+ if (update.docChanged || update.viewportChanged ||
1595
+ update.startState.facet(language) != update.state.facet(language) ||
1596
+ update.startState.field(foldState, false) != update.state.field(foldState, false) ||
1597
+ syntaxTree(update.startState) != syntaxTree(update.state) ||
1598
+ fullConfig.foldingChanged(update))
1599
+ this.markers = this.buildMarkers(update.view);
1600
+ }
1601
+ buildMarkers(view) {
1602
+ let builder = new state.RangeSetBuilder();
1603
+ for (let line of view.viewportLineBlocks) {
1604
+ let mark = findFold(view.state, line.from, line.to) ? canUnfold
1605
+ : foldable(view.state, line.from, line.to) ? canFold : null;
1606
+ if (mark)
1607
+ builder.add(line.from, line.from, mark);
1608
+ }
1609
+ return builder.finish();
1610
+ }
1611
+ });
1612
+ let { domEventHandlers } = fullConfig;
1613
+ return [
1614
+ markers,
1615
+ view.gutter({
1616
+ class: "cm-foldGutter",
1617
+ markers(view) { var _a; return ((_a = view.plugin(markers)) === null || _a === void 0 ? void 0 : _a.markers) || state.RangeSet.empty; },
1618
+ initialSpacer() {
1619
+ return new FoldMarker(fullConfig, false);
1620
+ },
1621
+ domEventHandlers: {
1622
+ ...domEventHandlers,
1623
+ click: (view, line, event) => {
1624
+ if (domEventHandlers.click && domEventHandlers.click(view, line, event))
1625
+ return true;
1626
+ let folded = findFold(view.state, line.from, line.to);
1627
+ if (folded) {
1628
+ view.dispatch({ effects: unfoldEffect.of(folded) });
1629
+ return true;
1630
+ }
1631
+ let range = foldable(view.state, line.from, line.to);
1632
+ if (range) {
1633
+ view.dispatch({ effects: foldEffect.of(range) });
1634
+ return true;
1635
+ }
1636
+ return false;
1637
+ }
1638
+ }
1639
+ }),
1640
+ codeFolding()
1641
+ ];
1642
+ }
1643
+ const baseTheme$1 = view.EditorView.baseTheme({
1644
+ ".cm-foldPlaceholder": {
1645
+ backgroundColor: "#eee",
1646
+ border: "1px solid #ddd",
1647
+ color: "#888",
1648
+ borderRadius: ".2em",
1649
+ margin: "0 1px",
1650
+ padding: "0 1px",
1651
+ cursor: "pointer"
1652
+ },
1653
+ ".cm-foldGutter span": {
1654
+ padding: "0 1px",
1655
+ cursor: "pointer"
1656
+ }
1657
+ });
1658
+
1659
+ /**
1660
+ A highlight style associates CSS styles with highlighting
1661
+ [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag).
1662
+ */
1663
+ class HighlightStyle {
1664
+ constructor(
1665
+ /**
1666
+ The tag styles used to create this highlight style.
1667
+ */
1668
+ specs, options) {
1669
+ this.specs = specs;
1670
+ let modSpec;
1671
+ function def(spec) {
1672
+ let cls = styleMod.StyleModule.newName();
1673
+ (modSpec || (modSpec = Object.create(null)))["." + cls] = spec;
1674
+ return cls;
1675
+ }
1676
+ const all = typeof options.all == "string" ? options.all : options.all ? def(options.all) : undefined;
1677
+ const scopeOpt = options.scope;
1678
+ this.scope = scopeOpt instanceof Language ? (type) => type.prop(languageDataProp) == scopeOpt.data
1679
+ : scopeOpt ? (type) => type == scopeOpt : undefined;
1680
+ this.style = highlight.tagHighlighter(specs.map(style => ({
1681
+ tag: style.tag,
1682
+ class: style.class || def(Object.assign({}, style, { tag: null }))
1683
+ })), {
1684
+ all,
1685
+ }).style;
1686
+ this.module = modSpec ? new styleMod.StyleModule(modSpec) : null;
1687
+ this.themeType = options.themeType;
1688
+ }
1689
+ /**
1690
+ Create a highlighter style that associates the given styles to
1691
+ the given tags. The specs must be objects that hold a style tag
1692
+ or array of tags in their `tag` property, and either a single
1693
+ `class` property providing a static CSS class (for highlighter
1694
+ that rely on external styling), or a
1695
+ [`style-mod`](https://github.com/marijnh/style-mod#documentation)-style
1696
+ set of CSS properties (which define the styling for those tags).
1697
+
1698
+ The CSS rules created for a highlighter will be emitted in the
1699
+ order of the spec's properties. That means that for elements that
1700
+ have multiple tags associated with them, styles defined further
1701
+ down in the list will have a higher CSS precedence than styles
1702
+ defined earlier.
1703
+ */
1704
+ static define(specs, options) {
1705
+ return new HighlightStyle(specs, options || {});
1706
+ }
1707
+ }
1708
+ const highlighterFacet = state.Facet.define();
1709
+ const fallbackHighlighter = state.Facet.define({
1710
+ combine(values) { return values.length ? [values[0]] : null; }
1711
+ });
1712
+ function getHighlighters(state) {
1713
+ let main = state.facet(highlighterFacet);
1714
+ return main.length ? main : state.facet(fallbackHighlighter);
1715
+ }
1716
+ /**
1717
+ Wrap a highlighter in an editor extension that uses it to apply
1718
+ syntax highlighting to the editor content.
1719
+
1720
+ When multiple (non-fallback) styles are provided, the styling
1721
+ applied is the union of the classes they emit.
1722
+ */
1723
+ function syntaxHighlighting(highlighter, options) {
1724
+ let ext = [treeHighlighter], themeType;
1725
+ if (highlighter instanceof HighlightStyle) {
1726
+ if (highlighter.module)
1727
+ ext.push(view.EditorView.styleModule.of(highlighter.module));
1728
+ themeType = highlighter.themeType;
1729
+ }
1730
+ if (options === null || options === void 0 ? void 0 : options.fallback)
1731
+ ext.push(fallbackHighlighter.of(highlighter));
1732
+ else if (themeType)
1733
+ ext.push(highlighterFacet.computeN([view.EditorView.darkTheme], state => {
1734
+ return state.facet(view.EditorView.darkTheme) == (themeType == "dark") ? [highlighter] : [];
1735
+ }));
1736
+ else
1737
+ ext.push(highlighterFacet.of(highlighter));
1738
+ return ext;
1739
+ }
1740
+ /**
1741
+ Returns the CSS classes (if any) that the highlighters active in
1742
+ the state would assign to the given style
1743
+ [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag) and
1744
+ (optional) language
1745
+ [scope](https://codemirror.net/6/docs/ref/#language.HighlightStyle^define^options.scope).
1746
+ */
1747
+ function highlightingFor(state, tags, scope) {
1748
+ let highlighters = getHighlighters(state);
1749
+ let result = null;
1750
+ if (highlighters)
1751
+ for (let highlighter of highlighters) {
1752
+ if (!highlighter.scope || scope && highlighter.scope(scope)) {
1753
+ let cls = highlighter.style(tags);
1754
+ if (cls)
1755
+ result = result ? result + " " + cls : cls;
1756
+ }
1757
+ }
1758
+ return result;
1759
+ }
1760
+ class TreeHighlighter {
1761
+ constructor(view) {
1762
+ this.markCache = Object.create(null);
1763
+ this.tree = syntaxTree(view.state);
1764
+ this.decorations = this.buildDeco(view, getHighlighters(view.state));
1765
+ this.decoratedTo = view.viewport.to;
1766
+ }
1767
+ update(update) {
1768
+ let tree = syntaxTree(update.state), highlighters = getHighlighters(update.state);
1769
+ let styleChange = highlighters != getHighlighters(update.startState);
1770
+ let { viewport } = update.view, decoratedToMapped = update.changes.mapPos(this.decoratedTo, 1);
1771
+ if (tree.length < viewport.to && !styleChange && tree.type == this.tree.type && decoratedToMapped >= viewport.to) {
1772
+ this.decorations = this.decorations.map(update.changes);
1773
+ this.decoratedTo = decoratedToMapped;
1774
+ }
1775
+ else if (tree != this.tree || update.viewportChanged || styleChange) {
1776
+ this.tree = tree;
1777
+ this.decorations = this.buildDeco(update.view, highlighters);
1778
+ this.decoratedTo = viewport.to;
1779
+ }
1780
+ }
1781
+ buildDeco(view$1, highlighters) {
1782
+ if (!highlighters || !this.tree.length)
1783
+ return view.Decoration.none;
1784
+ let builder = new state.RangeSetBuilder();
1785
+ for (let { from, to } of view$1.visibleRanges) {
1786
+ highlight.highlightTree(this.tree, highlighters, (from, to, style) => {
1787
+ builder.add(from, to, this.markCache[style] || (this.markCache[style] = view.Decoration.mark({ class: style })));
1788
+ }, from, to);
1789
+ }
1790
+ return builder.finish();
1791
+ }
1792
+ }
1793
+ const treeHighlighter = state.Prec.high(view.ViewPlugin.fromClass(TreeHighlighter, {
1794
+ decorations: v => v.decorations
1795
+ }));
1796
+ /**
1797
+ A default highlight style (works well with light themes).
1798
+ */
1799
+ const defaultHighlightStyle = HighlightStyle.define([
1800
+ { tag: highlight.tags.meta,
1801
+ color: "#404740" },
1802
+ { tag: highlight.tags.link,
1803
+ textDecoration: "underline" },
1804
+ { tag: highlight.tags.heading,
1805
+ textDecoration: "underline",
1806
+ fontWeight: "bold" },
1807
+ { tag: highlight.tags.emphasis,
1808
+ fontStyle: "italic" },
1809
+ { tag: highlight.tags.strong,
1810
+ fontWeight: "bold" },
1811
+ { tag: highlight.tags.strikethrough,
1812
+ textDecoration: "line-through" },
1813
+ { tag: highlight.tags.keyword,
1814
+ color: "#708" },
1815
+ { tag: [highlight.tags.atom, highlight.tags.bool, highlight.tags.url, highlight.tags.contentSeparator, highlight.tags.labelName],
1816
+ color: "#219" },
1817
+ { tag: [highlight.tags.literal, highlight.tags.inserted],
1818
+ color: "#164" },
1819
+ { tag: [highlight.tags.string, highlight.tags.deleted],
1820
+ color: "#a11" },
1821
+ { tag: [highlight.tags.regexp, highlight.tags.escape, highlight.tags.special(highlight.tags.string)],
1822
+ color: "#e40" },
1823
+ { tag: highlight.tags.definition(highlight.tags.variableName),
1824
+ color: "#00f" },
1825
+ { tag: highlight.tags.local(highlight.tags.variableName),
1826
+ color: "#30a" },
1827
+ { tag: [highlight.tags.typeName, highlight.tags.namespace],
1828
+ color: "#085" },
1829
+ { tag: highlight.tags.className,
1830
+ color: "#167" },
1831
+ { tag: [highlight.tags.special(highlight.tags.variableName), highlight.tags.macroName],
1832
+ color: "#256" },
1833
+ { tag: highlight.tags.definition(highlight.tags.propertyName),
1834
+ color: "#00c" },
1835
+ { tag: highlight.tags.comment,
1836
+ color: "#940" },
1837
+ { tag: highlight.tags.invalid,
1838
+ color: "#f00" }
1839
+ ]);
1840
+
1841
+ const baseTheme = view.EditorView.baseTheme({
1842
+ "&.cm-focused .cm-matchingBracket": { backgroundColor: "#328c8252" },
1843
+ "&.cm-focused .cm-nonmatchingBracket": { backgroundColor: "#bb555544" }
1844
+ });
1845
+ const DefaultScanDist = 10000, DefaultBrackets = "()[]{}";
1846
+ const bracketMatchingConfig = state.Facet.define({
1847
+ combine(configs) {
1848
+ return state.combineConfig(configs, {
1849
+ afterCursor: true,
1850
+ brackets: DefaultBrackets,
1851
+ maxScanDistance: DefaultScanDist,
1852
+ renderMatch: defaultRenderMatch
1853
+ });
1854
+ }
1855
+ });
1856
+ const matchingMark = view.Decoration.mark({ class: "cm-matchingBracket" }), nonmatchingMark = view.Decoration.mark({ class: "cm-nonmatchingBracket" });
1857
+ function defaultRenderMatch(match) {
1858
+ let decorations = [];
1859
+ let mark = match.matched ? matchingMark : nonmatchingMark;
1860
+ decorations.push(mark.range(match.start.from, match.start.to));
1861
+ if (match.end)
1862
+ decorations.push(mark.range(match.end.from, match.end.to));
1863
+ return decorations;
1864
+ }
1865
+ function bracketDeco(state) {
1866
+ let decorations = [];
1867
+ let config = state.facet(bracketMatchingConfig);
1868
+ for (let range of state.selection.ranges) {
1869
+ if (!range.empty)
1870
+ continue;
1871
+ let match = matchBrackets(state, range.head, -1, config)
1872
+ || (range.head > 0 && matchBrackets(state, range.head - 1, 1, config))
1873
+ || (config.afterCursor &&
1874
+ (matchBrackets(state, range.head, 1, config) ||
1875
+ (range.head < state.doc.length && matchBrackets(state, range.head + 1, -1, config))));
1876
+ if (match)
1877
+ decorations = decorations.concat(config.renderMatch(match, state));
1878
+ }
1879
+ return view.Decoration.set(decorations, true);
1880
+ }
1881
+ const bracketMatcher = view.ViewPlugin.fromClass(class {
1882
+ constructor(view) {
1883
+ this.paused = false;
1884
+ this.decorations = bracketDeco(view.state);
1885
+ }
1886
+ update(update) {
1887
+ if (update.docChanged || update.selectionSet || this.paused) {
1888
+ if (update.view.composing) {
1889
+ this.decorations = this.decorations.map(update.changes);
1890
+ this.paused = true;
1891
+ }
1892
+ else {
1893
+ this.decorations = bracketDeco(update.state);
1894
+ this.paused = false;
1895
+ }
1896
+ }
1897
+ }
1898
+ }, {
1899
+ decorations: v => v.decorations
1900
+ });
1901
+ const bracketMatchingUnique = [
1902
+ bracketMatcher,
1903
+ baseTheme
1904
+ ];
1905
+ /**
1906
+ Create an extension that enables bracket matching. Whenever the
1907
+ cursor is next to a bracket, that bracket and the one it matches
1908
+ are highlighted. Or, when no matching bracket is found, another
1909
+ highlighting style is used to indicate this.
1910
+ */
1911
+ function bracketMatching(config = {}) {
1912
+ return [bracketMatchingConfig.of(config), bracketMatchingUnique];
1913
+ }
1914
+ /**
1915
+ When larger syntax nodes, such as HTML tags, are marked as
1916
+ opening/closing, it can be a bit messy to treat the whole node as
1917
+ a matchable bracket. This node prop allows you to define, for such
1918
+ a node, a ‘handle’—the part of the node that is highlighted, and
1919
+ that the cursor must be on to activate highlighting in the first
1920
+ place.
1921
+ */
1922
+ const bracketMatchingHandle = new common.NodeProp();
1923
+ function matchingNodes(node, dir, brackets) {
1924
+ let byProp = node.prop(dir < 0 ? common.NodeProp.openedBy : common.NodeProp.closedBy);
1925
+ if (byProp)
1926
+ return byProp;
1927
+ if (node.name.length == 1) {
1928
+ let index = brackets.indexOf(node.name);
1929
+ if (index > -1 && index % 2 == (dir < 0 ? 1 : 0))
1930
+ return [brackets[index + dir]];
1931
+ }
1932
+ return null;
1933
+ }
1934
+ function findHandle(node) {
1935
+ let hasHandle = node.type.prop(bracketMatchingHandle);
1936
+ return hasHandle ? hasHandle(node.node) : node;
1937
+ }
1938
+ /**
1939
+ Find the matching bracket for the token at `pos`, scanning
1940
+ direction `dir`. Only the `brackets` and `maxScanDistance`
1941
+ properties are used from `config`, if given. Returns null if no
1942
+ bracket was found at `pos`, or a match result otherwise.
1943
+ */
1944
+ function matchBrackets(state, pos, dir, config = {}) {
1945
+ let maxScanDistance = config.maxScanDistance || DefaultScanDist, brackets = config.brackets || DefaultBrackets;
1946
+ let tree = syntaxTree(state), node = tree.resolveInner(pos, dir);
1947
+ for (let cur = node; cur; cur = cur.parent) {
1948
+ let matches = matchingNodes(cur.type, dir, brackets);
1949
+ if (matches && cur.from < cur.to) {
1950
+ let handle = findHandle(cur);
1951
+ if (handle && (dir > 0 ? pos >= handle.from && pos < handle.to : pos > handle.from && pos <= handle.to))
1952
+ return matchMarkedBrackets(state, pos, dir, cur, handle, matches, brackets);
1953
+ }
1954
+ }
1955
+ return matchPlainBrackets(state, pos, dir, tree, node.type, maxScanDistance, brackets);
1956
+ }
1957
+ function matchMarkedBrackets(_state, _pos, dir, token, handle, matching, brackets) {
1958
+ let parent = token.parent, firstToken = { from: handle.from, to: handle.to };
1959
+ let depth = 0, cursor = parent === null || parent === void 0 ? void 0 : parent.cursor();
1960
+ if (cursor && (dir < 0 ? cursor.childBefore(token.from) : cursor.childAfter(token.to)))
1961
+ do {
1962
+ if (dir < 0 ? cursor.to <= token.from : cursor.from >= token.to) {
1963
+ if (depth == 0 && matching.indexOf(cursor.type.name) > -1 && cursor.from < cursor.to) {
1964
+ let endHandle = findHandle(cursor);
1965
+ return { start: firstToken, end: endHandle ? { from: endHandle.from, to: endHandle.to } : undefined, matched: true };
1966
+ }
1967
+ else if (matchingNodes(cursor.type, dir, brackets)) {
1968
+ depth++;
1969
+ }
1970
+ else if (matchingNodes(cursor.type, -dir, brackets)) {
1971
+ if (depth == 0) {
1972
+ let endHandle = findHandle(cursor);
1973
+ return {
1974
+ start: firstToken,
1975
+ end: endHandle && endHandle.from < endHandle.to ? { from: endHandle.from, to: endHandle.to } : undefined,
1976
+ matched: false
1977
+ };
1978
+ }
1979
+ depth--;
1980
+ }
1981
+ }
1982
+ } while (dir < 0 ? cursor.prevSibling() : cursor.nextSibling());
1983
+ return { start: firstToken, matched: false };
1984
+ }
1985
+ function matchPlainBrackets(state, pos, dir, tree, tokenType, maxScanDistance, brackets) {
1986
+ if (dir < 0 ? !pos : pos == state.doc.length)
1987
+ return null;
1988
+ let startCh = dir < 0 ? state.sliceDoc(pos - 1, pos) : state.sliceDoc(pos, pos + 1);
1989
+ let bracket = brackets.indexOf(startCh);
1990
+ if (bracket < 0 || (bracket % 2 == 0) != (dir > 0))
1991
+ return null;
1992
+ let startToken = { from: dir < 0 ? pos - 1 : pos, to: dir > 0 ? pos + 1 : pos };
1993
+ let iter = state.doc.iterRange(pos, dir > 0 ? state.doc.length : 0), depth = 0;
1994
+ for (let distance = 0; !(iter.next()).done && distance <= maxScanDistance;) {
1995
+ let text = iter.value;
1996
+ if (dir < 0)
1997
+ distance += text.length;
1998
+ let basePos = pos + distance * dir;
1999
+ for (let pos = dir > 0 ? 0 : text.length - 1, end = dir > 0 ? text.length : -1; pos != end; pos += dir) {
2000
+ let found = brackets.indexOf(text[pos]);
2001
+ if (found < 0 || tree.resolveInner(basePos + pos, 1).type != tokenType)
2002
+ continue;
2003
+ if ((found % 2 == 0) == (dir > 0)) {
2004
+ depth++;
2005
+ }
2006
+ else if (depth == 1) { // Closing
2007
+ return { start: startToken, end: { from: basePos + pos, to: basePos + pos + 1 }, matched: (found >> 1) == (bracket >> 1) };
2008
+ }
2009
+ else {
2010
+ depth--;
2011
+ }
2012
+ }
2013
+ if (dir > 0)
2014
+ distance += text.length;
2015
+ }
2016
+ return iter.done ? { start: startToken, matched: false } : null;
2017
+ }
2018
+
2019
+ // Counts the column offset in a string, taking tabs into account.
2020
+ // Used mostly to find indentation.
2021
+ function countCol(string, end, tabSize, startIndex = 0, startValue = 0) {
2022
+ if (end == null) {
2023
+ end = string.search(/[^\s\u00a0]/);
2024
+ if (end == -1)
2025
+ end = string.length;
2026
+ }
2027
+ let n = startValue;
2028
+ for (let i = startIndex; i < end; i++) {
2029
+ if (string.charCodeAt(i) == 9)
2030
+ n += tabSize - (n % tabSize);
2031
+ else
2032
+ n++;
2033
+ }
2034
+ return n;
2035
+ }
2036
+ /**
2037
+ Encapsulates a single line of input. Given to stream syntax code,
2038
+ which uses it to tokenize the content.
2039
+ */
2040
+ class StringStream {
2041
+ /**
2042
+ Create a stream.
2043
+ */
2044
+ constructor(
2045
+ /**
2046
+ The line.
2047
+ */
2048
+ string, tabSize,
2049
+ /**
2050
+ The current indent unit size.
2051
+ */
2052
+ indentUnit, overrideIndent) {
2053
+ this.string = string;
2054
+ this.tabSize = tabSize;
2055
+ this.indentUnit = indentUnit;
2056
+ this.overrideIndent = overrideIndent;
2057
+ /**
2058
+ The current position on the line.
2059
+ */
2060
+ this.pos = 0;
2061
+ /**
2062
+ The start position of the current token.
2063
+ */
2064
+ this.start = 0;
2065
+ this.lastColumnPos = 0;
2066
+ this.lastColumnValue = 0;
2067
+ }
2068
+ /**
2069
+ True if we are at the end of the line.
2070
+ */
2071
+ eol() { return this.pos >= this.string.length; }
2072
+ /**
2073
+ True if we are at the start of the line.
2074
+ */
2075
+ sol() { return this.pos == 0; }
2076
+ /**
2077
+ Get the next code unit after the current position, or undefined
2078
+ if we're at the end of the line.
2079
+ */
2080
+ peek() { return this.string.charAt(this.pos) || undefined; }
2081
+ /**
2082
+ Read the next code unit and advance `this.pos`.
2083
+ */
2084
+ next() {
2085
+ if (this.pos < this.string.length)
2086
+ return this.string.charAt(this.pos++);
2087
+ }
2088
+ /**
2089
+ Match the next character against the given string, regular
2090
+ expression, or predicate. Consume and return it if it matches.
2091
+ */
2092
+ eat(match) {
2093
+ let ch = this.string.charAt(this.pos);
2094
+ let ok;
2095
+ if (typeof match == "string")
2096
+ ok = ch == match;
2097
+ else
2098
+ ok = ch && (match instanceof RegExp ? match.test(ch) : match(ch));
2099
+ if (ok) {
2100
+ ++this.pos;
2101
+ return ch;
2102
+ }
2103
+ }
2104
+ /**
2105
+ Continue matching characters that match the given string,
2106
+ regular expression, or predicate function. Return true if any
2107
+ characters were consumed.
2108
+ */
2109
+ eatWhile(match) {
2110
+ let start = this.pos;
2111
+ while (this.eat(match)) { }
2112
+ return this.pos > start;
2113
+ }
2114
+ /**
2115
+ Consume whitespace ahead of `this.pos`. Return true if any was
2116
+ found.
2117
+ */
2118
+ eatSpace() {
2119
+ let start = this.pos;
2120
+ while (/[\s\u00a0]/.test(this.string.charAt(this.pos)))
2121
+ ++this.pos;
2122
+ return this.pos > start;
2123
+ }
2124
+ /**
2125
+ Move to the end of the line.
2126
+ */
2127
+ skipToEnd() { this.pos = this.string.length; }
2128
+ /**
2129
+ Move to directly before the given character, if found on the
2130
+ current line.
2131
+ */
2132
+ skipTo(ch) {
2133
+ let found = this.string.indexOf(ch, this.pos);
2134
+ if (found > -1) {
2135
+ this.pos = found;
2136
+ return true;
2137
+ }
2138
+ }
2139
+ /**
2140
+ Move back `n` characters.
2141
+ */
2142
+ backUp(n) { this.pos -= n; }
2143
+ /**
2144
+ Get the column position at `this.pos`.
2145
+ */
2146
+ column() {
2147
+ if (this.lastColumnPos < this.start) {
2148
+ this.lastColumnValue = countCol(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
2149
+ this.lastColumnPos = this.start;
2150
+ }
2151
+ return this.lastColumnValue;
2152
+ }
2153
+ /**
2154
+ Get the indentation column of the current line.
2155
+ */
2156
+ indentation() {
2157
+ var _a;
2158
+ return (_a = this.overrideIndent) !== null && _a !== void 0 ? _a : countCol(this.string, null, this.tabSize);
2159
+ }
2160
+ /**
2161
+ Match the input against the given string or regular expression
2162
+ (which should start with a `^`). Return true or the regexp match
2163
+ if it matches.
2164
+
2165
+ Unless `consume` is set to `false`, this will move `this.pos`
2166
+ past the matched text.
2167
+
2168
+ When matching a string `caseInsensitive` can be set to true to
2169
+ make the match case-insensitive.
2170
+ */
2171
+ match(pattern, consume, caseInsensitive) {
2172
+ if (typeof pattern == "string") {
2173
+ let cased = (str) => caseInsensitive ? str.toLowerCase() : str;
2174
+ let substr = this.string.substr(this.pos, pattern.length);
2175
+ if (cased(substr) == cased(pattern)) {
2176
+ if (consume !== false)
2177
+ this.pos += pattern.length;
2178
+ return true;
2179
+ }
2180
+ else
2181
+ return null;
2182
+ }
2183
+ else {
2184
+ let match = this.string.slice(this.pos).match(pattern);
2185
+ if (match && match.index > 0)
2186
+ return null;
2187
+ if (match && consume !== false)
2188
+ this.pos += match[0].length;
2189
+ return match;
2190
+ }
2191
+ }
2192
+ /**
2193
+ Get the current token.
2194
+ */
2195
+ current() { return this.string.slice(this.start, this.pos); }
2196
+ }
2197
+
2198
+ function fullParser(spec) {
2199
+ return {
2200
+ name: spec.name || "",
2201
+ token: spec.token,
2202
+ blankLine: spec.blankLine || (() => { }),
2203
+ startState: spec.startState || (() => true),
2204
+ copyState: spec.copyState || defaultCopyState,
2205
+ indent: spec.indent || (() => null),
2206
+ languageData: spec.languageData || {},
2207
+ tokenTable: spec.tokenTable || noTokens,
2208
+ mergeTokens: spec.mergeTokens !== false
2209
+ };
2210
+ }
2211
+ function defaultCopyState(state) {
2212
+ if (typeof state != "object")
2213
+ return state;
2214
+ let newState = {};
2215
+ for (let prop in state) {
2216
+ let val = state[prop];
2217
+ newState[prop] = (val instanceof Array ? val.slice() : val);
2218
+ }
2219
+ return newState;
2220
+ }
2221
+ const IndentedFrom = new WeakMap();
2222
+ /**
2223
+ A [language](https://codemirror.net/6/docs/ref/#language.Language) class based on a CodeMirror
2224
+ 5-style [streaming parser](https://codemirror.net/6/docs/ref/#language.StreamParser).
2225
+ */
2226
+ class StreamLanguage extends Language {
2227
+ constructor(parser) {
2228
+ let data = defineLanguageFacet(parser.languageData);
2229
+ let p = fullParser(parser), self;
2230
+ let impl = new class extends common.Parser {
2231
+ createParse(input, fragments, ranges) {
2232
+ return new Parse(self, input, fragments, ranges);
2233
+ }
2234
+ };
2235
+ super(data, impl, [], parser.name);
2236
+ this.topNode = docID(data, this);
2237
+ self = this;
2238
+ this.streamParser = p;
2239
+ this.stateAfter = new common.NodeProp({ perNode: true });
2240
+ this.tokenTable = parser.tokenTable ? new TokenTable(p.tokenTable) : defaultTokenTable;
2241
+ }
2242
+ /**
2243
+ Define a stream language.
2244
+ */
2245
+ static define(spec) { return new StreamLanguage(spec); }
2246
+ /**
2247
+ @internal
2248
+ */
2249
+ getIndent(cx) {
2250
+ let from = undefined;
2251
+ let { overrideIndentation } = cx.options;
2252
+ if (overrideIndentation) {
2253
+ from = IndentedFrom.get(cx.state);
2254
+ if (from != null && from < cx.pos - 1e4)
2255
+ from = undefined;
2256
+ }
2257
+ let start = findState(this, cx.node.tree, cx.node.from, cx.node.from, from !== null && from !== void 0 ? from : cx.pos), statePos, state;
2258
+ if (start) {
2259
+ state = start.state;
2260
+ statePos = start.pos + 1;
2261
+ }
2262
+ else {
2263
+ state = this.streamParser.startState(cx.unit);
2264
+ statePos = cx.node.from;
2265
+ }
2266
+ if (cx.pos - statePos > 10000 /* C.MaxIndentScanDist */)
2267
+ return null;
2268
+ while (statePos < cx.pos) {
2269
+ let line = cx.state.doc.lineAt(statePos), end = Math.min(cx.pos, line.to);
2270
+ if (line.length) {
2271
+ let indentation = overrideIndentation ? overrideIndentation(line.from) : -1;
2272
+ let stream = new StringStream(line.text, cx.state.tabSize, cx.unit, indentation < 0 ? undefined : indentation);
2273
+ while (stream.pos < end - line.from)
2274
+ readToken(this.streamParser.token, stream, state);
2275
+ }
2276
+ else {
2277
+ this.streamParser.blankLine(state, cx.unit);
2278
+ }
2279
+ if (end == cx.pos)
2280
+ break;
2281
+ statePos = line.to + 1;
2282
+ }
2283
+ let line = cx.lineAt(cx.pos);
2284
+ if (overrideIndentation && from == null)
2285
+ IndentedFrom.set(cx.state, line.from);
2286
+ return this.streamParser.indent(state, /^\s*(.*)/.exec(line.text)[1], cx);
2287
+ }
2288
+ get allowsNesting() { return false; }
2289
+ }
2290
+ function findState(lang, tree, off, startPos, before) {
2291
+ let state = off >= startPos && off + tree.length <= before && tree.prop(lang.stateAfter);
2292
+ if (state)
2293
+ return { state: lang.streamParser.copyState(state), pos: off + tree.length };
2294
+ for (let i = tree.children.length - 1; i >= 0; i--) {
2295
+ let child = tree.children[i], pos = off + tree.positions[i];
2296
+ let found = child instanceof common.Tree && pos < before && findState(lang, child, pos, startPos, before);
2297
+ if (found)
2298
+ return found;
2299
+ }
2300
+ return null;
2301
+ }
2302
+ function cutTree(lang, tree, from, to, inside) {
2303
+ if (inside && from <= 0 && to >= tree.length)
2304
+ return tree;
2305
+ if (!inside && from == 0 && tree.type == lang.topNode)
2306
+ inside = true;
2307
+ for (let i = tree.children.length - 1; i >= 0; i--) {
2308
+ let pos = tree.positions[i], child = tree.children[i], inner;
2309
+ if (pos < to && child instanceof common.Tree) {
2310
+ if (!(inner = cutTree(lang, child, from - pos, to - pos, inside)))
2311
+ break;
2312
+ return !inside ? inner
2313
+ : new common.Tree(tree.type, tree.children.slice(0, i).concat(inner), tree.positions.slice(0, i + 1), pos + inner.length);
2314
+ }
2315
+ }
2316
+ return null;
2317
+ }
2318
+ function findStartInFragments(lang, fragments, startPos, endPos, editorState) {
2319
+ for (let f of fragments) {
2320
+ let from = f.from + (f.openStart ? 25 : 0), to = f.to - (f.openEnd ? 25 : 0);
2321
+ let found = from <= startPos && to > startPos && findState(lang, f.tree, 0 - f.offset, startPos, to), tree;
2322
+ if (found && found.pos <= endPos && (tree = cutTree(lang, f.tree, startPos + f.offset, found.pos + f.offset, false)))
2323
+ return { state: found.state, tree };
2324
+ }
2325
+ return { state: lang.streamParser.startState(editorState ? getIndentUnit(editorState) : 4), tree: common.Tree.empty };
2326
+ }
2327
+ class Parse {
2328
+ constructor(lang, input, fragments, ranges) {
2329
+ this.lang = lang;
2330
+ this.input = input;
2331
+ this.fragments = fragments;
2332
+ this.ranges = ranges;
2333
+ this.stoppedAt = null;
2334
+ this.chunks = [];
2335
+ this.chunkPos = [];
2336
+ this.chunk = [];
2337
+ this.chunkReused = undefined;
2338
+ this.rangeIndex = 0;
2339
+ this.to = ranges[ranges.length - 1].to;
2340
+ let context = ParseContext.get(), from = ranges[0].from;
2341
+ let { state, tree } = findStartInFragments(lang, fragments, from, this.to, context === null || context === void 0 ? void 0 : context.state);
2342
+ this.state = state;
2343
+ this.parsedPos = this.chunkStart = from + tree.length;
2344
+ for (let i = 0; i < tree.children.length; i++) {
2345
+ this.chunks.push(tree.children[i]);
2346
+ this.chunkPos.push(tree.positions[i]);
2347
+ }
2348
+ if (context && this.parsedPos < context.viewport.from - 100000 /* C.MaxDistanceBeforeViewport */ &&
2349
+ ranges.some(r => r.from <= context.viewport.from && r.to >= context.viewport.from)) {
2350
+ this.state = this.lang.streamParser.startState(getIndentUnit(context.state));
2351
+ context.skipUntilInView(this.parsedPos, context.viewport.from);
2352
+ this.parsedPos = context.viewport.from;
2353
+ }
2354
+ this.moveRangeIndex();
2355
+ }
2356
+ advance() {
2357
+ let context = ParseContext.get();
2358
+ let parseEnd = this.stoppedAt == null ? this.to : Math.min(this.to, this.stoppedAt);
2359
+ let end = Math.min(parseEnd, this.chunkStart + 512 /* C.ChunkSize */);
2360
+ if (context)
2361
+ end = Math.min(end, context.viewport.to);
2362
+ while (this.parsedPos < end)
2363
+ this.parseLine(context);
2364
+ if (this.chunkStart < this.parsedPos)
2365
+ this.finishChunk();
2366
+ if (this.parsedPos >= parseEnd)
2367
+ return this.finish();
2368
+ if (context && this.parsedPos >= context.viewport.to) {
2369
+ context.skipUntilInView(this.parsedPos, parseEnd);
2370
+ return this.finish();
2371
+ }
2372
+ return null;
2373
+ }
2374
+ stopAt(pos) {
2375
+ this.stoppedAt = pos;
2376
+ }
2377
+ lineAfter(pos) {
2378
+ let chunk = this.input.chunk(pos);
2379
+ if (!this.input.lineChunks) {
2380
+ let eol = chunk.indexOf("\n");
2381
+ if (eol > -1)
2382
+ chunk = chunk.slice(0, eol);
2383
+ }
2384
+ else if (chunk == "\n") {
2385
+ chunk = "";
2386
+ }
2387
+ return pos + chunk.length <= this.to ? chunk : chunk.slice(0, this.to - pos);
2388
+ }
2389
+ nextLine() {
2390
+ let from = this.parsedPos, line = this.lineAfter(from), end = from + line.length;
2391
+ for (let index = this.rangeIndex;;) {
2392
+ let rangeEnd = this.ranges[index].to;
2393
+ if (rangeEnd >= end)
2394
+ break;
2395
+ line = line.slice(0, rangeEnd - (end - line.length));
2396
+ index++;
2397
+ if (index == this.ranges.length)
2398
+ break;
2399
+ let rangeStart = this.ranges[index].from;
2400
+ let after = this.lineAfter(rangeStart);
2401
+ line += after;
2402
+ end = rangeStart + after.length;
2403
+ }
2404
+ return { line, end };
2405
+ }
2406
+ skipGapsTo(pos, offset, side) {
2407
+ for (;;) {
2408
+ let end = this.ranges[this.rangeIndex].to, offPos = pos + offset;
2409
+ if (side > 0 ? end > offPos : end >= offPos)
2410
+ break;
2411
+ let start = this.ranges[++this.rangeIndex].from;
2412
+ offset += start - end;
2413
+ }
2414
+ return offset;
2415
+ }
2416
+ moveRangeIndex() {
2417
+ while (this.ranges[this.rangeIndex].to < this.parsedPos)
2418
+ this.rangeIndex++;
2419
+ }
2420
+ emitToken(id, from, to, offset) {
2421
+ let size = 4;
2422
+ if (this.ranges.length > 1) {
2423
+ offset = this.skipGapsTo(from, offset, 1);
2424
+ from += offset;
2425
+ let len0 = this.chunk.length;
2426
+ offset = this.skipGapsTo(to, offset, -1);
2427
+ to += offset;
2428
+ size += this.chunk.length - len0;
2429
+ }
2430
+ let last = this.chunk.length - 4;
2431
+ if (this.lang.streamParser.mergeTokens && size == 4 && last >= 0 &&
2432
+ this.chunk[last] == id && this.chunk[last + 2] == from)
2433
+ this.chunk[last + 2] = to;
2434
+ else
2435
+ this.chunk.push(id, from, to, size);
2436
+ return offset;
2437
+ }
2438
+ parseLine(context) {
2439
+ let { line, end } = this.nextLine(), offset = 0, { streamParser } = this.lang;
2440
+ let stream = new StringStream(line, context ? context.state.tabSize : 4, context ? getIndentUnit(context.state) : 2);
2441
+ if (stream.eol()) {
2442
+ streamParser.blankLine(this.state, stream.indentUnit);
2443
+ }
2444
+ else {
2445
+ while (!stream.eol()) {
2446
+ let token = readToken(streamParser.token, stream, this.state);
2447
+ if (token)
2448
+ offset = this.emitToken(this.lang.tokenTable.resolve(token), this.parsedPos + stream.start, this.parsedPos + stream.pos, offset);
2449
+ if (stream.start > 10000 /* C.MaxLineLength */)
2450
+ break;
2451
+ }
2452
+ }
2453
+ this.parsedPos = end;
2454
+ this.moveRangeIndex();
2455
+ if (this.parsedPos < this.to)
2456
+ this.parsedPos++;
2457
+ }
2458
+ finishChunk() {
2459
+ let tree = common.Tree.build({
2460
+ buffer: this.chunk,
2461
+ start: this.chunkStart,
2462
+ length: this.parsedPos - this.chunkStart,
2463
+ nodeSet,
2464
+ topID: 0,
2465
+ maxBufferLength: 512 /* C.ChunkSize */,
2466
+ reused: this.chunkReused
2467
+ });
2468
+ tree = new common.Tree(tree.type, tree.children, tree.positions, tree.length, [[this.lang.stateAfter, this.lang.streamParser.copyState(this.state)]]);
2469
+ this.chunks.push(tree);
2470
+ this.chunkPos.push(this.chunkStart - this.ranges[0].from);
2471
+ this.chunk = [];
2472
+ this.chunkReused = undefined;
2473
+ this.chunkStart = this.parsedPos;
2474
+ }
2475
+ finish() {
2476
+ return new common.Tree(this.lang.topNode, this.chunks, this.chunkPos, this.parsedPos - this.ranges[0].from).balance();
2477
+ }
2478
+ }
2479
+ function readToken(token, stream, state) {
2480
+ stream.start = stream.pos;
2481
+ for (let i = 0; i < 10; i++) {
2482
+ let result = token(stream, state);
2483
+ if (stream.pos > stream.start)
2484
+ return result;
2485
+ }
2486
+ throw new Error("Stream parser failed to advance stream.");
2487
+ }
2488
+ const noTokens = Object.create(null);
2489
+ const typeArray = [common.NodeType.none];
2490
+ const nodeSet = new common.NodeSet(typeArray);
2491
+ const warned = [];
2492
+ // Cache of node types by name and tags
2493
+ const byTag = Object.create(null);
2494
+ const defaultTable = Object.create(null);
2495
+ for (let [legacyName, name] of [
2496
+ ["variable", "variableName"],
2497
+ ["variable-2", "variableName.special"],
2498
+ ["string-2", "string.special"],
2499
+ ["def", "variableName.definition"],
2500
+ ["tag", "tagName"],
2501
+ ["attribute", "attributeName"],
2502
+ ["type", "typeName"],
2503
+ ["builtin", "variableName.standard"],
2504
+ ["qualifier", "modifier"],
2505
+ ["error", "invalid"],
2506
+ ["header", "heading"],
2507
+ ["property", "propertyName"]
2508
+ ])
2509
+ defaultTable[legacyName] = createTokenType(noTokens, name);
2510
+ class TokenTable {
2511
+ constructor(extra) {
2512
+ this.extra = extra;
2513
+ this.table = Object.assign(Object.create(null), defaultTable);
2514
+ }
2515
+ resolve(tag) {
2516
+ return !tag ? 0 : this.table[tag] || (this.table[tag] = createTokenType(this.extra, tag));
2517
+ }
2518
+ }
2519
+ const defaultTokenTable = new TokenTable(noTokens);
2520
+ function warnForPart(part, msg) {
2521
+ if (warned.indexOf(part) > -1)
2522
+ return;
2523
+ warned.push(part);
2524
+ console.warn(msg);
2525
+ }
2526
+ function createTokenType(extra, tagStr) {
2527
+ let tags = [];
2528
+ for (let name of tagStr.split(" ")) {
2529
+ let found = [];
2530
+ for (let part of name.split(".")) {
2531
+ let value = (extra[part] || highlight.tags[part]);
2532
+ if (!value) {
2533
+ warnForPart(part, `Unknown highlighting tag ${part}`);
2534
+ }
2535
+ else if (typeof value == "function") {
2536
+ if (!found.length)
2537
+ warnForPart(part, `Modifier ${part} used at start of tag`);
2538
+ else
2539
+ found = found.map(value);
2540
+ }
2541
+ else {
2542
+ if (found.length)
2543
+ warnForPart(part, `Tag ${part} used as modifier`);
2544
+ else
2545
+ found = Array.isArray(value) ? value : [value];
2546
+ }
2547
+ }
2548
+ for (let tag of found)
2549
+ tags.push(tag);
2550
+ }
2551
+ if (!tags.length)
2552
+ return 0;
2553
+ let name = tagStr.replace(/ /g, "_"), key = name + " " + tags.map(t => t.id);
2554
+ let known = byTag[key];
2555
+ if (known)
2556
+ return known.id;
2557
+ let type = byTag[key] = common.NodeType.define({
2558
+ id: typeArray.length,
2559
+ name,
2560
+ props: [highlight.styleTags({ [name]: tags })]
2561
+ });
2562
+ typeArray.push(type);
2563
+ return type.id;
2564
+ }
2565
+ function docID(data, lang) {
2566
+ let type = common.NodeType.define({ id: typeArray.length, name: "Document", props: [
2567
+ languageDataProp.add(() => data),
2568
+ indentNodeProp.add(() => cx => lang.getIndent(cx))
2569
+ ], top: true });
2570
+ typeArray.push(type);
2571
+ return type;
2572
+ }
2573
+
2574
+ function buildForLine(line) {
2575
+ return line.length <= 4096 && /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/.test(line);
2576
+ }
2577
+ function textHasRTL(text) {
2578
+ for (let i = text.iter(); !i.next().done;)
2579
+ if (buildForLine(i.value))
2580
+ return true;
2581
+ return false;
2582
+ }
2583
+ function changeAddsRTL(change) {
2584
+ let added = false;
2585
+ change.iterChanges((fA, tA, fB, tB, ins) => {
2586
+ if (!added && textHasRTL(ins))
2587
+ added = true;
2588
+ });
2589
+ return added;
2590
+ }
2591
+ const alwaysIsolate = state.Facet.define({ combine: values => values.some(x => x) });
2592
+ /**
2593
+ Make sure nodes
2594
+ [marked](https://lezer.codemirror.net/docs/ref/#common.NodeProp^isolate)
2595
+ as isolating for bidirectional text are rendered in a way that
2596
+ isolates them from the surrounding text.
2597
+ */
2598
+ function bidiIsolates(options = {}) {
2599
+ let extensions = [isolateMarks];
2600
+ if (options.alwaysIsolate)
2601
+ extensions.push(alwaysIsolate.of(true));
2602
+ return extensions;
2603
+ }
2604
+ const isolateMarks = view.ViewPlugin.fromClass(class {
2605
+ constructor(view$1) {
2606
+ this.always = view$1.state.facet(alwaysIsolate) ||
2607
+ view$1.textDirection != view.Direction.LTR ||
2608
+ view$1.state.facet(view.EditorView.perLineTextDirection);
2609
+ this.hasRTL = !this.always && textHasRTL(view$1.state.doc);
2610
+ this.tree = syntaxTree(view$1.state);
2611
+ this.decorations = this.always || this.hasRTL ? buildDeco(view$1, this.tree, this.always) : view.Decoration.none;
2612
+ }
2613
+ update(update) {
2614
+ let always = update.state.facet(alwaysIsolate) ||
2615
+ update.view.textDirection != view.Direction.LTR ||
2616
+ update.state.facet(view.EditorView.perLineTextDirection);
2617
+ if (!always && !this.hasRTL && changeAddsRTL(update.changes))
2618
+ this.hasRTL = true;
2619
+ if (!always && !this.hasRTL)
2620
+ return;
2621
+ let tree = syntaxTree(update.state);
2622
+ if (always != this.always || tree != this.tree || update.docChanged || update.viewportChanged) {
2623
+ this.tree = tree;
2624
+ this.always = always;
2625
+ this.decorations = buildDeco(update.view, tree, always);
2626
+ }
2627
+ }
2628
+ }, {
2629
+ provide: plugin => {
2630
+ function access(view$1) {
2631
+ var _a, _b;
2632
+ return (_b = (_a = view$1.plugin(plugin)) === null || _a === void 0 ? void 0 : _a.decorations) !== null && _b !== void 0 ? _b : view.Decoration.none;
2633
+ }
2634
+ return [view.EditorView.outerDecorations.of(access),
2635
+ state.Prec.lowest(view.EditorView.bidiIsolatedRanges.of(access))];
2636
+ }
2637
+ });
2638
+ function buildDeco(view, tree, always) {
2639
+ let deco = new state.RangeSetBuilder();
2640
+ let ranges = view.visibleRanges;
2641
+ if (!always)
2642
+ ranges = clipRTLLines(ranges, view.state.doc);
2643
+ for (let { from, to } of ranges) {
2644
+ tree.iterate({
2645
+ enter: node => {
2646
+ let iso = node.type.prop(common.NodeProp.isolate);
2647
+ if (iso)
2648
+ deco.add(node.from, node.to, marks[iso]);
2649
+ },
2650
+ from, to
2651
+ });
2652
+ }
2653
+ return deco.finish();
2654
+ }
2655
+ function clipRTLLines(ranges, doc) {
2656
+ let cur = doc.iter(), pos = 0, result = [], last = null;
2657
+ for (let { from, to } of ranges) {
2658
+ if (last && last.to > from) {
2659
+ from = last.to;
2660
+ if (from >= to)
2661
+ continue;
2662
+ }
2663
+ if (pos + cur.value.length < from) {
2664
+ cur.next(from - (pos + cur.value.length));
2665
+ pos = from;
2666
+ }
2667
+ for (;;) {
2668
+ let start = pos, end = pos + cur.value.length;
2669
+ if (!cur.lineBreak && buildForLine(cur.value)) {
2670
+ if (last && last.to > start - 10)
2671
+ last.to = Math.min(to, end);
2672
+ else
2673
+ result.push(last = { from: start, to: Math.min(to, end) });
2674
+ }
2675
+ if (end >= to)
2676
+ break;
2677
+ pos = end;
2678
+ cur.next();
2679
+ }
2680
+ }
2681
+ return result;
2682
+ }
2683
+ const marks = {
2684
+ rtl: view.Decoration.mark({ class: "cm-iso", inclusive: true, attributes: { dir: "rtl" }, bidiIsolate: view.Direction.RTL }),
2685
+ ltr: view.Decoration.mark({ class: "cm-iso", inclusive: true, attributes: { dir: "ltr" }, bidiIsolate: view.Direction.LTR }),
2686
+ auto: view.Decoration.mark({ class: "cm-iso", inclusive: true, attributes: { dir: "auto" }, bidiIsolate: null })
2687
+ };
2688
+
2689
+ exports.DocInput = DocInput;
2690
+ exports.HighlightStyle = HighlightStyle;
2691
+ exports.IndentContext = IndentContext;
2692
+ exports.LRLanguage = LRLanguage;
2693
+ exports.Language = Language;
2694
+ exports.LanguageDescription = LanguageDescription;
2695
+ exports.LanguageSupport = LanguageSupport;
2696
+ exports.ParseContext = ParseContext;
2697
+ exports.StreamLanguage = StreamLanguage;
2698
+ exports.StringStream = StringStream;
2699
+ exports.TreeIndentContext = TreeIndentContext;
2700
+ exports.bidiIsolates = bidiIsolates;
2701
+ exports.bracketMatching = bracketMatching;
2702
+ exports.bracketMatchingHandle = bracketMatchingHandle;
2703
+ exports.codeFolding = codeFolding;
2704
+ exports.continuedIndent = continuedIndent;
2705
+ exports.defaultHighlightStyle = defaultHighlightStyle;
2706
+ exports.defineLanguageFacet = defineLanguageFacet;
2707
+ exports.delimitedIndent = delimitedIndent;
2708
+ exports.ensureSyntaxTree = ensureSyntaxTree;
2709
+ exports.flatIndent = flatIndent;
2710
+ exports.foldAll = foldAll;
2711
+ exports.foldCode = foldCode;
2712
+ exports.foldEffect = foldEffect;
2713
+ exports.foldGutter = foldGutter;
2714
+ exports.foldInside = foldInside;
2715
+ exports.foldKeymap = foldKeymap;
2716
+ exports.foldNodeProp = foldNodeProp;
2717
+ exports.foldService = foldService;
2718
+ exports.foldState = foldState;
2719
+ exports.foldable = foldable;
2720
+ exports.foldedRanges = foldedRanges;
2721
+ exports.forceParsing = forceParsing;
2722
+ exports.getIndentUnit = getIndentUnit;
2723
+ exports.getIndentation = getIndentation;
2724
+ exports.highlightingFor = highlightingFor;
2725
+ exports.indentNodeProp = indentNodeProp;
2726
+ exports.indentOnInput = indentOnInput;
2727
+ exports.indentRange = indentRange;
2728
+ exports.indentService = indentService;
2729
+ exports.indentString = indentString;
2730
+ exports.indentUnit = indentUnit;
2731
+ exports.language = language;
2732
+ exports.languageDataProp = languageDataProp;
2733
+ exports.matchBrackets = matchBrackets;
2734
+ exports.sublanguageProp = sublanguageProp;
2735
+ exports.syntaxHighlighting = syntaxHighlighting;
2736
+ exports.syntaxParserRunning = syntaxParserRunning;
2737
+ exports.syntaxTree = syntaxTree;
2738
+ exports.syntaxTreeAvailable = syntaxTreeAvailable;
2739
+ exports.toggleFold = toggleFold;
2740
+ exports.unfoldAll = unfoldAll;
2741
+ exports.unfoldCode = unfoldCode;
2742
+ exports.unfoldEffect = unfoldEffect;