diff --git a/compose.yaml b/compose.yaml index 781b011..2e4930f 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,7 +1,7 @@ # basex lsp, use with services: basex: - image: ghcr.io/quodatum/basexhttp:basex-12.2 + image: ghcr.io/quodatum/basexhttp:basex-12.1 container_name: basex-lsp restart: unless-stopped ports: @@ -13,7 +13,7 @@ services: - ./webapp/custom:/srv/basex/lib/custom:ro # jars - ./webapp/lsp:/srv/basex/webapp/lsp - ./webapp/static/clients:/srv/basex/webapp/static/clients:ro - - webawesome-3.1.0:/srv/basex/webapp/static/webawesome:ro + - webawesome:/srv/basex/webapp/static/webawesome:ro - ./webapp/lsp-manager:/srv/basex/webapp/lsp-manager # - ./repo:/srv/basex/repo environment: @@ -22,5 +22,6 @@ services: volumes: basex-lsp: - webawesome-3.1.0: # - external: true + webawesome: + external: true + name: webawesome-3.2.1 diff --git a/package-lock.json b/package-lock.json index 7e9eb30..36b07ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,7 @@ "packages": { "": { "dependencies": { - "@awesome.me/webawesome": "^3.0.0", + "@awesome.me/webawesome": "^3.2.1", "@codemirror/commands": "^6.10.0", "@codemirror/lang-javascript": "^6.2.4", "@codemirror/lang-markdown": "^6.5.0", @@ -33,9 +33,9 @@ } }, "node_modules/@awesome.me/webawesome": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@awesome.me/webawesome/-/webawesome-3.1.0.tgz", - "integrity": "sha512-9XgTxL/6/8Ynb4KvQBjK33RjnsRyqIJO8zYQODu8MDbS/2ecjah+cUOek6DkK0opg1DC6N7X6GStjcrjAuMMyQ==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@awesome.me/webawesome/-/webawesome-3.2.1.tgz", + "integrity": "sha512-D/cZlPC97Ni0K5IgE+l7UKDBlthRCWIyz42voxpZrl/the+A3dAJtUKG6sr1GDDp6v2JEh4iFsyFDpZH8kuVOQ==", "license": "MIT", "dependencies": { "@ctrl/tinycolor": "4.1.0", @@ -53,14 +53,14 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz", - "integrity": "sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==", + "version": "7.29.0", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.0.tgz", + "integrity": "sha512-9NhCeYjq9+3uxgdtp20LSiJXJvN0FeCtNGpJxuMFZ1Kv3cWUNb6DOhJwUvcVCzKGR66cw4njwM6hrJLqgOwbcw==", "dev": true, "license": "MIT", "optional": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.27.1", + "@babel/helper-validator-identifier": "^7.28.5", "js-tokens": "^4.0.0", "picocolors": "^1.1.1" }, @@ -115,9 +115,9 @@ } }, "node_modules/@codemirror/commands": { - "version": "6.10.1", - "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.10.1.tgz", - "integrity": "sha512-uWDWFypNdQmz2y1LaNJzK7fL7TYKLeUAU0npEC685OKTF3KcQ2Vu3klIM78D7I6wGhktme0lh3CuQLv0ZCrD9Q==", + "version": "6.10.2", + "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.10.2.tgz", + "integrity": "sha512-vvX1fsih9HledO1c9zdotZYUZnE4xV0m6i3m25s5DIfXofuprk6cRcLUZvSk3CASUbwjQX21tOGbkY2BH8TpnQ==", "license": "MIT", "dependencies": { "@codemirror/language": "^6.0.0", @@ -458,9 +458,9 @@ } }, "node_modules/@codemirror/lint": { - "version": "6.9.2", - "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.9.2.tgz", - "integrity": "sha512-sv3DylBiIyi+xKwRCJAAsBZZZWo82shJ/RTMymLabAdtbkV5cSKwWDeCgtUq3v8flTaXS2y1kKkICuRYtUswyQ==", + "version": "6.9.4", + "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.9.4.tgz", + "integrity": "sha512-ABc9vJ8DEmvOWuH26P3i8FpMWPQkduD9Rvba5iwb6O3hxASgclm3T3krGo8NASXkHCidz6b++LWlzWIUfEPSWw==", "license": "MIT", "dependencies": { "@codemirror/state": "^6.0.0", @@ -485,20 +485,20 @@ } }, "node_modules/@codemirror/search": { - "version": "6.5.11", - "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.5.11.tgz", - "integrity": "sha512-KmWepDE6jUdL6n8cAAqIpRmLPBZ5ZKnicE8oGU/s3QrAVID+0VhLFrzUucVKHG5035/BSykhExDL/Xm7dHthiA==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.6.0.tgz", + "integrity": "sha512-koFuNXcDvyyotWcgOnZGmY7LZqEOXZaaxD/j6n18TCLx2/9HieZJ5H6hs1g8FiRxBD0DNfs0nXn17g872RmYdw==", "license": "MIT", "dependencies": { "@codemirror/state": "^6.0.0", - "@codemirror/view": "^6.0.0", + "@codemirror/view": "^6.37.0", "crelt": "^1.0.5" } }, "node_modules/@codemirror/state": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.3.tgz", - "integrity": "sha512-MerMzJzlXogk2fxWFU1nKp36bY5orBG59HnPiz0G9nLRebWa0zXuv2siH6PLIHBvv5TH8CkQRqjBs0MlxCZu+A==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.4.tgz", + "integrity": "sha512-8y7xqG/hpB53l25CIoit9/ngxdfoG+fx+V3SHBrinnhOtLvKHRyAJJuHzkWrR4YXXLX8eXBsejgAAxHUOdW1yw==", "license": "MIT", "dependencies": { "@marijn/find-cluster-break": "^1.0.0" @@ -517,9 +517,9 @@ } }, "node_modules/@codemirror/view": { - "version": "6.39.8", - "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.39.8.tgz", - "integrity": "sha512-1rASYd9Z/mE3tkbC9wInRlCNyCkSn+nLsiQKZhEDUUJiUfs/5FHDpCUDaQpoTIaNGeDc6/bhaEAyLmeEucEFPw==", + "version": "6.39.14", + "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.39.14.tgz", + "integrity": "sha512-WJcvgHm/6Q7dvGT0YFv/6PSkoc36QlR0VCESS6x9tGsnF1lWLmmYxOgX3HH6v8fo6AvSLgpcs+H0Olre6MKXlg==", "license": "MIT", "dependencies": { "@codemirror/state": "^6.5.0", @@ -538,21 +538,21 @@ } }, "node_modules/@floating-ui/core": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.7.3.tgz", - "integrity": "sha512-sGnvb5dmrJaKEZ+LDIpguvdX3bDlEllmv4/ClQ9awcmCZrlx5jQyyMWFM5kBI+EyNOCDDiKk8il0zeuX3Zlg/w==", + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.7.4.tgz", + "integrity": "sha512-C3HlIdsBxszvm5McXlB8PeOEWfBhcGBTZGkGlWc2U0KFY5IwG5OQEuQ8rq52DZmcHDlPLd+YFBK+cZcytwIFWg==", "license": "MIT", "dependencies": { "@floating-ui/utils": "^0.2.10" } }, "node_modules/@floating-ui/dom": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.7.4.tgz", - "integrity": "sha512-OOchDgh4F2CchOX94cRVqhvy7b3AFb+/rQXyswmzmGakRfkMgoWVjfnLWkRirfLEfuD4ysVW16eXzwt3jHIzKA==", + "version": "1.7.5", + "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.7.5.tgz", + "integrity": "sha512-N0bD2kIPInNHUHehXhMke1rBGs1dwqvC9O9KYMyyjK7iXt7GAhnro7UlcuYcGdS/yYOlq0MAVgrow8IbWJwyqg==", "license": "MIT", "dependencies": { - "@floating-ui/core": "^1.7.3", + "@floating-ui/core": "^1.7.4", "@floating-ui/utils": "^0.2.10" } }, @@ -613,15 +613,15 @@ } }, "node_modules/@lezer/common": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.0.tgz", - "integrity": "sha512-PNGcolp9hr4PJdXR4ix7XtixDrClScvtSCYW3rQG106oVMOOI+jFb+0+J3mbeL/53g1Zd6s0kJzaw6Ri68GmAA==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.1.tgz", + "integrity": "sha512-6YRVG9vBkaY7p1IVxL4s44n5nUnaNnGM2/AckNgYOnxTG2kWh1vR8BMxPseWPjRNpb5VtXnMpeYAEAADoRV1Iw==", "license": "MIT" }, "node_modules/@lezer/cpp": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@lezer/cpp/-/cpp-1.1.4.tgz", - "integrity": "sha512-aYSdZyUueeTgnfXQntiGUqKNW5WujlAsIbbHzkfJDneSZoyjPg8ObmWG3bzDPVYMC/Kf4l43WJLCunPnYFfQ0g==", + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@lezer/cpp/-/cpp-1.1.5.tgz", + "integrity": "sha512-DIhSXmYtJKLehrjzDFN+2cPt547ySQ41nA8yqcDf/GxMc+YM736xqltFkvADL2M0VebU5I+3+4ks2Vv+Kyq3Aw==", "license": "MIT", "dependencies": { "@lezer/common": "^1.2.0", @@ -719,18 +719,18 @@ } }, "node_modules/@lezer/lr": { - "version": "1.4.5", - "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.5.tgz", - "integrity": "sha512-/YTRKP5yPPSo1xImYQk7AZZMAgap0kegzqCSYHjAL9x1AZ0ZQW+IpcEzMKagCsbTsLnVeWkxYrCNeXG8xEPrjg==", + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.8.tgz", + "integrity": "sha512-bPWa0Pgx69ylNlMlPvBPryqeLYQjyJjqPx+Aupm5zydLIF3NE+6MMLT8Yi23Bd9cif9VS00aUebn+6fDIGBcDA==", "license": "MIT", "dependencies": { "@lezer/common": "^1.0.0" } }, "node_modules/@lezer/markdown": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-1.6.2.tgz", - "integrity": "sha512-iNSdKrIK0FfOjVPVpV0fu7OykdncYpEzf4vkG9szFf60ql/ObZShoVbM9u1tgkogDOmubms1CyoNS2/unOXWNw==", + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-1.6.3.tgz", + "integrity": "sha512-jpGm5Ps+XErS+xA4urw7ogEGkeZOahVQF21Z6oECF0sj+2liwZopd2+I8uH5I/vZsRuuze3OxBREIANLf6KKUw==", "license": "MIT", "dependencies": { "@lezer/common": "^1.5.0", @@ -793,9 +793,9 @@ } }, "node_modules/@lezer/yaml": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@lezer/yaml/-/yaml-1.0.3.tgz", - "integrity": "sha512-GuBLekbw9jDBDhGur82nuwkxKQ+a3W5H0GfaAthDXcAu+XdpS43VlnxA9E9hllkpSP5ellRDKjLLj7Lu9Wr6xA==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@lezer/yaml/-/yaml-1.0.4.tgz", + "integrity": "sha512-2lrrHqxalACEbxIbsjhqGpSW8kWpUKuY6RHgnSAFZa6qK62wvnPxA8hGOwOoDbwHcOFs5M4o27mjGu+P7TvBmw==", "license": "MIT", "dependencies": { "@lezer/common": "^1.2.0", @@ -804,9 +804,9 @@ } }, "node_modules/@lit-labs/ssr-dom-shim": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.5.0.tgz", - "integrity": "sha512-HLomZXMmrCFHSRKESF5vklAKsDY7/fsT/ZhqCu3V0UoW/Qbv8wxmO4W9bx4KnCCF2Zak4yuk+AGraK/bPmI4kA==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.5.1.tgz", + "integrity": "sha512-Aou5UdlSpr5whQe8AA/bZG0jMj96CoJIWbGfZ91qieWu5AWUMKw8VR/pAkQkJYvBNhmCcWnZlyyk5oze8JIqYA==", "license": "BSD-3-Clause" }, "node_modules/@lit/react": { @@ -958,9 +958,9 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.54.0.tgz", - "integrity": "sha512-OywsdRHrFvCdvsewAInDKCNyR3laPA2mc9bRYJ6LBp5IyvF3fvXbbNR0bSzHlZVFtn6E0xw2oZlyjg4rKCVcng==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.57.1.tgz", + "integrity": "sha512-A6ehUVSiSaaliTxai040ZpZ2zTevHYbvu/lDoeAteHI8QnaosIzm4qwtezfRg1jOYaUmnzLX1AOD6Z+UJjtifg==", "cpu": [ "arm" ], @@ -972,9 +972,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.54.0.tgz", - "integrity": "sha512-Skx39Uv+u7H224Af+bDgNinitlmHyQX1K/atIA32JP3JQw6hVODX5tkbi2zof/E69M1qH2UoN3Xdxgs90mmNYw==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.57.1.tgz", + "integrity": "sha512-dQaAddCY9YgkFHZcFNS/606Exo8vcLHwArFZ7vxXq4rigo2bb494/xKMMwRRQW6ug7Js6yXmBZhSBRuBvCCQ3w==", "cpu": [ "arm64" ], @@ -986,9 +986,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.54.0.tgz", - "integrity": "sha512-k43D4qta/+6Fq+nCDhhv9yP2HdeKeP56QrUUTW7E6PhZP1US6NDqpJj4MY0jBHlJivVJD5P8NxrjuobZBJTCRw==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.57.1.tgz", + "integrity": "sha512-crNPrwJOrRxagUYeMn/DZwqN88SDmwaJ8Cvi/TN1HnWBU7GwknckyosC2gd0IqYRsHDEnXf328o9/HC6OkPgOg==", "cpu": [ "arm64" ], @@ -1000,9 +1000,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.54.0.tgz", - "integrity": "sha512-cOo7biqwkpawslEfox5Vs8/qj83M/aZCSSNIWpVzfU2CYHa2G3P1UN5WF01RdTHSgCkri7XOlTdtk17BezlV3A==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.57.1.tgz", + "integrity": "sha512-Ji8g8ChVbKrhFtig5QBV7iMaJrGtpHelkB3lsaKzadFBe58gmjfGXAOfI5FV0lYMH8wiqsxKQ1C9B0YTRXVy4w==", "cpu": [ "x64" ], @@ -1014,9 +1014,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-arm64": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.54.0.tgz", - "integrity": "sha512-miSvuFkmvFbgJ1BevMa4CPCFt5MPGw094knM64W9I0giUIMMmRYcGW/JWZDriaw/k1kOBtsWh1z6nIFV1vPNtA==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.57.1.tgz", + "integrity": "sha512-R+/WwhsjmwodAcz65guCGFRkMb4gKWTcIeLy60JJQbXrJ97BOXHxnkPFrP+YwFlaS0m+uWJTstrUA9o+UchFug==", "cpu": [ "arm64" ], @@ -1028,9 +1028,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-x64": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.54.0.tgz", - "integrity": "sha512-KGXIs55+b/ZfZsq9aR026tmr/+7tq6VG6MsnrvF4H8VhwflTIuYh+LFUlIsRdQSgrgmtM3fVATzEAj4hBQlaqQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.57.1.tgz", + "integrity": "sha512-IEQTCHeiTOnAUC3IDQdzRAGj3jOAYNr9kBguI7MQAAZK3caezRrg0GxAb6Hchg4lxdZEI5Oq3iov/w/hnFWY9Q==", "cpu": [ "x64" ], @@ -1042,9 +1042,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.54.0.tgz", - "integrity": "sha512-EHMUcDwhtdRGlXZsGSIuXSYwD5kOT9NVnx9sqzYiwAc91wfYOE1g1djOEDseZJKKqtHAHGwnGPQu3kytmfaXLQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.57.1.tgz", + "integrity": "sha512-F8sWbhZ7tyuEfsmOxwc2giKDQzN3+kuBLPwwZGyVkLlKGdV1nvnNwYD0fKQ8+XS6hp9nY7B+ZeK01EBUE7aHaw==", "cpu": [ "arm" ], @@ -1056,9 +1056,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.54.0.tgz", - "integrity": "sha512-+pBrqEjaakN2ySv5RVrj/qLytYhPKEUwk+e3SFU5jTLHIcAtqh2rLrd/OkbNuHJpsBgxsD8ccJt5ga/SeG0JmA==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.57.1.tgz", + "integrity": "sha512-rGfNUfn0GIeXtBP1wL5MnzSj98+PZe/AXaGBCRmT0ts80lU5CATYGxXukeTX39XBKsxzFpEeK+Mrp9faXOlmrw==", "cpu": [ "arm" ], @@ -1070,9 +1070,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.54.0.tgz", - "integrity": "sha512-NSqc7rE9wuUaRBsBp5ckQ5CVz5aIRKCwsoa6WMF7G01sX3/qHUw/z4pv+D+ahL1EIKy6Enpcnz1RY8pf7bjwng==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.57.1.tgz", + "integrity": "sha512-MMtej3YHWeg/0klK2Qodf3yrNzz6CGjo2UntLvk2RSPlhzgLvYEB3frRvbEF2wRKh1Z2fDIg9KRPe1fawv7C+g==", "cpu": [ "arm64" ], @@ -1084,9 +1084,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.54.0.tgz", - "integrity": "sha512-gr5vDbg3Bakga5kbdpqx81m2n9IX8M6gIMlQQIXiLTNeQW6CucvuInJ91EuCJ/JYvc+rcLLsDFcfAD1K7fMofg==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.57.1.tgz", + "integrity": "sha512-1a/qhaaOXhqXGpMFMET9VqwZakkljWHLmZOX48R0I/YLbhdxr1m4gtG1Hq7++VhVUmf+L3sTAf9op4JlhQ5u1Q==", "cpu": [ "arm64" ], @@ -1098,9 +1098,23 @@ ] }, "node_modules/@rollup/rollup-linux-loong64-gnu": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.54.0.tgz", - "integrity": "sha512-gsrtB1NA3ZYj2vq0Rzkylo9ylCtW/PhpLEivlgWe0bpgtX5+9j9EZa0wtZiCjgu6zmSeZWyI/e2YRX1URozpIw==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.57.1.tgz", + "integrity": "sha512-QWO6RQTZ/cqYtJMtxhkRkidoNGXc7ERPbZN7dVW5SdURuLeVU7lwKMpo18XdcmpWYd0qsP1bwKPf7DNSUinhvA==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-musl": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.57.1.tgz", + "integrity": "sha512-xpObYIf+8gprgWaPP32xiN5RVTi/s5FCR+XMXSKmhfoJjrpRAjCuuqQXyxUa/eJTdAE6eJ+KDKaoEqjZQxh3Gw==", "cpu": [ "loong64" ], @@ -1112,9 +1126,23 @@ ] }, "node_modules/@rollup/rollup-linux-ppc64-gnu": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.54.0.tgz", - "integrity": "sha512-y3qNOfTBStmFNq+t4s7Tmc9hW2ENtPg8FeUD/VShI7rKxNW7O4fFeaYbMsd3tpFlIg1Q8IapFgy7Q9i2BqeBvA==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.57.1.tgz", + "integrity": "sha512-4BrCgrpZo4hvzMDKRqEaW1zeecScDCR+2nZ86ATLhAoJ5FQ+lbHVD3ttKe74/c7tNT9c6F2viwB3ufwp01Oh2w==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-musl": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.57.1.tgz", + "integrity": "sha512-NOlUuzesGauESAyEYFSe3QTUguL+lvrN1HtwEEsU2rOwdUDeTMJdO5dUYl/2hKf9jWydJrO9OL/XSSf65R5+Xw==", "cpu": [ "ppc64" ], @@ -1126,9 +1154,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.54.0.tgz", - "integrity": "sha512-89sepv7h2lIVPsFma8iwmccN7Yjjtgz0Rj/Ou6fEqg3HDhpCa+Et+YSufy27i6b0Wav69Qv4WBNl3Rs6pwhebQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.57.1.tgz", + "integrity": "sha512-ptA88htVp0AwUUqhVghwDIKlvJMD/fmL/wrQj99PRHFRAG6Z5nbWoWG4o81Nt9FT+IuqUQi+L31ZKAFeJ5Is+A==", "cpu": [ "riscv64" ], @@ -1140,9 +1168,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-musl": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.54.0.tgz", - "integrity": "sha512-ZcU77ieh0M2Q8Ur7D5X7KvK+UxbXeDHwiOt/CPSBTI1fBmeDMivW0dPkdqkT4rOgDjrDDBUed9x4EgraIKoR2A==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.57.1.tgz", + "integrity": "sha512-S51t7aMMTNdmAMPpBg7OOsTdn4tySRQvklmL3RpDRyknk87+Sp3xaumlatU+ppQ+5raY7sSTcC2beGgvhENfuw==", "cpu": [ "riscv64" ], @@ -1154,9 +1182,9 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.54.0.tgz", - "integrity": "sha512-2AdWy5RdDF5+4YfG/YesGDDtbyJlC9LHmL6rZw6FurBJ5n4vFGupsOBGfwMRjBYH7qRQowT8D/U4LoSvVwOhSQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.57.1.tgz", + "integrity": "sha512-Bl00OFnVFkL82FHbEqy3k5CUCKH6OEJL54KCyx2oqsmZnFTR8IoNqBF+mjQVcRCT5sB6yOvK8A37LNm/kPJiZg==", "cpu": [ "s390x" ], @@ -1168,9 +1196,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.54.0.tgz", - "integrity": "sha512-WGt5J8Ij/rvyqpFexxk3ffKqqbLf9AqrTBbWDk7ApGUzaIs6V+s2s84kAxklFwmMF/vBNGrVdYgbblCOFFezMQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.57.1.tgz", + "integrity": "sha512-ABca4ceT4N+Tv/GtotnWAeXZUZuM/9AQyCyKYyKnpk4yoA7QIAuBt6Hkgpw8kActYlew2mvckXkvx0FfoInnLg==", "cpu": [ "x64" ], @@ -1182,9 +1210,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.54.0.tgz", - "integrity": "sha512-JzQmb38ATzHjxlPHuTH6tE7ojnMKM2kYNzt44LO/jJi8BpceEC8QuXYA908n8r3CNuG/B3BV8VR3Hi1rYtmPiw==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.57.1.tgz", + "integrity": "sha512-HFps0JeGtuOR2convgRRkHCekD7j+gdAuXM+/i6kGzQtFhlCtQkpwtNzkNj6QhCDp7DRJ7+qC/1Vg2jt5iSOFw==", "cpu": [ "x64" ], @@ -1195,10 +1223,24 @@ "linux" ] }, + "node_modules/@rollup/rollup-openbsd-x64": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.57.1.tgz", + "integrity": "sha512-H+hXEv9gdVQuDTgnqD+SQffoWoc0Of59AStSzTEj/feWTBAnSfSD3+Dql1ZruJQxmykT/JVY0dE8Ka7z0DH1hw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ] + }, "node_modules/@rollup/rollup-openharmony-arm64": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.54.0.tgz", - "integrity": "sha512-huT3fd0iC7jigGh7n3q/+lfPcXxBi+om/Rs3yiFxjvSxbSB6aohDFXbWvlspaqjeOh+hx7DDHS+5Es5qRkWkZg==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.57.1.tgz", + "integrity": "sha512-4wYoDpNg6o/oPximyc/NG+mYUejZrCU2q+2w6YZqrAs2UcNUChIZXjtafAiiZSUc7On8v5NyNj34Kzj/Ltk6dQ==", "cpu": [ "arm64" ], @@ -1210,9 +1252,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.54.0.tgz", - "integrity": "sha512-c2V0W1bsKIKfbLMBu/WGBz6Yci8nJ/ZJdheE0EwB73N3MvHYKiKGs3mVilX4Gs70eGeDaMqEob25Tw2Gb9Nqyw==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.57.1.tgz", + "integrity": "sha512-O54mtsV/6LW3P8qdTcamQmuC990HDfR71lo44oZMZlXU4tzLrbvTii87Ni9opq60ds0YzuAlEr/GNwuNluZyMQ==", "cpu": [ "arm64" ], @@ -1224,9 +1266,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.54.0.tgz", - "integrity": "sha512-woEHgqQqDCkAzrDhvDipnSirm5vxUXtSKDYTVpZG3nUdW/VVB5VdCYA2iReSj/u3yCZzXID4kuKG7OynPnB3WQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.57.1.tgz", + "integrity": "sha512-P3dLS+IerxCT/7D2q2FYcRdWRl22dNbrbBEtxdWhXrfIMPP9lQhb5h4Du04mdl5Woq05jVCDPCMF7Ub0NAjIew==", "cpu": [ "ia32" ], @@ -1238,9 +1280,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-gnu": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.54.0.tgz", - "integrity": "sha512-dzAc53LOuFvHwbCEOS0rPbXp6SIhAf2txMP5p6mGyOXXw5mWY8NGGbPMPrs4P1WItkfApDathBj/NzMLUZ9rtQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.57.1.tgz", + "integrity": "sha512-VMBH2eOOaKGtIJYleXsi2B8CPVADrh+TyNxJ4mWPnKfLB/DBUmzW+5m1xUrcwWoMfSLagIRpjUFeW5CO5hyciQ==", "cpu": [ "x64" ], @@ -1252,9 +1294,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.54.0.tgz", - "integrity": "sha512-hYT5d3YNdSh3mbCU1gwQyPgQd3T2ne0A3KG8KSBdav5TiBg6eInVmV+TeR5uHufiIgSFg0XsOWGW5/RhNcSvPg==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.57.1.tgz", + "integrity": "sha512-mxRFDdHIWRxg3UfIIAwCm6NzvxG0jDX/wBN6KsQFTvKFqqg9vTrWUE68qEjHt19A5wwx5X5aUi2zuZT7YR0jrA==", "cpu": [ "x64" ], @@ -1296,18 +1338,18 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "24.10.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.4.tgz", - "integrity": "sha512-vnDVpYPMzs4wunl27jHrfmwojOGKya0xyM3sH+UE5iv5uPS6vX7UIoh6m+vQc5LGBq52HBKPIn/zcSZVzeDEZg==", + "version": "24.10.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.13.tgz", + "integrity": "sha512-oH72nZRfDv9lADUBSo104Aq7gPHpQZc4BTx38r9xf9pg5LfP6EzSyH2n7qFmmxRQXh7YlUXODcYsg6PuTDSxGg==", "license": "MIT", "dependencies": { "undici-types": "~7.16.0" } }, "node_modules/@types/react": { - "version": "19.2.7", - "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.7.tgz", - "integrity": "sha512-MWtvHrGZLFttgeEj28VXHxpmwYbor/ATPYbBfSFZEIRK0ecCFLl2Qo55z52Hss+UV9CRN7trSeq1zbgx7YDWWg==", + "version": "19.2.14", + "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.14.tgz", + "integrity": "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w==", "license": "MIT", "peer": true, "dependencies": { @@ -1335,9 +1377,9 @@ "optional": true }, "node_modules/@zenfs/core": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/@zenfs/core/-/core-2.4.4.tgz", - "integrity": "sha512-4ove99nTRyS3WPNlHN6i0AxMMYW85YBo2lVS/aNXU48dYOl78XiM98d4uly/9PwtllGJHEv9GHkomxS2eoOLFw==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@zenfs/core/-/core-2.5.0.tgz", + "integrity": "sha512-8yiSZLnFRJz9gfsBC+U1lvbeJprHJJNWSGNnadO+0AyYhW68owhNdoxVkTrP1ugbTDVvbUGiT3iWSBHDd93VZQ==", "license": "LGPL-3.0-or-later", "dependencies": { "@types/node": "^24.1.0", @@ -1362,9 +1404,9 @@ } }, "node_modules/@zenfs/dom": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/@zenfs/dom/-/dom-1.2.6.tgz", - "integrity": "sha512-gIoYg/kBi8N+3OAQt9MFXPJrwhYvPzLjJdy+3Ln9csofY0Wgt+PENrj5/9pODyBdX1+Ug+KKEcPTEmmGkd7/ww==", + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@zenfs/dom/-/dom-1.2.7.tgz", + "integrity": "sha512-f0V512ROaUf44fKItRvZV3DQLMwo4jnQoprWGyasDSwn2oDG1TPkJ+vak3iuhqZgWD/wTWmXbpv3KE/yKDBGiA==", "license": "LGPL-3.0-or-later", "engines": { "node": ">= 22" @@ -1392,15 +1434,15 @@ } }, "node_modules/ace-builds": { - "version": "1.43.5", - "resolved": "https://registry.npmjs.org/ace-builds/-/ace-builds-1.43.5.tgz", - "integrity": "sha512-iH5FLBKdB7SVn9GR37UgA/tpQS8OTWIxWAuq3Ofaw+Qbc69FfPXsXd9jeW7KRG2xKpKMqBDnu0tHBrCWY5QI7A==", + "version": "1.43.6", + "resolved": "https://registry.npmjs.org/ace-builds/-/ace-builds-1.43.6.tgz", + "integrity": "sha512-L1ddibQ7F3vyXR2k2fg+I8TQTPWVA6CKeDQr/h2+8CeyTp3W6EQL8xNFZRTztuP8xNOAqL3IYPqdzs31GCjDvg==", "license": "BSD-3-Clause" }, "node_modules/ace-linters": { - "version": "1.8.7", - "resolved": "https://registry.npmjs.org/ace-linters/-/ace-linters-1.8.7.tgz", - "integrity": "sha512-wpNvjCirOo+XoCQur01a8e0EBp4lKO5Rt0OCpx6UAsBTpbq+ePOmFJPbNdkZmrbAt0k4OMTX+Ny9dYXQ0AYlTg==", + "version": "1.8.8", + "resolved": "https://registry.npmjs.org/ace-linters/-/ace-linters-1.8.8.tgz", + "integrity": "sha512-B+5C7RoEyNocO4czi3EBgsx4UPQLaGG3tXD5GvC16+KLVHjoeMIE3k72aE87KmB5L5W4m7YZkoGtjCWjoI270w==", "license": "MIT", "dependencies": { "vscode-languageserver-protocol": "^3.17.5", @@ -1843,9 +1885,9 @@ } }, "node_modules/diff": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", - "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.2.tgz", + "integrity": "sha512-vtcDfH3TOjP8UekytvnHH1o1P4FcUdt4eQ1Y+Abap1tk/OB2MWQvcwS2ClCd1zuIhc3JKOx6p3kod8Vfys3E+A==", "dev": true, "license": "BSD-3-Clause", "engines": { @@ -1973,9 +2015,9 @@ } }, "node_modules/eventemitter3": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", - "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.4.tgz", + "integrity": "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw==", "license": "MIT" }, "node_modules/events": { @@ -2083,7 +2125,7 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", - "deprecated": "Glob versions prior to v9 are no longer supported", + "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me", "dev": true, "license": "ISC", "dependencies": { @@ -3051,9 +3093,9 @@ } }, "node_modules/rollup": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.54.0.tgz", - "integrity": "sha512-3nk8Y3a9Ea8szgKhinMlGMhGMw89mqule3KWczxhIzqudyHdCIOHw8WJlj/r329fACjKLEh13ZSk7oE22kyeIw==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.57.1.tgz", + "integrity": "sha512-oQL6lgK3e2QZeQ7gcgIkS2YZPg5slw37hYufJ3edKlfQSGGm8ICoxswK15ntSzF/a8+h7ekRy7k7oWc3BQ7y8A==", "dev": true, "license": "MIT", "dependencies": { @@ -3067,28 +3109,31 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.54.0", - "@rollup/rollup-android-arm64": "4.54.0", - "@rollup/rollup-darwin-arm64": "4.54.0", - "@rollup/rollup-darwin-x64": "4.54.0", - "@rollup/rollup-freebsd-arm64": "4.54.0", - "@rollup/rollup-freebsd-x64": "4.54.0", - "@rollup/rollup-linux-arm-gnueabihf": "4.54.0", - "@rollup/rollup-linux-arm-musleabihf": "4.54.0", - "@rollup/rollup-linux-arm64-gnu": "4.54.0", - "@rollup/rollup-linux-arm64-musl": "4.54.0", - "@rollup/rollup-linux-loong64-gnu": "4.54.0", - "@rollup/rollup-linux-ppc64-gnu": "4.54.0", - "@rollup/rollup-linux-riscv64-gnu": "4.54.0", - "@rollup/rollup-linux-riscv64-musl": "4.54.0", - "@rollup/rollup-linux-s390x-gnu": "4.54.0", - "@rollup/rollup-linux-x64-gnu": "4.54.0", - "@rollup/rollup-linux-x64-musl": "4.54.0", - "@rollup/rollup-openharmony-arm64": "4.54.0", - "@rollup/rollup-win32-arm64-msvc": "4.54.0", - "@rollup/rollup-win32-ia32-msvc": "4.54.0", - "@rollup/rollup-win32-x64-gnu": "4.54.0", - "@rollup/rollup-win32-x64-msvc": "4.54.0", + "@rollup/rollup-android-arm-eabi": "4.57.1", + "@rollup/rollup-android-arm64": "4.57.1", + "@rollup/rollup-darwin-arm64": "4.57.1", + "@rollup/rollup-darwin-x64": "4.57.1", + "@rollup/rollup-freebsd-arm64": "4.57.1", + "@rollup/rollup-freebsd-x64": "4.57.1", + "@rollup/rollup-linux-arm-gnueabihf": "4.57.1", + "@rollup/rollup-linux-arm-musleabihf": "4.57.1", + "@rollup/rollup-linux-arm64-gnu": "4.57.1", + "@rollup/rollup-linux-arm64-musl": "4.57.1", + "@rollup/rollup-linux-loong64-gnu": "4.57.1", + "@rollup/rollup-linux-loong64-musl": "4.57.1", + "@rollup/rollup-linux-ppc64-gnu": "4.57.1", + "@rollup/rollup-linux-ppc64-musl": "4.57.1", + "@rollup/rollup-linux-riscv64-gnu": "4.57.1", + "@rollup/rollup-linux-riscv64-musl": "4.57.1", + "@rollup/rollup-linux-s390x-gnu": "4.57.1", + "@rollup/rollup-linux-x64-gnu": "4.57.1", + "@rollup/rollup-linux-x64-musl": "4.57.1", + "@rollup/rollup-openbsd-x64": "4.57.1", + "@rollup/rollup-openharmony-arm64": "4.57.1", + "@rollup/rollup-win32-arm64-msvc": "4.57.1", + "@rollup/rollup-win32-ia32-msvc": "4.57.1", + "@rollup/rollup-win32-x64-gnu": "4.57.1", + "@rollup/rollup-win32-x64-msvc": "4.57.1", "fsevents": "~2.3.2" } }, @@ -3151,9 +3196,9 @@ "license": "MIT" }, "node_modules/selenium-webdriver": { - "version": "4.39.0", - "resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.39.0.tgz", - "integrity": "sha512-NAs9jCU+UeZ/ZmRb8R6zOp7N8eMklefdBYASnaRmCNXdgFE8w3OCxxZmLixkwqnGDHY5VF7hCulfw1Mls43N/A==", + "version": "4.40.0", + "resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.40.0.tgz", + "integrity": "sha512-dU0QbnVKdPmoNP8OtMCazRdtU2Ux6Wl4FEpG1iwUbDeajJK1dBAywBLrC1D7YFRtogHzN96AbXBgBAJaarcysw==", "dev": true, "funding": [ { @@ -3389,9 +3434,9 @@ } }, "node_modules/terser": { - "version": "5.44.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.44.1.tgz", - "integrity": "sha512-t/R3R/n0MSwnnazuPpPNVO60LX0SKL45pyl9YlvxIdkH0Of7D5qM2EVe+yASRIlY5pZ73nclYJfNANGWPwFDZw==", + "version": "5.46.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.46.0.tgz", + "integrity": "sha512-jTwoImyr/QbOWFFso3YoU3ik0jBBDJ6JTOQiy/J2YxVJdZCc+5u7skhNwiOR3FQIygFqVUPHl7qbbxtjW2K3Qg==", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -3502,9 +3547,9 @@ "license": "MIT" }, "node_modules/utilium": { - "version": "2.5.8", - "resolved": "https://registry.npmjs.org/utilium/-/utilium-2.5.8.tgz", - "integrity": "sha512-RNXAYoYH7hefayCW/2LU3SYCwDGQlDc8f4gPCRbMO6dJsYGGlzAhyHqYQGp73ox41JtPKjdqzddAbDhWQ9MrXQ==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/utilium/-/utilium-2.6.0.tgz", + "integrity": "sha512-XIsFQrHyrss6Ex+Z2l5aAItPFJvkw/5vrCt2+C7uY1y6De18u8cIwL9qrzezfpGcgL0fi7FZhTBbgXZKD4rwxA==", "license": "LGPL-3.0-or-later", "dependencies": { "eventemitter3": "^5.0.1" @@ -3593,9 +3638,9 @@ "license": "ISC" }, "node_modules/ws": { - "version": "8.18.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", - "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.19.0.tgz", + "integrity": "sha512-blAT2mjOEIi0ZzruJfIhb3nps74PRWTCz1IjglWEEpQl5XS/UNama6u2/rjFkDDouqr4L67ry+1aGIALViWjDg==", "dev": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index 1fd4749..f2c8b89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "@awesome.me/webawesome": "^3.0.0", + "@awesome.me/webawesome": "^3.2.1", "@codemirror/commands": "^6.10.0", "@codemirror/lang-javascript": "^6.2.4", "@codemirror/lang-markdown": "^6.5.0", diff --git a/scripts/docker-populate-volume.sh b/scripts/docker-populate-volume.sh new file mode 100644 index 0000000..afa1bb3 --- /dev/null +++ b/scripts/docker-populate-volume.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# examine result +# docker run --rm -it -v webawesome-3.2.1:/volume alpine sh +set -euo pipefail # strict error handling + +# Usage message +usage() { + echo "Usage: $0 [source_dir]" + echo " volume_name Name of the Docker volume to create/populate" + echo " source_dir Source directory (default: current directory)" + exit 1 +} + +# Check args +[[ $# -lt 1 ]] && usage + +VOLUME_NAME="$1" +SOURCE_DIR="${2:-.}" + +# Resolve source dir to absolute path (handles relative paths, symlinks via readlink) +if ! SOURCE_DIR=$(cd "$SOURCE_DIR" && pwd); then + echo "❌ Error: Source directory '$2' does not exist or is not readable." >&2 + exit 1 +fi + +echo "📦 Populating Docker volume '$VOLUME_NAME' from: $SOURCE_DIR" + +# Create the volume (safe: no-op if exists) +docker volume create "$VOLUME_NAME" >/dev/null 2>&1 || true + +# Use Alpine Linux container to copy contents into the volume +# - --rm: auto-cleanup after exit +# - read-only source for safety +# - cp -a preserves all metadata (symlinks, perms, timestamps) +# - /source/. → copies *contents* of source dir into target root +docker run --rm \ + -v "$SOURCE_DIR:/source:ro" \ + -v "$VOLUME_NAME:/target" \ + alpine:latest \ + sh -c 'cp -a /source/. /target/' || { + echo "❌ Error copying files. Is Docker running?" >&2 + exit 1 +} + +echo "✅ Volume '$VOLUME_NAME' is now populated from '$SOURCE_DIR'" + diff --git a/webapp/lsp/storex.xqm b/webapp/lsp/storex.xqm new file mode 100644 index 0000000..193ac15 --- /dev/null +++ b/webapp/lsp/storex.xqm @@ -0,0 +1,68 @@ +(:~ + Manage a store for websocket info.It is named as the websocket $sid +:) +module namespace storex = 'storex'; + +(: cache has index :) +declare variable $storex:rules:={ + "doc":{ + "description":"A text document" + }, + + "parse":{ + "description":"XML parse tree" , + "depends":"text", + "calc": "xqparse" + }, + + "symbols":{ + "description":"LSP symbols", + "depends":"parse", + "calc": "symbols" + } + +}; +(:~ in store $sid, and key $uri get value of $property :) +declare function storex:get($uri as xs:string,$sid as xs:string,$property as xs:string) +{ +let $id:=storex:id($uri,$sid ) +let $property:=storex:property($property) +return store:get($property || $id,$sid) + otherwise error(xs:QName("storex:get"),`property unknown: '{$property}'`) +}; + +(:~ get value of $property :) +declare function storex:put($uri as xs:string, + $sid as xs:string, + $property as xs:string, + $value as item()) +{ +let $id:=storex:id($uri,$sid ,true() ) +let $property:=storex:property($property) +return store:put($property || $id,$value,$sid) +}; + +(:~ key for $sid and $uri, error if not found unless $add. +if $add then add entry for uri + :) +declare function storex:id($uri as xs:string,$sid as xs:string,$add as xs:boolean:=false()) +{ +let $index:=store:get-or-put("index",fn(){{}},$sid) +return if(map:contains($index,$uri)) + then $index?uri + else if($add) + then let $id:=random:uuid() + return ($id,store:put("index",map:put($index,$uri,$id),$sid)) + else error(xs:QName("storex:get"),`Uri not found: '{$uri}'`) +}; + +(:~ key for $sid and $uri, error if not found unless $add. +if $add then add entry for uri + :) +declare function storex:property($property as xs:string) +as xs:string +{ + if(map:contains($storex:rules,$property)) + then $property + else error(xs:QName("storex:get"),`property not in rules: '{$property}'`) +}; \ No newline at end of file diff --git a/webapp/static/clients/codemirror/index.html b/webapp/static/clients/codemirror/index.html index 69e54ac..5721e7e 100644 --- a/webapp/static/clients/codemirror/index.html +++ b/webapp/static/clients/codemirror/index.html @@ -70,29 +70,10 @@
EXPLORER
- - - -
- OUTLINE - - - -
- - -
- WORKSPACE - + + -
- MESSAGES - - - -
+ + + + + + + + + +
diff --git a/webapp/static/clients/codemirror/lsp.bundle.js b/webapp/static/clients/codemirror/lsp.bundle.js index 109e1ac..e940b98 100644 --- a/webapp/static/clients/codemirror/lsp.bundle.js +++ b/webapp/static/clients/codemirror/lsp.bundle.js @@ -1416,7 +1416,7 @@ var lsp = (function (exports) { Compare this range to another range. */ eq(other, includeAssoc = false) { - return this.anchor == other.anchor && this.head == other.head && + return this.anchor == other.anchor && this.head == other.head && this.goalColumn == other.goalColumn && (!includeAssoc || !this.empty || this.assoc == other.assoc); } /** @@ -2905,7 +2905,8 @@ var lsp = (function (exports) { - Other (anything else) */ charCategorizer(at) { - return makeCategorizer(this.languageDataAt("wordChars", at).join("")); + let chars = this.languageDataAt("wordChars", at); + return makeCategorizer(chars.length ? chars[0] : ""); } /** Find the word at the given position, meaning the range @@ -3091,6 +3092,9 @@ var lsp = (function (exports) { RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0; RangeValue.prototype.point = false; RangeValue.prototype.mapMode = MapMode.TrackDel; + function cmpVal(a, b) { + return a == b || a.constructor == b.constructor && a.eq(b); + } /** A range associates a value with a range of positions. */ @@ -3397,7 +3401,7 @@ var lsp = (function (exports) { for (;;) { if (sideA.to != sideB.to || !sameValues(sideA.active, sideB.active) || - sideA.point && (!sideB.point || !sideA.point.eq(sideB.point))) + sideA.point && (!sideB.point || !cmpVal(sideA.point, sideB.point))) return false; if (sideA.to > to) return true; @@ -3872,22 +3876,27 @@ var lsp = (function (exports) { b.goto(startB); let endB = startB + length; let pos = startB, dPos = startB - startA; - for (;;) { + let bounds = !!comparator.boundChange; + for (let boundChange = false;;) { let dEnd = (a.to + dPos) - b.to, diff = dEnd || a.endSide - b.endSide; let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB); - if (a.point || b.point) { - if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) && + let point = a.point || b.point; + if (point) { + if (!(a.point && b.point && cmpVal(a.point, b.point) && sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to)))) comparator.comparePoint(pos, clipEnd, a.point, b.point); + boundChange = false; } else { + if (boundChange) + comparator.boundChange(pos); if (clipEnd > pos && !sameValues(a.active, b.active)) comparator.compareRange(pos, clipEnd, a.active, b.active); + if (bounds && clipEnd < endB && (dEnd || a.openEnd(end) != b.openEnd(end))) + boundChange = true; } if (end > endB) break; - if ((dEnd || a.openEnd != b.openEnd) && comparator.boundChange) - comparator.boundChange(end); pos = end; if (diff <= 0) a.next(); @@ -3899,7 +3908,7 @@ var lsp = (function (exports) { if (a.length != b.length) return false; for (let i = 0; i < a.length; i++) - if (a[i] != b[i] && !a[i].eq(b[i])) + if (a[i] != b[i] && !cmpVal(a[i], b[i])) return false; return true; } @@ -4310,6 +4319,390 @@ var lsp = (function (exports) { tabSize: doc.documentElement.style.tabSize != null ? "tab-size" : "-moz-tab-size" }; + function combineAttrs(source, target) { + for (let name in source) { + if (name == "class" && target.class) + target.class += " " + source.class; + else if (name == "style" && target.style) + target.style += ";" + source.style; + else + target[name] = source[name]; + } + return target; + } + const noAttrs$1 = /*@__PURE__*/Object.create(null); + function attrsEq(a, b, ignore) { + if (a == b) + return true; + if (!a) + a = noAttrs$1; + if (!b) + b = noAttrs$1; + let keysA = Object.keys(a), keysB = Object.keys(b); + if (keysA.length - (0) != + keysB.length - (0)) + return false; + for (let key of keysA) { + if (key != ignore && (keysB.indexOf(key) == -1 || a[key] !== b[key])) + return false; + } + return true; + } + function setAttrs(dom, attrs) { + for (let i = dom.attributes.length - 1; i >= 0; i--) { + let name = dom.attributes[i].name; + if (attrs[name] == null) + dom.removeAttribute(name); + } + for (let name in attrs) { + let value = attrs[name]; + if (name == "style") + dom.style.cssText = value; + else if (dom.getAttribute(name) != value) + dom.setAttribute(name, value); + } + } + function updateAttrs(dom, prev, attrs) { + let changed = false; + if (prev) + for (let name in prev) + if (!(attrs && name in attrs)) { + changed = true; + if (name == "style") + dom.style.cssText = ""; + else + dom.removeAttribute(name); + } + if (attrs) + for (let name in attrs) + if (!(prev && prev[name] == attrs[name])) { + changed = true; + if (name == "style") + dom.style.cssText = attrs[name]; + else + dom.setAttribute(name, attrs[name]); + } + return changed; + } + function getAttrs(dom) { + let attrs = Object.create(null); + for (let i = 0; i < dom.attributes.length; i++) { + let attr = dom.attributes[i]; + attrs[attr.name] = attr.value; + } + return attrs; + } + + /** + Widgets added to the content are described by subclasses of this + class. Using a description object like that makes it possible to + delay creating of the DOM structure for a widget until it is + needed, and to avoid redrawing widgets even if the decorations + that define them are recreated. + */ + class WidgetType { + /** + Compare this instance to another instance of the same type. + (TypeScript can't express this, but only instances of the same + specific class will be passed to this method.) This is used to + avoid redrawing widgets when they are replaced by a new + decoration of the same type. The default implementation just + returns `false`, which will cause new instances of the widget to + always be redrawn. + */ + eq(widget) { return false; } + /** + Update a DOM element created by a widget of the same type (but + different, non-`eq` content) to reflect this widget. May return + true to indicate that it could update, false to indicate it + couldn't (in which case the widget will be redrawn). The default + implementation just returns false. + */ + updateDOM(dom, view) { return false; } + /** + @internal + */ + compare(other) { + return this == other || this.constructor == other.constructor && this.eq(other); + } + /** + The estimated height this widget will have, to be used when + estimating the height of content that hasn't been drawn. May + return -1 to indicate you don't know. The default implementation + returns -1. + */ + get estimatedHeight() { return -1; } + /** + For inline widgets that are displayed inline (as opposed to + `inline-block`) and introduce line breaks (through `
` tags + or textual newlines), this must indicate the amount of line + breaks they introduce. Defaults to 0. + */ + get lineBreaks() { return 0; } + /** + Can be used to configure which kinds of events inside the widget + should be ignored by the editor. The default is to ignore all + events. + */ + ignoreEvent(event) { return true; } + /** + Override the way screen coordinates for positions at/in the + widget are found. `pos` will be the offset into the widget, and + `side` the side of the position that is being queried—less than + zero for before, greater than zero for after, and zero for + directly at that position. + */ + coordsAt(dom, pos, side) { return null; } + /** + @internal + */ + get isHidden() { return false; } + /** + @internal + */ + get editable() { return false; } + /** + This is called when the an instance of the widget is removed + from the editor view. + */ + destroy(dom) { } + } + /** + The different types of blocks that can occur in an editor view. + */ + var BlockType = /*@__PURE__*/(function (BlockType) { + /** + A line of text. + */ + BlockType[BlockType["Text"] = 0] = "Text"; + /** + A block widget associated with the position after it. + */ + BlockType[BlockType["WidgetBefore"] = 1] = "WidgetBefore"; + /** + A block widget associated with the position before it. + */ + BlockType[BlockType["WidgetAfter"] = 2] = "WidgetAfter"; + /** + A block widget [replacing](https://codemirror.net/6/docs/ref/#view.Decoration^replace) a range of content. + */ + BlockType[BlockType["WidgetRange"] = 3] = "WidgetRange"; + return BlockType})(BlockType || (BlockType = {})); + /** + A decoration provides information on how to draw or style a piece + of content. You'll usually use it wrapped in a + [`Range`](https://codemirror.net/6/docs/ref/#state.Range), which adds a start and end position. + @nonabstract + */ + class Decoration extends RangeValue { + constructor( + /** + @internal + */ + startSide, + /** + @internal + */ + endSide, + /** + @internal + */ + widget, + /** + The config object used to create this decoration. You can + include additional properties in there to store metadata about + your decoration. + */ + spec) { + super(); + this.startSide = startSide; + this.endSide = endSide; + this.widget = widget; + this.spec = spec; + } + /** + @internal + */ + get heightRelevant() { return false; } + /** + Create a mark decoration, which influences the styling of the + content in its range. Nested mark decorations will cause nested + DOM elements to be created. Nesting order is determined by + precedence of the [facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), with + the higher-precedence decorations creating the inner DOM nodes. + Such elements are split on line boundaries and on the boundaries + of lower-precedence decorations. + */ + static mark(spec) { + return new MarkDecoration(spec); + } + /** + Create a widget decoration, which displays a DOM element at the + given position. + */ + static widget(spec) { + let side = Math.max(-1e4, Math.min(10000, spec.side || 0)), block = !!spec.block; + side += (block && !spec.inlineOrder) + ? (side > 0 ? 300000000 /* Side.BlockAfter */ : -4e8 /* Side.BlockBefore */) + : (side > 0 ? 100000000 /* Side.InlineAfter */ : -1e8 /* Side.InlineBefore */); + return new PointDecoration(spec, side, side, block, spec.widget || null, false); + } + /** + Create a replace decoration which replaces the given range with + a widget, or simply hides it. + */ + static replace(spec) { + let block = !!spec.block, startSide, endSide; + if (spec.isBlockGap) { + startSide = -5e8 /* Side.GapStart */; + endSide = 400000000 /* Side.GapEnd */; + } + else { + let { start, end } = getInclusive(spec, block); + startSide = (start ? (block ? -3e8 /* Side.BlockIncStart */ : -1 /* Side.InlineIncStart */) : 500000000 /* Side.NonIncStart */) - 1; + endSide = (end ? (block ? 200000000 /* Side.BlockIncEnd */ : 1 /* Side.InlineIncEnd */) : -6e8 /* Side.NonIncEnd */) + 1; + } + return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true); + } + /** + Create a line decoration, which can add DOM attributes to the + line starting at the given position. + */ + static line(spec) { + return new LineDecoration(spec); + } + /** + Build a [`DecorationSet`](https://codemirror.net/6/docs/ref/#view.DecorationSet) from the given + decorated range or ranges. If the ranges aren't already sorted, + pass `true` for `sort` to make the library sort them for you. + */ + static set(of, sort = false) { + return RangeSet.of(of, sort); + } + /** + @internal + */ + hasHeight() { return this.widget ? this.widget.estimatedHeight > -1 : false; } + } + /** + The empty set of decorations. + */ + Decoration.none = RangeSet.empty; + class MarkDecoration extends Decoration { + constructor(spec) { + let { start, end } = getInclusive(spec); + super(start ? -1 /* Side.InlineIncStart */ : 500000000 /* Side.NonIncStart */, end ? 1 /* Side.InlineIncEnd */ : -6e8 /* Side.NonIncEnd */, null, spec); + this.tagName = spec.tagName || "span"; + this.attrs = spec.class && spec.attributes ? combineAttrs(spec.attributes, { class: spec.class }) + : spec.class ? { class: spec.class } : spec.attributes || noAttrs$1; + } + eq(other) { + return this == other || other instanceof MarkDecoration && this.tagName == other.tagName && attrsEq(this.attrs, other.attrs); + } + range(from, to = from) { + if (from >= to) + throw new RangeError("Mark decorations may not be empty"); + return super.range(from, to); + } + } + MarkDecoration.prototype.point = false; + class LineDecoration extends Decoration { + constructor(spec) { + super(-2e8 /* Side.Line */, -2e8 /* Side.Line */, null, spec); + } + eq(other) { + return other instanceof LineDecoration && + this.spec.class == other.spec.class && + attrsEq(this.spec.attributes, other.spec.attributes); + } + range(from, to = from) { + if (to != from) + throw new RangeError("Line decoration ranges must be zero-length"); + return super.range(from, to); + } + } + LineDecoration.prototype.mapMode = MapMode.TrackBefore; + LineDecoration.prototype.point = true; + class PointDecoration extends Decoration { + constructor(spec, startSide, endSide, block, widget, isReplace) { + super(startSide, endSide, widget, spec); + this.block = block; + this.isReplace = isReplace; + this.mapMode = !block ? MapMode.TrackDel : startSide <= 0 ? MapMode.TrackBefore : MapMode.TrackAfter; + } + // Only relevant when this.block == true + get type() { + return this.startSide != this.endSide ? BlockType.WidgetRange + : this.startSide <= 0 ? BlockType.WidgetBefore : BlockType.WidgetAfter; + } + get heightRelevant() { + return this.block || !!this.widget && (this.widget.estimatedHeight >= 5 || this.widget.lineBreaks > 0); + } + eq(other) { + return other instanceof PointDecoration && + widgetsEq(this.widget, other.widget) && + this.block == other.block && + this.startSide == other.startSide && this.endSide == other.endSide; + } + range(from, to = from) { + if (this.isReplace && (from > to || (from == to && this.startSide > 0 && this.endSide <= 0))) + throw new RangeError("Invalid range for replacement decoration"); + if (!this.isReplace && to != from) + throw new RangeError("Widget decorations can only have zero-length ranges"); + return super.range(from, to); + } + } + PointDecoration.prototype.point = true; + function getInclusive(spec, block = false) { + let { inclusiveStart: start, inclusiveEnd: end } = spec; + if (start == null) + start = spec.inclusive; + if (end == null) + end = spec.inclusive; + return { start: start !== null && start !== void 0 ? start : block, end: end !== null && end !== void 0 ? end : block }; + } + function widgetsEq(a, b) { + return a == b || !!(a && b && a.compare(b)); + } + function addRange(from, to, ranges, margin = 0) { + let last = ranges.length - 1; + if (last >= 0 && ranges[last] + margin >= from) + ranges[last] = Math.max(ranges[last], to); + else + ranges.push(from, to); + } + /** + A block wrapper defines a DOM node that wraps lines or other block + wrappers at the top of the document. It affects any line or block + widget that starts inside its range, including blocks starting + directly at `from` but not including `to`. + */ + class BlockWrapper extends RangeValue { + constructor(tagName, attributes) { + super(); + this.tagName = tagName; + this.attributes = attributes; + } + eq(other) { + return other == this || + other instanceof BlockWrapper && this.tagName == other.tagName && attrsEq(this.attributes, other.attributes); + } + /** + Create a block wrapper object with the given tag name and + attributes. + */ + static create(spec) { + return new BlockWrapper(spec.tagName, spec.attributes || noAttrs$1); + } + /** + Create a range set from the given block wrapper ranges. + */ + static set(of, sort = false) { + return RangeSet.of(of, sort); + } + } + BlockWrapper.prototype.startSide = BlockWrapper.prototype.endSide = -1; + function getSelection(root) { let target; // Browsers differ on whether shadow roots have a getSelection @@ -4620,10 +5013,6 @@ var lsp = (function (exports) { } return null; } - function clearAttributes(node) { - while (node.attributes.length) - node.removeAttributeNode(node.attributes[0]); - } function atElementStart(doc, selection) { let node = selection.focusNode, offset = selection.focusOffset; if (!node || selection.anchorNode != node || selection.anchorOffset != offset) @@ -4694,7 +5083,6 @@ var lsp = (function (exports) { } } } - class DOMPos { constructor(node, offset, precise = true) { this.node = node; @@ -4704,1460 +5092,6 @@ var lsp = (function (exports) { static before(dom, precise) { return new DOMPos(dom.parentNode, domIndex(dom), precise); } static after(dom, precise) { return new DOMPos(dom.parentNode, domIndex(dom) + 1, precise); } } - const noChildren = []; - class ContentView { - constructor() { - this.parent = null; - this.dom = null; - this.flags = 2 /* ViewFlag.NodeDirty */; - } - get overrideDOMText() { return null; } - get posAtStart() { - return this.parent ? this.parent.posBefore(this) : 0; - } - get posAtEnd() { - return this.posAtStart + this.length; - } - posBefore(view) { - let pos = this.posAtStart; - for (let child of this.children) { - if (child == view) - return pos; - pos += child.length + child.breakAfter; - } - throw new RangeError("Invalid child in posBefore"); - } - posAfter(view) { - return this.posBefore(view) + view.length; - } - sync(view, track) { - if (this.flags & 2 /* ViewFlag.NodeDirty */) { - let parent = this.dom; - let prev = null, next; - for (let child of this.children) { - if (child.flags & 7 /* ViewFlag.Dirty */) { - if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild)) { - let contentView = ContentView.get(next); - if (!contentView || !contentView.parent && contentView.canReuseDOM(child)) - child.reuseDOM(next); - } - child.sync(view, track); - child.flags &= -8 /* ViewFlag.Dirty */; - } - next = prev ? prev.nextSibling : parent.firstChild; - if (track && !track.written && track.node == parent && next != child.dom) - track.written = true; - if (child.dom.parentNode == parent) { - while (next && next != child.dom) - next = rm$1(next); - } - else { - parent.insertBefore(child.dom, next); - } - prev = child.dom; - } - next = prev ? prev.nextSibling : parent.firstChild; - if (next && track && track.node == parent) - track.written = true; - while (next) - next = rm$1(next); - } - else if (this.flags & 1 /* ViewFlag.ChildDirty */) { - for (let child of this.children) - if (child.flags & 7 /* ViewFlag.Dirty */) { - child.sync(view, track); - child.flags &= -8 /* ViewFlag.Dirty */; - } - } - } - reuseDOM(_dom) { } - localPosFromDOM(node, offset) { - let after; - if (node == this.dom) { - after = this.dom.childNodes[offset]; - } - else { - let bias = maxOffset(node) == 0 ? 0 : offset == 0 ? -1 : 1; - for (;;) { - let parent = node.parentNode; - if (parent == this.dom) - break; - if (bias == 0 && parent.firstChild != parent.lastChild) { - if (node == parent.firstChild) - bias = -1; - else - bias = 1; - } - node = parent; - } - if (bias < 0) - after = node; - else - after = node.nextSibling; - } - if (after == this.dom.firstChild) - return 0; - while (after && !ContentView.get(after)) - after = after.nextSibling; - if (!after) - return this.length; - for (let i = 0, pos = 0;; i++) { - let child = this.children[i]; - if (child.dom == after) - return pos; - pos += child.length + child.breakAfter; - } - } - domBoundsAround(from, to, offset = 0) { - let fromI = -1, fromStart = -1, toI = -1, toEnd = -1; - for (let i = 0, pos = offset, prevEnd = offset; i < this.children.length; i++) { - let child = this.children[i], end = pos + child.length; - if (pos < from && end > to) - return child.domBoundsAround(from, to, pos); - if (end >= from && fromI == -1) { - fromI = i; - fromStart = pos; - } - if (pos > to && child.dom.parentNode == this.dom) { - toI = i; - toEnd = prevEnd; - break; - } - prevEnd = end; - pos = end + child.breakAfter; - } - return { from: fromStart, to: toEnd < 0 ? offset + this.length : toEnd, - startDOM: (fromI ? this.children[fromI - 1].dom.nextSibling : null) || this.dom.firstChild, - endDOM: toI < this.children.length && toI >= 0 ? this.children[toI].dom : null }; - } - markDirty(andParent = false) { - this.flags |= 2 /* ViewFlag.NodeDirty */; - this.markParentsDirty(andParent); - } - markParentsDirty(childList) { - for (let parent = this.parent; parent; parent = parent.parent) { - if (childList) - parent.flags |= 2 /* ViewFlag.NodeDirty */; - if (parent.flags & 1 /* ViewFlag.ChildDirty */) - return; - parent.flags |= 1 /* ViewFlag.ChildDirty */; - childList = false; - } - } - setParent(parent) { - if (this.parent != parent) { - this.parent = parent; - if (this.flags & 7 /* ViewFlag.Dirty */) - this.markParentsDirty(true); - } - } - setDOM(dom) { - if (this.dom == dom) - return; - if (this.dom) - this.dom.cmView = null; - this.dom = dom; - dom.cmView = this; - } - get rootView() { - for (let v = this;;) { - let parent = v.parent; - if (!parent) - return v; - v = parent; - } - } - replaceChildren(from, to, children = noChildren) { - this.markDirty(); - for (let i = from; i < to; i++) { - let child = this.children[i]; - if (child.parent == this && children.indexOf(child) < 0) - child.destroy(); - } - if (children.length < 250) - this.children.splice(from, to - from, ...children); - else - this.children = [].concat(this.children.slice(0, from), children, this.children.slice(to)); - for (let i = 0; i < children.length; i++) - children[i].setParent(this); - } - ignoreMutation(_rec) { return false; } - ignoreEvent(_event) { return false; } - childCursor(pos = this.length) { - return new ChildCursor(this.children, pos, this.children.length); - } - childPos(pos, bias = 1) { - return this.childCursor().findPos(pos, bias); - } - toString() { - let name = this.constructor.name.replace("View", ""); - return name + (this.children.length ? "(" + this.children.join() + ")" : - this.length ? "[" + (name == "Text" ? this.text : this.length) + "]" : "") + - (this.breakAfter ? "#" : ""); - } - static get(node) { return node.cmView; } - get isEditable() { return true; } - get isWidget() { return false; } - get isHidden() { return false; } - merge(from, to, source, hasStart, openStart, openEnd) { - return false; - } - become(other) { return false; } - canReuseDOM(other) { - return other.constructor == this.constructor && !((this.flags | other.flags) & 8 /* ViewFlag.Composition */); - } - // When this is a zero-length view with a side, this should return a - // number <= 0 to indicate it is before its position, or a - // number > 0 when after its position. - getSide() { return 0; } - destroy() { - for (let child of this.children) - if (child.parent == this) - child.destroy(); - this.parent = null; - } - } - ContentView.prototype.breakAfter = 0; - // Remove a DOM node and return its next sibling. - function rm$1(dom) { - let next = dom.nextSibling; - dom.parentNode.removeChild(dom); - return next; - } - class ChildCursor { - constructor(children, pos, i) { - this.children = children; - this.pos = pos; - this.i = i; - this.off = 0; - } - findPos(pos, bias = 1) { - for (;;) { - if (pos > this.pos || pos == this.pos && - (bias > 0 || this.i == 0 || this.children[this.i - 1].breakAfter)) { - this.off = pos - this.pos; - return this; - } - let next = this.children[--this.i]; - this.pos -= next.length + next.breakAfter; - } - } - } - function replaceRange(parent, fromI, fromOff, toI, toOff, insert, breakAtStart, openStart, openEnd) { - let { children } = parent; - let before = children.length ? children[fromI] : null; - let last = insert.length ? insert[insert.length - 1] : null; - let breakAtEnd = last ? last.breakAfter : breakAtStart; - // Change within a single child - if (fromI == toI && before && !breakAtStart && !breakAtEnd && insert.length < 2 && - before.merge(fromOff, toOff, insert.length ? last : null, fromOff == 0, openStart, openEnd)) - return; - if (toI < children.length) { - let after = children[toI]; - // Make sure the end of the child after the update is preserved in `after` - if (after && (toOff < after.length || after.breakAfter && (last === null || last === void 0 ? void 0 : last.breakAfter))) { - // If we're splitting a child, separate part of it to avoid that - // being mangled when updating the child before the update. - if (fromI == toI) { - after = after.split(toOff); - toOff = 0; - } - // If the element after the replacement should be merged with - // the last replacing element, update `content` - if (!breakAtEnd && last && after.merge(0, toOff, last, true, 0, openEnd)) { - insert[insert.length - 1] = after; - } - else { - // Remove the start of the after element, if necessary, and - // add it to `content`. - if (toOff || after.children.length && !after.children[0].length) - after.merge(0, toOff, null, false, 0, openEnd); - insert.push(after); - } - } - else if (after === null || after === void 0 ? void 0 : after.breakAfter) { - // The element at `toI` is entirely covered by this range. - // Preserve its line break, if any. - if (last) - last.breakAfter = 1; - else - breakAtStart = 1; - } - // Since we've handled the next element from the current elements - // now, make sure `toI` points after that. - toI++; - } - if (before) { - before.breakAfter = breakAtStart; - if (fromOff > 0) { - if (!breakAtStart && insert.length && before.merge(fromOff, before.length, insert[0], false, openStart, 0)) { - before.breakAfter = insert.shift().breakAfter; - } - else if (fromOff < before.length || before.children.length && before.children[before.children.length - 1].length == 0) { - before.merge(fromOff, before.length, null, false, openStart, 0); - } - fromI++; - } - } - // Try to merge widgets on the boundaries of the replacement - while (fromI < toI && insert.length) { - if (children[toI - 1].become(insert[insert.length - 1])) { - toI--; - insert.pop(); - openEnd = insert.length ? 0 : openStart; - } - else if (children[fromI].become(insert[0])) { - fromI++; - insert.shift(); - openStart = insert.length ? 0 : openEnd; - } - else { - break; - } - } - if (!insert.length && fromI && toI < children.length && !children[fromI - 1].breakAfter && - children[toI].merge(0, 0, children[fromI - 1], false, openStart, openEnd)) - fromI--; - if (fromI < toI || insert.length) - parent.replaceChildren(fromI, toI, insert); - } - function mergeChildrenInto(parent, from, to, insert, openStart, openEnd) { - let cur = parent.childCursor(); - let { i: toI, off: toOff } = cur.findPos(to, 1); - let { i: fromI, off: fromOff } = cur.findPos(from, -1); - let dLen = from - to; - for (let view of insert) - dLen += view.length; - parent.length += dLen; - replaceRange(parent, fromI, fromOff, toI, toOff, insert, 0, openStart, openEnd); - } - - const MaxJoinLen = 256; - class TextView extends ContentView { - constructor(text) { - super(); - this.text = text; - } - get length() { return this.text.length; } - createDOM(textDOM) { - this.setDOM(textDOM || document.createTextNode(this.text)); - } - sync(view, track) { - if (!this.dom) - this.createDOM(); - if (this.dom.nodeValue != this.text) { - if (track && track.node == this.dom) - track.written = true; - this.dom.nodeValue = this.text; - } - } - reuseDOM(dom) { - if (dom.nodeType == 3) - this.createDOM(dom); - } - merge(from, to, source) { - if ((this.flags & 8 /* ViewFlag.Composition */) || - source && (!(source instanceof TextView) || - this.length - (to - from) + source.length > MaxJoinLen || - (source.flags & 8 /* ViewFlag.Composition */))) - return false; - this.text = this.text.slice(0, from) + (source ? source.text : "") + this.text.slice(to); - this.markDirty(); - return true; - } - split(from) { - let result = new TextView(this.text.slice(from)); - this.text = this.text.slice(0, from); - this.markDirty(); - result.flags |= this.flags & 8 /* ViewFlag.Composition */; - return result; - } - localPosFromDOM(node, offset) { - return node == this.dom ? offset : offset ? this.text.length : 0; - } - domAtPos(pos) { return new DOMPos(this.dom, pos); } - domBoundsAround(_from, _to, offset) { - return { from: offset, to: offset + this.length, startDOM: this.dom, endDOM: this.dom.nextSibling }; - } - coordsAt(pos, side) { - return textCoords(this.dom, pos, side); - } - } - class MarkView extends ContentView { - constructor(mark, children = [], length = 0) { - super(); - this.mark = mark; - this.children = children; - this.length = length; - for (let ch of children) - ch.setParent(this); - } - setAttrs(dom) { - clearAttributes(dom); - if (this.mark.class) - dom.className = this.mark.class; - if (this.mark.attrs) - for (let name in this.mark.attrs) - dom.setAttribute(name, this.mark.attrs[name]); - return dom; - } - canReuseDOM(other) { - return super.canReuseDOM(other) && !((this.flags | other.flags) & 8 /* ViewFlag.Composition */); - } - reuseDOM(node) { - if (node.nodeName == this.mark.tagName.toUpperCase()) { - this.setDOM(node); - this.flags |= 4 /* ViewFlag.AttrsDirty */ | 2 /* ViewFlag.NodeDirty */; - } - } - sync(view, track) { - if (!this.dom) - this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))); - else if (this.flags & 4 /* ViewFlag.AttrsDirty */) - this.setAttrs(this.dom); - super.sync(view, track); - } - merge(from, to, source, _hasStart, openStart, openEnd) { - if (source && (!(source instanceof MarkView && source.mark.eq(this.mark)) || - (from && openStart <= 0) || (to < this.length && openEnd <= 0))) - return false; - mergeChildrenInto(this, from, to, source ? source.children.slice() : [], openStart - 1, openEnd - 1); - this.markDirty(); - return true; - } - split(from) { - let result = [], off = 0, detachFrom = -1, i = 0; - for (let elt of this.children) { - let end = off + elt.length; - if (end > from) - result.push(off < from ? elt.split(from - off) : elt); - if (detachFrom < 0 && off >= from) - detachFrom = i; - off = end; - i++; - } - let length = this.length - from; - this.length = from; - if (detachFrom > -1) { - this.children.length = detachFrom; - this.markDirty(); - } - return new MarkView(this.mark, result, length); - } - domAtPos(pos) { - return inlineDOMAtPos(this, pos); - } - coordsAt(pos, side) { - return coordsInChildren(this, pos, side); - } - } - function textCoords(text, pos, side) { - let length = text.nodeValue.length; - if (pos > length) - pos = length; - let from = pos, to = pos, flatten = 0; - if (pos == 0 && side < 0 || pos == length && side >= 0) { - if (!(browser.chrome || browser.gecko)) { // These browsers reliably return valid rectangles for empty ranges - if (pos) { - from--; - flatten = 1; - } // FIXME this is wrong in RTL text - else if (to < length) { - to++; - flatten = -1; - } - } - } - else { - if (side < 0) - from--; - else if (to < length) - to++; - } - let rects = textRange(text, from, to).getClientRects(); - if (!rects.length) - return null; - let rect = rects[(flatten ? flatten < 0 : side >= 0) ? 0 : rects.length - 1]; - if (browser.safari && !flatten && rect.width == 0) - rect = Array.prototype.find.call(rects, r => r.width) || rect; - return flatten ? flattenRect(rect, flatten < 0) : rect || null; - } - // Also used for collapsed ranges that don't have a placeholder widget! - class WidgetView extends ContentView { - static create(widget, length, side) { - return new WidgetView(widget, length, side); - } - constructor(widget, length, side) { - super(); - this.widget = widget; - this.length = length; - this.side = side; - this.prevWidget = null; - } - split(from) { - let result = WidgetView.create(this.widget, this.length - from, this.side); - this.length -= from; - return result; - } - sync(view) { - if (!this.dom || !this.widget.updateDOM(this.dom, view)) { - if (this.dom && this.prevWidget) - this.prevWidget.destroy(this.dom); - this.prevWidget = null; - this.setDOM(this.widget.toDOM(view)); - if (!this.widget.editable) - this.dom.contentEditable = "false"; - } - } - getSide() { return this.side; } - merge(from, to, source, hasStart, openStart, openEnd) { - if (source && (!(source instanceof WidgetView) || !this.widget.compare(source.widget) || - from > 0 && openStart <= 0 || to < this.length && openEnd <= 0)) - return false; - this.length = from + (source ? source.length : 0) + (this.length - to); - return true; - } - become(other) { - if (other instanceof WidgetView && other.side == this.side && - this.widget.constructor == other.widget.constructor) { - if (!this.widget.compare(other.widget)) - this.markDirty(true); - if (this.dom && !this.prevWidget) - this.prevWidget = this.widget; - this.widget = other.widget; - this.length = other.length; - return true; - } - return false; - } - ignoreMutation() { return true; } - ignoreEvent(event) { return this.widget.ignoreEvent(event); } - get overrideDOMText() { - if (this.length == 0) - return Text.empty; - let top = this; - while (top.parent) - top = top.parent; - let { view } = top, text = view && view.state.doc, start = this.posAtStart; - return text ? text.slice(start, start + this.length) : Text.empty; - } - domAtPos(pos) { - return (this.length ? pos == 0 : this.side > 0) - ? DOMPos.before(this.dom) - : DOMPos.after(this.dom, pos == this.length); - } - domBoundsAround() { return null; } - coordsAt(pos, side) { - let custom = this.widget.coordsAt(this.dom, pos, side); - if (custom) - return custom; - let rects = this.dom.getClientRects(), rect = null; - if (!rects.length) - return null; - let fromBack = this.side ? this.side < 0 : pos > 0; - for (let i = fromBack ? rects.length - 1 : 0;; i += (fromBack ? -1 : 1)) { - rect = rects[i]; - if (pos > 0 ? i == 0 : i == rects.length - 1 || rect.top < rect.bottom) - break; - } - return flattenRect(rect, !fromBack); - } - get isEditable() { return false; } - get isWidget() { return true; } - get isHidden() { return this.widget.isHidden; } - destroy() { - super.destroy(); - if (this.dom) - this.widget.destroy(this.dom); - } - } - // These are drawn around uneditable widgets to avoid a number of - // browser bugs that show up when the cursor is directly next to - // uneditable inline content. - class WidgetBufferView extends ContentView { - constructor(side) { - super(); - this.side = side; - } - get length() { return 0; } - merge() { return false; } - become(other) { - return other instanceof WidgetBufferView && other.side == this.side; - } - split() { return new WidgetBufferView(this.side); } - sync() { - if (!this.dom) { - let dom = document.createElement("img"); - dom.className = "cm-widgetBuffer"; - dom.setAttribute("aria-hidden", "true"); - this.setDOM(dom); - } - } - getSide() { return this.side; } - domAtPos(pos) { return this.side > 0 ? DOMPos.before(this.dom) : DOMPos.after(this.dom); } - localPosFromDOM() { return 0; } - domBoundsAround() { return null; } - coordsAt(pos) { - return this.dom.getBoundingClientRect(); - } - get overrideDOMText() { - return Text.empty; - } - get isHidden() { return true; } - } - TextView.prototype.children = WidgetView.prototype.children = WidgetBufferView.prototype.children = noChildren; - function inlineDOMAtPos(parent, pos) { - let dom = parent.dom, { children } = parent, i = 0; - for (let off = 0; i < children.length; i++) { - let child = children[i], end = off + child.length; - if (end == off && child.getSide() <= 0) - continue; - if (pos > off && pos < end && child.dom.parentNode == dom) - return child.domAtPos(pos - off); - if (pos <= off) - break; - off = end; - } - for (let j = i; j > 0; j--) { - let prev = children[j - 1]; - if (prev.dom.parentNode == dom) - return prev.domAtPos(prev.length); - } - for (let j = i; j < children.length; j++) { - let next = children[j]; - if (next.dom.parentNode == dom) - return next.domAtPos(0); - } - return new DOMPos(dom, 0); - } - // Assumes `view`, if a mark view, has precisely 1 child. - function joinInlineInto(parent, view, open) { - let last, { children } = parent; - if (open > 0 && view instanceof MarkView && children.length && - (last = children[children.length - 1]) instanceof MarkView && last.mark.eq(view.mark)) { - joinInlineInto(last, view.children[0], open - 1); - } - else { - children.push(view); - view.setParent(parent); - } - parent.length += view.length; - } - function coordsInChildren(view, pos, side) { - let before = null, beforePos = -1, after = null, afterPos = -1; - function scan(view, pos) { - for (let i = 0, off = 0; i < view.children.length && off <= pos; i++) { - let child = view.children[i], end = off + child.length; - if (end >= pos) { - if (child.children.length) { - scan(child, pos - off); - } - else if ((!after || after.isHidden && (side > 0 || onSameLine(after, child))) && - (end > pos || off == end && child.getSide() > 0)) { - after = child; - afterPos = pos - off; - } - else if (off < pos || (off == end && child.getSide() < 0) && !child.isHidden) { - before = child; - beforePos = pos - off; - } - } - off = end; - } - } - scan(view, pos); - let target = (side < 0 ? before : after) || before || after; - if (target) - return target.coordsAt(Math.max(0, target == before ? beforePos : afterPos), side); - return fallbackRect(view); - } - function fallbackRect(view) { - let last = view.dom.lastChild; - if (!last) - return view.dom.getBoundingClientRect(); - let rects = clientRectsFor(last); - return rects[rects.length - 1] || null; - } - function onSameLine(a, b) { - let posA = a.coordsAt(0, 1), posB = b.coordsAt(0, 1); - return posA && posB && posB.top < posA.bottom; - } - - function combineAttrs(source, target) { - for (let name in source) { - if (name == "class" && target.class) - target.class += " " + source.class; - else if (name == "style" && target.style) - target.style += ";" + source.style; - else - target[name] = source[name]; - } - return target; - } - const noAttrs$1 = /*@__PURE__*/Object.create(null); - function attrsEq(a, b, ignore) { - if (a == b) - return true; - if (!a) - a = noAttrs$1; - if (!b) - b = noAttrs$1; - let keysA = Object.keys(a), keysB = Object.keys(b); - if (keysA.length - (ignore && keysA.indexOf(ignore) > -1 ? 1 : 0) != - keysB.length - (ignore && keysB.indexOf(ignore) > -1 ? 1 : 0)) - return false; - for (let key of keysA) { - if (key != ignore && (keysB.indexOf(key) == -1 || a[key] !== b[key])) - return false; - } - return true; - } - function updateAttrs(dom, prev, attrs) { - let changed = false; - if (prev) - for (let name in prev) - if (!(attrs && name in attrs)) { - changed = true; - if (name == "style") - dom.style.cssText = ""; - else - dom.removeAttribute(name); - } - if (attrs) - for (let name in attrs) - if (!(prev && prev[name] == attrs[name])) { - changed = true; - if (name == "style") - dom.style.cssText = attrs[name]; - else - dom.setAttribute(name, attrs[name]); - } - return changed; - } - function getAttrs(dom) { - let attrs = Object.create(null); - for (let i = 0; i < dom.attributes.length; i++) { - let attr = dom.attributes[i]; - attrs[attr.name] = attr.value; - } - return attrs; - } - - /** - Widgets added to the content are described by subclasses of this - class. Using a description object like that makes it possible to - delay creating of the DOM structure for a widget until it is - needed, and to avoid redrawing widgets even if the decorations - that define them are recreated. - */ - class WidgetType { - /** - Compare this instance to another instance of the same type. - (TypeScript can't express this, but only instances of the same - specific class will be passed to this method.) This is used to - avoid redrawing widgets when they are replaced by a new - decoration of the same type. The default implementation just - returns `false`, which will cause new instances of the widget to - always be redrawn. - */ - eq(widget) { return false; } - /** - Update a DOM element created by a widget of the same type (but - different, non-`eq` content) to reflect this widget. May return - true to indicate that it could update, false to indicate it - couldn't (in which case the widget will be redrawn). The default - implementation just returns false. - */ - updateDOM(dom, view) { return false; } - /** - @internal - */ - compare(other) { - return this == other || this.constructor == other.constructor && this.eq(other); - } - /** - The estimated height this widget will have, to be used when - estimating the height of content that hasn't been drawn. May - return -1 to indicate you don't know. The default implementation - returns -1. - */ - get estimatedHeight() { return -1; } - /** - For inline widgets that are displayed inline (as opposed to - `inline-block`) and introduce line breaks (through `
` tags - or textual newlines), this must indicate the amount of line - breaks they introduce. Defaults to 0. - */ - get lineBreaks() { return 0; } - /** - Can be used to configure which kinds of events inside the widget - should be ignored by the editor. The default is to ignore all - events. - */ - ignoreEvent(event) { return true; } - /** - Override the way screen coordinates for positions at/in the - widget are found. `pos` will be the offset into the widget, and - `side` the side of the position that is being queried—less than - zero for before, greater than zero for after, and zero for - directly at that position. - */ - coordsAt(dom, pos, side) { return null; } - /** - @internal - */ - get isHidden() { return false; } - /** - @internal - */ - get editable() { return false; } - /** - This is called when the an instance of the widget is removed - from the editor view. - */ - destroy(dom) { } - } - /** - The different types of blocks that can occur in an editor view. - */ - var BlockType = /*@__PURE__*/(function (BlockType) { - /** - A line of text. - */ - BlockType[BlockType["Text"] = 0] = "Text"; - /** - A block widget associated with the position after it. - */ - BlockType[BlockType["WidgetBefore"] = 1] = "WidgetBefore"; - /** - A block widget associated with the position before it. - */ - BlockType[BlockType["WidgetAfter"] = 2] = "WidgetAfter"; - /** - A block widget [replacing](https://codemirror.net/6/docs/ref/#view.Decoration^replace) a range of content. - */ - BlockType[BlockType["WidgetRange"] = 3] = "WidgetRange"; - return BlockType})(BlockType || (BlockType = {})); - /** - A decoration provides information on how to draw or style a piece - of content. You'll usually use it wrapped in a - [`Range`](https://codemirror.net/6/docs/ref/#state.Range), which adds a start and end position. - @nonabstract - */ - class Decoration extends RangeValue { - constructor( - /** - @internal - */ - startSide, - /** - @internal - */ - endSide, - /** - @internal - */ - widget, - /** - The config object used to create this decoration. You can - include additional properties in there to store metadata about - your decoration. - */ - spec) { - super(); - this.startSide = startSide; - this.endSide = endSide; - this.widget = widget; - this.spec = spec; - } - /** - @internal - */ - get heightRelevant() { return false; } - /** - Create a mark decoration, which influences the styling of the - content in its range. Nested mark decorations will cause nested - DOM elements to be created. Nesting order is determined by - precedence of the [facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), with - the higher-precedence decorations creating the inner DOM nodes. - Such elements are split on line boundaries and on the boundaries - of lower-precedence decorations. - */ - static mark(spec) { - return new MarkDecoration(spec); - } - /** - Create a widget decoration, which displays a DOM element at the - given position. - */ - static widget(spec) { - let side = Math.max(-1e4, Math.min(10000, spec.side || 0)), block = !!spec.block; - side += (block && !spec.inlineOrder) - ? (side > 0 ? 300000000 /* Side.BlockAfter */ : -4e8 /* Side.BlockBefore */) - : (side > 0 ? 100000000 /* Side.InlineAfter */ : -1e8 /* Side.InlineBefore */); - return new PointDecoration(spec, side, side, block, spec.widget || null, false); - } - /** - Create a replace decoration which replaces the given range with - a widget, or simply hides it. - */ - static replace(spec) { - let block = !!spec.block, startSide, endSide; - if (spec.isBlockGap) { - startSide = -5e8 /* Side.GapStart */; - endSide = 400000000 /* Side.GapEnd */; - } - else { - let { start, end } = getInclusive(spec, block); - startSide = (start ? (block ? -3e8 /* Side.BlockIncStart */ : -1 /* Side.InlineIncStart */) : 500000000 /* Side.NonIncStart */) - 1; - endSide = (end ? (block ? 200000000 /* Side.BlockIncEnd */ : 1 /* Side.InlineIncEnd */) : -6e8 /* Side.NonIncEnd */) + 1; - } - return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true); - } - /** - Create a line decoration, which can add DOM attributes to the - line starting at the given position. - */ - static line(spec) { - return new LineDecoration(spec); - } - /** - Build a [`DecorationSet`](https://codemirror.net/6/docs/ref/#view.DecorationSet) from the given - decorated range or ranges. If the ranges aren't already sorted, - pass `true` for `sort` to make the library sort them for you. - */ - static set(of, sort = false) { - return RangeSet.of(of, sort); - } - /** - @internal - */ - hasHeight() { return this.widget ? this.widget.estimatedHeight > -1 : false; } - } - /** - The empty set of decorations. - */ - Decoration.none = RangeSet.empty; - class MarkDecoration extends Decoration { - constructor(spec) { - let { start, end } = getInclusive(spec); - super(start ? -1 /* Side.InlineIncStart */ : 500000000 /* Side.NonIncStart */, end ? 1 /* Side.InlineIncEnd */ : -6e8 /* Side.NonIncEnd */, null, spec); - this.tagName = spec.tagName || "span"; - this.class = spec.class || ""; - this.attrs = spec.attributes || null; - } - eq(other) { - var _a, _b; - return this == other || - other instanceof MarkDecoration && - this.tagName == other.tagName && - (this.class || ((_a = this.attrs) === null || _a === void 0 ? void 0 : _a.class)) == (other.class || ((_b = other.attrs) === null || _b === void 0 ? void 0 : _b.class)) && - attrsEq(this.attrs, other.attrs, "class"); - } - range(from, to = from) { - if (from >= to) - throw new RangeError("Mark decorations may not be empty"); - return super.range(from, to); - } - } - MarkDecoration.prototype.point = false; - class LineDecoration extends Decoration { - constructor(spec) { - super(-2e8 /* Side.Line */, -2e8 /* Side.Line */, null, spec); - } - eq(other) { - return other instanceof LineDecoration && - this.spec.class == other.spec.class && - attrsEq(this.spec.attributes, other.spec.attributes); - } - range(from, to = from) { - if (to != from) - throw new RangeError("Line decoration ranges must be zero-length"); - return super.range(from, to); - } - } - LineDecoration.prototype.mapMode = MapMode.TrackBefore; - LineDecoration.prototype.point = true; - class PointDecoration extends Decoration { - constructor(spec, startSide, endSide, block, widget, isReplace) { - super(startSide, endSide, widget, spec); - this.block = block; - this.isReplace = isReplace; - this.mapMode = !block ? MapMode.TrackDel : startSide <= 0 ? MapMode.TrackBefore : MapMode.TrackAfter; - } - // Only relevant when this.block == true - get type() { - return this.startSide != this.endSide ? BlockType.WidgetRange - : this.startSide <= 0 ? BlockType.WidgetBefore : BlockType.WidgetAfter; - } - get heightRelevant() { - return this.block || !!this.widget && (this.widget.estimatedHeight >= 5 || this.widget.lineBreaks > 0); - } - eq(other) { - return other instanceof PointDecoration && - widgetsEq(this.widget, other.widget) && - this.block == other.block && - this.startSide == other.startSide && this.endSide == other.endSide; - } - range(from, to = from) { - if (this.isReplace && (from > to || (from == to && this.startSide > 0 && this.endSide <= 0))) - throw new RangeError("Invalid range for replacement decoration"); - if (!this.isReplace && to != from) - throw new RangeError("Widget decorations can only have zero-length ranges"); - return super.range(from, to); - } - } - PointDecoration.prototype.point = true; - function getInclusive(spec, block = false) { - let { inclusiveStart: start, inclusiveEnd: end } = spec; - if (start == null) - start = spec.inclusive; - if (end == null) - end = spec.inclusive; - return { start: start !== null && start !== void 0 ? start : block, end: end !== null && end !== void 0 ? end : block }; - } - function widgetsEq(a, b) { - return a == b || !!(a && b && a.compare(b)); - } - function addRange(from, to, ranges, margin = 0) { - let last = ranges.length - 1; - if (last >= 0 && ranges[last] + margin >= from) - ranges[last] = Math.max(ranges[last], to); - else - ranges.push(from, to); - } - - class LineView extends ContentView { - constructor() { - super(...arguments); - this.children = []; - this.length = 0; - this.prevAttrs = undefined; - this.attrs = null; - this.breakAfter = 0; - } - // Consumes source - merge(from, to, source, hasStart, openStart, openEnd) { - if (source) { - if (!(source instanceof LineView)) - return false; - if (!this.dom) - source.transferDOM(this); // Reuse source.dom when appropriate - } - if (hasStart) - this.setDeco(source ? source.attrs : null); - mergeChildrenInto(this, from, to, source ? source.children.slice() : [], openStart, openEnd); - return true; - } - split(at) { - let end = new LineView; - end.breakAfter = this.breakAfter; - if (this.length == 0) - return end; - let { i, off } = this.childPos(at); - if (off) { - end.append(this.children[i].split(off), 0); - this.children[i].merge(off, this.children[i].length, null, false, 0, 0); - i++; - } - for (let j = i; j < this.children.length; j++) - end.append(this.children[j], 0); - while (i > 0 && this.children[i - 1].length == 0) - this.children[--i].destroy(); - this.children.length = i; - this.markDirty(); - this.length = at; - return end; - } - transferDOM(other) { - if (!this.dom) - return; - this.markDirty(); - other.setDOM(this.dom); - other.prevAttrs = this.prevAttrs === undefined ? this.attrs : this.prevAttrs; - this.prevAttrs = undefined; - this.dom = null; - } - setDeco(attrs) { - if (!attrsEq(this.attrs, attrs)) { - if (this.dom) { - this.prevAttrs = this.attrs; - this.markDirty(); - } - this.attrs = attrs; - } - } - append(child, openStart) { - joinInlineInto(this, child, openStart); - } - // Only called when building a line view in ContentBuilder - addLineDeco(deco) { - let attrs = deco.spec.attributes, cls = deco.spec.class; - if (attrs) - this.attrs = combineAttrs(attrs, this.attrs || {}); - if (cls) - this.attrs = combineAttrs({ class: cls }, this.attrs || {}); - } - domAtPos(pos) { - return inlineDOMAtPos(this, pos); - } - reuseDOM(node) { - if (node.nodeName == "DIV") { - this.setDOM(node); - this.flags |= 4 /* ViewFlag.AttrsDirty */ | 2 /* ViewFlag.NodeDirty */; - } - } - sync(view, track) { - var _a; - if (!this.dom) { - this.setDOM(document.createElement("div")); - this.dom.className = "cm-line"; - this.prevAttrs = this.attrs ? null : undefined; - } - else if (this.flags & 4 /* ViewFlag.AttrsDirty */) { - clearAttributes(this.dom); - this.dom.className = "cm-line"; - this.prevAttrs = this.attrs ? null : undefined; - } - if (this.prevAttrs !== undefined) { - updateAttrs(this.dom, this.prevAttrs, this.attrs); - this.dom.classList.add("cm-line"); - this.prevAttrs = undefined; - } - super.sync(view, track); - let last = this.dom.lastChild; - while (last && ContentView.get(last) instanceof MarkView) - last = last.lastChild; - if (!last || !this.length || - last.nodeName != "BR" && ((_a = ContentView.get(last)) === null || _a === void 0 ? void 0 : _a.isEditable) == false && - (!browser.ios || !this.children.some(ch => ch instanceof TextView))) { - let hack = document.createElement("BR"); - hack.cmIgnore = true; - this.dom.appendChild(hack); - } - } - measureTextSize() { - if (this.children.length == 0 || this.length > 20) - return null; - let totalWidth = 0, textHeight; - for (let child of this.children) { - if (!(child instanceof TextView) || /[^ -~]/.test(child.text)) - return null; - let rects = clientRectsFor(child.dom); - if (rects.length != 1) - return null; - totalWidth += rects[0].width; - textHeight = rects[0].height; - } - return !totalWidth ? null : { - lineHeight: this.dom.getBoundingClientRect().height, - charWidth: totalWidth / this.length, - textHeight - }; - } - coordsAt(pos, side) { - let rect = coordsInChildren(this, pos, side); - // Correct rectangle height for empty lines when the returned - // height is larger than the text height. - if (!this.children.length && rect && this.parent) { - let { heightOracle } = this.parent.view.viewState, height = rect.bottom - rect.top; - if (Math.abs(height - heightOracle.lineHeight) < 2 && heightOracle.textHeight < height) { - let dist = (height - heightOracle.textHeight) / 2; - return { top: rect.top + dist, bottom: rect.bottom - dist, left: rect.left, right: rect.left }; - } - } - return rect; - } - become(other) { - return other instanceof LineView && this.children.length == 0 && other.children.length == 0 && - attrsEq(this.attrs, other.attrs) && this.breakAfter == other.breakAfter; - } - covers() { return true; } - static find(docView, pos) { - for (let i = 0, off = 0; i < docView.children.length; i++) { - let block = docView.children[i], end = off + block.length; - if (end >= pos) { - if (block instanceof LineView) - return block; - if (end > pos) - break; - } - off = end + block.breakAfter; - } - return null; - } - } - class BlockWidgetView extends ContentView { - constructor(widget, length, deco) { - super(); - this.widget = widget; - this.length = length; - this.deco = deco; - this.breakAfter = 0; - this.prevWidget = null; - } - merge(from, to, source, _takeDeco, openStart, openEnd) { - if (source && (!(source instanceof BlockWidgetView) || !this.widget.compare(source.widget) || - from > 0 && openStart <= 0 || to < this.length && openEnd <= 0)) - return false; - this.length = from + (source ? source.length : 0) + (this.length - to); - return true; - } - domAtPos(pos) { - return pos == 0 ? DOMPos.before(this.dom) : DOMPos.after(this.dom, pos == this.length); - } - split(at) { - let len = this.length - at; - this.length = at; - let end = new BlockWidgetView(this.widget, len, this.deco); - end.breakAfter = this.breakAfter; - return end; - } - get children() { return noChildren; } - sync(view) { - if (!this.dom || !this.widget.updateDOM(this.dom, view)) { - if (this.dom && this.prevWidget) - this.prevWidget.destroy(this.dom); - this.prevWidget = null; - this.setDOM(this.widget.toDOM(view)); - if (!this.widget.editable) - this.dom.contentEditable = "false"; - } - } - get overrideDOMText() { - return this.parent ? this.parent.view.state.doc.slice(this.posAtStart, this.posAtEnd) : Text.empty; - } - domBoundsAround() { return null; } - become(other) { - if (other instanceof BlockWidgetView && - other.widget.constructor == this.widget.constructor) { - if (!other.widget.compare(this.widget)) - this.markDirty(true); - if (this.dom && !this.prevWidget) - this.prevWidget = this.widget; - this.widget = other.widget; - this.length = other.length; - this.deco = other.deco; - this.breakAfter = other.breakAfter; - return true; - } - return false; - } - ignoreMutation() { return true; } - ignoreEvent(event) { return this.widget.ignoreEvent(event); } - get isEditable() { return false; } - get isWidget() { return true; } - coordsAt(pos, side) { - let custom = this.widget.coordsAt(this.dom, pos, side); - if (custom) - return custom; - if (this.widget instanceof BlockGapWidget) - return null; - return flattenRect(this.dom.getBoundingClientRect(), this.length ? pos == 0 : side <= 0); - } - destroy() { - super.destroy(); - if (this.dom) - this.widget.destroy(this.dom); - } - covers(side) { - let { startSide, endSide } = this.deco; - return startSide == endSide ? false : side < 0 ? startSide < 0 : endSide > 0; - } - } - class BlockGapWidget extends WidgetType { - constructor(height) { - super(); - this.height = height; - } - toDOM() { - let elt = document.createElement("div"); - elt.className = "cm-gap"; - this.updateDOM(elt); - return elt; - } - eq(other) { return other.height == this.height; } - updateDOM(elt) { - elt.style.height = this.height + "px"; - return true; - } - get editable() { return true; } - get estimatedHeight() { return this.height; } - ignoreEvent() { return false; } - } - - class ContentBuilder { - constructor(doc, pos, end, disallowBlockEffectsFor) { - this.doc = doc; - this.pos = pos; - this.end = end; - this.disallowBlockEffectsFor = disallowBlockEffectsFor; - this.content = []; - this.curLine = null; - this.breakAtStart = 0; - this.pendingBuffer = 0 /* Buf.No */; - this.bufferMarks = []; - // Set to false directly after a widget that covers the position after it - this.atCursorPos = true; - this.openStart = -1; - this.openEnd = -1; - this.text = ""; - this.textOff = 0; - this.cursor = doc.iter(); - this.skip = pos; - } - posCovered() { - if (this.content.length == 0) - return !this.breakAtStart && this.doc.lineAt(this.pos).from != this.pos; - let last = this.content[this.content.length - 1]; - return !(last.breakAfter || last instanceof BlockWidgetView && last.deco.endSide < 0); - } - getLine() { - if (!this.curLine) { - this.content.push(this.curLine = new LineView); - this.atCursorPos = true; - } - return this.curLine; - } - flushBuffer(active = this.bufferMarks) { - if (this.pendingBuffer) { - this.curLine.append(wrapMarks(new WidgetBufferView(-1), active), active.length); - this.pendingBuffer = 0 /* Buf.No */; - } - } - addBlockWidget(view) { - this.flushBuffer(); - this.curLine = null; - this.content.push(view); - } - finish(openEnd) { - if (this.pendingBuffer && openEnd <= this.bufferMarks.length) - this.flushBuffer(); - else - this.pendingBuffer = 0 /* Buf.No */; - if (!this.posCovered() && - !(openEnd && this.content.length && this.content[this.content.length - 1] instanceof BlockWidgetView)) - this.getLine(); - } - buildText(length, active, openStart) { - while (length > 0) { - if (this.textOff == this.text.length) { - let { value, lineBreak, done } = this.cursor.next(this.skip); - this.skip = 0; - if (done) - throw new Error("Ran out of text content when drawing inline views"); - if (lineBreak) { - if (!this.posCovered()) - this.getLine(); - if (this.content.length) - this.content[this.content.length - 1].breakAfter = 1; - else - this.breakAtStart = 1; - this.flushBuffer(); - this.curLine = null; - this.atCursorPos = true; - length--; - continue; - } - else { - this.text = value; - this.textOff = 0; - } - } - let remaining = Math.min(this.text.length - this.textOff, length); - let take = Math.min(remaining, 512 /* T.Chunk */); - this.flushBuffer(active.slice(active.length - openStart)); - this.getLine().append(wrapMarks(new TextView(this.text.slice(this.textOff, this.textOff + take)), active), openStart); - this.atCursorPos = true; - this.textOff += take; - length -= take; - openStart = remaining <= take ? 0 : active.length; - } - } - span(from, to, active, openStart) { - this.buildText(to - from, active, openStart); - this.pos = to; - if (this.openStart < 0) - this.openStart = openStart; - } - point(from, to, deco, active, openStart, index) { - if (this.disallowBlockEffectsFor[index] && deco instanceof PointDecoration) { - if (deco.block) - throw new RangeError("Block decorations may not be specified via plugins"); - if (to > this.doc.lineAt(this.pos).to) - throw new RangeError("Decorations that replace line breaks may not be specified via plugins"); - } - let len = to - from; - if (deco instanceof PointDecoration) { - if (deco.block) { - if (deco.startSide > 0 && !this.posCovered()) - this.getLine(); - this.addBlockWidget(new BlockWidgetView(deco.widget || NullWidget.block, len, deco)); - } - else { - let view = WidgetView.create(deco.widget || NullWidget.inline, len, len ? 0 : deco.startSide); - let cursorBefore = this.atCursorPos && !view.isEditable && openStart <= active.length && - (from < to || deco.startSide > 0); - let cursorAfter = !view.isEditable && (from < to || openStart > active.length || deco.startSide <= 0); - let line = this.getLine(); - if (this.pendingBuffer == 2 /* Buf.IfCursor */ && !cursorBefore && !view.isEditable) - this.pendingBuffer = 0 /* Buf.No */; - this.flushBuffer(active); - if (cursorBefore) { - line.append(wrapMarks(new WidgetBufferView(1), active), openStart); - openStart = active.length + Math.max(0, openStart - active.length); - } - line.append(wrapMarks(view, active), openStart); - this.atCursorPos = cursorAfter; - this.pendingBuffer = !cursorAfter ? 0 /* Buf.No */ : from < to || openStart > active.length ? 1 /* Buf.Yes */ : 2 /* Buf.IfCursor */; - if (this.pendingBuffer) - this.bufferMarks = active.slice(); - } - } - else if (this.doc.lineAt(this.pos).from == this.pos) { // Line decoration - this.getLine().addLineDeco(deco); - } - if (len) { - // Advance the iterator past the replaced content - if (this.textOff + len <= this.text.length) { - this.textOff += len; - } - else { - this.skip += len - (this.text.length - this.textOff); - this.text = ""; - this.textOff = 0; - } - this.pos = to; - } - if (this.openStart < 0) - this.openStart = openStart; - } - static build(text, from, to, decorations, dynamicDecorationMap) { - let builder = new ContentBuilder(text, from, to, dynamicDecorationMap); - builder.openEnd = RangeSet.spans(decorations, from, to, builder); - if (builder.openStart < 0) - builder.openStart = builder.openEnd; - builder.finish(builder.openEnd); - return builder; - } - } - function wrapMarks(view, active) { - for (let mark of active) - view = new MarkView(mark, [view], view.length); - return view; - } - class NullWidget extends WidgetType { - constructor(tag) { - super(); - this.tag = tag; - } - eq(other) { return other.tag == this.tag; } - toDOM() { return document.createElement(this.tag); } - updateDOM(elt) { return elt.nodeName.toLowerCase() == this.tag; } - get isHidden() { return true; } - } - NullWidget.inline = /*@__PURE__*/new NullWidget("span"); - NullWidget.block = /*@__PURE__*/new NullWidget("div"); /** Used to indicate [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection). @@ -6848,6 +5782,7 @@ var lsp = (function (exports) { const contentAttributes = /*@__PURE__*/Facet.define(); // Provide decorations const decorations = /*@__PURE__*/Facet.define(); + const blockWrappers = /*@__PURE__*/Facet.define(); const outerDecorations = /*@__PURE__*/Facet.define(); const atomicRanges = /*@__PURE__*/Facet.define(); const bidiIsolatedRanges = /*@__PURE__*/Facet.define(); @@ -6924,29 +5859,44 @@ var lsp = (function (exports) { set.splice(i, 0, me); return set; } + // Extend a set to cover all the content in `ranges`, which is a + // flat array with each pair of numbers representing fromB/toB + // positions. These pairs are generated in unchanged ranges, so the + // offset between doc A and doc B is the same for their start and + // end points. static extendWithRanges(diff, ranges) { if (ranges.length == 0) return diff; let result = []; - for (let dI = 0, rI = 0, posA = 0, posB = 0;; dI++) { - let next = dI == diff.length ? null : diff[dI], off = posA - posB; - let end = next ? next.fromB : 1e9; - while (rI < ranges.length && ranges[rI] < end) { - let from = ranges[rI], to = ranges[rI + 1]; - let fromB = Math.max(posB, from), toB = Math.min(end, to); - if (fromB <= toB) - new ChangedRange(fromB + off, toB + off, fromB, toB).addToSet(result); - if (to > end) - break; - else + for (let dI = 0, rI = 0, off = 0;;) { + let nextD = dI < diff.length ? diff[dI].fromB : 1e9; + let nextR = rI < ranges.length ? ranges[rI] : 1e9; + let fromB = Math.min(nextD, nextR); + if (fromB == 1e9) + break; + let fromA = fromB + off, toB = fromB, toA = fromA; + for (;;) { + if (rI < ranges.length && ranges[rI] <= toB) { + let end = ranges[rI + 1]; rI += 2; + toB = Math.max(toB, end); + for (let i = dI; i < diff.length && diff[i].fromB <= toB; i++) + off = diff[i].toA - diff[i].toB; + toA = Math.max(toA, end + off); + } + else if (dI < diff.length && diff[dI].fromB <= toB) { + let next = diff[dI++]; + toB = Math.max(toB, next.toB); + toA = Math.max(toA, next.toA); + off = next.toA - next.toB; + } + else { + break; + } } - if (!next) - return result; - new ChangedRange(next.fromA, next.toA, next.fromB, next.toB).addToSet(result); - posA = next.toA; - posB = next.toB; + result.push(new ChangedRange(fromA, toA, fromB, toB)); } + return result; } } /** @@ -7043,16 +5993,1164 @@ var lsp = (function (exports) { get empty() { return this.flags == 0 && this.transactions.length == 0; } } - class DocView extends ContentView { - get length() { return this.view.state.doc.length; } + const noChildren = []; + class Tile { + constructor(dom, length, flags = 0) { + this.dom = dom; + this.length = length; + this.flags = flags; + this.parent = null; + dom.cmTile = this; + } + get breakAfter() { return (this.flags & 1 /* TileFlag.BreakAfter */); } + get children() { return noChildren; } + isWidget() { return false; } + get isHidden() { return false; } + isComposite() { return false; } + isLine() { return false; } + isText() { return false; } + isBlock() { return false; } + get domAttrs() { return null; } + sync(track) { + this.flags |= 2 /* TileFlag.Synced */; + if (this.flags & 4 /* TileFlag.AttrsDirty */) { + this.flags &= -5 /* TileFlag.AttrsDirty */; + let attrs = this.domAttrs; + if (attrs) + setAttrs(this.dom, attrs); + } + } + toString() { + return this.constructor.name + (this.children.length ? `(${this.children})` : "") + (this.breakAfter ? "#" : ""); + } + destroy() { this.parent = null; } + setDOM(dom) { + this.dom = dom; + dom.cmTile = this; + } + get posAtStart() { + return this.parent ? this.parent.posBefore(this) : 0; + } + get posAtEnd() { + return this.posAtStart + this.length; + } + posBefore(tile, start = this.posAtStart) { + let pos = start; + for (let child of this.children) { + if (child == tile) + return pos; + pos += child.length + child.breakAfter; + } + throw new RangeError("Invalid child in posBefore"); + } + posAfter(tile) { + return this.posBefore(tile) + tile.length; + } + covers(side) { return true; } + coordsIn(pos, side) { return null; } + domPosFor(off, side) { + let index = domIndex(this.dom); + let after = this.length ? off > 0 : side > 0; + return new DOMPos(this.parent.dom, index + (after ? 1 : 0), off == 0 || off == this.length); + } + markDirty(attrs) { + this.flags &= -3 /* TileFlag.Synced */; + if (attrs) + this.flags |= 4 /* TileFlag.AttrsDirty */; + if (this.parent && (this.parent.flags & 2 /* TileFlag.Synced */)) + this.parent.markDirty(false); + } + get overrideDOMText() { return null; } + get root() { + for (let t = this; t; t = t.parent) + if (t instanceof DocTile) + return t; + return null; + } + static get(dom) { + return dom.cmTile; + } + } + class CompositeTile extends Tile { + constructor(dom) { + super(dom, 0); + this._children = []; + } + isComposite() { return true; } + get children() { return this._children; } + get lastChild() { return this.children.length ? this.children[this.children.length - 1] : null; } + append(child) { + this.children.push(child); + child.parent = this; + } + sync(track) { + if (this.flags & 2 /* TileFlag.Synced */) + return; + super.sync(track); + let parent = this.dom, prev = null, next; + let tracking = (track === null || track === void 0 ? void 0 : track.node) == parent ? track : null; + let length = 0; + for (let child of this.children) { + child.sync(track); + length += child.length + child.breakAfter; + next = prev ? prev.nextSibling : parent.firstChild; + if (tracking && next != child.dom) + tracking.written = true; + if (child.dom.parentNode == parent) { + while (next && next != child.dom) + next = rm$1(next); + } + else { + parent.insertBefore(child.dom, next); + } + prev = child.dom; + } + next = prev ? prev.nextSibling : parent.firstChild; + if (tracking && next) + tracking.written = true; + while (next) + next = rm$1(next); + this.length = length; + } + } + // Remove a DOM node and return its next sibling. + function rm$1(dom) { + let next = dom.nextSibling; + dom.parentNode.removeChild(dom); + return next; + } + // The top-level tile. Its dom property equals view.contentDOM. + class DocTile extends CompositeTile { + constructor(view, dom) { + super(dom); + this.view = view; + } + owns(tile) { + for (; tile; tile = tile.parent) + if (tile == this) + return true; + return false; + } + isBlock() { return true; } + nearest(dom) { + for (;;) { + if (!dom) + return null; + let tile = Tile.get(dom); + if (tile && this.owns(tile)) + return tile; + dom = dom.parentNode; + } + } + blockTiles(f) { + for (let stack = [], cur = this, i = 0, pos = 0;;) { + if (i == cur.children.length) { + if (!stack.length) + return; + cur = cur.parent; + if (cur.breakAfter) + pos++; + i = stack.pop(); + } + else { + let next = cur.children[i++]; + if (next instanceof BlockWrapperTile) { + stack.push(i); + cur = next; + i = 0; + } + else { + let end = pos + next.length; + let result = f(next, pos); + if (result !== undefined) + return result; + pos = end + next.breakAfter; + } + } + } + } + // Find the block at the given position. If side < -1, make sure to + // stay before block widgets at that position, if side > 1, after + // such widgets (used for selection drawing, which needs to be able + // to get coordinates for positions that aren't valid cursor positions). + resolveBlock(pos, side) { + let before, beforeOff = -1, after, afterOff = -1; + this.blockTiles((tile, off) => { + let end = off + tile.length; + if (pos >= off && pos <= end) { + if (tile.isWidget() && side >= -1 && side <= 1) { + if (tile.flags & 32 /* TileFlag.After */) + return true; + if (tile.flags & 16 /* TileFlag.Before */) + before = undefined; + } + if ((off < pos || pos == end && (side < -1 ? tile.length : tile.covers(1))) && + (!before || !tile.isWidget() && before.isWidget())) { + before = tile; + beforeOff = pos - off; + } + if ((end > pos || pos == off && (side > 1 ? tile.length : tile.covers(-1))) && + (!after || !tile.isWidget() && after.isWidget())) { + after = tile; + afterOff = pos - off; + } + } + }); + if (!before && !after) + throw new Error("No tile at position " + pos); + return before && side < 0 || !after ? { tile: before, offset: beforeOff } : { tile: after, offset: afterOff }; + } + } + class BlockWrapperTile extends CompositeTile { + constructor(dom, wrapper) { + super(dom); + this.wrapper = wrapper; + } + isBlock() { return true; } + covers(side) { + if (!this.children.length) + return false; + return side < 0 ? this.children[0].covers(-1) : this.lastChild.covers(1); + } + get domAttrs() { return this.wrapper.attributes; } + static of(wrapper, dom) { + let tile = new BlockWrapperTile(dom || document.createElement(wrapper.tagName), wrapper); + if (!dom) + tile.flags |= 4 /* TileFlag.AttrsDirty */; + return tile; + } + } + class LineTile extends CompositeTile { + constructor(dom, attrs) { + super(dom); + this.attrs = attrs; + } + isLine() { return true; } + static start(attrs, dom, keepAttrs) { + let line = new LineTile(dom || document.createElement("div"), attrs); + if (!dom || !keepAttrs) + line.flags |= 4 /* TileFlag.AttrsDirty */; + return line; + } + get domAttrs() { return this.attrs; } + // Find the tile associated with a given position in this line. + resolveInline(pos, side, forCoords) { + let before = null, beforeOff = -1, after = null, afterOff = -1; + function scan(tile, pos) { + for (let i = 0, off = 0; i < tile.children.length && off <= pos; i++) { + let child = tile.children[i], end = off + child.length; + if (end >= pos) { + if (child.isComposite()) { + scan(child, pos - off); + } + else if ((!after || after.isHidden && (side > 0 || forCoords && onSameLine(after, child))) && + (end > pos || (child.flags & 32 /* TileFlag.After */))) { + after = child; + afterOff = pos - off; + } + else if (off < pos || (child.flags & 16 /* TileFlag.Before */) && !child.isHidden) { + before = child; + beforeOff = pos - off; + } + } + off = end; + } + } + scan(this, pos); + let target = ((side < 0 ? before : after) || before || after); + return target ? { tile: target, offset: target == before ? beforeOff : afterOff } : null; + } + coordsIn(pos, side) { + let found = this.resolveInline(pos, side, true); + if (!found) + return fallbackRect(this); + return found.tile.coordsIn(Math.max(0, found.offset), side); + } + domIn(pos, side) { + let found = this.resolveInline(pos, side); + if (found) { + let { tile, offset } = found; + if (this.dom.contains(tile.dom)) { + if (tile.isText()) + return new DOMPos(tile.dom, Math.min(tile.dom.nodeValue.length, offset)); + return tile.domPosFor(offset, tile.flags & 16 /* TileFlag.Before */ ? 1 : tile.flags & 32 /* TileFlag.After */ ? -1 : side); + } + let parent = found.tile.parent, saw = false; + for (let ch of parent.children) { + if (saw) + return new DOMPos(ch.dom, 0); + if (ch == found.tile) { + saw = true; + } + } + } + return new DOMPos(this.dom, 0); + } + } + function fallbackRect(tile) { + let last = tile.dom.lastChild; + if (!last) + return tile.dom.getBoundingClientRect(); + let rects = clientRectsFor(last); + return rects[rects.length - 1] || null; + } + function onSameLine(a, b) { + let posA = a.coordsIn(0, 1), posB = b.coordsIn(0, 1); + return posA && posB && posB.top < posA.bottom; + } + class MarkTile extends CompositeTile { + constructor(dom, mark) { + super(dom); + this.mark = mark; + } + get domAttrs() { return this.mark.attrs; } + static of(mark, dom) { + let tile = new MarkTile(dom || document.createElement(mark.tagName), mark); + if (!dom) + tile.flags |= 4 /* TileFlag.AttrsDirty */; + return tile; + } + } + class TextTile extends Tile { + constructor(dom, text) { + super(dom, text.length); + this.text = text; + } + sync(track) { + if (this.flags & 2 /* TileFlag.Synced */) + return; + super.sync(track); + if (this.dom.nodeValue != this.text) { + if (track && track.node == this.dom) + track.written = true; + this.dom.nodeValue = this.text; + } + } + isText() { return true; } + toString() { return JSON.stringify(this.text); } + coordsIn(pos, side) { + let length = this.dom.nodeValue.length; + if (pos > length) + pos = length; + let from = pos, to = pos, flatten = 0; + if (pos == 0 && side < 0 || pos == length && side >= 0) { + if (!(browser.chrome || browser.gecko)) { // These browsers reliably return valid rectangles for empty ranges + if (pos) { + from--; + flatten = 1; + } // FIXME this is wrong in RTL text + else if (to < length) { + to++; + flatten = -1; + } + } + } + else { + if (side < 0) + from--; + else if (to < length) + to++; + } + let rects = textRange(this.dom, from, to).getClientRects(); + if (!rects.length) + return null; + let rect = rects[(flatten ? flatten < 0 : side >= 0) ? 0 : rects.length - 1]; + if (browser.safari && !flatten && rect.width == 0) + rect = Array.prototype.find.call(rects, r => r.width) || rect; + return flatten ? flattenRect(rect, flatten < 0) : rect || null; + } + static of(text, dom) { + let tile = new TextTile(dom || document.createTextNode(text), text); + if (!dom) + tile.flags |= 2 /* TileFlag.Synced */; + return tile; + } + } + class WidgetTile extends Tile { + constructor(dom, length, widget, flags) { + super(dom, length, flags); + this.widget = widget; + } + isWidget() { return true; } + get isHidden() { return this.widget.isHidden; } + covers(side) { + if (this.flags & 48 /* TileFlag.PointWidget */) + return false; + return (this.flags & (side < 0 ? 64 /* TileFlag.IncStart */ : 128 /* TileFlag.IncEnd */)) > 0; + } + coordsIn(pos, side) { return this.coordsInWidget(pos, side, false); } + coordsInWidget(pos, side, block) { + let custom = this.widget.coordsAt(this.dom, pos, side); + if (custom) + return custom; + if (block) { + return flattenRect(this.dom.getBoundingClientRect(), this.length ? pos == 0 : side <= 0); + } + else { + let rects = this.dom.getClientRects(), rect = null; + if (!rects.length) + return null; + let fromBack = (this.flags & 16 /* TileFlag.Before */) ? true : (this.flags & 32 /* TileFlag.After */) ? false : pos > 0; + for (let i = fromBack ? rects.length - 1 : 0;; i += (fromBack ? -1 : 1)) { + rect = rects[i]; + if (pos > 0 ? i == 0 : i == rects.length - 1 || rect.top < rect.bottom) + break; + } + return flattenRect(rect, !fromBack); + } + } + get overrideDOMText() { + if (!this.length) + return Text.empty; + let { root } = this; + if (!root) + return Text.empty; + let start = this.posAtStart; + return root.view.state.doc.slice(start, start + this.length); + } + destroy() { + super.destroy(); + this.widget.destroy(this.dom); + } + static of(widget, view, length, flags, dom) { + if (!dom) { + dom = widget.toDOM(view); + if (!widget.editable) + dom.contentEditable = "false"; + } + return new WidgetTile(dom, length, widget, flags); + } + } + // These are drawn around uneditable widgets to avoid a number of + // browser bugs that show up when the cursor is directly next to + // uneditable inline content. + class WidgetBufferTile extends Tile { + constructor(flags) { + let img = document.createElement("img"); + img.className = "cm-widgetBuffer"; + img.setAttribute("aria-hidden", "true"); + super(img, 0, flags); + } + get isHidden() { return true; } + get overrideDOMText() { return Text.empty; } + coordsIn(pos) { return this.dom.getBoundingClientRect(); } + } + // Represents a position in the tile tree. + class TilePointer { + constructor(top) { + this.index = 0; + this.beforeBreak = false; + this.parents = []; + this.tile = top; + } + // Advance by the given distance. If side is -1, stop leaving or + // entering tiles, or skipping zero-length tiles, once the distance + // has been traversed. When side is 1, leave, enter, or skip + // everything at the end position. + advance(dist, side, walker) { + let { tile, index, beforeBreak, parents } = this; + while (dist || side > 0) { + if (!tile.isComposite()) { + if (index == tile.length) { + beforeBreak = !!tile.breakAfter; + ({ tile, index } = parents.pop()); + index++; + } + else if (!dist) { + break; + } + else { + let take = Math.min(dist, tile.length - index); + if (walker) + walker.skip(tile, index, index + take); + dist -= take; + index += take; + } + } + else if (beforeBreak) { + if (!dist) + break; + if (walker) + walker.break(); + dist--; + beforeBreak = false; + } + else if (index == tile.children.length) { + if (!dist && !parents.length) + break; + if (walker) + walker.leave(tile); + beforeBreak = !!tile.breakAfter; + ({ tile, index } = parents.pop()); + index++; + } + else { + let next = tile.children[index], brk = next.breakAfter; + if ((side > 0 ? next.length <= dist : next.length < dist) && + (!walker || walker.skip(next, 0, next.length) !== false || !next.isComposite)) { + beforeBreak = !!brk; + index++; + dist -= next.length; + } + else { + parents.push({ tile, index }); + tile = next; + index = 0; + if (walker && next.isComposite()) + walker.enter(next); + } + } + } + this.tile = tile; + this.index = index; + this.beforeBreak = beforeBreak; + return this; + } + get root() { return (this.parents.length ? this.parents[0].tile : this.tile); } + } + + // Used to track open block wrappers + class OpenWrapper { + constructor(from, to, wrapper, rank) { + this.from = from; + this.to = to; + this.wrapper = wrapper; + this.rank = rank; + } + } + // This class builds up a new document tile using input from either + // iteration over the old tree or iteration over the document + + // decorations. The add* methods emit elements into the tile + // structure. To avoid awkward synchronization issues, marks and block + // wrappers are treated as belonging to to their content, rather than + // opened/closed independently. + // + // All composite tiles that are touched by changes are rebuilt, + // reusing as much of the old tree (either whole nodes or just DOM + // elements) as possible. The new tree is built without the Synced + // flag, and then synced (during which DOM parent/child relations are + // fixed up, text nodes filled in, and attributes added) in a second + // phase. + class TileBuilder { + constructor(cache, root, blockWrappers) { + this.cache = cache; + this.root = root; + this.blockWrappers = blockWrappers; + this.curLine = null; + this.lastBlock = null; + this.afterWidget = null; + this.pos = 0; + this.wrappers = []; + this.wrapperPos = 0; + } + addText(text, marks, openStart, tile) { + var _a; + this.flushBuffer(); + let parent = this.ensureMarks(marks, openStart); + let prev = parent.lastChild; + if (prev && prev.isText() && !(prev.flags & 8 /* TileFlag.Composition */) && prev.length + text.length < 512 /* C.Chunk */) { + this.cache.reused.set(prev, 2 /* Reused.DOM */); + let tile = parent.children[parent.children.length - 1] = new TextTile(prev.dom, prev.text + text); + tile.parent = parent; + } + else { + parent.append(tile || TextTile.of(text, (_a = this.cache.find(TextTile)) === null || _a === void 0 ? void 0 : _a.dom)); + } + this.pos += text.length; + this.afterWidget = null; + } + addComposition(composition, context) { + let line = this.curLine; + if (line.dom != context.line.dom) { + line.setDOM(this.cache.reused.has(context.line) ? freeNode(context.line.dom) : context.line.dom); + this.cache.reused.set(context.line, 2 /* Reused.DOM */); + } + let head = line; + for (let i = context.marks.length - 1; i >= 0; i--) { + let mark = context.marks[i]; + let last = head.lastChild; + if (last instanceof MarkTile && last.mark.eq(mark.mark)) { + if (last.dom != mark.dom) + last.setDOM(freeNode(mark.dom)); + head = last; + } + else { + if (this.cache.reused.get(mark)) { + let tile = Tile.get(mark.dom); + if (tile) + tile.setDOM(freeNode(mark.dom)); + } + let nw = MarkTile.of(mark.mark, mark.dom); + head.append(nw); + head = nw; + } + this.cache.reused.set(mark, 2 /* Reused.DOM */); + } + let oldTile = Tile.get(composition.text); + if (oldTile) + this.cache.reused.set(oldTile, 2 /* Reused.DOM */); + let text = new TextTile(composition.text, composition.text.nodeValue); + text.flags |= 8 /* TileFlag.Composition */; + head.append(text); + } + addInlineWidget(widget, marks, openStart) { + // Adjacent same-side-facing non-replacing widgets don't need buffers between them + let noSpace = this.afterWidget && (widget.flags & 48 /* TileFlag.PointWidget */) && + (this.afterWidget.flags & 48 /* TileFlag.PointWidget */) == (widget.flags & 48 /* TileFlag.PointWidget */); + if (!noSpace) + this.flushBuffer(); + let parent = this.ensureMarks(marks, openStart); + if (!noSpace && !(widget.flags & 16 /* TileFlag.Before */)) + parent.append(this.getBuffer(1)); + parent.append(widget); + this.pos += widget.length; + this.afterWidget = widget; + } + addMark(tile, marks, openStart) { + this.flushBuffer(); + let parent = this.ensureMarks(marks, openStart); + parent.append(tile); + this.pos += tile.length; + this.afterWidget = null; + } + addBlockWidget(widget) { + this.getBlockPos().append(widget); + this.pos += widget.length; + this.lastBlock = widget; + this.endLine(); + } + continueWidget(length) { + let widget = this.afterWidget || this.lastBlock; + widget.length += length; + this.pos += length; + } + addLineStart(attrs, dom) { + var _a; + if (!attrs) + attrs = lineBaseAttrs; + let tile = LineTile.start(attrs, dom || ((_a = this.cache.find(LineTile)) === null || _a === void 0 ? void 0 : _a.dom), !!dom); + this.getBlockPos().append(this.lastBlock = this.curLine = tile); + } + addLine(tile) { + this.getBlockPos().append(tile); + this.pos += tile.length; + this.lastBlock = tile; + this.endLine(); + } + addBreak() { + this.lastBlock.flags |= 1 /* TileFlag.BreakAfter */; + this.endLine(); + this.pos++; + } + addLineStartIfNotCovered(attrs) { + if (!this.blockPosCovered()) + this.addLineStart(attrs); + } + ensureLine(attrs) { + if (!this.curLine) + this.addLineStart(attrs); + } + ensureMarks(marks, openStart) { + var _a; + let parent = this.curLine; + for (let i = marks.length - 1; i >= 0; i--) { + let mark = marks[i], last; + if (openStart > 0 && (last = parent.lastChild) && last instanceof MarkTile && last.mark.eq(mark)) { + parent = last; + openStart--; + } + else { + let tile = MarkTile.of(mark, (_a = this.cache.find(MarkTile, m => m.mark.eq(mark))) === null || _a === void 0 ? void 0 : _a.dom); + parent.append(tile); + parent = tile; + openStart = 0; + } + } + return parent; + } + endLine() { + if (this.curLine) { + this.flushBuffer(); + let last = this.curLine.lastChild; + if (!last || !hasContent(this.curLine, false) || + last.dom.nodeName != "BR" && last.isWidget() && !(browser.ios && hasContent(this.curLine, true))) + this.curLine.append(this.cache.findWidget(BreakWidget, 0, 32 /* TileFlag.After */) || + new WidgetTile(BreakWidget.toDOM(), 0, BreakWidget, 32 /* TileFlag.After */)); + this.curLine = this.afterWidget = null; + } + } + updateBlockWrappers() { + if (this.wrapperPos > this.pos + 10000 /* C.WrapperReset */) { + this.blockWrappers.goto(this.pos); + this.wrappers.length = 0; + } + for (let i = this.wrappers.length - 1; i >= 0; i--) + if (this.wrappers[i].to < this.pos) + this.wrappers.splice(i, 1); + for (let cur = this.blockWrappers; cur.value && cur.from <= this.pos; cur.next()) + if (cur.to >= this.pos) { + let wrap = new OpenWrapper(cur.from, cur.to, cur.value, cur.rank), i = this.wrappers.length; + while (i > 0 && (this.wrappers[i - 1].rank - wrap.rank || this.wrappers[i - 1].to - wrap.to) < 0) + i--; + this.wrappers.splice(i, 0, wrap); + } + this.wrapperPos = this.pos; + } + getBlockPos() { + var _a; + this.updateBlockWrappers(); + let parent = this.root; + for (let wrap of this.wrappers) { + let last = parent.lastChild; + if (wrap.from < this.pos && last instanceof BlockWrapperTile && last.wrapper.eq(wrap.wrapper)) { + parent = last; + } + else { + let tile = BlockWrapperTile.of(wrap.wrapper, (_a = this.cache.find(BlockWrapperTile, t => t.wrapper.eq(wrap.wrapper))) === null || _a === void 0 ? void 0 : _a.dom); + parent.append(tile); + parent = tile; + } + } + return parent; + } + blockPosCovered() { + let last = this.lastBlock; + return last != null && !last.breakAfter && (!last.isWidget() || (last.flags & (32 /* TileFlag.After */ | 128 /* TileFlag.IncEnd */)) > 0); + } + getBuffer(side) { + let flags = 2 /* TileFlag.Synced */ | (side < 0 ? 16 /* TileFlag.Before */ : 32 /* TileFlag.After */); + let found = this.cache.find(WidgetBufferTile, undefined, 1 /* Reused.Full */); + if (found) + found.flags = flags; + return found || new WidgetBufferTile(flags); + } + flushBuffer() { + if (this.afterWidget && !(this.afterWidget.flags & 32 /* TileFlag.After */)) { + this.afterWidget.parent.append(this.getBuffer(-1)); + this.afterWidget = null; + } + } + } + // Helps getting efficient access to the document text. + class TextStream { + constructor(doc) { + this.skipCount = 0; + this.text = ""; + this.textOff = 0; + this.cursor = doc.iter(); + } + skip(len) { + // Advance the iterator past the replaced content + if (this.textOff + len <= this.text.length) { + this.textOff += len; + } + else { + this.skipCount += len - (this.text.length - this.textOff); + this.text = ""; + this.textOff = 0; + } + } + next(maxLen) { + if (this.textOff == this.text.length) { + let { value, lineBreak, done } = this.cursor.next(this.skipCount); + this.skipCount = 0; + if (done) + throw new Error("Ran out of text content when drawing inline views"); + this.text = value; + let len = this.textOff = Math.min(maxLen, value.length); + return lineBreak ? null : value.slice(0, len); + } + let end = Math.min(this.text.length, this.textOff + maxLen); + let chars = this.text.slice(this.textOff, end); + this.textOff = end; + return chars; + } + } + // Assign the tile classes bucket numbers for caching. + const buckets = [WidgetTile, LineTile, TextTile, MarkTile, WidgetBufferTile, BlockWrapperTile, DocTile]; + for (let i = 0; i < buckets.length; i++) + buckets[i].bucket = i; + // Leaf tiles and line tiles may be reused in their entirety. All + // others will get new tiles allocated, using the old DOM when + // possible. + class TileCache { constructor(view) { + this.view = view; + // Buckets are circular buffers, using `index` as the current + // position. + this.buckets = buckets.map(() => []); + this.index = buckets.map(() => 0); + this.reused = new Map; + } + // Put a tile in the cache. + add(tile) { + let i = tile.constructor.bucket, bucket = this.buckets[i]; + if (bucket.length < 6 /* C.Bucket */) + bucket.push(tile); + else + bucket[this.index[i] = (this.index[i] + 1) % 6 /* C.Bucket */] = tile; + } + find(cls, test, type = 2 /* Reused.DOM */) { + let i = cls.bucket; + let bucket = this.buckets[i], off = this.index[i]; + for (let j = bucket.length - 1; j >= 0; j--) { + // Look at the most recently added items first (last-in, first-out) + let index = (j + off) % bucket.length, tile = bucket[index]; + if ((!test || test(tile)) && !this.reused.has(tile)) { + bucket.splice(index, 1); + if (index < off) + this.index[i]--; + this.reused.set(tile, type); + return tile; + } + } + return null; + } + findWidget(widget, length, flags) { + let widgets = this.buckets[0]; + if (widgets.length) + for (let i = 0, pass = 0;; i++) { + if (i == widgets.length) { + if (pass) + return null; + pass = 1; + i = 0; + } + let tile = widgets[i]; + if (!this.reused.has(tile) && + (pass == 0 ? tile.widget.compare(widget) + : tile.widget.constructor == widget.constructor && widget.updateDOM(tile.dom, this.view))) { + widgets.splice(i, 1); + if (i < this.index[0]) + this.index[0]--; + if (tile.widget == widget && tile.length == length && (tile.flags & (496 /* TileFlag.Widget */ | 1 /* TileFlag.BreakAfter */)) == flags) { + this.reused.set(tile, 1 /* Reused.Full */); + return tile; + } + else { + this.reused.set(tile, 2 /* Reused.DOM */); + return new WidgetTile(tile.dom, length, widget, (tile.flags & -498) | flags); + } + } + } + } + reuse(tile) { + this.reused.set(tile, 1 /* Reused.Full */); + return tile; + } + maybeReuse(tile, type = 2 /* Reused.DOM */) { + if (this.reused.has(tile)) + return undefined; + this.reused.set(tile, type); + return tile.dom; + } + clear() { + for (let i = 0; i < this.buckets.length; i++) + this.buckets[i].length = this.index[i] = 0; + } + } + // This class organizes a pass over the document, guided by the array + // of replaced ranges. For ranges that haven't changed, it iterates + // the old tree and copies its content into the new document. For + // changed ranges, it runs a decoration iterator to guide generation + // of content. + class TileUpdate { + constructor(view, old, blockWrappers, decorations, disallowBlockEffectsFor) { + this.view = view; + this.decorations = decorations; + this.disallowBlockEffectsFor = disallowBlockEffectsFor; + this.openWidget = false; + this.openMarks = 0; + this.cache = new TileCache(view); + this.text = new TextStream(view.state.doc); + this.builder = new TileBuilder(this.cache, new DocTile(view, view.contentDOM), RangeSet.iter(blockWrappers)); + this.cache.reused.set(old, 2 /* Reused.DOM */); + this.old = new TilePointer(old); + this.reuseWalker = { + skip: (tile, from, to) => { + this.cache.add(tile); + if (tile.isComposite()) + return false; + }, + enter: tile => this.cache.add(tile), + leave: () => { }, + break: () => { } + }; + } + run(changes, composition) { + let compositionContext = composition && this.getCompositionContext(composition.text); + for (let posA = 0, posB = 0, i = 0;;) { + let next = i < changes.length ? changes[i++] : null; + let skipA = next ? next.fromA : this.old.root.length; + if (skipA > posA) { + let len = skipA - posA; + this.preserve(len, !i, !next); + posA = skipA; + posB += len; + } + if (!next) + break; + // Compositions need to be handled specially, forcing the + // focused text node and its parent nodes to remain stable at + // that point in the document. + if (composition && next.fromA <= composition.range.fromA && next.toA >= composition.range.toA) { + this.forward(next.fromA, composition.range.fromA, composition.range.fromA < composition.range.toA ? 1 : -1); + this.emit(posB, composition.range.fromB); + this.cache.clear(); // Must not reuse DOM across composition + this.builder.addComposition(composition, compositionContext); + this.text.skip(composition.range.toB - composition.range.fromB); + this.forward(composition.range.fromA, next.toA); + this.emit(composition.range.toB, next.toB); + } + else { + this.forward(next.fromA, next.toA); + this.emit(posB, next.toB); + } + posB = next.toB; + posA = next.toA; + } + if (this.builder.curLine) + this.builder.endLine(); + return this.builder.root; + } + preserve(length, incStart, incEnd) { + let activeMarks = getMarks(this.old), openMarks = this.openMarks; + this.old.advance(length, incEnd ? 1 : -1, { + skip: (tile, from, to) => { + if (tile.isWidget()) { + if (this.openWidget) { + this.builder.continueWidget(to - from); + } + else { + let widget = to > 0 || from < tile.length + ? WidgetTile.of(tile.widget, this.view, to - from, tile.flags & 496 /* TileFlag.Widget */, this.cache.maybeReuse(tile)) + : this.cache.reuse(tile); + if (widget.flags & 256 /* TileFlag.Block */) { + widget.flags &= -2 /* TileFlag.BreakAfter */; + this.builder.addBlockWidget(widget); + } + else { + this.builder.ensureLine(null); + this.builder.addInlineWidget(widget, activeMarks, openMarks); + openMarks = activeMarks.length; + } + } + } + else if (tile.isText()) { + this.builder.ensureLine(null); + if (!from && to == tile.length) { + this.builder.addText(tile.text, activeMarks, openMarks, this.cache.reuse(tile)); + } + else { + this.cache.add(tile); + this.builder.addText(tile.text.slice(from, to), activeMarks, openMarks); + } + openMarks = activeMarks.length; + } + else if (tile.isLine()) { + tile.flags &= -2 /* TileFlag.BreakAfter */; + this.cache.reused.set(tile, 1 /* Reused.Full */); + this.builder.addLine(tile); + } + else if (tile instanceof WidgetBufferTile) { + this.cache.add(tile); + } + else if (tile instanceof MarkTile) { + this.builder.ensureLine(null); + this.builder.addMark(tile, activeMarks, openMarks); + this.cache.reused.set(tile, 1 /* Reused.Full */); + openMarks = activeMarks.length; + } + else { + return false; + } + this.openWidget = false; + }, + enter: (tile) => { + if (tile.isLine()) { + this.builder.addLineStart(tile.attrs, this.cache.maybeReuse(tile)); + } + else { + this.cache.add(tile); + if (tile instanceof MarkTile) + activeMarks.unshift(tile.mark); + } + this.openWidget = false; + }, + leave: (tile) => { + if (tile.isLine()) { + if (activeMarks.length) + activeMarks.length = openMarks = 0; + } + else if (tile instanceof MarkTile) { + activeMarks.shift(); + openMarks = Math.min(openMarks, activeMarks.length); + } + }, + break: () => { + this.builder.addBreak(); + this.openWidget = false; + }, + }); + this.text.skip(length); + } + emit(from, to) { + let pendingLineAttrs = null; + let b = this.builder, markCount = 0; + let openEnd = RangeSet.spans(this.decorations, from, to, { + point: (from, to, deco, active, openStart, index) => { + if (deco instanceof PointDecoration) { + if (this.disallowBlockEffectsFor[index]) { + if (deco.block) + throw new RangeError("Block decorations may not be specified via plugins"); + if (to > this.view.state.doc.lineAt(from).to) + throw new RangeError("Decorations that replace line breaks may not be specified via plugins"); + } + markCount = active.length; + if (openStart > active.length) { + b.continueWidget(to - from); + } + else { + let widget = deco.widget || (deco.block ? NullWidget.block : NullWidget.inline); + let flags = widgetFlags(deco); + let tile = this.cache.findWidget(widget, to - from, flags) || WidgetTile.of(widget, this.view, to - from, flags); + if (deco.block) { + if (deco.startSide > 0) + b.addLineStartIfNotCovered(pendingLineAttrs); + b.addBlockWidget(tile); + } + else { + b.ensureLine(pendingLineAttrs); + b.addInlineWidget(tile, active, openStart); + } + } + pendingLineAttrs = null; + } + else { + pendingLineAttrs = addLineDeco(pendingLineAttrs, deco); + } + if (to > from) + this.text.skip(to - from); + }, + span: (from, to, active, openStart) => { + for (let pos = from; pos < to;) { + let chars = this.text.next(Math.min(512 /* C.Chunk */, to - pos)); + if (chars == null) { // Line break + b.addLineStartIfNotCovered(pendingLineAttrs); + b.addBreak(); + pos++; + } + else { + b.ensureLine(pendingLineAttrs); + b.addText(chars, active, pos == from ? openStart : active.length); + pos += chars.length; + } + pendingLineAttrs = null; + } + } + }); + b.addLineStartIfNotCovered(pendingLineAttrs); + this.openWidget = openEnd > markCount; + this.openMarks = openEnd; + } + forward(from, to, side = 1) { + if (to - from <= 10) { + this.old.advance(to - from, side, this.reuseWalker); + } + else { + this.old.advance(5, -1, this.reuseWalker); + this.old.advance(to - from - 10, -1); + this.old.advance(5, side, this.reuseWalker); + } + } + getCompositionContext(text) { + let marks = [], line = null; + for (let parent = text.parentNode;; parent = parent.parentNode) { + let tile = Tile.get(parent); + if (parent == this.view.contentDOM) + break; + if (tile instanceof MarkTile) + marks.push(tile); + else if (tile === null || tile === void 0 ? void 0 : tile.isLine()) + line = tile; + else if (parent.nodeName == "DIV" && !line && parent != this.view.contentDOM) + line = new LineTile(parent, lineBaseAttrs); + else + marks.push(MarkTile.of(new MarkDecoration({ tagName: parent.nodeName.toLowerCase(), attributes: getAttrs(parent) }), parent)); + } + return { line: line, marks }; + } + } + function hasContent(tile, requireText) { + let scan = (tile) => { + for (let ch of tile.children) + if ((requireText ? ch.isText() : ch.length) || scan(ch)) + return true; + return false; + }; + return scan(tile); + } + function widgetFlags(deco) { + let flags = deco.isReplace ? (deco.startSide < 0 ? 64 /* TileFlag.IncStart */ : 0) | (deco.endSide > 0 ? 128 /* TileFlag.IncEnd */ : 0) + : (deco.startSide > 0 ? 32 /* TileFlag.After */ : 16 /* TileFlag.Before */); + if (deco.block) + flags |= 256 /* TileFlag.Block */; + return flags; + } + const lineBaseAttrs = { class: "cm-line" }; + function addLineDeco(value, deco) { + let attrs = deco.spec.attributes, cls = deco.spec.class; + if (!attrs && !cls) + return value; + if (!value) + value = { class: "cm-line" }; + if (attrs) + combineAttrs(attrs, value); + if (cls) + value.class += " " + cls; + return value; + } + function getMarks(ptr) { + let found = []; + for (let i = ptr.parents.length; i > 1; i--) { + let tile = i == ptr.parents.length ? ptr.tile : ptr.parents[i].tile; + if (tile instanceof MarkTile) + found.push(tile.mark); + } + return found; + } + function freeNode(node) { + let tile = Tile.get(node); + if (tile) + tile.setDOM(node.cloneNode()); + return node; + } + class NullWidget extends WidgetType { + constructor(tag) { super(); + this.tag = tag; + } + eq(other) { return other.tag == this.tag; } + toDOM() { return document.createElement(this.tag); } + updateDOM(elt) { return elt.nodeName.toLowerCase() == this.tag; } + get isHidden() { return true; } + } + NullWidget.inline = /*@__PURE__*/new NullWidget("span"); + NullWidget.block = /*@__PURE__*/new NullWidget("div"); + const BreakWidget = /*@__PURE__*/new class extends WidgetType { + toDOM() { return document.createElement("br"); } + get isHidden() { return true; } + get editable() { return true; } + }; + + class DocView { + constructor(view) { this.view = view; this.decorations = []; + this.blockWrappers = []; this.dynamicDecorationMap = [false]; this.domChanged = null; this.hasComposition = null; - this.markedForComposition = new Set; this.editContextFormatting = Decoration.none; this.lastCompositionAfterCursor = false; // Track a minimum width for the editor. When measuring sizes in @@ -7073,11 +7171,9 @@ var lsp = (function (exports) { // Used by the resize observer to ignore resizes that we caused // ourselves this.lastUpdate = Date.now(); - this.setDOM(view.contentDOM); - this.children = [new LineView]; - this.children[0].setParent(this); this.updateDeco(); - this.updateInner([new ChangedRange(0, 0, 0, view.state.doc.length)], 0, null); + this.tile = new DocTile(view, view.contentDOM); + this.updateInner([new ChangedRange(0, 0, 0, view.state.doc.length)], null); } // Update the document view to a given state. update(update) { @@ -7103,7 +7199,6 @@ var lsp = (function (exports) { let composition = readCompositionAt > -1 ? findCompositionRange(this.view, update.changes, readCompositionAt) : null; this.domChanged = null; if (this.hasComposition) { - this.markedForComposition.clear(); let { from, to } = this.hasComposition; changedRanges = new ChangedRange(from, to, update.changes.mapPos(from, -1), update.changes.mapPos(to, 1)) .addToSet(changedRanges.slice()); @@ -7117,14 +7212,21 @@ var lsp = (function (exports) { if ((browser.ie || browser.chrome) && !composition && update && update.state.doc.lines != update.startState.doc.lines) this.forceSelection = true; - let prevDeco = this.decorations, deco = this.updateDeco(); - let decoDiff = findChangedDeco(prevDeco, deco, update.changes); - changedRanges = ChangedRange.extendWithRanges(changedRanges, decoDiff); - if (!(this.flags & 7 /* ViewFlag.Dirty */) && changedRanges.length == 0) { + let prevDeco = this.decorations, prevWrappers = this.blockWrappers; + this.updateDeco(); + let decoDiff = findChangedDeco(prevDeco, this.decorations, update.changes); + if (decoDiff.length) + changedRanges = ChangedRange.extendWithRanges(changedRanges, decoDiff); + let blockDiff = findChangedWrappers(prevWrappers, this.blockWrappers, update.changes); + if (blockDiff.length) + changedRanges = ChangedRange.extendWithRanges(changedRanges, blockDiff); + if (composition && !changedRanges.some(r => r.fromA <= composition.range.fromA && r.toA >= composition.range.toA)) + changedRanges = composition.range.addToSet(changedRanges.slice()); + if ((this.tile.flags & 2 /* TileFlag.Synced */) && changedRanges.length == 0) { return false; } else { - this.updateInner(changedRanges, update.startState.doc.length, composition); + this.updateInner(changedRanges, composition); if (update.transactions.length) this.lastUpdate = Date.now(); return true; @@ -7132,76 +7234,39 @@ var lsp = (function (exports) { } // Used by update and the constructor do perform the actual DOM // update - updateInner(changes, oldLength, composition) { + updateInner(changes, composition) { this.view.viewState.mustMeasureContent = true; - this.updateChildren(changes, oldLength, composition); let { observer } = this.view; observer.ignore(() => { + if (composition || changes.length) { + let oldTile = this.tile; + let builder = new TileUpdate(this.view, oldTile, this.blockWrappers, this.decorations, this.dynamicDecorationMap); + this.tile = builder.run(changes, composition); + destroyDropped(oldTile, builder.cache.reused); + } // Lock the height during redrawing, since Chrome sometimes // messes with the scroll position during DOM mutation (though // no relayout is triggered and I cannot imagine how it can // recompute the scroll position without a layout) - this.dom.style.height = this.view.viewState.contentHeight / this.view.scaleY + "px"; - this.dom.style.flexBasis = this.minWidth ? this.minWidth + "px" : ""; + this.tile.dom.style.height = this.view.viewState.contentHeight / this.view.scaleY + "px"; + this.tile.dom.style.flexBasis = this.minWidth ? this.minWidth + "px" : ""; // Chrome will sometimes, when DOM mutations occur directly // around the selection, get confused and report a different // selection from the one it displays (issue #218). This tries // to detect that situation. let track = browser.chrome || browser.ios ? { node: observer.selectionRange.focusNode, written: false } : undefined; - this.sync(this.view, track); - this.flags &= -8 /* ViewFlag.Dirty */; - if (track && (track.written || observer.selectionRange.focusNode != track.node)) + this.tile.sync(track); + if (track && (track.written || observer.selectionRange.focusNode != track.node || !this.tile.dom.contains(track.node))) this.forceSelection = true; - this.dom.style.height = ""; + this.tile.dom.style.height = ""; }); - this.markedForComposition.forEach(cView => cView.flags &= -9 /* ViewFlag.Composition */); let gaps = []; if (this.view.viewport.from || this.view.viewport.to < this.view.state.doc.length) - for (let child of this.children) - if (child instanceof BlockWidgetView && child.widget instanceof BlockGapWidget) + for (let child of this.tile.children) + if (child.isWidget() && child.widget instanceof BlockGapWidget) gaps.push(child.dom); observer.updateGaps(gaps); } - updateChildren(changes, oldLength, composition) { - let ranges = composition ? composition.range.addToSet(changes.slice()) : changes; - let cursor = this.childCursor(oldLength); - for (let i = ranges.length - 1;; i--) { - let next = i >= 0 ? ranges[i] : null; - if (!next) - break; - let { fromA, toA, fromB, toB } = next, content, breakAtStart, openStart, openEnd; - if (composition && composition.range.fromB < toB && composition.range.toB > fromB) { - let before = ContentBuilder.build(this.view.state.doc, fromB, composition.range.fromB, this.decorations, this.dynamicDecorationMap); - let after = ContentBuilder.build(this.view.state.doc, composition.range.toB, toB, this.decorations, this.dynamicDecorationMap); - breakAtStart = before.breakAtStart; - openStart = before.openStart; - openEnd = after.openEnd; - let compLine = this.compositionView(composition); - if (after.breakAtStart) { - compLine.breakAfter = 1; - } - else if (after.content.length && - compLine.merge(compLine.length, compLine.length, after.content[0], false, after.openStart, 0)) { - compLine.breakAfter = after.content[0].breakAfter; - after.content.shift(); - } - if (before.content.length && - compLine.merge(0, 0, before.content[before.content.length - 1], true, 0, before.openEnd)) { - before.content.pop(); - } - content = before.content.concat(compLine).concat(after.content); - } - else { - ({ content, breakAtStart, openStart, openEnd } = - ContentBuilder.build(this.view.state.doc, fromB, toB, this.decorations, this.dynamicDecorationMap)); - } - let { i: toI, off: toOff } = cursor.findPos(toA, 1); - let { i: fromI, off: fromOff } = cursor.findPos(fromA, -1); - replaceRange(this, fromI, fromOff, toI, toOff, content, breakAtStart, openStart, openEnd); - } - if (composition) - this.fixCompositionDOM(composition); - } updateEditContextFormatting(update) { this.editContextFormatting = this.editContextFormatting.map(update.changes); for (let tr of update.transactions) @@ -7210,47 +7275,26 @@ var lsp = (function (exports) { this.editContextFormatting = effect.value; } } - compositionView(composition) { - let cur = new TextView(composition.text.nodeValue); - cur.flags |= 8 /* ViewFlag.Composition */; - for (let { deco } of composition.marks) - cur = new MarkView(deco, [cur], cur.length); - let line = new LineView; - line.append(cur, 0); - return line; - } - fixCompositionDOM(composition) { - let fix = (dom, cView) => { - cView.flags |= 8 /* ViewFlag.Composition */ | (cView.children.some(c => c.flags & 7 /* ViewFlag.Dirty */) ? 1 /* ViewFlag.ChildDirty */ : 0); - this.markedForComposition.add(cView); - let prev = ContentView.get(dom); - if (prev && prev != cView) - prev.dom = null; - cView.setDOM(dom); - }; - let pos = this.childPos(composition.range.fromB, 1); - let cView = this.children[pos.i]; - fix(composition.line, cView); - for (let i = composition.marks.length - 1; i >= -1; i--) { - pos = cView.childPos(pos.off, 1); - cView = cView.children[pos.i]; - fix(i >= 0 ? composition.marks[i].node : composition.text, cView); - } - } // Sync the DOM selection to this.state.selection updateSelection(mustRead = false, fromPointer = false) { if (mustRead || !this.view.observer.selectionRange.focusNode) this.view.observer.readSelectionRange(); - let activeElt = this.view.root.activeElement, focused = activeElt == this.dom; - let selectionNotFocus = !focused && !(this.view.state.facet(editable) || this.dom.tabIndex > -1) && - hasSelection(this.dom, this.view.observer.selectionRange) && !(activeElt && this.dom.contains(activeElt)); + let { dom } = this.tile; + let activeElt = this.view.root.activeElement, focused = activeElt == dom; + let selectionNotFocus = !focused && !(this.view.state.facet(editable) || dom.tabIndex > -1) && + hasSelection(dom, this.view.observer.selectionRange) && !(activeElt && dom.contains(activeElt)); if (!(focused || fromPointer || selectionNotFocus)) return; let force = this.forceSelection; this.forceSelection = false; - let main = this.view.state.selection.main; - let anchor = this.moveToLine(this.domAtPos(main.anchor)); - let head = main.empty ? anchor : this.moveToLine(this.domAtPos(main.head)); + let main = this.view.state.selection.main, anchor, head; + if (main.empty) { + head = anchor = this.inlineDOMNearPos(main.anchor, main.assoc || 1); + } + else { + head = this.inlineDOMNearPos(main.head, main.head == main.from ? 1 : -1); + anchor = this.inlineDOMNearPos(main.anchor, main.anchor == main.from ? 1 : -1); + } // Always reset on Firefox when next to an uneditable node to // avoid invisible cursor bugs (#111) if (browser.gecko && main.empty && !this.hasComposition && betweenUneditable(anchor)) { @@ -7268,10 +7312,10 @@ var lsp = (function (exports) { // inside an uneditable node, and not bring it back when we // move the cursor to its proper position. This tries to // restore the keyboard by cycling focus. - if (browser.android && browser.chrome && this.dom.contains(domSel.focusNode) && - inUneditable(domSel.focusNode, this.dom)) { - this.dom.blur(); - this.dom.focus({ preventScroll: true }); + if (browser.android && browser.chrome && dom.contains(domSel.focusNode) && + inUneditable(domSel.focusNode, dom)) { + dom.blur(); + dom.focus({ preventScroll: true }); } let rawSel = getSelection(this.view.root); if (!rawSel) ; @@ -7312,8 +7356,8 @@ var lsp = (function (exports) { rawSel.removeAllRanges(); rawSel.addRange(range); } - if (selectionNotFocus && this.view.root.activeElement == this.dom) { - this.dom.blur(); + if (selectionNotFocus && this.view.root.activeElement == dom) { + dom.blur(); if (activeElt) activeElt.focus(); } @@ -7339,7 +7383,7 @@ var lsp = (function (exports) { let { anchorNode, anchorOffset } = view.observer.selectionRange; if (!sel || !cursor.empty || !cursor.assoc || !sel.modify) return; - let line = LineView.find(this, cursor.head); + let line = this.lineAt(cursor.head, cursor.assoc); if (!line) return; let lineStart = line.posAtStart; @@ -7348,7 +7392,7 @@ var lsp = (function (exports) { let before = this.coordsAt(cursor.head, -1), after = this.coordsAt(cursor.head, 1); if (!before || !after || before.bottom > after.top) return; - let dom = this.domAtPos(cursor.head + cursor.assoc); + let dom = this.domAtPos(cursor.head + cursor.assoc, cursor.assoc); sel.collapse(dom.node, dom.offset); sel.modify("move", cursor.assoc < 0 ? "forward" : "backward", "lineboundary"); // This can go wrong in corner cases like single-character lines, @@ -7358,143 +7402,213 @@ var lsp = (function (exports) { if (view.docView.posFromDOM(newRange.anchorNode, newRange.anchorOffset) != cursor.from) sel.collapse(anchorNode, anchorOffset); } - // If a position is in/near a block widget, move it to a nearby text - // line, since we don't want the cursor inside a block widget. - moveToLine(pos) { - // Block widgets will return positions before/after them, which - // are thus directly in the document DOM element. - let dom = this.dom, newPos; - if (pos.node != dom) - return pos; - for (let i = pos.offset; !newPos && i < dom.childNodes.length; i++) { - let view = ContentView.get(dom.childNodes[i]); - if (view instanceof LineView) - newPos = view.domAtPos(0); - } - for (let i = pos.offset - 1; !newPos && i >= 0; i--) { - let view = ContentView.get(dom.childNodes[i]); - if (view instanceof LineView) - newPos = view.domAtPos(view.length); - } - return newPos ? new DOMPos(newPos.node, newPos.offset, true) : pos; - } - nearest(dom) { - for (let cur = dom; cur;) { - let domView = ContentView.get(cur); - if (domView && domView.rootView == this) - return domView; - cur = cur.parentNode; - } - return null; - } posFromDOM(node, offset) { - let view = this.nearest(node); - if (!view) - throw new RangeError("Trying to find position for a DOM position outside of the document"); - return view.localPosFromDOM(node, offset) + view.posAtStart; - } - domAtPos(pos) { - let { i, off } = this.childCursor().findPos(pos, -1); - for (; i < this.children.length - 1;) { - let child = this.children[i]; - if (off < child.length || child instanceof LineView) - break; - i++; - off = 0; + let tile = this.tile.nearest(node); + if (!tile) + return this.tile.dom.compareDocumentPosition(node) & 2 /* PRECEDING */ ? 0 : this.view.state.doc.length; + let start = tile.posAtStart; + if (tile.isComposite()) { + let after; + if (node == tile.dom) { + after = tile.dom.childNodes[offset]; + } + else { + let bias = maxOffset(node) == 0 ? 0 : offset == 0 ? -1 : 1; + for (;;) { + let parent = node.parentNode; + if (parent == tile.dom) + break; + if (bias == 0 && parent.firstChild != parent.lastChild) { + if (node == parent.firstChild) + bias = -1; + else + bias = 1; + } + node = parent; + } + if (bias < 0) + after = node; + else + after = node.nextSibling; + } + if (after == tile.dom.firstChild) + return start; + while (after && !Tile.get(after)) + after = after.nextSibling; + if (!after) + return start + tile.length; + for (let i = 0, pos = start;; i++) { + let child = tile.children[i]; + if (child.dom == after) + return pos; + pos += child.length + child.breakAfter; + } } - return this.children[i].domAtPos(off); + else if (tile.isText()) { + return node == tile.dom ? start + offset : start + (offset ? tile.length : 0); + } + else { + return start; + } + } + domAtPos(pos, side) { + let { tile, offset } = this.tile.resolveBlock(pos, side); + if (tile.isWidget()) + return tile.domPosFor(pos, side); + return tile.domIn(offset, side); + } + inlineDOMNearPos(pos, side) { + let before, beforeOff = -1, beforeBad = false; + let after, afterOff = -1, afterBad = false; + this.tile.blockTiles((tile, off) => { + if (tile.isWidget()) { + if ((tile.flags & 32 /* TileFlag.After */) && off >= pos) + return true; + if (tile.flags & 16 /* TileFlag.Before */) + beforeBad = true; + } + else { + let end = off + tile.length; + if (off <= pos) { + before = tile; + beforeOff = pos - off; + beforeBad = end < pos; + } + if (end >= pos && !after) { + after = tile; + afterOff = pos - off; + afterBad = off > pos; + } + if (off > pos && after) + return true; + } + }); + if (!before && !after) + return this.domAtPos(pos, side); + if (beforeBad && after) + before = null; + else if (afterBad && before) + after = null; + return before && side < 0 || !after ? before.domIn(beforeOff, side) : after.domIn(afterOff, side); } coordsAt(pos, side) { - let best = null, bestPos = 0; - for (let off = this.length, i = this.children.length - 1; i >= 0; i--) { - let child = this.children[i], end = off - child.breakAfter, start = end - child.length; - if (end < pos) - break; - if (start <= pos && (start < pos || child.covers(-1)) && (end > pos || child.covers(1)) && - (!best || child instanceof LineView && !(best instanceof LineView && side >= 0))) { - best = child; - bestPos = start; - } - else if (best && start == pos && end == pos && child instanceof BlockWidgetView && Math.abs(side) < 2) { - if (child.deco.startSide < 0) - break; - else if (i) - best = null; - } - off = start; + let { tile, offset } = this.tile.resolveBlock(pos, side); + if (tile.isWidget()) { + if (tile.widget instanceof BlockGapWidget) + return null; + return tile.coordsInWidget(offset, side, true); } - return best ? best.coordsAt(pos - bestPos, side) : null; + return tile.coordsIn(offset, side); + } + lineAt(pos, side) { + let { tile } = this.tile.resolveBlock(pos, side); + return tile.isLine() ? tile : null; } coordsForChar(pos) { - let { i, off } = this.childPos(pos, 1), child = this.children[i]; - if (!(child instanceof LineView)) + let { tile, offset } = this.tile.resolveBlock(pos, 1); + if (!tile.isLine()) return null; - while (child.children.length) { - let { i, off: childOff } = child.childPos(off, 1); - for (;; i++) { - if (i == child.children.length) - return null; - if ((child = child.children[i]).length) - break; + function scan(tile, offset) { + if (tile.isComposite()) { + for (let ch of tile.children) { + if (ch.length >= offset) { + let found = scan(ch, offset); + if (found) + return found; + } + offset -= ch.length; + if (offset < 0) + break; + } + } + else if (tile.isText() && offset < tile.length) { + let end = findClusterBreak(tile.text, offset); + if (end == offset) + return null; + let rects = textRange(tile.dom, offset, end).getClientRects(); + for (let i = 0; i < rects.length; i++) { + let rect = rects[i]; + if (i == rects.length - 1 || rect.top < rect.bottom && rect.left < rect.right) + return rect; + } } - off = childOff; - } - if (!(child instanceof TextView)) return null; - let end = findClusterBreak(child.text, off); - if (end == off) - return null; - let rects = textRange(child.dom, off, end).getClientRects(); - for (let i = 0; i < rects.length; i++) { - let rect = rects[i]; - if (i == rects.length - 1 || rect.top < rect.bottom && rect.left < rect.right) - return rect; } - return null; + return scan(tile, offset); } measureVisibleLineHeights(viewport) { let result = [], { from, to } = viewport; let contentWidth = this.view.contentDOM.clientWidth; let isWider = contentWidth > Math.max(this.view.scrollDOM.clientWidth, this.minWidth) + 1; let widest = -1, ltr = this.view.textDirection == Direction.LTR; - for (let pos = 0, i = 0; i < this.children.length; i++) { - let child = this.children[i], end = pos + child.length; - if (end > to) - break; - if (pos >= from) { - let childRect = child.dom.getBoundingClientRect(); - result.push(childRect.height); - if (isWider) { - let last = child.dom.lastChild; - let rects = last ? clientRectsFor(last) : []; - if (rects.length) { - let rect = rects[rects.length - 1]; - let width = ltr ? rect.right - childRect.left : childRect.right - rect.left; - if (width > widest) { - widest = width; - this.minWidth = contentWidth; - this.minWidthFrom = pos; - this.minWidthTo = end; + let spaceAbove = 0; + let scan = (tile, pos, measureBounds) => { + for (let i = 0; i < tile.children.length; i++) { + if (pos > to) + break; + let child = tile.children[i], end = pos + child.length; + let childRect = child.dom.getBoundingClientRect(), { height } = childRect; + if (measureBounds && !i) + spaceAbove += childRect.top - measureBounds.top; + if (child instanceof BlockWrapperTile) { + if (end > from) + scan(child, pos, childRect); + } + else if (pos >= from) { + if (spaceAbove > 0) + result.push(-spaceAbove); + result.push(height + spaceAbove); + spaceAbove = 0; + if (isWider) { + let last = child.dom.lastChild; + let rects = last ? clientRectsFor(last) : []; + if (rects.length) { + let rect = rects[rects.length - 1]; + let width = ltr ? rect.right - childRect.left : childRect.right - rect.left; + if (width > widest) { + widest = width; + this.minWidth = contentWidth; + this.minWidthFrom = pos; + this.minWidthTo = end; + } } } } + if (measureBounds && i == tile.children.length - 1) + spaceAbove += measureBounds.bottom - childRect.bottom; + pos = end + child.breakAfter; } - pos = end + child.breakAfter; - } + }; + scan(this.tile, 0, null); return result; } textDirectionAt(pos) { - let { i } = this.childPos(pos, 1); - return getComputedStyle(this.children[i].dom).direction == "rtl" ? Direction.RTL : Direction.LTR; + let { tile } = this.tile.resolveBlock(pos, 1); + return getComputedStyle(tile.dom).direction == "rtl" ? Direction.RTL : Direction.LTR; } measureTextSize() { - for (let child of this.children) { - if (child instanceof LineView) { - let measure = child.measureTextSize(); - if (measure) - return measure; + let lineMeasure = this.tile.blockTiles(tile => { + if (tile.isLine() && tile.children.length && tile.length <= 20) { + let totalWidth = 0, textHeight; + for (let child of tile.children) { + if (!child.isText() || /[^ -~]/.test(child.text)) + return undefined; + let rects = clientRectsFor(child.dom); + if (rects.length != 1) + return undefined; + totalWidth += rects[0].width; + textHeight = rects[0].height; + } + if (totalWidth) + return { + lineHeight: tile.dom.getBoundingClientRect().height, + charWidth: totalWidth / tile.length, + textHeight + }; } - } + }); + if (lineMeasure) + return lineMeasure; // If no workable line exists, force a layout of a measurable element let dummy = document.createElement("div"), lineHeight, charWidth, textHeight; dummy.className = "cm-line"; @@ -7502,29 +7616,20 @@ var lsp = (function (exports) { dummy.style.position = "absolute"; dummy.textContent = "abc def ghi jkl mno pqr stu"; this.view.observer.ignore(() => { - this.dom.appendChild(dummy); + this.tile.dom.appendChild(dummy); let rect = clientRectsFor(dummy.firstChild)[0]; lineHeight = dummy.getBoundingClientRect().height; - charWidth = rect ? rect.width / 27 : 7; - textHeight = rect ? rect.height : lineHeight; + charWidth = rect && rect.width ? rect.width / 27 : 7; + textHeight = rect && rect.height ? rect.height : lineHeight; dummy.remove(); }); return { lineHeight, charWidth, textHeight }; } - childCursor(pos = this.length) { - // Move back to start of last element when possible, so that - // `ChildCursor.findPos` doesn't have to deal with the edge case - // of being after the last element. - let i = this.children.length; - if (i) - pos -= this.children[--i].length; - return new ChildCursor(this.children, pos, i); - } computeBlockGapDeco() { let deco = [], vs = this.view.viewState; for (let pos = 0, i = 0;; i++) { let next = i == vs.viewports.length ? null : vs.viewports[i]; - let end = next ? next.from - 1 : this.length; + let end = next ? next.from - 1 : this.view.state.doc.length; if (end > pos) { let height = (vs.lineBlockAt(end).bottom - vs.lineBlockAt(pos).top) / this.view.scaleY; deco.push(Decoration.replace({ @@ -7564,7 +7669,7 @@ var lsp = (function (exports) { ]; while (i < this.decorations.length) this.dynamicDecorationMap[i++] = false; - return this.decorations; + this.blockWrappers = this.view.state.facet(blockWrappers).map(v => typeof v == "function" ? v(this.view) : v); } scrollIntoView(target) { if (target.isSnapshot) { @@ -7597,6 +7702,22 @@ var lsp = (function (exports) { let { offsetWidth, offsetHeight } = this.view.scrollDOM; scrollRectIntoView(this.view.scrollDOM, targetRect, range.head < range.anchor ? -1 : 1, target.x, target.y, Math.max(Math.min(target.xMargin, offsetWidth), -offsetWidth), Math.max(Math.min(target.yMargin, offsetHeight), -offsetHeight), this.view.textDirection == Direction.LTR); } + lineHasWidget(pos) { + let scan = (child) => child.isWidget() || child.children.some(scan); + return scan(this.tile.resolveBlock(pos, 1).tile); + } + destroy() { + destroyDropped(this.tile); + } + } + function destroyDropped(tile, reused) { + let r = reused === null || reused === void 0 ? void 0 : reused.get(tile); + if (r != 1 /* Reused.Full */) { + if (r == null) + tile.destroy(); + for (let ch of tile.children) + destroyDropped(ch, reused); + } } function betweenUneditable(pos) { return pos.node.nodeType == 1 && pos.node.firstChild && @@ -7611,13 +7732,13 @@ var lsp = (function (exports) { let textAfter = textNodeAfter(sel.focusNode, sel.focusOffset); let textNode = textBefore || textAfter; if (textAfter && textBefore && textAfter.node != textBefore.node) { - let descAfter = ContentView.get(textAfter.node); - if (!descAfter || descAfter instanceof TextView && descAfter.text != textAfter.node.nodeValue) { + let tileAfter = Tile.get(textAfter.node); + if (!tileAfter || tileAfter.isText() && tileAfter.text != textAfter.node.nodeValue) { textNode = textAfter; } else if (view.docView.lastCompositionAfterCursor) { - let descBefore = ContentView.get(textBefore.node); - if (!(!descBefore || descBefore instanceof TextView && descBefore.text != textBefore.node.nodeValue)) + let tileBefore = Tile.get(textBefore.node); + if (!(!tileBefore || tileBefore.isText() && tileBefore.text != textBefore.node.nodeValue)) textNode = textAfter; } } @@ -7638,23 +7759,7 @@ var lsp = (function (exports) { if (view.state.doc.sliceString(found.from, found.to) != text) return null; let inv = changes.invertedDesc; - let range = new ChangedRange(inv.mapPos(from), inv.mapPos(to), from, to); - let marks = []; - for (let parent = textNode.parentNode;; parent = parent.parentNode) { - let parentView = ContentView.get(parent); - if (parentView instanceof MarkView) - marks.push({ node: parent, deco: parentView.mark }); - else if (parentView instanceof LineView || parent.nodeName == "DIV" && parent.parentNode == view.contentDOM) - return { range, text: textNode, marks, line: parent }; - else if (parent != view.contentDOM) - marks.push({ node: parent, deco: new MarkDecoration({ - inclusive: true, - attributes: getAttrs(parent), - tagName: parent.tagName.toLowerCase() - }) }); - else - return null; - } + return { range: new ChangedRange(inv.mapPos(from), inv.mapPos(to), from, to), text: textNode }; } function nextToUneditable(node, offset) { if (node.nodeType != 1) @@ -7675,6 +7780,19 @@ var lsp = (function (exports) { RangeSet.compare(a, b, diff, comp); return comp.changes; } + class WrapperComparator { + constructor() { + this.changes = []; + } + compareRange(from, to) { addRange(from, to, this.changes); } + comparePoint() { } + boundChange(pos) { addRange(pos, pos, this.changes); } + } + function findChangedWrappers(a, b, diff) { + let comp = new WrapperComparator; + RangeSet.compare(a, b, diff, comp); + return comp.changes; + } function inUneditable(node, inside) { for (let cur = node; cur && cur != inside; cur = cur.assignedSlot || cur.parentNode) { if (cur.nodeType == 1 && cur.contentEditable == 'false') { @@ -7692,6 +7810,26 @@ var lsp = (function (exports) { }); return touched; } + class BlockGapWidget extends WidgetType { + constructor(height) { + super(); + this.height = height; + } + toDOM() { + let elt = document.createElement("div"); + elt.className = "cm-gap"; + this.updateDOM(elt); + return elt; + } + eq(other) { return other.height == this.height; } + updateDOM(elt) { + elt.style.height = this.height + "px"; + return true; + } + get editable() { return true; } + get estimatedHeight() { return this.height; } + ignoreEvent() { return false; } + } function groupAt(state, pos, bias = 1) { let categorize = state.charCategorizer(pos); @@ -7722,201 +7860,6 @@ var lsp = (function (exports) { } return EditorSelection.range(from + line.from, to + line.from); } - // Search the DOM for the {node, offset} position closest to the given - // coordinates. Very inefficient and crude, but can usually be avoided - // by calling caret(Position|Range)FromPoint instead. - function getdx(x, rect) { - return rect.left > x ? rect.left - x : Math.max(0, x - rect.right); - } - function getdy(y, rect) { - return rect.top > y ? rect.top - y : Math.max(0, y - rect.bottom); - } - function yOverlap(a, b) { - return a.top < b.bottom - 1 && a.bottom > b.top + 1; - } - function upTop(rect, top) { - return top < rect.top ? { top, left: rect.left, right: rect.right, bottom: rect.bottom } : rect; - } - function upBot(rect, bottom) { - return bottom > rect.bottom ? { top: rect.top, left: rect.left, right: rect.right, bottom } : rect; - } - function domPosAtCoords(parent, x, y) { - let closest, closestRect, closestX, closestY, closestOverlap = false; - let above, below, aboveRect, belowRect; - for (let child = parent.firstChild; child; child = child.nextSibling) { - let rects = clientRectsFor(child); - for (let i = 0; i < rects.length; i++) { - let rect = rects[i]; - if (closestRect && yOverlap(closestRect, rect)) - rect = upTop(upBot(rect, closestRect.bottom), closestRect.top); - let dx = getdx(x, rect), dy = getdy(y, rect); - if (dx == 0 && dy == 0) - return child.nodeType == 3 ? domPosInText(child, x, y) : domPosAtCoords(child, x, y); - if (!closest || closestY > dy || closestY == dy && closestX > dx) { - closest = child; - closestRect = rect; - closestX = dx; - closestY = dy; - closestOverlap = !dx ? true : x < rect.left ? i > 0 : i < rects.length - 1; - } - if (dx == 0) { - if (y > rect.bottom && (!aboveRect || aboveRect.bottom < rect.bottom)) { - above = child; - aboveRect = rect; - } - else if (y < rect.top && (!belowRect || belowRect.top > rect.top)) { - below = child; - belowRect = rect; - } - } - else if (aboveRect && yOverlap(aboveRect, rect)) { - aboveRect = upBot(aboveRect, rect.bottom); - } - else if (belowRect && yOverlap(belowRect, rect)) { - belowRect = upTop(belowRect, rect.top); - } - } - } - if (aboveRect && aboveRect.bottom >= y) { - closest = above; - closestRect = aboveRect; - } - else if (belowRect && belowRect.top <= y) { - closest = below; - closestRect = belowRect; - } - if (!closest) - return { node: parent, offset: 0 }; - let clipX = Math.max(closestRect.left, Math.min(closestRect.right, x)); - if (closest.nodeType == 3) - return domPosInText(closest, clipX, y); - if (closestOverlap && closest.contentEditable != "false") - return domPosAtCoords(closest, clipX, y); - let offset = Array.prototype.indexOf.call(parent.childNodes, closest) + - (x >= (closestRect.left + closestRect.right) / 2 ? 1 : 0); - return { node: parent, offset }; - } - function domPosInText(node, x, y) { - let len = node.nodeValue.length; - let closestOffset = -1, closestDY = 1e9, generalSide = 0; - for (let i = 0; i < len; i++) { - let rects = textRange(node, i, i + 1).getClientRects(); - for (let j = 0; j < rects.length; j++) { - let rect = rects[j]; - if (rect.top == rect.bottom) - continue; - if (!generalSide) - generalSide = x - rect.left; - let dy = (rect.top > y ? rect.top - y : y - rect.bottom) - 1; - if (rect.left - 1 <= x && rect.right + 1 >= x && dy < closestDY) { - let right = x >= (rect.left + rect.right) / 2, after = right; - if (browser.chrome || browser.gecko) { - // Check for RTL on browsers that support getting client - // rects for empty ranges. - let rectBefore = textRange(node, i).getBoundingClientRect(); - if (rectBefore.left == rect.right) - after = !right; - } - if (dy <= 0) - return { node, offset: i + (after ? 1 : 0) }; - closestOffset = i + (after ? 1 : 0); - closestDY = dy; - } - } - } - return { node, offset: closestOffset > -1 ? closestOffset : generalSide > 0 ? node.nodeValue.length : 0 }; - } - function posAtCoords(view, coords, precise, bias = -1) { - var _a, _b; - let content = view.contentDOM.getBoundingClientRect(), docTop = content.top + view.viewState.paddingTop; - let block, { docHeight } = view.viewState; - let { x, y } = coords, yOffset = y - docTop; - if (yOffset < 0) - return 0; - if (yOffset > docHeight) - return view.state.doc.length; - // Scan for a text block near the queried y position - for (let halfLine = view.viewState.heightOracle.textHeight / 2, bounced = false;;) { - block = view.elementAtHeight(yOffset); - if (block.type == BlockType.Text) - break; - for (;;) { - // Move the y position out of this block - yOffset = bias > 0 ? block.bottom + halfLine : block.top - halfLine; - if (yOffset >= 0 && yOffset <= docHeight) - break; - // If the document consists entirely of replaced widgets, we - // won't find a text block, so return 0 - if (bounced) - return precise ? null : 0; - bounced = true; - bias = -bias; - } - } - y = docTop + yOffset; - let lineStart = block.from; - // If this is outside of the rendered viewport, we can't determine a position - if (lineStart < view.viewport.from) - return view.viewport.from == 0 ? 0 : precise ? null : posAtCoordsImprecise(view, content, block, x, y); - if (lineStart > view.viewport.to) - return view.viewport.to == view.state.doc.length ? view.state.doc.length : - precise ? null : posAtCoordsImprecise(view, content, block, x, y); - // Prefer ShadowRootOrDocument.elementFromPoint if present, fall back to document if not - let doc = view.dom.ownerDocument; - let root = view.root.elementFromPoint ? view.root : doc; - let element = root.elementFromPoint(x, y); - if (element && !view.contentDOM.contains(element)) - element = null; - // If the element is unexpected, clip x at the sides of the content area and try again - if (!element) { - x = Math.max(content.left + 1, Math.min(content.right - 1, x)); - element = root.elementFromPoint(x, y); - if (element && !view.contentDOM.contains(element)) - element = null; - } - // There's visible editor content under the point, so we can try - // using caret(Position|Range)FromPoint as a shortcut - let node, offset = -1; - if (element && ((_a = view.docView.nearest(element)) === null || _a === void 0 ? void 0 : _a.isEditable) != false) { - if (doc.caretPositionFromPoint) { - let pos = doc.caretPositionFromPoint(x, y); - if (pos) - ({ offsetNode: node, offset } = pos); - } - else if (doc.caretRangeFromPoint) { - let range = doc.caretRangeFromPoint(x, y); - if (range) - ({ startContainer: node, startOffset: offset } = range); - } - if (node && (!view.contentDOM.contains(node) || - browser.safari && isSuspiciousSafariCaretResult(node, offset, x) || - browser.chrome && isSuspiciousChromeCaretResult(node, offset, x))) - node = undefined; - // Chrome will return offsets into elements without child - // nodes, which will lead to a null deref below, so clip the - // offset to the node size. - if (node) - offset = Math.min(maxOffset(node), offset); - } - // No luck, do our own (potentially expensive) search - if (!node || !view.docView.dom.contains(node)) { - let line = LineView.find(view.docView, lineStart); - if (!line) - return yOffset > block.top + block.height / 2 ? block.to : block.from; - ({ node, offset } = domPosAtCoords(line.dom, x, y)); - } - let nearest = view.docView.nearest(node); - if (!nearest) - return null; - if (nearest.isWidget && ((_b = nearest.dom) === null || _b === void 0 ? void 0 : _b.nodeType) == 1) { - let rect = nearest.dom.getBoundingClientRect(); - return coords.y < rect.top || coords.y <= rect.bottom && coords.x <= (rect.left + rect.right) / 2 - ? nearest.posAtStart : nearest.posAtEnd; - } - else { - return nearest.localPosFromDOM(node, offset) + nearest.posAtStart; - } - } function posAtCoordsImprecise(view, contentRect, block, x, y) { let into = Math.round((x - contentRect.left) * view.defaultCharacterWidth); if (view.lineWrapping && block.height > view.defaultLineHeight * 1.5) { @@ -7927,49 +7870,6 @@ var lsp = (function (exports) { let content = view.state.sliceDoc(block.from, block.to); return block.from + findColumn(content, into, view.state.tabSize); } - function isEndOfLineBefore(node, offset, x) { - let len, scan = node; - if (node.nodeType != 3 || offset != (len = node.nodeValue.length)) - return false; - for (;;) { // Check that there is no content after this node - let next = scan.nextSibling; - if (next) { - if (next.nodeName == "BR") - break; - return false; - } - else { - let parent = scan.parentNode; - if (!parent || parent.nodeName == "DIV") - break; - scan = parent; - } - } - return textRange(node, len - 1, len).getBoundingClientRect().right > x; - } - // In case of a high line height, Safari's caretRangeFromPoint treats - // the space between lines as belonging to the last character of the - // line before. This is used to detect such a result so that it can be - // ignored (issue #401). - function isSuspiciousSafariCaretResult(node, offset, x) { - return isEndOfLineBefore(node, offset, x); - } - // Chrome will move positions between lines to the start of the next line - function isSuspiciousChromeCaretResult(node, offset, x) { - if (offset != 0) - return isEndOfLineBefore(node, offset, x); - for (let cur = node;;) { - let parent = cur.parentNode; - if (!parent || parent.nodeType != 1 || parent.firstChild != cur) - return false; - if (parent.classList.contains("cm-line")) - break; - cur = parent; - } - let rect = node.nodeType == 1 ? node.getBoundingClientRect() - : textRange(node, 0, Math.max(node.nodeValue.length, 1)).getBoundingClientRect(); - return x - rect.left > 5; - } function blockAt(view, pos, side) { let line = view.lineBlockAt(pos); if (Array.isArray(line.type)) { @@ -8042,7 +7942,7 @@ var lsp = (function (exports) { return EditorSelection.cursor(startPos, start.assoc); let goal = start.goalColumn, startY; let rect = view.contentDOM.getBoundingClientRect(); - let startCoords = view.coordsAtPos(startPos, start.assoc || -1), docTop = view.documentTop; + let startCoords = view.coordsAtPos(startPos, (start.empty ? start.assoc : 0) || (forward ? 1 : -1)), docTop = view.documentTop; if (startCoords) { if (goal == null) goal = startCoords.left - rect.left; @@ -8056,15 +7956,8 @@ var lsp = (function (exports) { } let resolvedGoal = rect.left + goal; let dist = distance !== null && distance !== void 0 ? distance : (view.viewState.heightOracle.textHeight >> 1); - for (let extra = 0;; extra += 10) { - let curY = startY + (dist + extra) * dir; - let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir); - if (curY < rect.top || curY > rect.bottom || (dir < 0 ? pos < startPos : pos > startPos)) { - let charRect = view.docView.coordsForChar(pos); - let assoc = !charRect || curY < charRect.top ? -1 : 1; - return EditorSelection.cursor(pos, assoc, undefined, goal); - } - } + let pos = posAtCoords(view, { x: resolvedGoal, y: startY + dist * dir }, false, dir); + return EditorSelection.cursor(pos.pos, pos.assoc, undefined, goal); } function skipAtomicRanges(atoms, pos, bias) { for (;;) { @@ -8109,13 +8002,219 @@ var lsp = (function (exports) { let newPos = skipAtomicRanges(view.state.facet(atomicRanges).map(f => f(view)), pos.from, oldPos.head > pos.from ? -1 : 1); return newPos == pos.from ? pos : EditorSelection.cursor(newPos, newPos < pos.from ? 1 : -1); } + class PosAssoc { + constructor(pos, assoc) { + this.pos = pos; + this.assoc = assoc; + } + } + function posAtCoords(view, coords, precise, scanY) { + let content = view.contentDOM.getBoundingClientRect(), docTop = content.top + view.viewState.paddingTop; + let { x, y } = coords, yOffset = y - docTop, block; + // First find the block at the given Y position, if any. If scanY is + // given (used for vertical cursor motion), try to skip widgets and + // line padding. + for (;;) { + if (yOffset < 0) + return new PosAssoc(0, 1); + if (yOffset > view.viewState.docHeight) + return new PosAssoc(view.state.doc.length, -1); + block = view.elementAtHeight(yOffset); + if (scanY == null) + break; + if (block.type == BlockType.Text) { + if (scanY < 0 ? block.to < view.viewport.from : block.from > view.viewport.to) + break; + // Check whether we aren't landing on the top/bottom padding of the line + let rect = view.docView.coordsAt(scanY < 0 ? block.from : block.to, scanY > 0 ? -1 : 1); + if (rect && (scanY < 0 ? rect.top <= yOffset + docTop : rect.bottom >= yOffset + docTop)) + break; + } + let halfLine = view.viewState.heightOracle.textHeight / 2; + yOffset = scanY > 0 ? block.bottom + halfLine : block.top - halfLine; + } + // If outside the viewport, return null if precise==true, an + // estimate otherwise. + if (view.viewport.from >= block.to || view.viewport.to <= block.from) { + if (precise) + return null; + if (block.type == BlockType.Text) { + let pos = posAtCoordsImprecise(view, content, block, x, y); + return new PosAssoc(pos, pos == block.from ? 1 : -1); + } + } + if (block.type != BlockType.Text) + return yOffset < (block.top + block.bottom) / 2 ? new PosAssoc(block.from, 1) : new PosAssoc(block.to, -1); + // Here we know we're in a line, so run the logic for inline layout + let line = view.docView.lineAt(block.from, 2); + if (!line || line.length != block.length) + line = view.docView.lineAt(block.from, -2); + return new InlineCoordsScan(view, x, y, view.textDirectionAt(block.from)).scanTile(line, block.from); + } + class InlineCoordsScan { + constructor(view, x, y, baseDir) { + this.view = view; + this.x = x; + this.y = y; + this.baseDir = baseDir; + // Cached bidi info + this.line = null; + this.spans = null; + } + bidiSpansAt(pos) { + if (!this.line || this.line.from > pos || this.line.to < pos) { + this.line = this.view.state.doc.lineAt(pos); + this.spans = this.view.bidiSpans(this.line); + } + return this; + } + baseDirAt(pos, side) { + let { line, spans } = this.bidiSpansAt(pos); + let level = spans[BidiSpan.find(spans, pos - line.from, -1, side)].level; + return level == this.baseDir; + } + dirAt(pos, side) { + let { line, spans } = this.bidiSpansAt(pos); + return spans[BidiSpan.find(spans, pos - line.from, -1, side)].dir; + } + // Used to short-circuit bidi tests for content with a uniform direction + bidiIn(from, to) { + let { spans, line } = this.bidiSpansAt(from); + return spans.length > 1 || spans.length && (spans[0].level != this.baseDir || spans[0].to + line.from < to); + } + // Scan through the rectangles for the content of a tile with inline + // content, looking for one that overlaps the queried position + // vertically andis + // closest horizontally. The caller is responsible for dividing its + // content into N pieces, and pass an array with N+1 positions + // (including the position after the last piece). For a text tile, + // these will be character clusters, for a composite tile, these + // will be child tiles. + scan(positions, getRects) { + let lo = 0, hi = positions.length - 1, seen = new Set(); + let bidi = this.bidiIn(positions[0], positions[hi]); + let above, below; + let closestI = -1, closestDx = 1e9, closestRect; + // Because, when the content is bidirectional, a regular binary + // search is hard to perform (the content order does not + // correspond to visual order), this loop does something between a + // regular binary search and a full scan, depending on what it can + // get away with. The outer hi/lo bounds are only adjusted for + // elements that are part of the base order. + // + // To make sure all elements inside those bounds are visited, + // eventually, we keep a set of seen indices, and if the midpoint + // has already been handled, we start in a random index within the + // current bounds and scan forward until we find an index that + // hasn't been seen yet. + search: while (lo < hi) { + let dist = hi - lo, mid = (lo + hi) >> 1; + adjust: if (seen.has(mid)) { + let scan = lo + Math.floor(Math.random() * dist); + for (let i = 0; i < dist; i++) { + if (!seen.has(scan)) { + mid = scan; + break adjust; + } + scan++; + if (scan == hi) + scan = lo; // Wrap around + } + break search; // No index found, we're done + } + seen.add(mid); + let rects = getRects(mid); + if (rects) + for (let i = 0; i < rects.length; i++) { + let rect = rects[i], side = 0; + if (rect.bottom < this.y) { + if (!above || above.bottom < rect.bottom) + above = rect; + side = 1; + } + else if (rect.top > this.y) { + if (!below || below.top > rect.top) + below = rect; + side = -1; + } + else { + let off = rect.left > this.x ? this.x - rect.left : rect.right < this.x ? this.x - rect.right : 0; + let dx = Math.abs(off); + if (dx < closestDx) { + closestI = mid; + closestDx = dx; + closestRect = rect; + } + if (off) + side = (off < 0) == (this.baseDir == Direction.LTR) ? -1 : 1; + } + // Narrow binary search when it is safe to do so + if (side == -1 && (!bidi || this.baseDirAt(positions[mid], 1))) + hi = mid; + else if (side == 1 && (!bidi || this.baseDirAt(positions[mid + 1], -1))) + lo = mid + 1; + } + } + // If no element with y overlap is found, find the nearest element + // on the y axis, move this.y into it, and retry the scan. + if (!closestRect) { + let side = above && (!below || (this.y - above.bottom < below.top - this.y)) ? above : below; + this.y = (side.top + side.bottom) / 2; + return this.scan(positions, getRects); + } + let ltr = (bidi ? this.dirAt(positions[closestI], 1) : this.baseDir) == Direction.LTR; + return { + i: closestI, + // Test whether x is closes to the start or end of this element + after: (this.x > (closestRect.left + closestRect.right) / 2) == ltr + }; + } + scanText(tile, offset) { + let positions = []; + for (let i = 0; i < tile.length; i = findClusterBreak(tile.text, i)) + positions.push(offset + i); + positions.push(offset + tile.length); + let scan = this.scan(positions, i => { + let off = positions[i] - offset, end = positions[i + 1] - offset; + return textRange(tile.dom, off, end).getClientRects(); + }); + return scan.after ? new PosAssoc(positions[scan.i + 1], -1) : new PosAssoc(positions[scan.i], 1); + } + scanTile(tile, offset) { + if (!tile.length) + return new PosAssoc(offset, 1); + if (tile.children.length == 1) { // Short-circuit single-child tiles + let child = tile.children[0]; + if (child.isText()) + return this.scanText(child, offset); + else if (child.isComposite()) + return this.scanTile(child, offset); + } + let positions = [offset]; + for (let i = 0, pos = offset; i < tile.children.length; i++) + positions.push(pos += tile.children[i].length); + let scan = this.scan(positions, i => { + let child = tile.children[i]; + if (child.flags & 48 /* TileFlag.PointWidget */) + return null; + return (child.dom.nodeType == 1 ? child.dom : textRange(child.dom, 0, child.length)).getClientRects(); + }); + let child = tile.children[scan.i], pos = positions[scan.i]; + if (child.isText()) + return this.scanText(child, pos); + if (child.isComposite()) + return this.scanTile(child, pos); + return scan.after ? new PosAssoc(positions[scan.i + 1], -1) : new PosAssoc(pos, 1); + } + } const LineBreakPlaceholder = "\uffff"; class DOMReader { - constructor(points, state) { + constructor(points, view) { this.points = points; + this.view = view; this.text = ""; - this.lineSeparator = state.facet(EditorState.lineSeparator); + this.lineSeparator = view.state.facet(EditorState.lineSeparator); } append(text) { this.text += text; @@ -8131,13 +8230,16 @@ var lsp = (function (exports) { this.findPointBefore(parent, cur); let oldLen = this.text.length; this.readNode(cur); - let next = cur.nextSibling; - if (next == end) + let tile = Tile.get(cur), next = cur.nextSibling; + if (next == end) { + if ((tile === null || tile === void 0 ? void 0 : tile.breakAfter) && !next && parent != this.view.contentDOM) + this.lineBreak(); break; - let view = ContentView.get(cur), nextView = ContentView.get(next); - if ((view && nextView ? view.breakAfter : - (view ? view.breakAfter : isBlockElement(cur)) || - (isBlockElement(next) && (cur.nodeName != "BR" || cur.cmIgnore) && this.text.length > oldLen)) && + } + let nextTile = Tile.get(next); + if ((tile && nextTile ? tile.breakAfter : + (tile ? tile.breakAfter : isBlockElement(cur)) || + (isBlockElement(next) && (cur.nodeName != "BR" || (tile === null || tile === void 0 ? void 0 : tile.isWidget())) && this.text.length > oldLen)) && !isEmptyToEnd(next, end)) this.lineBreak(); cur = next; @@ -8172,10 +8274,8 @@ var lsp = (function (exports) { } } readNode(node) { - if (node.cmIgnore) - return; - let view = ContentView.get(node); - let fromView = view && view.overrideDOMText; + let tile = Tile.get(node); + let fromView = tile && tile.overrideDOMText; if (fromView != null) { this.findPointInside(node, fromView.length); for (let i = fromView.iter(); !i.next().done;) { @@ -8222,8 +8322,8 @@ var lsp = (function (exports) { for (;; node = node.nextSibling) { if (node == end || !node) break; - let view = ContentView.get(node); - if (!((view === null || view === void 0 ? void 0 : view.isWidget) || node.cmIgnore)) + let view = Tile.get(node); + if (!(view === null || view === void 0 ? void 0 : view.isWidget())) return false; if (view) (widgets || (widgets = [])).push(view); @@ -8255,9 +8355,9 @@ var lsp = (function (exports) { // Ignore changes when the editor is read-only this.newSel = null; } - else if (start > -1 && (this.bounds = view.docView.domBoundsAround(start, end, 0))) { + else if (start > -1 && (this.bounds = domBoundsAround(view.docView.tile, start, end, 0))) { let selPoints = iHead || iAnchor ? [] : selectionPoints(view); - let reader = new DOMReader(selPoints, view.state); + let reader = new DOMReader(selPoints, view); reader.readRange(this.bounds.startDOM, this.bounds.endDOM); this.text = reader.text; this.newSel = selectionFromPoints(selPoints, this.bounds.from); @@ -8286,10 +8386,43 @@ var lsp = (function (exports) { anchor = view.state.doc.length; } } - this.newSel = EditorSelection.single(anchor, head); + if (view.inputState.composing > -1 && view.state.selection.ranges.length > 1) + this.newSel = view.state.selection.replaceRange(EditorSelection.range(anchor, head)); + else + this.newSel = EditorSelection.single(anchor, head); } } } + function domBoundsAround(tile, from, to, offset) { + if (tile.isComposite()) { + let fromI = -1, fromStart = -1, toI = -1, toEnd = -1; + for (let i = 0, pos = offset, prevEnd = offset; i < tile.children.length; i++) { + let child = tile.children[i], end = pos + child.length; + if (pos < from && end > to) + return domBoundsAround(child, from, to, pos); + if (end >= from && fromI == -1) { + fromI = i; + fromStart = pos; + } + if (pos > to && child.dom.parentNode == tile.dom) { + toI = i; + toEnd = prevEnd; + break; + } + prevEnd = end; + pos = end + child.breakAfter; + } + return { from: fromStart, to: toEnd < 0 ? offset + tile.length : toEnd, + startDOM: (fromI ? tile.children[fromI - 1].dom.nextSibling : null) || tile.dom.firstChild, + endDOM: toI < tile.children.length && toI >= 0 ? tile.children[toI].dom : null }; + } + else if (tile.isText()) { + return { from: offset, to: offset + tile.length, startDOM: tile.dom, endDOM: tile.dom.nextSibling }; + } + else { + return null; + } + } function applyDOMChange(view, domChange) { let change; let { newSel } = domChange, sel = view.state.selection.main; @@ -8314,7 +8447,7 @@ var lsp = (function (exports) { insert: Text.of(domChange.text.slice(diff.from, diff.toB).split(LineBreakPlaceholder)) }; } } - else if (newSel && (!view.hasFocus && view.state.facet(editable) || newSel.main.eq(sel))) { + else if (newSel && (!view.hasFocus && view.state.facet(editable) || sameSelPos(newSel, sel))) { newSel = null; } if (!change && !newSel) @@ -8342,6 +8475,18 @@ var lsp = (function (exports) { insert: view.state.doc.slice(sel.from, change.from).append(change.insert).append(view.state.doc.slice(change.to, sel.to)) }; } + else if (view.state.doc.lineAt(sel.from).to < sel.to && view.docView.lineHasWidget(sel.to) && + view.inputState.insertingTextAt > Date.now() - 50) { + // For a cross-line insertion, Chrome and Safari will crudely take + // the text of the line after the selection, flattening any + // widgets, and move it into the joined line. This tries to detect + // such a situation, and replaces the change with a selection + // replace of the text provided by the beforeinput event. + change = { + from: sel.from, to: sel.to, + insert: view.state.toText(view.inputState.insertingText) + }; + } else if (browser.chrome && change && change.from == change.to && change.from == sel.head && change.insert.toString() == "\n " && view.lineWrapping) { // In Chrome, if you insert a space at the start of a wrapped @@ -8354,7 +8499,7 @@ var lsp = (function (exports) { if (change) { return applyDOMChangeInner(view, change, newSel, lastKey); } - else if (newSel && !newSel.main.eq(sel)) { + else if (newSel && !sameSelPos(newSel, sel)) { let scrollIntoView = false, userEvent = "select"; if (view.inputState.lastSelectionTime > Date.now() - 50) { if (view.inputState.lastSelectionOrigin == "select") @@ -8427,8 +8572,8 @@ var lsp = (function (exports) { let changes = startState.changes(change); let mainSel = newSel && newSel.main.to <= changes.newLength ? newSel.main : undefined; // Try to apply a composition change to all cursors - if (startState.selection.ranges.length > 1 && view.inputState.composing >= 0 && - change.to <= sel.to && change.to >= sel.to - 10) { + if (startState.selection.ranges.length > 1 && (view.inputState.composing >= 0 || view.inputState.compositionPendingChange) && + change.to <= sel.to + 10 && change.to >= sel.to - 10) { let replaced = view.state.sliceDoc(change.from, change.to); let compositionRange, composition = newSel && findCompositionNode(view, newSel.main.head); if (composition) { @@ -8438,17 +8583,17 @@ var lsp = (function (exports) { else { compositionRange = view.state.doc.lineAt(sel.head); } - let offset = sel.to - change.to, size = sel.to - sel.from; + let offset = sel.to - change.to; tr = startState.changeByRange(range => { if (range.from == sel.from && range.to == sel.to) return { changes, range: mainSel || range.map(changes) }; let to = range.to - offset, from = to - replaced.length; - if (range.to - range.from != size || view.state.sliceDoc(from, to) != replaced || + if (view.state.sliceDoc(from, to) != replaced || // Unfortunately, there's no way to make multiple // changes in the same node work without aborting // composition, so cursors in the composition range are // ignored. - range.to >= compositionRange.from && range.from <= compositionRange.to) + to >= compositionRange.from && from <= compositionRange.to) return { range }; let rangeChanges = startState.changes({ from, to, insert: change.insert }), selOff = range.to - sel.to; return { @@ -8525,6 +8670,9 @@ var lsp = (function (exports) { let anchor = points[0].pos, head = points.length == 2 ? points[1].pos : anchor; return anchor > -1 && head > -1 ? EditorSelection.single(anchor + base, head + base) : null; } + function sameSelPos(selection, range) { + return range.head == selection.main.head && range.anchor == selection.main.anchor; + } class InputState { setSelectionOrigin(origin) { @@ -8575,6 +8723,9 @@ var lsp = (function (exports) { // Used to categorize changes as part of a composition, even when // the mutation events fire shortly after the compositionend event this.compositionPendingChange = false; + // Set by beforeinput, used in DOM change reader + this.insertingText = ""; + this.insertingTextAt = 0; this.mouseSelection = null; // When a drag from the editor is active, this points at the range // being dragged. @@ -8898,8 +9049,9 @@ var lsp = (function (exports) { return true; if (event.defaultPrevented) return false; - for (let node = event.target, cView; node != view.contentDOM; node = node.parentNode) - if (!node || node.nodeType == 11 || ((cView = ContentView.get(node)) && cView.ignoreEvent(event))) + for (let node = event.target, tile; node != view.contentDOM; node = node.parentNode) + if (!node || node.nodeType == 11 || + ((tile = Tile.get(node)) && tile.isWidget() && !tile.isHidden && tile.widget.ignoreEvent(event))) return false; return true; } @@ -9018,42 +9170,13 @@ var lsp = (function (exports) { return groupAt(view.state, pos, bias); } else { // Triple click - let visual = LineView.find(view.docView, pos), line = view.state.doc.lineAt(visual ? visual.posAtEnd : pos); + let visual = view.docView.lineAt(pos, bias), line = view.state.doc.lineAt(visual ? visual.posAtEnd : pos); let from = visual ? visual.posAtStart : line.from, to = visual ? visual.posAtEnd : line.to; if (to < view.state.doc.length && to == line.to) to++; return EditorSelection.range(from, to); } } - let inside = (x, y, rect) => y >= rect.top && y <= rect.bottom && x >= rect.left && x <= rect.right; - // Try to determine, for the given coordinates, associated with the - // given position, whether they are related to the element before or - // the element after the position. - function findPositionSide(view, pos, x, y) { - let line = LineView.find(view.docView, pos); - if (!line) - return 1; - let off = pos - line.posAtStart; - // Line boundaries point into the line - if (off == 0) - return 1; - if (off == line.length) - return -1; - // Positions on top of an element point at that element - let before = line.coordsAt(off, -1); - if (before && inside(x, y, before)) - return -1; - let after = line.coordsAt(off, 1); - if (after && inside(x, y, after)) - return 1; - // This is probably a line wrap point. Pick before if the point is - // above its bottom. - return before && before.bottom >= y ? -1 : 1; - } - function queryPos(view, event) { - let pos = view.posAtCoords({ x: event.clientX, y: event.clientY }, false); - return { pos, bias: findPositionSide(view, pos, event.clientX, event.clientY) }; - } const BadMouseDetail = browser.ie && browser.ie_version <= 11; let lastMouseDown = null, lastMouseDownCount = 0, lastMouseDownTime = 0; function getClickType(event) { @@ -9066,7 +9189,7 @@ var lsp = (function (exports) { Math.abs(last.clientY - event.clientY) < 2) ? (lastMouseDownCount + 1) % 3 : 1; } function basicMouseSelection(view, event) { - let start = queryPos(view, event), type = getClickType(event); + let start = view.posAndSideAtCoords({ x: event.clientX, y: event.clientY }, false), type = getClickType(event); let startSel = view.state.selection; return { update(update) { @@ -9076,10 +9199,10 @@ var lsp = (function (exports) { } }, get(event, extend, multiple) { - let cur = queryPos(view, event), removed; - let range = rangeForClick(view, cur.pos, cur.bias, type); + let cur = view.posAndSideAtCoords({ x: event.clientX, y: event.clientY }, false), removed; + let range = rangeForClick(view, cur.pos, cur.assoc, type); if (start.pos != cur.pos && !extend) { - let startRange = rangeForClick(view, start.pos, start.bias, type); + let startRange = rangeForClick(view, start.pos, start.assoc, type); let from = Math.min(startRange.from, range.from), to = Math.max(startRange.to, range.to); range = from < range.from ? EditorSelection.range(from, to) : EditorSelection.range(to, from); } @@ -9105,9 +9228,9 @@ var lsp = (function (exports) { handlers.dragstart = (view, event) => { let { selection: { main: range } } = view.state; if (event.target.draggable) { - let cView = view.docView.nearest(event.target); - if (cView && cView.isWidget) { - let from = cView.posAtStart, to = from + cView.length; + let tile = view.docView.tile.nearest(event.target); + if (tile && tile.isWidget()) { + let from = tile.posAtStart, to = from + tile.length; if (from >= range.to || to <= range.from) range = EditorSelection.range(from, to); } @@ -9232,6 +9355,13 @@ var lsp = (function (exports) { } let lastLinewiseCopy = null; handlers.copy = handlers.cut = (view, event) => { + // If the DOM selection is outside this editor, don't intercept. + // This happens when a parent editor (like ProseMirror) selects content that + // spans multiple elements including this CodeMirror. The copy event may + // bubble through CodeMirror (e.g. when CodeMirror is the first or the last + // element in the selection), but we should let the parent handle it. + if (!hasSelection(view.contentDOM, view.observer.selectionRange)) + return false; let { text, ranges, linewise } = copiedRange(view.state); if (!text && !linewise) return false; @@ -9329,6 +9459,10 @@ var lsp = (function (exports) { }; handlers.beforeinput = (view, event) => { var _a, _b; + if (event.inputType == "insertText" || event.inputType == "insertCompositionText") { + view.inputState.insertingText = event.data; + view.inputState.insertingTextAt = Date.now(); + } // In EditContext mode, we must handle insertReplacementText events // directly, to make spell checking corrections work if (event.inputType == "insertReplacementText" && view.observer.editContext) { @@ -9435,7 +9569,8 @@ var lsp = (function (exports) { } refresh(whiteSpace, lineHeight, charWidth, textHeight, lineLength, knownHeights) { let lineWrapping = wrappingWhiteSpace.indexOf(whiteSpace) > -1; - let changed = Math.round(lineHeight) != Math.round(this.lineHeight) || this.lineWrapping != lineWrapping; + let changed = Math.abs(lineHeight - this.lineHeight) > 0.3 || this.lineWrapping != lineWrapping || + Math.abs(charWidth - this.charWidth) > 0.1; this.lineWrapping = lineWrapping; this.lineHeight = lineHeight; this.charWidth = charWidth; @@ -9455,7 +9590,7 @@ var lsp = (function (exports) { } } // This object is used by `updateHeight` to make DOM measurements - // arrive at the right nides. The `heights` array is a sequence of + // arrive at the right nodes. The `heights` array is a sequence of // block heights, starting from position `from`. class MeasuredHeights { constructor(from, heights) { @@ -9494,7 +9629,7 @@ var lsp = (function (exports) { /** @internal Weird packed field that holds an array of children for composite blocks, a decoration for block widgets, and a - number indicating the amount of widget-create line breaks for + number indicating the amount of widget-created line breaks for text blocks. */ _content) { @@ -9597,7 +9732,7 @@ var lsp = (function (exports) { } return me.updateHeight(oracle, 0); } - static empty() { return new HeightMapText(0, 0); } + static empty() { return new HeightMapText(0, 0, 0); } // nodes uses null values to indicate the position of line breaks. // There are never line breaks at the start or end of the array, or // two line breaks next to each other, and the array isn't allowed @@ -9661,45 +9796,64 @@ var lsp = (function (exports) { return val; } HeightMap.prototype.size = 1; + const SpaceDeco = /*@__PURE__*/Decoration.replace({}); class HeightMapBlock extends HeightMap { constructor(length, height, deco) { super(length, height); this.deco = deco; + this.spaceAbove = 0; } - blockAt(_height, _oracle, top, offset) { - return new BlockInfo(offset, this.length, top, this.height, this.deco || 0); + mainBlock(top, offset) { + return new BlockInfo(offset, this.length, top + this.spaceAbove, this.height - this.spaceAbove, this.deco || 0); + } + blockAt(height, _oracle, top, offset) { + return this.spaceAbove && height < top + this.spaceAbove ? new BlockInfo(offset, 0, top, this.spaceAbove, SpaceDeco) + : this.mainBlock(top, offset); } lineAt(_value, _type, oracle, top, offset) { - return this.blockAt(0, oracle, top, offset); + let main = this.mainBlock(top, offset); + return this.spaceAbove ? this.blockAt(0, oracle, top, offset).join(main) : main; } forEachLine(from, to, oracle, top, offset, f) { if (from <= offset + this.length && to >= offset) - f(this.blockAt(0, oracle, top, offset)); + f(this.lineAt(0, QueryType$1.ByPos, oracle, top, offset)); + } + setMeasuredHeight(measured) { + let next = measured.heights[measured.index++]; + if (next < 0) { + this.spaceAbove = -next; + next = measured.heights[measured.index++]; + } + else { + this.spaceAbove = 0; + } + this.setHeight(next); } updateHeight(oracle, offset = 0, _force = false, measured) { if (measured && measured.from <= offset && measured.more) - this.setHeight(measured.heights[measured.index++]); + this.setMeasuredHeight(measured); this.outdated = false; return this; } toString() { return `block(${this.length})`; } } class HeightMapText extends HeightMapBlock { - constructor(length, height) { + constructor(length, height, above) { super(length, height, null); this.collapsed = 0; // Amount of collapsed content in the line this.widgetHeight = 0; // Maximum inline widget height this.breaks = 0; // Number of widget-introduced line breaks on the line + this.spaceAbove = above; } - blockAt(_height, _oracle, top, offset) { - return new BlockInfo(offset, this.length, top, this.height, this.breaks); + mainBlock(top, offset) { + return new BlockInfo(offset, this.length, top + this.spaceAbove, this.height - this.spaceAbove, this.breaks); } replace(_from, _to, nodes) { let node = nodes[0]; if (nodes.length == 1 && (node instanceof HeightMapText || node instanceof HeightMapGap && (node.flags & 4 /* Flag.SingleLine */)) && Math.abs(this.length - node.length) < 10) { if (node instanceof HeightMapGap) - node = new HeightMapText(node.length, this.height); + node = new HeightMapText(node.length, this.height, this.spaceAbove); else node.height = this.height; if (!this.outdated) @@ -9711,11 +9865,14 @@ var lsp = (function (exports) { } } updateHeight(oracle, offset = 0, force = false, measured) { - if (measured && measured.from <= offset && measured.more) - this.setHeight(measured.heights[measured.index++]); - else if (force || this.outdated) + if (measured && measured.from <= offset && measured.more) { + this.setMeasuredHeight(measured); + } + else if (force || this.outdated) { + this.spaceAbove = 0; this.setHeight(Math.max(this.widgetHeight, oracle.heightForLine(this.length - this.collapsed)) + this.breaks * oracle.lineHeight); + } this.outdated = false; return this; } @@ -9822,12 +9979,16 @@ var lsp = (function (exports) { let len = oracle.doc.lineAt(pos).length; if (nodes.length) nodes.push(null); - let height = measured.heights[measured.index++]; + let height = measured.heights[measured.index++], above = 0; + if (height < 0) { + above = -height; + height = measured.heights[measured.index++]; + } if (singleHeight == -1) singleHeight = height; else if (Math.abs(height - singleHeight) >= Epsilon) singleHeight = -2; - let line = new HeightMapText(len, height); + let line = new HeightMapText(len, height, above); line.outdated = false; nodes.push(line); pos += len + 1; @@ -9992,7 +10153,7 @@ var lsp = (function (exports) { if (last instanceof HeightMapText) last.length += end - this.pos; else if (end > this.pos || !this.isCovered) - this.nodes.push(new HeightMapText(end - this.pos, -1)); + this.nodes.push(new HeightMapText(end - this.pos, -1, 0)); this.writtenTo = end; if (to > end) { this.nodes.push(null); @@ -10034,7 +10195,7 @@ var lsp = (function (exports) { this.nodes.push(null); } if (this.pos > from) - this.nodes.push(new HeightMapText(this.pos - from, -1)); + this.nodes.push(new HeightMapText(this.pos - from, -1, 0)); this.writtenTo = this.pos; } blankContent(from, to) { @@ -10048,7 +10209,7 @@ var lsp = (function (exports) { let last = this.nodes.length ? this.nodes[this.nodes.length - 1] : null; if (last instanceof HeightMapText) return last; - let line = new HeightMapText(0, -1); + let line = new HeightMapText(0, -1, 0); this.nodes.push(line); return line; } @@ -10073,7 +10234,7 @@ var lsp = (function (exports) { finish(from) { let last = this.nodes.length == 0 ? null : this.nodes[this.nodes.length - 1]; if (this.lineStart > -1 && !(last instanceof HeightMapText) && !this.isCovered) - this.nodes.push(new HeightMapText(0, -1)); + this.nodes.push(new HeightMapText(0, -1, 0)); else if (this.writtenTo < this.pos || last == null) this.nodes.push(this.blankContent(this.writtenTo, this.pos)); let pos = from; @@ -10242,7 +10403,7 @@ var lsp = (function (exports) { this.mustEnforceCursorAssoc = false; let guessWrapping = state.facet(contentAttributes).some(v => typeof v != "function" && v.class == "cm-lineWrapping"); this.heightOracle = new HeightOracle(guessWrapping); - this.stateDeco = state.facet(decorations).filter(d => typeof d != "function"); + this.stateDeco = staticDeco(state); this.heightMap = HeightMap.empty().applyChanges(this.stateDeco, Text.empty, this.heightOracle.setDoc(state.doc), [new ChangedRange(0, 0, 0, state.doc.length)]); for (let i = 0; i < 2; i++) { this.viewport = this.getViewport(0, null); @@ -10281,7 +10442,7 @@ var lsp = (function (exports) { update(update, scrollTarget = null) { this.state = update.state; let prevDeco = this.stateDeco; - this.stateDeco = this.state.facet(decorations).filter(d => typeof d != "function"); + this.stateDeco = staticDeco(this.state); let contentChanges = update.changedRanges; let heightChanges = ChangedRange.extendWithRanges(contentChanges, heightRelevantDecoChanges(prevDeco, this.stateDeco, update ? update.changes : ChangeSet.empty(this.state.doc.length))); let prevHeight = this.heightMap.height; @@ -10312,7 +10473,7 @@ var lsp = (function (exports) { update.flags |= this.computeVisibleRanges(update.changes); if (scrollTarget) this.scrollTarget = scrollTarget; - if (!this.mustEnforceCursorAssoc && update.selectionSet && update.view.lineWrapping && + if (!this.mustEnforceCursorAssoc && (update.selectionSet || update.focusChanged) && update.view.lineWrapping && update.state.selection.main.empty && update.state.selection.main.assoc && !update.state.facet(nativeSelectionHidden)) this.mustEnforceCursorAssoc = true; @@ -10322,7 +10483,7 @@ var lsp = (function (exports) { let oracle = this.heightOracle; let whiteSpace = style.whiteSpace; this.defaultTextDirection = style.direction == "rtl" ? Direction.RTL : Direction.LTR; - let refresh = this.heightOracle.mustRefreshForWrapping(whiteSpace); + let refresh = this.heightOracle.mustRefreshForWrapping(whiteSpace) || this.mustMeasureContent; let domRect = dom.getBoundingClientRect(); let measureContent = refresh || this.mustMeasureContent || this.contentDOMHeight != domRect.height; this.contentDOMHeight = domRect.height; @@ -10710,6 +10871,13 @@ var lsp = (function (exports) { scale: 1, eq(other) { return other == this; } }; + function staticDeco(state) { + let deco = state.facet(decorations).filter(d => typeof d != "function"); + let outer = state.facet(outerDecorations).filter(d => typeof d != "function"); + if (outer.length) + deco.push(RangeSet.join(outer)); + return deco; + } // When the height is too big (> VP.MaxDOMHeight), scale down the // regions outside the viewports so that the total height is // VP.MaxDOMHeight. @@ -10782,7 +10950,7 @@ var lsp = (function (exports) { } }); } - const baseTheme$1$2 = /*@__PURE__*/buildTheme("." + baseThemeID, { + const baseTheme$1$1 = /*@__PURE__*/buildTheme("." + baseThemeID, { "&": { position: "relative !important", boxSizing: "border-box", @@ -11200,8 +11368,8 @@ var lsp = (function (exports) { let { view } = this, sel = this.selectionRange; if (view.state.facet(editable) ? view.root.activeElement != this.dom : !hasSelection(this.dom, sel)) return; - let context = sel.anchorNode && view.docView.nearest(sel.anchorNode); - if (context && context.ignoreEvent(event)) { + let context = sel.anchorNode && view.docView.tile.nearest(sel.anchorNode); + if (context && context.isWidget() && context.widget.ignoreEvent(event)) { if (!wasChanged) this.selectionChanged = false; return; @@ -11426,25 +11594,23 @@ var lsp = (function (exports) { let handled = applyDOMChange(this.view, domChange); // The view wasn't updated but DOM/selection changes were seen. Reset the view. if (this.view.state == startState && - (domChange.domChanged || domChange.newSel && !domChange.newSel.main.eq(this.view.state.selection.main))) + (domChange.domChanged || domChange.newSel && !sameSelPos(this.view.state.selection, domChange.newSel.main))) this.view.update([]); return handled; } readMutation(rec) { - let cView = this.view.docView.nearest(rec.target); - if (!cView || cView.ignoreMutation(rec)) + let tile = this.view.docView.tile.nearest(rec.target); + if (!tile || tile.isWidget()) return null; - cView.markDirty(rec.type == "attributes"); - if (rec.type == "attributes") - cView.flags |= 4 /* ViewFlag.AttrsDirty */; + tile.markDirty(rec.type == "attributes"); if (rec.type == "childList") { - let childBefore = findChild(cView, rec.previousSibling || rec.target.previousSibling, -1); - let childAfter = findChild(cView, rec.nextSibling || rec.target.nextSibling, 1); - return { from: childBefore ? cView.posAfter(childBefore) : cView.posAtStart, - to: childAfter ? cView.posBefore(childAfter) : cView.posAtEnd, typeOver: false }; + let childBefore = findChild(tile, rec.previousSibling || rec.target.previousSibling, -1); + let childAfter = findChild(tile, rec.nextSibling || rec.target.nextSibling, 1); + return { from: childBefore ? tile.posAfter(childBefore) : tile.posAtStart, + to: childAfter ? tile.posBefore(childAfter) : tile.posAtEnd, typeOver: false }; } else if (rec.type == "characterData") { - return { from: cView.posAtStart, to: cView.posAtEnd, typeOver: rec.target.nodeValue == rec.oldValue }; + return { from: tile.posAtStart, to: tile.posAtEnd, typeOver: rec.target.nodeValue == rec.oldValue }; } else { return null; @@ -11509,20 +11675,20 @@ var lsp = (function (exports) { } } } - function findChild(cView, dom, dir) { + function findChild(tile, dom, dir) { while (dom) { - let curView = ContentView.get(dom); - if (curView && curView.parent == cView) - return curView; + let curTile = Tile.get(dom); + if (curTile && curTile.parent == tile) + return curTile; let parent = dom.parentNode; - dom = parent != cView.dom ? parent : dir > 0 ? dom.nextSibling : dom.previousSibling; + dom = parent != tile.dom ? parent : dir > 0 ? dom.nextSibling : dom.previousSibling; } return null; } function buildSelectionRangeFromRange(view, range) { let anchorNode = range.startContainer, anchorOffset = range.startOffset; let focusNode = range.endContainer, focusOffset = range.endOffset; - let curAnchor = view.docView.domAtPos(view.state.selection.main.anchor); + let curAnchor = view.docView.domAtPos(view.state.selection.main.anchor, 1); // Since such a range doesn't distinguish between anchor and head, // use a heuristic that flips it around if its end matches the // current anchor. @@ -11592,7 +11758,7 @@ var lsp = (function (exports) { // Edit contexts sometimes fire empty changes if (!diff) { let newSel = EditorSelection.single(this.toEditorPos(e.selectionStart), this.toEditorPos(e.selectionEnd)); - if (!newSel.main.eq(main)) + if (!sameSelPos(newSel, main)) view.dispatch({ selection: newSel, userEvent: "select" }); return; } @@ -11893,7 +12059,10 @@ var lsp = (function (exports) { this.updateState = 0 /* UpdateState.Idle */; this.requestMeasure(); if ((_a = document.fonts) === null || _a === void 0 ? void 0 : _a.ready) - document.fonts.ready.then(() => this.requestMeasure()); + document.fonts.ready.then(() => { + this.viewState.mustMeasureContent = true; + this.requestMeasure(); + }); } dispatch(...input) { let trs = input.length == 1 && input[0] instanceof Transaction ? input @@ -12261,7 +12430,7 @@ var lsp = (function (exports) { mountStyles() { this.styleModules = this.state.facet(styleModule); let nonce = this.state.facet(EditorView.cspNonce); - StyleModule.mount(this.root, this.styleModules.concat(baseTheme$1$2).reverse(), nonce ? { nonce } : undefined); + StyleModule.mount(this.root, this.styleModules.concat(baseTheme$1$1).reverse(), nonce ? { nonce } : undefined); } readMeasured() { if (this.updateState == 2 /* UpdateState.Updating */) @@ -12448,8 +12617,8 @@ var lsp = (function (exports) { meaningful (it may just point before or after a placeholder element). */ - domAtPos(pos) { - return this.docView.domAtPos(pos); + domAtPos(pos, side = 1) { + return this.docView.domAtPos(pos, side); } /** Find the document position at the given DOM node. Can be useful @@ -12460,6 +12629,11 @@ var lsp = (function (exports) { return this.docView.posFromDOM(node, offset); } posAtCoords(coords, precise = true) { + this.readMeasured(); + let found = posAtCoords(this, coords, precise); + return found && found.pos; + } + posAndSideAtCoords(coords, precise = true) { this.readMeasured(); return posAtCoords(this, coords, precise); } @@ -12717,8 +12891,8 @@ var lsp = (function (exports) { static findFromDOM(dom) { var _a; let content = dom.querySelector(".cm-content"); - let cView = content && ContentView.get(content) || ContentView.get(dom); - return ((_a = cView === null || cView === void 0 ? void 0 : cView.rootView) === null || _a === void 0 ? void 0 : _a.view) || null; + let tile = content && Tile.get(content) || Tile.get(dom); + return ((_a = tile === null || tile === void 0 ? void 0 : tile.root) === null || _a === void 0 ? void 0 : _a.view) || null; } } /** @@ -12830,11 +13004,19 @@ var lsp = (function (exports) { */ EditorView.decorations = decorations; /** + [Block wrappers](https://codemirror.net/6/docs/ref/#view.BlockWrapper) provide a way to add DOM + structure around editor lines and block widgets. Sets of + wrappers are provided in a similar way to decorations, and are + nested in a similar way when they overlap. A wrapper affects all + lines and block widgets that start inside its range. + */ + EditorView.blockWrappers = blockWrappers; + /** Facet that works much like [`decorations`](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), but puts its inputs at the very bottom of the precedence stack, meaning mark decorations provided here will only be split by other, partially - overlapping \`outerDecorations\` ranges, and wrap around all + overlapping `outerDecorations` ranges, and wrap around all regular decorations. Use this for mark elements that should, as much as possible, remain in one piece. */ @@ -13276,7 +13458,7 @@ var lsp = (function (exports) { return pieces(top).concat(between).concat(pieces(bottom)); } function piece(left, top, right, bottom) { - return new RectangleMarker(className, left - base.left, top - base.top, right - left, bottom - top); + return new RectangleMarker(className, left - base.left, top - base.top, Math.max(0, right - left), bottom - top); } function pieces({ top, bottom, horizontal }) { let pieces = []; @@ -14099,18 +14281,18 @@ var lsp = (function (exports) { let scaleX = 1, scaleY = 1, makeAbsolute = false; if (this.position == "fixed" && this.manager.tooltipViews.length) { let { dom } = this.manager.tooltipViews[0]; - if (browser.gecko) { - // Firefox sets the element's `offsetParent` to the - // transformed element when a transform interferes with fixed - // positioning. - makeAbsolute = dom.offsetParent != this.container.ownerDocument.body; - } - else if (dom.style.top == Outside && dom.style.left == "0px") { - // On other browsers, we have to awkwardly try and use other - // information to detect a transform. + if (browser.safari) { + // Safari always sets offsetParent to null, even if a fixed + // element is positioned relative to a transformed parent. So + // we use this kludge to try and detect this. let rect = dom.getBoundingClientRect(); makeAbsolute = Math.abs(rect.top + 10000) > 1 || Math.abs(rect.left) > 1; } + else { + // More conforming browsers will set offsetParent to the + // transformed element. + makeAbsolute = !!dom.offsetParent && dom.offsetParent != this.container.ownerDocument.body; + } } if (makeAbsolute || this.position == "absolute") { if (this.parent) { @@ -14416,12 +14598,12 @@ var lsp = (function (exports) { startHover() { clearTimeout(this.restartTimeout); let { view, lastMove } = this; - let desc = view.docView.nearest(lastMove.target); - if (!desc) + let tile = view.docView.tile.nearest(lastMove.target); + if (!tile) return; let pos, side = 1; - if (desc instanceof WidgetView) { - pos = desc.posAtStart; + if (tile.isWidget()) { + pos = tile.posAtStart; } else { pos = view.posAtCoords(lastMove); @@ -14495,6 +14677,7 @@ var lsp = (function (exports) { } destroy() { clearTimeout(this.hoverTimeout); + clearTimeout(this.restartTimeout); this.view.dom.removeEventListener("mouseleave", this.mouseleave); this.view.dom.removeEventListener("mousemove", this.mousemove); } @@ -14776,17 +14959,17 @@ var lsp = (function (exports) { let resolve; let promise = new Promise(r => resolve = r); let panelCtor = (view) => createDialog(view, config, resolve); - if (view.state.field(dialogField$1, false)) { + if (view.state.field(dialogField, false)) { view.dispatch({ effects: openDialogEffect.of(panelCtor) }); } else { - view.dispatch({ effects: StateEffect.appendConfig.of(dialogField$1.init(() => [panelCtor])) }); + view.dispatch({ effects: StateEffect.appendConfig.of(dialogField.init(() => [panelCtor])) }); } let close = closeDialogEffect.of(panelCtor); return { close, result: promise.then(form => { let queue = view.win.queueMicrotask || ((f) => view.win.setTimeout(f, 10)); queue(() => { - if (view.state.field(dialogField$1).indexOf(panelCtor) > -1) + if (view.state.field(dialogField).indexOf(panelCtor) > -1) view.dispatch({ effects: close }); }); return form; @@ -14797,7 +14980,7 @@ var lsp = (function (exports) { name as identifier. */ function getDialog(view, className) { - let dialogs = view.state.field(dialogField$1, false) || []; + let dialogs = view.state.field(dialogField, false) || []; for (let open of dialogs) { let panel = getPanel(view, open); if (panel && panel.dom.classList.contains(className)) @@ -14805,7 +14988,7 @@ var lsp = (function (exports) { } return null; } - const dialogField$1 = /*@__PURE__*/StateField.define({ + const dialogField = /*@__PURE__*/StateField.define({ create() { return []; }, update(dialogs, tr) { for (let e of tr.effects) { @@ -15745,40 +15928,31 @@ var lsp = (function (exports) { return pos; } - function createLineDialog(view) { - let line = String(view.state.doc.lineAt(view.state.selection.main.head).number); - let input = crelt("input", { class: "cm-textfield", name: "line", value: line }); - let dom = crelt("form", { - class: "cm-gotoLine", - onkeydown: (event) => { - if (event.keyCode == 27) { // Escape - event.preventDefault(); - view.dispatch({ effects: dialogEffect.of(false) }); - view.focus(); - } - else if (event.keyCode == 13) { // Enter - event.preventDefault(); - go(); - } - }, - onsubmit: (event) => { - event.preventDefault(); - go(); - } - }, crelt("label", view.state.phrase("Go to line"), ": ", input), " ", crelt("button", { class: "cm-button", type: "submit" }, view.state.phrase("go")), crelt("button", { - name: "close", - onclick: () => { - view.dispatch({ effects: dialogEffect.of(false) }); - view.focus(); - }, - "aria-label": view.state.phrase("close"), - type: "button" - }, ["×"])); - function go() { - let match = /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(input.value); - if (!match) + /** + Command that shows a dialog asking the user for a line number, and + when a valid position is provided, moves the cursor to that line. + + Supports line numbers, relative line offsets prefixed with `+` or + `-`, document percentages suffixed with `%`, and an optional + column position by adding `:` and a second number after the line + number. + */ + const gotoLine = view => { + let { state } = view; + let line = String(state.doc.lineAt(view.state.selection.main.head).number); + let { close, result } = showDialog(view, { + label: state.phrase("Go to line"), + input: { type: "text", name: "line", value: line }, + focus: true, + submitLabel: state.phrase("go"), + }); + result.then(form => { + let match = form && /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(form.elements["line"].value); + if (!match) { + view.dispatch({ effects: close }); return; - let { state } = view, startLine = state.doc.lineAt(state.selection.main.head); + } + let startLine = state.doc.lineAt(state.selection.main.head); let [, sign, ln, cl, percent] = match; let col = cl ? +cl.slice(1) : 0; let line = ln ? +ln : startLine.number; @@ -15794,62 +15968,12 @@ var lsp = (function (exports) { let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line))); let selection = EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length))); view.dispatch({ - effects: [dialogEffect.of(false), EditorView.scrollIntoView(selection.from, { y: 'center' })], + effects: [close, EditorView.scrollIntoView(selection.from, { y: 'center' })], selection, }); - view.focus(); - } - return { dom }; - } - const dialogEffect = /*@__PURE__*/StateEffect.define(); - const dialogField = /*@__PURE__*/StateField.define({ - create() { return true; }, - update(value, tr) { - for (let e of tr.effects) - if (e.is(dialogEffect)) - value = e.value; - return value; - }, - provide: f => showPanel.from(f, val => val ? createLineDialog : null) - }); - /** - Command that shows a dialog asking the user for a line number, and - when a valid position is provided, moves the cursor to that line. - - Supports line numbers, relative line offsets prefixed with `+` or - `-`, document percentages suffixed with `%`, and an optional - column position by adding `:` and a second number after the line - number. - */ - const gotoLine = view => { - let panel = getPanel(view, createLineDialog); - if (!panel) { - let effects = [dialogEffect.of(true)]; - if (view.state.field(dialogField, false) == null) - effects.push(StateEffect.appendConfig.of([dialogField, baseTheme$1$1])); - view.dispatch({ effects }); - panel = getPanel(view, createLineDialog); - } - if (panel) - panel.dom.querySelector("input").select(); + }); return true; }; - const baseTheme$1$1 = /*@__PURE__*/EditorView.baseTheme({ - ".cm-panel.cm-gotoLine": { - padding: "2px 6px 4px", - position: "relative", - "& label": { fontSize: "80%" }, - "& [name=close]": { - position: "absolute", - top: "0", bottom: "0", - right: "4px", - backgroundColor: "inherit", - border: "none", - font: "inherit", - padding: "0" - } - } - }); const defaultHighlightOptions = { highlightWordAroundCursor: false, @@ -16036,6 +16160,7 @@ var lsp = (function (exports) { this.valid = !!this.search && (!this.regexp || validRegExp(this.search)); this.unquoted = this.unquote(this.search); this.wholeWord = !!config.wholeWord; + this.test = config.test; } /** @internal @@ -16050,7 +16175,7 @@ var lsp = (function (exports) { eq(other) { return this.search == other.search && this.replace == other.replace && this.caseSensitive == other.caseSensitive && this.regexp == other.regexp && - this.wholeWord == other.wholeWord; + this.wholeWord == other.wholeWord && this.test == other.test; } /** @internal @@ -16074,8 +16199,23 @@ var lsp = (function (exports) { this.spec = spec; } } + function wrapStringTest(test, state, inner) { + return (from, to, buffer, bufferPos) => { + if (inner && !inner(from, to, buffer, bufferPos)) + return false; + let match = from >= bufferPos && to <= bufferPos + buffer.length + ? buffer.slice(from - bufferPos, to - bufferPos) + : state.doc.sliceString(from, to); + return test(match, state, from, to); + }; + } function stringCursor(spec, state, from, to) { - return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined); + let test; + if (spec.wholeWord) + test = stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)); + if (spec.test) + test = wrapStringTest(spec.test, state, test); + return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), test); } function stringWordTest(doc, categorizer) { return (from, to, buf, bufPos) => { @@ -16138,11 +16278,18 @@ var lsp = (function (exports) { add(cursor.value.from, cursor.value.to); } } + function wrapRegexpTest(test, state, inner) { + return (from, to, match) => { + return (!inner || inner(from, to, match)) && test(match[0], state, from, to); + }; + } function regexpCursor(spec, state, from, to) { - return new RegExpCursor(state.doc, spec.search, { - ignoreCase: !spec.caseSensitive, - test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined - }, from, to); + let test; + if (spec.wholeWord) + test = regexpWordTest(state.charCategorizer(state.selection.main.head)); + if (spec.test) + test = wrapRegexpTest(spec.test, state, test); + return new RegExpCursor(state.doc, spec.search, { ignoreCase: !spec.caseSensitive, test }, from, to); } function charBefore(str, index) { return str.slice(findClusterBreak(str, index, false), index); @@ -16903,10 +17050,10 @@ var lsp = (function (exports) { let field = view.state.field(lintState, false); if (!field) return false; - let sel = view.state.selection.main, next = field.diagnostics.iter(sel.to + 1); - if (!next.value) { - next = field.diagnostics.iter(0); - if (!next.value || next.from == sel.from && next.to == sel.to) + let sel = view.state.selection.main, next = findDiagnostic(field.diagnostics, null, sel.to + 1); + if (!next) { + next = findDiagnostic(field.diagnostics, null, 0); + if (!next || next.from == sel.from && next.to == sel.to) return false; } view.dispatch({ selection: { anchor: next.from, head: next.to }, scrollIntoView: true }); @@ -17087,6 +17234,8 @@ var lsp = (function (exports) { this.view = view; this.items = []; let onkeydown = (event) => { + if (event.ctrlKey || event.altKey || event.metaKey) + return; if (event.keyCode == 27) { // Escape closeLintPanel(this.view); this.view.focus(); @@ -17689,10 +17838,17 @@ var lsp = (function (exports) { /** The parser used to create this subtree. */ - parser) { + parser, + /** + [Indicates](#common.IterMode.EnterBracketed) that the nested + content is delineated with some kind + of bracket token. + */ + bracketed = false) { this.tree = tree; this.overlay = overlay; this.parser = parser; + this.bracketed = bracketed; } /** @internal @@ -17897,6 +18053,13 @@ var lsp = (function (exports) { position. */ IterMode[IterMode["IgnoreOverlays"] = 8] = "IgnoreOverlays"; + /** + When set, positions on the boundary of a mounted overlay tree + that has its [`bracketed`](#common.NestedParse.bracketed) flag + set will enter that tree regardless of side. Only supported in + [`enter`](#common.SyntaxNode.enter), not in cursors. + */ + IterMode[IterMode["EnterBracketed"] = 16] = "EnterBracketed"; })(IterMode || (IterMode = {})); /** A piece of syntax tree. There are two ways to approach these @@ -18296,8 +18459,11 @@ var lsp = (function (exports) { nextChild(i, dir, pos, side, mode = 0) { for (let parent = this;;) { for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) { - let next = children[i], start = positions[i] + parent.from; - if (!checkSide(side, pos, start, start + next.length)) + let next = children[i], start = positions[i] + parent.from, mounted; + if (!((mode & IterMode.EnterBracketed) && next instanceof Tree && + (mounted = MountedTree.get(next)) && !mounted.overlay && mounted.bracketed && + pos >= start && pos <= start + next.length) && + !checkSide(side, pos, start, start + next.length)) continue; if (next instanceof TreeBuffer) { if (mode & IterMode.ExcludeBuffers) @@ -18312,7 +18478,7 @@ var lsp = (function (exports) { return new TreeNode(mounted.tree, start, i, parent); let inner = new TreeNode(next, start, i, parent); return (mode & IterMode.IncludeAnonymous) || !inner.type.isAnonymous ? inner - : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side); + : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side, mode); } } if ((mode & IterMode.IncludeAnonymous) || !parent.type.isAnonymous) @@ -18330,13 +18496,14 @@ var lsp = (function (exports) { get lastChild() { return this.nextChild(this._tree.children.length - 1, -1, 0, 4 /* Side.DontCare */); } childAfter(pos) { return this.nextChild(0, 1, pos, 2 /* Side.After */); } childBefore(pos) { return this.nextChild(this._tree.children.length - 1, -1, pos, -2 /* Side.Before */); } + prop(prop) { return this._tree.prop(prop); } enter(pos, side, mode = 0) { let mounted; if (!(mode & IterMode.IgnoreOverlays) && (mounted = MountedTree.get(this._tree)) && mounted.overlay) { - let rPos = pos - this.from; + let rPos = pos - this.from, enterBracketed = (mode & IterMode.EnterBracketed) && mounted.bracketed; for (let { from, to } of mounted.overlay) { - if ((side > 0 ? from <= rPos : from < rPos) && - (side < 0 ? to >= rPos : to > rPos)) + if ((side > 0 || enterBracketed ? from <= rPos : from < rPos) && + (side < 0 || enterBracketed ? to >= rPos : to > rPos)) return new TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this); } } @@ -18423,6 +18590,7 @@ var lsp = (function (exports) { get lastChild() { return this.child(-1, 0, 4 /* Side.DontCare */); } childAfter(pos) { return this.child(1, pos, 2 /* Side.After */); } childBefore(pos) { return this.child(-1, pos, -2 /* Side.Before */); } + prop(prop) { return this.type.prop(prop); } enter(pos, side, mode = 0) { if (mode & IterMode.ExcludeBuffers) return null; @@ -18524,12 +18692,7 @@ var lsp = (function (exports) { /** @internal */ - constructor(node, - /** - @internal - */ - mode = 0) { - this.mode = mode; + constructor(node, mode = 0) { /** @internal */ @@ -18540,6 +18703,7 @@ var lsp = (function (exports) { */ this.index = 0; this.bufferNode = null; + this.mode = mode & ~IterMode.EnterBracketed; if (node instanceof TreeNode) { this.yieldNode(node); } @@ -19004,7 +19168,7 @@ var lsp = (function (exports) { fork.next(); while (fork.pos > startPos) { if (fork.size < 0) { - if (fork.size == -3 /* SpecialRecord.ContextChange */) + if (fork.size == -3 /* SpecialRecord.ContextChange */ || fork.size == -4 /* SpecialRecord.LookAhead */) localSkipped += 4; else break scan; @@ -20333,7 +20497,7 @@ var lsp = (function (exports) { function topNodeAt(state, pos, side) { let topLang = state.facet(language), tree = syntaxTree(state).topNode; if (!topLang || topLang.allowsNesting) { - for (let node = tree; node; node = node.enter(pos, side, IterMode.ExcludeBuffers)) + for (let node = tree; node; node = node.enter(pos, side, IterMode.ExcludeBuffers | IterMode.EnterBracketed)) if (node.type.isTop) tree = node; } @@ -21535,7 +21699,7 @@ var lsp = (function (exports) { }); /** - A highlight style associates CSS styles with higlighting + A highlight style associates CSS styles with highlighting [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag). */ class HighlightStyle { @@ -22556,13 +22720,15 @@ var lsp = (function (exports) { function changeLineComment(option, state, ranges = state.selection.ranges) { let lines = []; let prevLine = -1; - for (let { from, to } of ranges) { - let startI = lines.length, minIndent = 1e9; - let token = getConfig(state, from).line; - if (!token) - continue; + ranges: for (let { from, to } of ranges) { + let startI = lines.length, minIndent = 1e9, token; for (let pos = from; pos <= to;) { let line = state.doc.lineAt(pos); + if (token == undefined) { + token = getConfig(state, line.from).line; + if (!token) + continue ranges; + } if (line.from > prevLine && (from == to || to > line.from)) { prevLine = line.from; let indent = /^\s*/.exec(line.text)[0].length; @@ -22901,7 +23067,8 @@ var lsp = (function (exports) { let branch = side == 0 /* BranchName.Done */ ? this.done : this.undone; if (branch.length == 0) return null; - let event = branch[branch.length - 1], selection = event.selectionsAfter[0] || state.selection; + let event = branch[branch.length - 1], selection = event.selectionsAfter[0] || + (event.startSelection ? event.startSelection.map(event.changes.invertedDesc, 1) : state.selection); if (onlySelection && event.selectionsAfter.length) { return state.update({ selection: event.selectionsAfter[event.selectionsAfter.length - 1], @@ -23584,7 +23751,13 @@ var lsp = (function (exports) { else changes.push({ from: block.to, insert: state.lineBreak + state.doc.slice(block.from, block.to) }); } - dispatch(state.update({ changes, scrollIntoView: true, userEvent: "input.copyline" })); + let changeSet = state.changes(changes); + dispatch(state.update({ + changes: changeSet, + selection: state.selection.map(changeSet, forward ? 1 : -1), + scrollIntoView: true, + userEvent: "input.copyline" + })); return true; } /** @@ -24269,7 +24442,7 @@ var lsp = (function (exports) { addToOptions: [], positionInfo: defaultPositionInfo, filterStrict: false, - compareCompletions: (a, b) => a.label.localeCompare(b.label), + compareCompletions: (a, b) => (a.sortText || a.label).localeCompare(b.sortText || b.label), interactionDelay: 75, updateSyncTime: 100 }, { @@ -28905,6 +29078,8 @@ ${text} option.commitCharacters = item.commitCharacters; if (item.detail) option.detail = item.detail; + if (item.sortText) + option.sortText = item.sortText; if (item.insertTextFormat == 2 /* Snippet */) { option.apply = (view, c, from, to) => snippet(text)(view, c, from, to); option.label = item.label; diff --git a/webapp/static/clients/codemirror/lsp.bundle.js.map b/webapp/static/clients/codemirror/lsp.bundle.js.map index 171ad6a..1e36591 100644 --- a/webapp/static/clients/codemirror/lsp.bundle.js.map +++ b/webapp/static/clients/codemirror/lsp.bundle.js.map @@ -1 +1 @@ -{"version":3,"file":"lsp.bundle.js","sources":["../../../../node_modules/@marijn/find-cluster-break/src/index.js","../../../../node_modules/@codemirror/state/dist/index.js","../../../../node_modules/style-mod/src/style-mod.js","../../../../node_modules/w3c-keyname/index.js","../../../../node_modules/crelt/index.js","../../../../node_modules/@codemirror/view/dist/index.js","../../../../node_modules/@codemirror/search/dist/index.js","../../../../node_modules/@codemirror/lint/dist/index.js","../../../../node_modules/@lezer/common/dist/index.js","../../../../node_modules/@lezer/highlight/dist/index.js","../../../../node_modules/@codemirror/language/dist/index.js","../../../../node_modules/@codemirror/commands/dist/index.js","../../../../node_modules/@codemirror/autocomplete/dist/index.js","../../../../node_modules/marked/lib/marked.esm.js","../../../../node_modules/@codemirror/lsp-client/dist/index.js","../../../../node_modules/@codemirror/legacy-modes/mode/xquery.js","../../../../node_modules/@replit/codemirror-minimap/dist/index.js","../../../../bundles/cm6/lsp.js"],"sourcesContent":["// These are filled with ranges (rangeFrom[i] up to but not including\n// rangeTo[i]) of code points that count as extending characters.\nlet rangeFrom = [], rangeTo = []\n\n;(() => {\n // Compressed representation of the Grapheme_Cluster_Break=Extend\n // information from\n // http://www.unicode.org/Public/16.0.0/ucd/auxiliary/GraphemeBreakProperty.txt.\n // Each pair of elements represents a range, as an offet from the\n // previous range and a length. Numbers are in base-36, with the empty\n // string being a shorthand for 1.\n let numbers = \"lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o\".split(\",\").map(s => s ? parseInt(s, 36) : 1)\n for (let i = 0, n = 0; i < numbers.length; i++)\n (i % 2 ? rangeTo : rangeFrom).push(n = n + numbers[i])\n})()\n\nexport function isExtendingChar(code) {\n if (code < 768) return false\n for (let from = 0, to = rangeFrom.length;;) {\n let mid = (from + to) >> 1\n if (code < rangeFrom[mid]) to = mid\n else if (code >= rangeTo[mid]) from = mid + 1\n else return true\n if (from == to) return false\n }\n}\n\nfunction isRegionalIndicator(code) {\n return code >= 0x1F1E6 && code <= 0x1F1FF\n}\n\nfunction check(code) {\n for (let i = 0; i < rangeFrom.length; i++) {\n if (rangeTo[i] > code) return rangeFrom[i] <= code\n }\n return false\n}\n\nconst ZWJ = 0x200d\n\nexport function findClusterBreak(str, pos, forward = true, includeExtending = true) {\n return (forward ? nextClusterBreak : prevClusterBreak)(str, pos, includeExtending)\n}\n\nfunction nextClusterBreak(str, pos, includeExtending) {\n if (pos == str.length) return pos\n // If pos is in the middle of a surrogate pair, move to its start\n if (pos && surrogateLow(str.charCodeAt(pos)) && surrogateHigh(str.charCodeAt(pos - 1))) pos--\n let prev = codePointAt(str, pos)\n pos += codePointSize(prev)\n while (pos < str.length) {\n let next = codePointAt(str, pos)\n if (prev == ZWJ || next == ZWJ || includeExtending && isExtendingChar(next)) {\n pos += codePointSize(next)\n prev = next\n } else if (isRegionalIndicator(next)) {\n let countBefore = 0, i = pos - 2\n while (i >= 0 && isRegionalIndicator(codePointAt(str, i))) { countBefore++; i -= 2 }\n if (countBefore % 2 == 0) break\n else pos += 2\n } else {\n break\n }\n }\n return pos\n}\n\nfunction prevClusterBreak(str, pos, includeExtending) {\n while (pos > 0) {\n let found = nextClusterBreak(str, pos - 2, includeExtending)\n if (found < pos) return found\n pos--\n }\n return 0\n}\n\nfunction codePointAt(str, pos) {\n let code0 = str.charCodeAt(pos)\n if (!surrogateHigh(code0) || pos + 1 == str.length) return code0\n let code1 = str.charCodeAt(pos + 1)\n if (!surrogateLow(code1)) return code0\n return ((code0 - 0xd800) << 10) + (code1 - 0xdc00) + 0x10000\n}\n\nfunction surrogateLow(ch) { return ch >= 0xDC00 && ch < 0xE000 }\nfunction surrogateHigh(ch) { return ch >= 0xD800 && ch < 0xDC00 }\nfunction codePointSize(code) { return code < 0x10000 ? 1 : 2 }\n","import { findClusterBreak as findClusterBreak$1 } from '@marijn/find-cluster-break';\n\n/**\nThe data structure for documents. @nonabstract\n*/\nclass Text {\n /**\n Get the line description around the given position.\n */\n lineAt(pos) {\n if (pos < 0 || pos > this.length)\n throw new RangeError(`Invalid position ${pos} in document of length ${this.length}`);\n return this.lineInner(pos, false, 1, 0);\n }\n /**\n Get the description for the given (1-based) line number.\n */\n line(n) {\n if (n < 1 || n > this.lines)\n throw new RangeError(`Invalid line number ${n} in ${this.lines}-line document`);\n return this.lineInner(n, true, 1, 0);\n }\n /**\n Replace a range of the text with the given content.\n */\n replace(from, to, text) {\n [from, to] = clip(this, from, to);\n let parts = [];\n this.decompose(0, from, parts, 2 /* Open.To */);\n if (text.length)\n text.decompose(0, text.length, parts, 1 /* Open.From */ | 2 /* Open.To */);\n this.decompose(to, this.length, parts, 1 /* Open.From */);\n return TextNode.from(parts, this.length - (to - from) + text.length);\n }\n /**\n Append another document to this one.\n */\n append(other) {\n return this.replace(this.length, this.length, other);\n }\n /**\n Retrieve the text between the given points.\n */\n slice(from, to = this.length) {\n [from, to] = clip(this, from, to);\n let parts = [];\n this.decompose(from, to, parts, 0);\n return TextNode.from(parts, to - from);\n }\n /**\n Test whether this text is equal to another instance.\n */\n eq(other) {\n if (other == this)\n return true;\n if (other.length != this.length || other.lines != this.lines)\n return false;\n let start = this.scanIdentical(other, 1), end = this.length - this.scanIdentical(other, -1);\n let a = new RawTextCursor(this), b = new RawTextCursor(other);\n for (let skip = start, pos = start;;) {\n a.next(skip);\n b.next(skip);\n skip = 0;\n if (a.lineBreak != b.lineBreak || a.done != b.done || a.value != b.value)\n return false;\n pos += a.value.length;\n if (a.done || pos >= end)\n return true;\n }\n }\n /**\n Iterate over the text. When `dir` is `-1`, iteration happens\n from end to start. This will return lines and the breaks between\n them as separate strings.\n */\n iter(dir = 1) { return new RawTextCursor(this, dir); }\n /**\n Iterate over a range of the text. When `from` > `to`, the\n iterator will run in reverse.\n */\n iterRange(from, to = this.length) { return new PartialTextCursor(this, from, to); }\n /**\n Return a cursor that iterates over the given range of lines,\n _without_ returning the line breaks between, and yielding empty\n strings for empty lines.\n \n When `from` and `to` are given, they should be 1-based line numbers.\n */\n iterLines(from, to) {\n let inner;\n if (from == null) {\n inner = this.iter();\n }\n else {\n if (to == null)\n to = this.lines + 1;\n let start = this.line(from).from;\n inner = this.iterRange(start, Math.max(start, to == this.lines + 1 ? this.length : to <= 1 ? 0 : this.line(to - 1).to));\n }\n return new LineCursor(inner);\n }\n /**\n Return the document as a string, using newline characters to\n separate lines.\n */\n toString() { return this.sliceString(0); }\n /**\n Convert the document to an array of lines (which can be\n deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).\n */\n toJSON() {\n let lines = [];\n this.flatten(lines);\n return lines;\n }\n /**\n @internal\n */\n constructor() { }\n /**\n Create a `Text` instance for the given array of lines.\n */\n static of(text) {\n if (text.length == 0)\n throw new RangeError(\"A document must have at least one line\");\n if (text.length == 1 && !text[0])\n return Text.empty;\n return text.length <= 32 /* Tree.Branch */ ? new TextLeaf(text) : TextNode.from(TextLeaf.split(text, []));\n }\n}\n// Leaves store an array of line strings. There are always line breaks\n// between these strings. Leaves are limited in size and have to be\n// contained in TextNode instances for bigger documents.\nclass TextLeaf extends Text {\n constructor(text, length = textLength(text)) {\n super();\n this.text = text;\n this.length = length;\n }\n get lines() { return this.text.length; }\n get children() { return null; }\n lineInner(target, isLine, line, offset) {\n for (let i = 0;; i++) {\n let string = this.text[i], end = offset + string.length;\n if ((isLine ? line : end) >= target)\n return new Line(offset, end, line, string);\n offset = end + 1;\n line++;\n }\n }\n decompose(from, to, target, open) {\n let text = from <= 0 && to >= this.length ? this\n : new TextLeaf(sliceText(this.text, from, to), Math.min(to, this.length) - Math.max(0, from));\n if (open & 1 /* Open.From */) {\n let prev = target.pop();\n let joined = appendText(text.text, prev.text.slice(), 0, text.length);\n if (joined.length <= 32 /* Tree.Branch */) {\n target.push(new TextLeaf(joined, prev.length + text.length));\n }\n else {\n let mid = joined.length >> 1;\n target.push(new TextLeaf(joined.slice(0, mid)), new TextLeaf(joined.slice(mid)));\n }\n }\n else {\n target.push(text);\n }\n }\n replace(from, to, text) {\n if (!(text instanceof TextLeaf))\n return super.replace(from, to, text);\n [from, to] = clip(this, from, to);\n let lines = appendText(this.text, appendText(text.text, sliceText(this.text, 0, from)), to);\n let newLen = this.length + text.length - (to - from);\n if (lines.length <= 32 /* Tree.Branch */)\n return new TextLeaf(lines, newLen);\n return TextNode.from(TextLeaf.split(lines, []), newLen);\n }\n sliceString(from, to = this.length, lineSep = \"\\n\") {\n [from, to] = clip(this, from, to);\n let result = \"\";\n for (let pos = 0, i = 0; pos <= to && i < this.text.length; i++) {\n let line = this.text[i], end = pos + line.length;\n if (pos > from && i)\n result += lineSep;\n if (from < end && to > pos)\n result += line.slice(Math.max(0, from - pos), to - pos);\n pos = end + 1;\n }\n return result;\n }\n flatten(target) {\n for (let line of this.text)\n target.push(line);\n }\n scanIdentical() { return 0; }\n static split(text, target) {\n let part = [], len = -1;\n for (let line of text) {\n part.push(line);\n len += line.length + 1;\n if (part.length == 32 /* Tree.Branch */) {\n target.push(new TextLeaf(part, len));\n part = [];\n len = -1;\n }\n }\n if (len > -1)\n target.push(new TextLeaf(part, len));\n return target;\n }\n}\n// Nodes provide the tree structure of the `Text` type. They store a\n// number of other nodes or leaves, taking care to balance themselves\n// on changes. There are implied line breaks _between_ the children of\n// a node (but not before the first or after the last child).\nclass TextNode extends Text {\n constructor(children, length) {\n super();\n this.children = children;\n this.length = length;\n this.lines = 0;\n for (let child of children)\n this.lines += child.lines;\n }\n lineInner(target, isLine, line, offset) {\n for (let i = 0;; i++) {\n let child = this.children[i], end = offset + child.length, endLine = line + child.lines - 1;\n if ((isLine ? endLine : end) >= target)\n return child.lineInner(target, isLine, line, offset);\n offset = end + 1;\n line = endLine + 1;\n }\n }\n decompose(from, to, target, open) {\n for (let i = 0, pos = 0; pos <= to && i < this.children.length; i++) {\n let child = this.children[i], end = pos + child.length;\n if (from <= end && to >= pos) {\n let childOpen = open & ((pos <= from ? 1 /* Open.From */ : 0) | (end >= to ? 2 /* Open.To */ : 0));\n if (pos >= from && end <= to && !childOpen)\n target.push(child);\n else\n child.decompose(from - pos, to - pos, target, childOpen);\n }\n pos = end + 1;\n }\n }\n replace(from, to, text) {\n [from, to] = clip(this, from, to);\n if (text.lines < this.lines)\n for (let i = 0, pos = 0; i < this.children.length; i++) {\n let child = this.children[i], end = pos + child.length;\n // Fast path: if the change only affects one child and the\n // child's size remains in the acceptable range, only update\n // that child\n if (from >= pos && to <= end) {\n let updated = child.replace(from - pos, to - pos, text);\n let totalLines = this.lines - child.lines + updated.lines;\n if (updated.lines < (totalLines >> (5 /* Tree.BranchShift */ - 1)) &&\n updated.lines > (totalLines >> (5 /* Tree.BranchShift */ + 1))) {\n let copy = this.children.slice();\n copy[i] = updated;\n return new TextNode(copy, this.length - (to - from) + text.length);\n }\n return super.replace(pos, end, updated);\n }\n pos = end + 1;\n }\n return super.replace(from, to, text);\n }\n sliceString(from, to = this.length, lineSep = \"\\n\") {\n [from, to] = clip(this, from, to);\n let result = \"\";\n for (let i = 0, pos = 0; i < this.children.length && pos <= to; i++) {\n let child = this.children[i], end = pos + child.length;\n if (pos > from && i)\n result += lineSep;\n if (from < end && to > pos)\n result += child.sliceString(from - pos, to - pos, lineSep);\n pos = end + 1;\n }\n return result;\n }\n flatten(target) {\n for (let child of this.children)\n child.flatten(target);\n }\n scanIdentical(other, dir) {\n if (!(other instanceof TextNode))\n return 0;\n let length = 0;\n let [iA, iB, eA, eB] = dir > 0 ? [0, 0, this.children.length, other.children.length]\n : [this.children.length - 1, other.children.length - 1, -1, -1];\n for (;; iA += dir, iB += dir) {\n if (iA == eA || iB == eB)\n return length;\n let chA = this.children[iA], chB = other.children[iB];\n if (chA != chB)\n return length + chA.scanIdentical(chB, dir);\n length += chA.length + 1;\n }\n }\n static from(children, length = children.reduce((l, ch) => l + ch.length + 1, -1)) {\n let lines = 0;\n for (let ch of children)\n lines += ch.lines;\n if (lines < 32 /* Tree.Branch */) {\n let flat = [];\n for (let ch of children)\n ch.flatten(flat);\n return new TextLeaf(flat, length);\n }\n let chunk = Math.max(32 /* Tree.Branch */, lines >> 5 /* Tree.BranchShift */), maxChunk = chunk << 1, minChunk = chunk >> 1;\n let chunked = [], currentLines = 0, currentLen = -1, currentChunk = [];\n function add(child) {\n let last;\n if (child.lines > maxChunk && child instanceof TextNode) {\n for (let node of child.children)\n add(node);\n }\n else if (child.lines > minChunk && (currentLines > minChunk || !currentLines)) {\n flush();\n chunked.push(child);\n }\n else if (child instanceof TextLeaf && currentLines &&\n (last = currentChunk[currentChunk.length - 1]) instanceof TextLeaf &&\n child.lines + last.lines <= 32 /* Tree.Branch */) {\n currentLines += child.lines;\n currentLen += child.length + 1;\n currentChunk[currentChunk.length - 1] = new TextLeaf(last.text.concat(child.text), last.length + 1 + child.length);\n }\n else {\n if (currentLines + child.lines > chunk)\n flush();\n currentLines += child.lines;\n currentLen += child.length + 1;\n currentChunk.push(child);\n }\n }\n function flush() {\n if (currentLines == 0)\n return;\n chunked.push(currentChunk.length == 1 ? currentChunk[0] : TextNode.from(currentChunk, currentLen));\n currentLen = -1;\n currentLines = currentChunk.length = 0;\n }\n for (let child of children)\n add(child);\n flush();\n return chunked.length == 1 ? chunked[0] : new TextNode(chunked, length);\n }\n}\nText.empty = /*@__PURE__*/new TextLeaf([\"\"], 0);\nfunction textLength(text) {\n let length = -1;\n for (let line of text)\n length += line.length + 1;\n return length;\n}\nfunction appendText(text, target, from = 0, to = 1e9) {\n for (let pos = 0, i = 0, first = true; i < text.length && pos <= to; i++) {\n let line = text[i], end = pos + line.length;\n if (end >= from) {\n if (end > to)\n line = line.slice(0, to - pos);\n if (pos < from)\n line = line.slice(from - pos);\n if (first) {\n target[target.length - 1] += line;\n first = false;\n }\n else\n target.push(line);\n }\n pos = end + 1;\n }\n return target;\n}\nfunction sliceText(text, from, to) {\n return appendText(text, [\"\"], from, to);\n}\nclass RawTextCursor {\n constructor(text, dir = 1) {\n this.dir = dir;\n this.done = false;\n this.lineBreak = false;\n this.value = \"\";\n this.nodes = [text];\n this.offsets = [dir > 0 ? 1 : (text instanceof TextLeaf ? text.text.length : text.children.length) << 1];\n }\n nextInner(skip, dir) {\n this.done = this.lineBreak = false;\n for (;;) {\n let last = this.nodes.length - 1;\n let top = this.nodes[last], offsetValue = this.offsets[last], offset = offsetValue >> 1;\n let size = top instanceof TextLeaf ? top.text.length : top.children.length;\n if (offset == (dir > 0 ? size : 0)) {\n if (last == 0) {\n this.done = true;\n this.value = \"\";\n return this;\n }\n if (dir > 0)\n this.offsets[last - 1]++;\n this.nodes.pop();\n this.offsets.pop();\n }\n else if ((offsetValue & 1) == (dir > 0 ? 0 : 1)) {\n this.offsets[last] += dir;\n if (skip == 0) {\n this.lineBreak = true;\n this.value = \"\\n\";\n return this;\n }\n skip--;\n }\n else if (top instanceof TextLeaf) {\n // Move to the next string\n let next = top.text[offset + (dir < 0 ? -1 : 0)];\n this.offsets[last] += dir;\n if (next.length > Math.max(0, skip)) {\n this.value = skip == 0 ? next : dir > 0 ? next.slice(skip) : next.slice(0, next.length - skip);\n return this;\n }\n skip -= next.length;\n }\n else {\n let next = top.children[offset + (dir < 0 ? -1 : 0)];\n if (skip > next.length) {\n skip -= next.length;\n this.offsets[last] += dir;\n }\n else {\n if (dir < 0)\n this.offsets[last]--;\n this.nodes.push(next);\n this.offsets.push(dir > 0 ? 1 : (next instanceof TextLeaf ? next.text.length : next.children.length) << 1);\n }\n }\n }\n }\n next(skip = 0) {\n if (skip < 0) {\n this.nextInner(-skip, (-this.dir));\n skip = this.value.length;\n }\n return this.nextInner(skip, this.dir);\n }\n}\nclass PartialTextCursor {\n constructor(text, start, end) {\n this.value = \"\";\n this.done = false;\n this.cursor = new RawTextCursor(text, start > end ? -1 : 1);\n this.pos = start > end ? text.length : 0;\n this.from = Math.min(start, end);\n this.to = Math.max(start, end);\n }\n nextInner(skip, dir) {\n if (dir < 0 ? this.pos <= this.from : this.pos >= this.to) {\n this.value = \"\";\n this.done = true;\n return this;\n }\n skip += Math.max(0, dir < 0 ? this.pos - this.to : this.from - this.pos);\n let limit = dir < 0 ? this.pos - this.from : this.to - this.pos;\n if (skip > limit)\n skip = limit;\n limit -= skip;\n let { value } = this.cursor.next(skip);\n this.pos += (value.length + skip) * dir;\n this.value = value.length <= limit ? value : dir < 0 ? value.slice(value.length - limit) : value.slice(0, limit);\n this.done = !this.value;\n return this;\n }\n next(skip = 0) {\n if (skip < 0)\n skip = Math.max(skip, this.from - this.pos);\n else if (skip > 0)\n skip = Math.min(skip, this.to - this.pos);\n return this.nextInner(skip, this.cursor.dir);\n }\n get lineBreak() { return this.cursor.lineBreak && this.value != \"\"; }\n}\nclass LineCursor {\n constructor(inner) {\n this.inner = inner;\n this.afterBreak = true;\n this.value = \"\";\n this.done = false;\n }\n next(skip = 0) {\n let { done, lineBreak, value } = this.inner.next(skip);\n if (done && this.afterBreak) {\n this.value = \"\";\n this.afterBreak = false;\n }\n else if (done) {\n this.done = true;\n this.value = \"\";\n }\n else if (lineBreak) {\n if (this.afterBreak) {\n this.value = \"\";\n }\n else {\n this.afterBreak = true;\n this.next();\n }\n }\n else {\n this.value = value;\n this.afterBreak = false;\n }\n return this;\n }\n get lineBreak() { return false; }\n}\nif (typeof Symbol != \"undefined\") {\n Text.prototype[Symbol.iterator] = function () { return this.iter(); };\n RawTextCursor.prototype[Symbol.iterator] = PartialTextCursor.prototype[Symbol.iterator] =\n LineCursor.prototype[Symbol.iterator] = function () { return this; };\n}\n/**\nThis type describes a line in the document. It is created\non-demand when lines are [queried](https://codemirror.net/6/docs/ref/#state.Text.lineAt).\n*/\nclass Line {\n /**\n @internal\n */\n constructor(\n /**\n The position of the start of the line.\n */\n from, \n /**\n The position at the end of the line (_before_ the line break,\n or at the end of document for the last line).\n */\n to, \n /**\n This line's line number (1-based).\n */\n number, \n /**\n The line's content.\n */\n text) {\n this.from = from;\n this.to = to;\n this.number = number;\n this.text = text;\n }\n /**\n The length of the line (not including any line break after it).\n */\n get length() { return this.to - this.from; }\n}\nfunction clip(text, from, to) {\n from = Math.max(0, Math.min(text.length, from));\n return [from, Math.max(from, Math.min(text.length, to))];\n}\n\n/**\nReturns a next grapheme cluster break _after_ (not equal to)\n`pos`, if `forward` is true, or before otherwise. Returns `pos`\nitself if no further cluster break is available in the string.\nMoves across surrogate pairs, extending characters (when\n`includeExtending` is true), characters joined with zero-width\njoiners, and flag emoji.\n*/\nfunction findClusterBreak(str, pos, forward = true, includeExtending = true) {\n return findClusterBreak$1(str, pos, forward, includeExtending);\n}\nfunction surrogateLow(ch) { return ch >= 0xDC00 && ch < 0xE000; }\nfunction surrogateHigh(ch) { return ch >= 0xD800 && ch < 0xDC00; }\n/**\nFind the code point at the given position in a string (like the\n[`codePointAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)\nstring method).\n*/\nfunction codePointAt(str, pos) {\n let code0 = str.charCodeAt(pos);\n if (!surrogateHigh(code0) || pos + 1 == str.length)\n return code0;\n let code1 = str.charCodeAt(pos + 1);\n if (!surrogateLow(code1))\n return code0;\n return ((code0 - 0xd800) << 10) + (code1 - 0xdc00) + 0x10000;\n}\n/**\nGiven a Unicode codepoint, return the JavaScript string that\nrespresents it (like\n[`String.fromCodePoint`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)).\n*/\nfunction fromCodePoint(code) {\n if (code <= 0xffff)\n return String.fromCharCode(code);\n code -= 0x10000;\n return String.fromCharCode((code >> 10) + 0xd800, (code & 1023) + 0xdc00);\n}\n/**\nThe amount of positions a character takes up in a JavaScript string.\n*/\nfunction codePointSize(code) { return code < 0x10000 ? 1 : 2; }\n\nconst DefaultSplit = /\\r\\n?|\\n/;\n/**\nDistinguishes different ways in which positions can be mapped.\n*/\nvar MapMode = /*@__PURE__*/(function (MapMode) {\n /**\n Map a position to a valid new position, even when its context\n was deleted.\n */\n MapMode[MapMode[\"Simple\"] = 0] = \"Simple\";\n /**\n Return null if deletion happens across the position.\n */\n MapMode[MapMode[\"TrackDel\"] = 1] = \"TrackDel\";\n /**\n Return null if the character _before_ the position is deleted.\n */\n MapMode[MapMode[\"TrackBefore\"] = 2] = \"TrackBefore\";\n /**\n Return null if the character _after_ the position is deleted.\n */\n MapMode[MapMode[\"TrackAfter\"] = 3] = \"TrackAfter\";\nreturn MapMode})(MapMode || (MapMode = {}));\n/**\nA change description is a variant of [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet)\nthat doesn't store the inserted text. As such, it can't be\napplied, but is cheaper to store and manipulate.\n*/\nclass ChangeDesc {\n // Sections are encoded as pairs of integers. The first is the\n // length in the current document, and the second is -1 for\n // unaffected sections, and the length of the replacement content\n // otherwise. So an insertion would be (0, n>0), a deletion (n>0,\n // 0), and a replacement two positive numbers.\n /**\n @internal\n */\n constructor(\n /**\n @internal\n */\n sections) {\n this.sections = sections;\n }\n /**\n The length of the document before the change.\n */\n get length() {\n let result = 0;\n for (let i = 0; i < this.sections.length; i += 2)\n result += this.sections[i];\n return result;\n }\n /**\n The length of the document after the change.\n */\n get newLength() {\n let result = 0;\n for (let i = 0; i < this.sections.length; i += 2) {\n let ins = this.sections[i + 1];\n result += ins < 0 ? this.sections[i] : ins;\n }\n return result;\n }\n /**\n False when there are actual changes in this set.\n */\n get empty() { return this.sections.length == 0 || this.sections.length == 2 && this.sections[1] < 0; }\n /**\n Iterate over the unchanged parts left by these changes. `posA`\n provides the position of the range in the old document, `posB`\n the new position in the changed document.\n */\n iterGaps(f) {\n for (let i = 0, posA = 0, posB = 0; i < this.sections.length;) {\n let len = this.sections[i++], ins = this.sections[i++];\n if (ins < 0) {\n f(posA, posB, len);\n posB += len;\n }\n else {\n posB += ins;\n }\n posA += len;\n }\n }\n /**\n Iterate over the ranges changed by these changes. (See\n [`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a\n variant that also provides you with the inserted text.)\n `fromA`/`toA` provides the extent of the change in the starting\n document, `fromB`/`toB` the extent of the replacement in the\n changed document.\n \n When `individual` is true, adjacent changes (which are kept\n separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are\n reported separately.\n */\n iterChangedRanges(f, individual = false) {\n iterChanges(this, f, individual);\n }\n /**\n Get a description of the inverted form of these changes.\n */\n get invertedDesc() {\n let sections = [];\n for (let i = 0; i < this.sections.length;) {\n let len = this.sections[i++], ins = this.sections[i++];\n if (ins < 0)\n sections.push(len, ins);\n else\n sections.push(ins, len);\n }\n return new ChangeDesc(sections);\n }\n /**\n Compute the combined effect of applying another set of changes\n after this one. The length of the document after this set should\n match the length before `other`.\n */\n composeDesc(other) { return this.empty ? other : other.empty ? this : composeSets(this, other); }\n /**\n Map this description, which should start with the same document\n as `other`, over another set of changes, so that it can be\n applied after it. When `before` is true, map as if the changes\n in `this` happened before the ones in `other`.\n */\n mapDesc(other, before = false) { return other.empty ? this : mapSet(this, other, before); }\n mapPos(pos, assoc = -1, mode = MapMode.Simple) {\n let posA = 0, posB = 0;\n for (let i = 0; i < this.sections.length;) {\n let len = this.sections[i++], ins = this.sections[i++], endA = posA + len;\n if (ins < 0) {\n if (endA > pos)\n return posB + (pos - posA);\n posB += len;\n }\n else {\n if (mode != MapMode.Simple && endA >= pos &&\n (mode == MapMode.TrackDel && posA < pos && endA > pos ||\n mode == MapMode.TrackBefore && posA < pos ||\n mode == MapMode.TrackAfter && endA > pos))\n return null;\n if (endA > pos || endA == pos && assoc < 0 && !len)\n return pos == posA || assoc < 0 ? posB : posB + ins;\n posB += ins;\n }\n posA = endA;\n }\n if (pos > posA)\n throw new RangeError(`Position ${pos} is out of range for changeset of length ${posA}`);\n return posB;\n }\n /**\n Check whether these changes touch a given range. When one of the\n changes entirely covers the range, the string `\"cover\"` is\n returned.\n */\n touchesRange(from, to = from) {\n for (let i = 0, pos = 0; i < this.sections.length && pos <= to;) {\n let len = this.sections[i++], ins = this.sections[i++], end = pos + len;\n if (ins >= 0 && pos <= to && end >= from)\n return pos < from && end > to ? \"cover\" : true;\n pos = end;\n }\n return false;\n }\n /**\n @internal\n */\n toString() {\n let result = \"\";\n for (let i = 0; i < this.sections.length;) {\n let len = this.sections[i++], ins = this.sections[i++];\n result += (result ? \" \" : \"\") + len + (ins >= 0 ? \":\" + ins : \"\");\n }\n return result;\n }\n /**\n Serialize this change desc to a JSON-representable value.\n */\n toJSON() { return this.sections; }\n /**\n Create a change desc from its JSON representation (as produced\n by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON).\n */\n static fromJSON(json) {\n if (!Array.isArray(json) || json.length % 2 || json.some(a => typeof a != \"number\"))\n throw new RangeError(\"Invalid JSON representation of ChangeDesc\");\n return new ChangeDesc(json);\n }\n /**\n @internal\n */\n static create(sections) { return new ChangeDesc(sections); }\n}\n/**\nA change set represents a group of modifications to a document. It\nstores the document length, and can only be applied to documents\nwith exactly that length.\n*/\nclass ChangeSet extends ChangeDesc {\n constructor(sections, \n /**\n @internal\n */\n inserted) {\n super(sections);\n this.inserted = inserted;\n }\n /**\n Apply the changes to a document, returning the modified\n document.\n */\n apply(doc) {\n if (this.length != doc.length)\n throw new RangeError(\"Applying change set to a document with the wrong length\");\n iterChanges(this, (fromA, toA, fromB, _toB, text) => doc = doc.replace(fromB, fromB + (toA - fromA), text), false);\n return doc;\n }\n mapDesc(other, before = false) { return mapSet(this, other, before, true); }\n /**\n Given the document as it existed _before_ the changes, return a\n change set that represents the inverse of this set, which could\n be used to go from the document created by the changes back to\n the document as it existed before the changes.\n */\n invert(doc) {\n let sections = this.sections.slice(), inserted = [];\n for (let i = 0, pos = 0; i < sections.length; i += 2) {\n let len = sections[i], ins = sections[i + 1];\n if (ins >= 0) {\n sections[i] = ins;\n sections[i + 1] = len;\n let index = i >> 1;\n while (inserted.length < index)\n inserted.push(Text.empty);\n inserted.push(len ? doc.slice(pos, pos + len) : Text.empty);\n }\n pos += len;\n }\n return new ChangeSet(sections, inserted);\n }\n /**\n Combine two subsequent change sets into a single set. `other`\n must start in the document produced by `this`. If `this` goes\n `docA` → `docB` and `other` represents `docB` → `docC`, the\n returned value will represent the change `docA` → `docC`.\n */\n compose(other) { return this.empty ? other : other.empty ? this : composeSets(this, other, true); }\n /**\n Given another change set starting in the same document, maps this\n change set over the other, producing a new change set that can be\n applied to the document produced by applying `other`. When\n `before` is `true`, order changes as if `this` comes before\n `other`, otherwise (the default) treat `other` as coming first.\n \n Given two changes `A` and `B`, `A.compose(B.map(A))` and\n `B.compose(A.map(B, true))` will produce the same document. This\n provides a basic form of [operational\n transformation](https://en.wikipedia.org/wiki/Operational_transformation),\n and can be used for collaborative editing.\n */\n map(other, before = false) { return other.empty ? this : mapSet(this, other, before, true); }\n /**\n Iterate over the changed ranges in the document, calling `f` for\n each, with the range in the original document (`fromA`-`toA`)\n and the range that replaces it in the new document\n (`fromB`-`toB`).\n \n When `individual` is true, adjacent changes are reported\n separately.\n */\n iterChanges(f, individual = false) {\n iterChanges(this, f, individual);\n }\n /**\n Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change\n set.\n */\n get desc() { return ChangeDesc.create(this.sections); }\n /**\n @internal\n */\n filter(ranges) {\n let resultSections = [], resultInserted = [], filteredSections = [];\n let iter = new SectionIter(this);\n done: for (let i = 0, pos = 0;;) {\n let next = i == ranges.length ? 1e9 : ranges[i++];\n while (pos < next || pos == next && iter.len == 0) {\n if (iter.done)\n break done;\n let len = Math.min(iter.len, next - pos);\n addSection(filteredSections, len, -1);\n let ins = iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0;\n addSection(resultSections, len, ins);\n if (ins > 0)\n addInsert(resultInserted, resultSections, iter.text);\n iter.forward(len);\n pos += len;\n }\n let end = ranges[i++];\n while (pos < end) {\n if (iter.done)\n break done;\n let len = Math.min(iter.len, end - pos);\n addSection(resultSections, len, -1);\n addSection(filteredSections, len, iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0);\n iter.forward(len);\n pos += len;\n }\n }\n return { changes: new ChangeSet(resultSections, resultInserted),\n filtered: ChangeDesc.create(filteredSections) };\n }\n /**\n Serialize this change set to a JSON-representable value.\n */\n toJSON() {\n let parts = [];\n for (let i = 0; i < this.sections.length; i += 2) {\n let len = this.sections[i], ins = this.sections[i + 1];\n if (ins < 0)\n parts.push(len);\n else if (ins == 0)\n parts.push([len]);\n else\n parts.push([len].concat(this.inserted[i >> 1].toJSON()));\n }\n return parts;\n }\n /**\n Create a change set for the given changes, for a document of the\n given length, using `lineSep` as line separator.\n */\n static of(changes, length, lineSep) {\n let sections = [], inserted = [], pos = 0;\n let total = null;\n function flush(force = false) {\n if (!force && !sections.length)\n return;\n if (pos < length)\n addSection(sections, length - pos, -1);\n let set = new ChangeSet(sections, inserted);\n total = total ? total.compose(set.map(total)) : set;\n sections = [];\n inserted = [];\n pos = 0;\n }\n function process(spec) {\n if (Array.isArray(spec)) {\n for (let sub of spec)\n process(sub);\n }\n else if (spec instanceof ChangeSet) {\n if (spec.length != length)\n throw new RangeError(`Mismatched change set length (got ${spec.length}, expected ${length})`);\n flush();\n total = total ? total.compose(spec.map(total)) : spec;\n }\n else {\n let { from, to = from, insert } = spec;\n if (from > to || from < 0 || to > length)\n throw new RangeError(`Invalid change range ${from} to ${to} (in doc of length ${length})`);\n let insText = !insert ? Text.empty : typeof insert == \"string\" ? Text.of(insert.split(lineSep || DefaultSplit)) : insert;\n let insLen = insText.length;\n if (from == to && insLen == 0)\n return;\n if (from < pos)\n flush();\n if (from > pos)\n addSection(sections, from - pos, -1);\n addSection(sections, to - from, insLen);\n addInsert(inserted, sections, insText);\n pos = to;\n }\n }\n process(changes);\n flush(!total);\n return total;\n }\n /**\n Create an empty changeset of the given length.\n */\n static empty(length) {\n return new ChangeSet(length ? [length, -1] : [], []);\n }\n /**\n Create a changeset from its JSON representation (as produced by\n [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).\n */\n static fromJSON(json) {\n if (!Array.isArray(json))\n throw new RangeError(\"Invalid JSON representation of ChangeSet\");\n let sections = [], inserted = [];\n for (let i = 0; i < json.length; i++) {\n let part = json[i];\n if (typeof part == \"number\") {\n sections.push(part, -1);\n }\n else if (!Array.isArray(part) || typeof part[0] != \"number\" || part.some((e, i) => i && typeof e != \"string\")) {\n throw new RangeError(\"Invalid JSON representation of ChangeSet\");\n }\n else if (part.length == 1) {\n sections.push(part[0], 0);\n }\n else {\n while (inserted.length < i)\n inserted.push(Text.empty);\n inserted[i] = Text.of(part.slice(1));\n sections.push(part[0], inserted[i].length);\n }\n }\n return new ChangeSet(sections, inserted);\n }\n /**\n @internal\n */\n static createSet(sections, inserted) {\n return new ChangeSet(sections, inserted);\n }\n}\nfunction addSection(sections, len, ins, forceJoin = false) {\n if (len == 0 && ins <= 0)\n return;\n let last = sections.length - 2;\n if (last >= 0 && ins <= 0 && ins == sections[last + 1])\n sections[last] += len;\n else if (last >= 0 && len == 0 && sections[last] == 0)\n sections[last + 1] += ins;\n else if (forceJoin) {\n sections[last] += len;\n sections[last + 1] += ins;\n }\n else\n sections.push(len, ins);\n}\nfunction addInsert(values, sections, value) {\n if (value.length == 0)\n return;\n let index = (sections.length - 2) >> 1;\n if (index < values.length) {\n values[values.length - 1] = values[values.length - 1].append(value);\n }\n else {\n while (values.length < index)\n values.push(Text.empty);\n values.push(value);\n }\n}\nfunction iterChanges(desc, f, individual) {\n let inserted = desc.inserted;\n for (let posA = 0, posB = 0, i = 0; i < desc.sections.length;) {\n let len = desc.sections[i++], ins = desc.sections[i++];\n if (ins < 0) {\n posA += len;\n posB += len;\n }\n else {\n let endA = posA, endB = posB, text = Text.empty;\n for (;;) {\n endA += len;\n endB += ins;\n if (ins && inserted)\n text = text.append(inserted[(i - 2) >> 1]);\n if (individual || i == desc.sections.length || desc.sections[i + 1] < 0)\n break;\n len = desc.sections[i++];\n ins = desc.sections[i++];\n }\n f(posA, endA, posB, endB, text);\n posA = endA;\n posB = endB;\n }\n }\n}\nfunction mapSet(setA, setB, before, mkSet = false) {\n // Produce a copy of setA that applies to the document after setB\n // has been applied (assuming both start at the same document).\n let sections = [], insert = mkSet ? [] : null;\n let a = new SectionIter(setA), b = new SectionIter(setB);\n // Iterate over both sets in parallel. inserted tracks, for changes\n // in A that have to be processed piece-by-piece, whether their\n // content has been inserted already, and refers to the section\n // index.\n for (let inserted = -1;;) {\n if (a.done && b.len || b.done && a.len) {\n throw new Error(\"Mismatched change set lengths\");\n }\n else if (a.ins == -1 && b.ins == -1) {\n // Move across ranges skipped by both sets.\n let len = Math.min(a.len, b.len);\n addSection(sections, len, -1);\n a.forward(len);\n b.forward(len);\n }\n else if (b.ins >= 0 && (a.ins < 0 || inserted == a.i || a.off == 0 && (b.len < a.len || b.len == a.len && !before))) {\n // If there's a change in B that comes before the next change in\n // A (ordered by start pos, then len, then before flag), skip\n // that (and process any changes in A it covers).\n let len = b.len;\n addSection(sections, b.ins, -1);\n while (len) {\n let piece = Math.min(a.len, len);\n if (a.ins >= 0 && inserted < a.i && a.len <= piece) {\n addSection(sections, 0, a.ins);\n if (insert)\n addInsert(insert, sections, a.text);\n inserted = a.i;\n }\n a.forward(piece);\n len -= piece;\n }\n b.next();\n }\n else if (a.ins >= 0) {\n // Process the part of a change in A up to the start of the next\n // non-deletion change in B (if overlapping).\n let len = 0, left = a.len;\n while (left) {\n if (b.ins == -1) {\n let piece = Math.min(left, b.len);\n len += piece;\n left -= piece;\n b.forward(piece);\n }\n else if (b.ins == 0 && b.len < left) {\n left -= b.len;\n b.next();\n }\n else {\n break;\n }\n }\n addSection(sections, len, inserted < a.i ? a.ins : 0);\n if (insert && inserted < a.i)\n addInsert(insert, sections, a.text);\n inserted = a.i;\n a.forward(a.len - left);\n }\n else if (a.done && b.done) {\n return insert ? ChangeSet.createSet(sections, insert) : ChangeDesc.create(sections);\n }\n else {\n throw new Error(\"Mismatched change set lengths\");\n }\n }\n}\nfunction composeSets(setA, setB, mkSet = false) {\n let sections = [];\n let insert = mkSet ? [] : null;\n let a = new SectionIter(setA), b = new SectionIter(setB);\n for (let open = false;;) {\n if (a.done && b.done) {\n return insert ? ChangeSet.createSet(sections, insert) : ChangeDesc.create(sections);\n }\n else if (a.ins == 0) { // Deletion in A\n addSection(sections, a.len, 0, open);\n a.next();\n }\n else if (b.len == 0 && !b.done) { // Insertion in B\n addSection(sections, 0, b.ins, open);\n if (insert)\n addInsert(insert, sections, b.text);\n b.next();\n }\n else if (a.done || b.done) {\n throw new Error(\"Mismatched change set lengths\");\n }\n else {\n let len = Math.min(a.len2, b.len), sectionLen = sections.length;\n if (a.ins == -1) {\n let insB = b.ins == -1 ? -1 : b.off ? 0 : b.ins;\n addSection(sections, len, insB, open);\n if (insert && insB)\n addInsert(insert, sections, b.text);\n }\n else if (b.ins == -1) {\n addSection(sections, a.off ? 0 : a.len, len, open);\n if (insert)\n addInsert(insert, sections, a.textBit(len));\n }\n else {\n addSection(sections, a.off ? 0 : a.len, b.off ? 0 : b.ins, open);\n if (insert && !b.off)\n addInsert(insert, sections, b.text);\n }\n open = (a.ins > len || b.ins >= 0 && b.len > len) && (open || sections.length > sectionLen);\n a.forward2(len);\n b.forward(len);\n }\n }\n}\nclass SectionIter {\n constructor(set) {\n this.set = set;\n this.i = 0;\n this.next();\n }\n next() {\n let { sections } = this.set;\n if (this.i < sections.length) {\n this.len = sections[this.i++];\n this.ins = sections[this.i++];\n }\n else {\n this.len = 0;\n this.ins = -2;\n }\n this.off = 0;\n }\n get done() { return this.ins == -2; }\n get len2() { return this.ins < 0 ? this.len : this.ins; }\n get text() {\n let { inserted } = this.set, index = (this.i - 2) >> 1;\n return index >= inserted.length ? Text.empty : inserted[index];\n }\n textBit(len) {\n let { inserted } = this.set, index = (this.i - 2) >> 1;\n return index >= inserted.length && !len ? Text.empty\n : inserted[index].slice(this.off, len == null ? undefined : this.off + len);\n }\n forward(len) {\n if (len == this.len)\n this.next();\n else {\n this.len -= len;\n this.off += len;\n }\n }\n forward2(len) {\n if (this.ins == -1)\n this.forward(len);\n else if (len == this.ins)\n this.next();\n else {\n this.ins -= len;\n this.off += len;\n }\n }\n}\n\n/**\nA single selection range. When\n[`allowMultipleSelections`](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)\nis enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelection) may hold\nmultiple ranges. By default, selections hold exactly one range.\n*/\nclass SelectionRange {\n constructor(\n /**\n The lower boundary of the range.\n */\n from, \n /**\n The upper boundary of the range.\n */\n to, flags) {\n this.from = from;\n this.to = to;\n this.flags = flags;\n }\n /**\n The anchor of the range—the side that doesn't move when you\n extend it.\n */\n get anchor() { return this.flags & 32 /* RangeFlag.Inverted */ ? this.to : this.from; }\n /**\n The head of the range, which is moved when the range is\n [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).\n */\n get head() { return this.flags & 32 /* RangeFlag.Inverted */ ? this.from : this.to; }\n /**\n True when `anchor` and `head` are at the same position.\n */\n get empty() { return this.from == this.to; }\n /**\n If this is a cursor that is explicitly associated with the\n character on one of its sides, this returns the side. -1 means\n the character before its position, 1 the character after, and 0\n means no association.\n */\n get assoc() { return this.flags & 8 /* RangeFlag.AssocBefore */ ? -1 : this.flags & 16 /* RangeFlag.AssocAfter */ ? 1 : 0; }\n /**\n The bidirectional text level associated with this cursor, if\n any.\n */\n get bidiLevel() {\n let level = this.flags & 7 /* RangeFlag.BidiLevelMask */;\n return level == 7 ? null : level;\n }\n /**\n The goal column (stored vertical offset) associated with a\n cursor. This is used to preserve the vertical position when\n [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across\n lines of different length.\n */\n get goalColumn() {\n let value = this.flags >> 6 /* RangeFlag.GoalColumnOffset */;\n return value == 16777215 /* RangeFlag.NoGoalColumn */ ? undefined : value;\n }\n /**\n Map this range through a change, producing a valid range in the\n updated document.\n */\n map(change, assoc = -1) {\n let from, to;\n if (this.empty) {\n from = to = change.mapPos(this.from, assoc);\n }\n else {\n from = change.mapPos(this.from, 1);\n to = change.mapPos(this.to, -1);\n }\n return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags);\n }\n /**\n Extend this range to cover at least `from` to `to`.\n */\n extend(from, to = from) {\n if (from <= this.anchor && to >= this.anchor)\n return EditorSelection.range(from, to);\n let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;\n return EditorSelection.range(this.anchor, head);\n }\n /**\n Compare this range to another range.\n */\n eq(other, includeAssoc = false) {\n return this.anchor == other.anchor && this.head == other.head &&\n (!includeAssoc || !this.empty || this.assoc == other.assoc);\n }\n /**\n Return a JSON-serializable object representing the range.\n */\n toJSON() { return { anchor: this.anchor, head: this.head }; }\n /**\n Convert a JSON representation of a range to a `SelectionRange`\n instance.\n */\n static fromJSON(json) {\n if (!json || typeof json.anchor != \"number\" || typeof json.head != \"number\")\n throw new RangeError(\"Invalid JSON representation for SelectionRange\");\n return EditorSelection.range(json.anchor, json.head);\n }\n /**\n @internal\n */\n static create(from, to, flags) {\n return new SelectionRange(from, to, flags);\n }\n}\n/**\nAn editor selection holds one or more selection ranges.\n*/\nclass EditorSelection {\n constructor(\n /**\n The ranges in the selection, sorted by position. Ranges cannot\n overlap (but they may touch, if they aren't empty).\n */\n ranges, \n /**\n The index of the _main_ range in the selection (which is\n usually the range that was added last).\n */\n mainIndex) {\n this.ranges = ranges;\n this.mainIndex = mainIndex;\n }\n /**\n Map a selection through a change. Used to adjust the selection\n position for changes.\n */\n map(change, assoc = -1) {\n if (change.empty)\n return this;\n return EditorSelection.create(this.ranges.map(r => r.map(change, assoc)), this.mainIndex);\n }\n /**\n Compare this selection to another selection. By default, ranges\n are compared only by position. When `includeAssoc` is true,\n cursor ranges must also have the same\n [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.\n */\n eq(other, includeAssoc = false) {\n if (this.ranges.length != other.ranges.length ||\n this.mainIndex != other.mainIndex)\n return false;\n for (let i = 0; i < this.ranges.length; i++)\n if (!this.ranges[i].eq(other.ranges[i], includeAssoc))\n return false;\n return true;\n }\n /**\n Get the primary selection range. Usually, you should make sure\n your code applies to _all_ ranges, by using methods like\n [`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange).\n */\n get main() { return this.ranges[this.mainIndex]; }\n /**\n Make sure the selection only has one range. Returns a selection\n holding only the main range from this selection.\n */\n asSingle() {\n return this.ranges.length == 1 ? this : new EditorSelection([this.main], 0);\n }\n /**\n Extend this selection with an extra range.\n */\n addRange(range, main = true) {\n return EditorSelection.create([range].concat(this.ranges), main ? 0 : this.mainIndex + 1);\n }\n /**\n Replace a given range with another range, and then normalize the\n selection to merge and sort ranges if necessary.\n */\n replaceRange(range, which = this.mainIndex) {\n let ranges = this.ranges.slice();\n ranges[which] = range;\n return EditorSelection.create(ranges, this.mainIndex);\n }\n /**\n Convert this selection to an object that can be serialized to\n JSON.\n */\n toJSON() {\n return { ranges: this.ranges.map(r => r.toJSON()), main: this.mainIndex };\n }\n /**\n Create a selection from a JSON representation.\n */\n static fromJSON(json) {\n if (!json || !Array.isArray(json.ranges) || typeof json.main != \"number\" || json.main >= json.ranges.length)\n throw new RangeError(\"Invalid JSON representation for EditorSelection\");\n return new EditorSelection(json.ranges.map((r) => SelectionRange.fromJSON(r)), json.main);\n }\n /**\n Create a selection holding a single range.\n */\n static single(anchor, head = anchor) {\n return new EditorSelection([EditorSelection.range(anchor, head)], 0);\n }\n /**\n Sort and merge the given set of ranges, creating a valid\n selection.\n */\n static create(ranges, mainIndex = 0) {\n if (ranges.length == 0)\n throw new RangeError(\"A selection needs at least one range\");\n for (let pos = 0, i = 0; i < ranges.length; i++) {\n let range = ranges[i];\n if (range.empty ? range.from <= pos : range.from < pos)\n return EditorSelection.normalized(ranges.slice(), mainIndex);\n pos = range.to;\n }\n return new EditorSelection(ranges, mainIndex);\n }\n /**\n Create a cursor selection range at the given position. You can\n safely ignore the optional arguments in most situations.\n */\n static cursor(pos, assoc = 0, bidiLevel, goalColumn) {\n return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) |\n (bidiLevel == null ? 7 : Math.min(6, bidiLevel)) |\n ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */));\n }\n /**\n Create a selection range.\n */\n static range(anchor, head, goalColumn, bidiLevel) {\n let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */) |\n (bidiLevel == null ? 7 : Math.min(6, bidiLevel));\n return head < anchor ? SelectionRange.create(head, anchor, 32 /* RangeFlag.Inverted */ | 16 /* RangeFlag.AssocAfter */ | flags)\n : SelectionRange.create(anchor, head, (head > anchor ? 8 /* RangeFlag.AssocBefore */ : 0) | flags);\n }\n /**\n @internal\n */\n static normalized(ranges, mainIndex = 0) {\n let main = ranges[mainIndex];\n ranges.sort((a, b) => a.from - b.from);\n mainIndex = ranges.indexOf(main);\n for (let i = 1; i < ranges.length; i++) {\n let range = ranges[i], prev = ranges[i - 1];\n if (range.empty ? range.from <= prev.to : range.from < prev.to) {\n let from = prev.from, to = Math.max(range.to, prev.to);\n if (i <= mainIndex)\n mainIndex--;\n ranges.splice(--i, 2, range.anchor > range.head ? EditorSelection.range(to, from) : EditorSelection.range(from, to));\n }\n }\n return new EditorSelection(ranges, mainIndex);\n }\n}\nfunction checkSelection(selection, docLength) {\n for (let range of selection.ranges)\n if (range.to > docLength)\n throw new RangeError(\"Selection points outside of document\");\n}\n\nlet nextID = 0;\n/**\nA facet is a labeled value that is associated with an editor\nstate. It takes inputs from any number of extensions, and combines\nthose into a single output value.\n\nExamples of uses of facets are the [tab\nsize](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor\nattributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update\nlisteners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).\n\nNote that `Facet` instances can be used anywhere where\n[`FacetReader`](https://codemirror.net/6/docs/ref/#state.FacetReader) is expected.\n*/\nclass Facet {\n constructor(\n /**\n @internal\n */\n combine, \n /**\n @internal\n */\n compareInput, \n /**\n @internal\n */\n compare, isStatic, enables) {\n this.combine = combine;\n this.compareInput = compareInput;\n this.compare = compare;\n this.isStatic = isStatic;\n /**\n @internal\n */\n this.id = nextID++;\n this.default = combine([]);\n this.extensions = typeof enables == \"function\" ? enables(this) : enables;\n }\n /**\n Returns a facet reader for this facet, which can be used to\n [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.\n */\n get reader() { return this; }\n /**\n Define a new facet.\n */\n static define(config = {}) {\n return new Facet(config.combine || ((a) => a), config.compareInput || ((a, b) => a === b), config.compare || (!config.combine ? sameArray : (a, b) => a === b), !!config.static, config.enables);\n }\n /**\n Returns an extension that adds the given value to this facet.\n */\n of(value) {\n return new FacetProvider([], this, 0 /* Provider.Static */, value);\n }\n /**\n Create an extension that computes a value for the facet from a\n state. You must take care to declare the parts of the state that\n this value depends on, since your function is only called again\n for a new state when one of those parts changed.\n \n In cases where your value depends only on a single field, you'll\n want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.\n */\n compute(deps, get) {\n if (this.isStatic)\n throw new Error(\"Can't compute a static facet\");\n return new FacetProvider(deps, this, 1 /* Provider.Single */, get);\n }\n /**\n Create an extension that computes zero or more values for this\n facet from a state.\n */\n computeN(deps, get) {\n if (this.isStatic)\n throw new Error(\"Can't compute a static facet\");\n return new FacetProvider(deps, this, 2 /* Provider.Multi */, get);\n }\n from(field, get) {\n if (!get)\n get = x => x;\n return this.compute([field], state => get(state.field(field)));\n }\n}\nfunction sameArray(a, b) {\n return a == b || a.length == b.length && a.every((e, i) => e === b[i]);\n}\nclass FacetProvider {\n constructor(dependencies, facet, type, value) {\n this.dependencies = dependencies;\n this.facet = facet;\n this.type = type;\n this.value = value;\n this.id = nextID++;\n }\n dynamicSlot(addresses) {\n var _a;\n let getter = this.value;\n let compare = this.facet.compareInput;\n let id = this.id, idx = addresses[id] >> 1, multi = this.type == 2 /* Provider.Multi */;\n let depDoc = false, depSel = false, depAddrs = [];\n for (let dep of this.dependencies) {\n if (dep == \"doc\")\n depDoc = true;\n else if (dep == \"selection\")\n depSel = true;\n else if ((((_a = addresses[dep.id]) !== null && _a !== void 0 ? _a : 1) & 1) == 0)\n depAddrs.push(addresses[dep.id]);\n }\n return {\n create(state) {\n state.values[idx] = getter(state);\n return 1 /* SlotStatus.Changed */;\n },\n update(state, tr) {\n if ((depDoc && tr.docChanged) || (depSel && (tr.docChanged || tr.selection)) || ensureAll(state, depAddrs)) {\n let newVal = getter(state);\n if (multi ? !compareArray(newVal, state.values[idx], compare) : !compare(newVal, state.values[idx])) {\n state.values[idx] = newVal;\n return 1 /* SlotStatus.Changed */;\n }\n }\n return 0;\n },\n reconfigure: (state, oldState) => {\n let newVal, oldAddr = oldState.config.address[id];\n if (oldAddr != null) {\n let oldVal = getAddr(oldState, oldAddr);\n if (this.dependencies.every(dep => {\n return dep instanceof Facet ? oldState.facet(dep) === state.facet(dep) :\n dep instanceof StateField ? oldState.field(dep, false) == state.field(dep, false) : true;\n }) || (multi ? compareArray(newVal = getter(state), oldVal, compare) : compare(newVal = getter(state), oldVal))) {\n state.values[idx] = oldVal;\n return 0;\n }\n }\n else {\n newVal = getter(state);\n }\n state.values[idx] = newVal;\n return 1 /* SlotStatus.Changed */;\n }\n };\n }\n}\nfunction compareArray(a, b, compare) {\n if (a.length != b.length)\n return false;\n for (let i = 0; i < a.length; i++)\n if (!compare(a[i], b[i]))\n return false;\n return true;\n}\nfunction ensureAll(state, addrs) {\n let changed = false;\n for (let addr of addrs)\n if (ensureAddr(state, addr) & 1 /* SlotStatus.Changed */)\n changed = true;\n return changed;\n}\nfunction dynamicFacetSlot(addresses, facet, providers) {\n let providerAddrs = providers.map(p => addresses[p.id]);\n let providerTypes = providers.map(p => p.type);\n let dynamic = providerAddrs.filter(p => !(p & 1));\n let idx = addresses[facet.id] >> 1;\n function get(state) {\n let values = [];\n for (let i = 0; i < providerAddrs.length; i++) {\n let value = getAddr(state, providerAddrs[i]);\n if (providerTypes[i] == 2 /* Provider.Multi */)\n for (let val of value)\n values.push(val);\n else\n values.push(value);\n }\n return facet.combine(values);\n }\n return {\n create(state) {\n for (let addr of providerAddrs)\n ensureAddr(state, addr);\n state.values[idx] = get(state);\n return 1 /* SlotStatus.Changed */;\n },\n update(state, tr) {\n if (!ensureAll(state, dynamic))\n return 0;\n let value = get(state);\n if (facet.compare(value, state.values[idx]))\n return 0;\n state.values[idx] = value;\n return 1 /* SlotStatus.Changed */;\n },\n reconfigure(state, oldState) {\n let depChanged = ensureAll(state, providerAddrs);\n let oldProviders = oldState.config.facets[facet.id], oldValue = oldState.facet(facet);\n if (oldProviders && !depChanged && sameArray(providers, oldProviders)) {\n state.values[idx] = oldValue;\n return 0;\n }\n let value = get(state);\n if (facet.compare(value, oldValue)) {\n state.values[idx] = oldValue;\n return 0;\n }\n state.values[idx] = value;\n return 1 /* SlotStatus.Changed */;\n }\n };\n}\nconst initField = /*@__PURE__*/Facet.define({ static: true });\n/**\nFields can store additional information in an editor state, and\nkeep it in sync with the rest of the state.\n*/\nclass StateField {\n constructor(\n /**\n @internal\n */\n id, createF, updateF, compareF, \n /**\n @internal\n */\n spec) {\n this.id = id;\n this.createF = createF;\n this.updateF = updateF;\n this.compareF = compareF;\n this.spec = spec;\n /**\n @internal\n */\n this.provides = undefined;\n }\n /**\n Define a state field.\n */\n static define(config) {\n let field = new StateField(nextID++, config.create, config.update, config.compare || ((a, b) => a === b), config);\n if (config.provide)\n field.provides = config.provide(field);\n return field;\n }\n create(state) {\n let init = state.facet(initField).find(i => i.field == this);\n return ((init === null || init === void 0 ? void 0 : init.create) || this.createF)(state);\n }\n /**\n @internal\n */\n slot(addresses) {\n let idx = addresses[this.id] >> 1;\n return {\n create: (state) => {\n state.values[idx] = this.create(state);\n return 1 /* SlotStatus.Changed */;\n },\n update: (state, tr) => {\n let oldVal = state.values[idx];\n let value = this.updateF(oldVal, tr);\n if (this.compareF(oldVal, value))\n return 0;\n state.values[idx] = value;\n return 1 /* SlotStatus.Changed */;\n },\n reconfigure: (state, oldState) => {\n let init = state.facet(initField), oldInit = oldState.facet(initField), reInit;\n if ((reInit = init.find(i => i.field == this)) && reInit != oldInit.find(i => i.field == this)) {\n state.values[idx] = reInit.create(state);\n return 1 /* SlotStatus.Changed */;\n }\n if (oldState.config.address[this.id] != null) {\n state.values[idx] = oldState.field(this);\n return 0;\n }\n state.values[idx] = this.create(state);\n return 1 /* SlotStatus.Changed */;\n }\n };\n }\n /**\n Returns an extension that enables this field and overrides the\n way it is initialized. Can be useful when you need to provide a\n non-default starting value for the field.\n */\n init(create) {\n return [this, initField.of({ field: this, create })];\n }\n /**\n State field instances can be used as\n [`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a\n given state.\n */\n get extension() { return this; }\n}\nconst Prec_ = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };\nfunction prec(value) {\n return (ext) => new PrecExtension(ext, value);\n}\n/**\nBy default extensions are registered in the order they are found\nin the flattened form of nested array that was provided.\nIndividual extension values can be assigned a precedence to\noverride this. Extensions that do not have a precedence set get\nthe precedence of the nearest parent with a precedence, or\n[`default`](https://codemirror.net/6/docs/ref/#state.Prec.default) if there is no such parent. The\nfinal ordering of extensions is determined by first sorting by\nprecedence and then by order within each precedence.\n*/\nconst Prec = {\n /**\n The highest precedence level, for extensions that should end up\n near the start of the precedence ordering.\n */\n highest: /*@__PURE__*/prec(Prec_.highest),\n /**\n A higher-than-default precedence, for extensions that should\n come before those with default precedence.\n */\n high: /*@__PURE__*/prec(Prec_.high),\n /**\n The default precedence, which is also used for extensions\n without an explicit precedence.\n */\n default: /*@__PURE__*/prec(Prec_.default),\n /**\n A lower-than-default precedence.\n */\n low: /*@__PURE__*/prec(Prec_.low),\n /**\n The lowest precedence level. Meant for things that should end up\n near the end of the extension order.\n */\n lowest: /*@__PURE__*/prec(Prec_.lowest)\n};\nclass PrecExtension {\n constructor(inner, prec) {\n this.inner = inner;\n this.prec = prec;\n }\n}\n/**\nExtension compartments can be used to make a configuration\ndynamic. By [wrapping](https://codemirror.net/6/docs/ref/#state.Compartment.of) part of your\nconfiguration in a compartment, you can later\n[replace](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure) that part through a\ntransaction.\n*/\nclass Compartment {\n /**\n Create an instance of this compartment to add to your [state\n configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions).\n */\n of(ext) { return new CompartmentInstance(this, ext); }\n /**\n Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that\n reconfigures this compartment.\n */\n reconfigure(content) {\n return Compartment.reconfigure.of({ compartment: this, extension: content });\n }\n /**\n Get the current content of the compartment in the state, or\n `undefined` if it isn't present.\n */\n get(state) {\n return state.config.compartments.get(this);\n }\n}\nclass CompartmentInstance {\n constructor(compartment, inner) {\n this.compartment = compartment;\n this.inner = inner;\n }\n}\nclass Configuration {\n constructor(base, compartments, dynamicSlots, address, staticValues, facets) {\n this.base = base;\n this.compartments = compartments;\n this.dynamicSlots = dynamicSlots;\n this.address = address;\n this.staticValues = staticValues;\n this.facets = facets;\n this.statusTemplate = [];\n while (this.statusTemplate.length < dynamicSlots.length)\n this.statusTemplate.push(0 /* SlotStatus.Unresolved */);\n }\n staticFacet(facet) {\n let addr = this.address[facet.id];\n return addr == null ? facet.default : this.staticValues[addr >> 1];\n }\n static resolve(base, compartments, oldState) {\n let fields = [];\n let facets = Object.create(null);\n let newCompartments = new Map();\n for (let ext of flatten(base, compartments, newCompartments)) {\n if (ext instanceof StateField)\n fields.push(ext);\n else\n (facets[ext.facet.id] || (facets[ext.facet.id] = [])).push(ext);\n }\n let address = Object.create(null);\n let staticValues = [];\n let dynamicSlots = [];\n for (let field of fields) {\n address[field.id] = dynamicSlots.length << 1;\n dynamicSlots.push(a => field.slot(a));\n }\n let oldFacets = oldState === null || oldState === void 0 ? void 0 : oldState.config.facets;\n for (let id in facets) {\n let providers = facets[id], facet = providers[0].facet;\n let oldProviders = oldFacets && oldFacets[id] || [];\n if (providers.every(p => p.type == 0 /* Provider.Static */)) {\n address[facet.id] = (staticValues.length << 1) | 1;\n if (sameArray(oldProviders, providers)) {\n staticValues.push(oldState.facet(facet));\n }\n else {\n let value = facet.combine(providers.map(p => p.value));\n staticValues.push(oldState && facet.compare(value, oldState.facet(facet)) ? oldState.facet(facet) : value);\n }\n }\n else {\n for (let p of providers) {\n if (p.type == 0 /* Provider.Static */) {\n address[p.id] = (staticValues.length << 1) | 1;\n staticValues.push(p.value);\n }\n else {\n address[p.id] = dynamicSlots.length << 1;\n dynamicSlots.push(a => p.dynamicSlot(a));\n }\n }\n address[facet.id] = dynamicSlots.length << 1;\n dynamicSlots.push(a => dynamicFacetSlot(a, facet, providers));\n }\n }\n let dynamic = dynamicSlots.map(f => f(address));\n return new Configuration(base, newCompartments, dynamic, address, staticValues, facets);\n }\n}\nfunction flatten(extension, compartments, newCompartments) {\n let result = [[], [], [], [], []];\n let seen = new Map();\n function inner(ext, prec) {\n let known = seen.get(ext);\n if (known != null) {\n if (known <= prec)\n return;\n let found = result[known].indexOf(ext);\n if (found > -1)\n result[known].splice(found, 1);\n if (ext instanceof CompartmentInstance)\n newCompartments.delete(ext.compartment);\n }\n seen.set(ext, prec);\n if (Array.isArray(ext)) {\n for (let e of ext)\n inner(e, prec);\n }\n else if (ext instanceof CompartmentInstance) {\n if (newCompartments.has(ext.compartment))\n throw new RangeError(`Duplicate use of compartment in extensions`);\n let content = compartments.get(ext.compartment) || ext.inner;\n newCompartments.set(ext.compartment, content);\n inner(content, prec);\n }\n else if (ext instanceof PrecExtension) {\n inner(ext.inner, ext.prec);\n }\n else if (ext instanceof StateField) {\n result[prec].push(ext);\n if (ext.provides)\n inner(ext.provides, prec);\n }\n else if (ext instanceof FacetProvider) {\n result[prec].push(ext);\n if (ext.facet.extensions)\n inner(ext.facet.extensions, Prec_.default);\n }\n else {\n let content = ext.extension;\n if (!content)\n throw new Error(`Unrecognized extension value in extension set (${ext}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);\n inner(content, prec);\n }\n }\n inner(extension, Prec_.default);\n return result.reduce((a, b) => a.concat(b));\n}\nfunction ensureAddr(state, addr) {\n if (addr & 1)\n return 2 /* SlotStatus.Computed */;\n let idx = addr >> 1;\n let status = state.status[idx];\n if (status == 4 /* SlotStatus.Computing */)\n throw new Error(\"Cyclic dependency between fields and/or facets\");\n if (status & 2 /* SlotStatus.Computed */)\n return status;\n state.status[idx] = 4 /* SlotStatus.Computing */;\n let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);\n return state.status[idx] = 2 /* SlotStatus.Computed */ | changed;\n}\nfunction getAddr(state, addr) {\n return addr & 1 ? state.config.staticValues[addr >> 1] : state.values[addr >> 1];\n}\n\nconst languageData = /*@__PURE__*/Facet.define();\nconst allowMultipleSelections = /*@__PURE__*/Facet.define({\n combine: values => values.some(v => v),\n static: true\n});\nconst lineSeparator = /*@__PURE__*/Facet.define({\n combine: values => values.length ? values[0] : undefined,\n static: true\n});\nconst changeFilter = /*@__PURE__*/Facet.define();\nconst transactionFilter = /*@__PURE__*/Facet.define();\nconst transactionExtender = /*@__PURE__*/Facet.define();\nconst readOnly = /*@__PURE__*/Facet.define({\n combine: values => values.length ? values[0] : false\n});\n\n/**\nAnnotations are tagged values that are used to add metadata to\ntransactions in an extensible way. They should be used to model\nthings that effect the entire transaction (such as its [time\nstamp](https://codemirror.net/6/docs/ref/#state.Transaction^time) or information about its\n[origin](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)). For effects that happen\n_alongside_ the other changes made by the transaction, [state\neffects](https://codemirror.net/6/docs/ref/#state.StateEffect) are more appropriate.\n*/\nclass Annotation {\n /**\n @internal\n */\n constructor(\n /**\n The annotation type.\n */\n type, \n /**\n The value of this annotation.\n */\n value) {\n this.type = type;\n this.value = value;\n }\n /**\n Define a new type of annotation.\n */\n static define() { return new AnnotationType(); }\n}\n/**\nMarker that identifies a type of [annotation](https://codemirror.net/6/docs/ref/#state.Annotation).\n*/\nclass AnnotationType {\n /**\n Create an instance of this annotation.\n */\n of(value) { return new Annotation(this, value); }\n}\n/**\nRepresentation of a type of state effect. Defined with\n[`StateEffect.define`](https://codemirror.net/6/docs/ref/#state.StateEffect^define).\n*/\nclass StateEffectType {\n /**\n @internal\n */\n constructor(\n // The `any` types in these function types are there to work\n // around TypeScript issue #37631, where the type guard on\n // `StateEffect.is` mysteriously stops working when these properly\n // have type `Value`.\n /**\n @internal\n */\n map) {\n this.map = map;\n }\n /**\n Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this\n type.\n */\n of(value) { return new StateEffect(this, value); }\n}\n/**\nState effects can be used to represent additional effects\nassociated with a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction.effects). They\nare often useful to model changes to custom [state\nfields](https://codemirror.net/6/docs/ref/#state.StateField), when those changes aren't implicit in\ndocument or selection changes.\n*/\nclass StateEffect {\n /**\n @internal\n */\n constructor(\n /**\n @internal\n */\n type, \n /**\n The value of this effect.\n */\n value) {\n this.type = type;\n this.value = value;\n }\n /**\n Map this effect through a position mapping. Will return\n `undefined` when that ends up deleting the effect.\n */\n map(mapping) {\n let mapped = this.type.map(this.value, mapping);\n return mapped === undefined ? undefined : mapped == this.value ? this : new StateEffect(this.type, mapped);\n }\n /**\n Tells you whether this effect object is of a given\n [type](https://codemirror.net/6/docs/ref/#state.StateEffectType).\n */\n is(type) { return this.type == type; }\n /**\n Define a new effect type. The type parameter indicates the type\n of values that his effect holds. It should be a type that\n doesn't include `undefined`, since that is used in\n [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is\n removed.\n */\n static define(spec = {}) {\n return new StateEffectType(spec.map || (v => v));\n }\n /**\n Map an array of effects through a change set.\n */\n static mapEffects(effects, mapping) {\n if (!effects.length)\n return effects;\n let result = [];\n for (let effect of effects) {\n let mapped = effect.map(mapping);\n if (mapped)\n result.push(mapped);\n }\n return result;\n }\n}\n/**\nThis effect can be used to reconfigure the root extensions of\nthe editor. Doing this will discard any extensions\n[appended](https://codemirror.net/6/docs/ref/#state.StateEffect^appendConfig), but does not reset\nthe content of [reconfigured](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure)\ncompartments.\n*/\nStateEffect.reconfigure = /*@__PURE__*/StateEffect.define();\n/**\nAppend extensions to the top-level configuration of the editor.\n*/\nStateEffect.appendConfig = /*@__PURE__*/StateEffect.define();\n/**\nChanges to the editor state are grouped into transactions.\nTypically, a user action creates a single transaction, which may\ncontain any number of document changes, may change the selection,\nor have other effects. Create a transaction by calling\n[`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update), or immediately\ndispatch one by calling\n[`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch).\n*/\nclass Transaction {\n constructor(\n /**\n The state from which the transaction starts.\n */\n startState, \n /**\n The document changes made by this transaction.\n */\n changes, \n /**\n The selection set by this transaction, or undefined if it\n doesn't explicitly set a selection.\n */\n selection, \n /**\n The effects added to the transaction.\n */\n effects, \n /**\n @internal\n */\n annotations, \n /**\n Whether the selection should be scrolled into view after this\n transaction is dispatched.\n */\n scrollIntoView) {\n this.startState = startState;\n this.changes = changes;\n this.selection = selection;\n this.effects = effects;\n this.annotations = annotations;\n this.scrollIntoView = scrollIntoView;\n /**\n @internal\n */\n this._doc = null;\n /**\n @internal\n */\n this._state = null;\n if (selection)\n checkSelection(selection, changes.newLength);\n if (!annotations.some((a) => a.type == Transaction.time))\n this.annotations = annotations.concat(Transaction.time.of(Date.now()));\n }\n /**\n @internal\n */\n static create(startState, changes, selection, effects, annotations, scrollIntoView) {\n return new Transaction(startState, changes, selection, effects, annotations, scrollIntoView);\n }\n /**\n The new document produced by the transaction. Contrary to\n [`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't\n force the entire new state to be computed right away, so it is\n recommended that [transaction\n filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter\n when they need to look at the new document.\n */\n get newDoc() {\n return this._doc || (this._doc = this.changes.apply(this.startState.doc));\n }\n /**\n The new selection produced by the transaction. If\n [`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined,\n this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's\n current selection through the changes made by the transaction.\n */\n get newSelection() {\n return this.selection || this.startState.selection.map(this.changes);\n }\n /**\n The new state created by the transaction. Computed on demand\n (but retained for subsequent access), so it is recommended not to\n access it in [transaction\n filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.\n */\n get state() {\n if (!this._state)\n this.startState.applyTransaction(this);\n return this._state;\n }\n /**\n Get the value of the given annotation type, if any.\n */\n annotation(type) {\n for (let ann of this.annotations)\n if (ann.type == type)\n return ann.value;\n return undefined;\n }\n /**\n Indicates whether the transaction changed the document.\n */\n get docChanged() { return !this.changes.empty; }\n /**\n Indicates whether this transaction reconfigures the state\n (through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or\n with a top-level configuration\n [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).\n */\n get reconfigured() { return this.startState.config != this.state.config; }\n /**\n Returns true if the transaction has a [user\n event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to\n or more specific than `event`. For example, if the transaction\n has `\"select.pointer\"` as user event, `\"select\"` and\n `\"select.pointer\"` will match it.\n */\n isUserEvent(event) {\n let e = this.annotation(Transaction.userEvent);\n return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == \".\"));\n }\n}\n/**\nAnnotation used to store transaction timestamps. Automatically\nadded to every transaction, holding `Date.now()`.\n*/\nTransaction.time = /*@__PURE__*/Annotation.define();\n/**\nAnnotation used to associate a transaction with a user interface\nevent. Holds a string identifying the event, using a\ndot-separated format to support attaching more specific\ninformation. The events used by the core libraries are:\n\n - `\"input\"` when content is entered\n - `\"input.type\"` for typed input\n - `\"input.type.compose\"` for composition\n - `\"input.paste\"` for pasted input\n - `\"input.drop\"` when adding content with drag-and-drop\n - `\"input.complete\"` when autocompleting\n - `\"delete\"` when the user deletes content\n - `\"delete.selection\"` when deleting the selection\n - `\"delete.forward\"` when deleting forward from the selection\n - `\"delete.backward\"` when deleting backward from the selection\n - `\"delete.cut\"` when cutting to the clipboard\n - `\"move\"` when content is moved\n - `\"move.drop\"` when content is moved within the editor through drag-and-drop\n - `\"select\"` when explicitly changing the selection\n - `\"select.pointer\"` when selecting with a mouse or other pointing device\n - `\"undo\"` and `\"redo\"` for history actions\n\nUse [`isUserEvent`](https://codemirror.net/6/docs/ref/#state.Transaction.isUserEvent) to check\nwhether the annotation matches a given event.\n*/\nTransaction.userEvent = /*@__PURE__*/Annotation.define();\n/**\nAnnotation indicating whether a transaction should be added to\nthe undo history or not.\n*/\nTransaction.addToHistory = /*@__PURE__*/Annotation.define();\n/**\nAnnotation indicating (when present and true) that a transaction\nrepresents a change made by some other actor, not the user. This\nis used, for example, to tag other people's changes in\ncollaborative editing.\n*/\nTransaction.remote = /*@__PURE__*/Annotation.define();\nfunction joinRanges(a, b) {\n let result = [];\n for (let iA = 0, iB = 0;;) {\n let from, to;\n if (iA < a.length && (iB == b.length || b[iB] >= a[iA])) {\n from = a[iA++];\n to = a[iA++];\n }\n else if (iB < b.length) {\n from = b[iB++];\n to = b[iB++];\n }\n else\n return result;\n if (!result.length || result[result.length - 1] < from)\n result.push(from, to);\n else if (result[result.length - 1] < to)\n result[result.length - 1] = to;\n }\n}\nfunction mergeTransaction(a, b, sequential) {\n var _a;\n let mapForA, mapForB, changes;\n if (sequential) {\n mapForA = b.changes;\n mapForB = ChangeSet.empty(b.changes.length);\n changes = a.changes.compose(b.changes);\n }\n else {\n mapForA = b.changes.map(a.changes);\n mapForB = a.changes.mapDesc(b.changes, true);\n changes = a.changes.compose(mapForA);\n }\n return {\n changes,\n selection: b.selection ? b.selection.map(mapForB) : (_a = a.selection) === null || _a === void 0 ? void 0 : _a.map(mapForA),\n effects: StateEffect.mapEffects(a.effects, mapForA).concat(StateEffect.mapEffects(b.effects, mapForB)),\n annotations: a.annotations.length ? a.annotations.concat(b.annotations) : b.annotations,\n scrollIntoView: a.scrollIntoView || b.scrollIntoView\n };\n}\nfunction resolveTransactionInner(state, spec, docSize) {\n let sel = spec.selection, annotations = asArray(spec.annotations);\n if (spec.userEvent)\n annotations = annotations.concat(Transaction.userEvent.of(spec.userEvent));\n return {\n changes: spec.changes instanceof ChangeSet ? spec.changes\n : ChangeSet.of(spec.changes || [], docSize, state.facet(lineSeparator)),\n selection: sel && (sel instanceof EditorSelection ? sel : EditorSelection.single(sel.anchor, sel.head)),\n effects: asArray(spec.effects),\n annotations,\n scrollIntoView: !!spec.scrollIntoView\n };\n}\nfunction resolveTransaction(state, specs, filter) {\n let s = resolveTransactionInner(state, specs.length ? specs[0] : {}, state.doc.length);\n if (specs.length && specs[0].filter === false)\n filter = false;\n for (let i = 1; i < specs.length; i++) {\n if (specs[i].filter === false)\n filter = false;\n let seq = !!specs[i].sequential;\n s = mergeTransaction(s, resolveTransactionInner(state, specs[i], seq ? s.changes.newLength : state.doc.length), seq);\n }\n let tr = Transaction.create(state, s.changes, s.selection, s.effects, s.annotations, s.scrollIntoView);\n return extendTransaction(filter ? filterTransaction(tr) : tr);\n}\n// Finish a transaction by applying filters if necessary.\nfunction filterTransaction(tr) {\n let state = tr.startState;\n // Change filters\n let result = true;\n for (let filter of state.facet(changeFilter)) {\n let value = filter(tr);\n if (value === false) {\n result = false;\n break;\n }\n if (Array.isArray(value))\n result = result === true ? value : joinRanges(result, value);\n }\n if (result !== true) {\n let changes, back;\n if (result === false) {\n back = tr.changes.invertedDesc;\n changes = ChangeSet.empty(state.doc.length);\n }\n else {\n let filtered = tr.changes.filter(result);\n changes = filtered.changes;\n back = filtered.filtered.mapDesc(filtered.changes).invertedDesc;\n }\n tr = Transaction.create(state, changes, tr.selection && tr.selection.map(back), StateEffect.mapEffects(tr.effects, back), tr.annotations, tr.scrollIntoView);\n }\n // Transaction filters\n let filters = state.facet(transactionFilter);\n for (let i = filters.length - 1; i >= 0; i--) {\n let filtered = filters[i](tr);\n if (filtered instanceof Transaction)\n tr = filtered;\n else if (Array.isArray(filtered) && filtered.length == 1 && filtered[0] instanceof Transaction)\n tr = filtered[0];\n else\n tr = resolveTransaction(state, asArray(filtered), false);\n }\n return tr;\n}\nfunction extendTransaction(tr) {\n let state = tr.startState, extenders = state.facet(transactionExtender), spec = tr;\n for (let i = extenders.length - 1; i >= 0; i--) {\n let extension = extenders[i](tr);\n if (extension && Object.keys(extension).length)\n spec = mergeTransaction(spec, resolveTransactionInner(state, extension, tr.changes.newLength), true);\n }\n return spec == tr ? tr : Transaction.create(state, tr.changes, tr.selection, spec.effects, spec.annotations, spec.scrollIntoView);\n}\nconst none = [];\nfunction asArray(value) {\n return value == null ? none : Array.isArray(value) ? value : [value];\n}\n\n/**\nThe categories produced by a [character\ncategorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer). These are used\ndo things like selecting by word.\n*/\nvar CharCategory = /*@__PURE__*/(function (CharCategory) {\n /**\n Word characters.\n */\n CharCategory[CharCategory[\"Word\"] = 0] = \"Word\";\n /**\n Whitespace.\n */\n CharCategory[CharCategory[\"Space\"] = 1] = \"Space\";\n /**\n Anything else.\n */\n CharCategory[CharCategory[\"Other\"] = 2] = \"Other\";\nreturn CharCategory})(CharCategory || (CharCategory = {}));\nconst nonASCIISingleCaseWordChar = /[\\u00df\\u0587\\u0590-\\u05f4\\u0600-\\u06ff\\u3040-\\u309f\\u30a0-\\u30ff\\u3400-\\u4db5\\u4e00-\\u9fcc\\uac00-\\ud7af]/;\nlet wordChar;\ntry {\n wordChar = /*@__PURE__*/new RegExp(\"[\\\\p{Alphabetic}\\\\p{Number}_]\", \"u\");\n}\ncatch (_) { }\nfunction hasWordChar(str) {\n if (wordChar)\n return wordChar.test(str);\n for (let i = 0; i < str.length; i++) {\n let ch = str[i];\n if (/\\w/.test(ch) || ch > \"\\x80\" && (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch)))\n return true;\n }\n return false;\n}\nfunction makeCategorizer(wordChars) {\n return (char) => {\n if (!/\\S/.test(char))\n return CharCategory.Space;\n if (hasWordChar(char))\n return CharCategory.Word;\n for (let i = 0; i < wordChars.length; i++)\n if (char.indexOf(wordChars[i]) > -1)\n return CharCategory.Word;\n return CharCategory.Other;\n };\n}\n\n/**\nThe editor state class is a persistent (immutable) data structure.\nTo update a state, you [create](https://codemirror.net/6/docs/ref/#state.EditorState.update) a\n[transaction](https://codemirror.net/6/docs/ref/#state.Transaction), which produces a _new_ state\ninstance, without modifying the original object.\n\nAs such, _never_ mutate properties of a state directly. That'll\njust break things.\n*/\nclass EditorState {\n constructor(\n /**\n @internal\n */\n config, \n /**\n The current document.\n */\n doc, \n /**\n The current selection.\n */\n selection, \n /**\n @internal\n */\n values, computeSlot, tr) {\n this.config = config;\n this.doc = doc;\n this.selection = selection;\n this.values = values;\n this.status = config.statusTemplate.slice();\n this.computeSlot = computeSlot;\n // Fill in the computed state immediately, so that further queries\n // for it made during the update return this state\n if (tr)\n tr._state = this;\n for (let i = 0; i < this.config.dynamicSlots.length; i++)\n ensureAddr(this, i << 1);\n this.computeSlot = null;\n }\n field(field, require = true) {\n let addr = this.config.address[field.id];\n if (addr == null) {\n if (require)\n throw new RangeError(\"Field is not present in this state\");\n return undefined;\n }\n ensureAddr(this, addr);\n return getAddr(this, addr);\n }\n /**\n Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this\n state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec)\n can be passed. Unless\n [`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the\n [changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec\n are assumed to start in the _current_ document (not the document\n produced by previous specs), and its\n [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and\n [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer\n to the document created by its _own_ changes. The resulting\n transaction contains the combined effect of all the different\n specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later\n specs take precedence over earlier ones.\n */\n update(...specs) {\n return resolveTransaction(this, specs, true);\n }\n /**\n @internal\n */\n applyTransaction(tr) {\n let conf = this.config, { base, compartments } = conf;\n for (let effect of tr.effects) {\n if (effect.is(Compartment.reconfigure)) {\n if (conf) {\n compartments = new Map;\n conf.compartments.forEach((val, key) => compartments.set(key, val));\n conf = null;\n }\n compartments.set(effect.value.compartment, effect.value.extension);\n }\n else if (effect.is(StateEffect.reconfigure)) {\n conf = null;\n base = effect.value;\n }\n else if (effect.is(StateEffect.appendConfig)) {\n conf = null;\n base = asArray(base).concat(effect.value);\n }\n }\n let startValues;\n if (!conf) {\n conf = Configuration.resolve(base, compartments, this);\n let intermediateState = new EditorState(conf, this.doc, this.selection, conf.dynamicSlots.map(() => null), (state, slot) => slot.reconfigure(state, this), null);\n startValues = intermediateState.values;\n }\n else {\n startValues = tr.startState.values.slice();\n }\n let selection = tr.startState.facet(allowMultipleSelections) ? tr.newSelection : tr.newSelection.asSingle();\n new EditorState(conf, tr.newDoc, selection, startValues, (state, slot) => slot.update(state, tr), tr);\n }\n /**\n Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that\n replaces every selection range with the given content.\n */\n replaceSelection(text) {\n if (typeof text == \"string\")\n text = this.toText(text);\n return this.changeByRange(range => ({ changes: { from: range.from, to: range.to, insert: text },\n range: EditorSelection.cursor(range.from + text.length) }));\n }\n /**\n Create a set of changes and a new selection by running the given\n function for each range in the active selection. The function\n can return an optional set of changes (in the coordinate space\n of the start document), plus an updated range (in the coordinate\n space of the document produced by the call's own changes). This\n method will merge all the changes and ranges into a single\n changeset and selection, and return it as a [transaction\n spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to\n [`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).\n */\n changeByRange(f) {\n let sel = this.selection;\n let result1 = f(sel.ranges[0]);\n let changes = this.changes(result1.changes), ranges = [result1.range];\n let effects = asArray(result1.effects);\n for (let i = 1; i < sel.ranges.length; i++) {\n let result = f(sel.ranges[i]);\n let newChanges = this.changes(result.changes), newMapped = newChanges.map(changes);\n for (let j = 0; j < i; j++)\n ranges[j] = ranges[j].map(newMapped);\n let mapBy = changes.mapDesc(newChanges, true);\n ranges.push(result.range.map(mapBy));\n changes = changes.compose(newMapped);\n effects = StateEffect.mapEffects(effects, newMapped).concat(StateEffect.mapEffects(asArray(result.effects), mapBy));\n }\n return {\n changes,\n selection: EditorSelection.create(ranges, sel.mainIndex),\n effects\n };\n }\n /**\n Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change\n description, taking the state's document length and line\n separator into account.\n */\n changes(spec = []) {\n if (spec instanceof ChangeSet)\n return spec;\n return ChangeSet.of(spec, this.doc.length, this.facet(EditorState.lineSeparator));\n }\n /**\n Using the state's [line\n separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a\n [`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.\n */\n toText(string) {\n return Text.of(string.split(this.facet(EditorState.lineSeparator) || DefaultSplit));\n }\n /**\n Return the given range of the document as a string.\n */\n sliceDoc(from = 0, to = this.doc.length) {\n return this.doc.sliceString(from, to, this.lineBreak);\n }\n /**\n Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).\n */\n facet(facet) {\n let addr = this.config.address[facet.id];\n if (addr == null)\n return facet.default;\n ensureAddr(this, addr);\n return getAddr(this, addr);\n }\n /**\n Convert this state to a JSON-serializable object. When custom\n fields should be serialized, you can pass them in as an object\n mapping property names (in the resulting object, which should\n not use `doc` or `selection`) to fields.\n */\n toJSON(fields) {\n let result = {\n doc: this.sliceDoc(),\n selection: this.selection.toJSON()\n };\n if (fields)\n for (let prop in fields) {\n let value = fields[prop];\n if (value instanceof StateField && this.config.address[value.id] != null)\n result[prop] = value.spec.toJSON(this.field(fields[prop]), this);\n }\n return result;\n }\n /**\n Deserialize a state from its JSON representation. When custom\n fields should be deserialized, pass the same object you passed\n to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as\n third argument.\n */\n static fromJSON(json, config = {}, fields) {\n if (!json || typeof json.doc != \"string\")\n throw new RangeError(\"Invalid JSON representation for EditorState\");\n let fieldInit = [];\n if (fields)\n for (let prop in fields) {\n if (Object.prototype.hasOwnProperty.call(json, prop)) {\n let field = fields[prop], value = json[prop];\n fieldInit.push(field.init(state => field.spec.fromJSON(value, state)));\n }\n }\n return EditorState.create({\n doc: json.doc,\n selection: EditorSelection.fromJSON(json.selection),\n extensions: config.extensions ? fieldInit.concat([config.extensions]) : fieldInit\n });\n }\n /**\n Create a new state. You'll usually only need this when\n initializing an editor—updated states are created by applying\n transactions.\n */\n static create(config = {}) {\n let configuration = Configuration.resolve(config.extensions || [], new Map);\n let doc = config.doc instanceof Text ? config.doc\n : Text.of((config.doc || \"\").split(configuration.staticFacet(EditorState.lineSeparator) || DefaultSplit));\n let selection = !config.selection ? EditorSelection.single(0)\n : config.selection instanceof EditorSelection ? config.selection\n : EditorSelection.single(config.selection.anchor, config.selection.head);\n checkSelection(selection, doc.length);\n if (!configuration.staticFacet(allowMultipleSelections))\n selection = selection.asSingle();\n return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(() => null), (state, slot) => slot.create(state), null);\n }\n /**\n The size (in columns) of a tab in the document, determined by\n the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet.\n */\n get tabSize() { return this.facet(EditorState.tabSize); }\n /**\n Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)\n string for this state.\n */\n get lineBreak() { return this.facet(EditorState.lineSeparator) || \"\\n\"; }\n /**\n Returns true when the editor is\n [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.\n */\n get readOnly() { return this.facet(readOnly); }\n /**\n Look up a translation for the given phrase (via the\n [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the\n original string if no translation is found.\n \n If additional arguments are passed, they will be inserted in\n place of markers like `$1` (for the first value) and `$2`, etc.\n A single `$` is equivalent to `$1`, and `$$` will produce a\n literal dollar sign.\n */\n phrase(phrase, ...insert) {\n for (let map of this.facet(EditorState.phrases))\n if (Object.prototype.hasOwnProperty.call(map, phrase)) {\n phrase = map[phrase];\n break;\n }\n if (insert.length)\n phrase = phrase.replace(/\\$(\\$|\\d*)/g, (m, i) => {\n if (i == \"$\")\n return \"$\";\n let n = +(i || 1);\n return !n || n > insert.length ? m : insert[n - 1];\n });\n return phrase;\n }\n /**\n Find the values for a given language data field, provided by the\n the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.\n \n Examples of language data fields are...\n \n - [`\"commentTokens\"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying\n comment syntax.\n - [`\"autocomplete\"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)\n for providing language-specific completion sources.\n - [`\"wordChars\"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding\n characters that should be considered part of words in this\n language.\n - [`\"closeBrackets\"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls\n bracket closing behavior.\n */\n languageDataAt(name, pos, side = -1) {\n let values = [];\n for (let provider of this.facet(languageData)) {\n for (let result of provider(this, pos, side)) {\n if (Object.prototype.hasOwnProperty.call(result, name))\n values.push(result[name]);\n }\n }\n return values;\n }\n /**\n Return a function that can categorize strings (expected to\n represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))\n into one of:\n \n - Word (contains an alphanumeric character or a character\n explicitly listed in the local language's `\"wordChars\"`\n language data, which should be a string)\n - Space (contains only whitespace)\n - Other (anything else)\n */\n charCategorizer(at) {\n return makeCategorizer(this.languageDataAt(\"wordChars\", at).join(\"\"));\n }\n /**\n Find the word at the given position, meaning the range\n containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters\n around it. If no word characters are adjacent to the position,\n this returns null.\n */\n wordAt(pos) {\n let { text, from, length } = this.doc.lineAt(pos);\n let cat = this.charCategorizer(pos);\n let start = pos - from, end = pos - from;\n while (start > 0) {\n let prev = findClusterBreak(text, start, false);\n if (cat(text.slice(prev, start)) != CharCategory.Word)\n break;\n start = prev;\n }\n while (end < length) {\n let next = findClusterBreak(text, end);\n if (cat(text.slice(end, next)) != CharCategory.Word)\n break;\n end = next;\n }\n return start == end ? null : EditorSelection.range(start + from, end + from);\n }\n}\n/**\nA facet that, when enabled, causes the editor to allow multiple\nranges to be selected. Be careful though, because by default the\neditor relies on the native DOM selection, which cannot handle\nmultiple selections. An extension like\n[`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) can be used to make\nsecondary selections visible to the user.\n*/\nEditorState.allowMultipleSelections = allowMultipleSelections;\n/**\nConfigures the tab size to use in this state. The first\n(highest-precedence) value of the facet is used. If no value is\ngiven, this defaults to 4.\n*/\nEditorState.tabSize = /*@__PURE__*/Facet.define({\n combine: values => values.length ? values[0] : 4\n});\n/**\nThe line separator to use. By default, any of `\"\\n\"`, `\"\\r\\n\"`\nand `\"\\r\"` is treated as a separator when splitting lines, and\nlines are joined with `\"\\n\"`.\n\nWhen you configure a value here, only that precise separator\nwill be used, allowing you to round-trip documents through the\neditor without normalizing line separators.\n*/\nEditorState.lineSeparator = lineSeparator;\n/**\nThis facet controls the value of the\n[`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) getter, which is\nconsulted by commands and extensions that implement editing\nfunctionality to determine whether they should apply. It\ndefaults to false, but when its highest-precedence value is\n`true`, such functionality disables itself.\n\nNot to be confused with\n[`EditorView.editable`](https://codemirror.net/6/docs/ref/#view.EditorView^editable), which\ncontrols whether the editor's DOM is set to be editable (and\nthus focusable).\n*/\nEditorState.readOnly = readOnly;\n/**\nRegisters translation phrases. The\n[`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through\nall objects registered with this facet to find translations for\nits argument.\n*/\nEditorState.phrases = /*@__PURE__*/Facet.define({\n compare(a, b) {\n let kA = Object.keys(a), kB = Object.keys(b);\n return kA.length == kB.length && kA.every(k => a[k] == b[k]);\n }\n});\n/**\nA facet used to register [language\ndata](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.\n*/\nEditorState.languageData = languageData;\n/**\nFacet used to register change filters, which are called for each\ntransaction (unless explicitly\n[disabled](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter)), and can suppress\npart of the transaction's changes.\n\nSuch a function can return `true` to indicate that it doesn't\nwant to do anything, `false` to completely stop the changes in\nthe transaction, or a set of ranges in which changes should be\nsuppressed. Such ranges are represented as an array of numbers,\nwith each pair of two numbers indicating the start and end of a\nrange. So for example `[10, 20, 100, 110]` suppresses changes\nbetween 10 and 20, and between 100 and 110.\n*/\nEditorState.changeFilter = changeFilter;\n/**\nFacet used to register a hook that gets a chance to update or\nreplace transaction specs before they are applied. This will\nonly be applied for transactions that don't have\n[`filter`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter) set to `false`. You\ncan either return a single transaction spec (possibly the input\ntransaction), or an array of specs (which will be combined in\nthe same way as the arguments to\n[`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).\n\nWhen possible, it is recommended to avoid accessing\n[`Transaction.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state) in a filter,\nsince it will force creation of a state that will then be\ndiscarded again, if the transaction is actually filtered.\n\n(This functionality should be used with care. Indiscriminately\nmodifying transaction is likely to break something or degrade\nthe user experience.)\n*/\nEditorState.transactionFilter = transactionFilter;\n/**\nThis is a more limited form of\n[`transactionFilter`](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter),\nwhich can only add\n[annotations](https://codemirror.net/6/docs/ref/#state.TransactionSpec.annotations) and\n[effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects). _But_, this type\nof filter runs even if the transaction has disabled regular\n[filtering](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter), making it suitable\nfor effects that don't need to touch the changes or selection,\nbut do want to process every transaction.\n\nExtenders run _after_ filters, when both are present.\n*/\nEditorState.transactionExtender = transactionExtender;\nCompartment.reconfigure = /*@__PURE__*/StateEffect.define();\n\n/**\nUtility function for combining behaviors to fill in a config\nobject from an array of provided configs. `defaults` should hold\ndefault values for all optional fields in `Config`.\n\nThe function will, by default, error\nwhen a field gets two values that aren't `===`-equal, but you can\nprovide combine functions per field to do something else.\n*/\nfunction combineConfig(configs, defaults, // Should hold only the optional properties of Config, but I haven't managed to express that\ncombine = {}) {\n let result = {};\n for (let config of configs)\n for (let key of Object.keys(config)) {\n let value = config[key], current = result[key];\n if (current === undefined)\n result[key] = value;\n else if (current === value || value === undefined) ; // No conflict\n else if (Object.hasOwnProperty.call(combine, key))\n result[key] = combine[key](current, value);\n else\n throw new Error(\"Config merge conflict for field \" + key);\n }\n for (let key in defaults)\n if (result[key] === undefined)\n result[key] = defaults[key];\n return result;\n}\n\n/**\nEach range is associated with a value, which must inherit from\nthis class.\n*/\nclass RangeValue {\n /**\n Compare this value with another value. Used when comparing\n rangesets. The default implementation compares by identity.\n Unless you are only creating a fixed number of unique instances\n of your value type, it is a good idea to implement this\n properly.\n */\n eq(other) { return this == other; }\n /**\n Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.\n */\n range(from, to = from) { return Range.create(from, to, this); }\n}\nRangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;\nRangeValue.prototype.point = false;\nRangeValue.prototype.mapMode = MapMode.TrackDel;\n/**\nA range associates a value with a range of positions.\n*/\nclass Range {\n constructor(\n /**\n The range's start position.\n */\n from, \n /**\n Its end position.\n */\n to, \n /**\n The value associated with this range.\n */\n value) {\n this.from = from;\n this.to = to;\n this.value = value;\n }\n /**\n @internal\n */\n static create(from, to, value) {\n return new Range(from, to, value);\n }\n}\nfunction cmpRange(a, b) {\n return a.from - b.from || a.value.startSide - b.value.startSide;\n}\nclass Chunk {\n constructor(from, to, value, \n // Chunks are marked with the largest point that occurs\n // in them (or -1 for no points), so that scans that are\n // only interested in points (such as the\n // heightmap-related logic) can skip range-only chunks.\n maxPoint) {\n this.from = from;\n this.to = to;\n this.value = value;\n this.maxPoint = maxPoint;\n }\n get length() { return this.to[this.to.length - 1]; }\n // Find the index of the given position and side. Use the ranges'\n // `from` pos when `end == false`, `to` when `end == true`.\n findIndex(pos, side, end, startAt = 0) {\n let arr = end ? this.to : this.from;\n for (let lo = startAt, hi = arr.length;;) {\n if (lo == hi)\n return lo;\n let mid = (lo + hi) >> 1;\n let diff = arr[mid] - pos || (end ? this.value[mid].endSide : this.value[mid].startSide) - side;\n if (mid == lo)\n return diff >= 0 ? lo : hi;\n if (diff >= 0)\n hi = mid;\n else\n lo = mid + 1;\n }\n }\n between(offset, from, to, f) {\n for (let i = this.findIndex(from, -1000000000 /* C.Far */, true), e = this.findIndex(to, 1000000000 /* C.Far */, false, i); i < e; i++)\n if (f(this.from[i] + offset, this.to[i] + offset, this.value[i]) === false)\n return false;\n }\n map(offset, changes) {\n let value = [], from = [], to = [], newPos = -1, maxPoint = -1;\n for (let i = 0; i < this.value.length; i++) {\n let val = this.value[i], curFrom = this.from[i] + offset, curTo = this.to[i] + offset, newFrom, newTo;\n if (curFrom == curTo) {\n let mapped = changes.mapPos(curFrom, val.startSide, val.mapMode);\n if (mapped == null)\n continue;\n newFrom = newTo = mapped;\n if (val.startSide != val.endSide) {\n newTo = changes.mapPos(curFrom, val.endSide);\n if (newTo < newFrom)\n continue;\n }\n }\n else {\n newFrom = changes.mapPos(curFrom, val.startSide);\n newTo = changes.mapPos(curTo, val.endSide);\n if (newFrom > newTo || newFrom == newTo && val.startSide > 0 && val.endSide <= 0)\n continue;\n }\n if ((newTo - newFrom || val.endSide - val.startSide) < 0)\n continue;\n if (newPos < 0)\n newPos = newFrom;\n if (val.point)\n maxPoint = Math.max(maxPoint, newTo - newFrom);\n value.push(val);\n from.push(newFrom - newPos);\n to.push(newTo - newPos);\n }\n return { mapped: value.length ? new Chunk(from, to, value, maxPoint) : null, pos: newPos };\n }\n}\n/**\nA range set stores a collection of [ranges](https://codemirror.net/6/docs/ref/#state.Range) in a\nway that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.RangeSet.map) and\n[update](https://codemirror.net/6/docs/ref/#state.RangeSet.update). This is an immutable data\nstructure.\n*/\nclass RangeSet {\n constructor(\n /**\n @internal\n */\n chunkPos, \n /**\n @internal\n */\n chunk, \n /**\n @internal\n */\n nextLayer, \n /**\n @internal\n */\n maxPoint) {\n this.chunkPos = chunkPos;\n this.chunk = chunk;\n this.nextLayer = nextLayer;\n this.maxPoint = maxPoint;\n }\n /**\n @internal\n */\n static create(chunkPos, chunk, nextLayer, maxPoint) {\n return new RangeSet(chunkPos, chunk, nextLayer, maxPoint);\n }\n /**\n @internal\n */\n get length() {\n let last = this.chunk.length - 1;\n return last < 0 ? 0 : Math.max(this.chunkEnd(last), this.nextLayer.length);\n }\n /**\n The number of ranges in the set.\n */\n get size() {\n if (this.isEmpty)\n return 0;\n let size = this.nextLayer.size;\n for (let chunk of this.chunk)\n size += chunk.value.length;\n return size;\n }\n /**\n @internal\n */\n chunkEnd(index) {\n return this.chunkPos[index] + this.chunk[index].length;\n }\n /**\n Update the range set, optionally adding new ranges or filtering\n out existing ones.\n \n (Note: The type parameter is just there as a kludge to work\n around TypeScript variance issues that prevented `RangeSet`\n from being a subtype of `RangeSet` when `X` is a subtype of\n `Y`.)\n */\n update(updateSpec) {\n let { add = [], sort = false, filterFrom = 0, filterTo = this.length } = updateSpec;\n let filter = updateSpec.filter;\n if (add.length == 0 && !filter)\n return this;\n if (sort)\n add = add.slice().sort(cmpRange);\n if (this.isEmpty)\n return add.length ? RangeSet.of(add) : this;\n let cur = new LayerCursor(this, null, -1).goto(0), i = 0, spill = [];\n let builder = new RangeSetBuilder();\n while (cur.value || i < add.length) {\n if (i < add.length && (cur.from - add[i].from || cur.startSide - add[i].value.startSide) >= 0) {\n let range = add[i++];\n if (!builder.addInner(range.from, range.to, range.value))\n spill.push(range);\n }\n else if (cur.rangeIndex == 1 && cur.chunkIndex < this.chunk.length &&\n (i == add.length || this.chunkEnd(cur.chunkIndex) < add[i].from) &&\n (!filter || filterFrom > this.chunkEnd(cur.chunkIndex) || filterTo < this.chunkPos[cur.chunkIndex]) &&\n builder.addChunk(this.chunkPos[cur.chunkIndex], this.chunk[cur.chunkIndex])) {\n cur.nextChunk();\n }\n else {\n if (!filter || filterFrom > cur.to || filterTo < cur.from || filter(cur.from, cur.to, cur.value)) {\n if (!builder.addInner(cur.from, cur.to, cur.value))\n spill.push(Range.create(cur.from, cur.to, cur.value));\n }\n cur.next();\n }\n }\n return builder.finishInner(this.nextLayer.isEmpty && !spill.length ? RangeSet.empty\n : this.nextLayer.update({ add: spill, filter, filterFrom, filterTo }));\n }\n /**\n Map this range set through a set of changes, return the new set.\n */\n map(changes) {\n if (changes.empty || this.isEmpty)\n return this;\n let chunks = [], chunkPos = [], maxPoint = -1;\n for (let i = 0; i < this.chunk.length; i++) {\n let start = this.chunkPos[i], chunk = this.chunk[i];\n let touch = changes.touchesRange(start, start + chunk.length);\n if (touch === false) {\n maxPoint = Math.max(maxPoint, chunk.maxPoint);\n chunks.push(chunk);\n chunkPos.push(changes.mapPos(start));\n }\n else if (touch === true) {\n let { mapped, pos } = chunk.map(start, changes);\n if (mapped) {\n maxPoint = Math.max(maxPoint, mapped.maxPoint);\n chunks.push(mapped);\n chunkPos.push(pos);\n }\n }\n }\n let next = this.nextLayer.map(changes);\n return chunks.length == 0 ? next : new RangeSet(chunkPos, chunks, next || RangeSet.empty, maxPoint);\n }\n /**\n Iterate over the ranges that touch the region `from` to `to`,\n calling `f` for each. There is no guarantee that the ranges will\n be reported in any specific order. When the callback returns\n `false`, iteration stops.\n */\n between(from, to, f) {\n if (this.isEmpty)\n return;\n for (let i = 0; i < this.chunk.length; i++) {\n let start = this.chunkPos[i], chunk = this.chunk[i];\n if (to >= start && from <= start + chunk.length &&\n chunk.between(start, from - start, to - start, f) === false)\n return;\n }\n this.nextLayer.between(from, to, f);\n }\n /**\n Iterate over the ranges in this set, in order, including all\n ranges that end at or after `from`.\n */\n iter(from = 0) {\n return HeapCursor.from([this]).goto(from);\n }\n /**\n @internal\n */\n get isEmpty() { return this.nextLayer == this; }\n /**\n Iterate over the ranges in a collection of sets, in order,\n starting from `from`.\n */\n static iter(sets, from = 0) {\n return HeapCursor.from(sets).goto(from);\n }\n /**\n Iterate over two groups of sets, calling methods on `comparator`\n to notify it of possible differences.\n */\n static compare(oldSets, newSets, \n /**\n This indicates how the underlying data changed between these\n ranges, and is needed to synchronize the iteration.\n */\n textDiff, comparator, \n /**\n Can be used to ignore all non-point ranges, and points below\n the given size. When -1, all ranges are compared.\n */\n minPointSize = -1) {\n let a = oldSets.filter(set => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);\n let b = newSets.filter(set => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);\n let sharedChunks = findSharedChunks(a, b, textDiff);\n let sideA = new SpanCursor(a, sharedChunks, minPointSize);\n let sideB = new SpanCursor(b, sharedChunks, minPointSize);\n textDiff.iterGaps((fromA, fromB, length) => compare(sideA, fromA, sideB, fromB, length, comparator));\n if (textDiff.empty && textDiff.length == 0)\n compare(sideA, 0, sideB, 0, 0, comparator);\n }\n /**\n Compare the contents of two groups of range sets, returning true\n if they are equivalent in the given range.\n */\n static eq(oldSets, newSets, from = 0, to) {\n if (to == null)\n to = 1000000000 /* C.Far */ - 1;\n let a = oldSets.filter(set => !set.isEmpty && newSets.indexOf(set) < 0);\n let b = newSets.filter(set => !set.isEmpty && oldSets.indexOf(set) < 0);\n if (a.length != b.length)\n return false;\n if (!a.length)\n return true;\n let sharedChunks = findSharedChunks(a, b);\n let sideA = new SpanCursor(a, sharedChunks, 0).goto(from), sideB = new SpanCursor(b, sharedChunks, 0).goto(from);\n for (;;) {\n if (sideA.to != sideB.to ||\n !sameValues(sideA.active, sideB.active) ||\n sideA.point && (!sideB.point || !sideA.point.eq(sideB.point)))\n return false;\n if (sideA.to > to)\n return true;\n sideA.next();\n sideB.next();\n }\n }\n /**\n Iterate over a group of range sets at the same time, notifying\n the iterator about the ranges covering every given piece of\n content. Returns the open count (see\n [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end\n of the iteration.\n */\n static spans(sets, from, to, iterator, \n /**\n When given and greater than -1, only points of at least this\n size are taken into account.\n */\n minPointSize = -1) {\n let cursor = new SpanCursor(sets, null, minPointSize).goto(from), pos = from;\n let openRanges = cursor.openStart;\n for (;;) {\n let curTo = Math.min(cursor.to, to);\n if (cursor.point) {\n let active = cursor.activeForPoint(cursor.to);\n let openCount = cursor.pointFrom < from ? active.length + 1\n : cursor.point.startSide < 0 ? active.length\n : Math.min(active.length, openRanges);\n iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);\n openRanges = Math.min(cursor.openEnd(curTo), active.length);\n }\n else if (curTo > pos) {\n iterator.span(pos, curTo, cursor.active, openRanges);\n openRanges = cursor.openEnd(curTo);\n }\n if (cursor.to > to)\n return openRanges + (cursor.point && cursor.to > to ? 1 : 0);\n pos = cursor.to;\n cursor.next();\n }\n }\n /**\n Create a range set for the given range or array of ranges. By\n default, this expects the ranges to be _sorted_ (by start\n position and, if two start at the same position,\n `value.startSide`). You can pass `true` as second argument to\n cause the method to sort them.\n */\n static of(ranges, sort = false) {\n let build = new RangeSetBuilder();\n for (let range of ranges instanceof Range ? [ranges] : sort ? lazySort(ranges) : ranges)\n build.add(range.from, range.to, range.value);\n return build.finish();\n }\n /**\n Join an array of range sets into a single set.\n */\n static join(sets) {\n if (!sets.length)\n return RangeSet.empty;\n let result = sets[sets.length - 1];\n for (let i = sets.length - 2; i >= 0; i--) {\n for (let layer = sets[i]; layer != RangeSet.empty; layer = layer.nextLayer)\n result = new RangeSet(layer.chunkPos, layer.chunk, result, Math.max(layer.maxPoint, result.maxPoint));\n }\n return result;\n }\n}\n/**\nThe empty set of ranges.\n*/\nRangeSet.empty = /*@__PURE__*/new RangeSet([], [], null, -1);\nfunction lazySort(ranges) {\n if (ranges.length > 1)\n for (let prev = ranges[0], i = 1; i < ranges.length; i++) {\n let cur = ranges[i];\n if (cmpRange(prev, cur) > 0)\n return ranges.slice().sort(cmpRange);\n prev = cur;\n }\n return ranges;\n}\nRangeSet.empty.nextLayer = RangeSet.empty;\n/**\nA range set builder is a data structure that helps build up a\n[range set](https://codemirror.net/6/docs/ref/#state.RangeSet) directly, without first allocating\nan array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.\n*/\nclass RangeSetBuilder {\n finishChunk(newArrays) {\n this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));\n this.chunkPos.push(this.chunkStart);\n this.chunkStart = -1;\n this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);\n this.maxPoint = -1;\n if (newArrays) {\n this.from = [];\n this.to = [];\n this.value = [];\n }\n }\n /**\n Create an empty builder.\n */\n constructor() {\n this.chunks = [];\n this.chunkPos = [];\n this.chunkStart = -1;\n this.last = null;\n this.lastFrom = -1000000000 /* C.Far */;\n this.lastTo = -1000000000 /* C.Far */;\n this.from = [];\n this.to = [];\n this.value = [];\n this.maxPoint = -1;\n this.setMaxPoint = -1;\n this.nextLayer = null;\n }\n /**\n Add a range. Ranges should be added in sorted (by `from` and\n `value.startSide`) order.\n */\n add(from, to, value) {\n if (!this.addInner(from, to, value))\n (this.nextLayer || (this.nextLayer = new RangeSetBuilder)).add(from, to, value);\n }\n /**\n @internal\n */\n addInner(from, to, value) {\n let diff = from - this.lastTo || value.startSide - this.last.endSide;\n if (diff <= 0 && (from - this.lastFrom || value.startSide - this.last.startSide) < 0)\n throw new Error(\"Ranges must be added sorted by `from` position and `startSide`\");\n if (diff < 0)\n return false;\n if (this.from.length == 250 /* C.ChunkSize */)\n this.finishChunk(true);\n if (this.chunkStart < 0)\n this.chunkStart = from;\n this.from.push(from - this.chunkStart);\n this.to.push(to - this.chunkStart);\n this.last = value;\n this.lastFrom = from;\n this.lastTo = to;\n this.value.push(value);\n if (value.point)\n this.maxPoint = Math.max(this.maxPoint, to - from);\n return true;\n }\n /**\n @internal\n */\n addChunk(from, chunk) {\n if ((from - this.lastTo || chunk.value[0].startSide - this.last.endSide) < 0)\n return false;\n if (this.from.length)\n this.finishChunk(true);\n this.setMaxPoint = Math.max(this.setMaxPoint, chunk.maxPoint);\n this.chunks.push(chunk);\n this.chunkPos.push(from);\n let last = chunk.value.length - 1;\n this.last = chunk.value[last];\n this.lastFrom = chunk.from[last] + from;\n this.lastTo = chunk.to[last] + from;\n return true;\n }\n /**\n Finish the range set. Returns the new set. The builder can't be\n used anymore after this has been called.\n */\n finish() { return this.finishInner(RangeSet.empty); }\n /**\n @internal\n */\n finishInner(next) {\n if (this.from.length)\n this.finishChunk(false);\n if (this.chunks.length == 0)\n return next;\n let result = RangeSet.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(next) : next, this.setMaxPoint);\n this.from = null; // Make sure further `add` calls produce errors\n return result;\n }\n}\nfunction findSharedChunks(a, b, textDiff) {\n let inA = new Map();\n for (let set of a)\n for (let i = 0; i < set.chunk.length; i++)\n if (set.chunk[i].maxPoint <= 0)\n inA.set(set.chunk[i], set.chunkPos[i]);\n let shared = new Set();\n for (let set of b)\n for (let i = 0; i < set.chunk.length; i++) {\n let known = inA.get(set.chunk[i]);\n if (known != null && (textDiff ? textDiff.mapPos(known) : known) == set.chunkPos[i] &&\n !(textDiff === null || textDiff === void 0 ? void 0 : textDiff.touchesRange(known, known + set.chunk[i].length)))\n shared.add(set.chunk[i]);\n }\n return shared;\n}\nclass LayerCursor {\n constructor(layer, skip, minPoint, rank = 0) {\n this.layer = layer;\n this.skip = skip;\n this.minPoint = minPoint;\n this.rank = rank;\n }\n get startSide() { return this.value ? this.value.startSide : 0; }\n get endSide() { return this.value ? this.value.endSide : 0; }\n goto(pos, side = -1000000000 /* C.Far */) {\n this.chunkIndex = this.rangeIndex = 0;\n this.gotoInner(pos, side, false);\n return this;\n }\n gotoInner(pos, side, forward) {\n while (this.chunkIndex < this.layer.chunk.length) {\n let next = this.layer.chunk[this.chunkIndex];\n if (!(this.skip && this.skip.has(next) ||\n this.layer.chunkEnd(this.chunkIndex) < pos ||\n next.maxPoint < this.minPoint))\n break;\n this.chunkIndex++;\n forward = false;\n }\n if (this.chunkIndex < this.layer.chunk.length) {\n let rangeIndex = this.layer.chunk[this.chunkIndex].findIndex(pos - this.layer.chunkPos[this.chunkIndex], side, true);\n if (!forward || this.rangeIndex < rangeIndex)\n this.setRangeIndex(rangeIndex);\n }\n this.next();\n }\n forward(pos, side) {\n if ((this.to - pos || this.endSide - side) < 0)\n this.gotoInner(pos, side, true);\n }\n next() {\n for (;;) {\n if (this.chunkIndex == this.layer.chunk.length) {\n this.from = this.to = 1000000000 /* C.Far */;\n this.value = null;\n break;\n }\n else {\n let chunkPos = this.layer.chunkPos[this.chunkIndex], chunk = this.layer.chunk[this.chunkIndex];\n let from = chunkPos + chunk.from[this.rangeIndex];\n this.from = from;\n this.to = chunkPos + chunk.to[this.rangeIndex];\n this.value = chunk.value[this.rangeIndex];\n this.setRangeIndex(this.rangeIndex + 1);\n if (this.minPoint < 0 || this.value.point && this.to - this.from >= this.minPoint)\n break;\n }\n }\n }\n setRangeIndex(index) {\n if (index == this.layer.chunk[this.chunkIndex].value.length) {\n this.chunkIndex++;\n if (this.skip) {\n while (this.chunkIndex < this.layer.chunk.length && this.skip.has(this.layer.chunk[this.chunkIndex]))\n this.chunkIndex++;\n }\n this.rangeIndex = 0;\n }\n else {\n this.rangeIndex = index;\n }\n }\n nextChunk() {\n this.chunkIndex++;\n this.rangeIndex = 0;\n this.next();\n }\n compare(other) {\n return this.from - other.from || this.startSide - other.startSide || this.rank - other.rank ||\n this.to - other.to || this.endSide - other.endSide;\n }\n}\nclass HeapCursor {\n constructor(heap) {\n this.heap = heap;\n }\n static from(sets, skip = null, minPoint = -1) {\n let heap = [];\n for (let i = 0; i < sets.length; i++) {\n for (let cur = sets[i]; !cur.isEmpty; cur = cur.nextLayer) {\n if (cur.maxPoint >= minPoint)\n heap.push(new LayerCursor(cur, skip, minPoint, i));\n }\n }\n return heap.length == 1 ? heap[0] : new HeapCursor(heap);\n }\n get startSide() { return this.value ? this.value.startSide : 0; }\n goto(pos, side = -1000000000 /* C.Far */) {\n for (let cur of this.heap)\n cur.goto(pos, side);\n for (let i = this.heap.length >> 1; i >= 0; i--)\n heapBubble(this.heap, i);\n this.next();\n return this;\n }\n forward(pos, side) {\n for (let cur of this.heap)\n cur.forward(pos, side);\n for (let i = this.heap.length >> 1; i >= 0; i--)\n heapBubble(this.heap, i);\n if ((this.to - pos || this.value.endSide - side) < 0)\n this.next();\n }\n next() {\n if (this.heap.length == 0) {\n this.from = this.to = 1000000000 /* C.Far */;\n this.value = null;\n this.rank = -1;\n }\n else {\n let top = this.heap[0];\n this.from = top.from;\n this.to = top.to;\n this.value = top.value;\n this.rank = top.rank;\n if (top.value)\n top.next();\n heapBubble(this.heap, 0);\n }\n }\n}\nfunction heapBubble(heap, index) {\n for (let cur = heap[index];;) {\n let childIndex = (index << 1) + 1;\n if (childIndex >= heap.length)\n break;\n let child = heap[childIndex];\n if (childIndex + 1 < heap.length && child.compare(heap[childIndex + 1]) >= 0) {\n child = heap[childIndex + 1];\n childIndex++;\n }\n if (cur.compare(child) < 0)\n break;\n heap[childIndex] = cur;\n heap[index] = child;\n index = childIndex;\n }\n}\nclass SpanCursor {\n constructor(sets, skip, minPoint) {\n this.minPoint = minPoint;\n this.active = [];\n this.activeTo = [];\n this.activeRank = [];\n this.minActive = -1;\n // A currently active point range, if any\n this.point = null;\n this.pointFrom = 0;\n this.pointRank = 0;\n this.to = -1000000000 /* C.Far */;\n this.endSide = 0;\n // The amount of open active ranges at the start of the iterator.\n // Not including points.\n this.openStart = -1;\n this.cursor = HeapCursor.from(sets, skip, minPoint);\n }\n goto(pos, side = -1000000000 /* C.Far */) {\n this.cursor.goto(pos, side);\n this.active.length = this.activeTo.length = this.activeRank.length = 0;\n this.minActive = -1;\n this.to = pos;\n this.endSide = side;\n this.openStart = -1;\n this.next();\n return this;\n }\n forward(pos, side) {\n while (this.minActive > -1 && (this.activeTo[this.minActive] - pos || this.active[this.minActive].endSide - side) < 0)\n this.removeActive(this.minActive);\n this.cursor.forward(pos, side);\n }\n removeActive(index) {\n remove(this.active, index);\n remove(this.activeTo, index);\n remove(this.activeRank, index);\n this.minActive = findMinIndex(this.active, this.activeTo);\n }\n addActive(trackOpen) {\n let i = 0, { value, to, rank } = this.cursor;\n // Organize active marks by rank first, then by size\n while (i < this.activeRank.length && (rank - this.activeRank[i] || to - this.activeTo[i]) > 0)\n i++;\n insert(this.active, i, value);\n insert(this.activeTo, i, to);\n insert(this.activeRank, i, rank);\n if (trackOpen)\n insert(trackOpen, i, this.cursor.from);\n this.minActive = findMinIndex(this.active, this.activeTo);\n }\n // After calling this, if `this.point` != null, the next range is a\n // point. Otherwise, it's a regular range, covered by `this.active`.\n next() {\n let from = this.to, wasPoint = this.point;\n this.point = null;\n let trackOpen = this.openStart < 0 ? [] : null;\n for (;;) {\n let a = this.minActive;\n if (a > -1 && (this.activeTo[a] - this.cursor.from || this.active[a].endSide - this.cursor.startSide) < 0) {\n if (this.activeTo[a] > from) {\n this.to = this.activeTo[a];\n this.endSide = this.active[a].endSide;\n break;\n }\n this.removeActive(a);\n if (trackOpen)\n remove(trackOpen, a);\n }\n else if (!this.cursor.value) {\n this.to = this.endSide = 1000000000 /* C.Far */;\n break;\n }\n else if (this.cursor.from > from) {\n this.to = this.cursor.from;\n this.endSide = this.cursor.startSide;\n break;\n }\n else {\n let nextVal = this.cursor.value;\n if (!nextVal.point) { // Opening a range\n this.addActive(trackOpen);\n this.cursor.next();\n }\n else if (wasPoint && this.cursor.to == this.to && this.cursor.from < this.cursor.to) {\n // Ignore any non-empty points that end precisely at the end of the prev point\n this.cursor.next();\n }\n else { // New point\n this.point = nextVal;\n this.pointFrom = this.cursor.from;\n this.pointRank = this.cursor.rank;\n this.to = this.cursor.to;\n this.endSide = nextVal.endSide;\n this.cursor.next();\n this.forward(this.to, this.endSide);\n break;\n }\n }\n }\n if (trackOpen) {\n this.openStart = 0;\n for (let i = trackOpen.length - 1; i >= 0 && trackOpen[i] < from; i--)\n this.openStart++;\n }\n }\n activeForPoint(to) {\n if (!this.active.length)\n return this.active;\n let active = [];\n for (let i = this.active.length - 1; i >= 0; i--) {\n if (this.activeRank[i] < this.pointRank)\n break;\n if (this.activeTo[i] > to || this.activeTo[i] == to && this.active[i].endSide >= this.point.endSide)\n active.push(this.active[i]);\n }\n return active.reverse();\n }\n openEnd(to) {\n let open = 0;\n for (let i = this.activeTo.length - 1; i >= 0 && this.activeTo[i] > to; i--)\n open++;\n return open;\n }\n}\nfunction compare(a, startA, b, startB, length, comparator) {\n a.goto(startA);\n b.goto(startB);\n let endB = startB + length;\n let pos = startB, dPos = startB - startA;\n for (;;) {\n let dEnd = (a.to + dPos) - b.to, diff = dEnd || a.endSide - b.endSide;\n let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);\n if (a.point || b.point) {\n if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) &&\n sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))\n comparator.comparePoint(pos, clipEnd, a.point, b.point);\n }\n else {\n if (clipEnd > pos && !sameValues(a.active, b.active))\n comparator.compareRange(pos, clipEnd, a.active, b.active);\n }\n if (end > endB)\n break;\n if ((dEnd || a.openEnd != b.openEnd) && comparator.boundChange)\n comparator.boundChange(end);\n pos = end;\n if (diff <= 0)\n a.next();\n if (diff >= 0)\n b.next();\n }\n}\nfunction sameValues(a, b) {\n if (a.length != b.length)\n return false;\n for (let i = 0; i < a.length; i++)\n if (a[i] != b[i] && !a[i].eq(b[i]))\n return false;\n return true;\n}\nfunction remove(array, index) {\n for (let i = index, e = array.length - 1; i < e; i++)\n array[i] = array[i + 1];\n array.pop();\n}\nfunction insert(array, index, value) {\n for (let i = array.length - 1; i >= index; i--)\n array[i + 1] = array[i];\n array[index] = value;\n}\nfunction findMinIndex(value, array) {\n let found = -1, foundPos = 1000000000 /* C.Far */;\n for (let i = 0; i < array.length; i++)\n if ((array[i] - foundPos || value[i].endSide - value[found].endSide) < 0) {\n found = i;\n foundPos = array[i];\n }\n return found;\n}\n\n/**\nCount the column position at the given offset into the string,\ntaking extending characters and tab size into account.\n*/\nfunction countColumn(string, tabSize, to = string.length) {\n let n = 0;\n for (let i = 0; i < to && i < string.length;) {\n if (string.charCodeAt(i) == 9) {\n n += tabSize - (n % tabSize);\n i++;\n }\n else {\n n++;\n i = findClusterBreak(string, i);\n }\n }\n return n;\n}\n/**\nFind the offset that corresponds to the given column position in a\nstring, taking extending characters and tab size into account. By\ndefault, the string length is returned when it is too short to\nreach the column. Pass `strict` true to make it return -1 in that\nsituation.\n*/\nfunction findColumn(string, col, tabSize, strict) {\n for (let i = 0, n = 0;;) {\n if (n >= col)\n return i;\n if (i == string.length)\n break;\n n += string.charCodeAt(i) == 9 ? tabSize - (n % tabSize) : 1;\n i = findClusterBreak(string, i);\n }\n return strict === true ? -1 : string.length;\n}\n\nexport { Annotation, AnnotationType, ChangeDesc, ChangeSet, CharCategory, Compartment, EditorSelection, EditorState, Facet, Line, MapMode, Prec, Range, RangeSet, RangeSetBuilder, RangeValue, SelectionRange, StateEffect, StateEffectType, StateField, Text, Transaction, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };\n","const C = \"\\u037c\"\nconst COUNT = typeof Symbol == \"undefined\" ? \"__\" + C : Symbol.for(C)\nconst SET = typeof Symbol == \"undefined\" ? \"__styleSet\" + Math.floor(Math.random() * 1e8) : Symbol(\"styleSet\")\nconst top = typeof globalThis != \"undefined\" ? globalThis : typeof window != \"undefined\" ? window : {}\n\n// :: - Style modules encapsulate a set of CSS rules defined from\n// JavaScript. Their definitions are only available in a given DOM\n// root after it has been _mounted_ there with `StyleModule.mount`.\n//\n// Style modules should be created once and stored somewhere, as\n// opposed to re-creating them every time you need them. The amount of\n// CSS rules generated for a given DOM root is bounded by the amount\n// of style modules that were used. So to avoid leaking rules, don't\n// create these dynamically, but treat them as one-time allocations.\nexport class StyleModule {\n // :: (Object