diff --git a/.gitignore b/.gitignore
index 8336a44..d367d08 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
data/
.tmp/
*.sh
+assets/editor/node_modules/
diff --git a/Dockerfile b/Dockerfile
index c8c2f37..4746188 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,5 @@
-FROM golang:1.22-alpine
+FROM golang:1.25-alpine
+
WORKDIR /src
diff --git a/assets/editor/build.mjs b/assets/editor/build.mjs
new file mode 100644
index 0000000..e65c4fc
--- /dev/null
+++ b/assets/editor/build.mjs
@@ -0,0 +1,9 @@
+import { build } from "esbuild";
+
+await build({
+ entryPoints: ["src/editor.js"],
+ bundle: true,
+ minify: false,
+ sourcemap: true,
+ outfile: "../../static/vendor/codemirror/editor.bundle.js",
+});
diff --git a/assets/editor/package-lock.json b/assets/editor/package-lock.json
new file mode 100644
index 0000000..078c0a3
--- /dev/null
+++ b/assets/editor/package-lock.json
@@ -0,0 +1,677 @@
+{
+ "name": "editor",
+ "version": "1.0.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "editor",
+ "version": "1.0.0",
+ "license": "ISC",
+ "dependencies": {
+ "@codemirror/autocomplete": "^6.20.3",
+ "@codemirror/commands": "^6.10.3",
+ "@codemirror/lang-html": "^6.4.11",
+ "@codemirror/lang-markdown": "^6.5.0",
+ "@codemirror/language": "^6.12.3",
+ "@codemirror/state": "^6.6.0",
+ "@codemirror/view": "^6.43.0",
+ "@replit/codemirror-vim": "^6.3.0",
+ "esbuild": "^0.28.0"
+ }
+ },
+ "node_modules/@codemirror/autocomplete": {
+ "version": "6.20.3",
+ "resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.20.3.tgz",
+ "integrity": "sha512-tlosUqb+3BbxCxZdu4tKeRghPFC+QM7q4X5YhKV2eCmPG+1r2F3f4AaSz5sCrFqUtX4Jh20VFTKecl16MgiV9g==",
+ "dependencies": {
+ "@codemirror/language": "^6.0.0",
+ "@codemirror/state": "^6.0.0",
+ "@codemirror/view": "^6.17.0",
+ "@lezer/common": "^1.0.0"
+ }
+ },
+ "node_modules/@codemirror/commands": {
+ "version": "6.10.3",
+ "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.10.3.tgz",
+ "integrity": "sha512-JFRiqhKu+bvSkDLI+rUhJwSxQxYb759W5GBezE8Uc8mHLqC9aV/9aTC7yJSqCtB3F00pylrLCwnyS91Ap5ej4Q==",
+ "dependencies": {
+ "@codemirror/language": "^6.0.0",
+ "@codemirror/state": "^6.6.0",
+ "@codemirror/view": "^6.27.0",
+ "@lezer/common": "^1.1.0"
+ }
+ },
+ "node_modules/@codemirror/lang-css": {
+ "version": "6.3.1",
+ "resolved": "https://registry.npmjs.org/@codemirror/lang-css/-/lang-css-6.3.1.tgz",
+ "integrity": "sha512-kr5fwBGiGtmz6l0LSJIbno9QrifNMUusivHbnA1H6Dmqy4HZFte3UAICix1VuKo0lMPKQr2rqB+0BkKi/S3Ejg==",
+ "dependencies": {
+ "@codemirror/autocomplete": "^6.0.0",
+ "@codemirror/language": "^6.0.0",
+ "@codemirror/state": "^6.0.0",
+ "@lezer/common": "^1.0.2",
+ "@lezer/css": "^1.1.7"
+ }
+ },
+ "node_modules/@codemirror/lang-html": {
+ "version": "6.4.11",
+ "resolved": "https://registry.npmjs.org/@codemirror/lang-html/-/lang-html-6.4.11.tgz",
+ "integrity": "sha512-9NsXp7Nwp891pQchI7gPdTwBuSuT3K65NGTHWHNJ55HjYcHLllr0rbIZNdOzas9ztc1EUVBlHou85FFZS4BNnw==",
+ "dependencies": {
+ "@codemirror/autocomplete": "^6.0.0",
+ "@codemirror/lang-css": "^6.0.0",
+ "@codemirror/lang-javascript": "^6.0.0",
+ "@codemirror/language": "^6.4.0",
+ "@codemirror/state": "^6.0.0",
+ "@codemirror/view": "^6.17.0",
+ "@lezer/common": "^1.0.0",
+ "@lezer/css": "^1.1.0",
+ "@lezer/html": "^1.3.12"
+ }
+ },
+ "node_modules/@codemirror/lang-javascript": {
+ "version": "6.2.5",
+ "resolved": "https://registry.npmjs.org/@codemirror/lang-javascript/-/lang-javascript-6.2.5.tgz",
+ "integrity": "sha512-zD4e5mS+50htS7F+TYjBPsiIFGanfVqg4HyUz6WNFikgOPf2BgKlx+TQedI1w6n/IqRBVBbBWmGFdLB/7uxO4A==",
+ "dependencies": {
+ "@codemirror/autocomplete": "^6.0.0",
+ "@codemirror/language": "^6.6.0",
+ "@codemirror/lint": "^6.0.0",
+ "@codemirror/state": "^6.0.0",
+ "@codemirror/view": "^6.17.0",
+ "@lezer/common": "^1.0.0",
+ "@lezer/javascript": "^1.0.0"
+ }
+ },
+ "node_modules/@codemirror/lang-markdown": {
+ "version": "6.5.0",
+ "resolved": "https://registry.npmjs.org/@codemirror/lang-markdown/-/lang-markdown-6.5.0.tgz",
+ "integrity": "sha512-0K40bZ35jpHya6FriukbgaleaqzBLZfOh7HuzqbMxBXkbYMJDxfF39c23xOgxFezR+3G+tR2/Mup+Xk865OMvw==",
+ "dependencies": {
+ "@codemirror/autocomplete": "^6.7.1",
+ "@codemirror/lang-html": "^6.0.0",
+ "@codemirror/language": "^6.3.0",
+ "@codemirror/state": "^6.0.0",
+ "@codemirror/view": "^6.0.0",
+ "@lezer/common": "^1.2.1",
+ "@lezer/markdown": "^1.0.0"
+ }
+ },
+ "node_modules/@codemirror/language": {
+ "version": "6.12.3",
+ "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.12.3.tgz",
+ "integrity": "sha512-QwCZW6Tt1siP37Jet9Tb02Zs81TQt6qQrZR2H+eGMcFsL1zMrk2/b9CLC7/9ieP1fjIUMgviLWMmgiHoJrj+ZA==",
+ "dependencies": {
+ "@codemirror/state": "^6.0.0",
+ "@codemirror/view": "^6.23.0",
+ "@lezer/common": "^1.5.0",
+ "@lezer/highlight": "^1.0.0",
+ "@lezer/lr": "^1.0.0",
+ "style-mod": "^4.0.0"
+ }
+ },
+ "node_modules/@codemirror/lint": {
+ "version": "6.9.6",
+ "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.9.6.tgz",
+ "integrity": "sha512-6Kp7r6XfCi/D/5sdXieMfg9pJU1bUEx96WITuLU6ESaKizCz0QHFMjY/TaFSbigDdEAIgi93itLBIUETP4oK+A==",
+ "dependencies": {
+ "@codemirror/state": "^6.0.0",
+ "@codemirror/view": "^6.42.0",
+ "crelt": "^1.0.5"
+ }
+ },
+ "node_modules/@codemirror/search": {
+ "version": "6.7.0",
+ "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.7.0.tgz",
+ "integrity": "sha512-ZvGm99wc/s2cITtMT15LFdn8aH/aS+V+DqyGq/N5ZlV5vWtH+nILvC2nw0zX7ByNoHHDZ2IxxdW38O0tc5nVHg==",
+ "peer": true,
+ "dependencies": {
+ "@codemirror/state": "^6.0.0",
+ "@codemirror/view": "^6.37.0",
+ "crelt": "^1.0.5"
+ }
+ },
+ "node_modules/@codemirror/state": {
+ "version": "6.6.0",
+ "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.6.0.tgz",
+ "integrity": "sha512-4nbvra5R5EtiCzr9BTHiTLc+MLXK2QGiAVYMyi8PkQd3SR+6ixar/Q/01Fa21TBIDOZXgeWV4WppsQolSreAPQ==",
+ "dependencies": {
+ "@marijn/find-cluster-break": "^1.0.0"
+ }
+ },
+ "node_modules/@codemirror/view": {
+ "version": "6.43.0",
+ "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.0.tgz",
+ "integrity": "sha512-V7ZCLQO3Jus9hzh2jVCCPW3mO4IBMr43O37PqSUYautJSnnJF41YlgLw21x0fLJTYvJ+Vkm6Gp+qKGH9pltgXA==",
+ "dependencies": {
+ "@codemirror/state": "^6.6.0",
+ "crelt": "^1.0.6",
+ "style-mod": "^4.1.0",
+ "w3c-keyname": "^2.2.4"
+ }
+ },
+ "node_modules/@esbuild/aix-ppc64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.0.tgz",
+ "integrity": "sha512-lhRUCeuOyJQURhTxl4WkpFTjIsbDayJHih5kZC1giwE+MhIzAb7mEsQMqMf18rHLsrb5qI1tafG20mLxEWcWlA==",
+ "cpu": [
+ "ppc64"
+ ],
+ "optional": true,
+ "os": [
+ "aix"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.0.tgz",
+ "integrity": "sha512-wqh0ByljabXLKHeWXYLqoJ5jKC4XBaw6Hk08OfMrCRd2nP2ZQ5eleDZC41XHyCNgktBGYMbqnrJKq/K/lzPMSQ==",
+ "cpu": [
+ "arm"
+ ],
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.0.tgz",
+ "integrity": "sha512-+WzIXQOSaGs33tLEgYPYe/yQHf0WTU0X42Jca3y8NWMbUVhp7rUnw+vAsRC/QiDrdD31IszMrZy+qwPOPjd+rw==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/android-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.0.tgz",
+ "integrity": "sha512-+VJggoaKhk2VNNqVL7f6S189UzShHC/mR9EE8rDdSkdpN0KflSwWY/gWjDrNxxisg8Fp1ZCD9jLMo4m0OUfeUA==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "android"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.0.tgz",
+ "integrity": "sha512-0T+A9WZm+bZ84nZBtk1ckYsOvyA3x7e2Acj1KdVfV4/2tdG4fzUp91YHx+GArWLtwqp77pBXVCPn2We7Letr0Q==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/darwin-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.0.tgz",
+ "integrity": "sha512-fyzLm/DLDl/84OCfp2f/XQ4flmORsjU7VKt8HLjvIXChJoFFOIL6pLJPH4Yhd1n1gGFF9mPwtlN5Wf82DZs+LQ==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.0.tgz",
+ "integrity": "sha512-l9GeW5UZBT9k9brBYI+0WDffcRxgHQD8ShN2Ur4xWq/NFzUKm3k5lsH4PdaRgb2w7mI9u61nr2gI2mLI27Nh3Q==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/freebsd-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.0.tgz",
+ "integrity": "sha512-BXoQai/A0wPO6Es3yFJ7APCiKGc1tdAEOgeTNy3SsB491S3aHn4S4r3e976eUnPdU+NbdtmBuLncYir2tMU9Nw==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "freebsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.0.tgz",
+ "integrity": "sha512-CjaaREJagqJp7iTaNQjjidaNbCKYcd4IDkzbwwxtSvjI7NZm79qiHc8HqciMddQ6CKvJT6aBd8lO9kN/ZudLlw==",
+ "cpu": [
+ "arm"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.0.tgz",
+ "integrity": "sha512-RVyzfb3FWsGA55n6WY0MEIEPURL1FcbhFE6BffZEMEekfCzCIMtB5yyDcFnVbTnwk+CLAgTujmV/Lgvih56W+A==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ia32": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.0.tgz",
+ "integrity": "sha512-KBnSTt1kxl9x70q+ydterVdl+Cn0H18ngRMRCEQfrbqdUuntQQ0LoMZv47uB97NljZFzY6HcfqEZ2SAyIUTQBQ==",
+ "cpu": [
+ "ia32"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-loong64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.0.tgz",
+ "integrity": "sha512-zpSlUce1mnxzgBADvxKXX5sl8aYQHo2ezvMNI8I0lbblJtp8V4odlm3Yzlj7gPyt3T8ReksE6bK+pT3WD+aJRg==",
+ "cpu": [
+ "loong64"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-mips64el": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.0.tgz",
+ "integrity": "sha512-2jIfP6mmjkdmeTlsX/9vmdmhBmKADrWqN7zcdtHIeNSCH1SqIoNI63cYsjQR8J+wGa4Y5izRcSHSm8K3QWmk3w==",
+ "cpu": [
+ "mips64el"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-ppc64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.0.tgz",
+ "integrity": "sha512-bc0FE9wWeC0WBm49IQMPSPILRocGTQt3j5KPCA8os6VprfuJ7KD+5PzESSrJ6GmPIPJK965ZJHTUlSA6GNYEhg==",
+ "cpu": [
+ "ppc64"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-riscv64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.0.tgz",
+ "integrity": "sha512-SQPZOwoTTT/HXFXQJG/vBX8sOFagGqvZyXcgLA3NhIqcBv1BJU1d46c0rGcrij2B56Z2rNiSLaZOYW5cUk7yLQ==",
+ "cpu": [
+ "riscv64"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-s390x": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.0.tgz",
+ "integrity": "sha512-SCfR0HN8CEEjnYnySJTd2cw0k9OHB/YFzt5zgJEwa+wL/T/raGWYMBqwDNAC6dqFKmJYZoQBRfHjgwLHGSrn3Q==",
+ "cpu": [
+ "s390x"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/linux-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.0.tgz",
+ "integrity": "sha512-us0dSb9iFxIi8srnpl931Nvs65it/Jd2a2K3qs7fz2WfGPHqzfzZTfec7oxZJRNPXPnNYZtanmRc4AL/JwVzHQ==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.0.tgz",
+ "integrity": "sha512-CR/RYotgtCKwtftMwJlUU7xCVNg3lMYZ0RzTmAHSfLCXw3NtZtNpswLEj/Kkf6kEL3Gw+BpOekRX0BYCtklhUw==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/netbsd-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.0.tgz",
+ "integrity": "sha512-nU1yhmYutL+fQ71Kxnhg8uEOdC0pwEW9entHykTgEbna2pw2dkbFSMeqjjyHZoCmt8SBkOSvV+yNmm94aUrrqw==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "netbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.0.tgz",
+ "integrity": "sha512-cXb5vApOsRsxsEl4mcZ1XY3D4DzcoMxR/nnc4IyqYs0rTI8ZKmW6kyyg+11Z8yvgMfAEldKzP7AdP64HnSC/6g==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openbsd-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.0.tgz",
+ "integrity": "sha512-8wZM2qqtv9UP3mzy7HiGYNH/zjTA355mpeuA+859TyR+e+Tc08IHYpLJuMsfpDJwoLo1ikIJI8jC3GFjnRClzA==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "openbsd"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/openharmony-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.0.tgz",
+ "integrity": "sha512-FLGfyizszcef5C3YtoyQDACyg95+dndv79i2EekILBofh5wpCa1KuBqOWKrEHZg3zrL3t5ouE5jgr94vA+Wb2w==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "openharmony"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/sunos-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.0.tgz",
+ "integrity": "sha512-1ZgjUoEdHZZl/YlV76TSCz9Hqj9h9YmMGAgAPYd+q4SicWNX3G5GCyx9uhQWSLcbvPW8Ni7lj4gDa1T40akdlw==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "sunos"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-arm64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.0.tgz",
+ "integrity": "sha512-Q9StnDmQ/enxnpxCCLSg0oo4+34B9TdXpuyPeTedN/6+iXBJ4J+zwfQI28u/Jl40nOYAxGoNi7mFP40RUtkmUA==",
+ "cpu": [
+ "arm64"
+ ],
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-ia32": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.0.tgz",
+ "integrity": "sha512-zF3ag/gfiCe6U2iczcRzSYJKH1DCI+ByzSENHlM2FcDbEeo5Zd2C86Aq0tKUYAJJ1obRP84ymxIAksZUcdztHA==",
+ "cpu": [
+ "ia32"
+ ],
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@esbuild/win32-x64": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.0.tgz",
+ "integrity": "sha512-pEl1bO9mfAmIC+tW5btTmrKaujg3zGtUmWNdCw/xs70FBjwAL3o9OEKNHvNmnyylD6ubxUERiEhdsL0xBQ9efw==",
+ "cpu": [
+ "x64"
+ ],
+ "optional": true,
+ "os": [
+ "win32"
+ ],
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@lezer/common": {
+ "version": "1.5.2",
+ "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.2.tgz",
+ "integrity": "sha512-sxQE460fPZyU3sdc8lafxiPwJHBzZRy/udNFynGQky1SePYBdhkBl1kOagA9uT3pxR8K09bOrmTUqA9wb/PjSQ=="
+ },
+ "node_modules/@lezer/css": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@lezer/css/-/css-1.3.3.tgz",
+ "integrity": "sha512-RzBo8r+/6QJeow7aPHIpGVIH59xTcJXp399820gZoMo9noQDRVpJLheIBUicYwKcsbOYoBRoLZlf2720dG/4Tg==",
+ "dependencies": {
+ "@lezer/common": "^1.2.0",
+ "@lezer/highlight": "^1.0.0",
+ "@lezer/lr": "^1.3.0"
+ }
+ },
+ "node_modules/@lezer/highlight": {
+ "version": "1.2.3",
+ "resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.3.tgz",
+ "integrity": "sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g==",
+ "dependencies": {
+ "@lezer/common": "^1.3.0"
+ }
+ },
+ "node_modules/@lezer/html": {
+ "version": "1.3.13",
+ "resolved": "https://registry.npmjs.org/@lezer/html/-/html-1.3.13.tgz",
+ "integrity": "sha512-oI7n6NJml729m7pjm9lvLvmXbdoMoi2f+1pwSDJkl9d68zGr7a9Btz8NdHTGQZtW2DA25ybeuv/SyDb9D5tseg==",
+ "dependencies": {
+ "@lezer/common": "^1.2.0",
+ "@lezer/highlight": "^1.0.0",
+ "@lezer/lr": "^1.0.0"
+ }
+ },
+ "node_modules/@lezer/javascript": {
+ "version": "1.5.4",
+ "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.5.4.tgz",
+ "integrity": "sha512-vvYx3MhWqeZtGPwDStM2dwgljd5smolYD2lR2UyFcHfxbBQebqx8yjmFmxtJ/E6nN6u1D9srOiVWm3Rb4tmcUA==",
+ "dependencies": {
+ "@lezer/common": "^1.2.0",
+ "@lezer/highlight": "^1.1.3",
+ "@lezer/lr": "^1.3.0"
+ }
+ },
+ "node_modules/@lezer/lr": {
+ "version": "1.4.10",
+ "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.10.tgz",
+ "integrity": "sha512-rnCpTIBafOx4mRp43xOxDJbFipJm/c0cia/V5TiGlhmMa+wsSdoGmUN3w5Bqrks/09Q/D4tNAmWaT8p6NRi77A==",
+ "dependencies": {
+ "@lezer/common": "^1.0.0"
+ }
+ },
+ "node_modules/@lezer/markdown": {
+ "version": "1.6.4",
+ "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-1.6.4.tgz",
+ "integrity": "sha512-N0SxazMj4k65DBfaf1azqtMZd6u7MqluP84/NZnB/io8Td9aleFmAhz9hcbvSfsxT5tdYlJ5qgv5aMJGY4zEtA==",
+ "dependencies": {
+ "@lezer/common": "^1.5.0",
+ "@lezer/highlight": "^1.0.0"
+ }
+ },
+ "node_modules/@marijn/find-cluster-break": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz",
+ "integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g=="
+ },
+ "node_modules/@replit/codemirror-vim": {
+ "version": "6.3.0",
+ "resolved": "https://registry.npmjs.org/@replit/codemirror-vim/-/codemirror-vim-6.3.0.tgz",
+ "integrity": "sha512-aTx931ULAMuJx6xLf7KQDOL7CxD+Sa05FktTDrtLaSy53uj01ll3Zf17JdKsriER248oS55GBzg0CfCTjEneAQ==",
+ "peerDependencies": {
+ "@codemirror/commands": "6.x.x",
+ "@codemirror/language": "6.x.x",
+ "@codemirror/search": "6.x.x",
+ "@codemirror/state": "6.x.x",
+ "@codemirror/view": "6.x.x"
+ }
+ },
+ "node_modules/crelt": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz",
+ "integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g=="
+ },
+ "node_modules/esbuild": {
+ "version": "0.28.0",
+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.0.tgz",
+ "integrity": "sha512-sNR9MHpXSUV/XB4zmsFKN+QgVG82Cc7+/aaxJ8Adi8hyOac+EXptIp45QBPaVyX3N70664wRbTcLTOemCAnyqw==",
+ "hasInstallScript": true,
+ "bin": {
+ "esbuild": "bin/esbuild"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "optionalDependencies": {
+ "@esbuild/aix-ppc64": "0.28.0",
+ "@esbuild/android-arm": "0.28.0",
+ "@esbuild/android-arm64": "0.28.0",
+ "@esbuild/android-x64": "0.28.0",
+ "@esbuild/darwin-arm64": "0.28.0",
+ "@esbuild/darwin-x64": "0.28.0",
+ "@esbuild/freebsd-arm64": "0.28.0",
+ "@esbuild/freebsd-x64": "0.28.0",
+ "@esbuild/linux-arm": "0.28.0",
+ "@esbuild/linux-arm64": "0.28.0",
+ "@esbuild/linux-ia32": "0.28.0",
+ "@esbuild/linux-loong64": "0.28.0",
+ "@esbuild/linux-mips64el": "0.28.0",
+ "@esbuild/linux-ppc64": "0.28.0",
+ "@esbuild/linux-riscv64": "0.28.0",
+ "@esbuild/linux-s390x": "0.28.0",
+ "@esbuild/linux-x64": "0.28.0",
+ "@esbuild/netbsd-arm64": "0.28.0",
+ "@esbuild/netbsd-x64": "0.28.0",
+ "@esbuild/openbsd-arm64": "0.28.0",
+ "@esbuild/openbsd-x64": "0.28.0",
+ "@esbuild/openharmony-arm64": "0.28.0",
+ "@esbuild/sunos-x64": "0.28.0",
+ "@esbuild/win32-arm64": "0.28.0",
+ "@esbuild/win32-ia32": "0.28.0",
+ "@esbuild/win32-x64": "0.28.0"
+ }
+ },
+ "node_modules/style-mod": {
+ "version": "4.1.3",
+ "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.3.tgz",
+ "integrity": "sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ=="
+ },
+ "node_modules/w3c-keyname": {
+ "version": "2.2.8",
+ "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
+ "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ=="
+ }
+ }
+}
diff --git a/assets/editor/package.json b/assets/editor/package.json
new file mode 100644
index 0000000..ee70b7a
--- /dev/null
+++ b/assets/editor/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "editor",
+ "version": "1.0.0",
+ "description": "",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "keywords": [],
+ "author": "",
+ "license": "ISC",
+ "dependencies": {
+ "@codemirror/autocomplete": "^6.20.3",
+ "@codemirror/commands": "^6.10.3",
+ "@codemirror/lang-html": "^6.4.11",
+ "@codemirror/lang-markdown": "^6.5.0",
+ "@codemirror/language": "^6.12.3",
+ "@codemirror/state": "^6.6.0",
+ "@codemirror/view": "^6.43.0",
+ "@replit/codemirror-vim": "^6.3.0",
+ "esbuild": "^0.28.0"
+ }
+}
diff --git a/assets/editor/src/editor.js b/assets/editor/src/editor.js
new file mode 100644
index 0000000..4f8c611
--- /dev/null
+++ b/assets/editor/src/editor.js
@@ -0,0 +1,373 @@
+import { EditorView, keymap, lineNumbers } from "@codemirror/view";
+import { EditorState } from "@codemirror/state";
+import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
+import {
+ bracketMatching,
+ defaultHighlightStyle,
+ syntaxHighlighting,
+} from "@codemirror/language";
+import {
+ autocompletion,
+ completionKeymap,
+ closeBrackets,
+ closeBracketsKeymap,
+} from "@codemirror/autocomplete";
+
+import { html } from "@codemirror/lang-html";
+import { markdown } from "@codemirror/lang-markdown";
+import { vim, Vim } from "@replit/codemirror-vim";
+
+const pagesWikiTheme = EditorView.theme({
+ ".cm-selectionBackground": {
+ backgroundColor: "rgba(255, 216, 102, 0.48) !important",
+ },
+ "&.cm-focused .cm-selectionBackground": {
+ backgroundColor: "rgba(255, 216, 102, 0.58) !important",
+ },
+ ".cm-selectionLayer .cm-selectionBackground": {
+ backgroundColor: "rgba(255, 216, 102, 0.58) !important",
+ },
+ ".cm-content ::selection": {
+ backgroundColor: "rgba(255, 216, 102, 0.48) !important",
+ color: "#ffffff !important",
+ },
+});
+
+let vimMode = "INSERT";
+
+function setEditorMode(mode) {
+ vimMode = mode;
+
+ const el =
+ document.getElementById("editor-vim-mode");
+
+ if (!el) {
+ return;
+ }
+
+ const cls =
+ "mode-" + mode.toLowerCase();
+
+ el.innerHTML =
+ "" + mode + "";
+}
+
+function markdownCompletions(context) {
+ const word =
+ context.matchBefore(/[A-Za-z#`\-\[\]\{\}:\/]*/);
+
+ if (!word || (word.from === word.to && !context.explicit)) {
+ return null;
+ }
+
+ return {
+ from: word.from,
+ options: [
+ { label: "# ", type: "keyword", apply: "# " },
+ { label: "## ", type: "keyword", apply: "## " },
+ { label: "### ", type: "keyword", apply: "### " },
+ { label: "- ", type: "keyword", apply: "- " },
+ { label: "```text", type: "snippet", apply: "```text\n\n```" },
+ { label: "```go", type: "snippet", apply: "```go\n\n```" },
+ { label: "```bash", type: "snippet", apply: "```bash\n\n```" },
+ { label: "[link](url)", type: "snippet", apply: "[text](url)" },
+ { label: "{{children}}", type: "function", apply: "{{children}}" },
+ { label: "{{children:/}}", type: "function", apply: "{{children:/}}" },
+ { label: "{{children:/ exclude=/draft}}", type: "function", apply: "{{children:/ exclude=/draft}}" },
+ ],
+ };
+}
+
+function installVimCommands() {
+ if (!Vim || !Vim.defineEx || window.PagesWikiVimCommandsInstalled) {
+ return;
+ }
+
+ window.PagesWikiVimCommandsInstalled = true;
+
+ const save =
+ () => {
+ if (window.PagesEditor && window.PagesEditor.saveNow) {
+ window.PagesEditor.saveNow();
+ }
+ };
+
+ const quit =
+ () => {
+ location.href =
+ window.PagesWikiCurrentPath || "/";
+ };
+
+ const saveQuit =
+ () => {
+ save();
+ setTimeout(quit, 120);
+ };
+
+ // Register both canonical and short names.
+ Vim.defineEx("write", "w", save);
+ Vim.defineEx("w", "w", save);
+
+ Vim.defineEx("quit", "q", quit);
+ Vim.defineEx("q", "q", quit);
+
+ Vim.defineEx("wq", "wq", saveQuit);
+ Vim.defineEx("x", "x", saveQuit);
+}
+
+function attachVimModeTracking(view) {
+ view.dom.addEventListener(
+ "keydown",
+ (ev) => {
+ if (ev.key === "Escape" || (ev.ctrlKey && ev.key === "[")) {
+ setEditorMode("NORMAL");
+ return;
+ }
+
+ if (vimMode === "NORMAL") {
+ if (ev.key === "i" || ev.key === "a" || ev.key === "o" || ev.key === "O") {
+ setEditorMode("INSERT");
+ return;
+ }
+
+ if (ev.key === "R") {
+ setEditorMode("REPLACE");
+ return;
+ }
+
+ if (ev.key === "v" || ev.key === "V") {
+ setEditorMode("VISUAL");
+ return;
+ }
+ }
+
+ if (vimMode === "VISUAL" && ev.key === "Escape") {
+ setEditorMode("NORMAL");
+ }
+ },
+ true
+ );
+
+ view.dom.addEventListener(
+ "focusin",
+ () => {
+ if (!vimMode) {
+ setEditorMode("INSERT");
+ }
+ }
+ );
+}
+
+function attachStatusBar(view) {
+ const cursorEl =
+ document.getElementById("editor-cursor");
+
+ function updateCursor() {
+ if (!cursorEl) {
+ return;
+ }
+
+ const head =
+ view.state.selection.main.head;
+
+ const line =
+ view.state.doc.lineAt(head);
+
+ cursorEl.textContent =
+ "Ln " +
+ line.number +
+ ", Col " +
+ String(head - line.from + 1);
+ }
+
+ updateCursor();
+ setEditorMode(vimMode || "INSERT");
+
+ view.dom.addEventListener("keyup", updateCursor);
+ view.dom.addEventListener("mouseup", updateCursor);
+ view.dom.addEventListener("focusin", updateCursor);
+}
+
+window.PagesWikiEditor = {
+ create(target, initialText, mode, options = {}) {
+ const keymapName =
+ String(options.keymap || "default").toLowerCase();
+
+ const extensions = [
+ lineNumbers(),
+ history(),
+ bracketMatching(),
+ closeBrackets(),
+ pagesWikiTheme,
+ EditorView.lineWrapping,
+ EditorView.updateListener.of((update) => {
+ if (update.docChanged) {
+ schedulePagesWikiPreview(update.view);
+ }
+ }),
+ ];
+
+ if (keymapName === "vim") {
+ installVimCommands();
+ extensions.push(vim());
+ setEditorMode("NORMAL");
+ } else {
+ setEditorMode("INSERT");
+ }
+
+ extensions.push(
+ keymap.of([
+ ...defaultKeymap,
+ ...historyKeymap,
+ ...completionKeymap,
+ ...closeBracketsKeymap,
+ ])
+ );
+
+ if (options.syntax !== false) {
+ extensions.push(syntaxHighlighting(defaultHighlightStyle));
+ }
+
+ if (options.autocomplete !== false) {
+ extensions.push(
+ autocompletion({
+ activateOnTyping: true,
+ override: mode === "markdown"
+ ? [markdownCompletions]
+ : undefined,
+ })
+ );
+ }
+
+ if (mode === "markdown") {
+ extensions.push(markdown());
+ } else {
+ extensions.push(html());
+ }
+
+ const view =
+ new EditorView({
+ state: EditorState.create({
+ doc: initialText,
+ extensions,
+ }),
+ parent: target,
+ });
+
+ attachStatusBar(view);
+
+ if (keymapName === "vim") {
+ attachVimModeTracking(view);
+ attachPagesWikiExFallback(view);
+ }
+
+ return view;
+ },
+};
+
+
+function attachPagesWikiExFallback(view) {
+ let active = false;
+ let buffer = "";
+
+ function save() {
+ if (window.PagesEditor && window.PagesEditor.saveNow) {
+ window.PagesEditor.saveNow();
+ }
+ }
+
+ function quit() {
+ location.href =
+ window.PagesWikiCurrentPath || "/";
+ }
+
+ view.dom.addEventListener(
+ "keydown",
+ (ev) => {
+ if (!active && vimMode === "NORMAL" && ev.key === ":") {
+ active = true;
+ buffer = "";
+ return;
+ }
+
+ if (!active) {
+ return;
+ }
+
+ if (ev.key === "Escape" || (ev.ctrlKey && ev.key === "[")) {
+ active = false;
+ buffer = "";
+ return;
+ }
+
+ if (ev.key === "Enter") {
+ const cmd =
+ buffer.trim();
+
+ active = false;
+ buffer = "";
+
+ if (cmd === "w") {
+ ev.preventDefault();
+ save();
+ return;
+ }
+
+ if (cmd === "q") {
+ ev.preventDefault();
+ quit();
+ return;
+ }
+
+ if (cmd === "wq" || cmd === "x") {
+ ev.preventDefault();
+ save();
+ setTimeout(quit, 120);
+ return;
+ }
+
+ return;
+ }
+
+ if (ev.key.length === 1) {
+ buffer += ev.key;
+ }
+
+ if (ev.key === "Backspace") {
+ buffer =
+ buffer.slice(0, -1);
+ }
+ },
+ true
+ );
+}
+
+
+let pagesWikiPreviewTimer = null;
+
+function schedulePagesWikiPreview(view) {
+ const textarea =
+ document.getElementById("editor");
+
+ if (textarea) {
+ textarea.value =
+ view.state.doc.toString();
+ }
+
+ if (pagesWikiPreviewTimer) {
+ clearTimeout(pagesWikiPreviewTimer);
+ }
+
+ pagesWikiPreviewTimer =
+ setTimeout(
+ () => {
+ if (
+ window.PagesEditor &&
+ window.PagesEditor.renderPreview
+ ) {
+ window.PagesEditor.renderPreview();
+ }
+ },
+ 350
+ );
+}
diff --git a/docker-compose.yml b/docker-compose.yml
index 772245e..4ebd4f1 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -17,4 +17,20 @@ services:
- ./data:/data
environment:
PAGESWIKI_DATA_DIR: /data
+ KROKI_URL: http://kroki:8000
restart: unless-stopped
+ kroki:
+ image: yuzutech/kroki
+ environment:
+ KROKI_MERMAID_HOST: kroki-mermaid
+ KROKI_MERMAID_PORT: 8002
+ restart: unless-stopped
+ depends_on:
+ - kroki-mermaid
+
+
+ kroki-mermaid:
+ image: yuzutech/kroki-mermaid
+ restart: unless-stopped
+ expose:
+ - "8002"
diff --git a/go.mod b/go.mod
index f2cd1fb..261548b 100644
--- a/go.mod
+++ b/go.mod
@@ -1,8 +1,9 @@
module pageswiki
-go 1.22.12
+go 1.25
require (
+ github.com/JohannesKaufmann/html-to-markdown/v2 v2.3.0
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df
github.com/google/uuid v1.6.0
golang.org/x/text v0.22.0
@@ -10,12 +11,14 @@ require (
)
require (
+ github.com/JohannesKaufmann/dom v0.2.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
- github.com/mattn/go-isatty v0.0.20 // indirect
+ github.com/mattn/go-isatty v0.0.22 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
- golang.org/x/sys v0.22.0 // indirect
+ golang.org/x/net v0.35.0 // indirect
+ golang.org/x/sys v0.30.0 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.55.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
diff --git a/go.sum b/go.sum
index a80e4b1..cd04de0 100644
--- a/go.sum
+++ b/go.sum
@@ -1,3 +1,7 @@
+github.com/JohannesKaufmann/dom v0.2.0 h1:1bragmEb19K8lHAqgFgqCpiPCFEZMTXzOIEjuxkUfLQ=
+github.com/JohannesKaufmann/dom v0.2.0/go.mod h1:57iSUl5RKric4bUkgos4zu6Xt5LMHUnw3TF1l5CbGZo=
+github.com/JohannesKaufmann/html-to-markdown/v2 v2.3.0 h1:e+ZfpzWc28HIrpIwT+J0wvlK6zkb0ffXHDH9I4QF4lU=
+github.com/JohannesKaufmann/html-to-markdown/v2 v2.3.0/go.mod h1:CD7yrhaD1dBDORPdjkpBrvnrzVIs9kZM6SRteYYUqdA=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df h1:Mwihr/o+v4L5h56rwHLOE20+hh7Okhwno5BHz3zDuao=
@@ -8,21 +12,28 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
-github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
-github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
+github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
+github.com/sebdah/goldie/v2 v2.5.5 h1:rx1mwF95RxZ3/83sdS4Yp7t2C5TCokvWP4TBRbAyEWY=
+github.com/sebdah/goldie/v2 v2.5.5/go.mod h1:oZ9fp0+se1eapSRjfYbsV/0Hqhbuu3bJVvKI/NNtssI=
+github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
+github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
+github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
+github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
+golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
+golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
-golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
-golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
+golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
diff --git a/internal/compiler/diagram.go b/internal/compiler/diagram.go
new file mode 100644
index 0000000..9046192
--- /dev/null
+++ b/internal/compiler/diagram.go
@@ -0,0 +1,24 @@
+package compiler
+
+import (
+ "crypto/sha256"
+ "encoding/hex"
+)
+
+func DiagramHash(
+ diagramType string,
+ source string,
+ format string,
+) string {
+
+ sum :=
+ sha256.Sum256(
+ []byte(
+ diagramType + "\x00" + format + "\x00" + source,
+ ),
+ )
+
+ return hex.EncodeToString(
+ sum[:],
+ )
+}
diff --git a/internal/compiler/markdown.go b/internal/compiler/markdown.go
new file mode 100644
index 0000000..d74e420
--- /dev/null
+++ b/internal/compiler/markdown.go
@@ -0,0 +1,14 @@
+package compiler
+
+import (
+ htmltomarkdown "github.com/JohannesKaufmann/html-to-markdown/v2"
+)
+
+func HTMLToMarkdown(
+ html string,
+) (string, error) {
+
+ return htmltomarkdown.ConvertString(
+ html,
+ )
+}
diff --git a/internal/server/browser_handler.go b/internal/server/browser_handler.go
new file mode 100644
index 0000000..55f8dd1
--- /dev/null
+++ b/internal/server/browser_handler.go
@@ -0,0 +1,52 @@
+package server
+
+import (
+ "net/http"
+ "strings"
+)
+
+func (s *Server) handleBrowser(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+
+ currentPath :=
+ strings.TrimPrefix(
+ r.URL.Path,
+ "/v/browser",
+ )
+
+ if currentPath == "" || currentPath == "/" {
+ currentPath = "/"
+ }
+
+ if !strings.HasPrefix(currentPath, "/") {
+ currentPath = "/" + currentPath
+ }
+
+ entries, err :=
+ s.store.ListBrowserEntries(
+ currentPath,
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), 500)
+ return
+ }
+
+ s.render(
+ w,
+ "browser.gohtml",
+ map[string]any{
+ "NavItems": resolveNavItems(
+ s.getSystemNavItems(),
+ NavContext{
+ Path: currentPath,
+ },
+ ),
+ "Path": currentPath,
+ "Breadcrumbs": buildBreadcrumbs(currentPath),
+ "Entries": entries,
+ },
+ )
+}
diff --git a/internal/server/compile_handler.go b/internal/server/compile_handler.go
new file mode 100644
index 0000000..2f85a22
--- /dev/null
+++ b/internal/server/compile_handler.go
@@ -0,0 +1,80 @@
+package server
+
+import (
+ "net/http"
+ "strings"
+
+ "pageswiki/internal/compiler"
+)
+
+func (s *Server) compileMarkdownFromPath(
+ path string,
+) (string, error) {
+
+ objectUUID, err :=
+ s.store.ResolvePath(
+ path,
+ )
+
+ if err != nil {
+ return "", err
+ }
+
+ latest, err :=
+ s.store.GetLatestRevision(
+ objectUUID,
+ )
+
+ if err != nil {
+ return "", err
+ }
+
+ html :=
+ s.expandMacros(
+ latest.Body,
+ path,
+ )
+
+ return compiler.HTMLToMarkdown(
+ html,
+ )
+}
+
+func (s *Server) handleCompileMarkdown(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+
+ path :=
+ strings.TrimPrefix(
+ r.URL.Path,
+ "/:/compile/markdown",
+ )
+
+ if path == "" {
+ path = "/"
+ }
+
+ if !strings.HasPrefix(path, "/") {
+ path = "/" + path
+ }
+
+ out, err :=
+ s.compileMarkdownFromPath(
+ path,
+ )
+
+ if err != nil {
+ http.NotFound(w, r)
+ return
+ }
+
+ w.Header().Set(
+ "Content-Type",
+ "text/markdown; charset=utf-8",
+ )
+
+ _, _ = w.Write(
+ []byte(out),
+ )
+}
diff --git a/internal/server/config_handler.go b/internal/server/config_handler.go
index 058a192..af21ca8 100644
--- a/internal/server/config_handler.go
+++ b/internal/server/config_handler.go
@@ -166,10 +166,9 @@ func (s *Server) handleConfig(
s.getTheme()
if v := strings.TrimSpace(r.FormValue("theme")); v != "" {
- switch v {
- case "dark", "light", "monokai", "solarized-dark", "solarized-light", "terminal-green", "amber-crt", "lain-dark", "nanoha-dark":
+ if isAllowedTheme(v) {
theme = v
- default:
+ } else {
http.Error(w, "invalid theme", http.StatusBadRequest)
return
}
@@ -239,6 +238,51 @@ func (s *Server) handleConfig(
return
}
+ case "editor":
+
+ keymap :=
+ strings.TrimSpace(
+ r.FormValue("editor_keymap"),
+ )
+
+ if keymap != "vim" {
+ keymap = "default"
+ }
+
+ err = s.store.SetConfig(
+ "editor_keymap",
+ keymap,
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ err = s.store.SetConfig(
+ "editor_syntax_highlight",
+ boolFormValue(
+ r.FormValue("editor_syntax_highlight"),
+ ),
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ err = s.store.SetConfig(
+ "editor_autocomplete",
+ boolFormValue(
+ r.FormValue("editor_autocomplete"),
+ ),
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
case "zombie-purge":
_, err = s.store.PurgeZombieObjects(
@@ -338,6 +382,10 @@ func (s *Server) handleConfig(
"Locale": s.getLocale(),
"Timezone": s.getTimezoneName(),
"Theme": s.getTheme(),
+ "ThemeOptions": themeOptions(),
+ "EditorKeymap": s.getEditorKeymap(),
+ "EditorSyntax": s.getEditorSyntaxHighlight(),
+ "EditorAutocomplete": s.getEditorAutocomplete(),
"ZombieGraceHours": zombieGraceHours,
"Objects": recent,
"ZombieObjects": zombies,
@@ -346,3 +394,16 @@ func (s *Server) handleConfig(
},
)
}
+
+func boolFormValue(
+ v string,
+) string {
+
+ if v == "on" ||
+ v == "true" ||
+ v == "1" {
+ return "true"
+ }
+
+ return "false"
+}
diff --git a/internal/server/diagram_handler.go b/internal/server/diagram_handler.go
new file mode 100644
index 0000000..d440ca0
--- /dev/null
+++ b/internal/server/diagram_handler.go
@@ -0,0 +1,402 @@
+package server
+
+import (
+ "bytes"
+ "crypto/sha256"
+ "encoding/hex"
+ "io"
+ "net/http"
+ "os"
+ "path/filepath"
+ "regexp"
+ "strings"
+ "time"
+)
+
+var diagramSourceCache = map[string]diagramCacheEntry{}
+
+type diagramCacheEntry struct {
+ Type string
+ Source string
+ At time.Time
+}
+
+func diagramHash(
+ diagramType string,
+ source string,
+ format string,
+) string {
+
+ sum :=
+ sha256.Sum256(
+ []byte(
+ diagramType + "\x00" + format + "\x00" + source,
+ ),
+ )
+
+ return hex.EncodeToString(
+ sum[:],
+ )
+}
+
+func allowedDiagramType(
+ t string,
+) bool {
+
+ switch t {
+ case "mermaid", "plantuml", "graphviz", "dot", "d2":
+ return true
+ default:
+ return false
+ }
+}
+
+func normalizeDiagramType(
+ t string,
+) string {
+
+ switch t {
+ case "dot":
+ return "graphviz"
+ default:
+ return t
+ }
+}
+
+func krokiURL() string {
+
+ v :=
+ strings.TrimSpace(
+ os.Getenv("KROKI_URL"),
+ )
+
+ if v == "" {
+ return "http://kroki:8000"
+ }
+
+ return strings.TrimRight(
+ v,
+ "/",
+ )
+}
+
+func (s *Server) renderDiagramsInHTML(
+ html string,
+) string {
+
+ re :=
+ regexp.MustCompile(`(?s)
(.+?)
`)
+
+ return re.ReplaceAllStringFunc(
+ html,
+ func(block string) string {
+
+ m :=
+ re.FindStringSubmatch(
+ block,
+ )
+
+ if len(m) != 3 {
+ return block
+ }
+
+ diagramType :=
+ normalizeDiagramType(
+ m[1],
+ )
+
+ source :=
+ htmlUnescapeString(
+ m[2],
+ )
+
+ hash :=
+ diagramHash(
+ diagramType,
+ source,
+ "svg",
+ )
+
+ diagramSourceCache[hash] =
+ diagramCacheEntry{
+ Type: diagramType,
+ Source: source,
+ At: time.Now(),
+ }
+
+ return `` +
+ `
` +
+ ``
+ },
+ )
+}
+
+func htmlUnescapeString(
+ s string,
+) string {
+
+ r :=
+ strings.NewReplacer(
+ "<", "<",
+ ">", ">",
+ "&", "&",
+ """, `"`,
+ "'", "'",
+ )
+
+ return r.Replace(
+ s,
+ )
+}
+
+func (s *Server) handleCompileDiagram(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+
+ if r.Method == http.MethodPost {
+ s.handleCompileDiagramPost(
+ w,
+ r,
+ )
+ return
+ }
+
+ rest :=
+ strings.TrimPrefix(
+ r.URL.Path,
+ "/:/compile/diagram/",
+ )
+
+ parts :=
+ strings.Split(
+ rest,
+ "/",
+ )
+
+ if len(parts) != 2 {
+ http.NotFound(w, r)
+ return
+ }
+
+ diagramType :=
+ normalizeDiagramType(
+ parts[0],
+ )
+
+ if !allowedDiagramType(diagramType) {
+ http.NotFound(w, r)
+ return
+ }
+
+ hashFile :=
+ parts[1]
+
+ if !strings.HasSuffix(hashFile, ".svg") {
+ http.NotFound(w, r)
+ return
+ }
+
+ hash :=
+ strings.TrimSuffix(
+ hashFile,
+ ".svg",
+ )
+
+ if !regexp.MustCompile(`^[a-f0-9]{64}$`).MatchString(hash) {
+ http.NotFound(w, r)
+ return
+ }
+
+ cachePath :=
+ filepath.Join(
+ "/data/cache/diagram",
+ diagramType,
+ hash+".svg",
+ )
+
+ if b, err := os.ReadFile(cachePath); err == nil {
+
+ w.Header().Set(
+ "Content-Type",
+ "image/svg+xml; charset=utf-8",
+ )
+
+ _, _ = w.Write(b)
+ return
+ }
+
+ entry, ok :=
+ diagramSourceCache[hash]
+
+ if !ok || entry.Type != diagramType {
+ http.NotFound(w, r)
+ return
+ }
+
+ s.renderDiagramSVG(
+ w,
+ diagramType,
+ entry.Source,
+ cachePath,
+ )
+}
+
+func (s *Server) handleCompileDiagramPost(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+
+ rest :=
+ strings.TrimPrefix(
+ r.URL.Path,
+ "/:/compile/diagram/",
+ )
+
+ diagramType :=
+ normalizeDiagramType(
+ strings.Trim(rest, "/"),
+ )
+
+ if !allowedDiagramType(diagramType) {
+ http.NotFound(w, r)
+ return
+ }
+
+ defer r.Body.Close()
+
+ sourceBytes, err :=
+ io.ReadAll(
+ io.LimitReader(
+ r.Body,
+ 1024*1024,
+ ),
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), 500)
+ return
+ }
+
+ source :=
+ string(sourceBytes)
+
+ hash :=
+ diagramHash(
+ diagramType,
+ source,
+ "svg",
+ )
+
+ cachePath :=
+ filepath.Join(
+ "/data/cache/diagram",
+ diagramType,
+ hash+".svg",
+ )
+
+ if b, err := os.ReadFile(cachePath); err == nil {
+
+ w.Header().Set(
+ "Content-Type",
+ "image/svg+xml; charset=utf-8",
+ )
+
+ _, _ = w.Write(b)
+ return
+ }
+
+ s.renderDiagramSVG(
+ w,
+ diagramType,
+ source,
+ cachePath,
+ )
+}
+
+func (s *Server) renderDiagramSVG(
+ w http.ResponseWriter,
+ diagramType string,
+ source string,
+ cachePath string,
+) {
+
+ req, err :=
+ http.NewRequest(
+ http.MethodPost,
+ krokiURL()+"/"+diagramType+"/svg",
+ bytes.NewBufferString(source),
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), 500)
+ return
+ }
+
+ req.Header.Set(
+ "Content-Type",
+ "text/plain; charset=utf-8",
+ )
+
+ client :=
+ http.Client{
+ Timeout: 15 * time.Second,
+ }
+
+ resp, err :=
+ client.Do(
+ req,
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), 502)
+ return
+ }
+
+ defer resp.Body.Close()
+
+ if resp.StatusCode < 200 ||
+ resp.StatusCode >= 300 {
+
+ http.Error(w, "diagram renderer failed", 502)
+ return
+ }
+
+ b, err :=
+ io.ReadAll(
+ resp.Body,
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), 500)
+ return
+ }
+
+ _ =
+ os.MkdirAll(
+ filepath.Dir(cachePath),
+ 0755,
+ )
+
+ _ =
+ os.WriteFile(
+ cachePath,
+ b,
+ 0644,
+ )
+
+ w.Header().Set(
+ "Content-Type",
+ "image/svg+xml; charset=utf-8",
+ )
+
+ w.Header().Set(
+ "Content-Security-Policy",
+ "default-src 'none'; style-src 'unsafe-inline'; img-src data:",
+ )
+
+ _, _ =
+ w.Write(
+ b,
+ )
+}
diff --git a/internal/server/editor_config.go b/internal/server/editor_config.go
new file mode 100644
index 0000000..ecb311c
--- /dev/null
+++ b/internal/server/editor_config.go
@@ -0,0 +1,48 @@
+package server
+
+func (s *Server) getEditorKeymap() string {
+
+ v, err :=
+ s.store.GetConfig(
+ "editor_keymap",
+ )
+
+ if err != nil || v == "" {
+ return "default"
+ }
+
+ switch v {
+ case "default", "vim":
+ return v
+ default:
+ return "default"
+ }
+}
+
+func (s *Server) getEditorSyntaxHighlight() bool {
+
+ v, err :=
+ s.store.GetConfig(
+ "editor_syntax_highlight",
+ )
+
+ if err != nil || v == "" {
+ return true
+ }
+
+ return v != "false"
+}
+
+func (s *Server) getEditorAutocomplete() bool {
+
+ v, err :=
+ s.store.GetConfig(
+ "editor_autocomplete",
+ )
+
+ if err != nil || v == "" {
+ return true
+ }
+
+ return v != "false"
+}
diff --git a/internal/server/editor_route.go b/internal/server/editor_route.go
new file mode 100644
index 0000000..09a9986
--- /dev/null
+++ b/internal/server/editor_route.go
@@ -0,0 +1,49 @@
+package server
+
+import (
+ "net/http"
+ "strings"
+)
+
+func (s *Server) handleEditorRoute(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+
+ if strings.HasPrefix(r.URL.Path, "/e/-/") {
+ s.handleSemanticEditor(w, r)
+ return
+ }
+
+ // Known future editor adapters.
+ for _, prefix := range []string{
+ "/e/plain/",
+ "/e/hex/",
+ "/e/pdf/",
+ "/e/office/",
+ } {
+ if strings.HasPrefix(r.URL.Path, prefix) {
+ http.NotFound(w, r)
+ return
+ }
+ }
+
+ // Backward compatibility:
+ // /e/foo/bar -> /e/-/foo/bar
+ oldPath :=
+ strings.TrimPrefix(
+ r.URL.Path,
+ "/e",
+ )
+
+ if oldPath == "" {
+ oldPath = "/"
+ }
+
+ http.Redirect(
+ w,
+ r,
+ "/e/-"+oldPath,
+ http.StatusFound,
+ )
+}
diff --git a/internal/server/handlers.go b/internal/server/handlers.go
index cee161b..874fd06 100644
--- a/internal/server/handlers.go
+++ b/internal/server/handlers.go
@@ -11,6 +11,11 @@ func (s *Server) handleHome(
r *http.Request,
) {
+ if r.URL.Path != "/" {
+ s.handleSemanticRoute(w, r)
+ return
+ }
+
homePath, err :=
s.store.GetConfig(
"home_path",
diff --git a/internal/server/markdown_view_handler.go b/internal/server/markdown_view_handler.go
new file mode 100644
index 0000000..cd53e6a
--- /dev/null
+++ b/internal/server/markdown_view_handler.go
@@ -0,0 +1,109 @@
+package server
+
+import (
+ "net/http"
+ "strings"
+)
+
+type MarkdownLine struct {
+ Number int
+ Text string
+}
+
+func splitMarkdownLines(
+ body string,
+) []MarkdownLine {
+
+ body =
+ strings.ReplaceAll(
+ body,
+ "\r\n",
+ "\n",
+ )
+
+ lines :=
+ strings.Split(
+ body,
+ "\n",
+ )
+
+ out :=
+ make(
+ []MarkdownLine,
+ 0,
+ len(lines),
+ )
+
+ for i, line := range lines {
+
+ out = append(
+ out,
+ MarkdownLine{
+ Number: i + 1,
+ Text: line,
+ },
+ )
+ }
+
+ return out
+}
+
+func (s *Server) handleMarkdownView(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+
+ path :=
+ strings.TrimPrefix(
+ r.URL.Path,
+ "/v/markdown",
+ )
+
+ if path == "" {
+ path = "/"
+ }
+
+ if !strings.HasPrefix(path, "/") {
+ path = "/" + path
+ }
+
+ objectUUID, err :=
+ s.store.ResolvePath(
+ path,
+ )
+
+ if err != nil {
+ http.NotFound(w, r)
+ return
+ }
+
+ markdown, err :=
+ s.compileMarkdownFromPath(
+ path,
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), 500)
+ return
+ }
+
+ s.render(
+ w,
+ "markdown_view.gohtml",
+ map[string]any{
+ "NavItems": resolveNavItems(
+ s.getSystemNavItems(),
+ NavContext{
+ Path: path,
+ ObjectUUID: objectUUID,
+ ObjectURI: "uuid:" + objectUUID,
+ },
+ ),
+ "Path": path,
+ "ObjectUUID": objectUUID,
+ "ObjectURI": "uuid:" + objectUUID,
+ "Lines": splitMarkdownLines(markdown),
+ "MarkdownRaw": markdown,
+ },
+ )
+}
diff --git a/internal/server/plain_view_handler.go b/internal/server/plain_view_handler.go
new file mode 100644
index 0000000..db6ee57
--- /dev/null
+++ b/internal/server/plain_view_handler.go
@@ -0,0 +1,55 @@
+package server
+
+import (
+ "net/http"
+ "strings"
+)
+
+func (s *Server) handlePlainView(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+
+ path :=
+ strings.TrimPrefix(
+ r.URL.Path,
+ "/v/plain",
+ )
+
+ if path == "" {
+ path = "/"
+ }
+
+ if !strings.HasPrefix(path, "/") {
+ path = "/" + path
+ }
+
+ objectUUID, err :=
+ s.store.ResolvePath(
+ path,
+ )
+
+ if err != nil {
+ http.NotFound(w, r)
+ return
+ }
+
+ latest, err :=
+ s.store.GetLatestRevision(
+ objectUUID,
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), 500)
+ return
+ }
+
+ w.Header().Set(
+ "Content-Type",
+ "text/plain; charset=utf-8",
+ )
+
+ _, _ = w.Write(
+ []byte(latest.Body),
+ )
+}
diff --git a/internal/server/preview_handler.go b/internal/server/preview_handler.go
new file mode 100644
index 0000000..ed3c8b1
--- /dev/null
+++ b/internal/server/preview_handler.go
@@ -0,0 +1,85 @@
+package server
+
+import (
+ "html/template"
+ "net/http"
+ "strings"
+)
+
+func (s *Server) handlePreview(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+
+ path :=
+ strings.TrimPrefix(
+ r.URL.Path,
+ "/v/preview",
+ )
+
+ if path == "" {
+ path = "/"
+ }
+
+ if !strings.HasPrefix(path, "/") {
+ path = "/" + path
+ }
+
+ objectUUID, err :=
+ s.store.ResolvePath(
+ path,
+ )
+
+ if err == nil {
+
+ latest, err :=
+ s.store.GetLatestRevision(
+ objectUUID,
+ )
+
+ if err == nil &&
+ strings.TrimSpace(latest.Body) != "" {
+
+ rendered :=
+ s.renderDiagramsInHTML(
+ s.expandMacros(
+ latest.Body,
+ path,
+ ),
+ )
+
+ s.render(
+ w,
+ "preview.gohtml",
+ map[string]any{
+ "Path": path,
+ "RenderedHTML": template.HTML(
+ rendered,
+ ),
+ },
+ )
+
+ return
+ }
+ }
+
+ entries, err :=
+ s.store.ListBrowserEntries(
+ path,
+ )
+
+ if err != nil {
+ http.Error(w, err.Error(), 500)
+ return
+ }
+
+ s.render(
+ w,
+ "preview.gohtml",
+ map[string]any{
+ "Path": path,
+ "IsListing": true,
+ "Entries": entries,
+ },
+ )
+}
diff --git a/internal/server/render.go b/internal/server/render.go
index 09623ca..26a52e0 100644
--- a/internal/server/render.go
+++ b/internal/server/render.go
@@ -8,11 +8,13 @@ func mergeTemplateData(
data any,
wikiName string,
theme string,
+ sThemeCSS string,
) map[string]any {
out := map[string]any{
"WikiName": wikiName,
"Theme": theme,
+ "ThemeCSS": sThemeCSS,
}
if data == nil {
@@ -46,6 +48,7 @@ func (s *Server) render(
data,
s.getWikiName(),
s.getTheme(),
+ s.getThemeCSS(),
),
)
diff --git a/internal/server/routes/ui.go b/internal/server/routes/ui.go
index d8c2112..99e9223 100644
--- a/internal/server/routes/ui.go
+++ b/internal/server/routes/ui.go
@@ -3,15 +3,31 @@ package routes
import "net/http"
type UIHandlers struct {
- Home http.HandlerFunc
- NewPage http.HandlerFunc
- SemanticEditor http.HandlerFunc
- SemanticPage http.HandlerFunc
- RawView http.HandlerFunc
- LinkManager http.HandlerFunc
- Health http.HandlerFunc
- Tree http.HandlerFunc
- Config http.HandlerFunc
+ Home http.HandlerFunc
+ NewPage http.HandlerFunc
+ SemanticEditor http.HandlerFunc
+ SemanticPage http.HandlerFunc
+ RawView http.HandlerFunc
+ LinkManager http.HandlerFunc
+ Health http.HandlerFunc
+ Tree http.HandlerFunc
+ Browser http.HandlerFunc
+ Preview http.HandlerFunc
+ PlainView http.HandlerFunc
+ MarkdownView http.HandlerFunc
+ CompileMarkdown http.HandlerFunc
+ CompileDiagram http.HandlerFunc
+ Config http.HandlerFunc
+}
+
+func handleIfNotNil(
+ mux *http.ServeMux,
+ pattern string,
+ h http.HandlerFunc,
+) {
+ if h != nil {
+ mux.HandleFunc(pattern, h)
+ }
}
func RegisterUIRoutes(
@@ -19,103 +35,32 @@ func RegisterUIRoutes(
h UIHandlers,
) {
- mux.HandleFunc(
- "/healthz",
- h.Health,
- )
+ handleIfNotNil(mux, "/", h.Home)
- mux.HandleFunc(
- "/v/tree",
- h.Tree,
- )
+ handleIfNotNil(mux, "/:/new", h.NewPage)
+ handleIfNotNil(mux, "/new", func(w http.ResponseWriter, r *http.Request) {
+ http.Redirect(w, r, "/:/new", http.StatusFound)
+ })
+ handleIfNotNil(mux, "/e/", h.SemanticEditor)
+ handleIfNotNil(mux, "/r/", h.RawView)
+ handleIfNotNil(mux, "/l/", h.LinkManager)
+ handleIfNotNil(mux, "/health", h.Health)
- mux.HandleFunc(
- "/-/sys/config",
- h.Config,
- )
+ handleIfNotNil(mux, "/v/tree", h.Tree)
+ handleIfNotNil(mux, "/v/browser", h.Browser)
+ handleIfNotNil(mux, "/v/browser/", h.Browser)
+ handleIfNotNil(mux, "/v/preview", h.Preview)
+ handleIfNotNil(mux, "/v/preview/", h.Preview)
+ handleIfNotNil(mux, "/v/plain", h.PlainView)
+ handleIfNotNil(mux, "/v/plain/", h.PlainView)
- mux.HandleFunc(
- "/new",
- h.NewPage,
- )
+ handleIfNotNil(mux, "/v/markdown", h.MarkdownView)
+ handleIfNotNil(mux, "/v/markdown/", h.MarkdownView)
- mux.HandleFunc(
- "/e",
- h.SemanticEditor,
- )
+ handleIfNotNil(mux, "/:/compile/markdown", h.CompileMarkdown)
+ handleIfNotNil(mux, "/:/compile/markdown/", h.CompileMarkdown)
- mux.HandleFunc(
- "/e/",
- h.SemanticEditor,
- )
+ handleIfNotNil(mux, "/:/compile/diagram/", h.CompileDiagram)
- mux.HandleFunc(
- "/raw",
- h.RawView,
- )
-
- mux.HandleFunc(
- "/raw/",
- h.RawView,
- )
- mux.HandleFunc(
- "/l/",
- h.LinkManager,
- )
-
- mux.HandleFunc(
- "/",
- func(
- w http.ResponseWriter,
- r *http.Request,
- ) {
-
- if r.URL.Path == "/" {
-
- h.Home(
- w,
- r,
- )
-
- return
- }
-
- switch r.URL.Path {
-
- case "/v/tree":
-
- h.Tree(
- w,
- r,
- )
-
- return
-
- case "/new":
-
- h.NewPage(
- w,
- r,
- )
-
- return
- }
-
- if r.URL.Path == "/e" ||
- r.URL.Path == "/raw" {
-
- http.NotFound(
- w,
- r,
- )
-
- return
- }
-
- h.SemanticPage(
- w,
- r,
- )
- },
- )
+ handleIfNotNil(mux, "/-/sys/config", h.Config)
}
diff --git a/internal/server/semantic_handlers.go b/internal/server/semantic_handlers.go
index 5d3c610..7461467 100644
--- a/internal/server/semantic_handlers.go
+++ b/internal/server/semantic_handlers.go
@@ -2,7 +2,6 @@ package server
import (
"html/template"
- "log"
"net/http"
"strings"
)
@@ -41,12 +40,13 @@ func (s *Server) handleSemanticRoute(
}
bs := buildBreadcrumbs(path)
- log.Printf("breadcrumb debug path=%s bs=%#v", path, bs)
rendered :=
- s.expandMacros(
- latest.Body,
- path,
+ s.renderDiagramsInHTML(
+ s.expandMacros(
+ latest.Body,
+ path,
+ ),
)
s.render(
@@ -55,7 +55,7 @@ func (s *Server) handleSemanticRoute(
map[string]any{
"Title": path,
"Path": path,
- "Breadcrumbs": buildBreadcrumbs(path),
+ "Breadcrumbs": bs,
"ObjectUUID": objectUUID,
"NavItems": resolveNavItems(
s.getSystemNavItems(),
@@ -79,7 +79,7 @@ func (s *Server) handleSemanticEditor(
path := strings.TrimPrefix(
r.URL.Path,
- "/e",
+ "/e/-",
)
if path == "" {
@@ -128,12 +128,26 @@ func (s *Server) handleSemanticEditor(
if editType == "markdown" {
- body =
- htmlToMarkdown(
- body,
+ compiled, err :=
+ s.compileMarkdownFromPath(
+ path,
)
+
+ if err != nil {
+ http.Error(
+ w,
+ err.Error(),
+ 500,
+ )
+ return
+ }
+
+ body = compiled
}
+ renderedBody :=
+ body
+
s.render(
w,
"editor.gohtml",
@@ -144,56 +158,14 @@ func (s *Server) handleSemanticEditor(
"Body": body,
"RenderedHTML": template.HTML(
s.expandMacros(
- body,
+ renderedBody,
path,
),
),
- "EditType": editType,
+ "EditType": editType,
+ "EditorKeymap": s.getEditorKeymap(),
+ "EditorSyntax": s.getEditorSyntaxHighlight(),
+ "EditorAutocomplete": s.getEditorAutocomplete(),
},
)
}
-
-func htmlToMarkdown(
- in string,
-) string {
-
- out := in
-
- out = strings.ReplaceAll(
- out,
- "",
- "# ",
- )
-
- out = strings.ReplaceAll(
- out,
- "
",
- "",
- )
-
- out = strings.ReplaceAll(
- out,
- "",
- "",
- )
-
- out = strings.ReplaceAll(
- out,
- "
",
- "",
- )
-
- out = strings.ReplaceAll(
- out,
- "",
- "- ",
- )
-
- out = strings.ReplaceAll(
- out,
- "",
- "",
- )
-
- return out
-}
diff --git a/internal/server/server.go b/internal/server/server.go
index e28f585..d67206f 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -91,6 +91,18 @@ func (s *Server) registerStaticRoutes() {
staticFS,
),
)
+
+ themeFS := http.FileServer(
+ http.Dir("/data/themes"),
+ )
+
+ s.mux.Handle(
+ "/-/theme/",
+ http.StripPrefix(
+ "/-/theme/",
+ themeFS,
+ ),
+ )
}
func (s *Server) mustLoadTemplates() {
@@ -164,15 +176,21 @@ func (s *Server) registerRoutes() {
routespkg.RegisterUIRoutes(
s.mux,
routespkg.UIHandlers{
- Home: s.handleHome,
- NewPage: s.handleNewPage,
- SemanticEditor: s.handleSemanticEditor,
- SemanticPage: s.handleSemanticRoute,
- RawView: s.handleRawView,
- LinkManager: s.handleLinkManager,
- Health: s.handleHealth,
- Tree: s.handleTree,
- Config: s.handleConfig,
+ Home: s.handleHome,
+ NewPage: s.handleNewPage,
+ SemanticEditor: s.handleEditorRoute,
+ SemanticPage: s.handleSemanticRoute,
+ RawView: s.handleRawView,
+ LinkManager: s.handleLinkManager,
+ Health: s.handleHealth,
+ Tree: s.handleTree,
+ Browser: s.handleBrowser,
+ Preview: s.handlePreview,
+ PlainView: s.handlePlainView,
+ MarkdownView: s.handleMarkdownView,
+ CompileMarkdown: s.handleCompileMarkdown,
+ CompileDiagram: s.handleCompileDiagram,
+ Config: s.handleConfig,
},
)
diff --git a/internal/server/theme.go b/internal/server/theme.go
index 5818a59..72de511 100644
--- a/internal/server/theme.go
+++ b/internal/server/theme.go
@@ -1,20 +1,108 @@
package server
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "strings"
+)
+
+type ThemeOption struct {
+ ID string `json:"id"`
+ Label string `json:"label"`
+ CSS string `json:"css"`
+}
+
+func builtinThemeOptions() []ThemeOption {
+ return []ThemeOption{
+ {ID: "dark", Label: "Dark", CSS: "/static/css/theme/dark.css"},
+ {ID: "light", Label: "Light", CSS: "/static/css/theme/light.css"},
+ {ID: "monokai", Label: "Monokai", CSS: "/static/css/theme/monokai.css"},
+ {ID: "solarized-dark", Label: "Solarized Dark", CSS: "/static/css/theme/solarized-dark.css"},
+ {ID: "solarized-light", Label: "Solarized Light", CSS: "/static/css/theme/solarized-light.css"},
+ {ID: "terminal-green", Label: "Terminal Green", CSS: "/static/css/theme/terminal-green.css"},
+ {ID: "amber-crt", Label: "Amber CRT", CSS: "/static/css/theme/amber-crt.css"},
+ {ID: "lain-dark", Label: "Lain Dark", CSS: "/static/css/theme/lain-dark.css"},
+ {ID: "nanoha-dark", Label: "Nanoha Dark", CSS: "/static/css/theme/nanoha-dark.css"},
+ }
+}
+
+func externalThemeOptions() []ThemeOption {
+ path := "/data/themes/themes.json"
+
+ b, err := os.ReadFile(path)
+ if err != nil {
+ return nil
+ }
+
+ var items []ThemeOption
+ if err := json.Unmarshal(b, &items); err != nil {
+ return nil
+ }
+
+ var out []ThemeOption
+
+ for _, item := range items {
+ item.ID = strings.TrimSpace(item.ID)
+ item.Label = strings.TrimSpace(item.Label)
+ item.CSS = strings.TrimSpace(item.CSS)
+
+ if item.ID == "" || item.Label == "" || item.CSS == "" {
+ continue
+ }
+
+ if strings.Contains(item.ID, "/") || strings.Contains(item.ID, "..") {
+ continue
+ }
+
+ if !strings.HasPrefix(item.CSS, "/") {
+ item.CSS = "/-/theme/" + filepath.Base(item.CSS)
+ }
+
+ out = append(out, item)
+ }
+
+ return out
+}
+
+func themeOptions() []ThemeOption {
+ items := builtinThemeOptions()
+ items = append(items, externalThemeOptions()...)
+ return items
+}
+
+func findTheme(id string) (ThemeOption, bool) {
+ for _, opt := range themeOptions() {
+ if opt.ID == id {
+ return opt, true
+ }
+ }
+ return ThemeOption{}, false
+}
+
+func isAllowedTheme(theme string) bool {
+ _, ok := findTheme(theme)
+ return ok
+}
+
func (s *Server) getTheme() string {
-
- theme, err :=
- s.store.GetConfig(
- "theme",
- )
-
+ theme, err := s.store.GetConfig("theme")
if err != nil || theme == "" {
return "dark"
}
- switch theme {
- case "dark", "light", "monokai", "solarized-dark", "solarized-light", "terminal-green", "amber-crt", "lain-dark", "nanoha-dark":
- return theme
- default:
+ if !isAllowedTheme(theme) {
return "dark"
}
+
+ return theme
+}
+
+func (s *Server) getThemeCSS() string {
+ opt, ok := findTheme(s.getTheme())
+ if !ok {
+ return "/static/css/theme/dark.css"
+ }
+
+ return opt.CSS
}
diff --git a/internal/store/browser.go b/internal/store/browser.go
new file mode 100644
index 0000000..8a43755
--- /dev/null
+++ b/internal/store/browser.go
@@ -0,0 +1,191 @@
+package store
+
+import (
+ "path"
+ "sort"
+ "strings"
+)
+
+type BrowserEntry struct {
+ Name string
+ Path string
+ ObjectUUID string
+ IsDir bool
+ Size int
+ UpdatedAt int64
+ ChildCount int
+}
+
+func normalizeBrowserPath(p string) string {
+ p = strings.TrimSpace(p)
+
+ if p == "" {
+ return "/"
+ }
+
+ if !strings.HasPrefix(p, "/") {
+ p = "/" + p
+ }
+
+ if p != "/" {
+ p = strings.TrimRight(p, "/")
+ }
+
+ return p
+}
+
+func (s *Store) ListBrowserEntries(
+ parent string,
+) ([]BrowserEntry, error) {
+
+ parent = normalizeBrowserPath(parent)
+
+ rows, err := s.DB.Query(`
+ WITH latest AS (
+ SELECT
+ r.object_uuid,
+ r.body,
+ r.created_at,
+ ROW_NUMBER() OVER (
+ PARTITION BY r.object_uuid
+ ORDER BY r.created_at DESC
+ ) AS rn
+ FROM revisions r
+ )
+ SELECT
+ p.path,
+ p.object_uuid,
+ COALESCE(LENGTH(latest.body), 0),
+ COALESCE(latest.created_at, 0)
+ FROM paths p
+ LEFT JOIN latest
+ ON latest.object_uuid = p.object_uuid
+ AND latest.rn = 1
+ WHERE p.path = ?
+ OR p.path LIKE ?
+ ORDER BY p.path ASC
+ `,
+ parent,
+ func() string {
+ if parent == "/" {
+ return "/%"
+ }
+ return parent + "/%"
+ }(),
+ )
+
+ if err != nil {
+ return nil, err
+ }
+
+ defer rows.Close()
+
+ dirMap := map[string]*BrowserEntry{}
+ var files []BrowserEntry
+
+ prefix := parent
+ if prefix != "/" {
+ prefix += "/"
+ }
+
+ for rows.Next() {
+
+ var fullPath string
+ var objectUUID string
+ var size int
+ var updatedAt int64
+
+ err := rows.Scan(
+ &fullPath,
+ &objectUUID,
+ &size,
+ &updatedAt,
+ )
+
+ if err != nil {
+ return nil, err
+ }
+
+ if fullPath == parent {
+ continue
+ }
+
+ rel := ""
+
+ if parent == "/" {
+ rel = strings.TrimPrefix(fullPath, "/")
+ } else {
+ rel = strings.TrimPrefix(fullPath, prefix)
+ }
+
+ rel = strings.Trim(rel, "/")
+
+ if rel == "" {
+ continue
+ }
+
+ parts := strings.Split(rel, "/")
+
+ if len(parts) > 1 {
+
+ name := parts[0]
+ dirPath := path.Join(parent, name)
+
+ if !strings.HasPrefix(dirPath, "/") {
+ dirPath = "/" + dirPath
+ }
+
+ if dirPath == "." {
+ dirPath = "/"
+ }
+
+ ent, ok := dirMap[dirPath]
+
+ if !ok {
+ ent = &BrowserEntry{
+ Name: name,
+ Path: dirPath,
+ IsDir: true,
+ }
+ dirMap[dirPath] = ent
+ }
+
+ ent.ChildCount++
+
+ continue
+ }
+
+ files = append(
+ files,
+ BrowserEntry{
+ Name: parts[0],
+ Path: fullPath,
+ ObjectUUID: objectUUID,
+ IsDir: false,
+ Size: size,
+ UpdatedAt: updatedAt,
+ },
+ )
+ }
+
+ var out []BrowserEntry
+
+ for _, d := range dirMap {
+ out = append(out, *d)
+ }
+
+ out = append(out, files...)
+
+ sort.SliceStable(
+ out,
+ func(i, j int) bool {
+ if out[i].IsDir != out[j].IsDir {
+ return out[i].IsDir
+ }
+
+ return out[i].Name < out[j].Name
+ },
+ )
+
+ return out, nil
+}
diff --git a/internal/store/paths.go b/internal/store/paths.go
index dc5ddfb..3cbe45e 100644
--- a/internal/store/paths.go
+++ b/internal/store/paths.go
@@ -2,6 +2,7 @@ package store
import (
"database/sql"
+ "strings"
"time"
)
@@ -29,15 +30,17 @@ func (s *Store) ResolvePath(
path string,
) (string, error) {
- row := s.DB.QueryRow(`
- SELECT object_uuid
- FROM paths
- WHERE path = ?
- `, path)
+ path = normalizePath(path)
var objectUUID string
- err := row.Scan(&objectUUID)
+ err := s.DB.QueryRow(`
+ SELECT object_uuid
+ FROM paths
+ WHERE path = ?
+ LIMIT 1
+ `, path).Scan(&objectUUID)
+
if err != nil {
return "", err
}
@@ -45,6 +48,27 @@ func (s *Store) ResolvePath(
return objectUUID, nil
}
+func normalizePath(
+ path string,
+) string {
+
+ path = strings.TrimSpace(path)
+
+ if path == "" {
+ return "/"
+ }
+
+ if !strings.HasPrefix(path, "/") {
+ path = "/" + path
+ }
+
+ if path != "/" {
+ path = strings.TrimRight(path, "/")
+ }
+
+ return path
+}
+
func (s *Store) ListChildren(
prefix string,
) ([]string, error) {
diff --git a/static/css/theme/base.css b/static/css/theme/base.css
index 81d9c7b..16587e3 100644
--- a/static/css/theme/base.css
+++ b/static/css/theme/base.css
@@ -95,3 +95,70 @@ th {
.muted {
color: var(--muted);
}
+
+/* config hardening */
+body:has(.config-sidebar) main,
+body:has(.config-sidebar) .config-layout,
+body:has(.config-sidebar) .container {
+ display: grid;
+ grid-template-columns: 16rem minmax(0, 1fr);
+ gap: 1.5rem;
+ align-items: start;
+}
+
+body:has(.config-sidebar) .config-sidebar {
+ grid-column: 1;
+ position: sticky;
+ top: 4rem;
+}
+
+body:has(.config-sidebar) .config-panel,
+body:has(.config-sidebar) .config-section {
+ grid-column: 2;
+ min-width: 0;
+}
+
+body:has(.config-sidebar) .config-panel {
+ display: none;
+}
+
+body:has(.config-sidebar) .config-panel.active {
+ display: block;
+}
+
+/* disable previous experimental config hardening */
+body:has(.config-sidebar) main,
+body:has(.config-sidebar) .config-layout,
+body:has(.config-sidebar) .container {
+ display: initial;
+ grid-template-columns: initial;
+ gap: initial;
+ align-items: initial;
+}
+
+
+.diagram {
+ margin: 1rem 0;
+ padding: 0.75rem;
+ border: 1px solid var(--border-soft);
+ background: var(--panel);
+ overflow: auto;
+}
+
+.diagram img {
+ max-width: 100%;
+ height: auto;
+ display: block;
+}
+
+.diagram img {
+ background: #fff;
+ padding: 0.75rem;
+ border-radius: 0.35rem;
+}
+
+@media (prefers-color-scheme: dark) {
+ .diagram img {
+ filter: brightness(0.92) contrast(1.08);
+ }
+}
diff --git a/static/js/editor.js b/static/js/editor.js
index b3434c7..8f085c3 100644
--- a/static/js/editor.js
+++ b/static/js/editor.js
@@ -313,3 +313,289 @@ document.addEventListener(
)
},
)
+
+async function renderPagesWikiDiagramsInPreview(root) {
+
+ if (!root) {
+ return
+ }
+
+ const blocks =
+ root.querySelectorAll(
+ "pre code.language-mermaid, pre code.language-plantuml, pre code.language-graphviz, pre code.language-dot, pre code.language-d2"
+ )
+
+ for (const code of blocks) {
+
+ const pre =
+ code.closest("pre")
+
+ if (!pre) {
+ continue
+ }
+
+ let diagramType =
+ Array.from(code.classList)
+ .find(c => c.startsWith("language-"))
+ ?.replace("language-", "")
+
+ if (!diagramType) {
+ continue
+ }
+
+ if (diagramType === "dot") {
+ diagramType = "graphviz"
+ }
+
+ const source =
+ code.textContent || ""
+
+ const figure =
+ document.createElement("figure")
+
+ figure.className =
+ "diagram diagram-" + diagramType
+
+ figure.textContent =
+ "Rendering " + diagramType + "..."
+
+ pre.replaceWith(figure)
+
+ try {
+
+ const res =
+ await fetch(
+ "/:/compile/diagram/" + encodeURIComponent(diagramType),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "text/plain; charset=utf-8",
+ },
+ body: source,
+ },
+ )
+
+ if (!res.ok) {
+ figure.textContent =
+ "Diagram render failed: " + res.status
+ continue
+ }
+
+ const svg =
+ await res.text()
+
+ const blob =
+ new Blob(
+ [svg],
+ {
+ type: "image/svg+xml",
+ },
+ )
+
+ const url =
+ URL.createObjectURL(blob)
+
+ const img =
+ document.createElement("img")
+
+ img.src =
+ url
+
+ img.alt =
+ diagramType + " diagram"
+
+ img.onload =
+ () => {
+ URL.revokeObjectURL(url)
+ }
+
+ figure.textContent =
+ ""
+
+ figure.appendChild(img)
+
+ } catch (err) {
+
+ figure.textContent =
+ "Diagram render failed"
+ }
+ }
+}
+
+const PagesWikiOldRenderPreview =
+ window.PagesEditor &&
+ window.PagesEditor.renderPreview
+
+if (PagesWikiOldRenderPreview) {
+
+ window.PagesEditor.renderPreview =
+ async function() {
+
+ const ret =
+ PagesWikiOldRenderPreview.apply(
+ window.PagesEditor,
+ arguments,
+ )
+
+ await Promise.resolve(ret)
+
+ await renderPagesWikiDiagramsInPreview(
+ document.getElementById("preview"),
+ )
+
+ return ret
+ }
+}
+
+async function renderPagesWikiDiagramsInPreview(root) {
+
+ if (!root) {
+ return
+ }
+
+ const blocks =
+ root.querySelectorAll(
+ "pre code.language-mermaid, pre code.language-plantuml, pre code.language-graphviz, pre code.language-dot, pre code.language-d2"
+ )
+
+ for (const code of blocks) {
+
+ const pre =
+ code.closest("pre")
+
+ if (!pre) {
+ continue
+ }
+
+ let diagramType =
+ Array.from(code.classList)
+ .find(c => c.startsWith("language-"))
+ ?.replace("language-", "")
+
+ if (!diagramType) {
+ continue
+ }
+
+ if (diagramType === "dot") {
+ diagramType = "graphviz"
+ }
+
+ const source =
+ code.textContent || ""
+
+ const figure =
+ document.createElement("figure")
+
+ figure.className =
+ "diagram diagram-" + diagramType
+
+ figure.textContent =
+ "Rendering " + diagramType + "..."
+
+ pre.replaceWith(figure)
+
+ const res =
+ await fetch(
+ "/:/compile/diagram/" + encodeURIComponent(diagramType),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "text/plain; charset=utf-8",
+ },
+ body: source,
+ },
+ )
+
+ if (!res.ok) {
+ figure.textContent =
+ "Diagram render failed: " + res.status
+ continue
+ }
+
+ const svg =
+ await res.text()
+
+ const blob =
+ new Blob(
+ [svg],
+ {
+ type: "image/svg+xml",
+ },
+ )
+
+ const url =
+ URL.createObjectURL(blob)
+
+ const img =
+ document.createElement("img")
+
+ img.src =
+ url
+
+ img.alt =
+ diagramType + " diagram"
+
+ img.onload =
+ () => URL.revokeObjectURL(url)
+
+ figure.textContent =
+ ""
+
+ figure.appendChild(img)
+ }
+}
+
+function installPagesWikiDiagramPreviewHook() {
+
+ if (
+ !window.PagesEditor ||
+ !window.PagesEditor.renderPreview ||
+ window.PagesEditorDiagramPreviewHookInstalled
+ ) {
+ return
+ }
+
+ window.PagesEditorDiagramPreviewHookInstalled = true
+
+ const original =
+ window.PagesEditor.renderPreview
+
+ window.PagesEditor.renderPreview =
+ async function() {
+
+ const ret =
+ original.apply(
+ window.PagesEditor,
+ arguments,
+ )
+
+ await Promise.resolve(ret)
+
+ await renderPagesWikiDiagramsInPreview(
+ document.getElementById("preview"),
+ )
+
+ return ret
+ }
+}
+
+window.addEventListener(
+ "DOMContentLoaded",
+ () => {
+ installPagesWikiDiagramPreviewHook()
+
+ setTimeout(
+ () => {
+ installPagesWikiDiagramPreviewHook()
+
+ if (
+ window.PagesEditor &&
+ window.PagesEditor.renderPreview
+ ) {
+ window.PagesEditor.renderPreview()
+ }
+ },
+ 100,
+ )
+ },
+)
diff --git a/static/vendor/codemirror/editor.bundle.js b/static/vendor/codemirror/editor.bundle.js
new file mode 100644
index 0000000..53b0ed9
--- /dev/null
+++ b/static/vendor/codemirror/editor.bundle.js
@@ -0,0 +1,35585 @@
+(() => {
+ // node_modules/@marijn/find-cluster-break/src/index.js
+ var rangeFrom = [];
+ var rangeTo = [];
+ (() => {
+ 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);
+ for (let i = 0, n = 0; i < numbers.length; i++)
+ (i % 2 ? rangeTo : rangeFrom).push(n = n + numbers[i]);
+ })();
+ function isExtendingChar(code) {
+ if (code < 768) return false;
+ for (let from = 0, to = rangeFrom.length; ; ) {
+ let mid = from + to >> 1;
+ if (code < rangeFrom[mid]) to = mid;
+ else if (code >= rangeTo[mid]) from = mid + 1;
+ else return true;
+ if (from == to) return false;
+ }
+ }
+ function isRegionalIndicator(code) {
+ return code >= 127462 && code <= 127487;
+ }
+ var ZWJ = 8205;
+ function findClusterBreak(str, pos, forward = true, includeExtending = true) {
+ return (forward ? nextClusterBreak : prevClusterBreak)(str, pos, includeExtending);
+ }
+ function nextClusterBreak(str, pos, includeExtending) {
+ if (pos == str.length) return pos;
+ if (pos && surrogateLow(str.charCodeAt(pos)) && surrogateHigh(str.charCodeAt(pos - 1))) pos--;
+ let prev = codePointAt(str, pos);
+ pos += codePointSize(prev);
+ while (pos < str.length) {
+ let next = codePointAt(str, pos);
+ if (prev == ZWJ || next == ZWJ || includeExtending && isExtendingChar(next)) {
+ pos += codePointSize(next);
+ prev = next;
+ } else if (isRegionalIndicator(next)) {
+ let countBefore = 0, i = pos - 2;
+ while (i >= 0 && isRegionalIndicator(codePointAt(str, i))) {
+ countBefore++;
+ i -= 2;
+ }
+ if (countBefore % 2 == 0) break;
+ else pos += 2;
+ } else {
+ break;
+ }
+ }
+ return pos;
+ }
+ function prevClusterBreak(str, pos, includeExtending) {
+ while (pos > 0) {
+ let found = nextClusterBreak(str, pos - 2, includeExtending);
+ if (found < pos) return found;
+ pos--;
+ }
+ return 0;
+ }
+ function codePointAt(str, pos) {
+ let code0 = str.charCodeAt(pos);
+ if (!surrogateHigh(code0) || pos + 1 == str.length) return code0;
+ let code1 = str.charCodeAt(pos + 1);
+ if (!surrogateLow(code1)) return code0;
+ return (code0 - 55296 << 10) + (code1 - 56320) + 65536;
+ }
+ function surrogateLow(ch) {
+ return ch >= 56320 && ch < 57344;
+ }
+ function surrogateHigh(ch) {
+ return ch >= 55296 && ch < 56320;
+ }
+ function codePointSize(code) {
+ return code < 65536 ? 1 : 2;
+ }
+
+ // node_modules/@codemirror/state/dist/index.js
+ var Text2 = class _Text {
+ /**
+ Get the line description around the given position.
+ */
+ lineAt(pos) {
+ if (pos < 0 || pos > this.length)
+ throw new RangeError(`Invalid position ${pos} in document of length ${this.length}`);
+ return this.lineInner(pos, false, 1, 0);
+ }
+ /**
+ Get the description for the given (1-based) line number.
+ */
+ line(n) {
+ if (n < 1 || n > this.lines)
+ throw new RangeError(`Invalid line number ${n} in ${this.lines}-line document`);
+ return this.lineInner(n, true, 1, 0);
+ }
+ /**
+ Replace a range of the text with the given content.
+ */
+ replace(from, to, text) {
+ [from, to] = clip(this, from, to);
+ let parts = [];
+ this.decompose(
+ 0,
+ from,
+ parts,
+ 2
+ /* Open.To */
+ );
+ if (text.length)
+ text.decompose(
+ 0,
+ text.length,
+ parts,
+ 1 | 2
+ /* Open.To */
+ );
+ this.decompose(
+ to,
+ this.length,
+ parts,
+ 1
+ /* Open.From */
+ );
+ return TextNode.from(parts, this.length - (to - from) + text.length);
+ }
+ /**
+ Append another document to this one.
+ */
+ append(other) {
+ return this.replace(this.length, this.length, other);
+ }
+ /**
+ Retrieve the text between the given points.
+ */
+ slice(from, to = this.length) {
+ [from, to] = clip(this, from, to);
+ let parts = [];
+ this.decompose(from, to, parts, 0);
+ return TextNode.from(parts, to - from);
+ }
+ /**
+ Test whether this text is equal to another instance.
+ */
+ eq(other) {
+ if (other == this)
+ return true;
+ if (other.length != this.length || other.lines != this.lines)
+ return false;
+ let start = this.scanIdentical(other, 1), end = this.length - this.scanIdentical(other, -1);
+ let a = new RawTextCursor(this), b = new RawTextCursor(other);
+ for (let skip = start, pos = start; ; ) {
+ a.next(skip);
+ b.next(skip);
+ skip = 0;
+ if (a.lineBreak != b.lineBreak || a.done != b.done || a.value != b.value)
+ return false;
+ pos += a.value.length;
+ if (a.done || pos >= end)
+ return true;
+ }
+ }
+ /**
+ Iterate over the text. When `dir` is `-1`, iteration happens
+ from end to start. This will return lines and the breaks between
+ them as separate strings.
+ */
+ iter(dir = 1) {
+ return new RawTextCursor(this, dir);
+ }
+ /**
+ Iterate over a range of the text. When `from` > `to`, the
+ iterator will run in reverse.
+ */
+ iterRange(from, to = this.length) {
+ return new PartialTextCursor(this, from, to);
+ }
+ /**
+ Return a cursor that iterates over the given range of lines,
+ _without_ returning the line breaks between, and yielding empty
+ strings for empty lines.
+
+ When `from` and `to` are given, they should be 1-based line numbers.
+ */
+ iterLines(from, to) {
+ let inner;
+ if (from == null) {
+ inner = this.iter();
+ } else {
+ if (to == null)
+ to = this.lines + 1;
+ let start = this.line(from).from;
+ inner = this.iterRange(start, Math.max(start, to == this.lines + 1 ? this.length : to <= 1 ? 0 : this.line(to - 1).to));
+ }
+ return new LineCursor(inner);
+ }
+ /**
+ Return the document as a string, using newline characters to
+ separate lines.
+ */
+ toString() {
+ return this.sliceString(0);
+ }
+ /**
+ Convert the document to an array of lines (which can be
+ deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
+ */
+ toJSON() {
+ let lines = [];
+ this.flatten(lines);
+ return lines;
+ }
+ /**
+ @internal
+ */
+ constructor() {
+ }
+ /**
+ Create a `Text` instance for the given array of lines.
+ */
+ static of(text) {
+ if (text.length == 0)
+ throw new RangeError("A document must have at least one line");
+ if (text.length == 1 && !text[0])
+ return _Text.empty;
+ return text.length <= 32 ? new TextLeaf(text) : TextNode.from(TextLeaf.split(text, []));
+ }
+ };
+ var TextLeaf = class _TextLeaf extends Text2 {
+ constructor(text, length = textLength(text)) {
+ super();
+ this.text = text;
+ this.length = length;
+ }
+ get lines() {
+ return this.text.length;
+ }
+ get children() {
+ return null;
+ }
+ lineInner(target, isLine, line, offset) {
+ for (let i = 0; ; i++) {
+ let string2 = this.text[i], end = offset + string2.length;
+ if ((isLine ? line : end) >= target)
+ return new Line(offset, end, line, string2);
+ offset = end + 1;
+ line++;
+ }
+ }
+ decompose(from, to, target, open) {
+ let text = from <= 0 && to >= this.length ? this : new _TextLeaf(sliceText(this.text, from, to), Math.min(to, this.length) - Math.max(0, from));
+ if (open & 1) {
+ let prev = target.pop();
+ let joined = appendText(text.text, prev.text.slice(), 0, text.length);
+ if (joined.length <= 32) {
+ target.push(new _TextLeaf(joined, prev.length + text.length));
+ } else {
+ let mid = joined.length >> 1;
+ target.push(new _TextLeaf(joined.slice(0, mid)), new _TextLeaf(joined.slice(mid)));
+ }
+ } else {
+ target.push(text);
+ }
+ }
+ replace(from, to, text) {
+ if (!(text instanceof _TextLeaf))
+ return super.replace(from, to, text);
+ [from, to] = clip(this, from, to);
+ let lines = appendText(this.text, appendText(text.text, sliceText(this.text, 0, from)), to);
+ let newLen = this.length + text.length - (to - from);
+ if (lines.length <= 32)
+ return new _TextLeaf(lines, newLen);
+ return TextNode.from(_TextLeaf.split(lines, []), newLen);
+ }
+ sliceString(from, to = this.length, lineSep = "\n") {
+ [from, to] = clip(this, from, to);
+ let result = "";
+ for (let pos = 0, i = 0; pos <= to && i < this.text.length; i++) {
+ let line = this.text[i], end = pos + line.length;
+ if (pos > from && i)
+ result += lineSep;
+ if (from < end && to > pos)
+ result += line.slice(Math.max(0, from - pos), to - pos);
+ pos = end + 1;
+ }
+ return result;
+ }
+ flatten(target) {
+ for (let line of this.text)
+ target.push(line);
+ }
+ scanIdentical() {
+ return 0;
+ }
+ static split(text, target) {
+ let part = [], len = -1;
+ for (let line of text) {
+ part.push(line);
+ len += line.length + 1;
+ if (part.length == 32) {
+ target.push(new _TextLeaf(part, len));
+ part = [];
+ len = -1;
+ }
+ }
+ if (len > -1)
+ target.push(new _TextLeaf(part, len));
+ return target;
+ }
+ };
+ var TextNode = class _TextNode extends Text2 {
+ constructor(children, length) {
+ super();
+ this.children = children;
+ this.length = length;
+ this.lines = 0;
+ for (let child of children)
+ this.lines += child.lines;
+ }
+ lineInner(target, isLine, line, offset) {
+ for (let i = 0; ; i++) {
+ let child = this.children[i], end = offset + child.length, endLine = line + child.lines - 1;
+ if ((isLine ? endLine : end) >= target)
+ return child.lineInner(target, isLine, line, offset);
+ offset = end + 1;
+ line = endLine + 1;
+ }
+ }
+ decompose(from, to, target, open) {
+ for (let i = 0, pos = 0; pos <= to && i < this.children.length; i++) {
+ let child = this.children[i], end = pos + child.length;
+ if (from <= end && to >= pos) {
+ let childOpen = open & ((pos <= from ? 1 : 0) | (end >= to ? 2 : 0));
+ if (pos >= from && end <= to && !childOpen)
+ target.push(child);
+ else
+ child.decompose(from - pos, to - pos, target, childOpen);
+ }
+ pos = end + 1;
+ }
+ }
+ replace(from, to, text) {
+ [from, to] = clip(this, from, to);
+ if (text.lines < this.lines)
+ for (let i = 0, pos = 0; i < this.children.length; i++) {
+ let child = this.children[i], end = pos + child.length;
+ if (from >= pos && to <= end) {
+ let updated = child.replace(from - pos, to - pos, text);
+ let totalLines = this.lines - child.lines + updated.lines;
+ if (updated.lines < totalLines >> 5 - 1 && updated.lines > totalLines >> 5 + 1) {
+ let copy = this.children.slice();
+ copy[i] = updated;
+ return new _TextNode(copy, this.length - (to - from) + text.length);
+ }
+ return super.replace(pos, end, updated);
+ }
+ pos = end + 1;
+ }
+ return super.replace(from, to, text);
+ }
+ sliceString(from, to = this.length, lineSep = "\n") {
+ [from, to] = clip(this, from, to);
+ let result = "";
+ for (let i = 0, pos = 0; i < this.children.length && pos <= to; i++) {
+ let child = this.children[i], end = pos + child.length;
+ if (pos > from && i)
+ result += lineSep;
+ if (from < end && to > pos)
+ result += child.sliceString(from - pos, to - pos, lineSep);
+ pos = end + 1;
+ }
+ return result;
+ }
+ flatten(target) {
+ for (let child of this.children)
+ child.flatten(target);
+ }
+ scanIdentical(other, dir) {
+ if (!(other instanceof _TextNode))
+ return 0;
+ let length = 0;
+ let [iA, iB, eA, eB] = dir > 0 ? [0, 0, this.children.length, other.children.length] : [this.children.length - 1, other.children.length - 1, -1, -1];
+ for (; ; iA += dir, iB += dir) {
+ if (iA == eA || iB == eB)
+ return length;
+ let chA = this.children[iA], chB = other.children[iB];
+ if (chA != chB)
+ return length + chA.scanIdentical(chB, dir);
+ length += chA.length + 1;
+ }
+ }
+ static from(children, length = children.reduce((l, ch) => l + ch.length + 1, -1)) {
+ let lines = 0;
+ for (let ch of children)
+ lines += ch.lines;
+ if (lines < 32) {
+ let flat = [];
+ for (let ch of children)
+ ch.flatten(flat);
+ return new TextLeaf(flat, length);
+ }
+ let chunk = Math.max(
+ 32,
+ lines >> 5
+ /* Tree.BranchShift */
+ ), maxChunk = chunk << 1, minChunk = chunk >> 1;
+ let chunked = [], currentLines = 0, currentLen = -1, currentChunk = [];
+ function add(child) {
+ let last;
+ if (child.lines > maxChunk && child instanceof _TextNode) {
+ for (let node of child.children)
+ add(node);
+ } else if (child.lines > minChunk && (currentLines > minChunk || !currentLines)) {
+ flush();
+ chunked.push(child);
+ } else if (child instanceof TextLeaf && currentLines && (last = currentChunk[currentChunk.length - 1]) instanceof TextLeaf && child.lines + last.lines <= 32) {
+ currentLines += child.lines;
+ currentLen += child.length + 1;
+ currentChunk[currentChunk.length - 1] = new TextLeaf(last.text.concat(child.text), last.length + 1 + child.length);
+ } else {
+ if (currentLines + child.lines > chunk)
+ flush();
+ currentLines += child.lines;
+ currentLen += child.length + 1;
+ currentChunk.push(child);
+ }
+ }
+ function flush() {
+ if (currentLines == 0)
+ return;
+ chunked.push(currentChunk.length == 1 ? currentChunk[0] : _TextNode.from(currentChunk, currentLen));
+ currentLen = -1;
+ currentLines = currentChunk.length = 0;
+ }
+ for (let child of children)
+ add(child);
+ flush();
+ return chunked.length == 1 ? chunked[0] : new _TextNode(chunked, length);
+ }
+ };
+ Text2.empty = /* @__PURE__ */ new TextLeaf([""], 0);
+ function textLength(text) {
+ let length = -1;
+ for (let line of text)
+ length += line.length + 1;
+ return length;
+ }
+ function appendText(text, target, from = 0, to = 1e9) {
+ for (let pos = 0, i = 0, first = true; i < text.length && pos <= to; i++) {
+ let line = text[i], end = pos + line.length;
+ if (end >= from) {
+ if (end > to)
+ line = line.slice(0, to - pos);
+ if (pos < from)
+ line = line.slice(from - pos);
+ if (first) {
+ target[target.length - 1] += line;
+ first = false;
+ } else
+ target.push(line);
+ }
+ pos = end + 1;
+ }
+ return target;
+ }
+ function sliceText(text, from, to) {
+ return appendText(text, [""], from, to);
+ }
+ var RawTextCursor = class {
+ constructor(text, dir = 1) {
+ this.dir = dir;
+ this.done = false;
+ this.lineBreak = false;
+ this.value = "";
+ this.nodes = [text];
+ this.offsets = [dir > 0 ? 1 : (text instanceof TextLeaf ? text.text.length : text.children.length) << 1];
+ }
+ nextInner(skip, dir) {
+ this.done = this.lineBreak = false;
+ for (; ; ) {
+ let last = this.nodes.length - 1;
+ let top2 = this.nodes[last], offsetValue = this.offsets[last], offset = offsetValue >> 1;
+ let size = top2 instanceof TextLeaf ? top2.text.length : top2.children.length;
+ if (offset == (dir > 0 ? size : 0)) {
+ if (last == 0) {
+ this.done = true;
+ this.value = "";
+ return this;
+ }
+ if (dir > 0)
+ this.offsets[last - 1]++;
+ this.nodes.pop();
+ this.offsets.pop();
+ } else if ((offsetValue & 1) == (dir > 0 ? 0 : 1)) {
+ this.offsets[last] += dir;
+ if (skip == 0) {
+ this.lineBreak = true;
+ this.value = "\n";
+ return this;
+ }
+ skip--;
+ } else if (top2 instanceof TextLeaf) {
+ let next = top2.text[offset + (dir < 0 ? -1 : 0)];
+ this.offsets[last] += dir;
+ if (next.length > Math.max(0, skip)) {
+ this.value = skip == 0 ? next : dir > 0 ? next.slice(skip) : next.slice(0, next.length - skip);
+ return this;
+ }
+ skip -= next.length;
+ } else {
+ let next = top2.children[offset + (dir < 0 ? -1 : 0)];
+ if (skip > next.length) {
+ skip -= next.length;
+ this.offsets[last] += dir;
+ } else {
+ if (dir < 0)
+ this.offsets[last]--;
+ this.nodes.push(next);
+ this.offsets.push(dir > 0 ? 1 : (next instanceof TextLeaf ? next.text.length : next.children.length) << 1);
+ }
+ }
+ }
+ }
+ next(skip = 0) {
+ if (skip < 0) {
+ this.nextInner(-skip, -this.dir);
+ skip = this.value.length;
+ }
+ return this.nextInner(skip, this.dir);
+ }
+ };
+ var PartialTextCursor = class {
+ constructor(text, start, end) {
+ this.value = "";
+ this.done = false;
+ this.cursor = new RawTextCursor(text, start > end ? -1 : 1);
+ this.pos = start > end ? text.length : 0;
+ this.from = Math.min(start, end);
+ this.to = Math.max(start, end);
+ }
+ nextInner(skip, dir) {
+ if (dir < 0 ? this.pos <= this.from : this.pos >= this.to) {
+ this.value = "";
+ this.done = true;
+ return this;
+ }
+ skip += Math.max(0, dir < 0 ? this.pos - this.to : this.from - this.pos);
+ let limit = dir < 0 ? this.pos - this.from : this.to - this.pos;
+ if (skip > limit)
+ skip = limit;
+ limit -= skip;
+ let { value } = this.cursor.next(skip);
+ this.pos += (value.length + skip) * dir;
+ this.value = value.length <= limit ? value : dir < 0 ? value.slice(value.length - limit) : value.slice(0, limit);
+ this.done = !this.value;
+ return this;
+ }
+ next(skip = 0) {
+ if (skip < 0)
+ skip = Math.max(skip, this.from - this.pos);
+ else if (skip > 0)
+ skip = Math.min(skip, this.to - this.pos);
+ return this.nextInner(skip, this.cursor.dir);
+ }
+ get lineBreak() {
+ return this.cursor.lineBreak && this.value != "";
+ }
+ };
+ var LineCursor = class {
+ constructor(inner) {
+ this.inner = inner;
+ this.afterBreak = true;
+ this.value = "";
+ this.done = false;
+ }
+ next(skip = 0) {
+ let { done, lineBreak, value } = this.inner.next(skip);
+ if (done && this.afterBreak) {
+ this.value = "";
+ this.afterBreak = false;
+ } else if (done) {
+ this.done = true;
+ this.value = "";
+ } else if (lineBreak) {
+ if (this.afterBreak) {
+ this.value = "";
+ } else {
+ this.afterBreak = true;
+ this.next();
+ }
+ } else {
+ this.value = value;
+ this.afterBreak = false;
+ }
+ return this;
+ }
+ get lineBreak() {
+ return false;
+ }
+ };
+ if (typeof Symbol != "undefined") {
+ Text2.prototype[Symbol.iterator] = function() {
+ return this.iter();
+ };
+ RawTextCursor.prototype[Symbol.iterator] = PartialTextCursor.prototype[Symbol.iterator] = LineCursor.prototype[Symbol.iterator] = function() {
+ return this;
+ };
+ }
+ var Line = class {
+ /**
+ @internal
+ */
+ constructor(from, to, number2, text) {
+ this.from = from;
+ this.to = to;
+ this.number = number2;
+ this.text = text;
+ }
+ /**
+ The length of the line (not including any line break after it).
+ */
+ get length() {
+ return this.to - this.from;
+ }
+ };
+ function clip(text, from, to) {
+ from = Math.max(0, Math.min(text.length, from));
+ return [from, Math.max(from, Math.min(text.length, to))];
+ }
+ function findClusterBreak2(str, pos, forward = true, includeExtending = true) {
+ return findClusterBreak(str, pos, forward, includeExtending);
+ }
+ function surrogateLow2(ch) {
+ return ch >= 56320 && ch < 57344;
+ }
+ function surrogateHigh2(ch) {
+ return ch >= 55296 && ch < 56320;
+ }
+ function codePointAt2(str, pos) {
+ let code0 = str.charCodeAt(pos);
+ if (!surrogateHigh2(code0) || pos + 1 == str.length)
+ return code0;
+ let code1 = str.charCodeAt(pos + 1);
+ if (!surrogateLow2(code1))
+ return code0;
+ return (code0 - 55296 << 10) + (code1 - 56320) + 65536;
+ }
+ function fromCodePoint(code) {
+ if (code <= 65535)
+ return String.fromCharCode(code);
+ code -= 65536;
+ return String.fromCharCode((code >> 10) + 55296, (code & 1023) + 56320);
+ }
+ function codePointSize2(code) {
+ return code < 65536 ? 1 : 2;
+ }
+ var DefaultSplit = /\r\n?|\n/;
+ var MapMode = /* @__PURE__ */ (function(MapMode2) {
+ MapMode2[MapMode2["Simple"] = 0] = "Simple";
+ MapMode2[MapMode2["TrackDel"] = 1] = "TrackDel";
+ MapMode2[MapMode2["TrackBefore"] = 2] = "TrackBefore";
+ MapMode2[MapMode2["TrackAfter"] = 3] = "TrackAfter";
+ return MapMode2;
+ })(MapMode || (MapMode = {}));
+ var ChangeDesc = class _ChangeDesc {
+ // Sections are encoded as pairs of integers. The first is the
+ // length in the current document, and the second is -1 for
+ // unaffected sections, and the length of the replacement content
+ // otherwise. So an insertion would be (0, n>0), a deletion (n>0,
+ // 0), and a replacement two positive numbers.
+ /**
+ @internal
+ */
+ constructor(sections) {
+ this.sections = sections;
+ }
+ /**
+ The length of the document before the change.
+ */
+ get length() {
+ let result = 0;
+ for (let i = 0; i < this.sections.length; i += 2)
+ result += this.sections[i];
+ return result;
+ }
+ /**
+ The length of the document after the change.
+ */
+ get newLength() {
+ let result = 0;
+ for (let i = 0; i < this.sections.length; i += 2) {
+ let ins = this.sections[i + 1];
+ result += ins < 0 ? this.sections[i] : ins;
+ }
+ return result;
+ }
+ /**
+ False when there are actual changes in this set.
+ */
+ get empty() {
+ return this.sections.length == 0 || this.sections.length == 2 && this.sections[1] < 0;
+ }
+ /**
+ Iterate over the unchanged parts left by these changes. `posA`
+ provides the position of the range in the old document, `posB`
+ the new position in the changed document.
+ */
+ iterGaps(f) {
+ for (let i = 0, posA = 0, posB = 0; i < this.sections.length; ) {
+ let len = this.sections[i++], ins = this.sections[i++];
+ if (ins < 0) {
+ f(posA, posB, len);
+ posB += len;
+ } else {
+ posB += ins;
+ }
+ posA += len;
+ }
+ }
+ /**
+ Iterate over the ranges changed by these changes. (See
+ [`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a
+ variant that also provides you with the inserted text.)
+ `fromA`/`toA` provides the extent of the change in the starting
+ document, `fromB`/`toB` the extent of the replacement in the
+ changed document.
+
+ When `individual` is true, adjacent changes (which are kept
+ separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are
+ reported separately.
+ */
+ iterChangedRanges(f, individual = false) {
+ iterChanges(this, f, individual);
+ }
+ /**
+ Get a description of the inverted form of these changes.
+ */
+ get invertedDesc() {
+ let sections = [];
+ for (let i = 0; i < this.sections.length; ) {
+ let len = this.sections[i++], ins = this.sections[i++];
+ if (ins < 0)
+ sections.push(len, ins);
+ else
+ sections.push(ins, len);
+ }
+ return new _ChangeDesc(sections);
+ }
+ /**
+ Compute the combined effect of applying another set of changes
+ after this one. The length of the document after this set should
+ match the length before `other`.
+ */
+ composeDesc(other) {
+ return this.empty ? other : other.empty ? this : composeSets(this, other);
+ }
+ /**
+ Map this description, which should start with the same document
+ as `other`, over another set of changes, so that it can be
+ applied after it. When `before` is true, map as if the changes
+ in `this` happened before the ones in `other`.
+ */
+ mapDesc(other, before = false) {
+ return other.empty ? this : mapSet(this, other, before);
+ }
+ mapPos(pos, assoc = -1, mode = MapMode.Simple) {
+ let posA = 0, posB = 0;
+ for (let i = 0; i < this.sections.length; ) {
+ let len = this.sections[i++], ins = this.sections[i++], endA = posA + len;
+ if (ins < 0) {
+ if (endA > pos)
+ return posB + (pos - posA);
+ posB += len;
+ } else {
+ if (mode != MapMode.Simple && endA >= pos && (mode == MapMode.TrackDel && posA < pos && endA > pos || mode == MapMode.TrackBefore && posA < pos || mode == MapMode.TrackAfter && endA > pos))
+ return null;
+ if (endA > pos || endA == pos && assoc < 0 && !len)
+ return pos == posA || assoc < 0 ? posB : posB + ins;
+ posB += ins;
+ }
+ posA = endA;
+ }
+ if (pos > posA)
+ throw new RangeError(`Position ${pos} is out of range for changeset of length ${posA}`);
+ return posB;
+ }
+ /**
+ Check whether these changes touch a given range. When one of the
+ changes entirely covers the range, the string `"cover"` is
+ returned.
+ */
+ touchesRange(from, to = from) {
+ for (let i = 0, pos = 0; i < this.sections.length && pos <= to; ) {
+ let len = this.sections[i++], ins = this.sections[i++], end = pos + len;
+ if (ins >= 0 && pos <= to && end >= from)
+ return pos < from && end > to ? "cover" : true;
+ pos = end;
+ }
+ return false;
+ }
+ /**
+ @internal
+ */
+ toString() {
+ let result = "";
+ for (let i = 0; i < this.sections.length; ) {
+ let len = this.sections[i++], ins = this.sections[i++];
+ result += (result ? " " : "") + len + (ins >= 0 ? ":" + ins : "");
+ }
+ return result;
+ }
+ /**
+ Serialize this change desc to a JSON-representable value.
+ */
+ toJSON() {
+ return this.sections;
+ }
+ /**
+ Create a change desc from its JSON representation (as produced
+ by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON).
+ */
+ static fromJSON(json) {
+ if (!Array.isArray(json) || json.length % 2 || json.some((a) => typeof a != "number"))
+ throw new RangeError("Invalid JSON representation of ChangeDesc");
+ return new _ChangeDesc(json);
+ }
+ /**
+ @internal
+ */
+ static create(sections) {
+ return new _ChangeDesc(sections);
+ }
+ };
+ var ChangeSet = class _ChangeSet extends ChangeDesc {
+ constructor(sections, inserted) {
+ super(sections);
+ this.inserted = inserted;
+ }
+ /**
+ Apply the changes to a document, returning the modified
+ document.
+ */
+ apply(doc2) {
+ if (this.length != doc2.length)
+ throw new RangeError("Applying change set to a document with the wrong length");
+ iterChanges(this, (fromA, toA, fromB, _toB, text) => doc2 = doc2.replace(fromB, fromB + (toA - fromA), text), false);
+ return doc2;
+ }
+ mapDesc(other, before = false) {
+ return mapSet(this, other, before, true);
+ }
+ /**
+ Given the document as it existed _before_ the changes, return a
+ change set that represents the inverse of this set, which could
+ be used to go from the document created by the changes back to
+ the document as it existed before the changes.
+ */
+ invert(doc2) {
+ let sections = this.sections.slice(), inserted = [];
+ for (let i = 0, pos = 0; i < sections.length; i += 2) {
+ let len = sections[i], ins = sections[i + 1];
+ if (ins >= 0) {
+ sections[i] = ins;
+ sections[i + 1] = len;
+ let index = i >> 1;
+ while (inserted.length < index)
+ inserted.push(Text2.empty);
+ inserted.push(len ? doc2.slice(pos, pos + len) : Text2.empty);
+ }
+ pos += len;
+ }
+ return new _ChangeSet(sections, inserted);
+ }
+ /**
+ Combine two subsequent change sets into a single set. `other`
+ must start in the document produced by `this`. If `this` goes
+ `docA` → `docB` and `other` represents `docB` → `docC`, the
+ returned value will represent the change `docA` → `docC`.
+ */
+ compose(other) {
+ return this.empty ? other : other.empty ? this : composeSets(this, other, true);
+ }
+ /**
+ Given another change set starting in the same document, maps this
+ change set over the other, producing a new change set that can be
+ applied to the document produced by applying `other`. When
+ `before` is `true`, order changes as if `this` comes before
+ `other`, otherwise (the default) treat `other` as coming first.
+
+ Given two changes `A` and `B`, `A.compose(B.map(A))` and
+ `B.compose(A.map(B, true))` will produce the same document. This
+ provides a basic form of [operational
+ transformation](https://en.wikipedia.org/wiki/Operational_transformation),
+ and can be used for collaborative editing.
+ */
+ map(other, before = false) {
+ return other.empty ? this : mapSet(this, other, before, true);
+ }
+ /**
+ Iterate over the changed ranges in the document, calling `f` for
+ each, with the range in the original document (`fromA`-`toA`)
+ and the range that replaces it in the new document
+ (`fromB`-`toB`).
+
+ When `individual` is true, adjacent changes are reported
+ separately.
+ */
+ iterChanges(f, individual = false) {
+ iterChanges(this, f, individual);
+ }
+ /**
+ Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
+ set.
+ */
+ get desc() {
+ return ChangeDesc.create(this.sections);
+ }
+ /**
+ @internal
+ */
+ filter(ranges) {
+ let resultSections = [], resultInserted = [], filteredSections = [];
+ let iter = new SectionIter(this);
+ done: for (let i = 0, pos = 0; ; ) {
+ let next = i == ranges.length ? 1e9 : ranges[i++];
+ while (pos < next || pos == next && iter.len == 0) {
+ if (iter.done)
+ break done;
+ let len = Math.min(iter.len, next - pos);
+ addSection(filteredSections, len, -1);
+ let ins = iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0;
+ addSection(resultSections, len, ins);
+ if (ins > 0)
+ addInsert(resultInserted, resultSections, iter.text);
+ iter.forward(len);
+ pos += len;
+ }
+ let end = ranges[i++];
+ while (pos < end) {
+ if (iter.done)
+ break done;
+ let len = Math.min(iter.len, end - pos);
+ addSection(resultSections, len, -1);
+ addSection(filteredSections, len, iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0);
+ iter.forward(len);
+ pos += len;
+ }
+ }
+ return {
+ changes: new _ChangeSet(resultSections, resultInserted),
+ filtered: ChangeDesc.create(filteredSections)
+ };
+ }
+ /**
+ Serialize this change set to a JSON-representable value.
+ */
+ toJSON() {
+ let parts = [];
+ for (let i = 0; i < this.sections.length; i += 2) {
+ let len = this.sections[i], ins = this.sections[i + 1];
+ if (ins < 0)
+ parts.push(len);
+ else if (ins == 0)
+ parts.push([len]);
+ else
+ parts.push([len].concat(this.inserted[i >> 1].toJSON()));
+ }
+ return parts;
+ }
+ /**
+ Create a change set for the given changes, for a document of the
+ given length, using `lineSep` as line separator.
+ */
+ static of(changes, length, lineSep) {
+ let sections = [], inserted = [], pos = 0;
+ let total = null;
+ function flush(force = false) {
+ if (!force && !sections.length)
+ return;
+ if (pos < length)
+ addSection(sections, length - pos, -1);
+ let set = new _ChangeSet(sections, inserted);
+ total = total ? total.compose(set.map(total)) : set;
+ sections = [];
+ inserted = [];
+ pos = 0;
+ }
+ function process2(spec) {
+ if (Array.isArray(spec)) {
+ for (let sub of spec)
+ process2(sub);
+ } else if (spec instanceof _ChangeSet) {
+ if (spec.length != length)
+ throw new RangeError(`Mismatched change set length (got ${spec.length}, expected ${length})`);
+ flush();
+ total = total ? total.compose(spec.map(total)) : spec;
+ } else {
+ let { from, to = from, insert: insert2 } = spec;
+ if (from > to || from < 0 || to > length)
+ throw new RangeError(`Invalid change range ${from} to ${to} (in doc of length ${length})`);
+ let insText = !insert2 ? Text2.empty : typeof insert2 == "string" ? Text2.of(insert2.split(lineSep || DefaultSplit)) : insert2;
+ let insLen = insText.length;
+ if (from == to && insLen == 0)
+ return;
+ if (from < pos)
+ flush();
+ if (from > pos)
+ addSection(sections, from - pos, -1);
+ addSection(sections, to - from, insLen);
+ addInsert(inserted, sections, insText);
+ pos = to;
+ }
+ }
+ process2(changes);
+ flush(!total);
+ return total;
+ }
+ /**
+ Create an empty changeset of the given length.
+ */
+ static empty(length) {
+ return new _ChangeSet(length ? [length, -1] : [], []);
+ }
+ /**
+ Create a changeset from its JSON representation (as produced by
+ [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).
+ */
+ static fromJSON(json) {
+ if (!Array.isArray(json))
+ throw new RangeError("Invalid JSON representation of ChangeSet");
+ let sections = [], inserted = [];
+ for (let i = 0; i < json.length; i++) {
+ let part = json[i];
+ if (typeof part == "number") {
+ sections.push(part, -1);
+ } else if (!Array.isArray(part) || typeof part[0] != "number" || part.some((e, i2) => i2 && typeof e != "string")) {
+ throw new RangeError("Invalid JSON representation of ChangeSet");
+ } else if (part.length == 1) {
+ sections.push(part[0], 0);
+ } else {
+ while (inserted.length < i)
+ inserted.push(Text2.empty);
+ inserted[i] = Text2.of(part.slice(1));
+ sections.push(part[0], inserted[i].length);
+ }
+ }
+ return new _ChangeSet(sections, inserted);
+ }
+ /**
+ @internal
+ */
+ static createSet(sections, inserted) {
+ return new _ChangeSet(sections, inserted);
+ }
+ };
+ function addSection(sections, len, ins, forceJoin = false) {
+ if (len == 0 && ins <= 0)
+ return;
+ let last = sections.length - 2;
+ if (last >= 0 && ins <= 0 && ins == sections[last + 1])
+ sections[last] += len;
+ else if (last >= 0 && len == 0 && sections[last] == 0)
+ sections[last + 1] += ins;
+ else if (forceJoin) {
+ sections[last] += len;
+ sections[last + 1] += ins;
+ } else
+ sections.push(len, ins);
+ }
+ function addInsert(values2, sections, value) {
+ if (value.length == 0)
+ return;
+ let index = sections.length - 2 >> 1;
+ if (index < values2.length) {
+ values2[values2.length - 1] = values2[values2.length - 1].append(value);
+ } else {
+ while (values2.length < index)
+ values2.push(Text2.empty);
+ values2.push(value);
+ }
+ }
+ function iterChanges(desc, f, individual) {
+ let inserted = desc.inserted;
+ for (let posA = 0, posB = 0, i = 0; i < desc.sections.length; ) {
+ let len = desc.sections[i++], ins = desc.sections[i++];
+ if (ins < 0) {
+ posA += len;
+ posB += len;
+ } else {
+ let endA = posA, endB = posB, text = Text2.empty;
+ for (; ; ) {
+ endA += len;
+ endB += ins;
+ if (ins && inserted)
+ text = text.append(inserted[i - 2 >> 1]);
+ if (individual || i == desc.sections.length || desc.sections[i + 1] < 0)
+ break;
+ len = desc.sections[i++];
+ ins = desc.sections[i++];
+ }
+ f(posA, endA, posB, endB, text);
+ posA = endA;
+ posB = endB;
+ }
+ }
+ }
+ function mapSet(setA, setB, before, mkSet = false) {
+ let sections = [], insert2 = mkSet ? [] : null;
+ let a = new SectionIter(setA), b = new SectionIter(setB);
+ for (let inserted = -1; ; ) {
+ if (a.done && b.len || b.done && a.len) {
+ throw new Error("Mismatched change set lengths");
+ } else if (a.ins == -1 && b.ins == -1) {
+ let len = Math.min(a.len, b.len);
+ addSection(sections, len, -1);
+ a.forward(len);
+ b.forward(len);
+ } else if (b.ins >= 0 && (a.ins < 0 || inserted == a.i || a.off == 0 && (b.len < a.len || b.len == a.len && !before))) {
+ let len = b.len;
+ addSection(sections, b.ins, -1);
+ while (len) {
+ let piece = Math.min(a.len, len);
+ if (a.ins >= 0 && inserted < a.i && a.len <= piece) {
+ addSection(sections, 0, a.ins);
+ if (insert2)
+ addInsert(insert2, sections, a.text);
+ inserted = a.i;
+ }
+ a.forward(piece);
+ len -= piece;
+ }
+ b.next();
+ } else if (a.ins >= 0) {
+ let len = 0, left = a.len;
+ while (left) {
+ if (b.ins == -1) {
+ let piece = Math.min(left, b.len);
+ len += piece;
+ left -= piece;
+ b.forward(piece);
+ } else if (b.ins == 0 && b.len < left) {
+ left -= b.len;
+ b.next();
+ } else {
+ break;
+ }
+ }
+ addSection(sections, len, inserted < a.i ? a.ins : 0);
+ if (insert2 && inserted < a.i)
+ addInsert(insert2, sections, a.text);
+ inserted = a.i;
+ a.forward(a.len - left);
+ } else if (a.done && b.done) {
+ return insert2 ? ChangeSet.createSet(sections, insert2) : ChangeDesc.create(sections);
+ } else {
+ throw new Error("Mismatched change set lengths");
+ }
+ }
+ }
+ function composeSets(setA, setB, mkSet = false) {
+ let sections = [];
+ let insert2 = mkSet ? [] : null;
+ let a = new SectionIter(setA), b = new SectionIter(setB);
+ for (let open = false; ; ) {
+ if (a.done && b.done) {
+ return insert2 ? ChangeSet.createSet(sections, insert2) : ChangeDesc.create(sections);
+ } else if (a.ins == 0) {
+ addSection(sections, a.len, 0, open);
+ a.next();
+ } else if (b.len == 0 && !b.done) {
+ addSection(sections, 0, b.ins, open);
+ if (insert2)
+ addInsert(insert2, sections, b.text);
+ b.next();
+ } else if (a.done || b.done) {
+ throw new Error("Mismatched change set lengths");
+ } else {
+ let len = Math.min(a.len2, b.len), sectionLen = sections.length;
+ if (a.ins == -1) {
+ let insB = b.ins == -1 ? -1 : b.off ? 0 : b.ins;
+ addSection(sections, len, insB, open);
+ if (insert2 && insB)
+ addInsert(insert2, sections, b.text);
+ } else if (b.ins == -1) {
+ addSection(sections, a.off ? 0 : a.len, len, open);
+ if (insert2)
+ addInsert(insert2, sections, a.textBit(len));
+ } else {
+ addSection(sections, a.off ? 0 : a.len, b.off ? 0 : b.ins, open);
+ if (insert2 && !b.off)
+ addInsert(insert2, sections, b.text);
+ }
+ open = (a.ins > len || b.ins >= 0 && b.len > len) && (open || sections.length > sectionLen);
+ a.forward2(len);
+ b.forward(len);
+ }
+ }
+ }
+ var SectionIter = class {
+ constructor(set) {
+ this.set = set;
+ this.i = 0;
+ this.next();
+ }
+ next() {
+ let { sections } = this.set;
+ if (this.i < sections.length) {
+ this.len = sections[this.i++];
+ this.ins = sections[this.i++];
+ } else {
+ this.len = 0;
+ this.ins = -2;
+ }
+ this.off = 0;
+ }
+ get done() {
+ return this.ins == -2;
+ }
+ get len2() {
+ return this.ins < 0 ? this.len : this.ins;
+ }
+ get text() {
+ let { inserted } = this.set, index = this.i - 2 >> 1;
+ return index >= inserted.length ? Text2.empty : inserted[index];
+ }
+ textBit(len) {
+ let { inserted } = this.set, index = this.i - 2 >> 1;
+ return index >= inserted.length && !len ? Text2.empty : inserted[index].slice(this.off, len == null ? void 0 : this.off + len);
+ }
+ forward(len) {
+ if (len == this.len)
+ this.next();
+ else {
+ this.len -= len;
+ this.off += len;
+ }
+ }
+ forward2(len) {
+ if (this.ins == -1)
+ this.forward(len);
+ else if (len == this.ins)
+ this.next();
+ else {
+ this.ins -= len;
+ this.off += len;
+ }
+ }
+ };
+ var SelectionRange = class _SelectionRange {
+ constructor(from, to, flags) {
+ this.from = from;
+ this.to = to;
+ this.flags = flags;
+ }
+ /**
+ The anchor of the range—the side that doesn't move when you
+ extend it.
+ */
+ get anchor() {
+ return this.flags & 32 ? this.to : this.from;
+ }
+ /**
+ The head of the range, which is moved when the range is
+ [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
+ */
+ get head() {
+ return this.flags & 32 ? this.from : this.to;
+ }
+ /**
+ True when `anchor` and `head` are at the same position.
+ */
+ get empty() {
+ return this.from == this.to;
+ }
+ /**
+ If this is a cursor that is explicitly associated with the
+ character on one of its sides, this returns the side. -1 means
+ the character before its position, 1 the character after, and 0
+ means no association.
+ */
+ get assoc() {
+ return this.flags & 8 ? -1 : this.flags & 16 ? 1 : 0;
+ }
+ /**
+ The bidirectional text level associated with this cursor, if
+ any.
+ */
+ get bidiLevel() {
+ let level = this.flags & 7;
+ return level == 7 ? null : level;
+ }
+ /**
+ The goal column (stored vertical offset) associated with a
+ cursor. This is used to preserve the vertical position when
+ [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
+ lines of different length.
+ */
+ get goalColumn() {
+ let value = this.flags >> 6;
+ return value == 16777215 ? void 0 : value;
+ }
+ /**
+ Map this range through a change, producing a valid range in the
+ updated document.
+ */
+ map(change, assoc = -1) {
+ let from, to;
+ if (this.empty) {
+ from = to = change.mapPos(this.from, assoc);
+ } else {
+ from = change.mapPos(this.from, 1);
+ to = change.mapPos(this.to, -1);
+ }
+ return from == this.from && to == this.to ? this : new _SelectionRange(from, to, this.flags);
+ }
+ /**
+ Extend this range to cover at least `from` to `to`.
+ */
+ extend(from, to = from, assoc = 0) {
+ if (from <= this.anchor && to >= this.anchor)
+ return EditorSelection.range(from, to, void 0, void 0, assoc);
+ let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;
+ return EditorSelection.range(this.anchor, head, void 0, void 0, assoc);
+ }
+ /**
+ Compare this range to another range.
+ */
+ eq(other, includeAssoc = false) {
+ return this.anchor == other.anchor && this.head == other.head && this.goalColumn == other.goalColumn && (!includeAssoc || !this.empty || this.assoc == other.assoc);
+ }
+ /**
+ Return a JSON-serializable object representing the range.
+ */
+ toJSON() {
+ return { anchor: this.anchor, head: this.head };
+ }
+ /**
+ Convert a JSON representation of a range to a `SelectionRange`
+ instance.
+ */
+ static fromJSON(json) {
+ if (!json || typeof json.anchor != "number" || typeof json.head != "number")
+ throw new RangeError("Invalid JSON representation for SelectionRange");
+ return EditorSelection.range(json.anchor, json.head);
+ }
+ /**
+ @internal
+ */
+ static create(from, to, flags) {
+ return new _SelectionRange(from, to, flags);
+ }
+ };
+ var EditorSelection = class _EditorSelection {
+ constructor(ranges, mainIndex) {
+ this.ranges = ranges;
+ this.mainIndex = mainIndex;
+ }
+ /**
+ Map a selection through a change. Used to adjust the selection
+ position for changes.
+ */
+ map(change, assoc = -1) {
+ if (change.empty)
+ return this;
+ return _EditorSelection.create(this.ranges.map((r) => r.map(change, assoc)), this.mainIndex);
+ }
+ /**
+ Compare this selection to another selection. By default, ranges
+ are compared only by position. When `includeAssoc` is true,
+ cursor ranges must also have the same
+ [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
+ */
+ eq(other, includeAssoc = false) {
+ if (this.ranges.length != other.ranges.length || this.mainIndex != other.mainIndex)
+ return false;
+ for (let i = 0; i < this.ranges.length; i++)
+ if (!this.ranges[i].eq(other.ranges[i], includeAssoc))
+ return false;
+ return true;
+ }
+ /**
+ Get the primary selection range. Usually, you should make sure
+ your code applies to _all_ ranges, by using methods like
+ [`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange).
+ */
+ get main() {
+ return this.ranges[this.mainIndex];
+ }
+ /**
+ Make sure the selection only has one range. Returns a selection
+ holding only the main range from this selection.
+ */
+ asSingle() {
+ return this.ranges.length == 1 ? this : new _EditorSelection([this.main], 0);
+ }
+ /**
+ Extend this selection with an extra range.
+ */
+ addRange(range, main = true) {
+ return _EditorSelection.create([range].concat(this.ranges), main ? 0 : this.mainIndex + 1);
+ }
+ /**
+ Replace a given range with another range, and then normalize the
+ selection to merge and sort ranges if necessary.
+ */
+ replaceRange(range, which = this.mainIndex) {
+ let ranges = this.ranges.slice();
+ ranges[which] = range;
+ return _EditorSelection.create(ranges, this.mainIndex);
+ }
+ /**
+ Convert this selection to an object that can be serialized to
+ JSON.
+ */
+ toJSON() {
+ return { ranges: this.ranges.map((r) => r.toJSON()), main: this.mainIndex };
+ }
+ /**
+ Create a selection from a JSON representation.
+ */
+ static fromJSON(json) {
+ if (!json || !Array.isArray(json.ranges) || typeof json.main != "number" || json.main >= json.ranges.length)
+ throw new RangeError("Invalid JSON representation for EditorSelection");
+ return new _EditorSelection(json.ranges.map((r) => SelectionRange.fromJSON(r)), json.main);
+ }
+ /**
+ Create a selection holding a single range.
+ */
+ static single(anchor, head = anchor) {
+ return new _EditorSelection([_EditorSelection.range(anchor, head)], 0);
+ }
+ /**
+ Sort and merge the given set of ranges, creating a valid
+ selection.
+ */
+ static create(ranges, mainIndex = 0) {
+ if (ranges.length == 0)
+ throw new RangeError("A selection needs at least one range");
+ for (let pos = 0, i = 0; i < ranges.length; i++) {
+ let range = ranges[i];
+ if (range.empty ? range.from <= pos : range.from < pos)
+ return _EditorSelection.normalized(ranges.slice(), mainIndex);
+ pos = range.to;
+ }
+ return new _EditorSelection(ranges, mainIndex);
+ }
+ /**
+ Create a cursor selection range at the given position. You can
+ safely ignore the optional arguments in most situations.
+ */
+ static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
+ return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 : 16) | (bidiLevel == null ? 7 : Math.min(6, bidiLevel)) | (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215) << 6);
+ }
+ /**
+ Create a selection range.
+ */
+ static range(anchor, head, goalColumn, bidiLevel, assoc) {
+ let flags = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215) << 6 | (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
+ if (!assoc && anchor != head)
+ assoc = head < anchor ? 1 : -1;
+ return head < anchor ? SelectionRange.create(head, anchor, 32 | 16 | flags) : SelectionRange.create(anchor, head, (!assoc ? 0 : assoc < 0 ? 8 : 16) | flags);
+ }
+ /**
+ @internal
+ */
+ static normalized(ranges, mainIndex = 0) {
+ let main = ranges[mainIndex];
+ ranges.sort((a, b) => a.from - b.from);
+ mainIndex = ranges.indexOf(main);
+ for (let i = 1; i < ranges.length; i++) {
+ let range = ranges[i], prev = ranges[i - 1];
+ if (range.empty ? range.from <= prev.to : range.from < prev.to) {
+ let from = prev.from, to = Math.max(range.to, prev.to);
+ if (i <= mainIndex)
+ mainIndex--;
+ ranges.splice(--i, 2, range.anchor > range.head ? _EditorSelection.range(to, from) : _EditorSelection.range(from, to));
+ }
+ }
+ return new _EditorSelection(ranges, mainIndex);
+ }
+ };
+ function checkSelection(selection, docLength) {
+ for (let range of selection.ranges)
+ if (range.to > docLength)
+ throw new RangeError("Selection points outside of document");
+ }
+ var nextID = 0;
+ var Facet = class _Facet {
+ constructor(combine, compareInput, compare2, isStatic, enables) {
+ this.combine = combine;
+ this.compareInput = compareInput;
+ this.compare = compare2;
+ this.isStatic = isStatic;
+ this.id = nextID++;
+ this.default = combine([]);
+ this.extensions = typeof enables == "function" ? enables(this) : enables;
+ }
+ /**
+ Returns a facet reader for this facet, which can be used to
+ [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
+ */
+ get reader() {
+ return this;
+ }
+ /**
+ Define a new facet.
+ */
+ static define(config2 = {}) {
+ return new _Facet(config2.combine || ((a) => a), config2.compareInput || ((a, b) => a === b), config2.compare || (!config2.combine ? sameArray : (a, b) => a === b), !!config2.static, config2.enables);
+ }
+ /**
+ Returns an extension that adds the given value to this facet.
+ */
+ of(value) {
+ return new FacetProvider([], this, 0, value);
+ }
+ /**
+ Create an extension that computes a value for the facet from a
+ state. You must take care to declare the parts of the state that
+ this value depends on, since your function is only called again
+ for a new state when one of those parts changed.
+
+ In cases where your value depends only on a single field, you'll
+ want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
+ */
+ compute(deps, get) {
+ if (this.isStatic)
+ throw new Error("Can't compute a static facet");
+ return new FacetProvider(deps, this, 1, get);
+ }
+ /**
+ Create an extension that computes zero or more values for this
+ facet from a state.
+ */
+ computeN(deps, get) {
+ if (this.isStatic)
+ throw new Error("Can't compute a static facet");
+ return new FacetProvider(deps, this, 2, get);
+ }
+ from(field, get) {
+ if (!get)
+ get = (x) => x;
+ return this.compute([field], (state) => get(state.field(field)));
+ }
+ };
+ function sameArray(a, b) {
+ return a == b || a.length == b.length && a.every((e, i) => e === b[i]);
+ }
+ var FacetProvider = class {
+ constructor(dependencies, facet, type, value) {
+ this.dependencies = dependencies;
+ this.facet = facet;
+ this.type = type;
+ this.value = value;
+ this.id = nextID++;
+ }
+ dynamicSlot(addresses) {
+ var _a2;
+ let getter = this.value;
+ let compare2 = this.facet.compareInput;
+ let id2 = this.id, idx = addresses[id2] >> 1, multi = this.type == 2;
+ let depDoc = false, depSel = false, depAddrs = [];
+ for (let dep of this.dependencies) {
+ if (dep == "doc")
+ depDoc = true;
+ else if (dep == "selection")
+ depSel = true;
+ else if ((((_a2 = addresses[dep.id]) !== null && _a2 !== void 0 ? _a2 : 1) & 1) == 0)
+ depAddrs.push(addresses[dep.id]);
+ }
+ return {
+ create(state) {
+ state.values[idx] = getter(state);
+ return 1;
+ },
+ update(state, tr) {
+ if (depDoc && tr.docChanged || depSel && (tr.docChanged || tr.selection) || ensureAll(state, depAddrs)) {
+ let newVal = getter(state);
+ if (multi ? !compareArray(newVal, state.values[idx], compare2) : !compare2(newVal, state.values[idx])) {
+ state.values[idx] = newVal;
+ return 1;
+ }
+ }
+ return 0;
+ },
+ reconfigure: (state, oldState) => {
+ let newVal, oldAddr = oldState.config.address[id2];
+ if (oldAddr != null) {
+ let oldVal = getAddr(oldState, oldAddr);
+ if (this.dependencies.every((dep) => {
+ return dep instanceof Facet ? oldState.facet(dep) === state.facet(dep) : dep instanceof StateField ? oldState.field(dep, false) == state.field(dep, false) : true;
+ }) || (multi ? compareArray(newVal = getter(state), oldVal, compare2) : compare2(newVal = getter(state), oldVal))) {
+ state.values[idx] = oldVal;
+ return 0;
+ }
+ } else {
+ newVal = getter(state);
+ }
+ state.values[idx] = newVal;
+ return 1;
+ }
+ };
+ }
+ };
+ function compareArray(a, b, compare2) {
+ if (a.length != b.length)
+ return false;
+ for (let i = 0; i < a.length; i++)
+ if (!compare2(a[i], b[i]))
+ return false;
+ return true;
+ }
+ function ensureAll(state, addrs) {
+ let changed = false;
+ for (let addr of addrs)
+ if (ensureAddr(state, addr) & 1)
+ changed = true;
+ return changed;
+ }
+ function dynamicFacetSlot(addresses, facet, providers) {
+ let providerAddrs = providers.map((p) => addresses[p.id]);
+ let providerTypes = providers.map((p) => p.type);
+ let dynamic = providerAddrs.filter((p) => !(p & 1));
+ let idx = addresses[facet.id] >> 1;
+ function get(state) {
+ let values2 = [];
+ for (let i = 0; i < providerAddrs.length; i++) {
+ let value = getAddr(state, providerAddrs[i]);
+ if (providerTypes[i] == 2)
+ for (let val of value)
+ values2.push(val);
+ else
+ values2.push(value);
+ }
+ return facet.combine(values2);
+ }
+ return {
+ create(state) {
+ for (let addr of providerAddrs)
+ ensureAddr(state, addr);
+ state.values[idx] = get(state);
+ return 1;
+ },
+ update(state, tr) {
+ if (!ensureAll(state, dynamic))
+ return 0;
+ let value = get(state);
+ if (facet.compare(value, state.values[idx]))
+ return 0;
+ state.values[idx] = value;
+ return 1;
+ },
+ reconfigure(state, oldState) {
+ let depChanged = ensureAll(state, providerAddrs);
+ let oldProviders = oldState.config.facets[facet.id], oldValue = oldState.facet(facet);
+ if (oldProviders && !depChanged && sameArray(providers, oldProviders)) {
+ state.values[idx] = oldValue;
+ return 0;
+ }
+ let value = get(state);
+ if (facet.compare(value, oldValue)) {
+ state.values[idx] = oldValue;
+ return 0;
+ }
+ state.values[idx] = value;
+ return 1;
+ }
+ };
+ }
+ var initField = /* @__PURE__ */ Facet.define({ static: true });
+ var StateField = class _StateField {
+ constructor(id2, createF, updateF, compareF, spec) {
+ this.id = id2;
+ this.createF = createF;
+ this.updateF = updateF;
+ this.compareF = compareF;
+ this.spec = spec;
+ this.provides = void 0;
+ }
+ /**
+ Define a state field.
+ */
+ static define(config2) {
+ let field = new _StateField(nextID++, config2.create, config2.update, config2.compare || ((a, b) => a === b), config2);
+ if (config2.provide)
+ field.provides = config2.provide(field);
+ return field;
+ }
+ create(state) {
+ let init = state.facet(initField).find((i) => i.field == this);
+ return ((init === null || init === void 0 ? void 0 : init.create) || this.createF)(state);
+ }
+ /**
+ @internal
+ */
+ slot(addresses) {
+ let idx = addresses[this.id] >> 1;
+ return {
+ create: (state) => {
+ state.values[idx] = this.create(state);
+ return 1;
+ },
+ update: (state, tr) => {
+ let oldVal = state.values[idx];
+ let value = this.updateF(oldVal, tr);
+ if (this.compareF(oldVal, value))
+ return 0;
+ state.values[idx] = value;
+ return 1;
+ },
+ reconfigure: (state, oldState) => {
+ let init = state.facet(initField), oldInit = oldState.facet(initField), reInit;
+ if ((reInit = init.find((i) => i.field == this)) && reInit != oldInit.find((i) => i.field == this)) {
+ state.values[idx] = reInit.create(state);
+ return 1;
+ }
+ if (oldState.config.address[this.id] != null) {
+ state.values[idx] = oldState.field(this);
+ return 0;
+ }
+ state.values[idx] = this.create(state);
+ return 1;
+ }
+ };
+ }
+ /**
+ Returns an extension that enables this field and overrides the
+ way it is initialized. Can be useful when you need to provide a
+ non-default starting value for the field.
+ */
+ init(create) {
+ return [this, initField.of({ field: this, create })];
+ }
+ /**
+ State field instances can be used as
+ [`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a
+ given state.
+ */
+ get extension() {
+ return this;
+ }
+ };
+ var Prec_ = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };
+ function prec(value) {
+ return (ext) => new PrecExtension(ext, value);
+ }
+ var Prec = {
+ /**
+ The highest precedence level, for extensions that should end up
+ near the start of the precedence ordering.
+ */
+ highest: /* @__PURE__ */ prec(Prec_.highest),
+ /**
+ A higher-than-default precedence, for extensions that should
+ come before those with default precedence.
+ */
+ high: /* @__PURE__ */ prec(Prec_.high),
+ /**
+ The default precedence, which is also used for extensions
+ without an explicit precedence.
+ */
+ default: /* @__PURE__ */ prec(Prec_.default),
+ /**
+ A lower-than-default precedence.
+ */
+ low: /* @__PURE__ */ prec(Prec_.low),
+ /**
+ The lowest precedence level. Meant for things that should end up
+ near the end of the extension order.
+ */
+ lowest: /* @__PURE__ */ prec(Prec_.lowest)
+ };
+ var PrecExtension = class {
+ constructor(inner, prec2) {
+ this.inner = inner;
+ this.prec = prec2;
+ }
+ };
+ var Compartment = class _Compartment {
+ /**
+ Create an instance of this compartment to add to your [state
+ configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions).
+ */
+ of(ext) {
+ return new CompartmentInstance(this, ext);
+ }
+ /**
+ Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that
+ reconfigures this compartment.
+ */
+ reconfigure(content2) {
+ return _Compartment.reconfigure.of({ compartment: this, extension: content2 });
+ }
+ /**
+ Get the current content of the compartment in the state, or
+ `undefined` if it isn't present.
+ */
+ get(state) {
+ return state.config.compartments.get(this);
+ }
+ };
+ var CompartmentInstance = class {
+ constructor(compartment, inner) {
+ this.compartment = compartment;
+ this.inner = inner;
+ }
+ };
+ var Configuration = class _Configuration {
+ constructor(base2, compartments, dynamicSlots, address, staticValues, facets) {
+ this.base = base2;
+ this.compartments = compartments;
+ this.dynamicSlots = dynamicSlots;
+ this.address = address;
+ this.staticValues = staticValues;
+ this.facets = facets;
+ this.statusTemplate = [];
+ while (this.statusTemplate.length < dynamicSlots.length)
+ this.statusTemplate.push(
+ 0
+ /* SlotStatus.Unresolved */
+ );
+ }
+ staticFacet(facet) {
+ let addr = this.address[facet.id];
+ return addr == null ? facet.default : this.staticValues[addr >> 1];
+ }
+ static resolve(base2, compartments, oldState) {
+ let fields = [];
+ let facets = /* @__PURE__ */ Object.create(null);
+ let newCompartments = /* @__PURE__ */ new Map();
+ for (let ext of flatten(base2, compartments, newCompartments)) {
+ if (ext instanceof StateField)
+ fields.push(ext);
+ else
+ (facets[ext.facet.id] || (facets[ext.facet.id] = [])).push(ext);
+ }
+ let address = /* @__PURE__ */ Object.create(null);
+ let staticValues = [];
+ let dynamicSlots = [];
+ for (let field of fields) {
+ address[field.id] = dynamicSlots.length << 1;
+ dynamicSlots.push((a) => field.slot(a));
+ }
+ let oldFacets = oldState === null || oldState === void 0 ? void 0 : oldState.config.facets;
+ for (let id2 in facets) {
+ let providers = facets[id2], facet = providers[0].facet;
+ let oldProviders = oldFacets && oldFacets[id2] || [];
+ if (providers.every(
+ (p) => p.type == 0
+ /* Provider.Static */
+ )) {
+ address[facet.id] = staticValues.length << 1 | 1;
+ if (sameArray(oldProviders, providers)) {
+ staticValues.push(oldState.facet(facet));
+ } else {
+ let value = facet.combine(providers.map((p) => p.value));
+ staticValues.push(oldState && facet.compare(value, oldState.facet(facet)) ? oldState.facet(facet) : value);
+ }
+ } else {
+ for (let p of providers) {
+ if (p.type == 0) {
+ address[p.id] = staticValues.length << 1 | 1;
+ staticValues.push(p.value);
+ } else {
+ address[p.id] = dynamicSlots.length << 1;
+ dynamicSlots.push((a) => p.dynamicSlot(a));
+ }
+ }
+ address[facet.id] = dynamicSlots.length << 1;
+ dynamicSlots.push((a) => dynamicFacetSlot(a, facet, providers));
+ }
+ }
+ let dynamic = dynamicSlots.map((f) => f(address));
+ return new _Configuration(base2, newCompartments, dynamic, address, staticValues, facets);
+ }
+ };
+ function flatten(extension, compartments, newCompartments) {
+ let result = [[], [], [], [], []];
+ let seen = /* @__PURE__ */ new Map();
+ function inner(ext, prec2) {
+ let known = seen.get(ext);
+ if (known != null) {
+ if (known <= prec2)
+ return;
+ let found = result[known].indexOf(ext);
+ if (found > -1)
+ result[known].splice(found, 1);
+ if (ext instanceof CompartmentInstance)
+ newCompartments.delete(ext.compartment);
+ }
+ seen.set(ext, prec2);
+ if (Array.isArray(ext)) {
+ for (let e of ext)
+ inner(e, prec2);
+ } else if (ext instanceof CompartmentInstance) {
+ if (newCompartments.has(ext.compartment))
+ throw new RangeError(`Duplicate use of compartment in extensions`);
+ let content2 = compartments.get(ext.compartment) || ext.inner;
+ newCompartments.set(ext.compartment, content2);
+ inner(content2, prec2);
+ } else if (ext instanceof PrecExtension) {
+ inner(ext.inner, ext.prec);
+ } else if (ext instanceof StateField) {
+ result[prec2].push(ext);
+ if (ext.provides)
+ inner(ext.provides, prec2);
+ } else if (ext instanceof FacetProvider) {
+ result[prec2].push(ext);
+ if (ext.facet.extensions)
+ inner(ext.facet.extensions, Prec_.default);
+ } else {
+ let content2 = ext.extension;
+ if (!content2)
+ throw new Error(`Unrecognized extension value in extension set (${ext}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);
+ inner(content2, prec2);
+ }
+ }
+ inner(extension, Prec_.default);
+ return result.reduce((a, b) => a.concat(b));
+ }
+ function ensureAddr(state, addr) {
+ if (addr & 1)
+ return 2;
+ let idx = addr >> 1;
+ let status = state.status[idx];
+ if (status == 4)
+ throw new Error("Cyclic dependency between fields and/or facets");
+ if (status & 2)
+ return status;
+ state.status[idx] = 4;
+ let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);
+ return state.status[idx] = 2 | changed;
+ }
+ function getAddr(state, addr) {
+ return addr & 1 ? state.config.staticValues[addr >> 1] : state.values[addr >> 1];
+ }
+ var languageData = /* @__PURE__ */ Facet.define();
+ var allowMultipleSelections = /* @__PURE__ */ Facet.define({
+ combine: (values2) => values2.some((v) => v),
+ static: true
+ });
+ var lineSeparator = /* @__PURE__ */ Facet.define({
+ combine: (values2) => values2.length ? values2[0] : void 0,
+ static: true
+ });
+ var changeFilter = /* @__PURE__ */ Facet.define();
+ var transactionFilter = /* @__PURE__ */ Facet.define();
+ var transactionExtender = /* @__PURE__ */ Facet.define();
+ var readOnly = /* @__PURE__ */ Facet.define({
+ combine: (values2) => values2.length ? values2[0] : false
+ });
+ var Annotation = class {
+ /**
+ @internal
+ */
+ constructor(type, value) {
+ this.type = type;
+ this.value = value;
+ }
+ /**
+ Define a new type of annotation.
+ */
+ static define() {
+ return new AnnotationType();
+ }
+ };
+ var AnnotationType = class {
+ /**
+ Create an instance of this annotation.
+ */
+ of(value) {
+ return new Annotation(this, value);
+ }
+ };
+ var StateEffectType = class {
+ /**
+ @internal
+ */
+ constructor(map) {
+ this.map = map;
+ }
+ /**
+ Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this
+ type.
+ */
+ of(value) {
+ return new StateEffect(this, value);
+ }
+ };
+ var StateEffect = class _StateEffect {
+ /**
+ @internal
+ */
+ constructor(type, value) {
+ this.type = type;
+ this.value = value;
+ }
+ /**
+ Map this effect through a position mapping. Will return
+ `undefined` when that ends up deleting the effect.
+ */
+ map(mapping) {
+ let mapped = this.type.map(this.value, mapping);
+ return mapped === void 0 ? void 0 : mapped == this.value ? this : new _StateEffect(this.type, mapped);
+ }
+ /**
+ Tells you whether this effect object is of a given
+ [type](https://codemirror.net/6/docs/ref/#state.StateEffectType).
+ */
+ is(type) {
+ return this.type == type;
+ }
+ /**
+ Define a new effect type. The type parameter indicates the type
+ of values that his effect holds. It should be a type that
+ doesn't include `undefined`, since that is used in
+ [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
+ removed.
+ */
+ static define(spec = {}) {
+ return new StateEffectType(spec.map || ((v) => v));
+ }
+ /**
+ Map an array of effects through a change set.
+ */
+ static mapEffects(effects, mapping) {
+ if (!effects.length)
+ return effects;
+ let result = [];
+ for (let effect of effects) {
+ let mapped = effect.map(mapping);
+ if (mapped)
+ result.push(mapped);
+ }
+ return result;
+ }
+ };
+ StateEffect.reconfigure = /* @__PURE__ */ StateEffect.define();
+ StateEffect.appendConfig = /* @__PURE__ */ StateEffect.define();
+ var Transaction = class _Transaction {
+ constructor(startState, changes, selection, effects, annotations, scrollIntoView3) {
+ this.startState = startState;
+ this.changes = changes;
+ this.selection = selection;
+ this.effects = effects;
+ this.annotations = annotations;
+ this.scrollIntoView = scrollIntoView3;
+ this._doc = null;
+ this._state = null;
+ if (selection)
+ checkSelection(selection, changes.newLength);
+ if (!annotations.some((a) => a.type == _Transaction.time))
+ this.annotations = annotations.concat(_Transaction.time.of(Date.now()));
+ }
+ /**
+ @internal
+ */
+ static create(startState, changes, selection, effects, annotations, scrollIntoView3) {
+ return new _Transaction(startState, changes, selection, effects, annotations, scrollIntoView3);
+ }
+ /**
+ The new document produced by the transaction. Contrary to
+ [`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
+ force the entire new state to be computed right away, so it is
+ recommended that [transaction
+ filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter
+ when they need to look at the new document.
+ */
+ get newDoc() {
+ return this._doc || (this._doc = this.changes.apply(this.startState.doc));
+ }
+ /**
+ The new selection produced by the transaction. If
+ [`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined,
+ this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's
+ current selection through the changes made by the transaction.
+ */
+ get newSelection() {
+ return this.selection || this.startState.selection.map(this.changes);
+ }
+ /**
+ The new state created by the transaction. Computed on demand
+ (but retained for subsequent access), so it is recommended not to
+ access it in [transaction
+ filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
+ */
+ get state() {
+ if (!this._state)
+ this.startState.applyTransaction(this);
+ return this._state;
+ }
+ /**
+ Get the value of the given annotation type, if any.
+ */
+ annotation(type) {
+ for (let ann of this.annotations)
+ if (ann.type == type)
+ return ann.value;
+ return void 0;
+ }
+ /**
+ Indicates whether the transaction changed the document.
+ */
+ get docChanged() {
+ return !this.changes.empty;
+ }
+ /**
+ Indicates whether this transaction reconfigures the state
+ (through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or
+ with a top-level configuration
+ [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
+ */
+ get reconfigured() {
+ return this.startState.config != this.state.config;
+ }
+ /**
+ Returns true if the transaction has a [user
+ event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
+ or more specific than `event`. For example, if the transaction
+ has `"select.pointer"` as user event, `"select"` and
+ `"select.pointer"` will match it.
+ */
+ isUserEvent(event) {
+ let e = this.annotation(_Transaction.userEvent);
+ return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == "."));
+ }
+ };
+ Transaction.time = /* @__PURE__ */ Annotation.define();
+ Transaction.userEvent = /* @__PURE__ */ Annotation.define();
+ Transaction.addToHistory = /* @__PURE__ */ Annotation.define();
+ Transaction.remote = /* @__PURE__ */ Annotation.define();
+ function joinRanges(a, b) {
+ let result = [];
+ for (let iA = 0, iB = 0; ; ) {
+ let from, to;
+ if (iA < a.length && (iB == b.length || b[iB] >= a[iA])) {
+ from = a[iA++];
+ to = a[iA++];
+ } else if (iB < b.length) {
+ from = b[iB++];
+ to = b[iB++];
+ } else
+ return result;
+ if (!result.length || result[result.length - 1] < from)
+ result.push(from, to);
+ else if (result[result.length - 1] < to)
+ result[result.length - 1] = to;
+ }
+ }
+ function mergeTransaction(a, b, sequential) {
+ var _a2;
+ let mapForA, mapForB, changes;
+ if (sequential) {
+ mapForA = b.changes;
+ mapForB = ChangeSet.empty(b.changes.length);
+ changes = a.changes.compose(b.changes);
+ } else {
+ mapForA = b.changes.map(a.changes);
+ mapForB = a.changes.mapDesc(b.changes, true);
+ changes = a.changes.compose(mapForA);
+ }
+ return {
+ changes,
+ selection: b.selection ? b.selection.map(mapForB) : (_a2 = a.selection) === null || _a2 === void 0 ? void 0 : _a2.map(mapForA),
+ effects: StateEffect.mapEffects(a.effects, mapForA).concat(StateEffect.mapEffects(b.effects, mapForB)),
+ annotations: a.annotations.length ? a.annotations.concat(b.annotations) : b.annotations,
+ scrollIntoView: a.scrollIntoView || b.scrollIntoView
+ };
+ }
+ function resolveTransactionInner(state, spec, docSize) {
+ let sel = spec.selection, annotations = asArray(spec.annotations);
+ if (spec.userEvent)
+ annotations = annotations.concat(Transaction.userEvent.of(spec.userEvent));
+ return {
+ changes: spec.changes instanceof ChangeSet ? spec.changes : ChangeSet.of(spec.changes || [], docSize, state.facet(lineSeparator)),
+ selection: sel && (sel instanceof EditorSelection ? sel : EditorSelection.single(sel.anchor, sel.head)),
+ effects: asArray(spec.effects),
+ annotations,
+ scrollIntoView: !!spec.scrollIntoView
+ };
+ }
+ function resolveTransaction(state, specs, filter) {
+ let s = resolveTransactionInner(state, specs.length ? specs[0] : {}, state.doc.length);
+ if (specs.length && specs[0].filter === false)
+ filter = false;
+ for (let i = 1; i < specs.length; i++) {
+ if (specs[i].filter === false)
+ filter = false;
+ let seq = !!specs[i].sequential;
+ s = mergeTransaction(s, resolveTransactionInner(state, specs[i], seq ? s.changes.newLength : state.doc.length), seq);
+ }
+ let tr = Transaction.create(state, s.changes, s.selection, s.effects, s.annotations, s.scrollIntoView);
+ return extendTransaction(filter ? filterTransaction(tr) : tr);
+ }
+ function filterTransaction(tr) {
+ let state = tr.startState;
+ let result = true;
+ for (let filter of state.facet(changeFilter)) {
+ let value = filter(tr);
+ if (value === false) {
+ result = false;
+ break;
+ }
+ if (Array.isArray(value))
+ result = result === true ? value : joinRanges(result, value);
+ }
+ if (result !== true) {
+ let changes, back;
+ if (result === false) {
+ back = tr.changes.invertedDesc;
+ changes = ChangeSet.empty(state.doc.length);
+ } else {
+ let filtered = tr.changes.filter(result);
+ changes = filtered.changes;
+ back = filtered.filtered.mapDesc(filtered.changes).invertedDesc;
+ }
+ tr = Transaction.create(state, changes, tr.selection && tr.selection.map(back), StateEffect.mapEffects(tr.effects, back), tr.annotations, tr.scrollIntoView);
+ }
+ let filters = state.facet(transactionFilter);
+ for (let i = filters.length - 1; i >= 0; i--) {
+ let filtered = filters[i](tr);
+ if (filtered instanceof Transaction)
+ tr = filtered;
+ else if (Array.isArray(filtered) && filtered.length == 1 && filtered[0] instanceof Transaction)
+ tr = filtered[0];
+ else
+ tr = resolveTransaction(state, asArray(filtered), false);
+ }
+ return tr;
+ }
+ function extendTransaction(tr) {
+ let state = tr.startState, extenders = state.facet(transactionExtender), spec = tr;
+ for (let i = extenders.length - 1; i >= 0; i--) {
+ let extension = extenders[i](tr);
+ if (extension && Object.keys(extension).length)
+ spec = mergeTransaction(spec, resolveTransactionInner(state, extension, tr.changes.newLength), true);
+ }
+ return spec == tr ? tr : Transaction.create(state, tr.changes, tr.selection, spec.effects, spec.annotations, spec.scrollIntoView);
+ }
+ var none = [];
+ function asArray(value) {
+ return value == null ? none : Array.isArray(value) ? value : [value];
+ }
+ var CharCategory = /* @__PURE__ */ (function(CharCategory2) {
+ CharCategory2[CharCategory2["Word"] = 0] = "Word";
+ CharCategory2[CharCategory2["Space"] = 1] = "Space";
+ CharCategory2[CharCategory2["Other"] = 2] = "Other";
+ return CharCategory2;
+ })(CharCategory || (CharCategory = {}));
+ var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
+ var wordChar;
+ try {
+ wordChar = /* @__PURE__ */ new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u");
+ } catch (_) {
+ }
+ function hasWordChar(str) {
+ if (wordChar)
+ return wordChar.test(str);
+ for (let i = 0; i < str.length; i++) {
+ let ch = str[i];
+ if (/\w/.test(ch) || ch > "\x80" && (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch)))
+ return true;
+ }
+ return false;
+ }
+ function makeCategorizer(wordChars) {
+ return (char) => {
+ if (!/\S/.test(char))
+ return CharCategory.Space;
+ if (hasWordChar(char))
+ return CharCategory.Word;
+ for (let i = 0; i < wordChars.length; i++)
+ if (char.indexOf(wordChars[i]) > -1)
+ return CharCategory.Word;
+ return CharCategory.Other;
+ };
+ }
+ var EditorState = class _EditorState {
+ constructor(config2, doc2, selection, values2, computeSlot, tr) {
+ this.config = config2;
+ this.doc = doc2;
+ this.selection = selection;
+ this.values = values2;
+ this.status = config2.statusTemplate.slice();
+ this.computeSlot = computeSlot;
+ if (tr)
+ tr._state = this;
+ for (let i = 0; i < this.config.dynamicSlots.length; i++)
+ ensureAddr(this, i << 1);
+ this.computeSlot = null;
+ }
+ field(field, require2 = true) {
+ let addr = this.config.address[field.id];
+ if (addr == null) {
+ if (require2)
+ throw new RangeError("Field is not present in this state");
+ return void 0;
+ }
+ ensureAddr(this, addr);
+ return getAddr(this, addr);
+ }
+ /**
+ Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this
+ state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec)
+ can be passed. Unless
+ [`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the
+ [changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec
+ are assumed to start in the _current_ document (not the document
+ produced by previous specs), and its
+ [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and
+ [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer
+ to the document created by its _own_ changes. The resulting
+ transaction contains the combined effect of all the different
+ specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later
+ specs take precedence over earlier ones.
+ */
+ update(...specs) {
+ return resolveTransaction(this, specs, true);
+ }
+ /**
+ @internal
+ */
+ applyTransaction(tr) {
+ let conf = this.config, { base: base2, compartments } = conf;
+ for (let effect of tr.effects) {
+ if (effect.is(Compartment.reconfigure)) {
+ if (conf) {
+ compartments = /* @__PURE__ */ new Map();
+ conf.compartments.forEach((val, key) => compartments.set(key, val));
+ conf = null;
+ }
+ compartments.set(effect.value.compartment, effect.value.extension);
+ } else if (effect.is(StateEffect.reconfigure)) {
+ conf = null;
+ base2 = effect.value;
+ } else if (effect.is(StateEffect.appendConfig)) {
+ conf = null;
+ base2 = asArray(base2).concat(effect.value);
+ }
+ }
+ let startValues;
+ if (!conf) {
+ conf = Configuration.resolve(base2, compartments, this);
+ let intermediateState = new _EditorState(conf, this.doc, this.selection, conf.dynamicSlots.map(() => null), (state, slot) => slot.reconfigure(state, this), null);
+ startValues = intermediateState.values;
+ } else {
+ startValues = tr.startState.values.slice();
+ }
+ let selection = tr.startState.facet(allowMultipleSelections) ? tr.newSelection : tr.newSelection.asSingle();
+ new _EditorState(conf, tr.newDoc, selection, startValues, (state, slot) => slot.update(state, tr), tr);
+ }
+ /**
+ Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
+ replaces every selection range with the given content.
+ */
+ replaceSelection(text) {
+ if (typeof text == "string")
+ text = this.toText(text);
+ return this.changeByRange((range) => ({
+ changes: { from: range.from, to: range.to, insert: text },
+ range: EditorSelection.cursor(range.from + text.length)
+ }));
+ }
+ /**
+ Create a set of changes and a new selection by running the given
+ function for each range in the active selection. The function
+ can return an optional set of changes (in the coordinate space
+ of the start document), plus an updated range (in the coordinate
+ space of the document produced by the call's own changes). This
+ method will merge all the changes and ranges into a single
+ changeset and selection, and return it as a [transaction
+ spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to
+ [`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
+ */
+ changeByRange(f) {
+ let sel = this.selection;
+ let result1 = f(sel.ranges[0]);
+ let changes = this.changes(result1.changes), ranges = [result1.range];
+ let effects = asArray(result1.effects);
+ for (let i = 1; i < sel.ranges.length; i++) {
+ let result = f(sel.ranges[i]);
+ let newChanges = this.changes(result.changes), newMapped = newChanges.map(changes);
+ for (let j = 0; j < i; j++)
+ ranges[j] = ranges[j].map(newMapped);
+ let mapBy = changes.mapDesc(newChanges, true);
+ ranges.push(result.range.map(mapBy));
+ changes = changes.compose(newMapped);
+ effects = StateEffect.mapEffects(effects, newMapped).concat(StateEffect.mapEffects(asArray(result.effects), mapBy));
+ }
+ return {
+ changes,
+ selection: EditorSelection.create(ranges, sel.mainIndex),
+ effects
+ };
+ }
+ /**
+ Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change
+ description, taking the state's document length and line
+ separator into account.
+ */
+ changes(spec = []) {
+ if (spec instanceof ChangeSet)
+ return spec;
+ return ChangeSet.of(spec, this.doc.length, this.facet(_EditorState.lineSeparator));
+ }
+ /**
+ Using the state's [line
+ separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a
+ [`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
+ */
+ toText(string2) {
+ return Text2.of(string2.split(this.facet(_EditorState.lineSeparator) || DefaultSplit));
+ }
+ /**
+ Return the given range of the document as a string.
+ */
+ sliceDoc(from = 0, to = this.doc.length) {
+ return this.doc.sliceString(from, to, this.lineBreak);
+ }
+ /**
+ Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).
+ */
+ facet(facet) {
+ let addr = this.config.address[facet.id];
+ if (addr == null)
+ return facet.default;
+ ensureAddr(this, addr);
+ return getAddr(this, addr);
+ }
+ /**
+ Convert this state to a JSON-serializable object. When custom
+ fields should be serialized, you can pass them in as an object
+ mapping property names (in the resulting object, which should
+ not use `doc` or `selection`) to fields.
+ */
+ toJSON(fields) {
+ let result = {
+ doc: this.sliceDoc(),
+ selection: this.selection.toJSON()
+ };
+ if (fields)
+ for (let prop in fields) {
+ let value = fields[prop];
+ if (value instanceof StateField && this.config.address[value.id] != null)
+ result[prop] = value.spec.toJSON(this.field(fields[prop]), this);
+ }
+ return result;
+ }
+ /**
+ Deserialize a state from its JSON representation. When custom
+ fields should be deserialized, pass the same object you passed
+ to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as
+ third argument.
+ */
+ static fromJSON(json, config2 = {}, fields) {
+ if (!json || typeof json.doc != "string")
+ throw new RangeError("Invalid JSON representation for EditorState");
+ let fieldInit = [];
+ if (fields)
+ for (let prop in fields) {
+ if (Object.prototype.hasOwnProperty.call(json, prop)) {
+ let field = fields[prop], value = json[prop];
+ fieldInit.push(field.init((state) => field.spec.fromJSON(value, state)));
+ }
+ }
+ return _EditorState.create({
+ doc: json.doc,
+ selection: EditorSelection.fromJSON(json.selection),
+ extensions: config2.extensions ? fieldInit.concat([config2.extensions]) : fieldInit
+ });
+ }
+ /**
+ Create a new state. You'll usually only need this when
+ initializing an editor—updated states are created by applying
+ transactions.
+ */
+ static create(config2 = {}) {
+ let configuration = Configuration.resolve(config2.extensions || [], /* @__PURE__ */ new Map());
+ let doc2 = config2.doc instanceof Text2 ? config2.doc : Text2.of((config2.doc || "").split(configuration.staticFacet(_EditorState.lineSeparator) || DefaultSplit));
+ let selection = !config2.selection ? EditorSelection.single(0) : config2.selection instanceof EditorSelection ? config2.selection : EditorSelection.single(config2.selection.anchor, config2.selection.head);
+ checkSelection(selection, doc2.length);
+ if (!configuration.staticFacet(allowMultipleSelections))
+ selection = selection.asSingle();
+ return new _EditorState(configuration, doc2, selection, configuration.dynamicSlots.map(() => null), (state, slot) => slot.create(state), null);
+ }
+ /**
+ The size (in columns) of a tab in the document, determined by
+ the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet.
+ */
+ get tabSize() {
+ return this.facet(_EditorState.tabSize);
+ }
+ /**
+ Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)
+ string for this state.
+ */
+ get lineBreak() {
+ return this.facet(_EditorState.lineSeparator) || "\n";
+ }
+ /**
+ Returns true when the editor is
+ [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
+ */
+ get readOnly() {
+ return this.facet(readOnly);
+ }
+ /**
+ Look up a translation for the given phrase (via the
+ [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
+ original string if no translation is found.
+
+ If additional arguments are passed, they will be inserted in
+ place of markers like `$1` (for the first value) and `$2`, etc.
+ A single `$` is equivalent to `$1`, and `$$` will produce a
+ literal dollar sign.
+ */
+ phrase(phrase, ...insert2) {
+ for (let map of this.facet(_EditorState.phrases))
+ if (Object.prototype.hasOwnProperty.call(map, phrase)) {
+ phrase = map[phrase];
+ break;
+ }
+ if (insert2.length)
+ phrase = phrase.replace(/\$(\$|\d*)/g, (m, i) => {
+ if (i == "$")
+ return "$";
+ let n = +(i || 1);
+ return !n || n > insert2.length ? m : insert2[n - 1];
+ });
+ return phrase;
+ }
+ /**
+ Find the values for a given language data field, provided by the
+ the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
+
+ Examples of language data fields are...
+
+ - [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
+ comment syntax.
+ - [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
+ for providing language-specific completion sources.
+ - [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
+ characters that should be considered part of words in this
+ language.
+ - [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
+ bracket closing behavior.
+ */
+ languageDataAt(name2, pos, side = -1) {
+ let values2 = [];
+ for (let provider of this.facet(languageData)) {
+ for (let result of provider(this, pos, side)) {
+ if (Object.prototype.hasOwnProperty.call(result, name2))
+ values2.push(result[name2]);
+ }
+ }
+ return values2;
+ }
+ /**
+ Return a function that can categorize strings (expected to
+ represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
+ into one of:
+
+ - Word (contains an alphanumeric character or a character
+ explicitly listed in the local language's `"wordChars"`
+ language data, which should be a string)
+ - Space (contains only whitespace)
+ - Other (anything else)
+ */
+ charCategorizer(at) {
+ let chars = this.languageDataAt("wordChars", at);
+ return makeCategorizer(chars.length ? chars[0] : "");
+ }
+ /**
+ Find the word at the given position, meaning the range
+ containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
+ around it. If no word characters are adjacent to the position,
+ this returns null.
+ */
+ wordAt(pos) {
+ let { text, from, length } = this.doc.lineAt(pos);
+ let cat = this.charCategorizer(pos);
+ let start = pos - from, end = pos - from;
+ while (start > 0) {
+ let prev = findClusterBreak2(text, start, false);
+ if (cat(text.slice(prev, start)) != CharCategory.Word)
+ break;
+ start = prev;
+ }
+ while (end < length) {
+ let next = findClusterBreak2(text, end);
+ if (cat(text.slice(end, next)) != CharCategory.Word)
+ break;
+ end = next;
+ }
+ return start == end ? null : EditorSelection.range(start + from, end + from);
+ }
+ };
+ EditorState.allowMultipleSelections = allowMultipleSelections;
+ EditorState.tabSize = /* @__PURE__ */ Facet.define({
+ combine: (values2) => values2.length ? values2[0] : 4
+ });
+ EditorState.lineSeparator = lineSeparator;
+ EditorState.readOnly = readOnly;
+ EditorState.phrases = /* @__PURE__ */ Facet.define({
+ compare(a, b) {
+ let kA = Object.keys(a), kB = Object.keys(b);
+ return kA.length == kB.length && kA.every((k) => a[k] == b[k]);
+ }
+ });
+ EditorState.languageData = languageData;
+ EditorState.changeFilter = changeFilter;
+ EditorState.transactionFilter = transactionFilter;
+ EditorState.transactionExtender = transactionExtender;
+ Compartment.reconfigure = /* @__PURE__ */ StateEffect.define();
+ function combineConfig(configs, defaults2, combine = {}) {
+ let result = {};
+ for (let config2 of configs)
+ for (let key of Object.keys(config2)) {
+ let value = config2[key], current = result[key];
+ if (current === void 0)
+ result[key] = value;
+ else if (current === value || value === void 0) ;
+ else if (Object.hasOwnProperty.call(combine, key))
+ result[key] = combine[key](current, value);
+ else
+ throw new Error("Config merge conflict for field " + key);
+ }
+ for (let key in defaults2)
+ if (result[key] === void 0)
+ result[key] = defaults2[key];
+ return result;
+ }
+ var RangeValue = class {
+ /**
+ Compare this value with another value. Used when comparing
+ rangesets. The default implementation compares by identity.
+ Unless you are only creating a fixed number of unique instances
+ of your value type, it is a good idea to implement this
+ properly.
+ */
+ eq(other) {
+ return this == other;
+ }
+ /**
+ Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
+ */
+ range(from, to = from) {
+ return Range.create(from, to, this);
+ }
+ };
+ 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);
+ }
+ var Range = class _Range {
+ constructor(from, to, value) {
+ this.from = from;
+ this.to = to;
+ this.value = value;
+ }
+ /**
+ @internal
+ */
+ static create(from, to, value) {
+ return new _Range(from, to, value);
+ }
+ };
+ function cmpRange(a, b) {
+ return a.from - b.from || a.value.startSide - b.value.startSide;
+ }
+ var Chunk = class _Chunk {
+ constructor(from, to, value, maxPoint) {
+ this.from = from;
+ this.to = to;
+ this.value = value;
+ this.maxPoint = maxPoint;
+ }
+ get length() {
+ return this.to[this.to.length - 1];
+ }
+ // Find the index of the given position and side. Use the ranges'
+ // `from` pos when `end == false`, `to` when `end == true`.
+ findIndex(pos, side, end, startAt = 0) {
+ let arr = end ? this.to : this.from;
+ for (let lo = startAt, hi = arr.length; ; ) {
+ if (lo == hi)
+ return lo;
+ let mid = lo + hi >> 1;
+ let diff = arr[mid] - pos || (end ? this.value[mid].endSide : this.value[mid].startSide) - side;
+ if (mid == lo)
+ return diff >= 0 ? lo : hi;
+ if (diff >= 0)
+ hi = mid;
+ else
+ lo = mid + 1;
+ }
+ }
+ between(offset, from, to, f) {
+ for (let i = this.findIndex(from, -1e9, true), e = this.findIndex(to, 1e9, false, i); i < e; i++)
+ if (f(this.from[i] + offset, this.to[i] + offset, this.value[i]) === false)
+ return false;
+ }
+ map(offset, changes) {
+ let value = [], from = [], to = [], newPos = -1, maxPoint = -1;
+ for (let i = 0; i < this.value.length; i++) {
+ let val = this.value[i], curFrom = this.from[i] + offset, curTo = this.to[i] + offset, newFrom, newTo;
+ if (curFrom == curTo) {
+ let mapped = changes.mapPos(curFrom, val.startSide, val.mapMode);
+ if (mapped == null)
+ continue;
+ newFrom = newTo = mapped;
+ if (val.startSide != val.endSide) {
+ newTo = changes.mapPos(curFrom, val.endSide);
+ if (newTo < newFrom)
+ continue;
+ }
+ } else {
+ newFrom = changes.mapPos(curFrom, val.startSide);
+ newTo = changes.mapPos(curTo, val.endSide);
+ if (newFrom > newTo || newFrom == newTo && val.startSide > 0 && val.endSide <= 0)
+ continue;
+ }
+ if ((newTo - newFrom || val.endSide - val.startSide) < 0)
+ continue;
+ if (newPos < 0)
+ newPos = newFrom;
+ if (val.point)
+ maxPoint = Math.max(maxPoint, newTo - newFrom);
+ value.push(val);
+ from.push(newFrom - newPos);
+ to.push(newTo - newPos);
+ }
+ return { mapped: value.length ? new _Chunk(from, to, value, maxPoint) : null, pos: newPos };
+ }
+ };
+ var RangeSet = class _RangeSet {
+ constructor(chunkPos, chunk, nextLayer, maxPoint) {
+ this.chunkPos = chunkPos;
+ this.chunk = chunk;
+ this.nextLayer = nextLayer;
+ this.maxPoint = maxPoint;
+ }
+ /**
+ @internal
+ */
+ static create(chunkPos, chunk, nextLayer, maxPoint) {
+ return new _RangeSet(chunkPos, chunk, nextLayer, maxPoint);
+ }
+ /**
+ @internal
+ */
+ get length() {
+ let last = this.chunk.length - 1;
+ return last < 0 ? 0 : Math.max(this.chunkEnd(last), this.nextLayer.length);
+ }
+ /**
+ The number of ranges in the set.
+ */
+ get size() {
+ if (this.isEmpty)
+ return 0;
+ let size = this.nextLayer.size;
+ for (let chunk of this.chunk)
+ size += chunk.value.length;
+ return size;
+ }
+ /**
+ @internal
+ */
+ chunkEnd(index) {
+ return this.chunkPos[index] + this.chunk[index].length;
+ }
+ /**
+ Update the range set, optionally adding new ranges or filtering
+ out existing ones.
+
+ (Note: The type parameter is just there as a kludge to work
+ around TypeScript variance issues that prevented `RangeSet`
+ from being a subtype of `RangeSet` when `X` is a subtype of
+ `Y`.)
+ */
+ update(updateSpec) {
+ let { add = [], sort = false, filterFrom = 0, filterTo = this.length } = updateSpec;
+ let filter = updateSpec.filter;
+ if (add.length == 0 && !filter)
+ return this;
+ if (sort)
+ add = add.slice().sort(cmpRange);
+ if (this.isEmpty)
+ return add.length ? _RangeSet.of(add) : this;
+ let cur2 = new LayerCursor(this, null, -1).goto(0), i = 0, spill = [];
+ let builder = new RangeSetBuilder();
+ while (cur2.value || i < add.length) {
+ if (i < add.length && (cur2.from - add[i].from || cur2.startSide - add[i].value.startSide) >= 0) {
+ let range = add[i++];
+ if (!builder.addInner(range.from, range.to, range.value))
+ spill.push(range);
+ } else if (cur2.rangeIndex == 1 && cur2.chunkIndex < this.chunk.length && (i == add.length || this.chunkEnd(cur2.chunkIndex) < add[i].from) && (!filter || filterFrom > this.chunkEnd(cur2.chunkIndex) || filterTo < this.chunkPos[cur2.chunkIndex]) && builder.addChunk(this.chunkPos[cur2.chunkIndex], this.chunk[cur2.chunkIndex])) {
+ cur2.nextChunk();
+ } else {
+ if (!filter || filterFrom > cur2.to || filterTo < cur2.from || filter(cur2.from, cur2.to, cur2.value)) {
+ if (!builder.addInner(cur2.from, cur2.to, cur2.value))
+ spill.push(Range.create(cur2.from, cur2.to, cur2.value));
+ }
+ cur2.next();
+ }
+ }
+ return builder.finishInner(this.nextLayer.isEmpty && !spill.length ? _RangeSet.empty : this.nextLayer.update({ add: spill, filter, filterFrom, filterTo }));
+ }
+ /**
+ Map this range set through a set of changes, return the new set.
+ */
+ map(changes) {
+ if (changes.empty || this.isEmpty)
+ return this;
+ let chunks = [], chunkPos = [], maxPoint = -1;
+ for (let i = 0; i < this.chunk.length; i++) {
+ let start = this.chunkPos[i], chunk = this.chunk[i];
+ let touch = changes.touchesRange(start, start + chunk.length);
+ if (touch === false) {
+ maxPoint = Math.max(maxPoint, chunk.maxPoint);
+ chunks.push(chunk);
+ chunkPos.push(changes.mapPos(start));
+ } else if (touch === true) {
+ let { mapped, pos } = chunk.map(start, changes);
+ if (mapped) {
+ maxPoint = Math.max(maxPoint, mapped.maxPoint);
+ chunks.push(mapped);
+ chunkPos.push(pos);
+ }
+ }
+ }
+ let next = this.nextLayer.map(changes);
+ return chunks.length == 0 ? next : new _RangeSet(chunkPos, chunks, next || _RangeSet.empty, maxPoint);
+ }
+ /**
+ Iterate over the ranges that touch the region `from` to `to`,
+ calling `f` for each. There is no guarantee that the ranges will
+ be reported in any specific order. When the callback returns
+ `false`, iteration stops.
+ */
+ between(from, to, f) {
+ if (this.isEmpty)
+ return;
+ for (let i = 0; i < this.chunk.length; i++) {
+ let start = this.chunkPos[i], chunk = this.chunk[i];
+ if (to >= start && from <= start + chunk.length && chunk.between(start, from - start, to - start, f) === false)
+ return;
+ }
+ this.nextLayer.between(from, to, f);
+ }
+ /**
+ Iterate over the ranges in this set, in order, including all
+ ranges that end at or after `from`.
+ */
+ iter(from = 0) {
+ return HeapCursor.from([this]).goto(from);
+ }
+ /**
+ @internal
+ */
+ get isEmpty() {
+ return this.nextLayer == this;
+ }
+ /**
+ Iterate over the ranges in a collection of sets, in order,
+ starting from `from`.
+ */
+ static iter(sets, from = 0) {
+ return HeapCursor.from(sets).goto(from);
+ }
+ /**
+ Iterate over two groups of sets, calling methods on `comparator`
+ to notify it of possible differences.
+ */
+ static compare(oldSets, newSets, textDiff, comparator, minPointSize = -1) {
+ let a = oldSets.filter((set) => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);
+ let b = newSets.filter((set) => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);
+ let sharedChunks = findSharedChunks(a, b, textDiff);
+ let sideA = new SpanCursor(a, sharedChunks, minPointSize);
+ let sideB = new SpanCursor(b, sharedChunks, minPointSize);
+ textDiff.iterGaps((fromA, fromB, length) => compare(sideA, fromA, sideB, fromB, length, comparator));
+ if (textDiff.empty && textDiff.length == 0)
+ compare(sideA, 0, sideB, 0, 0, comparator);
+ }
+ /**
+ Compare the contents of two groups of range sets, returning true
+ if they are equivalent in the given range.
+ */
+ static eq(oldSets, newSets, from = 0, to) {
+ if (to == null)
+ to = 1e9 - 1;
+ let a = oldSets.filter((set) => !set.isEmpty && newSets.indexOf(set) < 0);
+ let b = newSets.filter((set) => !set.isEmpty && oldSets.indexOf(set) < 0);
+ if (a.length != b.length)
+ return false;
+ if (!a.length)
+ return true;
+ let sharedChunks = findSharedChunks(a, b);
+ let sideA = new SpanCursor(a, sharedChunks, 0).goto(from), sideB = new SpanCursor(b, sharedChunks, 0).goto(from);
+ for (; ; ) {
+ if (sideA.to != sideB.to || !sameValues(sideA.active, sideB.active) || sideA.point && (!sideB.point || !cmpVal(sideA.point, sideB.point)))
+ return false;
+ if (sideA.to > to)
+ return true;
+ sideA.next();
+ sideB.next();
+ }
+ }
+ /**
+ Iterate over a group of range sets at the same time, notifying
+ the iterator about the ranges covering every given piece of
+ content. Returns the open count (see
+ [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
+ of the iteration.
+ */
+ static spans(sets, from, to, iterator, minPointSize = -1) {
+ let cursor = new SpanCursor(sets, null, minPointSize).goto(from), pos = from;
+ let openRanges = cursor.openStart;
+ for (; ; ) {
+ let curTo = Math.min(cursor.to, to);
+ if (cursor.point) {
+ let active = cursor.activeForPoint(cursor.to);
+ let openCount = cursor.pointFrom < from ? active.length + 1 : cursor.point.startSide < 0 ? active.length : Math.min(active.length, openRanges);
+ iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
+ openRanges = Math.min(cursor.openEnd(curTo), active.length);
+ } else if (curTo > pos) {
+ iterator.span(pos, curTo, cursor.active, openRanges);
+ openRanges = cursor.openEnd(curTo);
+ }
+ if (cursor.to > to)
+ return openRanges + (cursor.point && cursor.to > to ? 1 : 0);
+ pos = cursor.to;
+ cursor.next();
+ }
+ }
+ /**
+ Create a range set for the given range or array of ranges. By
+ default, this expects the ranges to be _sorted_ (by start
+ position and, if two start at the same position,
+ `value.startSide`). You can pass `true` as second argument to
+ cause the method to sort them.
+ */
+ static of(ranges, sort = false) {
+ let build = new RangeSetBuilder();
+ for (let range of ranges instanceof Range ? [ranges] : sort ? lazySort(ranges) : ranges)
+ build.add(range.from, range.to, range.value);
+ return build.finish();
+ }
+ /**
+ Join an array of range sets into a single set.
+ */
+ static join(sets) {
+ if (!sets.length)
+ return _RangeSet.empty;
+ let result = sets[sets.length - 1];
+ for (let i = sets.length - 2; i >= 0; i--) {
+ for (let layer = sets[i]; layer != _RangeSet.empty; layer = layer.nextLayer)
+ result = new _RangeSet(layer.chunkPos, layer.chunk, result, Math.max(layer.maxPoint, result.maxPoint));
+ }
+ return result;
+ }
+ };
+ RangeSet.empty = /* @__PURE__ */ new RangeSet([], [], null, -1);
+ function lazySort(ranges) {
+ if (ranges.length > 1)
+ for (let prev = ranges[0], i = 1; i < ranges.length; i++) {
+ let cur2 = ranges[i];
+ if (cmpRange(prev, cur2) > 0)
+ return ranges.slice().sort(cmpRange);
+ prev = cur2;
+ }
+ return ranges;
+ }
+ RangeSet.empty.nextLayer = RangeSet.empty;
+ var RangeSetBuilder = class _RangeSetBuilder {
+ finishChunk(newArrays) {
+ this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
+ this.chunkPos.push(this.chunkStart);
+ this.chunkStart = -1;
+ this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
+ this.maxPoint = -1;
+ if (newArrays) {
+ this.from = [];
+ this.to = [];
+ this.value = [];
+ }
+ }
+ /**
+ Create an empty builder.
+ */
+ constructor() {
+ this.chunks = [];
+ this.chunkPos = [];
+ this.chunkStart = -1;
+ this.last = null;
+ this.lastFrom = -1e9;
+ this.lastTo = -1e9;
+ this.from = [];
+ this.to = [];
+ this.value = [];
+ this.maxPoint = -1;
+ this.setMaxPoint = -1;
+ this.nextLayer = null;
+ }
+ /**
+ Add a range. Ranges should be added in sorted (by `from` and
+ `value.startSide`) order.
+ */
+ add(from, to, value) {
+ if (!this.addInner(from, to, value))
+ (this.nextLayer || (this.nextLayer = new _RangeSetBuilder())).add(from, to, value);
+ }
+ /**
+ @internal
+ */
+ addInner(from, to, value) {
+ let diff = from - this.lastTo || value.startSide - this.last.endSide;
+ if (diff <= 0 && (from - this.lastFrom || value.startSide - this.last.startSide) < 0)
+ throw new Error("Ranges must be added sorted by `from` position and `startSide`");
+ if (diff < 0)
+ return false;
+ if (this.from.length == 250)
+ this.finishChunk(true);
+ if (this.chunkStart < 0)
+ this.chunkStart = from;
+ this.from.push(from - this.chunkStart);
+ this.to.push(to - this.chunkStart);
+ this.last = value;
+ this.lastFrom = from;
+ this.lastTo = to;
+ this.value.push(value);
+ if (value.point)
+ this.maxPoint = Math.max(this.maxPoint, to - from);
+ return true;
+ }
+ /**
+ @internal
+ */
+ addChunk(from, chunk) {
+ if ((from - this.lastTo || chunk.value[0].startSide - this.last.endSide) < 0)
+ return false;
+ if (this.from.length)
+ this.finishChunk(true);
+ this.setMaxPoint = Math.max(this.setMaxPoint, chunk.maxPoint);
+ this.chunks.push(chunk);
+ this.chunkPos.push(from);
+ let last = chunk.value.length - 1;
+ this.last = chunk.value[last];
+ this.lastFrom = chunk.from[last] + from;
+ this.lastTo = chunk.to[last] + from;
+ return true;
+ }
+ /**
+ Finish the range set. Returns the new set. The builder can't be
+ used anymore after this has been called.
+ */
+ finish() {
+ return this.finishInner(RangeSet.empty);
+ }
+ /**
+ @internal
+ */
+ finishInner(next) {
+ if (this.from.length)
+ this.finishChunk(false);
+ if (this.chunks.length == 0)
+ return next;
+ let result = RangeSet.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(next) : next, this.setMaxPoint);
+ this.from = null;
+ return result;
+ }
+ };
+ function findSharedChunks(a, b, textDiff) {
+ let inA = /* @__PURE__ */ new Map();
+ for (let set of a)
+ for (let i = 0; i < set.chunk.length; i++)
+ if (set.chunk[i].maxPoint <= 0)
+ inA.set(set.chunk[i], set.chunkPos[i]);
+ let shared = /* @__PURE__ */ new Set();
+ for (let set of b)
+ for (let i = 0; i < set.chunk.length; i++) {
+ let known = inA.get(set.chunk[i]);
+ if (known != null && (textDiff ? textDiff.mapPos(known) : known) == set.chunkPos[i] && !(textDiff === null || textDiff === void 0 ? void 0 : textDiff.touchesRange(known, known + set.chunk[i].length)))
+ shared.add(set.chunk[i]);
+ }
+ return shared;
+ }
+ var LayerCursor = class {
+ constructor(layer, skip, minPoint, rank = 0) {
+ this.layer = layer;
+ this.skip = skip;
+ this.minPoint = minPoint;
+ this.rank = rank;
+ }
+ get startSide() {
+ return this.value ? this.value.startSide : 0;
+ }
+ get endSide() {
+ return this.value ? this.value.endSide : 0;
+ }
+ goto(pos, side = -1e9) {
+ this.chunkIndex = this.rangeIndex = 0;
+ this.gotoInner(pos, side, false);
+ return this;
+ }
+ gotoInner(pos, side, forward) {
+ while (this.chunkIndex < this.layer.chunk.length) {
+ let next = this.layer.chunk[this.chunkIndex];
+ if (!(this.skip && this.skip.has(next) || this.layer.chunkEnd(this.chunkIndex) < pos || next.maxPoint < this.minPoint))
+ break;
+ this.chunkIndex++;
+ forward = false;
+ }
+ if (this.chunkIndex < this.layer.chunk.length) {
+ let rangeIndex = this.layer.chunk[this.chunkIndex].findIndex(pos - this.layer.chunkPos[this.chunkIndex], side, true);
+ if (!forward || this.rangeIndex < rangeIndex)
+ this.setRangeIndex(rangeIndex);
+ }
+ this.next();
+ }
+ forward(pos, side) {
+ if ((this.to - pos || this.endSide - side) < 0)
+ this.gotoInner(pos, side, true);
+ }
+ next() {
+ for (; ; ) {
+ if (this.chunkIndex == this.layer.chunk.length) {
+ this.from = this.to = 1e9;
+ this.value = null;
+ break;
+ } else {
+ let chunkPos = this.layer.chunkPos[this.chunkIndex], chunk = this.layer.chunk[this.chunkIndex];
+ let from = chunkPos + chunk.from[this.rangeIndex];
+ this.from = from;
+ this.to = chunkPos + chunk.to[this.rangeIndex];
+ this.value = chunk.value[this.rangeIndex];
+ this.setRangeIndex(this.rangeIndex + 1);
+ if (this.minPoint < 0 || this.value.point && this.to - this.from >= this.minPoint)
+ break;
+ }
+ }
+ }
+ setRangeIndex(index) {
+ if (index == this.layer.chunk[this.chunkIndex].value.length) {
+ this.chunkIndex++;
+ if (this.skip) {
+ while (this.chunkIndex < this.layer.chunk.length && this.skip.has(this.layer.chunk[this.chunkIndex]))
+ this.chunkIndex++;
+ }
+ this.rangeIndex = 0;
+ } else {
+ this.rangeIndex = index;
+ }
+ }
+ nextChunk() {
+ this.chunkIndex++;
+ this.rangeIndex = 0;
+ this.next();
+ }
+ compare(other) {
+ return this.from - other.from || this.startSide - other.startSide || this.rank - other.rank || this.to - other.to || this.endSide - other.endSide;
+ }
+ };
+ var HeapCursor = class _HeapCursor {
+ constructor(heap) {
+ this.heap = heap;
+ }
+ static from(sets, skip = null, minPoint = -1) {
+ let heap = [];
+ for (let i = 0; i < sets.length; i++) {
+ for (let cur2 = sets[i]; !cur2.isEmpty; cur2 = cur2.nextLayer) {
+ if (cur2.maxPoint >= minPoint)
+ heap.push(new LayerCursor(cur2, skip, minPoint, i));
+ }
+ }
+ return heap.length == 1 ? heap[0] : new _HeapCursor(heap);
+ }
+ get startSide() {
+ return this.value ? this.value.startSide : 0;
+ }
+ goto(pos, side = -1e9) {
+ for (let cur2 of this.heap)
+ cur2.goto(pos, side);
+ for (let i = this.heap.length >> 1; i >= 0; i--)
+ heapBubble(this.heap, i);
+ this.next();
+ return this;
+ }
+ forward(pos, side) {
+ for (let cur2 of this.heap)
+ cur2.forward(pos, side);
+ for (let i = this.heap.length >> 1; i >= 0; i--)
+ heapBubble(this.heap, i);
+ if ((this.to - pos || this.value.endSide - side) < 0)
+ this.next();
+ }
+ next() {
+ if (this.heap.length == 0) {
+ this.from = this.to = 1e9;
+ this.value = null;
+ this.rank = -1;
+ } else {
+ let top2 = this.heap[0];
+ this.from = top2.from;
+ this.to = top2.to;
+ this.value = top2.value;
+ this.rank = top2.rank;
+ if (top2.value)
+ top2.next();
+ heapBubble(this.heap, 0);
+ }
+ }
+ };
+ function heapBubble(heap, index) {
+ for (let cur2 = heap[index]; ; ) {
+ let childIndex = (index << 1) + 1;
+ if (childIndex >= heap.length)
+ break;
+ let child = heap[childIndex];
+ if (childIndex + 1 < heap.length && child.compare(heap[childIndex + 1]) >= 0) {
+ child = heap[childIndex + 1];
+ childIndex++;
+ }
+ if (cur2.compare(child) < 0)
+ break;
+ heap[childIndex] = cur2;
+ heap[index] = child;
+ index = childIndex;
+ }
+ }
+ var SpanCursor = class {
+ constructor(sets, skip, minPoint) {
+ this.minPoint = minPoint;
+ this.active = [];
+ this.activeTo = [];
+ this.activeRank = [];
+ this.minActive = -1;
+ this.point = null;
+ this.pointFrom = 0;
+ this.pointRank = 0;
+ this.to = -1e9;
+ this.endSide = 0;
+ this.openStart = -1;
+ this.cursor = HeapCursor.from(sets, skip, minPoint);
+ }
+ goto(pos, side = -1e9) {
+ this.cursor.goto(pos, side);
+ this.active.length = this.activeTo.length = this.activeRank.length = 0;
+ this.minActive = -1;
+ this.to = pos;
+ this.endSide = side;
+ this.openStart = -1;
+ this.next();
+ return this;
+ }
+ forward(pos, side) {
+ while (this.minActive > -1 && (this.activeTo[this.minActive] - pos || this.active[this.minActive].endSide - side) < 0)
+ this.removeActive(this.minActive);
+ this.cursor.forward(pos, side);
+ }
+ removeActive(index) {
+ remove(this.active, index);
+ remove(this.activeTo, index);
+ remove(this.activeRank, index);
+ this.minActive = findMinIndex(this.active, this.activeTo);
+ }
+ addActive(trackOpen) {
+ let i = 0, { value, to, rank } = this.cursor;
+ while (i < this.activeRank.length && (rank - this.activeRank[i] || to - this.activeTo[i]) > 0)
+ i++;
+ insert(this.active, i, value);
+ insert(this.activeTo, i, to);
+ insert(this.activeRank, i, rank);
+ if (trackOpen)
+ insert(trackOpen, i, this.cursor.from);
+ this.minActive = findMinIndex(this.active, this.activeTo);
+ }
+ // After calling this, if `this.point` != null, the next range is a
+ // point. Otherwise, it's a regular range, covered by `this.active`.
+ next() {
+ let from = this.to, wasPoint = this.point;
+ this.point = null;
+ let trackOpen = this.openStart < 0 ? [] : null;
+ for (; ; ) {
+ let a = this.minActive;
+ if (a > -1 && (this.activeTo[a] - this.cursor.from || this.active[a].endSide - this.cursor.startSide) < 0) {
+ if (this.activeTo[a] > from) {
+ this.to = this.activeTo[a];
+ this.endSide = this.active[a].endSide;
+ break;
+ }
+ this.removeActive(a);
+ if (trackOpen)
+ remove(trackOpen, a);
+ } else if (!this.cursor.value) {
+ this.to = this.endSide = 1e9;
+ break;
+ } else if (this.cursor.from > from) {
+ this.to = this.cursor.from;
+ this.endSide = this.cursor.startSide;
+ break;
+ } else {
+ let nextVal = this.cursor.value;
+ if (!nextVal.point) {
+ this.addActive(trackOpen);
+ this.cursor.next();
+ } else if (wasPoint && this.cursor.to == this.to && this.cursor.from < this.cursor.to) {
+ this.cursor.next();
+ } else {
+ this.point = nextVal;
+ this.pointFrom = this.cursor.from;
+ this.pointRank = this.cursor.rank;
+ this.to = this.cursor.to;
+ this.endSide = nextVal.endSide;
+ this.cursor.next();
+ this.forward(this.to, this.endSide);
+ break;
+ }
+ }
+ }
+ if (trackOpen) {
+ this.openStart = 0;
+ for (let i = trackOpen.length - 1; i >= 0 && trackOpen[i] < from; i--)
+ this.openStart++;
+ }
+ }
+ activeForPoint(to) {
+ if (!this.active.length)
+ return this.active;
+ let active = [];
+ for (let i = this.active.length - 1; i >= 0; i--) {
+ if (this.activeRank[i] < this.pointRank)
+ break;
+ if (this.activeTo[i] > to || this.activeTo[i] == to && this.active[i].endSide >= this.point.endSide)
+ active.push(this.active[i]);
+ }
+ return active.reverse();
+ }
+ openEnd(to) {
+ let open = 0;
+ for (let i = this.activeTo.length - 1; i >= 0 && this.activeTo[i] > to; i--)
+ open++;
+ return open;
+ }
+ };
+ function compare(a, startA, b, startB, length, comparator) {
+ a.goto(startA);
+ b.goto(startB);
+ let endB = startB + length;
+ let pos = startB, dPos = startB - startA;
+ 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);
+ 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;
+ pos = end;
+ if (diff <= 0)
+ a.next();
+ if (diff >= 0)
+ b.next();
+ }
+ }
+ function sameValues(a, b) {
+ if (a.length != b.length)
+ return false;
+ for (let i = 0; i < a.length; i++)
+ if (a[i] != b[i] && !cmpVal(a[i], b[i]))
+ return false;
+ return true;
+ }
+ function remove(array, index) {
+ for (let i = index, e = array.length - 1; i < e; i++)
+ array[i] = array[i + 1];
+ array.pop();
+ }
+ function insert(array, index, value) {
+ for (let i = array.length - 1; i >= index; i--)
+ array[i + 1] = array[i];
+ array[index] = value;
+ }
+ function findMinIndex(value, array) {
+ let found = -1, foundPos = 1e9;
+ for (let i = 0; i < array.length; i++)
+ if ((array[i] - foundPos || value[i].endSide - value[found].endSide) < 0) {
+ found = i;
+ foundPos = array[i];
+ }
+ return found;
+ }
+ function countColumn(string2, tabSize, to = string2.length) {
+ let n = 0;
+ for (let i = 0; i < to && i < string2.length; ) {
+ if (string2.charCodeAt(i) == 9) {
+ n += tabSize - n % tabSize;
+ i++;
+ } else {
+ n++;
+ i = findClusterBreak2(string2, i);
+ }
+ }
+ return n;
+ }
+ function findColumn(string2, col, tabSize, strict) {
+ for (let i = 0, n = 0; ; ) {
+ if (n >= col)
+ return i;
+ if (i == string2.length)
+ break;
+ n += string2.charCodeAt(i) == 9 ? tabSize - n % tabSize : 1;
+ i = findClusterBreak2(string2, i);
+ }
+ return strict === true ? -1 : string2.length;
+ }
+
+ // node_modules/style-mod/src/style-mod.js
+ var C = "\u037C";
+ var COUNT = typeof Symbol == "undefined" ? "__" + C : Symbol.for(C);
+ var SET = typeof Symbol == "undefined" ? "__styleSet" + Math.floor(Math.random() * 1e8) : /* @__PURE__ */ Symbol("styleSet");
+ var top = typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : {};
+ var StyleModule = class {
+ // :: (Object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{{ .Path }}
+
+
+
+
+{{ range .Entries }}
+
+
+
+
+{{ if .IsDir }}{{ else }}{{ end }}
+
+
+
+{{ .Name }}
+
+
+
+{{ if .IsDir }}
+{{ .ChildCount }} items
+{{ else }}
+{{ formatBytes .Size }}
+{{ end }}
+
+
+
+{{ if not .IsDir }}
+{{ formatUnix .UpdatedAt }}
+{{ end }}
+
+
+
+
+{{ end }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+