From f1171307cde554d84b7ca9148713bfc80cdd0f1d Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 00:19:18 +0100 Subject: [PATCH 01/12] Studio map app: Electron studio for the Iris bridge A standalone Electron + React + Tailwind + shadcn/ui app that connects to the localhost bridge `/iris studio map` opens and draws the world map with the v3e studio's views, shortcuts, hover card, legend and styling. - Finds running bridges from ~/.iris/studio/bridges and iris-studio:// links - Biome, region, height and biome layer views from 128-pixel tiles - Coarser previews first, so the screen fills sooner, then sharpens - Hover card with Shift details, legend census with click to highlight - Ctrl+click teleport, Alt+click open file, right-click menu - Light, dark and system themes from the v3e studio palette --- .gitignore | 4 + components.json | 21 + electron.vite.config.ts | 21 + package-lock.json | 4525 +++++++++++++++++ package.json | 39 + src/main/index.ts | 124 + src/preload/index.ts | 16 + src/renderer/index.html | 15 + src/renderer/src/App.tsx | 63 + src/renderer/src/bridge/BridgeClient.ts | 141 + src/renderer/src/bridge/tileDecoding.ts | 44 + src/renderer/src/bridge/types.ts | 70 + src/renderer/src/components/ui/button.tsx | 63 + .../src/components/ui/context-menu.tsx | 249 + src/renderer/src/components/ui/dialog.tsx | 158 + src/renderer/src/components/ui/input.tsx | 20 + src/renderer/src/components/ui/kbd.tsx | 28 + .../src/components/ui/scroll-area.tsx | 57 + src/renderer/src/components/ui/separator.tsx | 25 + src/renderer/src/components/ui/toggle.tsx | 44 + src/renderer/src/components/ui/tooltip.tsx | 56 + src/renderer/src/css.d.ts | 1 + src/renderer/src/env.d.ts | 9 + src/renderer/src/lib/utils.ts | 6 + src/renderer/src/main.tsx | 13 + src/renderer/src/map/MapController.ts | 406 ++ src/renderer/src/map/TileStore.ts | 167 + src/renderer/src/map/census.ts | 78 + src/renderer/src/map/heightColors.ts | 76 + src/renderer/src/map/map.test.ts | 178 + src/renderer/src/map/tileStyle.ts | 150 + src/renderer/src/map/viewport.ts | 93 + src/renderer/src/studio/ConnectScreen.tsx | 93 + src/renderer/src/studio/HelpDialog.tsx | 49 + src/renderer/src/studio/HoverCard.tsx | 137 + src/renderer/src/studio/Legend.tsx | 72 + src/renderer/src/studio/MapCanvas.tsx | 203 + src/renderer/src/studio/MapStudio.tsx | 358 ++ src/renderer/src/studio/StatusBar.tsx | 54 + src/renderer/src/studio/StudioToolbar.tsx | 125 + src/renderer/src/studio/ViewList.tsx | 61 + src/renderer/src/studio/colors.ts | 4 + src/renderer/src/studio/shortcuts.ts | 72 + src/renderer/src/studio/theme.ts | 33 + src/renderer/src/styles.css | 111 + src/shared/bridge.ts | 37 + tsconfig.json | 19 + 47 files changed, 8388 insertions(+) create mode 100644 .gitignore create mode 100644 components.json create mode 100644 electron.vite.config.ts create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/main/index.ts create mode 100644 src/preload/index.ts create mode 100644 src/renderer/index.html create mode 100644 src/renderer/src/App.tsx create mode 100644 src/renderer/src/bridge/BridgeClient.ts create mode 100644 src/renderer/src/bridge/tileDecoding.ts create mode 100644 src/renderer/src/bridge/types.ts create mode 100644 src/renderer/src/components/ui/button.tsx create mode 100644 src/renderer/src/components/ui/context-menu.tsx create mode 100644 src/renderer/src/components/ui/dialog.tsx create mode 100644 src/renderer/src/components/ui/input.tsx create mode 100644 src/renderer/src/components/ui/kbd.tsx create mode 100644 src/renderer/src/components/ui/scroll-area.tsx create mode 100644 src/renderer/src/components/ui/separator.tsx create mode 100644 src/renderer/src/components/ui/toggle.tsx create mode 100644 src/renderer/src/components/ui/tooltip.tsx create mode 100644 src/renderer/src/css.d.ts create mode 100644 src/renderer/src/env.d.ts create mode 100644 src/renderer/src/lib/utils.ts create mode 100644 src/renderer/src/main.tsx create mode 100644 src/renderer/src/map/MapController.ts create mode 100644 src/renderer/src/map/TileStore.ts create mode 100644 src/renderer/src/map/census.ts create mode 100644 src/renderer/src/map/heightColors.ts create mode 100644 src/renderer/src/map/map.test.ts create mode 100644 src/renderer/src/map/tileStyle.ts create mode 100644 src/renderer/src/map/viewport.ts create mode 100644 src/renderer/src/studio/ConnectScreen.tsx create mode 100644 src/renderer/src/studio/HelpDialog.tsx create mode 100644 src/renderer/src/studio/HoverCard.tsx create mode 100644 src/renderer/src/studio/Legend.tsx create mode 100644 src/renderer/src/studio/MapCanvas.tsx create mode 100644 src/renderer/src/studio/MapStudio.tsx create mode 100644 src/renderer/src/studio/StatusBar.tsx create mode 100644 src/renderer/src/studio/StudioToolbar.tsx create mode 100644 src/renderer/src/studio/ViewList.tsx create mode 100644 src/renderer/src/studio/colors.ts create mode 100644 src/renderer/src/studio/shortcuts.ts create mode 100644 src/renderer/src/studio/theme.ts create mode 100644 src/renderer/src/styles.css create mode 100644 src/shared/bridge.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..3794c4269 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +out/ +dist/ +*.log diff --git a/components.json b/components.json new file mode 100644 index 000000000..7ce205491 --- /dev/null +++ b/components.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://ui.shadcn.com/schema.json", + "style": "new-york", + "rsc": false, + "tsx": true, + "tailwind": { + "config": "", + "css": "src/renderer/src/styles.css", + "baseColor": "neutral", + "cssVariables": true, + "prefix": "" + }, + "aliases": { + "components": "@/components", + "utils": "@/lib/utils", + "ui": "@/components/ui", + "lib": "@/lib", + "hooks": "@/hooks" + }, + "iconLibrary": "lucide" +} diff --git a/electron.vite.config.ts b/electron.vite.config.ts new file mode 100644 index 000000000..0508e88c4 --- /dev/null +++ b/electron.vite.config.ts @@ -0,0 +1,21 @@ +import { resolve } from 'node:path' +import { defineConfig } from 'electron-vite' +import react from '@vitejs/plugin-react' +import tailwindcss from '@tailwindcss/vite' + +export default defineConfig({ + main: {}, + preload: { + build: { + rollupOptions: { + output: { format: 'cjs', entryFileNames: '[name].cjs' } + } + } + }, + renderer: { + resolve: { + alias: { '@': resolve(import.meta.dirname, 'src/renderer/src') } + }, + plugins: [react(), tailwindcss()] + } +}) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..c62737202 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,4525 @@ +{ + "name": "iris-studio", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "iris-studio", + "version": "0.1.0", + "dependencies": { + "class-variance-authority": "^0.7.1", + "clsx": "^2.1.1", + "cn": "^0.5.2", + "lucide-react": "^1.69.0", + "radix-ui": "^1.8.1", + "react": "^19.3.1", + "react-dom": "^19.3.1", + "tailwind-merge": "^3.7.0" + }, + "devDependencies": { + "@tailwindcss/vite": "^4.3.4", + "@types/node": "^26.6.6", + "@types/react": "^19.3.0", + "@types/react-dom": "^19.3.0", + "@vitejs/plugin-react": "^6.2.1", + "electron": "^45.2.3", + "electron-vite": "^6.0.0", + "tailwindcss": "^4.3.4", + "typescript": "^7.0.2", + "vite": "^8.3.6", + "vitest": "^5.1.0" + } + }, + "node_modules/@babel/code-frame": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", + "integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-validator-identifier": "^7.29.7", + "js-tokens": "^4.0.0", + "picocolors": "^1.1.1" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/compat-data": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.29.7.tgz", + "integrity": "sha512-locTkQyKvwIEgBzVrn8693ebc97F2U8ZHjbXwDXJ5Fn2TCpNwTlKcaKLkdHop5c/icOFE7qt7Q9JC5hnKNa6Gg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/core": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.13.tgz", + "integrity": "sha512-j1nvOQCZYSgp7HLmisnCXFTpVvFODiijQ9QHkORfGKWH6YDtskTEeCJS7eV545GZ9UBzrq0e2xsOd5QQ5PjIqw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/generator": "^7.29.13", + "@babel/helper-compilation-targets": "^7.29.13", + "@babel/helper-module-transforms": "^7.29.13", + "@babel/helpers": "^7.29.13", + "@babel/parser": "^7.29.13", + "@babel/template": "^7.29.7", + "@babel/traverse": "^7.29.13", + "@babel/types": "^7.29.11", + "@jridgewell/remapping": "^2.3.5", + "convert-source-map": "^2.0.0", + "debug": "^4.1.0", + "gensync": "^1.0.0-beta.2", + "json5": "^2.2.3", + "semver": "^6.3.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/babel" + } + }, + "node_modules/@babel/core/node_modules/semver": { + "version": "6.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.2.tgz", + "integrity": "sha512-GYrCADwpu6yV5OAvchkQ27Z5wwMxWAEMg5NNWjyHh/5DboFFqbdbvYNIvZouQpxXyeMPoTOh0vdPYKlf0ZswdQ==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/@babel/generator": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.13.tgz", + "integrity": "sha512-T5FRo+RzVHvGjWOuF1Ljc44b+NXAOazodHkGUHp4I3zCkQ4/sNVJm56h1S278LMR0bY5xBhztGziSbli8zObIw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.13", + "@babel/types": "^7.29.11", + "@jridgewell/gen-mapping": "^0.3.12", + "@jridgewell/trace-mapping": "^0.3.28", + "jsesc": "^3.0.2" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-compilation-targets": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.29.13.tgz", + "integrity": "sha512-8WxJ4/Vmes3ghacj8VOJy3NW8eyHiFY/4thU/LSBuBE470+igjR/j1ZTNn8fV5VdNrLx6iXUwig526UdOvfP0w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/compat-data": "^7.29.7", + "@babel/helper-validator-option": "^7.29.7", + "browserslist": "^4.24.0", + "lru-cache": "^5.1.1", + "semver": "^6.3.1" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-compilation-targets/node_modules/semver": { + "version": "6.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.2.tgz", + "integrity": "sha512-GYrCADwpu6yV5OAvchkQ27Z5wwMxWAEMg5NNWjyHh/5DboFFqbdbvYNIvZouQpxXyeMPoTOh0vdPYKlf0ZswdQ==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/@babel/helper-globals": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.29.7.tgz", + "integrity": "sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-module-imports": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.29.7.tgz", + "integrity": "sha512-ejHwrQQYcm9xnTivShn2IDOlIzInN34AXskvq9QicvCtEzq1Vzclu/tKF8Jq1Cg8JG2GL6/EmjgsCT7lXepE3g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/traverse": "^7.29.7", + "@babel/types": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-module-transforms": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.29.13.tgz", + "integrity": "sha512-/U96wOz+SCoZ7Da/8kjDGltcNY280JPQcRNPK0Hk3PTbdpaiBDQImtC6JsbVwb1HGMr3usZQU2WsWVjhYNmRzw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-module-imports": "^7.29.7", + "@babel/helper-validator-identifier": "^7.29.7", + "@babel/traverse": "^7.29.13" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } + }, + "node_modules/@babel/helper-plugin-utils": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.29.7.tgz", + "integrity": "sha512-G7sHYigPY17oO5SYWnfD/0MTBwVR781S/JI643e/JhUYgVgWE/61SoW3NH9KWUKyKq5LVh3npif99Wkt6j86Jw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-string-parser": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.13.tgz", + "integrity": "sha512-fWegr+WsEsiMVW4KUNdIIzzMTZSzNiqhy0//6+2MRi2d5NFNsL/AYwBQW8eBnRbTBVRnDVzjaJEUqKaCWjMMdQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", + "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-option": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.29.7.tgz", + "integrity": "sha512-N9ZErrD+yW5geCDtBqnOoxmR8+tNKiGuxKlDpuJxfsqpa2dFcexaziGAE/qoHLiDDreVNMupxGmSoNlyvsA3gw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helpers": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.29.13.tgz", + "integrity": "sha512-laoRpD/kO/iA4CDlgJbixHekg7oPvWALK0PQyK3Ob2I2njZRvVAD77RfWCIImtqWCq6KijoBoZK7bp/HlTWASQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/template": "^7.29.7", + "@babel/types": "^7.29.11" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/parser": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.13.tgz", + "integrity": "sha512-fJM50YYjlTiBhgdkGmC1tBpv+FMAyo4annf2X6Aks+0yRlaiVkYW/3f07xAfVVkYIoZ9fFZp+mEThUFnuybhkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.29.11" + }, + "bin": { + "parser": "bin/babel-parser.js" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@babel/plugin-transform-arrow-functions": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.29.7.tgz", + "integrity": "sha512-N7zArUXWzAMzm+/N0uPBeVB3Fam5lMxtUwMmDK5f/IBBS7a7p1qeUoxd/6CckXoxUdgsntq1Dh8xNW06maZbDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-plugin-utils": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/template": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.29.7.tgz", + "integrity": "sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/parser": "^7.29.7", + "@babel/types": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/traverse": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.13.tgz", + "integrity": "sha512-0ve0xMlFA73dgY1oyJRY6RoW+/bncdcOQqg6jjYcVfXBK90OdLXjm9R6lmRetdZVrPjXkKIoMVBqYFPjcAlZ4Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/generator": "^7.29.13", + "@babel/helper-globals": "^7.29.7", + "@babel/parser": "^7.29.13", + "@babel/template": "^7.29.7", + "@babel/types": "^7.29.11", + "debug": "^4.3.1" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/types": { + "version": "7.29.11", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.11.tgz", + "integrity": "sha512-WCsemW40Cpc6gouC1SrY6PBaZ+oLRlEVY9XBvZBI7il/HyUrb2nJ505wE1MHEFyDZNnrWDEuy4jL50WVHfTTSQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-string-parser": "^7.29.11", + "@babel/helper-validator-identifier": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@electron-internal/extract-zip": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@electron-internal/extract-zip/-/extract-zip-1.0.8.tgz", + "integrity": "sha512-8iajeLFbzNwM0m3AsQZSZgYREWglAImyGvvFSWU34FgMW8sHlzdwj9QKvv9dgN7jMP591EFUF/sLOC3Jl9YIjQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=22.12.0" + } + }, + "node_modules/@electron/get": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@electron/get/-/get-5.1.0.tgz", + "integrity": "sha512-3kSBtG8ObcTVfXanm5vVJ6UnBLEVmVsRk1M+vGqCuMBV+XLCbJYuWQful+yIy0GQDsSlK0kHEriEHn7SPk4EnA==", + "dev": true, + "license": "MIT", + "dependencies": { + "debug": "^4.1.1", + "env-paths": "^3.0.0", + "graceful-fs": "^4.2.11", + "progress": "^2.0.3", + "semver": "^7.6.3", + "sumchecker": "^3.0.1" + }, + "engines": { + "node": ">=22.12.0" + }, + "optionalDependencies": { + "undici": "^7.24.4" + } + }, + "node_modules/@floating-ui/core": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.8.0.tgz", + "integrity": "sha512-0CIZ5itps/8x7BG8dEIhs53BvCUH2PCoogtakwRTut+Arm58sJooJ0AuZhLw2HJYIR5cMLNPBSS728sPho2khQ==", + "license": "MIT", + "dependencies": { + "@floating-ui/utils": "^0.2.12" + } + }, + "node_modules/@floating-ui/dom": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.8.0.tgz", + "integrity": "sha512-yXSrzeHZBTZadLOlfyhCkJHNeLJnHRnRInwdZ40L7ZiaAtrBwoYlsDrX3v5zB1Utk7CLfzcOVnVVWoXEky7Ceg==", + "license": "MIT", + "dependencies": { + "@floating-ui/core": "^1.8.0", + "@floating-ui/utils": "^0.2.12" + } + }, + "node_modules/@floating-ui/react-dom": { + "version": "2.1.9", + "resolved": "https://registry.npmjs.org/@floating-ui/react-dom/-/react-dom-2.1.9.tgz", + "integrity": "sha512-JDjEFGCpImxDCA7JJKviA0M9+RtmJdj0m/NVU5IMgBK+AmZouAQQ7/+2GLH0GXXY0YMw9oXPB8hKdbPYg5QLYg==", + "license": "MIT", + "dependencies": { + "@floating-ui/dom": "^1.8.0" + }, + "peerDependencies": { + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, + "node_modules/@floating-ui/utils": { + "version": "0.2.12", + "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.12.tgz", + "integrity": "sha512-HpCo8tmWzLVad5s2d19EhAz5zqrrQ6s69qd6moPMQvkOuSwDT1YgRfWSVuc4ennqrgv3OHppiOGMQ7oC13yIww==", + "license": "MIT" + }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.13", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", + "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0", + "@jridgewell/trace-mapping": "^0.3.24" + } + }, + "node_modules/@jridgewell/remapping": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz", + "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.24" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@oxc-project/types": { + "version": "0.156.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.156.0.tgz", + "integrity": "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/oxc-project" + } + }, + "node_modules/@radix-ui/number": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.1.3.tgz", + "integrity": "sha512-Road2bidD0uu/1BGDOWNdPI06g0lIRy6IF9GZcIrDK2KGItfor8IQwQa+yM2ERgHM1MmHxaxpTzk0/Jp42lNfA==", + "license": "MIT" + }, + "node_modules/@radix-ui/primitive": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.2.0.tgz", + "integrity": "sha512-KABY+VMIRPJL+Vyzv/335FEhXXD/xDv8BMb1kl48/aXJZMH0LtHCTx5ga5RnxaEP3nZHtmTLf1P9vanmFX46bw==", + "license": "MIT" + }, + "node_modules/@radix-ui/react-accessible-icon": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-accessible-icon/-/react-accessible-icon-1.2.0.tgz", + "integrity": "sha512-BB4+HHkFl3HipEAhm/mLhrpXV+2kRX7MvY4AaImUcQVeWQt5KhV1JEByNs8NGfJOcr95RcQGijt9+OrCo68xGA==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-visually-hidden": "1.2.13" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-accordion": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-accordion/-/react-accordion-1.3.1.tgz", + "integrity": "sha512-lCZ6sbGS/7WO0j84yx4srIgOf0MRJ/sZ13RonADXxvKBym8xrxNCq5f6DibGcr38sIlwPk8/52uYdXeOPsbEDw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-collapsible": "1.2.1", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-alert-dialog": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-alert-dialog/-/react-alert-dialog-1.2.1.tgz", + "integrity": "sha512-MWC4N7RY+qsbNrFNo7yQ9ZbdoZEW+B5DtpWxJfUnVCqcQxxqqg3qis3RMPTDbCNaTIdHJSn5XDkl9ZdVWXknLg==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-dialog": "1.3.1", + "@radix-ui/react-primitive": "2.2.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-arrow": { + "version": "1.1.17", + "resolved": "https://registry.npmjs.org/@radix-ui/react-arrow/-/react-arrow-1.1.17.tgz", + "integrity": "sha512-67jjcVvxjXCCStnTW3Z+M7jmaFMuMR7M2JgpDzH4w7JSRrikmzhjfYgP/09ECb8n7whnsgh1ifJ+Ie96qEj+pQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-primitive": "2.2.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-aspect-ratio": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-aspect-ratio/-/react-aspect-ratio-1.2.0.tgz", + "integrity": "sha512-gHEU+Lx8DlT/FYIjZQvvBJrFSwUngXTjh7FeL9QvJaNALDLez6pgDj2axCUihBjtPBy82LN0gNb25+sTcSXNmA==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-primitive": "2.2.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-avatar": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-avatar/-/react-avatar-1.3.1.tgz", + "integrity": "sha512-ssZOkfQNkFpYVmCPQlr978xSaU7moSrGXdwg4j2Xs2WlGl/1KsSZtfpK+WnLnx0Rwll1BAh6oUrAy/uR31SBvQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-callback-ref": "1.1.5", + "@radix-ui/react-use-is-hydrated": "0.1.3", + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-checkbox": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-checkbox/-/react-checkbox-1.4.1.tgz", + "integrity": "sha512-KWtwhh+98ML3seZ9vO9yRY2OwaQG90dCiDAxjpSNY2AaZ3Hik3B0dsk6m0ILywo/no3A9/SozadyPMNweVT8yw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-size": "1.1.5" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-collapsible": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-collapsible/-/react-collapsible-1.2.1.tgz", + "integrity": "sha512-fSzLb/qy1wuZSxQBcxpW0hNXYHDMWiIXDGyJGdA4+FSLknOWZsNRrTCUavxb4PI8b8lvHo/CysO6NVi5zLpo5g==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-collection": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.2.0.tgz", + "integrity": "sha512-+yiQzqcc7Sy7/5s0jrMCjpPRFB3538VNrXPWdTLZhE/SCfgEws4aI6lHWN/vvcnyhHndROWBzqmqB4QBrITZ9Q==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-slot": "1.5.0", + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-compose-refs": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.5.tgz", + "integrity": "sha512-+48PbAAbq3didjJxa+OaWY2ZwgAKsNiRGyeHKszblZMQ+kcpd9pAaT11cMkGEie0vsOi3QdeTE6d5Fe3Gn61kA==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-context": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-context/-/react-context-1.3.0.tgz", + "integrity": "sha512-v5AYEocMISkbJ+1fTXzZpiFv7NRr3D2WiYbLIKf+FkmJ8VkP6d503eV2n34MFussHXY1pcoq3yfJiQH77dc4Mg==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-context-menu": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-context-menu/-/react-context-menu-2.4.1.tgz", + "integrity": "sha512-Pddn3Z8lio3/ChxyXaEP3jHTTo1LTHCWwF8+mG1chQlWijP+ttVHBKwezrQTiV6Mj670ojvumqvuGh+mdv33iQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-menu": "2.2.1", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-dialog": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-dialog/-/react-dialog-1.3.1.tgz", + "integrity": "sha512-+0E4qvVTwjAWra9sEhJ+9BTsvHE00zkUuNw1VGh7S+Gc13dfYk+S1PVQdchWDj+XYHhAai7Z7IpzXVDCGsDplg==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-dismissable-layer": "1.2.1", + "@radix-ui/react-focus-guards": "1.2.0", + "@radix-ui/react-focus-scope": "1.3.1", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-portal": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-slot": "1.5.0", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-layout-effect": "1.1.4", + "aria-hidden": "^1.2.4", + "react-remove-scroll": "^2.7.2" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-direction": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-direction/-/react-direction-1.2.0.tgz", + "integrity": "sha512-FtRA52a/r+LKStFT+neLUm+8vSe7wbzkbQGGeU8ixFiwC8NU14Evoq9ATECqL3eGbcUzJR4fyfA4KkK/q6dfqg==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-dismissable-layer": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-dismissable-layer/-/react-dismissable-layer-1.2.1.tgz", + "integrity": "sha512-KIfDcAsx+oVylFZ4xryVKusJUrLLhTQmfnJW4kwk4Km5myvhHCrj04hnWWUC166+xD4DHdH8tQGylwYX1h6+Pg==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-callback-ref": "1.1.5", + "@radix-ui/react-use-effect-event": "0.0.5" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-dropdown-menu": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-dropdown-menu/-/react-dropdown-menu-2.2.1.tgz", + "integrity": "sha512-XsHcmYG2AcqnvTqrOXXWcMrhquEIlqucizuDH1MV/qMRW+DndpBCMvNeTRXOxqmG1H5j89M/+I0/34Zdd+zDcQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-menu": "2.2.1", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-focus-guards": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-focus-guards/-/react-focus-guards-1.2.0.tgz", + "integrity": "sha512-MPm5R0iRGUDrDnPNxmLBkv+X7pN4XKzt+MbWJEuJQsH3NFH4omrbpXpucyYCCKTSt+na/ZxGhEWQrWTZ0285cA==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-focus-scope": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-focus-scope/-/react-focus-scope-1.3.1.tgz", + "integrity": "sha512-ugeMhbXt4y5S2T1GnIqbWDKEN962PDwnX1fN0eKOOgf5f63Dh2mn8F1FUySlgW0iF6GiVsRF32DzuDIWTUyQJg==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-callback-ref": "1.1.5" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-form": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-form/-/react-form-0.3.0.tgz", + "integrity": "sha512-KnmrCM27m7Jo1R8S6cFDPrEeq20Jfn5dqde0SZrJr2lVXlj6/QZSUCyFoYh1d8ti0uUrMNK5Lx6dUDuINT+f4Q==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-label": "2.1.17", + "@radix-ui/react-primitive": "2.2.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-hover-card": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-hover-card/-/react-hover-card-1.2.1.tgz", + "integrity": "sha512-4QooHxgmpCKRjj1Pft+hETKidYcrbPKcVwMGtk2Oa5DcWY2IH1fHuQt9LG6q5hUQBBV2MhQxSvtx6B/C1xfiTw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-dismissable-layer": "1.2.1", + "@radix-ui/react-focus-scope": "1.3.1", + "@radix-ui/react-popper": "1.4.0", + "@radix-ui/react-portal": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-id": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@radix-ui/react-id/-/react-id-1.1.4.tgz", + "integrity": "sha512-TMQp2llA+RYn7JcjnrMnz7wN4pcVttPZnRZo52PLQsoLVKzNlVwUeHmfePgTgRluXFvlD3GD5g5MOVVTJCO0qA==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-label": { + "version": "2.1.17", + "resolved": "https://registry.npmjs.org/@radix-ui/react-label/-/react-label-2.1.17.tgz", + "integrity": "sha512-xmj7MN/drx1oUAXkfiFIvyDmGNUIN/omGobvA5oAoNqu9zO2MkISYGZOkBcqSzs/UZXXwV+/3ACRE7q7mGcmkA==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-primitive": "2.2.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-menu": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-menu/-/react-menu-2.2.1.tgz", + "integrity": "sha512-G34BsU90SBj5foYpz8pQqq/Q0Dlfyyl6KitWEfRwXC0QvfwhWNAwS49DWP2+rRJ0iwv20Z2Qx7Sk+T03bGo5JA==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-dismissable-layer": "1.2.1", + "@radix-ui/react-focus-guards": "1.2.0", + "@radix-ui/react-focus-scope": "1.3.1", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-popper": "1.4.0", + "@radix-ui/react-portal": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-roving-focus": "1.2.1", + "@radix-ui/react-slot": "1.5.0", + "@radix-ui/react-use-callback-ref": "1.1.5", + "aria-hidden": "^1.2.4", + "react-remove-scroll": "^2.7.2" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-menubar": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-menubar/-/react-menubar-1.2.1.tgz", + "integrity": "sha512-bRTYtS9JITV2dUYqYZb7+N5SooQBkZrNRejfmyrSKe3Y57aXhKgx//kBUP0kY7pEpsWR/U1AHsAJRzjwCrK3PA==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-menu": "2.2.1", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-roving-focus": "1.2.1", + "@radix-ui/react-use-controllable-state": "1.3.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-navigation-menu": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-navigation-menu/-/react-navigation-menu-1.4.1.tgz", + "integrity": "sha512-XPPZjkeyCSMNNvt0FyDv/PUauG7Ow4GwHQ/XZSwW36F/TS7rR4HFTsXH8ewLnXTOLn3x96/pmTPNQIVoTX/86g==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-dismissable-layer": "1.2.1", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-slot": "1.5.0", + "@radix-ui/react-use-callback-ref": "1.1.5", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-layout-effect": "1.1.4", + "@radix-ui/react-use-previous": "1.1.4", + "@radix-ui/react-visually-hidden": "1.2.13" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-one-time-password-field": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-one-time-password-field/-/react-one-time-password-field-0.2.1.tgz", + "integrity": "sha512-KtHdcgnaAK6rohQ/MMJoGYcbgSRJsIuGBdHrFeTB1/9SaKlDs14oSOniW6BL6M43HqvgCO3u4WuVdFLkuc6sqw==", + "license": "MIT", + "dependencies": { + "@radix-ui/number": "1.1.3", + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-roving-focus": "1.2.1", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-effect-event": "0.0.5", + "@radix-ui/react-use-is-hydrated": "0.1.3", + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-password-toggle-field": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-password-toggle-field/-/react-password-toggle-field-0.2.1.tgz", + "integrity": "sha512-vu4+ZoJAaFjdI7l1lDSZRs+4dEv83Jmu7lyzajPrAeQzX74y84n0rUNWbWSgN9XB5NE8IY86Z02kGH6oRrzR+w==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-effect-event": "0.0.5", + "@radix-ui/react-use-is-hydrated": "0.1.3" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-popover": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.3.1.tgz", + "integrity": "sha512-ZNxvXRx5W2Wos4fXCXb5lpdqN0Z5chf+mStOUOTr4ik7d+62MRvoe9rzCA/eGNg36lxXqSrKEKmwuZEcUrIstw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-dismissable-layer": "1.2.1", + "@radix-ui/react-focus-guards": "1.2.0", + "@radix-ui/react-focus-scope": "1.3.1", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-popper": "1.4.0", + "@radix-ui/react-portal": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-slot": "1.5.0", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-layout-effect": "1.1.4", + "aria-hidden": "^1.2.4", + "react-remove-scroll": "^2.7.2" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-popper": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.4.0.tgz", + "integrity": "sha512-yCWRvLeGv9Pz3+efwHqGPp70mZ56r3kfIgQVF56Oj2aAa4uP/Tb+IE59wNcc+758rctqbCKx4LbK8II/r7Bn0Q==", + "license": "MIT", + "dependencies": { + "@floating-ui/react-dom": "^2.0.0", + "@radix-ui/react-arrow": "1.1.17", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-callback-ref": "1.1.5", + "@radix-ui/react-use-layout-effect": "1.1.4", + "@radix-ui/react-use-rect": "1.1.4", + "@radix-ui/react-use-size": "1.1.5", + "@radix-ui/rect": "1.1.3" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-portal": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-portal/-/react-portal-1.2.0.tgz", + "integrity": "sha512-StX7xXnaRU41VvFtMm9zlhVGz8XF6GmWWTXftkQaY+tqVkbs/R9UmAp5mLzHHapk5hM9RMZQvO/3usyIP/g42g==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-presence": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/@radix-ui/react-presence/-/react-presence-1.1.11.tgz", + "integrity": "sha512-Z7/atlkab36Z8hm+V8zYc79r0W+tiOB1o0tun1By94JyadkekLQmtEAnBSP9XKXBNQsStoStS4+gX10JpS5akA==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-primitive": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.2.0.tgz", + "integrity": "sha512-HCTSPMNqv55Qk0IX4geJbpyXazmqulcimwuyjxTkKi29v+QZbG2Zho9BnbBq4YS2PF+KlNb2CXoLz66uUmblkg==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-slot": "1.5.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-progress": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-progress/-/react-progress-1.2.1.tgz", + "integrity": "sha512-yQBiM6J3YM8Ums1orkEFpbznK47geKxa0igikzcaS1xHgdba3DdAQBsGbCTt5BVfR8zhEvgxQ0poGcINaD3lvw==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-primitive": "2.2.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-radio-group": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-radio-group/-/react-radio-group-1.5.1.tgz", + "integrity": "sha512-QbyVT1ddnjqB9H+CUYKkNWdU9fIK3QHCYtjf7mS6ekSqiuXkWtWn5UZW9mhA8qtl3vrVyIsmR9gePstAtKrqkw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-roving-focus": "1.2.1", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-size": "1.1.5" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-roving-focus": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-roving-focus/-/react-roving-focus-1.2.1.tgz", + "integrity": "sha512-UwraORzVUeEPMclhO1p0vz0qI+TbdDLO9i+FiOqhJyHKwdpCRCck9yVEscUnAMIzCiuNoQa8D4A9bIpOPXGt6Q==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-callback-ref": "1.1.5", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-is-hydrated": "0.1.3", + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-scroll-area": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-scroll-area/-/react-scroll-area-1.4.0.tgz", + "integrity": "sha512-CFrLqHNejWq5FhKAcj9V/WPGRsol76HBQto81NdOBVFEOqIEkJkKIJt0Z824A/9hHLCtoiR/Kw3euRgzXP2pxg==", + "license": "MIT", + "dependencies": { + "@radix-ui/number": "1.1.3", + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-slot": "1.5.0", + "@radix-ui/react-use-callback-ref": "1.1.5", + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-select": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-2.4.1.tgz", + "integrity": "sha512-888ZwW0Md6GyptuqYABRX9nLKgoYfcooCyBBvVaX5Jp3e+8Jp2i4Zo/Uy50Hm+Ysn2JfloQXstW4U36w8teVtg==", + "license": "MIT", + "dependencies": { + "@radix-ui/number": "1.1.3", + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-dismissable-layer": "1.2.1", + "@radix-ui/react-focus-guards": "1.2.0", + "@radix-ui/react-focus-scope": "1.3.1", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-popper": "1.4.0", + "@radix-ui/react-portal": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-slot": "1.5.0", + "@radix-ui/react-use-callback-ref": "1.1.5", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-layout-effect": "1.1.4", + "@radix-ui/react-visually-hidden": "1.2.13", + "aria-hidden": "^1.2.4", + "react-remove-scroll": "^2.7.2" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-separator": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-separator/-/react-separator-1.2.0.tgz", + "integrity": "sha512-1jUAap0wZEqVP05Ou7kJgRxe/W+Qftng+rUNWGa0qkKbv9r5pWTG3E7a3ELKo2eJoHKMECnzuYrZpSyO1YgcYQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-primitive": "2.2.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-slider": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-slider/-/react-slider-1.6.1.tgz", + "integrity": "sha512-IRNRR90moPqxfwCJ0XbMJIxo70W0/1ZExT/sNCxEHMaPx0SF9HoQrcPEC75+H28cFKa0b+KH63anfLYJmwKacw==", + "license": "MIT", + "dependencies": { + "@radix-ui/number": "1.1.3", + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-layout-effect": "1.1.4", + "@radix-ui/react-use-size": "1.1.5" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-slot": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.5.0.tgz", + "integrity": "sha512-tyYd9ddPXAysAbdbD9eYxgwpCSv6f3PncqVSNKQFSR5lcJVLz3cb/pANDoYrLiHBpXv7skortyUgGUWsYuPPFQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-compose-refs": "1.1.5" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-switch": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.4.1.tgz", + "integrity": "sha512-NpBGwc40rY02ZmSvuyeKk0Bvc8ZsNeTMi4qHvJ+ZH4EiYCv0zIXEgdCW4bVdzgIUeP9xxbLJSxKOUfqITYNmkA==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-size": "1.1.5" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-tabs": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-tabs/-/react-tabs-1.2.1.tgz", + "integrity": "sha512-hRoJlode+hg5ZNlR+3tkfkUliIybdTpD5lkAvHQ9yaXseGf7XVO9Ib2GPEIOuaJJbo7YWYbNpDDRfo8Dhf6/xA==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-roving-focus": "1.2.1", + "@radix-ui/react-use-controllable-state": "1.3.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-toast": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-toast/-/react-toast-1.3.1.tgz", + "integrity": "sha512-iQvL0J7XK4HtJNGkkWMyYrboNseI7vtotFeUkIno8YNxVA9oM7B6//fh0Mc6TSKI96+zioLWi98lQLso88yJmQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-dismissable-layer": "1.2.1", + "@radix-ui/react-portal": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-callback-ref": "1.1.5", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-layout-effect": "1.1.4", + "@radix-ui/react-visually-hidden": "1.2.13" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-toggle": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-toggle/-/react-toggle-1.2.1.tgz", + "integrity": "sha512-+3MUq+WyiBplXYqQ0EIYlq8R4sLQ0T5NbOK7DMdDLCKO93pe2uE0DUJTWWfTBprpJJXxfoF3eMW0xpakVZrYsg==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-use-controllable-state": "1.3.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-toggle-group": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-toggle-group/-/react-toggle-group-1.2.1.tgz", + "integrity": "sha512-O8Ldx5ao4p4KoW+DO8/PmkOe5mdKNi3F2SseqjVj88wvDGDHe60cUmO0Zm/uHsKrvNgQGV8Efpuh95Tht/h4vw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-roving-focus": "1.2.1", + "@radix-ui/react-toggle": "1.2.1", + "@radix-ui/react-use-controllable-state": "1.3.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-toolbar": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-toolbar/-/react-toolbar-1.2.1.tgz", + "integrity": "sha512-Cm8m7JTEeUdbfA6T9xgyu8HfOpyvSx8pB/wj0DlEuWaJe9FilIs4Az9wci/lU9RbthV/UkltszMw5WnnD+m/Ug==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-roving-focus": "1.2.1", + "@radix-ui/react-separator": "1.2.0", + "@radix-ui/react-toggle-group": "1.2.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-tooltip": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.4.1.tgz", + "integrity": "sha512-NxLFGSFtZ78zVfcoOhTwR1xwqo5qx1Jh8Pw6FMZ9McCaqfRzz7/gIRahs2Oy5XlPgQ+8QkUcKbN5B0U44J/kCg==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-dismissable-layer": "1.2.1", + "@radix-ui/react-focus-scope": "1.3.1", + "@radix-ui/react-id": "1.1.4", + "@radix-ui/react-popper": "1.4.0", + "@radix-ui/react-portal": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-slot": "1.5.0", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-layout-effect": "1.1.4", + "@radix-ui/react-visually-hidden": "1.2.13" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-use-callback-ref": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.1.5.tgz", + "integrity": "sha512-Y5GBf4NKeADoXI1geiMlMuMoURT3k9MizzzKhGb/m55H94aGigZ01PIpkvsO6lML13BA6XYAXSJ6gza7vTn5nw==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-use-controllable-state": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-controllable-state/-/react-use-controllable-state-1.3.0.tgz", + "integrity": "sha512-TAcBI7bw2ljYCbv4+zuTSd6zICu8pRt6SDN2vJ/Z06K2MXh6I9WYFe/A9ovlFDtR5HVHGm5iDxDoABm/++dbKg==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-use-effect-event": "0.0.5", + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-use-effect-event": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-effect-event/-/react-use-effect-event-0.0.5.tgz", + "integrity": "sha512-7cshFL8HGS/7HEiHH+9kL9HBwp2sa9yX18Knwek6KYWmXwM7pegMgta2AXMQKI+rq3JnfSj9x8wYqFMTdG1Jgg==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-use-escape-keydown": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-escape-keydown/-/react-use-escape-keydown-1.1.6.tgz", + "integrity": "sha512-9cRullnQRv+kqnRmFlmh0WC3kAPuGmHiQ9VwsXdrYk//sBhgCKEttcpPEPgIQbyx6TGUmooVEHYTyohwz/lSJg==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-use-callback-ref": "1.1.5" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-use-is-hydrated": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-is-hydrated/-/react-use-is-hydrated-0.1.3.tgz", + "integrity": "sha512-umO/aJ+82CpOnhDZUTbILCQf7kU/g0iv+oGs/Q8jw7IkhWBzaEP4sA268PhFAJTFetbwp3ICc6ktpI4TqtxcIw==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-use-layout-effect": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-layout-effect/-/react-use-layout-effect-1.1.4.tgz", + "integrity": "sha512-K20DkRkUwDnxEYMBPcg3Y6voLkEy5p5QQmszZgLngKKiC7dzBR/aEuK3w1qlx2JWDUNH6FluahYdgR3BP+QbYw==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-use-previous": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-previous/-/react-use-previous-1.1.4.tgz", + "integrity": "sha512-XoSLhbRbqxFtgJoi2fNHA3C6pDlY34x508vUpUGoFZfvePfHXHbE1lC4FYFMnJWgiCRroSTw6fOsXQoVS9RwZg==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-use-rect": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-rect/-/react-use-rect-1.1.4.tgz", + "integrity": "sha512-cSOCh6JlkmfjLyNcLiu2nB4v+nm+dkZ+Q5KHWk/soo4U7ZLiEQFKHK9/YmtBHjfCEaU43IBKQOc4/uJmCaiCTQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/rect": "1.1.3" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-use-size": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-size/-/react-use-size-1.1.5.tgz", + "integrity": "sha512-V1McDQkMGzgivwqdu7u96APs7oi0Jvj9LTzgq3WWrDZqxWdAqU9yZnZQqk5OizGFR8badUQwZsrlao7MOlWYOA==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-use-layout-effect": "1.1.4" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@radix-ui/react-visually-hidden": { + "version": "1.2.13", + "resolved": "https://registry.npmjs.org/@radix-ui/react-visually-hidden/-/react-visually-hidden-1.2.13.tgz", + "integrity": "sha512-feijiN1oPk4rck4u9Dm9tsU4mT6Wp9oeEEhaz1WUEs1VuqLf8xzsFG+Qk+uWq6TnMH9O+WRECRg0NftyP9E4Fw==", + "license": "MIT", + "dependencies": { + "@radix-ui/react-primitive": "2.2.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@radix-ui/rect": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@radix-ui/rect/-/rect-1.1.3.tgz", + "integrity": "sha512-JtyZR+mqgBibTo8xea3B6ZRmzZiM/YeVBtUkas6zMuXjAlfIFIW2FgqeM9eLyvEaYX66vr6DJMK+4U6LV0KhNw==", + "license": "MIT" + }, + "node_modules/@rolldown/binding-android-arm-eabi": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.16.tgz", + "integrity": "sha512-ia3DwAs0OsMGS7+IConptSiyk9pEXkOx/AbJ2n/lAGxH3QkWQus1t8d7gnAT38FCU2sQu8lUbeR6AiZFv4JxaA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.16.tgz", + "integrity": "sha512-kx5wBiMB6E7TEvpl2B9gjLU004BkvEm2Dr941BFjx/SontPwSzNuQUIoVKxHHoSjpFIfHMmcguyLOtyn0hObRg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.16.tgz", + "integrity": "sha512-qslZrXnKJU4cUpjoAmtAo/KQM9e2IRMlmpig6Zpwj+8KWxW8v+nkAf9216Bsek9lOC1jvg2yCjygCFo2f83msQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.16.tgz", + "integrity": "sha512-FdF+y48ND13eAyM2mQn+85kvAqNlvRWROy2rhgA463X/0Gv4vGtazZtfaF1mRBLscYvtOlh4QnLjOWiFzX69OQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.16.tgz", + "integrity": "sha512-ddjqFM5e95AgLbUPtKIS7V1KTVlA0RUgCVr5mn+/IEhsdy3pr+Vuj/HZ7nlMN2FyxIwUktOH1LEPIQXO1v9y1Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.16.tgz", + "integrity": "sha512-tHdKWbFkFBI687iim3LIyIvyL7j66VvQYkDPss5Stn/qyE2tWkR1YD0dXmXPFKKqT/o5ZEJVsaRsWS2meQwGOA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.16.tgz", + "integrity": "sha512-FJiLGAblPBMlBEdbOqw6kW6QcXDWAf/oJu7gYs9ZJZwmg+K+/zjFLxPTIY9izJUzxzc24FHvmseyA0IvJSl17w==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.16.tgz", + "integrity": "sha512-hrJpblMsrQ58U9veWpbXzkhV5zStunds6HWLprqq1qauvgBr1E6P+24kLj6lSLI9vjRn/RYpjprhkHQPKGWpNg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.16.tgz", + "integrity": "sha512-qJd/dC6j6CwLG9/s/RP2nb1RZ0GIgj7Ioj7x/SYa3RzjVrlzrmH0fhIOpfvqQDeIsdP0loi+kHaMhJzY1PBIaA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.16.tgz", + "integrity": "sha512-Vx7Xg5uUJuNcujJjI70OICaH0EYj80BtOLZTSN7uOYg8QOLlyKnaG0IW7Fn/J0IpJsaKzmDKMhOQv1JBM9m9vg==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.16.tgz", + "integrity": "sha512-TNKhgE3uJTsTzatUSSYt0Kgo+Oa2uSlSjz4r1aEIea7HX6ULBym4fAlYUhG1i6pjNf2njfCUAfKwr6C3E9Xg1w==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.16.tgz", + "integrity": "sha512-7chXdpjXZ8qG0+mIxECN3cT9kvhZ3/oZhMX6Pp876P7CDrIy8nJswva6Mq357JR7eYXfuskwZxMeV1SzoZdHrA==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.16.tgz", + "integrity": "sha512-Kwjt+7uNTJK5/MDkGWGVO2KQPnj8yAV75dMpfwyHZrJSXWHrniOB0aUEWlVYf3H1hOqFLIStLdM5QXq6bnKmOQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.16.tgz", + "integrity": "sha512-/LH6WfjDRXXJz/p5xl4TmU+jpcnwcxbKEQBW/GZE0JHfN0lGIyTtsUEGaQ/q/GikkGJ2yLKe6pwm7AnEWO8pdw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.16.tgz", + "integrity": "sha512-1lv1KvX0Z871zfk7vw+dnXMMnHNyDwMzWG8Kv3HxDXMOhzCX4SHc7HK319fInP0i+0p9D8brkfzL7pJOaGl+tw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", + "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tailwindcss/node": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.3.4.tgz", + "integrity": "sha512-b7QK/QG04v3j04NbpG82XLCedRyulnkuwUDwRa9oK/ypnJIzMapz2Wg+0TltVczjUzDaJJHIa1+jj9aMUOFMTQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/remapping": "^2.3.5", + "enhanced-resolve": "^5.24.5", + "jiti": "^2.7.0", + "lightningcss": "1.33.0", + "magic-string": "^1.1.0", + "source-map-js": "^1.2.1", + "tailwindcss": "4.3.4" + } + }, + "node_modules/@tailwindcss/oxide": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide/-/oxide-4.3.4.tgz", + "integrity": "sha512-riqsRw2sLF7B1sNCCkTl3KYXEqvhTiABzZ/4oxxHfZ3c3Td60bCBfOrUuUGOiHagd3E7V+zG46c+XBDWZGFBcg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 20" + }, + "optionalDependencies": { + "@tailwindcss/oxide-android-arm64": "4.3.4", + "@tailwindcss/oxide-darwin-arm64": "4.3.4", + "@tailwindcss/oxide-darwin-x64": "4.3.4", + "@tailwindcss/oxide-freebsd-x64": "4.3.4", + "@tailwindcss/oxide-linux-arm-gnueabihf": "4.3.4", + "@tailwindcss/oxide-linux-arm64-gnu": "4.3.4", + "@tailwindcss/oxide-linux-arm64-musl": "4.3.4", + "@tailwindcss/oxide-linux-x64-gnu": "4.3.4", + "@tailwindcss/oxide-linux-x64-musl": "4.3.4", + "@tailwindcss/oxide-wasm32-wasi": "4.3.4", + "@tailwindcss/oxide-win32-arm64-msvc": "4.3.4", + "@tailwindcss/oxide-win32-x64-msvc": "4.3.4" + } + }, + "node_modules/@tailwindcss/oxide-android-arm64": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-android-arm64/-/oxide-android-arm64-4.3.4.tgz", + "integrity": "sha512-qkjxt+EFocOi3mtsUS3ndlj6yj4SHubwBdvBynLnS8T4mvSzX0Enn0CpypJKmBEtczUAXOHVZKA2zTGzSNU2Sg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-darwin-arm64": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-arm64/-/oxide-darwin-arm64-4.3.4.tgz", + "integrity": "sha512-i/awUA/7mJQAbA3AzCW8aQtUh5goMieUdF1zOoclLaJUCxDvsXQ8VJqpQZY3dfcHS6PJjd3tw25nNneD/mEviQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-darwin-x64": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-x64/-/oxide-darwin-x64-4.3.4.tgz", + "integrity": "sha512-q56V9U6AnoYz/yj/alkDLhSQ9AZoXQSEl93f7WETa0+32CudbqM57BXdYXfMYPKudueXKaA+MG6L/0KRseF7Jg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-freebsd-x64": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-freebsd-x64/-/oxide-freebsd-x64-4.3.4.tgz", + "integrity": "sha512-r0W7A+Z9HTHh7bwihJl45E/zZKLjxD50/jToVF/E/RZHSl8+EWO+4yKKJpPMcUooT9hdoip3Zx1uWnbMg4N79g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-arm-gnueabihf": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm-gnueabihf/-/oxide-linux-arm-gnueabihf-4.3.4.tgz", + "integrity": "sha512-3aih/sRxzeYfi2Bkh+bGYNf2YU9Llamb2mpA7BNF1obYzdgEeWDAMQzK6BSwzLhs/eTdOaSur92qrGfchagUtQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-arm64-gnu": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.3.4.tgz", + "integrity": "sha512-ktJSrPGQou4OqL88rDEx5CkeM9BjzrwZvYo8u7B7VL1zkBa2XBm351o4MQrek95qikb2M++26Y7w7vbH6Mgl8g==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-arm64-musl": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-musl/-/oxide-linux-arm64-musl-4.3.4.tgz", + "integrity": "sha512-rt3hjUxT7utAtcB+df6wHyaXDyxhE7Zd1x7L/nvB5Jb2qBb8dZwFUoWqeRja1BaF5OlSqkKSjBmVXj9OsevmCQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-x64-gnu": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.3.4.tgz", + "integrity": "sha512-XE3jO2yOOWjttpeGvpwf3/b274NMi3QapQSAI/EzsgrmYNan1Tw8dXT9JQkN7K0OgvuqiC8mcCyNvGzEkpVJPQ==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-linux-x64-musl": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-musl/-/oxide-linux-x64-musl-4.3.4.tgz", + "integrity": "sha512-PaAZ2FjJaZk9SQLYtKIfQWiFm/xtl7pX2MKPgCzn0mS/VU54yu+vP457AJdB2XFLxU3gO2abLCt8N7Lg4EbKNg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-wasm32-wasi/-/oxide-wasm32-wasi-4.3.4.tgz", + "integrity": "sha512-bjO9WmoM687p8AoCIyw1DUqzpAs4JICLvNmIPxIWDmhw8IOsdubtWQLShyJmISnDKtRy1BBApHVOUl6sNFQQJA==", + "bundleDependencies": [ + "@napi-rs/wasm-runtime", + "@emnapi/core", + "@emnapi/runtime", + "@tybys/wasm-util", + "@emnapi/wasi-threads", + "tslib" + ], + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/core": "^1.11.3", + "@emnapi/runtime": "^1.11.3", + "@emnapi/wasi-threads": "^1.2.3", + "@napi-rs/wasm-runtime": "^1.2.2", + "@tybys/wasm-util": "^0.10.3", + "tslib": "^2.8.1" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/core": { + "version": "1.11.3", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "1.2.3", + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/runtime": { + "version": "1.11.3", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/wasi-threads": { + "version": "1.2.3", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@napi-rs/wasm-runtime": { + "version": "1.2.2", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@tybys/wasm-util": "^0.10.3" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@emnapi/core": "^1.7.1 || ^2.0.0-alpha.3", + "@emnapi/runtime": "^1.7.1 || ^2.0.0-alpha.3" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@tybys/wasm-util": { + "version": "0.10.3", + "dev": true, + "inBundle": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/tslib": { + "version": "2.8.1", + "dev": true, + "inBundle": true, + "license": "0BSD", + "optional": true + }, + "node_modules/@tailwindcss/oxide-win32-arm64-msvc": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.3.4.tgz", + "integrity": "sha512-jCrwCvWVtt7ruMXp6dFPd5KBNU8o1tWtEdZbTL/w/hvD3lUYZA0E2mmfvTzW4QLHIx5wGQU9HeY7997R1QTrEg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/oxide-win32-x64-msvc": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.3.4.tgz", + "integrity": "sha512-cge1wcedn1FrRSXL22lF5sNDYr8c9+VImk7zFYLPs12jkDmchSrZNfzWqOKub+5Hb/aYRdDEqERGGDKONBlOzQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 20" + } + }, + "node_modules/@tailwindcss/vite": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/@tailwindcss/vite/-/vite-4.3.4.tgz", + "integrity": "sha512-wGukGWb8SVuN7+FJvSS7M5eSJWDIWwVSvUvj1q41eTIhGPsS2DAgFWjA7YURJNwjHSgty59Hz8iMUiyO+YMHBQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@tailwindcss/node": "4.3.4", + "@tailwindcss/oxide": "4.3.4", + "tailwindcss": "4.3.4" + }, + "peerDependencies": { + "vite": "^5.2.0 || ^6 || ^7 || ^8" + } + }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", + "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "26.6.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.6.tgz", + "integrity": "sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~8.9.0" + } + }, + "node_modules/@types/react": { + "version": "19.3.0", + "resolved": "https://registry.npmjs.org/@types/react/-/react-19.3.0.tgz", + "integrity": "sha512-N0rFCuH9YoxG9/m61l9MfpJKfmLOVU0em7ipIz6TRgSSkvReLB9vL85GB+yr8Bs5leqpvg96JSwF4ZS1s4viQg==", + "devOptional": true, + "license": "MIT", + "dependencies": { + "csstype": "^3.2.2" + } + }, + "node_modules/@types/react-dom": { + "version": "19.3.0", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.3.0.tgz", + "integrity": "sha512-ZI7bU42mZXXKHn/qNLEw2IrbiINU7X5+vfgdixBHkCNpYWXjKgfQ/P+uyGb5CjOLB9UcnTeg3rylQtV2hym44Q==", + "devOptional": true, + "license": "MIT", + "peerDependencies": { + "@types/react": "^19.3.0" + } + }, + "node_modules/@typescript/typescript-aix-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-aix-ppc64/-/typescript-aix-ppc64-7.0.2.tgz", + "integrity": "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-arm64/-/typescript-darwin-arm64-7.0.2.tgz", + "integrity": "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-x64/-/typescript-darwin-x64-7.0.2.tgz", + "integrity": "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-arm64/-/typescript-freebsd-arm64-7.0.2.tgz", + "integrity": "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-x64/-/typescript-freebsd-x64-7.0.2.tgz", + "integrity": "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm/-/typescript-linux-arm-7.0.2.tgz", + "integrity": "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm64/-/typescript-linux-arm64-7.0.2.tgz", + "integrity": "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-loong64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-loong64/-/typescript-linux-loong64-7.0.2.tgz", + "integrity": "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-mips64el": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-mips64el/-/typescript-linux-mips64el-7.0.2.tgz", + "integrity": "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-ppc64/-/typescript-linux-ppc64-7.0.2.tgz", + "integrity": "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-riscv64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-riscv64/-/typescript-linux-riscv64-7.0.2.tgz", + "integrity": "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-s390x": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-s390x/-/typescript-linux-s390x-7.0.2.tgz", + "integrity": "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-x64/-/typescript-linux-x64-7.0.2.tgz", + "integrity": "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-arm64/-/typescript-netbsd-arm64-7.0.2.tgz", + "integrity": "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-x64/-/typescript-netbsd-x64-7.0.2.tgz", + "integrity": "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-arm64/-/typescript-openbsd-arm64-7.0.2.tgz", + "integrity": "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-x64/-/typescript-openbsd-x64-7.0.2.tgz", + "integrity": "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-sunos-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-sunos-x64/-/typescript-sunos-x64-7.0.2.tgz", + "integrity": "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-arm64/-/typescript-win32-arm64-7.0.2.tgz", + "integrity": "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-x64/-/typescript-win32-x64-7.0.2.tgz", + "integrity": "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@vitejs/plugin-react": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-6.2.1.tgz", + "integrity": "sha512-9KyWCij3r0+qLG3Q62vBmv0VyevmYibAtxaCIVK9o0k6CXgaajZRIe8tpfchQcdZArJ5b/7OrIz4W3b2uxVRDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rolldown/pluginutils": "^1.0.1" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "peerDependencies": { + "@rolldown/plugin-babel": "^0.1.7 || ^0.2.0 || ^0.3.0", + "babel-plugin-react-compiler": "^1.0.0", + "oxc-transform-react": ">=0.152.0 <0.157.0", + "vite": "^8.0.0" + }, + "peerDependenciesMeta": { + "@rolldown/plugin-babel": { + "optional": true + }, + "babel-plugin-react-compiler": { + "optional": true + }, + "oxc-transform-react": { + "optional": true + } + } + }, + "node_modules/@vitest/mocker": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.1.0.tgz", + "integrity": "sha512-5umB9/jlWcqVS6fsrFmv5Gdnpu6wAUio/lEOwAmvB7v+lFo/IW2B9FhAD0p19GCULTgMzLCdUmuCDCnAzWgppQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.31", + "@vitest/spy": "5.1.0", + "estree-walker": "^3.0.3", + "magic-string": "^1.4.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9 || ^3.0.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/spy": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.1.0.tgz", + "integrity": "sha512-2DPO5OMHWKrBngC+fCmTQqemNF0gidRhp3lxbBmRhW+M1XJrfgPpqNqWVevXtn2f2ufD5ZaR1B6B641aAlcX5A==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/aria-hidden": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/aria-hidden/-/aria-hidden-1.2.6.tgz", + "integrity": "sha512-ik3ZgC9dY/lYVVM++OISsaYDeg1tb0VtP5uL3ouh1koGOaUMDPpbFIei4JkFimWUFPn90sbMNMXQAIVOlnYKJA==", + "license": "MIT", + "dependencies": { + "tslib": "^2.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/baseline-browser-mapping": { + "version": "2.11.35", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.35.tgz", + "integrity": "sha512-GNk8KX52CHqeNKGk8+7tZnQab/2k1t/BgrUHPKNdijzpEhF1saPQZHVKb6m5loSAxB39gyrTYw34Qf9CQ3u1qQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "baseline-browser-mapping": "dist/cli.cjs" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/browserslist": { + "version": "4.29.5", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.29.5.tgz", + "integrity": "sha512-khTmKu5NGYTotqcYo8Bew2k4RAE9PuXRSFRXG2lQBrCEQHyeQ/vX6gKMxfokwywBsLiXZMnHsmWMG1pnO8J7uQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "baseline-browser-mapping": "^2.11.33", + "caniuse-lite": "^1.0.30001819", + "electron-to-chromium": "^1.5.464", + "node-releases": "^2.0.60", + "update-browserslist-db": "^1.3.4" + }, + "bin": { + "browserslist": "cli.js" + }, + "engines": { + "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" + } + }, + "node_modules/cac": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/cac/-/cac-7.1.0.tgz", + "integrity": "sha512-LMDU/U2yA4IPIY8KT0NsNPWEYZvAMkbgyspxJ6btJaYV+WMDOHAZCmB0lsTObiHaRS1V/ztKAl7+TSkTqXyeoA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/caniuse-lite": { + "version": "1.0.30001822", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001822.tgz", + "integrity": "sha512-Y3fvWQWzc69dlCyr07tuNrEhotv+db5FpMSPD3slZnkPKwRNOKwFBz2dP966XUmWMXLTOt+YShkFoQoom3U7hg==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "CC-BY-4.0" + }, + "node_modules/chai": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", + "integrity": "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/class-variance-authority": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/class-variance-authority/-/class-variance-authority-0.7.1.tgz", + "integrity": "sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg==", + "license": "Apache-2.0", + "dependencies": { + "clsx": "^2.1.1" + }, + "funding": { + "url": "https://polar.sh/cva" + } + }, + "node_modules/clsx": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", + "integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/cn": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/cn/-/cn-0.5.2.tgz", + "integrity": "sha512-wm10E6iuJ37rALOw3D+3cfaXXZSLNMh2uxpQn3dNICqfJM59yXqgbA9/9Iiz155j5kYNLdK6WreNdW3NQtx3OQ==", + "license": "MIT", + "bin": { + "cn": "bin/cn.mjs" + }, + "engines": { + "node": ">=22" + } + }, + "node_modules/convert-source-map": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", + "dev": true, + "license": "MIT" + }, + "node_modules/csstype": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", + "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", + "devOptional": true, + "license": "MIT" + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/detect-node-es": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/detect-node-es/-/detect-node-es-1.1.0.tgz", + "integrity": "sha512-ypdmJU/TbBby2Dxibuv7ZLW3Bs1QEmM7nHjEANfohJLvE0XVujisn1qPJcZxg+qDucsr+bP6fLD1rPS3AhJ7EQ==", + "license": "MIT" + }, + "node_modules/electron": { + "version": "45.2.3", + "resolved": "https://registry.npmjs.org/electron/-/electron-45.2.3.tgz", + "integrity": "sha512-Vurzu5UOA5nTGT4LqIwXD16QFGrOZdiXxF+1UP4KNsAOo/YtDcT3/u0jhP4WSwNJ0iLrLDi85hzBJ0arnGDhyw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@electron-internal/extract-zip": "^1.0.1", + "@electron/get": "^5.0.0", + "@types/node": "^24.9.0" + }, + "bin": { + "electron": "cli.js", + "install-electron": "install.js" + }, + "engines": { + "node": ">= 22.12.0" + } + }, + "node_modules/electron-to-chromium": { + "version": "1.5.477", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.477.tgz", + "integrity": "sha512-PN++F4zWZoVDGWinxMnSCpVqKhqFOJfLXxdU8bYJKudAEsHL/XKVITOKWVbfMt1r276Mi9RDLU9VHx9uKJ4RMQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/electron-vite": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/electron-vite/-/electron-vite-6.0.0.tgz", + "integrity": "sha512-zafg2uizgll7jdx0BNDkkzO/SowsUBsiHqYN3v9Ieq7XPDHreRGZ4G9IRY/+RslgBktpLOjLM4jlP+IVpV0BGw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/core": "^7.29.7", + "@babel/plugin-transform-arrow-functions": "^7.29.7", + "cac": "^7.0.0", + "magic-string": "^1.4.2", + "picocolors": "^1.1.1", + "rolldown": "~1.2.10" + }, + "bin": { + "electron-vite": "bin/electron-vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "peerDependencies": { + "@swc/core": "^1.0.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + } + } + }, + "node_modules/electron/node_modules/@types/node": { + "version": "24.19.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.19.2.tgz", + "integrity": "sha512-93d49wCWJkCyN87MxLpNN6KXPCwFw7bVUg79mGUV1OS40JGWwVCr8n61DXCSqz7CV6/VfPkb7xec7uP2M+QHWQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": ">=7.24.0 <7.24.7" + } + }, + "node_modules/electron/node_modules/undici-types": { + "version": "7.24.6", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.6.tgz", + "integrity": "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==", + "dev": true, + "license": "MIT" + }, + "node_modules/enhanced-resolve": { + "version": "5.26.1", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.26.1.tgz", + "integrity": "sha512-PPnnSJq3azKOIewXR/uppBV/6h98dprBJ/WaQ9Qgj10xX1lJLNfg+XShpbsrSqcDSy2yYYyhfXM1wWhftqgyzw==", + "dev": true, + "license": "MIT", + "dependencies": { + "graceful-fs": "^4.2.4", + "tapable": "^2.3.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/env-paths": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-3.0.0.tgz", + "integrity": "sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/es-module-lexer": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", + "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==", + "dev": true, + "license": "MIT" + }, + "node_modules/escalade": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", + "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/gensync": { + "version": "1.0.0-beta.2", + "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", + "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/get-nonce": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-nonce/-/get-nonce-1.0.1.tgz", + "integrity": "sha512-FJhYRoDaiatfEkUK8HKlicmu/3SGFD51q3itKDGoSTysQJBnfOcxU5GxnhE1E6soB76MbT0MBtnKJuXyAx+96Q==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/jiti": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz", + "integrity": "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==", + "dev": true, + "license": "MIT", + "bin": { + "jiti": "lib/jiti-cli.mjs" + } + }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/jsesc": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", + "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", + "dev": true, + "license": "MIT", + "bin": { + "jsesc": "bin/jsesc" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "license": "MIT", + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lru-cache": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", + "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", + "dev": true, + "license": "ISC", + "dependencies": { + "yallist": "^3.0.2" + } + }, + "node_modules/lucide-react": { + "version": "1.69.0", + "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-1.69.0.tgz", + "integrity": "sha512-UTFECm4yEgkgMN0kfLuxWcmlk+4u02Jrqehgk3ZXRx/Ud68OpP7hjkp67bvkBHmIpMaZCIveF1QDYeupO7XmYQ==", + "license": "ISC", + "peerDependencies": { + "@types/react": "*", + "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/magic-string": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz", + "integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.6.0" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/node-releases": { + "version": "2.0.63", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.63.tgz", + "integrity": "sha512-6li2QanLsAXpIH2R6j77MzRyvOyrvdTqlKtO4CgBdHGNvN99ZZfyxszHc5o5+IZBWD5u6Hzwg83JoGXmqZNG9Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/obug": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/obug/-/obug-3.0.0.tgz", + "integrity": "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.32", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz", + "integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/radix-ui": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/radix-ui/-/radix-ui-1.8.1.tgz", + "integrity": "sha512-HPfpVGizO9xANlsFSauruLhRe/3+iOt3vPX0MXYle/UQi3gorQrSYtBcdiv0BZYewcl2rvL59qrIuLFMGAmUrw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.2.0", + "@radix-ui/react-accessible-icon": "1.2.0", + "@radix-ui/react-accordion": "1.3.1", + "@radix-ui/react-alert-dialog": "1.2.1", + "@radix-ui/react-arrow": "1.1.17", + "@radix-ui/react-aspect-ratio": "1.2.0", + "@radix-ui/react-avatar": "1.3.1", + "@radix-ui/react-checkbox": "1.4.1", + "@radix-ui/react-collapsible": "1.2.1", + "@radix-ui/react-collection": "1.2.0", + "@radix-ui/react-compose-refs": "1.1.5", + "@radix-ui/react-context": "1.3.0", + "@radix-ui/react-context-menu": "2.4.1", + "@radix-ui/react-dialog": "1.3.1", + "@radix-ui/react-direction": "1.2.0", + "@radix-ui/react-dismissable-layer": "1.2.1", + "@radix-ui/react-dropdown-menu": "2.2.1", + "@radix-ui/react-focus-guards": "1.2.0", + "@radix-ui/react-focus-scope": "1.3.1", + "@radix-ui/react-form": "0.3.0", + "@radix-ui/react-hover-card": "1.2.1", + "@radix-ui/react-label": "2.1.17", + "@radix-ui/react-menu": "2.2.1", + "@radix-ui/react-menubar": "1.2.1", + "@radix-ui/react-navigation-menu": "1.4.1", + "@radix-ui/react-one-time-password-field": "0.2.1", + "@radix-ui/react-password-toggle-field": "0.2.1", + "@radix-ui/react-popover": "1.3.1", + "@radix-ui/react-popper": "1.4.0", + "@radix-ui/react-portal": "1.2.0", + "@radix-ui/react-presence": "1.1.11", + "@radix-ui/react-primitive": "2.2.0", + "@radix-ui/react-progress": "1.2.1", + "@radix-ui/react-radio-group": "1.5.1", + "@radix-ui/react-roving-focus": "1.2.1", + "@radix-ui/react-scroll-area": "1.4.0", + "@radix-ui/react-select": "2.4.1", + "@radix-ui/react-separator": "1.2.0", + "@radix-ui/react-slider": "1.6.1", + "@radix-ui/react-slot": "1.5.0", + "@radix-ui/react-switch": "1.4.1", + "@radix-ui/react-tabs": "1.2.1", + "@radix-ui/react-toast": "1.3.1", + "@radix-ui/react-toggle": "1.2.1", + "@radix-ui/react-toggle-group": "1.2.1", + "@radix-ui/react-toolbar": "1.2.1", + "@radix-ui/react-tooltip": "1.4.1", + "@radix-ui/react-use-callback-ref": "1.1.5", + "@radix-ui/react-use-controllable-state": "1.3.0", + "@radix-ui/react-use-effect-event": "0.0.5", + "@radix-ui/react-use-escape-keydown": "1.1.6", + "@radix-ui/react-use-is-hydrated": "0.1.3", + "@radix-ui/react-use-layout-effect": "1.1.4", + "@radix-ui/react-use-size": "1.1.5", + "@radix-ui/react-visually-hidden": "1.2.13" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/react": { + "version": "19.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-19.3.1.tgz", + "integrity": "sha512-QNhWdt7nrgVWWQG58QuGsAR3jv3Hbe4mb4vz7w2csnHavciZJgda1CPNaldF6eVxv90ud3jUXpKlHL69gO38yw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dom": { + "version": "19.3.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.1.tgz", + "integrity": "sha512-Y0bARz53lhEC1NMCASs0/j+faB/zqt3R8hpvg1e8+61ZVJ4UL0UdC4cBbXfZMcIuhrfgeILTLe+ZeBCavQPtKQ==", + "license": "MIT", + "dependencies": { + "scheduler": "^0.28.0" + }, + "peerDependencies": { + "react": "^19.3.1" + } + }, + "node_modules/react-remove-scroll": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.7.2.tgz", + "integrity": "sha512-Iqb9NjCCTt6Hf+vOdNIZGdTiH1QSqr27H/Ek9sv/a97gfueI/5h1s3yRi1nngzMUaOOToin5dI1dXKdXiF+u0Q==", + "license": "MIT", + "dependencies": { + "react-remove-scroll-bar": "^2.3.7", + "react-style-singleton": "^2.2.3", + "tslib": "^2.1.0", + "use-callback-ref": "^1.3.3", + "use-sidecar": "^1.1.3" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/react-remove-scroll-bar": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/react-remove-scroll-bar/-/react-remove-scroll-bar-2.3.8.tgz", + "integrity": "sha512-9r+yi9+mgU33AKcj6IbT9oRCO78WriSj6t/cF8DWBZJ9aOGPOTEDvdUDz1FwKim7QXWwmHqtdHnRJfhAxEG46Q==", + "license": "MIT", + "dependencies": { + "react-style-singleton": "^2.2.2", + "tslib": "^2.0.0" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/react-style-singleton": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/react-style-singleton/-/react-style-singleton-2.2.3.tgz", + "integrity": "sha512-b6jSvxvVnyptAiLjbkWLE/lOnR4lfTtDAl+eUC7RZy+QQWc6wRzIV2CE6xBuMmDxc2qIihtDCZD5NPOFl7fRBQ==", + "license": "MIT", + "dependencies": { + "get-nonce": "^1.0.0", + "tslib": "^2.0.0" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/rolldown": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.16.tgz", + "integrity": "sha512-bWvlMpFKiTfDKfnK7FC2MPgPeWCf/Kpwsq49ApdW+FQaBZb6O6dZ4MAPbPUjp7hYQrw/RobqCzn64BRrQecGHw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.156.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm-eabi": "1.2.16", + "@rolldown/binding-android-arm64": "1.2.16", + "@rolldown/binding-darwin-arm64": "1.2.16", + "@rolldown/binding-darwin-x64": "1.2.16", + "@rolldown/binding-freebsd-x64": "1.2.16", + "@rolldown/binding-linux-arm-gnueabihf": "1.2.16", + "@rolldown/binding-linux-arm64-gnu": "1.2.16", + "@rolldown/binding-linux-arm64-musl": "1.2.16", + "@rolldown/binding-linux-ppc64-gnu": "1.2.16", + "@rolldown/binding-linux-s390x-gnu": "1.2.16", + "@rolldown/binding-linux-x64-gnu": "1.2.16", + "@rolldown/binding-linux-x64-musl": "1.2.16", + "@rolldown/binding-openharmony-arm64": "1.2.16", + "@rolldown/binding-win32-arm64-msvc": "1.2.16", + "@rolldown/binding-win32-x64-msvc": "1.2.16" + } + }, + "node_modules/scheduler": { + "version": "0.28.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.28.0.tgz", + "integrity": "sha512-juorfCmIkIw8tT+p5BXSm6PJjQF/ycEYmKyzURCIt/RaZIhL+PulbQ9Yu2z1HdOJDdqDTlxA1+xKBmHXJsczAw==", + "license": "MIT" + }, + "node_modules/semver": { + "version": "7.8.6", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz", + "integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/source-map-js": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz", + "integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/std-env": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.3.0.tgz", + "integrity": "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==", + "dev": true, + "license": "MIT" + }, + "node_modules/sumchecker": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz", + "integrity": "sha512-MvjXzkz/BOfyVDkG0oFOtBxHX2u3gKbMHIF/dXblZsgD3BWOFLmHovIpZY7BykJdAjcqRCBi1WYBNdEC9yI7vg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "debug": "^4.1.0" + }, + "engines": { + "node": ">= 8.0" + } + }, + "node_modules/tailwind-merge": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.7.0.tgz", + "integrity": "sha512-XPPUyAc+cvspz3lHTcR/QgPfW2A0lv/xQNIjX3HGhLR+Nq2lHaLq5MtTesHn8GUr3W3DguT2KT5x3NVgRtYwmA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/dcastil" + } + }, + "node_modules/tailwindcss": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.3.4.tgz", + "integrity": "sha512-PCJZTFFdG+sL3gvnP1Do9o6GbkvH2q0p04xSs3f7cSvmAeK+sttG+/7ncK1fdRwKFfC7n+wDDJaOMBSefkI9ow==", + "dev": true, + "license": "MIT" + }, + "node_modules/tapable": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.3.3.tgz", + "integrity": "sha512-uxc/zpqFg6x7C8vOE7lh6Lbda8eEL9zmVm/PLeTPBRhh1xCgdWaQ+J1CUieGpIfm2HdtsUpRv+HshiasBMcc6A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + } + }, + "node_modules/tinybench": { + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.3.tgz", + "integrity": "sha512-Al01C2JIBnO2CXCAPbpAl6sUiOZHeThGtHYNTa51JRw9PyWOCdr+9Ong05R4qg/Sk3+H645E8ov1h2c58ityNw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/tinyexec": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", + "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/tslib": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz", + "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==", + "license": "0BSD" + }, + "node_modules/typescript": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz", + "integrity": "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc" + }, + "engines": { + "node": ">=16.20.0" + }, + "optionalDependencies": { + "@typescript/typescript-aix-ppc64": "7.0.2", + "@typescript/typescript-darwin-arm64": "7.0.2", + "@typescript/typescript-darwin-x64": "7.0.2", + "@typescript/typescript-freebsd-arm64": "7.0.2", + "@typescript/typescript-freebsd-x64": "7.0.2", + "@typescript/typescript-linux-arm": "7.0.2", + "@typescript/typescript-linux-arm64": "7.0.2", + "@typescript/typescript-linux-loong64": "7.0.2", + "@typescript/typescript-linux-mips64el": "7.0.2", + "@typescript/typescript-linux-ppc64": "7.0.2", + "@typescript/typescript-linux-riscv64": "7.0.2", + "@typescript/typescript-linux-s390x": "7.0.2", + "@typescript/typescript-linux-x64": "7.0.2", + "@typescript/typescript-netbsd-arm64": "7.0.2", + "@typescript/typescript-netbsd-x64": "7.0.2", + "@typescript/typescript-openbsd-arm64": "7.0.2", + "@typescript/typescript-openbsd-x64": "7.0.2", + "@typescript/typescript-sunos-x64": "7.0.2", + "@typescript/typescript-win32-arm64": "7.0.2", + "@typescript/typescript-win32-x64": "7.0.2" + } + }, + "node_modules/undici": { + "version": "7.30.2", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.30.2.tgz", + "integrity": "sha512-mLyPQnHwUxaM/rideoK/+KL8DaAJLRl4aBCfmX444aCSLnIaomqPLtNRe2jdCYcsk5wZzXrDIQC8ZeYNRAYyIA==", + "dev": true, + "license": "MIT", + "optional": true, + "engines": { + "node": ">=20.18.1" + } + }, + "node_modules/undici-types": { + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.9.0.tgz", + "integrity": "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg==", + "dev": true, + "license": "MIT" + }, + "node_modules/update-browserslist-db": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.3.4.tgz", + "integrity": "sha512-t8wonIOdQyOjtPd2VktlBu6QjTVTks6v8bSi7kd0r2Vll8TK1JYDZtRRdbmCHOAMphkZgrzK+L+vXK4pyZ8t4A==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "escalade": "^3.2.0", + "picocolors": "^1.1.1" + }, + "bin": { + "update-browserslist-db": "cli.js" + }, + "peerDependencies": { + "browserslist": ">= 4.21.0" + } + }, + "node_modules/use-callback-ref": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.3.tgz", + "integrity": "sha512-jQL3lRnocaFtu3V00JToYz/4QkNWswxijDaCVNZRiRTO3HQDLsdu1ZtmIUvV4yPp+rvWm5j0y0TG/S61cuijTg==", + "license": "MIT", + "dependencies": { + "tslib": "^2.0.0" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/use-sidecar": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/use-sidecar/-/use-sidecar-1.1.3.tgz", + "integrity": "sha512-Fedw0aZvkhynoPYlA5WXrMCAMm+nSWdZt6lzJQ7Ok8S6Q+VsHmHpRWndVRJ8Be0ZbkfPc5LRYH+5XrzXcEeLRQ==", + "license": "MIT", + "dependencies": { + "detect-node-es": "^1.1.0", + "tslib": "^2.0.0" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "@types/react": "*", + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/vite": { + "version": "8.3.6", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.6.tgz", + "integrity": "sha512-UI7dK29NnS54Fk+mmo7o+jI6U8Fp7hDl+X5Q1k45WH+d4dSlbLVUETGQ+hfkNgvLQGyoElPj837nZyv4MBc0VA==", + "dev": true, + "license": "MIT", + "dependencies": { + "lightningcss": "^1.33.0", + "picomatch": "^4.0.7", + "postcss": "^8.5.32", + "rolldown": "~1.2.16", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.7.1 || ^0.8.0", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vitest": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-5.1.0.tgz", + "integrity": "sha512-MzmNFnrwa8v8lF1bLxw3UJ4EREwVOVb75VqJZmUDRjJ6EluK/x9th7qTbaeDk41WxE1GxWqmTXcdsfobfH5sOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/chai": "^5.2.2", + "@vitest/mocker": "5.1.0", + "chai": "^6.3.0", + "es-module-lexer": "^2.3.2", + "expect-type": "^1.4.0", + "magic-string": "^1.4.3", + "obug": "^3.0.0", + "picomatch": "^4.0.7", + "std-env": "^4.3.0", + "tinybench": "^6.2.2", + "tinyexec": "^1.3.1", + "tinyglobby": "^0.2.17", + "why-is-node-running": "3.2.1" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^22.12.0 || ^24.0.0 || >=26.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "5.1.0", + "@vitest/browser-preview": "5.1.0", + "@vitest/browser-webdriverio": "^5.0.0-beta.5 || >=5.0.0", + "@vitest/coverage-istanbul": "5.1.0", + "@vitest/coverage-v8": "5.1.0", + "@vitest/ui": "5.1.0", + "happy-dom": "*", + "jsdom": "*", + "vite": "^6.4.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/coverage-istanbul": { + "optional": true + }, + "@vitest/coverage-v8": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "vite": { + "optional": false + } + } + }, + "node_modules/why-is-node-running": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-3.2.1.tgz", + "integrity": "sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ==", + "dev": true, + "license": "MIT", + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=20.11" + } + }, + "node_modules/yallist": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", + "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", + "dev": true, + "license": "ISC" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..47598774d --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "iris-studio", + "productName": "Iris Studio", + "version": "0.1.0", + "description": "The studio app for Iris worlds: maps, objects and editors, connected to a running server", + "private": true, + "type": "module", + "main": "out/main/index.js", + "scripts": { + "dev": "electron-vite dev", + "build": "electron-vite build", + "start": "electron-vite preview", + "typecheck": "tsc --noEmit -p tsconfig.json", + "test": "vitest run" + }, + "devDependencies": { + "@tailwindcss/vite": "^4.3.4", + "@types/node": "^26.6.6", + "@types/react": "^19.3.0", + "@types/react-dom": "^19.3.0", + "@vitejs/plugin-react": "^6.2.1", + "electron": "^45.2.3", + "electron-vite": "^6.0.0", + "tailwindcss": "^4.3.4", + "typescript": "^7.0.2", + "vite": "^8.3.6", + "vitest": "^5.1.0" + }, + "dependencies": { + "class-variance-authority": "^0.7.1", + "clsx": "^2.1.1", + "cn": "^0.5.2", + "lucide-react": "^1.69.0", + "radix-ui": "^1.8.1", + "react": "^19.3.1", + "react-dom": "^19.3.1", + "tailwind-merge": "^3.7.0" + } +} diff --git a/src/main/index.ts b/src/main/index.ts new file mode 100644 index 000000000..4d42f088a --- /dev/null +++ b/src/main/index.ts @@ -0,0 +1,124 @@ +import { app, BrowserWindow, clipboard, ipcMain, nativeTheme, shell } from 'electron' +import { readdir, readFile } from 'node:fs/promises' +import { homedir } from 'node:os' +import { join } from 'node:path' +import type { BridgeConnection, ThemeChoice } from '../shared/bridge' + +const CONNECTION_FOLDER = join(homedir(), '.iris', 'studio', 'bridges') +const LINK_PREFIX = 'iris-studio://' +const DARK_BACKGROUND = '#1e1f22' +const WINDOW_SIZE = { width: 1440, height: 880, minWidth: 820, minHeight: 520 } + +let window: BrowserWindow | null = null +let pendingLink: string | null = findLink(process.argv) + +function findLink(argv: string[]): string | null { + return argv.find((argument) => argument.startsWith(LINK_PREFIX)) ?? null +} + +function isRunning(pid: unknown): boolean { + if (typeof pid !== 'number') { + return true + } + try { + process.kill(pid, 0) + return true + } catch (error) { + return (error as NodeJS.ErrnoException).code === 'EPERM' + } +} + +/** The bridges announced on this machine whose server still runs, newest first. */ +async function listBridges(): Promise { + let files: string[] + try { + files = (await readdir(CONNECTION_FOLDER)).filter((name) => name.endsWith('.json')) + } catch { + return [] + } + const bridges = await Promise.all(files.map(readConnection)) + return bridges + .filter((bridge): bridge is BridgeConnection => bridge !== null) + .sort((first, second) => (second.startedMillis ?? 0) - (first.startedMillis ?? 0)) +} + +async function readConnection(name: string): Promise { + try { + const file = JSON.parse(await readFile(join(CONNECTION_FOLDER, name), 'utf8')) + if (!isRunning(file.pid) || typeof file.port !== 'number' || typeof file.token !== 'string') { + return null + } + return { world: String(file.world ?? ''), port: file.port, token: file.token, startedMillis: file.startedMillis } + } catch { + return null + } +} + +function createWindow(): void { + window = new BrowserWindow({ + ...WINDOW_SIZE, + title: 'Iris Studio', + backgroundColor: DARK_BACKGROUND, + autoHideMenuBar: true, + show: false, + webPreferences: { + preload: join(import.meta.dirname, '../preload/index.cjs'), + sandbox: true, + contextIsolation: true + } + }) + window.once('ready-to-show', () => window?.show()) + window.webContents.setWindowOpenHandler(({ url }) => { + void shell.openExternal(url) + return { action: 'deny' } + }) + if (process.env.ELECTRON_RENDERER_URL) { + void window.loadURL(process.env.ELECTRON_RENDERER_URL) + } else { + void window.loadFile(join(import.meta.dirname, '../renderer/index.html')) + } +} + +function deliverLink(link: string): void { + if (window === null) { + pendingLink = link + return + } + window.webContents.send('studio:link', link) + if (window.isMinimized()) { + window.restore() + } + window.focus() +} + +if (!app.requestSingleInstanceLock()) { + app.quit() +} else { + app.setAsDefaultProtocolClient('iris-studio') + app.on('second-instance', (_event, argv) => { + const link = findLink(argv) + if (link !== null) { + deliverLink(link) + } else { + window?.focus() + } + }) + app.on('open-url', (event, url) => { + event.preventDefault() + deliverLink(url) + }) + + ipcMain.handle('studio:list-bridges', listBridges) + ipcMain.handle('studio:initial-link', () => { + const link = pendingLink + pendingLink = null + return link + }) + ipcMain.on('studio:set-theme', (_event, theme: ThemeChoice) => { + nativeTheme.themeSource = theme + }) + ipcMain.on('studio:copy-text', (_event, text: string) => clipboard.writeText(text)) + + void app.whenReady().then(createWindow) + app.on('window-all-closed', () => app.quit()) +} diff --git a/src/preload/index.ts b/src/preload/index.ts new file mode 100644 index 000000000..04fc0b303 --- /dev/null +++ b/src/preload/index.ts @@ -0,0 +1,16 @@ +import { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron' +import type { StudioHost, ThemeChoice } from '../shared/bridge' + +const host: StudioHost = { + listBridges: () => ipcRenderer.invoke('studio:list-bridges'), + initialLink: () => ipcRenderer.invoke('studio:initial-link'), + onLink: (listener) => { + const forward = (_event: IpcRendererEvent, link: string): void => listener(link) + ipcRenderer.on('studio:link', forward) + return () => ipcRenderer.removeListener('studio:link', forward) + }, + setTheme: (theme: ThemeChoice) => ipcRenderer.send('studio:set-theme', theme), + copyText: (text: string) => ipcRenderer.send('studio:copy-text', text) +} + +contextBridge.exposeInMainWorld('studio', host) diff --git a/src/renderer/index.html b/src/renderer/index.html new file mode 100644 index 000000000..34d3713d1 --- /dev/null +++ b/src/renderer/index.html @@ -0,0 +1,15 @@ + + + + + + Iris Studio + + +
+ + + diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx new file mode 100644 index 000000000..a611c54bb --- /dev/null +++ b/src/renderer/src/App.tsx @@ -0,0 +1,63 @@ +import { useCallback, useEffect, useState } from 'react' +import { parseStudioLink, type BridgeConnection } from '../../shared/bridge' +import { BridgeClient } from './bridge/BridgeClient' +import type { WorldInfo } from './bridge/types' +import { ConnectScreen } from './studio/ConnectScreen' +import { MapStudio } from './studio/MapStudio' +import { useTheme } from './studio/theme' + +interface Session { + client: BridgeClient + world: WorldInfo +} + +/** The studio: a connect screen until a bridge answers, then the map of its world. */ +export function App(): React.JSX.Element { + const theme = useTheme() + const [session, setSession] = useState(null) + const [error, setError] = useState(null) + const [connecting, setConnecting] = useState(false) + + const connect = useCallback(async (connection: BridgeConnection) => { + setConnecting(true) + setError(null) + const client = new BridgeClient(connection) + try { + setSession({ client, world: await client.world() }) + } catch (failure) { + setError(failure instanceof Error ? failure.message : String(failure)) + } finally { + setConnecting(false) + } + }, []) + + const connectLink = useCallback( + (link: string) => { + const connection = parseStudioLink(link) + if (connection === null) { + setError('That is not a studio link') + return + } + void connect(connection) + }, + [connect] + ) + + useEffect(() => { + void window.studio.initialLink().then((link) => link !== null && connectLink(link)) + return window.studio.onLink(connectLink) + }, [connectLink]) + + if (session === null) { + return + } + return ( + setSession(null)} + /> + ) +} diff --git a/src/renderer/src/bridge/BridgeClient.ts b/src/renderer/src/bridge/BridgeClient.ts new file mode 100644 index 000000000..f98f907e6 --- /dev/null +++ b/src/renderer/src/bridge/BridgeClient.ts @@ -0,0 +1,141 @@ +import type { BridgeConnection } from '../../../shared/bridge' +import { decodeTile } from './tileDecoding' +import type { MapHover, MapTile, Marker, WorldInfo } from './types' + +export class BridgeError extends Error { + constructor( + readonly status: number, + message: string + ) { + super(message) + } +} + +export interface TileRequest { + view: string + tileX: number + tileZ: number + blocksPerPixel: number + size: number + heights: boolean +} + +export interface BridgeEvents { + onWorld(running: boolean): void + onPlayers(players: Marker[]): void + onClosed(): void +} + +const EVENT_SEPARATOR = '\n\n' + +/** One connection to a world's bridge, over HTTP on the loopback interface. */ +export class BridgeClient { + private readonly base: string + private readonly authorization: string + + constructor(readonly connection: BridgeConnection) { + this.base = `http://127.0.0.1:${connection.port}/v1/` + this.authorization = `Bearer ${connection.token}` + } + + world(): Promise { + return this.json('world') + } + + hover(worldX: number, worldZ: number, signal?: AbortSignal): Promise { + return this.json(`hover?x=${worldX}&z=${worldZ}`, { signal }) + } + + entities(): Promise { + return this.json('entities') + } + + async teleport(worldX: number, worldZ: number): Promise { + await this.json(`teleport?x=${worldX}&z=${worldZ}`, { method: 'POST' }) + } + + /** Opens the file of the biome or region at a spot on the server's machine; the server's answer, if any. */ + async openInEditor(worldX: number, worldZ: number, view: string): Promise { + const answer = await this.json<{ message: string | null }>(`open?x=${worldX}&z=${worldZ}&view=${view}`, { method: 'POST' }) + return answer.message + } + + async tile(request: TileRequest, signal: AbortSignal): Promise { + const query = new URLSearchParams({ + view: request.view, + x: String(request.tileX), + z: String(request.tileZ), + scale: String(request.blocksPerPixel), + size: String(request.size), + heights: request.heights ? '1' : '0' + }) + const response = await this.fetch(`tile?${query}`, { signal }) + return decodeTile(await response.arrayBuffer()) + } + + /** Streams the bridge's events until {@code signal} aborts or the bridge goes away. */ + async listen(events: BridgeEvents, signal: AbortSignal): Promise { + try { + const response = await this.fetch('events', { signal }) + const reader = response.body!.pipeThrough(new TextDecoderStream()).getReader() + let pending = '' + for (;;) { + const { value, done } = await reader.read() + if (done) { + break + } + pending += value + let end: number + while ((end = pending.indexOf(EVENT_SEPARATOR)) >= 0) { + dispatch(pending.slice(0, end), events) + pending = pending.slice(end + EVENT_SEPARATOR.length) + } + } + } catch (error) { + if (signal.aborted) { + return + } + console.warn('Studio events stopped', error) + } + if (!signal.aborted) { + events.onClosed() + } + } + + private async json(endpoint: string, init: RequestInit = {}): Promise { + const response = await this.fetch(endpoint, init) + return (await response.json()) as T + } + + private async fetch(endpoint: string, init: RequestInit): Promise { + const response = await fetch(this.base + endpoint, { + ...init, + headers: { Authorization: this.authorization } + }) + if (!response.ok) { + const body = await response.json().catch(() => ({ error: response.statusText })) + throw new BridgeError(response.status, String(body.error ?? response.statusText)) + } + return response + } +} + +function dispatch(block: string, events: BridgeEvents): void { + let name = 'message' + let data = '' + for (const line of block.split('\n')) { + if (line.startsWith('event: ')) { + name = line.slice('event: '.length) + } else if (line.startsWith('data: ')) { + data += line.slice('data: '.length) + } + } + if (data === '') { + return + } + if (name === 'world') { + events.onWorld((JSON.parse(data) as { running: boolean }).running) + } else if (name === 'players') { + events.onPlayers(JSON.parse(data) as Marker[]) + } +} diff --git a/src/renderer/src/bridge/tileDecoding.ts b/src/renderer/src/bridge/tileDecoding.ts new file mode 100644 index 000000000..60b0da3cd --- /dev/null +++ b/src/renderer/src/bridge/tileDecoding.ts @@ -0,0 +1,44 @@ +import type { LabelKind, MapLabel, MapTile } from './types' + +const ALIGNMENT_BYTES = 4 + +interface TileHeader { + size: number + blocksPerPixel: number + subjectKind: LabelKind + labels: MapLabel[] + heights: boolean +} + +function aligned(bytes: number): number { + return Math.ceil(bytes / ALIGNMENT_BYTES) * ALIGNMENT_BYTES +} + +/** + * Reads a tile as the bridge writes it (MapTileEncoding): a u32 header length, the JSON header, then the subject, + * region and height grids, each starting on a multiple of 4 bytes. The grids are views into the buffer, not copies. + */ +export function decodeTile(buffer: ArrayBuffer): MapTile { + const view = new DataView(buffer) + const headerLength = view.getUint32(0, true) + const header = JSON.parse(new TextDecoder().decode(new Uint8Array(buffer, 4, headerLength))) as TileHeader + const gridSize = header.size + 2 + const cells = gridSize * gridSize + const subjectsAt = aligned(4 + headerLength) + const regionsAt = aligned(subjectsAt + cells * Int16Array.BYTES_PER_ELEMENT) + const heightsAt = aligned(regionsAt + cells * Int16Array.BYTES_PER_ELEMENT) + return { + size: header.size, + blocksPerPixel: header.blocksPerPixel, + subjectKind: header.subjectKind, + labels: header.labels, + subjects: new Int16Array(buffer, subjectsAt, cells), + regions: new Int16Array(buffer, regionsAt, cells), + heights: header.heights ? new Float32Array(buffer, heightsAt, cells) : null + } +} + +/** The grid index of a pixel; pixel coordinates run from -1 to size, the ring being the neighbours'. */ +export function gridIndex(tile: MapTile, pixelX: number, pixelZ: number): number { + return (pixelZ + 1) * (tile.size + 2) + pixelX + 1 +} diff --git a/src/renderer/src/bridge/types.ts b/src/renderer/src/bridge/types.ts new file mode 100644 index 000000000..6fd5ee3e3 --- /dev/null +++ b/src/renderer/src/bridge/types.ts @@ -0,0 +1,70 @@ +/** The shapes the Iris bridge answers with (Iris core, art.arcane.iris.core.studio). */ + +export type LabelKind = 'BIOME' | 'REGION' + +export interface MapLabel { + kind: LabelKind + key: string + name: string + /** 0xRRGGBB */ + color: number +} + +export interface ViewInfo { + id: string + label: string + description: string + group: string + groupLabel: string +} + +export interface WorldInfo { + world: string + dimension: string + dimensionName: string + seed: string + minY: number + height: number + fluidHeight: number + tileSize: number + hasPlayers: boolean + views: ViewInfo[] +} + +export interface MapHover { + worldX: number + worldZ: number + biome: MapLabel | null + caveBiome: MapLabel | null + region: MapLabel | null + vanillaBiome: string | null + height: number + fluidHeight: number + slopeDegrees: number + biomeFile: string | null + regionFile: string | null +} + +export interface Marker { + label: string + worldX: number + worldY: number + worldZ: number + health: number + maxHealth: number +} + +/** + * A decoded map tile. Grids hold (size + 2)² cells, the tile's pixels inside a ring of its neighbours' edge pixels. + */ +export interface MapTile { + size: number + blocksPerPixel: number + subjectKind: LabelKind + labels: MapLabel[] + subjects: Int16Array + regions: Int16Array + heights: Float32Array | null +} + +export const NO_LABEL = -1 diff --git a/src/renderer/src/components/ui/button.tsx b/src/renderer/src/components/ui/button.tsx new file mode 100644 index 000000000..0d202d63f --- /dev/null +++ b/src/renderer/src/components/ui/button.tsx @@ -0,0 +1,63 @@ +import * as React from "react" +import { cva, type VariantProps } from "class-variance-authority" +import { cn } from "@/lib/utils" +import { Slot } from "radix-ui" + +const buttonVariants = cva( + "inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", + { + variants: { + variant: { + default: "bg-primary text-primary-foreground hover:bg-primary/90", + destructive: + "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40", + outline: + "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50", + secondary: + "bg-secondary text-secondary-foreground hover:bg-secondary/80", + ghost: + "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-9 px-4 py-2 has-[>svg]:px-3", + xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3", + sm: "h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5", + lg: "h-10 rounded-md px-6 has-[>svg]:px-4", + icon: "size-9", + "icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3", + "icon-sm": "size-8", + "icon-lg": "size-10", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, + } +) + +function Button({ + className, + variant = "default", + size = "default", + asChild = false, + ...props +}: React.ComponentProps<"button"> & + VariantProps & { + asChild?: boolean + }) { + const Comp = asChild ? Slot.Root : "button" + + return ( + + ) +} + +export { Button, buttonVariants } diff --git a/src/renderer/src/components/ui/context-menu.tsx b/src/renderer/src/components/ui/context-menu.tsx new file mode 100644 index 000000000..c8d0ff606 --- /dev/null +++ b/src/renderer/src/components/ui/context-menu.tsx @@ -0,0 +1,249 @@ +import * as React from "react" +import { cn } from "@/lib/utils" +import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react" +import { ContextMenu as ContextMenuPrimitive } from "radix-ui" + +function ContextMenu({ + ...props +}: React.ComponentProps) { + return +} + +function ContextMenuTrigger({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function ContextMenuGroup({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function ContextMenuPortal({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function ContextMenuSub({ + ...props +}: React.ComponentProps) { + return +} + +function ContextMenuRadioGroup({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function ContextMenuSubTrigger({ + className, + inset, + children, + ...props +}: React.ComponentProps & { + inset?: boolean +}) { + return ( + + {children} + + + ) +} + +function ContextMenuSubContent({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function ContextMenuContent({ + className, + ...props +}: React.ComponentProps) { + return ( + + + + ) +} + +function ContextMenuItem({ + className, + inset, + variant = "default", + ...props +}: React.ComponentProps & { + inset?: boolean + variant?: "default" | "destructive" +}) { + return ( + + ) +} + +function ContextMenuCheckboxItem({ + className, + children, + checked, + ...props +}: React.ComponentProps) { + return ( + + + + + + + {children} + + ) +} + +function ContextMenuRadioItem({ + className, + children, + ...props +}: React.ComponentProps) { + return ( + + + + + + + {children} + + ) +} + +function ContextMenuLabel({ + className, + inset, + ...props +}: React.ComponentProps & { + inset?: boolean +}) { + return ( + + ) +} + +function ContextMenuSeparator({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function ContextMenuShortcut({ + className, + ...props +}: React.ComponentProps<"span">) { + return ( + + ) +} + +export { + ContextMenu, + ContextMenuTrigger, + ContextMenuContent, + ContextMenuItem, + ContextMenuCheckboxItem, + ContextMenuRadioItem, + ContextMenuLabel, + ContextMenuSeparator, + ContextMenuShortcut, + ContextMenuGroup, + ContextMenuPortal, + ContextMenuSub, + ContextMenuSubContent, + ContextMenuSubTrigger, + ContextMenuRadioGroup, +} diff --git a/src/renderer/src/components/ui/dialog.tsx b/src/renderer/src/components/ui/dialog.tsx new file mode 100644 index 000000000..92a3c49bb --- /dev/null +++ b/src/renderer/src/components/ui/dialog.tsx @@ -0,0 +1,158 @@ +"use client" + +import * as React from "react" +import { cn } from "@/lib/utils" +import { XIcon } from "lucide-react" +import { Dialog as DialogPrimitive } from "radix-ui" + +import { Button } from "@/components/ui/button" + +function Dialog({ + ...props +}: React.ComponentProps) { + return +} + +function DialogTrigger({ + ...props +}: React.ComponentProps) { + return +} + +function DialogPortal({ + ...props +}: React.ComponentProps) { + return +} + +function DialogClose({ + ...props +}: React.ComponentProps) { + return +} + +function DialogOverlay({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function DialogContent({ + className, + children, + showCloseButton = true, + ...props +}: React.ComponentProps & { + showCloseButton?: boolean +}) { + return ( + + + + {children} + {showCloseButton && ( + + + Close + + )} + + + ) +} + +function DialogHeader({ className, ...props }: React.ComponentProps<"div">) { + return ( +
+ ) +} + +function DialogFooter({ + className, + showCloseButton = false, + children, + ...props +}: React.ComponentProps<"div"> & { + showCloseButton?: boolean +}) { + return ( +
+ {children} + {showCloseButton && ( + + + + )} +
+ ) +} + +function DialogTitle({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function DialogDescription({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogOverlay, + DialogPortal, + DialogTitle, + DialogTrigger, +} diff --git a/src/renderer/src/components/ui/input.tsx b/src/renderer/src/components/ui/input.tsx new file mode 100644 index 000000000..1e3b93289 --- /dev/null +++ b/src/renderer/src/components/ui/input.tsx @@ -0,0 +1,20 @@ +import * as React from "react" +import { cn } from "@/lib/utils" + +function Input({ className, type, ...props }: React.ComponentProps<"input">) { + return ( + + ) +} + +export { Input } diff --git a/src/renderer/src/components/ui/kbd.tsx b/src/renderer/src/components/ui/kbd.tsx new file mode 100644 index 000000000..2459224fb --- /dev/null +++ b/src/renderer/src/components/ui/kbd.tsx @@ -0,0 +1,28 @@ +import { cn } from "@/lib/utils" + +function Kbd({ className, ...props }: React.ComponentProps<"kbd">) { + return ( + + ) +} + +function KbdGroup({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +export { Kbd, KbdGroup } diff --git a/src/renderer/src/components/ui/scroll-area.tsx b/src/renderer/src/components/ui/scroll-area.tsx new file mode 100644 index 000000000..b699a24ff --- /dev/null +++ b/src/renderer/src/components/ui/scroll-area.tsx @@ -0,0 +1,57 @@ +"use client" + +import * as React from "react" +import { cn } from "@/lib/utils" +import { ScrollArea as ScrollAreaPrimitive } from "radix-ui" + +function ScrollArea({ + className, + children, + ...props +}: React.ComponentProps) { + return ( + + + {children} + + + + + ) +} + +function ScrollBar({ + className, + orientation = "vertical", + ...props +}: React.ComponentProps) { + return ( + + + + ) +} + +export { ScrollArea, ScrollBar } diff --git a/src/renderer/src/components/ui/separator.tsx b/src/renderer/src/components/ui/separator.tsx new file mode 100644 index 000000000..056d875a1 --- /dev/null +++ b/src/renderer/src/components/ui/separator.tsx @@ -0,0 +1,25 @@ +import * as React from "react" +import { cn } from "@/lib/utils" +import { Separator as SeparatorPrimitive } from "radix-ui" + +function Separator({ + className, + orientation = "horizontal", + decorative = true, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { Separator } diff --git a/src/renderer/src/components/ui/toggle.tsx b/src/renderer/src/components/ui/toggle.tsx new file mode 100644 index 000000000..137c38510 --- /dev/null +++ b/src/renderer/src/components/ui/toggle.tsx @@ -0,0 +1,44 @@ +import * as React from "react" +import { cva, type VariantProps } from "class-variance-authority" +import { cn } from "@/lib/utils" +import { Toggle as TogglePrimitive } from "radix-ui" + +const toggleVariants = cva( + "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-[color,box-shadow] outline-none hover:bg-muted hover:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", + { + variants: { + variant: { + default: "bg-transparent", + outline: + "border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground", + }, + size: { + default: "h-9 min-w-9 px-2", + sm: "h-8 min-w-8 px-1.5", + lg: "h-10 min-w-10 px-2.5", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, + } +) + +function Toggle({ + className, + variant, + size, + ...props +}: React.ComponentProps & + VariantProps) { + return ( + + ) +} + +export { Toggle, toggleVariants } diff --git a/src/renderer/src/components/ui/tooltip.tsx b/src/renderer/src/components/ui/tooltip.tsx new file mode 100644 index 000000000..d10e766a1 --- /dev/null +++ b/src/renderer/src/components/ui/tooltip.tsx @@ -0,0 +1,56 @@ +"use client" + +import * as React from "react" +import { cn } from "@/lib/utils" +import { Tooltip as TooltipPrimitive } from "radix-ui" + +function TooltipProvider({ + delayDuration = 0, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function Tooltip({ + ...props +}: React.ComponentProps) { + return +} + +function TooltipTrigger({ + ...props +}: React.ComponentProps) { + return +} + +function TooltipContent({ + className, + sideOffset = 0, + children, + ...props +}: React.ComponentProps) { + return ( + + + {children} + + + + ) +} + +export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } diff --git a/src/renderer/src/css.d.ts b/src/renderer/src/css.d.ts new file mode 100644 index 000000000..5894ae0b6 --- /dev/null +++ b/src/renderer/src/css.d.ts @@ -0,0 +1 @@ +declare module '*.css' diff --git a/src/renderer/src/env.d.ts b/src/renderer/src/env.d.ts new file mode 100644 index 000000000..dc2bc14e4 --- /dev/null +++ b/src/renderer/src/env.d.ts @@ -0,0 +1,9 @@ +import type { StudioHost } from '../../shared/bridge' + +declare global { + interface Window { + studio: StudioHost + } +} + +export {} diff --git a/src/renderer/src/lib/utils.ts b/src/renderer/src/lib/utils.ts new file mode 100644 index 000000000..b057456de --- /dev/null +++ b/src/renderer/src/lib/utils.ts @@ -0,0 +1,6 @@ +import { clsx, type ClassValue } from 'clsx' +import { twMerge } from 'tailwind-merge' + +export function cn(...inputs: ClassValue[]): string { + return twMerge(clsx(inputs)) +} diff --git a/src/renderer/src/main.tsx b/src/renderer/src/main.tsx new file mode 100644 index 000000000..3ea6345e0 --- /dev/null +++ b/src/renderer/src/main.tsx @@ -0,0 +1,13 @@ +import { StrictMode } from 'react' +import { createRoot } from 'react-dom/client' +import { TooltipProvider } from '@/components/ui/tooltip' +import { App } from './App' +import './styles.css' + +createRoot(document.getElementById('root')!).render( + + + + + +) diff --git a/src/renderer/src/map/MapController.ts b/src/renderer/src/map/MapController.ts new file mode 100644 index 000000000..1e814b01a --- /dev/null +++ b/src/renderer/src/map/MapController.ts @@ -0,0 +1,406 @@ +import type { BridgeClient } from '../bridge/BridgeClient' +import { gridIndex } from '../bridge/tileDecoding' +import { NO_LABEL, type MapLabel, type Marker, type WorldInfo } from '../bridge/types' +import { countShares, type PlacedTile, type Share } from './census' +import { bandIndexOf, HEIGHT_BANDS } from './heightColors' +import type { Highlight, TileStyle } from './tileStyle' +import { TileStore, type TileLayer } from './TileStore' +import { + clampBlocksPerPixel, + coarserTile, + previewsFor, + DEFAULT_BLOCKS_PER_PIXEL, + renderBlocksPerPixel, + screenToWorldX, + screenToWorldZ, + visibleTiles, + worldToScreenX, + worldToScreenZ, + type TileAddress, + type Viewport +} from './viewport' + +export interface MapStatus { + blocksPerPixel: number + widthBlocks: number + heightBlocks: number + tilesReady: number + tilesTotal: number + cursorX: number + cursorZ: number +} + +export interface MapListener { + onStatus(status: MapStatus): void + onShares(shares: Share[]): void + onError(message: string): void +} + +/** What the map shows at a spot, read from the tiles already drawn. */ +export interface SpotSubjects { + subject: Highlight | null + region: Highlight | null +} + +export interface MapToggles { + shading: boolean + regionBorders: boolean + grid: boolean +} + +// While a tile is on its way, a coarser one already drawn stands in, up to this many zoom levels out. +const COARSER_FALLBACK_LEVELS = 6 +const CENSUS_INTERVAL_MILLIS = 250 +const CHUNK_BLOCKS = 16 +const REGION_BLOCKS = 512 +const SMALLEST_GRID_GAP_PIXELS = 8 +const CHUNK_LINE = 'rgba(255, 255, 255, 0.14)' +const REGION_LINE = 'rgba(255, 255, 255, 0.38)' +const PLAYER_FILL = '#3574f0' +const ENTITY_FILL = '#f75464' +const MARKER_OUTLINE = '#ffffff' +const PLAYER_RADIUS_PIXELS = 6 +const ENTITY_RADIUS_PIXELS = 3 + +/** + * The 2D map on a canvas: which tiles to fetch for the view, drawing them in the current style, and the grid and + * markers on top. Kept outside React, as it redraws on every drag and wheel step. + */ +export class MapController { + private readonly context: CanvasRenderingContext2D + private readonly store: TileStore + private readonly view: Viewport = { centerX: 0, centerZ: 0, blocksPerPixel: DEFAULT_BLOCKS_PER_PIXEL, width: 1, height: 1 } + private layer: TileLayer + private toggles: MapToggles = { shading: true, regionBorders: false, grid: false } + private highlight: Highlight | null = null + private players: Marker[] = [] + private entities: Marker[] = [] + private cursor: { x: number; y: number } | null = null + private frameRequested = false + private lastCensusMillis = 0 + private censusTimer: number | undefined + private closed = false + + constructor( + private readonly canvas: HTMLCanvasElement, + client: BridgeClient, + private readonly world: WorldInfo, + view: string, + private readonly listener: MapListener + ) { + this.context = canvas.getContext('2d')! + this.layer = { view, heights: this.needsHeights(view, this.toggles), revision: 0 } + this.store = new TileStore(client, world.tileSize, () => this.redraw(), (message) => listener.onError(message)) + } + + close(): void { + this.closed = true + window.clearTimeout(this.censusTimer) + this.store.clear() + } + + resize(width: number, height: number): void { + const ratio = window.devicePixelRatio + this.canvas.width = Math.round(width * ratio) + this.canvas.height = Math.round(height * ratio) + this.view.width = width + this.view.height = height + this.redraw() + } + + setView(view: string): void { + this.layer = { ...this.layer, view, heights: this.needsHeights(view, this.toggles) } + this.redraw() + } + + setToggles(toggles: MapToggles): void { + this.toggles = toggles + this.layer = { ...this.layer, heights: this.needsHeights(this.layer.view, toggles) } + this.redraw() + } + + // Heights are the costly part of a tile, so they are only asked for when something draws with them. + private needsHeights(view: string, toggles: MapToggles): boolean { + return toggles.shading || view === 'height' + } + + setHighlight(highlight: Highlight | null): void { + this.highlight = highlight + this.redraw() + } + + setMarkers(players: Marker[], entities: Marker[]): void { + this.players = players + this.entities = entities + this.redraw() + } + + setCursor(cursor: { x: number; y: number } | null): void { + this.cursor = cursor + this.reportStatus() + } + + /** Draws everything again from the server, after the pack changed. */ + refresh(): void { + this.store.clear() + this.layer = { ...this.layer, revision: this.layer.revision + 1 } + this.redraw() + } + + panBy(screenDeltaX: number, screenDeltaZ: number): void { + this.view.centerX -= screenDeltaX * this.view.blocksPerPixel + this.view.centerZ -= screenDeltaZ * this.view.blocksPerPixel + this.redraw() + } + + centerOn(worldX: number, worldZ: number): void { + this.view.centerX = worldX + this.view.centerZ = worldZ + this.redraw() + } + + /** Zooms by {@code factor} (above 1 zooms in) keeping the world spot under the screen point where it is. */ + zoomAt(factor: number, screenX = this.view.width / 2, screenZ = this.view.height / 2): void { + const worldX = screenToWorldX(this.view, screenX) + const worldZ = screenToWorldZ(this.view, screenZ) + this.view.blocksPerPixel = clampBlocksPerPixel(this.view.blocksPerPixel / factor) + this.view.centerX = worldX - (screenX - this.view.width / 2) * this.view.blocksPerPixel + this.view.centerZ = worldZ - (screenZ - this.view.height / 2) * this.view.blocksPerPixel + this.redraw() + } + + resetZoom(): void { + this.view.blocksPerPixel = DEFAULT_BLOCKS_PER_PIXEL + this.redraw() + } + + worldAt(screenX: number, screenZ: number): { x: number; z: number } { + return { x: screenToWorldX(this.view, screenX), z: screenToWorldZ(this.view, screenZ) } + } + + /** The biome or region and the region at a screen point, from the tile drawn there; nulls before it arrived. */ + subjectsAt(screenX: number, screenZ: number): SpotSubjects { + const worldX = screenToWorldX(this.view, screenX) + const worldZ = screenToWorldZ(this.view, screenZ) + const scale = this.renderScale() + const span = this.world.tileSize * scale + const address = { tileX: Math.floor(worldX / span), tileZ: Math.floor(worldZ / span), blocksPerPixel: scale } + const tile = this.store.get(address, this.layer) + if (tile === null) { + return { subject: null, region: null } + } + const pixelX = Math.min(tile.size - 1, Math.floor((worldX - address.tileX * span) / scale)) + const pixelZ = Math.min(tile.size - 1, Math.floor((worldZ - address.tileZ * span) / scale)) + const cell = gridIndex(tile, pixelX, pixelZ) + const region = labelAt(tile.labels, tile.regions[cell]) + if (this.isHeightView() && tile.heights !== null) { + const band = HEIGHT_BANDS[bandIndexOf(tile.heights[cell], this.world.fluidHeight)] + return { subject: { kind: 'HEIGHT', key: band.key, name: band.name }, region } + } + return { subject: labelAt(tile.labels, tile.subjects[cell]), region } + } + + private isHeightView(): boolean { + return this.layer.view === 'height' + } + + private renderScale(): number { + return renderBlocksPerPixel(this.view.blocksPerPixel, window.devicePixelRatio) + } + + private style(): TileStyle { + return { + byHeight: this.isHeightView(), + shading: this.toggles.shading, + regionBorders: this.toggles.regionBorders, + highlight: this.highlight, + seaLevel: this.world.fluidHeight + } + } + + private redraw(): void { + if (this.frameRequested || this.closed) { + return + } + this.frameRequested = true + requestAnimationFrame(() => { + this.frameRequested = false + if (!this.closed) { + this.draw() + } + }) + } + + private draw(): void { + const ratio = window.devicePixelRatio + const context = this.context + context.setTransform(ratio, 0, 0, ratio, 0, 0) + context.fillStyle = getComputedStyle(this.canvas).getPropertyValue('--map-background') || '#16171a' + context.fillRect(0, 0, this.view.width, this.view.height) + + const scale = this.renderScale() + const tiles = visibleTiles(this.view, scale, this.world.tileSize) + const style = this.style() + context.imageSmoothingEnabled = this.view.blocksPerPixel > scale + let ready = 0 + const blank: TileAddress[] = [] + for (const address of tiles) { + const picture = this.store.picture(address, this.layer, style) + if (picture !== null) { + this.drawTile(picture, address, 0, 0, picture.width) + ready++ + } else if (!this.drawFallback(address, style)) { + blank.push(address) + } + } + this.store.want([...previewsFor(blank), ...tiles], this.layer) + if (this.toggles.grid) { + this.drawGrid() + } + this.drawMarkers() + this.reportStatus(ready, tiles.length) + this.scheduleCensus(tiles) + } + + /** Draws the part of a tile picture from (sourceX, sourceZ), {@code sourceSize} pixels wide, over {@code address}. */ + private drawTile(picture: HTMLCanvasElement, address: TileAddress, sourceX: number, sourceZ: number, sourceSize: number): void { + const span = this.world.tileSize * address.blocksPerPixel + const left = Math.round(worldToScreenX(this.view, address.tileX * span)) + const top = Math.round(worldToScreenZ(this.view, address.tileZ * span)) + const right = Math.round(worldToScreenX(this.view, (address.tileX + 1) * span)) + const bottom = Math.round(worldToScreenZ(this.view, (address.tileZ + 1) * span)) + this.context.drawImage(picture, sourceX, sourceZ, sourceSize, sourceSize, left, top, right - left, bottom - top) + } + + /** Draws the part of a coarser tile that covers {@code address}; false when no coarser tile has arrived either. */ + private drawFallback(address: TileAddress, style: TileStyle): boolean { + for (let levels = 1; levels <= COARSER_FALLBACK_LEVELS; levels++) { + const coarser = coarserTile(address, levels) + const picture = this.store.picture(coarser, this.layer, style) + if (picture === null) { + continue + } + const factor = 2 ** levels + const sourceSize = picture.width / factor + const sourceX = (address.tileX - coarser.tileX * factor) * sourceSize + const sourceZ = (address.tileZ - coarser.tileZ * factor) * sourceSize + this.drawTile(picture, address, sourceX, sourceZ, sourceSize) + return true + } + return false + } + + private drawGrid(): void { + this.drawLines(CHUNK_BLOCKS, CHUNK_LINE, 1) + this.drawLines(REGION_BLOCKS, REGION_LINE, 1.5) + } + + private drawLines(gapBlocks: number, color: string, width: number): void { + if (gapBlocks / this.view.blocksPerPixel < SMALLEST_GRID_GAP_PIXELS) { + return + } + const context = this.context + context.strokeStyle = color + context.lineWidth = width + context.beginPath() + const firstX = Math.ceil(screenToWorldX(this.view, 0) / gapBlocks) * gapBlocks + for (let worldX = firstX; worldX <= screenToWorldX(this.view, this.view.width); worldX += gapBlocks) { + const screenX = Math.round(worldToScreenX(this.view, worldX)) + 0.5 + context.moveTo(screenX, 0) + context.lineTo(screenX, this.view.height) + } + const firstZ = Math.ceil(screenToWorldZ(this.view, 0) / gapBlocks) * gapBlocks + for (let worldZ = firstZ; worldZ <= screenToWorldZ(this.view, this.view.height); worldZ += gapBlocks) { + const screenZ = Math.round(worldToScreenZ(this.view, worldZ)) + 0.5 + context.moveTo(0, screenZ) + context.lineTo(this.view.width, screenZ) + } + context.stroke() + } + + private drawMarkers(): void { + for (const entity of this.entities) { + this.drawMarker(entity, ENTITY_FILL, ENTITY_RADIUS_PIXELS, false) + } + for (const player of this.players) { + this.drawMarker(player, PLAYER_FILL, PLAYER_RADIUS_PIXELS, true) + } + } + + private drawMarker(marker: Marker, fill: string, radius: number, named: boolean): void { + const context = this.context + const x = worldToScreenX(this.view, marker.worldX) + const z = worldToScreenZ(this.view, marker.worldZ) + context.beginPath() + context.arc(x, z, radius, 0, Math.PI * 2) + context.fillStyle = fill + context.fill() + context.lineWidth = 2 + context.strokeStyle = MARKER_OUTLINE + context.stroke() + if (!named) { + return + } + context.font = '600 12px Inter, "Segoe UI", system-ui, sans-serif' + context.textAlign = 'center' + context.lineWidth = 3 + context.strokeStyle = 'rgba(0, 0, 0, 0.7)' + context.strokeText(marker.label, x, z - radius - 6) + context.fillStyle = MARKER_OUTLINE + context.fillText(marker.label, x, z - radius - 6) + } + + private lastReady = 0 + private lastTotal = 0 + + private reportStatus(ready = this.lastReady, total = this.lastTotal): void { + this.lastReady = ready + this.lastTotal = total + const cursor = this.cursor === null ? { x: this.view.width / 2, y: this.view.height / 2 } : this.cursor + this.listener.onStatus({ + blocksPerPixel: this.view.blocksPerPixel, + widthBlocks: Math.round(this.view.width * this.view.blocksPerPixel), + heightBlocks: Math.round(this.view.height * this.view.blocksPerPixel), + tilesReady: ready, + tilesTotal: total, + cursorX: Math.floor(screenToWorldX(this.view, cursor.x)), + cursorZ: Math.floor(screenToWorldZ(this.view, cursor.y)) + }) + } + + // Counting what is on screen is cheap but not free, so it runs at most a few times a second and once more at rest. + private scheduleCensus(tiles: TileAddress[]): void { + window.clearTimeout(this.censusTimer) + const wait = Math.max(0, this.lastCensusMillis + CENSUS_INTERVAL_MILLIS - performance.now()) + this.censusTimer = window.setTimeout(() => { + this.lastCensusMillis = performance.now() + this.listener.onShares(this.census(tiles)) + }, wait) + } + + private census(tiles: TileAddress[]): Share[] { + const placed: PlacedTile[] = [] + for (const address of tiles) { + const tile = this.store.get(address, this.layer) + if (tile !== null) { + const span = this.world.tileSize * address.blocksPerPixel + placed.push({ tile, worldX: address.tileX * span, worldZ: address.tileZ * span }) + } + } + const area = { + minimumX: screenToWorldX(this.view, 0), + minimumZ: screenToWorldZ(this.view, 0), + maximumX: screenToWorldX(this.view, this.view.width), + maximumZ: screenToWorldZ(this.view, this.view.height) + } + return countShares(placed, area, this.isHeightView(), this.world.fluidHeight) + } +} + +function labelAt(labels: MapLabel[], index: number): Highlight | null { + if (index === NO_LABEL) { + return null + } + const label = labels[index] + return { kind: label.kind, key: label.key, name: label.name } +} diff --git a/src/renderer/src/map/TileStore.ts b/src/renderer/src/map/TileStore.ts new file mode 100644 index 000000000..56d279562 --- /dev/null +++ b/src/renderer/src/map/TileStore.ts @@ -0,0 +1,167 @@ +import { BridgeError, type BridgeClient } from '../bridge/BridgeClient' +import type { MapTile } from '../bridge/types' +import { stylePixels, styleKey, type TileStyle } from './tileStyle' +import type { TileAddress } from './viewport' + +/** What one tile request needs besides where the tile is. */ +export interface TileLayer { + view: string + heights: boolean + /** Bumped when the pack is hotloaded, so older tiles are not used again. */ + revision: number +} + +interface StoredTile { + tile: MapTile + bytes: number + lastUsed: number + picture: HTMLCanvasElement | null + pictureStyle: string +} + +// Drawing a few hundred tiles at once only queues them on the server; a handful in flight keeps it busy. +const MAXIMUM_IN_FLIGHT = 6 +const CACHE_BYTES = 256 * 1024 * 1024 + +/** + * The map's tiles: fetched from the bridge as the view needs them, kept within a memory budget, and drawn as the + * current style asks. A tile that leaves the view before it arrives is not fetched. + */ +export class TileStore { + private readonly tiles = new Map() + private readonly inFlight = new Map() + /** Asked for again only after a refresh, which changes every key, so a broken tile is not fetched on every frame. */ + private readonly failed = new Set() + private wanted: { key: string; address: TileAddress; layer: TileLayer }[] = [] + private storedBytes = 0 + private useClock = 0 + + constructor( + private readonly client: BridgeClient, + private readonly tileSize: number, + private readonly onChange: () => void, + private readonly onError: (message: string) => void + ) {} + + key(address: TileAddress, layer: TileLayer): string { + return `${layer.revision}/${layer.view}/${layer.heights}/${address.blocksPerPixel}/${address.tileX}/${address.tileZ}` + } + + /** The tile if it has arrived, marked as just used. */ + get(address: TileAddress, layer: TileLayer): MapTile | null { + const stored = this.tiles.get(this.key(address, layer)) + if (stored === undefined) { + return null + } + stored.lastUsed = ++this.useClock + return stored.tile + } + + /** The tile drawn in {@code style}; restyled only when the style changed since it was last drawn. */ + picture(address: TileAddress, layer: TileLayer, style: TileStyle): HTMLCanvasElement | null { + const stored = this.tiles.get(this.key(address, layer)) + if (stored === undefined) { + return null + } + stored.lastUsed = ++this.useClock + const wantedStyle = styleKey(style) + if (stored.picture === null || stored.pictureStyle !== wantedStyle) { + stored.picture = stored.picture ?? document.createElement('canvas') + paint(stored.picture, stored.tile, style) + stored.pictureStyle = wantedStyle + } + return stored.picture + } + + /** Fetches the tiles the view shows, in the order given, and gives up on the ones it no longer shows. */ + want(addresses: TileAddress[], layer: TileLayer): void { + this.wanted = addresses + .map((address) => ({ key: this.key(address, layer), address, layer })) + .filter((entry) => !this.tiles.has(entry.key) && !this.failed.has(entry.key)) + const stillWanted = new Set(this.wanted.map((entry) => entry.key)) + for (const [key, controller] of this.inFlight) { + if (!stillWanted.has(key)) { + controller.abort() + this.inFlight.delete(key) + } + } + this.startRequests() + } + + /** How many of the wanted tiles are still on their way. */ + pending(): number { + return this.wanted.length + } + + clear(): void { + for (const controller of this.inFlight.values()) { + controller.abort() + } + this.inFlight.clear() + this.failed.clear() + this.tiles.clear() + this.wanted = [] + this.storedBytes = 0 + } + + private startRequests(): void { + for (const entry of this.wanted) { + if (this.inFlight.size >= MAXIMUM_IN_FLIGHT) { + return + } + if (!this.inFlight.has(entry.key)) { + this.fetchTile(entry.key, entry.address, entry.layer) + } + } + } + + private fetchTile(key: string, address: TileAddress, layer: TileLayer): void { + const controller = new AbortController() + this.inFlight.set(key, controller) + const request = { view: layer.view, ...address, size: this.tileSize, heights: layer.heights } + this.client + .tile(request, controller.signal) + .then((tile) => this.store(key, tile)) + .catch((error: unknown) => { + if (!controller.signal.aborted) { + this.failed.add(key) + this.onError(error instanceof BridgeError ? error.message : 'The server did not answer') + } + }) + .finally(() => { + if (this.inFlight.get(key) === controller) { + this.inFlight.delete(key) + } + this.wanted = this.wanted.filter((entry) => entry.key !== key) + this.startRequests() + this.onChange() + }) + } + + private store(key: string, tile: MapTile): void { + const bytes = tile.subjects.byteLength * 2 + (tile.heights?.byteLength ?? 0) + tile.size * tile.size * 4 + this.tiles.set(key, { tile, bytes, lastUsed: ++this.useClock, picture: null, pictureStyle: '' }) + this.storedBytes += bytes + this.evictOldest() + } + + private evictOldest(): void { + if (this.storedBytes <= CACHE_BYTES) { + return + } + const byAge = [...this.tiles.entries()].sort((first, second) => first[1].lastUsed - second[1].lastUsed) + for (const [key, stored] of byAge) { + if (this.storedBytes <= CACHE_BYTES * 0.8) { + return + } + this.tiles.delete(key) + this.storedBytes -= stored.bytes + } + } +} + +function paint(canvas: HTMLCanvasElement, tile: MapTile, style: TileStyle): void { + canvas.width = tile.size + canvas.height = tile.size + canvas.getContext('2d')!.putImageData(new ImageData(stylePixels(tile, style), tile.size, tile.size), 0, 0) +} diff --git a/src/renderer/src/map/census.ts b/src/renderer/src/map/census.ts new file mode 100644 index 000000000..83df8b6ee --- /dev/null +++ b/src/renderer/src/map/census.ts @@ -0,0 +1,78 @@ +import { gridIndex } from '../bridge/tileDecoding' +import { NO_LABEL, type MapTile } from '../bridge/types' +import { bandIndexOf, HEIGHT_BANDS } from './heightColors' +import type { Highlight } from './tileStyle' + +/** How much of the screen one biome, region or height band covers. */ +export interface Share { + subject: Highlight + color: number + fraction: number +} + +/** A loaded tile and where its top left pixel lies in the world. */ +export interface PlacedTile { + tile: MapTile + worldX: number + worldZ: number +} + +export interface WorldArea { + minimumX: number + minimumZ: number + maximumX: number + maximumZ: number +} + +// Enough samples that a share is right to a fraction of a percent, few enough to count every frame the map settles. +const MAXIMUM_COUNTED_PIXELS = 250_000 + +/** + * The shares of what the tiles show inside {@code area}, largest first: their subjects (biomes or regions), or their + * height bands when {@code byHeight} is set. + */ +export function countShares(tiles: PlacedTile[], area: WorldArea, byHeight: boolean, seaLevel: number): Share[] { + const counts = new Map() + const totalPixels = tiles.reduce((sum, placed) => sum + placed.tile.size * placed.tile.size, 0) + const stride = Math.max(1, Math.ceil(Math.sqrt(totalPixels / MAXIMUM_COUNTED_PIXELS))) + let counted = 0 + for (const { tile, worldX, worldZ } of tiles) { + const scale = tile.blocksPerPixel + const firstX = Math.max(0, Math.ceil((area.minimumX - worldX) / scale)) + const endX = Math.min(tile.size, Math.ceil((area.maximumX - worldX) / scale)) + const firstZ = Math.max(0, Math.ceil((area.minimumZ - worldZ) / scale)) + const endZ = Math.min(tile.size, Math.ceil((area.maximumZ - worldZ) / scale)) + for (let pixelZ = firstZ; pixelZ < endZ; pixelZ += stride) { + for (let pixelX = firstX; pixelX < endX; pixelX += stride) { + const subject = subjectAt(tile, gridIndex(tile, pixelX, pixelZ), byHeight, seaLevel) + if (subject === null) { + continue + } + const id = `${subject.subject.kind}:${subject.subject.key}` + const entry = counts.get(id) ?? { ...subject, count: 0 } + entry.count++ + counts.set(id, entry) + counted++ + } + } + } + return [...counts.values()] + .map((entry) => ({ subject: entry.subject, color: entry.color, fraction: entry.count / Math.max(1, counted) })) + .sort((first, second) => second.fraction - first.fraction) +} + +function subjectAt(tile: MapTile, cell: number, byHeight: boolean, seaLevel: number): { subject: Highlight; color: number } | null { + if (byHeight) { + if (tile.heights === null) { + return null + } + const band = HEIGHT_BANDS[bandIndexOf(tile.heights[cell], seaLevel)] + return { subject: { kind: 'HEIGHT', key: band.key, name: band.name }, color: band.color } + } + const index = tile.subjects[cell] + if (index === NO_LABEL) { + return null + } + const label = tile.labels[index] + return { subject: { kind: label.kind, key: label.key, name: label.name }, color: label.color } +} diff --git a/src/renderer/src/map/heightColors.ts b/src/renderer/src/map/heightColors.ts new file mode 100644 index 000000000..60c364b0a --- /dev/null +++ b/src/renderer/src/map/heightColors.ts @@ -0,0 +1,76 @@ +/** The height scale of the map, from deep water to snowy peaks, measured from sea level (v3e HeightColors). */ + +const DEEPEST_BELOW_SEA_BLOCKS = 90 +const HIGHEST_ABOVE_SEA_BLOCKS = 300 +const DEPTH_BLOCKS = [0, 10, 40, DEEPEST_BELOW_SEA_BLOCKS] +const DEPTH_COLORS = [0x7db8d8, 0x4c8dba, 0x2a5e8f, 0x15304f] +const ABOVE_SEA_BLOCKS = [0, 8, 30, 70, 130, 200, HIGHEST_ABOVE_SEA_BLOCKS] +const LAND_COLORS = [0x7fa35a, 0x5e8c44, 0x8fa65a, 0xc2ae78, 0x8e7663, 0xa9a6a2, 0xf4f4f4] +// Where each band ends, in blocks above sea; they follow the colour stops, merging the deepest two. +const BAND_TOPS_ABOVE_SEA = [-40, -10, 0, 8, 30, 70, 130, 200, 300, Number.POSITIVE_INFINITY] + +/** A stretch of heights between two of the scale's stops, for telling how much ground lies at each height. */ +export interface HeightBand { + /** The band's place from the deepest, as text that sorts the same way. */ + key: string + name: string + color: number +} + +export function heightColor(height: number, seaLevel: number): number { + if (height <= seaLevel) { + return along(DEPTH_BLOCKS, DEPTH_COLORS, seaLevel - height) + } + return along(ABOVE_SEA_BLOCKS, LAND_COLORS, height - seaLevel) +} + +export const HEIGHT_BANDS: readonly HeightBand[] = createBands() + +export function bandIndexOf(height: number, seaLevel: number): number { + const aboveSea = height - seaLevel + const index = BAND_TOPS_ABOVE_SEA.findIndex((top) => aboveSea <= top) + return index < 0 ? BAND_TOPS_ABOVE_SEA.length - 1 : index +} + +function createBands(): HeightBand[] { + const bands: HeightBand[] = [] + let bottom = -DEEPEST_BELOW_SEA_BLOCKS + BAND_TOPS_ABOVE_SEA.forEach((top, band) => { + const colorHeight = Number.isFinite(top) ? (bottom + top) / 2 : bottom + bands.push({ key: String(band).padStart(2, '0'), name: bandName(band, bottom, top), color: heightColor(colorHeight, 0) }) + bottom = top + }) + return bands +} + +function bandName(band: number, bottom: number, top: number): string { + if (band === 0) { + return `${Math.round(-top)}+ below sea` + } + if (!Number.isFinite(top)) { + return `${Math.round(bottom)}+ above sea` + } + if (top <= 0) { + return `${Math.round(-top)}–${Math.round(-bottom)} below sea` + } + return `${Math.round(bottom)}–${Math.round(top)} above sea` +} + +function along(stops: number[], colors: number[], blocks: number): number { + if (blocks <= stops[0]) { + return colors[0] + } + for (let stop = 1; stop < stops.length; stop++) { + if (blocks <= stops[stop]) { + return blend(colors[stop - 1], colors[stop], (blocks - stops[stop - 1]) / (stops[stop] - stops[stop - 1])) + } + } + return colors[colors.length - 1] +} + +export function blend(first: number, second: number, amount: number): number { + const red = Math.round(((first >> 16) & 0xff) * (1 - amount) + ((second >> 16) & 0xff) * amount) + const green = Math.round(((first >> 8) & 0xff) * (1 - amount) + ((second >> 8) & 0xff) * amount) + const blue = Math.round((first & 0xff) * (1 - amount) + (second & 0xff) * amount) + return (red << 16) | (green << 8) | blue +} diff --git a/src/renderer/src/map/map.test.ts b/src/renderer/src/map/map.test.ts new file mode 100644 index 000000000..555b304b6 --- /dev/null +++ b/src/renderer/src/map/map.test.ts @@ -0,0 +1,178 @@ +import { describe, expect, it } from 'vitest' +import { decodeTile, gridIndex } from '../bridge/tileDecoding' +import type { MapLabel, MapTile } from '../bridge/types' +import { countShares } from './census' +import { bandIndexOf, HEIGHT_BANDS, heightColor } from './heightColors' +import { stylePixels, type TileStyle } from './tileStyle' +import { coarserTile, previewsFor, renderBlocksPerPixel, screenToWorldX, visibleTiles, worldToScreenX, type Viewport } from './viewport' + +const PLAINS: MapLabel = { kind: 'BIOME', key: 'plains', name: 'Plains', color: 0x00ff00 } +const DESERT: MapLabel = { kind: 'BIOME', key: 'desert', name: 'Desert', color: 0xffff00 } +const WARM: MapLabel = { kind: 'REGION', key: 'warm', name: 'Warm', color: 0xff0000 } +const FLAT: TileStyle = { byHeight: false, shading: false, regionBorders: false, highlight: null, seaLevel: 63 } + +/** A tile whose left half is plains and right half desert, all in one region, at height 70. */ +function splitTile(size = 4): MapTile { + const cells = (size + 2) ** 2 + const subjects = new Int16Array(cells) + for (let cell = 0; cell < cells; cell++) { + subjects[cell] = cell % (size + 2) <= size / 2 ? 0 : 1 + } + return { + size, + blocksPerPixel: 1, + subjectKind: 'BIOME', + labels: [PLAINS, DESERT, WARM], + subjects, + regions: new Int16Array(cells).fill(2), + heights: new Float32Array(cells).fill(70) + } +} + +/** A tile as the bridge sends it: u32 header length, JSON header, aligned grids. */ +function encode(size: number, withHeights: boolean): ArrayBuffer { + const header = new TextEncoder().encode(JSON.stringify({ size, blocksPerPixel: 2, subjectKind: 'BIOME', labels: [PLAINS], heights: withHeights })) + const cells = (size + 2) ** 2 + const align = (bytes: number): number => Math.ceil(bytes / 4) * 4 + const subjectsAt = align(4 + header.length) + const regionsAt = align(subjectsAt + cells * 2) + const heightsAt = align(regionsAt + cells * 2) + const buffer = new ArrayBuffer(heightsAt + (withHeights ? cells * 4 : 0)) + new DataView(buffer).setUint32(0, header.length, true) + new Uint8Array(buffer, 4).set(header) + new Int16Array(buffer, subjectsAt, cells).fill(0) + new Int16Array(buffer, regionsAt, cells).fill(-1) + if (withHeights) { + new Float32Array(buffer, heightsAt, cells).fill(81.5) + } + return buffer +} + +describe('tile decoding', () => { + it('reads the header and views each grid where the bridge put it', () => { + const tile = decodeTile(encode(3, true)) + + expect(tile.size).toBe(3) + expect(tile.blocksPerPixel).toBe(2) + expect(tile.labels[0].key).toBe('plains') + expect(tile.subjects.length).toBe(25) + expect(tile.regions[0]).toBe(-1) + expect(tile.heights?.[24]).toBe(81.5) + }) + + it('has no heights when the header says so', () => { + expect(decodeTile(encode(3, false)).heights).toBeNull() + }) +}) + +describe('height colours', () => { + it('runs from deep water to snow and stays at the ends beyond them', () => { + expect(heightColor(63, 63)).toBe(0x7db8d8) + expect(heightColor(-1000, 63)).toBe(0x15304f) + expect(heightColor(1000, 63)).toBe(0xf4f4f4) + }) + + it('puts each height in the band the legend names', () => { + expect(HEIGHT_BANDS[bandIndexOf(63, 63)].name).toBe('0–10 below sea') + expect(HEIGHT_BANDS[bandIndexOf(64, 63)].name).toBe('0–8 above sea') + expect(HEIGHT_BANDS[bandIndexOf(500, 63)].name).toBe('300+ above sea') + expect(HEIGHT_BANDS[bandIndexOf(-500, 63)].name).toBe('40+ below sea') + }) +}) + +describe('tile style', () => { + const pixel = (pixels: Uint8ClampedArray, size: number, x: number, z: number): number => { + const at = (z * size + x) * 4 + return (pixels[at] << 16) | (pixels[at + 1] << 8) | pixels[at + 2] + } + + it('paints each pixel in its label colour', () => { + const pixels = stylePixels(splitTile(), FLAT) + + expect(pixel(pixels, 4, 0, 0)).toBe(PLAINS.color) + expect(pixel(pixels, 4, 3, 3)).toBe(DESERT.color) + }) + + it('dims everything but the highlight, and tints the highlight edge', () => { + const pixels = stylePixels(splitTile(), { ...FLAT, highlight: { kind: 'BIOME', key: 'plains', name: 'Plains' } }) + + expect(pixel(pixels, 4, 3, 3)).not.toBe(DESERT.color) + expect(pixel(pixels, 4, 0, 1)).toBe(PLAINS.color) + expect(pixel(pixels, 4, 1, 1)).not.toBe(PLAINS.color) + }) + + it('leaves flat ground almost as it is when shading', () => { + const pixels = stylePixels(splitTile(), { ...FLAT, shading: true }) + const green = (pixel(pixels, 4, 0, 0) >> 8) & 0xff + + expect(green).toBeGreaterThan(200) + }) +}) + +describe('viewport', () => { + const view: Viewport = { centerX: 100, centerZ: -50, blocksPerPixel: 2, width: 800, height: 600 } + + it('maps screen and world both ways', () => { + expect(screenToWorldX(view, 400)).toBe(100) + expect(worldToScreenX(view, screenToWorldX(view, 123))).toBe(123) + }) + + it('draws tiles at the power of two nearest a device pixel, never finer than a block', () => { + expect(renderBlocksPerPixel(4, 1)).toBe(4) + expect(renderBlocksPerPixel(4, 2)).toBe(2) + expect(renderBlocksPerPixel(0.25, 1)).toBe(1) + expect(renderBlocksPerPixel(5.5, 1)).toBe(4) + }) + + it('covers the screen, starting from the middle', () => { + const tiles = visibleTiles(view, 2, 128) + + // 1600 × 1200 blocks around (100, -50) in tiles of 256 blocks: x -3 to 3, z -3 to 2. + expect(tiles.length).toBe(7 * 6) + expect(tiles[0]).toEqual({ tileX: 0, tileZ: -1, blocksPerPixel: 2 }) + }) + + it('finds the coarser tile that covers a tile', () => { + expect(coarserTile({ tileX: -3, tileZ: 5, blocksPerPixel: 2 }, 2)).toEqual({ tileX: -1, tileZ: 1, blocksPerPixel: 8 }) + }) + + it('previews four blank tiles with one tile a level out, never past the coarsest scale', () => { + const blank = [ + { tileX: 0, tileZ: 0, blocksPerPixel: 2 }, + { tileX: 1, tileZ: 0, blocksPerPixel: 2 }, + { tileX: 0, tileZ: 1, blocksPerPixel: 2 }, + { tileX: -1, tileZ: 0, blocksPerPixel: 2 }, + { tileX: 0, tileZ: 0, blocksPerPixel: 4096 } + ] + + expect(previewsFor(blank)).toEqual([ + { tileX: 0, tileZ: 0, blocksPerPixel: 4 }, + { tileX: -1, tileZ: 0, blocksPerPixel: 4 } + ]) + }) +}) + +describe('census', () => { + it('shares the visible pixels between the labels', () => { + const tile = splitTile(4) + const shares = countShares([{ tile, worldX: 0, worldZ: 0 }], { minimumX: 0, minimumZ: 0, maximumX: 4, maximumZ: 4 }, false, 63) + + expect(shares.map((share) => share.subject.key).sort()).toEqual(['desert', 'plains']) + expect(shares[0].fraction).toBeCloseTo(0.5) + expect(gridIndex(tile, -1, -1)).toBe(0) + }) + + it('counts only the part of a tile inside the area, largest share first', () => { + const shares = countShares([{ tile: splitTile(4), worldX: 0, worldZ: 0 }], { minimumX: 0, minimumZ: 0, maximumX: 3, maximumZ: 4 }, false, 63) + + expect(shares.map((share) => share.subject.key)).toEqual(['plains', 'desert']) + expect(shares[0].fraction).toBeCloseTo(2 / 3) + }) + + it('counts height bands in the height view', () => { + const shares = countShares([{ tile: splitTile(4), worldX: 0, worldZ: 0 }], { minimumX: 0, minimumZ: 0, maximumX: 4, maximumZ: 4 }, true, 63) + + expect(shares).toHaveLength(1) + expect(shares[0].subject).toMatchObject({ kind: 'HEIGHT', name: '0–8 above sea' }) + }) +}) diff --git a/src/renderer/src/map/tileStyle.ts b/src/renderer/src/map/tileStyle.ts new file mode 100644 index 000000000..f3a6bb09f --- /dev/null +++ b/src/renderer/src/map/tileStyle.ts @@ -0,0 +1,150 @@ +import { gridIndex } from '../bridge/tileDecoding' +import { NO_LABEL, type MapTile } from '../bridge/types' +import { bandIndexOf, blend, heightColor } from './heightColors' + +/** What a highlight picks out: a biome or region by key, or a height band in the height view. */ +export interface Highlight { + kind: 'BIOME' | 'REGION' | 'HEIGHT' + key: string + name: string +} + +export interface TileStyle { + /** Colour by height instead of by label. */ + byHeight: boolean + shading: boolean + regionBorders: boolean + highlight: Highlight | null + seaLevel: number +} + +export function styleKey(style: TileStyle): string { + const highlight = style.highlight === null ? '' : `${style.highlight.kind}:${style.highlight.key}` + return `${style.byHeight}|${style.shading}|${style.regionBorders}|${highlight}|${style.seaLevel}` +} + +const UNKNOWN_SUBJECT = 0x5a5c62 +const SHADING_EXAGGERATION = 2 +const LIGHT_X = -0.5 +const LIGHT_Y = 0.7 +const LIGHT_Z = -0.5 +const LIGHT_LENGTH = Math.sqrt(LIGHT_X * LIGHT_X + LIGHT_Y * LIGHT_Y + LIGHT_Z * LIGHT_Z) +const AMBIENT_LIGHT = 0.35 +const DIRECT_LIGHT = 0.75 +const DARKEST_SHADE = 0.25 +const BRIGHTEST_SHADE = 1.15 +// Water lies flat over the seafloor, so only a hint of the relief beneath shows through. +const UNDERWATER_RELIEF = 0.15 +const DIM_TARGET = 0x1e1f22 +const DIM_AMOUNT = 0.72 +const DIM_DESATURATION = 0.6 +const HIGHLIGHT_EDGE = 0xffffff +// A solid outline turns biomes that are scattered pixel by pixel into white noise, so the edge only tints. +const HIGHLIGHT_EDGE_STRENGTH = 0.55 +const REGION_BORDER = 0x101114 +const REGION_BORDER_STRENGTH = 0.6 + +/** The tile's pixels as RGBA, as {@code style} draws them (v3e MapTile.styledPixels). */ +export function stylePixels(tile: MapTile, style: TileStyle): Uint8ClampedArray { + const { size, heights } = tile + const pixels = new Uint8ClampedArray(size * size * 4) + const colors = tile.labels.map((label) => label.color) + const byHeight = style.byHeight && heights !== null + const shading = (style.shading || byHeight) && heights !== null + const highlighted = highlightCells(tile, style) + for (let pixelZ = 0; pixelZ < size; pixelZ++) { + for (let pixelX = 0; pixelX < size; pixelX++) { + const cell = gridIndex(tile, pixelX, pixelZ) + let color = byHeight ? heightColor(heights[cell], style.seaLevel) : labelColor(colors, tile.subjects[cell]) + if (shading) { + color = shade(tile, heights, cell, color, style.seaLevel) + } + if (highlighted !== null) { + color = highlight(tile, highlighted, cell, color) + } + if (style.regionBorders && isRegionEdge(tile, cell)) { + color = blend(color, REGION_BORDER, REGION_BORDER_STRENGTH) + } + const at = (pixelZ * size + pixelX) * 4 + pixels[at] = (color >> 16) & 0xff + pixels[at + 1] = (color >> 8) & 0xff + pixels[at + 2] = color & 0xff + pixels[at + 3] = 0xff + } + } + return pixels +} + +function labelColor(colors: number[], index: number): number { + return index === NO_LABEL ? UNKNOWN_SUBJECT : colors[index] +} + +// Lit from the north west like a relief map, so slopes read as hills and valleys at a glance. +function shade(tile: MapTile, heights: Float32Array, cell: number, color: number, seaLevel: number): number { + const row = tile.size + 2 + const slopeX = (heights[cell + 1] - heights[cell - 1]) / (2 * tile.blocksPerPixel) + const slopeZ = (heights[cell + row] - heights[cell - row]) / (2 * tile.blocksPerPixel) + const normalX = -slopeX * SHADING_EXAGGERATION + const normalZ = -slopeZ * SHADING_EXAGGERATION + const normalLength = Math.sqrt(normalX * normalX + 1 + normalZ * normalZ) + const light = (normalX * LIGHT_X + LIGHT_Y + normalZ * LIGHT_Z) / (normalLength * LIGHT_LENGTH) + let factor = Math.min(BRIGHTEST_SHADE, Math.max(DARKEST_SHADE, AMBIENT_LIGHT + DIRECT_LIGHT * light)) + if (heights[cell] <= seaLevel) { + factor = 1 - (1 - factor) * UNDERWATER_RELIEF + } + return scale(color, factor) +} + +/** Which cells the highlight covers, as one flag per grid cell; null when nothing is highlighted. */ +function highlightCells(tile: MapTile, style: TileStyle): Uint8Array | null { + const target = style.highlight + if (target === null) { + return null + } + const cells = new Uint8Array(tile.subjects.length) + if (target.kind === 'HEIGHT') { + if (tile.heights !== null) { + const band = Number(target.key) + tile.heights.forEach((height, cell) => { + cells[cell] = bandIndexOf(height, style.seaLevel) === band ? 1 : 0 + }) + } + return cells + } + // Every view knows its regions, so a region can be highlighted in a biome view too. + const grid = target.kind === tile.subjectKind ? tile.subjects : target.kind === 'REGION' ? tile.regions : null + const index = tile.labels.findIndex((label) => label.kind === target.kind && label.key === target.key) + if (grid !== null && index >= 0) { + grid.forEach((label, cell) => { + cells[cell] = label === index ? 1 : 0 + }) + } + return cells +} + +function highlight(tile: MapTile, highlighted: Uint8Array, cell: number, color: number): number { + if (highlighted[cell] === 0) { + return dim(color) + } + const row = tile.size + 2 + const edge = highlighted[cell + 1] === 0 || highlighted[cell - 1] === 0 || highlighted[cell + row] === 0 || highlighted[cell - row] === 0 + return edge ? blend(color, HIGHLIGHT_EDGE, HIGHLIGHT_EDGE_STRENGTH) : color +} + +function isRegionEdge(tile: MapTile, cell: number): boolean { + const region = tile.regions[cell] + return tile.regions[cell + 1] !== region || tile.regions[cell + tile.size + 2] !== region +} + +function dim(color: number): number { + const gray = Math.floor((((color >> 16) & 0xff) + ((color >> 8) & 0xff) + (color & 0xff)) / 3) + const desaturated = blend(color, (gray << 16) | (gray << 8) | gray, DIM_DESATURATION) + return blend(desaturated, DIM_TARGET, DIM_AMOUNT) +} + +function scale(color: number, factor: number): number { + const red = Math.min(255, Math.floor(((color >> 16) & 0xff) * factor)) + const green = Math.min(255, Math.floor(((color >> 8) & 0xff) * factor)) + const blue = Math.min(255, Math.floor((color & 0xff) * factor)) + return (red << 16) | (green << 8) | blue +} diff --git a/src/renderer/src/map/viewport.ts b/src/renderer/src/map/viewport.ts new file mode 100644 index 000000000..8fd0a5254 --- /dev/null +++ b/src/renderer/src/map/viewport.ts @@ -0,0 +1,93 @@ +/** Where the map looks and how far it is zoomed; screen sizes are CSS pixels. */ +export interface Viewport { + centerX: number + centerZ: number + blocksPerPixel: number + width: number + height: number +} + +export interface TileAddress { + tileX: number + tileZ: number + blocksPerPixel: number +} + +export const MINIMUM_VIEW_BLOCKS_PER_PIXEL = 1 / 8 +export const MAXIMUM_BLOCKS_PER_PIXEL = 4096 +export const DEFAULT_BLOCKS_PER_PIXEL = 4 +// Iris has nothing finer than a block, so closer views magnify the block-sized tiles. +const MINIMUM_RENDER_BLOCKS_PER_PIXEL = 1 + +export function clampBlocksPerPixel(blocksPerPixel: number): number { + return Math.min(MAXIMUM_BLOCKS_PER_PIXEL, Math.max(MINIMUM_VIEW_BLOCKS_PER_PIXEL, blocksPerPixel)) +} + +export function screenToWorldX(view: Viewport, screenX: number): number { + return view.centerX + (screenX - view.width / 2) * view.blocksPerPixel +} + +export function screenToWorldZ(view: Viewport, screenZ: number): number { + return view.centerZ + (screenZ - view.height / 2) * view.blocksPerPixel +} + +export function worldToScreenX(view: Viewport, worldX: number): number { + return (worldX - view.centerX) / view.blocksPerPixel + view.width / 2 +} + +export function worldToScreenZ(view: Viewport, worldZ: number): number { + return (worldZ - view.centerZ) / view.blocksPerPixel + view.height / 2 +} + +/** + * The scale tiles are drawn at for a view: the nearest power of two to one tile pixel per device pixel, so tiles stay + * sharp on dense screens and every zoom between two levels reuses the same tiles. + */ +export function renderBlocksPerPixel(viewBlocksPerPixel: number, devicePixelRatio: number): number { + const level = 2 ** Math.round(Math.log2(viewBlocksPerPixel / devicePixelRatio)) + return Math.min(MAXIMUM_BLOCKS_PER_PIXEL, Math.max(MINIMUM_RENDER_BLOCKS_PER_PIXEL, level)) +} + +/** The tiles covering the view, nearest the centre first so the middle of the screen fills in first. */ +export function visibleTiles(view: Viewport, renderScale: number, tileSize: number): TileAddress[] { + const span = tileSize * renderScale + const firstX = Math.floor(screenToWorldX(view, 0) / span) + const lastX = Math.floor(screenToWorldX(view, view.width) / span) + const firstZ = Math.floor(screenToWorldZ(view, 0) / span) + const lastZ = Math.floor(screenToWorldZ(view, view.height) / span) + const middleX = view.centerX / span - 0.5 + const middleZ = view.centerZ / span - 0.5 + const tiles: TileAddress[] = [] + for (let tileZ = firstZ; tileZ <= lastZ; tileZ++) { + for (let tileX = firstX; tileX <= lastX; tileX++) { + tiles.push({ tileX, tileZ, blocksPerPixel: renderScale }) + } + } + const distance = (tile: TileAddress): number => (tile.tileX - middleX) ** 2 + (tile.tileZ - middleZ) ** 2 + return tiles.sort((first, second) => distance(first) - distance(second)) +} + +/** + * One tile a level out for each group of blank tiles, in their order: a quarter of the pixels, so the screen fills + * about four times sooner and sharpens as the tiles themselves arrive. + */ +export function previewsFor(blankTiles: TileAddress[]): TileAddress[] { + const previews = new Map() + for (const tile of blankTiles) { + const preview = coarserTile(tile, 1) + if (preview.blocksPerPixel <= MAXIMUM_BLOCKS_PER_PIXEL) { + previews.set(`${preview.tileX}/${preview.tileZ}/${preview.blocksPerPixel}`, preview) + } + } + return [...previews.values()] +} + +/** The coarser tile that covers {@code tile}, {@code levels} zoom levels out. */ +export function coarserTile(tile: TileAddress, levels: number): TileAddress { + const factor = 2 ** levels + return { + tileX: Math.floor(tile.tileX / factor), + tileZ: Math.floor(tile.tileZ / factor), + blocksPerPixel: tile.blocksPerPixel * factor + } +} diff --git a/src/renderer/src/studio/ConnectScreen.tsx b/src/renderer/src/studio/ConnectScreen.tsx new file mode 100644 index 000000000..faf2d5036 --- /dev/null +++ b/src/renderer/src/studio/ConnectScreen.tsx @@ -0,0 +1,93 @@ +import { useEffect, useRef, useState } from 'react' +import { Globe2, Loader2 } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import type { BridgeConnection } from '../../../shared/bridge' + +const BRIDGE_POLL_MILLIS = 2000 + +interface ConnectScreenProps { + connecting: boolean + error: string | null + onConnect(connection: BridgeConnection): void + onLink(link: string): void +} + +/** + * Lists the worlds servers on this machine opened to the studio, and takes a pasted link for any other. A single + * world is opened right away, once. + */ +export function ConnectScreen({ connecting, error, onConnect, onLink }: ConnectScreenProps): React.JSX.Element { + const [bridges, setBridges] = useState([]) + const [link, setLink] = useState('') + const openedOnItsOwn = useRef(false) + + useEffect(() => { + let active = true + const refresh = (): void => { + void window.studio.listBridges().then((found) => { + if (!active) { + return + } + setBridges(found) + if (found.length === 1 && !openedOnItsOwn.current) { + openedOnItsOwn.current = true + onConnect(found[0]) + } + }) + } + refresh() + const timer = window.setInterval(refresh, BRIDGE_POLL_MILLIS) + return () => { + active = false + window.clearInterval(timer) + } + }, [onConnect]) + + return ( +
+
+

Open a world

+

+ Run /iris studio map in game or in the + server console. +

+ +
+ {bridges.length === 0 ? ( +
+ Waiting for a server on this machine +
+ ) : ( + bridges.map((bridge) => ( + + )) + )} +
+ +
{ + event.preventDefault() + onLink(link) + }} + > + setLink(event.target.value)} placeholder="iris-studio://…" className="h-8" /> + +
+ {error !== null &&

{error}

} +
+
+ ) +} diff --git a/src/renderer/src/studio/HelpDialog.tsx b/src/renderer/src/studio/HelpDialog.tsx new file mode 100644 index 000000000..1544a2876 --- /dev/null +++ b/src/renderer/src/studio/HelpDialog.tsx @@ -0,0 +1,49 @@ +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' +import { Kbd } from '@/components/ui/kbd' +import type { ViewInfo } from '../bridge/types' +import { MOUSE_HINTS, SHORTCUTS, VIEW_KEYS } from './shortcuts' + +interface HelpDialogProps { + open: boolean + onOpenChange(open: boolean): void + views: ViewInfo[] +} + +/** Every key and mouse gesture of the map. */ +export function HelpDialog({ open, onOpenChange, views }: HelpDialogProps): React.JSX.Element { + const viewRows = views.filter((view) => VIEW_KEYS[view.id] !== undefined).map((view) => ({ key: VIEW_KEYS[view.id], label: view.label })) + const groups = [ + { title: 'Views', rows: [...viewRows, ...rowsOf('Views')] }, + { title: 'Everywhere', rows: rowsOf('Everywhere') }, + { title: 'Map', rows: rowsOf('Map') }, + { title: 'Mouse', rows: MOUSE_HINTS.map((hint) => ({ key: hint.gesture, label: hint.label })) } + ] + return ( + + + + Shortcuts + +
+ {groups.map((group) => ( +
+

{group.title}

+
    + {group.rows.map((row) => ( +
  • + {row.label} + {row.key} +
  • + ))} +
+
+ ))} +
+
+
+ ) +} + +function rowsOf(group: 'Views' | 'Everywhere' | 'Map'): { key: string; label: string }[] { + return SHORTCUTS.filter((shortcut) => shortcut.group === group).map((shortcut) => ({ key: shortcut.keyText, label: shortcut.label })) +} diff --git a/src/renderer/src/studio/HoverCard.tsx b/src/renderer/src/studio/HoverCard.tsx new file mode 100644 index 000000000..b861b6558 --- /dev/null +++ b/src/renderer/src/studio/HoverCard.tsx @@ -0,0 +1,137 @@ +import { useLayoutEffect, useRef, useState } from 'react' +import { Kbd } from '@/components/ui/kbd' +import type { MapHover, MapLabel } from '../bridge/types' +import { hexColor } from './colors' +import type { CanvasPoint } from './MapCanvas' +import { shortcutFor } from './shortcuts' + +interface HoverCardProps { + hover: MapHover + point: CanvasPoint + viewId: string + detailed: boolean + minY: number +} + +const CURSOR_GAP_PIXELS = 18 +const EDGE_MARGIN_PIXELS = 8 + +interface Row { + label: string + value: string + mono?: boolean +} + +/** The spot under the cursor: its biome and ground, and with Shift held, the rest of what the server knows. */ +export function HoverCard({ hover, point, viewId, detailed, minY }: HoverCardProps): React.JSX.Element { + const card = useRef(null) + const [position, setPosition] = useState({ left: point.x + CURSOR_GAP_PIXELS, top: point.y + CURSOR_GAP_PIXELS }) + + useLayoutEffect(() => { + const element = card.current + const parent = element?.parentElement + if (!element || !parent) { + return + } + const fitsRight = point.x + CURSOR_GAP_PIXELS + element.offsetWidth + EDGE_MARGIN_PIXELS <= parent.clientWidth + const fitsBelow = point.y + CURSOR_GAP_PIXELS + element.offsetHeight + EDGE_MARGIN_PIXELS <= parent.clientHeight + setPosition({ + left: fitsRight ? point.x + CURSOR_GAP_PIXELS : Math.max(EDGE_MARGIN_PIXELS, point.x - CURSOR_GAP_PIXELS - element.offsetWidth), + top: fitsBelow ? point.y + CURSOR_GAP_PIXELS : Math.max(EDGE_MARGIN_PIXELS, point.y - CURSOR_GAP_PIXELS - element.offsetHeight) + }) + }, [point, hover, detailed]) + + const subject = viewId === 'caveBiomes' ? hover.caveBiome : viewId === 'regions' ? hover.region : hover.biome + const groups = detailed ? detailGroups(hover, viewId) : [] + return ( +
+
+

{ground(hover, minY)}

+ {groups.map((group) => ( +
+

{group.title}

+
+ {group.rows.map((row) => ( +
+
{row.label}
+
{row.value}
+
+ ))} +
+
+ ))} +
+ {!detailed && } + + +
+
+ ) +} + +function Header({ subject, region }: { subject: MapLabel | null; region: MapLabel | null }): React.JSX.Element { + return ( +
+ {subject !== null && } + {subject?.name ?? 'Nothing here'} + {region !== null && {region.name}} +
+ ) +} + +function Hint({ keyText, label }: { keyText: string; label: string }): React.JSX.Element { + return ( + + {keyText} + {label} + + ) +} + +/** Height as the world's Y, how far above or below the water, and how steep. */ +function ground(hover: MapHover, minY: number): string { + const aboveWater = Math.round(hover.height - hover.fluidHeight) + const signed = aboveWater > 0 ? `+${aboveWater}` : String(aboveWater) + return `Y ${Math.round(hover.height + minY)} · ${signed} from water · ${Math.round(hover.slopeDegrees)}°` +} + +function detailGroups(hover: MapHover, viewId: string): { title: string; rows: Row[] }[] { + const groups: { title: string; rows: Row[] }[] = [] + const terrain: Row[] = [] + if (viewId === 'caveBiomes' && hover.biome !== null) { + terrain.push({ label: 'Surface biome', value: hover.biome.name }) + } else if (hover.caveBiome !== null && hover.caveBiome.key !== hover.biome?.key) { + terrain.push({ label: 'Cave biome', value: hover.caveBiome.name }) + } + if (hover.vanillaBiome !== null) { + terrain.push({ label: 'Minecraft', value: hover.vanillaBiome.replace('minecraft:', '').replaceAll('_', ' ') }) + } + if (terrain.length > 0) { + groups.push({ title: 'Terrain', rows: terrain }) + } + const blockX = Math.floor(hover.worldX) + const blockZ = Math.floor(hover.worldZ) + groups.push({ + title: 'Location', + rows: [ + { label: 'Block', value: `${blockX}, ${blockZ}` }, + { label: 'Chunk', value: `${blockX >> 4}, ${blockZ >> 4}` }, + { label: 'Region file', value: `r.${blockX >> 9}.${blockZ >> 9}.mca`, mono: true } + ] + }) + const files: Row[] = [] + if (hover.biomeFile !== null) { + files.push({ label: 'Biome', value: hover.biomeFile, mono: true }) + } + if (hover.regionFile !== null) { + files.push({ label: 'Region', value: hover.regionFile, mono: true }) + } + if (files.length > 0) { + groups.push({ title: 'Files', rows: files }) + } + return groups +} diff --git a/src/renderer/src/studio/Legend.tsx b/src/renderer/src/studio/Legend.tsx new file mode 100644 index 000000000..0ce53ae46 --- /dev/null +++ b/src/renderer/src/studio/Legend.tsx @@ -0,0 +1,72 @@ +import { ScrollArea } from '@/components/ui/scroll-area' +import { cn } from '@/lib/utils' +import type { Share } from '../map/census' +import type { Highlight } from '../map/tileStyle' +import { hexColor } from './colors' + +interface LegendProps { + title: string + shares: Share[] + highlight: Highlight | null + onSelect(subject: Highlight): void +} + +/** What is on screen and how much of it each covers; clicking one highlights it on the map. */ +export function Legend({ title, shares, highlight, onSelect }: LegendProps): React.JSX.Element { + const sharedNames = namesUsedMoreThanOnce(shares) + return ( + + ) +} + +function namesUsedMoreThanOnce(shares: Share[]): Set { + const seen = new Set() + const repeated = new Set() + for (const share of shares) { + if (seen.has(share.subject.name)) { + repeated.add(share.subject.name) + } + seen.add(share.subject.name) + } + return repeated +} + +function fileName(key: string): string { + return key.slice(key.lastIndexOf('/') + 1) +} + +function percent(fraction: number): string { + if (fraction < 0.001) { + return '<0.1%' + } + return fraction < 0.1 ? `${(fraction * 100).toFixed(1)}%` : `${Math.round(fraction * 100)}%` +} diff --git a/src/renderer/src/studio/MapCanvas.tsx b/src/renderer/src/studio/MapCanvas.tsx new file mode 100644 index 000000000..3a164ab80 --- /dev/null +++ b/src/renderer/src/studio/MapCanvas.tsx @@ -0,0 +1,203 @@ +import { useEffect, useRef, useState } from 'react' +import { + ContextMenu, + ContextMenuContent, + ContextMenuItem, + ContextMenuSeparator, + ContextMenuTrigger +} from '@/components/ui/context-menu' +import type { BridgeClient } from '../bridge/BridgeClient' +import type { WorldInfo } from '../bridge/types' +import { MapController, type MapListener, type SpotSubjects } from '../map/MapController' +import type { Highlight } from '../map/tileStyle' + +export interface CanvasPoint { + x: number + y: number +} + +interface MapCanvasProps { + client: BridgeClient + world: WorldInfo + viewId: string + controllerRef: React.RefObject + listener: MapListener + highlight: Highlight | null + onPointer(point: CanvasPoint | null): void + onDragged(): void + onTeleport(point: CanvasPoint): void + onOpenFile(point: CanvasPoint): void + onHighlight(subject: Highlight): void + onCopy(text: string): void +} + +// A press that moves less than this is a click, not a drag. +const CLICK_SLOP_PIXELS = 4 +// One wheel notch is about 100; this zooms about 15% per notch, and smoothly on touchpads. +const WHEEL_ZOOM_PER_DELTA = 0.002 + +interface ContextSpot { + point: CanvasPoint + subjects: SpotSubjects + blockX: number + blockZ: number +} + +/** The map canvas and its mouse: drag to move, wheel to zoom, Ctrl+click to teleport, Alt+click to open a file. */ +export function MapCanvas(props: MapCanvasProps): React.JSX.Element { + const { client, world, viewId, controllerRef } = props + const canvasRef = useRef(null) + const latest = useRef(props) + latest.current = props + const [contextSpot, setContextSpot] = useState(null) + + useEffect(() => { + const canvas = canvasRef.current! + const map = new MapController(canvas, client, world, viewId, { + onStatus: (status) => latest.current.listener.onStatus(status), + onShares: (shares) => latest.current.listener.onShares(shares), + onError: (message) => latest.current.listener.onError(message) + }) + controllerRef.current = map + const resize = new ResizeObserver(([entry]) => map.resize(entry.contentRect.width, entry.contentRect.height)) + resize.observe(canvas) + return () => { + resize.disconnect() + map.close() + controllerRef.current = null + } + // The controller lives as long as the connection; later view changes go through setView, not a new controller. + }, [client, world, controllerRef]) + + useMouse(canvasRef, controllerRef, latest) + + return ( + { + if (!open) { + setContextSpot(null) + } + }} + > + + { + const map = controllerRef.current + if (map === null) { + return + } + const point = canvasPoint(event) + const spot = map.worldAt(point.x, point.y) + setContextSpot({ point, subjects: map.subjectsAt(point.x, point.y), blockX: Math.floor(spot.x), blockZ: Math.floor(spot.z) }) + }} + /> + + + {contextSpot !== null && } + + + ) +} + +function SpotMenu({ spot, viewId, props }: { spot: ContextSpot; viewId: string; props: MapCanvasProps }): React.JSX.Element { + const { subject, region } = spot.subjects + const coordinates = `${spot.blockX}, ${spot.blockZ}` + return ( + <> + {subject !== null && props.onHighlight(subject)}>{highlightText(subject, props.highlight)}} + {region !== null && subject?.kind !== 'REGION' && ( + props.onHighlight(region)}>{highlightText(region, props.highlight)} + )} + props.onTeleport(spot.point)}>Teleport here + props.onOpenFile(spot.point)}>{viewId === 'regions' ? 'Open region file' : 'Open biome file'} + + props.onCopy(coordinates)}>Copy coordinates ({coordinates}) + + ) +} + +function highlightText(subject: Highlight, current: Highlight | null): string { + const highlighted = current !== null && current.kind === subject.kind && current.key === subject.key + return `${highlighted ? 'Clear highlight of' : 'Highlight'} ${subject.name}` +} + +function canvasPoint(event: { clientX: number; clientY: number; currentTarget: Element }): CanvasPoint { + const bounds = event.currentTarget.getBoundingClientRect() + return { x: event.clientX - bounds.left, y: event.clientY - bounds.top } +} + +function useMouse( + canvasRef: React.RefObject, + controllerRef: React.RefObject, + latest: React.RefObject +): void { + useEffect(() => { + const canvas = canvasRef.current! + let press: { x: number; y: number; lastX: number; lastY: number; dragged: boolean } | null = null + + const down = (event: PointerEvent): void => { + if (event.button !== 0) { + return + } + canvas.setPointerCapture(event.pointerId) + press = { x: event.clientX, y: event.clientY, lastX: event.clientX, lastY: event.clientY, dragged: false } + } + const move = (event: PointerEvent): void => { + const point = canvasPoint({ clientX: event.clientX, clientY: event.clientY, currentTarget: canvas }) + controllerRef.current?.setCursor(point) + latest.current.onPointer(point) + if (press === null) { + return + } + if (!press.dragged && Math.hypot(event.clientX - press.x, event.clientY - press.y) >= CLICK_SLOP_PIXELS) { + press.dragged = true + latest.current.onDragged() + } + if (press.dragged) { + controllerRef.current?.panBy(event.clientX - press.lastX, event.clientY - press.lastY) + } + press.lastX = event.clientX + press.lastY = event.clientY + } + const up = (event: PointerEvent): void => { + if (press === null || event.button !== 0) { + return + } + const wasClick = !press.dragged + press = null + if (!wasClick) { + return + } + const point = canvasPoint({ clientX: event.clientX, clientY: event.clientY, currentTarget: canvas }) + if (event.ctrlKey || event.metaKey) { + latest.current.onTeleport(point) + } else if (event.altKey) { + latest.current.onOpenFile(point) + } + } + const leave = (): void => { + controllerRef.current?.setCursor(null) + latest.current.onPointer(null) + } + const wheel = (event: WheelEvent): void => { + event.preventDefault() + const point = canvasPoint({ clientX: event.clientX, clientY: event.clientY, currentTarget: canvas }) + controllerRef.current?.zoomAt(2 ** (-event.deltaY * WHEEL_ZOOM_PER_DELTA), point.x, point.y) + } + + canvas.addEventListener('pointerdown', down) + canvas.addEventListener('pointermove', move) + canvas.addEventListener('pointerup', up) + canvas.addEventListener('pointerleave', leave) + canvas.addEventListener('wheel', wheel, { passive: false }) + return () => { + canvas.removeEventListener('pointerdown', down) + canvas.removeEventListener('pointermove', move) + canvas.removeEventListener('pointerup', up) + canvas.removeEventListener('pointerleave', leave) + canvas.removeEventListener('wheel', wheel) + } + }, [canvasRef, controllerRef, latest]) +} diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx new file mode 100644 index 000000000..0cbd10562 --- /dev/null +++ b/src/renderer/src/studio/MapStudio.tsx @@ -0,0 +1,358 @@ +import { useCallback, useEffect, useRef, useState } from 'react' +import type { ThemeChoice } from '../../../shared/bridge' +import type { BridgeClient } from '../bridge/BridgeClient' +import type { MapHover, Marker, WorldInfo } from '../bridge/types' +import type { Share } from '../map/census' +import type { MapController, MapStatus, MapToggles } from '../map/MapController' +import type { Highlight } from '../map/tileStyle' +import { HelpDialog } from './HelpDialog' +import { HoverCard } from './HoverCard' +import { Legend } from './Legend' +import { MapCanvas, type CanvasPoint } from './MapCanvas' +import { actionForKey, viewForKey, type ShortcutAction } from './shortcuts' +import { StatusBar } from './StatusBar' +import { StudioToolbar } from './StudioToolbar' +import { ViewList } from './ViewList' + +const KEYBOARD_ZOOM_FACTOR = 2 ** 0.25 +const ENTITY_POLL_MILLIS = 2000 +const NOTICE_MILLIS = 4000 + +interface MapStudioProps { + client: BridgeClient + world: WorldInfo + theme: { choice: ThemeChoice; next: () => void } + onDisconnect(): void +} + +export interface StudioToggles extends MapToggles { + follow: boolean + entities: boolean +} + +/** The map of one world: views on the left, the map in the middle, what is on screen on the right. */ +export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps): React.JSX.Element { + const controller = useRef(null) + const [viewId, setViewId] = useState(world.views[0]?.id ?? 'biomes') + const [toggles, setToggles] = useState({ shading: true, regionBorders: false, grid: false, follow: false, entities: false }) + const [highlight, setHighlight] = useState(null) + const [status, setStatus] = useState(null) + const [shares, setShares] = useState([]) + const [players, setPlayers] = useState([]) + const [entities, setEntities] = useState([]) + const [pointer, setPointer] = useState(null) + const [hover, setHover] = useState(null) + const [detailed, setDetailed] = useState(false) + const [helpOpen, setHelpOpen] = useState(false) + const [notice, setNotice] = useState(null) + const [connected, setConnected] = useState(true) + const view = world.views.find((candidate) => candidate.id === viewId) ?? world.views[0] + + const tell = useCallback((message: string) => setNotice(message), []) + + useEffect(() => { + if (notice === null) { + return + } + const timer = window.setTimeout(() => setNotice(null), NOTICE_MILLIS) + return () => window.clearTimeout(timer) + }, [notice]) + + useEffect(() => controller.current?.setView(viewId), [viewId]) + useEffect(() => controller.current?.setToggles(toggles), [toggles]) + useEffect(() => controller.current?.setHighlight(highlight), [highlight]) + useEffect(() => controller.current?.setMarkers(players, toggles.entities ? entities : []), [players, entities, toggles.entities]) + + useEffect(() => { + if (toggles.follow && players.length > 0) { + controller.current?.centerOn(players[0].worldX, players[0].worldZ) + } + }, [players, toggles.follow]) + + useServerEvents(client, controller, setPlayers, tell, setConnected) + useEntities(client, toggles.entities, setEntities) + useHover(client, controller, pointer, setHover) + + const selectView = useCallback((nextViewId: string) => { + setViewId(nextViewId) + setHighlight(null) + }, []) + + const toggle = useCallback((name: keyof StudioToggles) => setToggles((current) => ({ ...current, [name]: !current[name] })), []) + + const highlightUnderCursor = useCallback(() => { + if (pointer === null || controller.current === null) { + return + } + const { subject } = controller.current.subjectsAt(pointer.x, pointer.y) + setHighlight((current) => (subject === null || sameSubject(current, subject) ? null : subject)) + }, [pointer]) + + const runShortcut = useCallback( + (action: ShortcutAction) => { + const map = controller.current + switch (action) { + case 'nextView': + selectView(world.views[(world.views.findIndex((candidate) => candidate.id === viewId) + 1) % world.views.length].id) + return + case 'refresh': + map?.refresh() + tell('Redrawing with the latest pack files') + return + case 'zoomIn': + map?.zoomAt(KEYBOARD_ZOOM_FACTOR) + return + case 'zoomOut': + map?.zoomAt(1 / KEYBOARD_ZOOM_FACTOR) + return + case 'resetZoom': + map?.resetZoom() + return + case 'dismiss': + setHighlight(null) + return + case 'follow': + toggle('follow') + return + case 'grid': + toggle('grid') + return + case 'entities': + toggle('entities') + return + case 'highlight': + highlightUnderCursor() + return + case 'shading': + toggle('shading') + return + case 'borders': + toggle('regionBorders') + return + case 'help': + setHelpOpen((open) => !open) + } + }, + [world.views, viewId, selectView, toggle, highlightUnderCursor, tell] + ) + + useKeyboard(runShortcut, selectView, setDetailed, world) + + const teleport = useCallback( + (point: CanvasPoint) => { + const spot = controller.current?.worldAt(point.x, point.y) + if (spot === undefined) { + return + } + client + .teleport(Math.floor(spot.x), Math.floor(spot.z)) + .then(() => tell(`Teleporting to ${Math.floor(spot.x)}, ${Math.floor(spot.z)}`)) + .catch((failure: Error) => tell(failure.message)) + }, + [client, tell] + ) + + const openFile = useCallback( + (point: CanvasPoint) => { + const spot = controller.current?.worldAt(point.x, point.y) + if (spot === undefined) { + return + } + client + .openInEditor(spot.x, spot.z, viewId) + .then((message) => tell(message ?? 'Opened on the server')) + .catch((failure: Error) => tell(failure.message)) + }, + [client, viewId, tell] + ) + + return ( +
+ runShortcut('refresh')} + onResetZoom={() => runShortcut('resetZoom')} + onHelp={() => setHelpOpen(true)} + onDisconnect={onDisconnect} + /> +
+ +
+ setToggles((current) => (current.follow ? { ...current, follow: false } : current))} + onTeleport={teleport} + onOpenFile={openFile} + onHighlight={(subject) => setHighlight((current) => (sameSubject(current, subject) ? null : subject))} + highlight={highlight} + onCopy={(text) => { + window.studio.copyText(text) + tell(`Copied ${text}`) + }} + /> + {pointer !== null && hover !== null && ( + + )} + {!connected && ( +
+
+

Lost the connection to the server

+ +
+
+ )} +
+ setHighlight((current) => (sameSubject(current, subject) ? null : subject))} + /> +
+ + +
+ ) +} + +function sameSubject(first: Highlight | null, second: Highlight | null): boolean { + return first !== null && second !== null && first.kind === second.kind && first.key === second.key +} + +function legendTitle(viewId: string): string { + if (viewId === 'regions') { + return 'Regions on screen' + } + return viewId === 'height' ? 'Heights on screen' : 'Biomes on screen' +} + +/** Players and hotloads from the server; the first world event only says the world runs, which is known. */ +function useServerEvents( + client: BridgeClient, + controller: React.RefObject, + setPlayers: (players: Marker[]) => void, + tell: (message: string) => void, + setConnected: (connected: boolean) => void +): void { + useEffect(() => { + const stop = new AbortController() + let firstWorldEvent = true + void client.listen( + { + onWorld: (running) => { + if (firstWorldEvent) { + firstWorldEvent = false + return + } + if (running) { + controller.current?.refresh() + tell('Pack reloaded, redrawing') + } else { + tell('The world stopped') + } + }, + onPlayers: setPlayers, + onClosed: () => setConnected(false) + }, + stop.signal + ) + return () => stop.abort() + }, [client, controller, setPlayers, tell, setConnected]) +} + +function useEntities(client: BridgeClient, visible: boolean, setEntities: (entities: Marker[]) => void): void { + useEffect(() => { + if (!visible) { + return + } + let active = true + const refresh = (): void => { + client + .entities() + .then((found) => active && setEntities(found)) + .catch(() => undefined) + } + refresh() + const timer = window.setInterval(refresh, ENTITY_POLL_MILLIS) + return () => { + active = false + window.clearInterval(timer) + } + }, [client, visible, setEntities]) +} + +/** Asks the server about the spot under the cursor; a newer spot aborts the question about an older one. */ +function useHover( + client: BridgeClient, + controller: React.RefObject, + pointer: CanvasPoint | null, + setHover: (hover: MapHover | null) => void +): void { + useEffect(() => { + if (pointer === null || controller.current === null) { + setHover(null) + return + } + const spot = controller.current.worldAt(pointer.x, pointer.y) + const stop = new AbortController() + client + .hover(Math.floor(spot.x), Math.floor(spot.z), stop.signal) + .then(setHover) + .catch(() => undefined) + return () => stop.abort() + }, [client, controller, pointer, setHover]) +} + +function useKeyboard( + runShortcut: (action: ShortcutAction) => void, + selectView: (view: string) => void, + setDetailed: (detailed: boolean) => void, + world: WorldInfo +): void { + useEffect(() => { + const down = (event: KeyboardEvent): void => { + if (event.key === 'Shift') { + setDetailed(true) + } + if (event.ctrlKey || event.metaKey || event.altKey || event.target instanceof HTMLInputElement) { + return + } + const viewId = viewForKey(event.key) + if (viewId !== null && world.views.some((view) => view.id === viewId)) { + selectView(viewId) + return + } + const action = actionForKey(event.key) + if (action !== null) { + event.preventDefault() + runShortcut(action) + } + } + const up = (event: KeyboardEvent): void => { + if (event.key === 'Shift') { + setDetailed(false) + } + } + const blur = (): void => setDetailed(false) + window.addEventListener('keydown', down) + window.addEventListener('keyup', up) + window.addEventListener('blur', blur) + return () => { + window.removeEventListener('keydown', down) + window.removeEventListener('keyup', up) + window.removeEventListener('blur', blur) + } + }, [runShortcut, selectView, setDetailed, world]) +} diff --git a/src/renderer/src/studio/StatusBar.tsx b/src/renderer/src/studio/StatusBar.tsx new file mode 100644 index 000000000..71596ceeb --- /dev/null +++ b/src/renderer/src/studio/StatusBar.tsx @@ -0,0 +1,54 @@ +import type { MapStatus } from '../map/MapController' + +interface StatusBarProps { + viewLabel: string + status: MapStatus | null + notice: string | null +} + +const NUMBER = new Intl.NumberFormat('en-US') + +/** What the map shows, what it is busy with, and where the cursor is (v3e StudioStatusBar). */ +export function StatusBar({ viewLabel, status, notice }: StatusBarProps): React.JSX.Element { + const drawing = status !== null && status.tilesReady < status.tilesTotal + return ( +
+ + {viewLabel} + {status !== null && ( + <> + + {formatScale(status.blocksPerPixel)} blocks/px + + {NUMBER.format(status.widthBlocks)} × {NUMBER.format(status.heightBlocks)} blocks + + )} + + + {notice ?? (drawing ? `Drawing ${status.tilesReady} of ${status.tilesTotal} tiles` : '')} + {notice === null && drawing && ( + + + + )} + + {status !== null && ( + + X {NUMBER.format(status.cursorX)} + Z {NUMBER.format(status.cursorZ)} + + )} +
+ ) +} + +function Gap(): React.JSX.Element { + return +} + +function formatScale(blocksPerPixel: number): string { + if (blocksPerPixel >= 10) { + return String(Math.round(blocksPerPixel)) + } + return blocksPerPixel >= 1 ? blocksPerPixel.toFixed(1) : blocksPerPixel.toFixed(2) +} diff --git a/src/renderer/src/studio/StudioToolbar.tsx b/src/renderer/src/studio/StudioToolbar.tsx new file mode 100644 index 000000000..386013f42 --- /dev/null +++ b/src/renderer/src/studio/StudioToolbar.tsx @@ -0,0 +1,125 @@ +import { CircleHelp, Grid3x3, LocateFixed, LogOut, Monitor, Moon, Mountain, PawPrint, RefreshCw, Spline, Sun, ZoomIn } from 'lucide-react' +import type { ReactNode } from 'react' +import { Button } from '@/components/ui/button' +import { Kbd } from '@/components/ui/kbd' +import { Separator } from '@/components/ui/separator' +import { Toggle } from '@/components/ui/toggle' +import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' +import type { ThemeChoice } from '../../../shared/bridge' +import type { WorldInfo } from '../bridge/types' +import type { StudioToggles } from './MapStudio' +import { shortcutFor, type ShortcutAction } from './shortcuts' + +interface StudioToolbarProps { + title: string + world: WorldInfo + toggles: StudioToggles + hasPlayers: boolean + theme: { choice: ThemeChoice; next: () => void } + onToggle(name: keyof StudioToggles): void + onRefresh(): void + onResetZoom(): void + onHelp(): void + onDisconnect(): void +} + +const THEME_ICONS: Record = { system: , light: , dark: } +const THEME_NAMES: Record = { system: 'Theme: system', light: 'Theme: light', dark: 'Theme: dark' } + +export function StudioToolbar(props: StudioToolbarProps): React.JSX.Element { + const { toggles, onToggle } = props + return ( +
+ {props.title} + + + + + + + onToggle('grid')}> + Grid + + onToggle('entities')}> + Entities + + onToggle('follow')}> + Follow + + + onToggle('shading')}> + Shading + + onToggle('regionBorders')}> + Borders + + +
+ + {props.world.world} + + + + + + + + + + +
+ ) +} + +function IconHint({ hint, keyText, children }: { hint: string; keyText?: string; children: ReactNode }): React.JSX.Element { + return ( + + {children} + + {hint} + {keyText !== undefined && {keyText}} + + + ) +} + +function ToolButton({ action, hint, onClick, children }: { action: ShortcutAction; hint: string; onClick(): void; children: ReactNode }): React.JSX.Element { + return ( + + + + ) +} + +interface ToolToggleProps { + action: ShortcutAction + hint: string + pressed: boolean + disabled?: boolean + onPressed(): void + children: ReactNode +} + +function ToolToggle({ action, hint, pressed, disabled, onPressed, children }: ToolToggleProps): React.JSX.Element { + return ( + + + + {children} + + + + ) +} diff --git a/src/renderer/src/studio/ViewList.tsx b/src/renderer/src/studio/ViewList.tsx new file mode 100644 index 000000000..43a57b869 --- /dev/null +++ b/src/renderer/src/studio/ViewList.tsx @@ -0,0 +1,61 @@ +import { Gem, Map as MapIcon, Mountain, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' +import { Kbd } from '@/components/ui/kbd' +import { ScrollArea } from '@/components/ui/scroll-area' +import { cn } from '@/lib/utils' +import type { ViewInfo } from '../bridge/types' +import { VIEW_KEYS } from './shortcuts' + +const VIEW_ICONS: Record = { + biomes: Trees, + regions: MapIcon, + height: Mountain, + landBiomes: Sprout, + seaBiomes: Waves, + caveBiomes: Gem +} + +interface ViewListProps { + views: ViewInfo[] + current: string + onSelect(view: string): void +} + +/** The views the server offers, in its groups, each with what it shows and its key. */ +export function ViewList({ views, current, onSelect }: ViewListProps): React.JSX.Element { + const groups = [...new Set(views.map((view) => view.groupLabel))] + return ( + + ) +} + +function ViewRow({ view, selected, onSelect }: { view: ViewInfo; selected: boolean; onSelect(): void }): React.JSX.Element { + const Icon = VIEW_ICONS[view.id] ?? MapIcon + return ( + + ) +} diff --git a/src/renderer/src/studio/colors.ts b/src/renderer/src/studio/colors.ts new file mode 100644 index 000000000..79e9ca266 --- /dev/null +++ b/src/renderer/src/studio/colors.ts @@ -0,0 +1,4 @@ +/** A 0xRRGGBB colour as CSS. */ +export function hexColor(color: number): string { + return `#${color.toString(16).padStart(6, '0')}` +} diff --git a/src/renderer/src/studio/shortcuts.ts b/src/renderer/src/studio/shortcuts.ts new file mode 100644 index 000000000..14bd71831 --- /dev/null +++ b/src/renderer/src/studio/shortcuts.ts @@ -0,0 +1,72 @@ +/** The studio's keys, as v3e's studio had them (StudioShortcut). */ +export type ShortcutAction = + | 'nextView' + | 'refresh' + | 'zoomIn' + | 'zoomOut' + | 'resetZoom' + | 'dismiss' + | 'follow' + | 'grid' + | 'entities' + | 'highlight' + | 'shading' + | 'borders' + | 'help' + +export interface Shortcut { + action: ShortcutAction + label: string + group: 'Views' | 'Everywhere' | 'Map' + /** The key as shown, then every KeyboardEvent.key that triggers it. */ + keyText: string + keys: string[] +} + +export const SHORTCUTS: Shortcut[] = [ + { action: 'nextView', label: 'Next view', group: 'Views', keyText: 'M', keys: ['m'] }, + { action: 'refresh', label: 'Redraw the map with the latest pack files', group: 'Everywhere', keyText: 'R', keys: ['r'] }, + { action: 'zoomIn', label: 'Zoom in', group: 'Everywhere', keyText: '=', keys: ['=', '+'] }, + { action: 'zoomOut', label: 'Zoom out', group: 'Everywhere', keyText: '-', keys: ['-'] }, + { action: 'resetZoom', label: 'Reset zoom', group: 'Everywhere', keyText: '\\', keys: ['\\'] }, + { action: 'dismiss', label: 'Clear the highlight', group: 'Everywhere', keyText: 'Esc', keys: ['Escape'] }, + { action: 'follow', label: 'Follow your player', group: 'Map', keyText: 'F', keys: ['f'] }, + { action: 'grid', label: 'Chunk and region grid', group: 'Map', keyText: 'G', keys: ['g'] }, + { action: 'entities', label: 'Show entities', group: 'Map', keyText: 'E', keys: ['e'] }, + { action: 'highlight', label: 'Highlight what is under the cursor', group: 'Map', keyText: 'H', keys: ['h'] }, + { action: 'shading', label: 'Terrain shading', group: 'Map', keyText: 'S', keys: ['s'] }, + { action: 'borders', label: 'Region borders', group: 'Map', keyText: 'B', keys: ['b'] }, + { action: 'help', label: 'Show the shortcuts', group: 'Map', keyText: '/', keys: ['/', '?'] } +] + +/** The key of each view; 4 stays free for the 3D world, as in v3e. */ +export const VIEW_KEYS: Record = { + biomes: '1', + regions: '2', + height: '3', + landBiomes: '5', + seaBiomes: '6', + caveBiomes: '7' +} + +export const MOUSE_HINTS: { gesture: string; label: string }[] = [ + { gesture: 'Drag', label: 'Move the map' }, + { gesture: 'Wheel', label: 'Zoom around the cursor' }, + { gesture: 'Shift', label: 'More about the spot under the cursor' }, + { gesture: 'Ctrl+Click', label: 'Teleport there' }, + { gesture: 'Alt+Click', label: 'Open the biome or region file' }, + { gesture: 'Right click', label: 'Highlight, teleport, open or copy' } +] + +export function shortcutFor(action: ShortcutAction): Shortcut { + return SHORTCUTS.find((shortcut) => shortcut.action === action)! +} + +export function actionForKey(key: string): ShortcutAction | null { + const pressed = key.length === 1 ? key.toLowerCase() : key + return SHORTCUTS.find((shortcut) => shortcut.keys.includes(pressed))?.action ?? null +} + +export function viewForKey(key: string): string | null { + return Object.entries(VIEW_KEYS).find(([, viewKey]) => viewKey === key)?.[0] ?? null +} diff --git a/src/renderer/src/studio/theme.ts b/src/renderer/src/studio/theme.ts new file mode 100644 index 000000000..2302a2cca --- /dev/null +++ b/src/renderer/src/studio/theme.ts @@ -0,0 +1,33 @@ +import { useEffect, useState } from 'react' +import type { ThemeChoice } from '../../../shared/bridge' + +const STORAGE_KEY = 'iris-studio.theme' +const DARK_QUERY = '(prefers-color-scheme: dark)' +const ORDER: ThemeChoice[] = ['system', 'light', 'dark'] + +function storedChoice(): ThemeChoice { + const stored = localStorage.getItem(STORAGE_KEY) + return stored === 'light' || stored === 'dark' ? stored : 'system' +} + +function apply(choice: ThemeChoice): void { + const dark = choice === 'dark' || (choice === 'system' && matchMedia(DARK_QUERY).matches) + document.documentElement.classList.toggle('dark', dark) +} + +/** The light or dark look, following the system unless chosen; the choice outlives the window. */ +export function useTheme(): { choice: ThemeChoice; next: () => void } { + const [choice, setChoice] = useState(storedChoice) + + useEffect(() => { + apply(choice) + window.studio.setTheme(choice) + localStorage.setItem(STORAGE_KEY, choice) + const media = matchMedia(DARK_QUERY) + const follow = (): void => apply(choice) + media.addEventListener('change', follow) + return () => media.removeEventListener('change', follow) + }, [choice]) + + return { choice, next: () => setChoice(ORDER[(ORDER.indexOf(choice) + 1) % ORDER.length]) } +} diff --git a/src/renderer/src/styles.css b/src/renderer/src/styles.css new file mode 100644 index 000000000..78fffb682 --- /dev/null +++ b/src/renderer/src/styles.css @@ -0,0 +1,111 @@ +@import "tailwindcss"; + +@custom-variant dark (&:is(.dark *)); + +/* The studio's colours, taken from the Swing studio (StudioTheme) so both look alike. */ +:root { + --background: #ffffff; + --foreground: #000000; + --card: #f7f8fa; + --card-foreground: #000000; + --popover: rgb(255 255 255 / 0.94); + --popover-foreground: #000000; + --primary: #3574f0; + --primary-foreground: #ffffff; + --secondary: #dfe1e5; + --secondary-foreground: #000000; + --muted: #f7f8fa; + --muted-foreground: #818594; + --secondary-text: #6c707e; + --accent: #dfe1e5; + --accent-foreground: #000000; + --selection: #d4e2ff; + --destructive: #db3b4b; + --warning: #c27d04; + --success: #208a3c; + --link: #315fbd; + --border: #ebecf0; + --input: #c9ccd6; + --ring: #3574f0; + --overlay-border: #dfe1e5; + --map-background: #e4e6eb; + --radius: 10px; +} + +.dark { + --background: #1e1f22; + --foreground: #dfe1e5; + --card: #2b2d30; + --card-foreground: #dfe1e5; + --popover: rgb(43 45 48 / 0.93); + --popover-foreground: #dfe1e5; + --primary: #3574f0; + --primary-foreground: #ffffff; + --secondary: #393b40; + --secondary-foreground: #dfe1e5; + --muted: #2b2d30; + --muted-foreground: #6f737a; + --secondary-text: #9da0a8; + --accent: #393b40; + --accent-foreground: #dfe1e5; + --selection: #2e436e; + --destructive: #f75464; + --warning: #f2c55c; + --success: #5fb865; + --link: #548af7; + --border: #1e1f22; + --input: #4e5157; + --ring: #3574f0; + --overlay-border: #43454a; + --map-background: #16171a; +} + +@theme inline { + --color-background: var(--background); + --color-foreground: var(--foreground); + --color-card: var(--card); + --color-card-foreground: var(--card-foreground); + --color-popover: var(--popover); + --color-popover-foreground: var(--popover-foreground); + --color-primary: var(--primary); + --color-primary-foreground: var(--primary-foreground); + --color-secondary: var(--secondary); + --color-secondary-foreground: var(--secondary-foreground); + --color-muted: var(--muted); + --color-muted-foreground: var(--muted-foreground); + --color-secondary-text: var(--secondary-text); + --color-accent: var(--accent); + --color-accent-foreground: var(--accent-foreground); + --color-selection: var(--selection); + --color-destructive: var(--destructive); + --color-warning: var(--warning); + --color-success: var(--success); + --color-link: var(--link); + --color-border: var(--border); + --color-input: var(--input); + --color-ring: var(--ring); + --color-overlay-border: var(--overlay-border); + --color-map-background: var(--map-background); + --radius-sm: calc(var(--radius) - 4px); + --radius-md: calc(var(--radius) - 2px); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) + 4px); + --font-sans: "Inter", "Segoe UI", system-ui, sans-serif; + --font-mono: "JetBrains Mono", ui-monospace, monospace; +} + +@layer base { + * { + @apply border-border outline-ring/50; + } + + html, + body, + #root { + @apply h-full overflow-hidden; + } + + body { + @apply bg-background text-foreground text-[13px] antialiased select-none; + } +} diff --git a/src/shared/bridge.ts b/src/shared/bridge.ts new file mode 100644 index 000000000..3f1e1d68a --- /dev/null +++ b/src/shared/bridge.ts @@ -0,0 +1,37 @@ +/** A bridge a running Iris server opened, as its connection file or a studio link describes it. */ +export interface BridgeConnection { + world: string + port: number + token: string + startedMillis?: number +} + +export type ThemeChoice = 'system' | 'light' | 'dark' + +/** What the preload script hands the renderer. */ +export interface StudioHost { + listBridges(): Promise + /** The studio link the app was started with, if any. */ + initialLink(): Promise + onLink(listener: (link: string) => void): () => void + setTheme(theme: ThemeChoice): void + copyText(text: string): void +} + +const LINK_PROTOCOL = 'iris-studio:' + +/** The bridge a link such as {@code iris-studio://127.0.0.1:44503/?token=...} names; null for anything else. */ +export function parseStudioLink(text: string): BridgeConnection | null { + let url: URL + try { + url = new URL(text.trim()) + } catch { + return null + } + const port = Number(url.port) + const token = url.searchParams.get('token') + if (url.protocol !== LINK_PROTOCOL || !Number.isInteger(port) || port <= 0 || !token) { + return null + } + return { world: url.searchParams.get('world') ?? '', port, token } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..434c40bb5 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "ES2023", + "module": "ESNext", + "moduleResolution": "Bundler", + "lib": ["ES2023", "DOM", "DOM.Iterable"], + "jsx": "react-jsx", + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "skipLibCheck": true, + "isolatedModules": true, + "resolveJsonModule": true, + "types": ["node"], + "paths": { "@/*": ["./src/renderer/src/*"] } + }, + "include": ["src", "electron.vite.config.ts"] +} From e20bf1dd57a8c72740c2a72f121d012fb0ddf4f7 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 00:40:36 +0100 Subject: [PATCH 02/12] Hover card: show how the spot was picked One row per pick under the card's title: region, biome list and each child level, with the options' shares of the noise as a segmented bar, the picked one in its colour and a marker at the noise value. A child names the parent it replaced on its own line. The card is a little wider so long biome names keep their region beside them. --- src/renderer/src/bridge/BridgeClient.ts | 4 +- src/renderer/src/bridge/types.ts | 24 +++++++ src/renderer/src/studio/HoverCard.tsx | 8 ++- src/renderer/src/studio/MapStudio.tsx | 7 ++- src/renderer/src/studio/PickRows.tsx | 83 +++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 src/renderer/src/studio/PickRows.tsx diff --git a/src/renderer/src/bridge/BridgeClient.ts b/src/renderer/src/bridge/BridgeClient.ts index f98f907e6..0b643d28c 100644 --- a/src/renderer/src/bridge/BridgeClient.ts +++ b/src/renderer/src/bridge/BridgeClient.ts @@ -42,8 +42,8 @@ export class BridgeClient { return this.json('world') } - hover(worldX: number, worldZ: number, signal?: AbortSignal): Promise { - return this.json(`hover?x=${worldX}&z=${worldZ}`, { signal }) + hover(view: string, worldX: number, worldZ: number, signal?: AbortSignal): Promise { + return this.json(`hover?view=${encodeURIComponent(view)}&x=${worldX}&z=${worldZ}`, { signal }) } entities(): Promise { diff --git a/src/renderer/src/bridge/types.ts b/src/renderer/src/bridge/types.ts index 6fd5ee3e3..a122c6fda 100644 --- a/src/renderer/src/bridge/types.ts +++ b/src/renderer/src/bridge/types.ts @@ -43,6 +43,30 @@ export interface MapHover { slopeDegrees: number biomeFile: string | null regionFile: string | null + /** How the spot got its region and the biome the view shows, region first. */ + pickPath: PickStep[] +} + +/** REGION, BIOME and CHILD were picked by noise; IMAGE_MAP and FOCUS were set without a pick. */ +export type PickKind = 'REGION' | 'BIOME' | 'CHILD' | 'IMAGE_MAP' | 'FOCUS' + +export interface PickStep { + kind: PickKind + picked: MapLabel + /** The biome list a BIOME step picked from, such as "land". */ + list: string | null + /** The parent name a CHILD step replaced; null when the parent kept the spot. */ + replaced: string | null + /** 0 to 1; null when nothing was picked. */ + noise: number | null + bands: PickBand[] +} + +/** One option's share of a pick noise: picked from `from` up to `to`. */ +export interface PickBand { + option: MapLabel + from: number + to: number } export interface Marker { diff --git a/src/renderer/src/studio/HoverCard.tsx b/src/renderer/src/studio/HoverCard.tsx index b861b6558..7b6872095 100644 --- a/src/renderer/src/studio/HoverCard.tsx +++ b/src/renderer/src/studio/HoverCard.tsx @@ -3,6 +3,7 @@ import { Kbd } from '@/components/ui/kbd' import type { MapHover, MapLabel } from '../bridge/types' import { hexColor } from './colors' import type { CanvasPoint } from './MapCanvas' +import { PickRows, replacedParent } from './PickRows' import { shortcutFor } from './shortcuts' interface HoverCardProps { @@ -43,14 +44,17 @@ export function HoverCard({ hover, point, viewId, detailed, minY }: HoverCardPro const subject = viewId === 'caveBiomes' ? hover.caveBiome : viewId === 'regions' ? hover.region : hover.biome const groups = detailed ? detailGroups(hover, viewId) : [] + const parent = replacedParent(hover.pickPath) return (
-

{ground(hover, minY)}

+ {parent !== null &&

child of {parent}

} +

{ground(hover, minY)}

+ {groups.map((group) => (

{group.title}

diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx index 0cbd10562..b03ca911e 100644 --- a/src/renderer/src/studio/MapStudio.tsx +++ b/src/renderer/src/studio/MapStudio.tsx @@ -71,7 +71,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps useServerEvents(client, controller, setPlayers, tell, setConnected) useEntities(client, toggles.entities, setEntities) - useHover(client, controller, pointer, setHover) + useHover(client, controller, viewId, pointer, setHover) const selectView = useCallback((nextViewId: string) => { setViewId(nextViewId) @@ -297,6 +297,7 @@ function useEntities(client: BridgeClient, visible: boolean, setEntities: (entit function useHover( client: BridgeClient, controller: React.RefObject, + viewId: string, pointer: CanvasPoint | null, setHover: (hover: MapHover | null) => void ): void { @@ -308,11 +309,11 @@ function useHover( const spot = controller.current.worldAt(pointer.x, pointer.y) const stop = new AbortController() client - .hover(Math.floor(spot.x), Math.floor(spot.z), stop.signal) + .hover(viewId, Math.floor(spot.x), Math.floor(spot.z), stop.signal) .then(setHover) .catch(() => undefined) return () => stop.abort() - }, [client, controller, pointer, setHover]) + }, [client, controller, viewId, pointer, setHover]) } function useKeyboard( diff --git a/src/renderer/src/studio/PickRows.tsx b/src/renderer/src/studio/PickRows.tsx new file mode 100644 index 000000000..cc2d9ded5 --- /dev/null +++ b/src/renderer/src/studio/PickRows.tsx @@ -0,0 +1,83 @@ +import type { PickBand, PickStep } from '../bridge/types' +import { hexColor } from './colors' + +// Gaps between bands shrink as there are more of them, so many thin bands still read as a bar. +const WIDE_GAP_MOST_BANDS = 18 +const NARROW_GAP_MOST_BANDS = 50 + +/** How the spot got its region and biome: one row per pick, the noise value marked on every option's share of it. */ +export function PickRows({ path }: { path: PickStep[] }): React.JSX.Element | null { + if (path.length === 0) { + return null + } + return ( +
+ {path.map((step, index) => ( + + ))} +
+ ) +} + +function PickRow({ step }: { step: PickStep }): React.JSX.Element { + return ( + <> + {rowLabel(step)} + {step.noise === null ? ( + {step.kind === 'FOCUS' ? 'Focus' : 'Image map'} + ) : ( + + )} + {step.noise === null ? '' : step.noise.toFixed(3)} + + ) +} + +function NoiseBar({ bands, noise }: { bands: PickBand[]; noise: number }): React.JSX.Element { + const picked = pickedBandIndex(bands, noise) + const gap = bands.length <= WIDE_GAP_MOST_BANDS ? 2 : bands.length <= NARROW_GAP_MOST_BANDS ? 1 : 0 + return ( +
+ {bands.map((band, index) => ( + + ))} + +
+ ) +} + +/** The first band the noise does not pass; values beyond 1 pick the last, as the generator does. */ +export function pickedBandIndex(bands: PickBand[], noise: number): number { + const index = bands.findIndex((band) => noise <= band.to) + return index === -1 ? bands.length - 1 : index +} + +function rowLabel(step: PickStep): string { + switch (step.kind) { + case 'REGION': + return 'Region' + case 'BIOME': + return step.list === null ? 'Biome' : step.list.charAt(0).toUpperCase() + step.list.slice(1) + case 'CHILD': + return 'Child' + case 'IMAGE_MAP': + case 'FOCUS': + return step.picked.kind === 'REGION' ? 'Region' : 'Biome' + } +} + +/** The parent the spot's biome replaced, when a child step replaced one. */ +export function replacedParent(path: PickStep[]): string | null { + return path.findLast((step) => step.kind === 'CHILD' && step.replaced !== null)?.replaced ?? null +} From 674f9756e305f06954c768693a369d166b044264 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 01:10:21 +0100 Subject: [PATCH 03/12] Map: pick inspector, noise display and region preview A right-hand panel shows how the noise picks the regions or biomes in view: a histogram per noise over its pick bands, and each option's weight against its share of the view. The map can draw the picks, the settling noise, or both, and any prepared region can be previewed across the map. --- src/renderer/src/bridge/BridgeClient.ts | 47 +++++- src/renderer/src/bridge/tileDecoding.ts | 8 +- src/renderer/src/bridge/types.ts | 40 ++++- .../src/components/ui/toggle-group.tsx | 69 +++++++++ src/renderer/src/map/MapController.ts | 55 +++++-- src/renderer/src/map/TileStore.ts | 10 +- src/renderer/src/map/map.test.ts | 48 +++++- src/renderer/src/map/tileStyle.ts | 26 +++- src/renderer/src/studio/HoverCard.tsx | 9 +- src/renderer/src/studio/Legend.tsx | 7 +- src/renderer/src/studio/MapCanvas.tsx | 1 + src/renderer/src/studio/MapStudio.tsx | 138 +++++++++++++++--- src/renderer/src/studio/NoiseChart.tsx | 131 +++++++++++++++++ src/renderer/src/studio/PickInspector.tsx | 112 ++++++++++++++ src/renderer/src/studio/PickRows.tsx | 5 +- src/renderer/src/studio/RegionPreviewList.tsx | 72 +++++++++ src/renderer/src/studio/ViewList.tsx | 5 +- 17 files changed, 718 insertions(+), 65 deletions(-) create mode 100644 src/renderer/src/components/ui/toggle-group.tsx create mode 100644 src/renderer/src/studio/NoiseChart.tsx create mode 100644 src/renderer/src/studio/PickInspector.tsx create mode 100644 src/renderer/src/studio/RegionPreviewList.tsx diff --git a/src/renderer/src/bridge/BridgeClient.ts b/src/renderer/src/bridge/BridgeClient.ts index 0b643d28c..9a3c0255c 100644 --- a/src/renderer/src/bridge/BridgeClient.ts +++ b/src/renderer/src/bridge/BridgeClient.ts @@ -1,6 +1,6 @@ import type { BridgeConnection } from '../../../shared/bridge' import { decodeTile } from './tileDecoding' -import type { MapHover, MapTile, Marker, WorldInfo } from './types' +import type { MapHover, MapLabel, MapTile, Marker, PickInspection, WorldInfo } from './types' export class BridgeError extends Error { constructor( @@ -13,11 +13,27 @@ export class BridgeError extends Error { export interface TileRequest { view: string + /** The region the region view previews everywhere, or null for the world as it is. */ + preview: string | null tileX: number tileZ: number blocksPerPixel: number size: number heights: boolean + pickNoise: boolean +} + +/** What a map spot or area is asked about: a view, and the region it previews. */ +export interface MapLayerQuery { + view: string + preview: string | null +} + +export interface WorldRect { + minX: number + minZ: number + maxX: number + maxZ: number } export interface BridgeEvents { @@ -42,8 +58,19 @@ export class BridgeClient { return this.json('world') } - hover(view: string, worldX: number, worldZ: number, signal?: AbortSignal): Promise { - return this.json(`hover?view=${encodeURIComponent(view)}&x=${worldX}&z=${worldZ}`, { signal }) + hover(layer: MapLayerQuery, worldX: number, worldZ: number, signal?: AbortSignal): Promise { + return this.json(`hover?${layerQuery(layer, { x: String(worldX), z: String(worldZ) })}`, { signal }) + } + + /** How the noise picks what the layer shows across {@code area}. */ + picks(layer: MapLayerQuery, area: WorldRect, signal?: AbortSignal): Promise { + const corners = { minX: String(area.minX), minZ: String(area.minZ), maxX: String(area.maxX), maxZ: String(area.maxZ) } + return this.json(`picks?${layerQuery(layer, corners)}`, { signal }) + } + + /** The regions the world picks biomes for, which the region view can preview. */ + regions(): Promise { + return this.json('regions') } entities(): Promise { @@ -61,13 +88,13 @@ export class BridgeClient { } async tile(request: TileRequest, signal: AbortSignal): Promise { - const query = new URLSearchParams({ - view: request.view, + const query = layerQuery(request, { x: String(request.tileX), z: String(request.tileZ), scale: String(request.blocksPerPixel), size: String(request.size), - heights: request.heights ? '1' : '0' + heights: request.heights ? '1' : '0', + noise: request.pickNoise ? '1' : '0' }) const response = await this.fetch(`tile?${query}`, { signal }) return decodeTile(await response.arrayBuffer()) @@ -120,6 +147,14 @@ export class BridgeClient { } } +function layerQuery(layer: MapLayerQuery, rest: Record): URLSearchParams { + const query = new URLSearchParams({ view: layer.view, ...rest }) + if (layer.preview !== null) { + query.set('preview', layer.preview) + } + return query +} + function dispatch(block: string, events: BridgeEvents): void { let name = 'message' let data = '' diff --git a/src/renderer/src/bridge/tileDecoding.ts b/src/renderer/src/bridge/tileDecoding.ts index 60b0da3cd..ac5f23e90 100644 --- a/src/renderer/src/bridge/tileDecoding.ts +++ b/src/renderer/src/bridge/tileDecoding.ts @@ -8,6 +8,7 @@ interface TileHeader { subjectKind: LabelKind labels: MapLabel[] heights: boolean + pickNoise: boolean } function aligned(bytes: number): number { @@ -16,7 +17,8 @@ function aligned(bytes: number): number { /** * Reads a tile as the bridge writes it (MapTileEncoding): a u32 header length, the JSON header, then the subject, - * region and height grids, each starting on a multiple of 4 bytes. The grids are views into the buffer, not copies. + * region, height and pick noise grids, each starting on a multiple of 4 bytes. The grids are views into the buffer, + * not copies. */ export function decodeTile(buffer: ArrayBuffer): MapTile { const view = new DataView(buffer) @@ -27,6 +29,7 @@ export function decodeTile(buffer: ArrayBuffer): MapTile { const subjectsAt = aligned(4 + headerLength) const regionsAt = aligned(subjectsAt + cells * Int16Array.BYTES_PER_ELEMENT) const heightsAt = aligned(regionsAt + cells * Int16Array.BYTES_PER_ELEMENT) + const pickNoiseAt = heightsAt + (header.heights ? cells * Float32Array.BYTES_PER_ELEMENT : 0) return { size: header.size, blocksPerPixel: header.blocksPerPixel, @@ -34,7 +37,8 @@ export function decodeTile(buffer: ArrayBuffer): MapTile { labels: header.labels, subjects: new Int16Array(buffer, subjectsAt, cells), regions: new Int16Array(buffer, regionsAt, cells), - heights: header.heights ? new Float32Array(buffer, heightsAt, cells) : null + heights: header.heights ? new Float32Array(buffer, heightsAt, cells) : null, + pickNoise: header.pickNoise ? new Float32Array(buffer, pickNoiseAt, cells) : null } } diff --git a/src/renderer/src/bridge/types.ts b/src/renderer/src/bridge/types.ts index a122c6fda..97fecd342 100644 --- a/src/renderer/src/bridge/types.ts +++ b/src/renderer/src/bridge/types.ts @@ -47,8 +47,8 @@ export interface MapHover { pickPath: PickStep[] } -/** REGION, BIOME and CHILD were picked by noise; IMAGE_MAP and FOCUS were set without a pick. */ -export type PickKind = 'REGION' | 'BIOME' | 'CHILD' | 'IMAGE_MAP' | 'FOCUS' +/** REGION, BIOME and CHILD were picked by noise; IMAGE_MAP, FOCUS and PREVIEW were set without a pick. */ +export type PickKind = 'REGION' | 'BIOME' | 'CHILD' | 'IMAGE_MAP' | 'FOCUS' | 'PREVIEW' export interface PickStep { kind: PickKind @@ -69,6 +69,40 @@ export interface PickBand { to: number } +/** How the noise picks what an area of the map shows (MapPickInspection). */ +export interface PickInspection { + detail: string + sections: PickSection[] +} + +/** The picks on one region's ground; `region` is null in the region view, where the regions themselves are picked. */ +export interface PickSection { + region: MapLabel | null + /** How much of the area's picked ground the region holds. */ + share: number + biomeCount: number + spreads: PickSpread[] +} + +/** One noise in the area: its values in 50 equal steps from 0 to 1, and each option's share of it. */ +export interface PickSpread { + title: string + bands: PickBand[] + histogram: number[] + samples: number + rows: PickShare[] +} + +/** `weight`: how much of the noise picks the option; `inView`: how much of the area's values do. */ +export interface PickShare { + option: MapLabel + weight: number + inView: number +} + +/** How the region and biome views draw their picks: the labels, the noise that picked them, or the labels by noise. */ +export type PickDisplay = 'picks' | 'noise' | 'both' + export interface Marker { label: string worldX: number @@ -89,6 +123,8 @@ export interface MapTile { subjects: Int16Array regions: Int16Array heights: Float32Array | null + /** The noise value that settled each cell's pick, 0 to 1 and NaN where nothing picked it; null unless asked for. */ + pickNoise: Float32Array | null } export const NO_LABEL = -1 diff --git a/src/renderer/src/components/ui/toggle-group.tsx b/src/renderer/src/components/ui/toggle-group.tsx new file mode 100644 index 000000000..54d3d9019 --- /dev/null +++ b/src/renderer/src/components/ui/toggle-group.tsx @@ -0,0 +1,69 @@ +import * as React from "react" +import { type VariantProps } from "class-variance-authority" +import { ToggleGroup as ToggleGroupPrimitive } from "radix-ui" + +import { cn } from "@/lib/utils" +import { toggleVariants } from "@/components/ui/toggle" + +const ToggleGroupContext = React.createContext>({ + size: "default", + variant: "default", +}) + +function ToggleGroup({ + className, + variant, + size, + children, + ...props +}: React.ComponentProps & + VariantProps) { + return ( + + + {children} + + + ) +} + +function ToggleGroupItem({ + className, + children, + variant, + size, + ...props +}: React.ComponentProps & + VariantProps) { + const context = React.useContext(ToggleGroupContext) + + return ( + + {children} + + ) +} + +export { ToggleGroup, ToggleGroupItem } diff --git a/src/renderer/src/map/MapController.ts b/src/renderer/src/map/MapController.ts index 1e814b01a..287bc8dd2 100644 --- a/src/renderer/src/map/MapController.ts +++ b/src/renderer/src/map/MapController.ts @@ -1,6 +1,6 @@ -import type { BridgeClient } from '../bridge/BridgeClient' +import type { BridgeClient, WorldRect } from '../bridge/BridgeClient' import { gridIndex } from '../bridge/tileDecoding' -import { NO_LABEL, type MapLabel, type Marker, type WorldInfo } from '../bridge/types' +import { NO_LABEL, type MapLabel, type Marker, type PickDisplay, type WorldInfo } from '../bridge/types' import { countShares, type PlacedTile, type Share } from './census' import { bandIndexOf, HEIGHT_BANDS } from './heightColors' import type { Highlight, TileStyle } from './tileStyle' @@ -33,9 +33,14 @@ export interface MapStatus { export interface MapListener { onStatus(status: MapStatus): void onShares(shares: Share[]): void + /** The world area on screen, reported with the shares: a few times a second while it moves, and once at rest. */ + onArea(area: WorldRect): void onError(message: string): void } +/** The views whose spots a noise picks, so they can draw that noise. */ +const PICK_NOISE_VIEWS = new Set(['biomes', 'regions']) + /** What the map shows at a spot, read from the tiles already drawn. */ export interface SpotSubjects { subject: Highlight | null @@ -72,6 +77,7 @@ export class MapController { private readonly view: Viewport = { centerX: 0, centerZ: 0, blocksPerPixel: DEFAULT_BLOCKS_PER_PIXEL, width: 1, height: 1 } private layer: TileLayer private toggles: MapToggles = { shading: true, regionBorders: false, grid: false } + private pickDisplay: PickDisplay = 'picks' private highlight: Highlight | null = null private players: Marker[] = [] private entities: Marker[] = [] @@ -89,7 +95,7 @@ export class MapController { private readonly listener: MapListener ) { this.context = canvas.getContext('2d')! - this.layer = { view, heights: this.needsHeights(view, this.toggles), revision: 0 } + this.layer = { view, preview: null, heights: this.needsHeights(view, this.toggles), pickNoise: false, revision: 0 } this.store = new TileStore(client, world.tileSize, () => this.redraw(), (message) => listener.onError(message)) } @@ -108,11 +114,29 @@ export class MapController { this.redraw() } - setView(view: string): void { - this.layer = { ...this.layer, view, heights: this.needsHeights(view, this.toggles) } + /** Shows a view; the region view previews {@code preview} everywhere when it is not null. */ + setView(view: string, preview: string | null = null): void { + this.layer = { + ...this.layer, + view, + preview: view === 'regions' ? preview : null, + heights: this.needsHeights(view, this.toggles), + pickNoise: this.needsPickNoise(view, this.pickDisplay) + } this.redraw() } + setPickDisplay(display: PickDisplay): void { + this.pickDisplay = display + this.layer = { ...this.layer, pickNoise: this.needsPickNoise(this.layer.view, display) } + this.redraw() + } + + // Tiles only carry their pick noise while it is drawn, so drawing the picks alone costs nothing extra. + private needsPickNoise(view: string, display: PickDisplay): boolean { + return display !== 'picks' && PICK_NOISE_VIEWS.has(view) + } + setToggles(toggles: MapToggles): void { this.toggles = toggles this.layer = { ...this.layer, heights: this.needsHeights(this.layer.view, toggles) } @@ -214,7 +238,8 @@ export class MapController { shading: this.toggles.shading, regionBorders: this.toggles.regionBorders, highlight: this.highlight, - seaLevel: this.world.fluidHeight + seaLevel: this.world.fluidHeight, + pickDisplay: this.pickDisplay } } @@ -375,9 +400,19 @@ export class MapController { this.censusTimer = window.setTimeout(() => { this.lastCensusMillis = performance.now() this.listener.onShares(this.census(tiles)) + this.listener.onArea(this.screenArea()) }, wait) } + private screenArea(): WorldRect { + return { + minX: screenToWorldX(this.view, 0), + minZ: screenToWorldZ(this.view, 0), + maxX: screenToWorldX(this.view, this.view.width), + maxZ: screenToWorldZ(this.view, this.view.height) + } + } + private census(tiles: TileAddress[]): Share[] { const placed: PlacedTile[] = [] for (const address of tiles) { @@ -387,12 +422,8 @@ export class MapController { placed.push({ tile, worldX: address.tileX * span, worldZ: address.tileZ * span }) } } - const area = { - minimumX: screenToWorldX(this.view, 0), - minimumZ: screenToWorldZ(this.view, 0), - maximumX: screenToWorldX(this.view, this.view.width), - maximumZ: screenToWorldZ(this.view, this.view.height) - } + const screen = this.screenArea() + const area = { minimumX: screen.minX, minimumZ: screen.minZ, maximumX: screen.maxX, maximumZ: screen.maxZ } return countShares(placed, area, this.isHeightView(), this.world.fluidHeight) } } diff --git a/src/renderer/src/map/TileStore.ts b/src/renderer/src/map/TileStore.ts index 56d279562..9ecc91c10 100644 --- a/src/renderer/src/map/TileStore.ts +++ b/src/renderer/src/map/TileStore.ts @@ -6,7 +6,10 @@ import type { TileAddress } from './viewport' /** What one tile request needs besides where the tile is. */ export interface TileLayer { view: string + /** The region the region view previews everywhere, or null for the world as it is. */ + preview: string | null heights: boolean + pickNoise: boolean /** Bumped when the pack is hotloaded, so older tiles are not used again. */ revision: number } @@ -44,7 +47,8 @@ export class TileStore { ) {} key(address: TileAddress, layer: TileLayer): string { - return `${layer.revision}/${layer.view}/${layer.heights}/${address.blocksPerPixel}/${address.tileX}/${address.tileZ}` + const parts = [layer.revision, layer.view, layer.preview ?? '', layer.heights, layer.pickNoise] + return `${parts.join('/')}/${address.blocksPerPixel}/${address.tileX}/${address.tileZ}` } /** The tile if it has arrived, marked as just used. */ @@ -118,7 +122,7 @@ export class TileStore { private fetchTile(key: string, address: TileAddress, layer: TileLayer): void { const controller = new AbortController() this.inFlight.set(key, controller) - const request = { view: layer.view, ...address, size: this.tileSize, heights: layer.heights } + const request = { ...layer, ...address, size: this.tileSize } this.client .tile(request, controller.signal) .then((tile) => this.store(key, tile)) @@ -139,7 +143,7 @@ export class TileStore { } private store(key: string, tile: MapTile): void { - const bytes = tile.subjects.byteLength * 2 + (tile.heights?.byteLength ?? 0) + tile.size * tile.size * 4 + const bytes = tile.subjects.byteLength * 2 + (tile.heights?.byteLength ?? 0) + (tile.pickNoise?.byteLength ?? 0) + tile.size * tile.size * 4 this.tiles.set(key, { tile, bytes, lastUsed: ++this.useClock, picture: null, pictureStyle: '' }) this.storedBytes += bytes this.evictOldest() diff --git a/src/renderer/src/map/map.test.ts b/src/renderer/src/map/map.test.ts index 555b304b6..79f00f37f 100644 --- a/src/renderer/src/map/map.test.ts +++ b/src/renderer/src/map/map.test.ts @@ -9,7 +9,7 @@ import { coarserTile, previewsFor, renderBlocksPerPixel, screenToWorldX, visible const PLAINS: MapLabel = { kind: 'BIOME', key: 'plains', name: 'Plains', color: 0x00ff00 } const DESERT: MapLabel = { kind: 'BIOME', key: 'desert', name: 'Desert', color: 0xffff00 } const WARM: MapLabel = { kind: 'REGION', key: 'warm', name: 'Warm', color: 0xff0000 } -const FLAT: TileStyle = { byHeight: false, shading: false, regionBorders: false, highlight: null, seaLevel: 63 } +const FLAT: TileStyle = { byHeight: false, shading: false, regionBorders: false, highlight: null, seaLevel: 63, pickDisplay: 'picks' } /** A tile whose left half is plains and right half desert, all in one region, at height 70. */ function splitTile(size = 4): MapTile { @@ -25,19 +25,23 @@ function splitTile(size = 4): MapTile { labels: [PLAINS, DESERT, WARM], subjects, regions: new Int16Array(cells).fill(2), - heights: new Float32Array(cells).fill(70) + heights: new Float32Array(cells).fill(70), + pickNoise: null } } /** A tile as the bridge sends it: u32 header length, JSON header, aligned grids. */ -function encode(size: number, withHeights: boolean): ArrayBuffer { - const header = new TextEncoder().encode(JSON.stringify({ size, blocksPerPixel: 2, subjectKind: 'BIOME', labels: [PLAINS], heights: withHeights })) +function encode(size: number, withHeights: boolean, withPickNoise = false): ArrayBuffer { + const header = new TextEncoder().encode( + JSON.stringify({ size, blocksPerPixel: 2, subjectKind: 'BIOME', labels: [PLAINS], heights: withHeights, pickNoise: withPickNoise }) + ) const cells = (size + 2) ** 2 const align = (bytes: number): number => Math.ceil(bytes / 4) * 4 const subjectsAt = align(4 + header.length) const regionsAt = align(subjectsAt + cells * 2) const heightsAt = align(regionsAt + cells * 2) - const buffer = new ArrayBuffer(heightsAt + (withHeights ? cells * 4 : 0)) + const pickNoiseAt = heightsAt + (withHeights ? cells * 4 : 0) + const buffer = new ArrayBuffer(pickNoiseAt + (withPickNoise ? cells * 4 : 0)) new DataView(buffer).setUint32(0, header.length, true) new Uint8Array(buffer, 4).set(header) new Int16Array(buffer, subjectsAt, cells).fill(0) @@ -45,6 +49,9 @@ function encode(size: number, withHeights: boolean): ArrayBuffer { if (withHeights) { new Float32Array(buffer, heightsAt, cells).fill(81.5) } + if (withPickNoise) { + new Float32Array(buffer, pickNoiseAt, cells).fill(0.25) + } return buffer } @@ -63,6 +70,37 @@ describe('tile decoding', () => { it('has no heights when the header says so', () => { expect(decodeTile(encode(3, false)).heights).toBeNull() }) + + it('reads the pick noise after the heights, or in their place without them', () => { + expect(decodeTile(encode(3, true, true)).pickNoise?.[24]).toBe(0.25) + expect(decodeTile(encode(3, false, true)).pickNoise?.[0]).toBe(0.25) + expect(decodeTile(encode(3, true)).pickNoise).toBeNull() + }) +}) + +describe('pick noise', () => { + function noisyTile(noise: number): MapTile { + const tile = splitTile() + return { ...tile, pickNoise: new Float32Array(tile.subjects.length).fill(noise) } + } + + it('draws the bare noise from dark to white', () => { + const pixels = stylePixels(noisyTile(1), { ...FLAT, pickDisplay: 'noise' }) + + expect([pixels[0], pixels[1], pixels[2]]).toEqual([255, 255, 255]) + }) + + it('draws the picks darker where their noise is lower', () => { + const pixels = stylePixels(noisyTile(0), { ...FLAT, pickDisplay: 'both' }) + + expect(pixels[1]).toBe(Math.floor(255 * 0.3)) + }) + + it('leaves a spot nothing picked in its own colour', () => { + const pixels = stylePixels(noisyTile(Number.NaN), { ...FLAT, pickDisplay: 'noise' }) + + expect([pixels[0], pixels[1], pixels[2]]).toEqual([0, 255, 0]) + }) }) describe('height colours', () => { diff --git a/src/renderer/src/map/tileStyle.ts b/src/renderer/src/map/tileStyle.ts index f3a6bb09f..5354d9904 100644 --- a/src/renderer/src/map/tileStyle.ts +++ b/src/renderer/src/map/tileStyle.ts @@ -1,5 +1,5 @@ import { gridIndex } from '../bridge/tileDecoding' -import { NO_LABEL, type MapTile } from '../bridge/types' +import { NO_LABEL, type MapTile, type PickDisplay } from '../bridge/types' import { bandIndexOf, blend, heightColor } from './heightColors' /** What a highlight picks out: a biome or region by key, or a height band in the height view. */ @@ -16,11 +16,13 @@ export interface TileStyle { regionBorders: boolean highlight: Highlight | null seaLevel: number + /** How tiles that carry their pick noise draw it. */ + pickDisplay: PickDisplay } export function styleKey(style: TileStyle): string { const highlight = style.highlight === null ? '' : `${style.highlight.kind}:${style.highlight.key}` - return `${style.byHeight}|${style.shading}|${style.regionBorders}|${highlight}|${style.seaLevel}` + return `${style.byHeight}|${style.shading}|${style.regionBorders}|${highlight}|${style.seaLevel}|${style.pickDisplay}` } const UNKNOWN_SUBJECT = 0x5a5c62 @@ -43,6 +45,10 @@ const HIGHLIGHT_EDGE = 0xffffff const HIGHLIGHT_EDGE_STRENGTH = 0.55 const REGION_BORDER = 0x101114 const REGION_BORDER_STRENGTH = 0.6 +const NOISE_LOW = 0x050505 +const NOISE_HIGH = 0xffffff +// Picks drawn by their noise keep some colour where the noise is low, so they still read as the pick. +const DARKEST_PICK_SHADE = 0.3 /** The tile's pixels as RGBA, as {@code style} draws them (v3e MapTile.styledPixels). */ export function stylePixels(tile: MapTile, style: TileStyle): Uint8ClampedArray { @@ -50,12 +56,17 @@ export function stylePixels(tile: MapTile, style: TileStyle): Uint8ClampedArray< const pixels = new Uint8ClampedArray(size * size * 4) const colors = tile.labels.map((label) => label.color) const byHeight = style.byHeight && heights !== null - const shading = (style.shading || byHeight) && heights !== null + const pickNoise = style.pickDisplay === 'picks' ? null : tile.pickNoise + // The bare noise is read by its brightness, which relief shading would mix up. + const shading = (style.shading || byHeight) && heights !== null && !(pickNoise !== null && style.pickDisplay === 'noise') const highlighted = highlightCells(tile, style) for (let pixelZ = 0; pixelZ < size; pixelZ++) { for (let pixelX = 0; pixelX < size; pixelX++) { const cell = gridIndex(tile, pixelX, pixelZ) let color = byHeight ? heightColor(heights[cell], style.seaLevel) : labelColor(colors, tile.subjects[cell]) + if (pickNoise !== null) { + color = byNoise(color, pickNoise[cell], style.pickDisplay) + } if (shading) { color = shade(tile, heights, cell, color, style.seaLevel) } @@ -79,6 +90,15 @@ function labelColor(colors: number[], index: number): number { return index === NO_LABEL ? UNKNOWN_SUBJECT : colors[index] } +// Where nothing picked the spot, as on an image map, it keeps its colour. +function byNoise(color: number, noise: number, display: PickDisplay): number { + if (Number.isNaN(noise)) { + return color + } + const value = Math.min(1, Math.max(0, noise)) + return display === 'noise' ? blend(NOISE_LOW, NOISE_HIGH, value) : scale(color, DARKEST_PICK_SHADE + (1 - DARKEST_PICK_SHADE) * value) +} + // Lit from the north west like a relief map, so slopes read as hills and valleys at a glance. function shade(tile: MapTile, heights: Float32Array, cell: number, color: number, seaLevel: number): number { const row = tile.size + 2 diff --git a/src/renderer/src/studio/HoverCard.tsx b/src/renderer/src/studio/HoverCard.tsx index 7b6872095..d6e11f456 100644 --- a/src/renderer/src/studio/HoverCard.tsx +++ b/src/renderer/src/studio/HoverCard.tsx @@ -10,6 +10,8 @@ interface HoverCardProps { hover: MapHover point: CanvasPoint viewId: string + /** The region view fills the map with one region's biomes, so the spot is described by its previewed biome. */ + previewing: boolean detailed: boolean minY: number } @@ -24,7 +26,7 @@ interface Row { } /** The spot under the cursor: its biome and ground, and with Shift held, the rest of what the server knows. */ -export function HoverCard({ hover, point, viewId, detailed, minY }: HoverCardProps): React.JSX.Element { +export function HoverCard({ hover, point, viewId, previewing, detailed, minY }: HoverCardProps): React.JSX.Element { const card = useRef(null) const [position, setPosition] = useState({ left: point.x + CURSOR_GAP_PIXELS, top: point.y + CURSOR_GAP_PIXELS }) @@ -42,7 +44,8 @@ export function HoverCard({ hover, point, viewId, detailed, minY }: HoverCardPro }) }, [point, hover, detailed]) - const subject = viewId === 'caveBiomes' ? hover.caveBiome : viewId === 'regions' ? hover.region : hover.biome + const labelsRegions = viewId === 'regions' && !previewing + const subject = viewId === 'caveBiomes' ? hover.caveBiome : labelsRegions ? hover.region : hover.biome const groups = detailed ? detailGroups(hover, viewId) : [] const parent = replacedParent(hover.pickPath) return ( @@ -51,7 +54,7 @@ export function HoverCard({ hover, point, viewId, detailed, minY }: HoverCardPro className="pointer-events-none absolute z-10 w-80 rounded-[10px] border border-overlay-border bg-popover px-3.5 py-3 text-popover-foreground shadow-xl backdrop-blur-sm" style={position} > -
+
{parent !== null &&

child of {parent}

}

{ground(hover, minY)}

diff --git a/src/renderer/src/studio/Legend.tsx b/src/renderer/src/studio/Legend.tsx index 0ce53ae46..83125383f 100644 --- a/src/renderer/src/studio/Legend.tsx +++ b/src/renderer/src/studio/Legend.tsx @@ -9,13 +9,14 @@ interface LegendProps { shares: Share[] highlight: Highlight | null onSelect(subject: Highlight): void + className?: string } /** What is on screen and how much of it each covers; clicking one highlights it on the map. */ -export function Legend({ title, shares, highlight, onSelect }: LegendProps): React.JSX.Element { +export function Legend({ title, shares, highlight, onSelect, className }: LegendProps): React.JSX.Element { const sharedNames = namesUsedMoreThanOnce(shares) return ( - +
) } diff --git a/src/renderer/src/studio/MapCanvas.tsx b/src/renderer/src/studio/MapCanvas.tsx index 3a164ab80..99ad5228c 100644 --- a/src/renderer/src/studio/MapCanvas.tsx +++ b/src/renderer/src/studio/MapCanvas.tsx @@ -56,6 +56,7 @@ export function MapCanvas(props: MapCanvasProps): React.JSX.Element { const map = new MapController(canvas, client, world, viewId, { onStatus: (status) => latest.current.listener.onStatus(status), onShares: (shares) => latest.current.listener.onShares(shares), + onArea: (area) => latest.current.listener.onArea(area), onError: (message) => latest.current.listener.onError(message) }) controllerRef.current = map diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx index b03ca911e..4ac806c69 100644 --- a/src/renderer/src/studio/MapStudio.tsx +++ b/src/renderer/src/studio/MapStudio.tsx @@ -1,7 +1,7 @@ -import { useCallback, useEffect, useRef, useState } from 'react' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import type { ThemeChoice } from '../../../shared/bridge' -import type { BridgeClient } from '../bridge/BridgeClient' -import type { MapHover, Marker, WorldInfo } from '../bridge/types' +import type { BridgeClient, MapLayerQuery, WorldRect } from '../bridge/BridgeClient' +import type { MapHover, MapLabel, Marker, PickDisplay, PickInspection, WorldInfo } from '../bridge/types' import type { Share } from '../map/census' import type { MapController, MapStatus, MapToggles } from '../map/MapController' import type { Highlight } from '../map/tileStyle' @@ -9,6 +9,8 @@ import { HelpDialog } from './HelpDialog' import { HoverCard } from './HoverCard' import { Legend } from './Legend' import { MapCanvas, type CanvasPoint } from './MapCanvas' +import { PickInspector } from './PickInspector' +import { RegionPreviewList } from './RegionPreviewList' import { actionForKey, viewForKey, type ShortcutAction } from './shortcuts' import { StatusBar } from './StatusBar' import { StudioToolbar } from './StudioToolbar' @@ -17,6 +19,10 @@ import { ViewList } from './ViewList' const KEYBOARD_ZOOM_FACTOR = 2 ** 0.25 const ENTITY_POLL_MILLIS = 2000 const NOTICE_MILLIS = 4000 +// Measuring the picks in view samples thousands of spots, so it waits for the map to rest. +const INSPECTION_REST_MILLIS = 350 +/** The views whose spots a noise picks, which the pick inspector explains. */ +const PICK_VIEWS = new Set(['biomes', 'regions']) interface MapStudioProps { client: BridgeClient @@ -46,7 +52,16 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps const [helpOpen, setHelpOpen] = useState(false) const [notice, setNotice] = useState(null) const [connected, setConnected] = useState(true) + const [preview, setPreview] = useState(null) + const [pickDisplay, setPickDisplay] = useState('picks') + const [area, setArea] = useState(null) + const [packRevision, setPackRevision] = useState(0) const view = world.views.find((candidate) => candidate.id === viewId) ?? world.views[0] + const layer = useMemo(() => ({ view: viewId, preview: viewId === 'regions' ? preview : null }), [viewId, preview]) + const regions = usePreviewableRegions(client, packRevision) + const inspectsPicks = PICK_VIEWS.has(viewId) + const inspection = usePickInspection(client, layer, area, inspectsPicks, packRevision) + const previewName = layer.preview === null ? null : (regions.find((region) => region.key === layer.preview)?.name ?? layer.preview) const tell = useCallback((message: string) => setNotice(message), []) @@ -58,7 +73,8 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps return () => window.clearTimeout(timer) }, [notice]) - useEffect(() => controller.current?.setView(viewId), [viewId]) + useEffect(() => controller.current?.setView(layer.view, layer.preview), [layer]) + useEffect(() => controller.current?.setPickDisplay(pickDisplay), [pickDisplay]) useEffect(() => controller.current?.setToggles(toggles), [toggles]) useEffect(() => controller.current?.setHighlight(highlight), [highlight]) useEffect(() => controller.current?.setMarkers(players, toggles.entities ? entities : []), [players, entities, toggles.entities]) @@ -69,15 +85,21 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps } }, [players, toggles.follow]) - useServerEvents(client, controller, setPlayers, tell, setConnected) + const packReloaded = useCallback(() => setPackRevision((revision) => revision + 1), []) + useServerEvents(client, controller, setPlayers, tell, setConnected, packReloaded) useEntities(client, toggles.entities, setEntities) - useHover(client, controller, viewId, pointer, setHover) + useHover(client, controller, layer, pointer, setHover) const selectView = useCallback((nextViewId: string) => { setViewId(nextViewId) setHighlight(null) }, []) + const selectPreview = useCallback((regionKey: string | null) => { + setPreview(regionKey) + setHighlight(null) + }, []) + const toggle = useCallback((name: keyof StudioToggles) => setToggles((current) => ({ ...current, [name]: !current[name] })), []) const highlightUnderCursor = useCallback(() => { @@ -181,14 +203,16 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps onDisconnect={onDisconnect} />
- + + {viewId === 'regions' && regions.length > 1 && } +
setArea((current) => (sameRect(current, next) ? current : next)), onError: tell }} onPointer={setPointer} onDragged={() => setToggles((current) => (current.follow ? { ...current, follow: false } : current))} onTeleport={teleport} @@ -201,7 +225,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps }} /> {pointer !== null && hover !== null && ( - + )} {!connected && (
@@ -214,14 +238,26 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
)}
- setHighlight((current) => (sameSubject(current, subject) ? null : subject))} - /> +
- +
) @@ -231,11 +267,63 @@ function sameSubject(first: Highlight | null, second: Highlight | null): boolean return first !== null && second !== null && first.kind === second.kind && first.key === second.key } -function legendTitle(viewId: string): string { - if (viewId === 'regions') { +function sameRect(first: WorldRect | null, second: WorldRect): boolean { + return first !== null && first.minX === second.minX && first.minZ === second.minZ && first.maxX === second.maxX && first.maxZ === second.maxZ +} + +function legendTitle(layer: MapLayerQuery): string { + if (layer.view === 'regions' && layer.preview === null) { return 'Regions on screen' } - return viewId === 'height' ? 'Heights on screen' : 'Biomes on screen' + return layer.view === 'height' ? 'Heights on screen' : 'Biomes on screen' +} + +/** The regions the region view can preview, read again after the pack reloads. */ +function usePreviewableRegions(client: BridgeClient, packRevision: number): MapLabel[] { + const [regions, setRegions] = useState([]) + useEffect(() => { + let active = true + client + .regions() + .then((found) => active && setRegions(found)) + .catch(() => undefined) + return () => { + active = false + } + }, [client, packRevision]) + return regions +} + +/** + * Measures how the noise picks what the view shows, once the map has rested on an area for a moment; the last + * measurement stays up until the next one arrives, so panning does not blank the panel. + */ +function usePickInspection( + client: BridgeClient, + layer: MapLayerQuery, + area: WorldRect | null, + enabled: boolean, + packRevision: number +): PickInspection | null { + const [inspection, setInspection] = useState(null) + useEffect(() => setInspection(null), [layer, packRevision]) + useEffect(() => { + if (!enabled || area === null) { + return + } + const stop = new AbortController() + const timer = window.setTimeout(() => { + client + .picks(layer, area, stop.signal) + .then(setInspection) + .catch(() => undefined) + }, INSPECTION_REST_MILLIS) + return () => { + window.clearTimeout(timer) + stop.abort() + } + }, [client, layer, area, enabled, packRevision]) + return inspection } /** Players and hotloads from the server; the first world event only says the world runs, which is known. */ @@ -244,7 +332,8 @@ function useServerEvents( controller: React.RefObject, setPlayers: (players: Marker[]) => void, tell: (message: string) => void, - setConnected: (connected: boolean) => void + setConnected: (connected: boolean) => void, + onPackReloaded: () => void ): void { useEffect(() => { const stop = new AbortController() @@ -258,6 +347,7 @@ function useServerEvents( } if (running) { controller.current?.refresh() + onPackReloaded() tell('Pack reloaded, redrawing') } else { tell('The world stopped') @@ -269,7 +359,7 @@ function useServerEvents( stop.signal ) return () => stop.abort() - }, [client, controller, setPlayers, tell, setConnected]) + }, [client, controller, setPlayers, tell, setConnected, onPackReloaded]) } function useEntities(client: BridgeClient, visible: boolean, setEntities: (entities: Marker[]) => void): void { @@ -297,7 +387,7 @@ function useEntities(client: BridgeClient, visible: boolean, setEntities: (entit function useHover( client: BridgeClient, controller: React.RefObject, - viewId: string, + layer: MapLayerQuery, pointer: CanvasPoint | null, setHover: (hover: MapHover | null) => void ): void { @@ -309,11 +399,11 @@ function useHover( const spot = controller.current.worldAt(pointer.x, pointer.y) const stop = new AbortController() client - .hover(viewId, Math.floor(spot.x), Math.floor(spot.z), stop.signal) + .hover(layer, Math.floor(spot.x), Math.floor(spot.z), stop.signal) .then(setHover) .catch(() => undefined) return () => stop.abort() - }, [client, controller, viewId, pointer, setHover]) + }, [client, controller, layer, pointer, setHover]) } function useKeyboard( diff --git a/src/renderer/src/studio/NoiseChart.tsx b/src/renderer/src/studio/NoiseChart.tsx new file mode 100644 index 000000000..8ab7b37b2 --- /dev/null +++ b/src/renderer/src/studio/NoiseChart.tsx @@ -0,0 +1,131 @@ +import { useState } from 'react' +import { cn } from '@/lib/utils' +import type { PickShare, PickSpread } from '../bridge/types' +import { hexColor } from './colors' + +// A long table keeps the options with the most ground in view until asked for all. +const SHORT_TABLE_ROWS = 6 +// An option getting under half or over twice its share of the noise stands out. +const FAR_FROM_WEIGHT_FACTOR = 2 + +interface NoiseChartProps { + spread: PickSpread + /** What the noise picks, as the table's heading: "Regions" or "Biomes". */ + optionNoun: string +} + +/** + * One noise that picks regions or biomes: how its values in view spread over the bands that pick each option, and a + * table of each option's share of the noise against its share of the ground in view (v3e NoisePickChart). + */ +export function NoiseChart({ spread, optionNoun }: NoiseChartProps): React.JSX.Element { + if (spread.rows.length === 1) { + return ( +
+ {spread.title} +
+ + Picked everywhere +
+
+ ) + } + return ( +
+ {spread.title} + + +
+ ) +} + +function ChartTitle({ children }: { children: React.ReactNode }): React.JSX.Element { + return

{children}

+} + +function Spread({ spread }: { spread: PickSpread }): React.JSX.Element { + const peak = Math.max(1, ...spread.histogram) + return ( +
+
+ {spread.histogram.map((count, bin) => ( + + ))} + {spread.bands.slice(0, -1).map((band, index) => ( + + ))} +
+
+ {spread.bands.map((band, index) => ( + + ))} +
+
+ 0 + 0.5 + 1 +
+
+ ) +} + +function ShareTable({ rows, optionNoun }: { rows: PickShare[]; optionNoun: string }): React.JSX.Element { + const [showsAll, setShowsAll] = useState(false) + const long = rows.length > SHORT_TABLE_ROWS + const shown = showsAll || !long ? rows : largestInView(rows) + return ( +
+ {optionNoun} + Weight + In view + {shown.map((share) => ( + + ))} + {long && ( + + )} +
+ ) +} + +function ShareRow({ share, rows }: { share: PickShare; rows: PickShare[] }): React.JSX.Element { + const farFromWeight = share.inView * FAR_FROM_WEIGHT_FACTOR < share.weight || share.inView > share.weight * FAR_FROM_WEIGHT_FACTOR + return ( + <> + + {percent(share.weight)} + {percent(share.inView)} + + ) +} + +// Two biomes in different folders can share a name, so their keys tell them apart. +function OptionName({ share, rows }: { share: PickShare; rows: PickShare[] }): React.JSX.Element { + const shared = rows.some((other) => other !== share && other.option.name === share.option.name) + return ( + + + {shared ? `${share.option.name} (${share.option.key})` : share.option.name} + + ) +} + +/** The rows with the most ground in view, still in the order the noise meets them. */ +export function largestInView(rows: PickShare[]): PickShare[] { + const largest = new Set([...rows].sort((first, second) => second.inView - first.inView).slice(0, SHORT_TABLE_ROWS)) + return rows.filter((row) => largest.has(row)) +} + +export function percent(fraction: number): string { + if (fraction > 0 && fraction < 0.001) { + return '<0.1%' + } + return `${(fraction * 100).toFixed(1)}%` +} diff --git a/src/renderer/src/studio/PickInspector.tsx b/src/renderer/src/studio/PickInspector.tsx new file mode 100644 index 000000000..36610ae72 --- /dev/null +++ b/src/renderer/src/studio/PickInspector.tsx @@ -0,0 +1,112 @@ +import { ChevronRight } from 'lucide-react' +import { useState } from 'react' +import { ScrollArea } from '@/components/ui/scroll-area' +import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group' +import type { PickDisplay, PickInspection, PickSection } from '../bridge/types' +import { hexColor } from './colors' +import { NoiseChart, percent } from './NoiseChart' + +// The chosen display reads like the toolbar's switched-on toggles. +const DISPLAY_ITEM = 'h-7 text-[12px] data-[state=on]:bg-selection data-[state=on]:text-foreground' + +interface PickInspectorProps { + /** What is inspected: "Regions", "Biomes", or the previewed region's name. */ + title: string + /** What the map shows when it draws the picks: "Regions" or "Biomes". */ + picksLabel: string + /** The latest measurement of the view; null until the first one arrives. */ + inspection: PickInspection | null + display: PickDisplay + onDisplay(display: PickDisplay): void +} + +/** + * How noise picks the regions or biomes in view, measured against what is in view, with a switch for how the map + * draws the picks (v3e PickInspectorPanel). + */ +export function PickInspector({ title, picksLabel, inspection, display, onDisplay }: PickInspectorProps): React.JSX.Element { + return ( +
+
+

{title}

+

{inspection?.detail ?? 'Measuring what is in view…'}

+ value !== '' && onDisplay(value as PickDisplay)} + > + + {picksLabel} + + + Noise + + + Both + + +
+ +
{inspection !== null && }
+
+
+ ) +} + +// A single section is the whole view, so its charts stand on their own; several are one region each, folded. +function Sections({ sections }: { sections: PickSection[] }): React.JSX.Element { + const [opened, setOpened] = useState | null>(null) + if (sections.length === 1) { + return + } + const open = opened ?? new Set(sections.slice(0, 1).map(sectionKey)) + const toggle = (key: string): void => { + const next = new Set(open) + if (!next.delete(key)) { + next.add(key) + } + setOpened(next) + } + return ( + <> + {sections.map((section) => ( + toggle(sectionKey(section))} /> + ))} + + ) +} + +function RegionSection({ section, open, onToggle }: { section: PickSection; open: boolean; onToggle(): void }): React.JSX.Element { + const region = section.region + return ( +
+ + {open && } +
+ ) +} + +function Charts({ section }: { section: PickSection }): React.JSX.Element { + const optionNoun = section.region === null ? 'Regions' : 'Biomes' + return ( +
+ {section.spreads.map((spread) => ( + + ))} +
+ ) +} + +function sectionKey(section: PickSection): string { + return section.region?.key ?? '' +} diff --git a/src/renderer/src/studio/PickRows.tsx b/src/renderer/src/studio/PickRows.tsx index cc2d9ded5..8ce947999 100644 --- a/src/renderer/src/studio/PickRows.tsx +++ b/src/renderer/src/studio/PickRows.tsx @@ -4,6 +4,8 @@ import { hexColor } from './colors' // Gaps between bands shrink as there are more of them, so many thin bands still read as a bar. const WIDE_GAP_MOST_BANDS = 18 const NARROW_GAP_MOST_BANDS = 50 +/** Why a step that nothing picked has its label. */ +const UNPICKED_NOTES: Partial> = { FOCUS: 'Focus', IMAGE_MAP: 'Image map', PREVIEW: 'Preview' } /** How the spot got its region and biome: one row per pick, the noise value marked on every option's share of it. */ export function PickRows({ path }: { path: PickStep[] }): React.JSX.Element | null { @@ -24,7 +26,7 @@ function PickRow({ step }: { step: PickStep }): React.JSX.Element { <> {rowLabel(step)} {step.noise === null ? ( - {step.kind === 'FOCUS' ? 'Focus' : 'Image map'} + {UNPICKED_NOTES[step.kind] ?? ''} ) : ( )} @@ -73,6 +75,7 @@ function rowLabel(step: PickStep): string { return 'Child' case 'IMAGE_MAP': case 'FOCUS': + case 'PREVIEW': return step.picked.kind === 'REGION' ? 'Region' : 'Biome' } } diff --git a/src/renderer/src/studio/RegionPreviewList.tsx b/src/renderer/src/studio/RegionPreviewList.tsx new file mode 100644 index 000000000..d3b1e1d2b --- /dev/null +++ b/src/renderer/src/studio/RegionPreviewList.tsx @@ -0,0 +1,72 @@ +import { useState } from 'react' +import { Input } from '@/components/ui/input' +import { cn } from '@/lib/utils' +import type { MapLabel } from '../bridge/types' +import { hexColor } from './colors' + +// Short lists are scanned at a glance; longer ones get a search field. +const SEARCHABLE_FROM_REGIONS = 8 + +interface RegionPreviewListProps { + regions: MapLabel[] + /** The previewed region's key, or null for all regions. */ + current: string | null + onSelect(regionKey: string | null): void +} + +/** The region view's regions, any of which can fill the map with its biomes, or all of them as they are (v3e RegionNavigator). */ +export function RegionPreviewList({ regions, current, onSelect }: RegionPreviewListProps): React.JSX.Element { + const [search, setSearch] = useState('') + const wanted = search.trim().toLowerCase() + const shown = wanted === '' ? regions : regions.filter((region) => `${region.name} ${region.key}`.toLowerCase().includes(wanted)) + return ( +
+

Preview a region

+ {regions.length >= SEARCHABLE_FROM_REGIONS && ( + setSearch(event.target.value)} + onKeyDown={(event) => event.key === 'Escape' && setSearch('')} + /> + )} + onSelect(null)} /> + {shown.map((region) => ( + onSelect(region.key)} + /> + ))} + {shown.length === 0 &&

No region matches

} +
+ ) +} + +interface RegionRowProps { + name: string + color: number | null + title?: string + selected: boolean + onSelect(): void +} + +function RegionRow({ name, color, title, selected, onSelect }: RegionRowProps): React.JSX.Element { + return ( + + ) +} diff --git a/src/renderer/src/studio/ViewList.tsx b/src/renderer/src/studio/ViewList.tsx index 43a57b869..362e0e074 100644 --- a/src/renderer/src/studio/ViewList.tsx +++ b/src/renderer/src/studio/ViewList.tsx @@ -18,10 +18,12 @@ interface ViewListProps { views: ViewInfo[] current: string onSelect(view: string): void + /** What the current view adds below the views, such as the regions it can preview. */ + children?: React.ReactNode } /** The views the server offers, in its groups, each with what it shows and its key. */ -export function ViewList({ views, current, onSelect }: ViewListProps): React.JSX.Element { +export function ViewList({ views, current, onSelect, children }: ViewListProps): React.JSX.Element { const groups = [...new Set(views.map((view) => view.groupLabel))] return ( From e0812cca660d5943e4c7496a9d344c081722140a Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 01:26:06 +0100 Subject: [PATCH 04/12] Objects view: the pack's block scenes in 3D Scene views the pack's modules show join the view list under Blocks. Choosing one lists its entries under their folders, with a search, and draws the chosen one with three.js: block states resolve to the client's models (variants, multipart, parents, element and variant turns), their textures go into one atlas, faces against solid blocks are left out, and each side gets Minecraft's flat light and its block's tint. The blocks it is made of are listed with their counts. Models the client draws without elements stand in as cubes of their break texture. --- package-lock.json | 67 +++- package.json | 4 +- src/renderer/src/bridge/BridgeClient.ts | 32 +- src/renderer/src/bridge/types.ts | 15 + src/renderer/src/scene/BridgeAssets.ts | 44 +++ src/renderer/src/scene/blockModels.test.ts | 68 ++++ src/renderer/src/scene/blockModels.ts | 389 +++++++++++++++++++++ src/renderer/src/scene/blockTints.ts | 51 +++ src/renderer/src/scene/sceneDecoding.ts | 32 ++ src/renderer/src/scene/sceneMesh.ts | 137 ++++++++ src/renderer/src/scene/textureAtlas.ts | 105 ++++++ src/renderer/src/studio/MapStudio.tsx | 53 ++- src/renderer/src/studio/SceneStudio.tsx | 219 ++++++++++++ src/renderer/src/studio/SceneViewport.tsx | 122 +++++++ src/renderer/src/studio/StudioToolbar.tsx | 50 +-- src/renderer/src/studio/ViewList.tsx | 5 +- 16 files changed, 1361 insertions(+), 32 deletions(-) create mode 100644 src/renderer/src/scene/BridgeAssets.ts create mode 100644 src/renderer/src/scene/blockModels.test.ts create mode 100644 src/renderer/src/scene/blockModels.ts create mode 100644 src/renderer/src/scene/blockTints.ts create mode 100644 src/renderer/src/scene/sceneDecoding.ts create mode 100644 src/renderer/src/scene/sceneMesh.ts create mode 100644 src/renderer/src/scene/textureAtlas.ts create mode 100644 src/renderer/src/studio/SceneStudio.tsx create mode 100644 src/renderer/src/studio/SceneViewport.tsx diff --git a/package-lock.json b/package-lock.json index c62737202..2ed25bf5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,13 +15,15 @@ "radix-ui": "^1.8.1", "react": "^19.3.1", "react-dom": "^19.3.1", - "tailwind-merge": "^3.7.0" + "tailwind-merge": "^3.7.0", + "three": "^0.187.0" }, "devDependencies": { "@tailwindcss/vite": "^4.3.4", "@types/node": "^26.6.6", "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", + "@types/three": "^0.187.0", "@vitejs/plugin-react": "^6.2.1", "electron": "^45.2.3", "electron-vite": "^6.0.0", @@ -317,6 +319,13 @@ "node": ">=6.9.0" } }, + "node_modules/@dimforge/rapier3d-compat": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@dimforge/rapier3d-compat/-/rapier3d-compat-0.12.0.tgz", + "integrity": "sha512-uekIGetywIgopfD97oDL5PfeezkFpNhwlzlaEYNOA0N6ghdsOvh/HYjSMek5Q2O1PYvRSDFcqFVJl4r4ZBwOow==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/@electron-internal/extract-zip": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@electron-internal/extract-zip/-/extract-zip-1.0.8.tgz", @@ -2579,6 +2588,13 @@ "vite": "^5.2.0 || ^6 || ^7 || ^8" } }, + "node_modules/@tweenjs/tween.js": { + "version": "23.1.3", + "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-23.1.3.tgz", + "integrity": "sha512-vJmvvwFxYuGnF2axRtPYocag6Clbb5YS7kLL+SO/TeVFzHqDIWrNKYtcsPMibjDx9O+bu+psAy9NKfWklassUA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/chai": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", @@ -2634,6 +2650,35 @@ "@types/react": "^19.3.0" } }, + "node_modules/@types/stats.js": { + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/@types/stats.js/-/stats.js-0.17.4.tgz", + "integrity": "sha512-jIBvWWShCvlBqBNIZt0KAshWpvSjhkwkEu4ZUcASoAvhmrgAUI2t1dXrjSL4xXVLB4FznPrIsX3nKXFl/Dt4vA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/three": { + "version": "0.187.0", + "resolved": "https://registry.npmjs.org/@types/three/-/three-0.187.0.tgz", + "integrity": "sha512-v+vKNarUtk4n2QRZ4+CN5ygMM0ARUjXjIQl0R/unMUfmStFeVqGbgqarbrpoGTXRZoulSH16ePrVJVxPJEbMUA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@dimforge/rapier3d-compat": "~0.12.0", + "@tweenjs/tween.js": "~23.1.3", + "@types/stats.js": "*", + "@types/webxr": ">=0.5.17", + "fflate": "~0.8.3", + "meshoptimizer": "~1.1.1" + } + }, + "node_modules/@types/webxr": { + "version": "0.5.24", + "resolved": "https://registry.npmjs.org/@types/webxr/-/webxr-0.5.24.tgz", + "integrity": "sha512-h8fgEd/DpoS9CBrjEQXR+dIDraopAEfu4wYVNY2tEPwk60stPWhvZMf4Foo5FakuQ7HFZoa8WceaWFervK2Ovg==", + "dev": true, + "license": "MIT" + }, "node_modules/@typescript/typescript-aix-ppc64": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/@typescript/typescript-aix-ppc64/-/typescript-aix-ppc64-7.0.2.tgz", @@ -3388,6 +3433,13 @@ } } }, + "node_modules/fflate": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz", + "integrity": "sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA==", + "dev": true, + "license": "MIT" + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -3780,6 +3832,13 @@ "@jridgewell/sourcemap-codec": "^1.6.0" } }, + "node_modules/meshoptimizer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/meshoptimizer/-/meshoptimizer-1.1.1.tgz", + "integrity": "sha512-oRFNWJRDA/WTrVj7NWvqa5HqE1t9MYDj2VaWirQCzCCrAd2GHrqR/sQezCxiWATPNlKTcRaPRHPJwIRoPBAp5g==", + "dev": true, + "license": "MIT" + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -4170,6 +4229,12 @@ "url": "https://opencollective.com/webpack" } }, + "node_modules/three": { + "version": "0.187.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.187.0.tgz", + "integrity": "sha512-Qiu7R+Cmh8CstZsY1uJOSWnVlfo7ZtNLV7mF8Jltk3LB3AtDu9cRZlcnRKkAk8Y4z6KKw35z7Y7Urd7jWY8etA==", + "license": "MIT" + }, "node_modules/tinybench": { "version": "6.2.3", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.3.tgz", diff --git a/package.json b/package.json index 47598774d..38e4424d5 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@types/node": "^26.6.6", "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", + "@types/three": "^0.187.0", "@vitejs/plugin-react": "^6.2.1", "electron": "^45.2.3", "electron-vite": "^6.0.0", @@ -34,6 +35,7 @@ "radix-ui": "^1.8.1", "react": "^19.3.1", "react-dom": "^19.3.1", - "tailwind-merge": "^3.7.0" + "tailwind-merge": "^3.7.0", + "three": "^0.187.0" } } diff --git a/src/renderer/src/bridge/BridgeClient.ts b/src/renderer/src/bridge/BridgeClient.ts index 9a3c0255c..15a27ab73 100644 --- a/src/renderer/src/bridge/BridgeClient.ts +++ b/src/renderer/src/bridge/BridgeClient.ts @@ -1,6 +1,10 @@ import type { BridgeConnection } from '../../../shared/bridge' +import { decodeScene, type BlockScene } from '../scene/sceneDecoding' import { decodeTile } from './tileDecoding' -import type { MapHover, MapLabel, MapTile, Marker, PickInspection, WorldInfo } from './types' +import type { MapHover, MapLabel, MapTile, Marker, PickInspection, SceneEntry, SceneViewInfo, WorldInfo } from './types' + +export const STATUS_NOT_FOUND = 404 +export const STATUS_UNAVAILABLE = 503 export class BridgeError extends Error { constructor( @@ -100,6 +104,32 @@ export class BridgeClient { return decodeTile(await response.arrayBuffer()) } + /** The scene views the pack's modules show, such as its objects. */ + sceneViews(): Promise { + return this.json('scenes') + } + + sceneEntries(viewId: string): Promise { + return this.json(`scene-entries?${new URLSearchParams({ view: viewId })}`) + } + + async scene(viewId: string, key: string, variant: number, signal?: AbortSignal): Promise { + const response = await this.fetch(`scene?${new URLSearchParams({ view: viewId, key, variant: String(variant) })}`, { signal }) + return decodeScene(await response.arrayBuffer()) + } + + /** A file of the Minecraft client's assets, such as {@code minecraft/blockstates/stone.json}; null when there is none. */ + async asset(path: string): Promise { + try { + return await this.fetch(`assets/${path}`, {}) + } catch (error) { + if (error instanceof BridgeError && error.status === STATUS_NOT_FOUND) { + return null + } + throw error + } + } + /** Streams the bridge's events until {@code signal} aborts or the bridge goes away. */ async listen(events: BridgeEvents, signal: AbortSignal): Promise { try { diff --git a/src/renderer/src/bridge/types.ts b/src/renderer/src/bridge/types.ts index 97fecd342..ec4592f5c 100644 --- a/src/renderer/src/bridge/types.ts +++ b/src/renderer/src/bridge/types.ts @@ -18,6 +18,21 @@ export interface ViewInfo { groupLabel: string } +/** A view of block scenes a module of the pack shows, such as its objects (IrisApi SceneView). */ +export interface SceneViewInfo { + id: string + label: string + description: string +} + +export interface SceneEntry { + key: string + name: string + /** The folder it is listed under; empty for none. */ + group: string + variants: number +} + export interface WorldInfo { world: string dimension: string diff --git a/src/renderer/src/scene/BridgeAssets.ts b/src/renderer/src/scene/BridgeAssets.ts new file mode 100644 index 000000000..e6fc40d6d --- /dev/null +++ b/src/renderer/src/scene/BridgeAssets.ts @@ -0,0 +1,44 @@ +import { BridgeError, STATUS_UNAVAILABLE, type BridgeClient } from '../bridge/BridgeClient' +import type { AssetSource } from './blockModels' +import type { ImageSource } from './textureAtlas' + +const RETRY_MILLIS = 2000 +const LONGEST_WAIT_MILLIS = 10 * 60 * 1000 + +/** + * The Minecraft client's assets through the bridge. The server fetches the client the first time anyone asks, so + * until it has it every request waits, telling {@code onWaiting} why. + */ +export class BridgeAssets implements AssetSource, ImageSource { + constructor( + private readonly client: BridgeClient, + private readonly onWaiting: (reason: string | null) => void + ) {} + + async json(path: string): Promise { + const response = await this.fetch(path) + return response === null ? null : response.json() + } + + async image(path: string): Promise { + const response = await this.fetch(path) + return response === null ? null : createImageBitmap(await response.blob()) + } + + private async fetch(path: string): Promise { + const giveUpAt = Date.now() + LONGEST_WAIT_MILLIS + for (;;) { + try { + const response = await this.client.asset(path) + this.onWaiting(null) + return response + } catch (error) { + if (!(error instanceof BridgeError) || error.status !== STATUS_UNAVAILABLE || Date.now() > giveUpAt) { + throw error + } + this.onWaiting(error.message) + await new Promise((resume) => window.setTimeout(resume, RETRY_MILLIS)) + } + } + } +} diff --git a/src/renderer/src/scene/blockModels.test.ts b/src/renderer/src/scene/blockModels.test.ts new file mode 100644 index 000000000..7cf4570bd --- /dev/null +++ b/src/renderer/src/scene/blockModels.test.ts @@ -0,0 +1,68 @@ +import { describe, expect, it } from 'vitest' +import { BlockModels, parseState, type AssetSource } from './blockModels' + +const CUBE_ALL = { + textures: { particle: '#all' }, + elements: [ + { + from: [0, 0, 0], + to: [16, 16, 16], + faces: Object.fromEntries(['down', 'up', 'north', 'south', 'west', 'east'].map((side) => [side, { texture: '#all', cullface: side }])) + } + ] +} + +const FILES: Record = { + 'minecraft/blockstates/stone.json': { variants: { '': { model: 'minecraft:block/stone' } } }, + 'minecraft/models/block/stone.json': { parent: 'block/cube_all', textures: { all: 'minecraft:block/stone' } }, + 'minecraft/models/block/cube_all.json': CUBE_ALL, + 'minecraft/blockstates/oak_log.json': { + variants: { 'axis=y': { model: 'block/oak_log' }, 'axis=x': { model: 'block/oak_log', x: 90, y: 90 } } + }, + 'minecraft/models/block/oak_log.json': { parent: 'block/cube_all', textures: { all: 'block/oak_log' } }, + 'minecraft/blockstates/fence.json': { + multipart: [{ apply: { model: 'block/stone' } }, { when: { north: 'true' }, apply: { model: 'block/stone' } }, { when: { OR: [{ east: 'true' }, { west: 'true|x' }] }, apply: { model: 'block/stone' } }] + }, + 'minecraft/blockstates/chest.json': { variants: { '': { model: 'block/chest' } } }, + 'minecraft/models/block/chest.json': { textures: { particle: 'block/oak_planks' } } +} + +const assets: AssetSource = { json: async (path) => FILES[path] ?? null } + +describe('block models', () => { + it('reads a block state key', () => { + expect(parseState('minecraft:oak_log[axis=y]')).toEqual({ namespace: 'minecraft', name: 'oak_log', properties: { axis: 'y' } }) + expect(parseState('stone')).toEqual({ namespace: 'minecraft', name: 'stone', properties: {} }) + }) + + it('fills a model from its parents and keeps its six faces culled by their sides', async () => { + const stone = (await new BlockModels(assets).model('minecraft:stone'))! + + expect(stone.fullCube).toBe(true) + expect(stone.particle).toBe('minecraft:block/stone') + expect(stone.quads.map((quad) => quad.texture)).toEqual(Array(6).fill('minecraft:block/stone')) + expect(stone.quads.find((quad) => quad.facing === 'up')!.corners.every(([, y]) => y === 1)).toBe(true) + }) + + it('turns a variant: x first, then y, so a log lying along x shows its top to the east', async () => { + const log = (await new BlockModels(assets).model('minecraft:oak_log[axis=x]'))! + const top = log.quads.find((quad) => quad.cullFace === 'east')! + + expect(top.facing).toBe('east') + expect(top.corners.every(([x]) => Math.abs(x - 1) < 1e-9)).toBe(true) + }) + + it('applies the multipart pieces whose conditions the state meets', async () => { + const models = new BlockModels(assets) + + expect((await models.model('minecraft:fence[east=false,north=false,west=false]'))!.quads).toHaveLength(6) + expect((await models.model('minecraft:fence[east=false,north=true,west=x]'))!.quads).toHaveLength(18) + }) + + it('knows a model without elements, and no model at all', async () => { + const models = new BlockModels(assets) + + expect(await models.model('minecraft:chest')).toEqual({ quads: [], fullCube: false, particle: 'minecraft:block/oak_planks' }) + expect(await models.model('minecraft:nothing')).toBeNull() + }) +}) diff --git a/src/renderer/src/scene/blockModels.ts b/src/renderer/src/scene/blockModels.ts new file mode 100644 index 000000000..abecc1a4c --- /dev/null +++ b/src/renderer/src/scene/blockModels.ts @@ -0,0 +1,389 @@ +/** + * Minecraft's block models, read the way the client reads them: a block state picks variants or multipart pieces from + * its blockstate file, each a model whose parents fill in textures and elements, turned in steps of 90 degrees. + */ + +export type Direction = 'down' | 'up' | 'north' | 'south' | 'west' | 'east' +export type Vec3 = [number, number, number] + +/** Where a block model's files come from: the bridge's copy of the client's assets. */ +export interface AssetSource { + /** The JSON file at {@code path} below the assets folder, or null when there is none. */ + json(path: string): Promise +} + +/** One textured face of a block, in block units from its lowest corner (0 to 1 on each axis). */ +export interface Quad { + /** Top left, bottom left, bottom right, top right as the texture lies on the face, seen from outside. */ + corners: [Vec3, Vec3, Vec3, Vec3] + /** The texture's coordinates at each corner, 0 to 1 from its top left. */ + uvs: [[number, number], [number, number], [number, number], [number, number]] + /** Such as minecraft:block/stone. */ + texture: string + /** Which of the block's tints colours the face, or -1 for none. */ + tintIndex: number + /** The side whose neighbour, when it is a solid block, hides the face; null when nothing hides it. */ + cullFace: Direction | null + /** The side the face looks toward, for its light. */ + facing: Direction + shade: boolean +} + +export interface BlockModel { + quads: Quad[] + /** A single element filling the whole block on every side, which hides the faces it touches if its textures are solid. */ + fullCube: boolean + /** The texture the client breaks the block with, which stands in for blocks the client draws without a model. */ + particle: string | null +} + +export interface ParsedState { + namespace: string + name: string + properties: Record +} + +type Json = Record + +interface Variant { + model: string + x: number + y: number +} + +interface ModelFile { + parent?: string + textures?: Record + elements?: ElementJson[] +} + +interface ElementJson { + from: Vec3 + to: Vec3 + rotation?: { origin: Vec3; axis: 'x' | 'y' | 'z'; angle: number; rescale?: boolean } + shade?: boolean + faces: Partial> +} + +interface FaceJson { + uv?: [number, number, number, number] + texture: string + cullface?: Direction + rotation?: number + tintindex?: number +} + +const PIXELS = 16 +const DEFAULT_NAMESPACE = 'minecraft' +const MAX_PARENT_DEPTH = 32 +const DIRECTIONS: Direction[] = ['down', 'up', 'north', 'south', 'west', 'east'] +const DIRECTION_VECTORS: Record = { + down: [0, -1, 0], + up: [0, 1, 0], + north: [0, 0, -1], + south: [0, 0, 1], + west: [-1, 0, 0], + east: [1, 0, 0] +} + +/** Reads {@code minecraft:oak_log[axis=y]}. */ +export function parseState(key: string): ParsedState { + const open = key.indexOf('[') + const id = open < 0 ? key : key.slice(0, open) + const colon = id.indexOf(':') + const properties: Record = {} + if (open >= 0) { + for (const pair of key.slice(open + 1, -1).split(',')) { + const equals = pair.indexOf('=') + if (equals > 0) { + properties[pair.slice(0, equals)] = pair.slice(equals + 1) + } + } + } + return colon < 0 + ? { namespace: DEFAULT_NAMESPACE, name: id, properties } + : { namespace: id.slice(0, colon), name: id.slice(colon + 1), properties } +} + +/** Resolves and keeps the models of block states; one per connection, as its assets are one Minecraft version's. */ +export class BlockModels { + private readonly models = new Map>() + private readonly files = new Map>() + + constructor(private readonly assets: AssetSource) {} + + /** The model of a block state, or null when the client has no blockstate file for the block. */ + model(stateKey: string): Promise { + let model = this.models.get(stateKey) + if (model === undefined) { + model = this.resolve(parseState(stateKey)) + this.models.set(stateKey, model) + } + return model + } + + private async resolve(state: ParsedState): Promise { + const blockstate = (await this.assets.json(`${state.namespace}/blockstates/${state.name}.json`)) as Json | null + if (blockstate === null) { + return null + } + const variants = pickVariants(blockstate, state.properties) + const pieces = await Promise.all(variants.map((variant) => this.piece(variant))) + const quads = pieces.flatMap((piece) => piece.quads) + return { quads, fullCube: pieces.length === 1 && pieces[0].fullCube, particle: pieces[0]?.particle ?? null } + } + + private async piece(variant: Variant): Promise { + const chain = await this.parentChain(variant.model) + const textures: Record = {} + for (const file of [...chain].reverse()) { + Object.assign(textures, file.textures ?? {}) + } + const elements = chain.find((file) => file.elements !== undefined)?.elements ?? [] + const quads = elements.flatMap((element) => elementQuads(element, textures)) + const turned = quads.map((quad) => turn(quad, variant.x, variant.y)) + return { quads: turned, fullCube: elements.length === 1 && isFullCube(elements[0]), particle: textureOf('#particle', textures) } + } + + private async parentChain(modelId: string): Promise { + const chain: ModelFile[] = [] + let next: string | undefined = modelId + while (next !== undefined && chain.length < MAX_PARENT_DEPTH) { + const file = await this.file(next) + if (file === null) { + break + } + chain.push(file) + next = file.parent + } + return chain + } + + private file(modelId: string): Promise { + let file = this.files.get(modelId) + if (file === undefined) { + const { namespace, path } = splitId(modelId) + file = this.assets.json(`${namespace}/models/${path}.json`) as Promise + this.files.set(modelId, file) + } + return file + } +} + +/** A whole block with {@code texture} on every side, for blocks the client draws without a model. */ +export function cubeModel(texture: string): BlockModel { + const faces = Object.fromEntries(DIRECTIONS.map((direction) => [direction, { texture: '#all', cullface: direction }])) + const quads = elementQuads({ from: [0, 0, 0], to: [PIXELS, PIXELS, PIXELS], faces }, { all: texture }) + return { quads, fullCube: true, particle: texture } +} + +/** The variant a block state picks, or the multipart pieces whose conditions it meets; the first of weighted choices. */ +function pickVariants(blockstate: Json, properties: Record): Variant[] { + const variants = blockstate.variants as Record | undefined + if (variants !== undefined) { + for (const [condition, choice] of Object.entries(variants)) { + if (matchesVariantKey(condition, properties)) { + return [variantOf(choice)] + } + } + return [] + } + const multipart = blockstate.multipart as { when?: Json; apply: unknown }[] | undefined + return (multipart ?? []).filter((part) => part.when === undefined || meets(part.when, properties)).map((part) => variantOf(part.apply)) +} + +function matchesVariantKey(condition: string, properties: Record): boolean { + if (condition === '') { + return true + } + return condition.split(',').every((pair) => { + const [name, value] = pair.split('=') + return properties[name] === value + }) +} + +function meets(condition: Json, properties: Record): boolean { + if (Array.isArray(condition.OR)) { + return (condition.OR as Json[]).some((part) => meets(part, properties)) + } + if (Array.isArray(condition.AND)) { + return (condition.AND as Json[]).every((part) => meets(part, properties)) + } + return Object.entries(condition).every(([name, allowed]) => String(allowed).split('|').includes(properties[name])) +} + +function variantOf(choice: unknown): Variant { + const picked = (Array.isArray(choice) ? choice[0] : choice) as Json + return { model: String(picked.model), x: Number(picked.x ?? 0), y: Number(picked.y ?? 0) } +} + +function splitId(id: string): { namespace: string; path: string } { + const colon = id.indexOf(':') + return colon < 0 ? { namespace: DEFAULT_NAMESPACE, path: id } : { namespace: id.slice(0, colon), path: id.slice(colon + 1) } +} + +function isFullCube(element: ElementJson): boolean { + const fills = element.from.every((value) => value === 0) && element.to.every((value) => value === PIXELS) + return fills && element.rotation === undefined && DIRECTIONS.every((direction) => element.faces[direction] !== undefined) +} + +function elementQuads(element: ElementJson, textures: Record): Quad[] { + const quads: Quad[] = [] + for (const direction of DIRECTIONS) { + const face = element.faces[direction] + if (face === undefined) { + continue + } + const texture = textureOf(face.texture, textures) + if (texture === null) { + continue + } + const corners = faceCorners(direction, element.from, element.to).map((corner) => rotateInElement(corner, element)) as Quad['corners'] + quads.push({ + corners, + uvs: faceUvs(face, direction, element.from, element.to), + texture, + tintIndex: face.tintindex ?? -1, + cullFace: face.cullface ?? null, + facing: direction, + shade: element.shade ?? true + }) + } + return quads +} + +/** Follows {@code #name} references through the model's textures to a texture id. */ +function textureOf(reference: string, textures: Record): string | null { + let current = reference + for (let step = 0; step < MAX_PARENT_DEPTH && current.startsWith('#'); step++) { + const next = textures[current.slice(1)] + if (next === undefined) { + return null + } + current = next + } + if (current.startsWith('#')) { + return null + } + const { namespace, path } = splitId(current) + return `${namespace}:${path}` +} + +/** A face's corners in pixels, top left first and counter-clockwise seen from outside, as {@link Quad#corners}. */ +function faceCorners(direction: Direction, from: Vec3, to: Vec3): Vec3[] { + const [x1, y1, z1] = from.map((value) => value / PIXELS) + const [x2, y2, z2] = to.map((value) => value / PIXELS) + switch (direction) { + case 'north': + return [[x2, y2, z1], [x2, y1, z1], [x1, y1, z1], [x1, y2, z1]] + case 'south': + return [[x1, y2, z2], [x1, y1, z2], [x2, y1, z2], [x2, y2, z2]] + case 'west': + return [[x1, y2, z1], [x1, y1, z1], [x1, y1, z2], [x1, y2, z2]] + case 'east': + return [[x2, y2, z2], [x2, y1, z2], [x2, y1, z1], [x2, y2, z1]] + case 'up': + return [[x1, y2, z1], [x1, y2, z2], [x2, y2, z2], [x2, y2, z1]] + case 'down': + return [[x1, y1, z2], [x1, y1, z1], [x2, y1, z1], [x2, y1, z2]] + } +} + +function faceUvs(face: FaceJson, direction: Direction, from: Vec3, to: Vec3): Quad['uvs'] { + const [u1, v1, u2, v2] = (face.uv ?? defaultUv(direction, from, to)).map((value) => value / PIXELS) + const uvs: Quad['uvs'] = [[u1, v1], [u1, v2], [u2, v2], [u2, v1]] + const steps = (((face.rotation ?? 0) / 90) % 4 + 4) % 4 + return uvs.map((_, corner) => uvs[(corner + steps) % 4]) as Quad['uvs'] +} + +// Minecraft's own default: the face shows the part of the texture its element covers, seen from outside. +function defaultUv(direction: Direction, [x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): [number, number, number, number] { + switch (direction) { + case 'down': + return [x1, PIXELS - z2, x2, PIXELS - z1] + case 'up': + return [x1, z1, x2, z2] + case 'north': + return [PIXELS - x2, PIXELS - y2, PIXELS - x1, PIXELS - y1] + case 'south': + return [x1, PIXELS - y2, x2, PIXELS - y1] + case 'west': + return [z1, PIXELS - y2, z2, PIXELS - y1] + case 'east': + return [PIXELS - z2, PIXELS - y2, PIXELS - z1, PIXELS - y1] + } +} + +function rotateInElement(corner: Vec3, element: ElementJson): Vec3 { + const rotation = element.rotation + if (rotation === undefined || rotation.angle === 0) { + return corner + } + const origin = rotation.origin.map((value) => value / PIXELS) as Vec3 + const radians = (rotation.angle * Math.PI) / 180 + const relative: Vec3 = [corner[0] - origin[0], corner[1] - origin[1], corner[2] - origin[2]] + const turned = rotateAboutAxis(relative, rotation.axis, radians) + if (rotation.rescale === true) { + const stretch = 1 / Math.cos(Math.abs(radians)) + for (const axis of [0, 1, 2]) { + if (axis !== 'xyz'.indexOf(rotation.axis)) { + turned[axis] *= stretch + } + } + } + return [turned[0] + origin[0], turned[1] + origin[1], turned[2] + origin[2]] +} + +function rotateAboutAxis([x, y, z]: Vec3, axis: 'x' | 'y' | 'z', radians: number): Vec3 { + const cos = Math.cos(radians) + const sin = Math.sin(radians) + switch (axis) { + case 'x': + return [x, y * cos - z * sin, y * sin + z * cos] + case 'y': + return [x * cos + z * sin, y, -x * sin + z * cos] + case 'z': + return [x * cos - y * sin, x * sin + y * cos, z] + } +} + +/** A variant's turn: {@code x} first, then {@code y}, each in steps of 90 degrees about the block's centre. */ +function turn(quad: Quad, xDegrees: number, yDegrees: number): Quad { + const xSteps = quarterTurns(xDegrees) + const ySteps = quarterTurns(yDegrees) + if (xSteps === 0 && ySteps === 0) { + return quad + } + const turnPoint = (point: Vec3): Vec3 => offsetFromCentre(turnVector(offsetFromCentre(point, -0.5), xSteps, ySteps), 0.5) + return { + ...quad, + corners: quad.corners.map(turnPoint) as Quad['corners'], + cullFace: quad.cullFace === null ? null : directionOf(turnVector(DIRECTION_VECTORS[quad.cullFace], xSteps, ySteps)), + facing: directionOf(turnVector(DIRECTION_VECTORS[quad.facing], xSteps, ySteps)) + } +} + +function quarterTurns(degrees: number): number { + return ((Math.round(degrees / 90) % 4) + 4) % 4 +} + +function offsetFromCentre([x, y, z]: Vec3, by: number): Vec3 { + return [x + by, y + by, z + by] +} + +// A quarter turn about x takes north to down; one about y takes north to east, as Minecraft turns its variants. +function turnVector(vector: Vec3, xSteps: number, ySteps: number): Vec3 { + let [x, y, z] = vector + for (let step = 0; step < xSteps; step++) { + ;[y, z] = [z, -y] + } + for (let step = 0; step < ySteps; step++) { + ;[x, z] = [-z, x] + } + return [x, y, z] +} + +function directionOf([x, y, z]: Vec3): Direction { + const rounded = [Math.round(x), Math.round(y), Math.round(z)].join(',') + return DIRECTIONS.find((direction) => DIRECTION_VECTORS[direction].join(',') === rounded) ?? 'up' +} diff --git a/src/renderer/src/scene/blockTints.ts b/src/renderer/src/scene/blockTints.ts new file mode 100644 index 000000000..e1d7a4f09 --- /dev/null +++ b/src/renderer/src/scene/blockTints.ts @@ -0,0 +1,51 @@ +/** + * The colour each tinted face of a block is multiplied with, as Minecraft's BlockColors give it (v3e + * MinecraftBlockTints). Scenes stand in no biome, so the biome tints are the plains' colours. + */ + +const NO_TINT = 0xffffff +const PLAINS_GRASS = 0x91bd59 +const PLAINS_FOLIAGE = 0x77ab2f +const PLAINS_DRY_FOLIAGE = 0xa0804b +const PLAINS_WATER = 0x3f76e4 + +const GRASS_TINTED = new Set(['grass_block', 'short_grass', 'fern', 'potted_fern', 'bush', 'tall_grass', 'large_fern', 'sugar_cane']) +const GRASS_TINTED_ON_SECOND_LAYER = new Set(['pink_petals', 'wildflowers']) +const FOLIAGE_TINTED = new Set(['oak_leaves', 'jungle_leaves', 'acacia_leaves', 'dark_oak_leaves', 'vine', 'mangrove_leaves']) +const WATER_TINTED = new Set(['water', 'bubble_column', 'water_cauldron']) +const GROWING_STEMS = new Set(['melon_stem', 'pumpkin_stem']) +const FIXED_TINTS: Record = { + spruce_leaves: 0x619961, + birch_leaves: 0x80a755, + attached_melon_stem: 0xe0c71c, + attached_pumpkin_stem: 0xe0c71c, + lily_pad: 0x208030 +} + +/** The tint of one face of block {@code name}, as 0xRRGGBB; white for an untinted face. */ +export function blockTint(name: string, properties: Record, tintIndex: number): number { + // The client tints water when it draws the fluid, which has no model, so its stand-in is tinted whole. + if (WATER_TINTED.has(name)) { + return PLAINS_WATER + } + if (GRASS_TINTED_ON_SECOND_LAYER.has(name)) { + return tintIndex === 1 ? PLAINS_GRASS : NO_TINT + } + if (tintIndex !== 0) { + return NO_TINT + } + if (GRASS_TINTED.has(name)) { + return PLAINS_GRASS + } + if (FOLIAGE_TINTED.has(name)) { + return PLAINS_FOLIAGE + } + if (name === 'leaf_litter') { + return PLAINS_DRY_FOLIAGE + } + if (GROWING_STEMS.has(name)) { + const age = Number(properties.age ?? '0') + return ((age * 32) << 16) | ((255 - age * 8) << 8) | (age * 4) + } + return FIXED_TINTS[name] ?? NO_TINT +} diff --git a/src/renderer/src/scene/sceneDecoding.ts b/src/renderer/src/scene/sceneDecoding.ts new file mode 100644 index 000000000..6a06858ea --- /dev/null +++ b/src/renderer/src/scene/sceneDecoding.ts @@ -0,0 +1,32 @@ +/** A block scene as the bridge encodes it (Iris SceneEncoding). */ +export interface BlockScene { + /** The block states the scene uses, once each. */ + palette: string[] + /** Four numbers per block: x, y, z from the scene's anchor, then the index of its state in the palette. */ + blocks: Int32Array + /** The lowest corner from the anchor, inclusive; {@code max} the highest, exclusive. */ + min: [number, number, number] + max: [number, number, number] +} + +interface Header { + palette: string[] + blockCount: number + min: [number, number, number] + max: [number, number, number] +} + +export const INTS_PER_BLOCK = 4 +const ALIGNMENT_BYTES = 4 + +export function decodeScene(buffer: ArrayBuffer): BlockScene { + const headerLength = new DataView(buffer).getUint32(0, true) + const header = JSON.parse(new TextDecoder().decode(new Uint8Array(buffer, 4, headerLength))) as Header + const blocksAt = Math.ceil((4 + headerLength) / ALIGNMENT_BYTES) * ALIGNMENT_BYTES + return { + palette: header.palette, + blocks: new Int32Array(buffer, blocksAt, header.blockCount * INTS_PER_BLOCK), + min: header.min, + max: header.max + } +} diff --git a/src/renderer/src/scene/sceneMesh.ts b/src/renderer/src/scene/sceneMesh.ts new file mode 100644 index 000000000..17a95dfc9 --- /dev/null +++ b/src/renderer/src/scene/sceneMesh.ts @@ -0,0 +1,137 @@ +import { BufferAttribute, BufferGeometry } from 'three' +import { cubeModel, parseState, type BlockModels, type BlockModel, type Direction, type Quad } from './blockModels' +import { blockTint } from './blockTints' +import { INTS_PER_BLOCK, type BlockScene } from './sceneDecoding' +import { TextureAtlas, type ImageSource } from './textureAtlas' + +export interface SceneMesh { + geometry: BufferGeometry + atlas: TextureAtlas + /** Block states the client has no blockstate file for, drawn as magenta and black cubes. */ + unknownStates: string[] +} + +/** The light Minecraft gives each side of a block without shadows: the top brightest, the bottom darkest. */ +const FACE_LIGHT: Record = { up: 1, down: 0.5, north: 0.8, south: 0.8, west: 0.6, east: 0.6 } +const MISSING_TEXTURE = 'iris:missing' +const NEIGHBOUR_OFFSETS: Record = { + down: [0, -1, 0], + up: [0, 1, 0], + north: [0, 0, -1], + south: [0, 0, 1], + west: [-1, 0, 0], + east: [1, 0, 0] +} +const CORNERS_PER_QUAD = 4 +const INDICES_PER_QUAD = 6 + +interface PaletteEntry { + model: BlockModel + name: string + properties: Record + /** Hides the faces of its neighbours that touch it. */ + solid: boolean +} + +/** One geometry for the whole scene, its faces against solid neighbours left out, textured from one atlas. */ +export async function buildSceneMesh(scene: BlockScene, models: BlockModels, images: ImageSource): Promise { + const resolved = await Promise.all(scene.palette.map((state) => models.model(state))) + const unknownStates = scene.palette.filter((_, index) => resolved[index] === null) + const drawn = resolved.map((model) => drawnModel(model)) + const atlas = await TextureAtlas.of( + drawn.flatMap((model) => model.quads.map((quad) => quad.texture)), + images + ) + const palette = drawn.map((model, index): PaletteEntry => { + const state = parseState(scene.palette[index]) + const solid = model.fullCube && model.quads.every((quad) => atlas.cell(quad.texture).solid) + return { model, name: state.name, properties: state.properties, solid } + }) + return { geometry: geometryOf(scene, palette, atlas), atlas, unknownStates } +} + +// The client draws chests, signs, water and the like without a block model; their break texture stands in for them. +function drawnModel(model: BlockModel | null): BlockModel { + if (model === null) { + return cubeModel(MISSING_TEXTURE) + } + if (model.quads.length === 0) { + return cubeModel(model.particle ?? MISSING_TEXTURE) + } + return model +} + +function geometryOf(scene: BlockScene, palette: PaletteEntry[], atlas: TextureAtlas): BufferGeometry { + const solids = new SolidBlocks(scene, palette) + const visible: { quad: Quad; entry: PaletteEntry; x: number; y: number; z: number }[] = [] + const blocks = scene.blocks + for (let offset = 0; offset < blocks.length; offset += INTS_PER_BLOCK) { + const [x, y, z, paletteIndex] = [blocks[offset], blocks[offset + 1], blocks[offset + 2], blocks[offset + 3]] + const entry = palette[paletteIndex] + for (const quad of entry.model.quads) { + if (quad.cullFace !== null && solids.besides(x, y, z, quad.cullFace)) { + continue + } + visible.push({ quad, entry, x, y, z }) + } + } + const positions = new Float32Array(visible.length * CORNERS_PER_QUAD * 3) + const uvs = new Float32Array(visible.length * CORNERS_PER_QUAD * 2) + const colors = new Float32Array(visible.length * CORNERS_PER_QUAD * 3) + const indices = new Uint32Array(visible.length * INDICES_PER_QUAD) + visible.forEach(({ quad, entry, x, y, z }, quadIndex) => { + const cell = atlas.cell(quad.texture) + const light = quad.shade ? FACE_LIGHT[quad.facing] : 1 + const tint = blockTint(entry.name, entry.properties, quad.tintIndex) + const [red, green, blue] = [((tint >> 16) & 0xff) / 255, ((tint >> 8) & 0xff) / 255, (tint & 0xff) / 255] + for (let corner = 0; corner < CORNERS_PER_QUAD; corner++) { + const vertex = quadIndex * CORNERS_PER_QUAD + corner + const [cornerX, cornerY, cornerZ] = quad.corners[corner] + positions.set([x + cornerX, y + cornerY, z + cornerZ], vertex * 3) + uvs.set([cell.u + quad.uvs[corner][0] * cell.width, cell.v + quad.uvs[corner][1] * cell.height], vertex * 2) + colors.set([red * light, green * light, blue * light], vertex * 3) + } + const first = quadIndex * CORNERS_PER_QUAD + indices.set([first, first + 1, first + 2, first, first + 2, first + 3], quadIndex * INDICES_PER_QUAD) + }) + const geometry = new BufferGeometry() + geometry.setAttribute('position', new BufferAttribute(positions, 3)) + geometry.setAttribute('uv', new BufferAttribute(uvs, 2)) + geometry.setAttribute('color', new BufferAttribute(colors, 3)) + geometry.setIndex(new BufferAttribute(indices, 1)) + geometry.computeBoundingSphere() + return geometry +} + +/** Which spots of the scene hold a solid block, in a grid over its bounds. */ +class SolidBlocks { + private readonly solid: Uint8Array + private readonly sizeX: number + private readonly sizeY: number + private readonly sizeZ: number + + constructor(private readonly scene: BlockScene, palette: PaletteEntry[]) { + ;[this.sizeX, this.sizeY, this.sizeZ] = [0, 1, 2].map((axis) => scene.max[axis] - scene.min[axis]) + this.solid = new Uint8Array(this.sizeX * this.sizeY * this.sizeZ) + const blocks = scene.blocks + for (let offset = 0; offset < blocks.length; offset += INTS_PER_BLOCK) { + if (palette[blocks[offset + 3]].solid) { + this.solid[this.indexOf(blocks[offset], blocks[offset + 1], blocks[offset + 2])] = 1 + } + } + } + + besides(x: number, y: number, z: number, side: Direction): boolean { + const [dx, dy, dz] = NEIGHBOUR_OFFSETS[side] + const index = this.indexOf(x + dx, y + dy, z + dz) + return index >= 0 && this.solid[index] === 1 + } + + private indexOf(x: number, y: number, z: number): number { + const [localX, localY, localZ] = [x - this.scene.min[0], y - this.scene.min[1], z - this.scene.min[2]] + if (localX < 0 || localY < 0 || localZ < 0 || localX >= this.sizeX || localY >= this.sizeY || localZ >= this.sizeZ) { + return -1 + } + return (localX * this.sizeY + localY) * this.sizeZ + localZ + } +} diff --git a/src/renderer/src/scene/textureAtlas.ts b/src/renderer/src/scene/textureAtlas.ts new file mode 100644 index 000000000..ffc8d6665 --- /dev/null +++ b/src/renderer/src/scene/textureAtlas.ts @@ -0,0 +1,105 @@ +import { CanvasTexture, NearestFilter, SRGBColorSpace } from 'three' + +/** Where block textures come from: the bridge's copy of the client's assets. */ +export interface ImageSource { + /** The PNG at {@code path} below the assets folder, or null when there is none. */ + image(path: string): Promise +} + +/** Where one texture lies in the atlas, as a rectangle of the atlas from 0 to 1. */ +export interface AtlasCell { + u: number + v: number + width: number + height: number + /** Whether every pixel is fully opaque, so a block made of it hides its neighbours' faces. */ + solid: boolean +} + +const CELL_PIXELS = 16 +const CELLS_PER_ROW = 32 +const OPAQUE_ALPHA = 255 +const MISSING_TEXTURE_COLORS = ['#f800f8', '#000000'] + +/** + * The block textures of one scene in one image, each scaled to 16 pixels; an animated texture shows its first frame, + * and a missing one Minecraft's magenta and black checks. + */ +export class TextureAtlas { + readonly texture: CanvasTexture + + private constructor( + private readonly cells: Map, + canvas: HTMLCanvasElement + ) { + this.texture = new CanvasTexture(canvas) + this.texture.magFilter = NearestFilter + this.texture.minFilter = NearestFilter + this.texture.generateMipmaps = false + this.texture.flipY = false + this.texture.colorSpace = SRGBColorSpace + } + + static async of(textureIds: string[], images: ImageSource): Promise { + const unique = [...new Set(textureIds)] + const bitmaps = await Promise.all(unique.map((id) => images.image(texturePath(id)).catch(() => null))) + const rows = Math.max(1, Math.ceil(unique.length / CELLS_PER_ROW)) + const canvas = document.createElement('canvas') + canvas.width = CELLS_PER_ROW * CELL_PIXELS + canvas.height = rows * CELL_PIXELS + const drawing = canvas.getContext('2d', { willReadFrequently: true })! + drawing.imageSmoothingEnabled = false + const cells = new Map() + unique.forEach((id, index) => { + const left = (index % CELLS_PER_ROW) * CELL_PIXELS + const top = Math.floor(index / CELLS_PER_ROW) * CELL_PIXELS + const bitmap = bitmaps[index] + if (bitmap === null) { + drawMissing(drawing, left, top) + } else { + drawing.drawImage(bitmap, 0, 0, bitmap.width, Math.min(bitmap.width, bitmap.height), left, top, CELL_PIXELS, CELL_PIXELS) + } + cells.set(id, { + u: left / canvas.width, + v: top / canvas.height, + width: CELL_PIXELS / canvas.width, + height: CELL_PIXELS / canvas.height, + solid: isSolid(drawing.getImageData(left, top, CELL_PIXELS, CELL_PIXELS).data) + }) + }) + return new TextureAtlas(cells, canvas) + } + + cell(textureId: string): AtlasCell { + return this.cells.get(textureId)! + } + + dispose(): void { + this.texture.dispose() + } +} + +/** {@code minecraft:block/stone} lies at {@code minecraft/textures/block/stone.png}. */ +function texturePath(textureId: string): string { + const colon = textureId.indexOf(':') + return `${textureId.slice(0, colon)}/textures/${textureId.slice(colon + 1)}.png` +} + +function drawMissing(drawing: CanvasRenderingContext2D, left: number, top: number): void { + const half = CELL_PIXELS / 2 + for (let quarter = 0; quarter < 4; quarter++) { + const column = quarter % 2 + const row = Math.floor(quarter / 2) + drawing.fillStyle = MISSING_TEXTURE_COLORS[(column + row) % 2] + drawing.fillRect(left + column * half, top + row * half, half, half) + } +} + +function isSolid(pixels: Uint8ClampedArray): boolean { + for (let alpha = 3; alpha < pixels.length; alpha += 4) { + if (pixels[alpha] < OPAQUE_ALPHA) { + return false + } + } + return true +} diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx index 4ac806c69..a979b380e 100644 --- a/src/renderer/src/studio/MapStudio.tsx +++ b/src/renderer/src/studio/MapStudio.tsx @@ -1,7 +1,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import type { ThemeChoice } from '../../../shared/bridge' import type { BridgeClient, MapLayerQuery, WorldRect } from '../bridge/BridgeClient' -import type { MapHover, MapLabel, Marker, PickDisplay, PickInspection, WorldInfo } from '../bridge/types' +import type { MapHover, MapLabel, Marker, PickDisplay, PickInspection, SceneViewInfo, ViewInfo, WorldInfo } from '../bridge/types' import type { Share } from '../map/census' import type { MapController, MapStatus, MapToggles } from '../map/MapController' import type { Highlight } from '../map/tileStyle' @@ -11,6 +11,7 @@ import { Legend } from './Legend' import { MapCanvas, type CanvasPoint } from './MapCanvas' import { PickInspector } from './PickInspector' import { RegionPreviewList } from './RegionPreviewList' +import { SceneStudio } from './SceneStudio' import { actionForKey, viewForKey, type ShortcutAction } from './shortcuts' import { StatusBar } from './StatusBar' import { StudioToolbar } from './StudioToolbar' @@ -56,7 +57,11 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps const [pickDisplay, setPickDisplay] = useState('picks') const [area, setArea] = useState(null) const [packRevision, setPackRevision] = useState(0) - const view = world.views.find((candidate) => candidate.id === viewId) ?? world.views[0] + const [sceneSummary, setSceneSummary] = useState(null) + const sceneViews = useSceneViews(client, packRevision) + const views = useMemo(() => [...world.views, ...sceneViews.map(asViewInfo)], [world.views, sceneViews]) + const sceneView = sceneViews.find((candidate) => candidate.id === viewId) ?? null + const view = views.find((candidate) => candidate.id === viewId) ?? views[0] const layer = useMemo(() => ({ view: viewId, preview: viewId === 'regions' ? preview : null }), [viewId, preview]) const regions = usePreviewableRegions(client, packRevision) const inspectsPicks = PICK_VIEWS.has(viewId) @@ -115,7 +120,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps const map = controller.current switch (action) { case 'nextView': - selectView(world.views[(world.views.findIndex((candidate) => candidate.id === viewId) + 1) % world.views.length].id) + selectView(views[(views.findIndex((candidate) => candidate.id === viewId) + 1) % views.length].id) return case 'refresh': map?.refresh() @@ -155,7 +160,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps setHelpOpen((open) => !open) } }, - [world.views, viewId, selectView, toggle, highlightUnderCursor, tell] + [views, viewId, selectView, toggle, highlightUnderCursor, tell] ) useKeyboard(runShortcut, selectView, setDetailed, world) @@ -195,6 +200,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps world={world} toggles={toggles} hasPlayers={world.hasPlayers} + mapTools={sceneView === null} theme={theme} onToggle={toggle} onRefresh={() => runShortcut('refresh')} @@ -203,9 +209,13 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps onDisconnect={onDisconnect} />
- + {viewId === 'regions' && regions.length > 1 && } + {sceneView !== null ? ( + + ) : ( + <>
setHighlight((current) => (sameSubject(current, subject) ? null : subject))} /> + + )}
- - + +
) } +const SCENE_GROUP = { group: 'BLOCKS', groupLabel: 'Blocks' } + +function asViewInfo(view: SceneViewInfo): ViewInfo { + return { ...view, ...SCENE_GROUP } +} + +function statusLabel(viewLabel: string, previewName: string | null, sceneSummary: string | null): string { + const detail = sceneSummary ?? previewName + return detail === null ? viewLabel : `${viewLabel} · ${detail}` +} + +/** The scene views the pack's modules show, read again after the pack reloads. */ +function useSceneViews(client: BridgeClient, packRevision: number): SceneViewInfo[] { + const [views, setViews] = useState([]) + useEffect(() => { + let active = true + client + .sceneViews() + .then((found) => active && setViews(found)) + .catch(() => undefined) + return () => { + active = false + } + }, [client, packRevision]) + return views +} + function sameSubject(first: Highlight | null, second: Highlight | null): boolean { return first !== null && second !== null && first.kind === second.kind && first.key === second.key } diff --git a/src/renderer/src/studio/SceneStudio.tsx b/src/renderer/src/studio/SceneStudio.tsx new file mode 100644 index 000000000..5d44dbcda --- /dev/null +++ b/src/renderer/src/studio/SceneStudio.tsx @@ -0,0 +1,219 @@ +import { useEffect, useMemo, useState } from 'react' +import { Input } from '@/components/ui/input' +import { ScrollArea } from '@/components/ui/scroll-area' +import { cn } from '@/lib/utils' +import type { BridgeClient } from '../bridge/BridgeClient' +import type { SceneEntry, SceneViewInfo } from '../bridge/types' +import { BlockModels } from '../scene/blockModels' +import { BridgeAssets } from '../scene/BridgeAssets' +import { INTS_PER_BLOCK, type BlockScene } from '../scene/sceneDecoding' +import { buildSceneMesh, type SceneMesh } from '../scene/sceneMesh' +import { SceneViewport } from './SceneViewport' + +const NUMBER = new Intl.NumberFormat('en-US') +const DEFAULT_NAMESPACE_PREFIX = 'minecraft:' + +interface SceneStudioProps { + client: BridgeClient + view: SceneViewInfo + /** Changes when the pack reloads, so the entries and the scene are read again. */ + packRevision: number + /** What the status bar says about the scene, or null while none is shown. */ + onSummary(summary: string | null): void + tell(message: string): void +} + +/** A scene view: its entries on the right, the chosen one in 3D in the middle, with the blocks it is made of. */ +export function SceneStudio({ client, view, packRevision, onSummary, tell }: SceneStudioProps): React.JSX.Element { + const [waiting, setWaiting] = useState(null) + const images = useMemo(() => new BridgeAssets(client, setWaiting), [client]) + const models = useMemo(() => new BlockModels(images), [images]) + const entries = useSceneEntries(client, view.id, packRevision, tell) + const [chosen, setChosen] = useState(null) + const entry = entries.find((candidate) => candidate.key === chosen) ?? entries[0] ?? null + const { scene, mesh, building } = useSceneMesh(client, view.id, entry, packRevision, models, images, tell) + + useEffect(() => onSummary(entry === null || scene === null ? null : summaryOf(entry, scene)), [entry, scene, onSummary]) + useEffect(() => () => onSummary(null), [onSummary]) + + return ( + <> +
+ + {building && entry !== null && ( +
+ {waiting ?? `Building ${entry.name}`} +
+ )} +
+ + + ) +} + +function summaryOf(entry: SceneEntry, scene: BlockScene): string { + const [width, height, depth] = [0, 1, 2].map((axis) => scene.max[axis] - scene.min[axis]) + const blocks = scene.blocks.length / INTS_PER_BLOCK + return `${entry.key} · ${NUMBER.format(blocks)} blocks · ${width} × ${height} × ${depth}` +} + +function useSceneEntries(client: BridgeClient, viewId: string, packRevision: number, tell: (message: string) => void): SceneEntry[] { + const [entries, setEntries] = useState([]) + useEffect(() => { + let active = true + client + .sceneEntries(viewId) + .then((found) => active && setEntries(found)) + .catch((failure: Error) => active && tell(failure.message)) + return () => { + active = false + } + }, [client, viewId, packRevision, tell]) + return entries +} + +/** The chosen entry's scene and its mesh; a newer choice abandons an older one, and a replaced mesh is freed. */ +function useSceneMesh( + client: BridgeClient, + viewId: string, + entry: SceneEntry | null, + packRevision: number, + models: BlockModels, + images: BridgeAssets, + tell: (message: string) => void +): { scene: BlockScene | null; mesh: SceneMesh | null; building: boolean } { + const [scene, setScene] = useState(null) + const [mesh, setMesh] = useState(null) + const [building, setBuilding] = useState(false) + const key = entry?.key ?? null + + useEffect(() => { + if (key === null) { + return + } + const stop = new AbortController() + setBuilding(true) + client + .scene(viewId, key, 0, stop.signal) + .then(async (found) => { + const built = await buildSceneMesh(found, models, images) + if (stop.signal.aborted) { + disposeMesh(built) + return + } + setScene(found) + setMesh(built) + if (built.unknownStates.length > 0) { + tell(`No model for ${built.unknownStates.length === 1 ? built.unknownStates[0] : `${built.unknownStates.length} block states`}`) + } + }) + .catch((failure: Error) => !stop.signal.aborted && tell(failure.message)) + .finally(() => !stop.signal.aborted && setBuilding(false)) + return () => stop.abort() + }, [client, viewId, key, packRevision, models, images, tell]) + + useEffect(() => () => disposeMesh(mesh), [mesh]) + + return { scene, mesh, building } +} + +function disposeMesh(mesh: SceneMesh | null): void { + mesh?.geometry.dispose() + mesh?.atlas.dispose() +} + +interface EntryBrowserProps { + title: string + entries: SceneEntry[] + current: string | null + onSelect(key: string): void +} + +/** The view's entries under their folders, with a search over names and folders (v3e ObjectBrowser). */ +function EntryBrowser({ title, entries, current, onSelect }: EntryBrowserProps): React.JSX.Element { + const [search, setSearch] = useState('') + const wanted = search.trim().toLowerCase() + const groups = useMemo(() => groupedEntries(entries, wanted), [entries, wanted]) + return ( +
+
+

{title}

+

{NUMBER.format(entries.length)} in the pack

+ setSearch(event.target.value)} + onKeyDown={(event) => event.key === 'Escape' && setSearch('')} + /> +
+ +
+ {groups.map(([group, members]) => ( +
+ {group !== '' &&

{group}

} + {members.map((entry) => ( + + ))} +
+ ))} + {groups.length === 0 &&

{entries.length === 0 ? 'Nothing to show' : 'Nothing matches'}

} +
+
+
+ ) +} + +function groupedEntries(entries: SceneEntry[], wanted: string): [string, SceneEntry[]][] { + const groups = new Map() + for (const entry of entries) { + if (wanted !== '' && !entry.key.toLowerCase().includes(wanted)) { + continue + } + const members = groups.get(entry.group) ?? [] + members.push(entry) + groups.set(entry.group, members) + } + return [...groups.entries()] +} + +/** The blocks of the scene, most used first, each with its count (v3e ObjectOverviewPanel). */ +function BlockList({ scene }: { scene: BlockScene | null }): React.JSX.Element { + const counts = useMemo(() => (scene === null ? [] : blockCounts(scene)), [scene]) + return ( +
+

Blocks

+ +
+ {counts.map(([state, count]) => ( +
+ {state.replace(DEFAULT_NAMESPACE_PREFIX, '')} + {NUMBER.format(count)} +
+ ))} +
+
+
+ ) +} + +// Block states that differ only in how they face count as one block, as a builder reads the list. +function blockCounts(scene: BlockScene): [string, number][] { + const counts = new Map() + for (let offset = 3; offset < scene.blocks.length; offset += INTS_PER_BLOCK) { + const state = scene.palette[scene.blocks[offset]] + const material = state.includes('[') ? state.slice(0, state.indexOf('[')) : state + counts.set(material, (counts.get(material) ?? 0) + 1) + } + return [...counts.entries()].sort((first, second) => second[1] - first[1]) +} diff --git a/src/renderer/src/studio/SceneViewport.tsx b/src/renderer/src/studio/SceneViewport.tsx new file mode 100644 index 000000000..7f8ef3764 --- /dev/null +++ b/src/renderer/src/studio/SceneViewport.tsx @@ -0,0 +1,122 @@ +import { useEffect, useRef } from 'react' +import { Box3, Mesh, MeshBasicMaterial, PerspectiveCamera, Scene, Sphere, Vector3, WebGLRenderer } from 'three' +import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js' +import type { SceneMesh } from '../scene/sceneMesh' + +const FIELD_OF_VIEW_DEGREES = 45 +// Looking down at the scene from the south east, as v3e's object view opens. +const VIEW_DIRECTION = new Vector3(1, 0.8, 1.2).normalize() +const FRAMING_MARGIN = 1.15 +const NEAREST_CLIP = 0.05 +const CUTOUT_ALPHA = 0.1 + +interface SceneViewportProps { + mesh: SceneMesh | null +} + +/** A block scene in 3D: drag to turn around it, right drag to move, scroll to come closer. Drawn only when it changes. */ +export function SceneViewport({ mesh }: SceneViewportProps): React.JSX.Element { + const host = useRef(null) + const stage = useRef(null) + + useEffect(() => { + const created = new Stage(host.current!) + stage.current = created + return () => { + created.dispose() + stage.current = null + } + }, []) + + useEffect(() => stage.current?.show(mesh), [mesh]) + + return
+} + +/** The renderer, camera and controls of one viewport. */ +class Stage { + private readonly renderer = new WebGLRenderer({ antialias: true, alpha: true }) + private readonly camera = new PerspectiveCamera(FIELD_OF_VIEW_DEGREES, 1, NEAREST_CLIP, 10_000) + private readonly scene = new Scene() + private readonly controls: OrbitControls + private readonly resizes: ResizeObserver + private shown: Mesh | null = null + private frameRequested = false + + constructor(private readonly host: HTMLDivElement) { + this.renderer.setPixelRatio(window.devicePixelRatio) + this.renderer.setClearAlpha(0) + host.appendChild(this.renderer.domElement) + this.controls = new OrbitControls(this.camera, this.renderer.domElement) + this.controls.enableDamping = true + this.controls.addEventListener('change', () => this.requestFrame()) + this.resizes = new ResizeObserver(() => this.fitToHost()) + this.resizes.observe(host) + this.fitToHost() + } + + show(mesh: SceneMesh | null): void { + this.removeShown() + if (mesh === null) { + this.requestFrame() + return + } + const material = new MeshBasicMaterial({ map: mesh.atlas.texture, vertexColors: true, alphaTest: CUTOUT_ALPHA }) + this.shown = new Mesh(mesh.geometry, material) + this.scene.add(this.shown) + this.frame(new Box3().setFromBufferAttribute(mesh.geometry.getAttribute('position') as never)) + this.requestFrame() + } + + dispose(): void { + this.removeShown() + this.resizes.disconnect() + this.controls.dispose() + this.renderer.dispose() + this.renderer.domElement.remove() + } + + private frame(bounds: Box3): void { + const sphere = bounds.isEmpty() ? new Sphere(new Vector3(), 1) : bounds.getBoundingSphere(new Sphere()) + const halfVertical = (FIELD_OF_VIEW_DEGREES * Math.PI) / 360 + const halfHorizontal = Math.atan(Math.tan(halfVertical) * this.camera.aspect) + const distance = (sphere.radius * FRAMING_MARGIN) / Math.sin(Math.min(halfVertical, halfHorizontal)) + this.controls.target.copy(sphere.center) + this.camera.position.copy(sphere.center).addScaledVector(VIEW_DIRECTION, distance) + this.camera.far = distance * 10 + sphere.radius * 4 + this.camera.updateProjectionMatrix() + this.controls.update() + } + + // The mesh and its atlas belong to whoever built them; only the material is the viewport's. + private removeShown(): void { + if (this.shown === null) { + return + } + this.scene.remove(this.shown) + ;(this.shown.material as MeshBasicMaterial).dispose() + this.shown = null + } + + private fitToHost(): void { + const width = Math.max(1, this.host.clientWidth) + const height = Math.max(1, this.host.clientHeight) + this.renderer.setSize(width, height) + this.camera.aspect = width / height + this.camera.updateProjectionMatrix() + this.requestFrame() + } + + private requestFrame(): void { + if (this.frameRequested) { + return + } + this.frameRequested = true + requestAnimationFrame(() => { + this.frameRequested = false + // Damping keeps turning the camera for a moment after a drag, and asks for frames until it stops. + this.controls.update() + this.renderer.render(this.scene, this.camera) + }) + } +} diff --git a/src/renderer/src/studio/StudioToolbar.tsx b/src/renderer/src/studio/StudioToolbar.tsx index 386013f42..a14590184 100644 --- a/src/renderer/src/studio/StudioToolbar.tsx +++ b/src/renderer/src/studio/StudioToolbar.tsx @@ -15,6 +15,8 @@ interface StudioToolbarProps { world: WorldInfo toggles: StudioToggles hasPlayers: boolean + /** Whether the map's buttons apply: a scene view has no map to redraw, zoom or overlay. */ + mapTools: boolean theme: { choice: ThemeChoice; next: () => void } onToggle(name: keyof StudioToggles): void onRefresh(): void @@ -27,10 +29,36 @@ const THEME_ICONS: Record = { system: , light const THEME_NAMES: Record = { system: 'Theme: system', light: 'Theme: light', dark: 'Theme: dark' } export function StudioToolbar(props: StudioToolbarProps): React.JSX.Element { - const { toggles, onToggle } = props return (
{props.title} + {props.mapTools && } + +
+ + {props.world.world} + + + + + + + + + + +
+ ) +} + +function MapTools(props: StudioToolbarProps): React.JSX.Element { + const { toggles, onToggle } = props + return ( + <> @@ -53,25 +81,7 @@ export function StudioToolbar(props: StudioToolbarProps): React.JSX.Element { onToggle('regionBorders')}> Borders - -
- - {props.world.world} - - - - - - - - - - - + ) } diff --git a/src/renderer/src/studio/ViewList.tsx b/src/renderer/src/studio/ViewList.tsx index 362e0e074..001416f8d 100644 --- a/src/renderer/src/studio/ViewList.tsx +++ b/src/renderer/src/studio/ViewList.tsx @@ -1,4 +1,4 @@ -import { Gem, Map as MapIcon, Mountain, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' +import { Box, Gem, Map as MapIcon, Mountain, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' import { Kbd } from '@/components/ui/kbd' import { ScrollArea } from '@/components/ui/scroll-area' import { cn } from '@/lib/utils' @@ -11,7 +11,8 @@ const VIEW_ICONS: Record = { height: Mountain, landBiomes: Sprout, seaBiomes: Waves, - caveBiomes: Gem + caveBiomes: Gem, + 'iris:objects': Box } interface ViewListProps { From 0732f5a9b86de083c2cbfc72ed97bbfcfa9e60cc Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 01:28:44 +0100 Subject: [PATCH 05/12] Scene views: step through an entry's variants --- src/renderer/src/studio/SceneStudio.tsx | 34 ++++++++++++++++++++----- src/renderer/src/studio/ViewList.tsx | 5 ++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/studio/SceneStudio.tsx b/src/renderer/src/studio/SceneStudio.tsx index 5d44dbcda..6cfeefaa3 100644 --- a/src/renderer/src/studio/SceneStudio.tsx +++ b/src/renderer/src/studio/SceneStudio.tsx @@ -1,4 +1,6 @@ +import { ChevronLeft, ChevronRight } from 'lucide-react' import { useEffect, useMemo, useState } from 'react' +import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { ScrollArea } from '@/components/ui/scroll-area' import { cn } from '@/lib/utils' @@ -29,9 +31,15 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce const images = useMemo(() => new BridgeAssets(client, setWaiting), [client]) const models = useMemo(() => new BlockModels(images), [images]) const entries = useSceneEntries(client, view.id, packRevision, tell) - const [chosen, setChosen] = useState(null) - const entry = entries.find((candidate) => candidate.key === chosen) ?? entries[0] ?? null - const { scene, mesh, building } = useSceneMesh(client, view.id, entry, packRevision, models, images, tell) + const [chosen, setChosen] = useState<{ key: string; variant: number } | null>(null) + const entry = entries.find((candidate) => candidate.key === chosen?.key) ?? entries[0] ?? null + const variant = entry !== null && chosen?.key === entry.key ? Math.min(chosen.variant, entry.variants - 1) : 0 + const { scene, mesh, building } = useSceneMesh(client, view.id, entry, variant, packRevision, models, images, tell) + const chooseVariant = (next: number): void => { + if (entry !== null) { + setChosen({ key: entry.key, variant: (next + entry.variants) % entry.variants }) + } + } useEffect(() => onSummary(entry === null || scene === null ? null : summaryOf(entry, scene)), [entry, scene, onSummary]) useEffect(() => () => onSummary(null), [onSummary]) @@ -40,6 +48,19 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce <>
+ {entry !== null && entry.variants > 1 && ( +
+ + + Variant {variant + 1} of {entry.variants} + + +
+ )} {building && entry !== null && (
{waiting ?? `Building ${entry.name}`} @@ -47,7 +68,7 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce )}
@@ -80,6 +101,7 @@ function useSceneMesh( client: BridgeClient, viewId: string, entry: SceneEntry | null, + variant: number, packRevision: number, models: BlockModels, images: BridgeAssets, @@ -97,7 +119,7 @@ function useSceneMesh( const stop = new AbortController() setBuilding(true) client - .scene(viewId, key, 0, stop.signal) + .scene(viewId, key, variant, stop.signal) .then(async (found) => { const built = await buildSceneMesh(found, models, images) if (stop.signal.aborted) { @@ -113,7 +135,7 @@ function useSceneMesh( .catch((failure: Error) => !stop.signal.aborted && tell(failure.message)) .finally(() => !stop.signal.aborted && setBuilding(false)) return () => stop.abort() - }, [client, viewId, key, packRevision, models, images, tell]) + }, [client, viewId, key, variant, packRevision, models, images, tell]) useEffect(() => () => disposeMesh(mesh), [mesh]) diff --git a/src/renderer/src/studio/ViewList.tsx b/src/renderer/src/studio/ViewList.tsx index 001416f8d..e4dbf7e50 100644 --- a/src/renderer/src/studio/ViewList.tsx +++ b/src/renderer/src/studio/ViewList.tsx @@ -1,4 +1,4 @@ -import { Box, Gem, Map as MapIcon, Mountain, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' +import { Box, Gem, Map as MapIcon, Mountain, Shapes, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' import { Kbd } from '@/components/ui/kbd' import { ScrollArea } from '@/components/ui/scroll-area' import { cn } from '@/lib/utils' @@ -12,7 +12,8 @@ const VIEW_ICONS: Record = { landBiomes: Sprout, seaBiomes: Waves, caveBiomes: Gem, - 'iris:objects': Box + 'iris:objects': Box, + 'iris:objects/procedural': Shapes } interface ViewListProps { From 874cb4fe161ce7b2e683fe47fe6ff5032651a5c5 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 01:36:59 +0100 Subject: [PATCH 06/12] Add the 3D world view The terrain around where the map last looked, 1,024 blocks square, in 3D: one vertex per map pixel from the biome tiles with heights, coloured by biome, region or height, lit by slope. Walls round the rim and a see-through sea at fluid height make the square read as a solid block. The viewport now takes content with its own bounds and frames again when told to, so the scene views and the 3D world share it. The near clip follows the orbit distance, so surfaces a block apart no longer flicker when the camera is far away. --- src/renderer/src/scene/sceneMesh.ts | 23 ++- src/renderer/src/scene/terrainMesh.ts | 199 ++++++++++++++++++++++ src/renderer/src/studio/MapStudio.tsx | 23 ++- src/renderer/src/studio/SceneStudio.tsx | 5 +- src/renderer/src/studio/SceneViewport.tsx | 92 ++++++---- src/renderer/src/studio/ViewList.tsx | 3 +- src/renderer/src/studio/WorldStudio3D.tsx | 109 ++++++++++++ 7 files changed, 406 insertions(+), 48 deletions(-) create mode 100644 src/renderer/src/scene/terrainMesh.ts create mode 100644 src/renderer/src/studio/WorldStudio3D.tsx diff --git a/src/renderer/src/scene/sceneMesh.ts b/src/renderer/src/scene/sceneMesh.ts index 17a95dfc9..07fd89746 100644 --- a/src/renderer/src/scene/sceneMesh.ts +++ b/src/renderer/src/scene/sceneMesh.ts @@ -1,16 +1,20 @@ -import { BufferAttribute, BufferGeometry } from 'three' +import { Box3, BufferAttribute, BufferGeometry, Mesh, MeshBasicMaterial } from 'three' +import type { ViewportContent } from '../studio/SceneViewport' import { cubeModel, parseState, type BlockModels, type BlockModel, type Direction, type Quad } from './blockModels' import { blockTint } from './blockTints' import { INTS_PER_BLOCK, type BlockScene } from './sceneDecoding' import { TextureAtlas, type ImageSource } from './textureAtlas' export interface SceneMesh { - geometry: BufferGeometry - atlas: TextureAtlas + content: ViewportContent /** Block states the client has no blockstate file for, drawn as magenta and black cubes. */ unknownStates: string[] + /** Frees the mesh's geometry, material and atlas. */ + dispose(): void } +const CUTOUT_ALPHA = 0.1 + /** The light Minecraft gives each side of a block without shadows: the top brightest, the bottom darkest. */ const FACE_LIGHT: Record = { up: 1, down: 0.5, north: 0.8, south: 0.8, west: 0.6, east: 0.6 } const MISSING_TEXTURE = 'iris:missing' @@ -47,7 +51,18 @@ export async function buildSceneMesh(scene: BlockScene, models: BlockModels, ima const solid = model.fullCube && model.quads.every((quad) => atlas.cell(quad.texture).solid) return { model, name: state.name, properties: state.properties, solid } }) - return { geometry: geometryOf(scene, palette, atlas), atlas, unknownStates } + const geometry = geometryOf(scene, palette, atlas) + const material = new MeshBasicMaterial({ map: atlas.texture, vertexColors: true, alphaTest: CUTOUT_ALPHA }) + const bounds = new Box3().setFromBufferAttribute(geometry.getAttribute('position') as BufferAttribute) + return { + content: { object: new Mesh(geometry, material), bounds }, + unknownStates, + dispose: () => { + geometry.dispose() + material.dispose() + atlas.dispose() + } + } } // The client draws chests, signs, water and the like without a block model; their break texture stands in for them. diff --git a/src/renderer/src/scene/terrainMesh.ts b/src/renderer/src/scene/terrainMesh.ts new file mode 100644 index 000000000..175b3cbaa --- /dev/null +++ b/src/renderer/src/scene/terrainMesh.ts @@ -0,0 +1,199 @@ +import { Box3, BufferAttribute, BufferGeometry, DoubleSide, Group, Mesh, MeshBasicMaterial, PlaneGeometry, Vector3 } from 'three' +import { NO_LABEL, type MapTile } from '../bridge/types' +import { heightColor } from '../map/heightColors' +import type { ViewportContent } from '../studio/SceneViewport' + +export type TerrainColoring = 'biomes' | 'regions' | 'height' + +/** A square of map tiles with heights, row by row from the north west. */ +export interface TerrainArea { + tiles: MapTile[][] + /** The world spot of the first tile's first pixel. */ + originX: number + originZ: number +} + +export interface TerrainMesh { + content: ViewportContent + dispose(): void +} + +const WATER_COLOR = 0x3f76e4 +const WATER_OPACITY = 0.55 +const UNLABELLED_COLOR = 0x5a5f6b +// Light from high in the south west, so slopes read as relief; the darkest side keeps some light. +const LIGHT = new Vector3(-0.6, 1, 0.4).normalize() +const AMBIENT_LIGHT = 0.5 +const WALL_DEPTH_BLOCKS = 8 +const WALL_TOP_LIGHT = 0.55 +const WALL_BASE_LIGHT = 0.25 +const SEA_INSET_BLOCKS = 0.05 + +/** The terrain of the area, one vertex per map pixel, with the dimension's sea as a sheet of water at fluid height. */ +export function buildTerrainMesh(area: TerrainArea, coloring: TerrainColoring, fluidHeight: number): TerrainMesh { + const grid = TerrainGrid.of(area) + const terrain = terrainGeometry(grid, coloring, fluidHeight) + const base = Math.min(grid.lowestHeight(), fluidHeight) - WALL_DEPTH_BLOCKS + const landWalls = rimWall(grid, terrain, (ground) => ground, () => base) + const seaWalls = rimWall(grid, terrain, () => fluidHeight, (ground) => Math.min(ground, fluidHeight)) + const terrainMaterial = new MeshBasicMaterial({ vertexColors: true, side: DoubleSide }) + const sea = seaSurface(grid, fluidHeight) + const waterMaterial = new MeshBasicMaterial({ color: WATER_COLOR, transparent: true, opacity: WATER_OPACITY, depthWrite: false, side: DoubleSide }) + const group = new Group() + group.add(new Mesh(terrain, terrainMaterial), new Mesh(landWalls, terrainMaterial), new Mesh(sea, waterMaterial), new Mesh(seaWalls, waterMaterial)) + const geometries = [terrain, landWalls, sea, seaWalls] + return { + content: { object: group, bounds: new Box3().setFromObject(group) }, + dispose: () => { + geometries.forEach((geometry) => geometry.dispose()) + terrainMaterial.dispose() + waterMaterial.dispose() + } + } +} + +// Kept a little inside the walls, so its edge does not flicker against them. +function seaSurface(grid: TerrainGrid, fluidHeight: number): BufferGeometry { + const sea = new PlaneGeometry(grid.spanX - 2 * SEA_INSET_BLOCKS, grid.spanZ - 2 * SEA_INSET_BLOCKS).rotateX(-Math.PI / 2) + return sea.translate(grid.worldX(0) + grid.spanX / 2, fluidHeight, grid.worldZ(0) + grid.spanZ / 2) +} + +/** + * A wall round the terrain's rim, from {@code topAt} down to {@code bottomAt} of the ground height at each rim vertex; + * in the terrain's colour, darkening downwards, for a material that uses vertex colours. + */ +function rimWall(grid: TerrainGrid, terrain: BufferGeometry, topAt: (ground: number) => number, bottomAt: (ground: number) => number): BufferGeometry { + const rim = grid.rimVertices() + const surface = terrain.getAttribute('position') + const shade = terrain.getAttribute('color') + const positions = new Float32Array(rim.length * 2 * 3) + const colors = new Float32Array(rim.length * 2 * 3) + rim.forEach((vertex, index) => { + const [x, ground, z] = [surface.getX(vertex), surface.getY(vertex), surface.getZ(vertex)] + positions.set([x, topAt(ground), z, x, bottomAt(ground), z], index * 6) + const [red, green, blue] = [shade.getX(vertex), shade.getY(vertex), shade.getZ(vertex)] + colors.set([red * WALL_TOP_LIGHT, green * WALL_TOP_LIGHT, blue * WALL_TOP_LIGHT], index * 6) + colors.set([red * WALL_BASE_LIGHT, green * WALL_BASE_LIGHT, blue * WALL_BASE_LIGHT], index * 6 + 3) + }) + const indices: number[] = [] + for (let index = 0; index < rim.length; index++) { + const next = (index + 1) % rim.length + const [upper, lower, nextUpper, nextLower] = [index * 2, index * 2 + 1, next * 2, next * 2 + 1] + indices.push(upper, lower, nextUpper, nextUpper, lower, nextLower) + } + const geometry = new BufferGeometry() + geometry.setAttribute('position', new BufferAttribute(positions, 3)) + geometry.setAttribute('color', new BufferAttribute(colors, 3)) + geometry.setIndex(indices) + return geometry +} + +function terrainGeometry(grid: TerrainGrid, coloring: TerrainColoring, fluidHeight: number): BufferGeometry { + const { columns, rows } = grid + const positions = new Float32Array(columns * rows * 3) + const colors = new Float32Array(columns * rows * 3) + for (let row = 0; row < rows; row++) { + for (let column = 0; column < columns; column++) { + const vertex = row * columns + column + const height = grid.height(column, row) + positions.set([grid.worldX(column), height, grid.worldZ(row)], vertex * 3) + const color = coloring === 'height' ? heightColor(height, fluidHeight) : grid.labelColor(column, row, coloring) + const light = AMBIENT_LIGHT + (1 - AMBIENT_LIGHT) * Math.max(0, grid.normal(column, row).dot(LIGHT)) + colors.set([(((color >> 16) & 0xff) / 255) * light, (((color >> 8) & 0xff) / 255) * light, ((color & 0xff) / 255) * light], vertex * 3) + } + } + const indices = new Uint32Array((columns - 1) * (rows - 1) * 6) + let next = 0 + for (let row = 0; row < rows - 1; row++) { + for (let column = 0; column < columns - 1; column++) { + const northWest = row * columns + column + const southWest = northWest + columns + indices.set([northWest, southWest, northWest + 1, northWest + 1, southWest, southWest + 1], next) + next += 6 + } + } + const geometry = new BufferGeometry() + geometry.setAttribute('position', new BufferAttribute(positions, 3)) + geometry.setAttribute('color', new BufferAttribute(colors, 3)) + geometry.setIndex(new BufferAttribute(indices, 1)) + return geometry +} + +/** The area's tiles as one grid of pixels, without the ring each tile carries for its neighbours. */ +class TerrainGrid { + readonly columns: number + readonly rows: number + /** How far the vertices reach, west to east and north to south, in blocks. */ + readonly spanX: number + readonly spanZ: number + private readonly size: number + private readonly blocksPerPixel: number + + private constructor(private readonly area: TerrainArea) { + const first = area.tiles[0][0] + this.size = first.size + this.blocksPerPixel = first.blocksPerPixel + this.columns = area.tiles[0].length * this.size + this.rows = area.tiles.length * this.size + this.spanX = (this.columns - 1) * this.blocksPerPixel + this.spanZ = (this.rows - 1) * this.blocksPerPixel + } + + static of(area: TerrainArea): TerrainGrid { + return new TerrainGrid(area) + } + + worldX(column: number): number { + return this.area.originX + column * this.blocksPerPixel + } + + worldZ(row: number): number { + return this.area.originZ + row * this.blocksPerPixel + } + + height(column: number, row: number): number { + const { tile, cell } = this.cellAt(column, row) + return tile.heights![cell] + } + + labelColor(column: number, row: number, coloring: 'biomes' | 'regions'): number { + const { tile, cell } = this.cellAt(column, row) + const index = coloring === 'regions' ? tile.regions[cell] : tile.subjects[cell] + return index === NO_LABEL ? UNLABELLED_COLOR : tile.labels[index].color + } + + lowestHeight(): number { + let lowest = Infinity + for (let row = 0; row < this.rows; row++) { + for (let column = 0; column < this.columns; column++) { + lowest = Math.min(lowest, this.height(column, row)) + } + } + return lowest + } + + /** The vertices on the edge of the grid, once each, going round clockwise from the north west corner. */ + rimVertices(): number[] { + const { columns, rows } = this + const rim: number[] = [] + for (let column = 0; column < columns - 1; column++) rim.push(column) + for (let row = 0; row < rows - 1; row++) rim.push(row * columns + columns - 1) + for (let column = columns - 1; column > 0; column--) rim.push((rows - 1) * columns + column) + for (let row = rows - 1; row > 0; row--) rim.push(row * columns) + return rim + } + + normal(column: number, row: number): Vector3 { + const west = this.height(Math.max(0, column - 1), row) + const east = this.height(Math.min(this.columns - 1, column + 1), row) + const north = this.height(column, Math.max(0, row - 1)) + const south = this.height(column, Math.min(this.rows - 1, row + 1)) + return new Vector3(west - east, 2 * this.blocksPerPixel, north - south).normalize() + } + + private cellAt(column: number, row: number): { tile: MapTile; cell: number } { + const tile = this.area.tiles[Math.floor(row / this.size)][Math.floor(column / this.size)] + const gridSize = this.size + 2 + return { tile, cell: ((row % this.size) + 1) * gridSize + (column % this.size) + 1 } + } +} diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx index a979b380e..a3a2e3498 100644 --- a/src/renderer/src/studio/MapStudio.tsx +++ b/src/renderer/src/studio/MapStudio.tsx @@ -12,6 +12,7 @@ import { MapCanvas, type CanvasPoint } from './MapCanvas' import { PickInspector } from './PickInspector' import { RegionPreviewList } from './RegionPreviewList' import { SceneStudio } from './SceneStudio' +import { WorldStudio3D } from './WorldStudio3D' import { actionForKey, viewForKey, type ShortcutAction } from './shortcuts' import { StatusBar } from './StatusBar' import { StudioToolbar } from './StudioToolbar' @@ -59,8 +60,9 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps const [packRevision, setPackRevision] = useState(0) const [sceneSummary, setSceneSummary] = useState(null) const sceneViews = useSceneViews(client, packRevision) - const views = useMemo(() => [...world.views, ...sceneViews.map(asViewInfo)], [world.views, sceneViews]) + const views = useMemo(() => [...withWorld3D(world.views), ...sceneViews.map(asViewInfo)], [world.views, sceneViews]) const sceneView = sceneViews.find((candidate) => candidate.id === viewId) ?? null + const showsMap = sceneView === null && viewId !== WORLD_3D.id const view = views.find((candidate) => candidate.id === viewId) ?? views[0] const layer = useMemo(() => ({ view: viewId, preview: viewId === 'regions' ? preview : null }), [viewId, preview]) const regions = usePreviewableRegions(client, packRevision) @@ -200,7 +202,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps world={world} toggles={toggles} hasPlayers={world.hasPlayers} - mapTools={sceneView === null} + mapTools={showsMap} theme={theme} onToggle={toggle} onRefresh={() => runShortcut('refresh')} @@ -214,6 +216,8 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps {sceneView !== null ? ( + ) : viewId === WORLD_3D.id ? ( + ) : ( <>
@@ -269,13 +273,26 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps )}
- +
) } const SCENE_GROUP = { group: 'BLOCKS', groupLabel: 'Blocks' } +/** The app draws the 3D world from the server's biome tiles, so the server does not list it among its views. */ +const WORLD_3D: ViewInfo = { + id: 'world3d', + label: '3D world', + description: 'The terrain in 3D, coloured by biome, region or height', + group: 'WORLD', + groupLabel: 'World' +} + +function withWorld3D(serverViews: ViewInfo[]): ViewInfo[] { + const afterHeight = serverViews.findIndex((candidate) => candidate.id === 'height') + 1 + return [...serverViews.slice(0, afterHeight), WORLD_3D, ...serverViews.slice(afterHeight)] +} function asViewInfo(view: SceneViewInfo): ViewInfo { return { ...view, ...SCENE_GROUP } diff --git a/src/renderer/src/studio/SceneStudio.tsx b/src/renderer/src/studio/SceneStudio.tsx index 6cfeefaa3..ffecd61dc 100644 --- a/src/renderer/src/studio/SceneStudio.tsx +++ b/src/renderer/src/studio/SceneStudio.tsx @@ -47,7 +47,7 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce return ( <>
- + {entry !== null && entry.variants > 1 && (
+
+ {reading && chosen !== null &&
Reading {chosen.name}
} + {!reading && chosen !== null && start === null &&
Nothing finished is saved in {chosen.name}
} +
+ + + ) +} + +function WorldList({ worlds, current, onSelect }: { worlds: SavedWorldInfo[]; current: string | null; onSelect(id: string): void }): React.JSX.Element { + const namespaces = [...new Set(worlds.map((world) => world.namespace))] + return ( +
+ {namespaces.map((namespace) => ( +
+

{namespace}

+ {worlds + .filter((world) => world.namespace === namespace) + .map((world) => ( + + ))} +
+ ))} + {worlds.length === 0 &&

Nothing to show

} +
+ ) +} + +// The studio's world folder is named after its dimension, so world_iris_procfix is saved as iris/procfix. +function ownWorldAmong(worlds: SavedWorldInfo[], world: WorldInfo): SavedWorldInfo | undefined { + return worlds.find((candidate) => world.world.endsWith(`_${candidate.name}`) || world.world === candidate.name) +} + +function useSavedWorlds(client: BridgeClient, tell: (message: string) => void): SavedWorldInfo[] { + const [worlds, setWorlds] = useState([]) + useEffect(() => { + let active = true + client + .savedWorlds() + .then((found) => active && setWorlds(found)) + .catch((failure: Error) => active && tell(failure.message)) + return () => { + active = false + } + }, [client, tell]) + return worlds +} + +/** Where the chosen world's view opens and the square of tiles around it; every tile arrives before it is shown. */ +function useSavedArea( + client: BridgeClient, + worldId: string | null, + readings: number, + tell: (message: string) => void +): { start: SavedStart | null; area: SavedTerrainArea | null; reading: boolean } { + const [start, setStart] = useState(null) + const [area, setArea] = useState(null) + const [reading, setReading] = useState(false) + useEffect(() => { + if (worldId === null) { + return + } + const stop = new AbortController() + setReading(true) + setStart(null) + setArea(null) + readSavedArea(client, worldId, stop.signal) + .then((found) => { + setStart(found?.start ?? null) + setArea(found?.area ?? null) + }) + .catch((failure: Error) => !stop.signal.aborted && tell(failure.message)) + .finally(() => !stop.signal.aborted && setReading(false)) + return () => stop.abort() + }, [client, worldId, readings, tell]) + return { start, area, reading } +} + +async function readSavedArea(client: BridgeClient, worldId: string, signal: AbortSignal): Promise<{ start: SavedStart; area: SavedTerrainArea } | null> { + let start: SavedStart + try { + start = await client.savedStart(worldId, signal) + } catch (failure) { + if (failure instanceof BridgeError && failure.status === STATUS_NOT_FOUND) { + return null + } + throw failure + } + const firstTileX = Math.floor(start.centerX / TILE_BLOCKS - TILES_PER_SIDE / 2) + const firstTileZ = Math.floor(start.centerZ / TILE_BLOCKS - TILES_PER_SIDE / 2) + const tiles: SavedTile[][] = await Promise.all( + Array.from({ length: TILES_PER_SIDE }, (_, row) => + Promise.all( + Array.from({ length: TILES_PER_SIDE }, (_, column) => + client.savedTile(worldId, firstTileX + column, firstTileZ + row, BLOCKS_PER_PIXEL, TILE_PIXELS, signal) + ) + ) + ) + ) + return { start, area: { tiles, originX: firstTileX * TILE_BLOCKS, originZ: firstTileZ * TILE_BLOCKS } } +} + +/** The colour of every block in the area, read from the client's textures, or null until they are read. */ +function useBlockColors(client: BridgeClient, area: SavedTerrainArea | null): Map | null { + const colors = useMemo(() => { + const images = new BridgeAssets(client, () => {}) + return new BlockColors(new BlockModels(images), images) + }, [client]) + const [read, setRead] = useState | null>(null) + useEffect(() => { + setRead(null) + if (area === null) { + return + } + let active = true + const blocks = area.tiles.flat().flatMap((tile) => tile.blockNames) + colors.colorsOf(blocks).then((found) => active && setRead(found)) + return () => { + active = false + } + }, [colors, area]) + return read +} diff --git a/src/renderer/src/studio/ViewList.tsx b/src/renderer/src/studio/ViewList.tsx index 505beac6b..6db760567 100644 --- a/src/renderer/src/studio/ViewList.tsx +++ b/src/renderer/src/studio/ViewList.tsx @@ -1,4 +1,4 @@ -import { Box, Gem, Globe, Map as MapIcon, Mountain, Shapes, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' +import { Box, Gem, Globe, HardDrive, Map as MapIcon, Mountain, Shapes, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' import { Kbd } from '@/components/ui/kbd' import { ScrollArea } from '@/components/ui/scroll-area' import { cn } from '@/lib/utils' @@ -10,6 +10,7 @@ const VIEW_ICONS: Record = { regions: MapIcon, height: Mountain, world3d: Globe, + savedWorld: HardDrive, landBiomes: Sprout, seaBiomes: Waves, caveBiomes: Gem, diff --git a/src/renderer/src/studio/WorldStudio3D.tsx b/src/renderer/src/studio/WorldStudio3D.tsx index 4117c5dc6..a9a5b58bc 100644 --- a/src/renderer/src/studio/WorldStudio3D.tsx +++ b/src/renderer/src/studio/WorldStudio3D.tsx @@ -2,7 +2,8 @@ import { useEffect, useMemo, useState } from 'react' import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group' import type { BridgeClient, WorldRect } from '../bridge/BridgeClient' import type { MapTile, WorldInfo } from '../bridge/types' -import { buildTerrainMesh, type TerrainArea, type TerrainColoring } from '../scene/terrainMesh' +import { MapTerrain, type MapTerrainArea, type MapTerrainColoring } from '../scene/mapTerrain' +import { buildTerrainMesh } from '../scene/terrainMesh' import { SceneViewport } from './SceneViewport' const NUMBER = new Intl.NumberFormat('en-US') @@ -24,10 +25,10 @@ interface WorldStudio3DProps { /** The terrain around where the map looked, in 3D, coloured by biome, region or height (v3e's 3D world view). */ export function WorldStudio3D({ client, world, mapArea, packRevision, onSummary, tell }: WorldStudio3DProps): React.JSX.Element { - const [coloring, setColoring] = useState('biomes') + const [coloring, setColoring] = useState('biomes') const centre = useMemo(() => centreOf(mapArea), [mapArea]) const area = useTerrainArea(client, centre, packRevision, tell) - const mesh = useMemo(() => (area === null ? null : buildTerrainMesh(area, coloring, world.fluidHeight)), [area, coloring, world.fluidHeight]) + const mesh = useMemo(() => (area === null ? null : buildTerrainMesh(new MapTerrain(area, coloring, world.fluidHeight))), [area, coloring, world.fluidHeight]) useEffect(() => () => mesh?.dispose(), [mesh]) useEffect(() => { @@ -45,7 +46,7 @@ export function WorldStudio3D({ client, world, mapArea, packRevision, onSummary, size="sm" className="absolute top-3 left-3 bg-card/90" value={coloring} - onValueChange={(value) => value !== '' && setColoring(value as TerrainColoring)} + onValueChange={(value) => value !== '' && setColoring(value as MapTerrainColoring)} > Biomes @@ -74,8 +75,8 @@ function centreOf(area: WorldRect | null): { x: number; z: number } { } /** The tiles of the square around {@code centre}, with heights; every tile arrives before the square is shown. */ -function useTerrainArea(client: BridgeClient, centre: { x: number; z: number }, packRevision: number, tell: (message: string) => void): TerrainArea | null { - const [area, setArea] = useState(null) +function useTerrainArea(client: BridgeClient, centre: { x: number; z: number }, packRevision: number, tell: (message: string) => void): MapTerrainArea | null { + const [area, setArea] = useState(null) useEffect(() => { const stop = new AbortController() const firstTileX = Math.floor(centre.x / TILE_BLOCKS - TILES_PER_SIDE / 2) From 8ace4ccc9950824b7c483ef293b434b3a76c12b1 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 02:15:27 +0100 Subject: [PATCH 08/12] Noise view: the pack's noise and the noise styles in 2D and 3D v3e's noise explorer: sources by category, seed with a random pick, five palettes, pan and zoom down to sixteenth-block tiles, a hover readout, and the noise as terrain with a relief slider. TileStore now takes a tile source, so the map and the noise view share fetching, caching and the coarser fallback drawing. --- src/renderer/src/bridge/BridgeClient.ts | 13 + src/renderer/src/bridge/types.ts | 17 ++ src/renderer/src/map/MapController.ts | 66 +--- src/renderer/src/map/TileStore.ts | 72 ++--- src/renderer/src/map/heightColors.ts | 4 +- src/renderer/src/map/mapTileSource.ts | 26 ++ src/renderer/src/map/tileDrawing.ts | 82 +++++ src/renderer/src/map/viewport.ts | 8 +- src/renderer/src/noise/NoiseController.ts | 206 +++++++++++++ src/renderer/src/noise/noise.test.ts | 48 +++ src/renderer/src/noise/noiseScale.ts | 81 +++++ src/renderer/src/noise/noiseTerrain.ts | 73 +++++ src/renderer/src/studio/MapStudio.tsx | 14 +- src/renderer/src/studio/NoiseCanvas.tsx | 82 +++++ src/renderer/src/studio/NoiseStudio.tsx | 348 ++++++++++++++++++++++ src/renderer/src/studio/ViewList.tsx | 3 +- 16 files changed, 1043 insertions(+), 100 deletions(-) create mode 100644 src/renderer/src/map/mapTileSource.ts create mode 100644 src/renderer/src/map/tileDrawing.ts create mode 100644 src/renderer/src/noise/NoiseController.ts create mode 100644 src/renderer/src/noise/noise.test.ts create mode 100644 src/renderer/src/noise/noiseScale.ts create mode 100644 src/renderer/src/noise/noiseTerrain.ts create mode 100644 src/renderer/src/studio/NoiseCanvas.tsx create mode 100644 src/renderer/src/studio/NoiseStudio.tsx diff --git a/src/renderer/src/bridge/BridgeClient.ts b/src/renderer/src/bridge/BridgeClient.ts index 2658ef309..be9774ac9 100644 --- a/src/renderer/src/bridge/BridgeClient.ts +++ b/src/renderer/src/bridge/BridgeClient.ts @@ -7,6 +7,8 @@ import type { MapLabel, MapTile, Marker, + NoiseSource, + NoiseTile, PickInspection, SavedStart, SavedTile, @@ -147,6 +149,17 @@ export class BridgeClient { return decodeSavedTile(await response.arrayBuffer()) } + /** The pack's generators and expressions, the dimension's overlay noise, and the built-in noise styles. */ + noiseSources(): Promise { + return this.json('noise-sources') + } + + async noiseTile(sourceId: string, seed: string, tileX: number, tileZ: number, blocksPerPixel: number, size: number, signal: AbortSignal): Promise { + const query = new URLSearchParams({ source: sourceId, seed, x: String(tileX), z: String(tileZ), scale: String(blocksPerPixel), size: String(size) }) + const response = await this.fetch(`noise-tile?${query}`, { signal }) + return { size, values: new Float32Array(await response.arrayBuffer()) } + } + /** A file of the Minecraft client's assets, such as {@code minecraft/blockstates/stone.json}; null when there is none. */ async asset(path: string): Promise { try { diff --git a/src/renderer/src/bridge/types.ts b/src/renderer/src/bridge/types.ts index a31b79356..b3e256bbf 100644 --- a/src/renderer/src/bridge/types.ts +++ b/src/renderer/src/bridge/types.ts @@ -42,6 +42,23 @@ export interface SavedWorldInfo { namespace: string } +/** One noise the noise view can show. */ +export interface NoiseSource { + id: string + name: string + category: string + /** Whether the view's seed changes it; the dimension's overlay keeps the world's. */ + usesSeed: boolean + /** What the noise spans where it is measured in blocks above the fluid; null for noise of 0 to 1. */ + blockRange: { lowest: number; highest: number } | null +} + +/** A square of noise values, a pixel's value taken at its north west corner, row by row from the north west. */ +export interface NoiseTile { + size: number + values: Float32Array +} + /** Where a saved world's view opens: the middle of the region nearest the origin, and how its ground lies there. */ export interface SavedStart { centerX: number diff --git a/src/renderer/src/map/MapController.ts b/src/renderer/src/map/MapController.ts index 287bc8dd2..0cdb5b9c4 100644 --- a/src/renderer/src/map/MapController.ts +++ b/src/renderer/src/map/MapController.ts @@ -1,19 +1,18 @@ import type { BridgeClient, WorldRect } from '../bridge/BridgeClient' import { gridIndex } from '../bridge/tileDecoding' -import { NO_LABEL, type MapLabel, type Marker, type PickDisplay, type WorldInfo } from '../bridge/types' +import { NO_LABEL, type MapLabel, type MapTile, type Marker, type PickDisplay, type WorldInfo } from '../bridge/types' import { countShares, type PlacedTile, type Share } from './census' import { bandIndexOf, HEIGHT_BANDS } from './heightColors' +import { mapTileSource, type TileLayer } from './mapTileSource' +import { drawVisibleTiles } from './tileDrawing' import type { Highlight, TileStyle } from './tileStyle' -import { TileStore, type TileLayer } from './TileStore' +import { TileStore } from './TileStore' import { clampBlocksPerPixel, - coarserTile, - previewsFor, DEFAULT_BLOCKS_PER_PIXEL, renderBlocksPerPixel, screenToWorldX, screenToWorldZ, - visibleTiles, worldToScreenX, worldToScreenZ, type TileAddress, @@ -53,8 +52,6 @@ export interface MapToggles { grid: boolean } -// While a tile is on its way, a coarser one already drawn stands in, up to this many zoom levels out. -const COARSER_FALLBACK_LEVELS = 6 const CENSUS_INTERVAL_MILLIS = 250 const CHUNK_BLOCKS = 16 const REGION_BLOCKS = 512 @@ -73,7 +70,7 @@ const ENTITY_RADIUS_PIXELS = 3 */ export class MapController { private readonly context: CanvasRenderingContext2D - private readonly store: TileStore + private readonly store: TileStore private readonly view: Viewport = { centerX: 0, centerZ: 0, blocksPerPixel: DEFAULT_BLOCKS_PER_PIXEL, width: 1, height: 1 } private layer: TileLayer private toggles: MapToggles = { shading: true, regionBorders: false, grid: false } @@ -96,7 +93,7 @@ export class MapController { ) { this.context = canvas.getContext('2d')! this.layer = { view, preview: null, heights: this.needsHeights(view, this.toggles), pickNoise: false, revision: 0 } - this.store = new TileStore(client, world.tileSize, () => this.redraw(), (message) => listener.onError(message)) + this.store = new TileStore(mapTileSource(client, world.tileSize), () => this.redraw(), (message) => listener.onError(message)) } close(): void { @@ -263,56 +260,17 @@ export class MapController { context.fillStyle = getComputedStyle(this.canvas).getPropertyValue('--map-background') || '#16171a' context.fillRect(0, 0, this.view.width, this.view.height) - const scale = this.renderScale() - const tiles = visibleTiles(this.view, scale, this.world.tileSize) const style = this.style() - context.imageSmoothingEnabled = this.view.blocksPerPixel > scale - let ready = 0 - const blank: TileAddress[] = [] - for (const address of tiles) { - const picture = this.store.picture(address, this.layer, style) - if (picture !== null) { - this.drawTile(picture, address, 0, 0, picture.width) - ready++ - } else if (!this.drawFallback(address, style)) { - blank.push(address) - } - } - this.store.want([...previewsFor(blank), ...tiles], this.layer) + const drawn = drawVisibleTiles(context, this.view, this.renderScale(), this.world.tileSize, (address) => + this.store.picture(address, this.layer, style) + ) + this.store.want(drawn.wanted, this.layer) if (this.toggles.grid) { this.drawGrid() } this.drawMarkers() - this.reportStatus(ready, tiles.length) - this.scheduleCensus(tiles) - } - - /** Draws the part of a tile picture from (sourceX, sourceZ), {@code sourceSize} pixels wide, over {@code address}. */ - private drawTile(picture: HTMLCanvasElement, address: TileAddress, sourceX: number, sourceZ: number, sourceSize: number): void { - const span = this.world.tileSize * address.blocksPerPixel - const left = Math.round(worldToScreenX(this.view, address.tileX * span)) - const top = Math.round(worldToScreenZ(this.view, address.tileZ * span)) - const right = Math.round(worldToScreenX(this.view, (address.tileX + 1) * span)) - const bottom = Math.round(worldToScreenZ(this.view, (address.tileZ + 1) * span)) - this.context.drawImage(picture, sourceX, sourceZ, sourceSize, sourceSize, left, top, right - left, bottom - top) - } - - /** Draws the part of a coarser tile that covers {@code address}; false when no coarser tile has arrived either. */ - private drawFallback(address: TileAddress, style: TileStyle): boolean { - for (let levels = 1; levels <= COARSER_FALLBACK_LEVELS; levels++) { - const coarser = coarserTile(address, levels) - const picture = this.store.picture(coarser, this.layer, style) - if (picture === null) { - continue - } - const factor = 2 ** levels - const sourceSize = picture.width / factor - const sourceX = (address.tileX - coarser.tileX * factor) * sourceSize - const sourceZ = (address.tileZ - coarser.tileZ * factor) * sourceSize - this.drawTile(picture, address, sourceX, sourceZ, sourceSize) - return true - } - return false + this.reportStatus(drawn.ready, drawn.tiles.length) + this.scheduleCensus(drawn.tiles) } private drawGrid(): void { diff --git a/src/renderer/src/map/TileStore.ts b/src/renderer/src/map/TileStore.ts index 9ecc91c10..30d949527 100644 --- a/src/renderer/src/map/TileStore.ts +++ b/src/renderer/src/map/TileStore.ts @@ -1,21 +1,18 @@ -import { BridgeError, type BridgeClient } from '../bridge/BridgeClient' -import type { MapTile } from '../bridge/types' -import { stylePixels, styleKey, type TileStyle } from './tileStyle' +import { BridgeError } from '../bridge/BridgeClient' import type { TileAddress } from './viewport' -/** What one tile request needs besides where the tile is. */ -export interface TileLayer { - view: string - /** The region the region view previews everywhere, or null for the world as it is. */ - preview: string | null - heights: boolean - pickNoise: boolean - /** Bumped when the pack is hotloaded, so older tiles are not used again. */ - revision: number +/** What a store's tiles are, where they come from, and how one is drawn in a style. */ +export interface TileSource { + /** Tells layers apart; a layer that changes on hotload carries its revision here, so older tiles are not used again. */ + layerKey(layer: Layer): string + fetch(address: TileAddress, layer: Layer, signal: AbortSignal): Promise + bytesOf(tile: Tile): number + styleKey(style: Style): string + pixels(tile: Tile, style: Style): ImageData } -interface StoredTile { - tile: MapTile +interface StoredTile { + tile: Tile bytes: number lastUsed: number picture: HTMLCanvasElement | null @@ -27,32 +24,30 @@ const MAXIMUM_IN_FLIGHT = 6 const CACHE_BYTES = 256 * 1024 * 1024 /** - * The map's tiles: fetched from the bridge as the view needs them, kept within a memory budget, and drawn as the - * current style asks. A tile that leaves the view before it arrives is not fetched. + * Tiles fetched from the bridge as a view needs them, kept within a memory budget, and drawn as the current style + * asks. A tile that leaves the view before it arrives is not fetched. */ -export class TileStore { - private readonly tiles = new Map() +export class TileStore { + private readonly tiles = new Map>() private readonly inFlight = new Map() /** Asked for again only after a refresh, which changes every key, so a broken tile is not fetched on every frame. */ private readonly failed = new Set() - private wanted: { key: string; address: TileAddress; layer: TileLayer }[] = [] + private wanted: { key: string; address: TileAddress; layer: Layer }[] = [] private storedBytes = 0 private useClock = 0 constructor( - private readonly client: BridgeClient, - private readonly tileSize: number, + private readonly source: TileSource, private readonly onChange: () => void, private readonly onError: (message: string) => void ) {} - key(address: TileAddress, layer: TileLayer): string { - const parts = [layer.revision, layer.view, layer.preview ?? '', layer.heights, layer.pickNoise] - return `${parts.join('/')}/${address.blocksPerPixel}/${address.tileX}/${address.tileZ}` + key(address: TileAddress, layer: Layer): string { + return `${this.source.layerKey(layer)}/${address.blocksPerPixel}/${address.tileX}/${address.tileZ}` } /** The tile if it has arrived, marked as just used. */ - get(address: TileAddress, layer: TileLayer): MapTile | null { + get(address: TileAddress, layer: Layer): Tile | null { const stored = this.tiles.get(this.key(address, layer)) if (stored === undefined) { return null @@ -62,23 +57,23 @@ export class TileStore { } /** The tile drawn in {@code style}; restyled only when the style changed since it was last drawn. */ - picture(address: TileAddress, layer: TileLayer, style: TileStyle): HTMLCanvasElement | null { + picture(address: TileAddress, layer: Layer, style: Style): HTMLCanvasElement | null { const stored = this.tiles.get(this.key(address, layer)) if (stored === undefined) { return null } stored.lastUsed = ++this.useClock - const wantedStyle = styleKey(style) + const wantedStyle = this.source.styleKey(style) if (stored.picture === null || stored.pictureStyle !== wantedStyle) { stored.picture = stored.picture ?? document.createElement('canvas') - paint(stored.picture, stored.tile, style) + paint(stored.picture, this.source.pixels(stored.tile, style)) stored.pictureStyle = wantedStyle } return stored.picture } /** Fetches the tiles the view shows, in the order given, and gives up on the ones it no longer shows. */ - want(addresses: TileAddress[], layer: TileLayer): void { + want(addresses: TileAddress[], layer: Layer): void { this.wanted = addresses .map((address) => ({ key: this.key(address, layer), address, layer })) .filter((entry) => !this.tiles.has(entry.key) && !this.failed.has(entry.key)) @@ -119,12 +114,11 @@ export class TileStore { } } - private fetchTile(key: string, address: TileAddress, layer: TileLayer): void { + private fetchTile(key: string, address: TileAddress, layer: Layer): void { const controller = new AbortController() this.inFlight.set(key, controller) - const request = { ...layer, ...address, size: this.tileSize } - this.client - .tile(request, controller.signal) + this.source + .fetch(address, layer, controller.signal) .then((tile) => this.store(key, tile)) .catch((error: unknown) => { if (!controller.signal.aborted) { @@ -142,8 +136,8 @@ export class TileStore { }) } - private store(key: string, tile: MapTile): void { - const bytes = tile.subjects.byteLength * 2 + (tile.heights?.byteLength ?? 0) + (tile.pickNoise?.byteLength ?? 0) + tile.size * tile.size * 4 + private store(key: string, tile: Tile): void { + const bytes = this.source.bytesOf(tile) this.tiles.set(key, { tile, bytes, lastUsed: ++this.useClock, picture: null, pictureStyle: '' }) this.storedBytes += bytes this.evictOldest() @@ -164,8 +158,8 @@ export class TileStore { } } -function paint(canvas: HTMLCanvasElement, tile: MapTile, style: TileStyle): void { - canvas.width = tile.size - canvas.height = tile.size - canvas.getContext('2d')!.putImageData(new ImageData(stylePixels(tile, style), tile.size, tile.size), 0, 0) +function paint(canvas: HTMLCanvasElement, pixels: ImageData): void { + canvas.width = pixels.width + canvas.height = pixels.height + canvas.getContext('2d')!.putImageData(pixels, 0, 0) } diff --git a/src/renderer/src/map/heightColors.ts b/src/renderer/src/map/heightColors.ts index 60c364b0a..de14ad17e 100644 --- a/src/renderer/src/map/heightColors.ts +++ b/src/renderer/src/map/heightColors.ts @@ -1,7 +1,7 @@ /** The height scale of the map, from deep water to snowy peaks, measured from sea level (v3e HeightColors). */ -const DEEPEST_BELOW_SEA_BLOCKS = 90 -const HIGHEST_ABOVE_SEA_BLOCKS = 300 +export const DEEPEST_BELOW_SEA_BLOCKS = 90 +export const HIGHEST_ABOVE_SEA_BLOCKS = 300 const DEPTH_BLOCKS = [0, 10, 40, DEEPEST_BELOW_SEA_BLOCKS] const DEPTH_COLORS = [0x7db8d8, 0x4c8dba, 0x2a5e8f, 0x15304f] const ABOVE_SEA_BLOCKS = [0, 8, 30, 70, 130, 200, HIGHEST_ABOVE_SEA_BLOCKS] diff --git a/src/renderer/src/map/mapTileSource.ts b/src/renderer/src/map/mapTileSource.ts new file mode 100644 index 000000000..fc8c0bf7a --- /dev/null +++ b/src/renderer/src/map/mapTileSource.ts @@ -0,0 +1,26 @@ +import type { BridgeClient } from '../bridge/BridgeClient' +import type { MapTile } from '../bridge/types' +import { stylePixels, styleKey, type TileStyle } from './tileStyle' +import type { TileSource } from './TileStore' + +/** What one map tile request needs besides where the tile is. */ +export interface TileLayer { + view: string + /** The region the region view previews everywhere, or null for the world as it is. */ + preview: string | null + heights: boolean + pickNoise: boolean + /** Bumped when the pack is hotloaded, so older tiles are not used again. */ + revision: number +} + +/** The world map's tiles: the engine's streams, drawn in the map's styles. */ +export function mapTileSource(client: BridgeClient, tileSize: number): TileSource { + return { + layerKey: (layer) => [layer.revision, layer.view, layer.preview ?? '', layer.heights, layer.pickNoise].join('/'), + fetch: (address, layer, signal) => client.tile({ ...layer, ...address, size: tileSize }, signal), + bytesOf: (tile) => tile.subjects.byteLength * 2 + (tile.heights?.byteLength ?? 0) + (tile.pickNoise?.byteLength ?? 0) + tile.size * tile.size * 4, + styleKey, + pixels: (tile, style) => new ImageData(stylePixels(tile, style), tile.size, tile.size) + } +} diff --git a/src/renderer/src/map/tileDrawing.ts b/src/renderer/src/map/tileDrawing.ts new file mode 100644 index 000000000..ac3b9545a --- /dev/null +++ b/src/renderer/src/map/tileDrawing.ts @@ -0,0 +1,82 @@ +import { coarserTile, previewsFor, visibleTiles, worldToScreenX, worldToScreenZ, type TileAddress, type Viewport } from './viewport' + +// While a tile is on its way, a coarser one already drawn stands in, up to this many zoom levels out. +const COARSER_FALLBACK_LEVELS = 6 + +export interface DrawnTiles { + /** Every tile the view covers, nearest the centre first. */ + tiles: TileAddress[] + ready: number + /** What to fetch, in order: a coarser preview for each blank stretch first, then the tiles themselves. */ + wanted: TileAddress[] +} + +/** + * Draws the tiles covering the view at {@code renderScale}, from {@code pictureOf}; where one hasn't arrived, the part + * of a coarser one that covers it. + */ +export function drawVisibleTiles( + context: CanvasRenderingContext2D, + view: Viewport, + renderScale: number, + tileSize: number, + pictureOf: (address: TileAddress) => HTMLCanvasElement | null +): DrawnTiles { + const tiles = visibleTiles(view, renderScale, tileSize) + context.imageSmoothingEnabled = view.blocksPerPixel > renderScale + let ready = 0 + const blank: TileAddress[] = [] + for (const address of tiles) { + const picture = pictureOf(address) + if (picture !== null) { + drawTile(context, view, tileSize, picture, address, 0, 0, picture.width) + ready++ + } else if (!drawFallback(context, view, tileSize, address, pictureOf)) { + blank.push(address) + } + } + return { tiles, ready, wanted: [...previewsFor(blank), ...tiles] } +} + +/** Draws the part of a tile picture from (sourceX, sourceZ), {@code sourceSize} pixels wide, over {@code address}. */ +function drawTile( + context: CanvasRenderingContext2D, + view: Viewport, + tileSize: number, + picture: HTMLCanvasElement, + address: TileAddress, + sourceX: number, + sourceZ: number, + sourceSize: number +): void { + const span = tileSize * address.blocksPerPixel + const left = Math.round(worldToScreenX(view, address.tileX * span)) + const top = Math.round(worldToScreenZ(view, address.tileZ * span)) + const right = Math.round(worldToScreenX(view, (address.tileX + 1) * span)) + const bottom = Math.round(worldToScreenZ(view, (address.tileZ + 1) * span)) + context.drawImage(picture, sourceX, sourceZ, sourceSize, sourceSize, left, top, right - left, bottom - top) +} + +/** Draws the part of a coarser tile that covers {@code address}; false when no coarser tile has arrived either. */ +function drawFallback( + context: CanvasRenderingContext2D, + view: Viewport, + tileSize: number, + address: TileAddress, + pictureOf: (address: TileAddress) => HTMLCanvasElement | null +): boolean { + for (let levels = 1; levels <= COARSER_FALLBACK_LEVELS; levels++) { + const coarser = coarserTile(address, levels) + const picture = pictureOf(coarser) + if (picture === null) { + continue + } + const factor = 2 ** levels + const sourceSize = picture.width / factor + const sourceX = (address.tileX - coarser.tileX * factor) * sourceSize + const sourceZ = (address.tileZ - coarser.tileZ * factor) * sourceSize + drawTile(context, view, tileSize, picture, address, sourceX, sourceZ, sourceSize) + return true + } + return false +} diff --git a/src/renderer/src/map/viewport.ts b/src/renderer/src/map/viewport.ts index 8fd0a5254..c243ff9ac 100644 --- a/src/renderer/src/map/viewport.ts +++ b/src/renderer/src/map/viewport.ts @@ -43,9 +43,13 @@ export function worldToScreenZ(view: Viewport, worldZ: number): number { * The scale tiles are drawn at for a view: the nearest power of two to one tile pixel per device pixel, so tiles stay * sharp on dense screens and every zoom between two levels reuses the same tiles. */ -export function renderBlocksPerPixel(viewBlocksPerPixel: number, devicePixelRatio: number): number { +export function renderBlocksPerPixel( + viewBlocksPerPixel: number, + devicePixelRatio: number, + finestBlocksPerPixel = MINIMUM_RENDER_BLOCKS_PER_PIXEL +): number { const level = 2 ** Math.round(Math.log2(viewBlocksPerPixel / devicePixelRatio)) - return Math.min(MAXIMUM_BLOCKS_PER_PIXEL, Math.max(MINIMUM_RENDER_BLOCKS_PER_PIXEL, level)) + return Math.min(MAXIMUM_BLOCKS_PER_PIXEL, Math.max(finestBlocksPerPixel, level)) } /** The tiles covering the view, nearest the centre first so the middle of the screen fills in first. */ diff --git a/src/renderer/src/noise/NoiseController.ts b/src/renderer/src/noise/NoiseController.ts new file mode 100644 index 000000000..ca8a71d96 --- /dev/null +++ b/src/renderer/src/noise/NoiseController.ts @@ -0,0 +1,206 @@ +import type { BridgeClient } from '../bridge/BridgeClient' +import type { NoiseTile } from '../bridge/types' +import { drawVisibleTiles } from '../map/tileDrawing' +import { TileStore, type TileSource } from '../map/TileStore' +import { clampBlocksPerPixel, renderBlocksPerPixel, screenToWorldX, screenToWorldZ, type TileAddress, type Viewport } from '../map/viewport' +import type { NoiseScale } from './noiseScale' + +/** Which noise the tiles hold. */ +export interface NoiseLayer { + sourceId: string + /** A 64 bit seed, as text so no digit is lost. */ + seed: string + /** Bumped when the pack is hotloaded, so older tiles are not used again. */ + revision: number +} + +export interface NoiseStyle { + /** Tells styles apart, so a tile is recoloured only when its style changed. */ + key: string + scale: NoiseScale +} + +export interface NoiseStatus { + blocksPerPixel: number + tilesReady: number + tilesTotal: number + cursorX: number + cursorZ: number + /** The noise at the cursor, or null before its tile arrived. */ + value: number | null +} + +export interface NoiseListener { + onStatus(status: NoiseStatus): void + onError(message: string): void +} + +export const NOISE_TILE_PIXELS = 128 +const DEFAULT_NOISE_BLOCKS_PER_PIXEL = 1 +// Noise has detail finer than a block, so it is drawn finer than the world map's one block per pixel. +const FINEST_NOISE_BLOCKS_PER_PIXEL = 1 / 16 + +function noiseTileSource(client: BridgeClient): TileSource { + return { + layerKey: (layer) => `${layer.revision}/${layer.sourceId}/${layer.seed}`, + fetch: (address, layer, signal) => + client.noiseTile(layer.sourceId, layer.seed, address.tileX, address.tileZ, address.blocksPerPixel, NOISE_TILE_PIXELS, signal), + bytesOf: (tile) => tile.values.byteLength + tile.size * tile.size * 4, + styleKey: (style) => style.key, + pixels: (tile, style) => noisePixels(tile, style.scale) + } +} + +function noisePixels(tile: NoiseTile, scale: NoiseScale): ImageData { + const pixels = new ImageData(tile.size, tile.size) + for (let index = 0; index < tile.values.length; index++) { + const color = scale.colorOf(tile.values[index]) + pixels.data[index * 4] = (color >> 16) & 0xff + pixels.data[index * 4 + 1] = (color >> 8) & 0xff + pixels.data[index * 4 + 2] = color & 0xff + pixels.data[index * 4 + 3] = 0xff + } + return pixels +} + +/** The noise from above on a canvas, fetched in tiles as the view moves. Kept outside React, as it redraws on every drag. */ +export class NoiseController { + private readonly context: CanvasRenderingContext2D + private readonly store: TileStore + private readonly view: Viewport = { centerX: 0, centerZ: 0, blocksPerPixel: DEFAULT_NOISE_BLOCKS_PER_PIXEL, width: 1, height: 1 } + private layer: NoiseLayer | null = null + private style: NoiseStyle | null = null + private cursor: { x: number; y: number } | null = null + private lastReady = 0 + private lastTotal = 0 + private frameRequested = false + private closed = false + + constructor( + private readonly canvas: HTMLCanvasElement, + client: BridgeClient, + private readonly listener: NoiseListener + ) { + this.context = canvas.getContext('2d')! + this.store = new TileStore(noiseTileSource(client), () => this.redraw(), (message) => listener.onError(message)) + } + + close(): void { + this.closed = true + this.store.clear() + } + + resize(width: number, height: number): void { + const ratio = window.devicePixelRatio + this.canvas.width = Math.round(width * ratio) + this.canvas.height = Math.round(height * ratio) + this.view.width = width + this.view.height = height + this.redraw() + } + + show(layer: NoiseLayer | null, style: NoiseStyle): void { + this.layer = layer + this.style = style + this.redraw() + } + + panBy(screenDeltaX: number, screenDeltaZ: number): void { + this.view.centerX -= screenDeltaX * this.view.blocksPerPixel + this.view.centerZ -= screenDeltaZ * this.view.blocksPerPixel + this.redraw() + } + + /** Zooms by {@code factor} (above 1 zooms in) keeping the spot under the screen point where it is. */ + zoomAt(factor: number, screenX = this.view.width / 2, screenZ = this.view.height / 2): void { + const worldX = screenToWorldX(this.view, screenX) + const worldZ = screenToWorldZ(this.view, screenZ) + this.view.blocksPerPixel = clampBlocksPerPixel(this.view.blocksPerPixel / factor) + this.view.centerX = worldX - (screenX - this.view.width / 2) * this.view.blocksPerPixel + this.view.centerZ = worldZ - (screenZ - this.view.height / 2) * this.view.blocksPerPixel + this.redraw() + } + + resetView(): void { + this.view.centerX = 0 + this.view.centerZ = 0 + this.view.blocksPerPixel = DEFAULT_NOISE_BLOCKS_PER_PIXEL + this.redraw() + } + + setCursor(cursor: { x: number; y: number } | null): void { + this.cursor = cursor + this.reportStatus() + } + + /** Where the view looks and the scale its tiles are drawn at, for the 3D view to sample the same noise. */ + framing(): { centerX: number; centerZ: number; renderScale: number } { + return { centerX: this.view.centerX, centerZ: this.view.centerZ, renderScale: this.renderScale() } + } + + private renderScale(): number { + return renderBlocksPerPixel(this.view.blocksPerPixel, window.devicePixelRatio, FINEST_NOISE_BLOCKS_PER_PIXEL) + } + + private redraw(): void { + if (this.frameRequested || this.closed) { + return + } + this.frameRequested = true + requestAnimationFrame(() => { + this.frameRequested = false + if (!this.closed) { + this.draw() + } + }) + } + + private draw(): void { + const ratio = window.devicePixelRatio + const context = this.context + context.setTransform(ratio, 0, 0, ratio, 0, 0) + context.fillStyle = getComputedStyle(this.canvas).getPropertyValue('--map-background') || '#16171a' + context.fillRect(0, 0, this.view.width, this.view.height) + const layer = this.layer + const style = this.style + if (layer === null || style === null) { + this.reportStatus(0, 0) + return + } + const drawn = drawVisibleTiles(context, this.view, this.renderScale(), NOISE_TILE_PIXELS, (address) => this.store.picture(address, layer, style)) + this.store.want(drawn.wanted, layer) + this.reportStatus(drawn.ready, drawn.tiles.length) + } + + private valueAt(worldX: number, worldZ: number): number | null { + if (this.layer === null) { + return null + } + const scale = this.renderScale() + const span = NOISE_TILE_PIXELS * scale + const address: TileAddress = { tileX: Math.floor(worldX / span), tileZ: Math.floor(worldZ / span), blocksPerPixel: scale } + const tile = this.store.get(address, this.layer) + if (tile === null) { + return null + } + const pixelX = Math.min(tile.size - 1, Math.floor((worldX - address.tileX * span) / scale)) + const pixelZ = Math.min(tile.size - 1, Math.floor((worldZ - address.tileZ * span) / scale)) + return tile.values[pixelZ * tile.size + pixelX] + } + + private reportStatus(ready = this.lastReady, total = this.lastTotal): void { + this.lastReady = ready + this.lastTotal = total + const cursor = this.cursor ?? { x: this.view.width / 2, y: this.view.height / 2 } + const worldX = screenToWorldX(this.view, cursor.x) + const worldZ = screenToWorldZ(this.view, cursor.y) + this.listener.onStatus({ + blocksPerPixel: this.view.blocksPerPixel, + tilesReady: ready, + tilesTotal: total, + cursorX: worldX, + cursorZ: worldZ, + value: this.valueAt(worldX, worldZ) + }) + } +} diff --git a/src/renderer/src/noise/noise.test.ts b/src/renderer/src/noise/noise.test.ts new file mode 100644 index 000000000..1b6c6abed --- /dev/null +++ b/src/renderer/src/noise/noise.test.ts @@ -0,0 +1,48 @@ +import { describe, expect, it } from 'vitest' +import type { NoiseSource } from '../bridge/types' +import { heightColor } from '../map/heightColors' +import { INVALID_NOISE_COLOR, noiseScale } from './noiseScale' +import { NoiseTerrain } from './noiseTerrain' + +const UNIT_NOISE: NoiseSource = { id: 'style:SIMPLEX', name: 'Simplex', category: 'Simplex', usesSeed: true, blockRange: null } +const BLOCK_NOISE: NoiseSource = { id: 'world:overlay', name: 'Overlay noise', category: 'Pack generators', usesSeed: false, blockRange: { lowest: -20, highest: 40 } } + +describe('noise scale', () => { + it('spans the palette for noise of 0 to 1 and takes its end colours past it', () => { + const terrain = noiseScale('terrain', UNIT_NOISE) + expect([terrain.minimum, terrain.maximum]).toEqual([0, 1]) + expect(terrain.colorOf(0)).toBe(0x071a2f) + expect(terrain.colorOf(1)).toBe(0xf4f1de) + expect(terrain.colorOf(7)).toBe(0xf4f1de) + expect(noiseScale('signed', UNIT_NOISE).minimum).toBe(-1) + }) + + it('spans the block range for noise in blocks, coloured as heights above the fluid', () => { + const height = noiseScale('height', BLOCK_NOISE) + expect([height.minimum, height.maximum]).toEqual([-20, 40]) + expect(height.colorOf(-20)).toBe(heightColor(-20, 0)) + expect(height.colorOf(40)).toBe(heightColor(40, 0)) + }) + + it('marks a value the noise could not give', () => { + expect(noiseScale('grayscale', UNIT_NOISE).colorOf(Number.NaN)).toBe(INVALID_NOISE_COLOR) + }) +}) + +describe('noise terrain', () => { + const area = (values: number[]) => ({ tiles: [[{ size: 2, values: Float32Array.from(values) }]], originX: 10, originZ: 20, blocksPerValue: 4 }) + + it('raises noise of 0 to 1 to the relief, without water', () => { + const terrain = new NoiseTerrain(area([0, 0.5, 1, Number.NaN]), UNIT_NOISE, noiseScale('terrain', UNIT_NOISE), 64) + expect([terrain.groundAt(0, 0), terrain.groundAt(1, 0), terrain.groundAt(0, 1), terrain.groundAt(1, 1)]).toEqual([0, 32, 64, null]) + expect(terrain.waterAt(0, 0)).toBeNull() + expect([terrain.worldX(1), terrain.worldZ(1)]).toEqual([14, 24]) + }) + + it('stands noise in blocks at its own height, under water below the fluid', () => { + const terrain = new NoiseTerrain(area([-5, 12, 0, 3]), BLOCK_NOISE, noiseScale('height', BLOCK_NOISE), 64) + expect(terrain.groundAt(0, 0)).toBe(-5) + expect(terrain.waterAt(0, 0)).toBe(0) + expect(terrain.waterAt(1, 0)).toBeNull() + }) +}) diff --git a/src/renderer/src/noise/noiseScale.ts b/src/renderer/src/noise/noiseScale.ts new file mode 100644 index 000000000..4c5026bef --- /dev/null +++ b/src/renderer/src/noise/noiseScale.ts @@ -0,0 +1,81 @@ +import type { NoiseSource } from '../bridge/types' +import { DEEPEST_BELOW_SEA_BLOCKS, heightColor, HIGHEST_ABOVE_SEA_BLOCKS } from '../map/heightColors' + +export type NoisePaletteId = 'terrain' | 'signed' | 'grayscale' | 'height' | 'green' + +interface NoisePalette { + id: NoisePaletteId + label: string + minimum: number + maximum: number + /** Colours from the minimum to the maximum, evenly spaced; null for the map's height colours. */ + stops: number[] | null +} + +/** v3e's noise palettes, each with the values it spans when the noise is not measured in blocks. */ +export const NOISE_PALETTES: readonly NoisePalette[] = [ + { id: 'terrain', label: 'Terrain', minimum: 0, maximum: 1, stops: [0x071a2f, 0x155e75, 0x2a9d8f, 0xe9c46a, 0xf4f1de] }, + { id: 'signed', label: 'Signed', minimum: -1, maximum: 1, stops: [0x173b66, 0x4f86c6, 0xe7edf3, 0xe89555, 0x9d3b35] }, + { id: 'grayscale', label: 'Grayscale', minimum: 0, maximum: 1, stops: [0x050505, 0xffffff] }, + { id: 'height', label: 'Height', minimum: 0, maximum: 1, stops: null }, + { id: 'green', label: 'Green', minimum: 0, maximum: 1, stops: [0x2a3330, 0x5fd3a8] } +] + +/** The colour of a value the noise couldn't give, so it stands out from every palette. */ +export const INVALID_NOISE_COLOR = 0xff2daa +const LOOKUP_SIZE = 256 + +/** How values become colours: the span the palette covers, and the colour of a value. */ +export interface NoiseScale { + minimum: number + maximum: number + /** Over and under the span take the end colours. */ + colorOf(value: number): number + /** The colour a fraction of the way along the span, for the legend. */ + colorAlong(fraction: number): number +} + +/** + * The scale for a palette and a source: noise of 0 to 1 spans the palette's own range; noise in blocks spans its block + * range, and the height palette then colours it as the map colours heights above the fluid. + */ +export function noiseScale(paletteId: NoisePaletteId, source: NoiseSource | null): NoiseScale { + const palette = NOISE_PALETTES.find((candidate) => candidate.id === paletteId)! + const blocks = source?.blockRange ?? null + const minimum = blocks?.lowest ?? palette.minimum + const maximum = blocks?.highest ?? palette.maximum + const colorAlong = paletteColors(palette, blocks === null ? null : [blocks.lowest, blocks.highest]) + const span = maximum - minimum + return { + minimum, + maximum, + colorAlong, + colorOf: (value) => (Number.isFinite(value) ? colorAlong(span <= 0 ? 0.5 : (value - minimum) / span) : INVALID_NOISE_COLOR) + } +} + +function paletteColors(palette: NoisePalette, blockSpan: [number, number] | null): (fraction: number) => number { + if (palette.stops === null) { + const [lowest, highest] = blockSpan ?? [-DEEPEST_BELOW_SEA_BLOCKS, HIGHEST_ABOVE_SEA_BLOCKS] + return (fraction) => heightColor(lowest + (highest - lowest) * clampUnit(fraction), 0) + } + const lookup = lookupOf(palette.stops) + return (fraction) => lookup[Math.round(clampUnit(fraction) * (LOOKUP_SIZE - 1))] +} + +function lookupOf(stops: number[]): number[] { + return Array.from({ length: LOOKUP_SIZE }, (_, index) => { + const position = (index / (LOOKUP_SIZE - 1)) * (stops.length - 1) + const lower = Math.min(stops.length - 2, Math.floor(position)) + return mix(stops[lower], stops[lower + 1], position - lower) + }) +} + +function mix(from: number, to: number, fraction: number): number { + const channel = (shift: number): number => Math.round(((from >>> shift) & 0xff) + (((to >>> shift) & 0xff) - ((from >>> shift) & 0xff)) * fraction) + return (channel(16) << 16) | (channel(8) << 8) | channel(0) +} + +function clampUnit(fraction: number): number { + return Math.min(1, Math.max(0, fraction)) +} diff --git a/src/renderer/src/noise/noiseTerrain.ts b/src/renderer/src/noise/noiseTerrain.ts new file mode 100644 index 000000000..173c2b74e --- /dev/null +++ b/src/renderer/src/noise/noiseTerrain.ts @@ -0,0 +1,73 @@ +import type { NoiseSource, NoiseTile } from '../bridge/types' +import type { TerrainSurface } from '../scene/terrainMesh' +import type { NoiseScale } from './noiseScale' + +/** A square of noise tiles, row by row from the north west, and the block its first value is taken at. */ +export interface NoiseArea { + tiles: NoiseTile[][] + originX: number + originZ: number + blocksPerValue: number +} + +// The fluid of noise measured in blocks lies at its zero, as the world adds the overlay above its fluid height. +const FLUID_BLOCKS = 0 + +/** + * Noise as terrain (v3e's 3D noise): noise measured in blocks stands at its own height with water at the fluid; + * other noise rises from its scale's minimum to {@code reliefBlocks} at its maximum, with no water. + */ +export class NoiseTerrain implements TerrainSurface { + readonly columns: number + readonly rows: number + private readonly tileSize: number + + constructor( + private readonly area: NoiseArea, + private readonly source: NoiseSource, + private readonly scale: NoiseScale, + private readonly reliefBlocks: number + ) { + this.tileSize = area.tiles[0][0].size + this.rows = area.tiles.length * this.tileSize + this.columns = area.tiles[0].length * this.tileSize + } + + worldX(column: number): number { + return this.area.originX + column * this.area.blocksPerValue + } + + worldZ(row: number): number { + return this.area.originZ + row * this.area.blocksPerValue + } + + groundAt(column: number, row: number): number | null { + const value = this.valueAt(column, row) + return Number.isFinite(value) ? this.heightOf(value) : null + } + + waterAt(column: number, row: number): number | null { + if (this.source.blockRange === null) { + return null + } + const ground = this.groundAt(column, row) + return ground !== null && ground < FLUID_BLOCKS ? FLUID_BLOCKS : null + } + + colorAt(column: number, row: number): number { + return this.scale.colorOf(this.valueAt(column, row)) + } + + private heightOf(value: number): number { + if (this.source.blockRange !== null) { + return value + } + const span = this.scale.maximum - this.scale.minimum + return ((value - this.scale.minimum) / span) * this.reliefBlocks + } + + private valueAt(column: number, row: number): number { + const tile = this.area.tiles[Math.floor(row / this.tileSize)][Math.floor(column / this.tileSize)] + return tile.values[(row % this.tileSize) * tile.size + (column % this.tileSize)] + } +} diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx index 8a9b8160a..5d43af44f 100644 --- a/src/renderer/src/studio/MapStudio.tsx +++ b/src/renderer/src/studio/MapStudio.tsx @@ -11,6 +11,7 @@ import { Legend } from './Legend' import { MapCanvas, type CanvasPoint } from './MapCanvas' import { PickInspector } from './PickInspector' import { RegionPreviewList } from './RegionPreviewList' +import { NoiseStudio } from './NoiseStudio' import { SavedWorldStudio } from './SavedWorldStudio' import { SceneStudio } from './SceneStudio' import { WorldStudio3D } from './WorldStudio3D' @@ -61,7 +62,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps const [packRevision, setPackRevision] = useState(0) const [sceneSummary, setSceneSummary] = useState(null) const sceneViews = useSceneViews(client, packRevision) - const views = useMemo(() => [...withAppViews(world.views), ...sceneViews.map(asViewInfo)], [world.views, sceneViews]) + const views = useMemo(() => [...withAppViews(world.views), ...sceneViews.map(asViewInfo), NOISE], [world.views, sceneViews]) const sceneView = sceneViews.find((candidate) => candidate.id === viewId) ?? null const showsMap = sceneView === null && !APP_VIEW_IDS.has(viewId) const view = views.find((candidate) => candidate.id === viewId) ?? views[0] @@ -221,6 +222,8 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps ) : viewId === SAVED_WORLD.id ? ( + ) : viewId === NOISE.id ? ( + ) : ( <>
@@ -298,7 +301,14 @@ const SAVED_WORLD: ViewInfo = { group: 'WORLD', groupLabel: 'World' } -const APP_VIEW_IDS = new Set([WORLD_3D.id, SAVED_WORLD.id]) +const NOISE: ViewInfo = { + id: 'noise', + label: 'Noise', + description: "The pack's generators and expressions and the built-in noise styles, from above or as terrain", + group: 'PACK', + groupLabel: 'Pack' +} +const APP_VIEW_IDS = new Set([WORLD_3D.id, SAVED_WORLD.id, NOISE.id]) function withAppViews(serverViews: ViewInfo[]): ViewInfo[] { const afterHeight = serverViews.findIndex((candidate) => candidate.id === 'height') + 1 diff --git a/src/renderer/src/studio/NoiseCanvas.tsx b/src/renderer/src/studio/NoiseCanvas.tsx new file mode 100644 index 000000000..49621ac93 --- /dev/null +++ b/src/renderer/src/studio/NoiseCanvas.tsx @@ -0,0 +1,82 @@ +import { useEffect, useRef } from 'react' +import type { BridgeClient } from '../bridge/BridgeClient' +import { NoiseController, type NoiseListener } from '../noise/NoiseController' + +interface NoiseCanvasProps { + client: BridgeClient + controllerRef: React.RefObject + listener: NoiseListener + className?: string +} + +// One wheel notch is about 100; this zooms about 15% per notch, and smoothly on touchpads. +const WHEEL_ZOOM_PER_DELTA = 0.002 + +/** The noise from above: drag to move, wheel to zoom. */ +export function NoiseCanvas({ client, controllerRef, listener, className }: NoiseCanvasProps): React.JSX.Element { + const canvasRef = useRef(null) + const latestListener = useRef(listener) + latestListener.current = listener + + useEffect(() => { + const canvas = canvasRef.current! + const noise = new NoiseController(canvas, client, { + onStatus: (status) => latestListener.current.onStatus(status), + onError: (message) => latestListener.current.onError(message) + }) + controllerRef.current = noise + const resize = new ResizeObserver(([entry]) => noise.resize(entry.contentRect.width, entry.contentRect.height)) + resize.observe(canvas) + const stopMouse = followMouse(canvas, noise) + return () => { + stopMouse() + resize.disconnect() + noise.close() + controllerRef.current = null + } + }, [client, controllerRef]) + + return +} + +function followMouse(canvas: HTMLCanvasElement, noise: NoiseController): () => void { + let last: { x: number; y: number } | null = null + const pointOf = (event: MouseEvent): { x: number; y: number } => { + const bounds = canvas.getBoundingClientRect() + return { x: event.clientX - bounds.left, y: event.clientY - bounds.top } + } + const down = (event: PointerEvent): void => { + if (event.button === 0) { + canvas.setPointerCapture(event.pointerId) + last = { x: event.clientX, y: event.clientY } + } + } + const move = (event: PointerEvent): void => { + noise.setCursor(pointOf(event)) + if (last !== null) { + noise.panBy(event.clientX - last.x, event.clientY - last.y) + last = { x: event.clientX, y: event.clientY } + } + } + const up = (): void => { + last = null + } + const leave = (): void => noise.setCursor(null) + const wheel = (event: WheelEvent): void => { + event.preventDefault() + const point = pointOf(event) + noise.zoomAt(2 ** (-event.deltaY * WHEEL_ZOOM_PER_DELTA), point.x, point.y) + } + canvas.addEventListener('pointerdown', down) + canvas.addEventListener('pointermove', move) + canvas.addEventListener('pointerup', up) + canvas.addEventListener('pointerleave', leave) + canvas.addEventListener('wheel', wheel, { passive: false }) + return () => { + canvas.removeEventListener('pointerdown', down) + canvas.removeEventListener('pointermove', move) + canvas.removeEventListener('pointerup', up) + canvas.removeEventListener('pointerleave', leave) + canvas.removeEventListener('wheel', wheel) + } +} diff --git a/src/renderer/src/studio/NoiseStudio.tsx b/src/renderer/src/studio/NoiseStudio.tsx new file mode 100644 index 000000000..7fe0d1e49 --- /dev/null +++ b/src/renderer/src/studio/NoiseStudio.tsx @@ -0,0 +1,348 @@ +import { Dices, RotateCcw, Search } from 'lucide-react' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { ScrollArea } from '@/components/ui/scroll-area' +import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group' +import { cn } from '@/lib/utils' +import type { BridgeClient } from '../bridge/BridgeClient' +import type { NoiseSource, NoiseTile } from '../bridge/types' +import { NOISE_TILE_PIXELS, type NoiseController, type NoiseStatus } from '../noise/NoiseController' +import { NOISE_PALETTES, noiseScale, type NoisePaletteId, type NoiseScale } from '../noise/noiseScale' +import { NoiseTerrain, type NoiseArea } from '../noise/noiseTerrain' +import { buildTerrainMesh } from '../scene/terrainMesh' +import { hexColor } from './colors' +import { NoiseCanvas } from './NoiseCanvas' +import { SceneViewport } from './SceneViewport' + +type NoiseDisplay = 'flat' | 'terrain' + +const NUMBER = new Intl.NumberFormat('en-US', { maximumFractionDigits: 3 }) +const DEFAULT_SEED = '12345' +const TERRAIN_TILES_PER_SIDE = 4 +const LOWEST_RELIEF_BLOCKS = 1 +const TALLEST_RELIEF_BLOCKS = 4064 +const DEFAULT_RELIEF_BLOCKS = 64 +const RELIEF_STEPS = 1000 +const SWATCH_STEPS = 24 +const TOGGLE_ITEM = 'h-7 px-3 text-[12px] data-[state=on]:bg-selection data-[state=on]:text-foreground' +const PILL = 'pointer-events-none absolute rounded-md border border-overlay-border bg-card/90 px-3 py-1.5 text-[12px] text-secondary-text' + +interface NoiseStudioProps { + client: BridgeClient + packRevision: number + onSummary(summary: string | null): void + tell(message: string): void +} + +/** The pack's noise and the built-in styles, from above or as terrain (v3e's noise explorer). */ +export function NoiseStudio({ client, packRevision, onSummary, tell }: NoiseStudioProps): React.JSX.Element { + const sources = useNoiseSources(client, packRevision, tell) + const [chosenId, setChosenId] = useState(null) + const source = sources.find((candidate) => candidate.id === chosenId) ?? sources[0] ?? null + const [seed, setSeed] = useState(DEFAULT_SEED) + const [paletteId, setPaletteId] = useState('terrain') + const [display, setDisplay] = useState('flat') + const [reliefBlocks, setReliefBlocks] = useState(DEFAULT_RELIEF_BLOCKS) + const [status, setStatus] = useState(null) + const [terrainFraming, setTerrainFraming] = useState(null) + const controllerRef = useRef(null) + const scale = useMemo(() => noiseScale(paletteId, source), [paletteId, source]) + const listener = useMemo(() => ({ onStatus: setStatus, onError: tell }), [tell]) + + useEffect(() => { + const layer = source === null ? null : { sourceId: source.id, seed, revision: packRevision } + controllerRef.current?.show(layer, { key: `${paletteId}/${source?.blockRange?.lowest}/${source?.blockRange?.highest}`, scale }) + }, [source, seed, packRevision, paletteId, scale]) + + const showAs = useCallback((next: NoiseDisplay) => { + setDisplay(next) + if (next === 'terrain') { + setTerrainFraming(controllerRef.current?.framing() ?? null) + } + }, []) + + useEffect(() => { + if (source === null) { + onSummary(null) + return + } + const seedText = source.usesSeed ? `seed ${seed}` : "the world's seed" + onSummary(`${source.name} · ${seedText}`) + }, [source, seed, onSummary]) + useEffect(() => () => onSummary(null), [onSummary]) + + return ( + <> +
+ + {display === 'terrain' && source !== null && terrainFraming !== null && ( + + )} +
+ value !== '' && showAs(value as NoiseDisplay)}> + + 2D + + + 3D + + + {display === 'flat' && ( + + )} + {display === 'terrain' && source?.blockRange === null && } +
+ {display === 'flat' && status !== null && source !== null &&
{readout(status, source)}
} +
+ + + ) +} + +function readout(status: NoiseStatus, source: NoiseSource): string { + const spot = `${Math.floor(status.cursorX)}, ${Math.floor(status.cursorZ)}` + if (status.value === null) { + return spot + } + const value = NUMBER.format(status.value) + return `${spot} · ${source.blockRange === null ? value : `${value} blocks`}` +} + +function SeedField({ seed, usesSeed, onChange }: { seed: string; usesSeed: boolean; onChange(seed: string): void }): React.JSX.Element { + const [draft, setDraft] = useState(seed) + useEffect(() => setDraft(seed), [seed]) + const commit = (): void => { + const trimmed = draft.trim() + if (/^-?\d{1,19}$/.test(trimmed) && isLong(trimmed)) { + onChange(trimmed) + } else { + setDraft(seed) + } + } + return ( +
+

Seed

+
+ setDraft(event.target.value)} + onBlur={commit} + onKeyDown={(event) => event.key === 'Enter' && commit()} + /> + +
+ {!usesSeed &&

Keeps the world's seed

} +
+ ) +} + +const LONG_LIMIT = 2n ** 63n + +function isLong(text: string): boolean { + const value = BigInt(text) + return value >= -LONG_LIMIT && value < LONG_LIMIT +} + +function randomSeed(): string { + const [high, low] = crypto.getRandomValues(new Uint32Array(2)) + return BigInt.asIntN(64, (BigInt(high) << 32n) | BigInt(low)).toString() +} + +function PaletteList({ + current, + source, + scale, + onSelect +}: { + current: NoisePaletteId + source: NoiseSource | null + scale: NoiseScale + onSelect(palette: NoisePaletteId): void +}): React.JSX.Element { + return ( +
+

Palette

+ {NOISE_PALETTES.map((palette) => ( + + ))} +

+ {NUMBER.format(scale.minimum)} + {source?.blockRange === null ? '' : 'blocks above the fluid'} + {NUMBER.format(scale.maximum)} +

+
+ ) +} + +function gradientOf(scale: NoiseScale): string { + const stops = Array.from({ length: SWATCH_STEPS + 1 }, (_, step) => hexColor(scale.colorAlong(step / SWATCH_STEPS))) + return `linear-gradient(to right, ${stops.join(', ')})` +} + +function SourceList({ sources, current, onSelect }: { sources: NoiseSource[]; current: string | null; onSelect(id: string): void }): React.JSX.Element { + const [filter, setFilter] = useState('') + const shown = sources.filter((source) => source.name.toLowerCase().includes(filter.trim().toLowerCase())) + const categories = [...new Set(shown.map((source) => source.category))] + return ( +
+
+ + setFilter(event.target.value)} /> +
+ +
+ {categories.map((category) => ( +
+

{category}

+ {shown + .filter((source) => source.category === category) + .map((source) => ( + + ))} +
+ ))} + {shown.length === 0 &&

Nothing to show

} +
+
+
+ ) +} + +/** How many blocks the highest noise rises above the lowest, on a scale that gives low reliefs room. */ +function ReliefControl({ blocks, onChange }: { blocks: number; onChange(blocks: number): void }): React.JSX.Element { + const span = Math.log(TALLEST_RELIEF_BLOCKS) - Math.log(LOWEST_RELIEF_BLOCKS) + const step = Math.round(((Math.log(blocks) - Math.log(LOWEST_RELIEF_BLOCKS)) / span) * RELIEF_STEPS) + return ( + + ) +} + +interface TerrainFraming { + centerX: number + centerZ: number + renderScale: number +} + +function NoiseTerrainView({ + client, + source, + seed, + revision, + framing, + scale, + reliefBlocks, + tell +}: { + client: BridgeClient + source: NoiseSource + seed: string + revision: number + framing: TerrainFraming + scale: NoiseScale + reliefBlocks: number + tell(message: string): void +}): React.JSX.Element { + const area = useNoiseArea(client, source.id, seed, revision, framing, tell) + const mesh = useMemo(() => (area === null ? null : buildTerrainMesh(new NoiseTerrain(area, source, scale, reliefBlocks))), [area, source, scale, reliefBlocks]) + useEffect(() => () => mesh?.dispose(), [mesh]) + return ( +
+ + {area === null &&
Sampling {source.name}
} +
+ ) +} + +/** The square of tiles around where the 2D view looked, at the scale it drew; every tile arrives before it is shown. */ +function useNoiseArea( + client: BridgeClient, + sourceId: string, + seed: string, + revision: number, + framing: TerrainFraming, + tell: (message: string) => void +): NoiseArea | null { + const [area, setArea] = useState(null) + useEffect(() => { + const stop = new AbortController() + const tileBlocks = NOISE_TILE_PIXELS * framing.renderScale + const firstTileX = Math.floor(framing.centerX / tileBlocks - TERRAIN_TILES_PER_SIDE / 2) + const firstTileZ = Math.floor(framing.centerZ / tileBlocks - TERRAIN_TILES_PER_SIDE / 2) + const rows = Array.from({ length: TERRAIN_TILES_PER_SIDE }, (_, row) => + Promise.all( + Array.from({ length: TERRAIN_TILES_PER_SIDE }, (_, column) => + client.noiseTile(sourceId, seed, firstTileX + column, firstTileZ + row, framing.renderScale, NOISE_TILE_PIXELS, stop.signal) + ) + ) + ) + setArea(null) + Promise.all(rows) + .then((tiles: NoiseTile[][]) => + setArea({ tiles, originX: firstTileX * tileBlocks, originZ: firstTileZ * tileBlocks, blocksPerValue: framing.renderScale }) + ) + .catch((failure: Error) => !stop.signal.aborted && tell(failure.message)) + return () => stop.abort() + }, [client, sourceId, seed, revision, framing, tell]) + return area +} + +function useNoiseSources(client: BridgeClient, packRevision: number, tell: (message: string) => void): NoiseSource[] { + const [sources, setSources] = useState([]) + useEffect(() => { + let active = true + client + .noiseSources() + .then((found) => active && setSources(found)) + .catch((failure: Error) => active && tell(failure.message)) + return () => { + active = false + } + }, [client, packRevision, tell]) + return sources +} diff --git a/src/renderer/src/studio/ViewList.tsx b/src/renderer/src/studio/ViewList.tsx index 6db760567..5734c8cc2 100644 --- a/src/renderer/src/studio/ViewList.tsx +++ b/src/renderer/src/studio/ViewList.tsx @@ -1,4 +1,4 @@ -import { Box, Gem, Globe, HardDrive, Map as MapIcon, Mountain, Shapes, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' +import { AudioWaveform, Box, Gem, Globe, HardDrive, Map as MapIcon, Mountain, Shapes, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' import { Kbd } from '@/components/ui/kbd' import { ScrollArea } from '@/components/ui/scroll-area' import { cn } from '@/lib/utils' @@ -11,6 +11,7 @@ const VIEW_ICONS: Record = { height: Mountain, world3d: Globe, savedWorld: HardDrive, + noise: AudioWaveform, landBiomes: Sprout, seaBiomes: Waves, caveBiomes: Gem, From 1aba4301539287da3a2871316ed8036a032efad6 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 02:39:48 +0100 Subject: [PATCH 09/12] Add the Palettes view Pattern views from the server get a view each: entries by biome with a search over names, a depth stepper, the entry's facts, and the blocks on screen. Tiles are a pixel per column from afar and each block's tinted top texture up close; spots a layer leaves empty read as nothing at this depth. The pan and zoom tile canvas the noise view had is now TiledView and TiledCanvas, shared by noise and palettes, and the entry list is shared with the scene views. --- src/renderer/src/bridge/BridgeClient.ts | 42 +++- .../src/bridge/patternDecoding.test.ts | 25 +++ src/renderer/src/bridge/patternDecoding.ts | 25 +++ src/renderer/src/bridge/types.ts | 28 ++- src/renderer/src/map/TiledView.ts | 188 ++++++++++++++++ src/renderer/src/noise/NoiseController.ts | 206 ----------------- src/renderer/src/noise/noiseTiles.ts | 77 +++++++ src/renderer/src/pattern/patternTiles.ts | 152 +++++++++++++ src/renderer/src/scene/blockColors.ts | 59 +++-- src/renderer/src/studio/EntryBrowser.tsx | 76 +++++++ src/renderer/src/studio/MapStudio.tsx | 31 ++- src/renderer/src/studio/NoiseStudio.tsx | 27 ++- src/renderer/src/studio/PatternStudio.tsx | 209 ++++++++++++++++++ src/renderer/src/studio/SceneStudio.tsx | 71 +----- .../{NoiseCanvas.tsx => TiledCanvas.tsx} | 46 ++-- src/renderer/src/studio/ViewList.tsx | 5 +- 16 files changed, 921 insertions(+), 346 deletions(-) create mode 100644 src/renderer/src/bridge/patternDecoding.test.ts create mode 100644 src/renderer/src/bridge/patternDecoding.ts create mode 100644 src/renderer/src/map/TiledView.ts delete mode 100644 src/renderer/src/noise/NoiseController.ts create mode 100644 src/renderer/src/noise/noiseTiles.ts create mode 100644 src/renderer/src/pattern/patternTiles.ts create mode 100644 src/renderer/src/studio/EntryBrowser.tsx create mode 100644 src/renderer/src/studio/PatternStudio.tsx rename src/renderer/src/studio/{NoiseCanvas.tsx => TiledCanvas.tsx} (56%) diff --git a/src/renderer/src/bridge/BridgeClient.ts b/src/renderer/src/bridge/BridgeClient.ts index be9774ac9..142a0b005 100644 --- a/src/renderer/src/bridge/BridgeClient.ts +++ b/src/renderer/src/bridge/BridgeClient.ts @@ -1,5 +1,6 @@ import type { BridgeConnection } from '../../../shared/bridge' import { decodeScene, type BlockScene } from '../scene/sceneDecoding' +import { decodePattern } from './patternDecoding' import { decodeSavedTile } from './savedTileDecoding' import { decodeTile } from './tileDecoding' import type { @@ -7,14 +8,16 @@ import type { MapLabel, MapTile, Marker, + ModuleViewInfo, NoiseSource, NoiseTile, + PatternEntry, + PatternTile, PickInspection, SavedStart, SavedTile, SavedWorldInfo, SceneEntry, - SceneViewInfo, WorldInfo } from './types' @@ -42,6 +45,17 @@ export interface TileRequest { pickNoise: boolean } +/** One tile of a pattern: tile (x, z) covers columns × blocksPerColumn blocks from x × that, z × that. */ +export interface PatternRequest { + viewId: string + key: string + depth: number + tileX: number + tileZ: number + blocksPerColumn: number + columns: number +} + /** What a map spot or area is asked about: a view, and the region it previews. */ export interface MapLayerQuery { view: string @@ -120,7 +134,7 @@ export class BridgeClient { } /** The scene views the pack's modules show, such as its objects. */ - sceneViews(): Promise { + sceneViews(): Promise { return this.json('scenes') } @@ -133,6 +147,30 @@ export class BridgeClient { return decodeScene(await response.arrayBuffer()) } + /** The pattern views the pack's modules show, such as its palettes. */ + patternViews(): Promise { + return this.json('patterns') + } + + patternEntries(viewId: string): Promise { + return this.json(`pattern-entries?${new URLSearchParams({ view: viewId })}`) + } + + /** What an entry places at {@code depth} below the top across one tile, a column every {@code blocksPerColumn} blocks. */ + async pattern(request: PatternRequest, signal: AbortSignal): Promise { + const query = new URLSearchParams({ + view: request.viewId, + key: request.key, + depth: String(request.depth), + x: String(request.tileX), + z: String(request.tileZ), + scale: String(request.blocksPerColumn), + size: String(request.columns) + }) + const response = await this.fetch(`pattern?${query}`, { signal }) + return decodePattern(await response.arrayBuffer()) + } + /** The worlds saved on the server's disk. */ savedWorlds(): Promise { return this.json('saved-worlds') diff --git a/src/renderer/src/bridge/patternDecoding.test.ts b/src/renderer/src/bridge/patternDecoding.test.ts new file mode 100644 index 000000000..7921cf6a3 --- /dev/null +++ b/src/renderer/src/bridge/patternDecoding.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from 'vitest' +import { decodePattern } from './patternDecoding' +import { NO_PATTERN_BLOCK } from './types' + +function encodedPattern(header: object, picks: number[]): ArrayBuffer { + const headerBytes = new TextEncoder().encode(JSON.stringify(header)) + const picksAt = Math.ceil((4 + headerBytes.length) / 4) * 4 + const buffer = new ArrayBuffer(picksAt + picks.length * 2) + const view = new DataView(buffer) + view.setUint32(0, headerBytes.length, true) + new Uint8Array(buffer, 4).set(headerBytes) + picks.forEach((pick, index) => view.setInt16(picksAt + index * 2, pick, true)) + return buffer +} + +describe('decodePattern', () => { + it('reads the picks after the padded header, row by row, with no block as -1', () => { + const header = { columns: 2, blocksPerColumn: 4, blocks: ['minecraft:grass_block[snowy=false]', 'minecraft:dirt'], noBlock: -1 } + const pattern = decodePattern(encodedPattern(header, [0, -1, 1, 0])) + expect(pattern.columns).toBe(2) + expect(pattern.blocksPerColumn).toBe(4) + expect(pattern.blocks).toEqual(header.blocks) + expect([...pattern.picks]).toEqual([0, NO_PATTERN_BLOCK, 1, 0]) + }) +}) diff --git a/src/renderer/src/bridge/patternDecoding.ts b/src/renderer/src/bridge/patternDecoding.ts new file mode 100644 index 000000000..a31b0e434 --- /dev/null +++ b/src/renderer/src/bridge/patternDecoding.ts @@ -0,0 +1,25 @@ +import type { PatternTile } from './types' + +const ALIGNMENT_BYTES = 4 + +interface PatternHeader { + columns: number + blocksPerColumn: number + blocks: string[] +} + +/** + * Reads a pattern as the bridge writes it (PatternEncoding): a u32 header length, the JSON header, then from the next + * multiple of 4 bytes an i16 pick per column, row by row. The picks are a view into the buffer, not a copy. + */ +export function decodePattern(buffer: ArrayBuffer): PatternTile { + const headerLength = new DataView(buffer).getUint32(0, true) + const header = JSON.parse(new TextDecoder().decode(new Uint8Array(buffer, 4, headerLength))) as PatternHeader + const picksAt = Math.ceil((4 + headerLength) / ALIGNMENT_BYTES) * ALIGNMENT_BYTES + return { + columns: header.columns, + blocksPerColumn: header.blocksPerColumn, + blocks: header.blocks, + picks: new Int16Array(buffer, picksAt, header.columns * header.columns) + } +} diff --git a/src/renderer/src/bridge/types.ts b/src/renderer/src/bridge/types.ts index b3e256bbf..7b24d5887 100644 --- a/src/renderer/src/bridge/types.ts +++ b/src/renderer/src/bridge/types.ts @@ -18,8 +18,8 @@ export interface ViewInfo { groupLabel: string } -/** A view of block scenes a module of the pack shows, such as its objects (IrisApi SceneView). */ -export interface SceneViewInfo { +/** A studio view a module of the pack shows (IrisApi StudioView): block scenes such as its objects, or patterns such as its palettes. */ +export interface ModuleViewInfo { id: string label: string description: string @@ -33,6 +33,30 @@ export interface SceneEntry { variants: number } +/** Something a pattern view lays out, such as one of a biome's palettes (IrisApi PatternEntry). */ +export interface PatternEntry { + key: string + name: string + /** The heading it is listed under, such as its biome. */ + group: string + /** How many depths below the top it has a pick for; at least 1. */ + depths: number + /** Short lines about it, such as its blocks and noise. */ + facts: string[] +} + +/** What a pattern entry places across a square of columns, row by row from the north west. */ +export interface PatternTile { + columns: number + blocksPerColumn: number + /** The block states the picks index, as BlockState keys. */ + blocks: string[] + /** Each column's block, or NO_PATTERN_BLOCK where the pattern places none. */ + picks: Int16Array +} + +export const NO_PATTERN_BLOCK = -1 + /** A world saved on the server's disk, a dimension folder of region files. */ export interface SavedWorldInfo { /** Its folder below the server's level folder. */ diff --git a/src/renderer/src/map/TiledView.ts b/src/renderer/src/map/TiledView.ts new file mode 100644 index 000000000..faedff9dc --- /dev/null +++ b/src/renderer/src/map/TiledView.ts @@ -0,0 +1,188 @@ +import { drawVisibleTiles } from './tileDrawing' +import { TileStore, type TileSource } from './TileStore' +import { + MAXIMUM_BLOCKS_PER_PIXEL, + MINIMUM_VIEW_BLOCKS_PER_PIXEL, + renderBlocksPerPixel, + screenToWorldX, + screenToWorldZ, + type TileAddress, + type Viewport +} from './viewport' + +export interface TiledViewOptions { + source: TileSource + tileSize: number + defaultBlocksPerPixel: number + /** The finest scale tiles are asked for at; closer views magnify them. */ + finestRenderBlocksPerPixel: number + /** How far the view may zoom out. */ + coarsestBlocksPerPixel?: number + onFrame(frame: TiledFrame): void + onError(message: string): void +} + +export interface TiledFrame { + blocksPerPixel: number + tilesReady: number + tilesTotal: number + /** The world spot under the cursor, or under the middle when the cursor is away. */ + cursorX: number + cursorZ: number +} + +/** A tile and the pixel of it at a world spot. */ +export interface TileSpot { + tile: Tile + pixelX: number + pixelZ: number +} + +/** Where a view looks and the scale its tiles are drawn at. */ +export interface TiledFraming { + centerX: number + centerZ: number + renderScale: number +} + +/** + * A pan and zoom view of tiles on a canvas, fetched as the view moves and drawn in the current style. Kept outside + * React, as it redraws on every drag and wheel step. + */ +export class TiledView { + private readonly context: CanvasRenderingContext2D + private readonly store: TileStore + private readonly view: Viewport + private layer: Layer | null = null + private style: Style | null = null + private cursor: { x: number; y: number } | null = null + private drawn = { tilesReady: 0, tilesTotal: 0 } + private frameRequested = false + private closed = false + + constructor( + private readonly canvas: HTMLCanvasElement, + private readonly options: TiledViewOptions + ) { + this.context = canvas.getContext('2d')! + this.view = { centerX: 0, centerZ: 0, blocksPerPixel: options.defaultBlocksPerPixel, width: 1, height: 1 } + this.store = new TileStore(options.source, () => this.redraw(), options.onError) + } + + close(): void { + this.closed = true + this.store.clear() + } + + resize(width: number, height: number): void { + const ratio = window.devicePixelRatio + this.canvas.width = Math.round(width * ratio) + this.canvas.height = Math.round(height * ratio) + this.view.width = width + this.view.height = height + this.redraw() + } + + show(layer: Layer | null, style: Style): void { + this.layer = layer + this.style = style + this.redraw() + } + + panBy(screenDeltaX: number, screenDeltaZ: number): void { + this.view.centerX -= screenDeltaX * this.view.blocksPerPixel + this.view.centerZ -= screenDeltaZ * this.view.blocksPerPixel + this.redraw() + } + + /** Zooms by {@code factor} (above 1 zooms in) keeping the spot under the screen point where it is. */ + zoomAt(factor: number, screenX = this.view.width / 2, screenZ = this.view.height / 2): void { + const worldX = screenToWorldX(this.view, screenX) + const worldZ = screenToWorldZ(this.view, screenZ) + const coarsest = this.options.coarsestBlocksPerPixel ?? MAXIMUM_BLOCKS_PER_PIXEL + this.view.blocksPerPixel = Math.min(coarsest, Math.max(MINIMUM_VIEW_BLOCKS_PER_PIXEL, this.view.blocksPerPixel / factor)) + this.view.centerX = worldX - (screenX - this.view.width / 2) * this.view.blocksPerPixel + this.view.centerZ = worldZ - (screenZ - this.view.height / 2) * this.view.blocksPerPixel + this.redraw() + } + + resetView(): void { + this.view.centerX = 0 + this.view.centerZ = 0 + this.view.blocksPerPixel = this.options.defaultBlocksPerPixel + this.redraw() + } + + setCursor(cursor: { x: number; y: number } | null): void { + this.cursor = cursor + this.reportFrame() + } + + framing(): TiledFraming { + return { centerX: this.view.centerX, centerZ: this.view.centerZ, renderScale: this.renderScale() } + } + + /** The tile drawn at a world spot at the current scale and its pixel there; null before it arrived. */ + spotAt(worldX: number, worldZ: number): TileSpot | null { + if (this.layer === null) { + return null + } + const scale = this.renderScale() + const span = this.options.tileSize * scale + const address: TileAddress = { tileX: Math.floor(worldX / span), tileZ: Math.floor(worldZ / span), blocksPerPixel: scale } + const tile = this.store.get(address, this.layer) + if (tile === null) { + return null + } + const last = this.options.tileSize - 1 + const pixelX = Math.min(last, Math.floor((worldX - address.tileX * span) / scale)) + const pixelZ = Math.min(last, Math.floor((worldZ - address.tileZ * span) / scale)) + return { tile, pixelX, pixelZ } + } + + private renderScale(): number { + return renderBlocksPerPixel(this.view.blocksPerPixel, window.devicePixelRatio, this.options.finestRenderBlocksPerPixel) + } + + private redraw(): void { + if (this.frameRequested || this.closed) { + return + } + this.frameRequested = true + requestAnimationFrame(() => { + this.frameRequested = false + if (!this.closed) { + this.draw() + } + }) + } + + private draw(): void { + const ratio = window.devicePixelRatio + const context = this.context + context.setTransform(ratio, 0, 0, ratio, 0, 0) + context.fillStyle = getComputedStyle(this.canvas).getPropertyValue('--map-background') || '#16171a' + context.fillRect(0, 0, this.view.width, this.view.height) + const layer = this.layer + const style = this.style + if (layer === null || style === null) { + this.drawn = { tilesReady: 0, tilesTotal: 0 } + this.reportFrame() + return + } + const drawn = drawVisibleTiles(context, this.view, this.renderScale(), this.options.tileSize, (address) => this.store.picture(address, layer, style)) + this.store.want(drawn.wanted, layer) + this.drawn = { tilesReady: drawn.ready, tilesTotal: drawn.tiles.length } + this.reportFrame() + } + + private reportFrame(): void { + const cursor = this.cursor ?? { x: this.view.width / 2, y: this.view.height / 2 } + this.options.onFrame({ + blocksPerPixel: this.view.blocksPerPixel, + ...this.drawn, + cursorX: screenToWorldX(this.view, cursor.x), + cursorZ: screenToWorldZ(this.view, cursor.y) + }) + } +} diff --git a/src/renderer/src/noise/NoiseController.ts b/src/renderer/src/noise/NoiseController.ts deleted file mode 100644 index ca8a71d96..000000000 --- a/src/renderer/src/noise/NoiseController.ts +++ /dev/null @@ -1,206 +0,0 @@ -import type { BridgeClient } from '../bridge/BridgeClient' -import type { NoiseTile } from '../bridge/types' -import { drawVisibleTiles } from '../map/tileDrawing' -import { TileStore, type TileSource } from '../map/TileStore' -import { clampBlocksPerPixel, renderBlocksPerPixel, screenToWorldX, screenToWorldZ, type TileAddress, type Viewport } from '../map/viewport' -import type { NoiseScale } from './noiseScale' - -/** Which noise the tiles hold. */ -export interface NoiseLayer { - sourceId: string - /** A 64 bit seed, as text so no digit is lost. */ - seed: string - /** Bumped when the pack is hotloaded, so older tiles are not used again. */ - revision: number -} - -export interface NoiseStyle { - /** Tells styles apart, so a tile is recoloured only when its style changed. */ - key: string - scale: NoiseScale -} - -export interface NoiseStatus { - blocksPerPixel: number - tilesReady: number - tilesTotal: number - cursorX: number - cursorZ: number - /** The noise at the cursor, or null before its tile arrived. */ - value: number | null -} - -export interface NoiseListener { - onStatus(status: NoiseStatus): void - onError(message: string): void -} - -export const NOISE_TILE_PIXELS = 128 -const DEFAULT_NOISE_BLOCKS_PER_PIXEL = 1 -// Noise has detail finer than a block, so it is drawn finer than the world map's one block per pixel. -const FINEST_NOISE_BLOCKS_PER_PIXEL = 1 / 16 - -function noiseTileSource(client: BridgeClient): TileSource { - return { - layerKey: (layer) => `${layer.revision}/${layer.sourceId}/${layer.seed}`, - fetch: (address, layer, signal) => - client.noiseTile(layer.sourceId, layer.seed, address.tileX, address.tileZ, address.blocksPerPixel, NOISE_TILE_PIXELS, signal), - bytesOf: (tile) => tile.values.byteLength + tile.size * tile.size * 4, - styleKey: (style) => style.key, - pixels: (tile, style) => noisePixels(tile, style.scale) - } -} - -function noisePixels(tile: NoiseTile, scale: NoiseScale): ImageData { - const pixels = new ImageData(tile.size, tile.size) - for (let index = 0; index < tile.values.length; index++) { - const color = scale.colorOf(tile.values[index]) - pixels.data[index * 4] = (color >> 16) & 0xff - pixels.data[index * 4 + 1] = (color >> 8) & 0xff - pixels.data[index * 4 + 2] = color & 0xff - pixels.data[index * 4 + 3] = 0xff - } - return pixels -} - -/** The noise from above on a canvas, fetched in tiles as the view moves. Kept outside React, as it redraws on every drag. */ -export class NoiseController { - private readonly context: CanvasRenderingContext2D - private readonly store: TileStore - private readonly view: Viewport = { centerX: 0, centerZ: 0, blocksPerPixel: DEFAULT_NOISE_BLOCKS_PER_PIXEL, width: 1, height: 1 } - private layer: NoiseLayer | null = null - private style: NoiseStyle | null = null - private cursor: { x: number; y: number } | null = null - private lastReady = 0 - private lastTotal = 0 - private frameRequested = false - private closed = false - - constructor( - private readonly canvas: HTMLCanvasElement, - client: BridgeClient, - private readonly listener: NoiseListener - ) { - this.context = canvas.getContext('2d')! - this.store = new TileStore(noiseTileSource(client), () => this.redraw(), (message) => listener.onError(message)) - } - - close(): void { - this.closed = true - this.store.clear() - } - - resize(width: number, height: number): void { - const ratio = window.devicePixelRatio - this.canvas.width = Math.round(width * ratio) - this.canvas.height = Math.round(height * ratio) - this.view.width = width - this.view.height = height - this.redraw() - } - - show(layer: NoiseLayer | null, style: NoiseStyle): void { - this.layer = layer - this.style = style - this.redraw() - } - - panBy(screenDeltaX: number, screenDeltaZ: number): void { - this.view.centerX -= screenDeltaX * this.view.blocksPerPixel - this.view.centerZ -= screenDeltaZ * this.view.blocksPerPixel - this.redraw() - } - - /** Zooms by {@code factor} (above 1 zooms in) keeping the spot under the screen point where it is. */ - zoomAt(factor: number, screenX = this.view.width / 2, screenZ = this.view.height / 2): void { - const worldX = screenToWorldX(this.view, screenX) - const worldZ = screenToWorldZ(this.view, screenZ) - this.view.blocksPerPixel = clampBlocksPerPixel(this.view.blocksPerPixel / factor) - this.view.centerX = worldX - (screenX - this.view.width / 2) * this.view.blocksPerPixel - this.view.centerZ = worldZ - (screenZ - this.view.height / 2) * this.view.blocksPerPixel - this.redraw() - } - - resetView(): void { - this.view.centerX = 0 - this.view.centerZ = 0 - this.view.blocksPerPixel = DEFAULT_NOISE_BLOCKS_PER_PIXEL - this.redraw() - } - - setCursor(cursor: { x: number; y: number } | null): void { - this.cursor = cursor - this.reportStatus() - } - - /** Where the view looks and the scale its tiles are drawn at, for the 3D view to sample the same noise. */ - framing(): { centerX: number; centerZ: number; renderScale: number } { - return { centerX: this.view.centerX, centerZ: this.view.centerZ, renderScale: this.renderScale() } - } - - private renderScale(): number { - return renderBlocksPerPixel(this.view.blocksPerPixel, window.devicePixelRatio, FINEST_NOISE_BLOCKS_PER_PIXEL) - } - - private redraw(): void { - if (this.frameRequested || this.closed) { - return - } - this.frameRequested = true - requestAnimationFrame(() => { - this.frameRequested = false - if (!this.closed) { - this.draw() - } - }) - } - - private draw(): void { - const ratio = window.devicePixelRatio - const context = this.context - context.setTransform(ratio, 0, 0, ratio, 0, 0) - context.fillStyle = getComputedStyle(this.canvas).getPropertyValue('--map-background') || '#16171a' - context.fillRect(0, 0, this.view.width, this.view.height) - const layer = this.layer - const style = this.style - if (layer === null || style === null) { - this.reportStatus(0, 0) - return - } - const drawn = drawVisibleTiles(context, this.view, this.renderScale(), NOISE_TILE_PIXELS, (address) => this.store.picture(address, layer, style)) - this.store.want(drawn.wanted, layer) - this.reportStatus(drawn.ready, drawn.tiles.length) - } - - private valueAt(worldX: number, worldZ: number): number | null { - if (this.layer === null) { - return null - } - const scale = this.renderScale() - const span = NOISE_TILE_PIXELS * scale - const address: TileAddress = { tileX: Math.floor(worldX / span), tileZ: Math.floor(worldZ / span), blocksPerPixel: scale } - const tile = this.store.get(address, this.layer) - if (tile === null) { - return null - } - const pixelX = Math.min(tile.size - 1, Math.floor((worldX - address.tileX * span) / scale)) - const pixelZ = Math.min(tile.size - 1, Math.floor((worldZ - address.tileZ * span) / scale)) - return tile.values[pixelZ * tile.size + pixelX] - } - - private reportStatus(ready = this.lastReady, total = this.lastTotal): void { - this.lastReady = ready - this.lastTotal = total - const cursor = this.cursor ?? { x: this.view.width / 2, y: this.view.height / 2 } - const worldX = screenToWorldX(this.view, cursor.x) - const worldZ = screenToWorldZ(this.view, cursor.y) - this.listener.onStatus({ - blocksPerPixel: this.view.blocksPerPixel, - tilesReady: ready, - tilesTotal: total, - cursorX: worldX, - cursorZ: worldZ, - value: this.valueAt(worldX, worldZ) - }) - } -} diff --git a/src/renderer/src/noise/noiseTiles.ts b/src/renderer/src/noise/noiseTiles.ts new file mode 100644 index 000000000..a2fa4ae4c --- /dev/null +++ b/src/renderer/src/noise/noiseTiles.ts @@ -0,0 +1,77 @@ +import type { BridgeClient } from '../bridge/BridgeClient' +import type { NoiseTile } from '../bridge/types' +import { TiledView, type TiledFrame } from '../map/TiledView' +import type { TileSource } from '../map/TileStore' +import type { NoiseScale } from './noiseScale' + +/** Which noise the tiles hold. */ +export interface NoiseLayer { + sourceId: string + /** A 64 bit seed, as text so no digit is lost. */ + seed: string + /** Bumped when the pack is hotloaded, so older tiles are not used again. */ + revision: number +} + +export interface NoiseStyle { + /** Tells styles apart, so a tile is recoloured only when its style changed. */ + key: string + scale: NoiseScale +} + +export type NoiseView = TiledView + +export interface NoiseStatus extends TiledFrame { + /** The noise at the cursor, or null before its tile arrived. */ + value: number | null +} + +export interface NoiseListener { + onStatus(status: NoiseStatus): void + onError(message: string): void +} + +export const NOISE_TILE_PIXELS = 128 +const DEFAULT_NOISE_BLOCKS_PER_PIXEL = 1 +// Noise has detail finer than a block, so it is drawn finer than the world map's one block per pixel. +const FINEST_NOISE_BLOCKS_PER_PIXEL = 1 / 16 + +export function createNoiseView(canvas: HTMLCanvasElement, client: BridgeClient, listener: NoiseListener): NoiseView { + const view: NoiseView = new TiledView(canvas, { + source: noiseTileSource(client), + tileSize: NOISE_TILE_PIXELS, + defaultBlocksPerPixel: DEFAULT_NOISE_BLOCKS_PER_PIXEL, + finestRenderBlocksPerPixel: FINEST_NOISE_BLOCKS_PER_PIXEL, + onFrame: (frame) => listener.onStatus({ ...frame, value: valueAt(view, frame.cursorX, frame.cursorZ) }), + onError: (message) => listener.onError(message) + }) + return view +} + +function valueAt(view: NoiseView, worldX: number, worldZ: number): number | null { + const spot = view.spotAt(worldX, worldZ) + return spot === null ? null : spot.tile.values[spot.pixelZ * spot.tile.size + spot.pixelX] +} + +function noiseTileSource(client: BridgeClient): TileSource { + return { + layerKey: (layer) => `${layer.revision}/${layer.sourceId}/${layer.seed}`, + fetch: (address, layer, signal) => + client.noiseTile(layer.sourceId, layer.seed, address.tileX, address.tileZ, address.blocksPerPixel, NOISE_TILE_PIXELS, signal), + bytesOf: (tile) => tile.values.byteLength + tile.size * tile.size * 4, + styleKey: (style) => style.key, + pixels: (tile, style) => noisePixels(tile, style.scale) + } +} + +function noisePixels(tile: NoiseTile, scale: NoiseScale): ImageData { + const pixels = new ImageData(tile.size, tile.size) + for (let index = 0; index < tile.values.length; index++) { + const color = scale.colorOf(tile.values[index]) + pixels.data[index * 4] = (color >> 16) & 0xff + pixels.data[index * 4 + 1] = (color >> 8) & 0xff + pixels.data[index * 4 + 2] = color & 0xff + pixels.data[index * 4 + 3] = 0xff + } + return pixels +} diff --git a/src/renderer/src/pattern/patternTiles.ts b/src/renderer/src/pattern/patternTiles.ts new file mode 100644 index 000000000..eff5e4e0b --- /dev/null +++ b/src/renderer/src/pattern/patternTiles.ts @@ -0,0 +1,152 @@ +import type { BridgeClient } from '../bridge/BridgeClient' +import { NO_PATTERN_BLOCK, type PatternTile } from '../bridge/types' +import { TiledView, type TiledFrame } from '../map/TiledView' +import type { TileSource } from '../map/TileStore' +import type { TileAddress } from '../map/viewport' +import type { BlockColors } from '../scene/blockColors' + +/** Which entry, at which depth, the tiles lay out. */ +export interface PatternLayer { + viewId: string + key: string + depth: number + /** Bumped when the pack is hotloaded, so older tiles are not used again. */ + revision: number +} + +/** A pattern tile with what it needs to be drawn: each block's colour, and its texture once a block spans pixels. */ +export interface PatternPicture { + pattern: PatternTile + colors: number[] + /** Per block, its top texture; empty while a block is a pixel or smaller. */ + textures: (ImageData | null)[] + /** How many pixels across a column is drawn; 1 when it is a pixel or smaller. */ + pixelsPerColumn: number +} + +/** Patterns have one look; the style only satisfies the tile store. */ +export type PatternStyle = 'blocks' +export type PatternView = TiledView + +/** What is under the cursor: a block, nothing placed there, or not known before its tile arrived. */ +export type PatternSpot = { kind: 'block'; block: string } | { kind: 'none' } | { kind: 'unknown' } + +export interface PatternStatus extends TiledFrame { + spot: PatternSpot +} + +/** The blocks a tile placed with their colours, and whether it left some columns without a block. */ +export interface PatternBlocks { + colors: Map + someNone: boolean +} + +export interface PatternListener { + onStatus(status: PatternStatus): void + /** What a tile of the layer showed, for the legend. */ + onBlocks(layer: PatternLayer, blocks: PatternBlocks): void + onError(message: string): void +} + +export const PATTERN_TILE_PIXELS = 128 +const DEFAULT_PATTERN_BLOCKS_PER_PIXEL = 1 +// A block texture is 16 pixels across; drawing a block that wide shows it whole. +const FINEST_PATTERN_BLOCKS_PER_PIXEL = 1 / 16 +// The bridge lays out a column at most every 64 blocks; views stop a level short so their previews stay within it. +const COARSEST_PATTERN_BLOCKS_PER_PIXEL = 32 +const NO_COLOR = 0x000000 +const OPAQUE = 0xff +const OPAQUE_ENOUGH_ALPHA = 128 + +export function createPatternView(canvas: HTMLCanvasElement, client: BridgeClient, blockColors: BlockColors, listener: PatternListener): PatternView { + const view: PatternView = new TiledView(canvas, { + source: patternTileSource(client, blockColors, listener), + tileSize: PATTERN_TILE_PIXELS, + defaultBlocksPerPixel: DEFAULT_PATTERN_BLOCKS_PER_PIXEL, + finestRenderBlocksPerPixel: FINEST_PATTERN_BLOCKS_PER_PIXEL, + coarsestBlocksPerPixel: COARSEST_PATTERN_BLOCKS_PER_PIXEL, + onFrame: (frame) => listener.onStatus({ ...frame, spot: spotAt(view, frame.cursorX, frame.cursorZ) }), + onError: (message) => listener.onError(message) + }) + return view +} + +function spotAt(view: PatternView, worldX: number, worldZ: number): PatternSpot { + const spot = view.spotAt(worldX, worldZ) + if (spot === null) { + return { kind: 'unknown' } + } + const { pattern, pixelsPerColumn } = spot.tile + const column = Math.floor(spot.pixelX / pixelsPerColumn) + const row = Math.floor(spot.pixelZ / pixelsPerColumn) + const pick = pattern.picks[row * pattern.columns + column] + return pick === NO_PATTERN_BLOCK ? { kind: 'none' } : { kind: 'block', block: pattern.blocks[pick] } +} + +function patternTileSource(client: BridgeClient, blockColors: BlockColors, listener: PatternListener): TileSource { + return { + layerKey: (layer) => `${layer.revision}/${layer.viewId}/${layer.key}/${layer.depth}`, + fetch: async (address, layer, signal) => { + const picture = await fetchPicture(client, blockColors, address, layer, signal) + listener.onBlocks(layer, { + colors: new Map(picture.pattern.blocks.map((block, index) => [block, picture.colors[index]])), + someNone: picture.pattern.picks.includes(NO_PATTERN_BLOCK) + }) + return picture + }, + bytesOf: (picture) => picture.pattern.picks.byteLength + PATTERN_TILE_PIXELS * PATTERN_TILE_PIXELS * 4, + styleKey: (style) => style, + pixels: (picture) => patternPixels(picture) + } +} + +/** + * A tile a pixel per column where a column is a pixel or more, and otherwise a column per block, each drawn a few + * pixels wide in its texture. + */ +async function fetchPicture(client: BridgeClient, blockColors: BlockColors, address: TileAddress, layer: PatternLayer, signal: AbortSignal): Promise { + const blocksPerColumn = Math.max(1, address.blocksPerPixel) + const pixelsPerColumn = Math.round(blocksPerColumn / address.blocksPerPixel) + const columns = PATTERN_TILE_PIXELS / pixelsPerColumn + const pattern = await client.pattern({ ...layer, tileX: address.tileX, tileZ: address.tileZ, blocksPerColumn, columns }, signal) + const colors = await Promise.all(pattern.blocks.map((block) => blockColors.colorOf(block))) + const textures = pixelsPerColumn > 1 ? await Promise.all(pattern.blocks.map((block) => blockColors.topTexture(block))) : [] + return { pattern, colors, textures, pixelsPerColumn } +} + +function patternPixels(picture: PatternPicture): ImageData { + const pixels = new ImageData(PATTERN_TILE_PIXELS, PATTERN_TILE_PIXELS) + const { pattern, pixelsPerColumn } = picture + for (let pixelZ = 0; pixelZ < PATTERN_TILE_PIXELS; pixelZ++) { + for (let pixelX = 0; pixelX < PATTERN_TILE_PIXELS; pixelX++) { + const pick = pattern.picks[Math.floor(pixelZ / pixelsPerColumn) * pattern.columns + Math.floor(pixelX / pixelsPerColumn)] + if (pick !== NO_PATTERN_BLOCK) { + writePixel(pixels, (pixelZ * PATTERN_TILE_PIXELS + pixelX) * 4, picture, pick, pixelX % pixelsPerColumn, pixelZ % pixelsPerColumn) + } + } + } + return pixels +} + +/** + * The block's texture at a spot within its column, and its colour where it has no texture or the texture is see + * through, such as between leaves, so a palette reads as solid ground. + */ +function writePixel(pixels: ImageData, offset: number, picture: PatternPicture, pick: number, insideX: number, insideZ: number): void { + const texture = picture.textures[pick] ?? null + if (texture !== null) { + const textureX = Math.floor((insideX * texture.width) / picture.pixelsPerColumn) + const textureZ = Math.floor((insideZ * texture.height) / picture.pixelsPerColumn) + const from = (textureZ * texture.width + textureX) * 4 + if (texture.data[from + 3] >= OPAQUE_ENOUGH_ALPHA) { + pixels.data.set(texture.data.subarray(from, from + 3), offset) + pixels.data[offset + 3] = OPAQUE + return + } + } + const color = picture.colors[pick] ?? NO_COLOR + pixels.data[offset] = (color >> 16) & 0xff + pixels.data[offset + 1] = (color >> 8) & 0xff + pixels.data[offset + 2] = color & 0xff + pixels.data[offset + 3] = OPAQUE +} diff --git a/src/renderer/src/scene/blockColors.ts b/src/renderer/src/scene/blockColors.ts index 9154879ce..fb26184fc 100644 --- a/src/renderer/src/scene/blockColors.ts +++ b/src/renderer/src/scene/blockColors.ts @@ -4,21 +4,33 @@ import { texturePath, type ImageSource } from './textureAtlas' const UNKNOWN_BLOCK_COLOR = 0x7f7f7f const OPAQUE_ENOUGH_ALPHA = 128 +const NO_TINT = 0xffffff -/** Each block's colour seen from above: its top face's texture averaged and tinted as the client tints it, read once. */ +/** Each block seen from above: its top face's texture tinted as the client tints it, and that texture's average colour, read once. */ export class BlockColors { - private readonly known = new Map>() + private readonly textures = new Map>() + private readonly colors = new Map>() constructor( private readonly models: BlockModels, private readonly images: ImageSource ) {} + /** The first frame of the block's top face texture, tinted; null when the block has no model or texture. */ + topTexture(block: string): Promise { + let texture = this.textures.get(block) + if (texture === undefined) { + texture = this.readTopTexture(block).catch(() => null) + this.textures.set(block, texture) + } + return texture + } + colorOf(block: string): Promise { - let color = this.known.get(block) + let color = this.colors.get(block) if (color === undefined) { - color = this.read(block).catch(() => UNKNOWN_BLOCK_COLOR) - this.known.set(block, color) + color = this.topTexture(block).then((texture) => (texture === null ? UNKNOWN_BLOCK_COLOR : averageColor(texture))) + this.colors.set(block, color) } return color } @@ -30,29 +42,47 @@ export class BlockColors { return new Map(names.map((name, index) => [name, colors[index]])) } - private async read(block: string): Promise { + private async readTopTexture(block: string): Promise { const model = await this.models.model(block) const top = model?.quads.filter((quad) => quad.facing === 'up').at(-1) const texture = top?.texture ?? model?.particle if (texture === undefined || texture === null) { - return UNKNOWN_BLOCK_COLOR + return null } const bitmap = await this.images.image(texturePath(texture)) if (bitmap === null) { - return UNKNOWN_BLOCK_COLOR + return null } const state = parseState(block) - return multiplied(averageColor(bitmap), blockTint(state.name, state.properties, top?.tintIndex ?? -1)) + return tinted(firstFrame(bitmap), blockTint(state.name, state.properties, top?.tintIndex ?? -1)) } } -// The first frame only: an animated texture stacks its frames downwards. -function averageColor(bitmap: ImageBitmap): number { +// An animated texture stacks its frames downwards. +function firstFrame(bitmap: ImageBitmap): ImageData { const side = bitmap.width const canvas = new OffscreenCanvas(side, side) const drawing = canvas.getContext('2d', { willReadFrequently: true })! drawing.drawImage(bitmap, 0, 0, side, side, 0, 0, side, side) - const pixels = drawing.getImageData(0, 0, side, side).data + return drawing.getImageData(0, 0, side, side) +} + +function tinted(texture: ImageData, tint: number): ImageData { + if (tint === NO_TINT) { + return texture + } + const pixels = texture.data + const [red, green, blue] = [(tint >> 16) & 0xff, (tint >> 8) & 0xff, tint & 0xff] + for (let offset = 0; offset < pixels.length; offset += 4) { + pixels[offset] = Math.round((pixels[offset] * red) / 255) + pixels[offset + 1] = Math.round((pixels[offset + 1] * green) / 255) + pixels[offset + 2] = Math.round((pixels[offset + 2] * blue) / 255) + } + return texture +} + +function averageColor(texture: ImageData): number { + const pixels = texture.data let [red, green, blue, counted] = [0, 0, 0, 0] for (let offset = 0; offset < pixels.length; offset += 4) { if (pixels[offset + 3] >= OPAQUE_ENOUGH_ALPHA) { @@ -67,8 +97,3 @@ function averageColor(bitmap: ImageBitmap): number { } return (Math.round(red / counted) << 16) | (Math.round(green / counted) << 8) | Math.round(blue / counted) } - -function multiplied(color: number, tint: number): number { - const channel = (shift: number): number => Math.round((((color >> shift) & 0xff) * ((tint >> shift) & 0xff)) / 255) - return (channel(16) << 16) | (channel(8) << 8) | channel(0) -} diff --git a/src/renderer/src/studio/EntryBrowser.tsx b/src/renderer/src/studio/EntryBrowser.tsx new file mode 100644 index 000000000..f2663fc0e --- /dev/null +++ b/src/renderer/src/studio/EntryBrowser.tsx @@ -0,0 +1,76 @@ +import { useMemo, useState } from 'react' +import { Input } from '@/components/ui/input' +import { ScrollArea } from '@/components/ui/scroll-area' +import { cn } from '@/lib/utils' + +const NUMBER = new Intl.NumberFormat('en-US') + +/** An entry of a module view: its key, the name it is listed by, and the heading it is listed under (empty for none). */ +export interface BrowsableEntry { + key: string + name: string + group: string +} + +interface EntryBrowserProps { + title: string + entries: BrowsableEntry[] + current: string | null + onSelect(key: string): void + className?: string +} + +/** A view's entries under their headings, with a search over keys, names and headings (v3e ObjectBrowser). */ +export function EntryBrowser({ title, entries, current, onSelect, className }: EntryBrowserProps): React.JSX.Element { + const [search, setSearch] = useState('') + const wanted = search.trim().toLowerCase() + const groups = useMemo(() => groupedEntries(entries, wanted), [entries, wanted]) + return ( +
+
+

{title}

+

{NUMBER.format(entries.length)} in the pack

+ setSearch(event.target.value)} + onKeyDown={(event) => event.key === 'Escape' && setSearch('')} + /> +
+ +
+ {groups.map(([group, members]) => ( +
+ {group !== '' &&

{group}

} + {members.map((entry) => ( + + ))} +
+ ))} + {groups.length === 0 &&

{entries.length === 0 ? 'Nothing to show' : 'Nothing matches'}

} +
+
+
+ ) +} + +function groupedEntries(entries: Entry[], wanted: string): [string, Entry[]][] { + const groups = new Map() + for (const entry of entries) { + if (wanted !== '' && ![entry.key, entry.name, entry.group].some((text) => text.toLowerCase().includes(wanted))) { + continue + } + const members = groups.get(entry.group) ?? [] + members.push(entry) + groups.set(entry.group, members) + } + return [...groups.entries()] +} diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx index 5d43af44f..762f4440e 100644 --- a/src/renderer/src/studio/MapStudio.tsx +++ b/src/renderer/src/studio/MapStudio.tsx @@ -1,7 +1,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import type { ThemeChoice } from '../../../shared/bridge' import type { BridgeClient, MapLayerQuery, WorldRect } from '../bridge/BridgeClient' -import type { MapHover, MapLabel, Marker, PickDisplay, PickInspection, SceneViewInfo, ViewInfo, WorldInfo } from '../bridge/types' +import type { MapHover, MapLabel, Marker, ModuleViewInfo, PickDisplay, PickInspection, ViewInfo, WorldInfo } from '../bridge/types' import type { Share } from '../map/census' import type { MapController, MapStatus, MapToggles } from '../map/MapController' import type { Highlight } from '../map/tileStyle' @@ -12,6 +12,7 @@ import { MapCanvas, type CanvasPoint } from './MapCanvas' import { PickInspector } from './PickInspector' import { RegionPreviewList } from './RegionPreviewList' import { NoiseStudio } from './NoiseStudio' +import { PatternStudio } from './PatternStudio' import { SavedWorldStudio } from './SavedWorldStudio' import { SceneStudio } from './SceneStudio' import { WorldStudio3D } from './WorldStudio3D' @@ -61,10 +62,17 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps const [area, setArea] = useState(null) const [packRevision, setPackRevision] = useState(0) const [sceneSummary, setSceneSummary] = useState(null) - const sceneViews = useSceneViews(client, packRevision) - const views = useMemo(() => [...withAppViews(world.views), ...sceneViews.map(asViewInfo), NOISE], [world.views, sceneViews]) + const loadSceneViews = useCallback(() => client.sceneViews(), [client]) + const loadPatternViews = useCallback(() => client.patternViews(), [client]) + const sceneViews = useModuleViews(loadSceneViews, packRevision) + const patternViews = useModuleViews(loadPatternViews, packRevision) + const views = useMemo( + () => [...withAppViews(world.views), ...patternViews.map(asViewInfo), ...sceneViews.map(asViewInfo), NOISE], + [world.views, patternViews, sceneViews] + ) const sceneView = sceneViews.find((candidate) => candidate.id === viewId) ?? null - const showsMap = sceneView === null && !APP_VIEW_IDS.has(viewId) + const patternView = patternViews.find((candidate) => candidate.id === viewId) ?? null + const showsMap = sceneView === null && patternView === null && !APP_VIEW_IDS.has(viewId) const view = views.find((candidate) => candidate.id === viewId) ?? views[0] const layer = useMemo(() => ({ view: viewId, preview: viewId === 'regions' ? preview : null }), [viewId, preview]) const regions = usePreviewableRegions(client, packRevision) @@ -218,6 +226,8 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps {sceneView !== null ? ( + ) : patternView !== null ? ( + ) : viewId === WORLD_3D.id ? ( ) : viewId === SAVED_WORLD.id ? ( @@ -315,7 +325,7 @@ function withAppViews(serverViews: ViewInfo[]): ViewInfo[] { return [...serverViews.slice(0, afterHeight), WORLD_3D, SAVED_WORLD, ...serverViews.slice(afterHeight)] } -function asViewInfo(view: SceneViewInfo): ViewInfo { +function asViewInfo(view: ModuleViewInfo): ViewInfo { return { ...view, ...SCENE_GROUP } } @@ -324,19 +334,18 @@ function statusLabel(viewLabel: string, previewName: string | null, sceneSummary return detail === null ? viewLabel : `${viewLabel} · ${detail}` } -/** The scene views the pack's modules show, read again after the pack reloads. */ -function useSceneViews(client: BridgeClient, packRevision: number): SceneViewInfo[] { - const [views, setViews] = useState([]) +/** Views the pack's modules show, read again after the pack reloads; keep {@code load} stable. */ +function useModuleViews(load: () => Promise, packRevision: number): ModuleViewInfo[] { + const [views, setViews] = useState([]) useEffect(() => { let active = true - client - .sceneViews() + load() .then((found) => active && setViews(found)) .catch(() => undefined) return () => { active = false } - }, [client, packRevision]) + }, [load, packRevision]) return views } diff --git a/src/renderer/src/studio/NoiseStudio.tsx b/src/renderer/src/studio/NoiseStudio.tsx index 7fe0d1e49..25d25776e 100644 --- a/src/renderer/src/studio/NoiseStudio.tsx +++ b/src/renderer/src/studio/NoiseStudio.tsx @@ -7,13 +7,14 @@ import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group' import { cn } from '@/lib/utils' import type { BridgeClient } from '../bridge/BridgeClient' import type { NoiseSource, NoiseTile } from '../bridge/types' -import { NOISE_TILE_PIXELS, type NoiseController, type NoiseStatus } from '../noise/NoiseController' +import type { TiledFraming as TerrainFraming } from '../map/TiledView' import { NOISE_PALETTES, noiseScale, type NoisePaletteId, type NoiseScale } from '../noise/noiseScale' import { NoiseTerrain, type NoiseArea } from '../noise/noiseTerrain' +import { createNoiseView, NOISE_TILE_PIXELS, type NoiseStatus, type NoiseView } from '../noise/noiseTiles' import { buildTerrainMesh } from '../scene/terrainMesh' import { hexColor } from './colors' -import { NoiseCanvas } from './NoiseCanvas' import { SceneViewport } from './SceneViewport' +import { TiledCanvas } from './TiledCanvas' type NoiseDisplay = 'flat' | 'terrain' @@ -46,9 +47,14 @@ export function NoiseStudio({ client, packRevision, onSummary, tell }: NoiseStud const [reliefBlocks, setReliefBlocks] = useState(DEFAULT_RELIEF_BLOCKS) const [status, setStatus] = useState(null) const [terrainFraming, setTerrainFraming] = useState(null) - const controllerRef = useRef(null) + const controllerRef = useRef(null) const scale = useMemo(() => noiseScale(paletteId, source), [paletteId, source]) - const listener = useMemo(() => ({ onStatus: setStatus, onError: tell }), [tell]) + const latestTell = useRef(tell) + latestTell.current = tell + const createView = useCallback( + (canvas: HTMLCanvasElement) => createNoiseView(canvas, client, { onStatus: setStatus, onError: (message) => latestTell.current(message) }), + [client] + ) useEffect(() => { const layer = source === null ? null : { sourceId: source.id, seed, revision: packRevision } @@ -75,10 +81,9 @@ export function NoiseStudio({ client, packRevision, onSummary, tell }: NoiseStud return ( <>
- {display === 'terrain' && source !== null && terrainFraming !== null && ( @@ -263,12 +268,6 @@ function ReliefControl({ blocks, onChange }: { blocks: number; onChange(blocks: ) } -interface TerrainFraming { - centerX: number - centerZ: number - renderScale: number -} - function NoiseTerrainView({ client, source, diff --git a/src/renderer/src/studio/PatternStudio.tsx b/src/renderer/src/studio/PatternStudio.tsx new file mode 100644 index 000000000..32b7e2218 --- /dev/null +++ b/src/renderer/src/studio/PatternStudio.tsx @@ -0,0 +1,209 @@ +import { ChevronLeft, ChevronRight, RotateCcw } from 'lucide-react' +import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { Button } from '@/components/ui/button' +import { ScrollArea } from '@/components/ui/scroll-area' +import { cn } from '@/lib/utils' +import type { BridgeClient } from '../bridge/BridgeClient' +import type { ModuleViewInfo, PatternEntry } from '../bridge/types' +import { createPatternView, type PatternBlocks, type PatternLayer, type PatternStatus, type PatternView } from '../pattern/patternTiles' +import { BlockColors } from '../scene/blockColors' +import { BlockModels } from '../scene/blockModels' +import { BridgeAssets } from '../scene/BridgeAssets' +import { hexColor } from './colors' +import { EntryBrowser } from './EntryBrowser' +import { TiledCanvas } from './TiledCanvas' + +const DEFAULT_NAMESPACE_PREFIX = 'minecraft:' +// A layer thinner than the depth shown, or a palette with no block for the spot. +const NONE_LABEL = 'nothing at this depth' + +/** The blocks the shown layer's tiles placed so far by name, with their colours, and whether some spots got none. */ +interface LegendBlocks { + colors: Map + someNone: boolean +} + +const EMPTY_LEGEND: LegendBlocks = { colors: new Map(), someNone: false } +const PILL = 'pointer-events-none absolute rounded-md border border-overlay-border bg-card/90 px-3 py-1.5 text-[12px] text-secondary-text' + +interface PatternStudioProps { + client: BridgeClient + view: ModuleViewInfo + /** Changes when the pack reloads, so the entries and the tiles are read again. */ + packRevision: number + onSummary(summary: string | null): void + tell(message: string): void +} + +/** A pattern view: its entries on the right, what the chosen one places from above in the middle (v3e palette explorer). */ +export function PatternStudio({ client, view, packRevision, onSummary, tell }: PatternStudioProps): React.JSX.Element { + const entries = usePatternEntries(client, view.id, packRevision, tell) + const [chosen, setChosen] = useState<{ key: string; depth: number } | null>(null) + const entry = entries.find((candidate) => candidate.key === chosen?.key) ?? entries[0] ?? null + const depth = entry !== null && chosen?.key === entry.key ? Math.min(chosen.depth, entry.depths - 1) : 0 + const layer = useMemo( + () => (entry === null ? null : { viewId: view.id, key: entry.key, depth, revision: packRevision }), + [view.id, entry, depth, packRevision] + ) + const [status, setStatus] = useState(null) + const { legend, createView } = usePatternView(client, layer, setStatus, tell) + const viewRef = useRef(null) + + useEffect(() => viewRef.current?.show(layer, 'blocks'), [layer]) + useEffect(() => onSummary(entry === null ? null : `${entry.group} · ${entry.name}`), [entry, onSummary]) + useEffect(() => () => onSummary(null), [onSummary]) + + const chooseDepth = (next: number): void => { + if (entry !== null) { + setChosen({ key: entry.key, depth: (next + entry.depths) % entry.depths }) + } + } + + return ( + <> +
+ +
+ {entry !== null && entry.depths > 1 && ( + <> + + + Depth {depth + 1} of {entry.depths} + + + + )} + +
+ {status !== null && entry !== null &&
{readout(status)}
} +
+ + + ) +} + +function readout(status: PatternStatus): string { + const spot = `${Math.floor(status.cursorX)}, ${Math.floor(status.cursorZ)}` + switch (status.spot.kind) { + case 'block': + return `${spot} · ${shortName(status.spot.block)}` + case 'none': + return `${spot} · ${NONE_LABEL}` + case 'unknown': + return spot + } +} + +/** The block without its namespace when that is Minecraft's, and without its state, as a builder names it. */ +function shortName(block: string): string { + const material = block.includes('[') ? block.slice(0, block.indexOf('[')) : block + return material.startsWith(DEFAULT_NAMESPACE_PREFIX) ? material.slice(DEFAULT_NAMESPACE_PREFIX.length) : material +} + +function usePatternEntries(client: BridgeClient, viewId: string, packRevision: number, tell: (message: string) => void): PatternEntry[] { + const [entries, setEntries] = useState([]) + useEffect(() => { + let active = true + client + .patternEntries(viewId) + .then((found) => active && setEntries(found)) + .catch((failure: Error) => active && tell(failure.message)) + return () => { + active = false + } + }, [client, viewId, packRevision, tell]) + return entries +} + +/** The view's maker for the canvas, and the blocks the shown layer's tiles placed so far with their colours. */ +function usePatternView( + client: BridgeClient, + layer: PatternLayer | null, + onStatus: (status: PatternStatus) => void, + tell: (message: string) => void +): { legend: LegendBlocks; createView(canvas: HTMLCanvasElement): PatternView } { + const blockColors = useMemo(() => { + const images = new BridgeAssets(client, () => {}) + return new BlockColors(new BlockModels(images), images) + }, [client]) + const [legend, setLegend] = useState(EMPTY_LEGEND) + const latest = useRef({ layer, onStatus, tell }) + latest.current = { layer, onStatus, tell } + + useEffect(() => setLegend(EMPTY_LEGEND), [layer]) + + const createView = useCallback( + (canvas: HTMLCanvasElement) => + createPatternView(canvas, client, blockColors, { + onStatus: (status) => latest.current.onStatus(status), + onBlocks: (tileLayer, blocks) => tileLayer === latest.current.layer && setLegend((shown) => withBlocks(shown, blocks)), + onError: (message) => latest.current.tell(message) + }), + [client, blockColors] + ) + return { legend, createView } +} + +/** The legend with the tile's blocks added, one row per block whatever its state; unchanged when it had them all. */ +function withBlocks(shown: LegendBlocks, tile: PatternBlocks): LegendBlocks { + const added = [...tile.colors].map(([block, color]) => [shortName(block), color] as const).filter(([name]) => !shown.colors.has(name)) + const someNone = shown.someNone || tile.someNone + if (added.length === 0 && someNone === shown.someNone) { + return shown + } + return { colors: new Map([...shown.colors, ...added]), someNone } +} + +function EntryFacts({ entry }: { entry: PatternEntry | null }): React.JSX.Element | null { + if (entry === null) { + return null + } + return ( +
+

+ {entry.group} · {entry.name} +

+ {entry.facts.map((fact) => ( +

+ {fact} +

+ ))} +
+ ) +} + +/** The blocks the shown tiles place, each with the colour it is drawn in from afar. */ +function Legend({ blocks }: { blocks: LegendBlocks }): React.JSX.Element { + const sorted = [...blocks.colors.entries()].sort(([first], [second]) => first.localeCompare(second)) + return ( +
+

Blocks

+ +
+ {sorted.map(([block, color]) => ( +
+ + {block} +
+ ))} + {blocks.someNone && ( +
+ + Nothing at this depth +
+ )} +
+
+
+ ) +} diff --git a/src/renderer/src/studio/SceneStudio.tsx b/src/renderer/src/studio/SceneStudio.tsx index ffecd61dc..a282b0fc8 100644 --- a/src/renderer/src/studio/SceneStudio.tsx +++ b/src/renderer/src/studio/SceneStudio.tsx @@ -1,15 +1,14 @@ import { ChevronLeft, ChevronRight } from 'lucide-react' import { useEffect, useMemo, useState } from 'react' import { Button } from '@/components/ui/button' -import { Input } from '@/components/ui/input' import { ScrollArea } from '@/components/ui/scroll-area' -import { cn } from '@/lib/utils' import type { BridgeClient } from '../bridge/BridgeClient' -import type { SceneEntry, SceneViewInfo } from '../bridge/types' +import type { ModuleViewInfo, SceneEntry } from '../bridge/types' import { BlockModels } from '../scene/blockModels' import { BridgeAssets } from '../scene/BridgeAssets' import { INTS_PER_BLOCK, type BlockScene } from '../scene/sceneDecoding' import { buildSceneMesh, type SceneMesh } from '../scene/sceneMesh' +import { EntryBrowser } from './EntryBrowser' import { SceneViewport } from './SceneViewport' const NUMBER = new Intl.NumberFormat('en-US') @@ -17,7 +16,7 @@ const DEFAULT_NAMESPACE_PREFIX = 'minecraft:' interface SceneStudioProps { client: BridgeClient - view: SceneViewInfo + view: ModuleViewInfo /** Changes when the pack reloads, so the entries and the scene are read again. */ packRevision: number /** What the status bar says about the scene, or null while none is shown. */ @@ -68,7 +67,7 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce )}
@@ -146,68 +145,6 @@ function disposeMesh(mesh: SceneMesh | null): void { mesh?.dispose() } -interface EntryBrowserProps { - title: string - entries: SceneEntry[] - current: string | null - onSelect(key: string): void -} - -/** The view's entries under their folders, with a search over names and folders (v3e ObjectBrowser). */ -function EntryBrowser({ title, entries, current, onSelect }: EntryBrowserProps): React.JSX.Element { - const [search, setSearch] = useState('') - const wanted = search.trim().toLowerCase() - const groups = useMemo(() => groupedEntries(entries, wanted), [entries, wanted]) - return ( -
-
-

{title}

-

{NUMBER.format(entries.length)} in the pack

- setSearch(event.target.value)} - onKeyDown={(event) => event.key === 'Escape' && setSearch('')} - /> -
- -
- {groups.map(([group, members]) => ( -
- {group !== '' &&

{group}

} - {members.map((entry) => ( - - ))} -
- ))} - {groups.length === 0 &&

{entries.length === 0 ? 'Nothing to show' : 'Nothing matches'}

} -
-
-
- ) -} - -function groupedEntries(entries: SceneEntry[], wanted: string): [string, SceneEntry[]][] { - const groups = new Map() - for (const entry of entries) { - if (wanted !== '' && !entry.key.toLowerCase().includes(wanted)) { - continue - } - const members = groups.get(entry.group) ?? [] - members.push(entry) - groups.set(entry.group, members) - } - return [...groups.entries()] -} - /** The blocks of the scene, most used first, each with its count (v3e ObjectOverviewPanel). */ function BlockList({ scene }: { scene: BlockScene | null }): React.JSX.Element { const counts = useMemo(() => (scene === null ? [] : blockCounts(scene)), [scene]) diff --git a/src/renderer/src/studio/NoiseCanvas.tsx b/src/renderer/src/studio/TiledCanvas.tsx similarity index 56% rename from src/renderer/src/studio/NoiseCanvas.tsx rename to src/renderer/src/studio/TiledCanvas.tsx index 49621ac93..79a291f1f 100644 --- a/src/renderer/src/studio/NoiseCanvas.tsx +++ b/src/renderer/src/studio/TiledCanvas.tsx @@ -1,45 +1,41 @@ import { useEffect, useRef } from 'react' -import type { BridgeClient } from '../bridge/BridgeClient' -import { NoiseController, type NoiseListener } from '../noise/NoiseController' +import type { TiledView } from '../map/TiledView' -interface NoiseCanvasProps { - client: BridgeClient - controllerRef: React.RefObject - listener: NoiseListener +type AnyTiledView = TiledView + +interface TiledCanvasProps { + /** Makes the view on the canvas; called again only when it changes, so keep it stable. */ + create(canvas: HTMLCanvasElement): View + viewRef: React.RefObject className?: string } // One wheel notch is about 100; this zooms about 15% per notch, and smoothly on touchpads. const WHEEL_ZOOM_PER_DELTA = 0.002 -/** The noise from above: drag to move, wheel to zoom. */ -export function NoiseCanvas({ client, controllerRef, listener, className }: NoiseCanvasProps): React.JSX.Element { +/** A tiled view from above: drag to move, wheel to zoom. */ +export function TiledCanvas({ create, viewRef, className }: TiledCanvasProps): React.JSX.Element { const canvasRef = useRef(null) - const latestListener = useRef(listener) - latestListener.current = listener useEffect(() => { const canvas = canvasRef.current! - const noise = new NoiseController(canvas, client, { - onStatus: (status) => latestListener.current.onStatus(status), - onError: (message) => latestListener.current.onError(message) - }) - controllerRef.current = noise - const resize = new ResizeObserver(([entry]) => noise.resize(entry.contentRect.width, entry.contentRect.height)) + const view = create(canvas) + viewRef.current = view + const resize = new ResizeObserver(([entry]) => view.resize(entry.contentRect.width, entry.contentRect.height)) resize.observe(canvas) - const stopMouse = followMouse(canvas, noise) + const stopMouse = followMouse(canvas, view) return () => { stopMouse() resize.disconnect() - noise.close() - controllerRef.current = null + view.close() + viewRef.current = null } - }, [client, controllerRef]) + }, [create, viewRef]) return } -function followMouse(canvas: HTMLCanvasElement, noise: NoiseController): () => void { +function followMouse(canvas: HTMLCanvasElement, view: AnyTiledView): () => void { let last: { x: number; y: number } | null = null const pointOf = (event: MouseEvent): { x: number; y: number } => { const bounds = canvas.getBoundingClientRect() @@ -52,20 +48,20 @@ function followMouse(canvas: HTMLCanvasElement, noise: NoiseController): () => v } } const move = (event: PointerEvent): void => { - noise.setCursor(pointOf(event)) + view.setCursor(pointOf(event)) if (last !== null) { - noise.panBy(event.clientX - last.x, event.clientY - last.y) + view.panBy(event.clientX - last.x, event.clientY - last.y) last = { x: event.clientX, y: event.clientY } } } const up = (): void => { last = null } - const leave = (): void => noise.setCursor(null) + const leave = (): void => view.setCursor(null) const wheel = (event: WheelEvent): void => { event.preventDefault() const point = pointOf(event) - noise.zoomAt(2 ** (-event.deltaY * WHEEL_ZOOM_PER_DELTA), point.x, point.y) + view.zoomAt(2 ** (-event.deltaY * WHEEL_ZOOM_PER_DELTA), point.x, point.y) } canvas.addEventListener('pointerdown', down) canvas.addEventListener('pointermove', move) diff --git a/src/renderer/src/studio/ViewList.tsx b/src/renderer/src/studio/ViewList.tsx index 5734c8cc2..40e6aeef9 100644 --- a/src/renderer/src/studio/ViewList.tsx +++ b/src/renderer/src/studio/ViewList.tsx @@ -1,4 +1,4 @@ -import { AudioWaveform, Box, Gem, Globe, HardDrive, Map as MapIcon, Mountain, Shapes, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' +import { AudioWaveform, Box, Gem, Globe, HardDrive, Layers, Map as MapIcon, Mountain, Shapes, Sprout, Trees, Waves, type LucideIcon } from 'lucide-react' import { Kbd } from '@/components/ui/kbd' import { ScrollArea } from '@/components/ui/scroll-area' import { cn } from '@/lib/utils' @@ -16,7 +16,8 @@ const VIEW_ICONS: Record = { seaBiomes: Waves, caveBiomes: Gem, 'iris:objects': Box, - 'iris:objects/procedural': Shapes + 'iris:objects/procedural': Shapes, + 'iris:terrain/palettes': Layers } interface ViewListProps { From 922fe5e4cf05e7bcfb60c9bfd0c81e33700d5306 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 05:06:28 +0100 Subject: [PATCH 10/12] Add the node editor to the procedural scene view Under the 3D scene the entry's file shows as a tree of nodes, laid out left to right. Clicking a node shows its settings on the right, a field per schema option with defaults, ranges and enums; right click adds, duplicates and deletes; dragging a node onto another regrows it there. Undo and redo write earlier texts back. Edits are queued so quick ones never refuse each other, and a file changed elsewhere is read again. Context menus blur what is behind them, and submenus are portalled so the menu no longer clips them. --- src/renderer/src/bridge/BridgeClient.ts | 21 +- src/renderer/src/bridge/types.ts | 90 ++++++ .../src/components/ui/context-menu.tsx | 21 +- src/renderer/src/editor/EditHistory.test.ts | 35 ++ src/renderer/src/editor/EditHistory.ts | 45 +++ src/renderer/src/editor/jsonValues.ts | 22 ++ src/renderer/src/editor/nodeLayout.test.ts | 47 +++ src/renderer/src/editor/nodeLayout.ts | 91 ++++++ src/renderer/src/editor/useNodeEditor.ts | 122 +++++++ src/renderer/src/studio/MapStudio.tsx | 8 +- src/renderer/src/studio/NodeCanvas.tsx | 300 ++++++++++++++++++ src/renderer/src/studio/NodeInspector.tsx | 231 ++++++++++++++ src/renderer/src/studio/NodePane.tsx | 95 ++++++ src/renderer/src/studio/SceneStudio.tsx | 75 ++++- src/renderer/src/studio/shortcuts.ts | 5 + 15 files changed, 1179 insertions(+), 29 deletions(-) create mode 100644 src/renderer/src/editor/EditHistory.test.ts create mode 100644 src/renderer/src/editor/EditHistory.ts create mode 100644 src/renderer/src/editor/jsonValues.ts create mode 100644 src/renderer/src/editor/nodeLayout.test.ts create mode 100644 src/renderer/src/editor/nodeLayout.ts create mode 100644 src/renderer/src/editor/useNodeEditor.ts create mode 100644 src/renderer/src/studio/NodeCanvas.tsx create mode 100644 src/renderer/src/studio/NodeInspector.tsx create mode 100644 src/renderer/src/studio/NodePane.tsx diff --git a/src/renderer/src/bridge/BridgeClient.ts b/src/renderer/src/bridge/BridgeClient.ts index 142a0b005..f094118a5 100644 --- a/src/renderer/src/bridge/BridgeClient.ts +++ b/src/renderer/src/bridge/BridgeClient.ts @@ -4,6 +4,8 @@ import { decodePattern } from './patternDecoding' import { decodeSavedTile } from './savedTileDecoding' import { decodeTile } from './tileDecoding' import type { + EditorState, + GraphEdit, MapHover, MapLabel, MapTile, @@ -18,10 +20,12 @@ import type { SavedTile, SavedWorldInfo, SceneEntry, + SceneViewInfo, WorldInfo } from './types' export const STATUS_NOT_FOUND = 404 +export const STATUS_CONFLICT = 409 export const STATUS_UNAVAILABLE = 503 export class BridgeError extends Error { @@ -134,10 +138,25 @@ export class BridgeClient { } /** The scene views the pack's modules show, such as its objects. */ - sceneViews(): Promise { + sceneViews(): Promise { return this.json('scenes') } + /** An editable entry's file, as nodes. */ + sceneFile(viewId: string, key: string, signal?: AbortSignal): Promise { + return this.json(`scene-file?${new URLSearchParams({ view: viewId, key })}`, { signal }) + } + + /** Makes {@code edit} on the file as it was at {@code revision} and saves it; refused with STATUS_CONFLICT when it changed since. */ + sceneEdit(viewId: string, key: string, revision: string, edit: GraphEdit): Promise { + return this.json(`scene-edit?${new URLSearchParams({ view: viewId, key })}`, { method: 'POST', body: JSON.stringify({ revision, edit }) }) + } + + /** Replaces the whole file, as undoing does; refused with STATUS_CONFLICT when it changed since {@code revision}. */ + sceneWrite(viewId: string, key: string, revision: string, text: string): Promise { + return this.json(`scene-write?${new URLSearchParams({ view: viewId, key })}`, { method: 'POST', body: JSON.stringify({ revision, text }) }) + } + sceneEntries(viewId: string): Promise { return this.json(`scene-entries?${new URLSearchParams({ view: viewId })}`) } diff --git a/src/renderer/src/bridge/types.ts b/src/renderer/src/bridge/types.ts index 7b24d5887..a428efa21 100644 --- a/src/renderer/src/bridge/types.ts +++ b/src/renderer/src/bridge/types.ts @@ -33,6 +33,96 @@ export interface SceneEntry { variants: number } +/** A scene view as the server lists it; `editable` when its entries can be edited as nodes. */ +export interface SceneViewInfo extends ModuleViewInfo { + editable: boolean +} + +/** Where a value sits in a JSON file: member names and element indices from the root. */ +export type JsonPath = (string | number)[] + +/** An entry's file as the node editor shows it (StudioEditors.EditorState). */ +export interface EditorState { + /** Where it is below the pack folder. */ + file: string + /** Tells this text from any other; an edit sent with an older one is refused. */ + revision: string + text: string + /** The file as nodes, or null when it can't be read as nodes and `problem` says why. */ + roots: GraphNode[] | null + problem: string | null + /** Why the file can't be edited here, such as outside a studio world; null when it can. */ + locked: string | null + types: Record +} + +export interface GraphNode { + kind: string + title: string + path: JsonPath + /** The scene part it draws, or NO_PART. */ + partId: number + roles: string[] + settings: NodeSettings[] + children: { wire: string; node: GraphNode }[] + /** The array a node moved under this one joins; null when nothing can move here. */ + childList: JsonPath | null + movable: boolean + duplicable: boolean + additions: { label: string; list: JsonPath; literal: string }[] +} + +export const NO_PART = -1 + +/** The settings of the object at `path`, of schema type `type`, without the members shown as nodes. */ +export interface NodeSettings { + title: string + path: JsonPath + type: string + shownAsNodes: string[] +} + +/** A settings type of the pack's schema (SchemaTypes.TypeWire). */ +export interface SettingsType { + description: string + options: SettingOption[] +} + +export interface SettingOption { + name: string + description: string + required: boolean + minimum: number | null + maximum: number | null + minItems: number | null + defaultValue: unknown + kind: ValueKind +} + +export type ValueKind = + | { kind: 'boolean' } + | { kind: 'integer' } + | { kind: 'decimal' } + | { kind: 'text'; format: string } + | { kind: 'reference'; reference: string; format: string } + | { kind: 'resource'; resource: string } + | { kind: 'enum'; constants: { name: string; description: string }[] } + | { kind: 'list'; element: ValueKind; unique: boolean } + | { kind: 'map'; value: ValueKind } + | { kind: 'object'; type: string } + | { kind: 'host'; type: string } + | { kind: 'any' } + +/** One change the node editor makes (GraphEditRequest). */ +export type GraphEdit = + | { op: 'set'; object: JsonPath; key: string; literal: string } + | { op: 'unset'; object: JsonPath; key: string } + | { op: 'append'; list: JsonPath; literal: string } + | { op: 'addItem'; list: JsonPath } + | { op: 'delete'; path: JsonPath } + | { op: 'duplicate'; path: JsonPath } + | { op: 'move'; path: JsonPath; toList: JsonPath } + /** Something a pattern view lays out, such as one of a biome's palettes (IrisApi PatternEntry). */ export interface PatternEntry { key: string diff --git a/src/renderer/src/components/ui/context-menu.tsx b/src/renderer/src/components/ui/context-menu.tsx index c8d0ff606..d3d0f9c5b 100644 --- a/src/renderer/src/components/ui/context-menu.tsx +++ b/src/renderer/src/components/ui/context-menu.tsx @@ -78,15 +78,18 @@ function ContextMenuSubContent({ className, ...props }: React.ComponentProps) { + // Portalled like the menu itself: inside it, the menu's blur and scrolling would clip the submenu away. return ( - + + + ) } @@ -99,7 +102,7 @@ function ContextMenuContent({ { + it('undoes back to the text before an edit and redoes forward again', () => { + const history = new EditHistory() + history.edited('a') + + expect(history.nextUndo()).toBe('a') + history.undone('b') + expect(history.canUndo).toBe(false) + expect(history.nextRedo()).toBe('b') + history.redone('a') + expect(history.nextUndo()).toBe('a') + }) + + it('forgets what could be redone once a new edit is made', () => { + const history = new EditHistory() + history.edited('a') + history.undone('b') + + history.edited('a') + + expect(history.canRedo).toBe(false) + }) + + it('keeps the history as it was when an undo is never written', () => { + const history = new EditHistory() + history.edited('a') + + history.nextUndo() + + expect(history.canUndo).toBe(true) + }) +}) diff --git a/src/renderer/src/editor/EditHistory.ts b/src/renderer/src/editor/EditHistory.ts new file mode 100644 index 000000000..b1b002caa --- /dev/null +++ b/src/renderer/src/editor/EditHistory.ts @@ -0,0 +1,45 @@ +const KEPT_STEPS = 100 + +/** + * The texts a file had before each edit, so undoing writes an earlier text back whole. A step is only taken once its + * write succeeded, so a refused undo leaves the history as it was. + */ +export class EditHistory { + private readonly undos: string[] = [] + private readonly redos: string[] = [] + + get canUndo(): boolean { + return this.undos.length > 0 + } + + get canRedo(): boolean { + return this.redos.length > 0 + } + + edited(before: string): void { + this.undos.push(before) + if (this.undos.length > KEPT_STEPS) { + this.undos.shift() + } + this.redos.length = 0 + } + + /** The text undoing writes, if there is one. */ + nextUndo(): string | undefined { + return this.undos.at(-1) + } + + undone(before: string): void { + this.undos.pop() + this.redos.push(before) + } + + nextRedo(): string | undefined { + return this.redos.at(-1) + } + + redone(before: string): void { + this.redos.pop() + this.undos.push(before) + } +} diff --git a/src/renderer/src/editor/jsonValues.ts b/src/renderer/src/editor/jsonValues.ts new file mode 100644 index 000000000..418f01b2d --- /dev/null +++ b/src/renderer/src/editor/jsonValues.ts @@ -0,0 +1,22 @@ +import type { JsonPath } from '../bridge/types' + +/** The value at {@code path} in a parsed file; undefined where nothing is written. */ +export function valueAt(root: unknown, path: JsonPath): unknown { + let current = root + for (const step of path) { + if (current === null || typeof current !== 'object') { + return undefined + } + current = (current as Record)[step] + } + return current +} + +/** The file parsed, or undefined when it is not JSON (the editor then shows why instead). */ +export function parsedText(text: string): unknown { + try { + return JSON.parse(text) + } catch { + return undefined + } +} diff --git a/src/renderer/src/editor/nodeLayout.test.ts b/src/renderer/src/editor/nodeLayout.test.ts new file mode 100644 index 000000000..7eb18f73f --- /dev/null +++ b/src/renderer/src/editor/nodeLayout.test.ts @@ -0,0 +1,47 @@ +import { describe, expect, it } from 'vitest' +import type { GraphNode, JsonPath } from '../bridge/types' +import { NO_PART } from '../bridge/types' +import { isWithin, layoutNodes, NODE_WIDTH } from './nodeLayout' + +function node(path: JsonPath, children: GraphNode[] = []): GraphNode { + return { + kind: 'Stem', + title: 'Stem', + path, + partId: NO_PART, + roles: [], + settings: [], + children: children.map((child) => ({ wire: '', node: child })), + childList: null, + movable: true, + duplicable: true, + additions: [] + } +} + +describe('layoutNodes', () => { + it('sets a parent level with the middle of its children, a column to their left', () => { + const layout = layoutNodes([node([], [node(['parts', 0]), node(['parts', 1]), node(['parts', 2])])]) + const [first, , last, parent] = layout.nodes + + expect(parent.y).toBe((first.y + last.y) / 2) + expect(first.x - parent.x).toBeGreaterThan(NODE_WIDTH) + expect(layout.wires).toHaveLength(3) + }) + + it('lays the next root out under the tree before it', () => { + const layout = layoutNodes([node([], [node(['parts', 0])]), node(['materials', 0])]) + const material = layout.nodes.find((placed) => placed.id === JSON.stringify(['materials', 0]))! + + expect(material.x).toBe(0) + expect(material.y).toBeGreaterThan(Math.max(...layout.nodes.filter((placed) => placed !== material).map((placed) => placed.y))) + }) +}) + +describe('isWithin', () => { + it('holds for the path itself and what sits inside it, not for a sibling', () => { + expect(isWithin(['parts', 0, 'children', 1], ['parts', 0])).toBe(true) + expect(isWithin(['parts', 0], ['parts', 0])).toBe(true) + expect(isWithin(['parts', 1], ['parts', 0])).toBe(false) + }) +}) diff --git a/src/renderer/src/editor/nodeLayout.ts b/src/renderer/src/editor/nodeLayout.ts new file mode 100644 index 000000000..df108ce23 --- /dev/null +++ b/src/renderer/src/editor/nodeLayout.ts @@ -0,0 +1,91 @@ +import type { GraphNode, JsonPath } from '../bridge/types' + +export const NODE_WIDTH = 168 +export const NODE_HEIGHT = 46 +const COLUMN_GAP = 64 +const ROW_GAP = 10 +const TREE_GAP = 26 + +/** A node where the canvas draws it, by its top left corner; `id` tells it from every other node of the file. */ +export interface PlacedNode { + id: string + node: GraphNode + x: number + y: number +} + +export interface PlacedWire { + from: PlacedNode + to: PlacedNode + label: string +} + +export interface NodeLayout { + nodes: PlacedNode[] + wires: PlacedWire[] + width: number + height: number +} + +export function idOf(path: JsonPath): string { + return JSON.stringify(path) +} + +/** The node at {@code path} among the trees of {@code roots}, or null when there is none, such as after it was deleted. */ +export function nodeWithPath(roots: GraphNode[], path: JsonPath): GraphNode | null { + const id = idOf(path) + for (const root of roots) { + if (idOf(root.path) === id) { + return root + } + const found = nodeWithPath( + root.children.map((link) => link.node), + path + ) + if (found !== null) { + return found + } + } + return null +} + +/** Whether {@code path} is {@code ancestor} or sits inside it. */ +export function isWithin(path: JsonPath, ancestor: JsonPath): boolean { + return ancestor.length <= path.length && ancestor.every((step, index) => path[index] === step) +} + +/** + * Lays each root's tree out from left to right, a column per generation, one tree under the other. Leaves take a row + * each and a parent sits level with the middle of its children, so wires never cross. + */ +export function layoutNodes(roots: GraphNode[]): NodeLayout { + const nodes: PlacedNode[] = [] + const wires: PlacedWire[] = [] + let nextTop = 0 + let width = 0 + + const place = (node: GraphNode, depth: number): PlacedNode => { + const x = depth * (NODE_WIDTH + COLUMN_GAP) + width = Math.max(width, x + NODE_WIDTH) + const children = node.children.map((link) => ({ label: link.wire, placed: place(link.node, depth + 1) })) + const y = children.length === 0 ? takeRow() : (children[0].placed.y + children[children.length - 1].placed.y) / 2 + const placed: PlacedNode = { id: idOf(node.path), node, x, y } + nodes.push(placed) + for (const child of children) { + wires.push({ from: placed, to: child.placed, label: child.label }) + } + return placed + } + + const takeRow = (): number => { + const top = nextTop + nextTop += NODE_HEIGHT + ROW_GAP + return top + } + + for (const root of roots) { + place(root, 0) + nextTop += TREE_GAP + } + return { nodes, wires, width, height: Math.max(0, nextTop - ROW_GAP - TREE_GAP) } +} diff --git a/src/renderer/src/editor/useNodeEditor.ts b/src/renderer/src/editor/useNodeEditor.ts new file mode 100644 index 000000000..e0bd74f82 --- /dev/null +++ b/src/renderer/src/editor/useNodeEditor.ts @@ -0,0 +1,122 @@ +import { useCallback, useEffect, useRef, useState } from 'react' +import { BridgeError, STATUS_CONFLICT, type BridgeClient } from '../bridge/BridgeClient' +import type { EditorState, GraphEdit } from '../bridge/types' +import { EditHistory } from './EditHistory' + +export interface NodeEditor { + /** The entry's file as it is now; null while it is read. */ + state: EditorState | null + saving: boolean + canUndo: boolean + canRedo: boolean + edit(edit: GraphEdit): void + undo(): void + redo(): void +} + +/** + * Reads an entry's file as nodes and edits it. Edits are sent one after another, each on the text the one before left, + * so quick edits never refuse each other; one refused because the file changed elsewhere reads the file again. + */ +export function useNodeEditor(client: BridgeClient, viewId: string, key: string | null, packRevision: number, tell: (message: string) => void): NodeEditor { + const [state, setState] = useState(null) + const [saving, setSaving] = useState(false) + const [, setHistoryChanges] = useState(0) + const history = useRef(new EditHistory()) + const shown = useRef(null) + const queue = useRef>(Promise.resolve()) + const entry = useRef({ viewId, key }) + + const run = useCallback( + (task: (current: EditorState | null) => Promise): void => { + const asked = entry.current + queue.current = queue.current.then(async () => { + if (entry.current !== asked) { + return + } + setSaving(true) + try { + const next = await task(shown.current) + if (entry.current === asked && next !== null) { + shown.current = next + setState(next) + } + } catch (failure) { + if (entry.current !== asked) { + return + } + tell((failure as Error).message) + if (failure instanceof BridgeError && failure.status === STATUS_CONFLICT && asked.key !== null) { + const reread = await client.sceneFile(asked.viewId, asked.key).catch(() => null) + if (reread !== null && entry.current === asked) { + shown.current = reread + setState(reread) + } + } + } finally { + setSaving(false) + setHistoryChanges((changes) => changes + 1) + } + }) + }, + [client, tell] + ) + + useEffect(() => { + entry.current = { viewId, key } + history.current = new EditHistory() + shown.current = null + setState(null) + }, [viewId, key]) + + useEffect(() => { + if (key !== null) { + run(() => client.sceneFile(viewId, key)) + } + }, [client, viewId, key, packRevision, run]) + + const edit = useCallback( + (change: GraphEdit) => + run(async (current) => { + if (current === null || key === null) { + return null + } + const next = await client.sceneEdit(viewId, key, current.revision, change) + if (next.text !== current.text) { + history.current.edited(current.text) + } + return next + }), + [client, viewId, key, run] + ) + + const undo = useCallback( + () => + run(async (current) => { + const earlier = history.current.nextUndo() + if (current === null || key === null || earlier === undefined) { + return null + } + const next = await client.sceneWrite(viewId, key, current.revision, earlier) + history.current.undone(current.text) + return next + }), + [client, viewId, key, run] + ) + + const redo = useCallback( + () => + run(async (current) => { + const later = history.current.nextRedo() + if (current === null || key === null || later === undefined) { + return null + } + const next = await client.sceneWrite(viewId, key, current.revision, later) + history.current.redone(current.text) + return next + }), + [client, viewId, key, run] + ) + + return { state, saving, canUndo: history.current.canUndo, canRedo: history.current.canRedo, edit, undo, redo } +} diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx index 762f4440e..63e39b959 100644 --- a/src/renderer/src/studio/MapStudio.tsx +++ b/src/renderer/src/studio/MapStudio.tsx @@ -16,7 +16,7 @@ import { PatternStudio } from './PatternStudio' import { SavedWorldStudio } from './SavedWorldStudio' import { SceneStudio } from './SceneStudio' import { WorldStudio3D } from './WorldStudio3D' -import { actionForKey, viewForKey, type ShortcutAction } from './shortcuts' +import { actionForKey, isTypingInto, viewForKey, type ShortcutAction } from './shortcuts' import { StatusBar } from './StatusBar' import { StudioToolbar } from './StudioToolbar' import { ViewList } from './ViewList' @@ -335,8 +335,8 @@ function statusLabel(viewLabel: string, previewName: string | null, sceneSummary } /** Views the pack's modules show, read again after the pack reloads; keep {@code load} stable. */ -function useModuleViews(load: () => Promise, packRevision: number): ModuleViewInfo[] { - const [views, setViews] = useState([]) +function useModuleViews(load: () => Promise, packRevision: number): View[] { + const [views, setViews] = useState([]) useEffect(() => { let active = true load() @@ -503,7 +503,7 @@ function useKeyboard( if (event.key === 'Shift') { setDetailed(true) } - if (event.ctrlKey || event.metaKey || event.altKey || event.target instanceof HTMLInputElement) { + if (event.ctrlKey || event.metaKey || event.altKey || isTypingInto(event.target)) { return } const viewId = viewForKey(event.key) diff --git a/src/renderer/src/studio/NodeCanvas.tsx b/src/renderer/src/studio/NodeCanvas.tsx new file mode 100644 index 000000000..96e8cf571 --- /dev/null +++ b/src/renderer/src/studio/NodeCanvas.tsx @@ -0,0 +1,300 @@ +import { Box, Circle, Flower2, GitCommitVertical, GitFork, Group, Link2, Paintbrush, Sparkles, type LucideIcon } from 'lucide-react' +import { useEffect, useMemo, useRef, useState } from 'react' +import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger } from '@/components/ui/context-menu' +import { cn } from '@/lib/utils' +import type { GraphEdit, GraphNode, JsonPath } from '../bridge/types' +import { idOf, isWithin, layoutNodes, NODE_HEIGHT, NODE_WIDTH, type NodeLayout, type PlacedNode } from '../editor/nodeLayout' + +const KIND_ICONS: Record = { + Object: Box, + Stem: GitCommitVertical, + Blob: Circle, + Branches: GitFork, + Cluster: Sparkles, + Group: Group, + 'Shared part': Link2, + Material: Paintbrush, + Decoration: Flower2 +} +const FIT_MARGIN = 24 +const LARGEST_FIT_SCALE = 1 +// Below this the node text can't be read; a larger tree is panned instead of shrunk further. +const SMALLEST_FIT_SCALE = 0.8 +const SMALLEST_SCALE = 0.25 +const LARGEST_SCALE = 2 +const WHEEL_ZOOM_PER_PIXEL = 0.0015 +const DRAG_START_PIXELS = 4 +const GRID_SPACING = 16 + +interface Camera { + x: number + y: number + scale: number +} + +interface NodeDrag { + placed: PlacedNode + startX: number + startY: number + pointerX: number + pointerY: number + moved: boolean + target: PlacedNode | null +} + +interface NodeCanvasProps { + roots: GraphNode[] + /** Tells files apart, so a new one is fitted into view. */ + fileKey: string + selectedId: string | null + locked: boolean + onSelect(node: GraphNode | null): void + onEdit(edit: GraphEdit): void +} + +/** The file as a tree of nodes: drag the background to look around, drag a node onto another to grow it from there. */ +export function NodeCanvas({ roots, fileKey, selectedId, locked, onSelect, onEdit }: NodeCanvasProps): React.JSX.Element { + const layout = useMemo(() => layoutNodes(roots), [roots]) + const frame = useRef(null) + const [camera, setCamera] = useCamera(frame, layout, fileKey) + const [drag, setDrag] = useState(null) + const [menuNode, setMenuNode] = useState(null) + const pan = useRef<{ x: number; y: number } | null>(null) + + const canvasPoint = (clientX: number, clientY: number): { x: number; y: number } => { + const bounds = frame.current!.getBoundingClientRect() + return { x: (clientX - bounds.left - camera.x) / camera.scale, y: (clientY - bounds.top - camera.y) / camera.scale } + } + + const pointerDown = (event: React.PointerEvent): void => { + if (event.button !== 0) { + return + } + event.currentTarget.setPointerCapture(event.pointerId) + const placed = nodeAt(layout, canvasPoint(event.clientX, event.clientY)) + if (placed === null) { + pan.current = { x: event.clientX, y: event.clientY } + return + } + setDrag({ placed, startX: event.clientX, startY: event.clientY, pointerX: event.clientX, pointerY: event.clientY, moved: false, target: null }) + } + + const pointerMove = (event: React.PointerEvent): void => { + if (pan.current !== null) { + const [dx, dy] = [event.clientX - pan.current.x, event.clientY - pan.current.y] + pan.current = { x: event.clientX, y: event.clientY } + setCamera((current) => ({ ...current, x: current.x + dx, y: current.y + dy })) + return + } + if (drag === null) { + return + } + const moved = drag.moved || Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) > DRAG_START_PIXELS + const canMove = moved && !locked && drag.placed.node.movable + const target = canMove ? moveTarget(layout, drag.placed, canvasPoint(event.clientX, event.clientY)) : null + setDrag({ ...drag, pointerX: event.clientX, pointerY: event.clientY, moved, target }) + } + + const pointerUp = (): void => { + pan.current = null + if (drag === null) { + return + } + if (!drag.moved) { + onSelect(drag.placed.node) + } else if (drag.target !== null) { + onEdit({ op: 'move', path: drag.placed.node.path, toList: drag.target.node.childList! }) + } + setDrag(null) + } + + const dragging = drag !== null && drag.moved && drag.placed.node.movable && !locked + const dragOffset = dragging ? { x: (drag.pointerX - drag.startX) / camera.scale, y: (drag.pointerY - drag.startY) / camera.scale } : null + + return ( + !open && setMenuNode(null)}> + +
{ + pan.current = null + setDrag(null) + }} + onContextMenu={(event) => { + const placed = nodeAt(layout, canvasPoint(event.clientX, event.clientY)) + setMenuNode(placed?.node ?? null) + if (placed === null) { + event.preventDefault() + } else { + onSelect(placed.node) + } + }} + onDoubleClick={(event) => nodeAt(layout, canvasPoint(event.clientX, event.clientY)) === null && setCamera(fitted(frame.current!, layout))} + > +
+ + {layout.nodes.map((placed) => ( + + ))} +
+
+
+ {menuNode !== null && } +
+ ) +} + +function NodeBox({ placed, selected, target, offset }: { placed: PlacedNode; selected: boolean; target: boolean; offset: { x: number; y: number } | null }): React.JSX.Element { + const { node } = placed + const Icon = KIND_ICONS[node.kind] ?? Box + const detail = node.roles.length > 0 ? node.roles.join(', ') : node.title === node.kind ? null : node.kind + return ( +
+ +
+
{node.title}
+ {detail !== null &&
{detail}
} +
+
+ ) +} + +function Wires({ layout }: { layout: NodeLayout }): React.JSX.Element { + return ( + + {layout.wires.map(({ from, to, label }) => { + const [startX, startY] = [from.x + NODE_WIDTH, from.y + NODE_HEIGHT / 2] + const [endX, endY] = [to.x, to.y + NODE_HEIGHT / 2] + const bend = (endX - startX) / 2 + return ( + ${to.id}`}> + + {label !== '' && ( + + {label} + + )} + + ) + })} + + ) +} + +function NodeMenu({ node, locked, onEdit }: { node: GraphNode; locked: boolean; onEdit(edit: GraphEdit): void }): React.JSX.Element { + const removable = node.duplicable + return ( + + {node.additions.length > 0 && ( + + Add + + {node.additions.map((addition) => ( + onEdit({ op: 'append', list: addition.list, literal: addition.literal })}> + {addition.label} + + ))} + + + )} + onEdit({ op: 'duplicate', path: node.path })}> + Duplicate + + + onEdit({ op: 'delete', path: node.path })}> + Delete + + + ) +} + +function nodeAt(layout: NodeLayout, point: { x: number; y: number }): PlacedNode | null { + return layout.nodes.find((placed) => point.x >= placed.x && point.x <= placed.x + NODE_WIDTH && point.y >= placed.y && point.y <= placed.y + NODE_HEIGHT) ?? null +} + +// A node can grow from any other that takes children, except from inside itself or from where it already grows. +function moveTarget(layout: NodeLayout, dragged: PlacedNode, point: { x: number; y: number }): PlacedNode | null { + const over = nodeAt(layout, point) + const toList = over?.node.childList + if (over === null || toList === null || toList === undefined || isWithin(toList, dragged.node.path) || isParentList(dragged.node.path, toList)) { + return null + } + return over +} + +function isParentList(path: JsonPath, list: JsonPath): boolean { + return path.length === list.length + 1 && isWithin(path, list) +} + +function useCamera(frame: React.RefObject, layout: NodeLayout, fileKey: string): [Camera, React.Dispatch>] { + const [camera, setCamera] = useState({ x: FIT_MARGIN, y: FIT_MARGIN, scale: 1 }) + const fittedFile = useRef(null) + + useEffect(() => { + if (frame.current === null || layout.nodes.length === 0 || fittedFile.current === fileKey) { + return + } + fittedFile.current = fileKey + setCamera(fitted(frame.current, layout)) + }, [frame, layout, fileKey]) + + useEffect(() => { + const element = frame.current + if (element === null) { + return + } + const wheel = (event: WheelEvent): void => { + event.preventDefault() + const bounds = element.getBoundingClientRect() + const [pointerX, pointerY] = [event.clientX - bounds.left, event.clientY - bounds.top] + setCamera((current) => { + const scale = clamp(current.scale * Math.exp(-event.deltaY * WHEEL_ZOOM_PER_PIXEL), SMALLEST_SCALE, LARGEST_SCALE) + const ratio = scale / current.scale + return { scale, x: pointerX - (pointerX - current.x) * ratio, y: pointerY - (pointerY - current.y) * ratio } + }) + } + element.addEventListener('wheel', wheel, { passive: false }) + return () => element.removeEventListener('wheel', wheel) + }, [frame]) + + return [camera, setCamera] +} + +function fitted(frame: HTMLDivElement, layout: NodeLayout): Camera { + const [width, height] = [frame.clientWidth - 2 * FIT_MARGIN, frame.clientHeight - 2 * FIT_MARGIN] + const scale = clamp(Math.min(width / Math.max(layout.width, 1), height / Math.max(layout.height, 1)), SMALLEST_FIT_SCALE, LARGEST_FIT_SCALE) + return { scale, x: FIT_MARGIN, y: FIT_MARGIN + Math.max(0, (height - layout.height * scale) / 2) } +} + +function clamp(value: number, lowest: number, highest: number): number { + return Math.min(highest, Math.max(lowest, value)) +} diff --git a/src/renderer/src/studio/NodeInspector.tsx b/src/renderer/src/studio/NodeInspector.tsx new file mode 100644 index 000000000..27cde9707 --- /dev/null +++ b/src/renderer/src/studio/NodeInspector.tsx @@ -0,0 +1,231 @@ +import { RotateCcw } from 'lucide-react' +import { useState } from 'react' +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { ScrollArea } from '@/components/ui/scroll-area' +import { cn } from '@/lib/utils' +import type { EditorState, GraphEdit, GraphNode, NodeSettings, SettingOption, ValueKind } from '../bridge/types' +import { valueAt } from '../editor/jsonValues' + +const NOT_SET = '' + +interface NodeInspectorProps { + node: GraphNode + state: EditorState + /** The file parsed, to read what each setting is set to. */ + values: unknown + onEdit(edit: GraphEdit): void +} + +/** The settings of the chosen node, a field per option of its schema type; an empty field leaves the option unset. */ +export function NodeInspector({ node, state, values, onEdit }: NodeInspectorProps): React.JSX.Element { + const locked = state.locked !== null + return ( +
+
+

{node.title}

+

{node.roles.length > 0 ? node.roles.join(', ') : node.kind}

+
+ +
+ {node.settings.map((section) => ( + + ))} +
+
+
+ ) +} + +function SettingsSection({ + section, + state, + values, + locked, + onEdit +}: { + section: NodeSettings + state: EditorState + values: unknown + locked: boolean + onEdit(edit: GraphEdit): void +}): React.JSX.Element { + const type = state.types[section.type] + const options = type?.options.filter((option) => !section.shownAsNodes.includes(option.name)) ?? [] + return ( +
+

+ {section.title} +

+ {options.map((option) => { + const value = valueAt(values, [...section.path, option.name]) + return ( + onEdit({ op: 'set', object: section.path, key: option.name, literal })} + onUnset={() => onEdit({ op: 'unset', object: section.path, key: option.name })} + /> + ) + })} +
+ ) +} + +interface SettingFieldProps { + option: SettingOption + /** What the file sets it to; undefined when it is not set. */ + value: unknown + locked: boolean + onSet(literal: string): void + onUnset(): void +} + +function SettingField(props: SettingFieldProps): React.JSX.Element { + const kind = props.option.kind.kind + return kind === 'boolean' || kind === 'enum' ? : +} + +function FieldRow({ option, value, locked, onUnset, problem, children }: SettingFieldProps & { problem: string | null; children: React.ReactNode }): React.JSX.Element { + return ( +
+
+ +
+ {children} + +
+
+ {problem !== null &&

{problem}

} +
+ ) +} + +function ChoiceField(props: SettingFieldProps): React.JSX.Element { + const { option, value, locked, onSet, onUnset } = props + const choices = option.kind.kind === 'enum' ? option.kind.constants.map((constant) => constant.name) : ['true', 'false'] + const literalOf = (choice: string): string => (option.kind.kind === 'enum' ? JSON.stringify(choice) : choice) + return ( + + + + ) +} + +// Numbers, text and anything else are typed in; a draft that does not fit the option says why and is not written. +function TypedField(props: SettingFieldProps): React.JSX.Element { + const { option, value, locked, onSet, onUnset } = props + const shown = textOf(option.kind, value) + const [draft, setDraft] = useState(shown) + const problem = draft.trim() === NOT_SET ? null : problemWith(option, draft) + const commit = (): void => { + if (draft === shown || problem !== null) { + return + } + if (draft.trim() === NOT_SET) { + onUnset() + return + } + onSet(literalOf(option.kind, draft)) + } + return ( + + setDraft(event.target.value)} + onBlur={commit} + onKeyDown={(event) => { + if (event.key === 'Enter') { + commit() + } else if (event.key === 'Escape') { + setDraft(shown) + } + }} + /> + + ) +} + +function defaultLabel(option: SettingOption): string { + if (option.defaultValue === null || option.defaultValue === undefined) { + return option.required ? 'Required' : 'Not set' + } + const text = typeof option.defaultValue === 'string' ? option.defaultValue : JSON.stringify(option.defaultValue) + return `Default ${text}` +} + +function isNumber(kind: ValueKind): boolean { + return kind.kind === 'integer' || kind.kind === 'decimal' +} + +function isText(kind: ValueKind): boolean { + return kind.kind === 'text' || kind.kind === 'reference' || kind.kind === 'resource' +} + +function textOf(kind: ValueKind, value: unknown): string { + if (value === undefined) { + return NOT_SET + } + return isText(kind) && typeof value === 'string' ? value : JSON.stringify(value) +} + +function literalOf(kind: ValueKind, draft: string): string { + return isText(kind) ? JSON.stringify(draft) : draft.trim() +} + +function problemWith(option: SettingOption, draft: string): string | null { + if (isText(option.kind)) { + return null + } + if (!isNumber(option.kind)) { + return isJson(draft) ? null : 'Not JSON' + } + const number = Number(draft) + if (draft.trim() === '' || !Number.isFinite(number)) { + return 'Not a number' + } + if (option.kind.kind === 'integer' && !Number.isInteger(number)) { + return 'Not a whole number' + } + if (option.minimum !== null && number < option.minimum) { + return `At least ${option.minimum}` + } + if (option.maximum !== null && number > option.maximum) { + return `At most ${option.maximum}` + } + return null +} + +function isJson(text: string): boolean { + try { + JSON.parse(text) + return true + } catch { + return false + } +} diff --git a/src/renderer/src/studio/NodePane.tsx b/src/renderer/src/studio/NodePane.tsx new file mode 100644 index 000000000..122603a70 --- /dev/null +++ b/src/renderer/src/studio/NodePane.tsx @@ -0,0 +1,95 @@ +import { Lock, Redo2, Undo2 } from 'lucide-react' +import { useEffect } from 'react' +import { Button } from '@/components/ui/button' +import type { GraphNode } from '../bridge/types' +import type { NodeEditor } from '../editor/useNodeEditor' +import { NodeCanvas } from './NodeCanvas' +import { isTypingInto } from './shortcuts' + +interface NodePaneProps { + editor: NodeEditor + /** The entry the file belongs to. */ + entryKey: string + selected: GraphNode | null + onSelect(node: GraphNode | null): void +} + +/** The node editor under the scene: the entry's file as nodes, with undo and redo. */ +export function NodePane({ editor, entryKey, selected, onSelect }: NodePaneProps): React.JSX.Element { + const { state } = editor + const locked = state === null || state.locked !== null + useEditorKeys(editor, selected, locked) + + return ( +
+
+

Nodes

+ {state?.file ?? entryKey} + + {state?.locked != null && ( + + + {state.locked} + + )} + {editor.saving && Saving…} + + +
+
+ {state === null &&

Reading the file…

} + {state !== null && state.roots === null && ( +
+

This file can't be shown as nodes

+

{state.problem}

+
+ )} + {state !== null && state.roots !== null && ( + + )} +
+
+ ) +} + +function useEditorKeys(editor: NodeEditor, selected: GraphNode | null, locked: boolean): void { + const { undo, redo, edit } = editor + useEffect(() => { + if (locked) { + return + } + const down = (event: KeyboardEvent): void => { + if (isTypingInto(event.target)) { + return + } + const command = event.ctrlKey || event.metaKey + if (command && event.key.toLowerCase() === 'z') { + event.preventDefault() + if (event.shiftKey) { + redo() + } else { + undo() + } + } else if (command && event.key.toLowerCase() === 'y') { + event.preventDefault() + redo() + } else if (event.key === 'Delete' && selected !== null && selected.duplicable) { + event.preventDefault() + edit({ op: 'delete', path: selected.path }) + } + } + window.addEventListener('keydown', down) + return () => window.removeEventListener('keydown', down) + }, [undo, redo, edit, selected, locked]) +} diff --git a/src/renderer/src/studio/SceneStudio.tsx b/src/renderer/src/studio/SceneStudio.tsx index a282b0fc8..79f5077e3 100644 --- a/src/renderer/src/studio/SceneStudio.tsx +++ b/src/renderer/src/studio/SceneStudio.tsx @@ -2,13 +2,19 @@ import { ChevronLeft, ChevronRight } from 'lucide-react' import { useEffect, useMemo, useState } from 'react' import { Button } from '@/components/ui/button' import { ScrollArea } from '@/components/ui/scroll-area' +import { cn } from '@/lib/utils' import type { BridgeClient } from '../bridge/BridgeClient' -import type { ModuleViewInfo, SceneEntry } from '../bridge/types' +import type { JsonPath, SceneEntry, SceneViewInfo } from '../bridge/types' +import { parsedText } from '../editor/jsonValues' +import { nodeWithPath } from '../editor/nodeLayout' +import { useNodeEditor } from '../editor/useNodeEditor' import { BlockModels } from '../scene/blockModels' import { BridgeAssets } from '../scene/BridgeAssets' import { INTS_PER_BLOCK, type BlockScene } from '../scene/sceneDecoding' import { buildSceneMesh, type SceneMesh } from '../scene/sceneMesh' import { EntryBrowser } from './EntryBrowser' +import { NodeInspector } from './NodeInspector' +import { NodePane } from './NodePane' import { SceneViewport } from './SceneViewport' const NUMBER = new Intl.NumberFormat('en-US') @@ -16,7 +22,7 @@ const DEFAULT_NAMESPACE_PREFIX = 'minecraft:' interface SceneStudioProps { client: BridgeClient - view: ModuleViewInfo + view: SceneViewInfo /** Changes when the pack reloads, so the entries and the scene are read again. */ packRevision: number /** What the status bar says about the scene, or null while none is shown. */ @@ -24,7 +30,10 @@ interface SceneStudioProps { tell(message: string): void } -/** A scene view: its entries on the right, the chosen one in 3D in the middle, with the blocks it is made of. */ +/** + * A scene view: its entries on the right, the chosen one in 3D in the middle, with the blocks it is made of. An + * editable view shows the entry's file as nodes under the scene, and the chosen node's settings on the right. + */ export function SceneStudio({ client, view, packRevision, onSummary, tell }: SceneStudioProps): React.JSX.Element { const [waiting, setWaiting] = useState(null) const images = useMemo(() => new BridgeAssets(client, setWaiting), [client]) @@ -40,37 +49,73 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce } } + const editor = useNodeEditor(client, view.id, view.editable ? (entry?.key ?? null) : null, packRevision, tell) + const [selectedPath, setSelectedPath] = useState(null) + const selected = editor.state?.roots != null && selectedPath !== null ? nodeWithPath(editor.state.roots, selectedPath) : null + const values = useMemo(() => (editor.state === null ? undefined : parsedText(editor.state.text)), [editor.state]) + useEffect(() => onSummary(entry === null || scene === null ? null : summaryOf(entry, scene)), [entry, scene, onSummary]) useEffect(() => () => onSummary(null), [onSummary]) + useEffect(() => setSelectedPath(null), [entry?.key]) return ( <> -
- +
+ + {view.editable && entry !== null && ( + setSelectedPath(node?.path ?? null)} /> + )} +
+ + + ) +} + +interface SceneAreaProps { + entry: SceneEntry | null + variant: number + mesh: SceneMesh | null + /** What is being built, or null when nothing is. */ + status: string | null + onVariant(variant: number): void +} + +function SceneArea({ entry, variant, mesh, status, onVariant }: SceneAreaProps): React.JSX.Element { + return ( +
+ {entry !== null && entry.variants > 1 && (
- Variant {variant + 1} of {entry.variants} -
)} - {building && entry !== null && ( + {status !== null && (
- {waiting ?? `Building ${entry.name}`} + {status}
)} -
- - +
) } diff --git a/src/renderer/src/studio/shortcuts.ts b/src/renderer/src/studio/shortcuts.ts index 14bd71831..18ad2b85d 100644 --- a/src/renderer/src/studio/shortcuts.ts +++ b/src/renderer/src/studio/shortcuts.ts @@ -70,3 +70,8 @@ export function actionForKey(key: string): ShortcutAction | null { export function viewForKey(key: string): string | null { return Object.entries(VIEW_KEYS).find(([, viewKey]) => viewKey === key)?.[0] ?? null } + +/** Whether a key press goes to a field being typed into, so the studio's keys leave it alone. */ +export function isTypingInto(target: EventTarget | null): boolean { + return target instanceof HTMLInputElement || target instanceof HTMLSelectElement || target instanceof HTMLTextAreaElement +} From a27c0bf8607cc37b1d31e2bfeb11d04b3920fee2 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 05:15:02 +0100 Subject: [PATCH 11/12] Show a read-only node editor as a short lock label The reason, outside a studio world, moves to the label's tooltip so the header stays on one line. --- src/renderer/src/studio/NodePane.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/studio/NodePane.tsx b/src/renderer/src/studio/NodePane.tsx index 122603a70..d2f516f67 100644 --- a/src/renderer/src/studio/NodePane.tsx +++ b/src/renderer/src/studio/NodePane.tsx @@ -27,9 +27,9 @@ export function NodePane({ editor, entryKey, selected, onSelect }: NodePaneProps {state?.file ?? entryKey} {state?.locked != null && ( - + - {state.locked} + Read only )} {editor.saving && Saving…} From 1c50eaf776ee3334b43dc899331be1a77e9c837c Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 05:31:18 +0100 Subject: [PATCH 12/12] Fall back to a plain "Opened" when the server sends no message --- src/renderer/src/studio/MapStudio.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/studio/MapStudio.tsx b/src/renderer/src/studio/MapStudio.tsx index 63e39b959..aeb040f99 100644 --- a/src/renderer/src/studio/MapStudio.tsx +++ b/src/renderer/src/studio/MapStudio.tsx @@ -199,7 +199,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps } client .openInEditor(spot.x, spot.z, viewId) - .then((message) => tell(message ?? 'Opened on the server')) + .then((message) => tell(message ?? 'Opened')) .catch((failure: Error) => tell(failure.message)) }, [client, viewId, tell]