Skip to content

Free open-source image editor for the browser

Implement v0

Rodrigoc5485d8b9f4e
diff --git a/.gitignore b/.gitignore
index 6acc570..ba765a4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
node_modules
dist
-.DS_Store
\ No newline at end of file
+.DS_Store
+.vercel
+.env*
diff --git a/.vercelignore b/.vercelignore
new file mode 100644
index 0000000..0638e11
--- /dev/null
+++ b/.vercelignore
@@ -0,0 +1,4 @@
+node_modules
+dist
+.DS_Store
+public/debug
\ No newline at end of file
diff --git a/AGENTS.md b/AGENTS.md
index 15f5d70..16d5c5e 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,14 +1,27 @@
-# vgpu-react-starter
+# OpenLight
-A starting point for a Vite + React + vgpu app. Bun for install and scripts. Biome for format and lint.
+A Vite, React, and vgpu app. Bun for install and scripts. Biome for format and lint.
-`src/main.tsx` mounts `GpuProvider`, which calls `init()` and renders nothing until the device is ready. `src/app.tsx` is the first component inside it. Grow from there.
+`src/main.tsx` owns runtime and provider composition. Browser and WebGPU lifecycles stay behind `vgpu-react` providers and hooks.
## Size
-Build the smallest app that satisfies the current need.
-Keep code local and linear. Add an abstraction or a dependency only when it removes real complexity.
-Grow from the files that already exist. Split a file when it is doing two jobs.
+Keep each file focused on one responsibility and one abstraction level. Entry points compose; providers, hooks, and domain modules own lifecycles and policy.
+Prefer the smallest implementation that preserves clear ownership.
+One component per responsibility: when a component holds state or refs that only part of its markup uses, extract that part into its own component. Within a file, define a function above the function that uses it.
+
+## Structure
+
+The `src/` root holds entrypoints, ambient types, and global styles. Import across folders through the `@/` alias (`@/hooks/use-pointer`); relative paths stay inside a folder. Source modules belong to these folders:
+
+- `app/`: application shell, app-wide state, and composition. It may import every folder below; no folder imports it.
+- `features/`: removable product capabilities. A feature owns its UI, state, and behavior; removing its folder and `app/` composition leaves the rest working. Features never import each other.
+- `components/`: generic React presentation grouped by role, such as `ui/` and `layout/`. It contains no product workflows.
+- `hooks/`: generic React hooks without OpenLight business logic.
+- `lib/`: framework-independent low-level code that could become an external package.
+
+Dependencies point downward: `app/` may import every folder; `features/` may import `components/`, `hooks/`, and `lib/`; `components/` and `hooks/` may import `lib/`.
+Keep feature-specific components, hooks, and helpers inside their feature. Move them to a generic folder only when their interface no longer contains feature concepts.
## GPU
@@ -19,7 +32,8 @@ All React bindings come from `vgpu-react`; everything else comes from `vgpu`.
- `useSurface(canvasRef)` turns a `<canvas>` into a render target and disposes it on unmount. Its options are read once; to change them, remount the canvas with a `key`.
- `useFrameLoop` renders every animation frame. `useFrame` returns a function that renders once, for pointer and other events.
- Shader code lives in `.wgsl` files next to the component that imports them. The Vite loader and ambient types are already configured.
+- The working space is linear Rec.2020 in `rgba16float`. Decoders convert into it, the editor shader converts out of it; nothing in between assumes a format or primaries, so both can change (an 8-bit variant is planned).
## Done
-`bun run check` formats and lints. `bun run build` type-checks. Run both after changing files and before a commit, until neither reports an issue.
+`bun run check` formats and lints. `bun run build` type-checks. Run both after changing files and before a commit.
diff --git a/README.md b/README.md
index 5fb3053..0fa9bee 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,10 @@
-# vgpu-react-starter
+# OpenLight
-A Vite, React, and vgpu starting point.
+**An open-source image editor for the browser, built with [vgpu.sh](https://vgpu.sh)**
+
+Open a photo, adjust light and color, export the result. Edits are non-destructive and rendering runs on your GPU through WebGPU. Everything stays on your machine: no account, no upload.
+
+Needs a WebGPU-capable browser: Chrome or Edge stable, Safari 26+.
## Run
@@ -9,8 +13,11 @@ bun install
bun dev
```
-## Build
-
```sh
-bun run build
+bun run check # format + lint
+bun run build # typecheck + bundle
```
+
+## License
+
+[MIT](LICENSE)
diff --git a/biome.json b/biome.json
index 097fc56..2d29a95 100644
--- a/biome.json
+++ b/biome.json
@@ -2,5 +2,22 @@
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
"includes": ["**", "!dist"]
+ },
+ "linter": {
+ "rules": {
+ "style": {
+ "noRestrictedImports": {
+ "level": "error",
+ "options": {
+ "patterns": [
+ {
+ "group": ["../**"],
+ "message": "Import from @/ instead of a parent directory."
+ }
+ ]
+ }
+ }
+ }
+ }
}
}
diff --git a/bun.lock b/bun.lock
index be39127..add8028 100644
--- a/bun.lock
+++ b/bun.lock
@@ -3,15 +3,20 @@
"configVersion": 1,
"workspaces": {
"": {
- "name": "vgpu-react-starter",
+ "name": "openlight",
"dependencies": {
+ "@tailwindcss/vite": "^4.3.3",
+ "cn": "^0.2.4",
"react": "^19.2.8",
"react-dom": "^19.2.8",
+ "tailwindcss": "^4.3.3",
"vgpu": "^0.3.1",
- "vgpu-react": "^0.1.2",
+ "vgpu-react": "^0.2.0",
},
"devDependencies": {
"@biomejs/biome": "2.5.11",
+ "@types/react": "^19.2.18",
+ "@types/react-dom": "^19.2.5",
"@vitejs/plugin-react": "^6.1.1",
"typescript": "^7.0.2",
"vite": "^8.2.2",
@@ -37,6 +42,16 @@
"@biomejs/cli-win32-x64": ["@biomejs/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-QSQr/KjOgXA7OzXJUWS+oguKyAZ3Q0l/lnlDGbu397eKo83atuWUjBPJrsqbKNF6CARGw8XXJLGzpHC8Ryhd4Q=="],
+ "@jridgewell/gen-mapping": ["@jridgewell/[email protected]", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.0", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA=="],
+
+ "@jridgewell/remapping": ["@jridgewell/[email protected]", "", { "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ=="],
+
+ "@jridgewell/resolve-uri": ["@jridgewell/[email protected]", "", {}, "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw=="],
+
+ "@jridgewell/sourcemap-codec": ["@jridgewell/[email protected]", "", {}, "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="],
+
+ "@jridgewell/trace-mapping": ["@jridgewell/[email protected]", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="],
+
"@modelcontextprotocol/core": ["@modelcontextprotocol/[email protected]", "", { "dependencies": { "zod": "^4.2.0" } }, "sha512-pJCEwGG7Lfr/+PQp9ZTwKXNeO5wzbfKL7H3MYpCorM4oFBoQrdjnBgEoqG+RjhsvS1FKrDbKux+M1HhlnGWqcA=="],
"@modelcontextprotocol/server": ["@modelcontextprotocol/[email protected]", "", { "dependencies": { "@modelcontextprotocol/core": "2.0.0", "zod": "^4.2.0" } }, "sha512-YhHWdHfpFMQfd0prsEnxKeS3Qz3ytIGmsS0sth4KDjnacIT7hxk6hXHkJ9KysxlkvTM+WZAtQbbcUhdoP4Hvtw=="],
@@ -75,6 +90,40 @@
"@rolldown/pluginutils": ["@rolldown/[email protected]", "", {}, "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw=="],
+ "@tailwindcss/node": ["@tailwindcss/[email protected]", "", { "dependencies": { "@jridgewell/remapping": "^2.3.5", "enhanced-resolve": "^5.24.1", "jiti": "^2.7.0", "lightningcss": "1.32.0", "magic-string": "^0.30.21", "source-map-js": "^1.2.1", "tailwindcss": "4.3.3" } }, "sha512-/T8IKEsf9VTU6tLjgC7+sv2mOPtQxzE2jMw7u4Tt40Tx+QSZxpzh95/H6cMKoja9XuW7iMdLJYBB0o9G1CaAgg=="],
+
+ "@tailwindcss/oxide": ["@tailwindcss/[email protected]", "", { "optionalDependencies": { "@tailwindcss/oxide-android-arm64": "4.3.3", "@tailwindcss/oxide-darwin-arm64": "4.3.3", "@tailwindcss/oxide-darwin-x64": "4.3.3", "@tailwindcss/oxide-freebsd-x64": "4.3.3", "@tailwindcss/oxide-linux-arm-gnueabihf": "4.3.3", "@tailwindcss/oxide-linux-arm64-gnu": "4.3.3", "@tailwindcss/oxide-linux-arm64-musl": "4.3.3", "@tailwindcss/oxide-linux-x64-gnu": "4.3.3", "@tailwindcss/oxide-linux-x64-musl": "4.3.3", "@tailwindcss/oxide-wasm32-wasi": "4.3.3", "@tailwindcss/oxide-win32-arm64-msvc": "4.3.3", "@tailwindcss/oxide-win32-x64-msvc": "4.3.3" } }, "sha512-krXjAikiaFSPaK/FkAQT5UTx3VormQaiZ5hBFlJZ9UFQGB/rwg1MZIhHAG9smMQRTdyJxP6Qt5MwMtdyU5FWrA=="],
+
+ "@tailwindcss/oxide-android-arm64": ["@tailwindcss/[email protected]", "", { "os": "android", "cpu": "arm64" }, "sha512-Y85A2gmPSkl5Ve5qR86GL4HT509cFqQh1aes9p3sSkyTPwt0Pppf3GkwGe4JPACcRYjgJIEhQgM6dBClnr0NYw=="],
+
+ "@tailwindcss/oxide-darwin-arm64": ["@tailwindcss/[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-BiaWatpBcERQFDlOjRDpIVXuFK5PJez5SA4JMg6VYZdBYU+qKfV/vqjcIs+IYmtitf1xYQZTwXvU/8y4lfZUGw=="],
+
+ "@tailwindcss/oxide-darwin-x64": ["@tailwindcss/[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-fAeUqfV5ndhxRwai8cXGzdLvul9utWOmeTkv69unv4ZXixjn61Z+p9lCWdwOwA3TYboG3BwdVuN/RDjhBRl0mw=="],
+
+ "@tailwindcss/oxide-freebsd-x64": ["@tailwindcss/[email protected]", "", { "os": "freebsd", "cpu": "x64" }, "sha512-iyf5bV6+wnAlflVeEy7R25dupxTNECZN5QMI0qNT6eT+EgaGdZcKhGkr5SdoaWiLJ3spLqIY9VCeSGrwmtg4kw=="],
+
+ "@tailwindcss/oxide-linux-arm-gnueabihf": ["@tailwindcss/[email protected]", "", { "os": "linux", "cpu": "arm" }, "sha512-aAYUprJAJQWWbRrPvtjdroZ56Md+JM8pMiopS6xGEwDfLhqj+2ver2p4nU4Mb3CRqcMmNBjo8KkUgcxhkzVQGQ=="],
+
+ "@tailwindcss/oxide-linux-arm64-gnu": ["@tailwindcss/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-nDxldcEENOxZRzC2uu9jrutZdAAQtb+8WWDCSnWL1zvBk1+FN+x6MtDViPB5AJMfttVCUhehGWus3XBPgatM/w=="],
+
+ "@tailwindcss/oxide-linux-arm64-musl": ["@tailwindcss/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-Md44bD6veX/PC5iyF8cDVnw4HBIANZepRZZ7a8DQOvkfo5WUBwcp6iAuCUz23u+4SUkhJlD3eL7hNdW8ezd/kA=="],
+
+ "@tailwindcss/oxide-linux-x64-gnu": ["@tailwindcss/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-tx7us1muwOKAKWao2v/GaafFeQboE6aj88vC6ziN2NCGcRm8gWUhwjzg+YdVB1e4boAtdtma4L43onunI6NS4w=="],
+
+ "@tailwindcss/oxide-linux-x64-musl": ["@tailwindcss/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-SJxX60smvHgasZoBy11dX6YRjXJFovwWBoedhbQPOBzgFWBHGB+TVPWB9BxzR7TTxU8FQZAI2AyiNCMzFm8Img=="],
+
+ "@tailwindcss/oxide-wasm32-wasi": ["@tailwindcss/[email protected]", "", { "dependencies": { "@emnapi/core": "^1.11.1", "@emnapi/runtime": "^1.11.1", "@emnapi/wasi-threads": "^1.2.2", "@napi-rs/wasm-runtime": "^1.1.4", "@tybys/wasm-util": "^0.10.2", "tslib": "^2.8.1" }, "cpu": "none" }, "sha512-jx1+rPhY/5Ympkktd656HBWEBLxP7dH06losBLjjf5vgCODXvi9KhtftWcMIwTFIDqBr7cRnQkdLnAG+IOlGvQ=="],
+
+ "@tailwindcss/oxide-win32-arm64-msvc": ["@tailwindcss/[email protected]", "", { "os": "win32", "cpu": "arm64" }, "sha512-3rc292Ca2ceK6Ulcc/bAVnTs/3nDtoPhyEKlgPv+yQJQi/JS/AMJlqzxvlDacL1nekbrcf6bTqp/jV4qgnPxNQ=="],
+
+ "@tailwindcss/oxide-win32-x64-msvc": ["@tailwindcss/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-yJ0pwIVc/nYeGoV02WtsN8KYyLQv7kyI2wDnkezyJlGGjkd4QLwDGAwl47YpPJeuI0M0ObaXGSPjvWDPeTPggw=="],
+
+ "@tailwindcss/vite": ["@tailwindcss/[email protected]", "", { "dependencies": { "@tailwindcss/node": "4.3.3", "@tailwindcss/oxide": "4.3.3", "tailwindcss": "4.3.3" }, "peerDependencies": { "vite": "^5.2.0 || ^6 || ^7 || ^8" } }, "sha512-yYU8cogLeSh/ms2jh8Fj7jaba/EWa7Ja6GoUqYZaraEuCI5YS6ms6ObZgjjedm+jm6XZjdNRWBpPP6Z86oOxcw=="],
+
+ "@types/react": ["@types/[email protected]", "", { "dependencies": { "csstype": "^3.2.2" } }, "sha512-AnzbBERsrLKtk2XSfTbYRLjQPdy116Sty4q+T+Bp3IC4l6jNBvreVPAHmpq9qhXQM7CXZPjLVmGMw9sy+hxQ3w=="],
+
+ "@types/react-dom": ["@types/[email protected]", "", { "peerDependencies": { "@types/react": "^19.2.0" } }, "sha512-fMPwH9v7r/pp43yUd2/Mbiex5KouJwwR3dzHkhLREUC6764VyDsqxhAxv6OFEYR1RhjOyD1naqba8ECDBe7ZQg=="],
+
"@typescript/typescript-aix-ppc64": ["@typescript/[email protected]", "", { "os": "aix", "cpu": "ppc64" }, "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ=="],
"@typescript/typescript-darwin-arm64": ["@typescript/[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA=="],
@@ -129,14 +178,24 @@
"@webgpu/types": ["@webgpu/[email protected]", "", {}, "sha512-0cF7RFM2edNoiIS1ODJp0/Gzv4/xSXhwoR0YCza+OWpJWtn4wmo9DvK91aLlH9+uUnwIriP7ZiC3WitmyhuzBw=="],
+ "cn": ["[email protected]", "", { "bin": { "cn": "bin/cn.mjs" } }, "sha512-SzQvoh5FwizWtQg9+JueKdjWhlfCZMdu5DqNHm9q1wUlRVmKb9WXlepR9bTTbPwzEOyX1ujJ6lcCppmn3bNUCg=="],
+
+ "csstype": ["[email protected]", "", {}, "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ=="],
+
"debug": ["[email protected]", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
"detect-libc": ["[email protected]", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
+ "enhanced-resolve": ["[email protected]", "", { "dependencies": { "graceful-fs": "^4.2.4", "tapable": "^2.3.3" } }, "sha512-L1l8TNvomm6UVW5B253AGxQagSQr+vGwhMlrrfRS2qmhx46AMpMVJKQYLvWYbysTMY8VoicOvzHzoHMbyzB+4A=="],
+
"fdir": ["[email protected]", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="],
"fsevents": ["[email protected]", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="],
+ "graceful-fs": ["[email protected]", "", {}, "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="],
+
+ "jiti": ["[email protected]", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="],
+
"lightningcss": ["[email protected]", "", { "dependencies": { "detect-libc": "^2.0.3" }, "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" } }, "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA=="],
"lightningcss-android-arm64": ["[email protected]", "", { "os": "android", "cpu": "arm64" }, "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg=="],
@@ -161,6 +220,8 @@
"lightningcss-win32-x64-msvc": ["[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA=="],
+ "magic-string": ["[email protected]", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="],
+
"ms": ["[email protected]", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
"nanoid": ["[email protected]", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w=="],
@@ -185,13 +246,17 @@
"source-map-js": ["[email protected]", "", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="],
+ "tailwindcss": ["[email protected]", "", {}, "sha512-gOhV3P7ufE62QDGg1zVaTgCR+EtPv92k2nIhVcVKcLmxT1sUBsQGhnZj175j+MqRt4zLF7ic+sCYjfhxMxj7YQ=="],
+
+ "tapable": ["[email protected]", "", {}, "sha512-uxc/zpqFg6x7C8vOE7lh6Lbda8eEL9zmVm/PLeTPBRhh1xCgdWaQ+J1CUieGpIfm2HdtsUpRv+HshiasBMcc6A=="],
+
"tinyglobby": ["[email protected]", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="],
"typescript": ["[email protected]", "", { "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" }, "bin": { "tsc": "bin/tsc" } }, "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA=="],
"vgpu": ["[email protected]", "", { "dependencies": { "@modelcontextprotocol/server": "2.0.0", "@vgpu/adapter-mock": "0.3.1", "@vgpu/adapter-node": "0.3.1", "@vgpu/core": "0.3.1", "@vgpu/wgsl": "0.3.1", "@vgpu/wgsl-std": "0.3.1", "@webgpu/types": "^0.1.69", "pixelmatch": "^7.2.0", "pngjs": "^7.0.0", "wgpu-matrix": "^3.4.2", "zod": "^4.4.3" }, "bin": { "vgpu": "bin/vgpu.js" } }, "sha512-NeEETis2aCr0I9/8dy42lueNGNs3GZxL+0OmjLI82wlgPD/4WpW/XNX4xduc+ChxFqOJtjEYsz297VS9GmIuyA=="],
- "vgpu-react": ["[email protected]", "", { "peerDependencies": { "react": ">=19", "vgpu": ">=0.3.0" } }, "sha512-VW+4I3ja5sIQjREkSksNajNCxjri6xwZm8ZlntACa4gJNxvu8T2FtI33WfTPcz1XFDJz6hzl+O5YhenUr+Ryfw=="],
+ "vgpu-react": ["[email protected]", "", { "peerDependencies": { "react": ">=19", "vgpu": ">=0.3.0" } }, "sha512-gv/e68VXN9k98M6yJIi8ToxhNEFWCnY9Vt42ONFMFoyvkGhvJG64WG6fNYwfnX47MStFtpYHNNBCTLJvhGQvhA=="],
"vite": ["[email protected]", "", { "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.5", "postcss": "^8.5.26", "rolldown": "~1.2.4", "tinyglobby": "^0.2.17" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "@vitejs/devtools": "^0.4.0 || ^0.5.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" }, "optionalPeers": ["@types/node", "@vitejs/devtools", "esbuild", "jiti", "less", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-cFKLV/PRgAUlIRm5WjMjJ86jrftzpqcgH+Us+DS8mI3CDNiH30Whrz8uHL3+MOLPAgqbMBAqWdAHAphOAM+z/Q=="],
@@ -200,5 +265,41 @@
"wgpu-matrix": ["[email protected]", "", {}, "sha512-IfZFbG7olEYBD76VCZy2TzqM57GKy3LT++AZh37tMHPPByO6R2h61zXGBZFNPi2IzxNivNi8y5dvze5PjaczjA=="],
"zod": ["[email protected]", "", {}, "sha512-sC95tT5iHHH9gtpj6A81kh+NEaRAUFN+qlUPDUbRfOMvNf5QCBqsb3WgvnpVtK5Y+4UfA6KqufotuTvMGiTlsA=="],
+
+ "@tailwindcss/node/lightningcss": ["[email protected]", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.32.0", "lightningcss-darwin-arm64": "1.32.0", "lightningcss-darwin-x64": "1.32.0", "lightningcss-freebsd-x64": "1.32.0", "lightningcss-linux-arm-gnueabihf": "1.32.0", "lightningcss-linux-arm64-gnu": "1.32.0", "lightningcss-linux-arm64-musl": "1.32.0", "lightningcss-linux-x64-gnu": "1.32.0", "lightningcss-linux-x64-musl": "1.32.0", "lightningcss-win32-arm64-msvc": "1.32.0", "lightningcss-win32-x64-msvc": "1.32.0" } }, "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ=="],
+
+ "@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/[email protected]", "", { "dependencies": { "@emnapi/wasi-threads": "1.2.3", "tslib": "^2.4.0" }, "bundled": true }, "sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg=="],
+
+ "@tailwindcss/oxide-wasm32-wasi/@emnapi/runtime": ["@emnapi/[email protected]", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA=="],
+
+ "@tailwindcss/oxide-wasm32-wasi/@emnapi/wasi-threads": ["@emnapi/[email protected]", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-ELEBe8PsLvvJ6QMr0zLt8ffvOHW/dc1m3CEzNMg7aJUv3bMaoDtw2TXyDAwkYBuroxxuHEwhRTLJSe5sya547g=="],
+
+ "@tailwindcss/oxide-wasm32-wasi/@napi-rs/wasm-runtime": ["@napi-rs/[email protected]", "", { "dependencies": { "@tybys/wasm-util": "^0.10.3" }, "peerDependencies": { "@emnapi/core": "^1.7.1 || ^2.0.0-alpha.4", "@emnapi/runtime": "^1.7.1 || ^2.0.0-alpha.4" }, "bundled": true }, "sha512-UMduMbqO5s5zF2NkNacMT/yK5Y5QiKvWr2+50bzIIxFDwVJ2h49b+oyjaCGPhJxd2/gC2x39EHv/gHVuu36x2Q=="],
+
+ "@tailwindcss/oxide-wasm32-wasi/@tybys/wasm-util": ["@tybys/[email protected]", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg=="],
+
+ "@tailwindcss/oxide-wasm32-wasi/tslib": ["[email protected]", "", { "bundled": true }, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-android-arm64": ["[email protected]", "", { "os": "android", "cpu": "arm64" }, "sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-darwin-arm64": ["[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-RzeG9Ju5bag2Bv1/lwlVJvBE3q6TtXskdZLLCyfg5pt+HLz9BqlICO7LZM7VHNTTn/5PRhHFBSjk5lc4cmscPQ=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-darwin-x64": ["[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-U+QsBp2m/s2wqpUYT/6wnlagdZbtZdndSmut/NJqlCcMLTWp5muCrID+K5UJ6jqD2BFshejCYXniPDbNh73V8w=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-freebsd-x64": ["[email protected]", "", { "os": "freebsd", "cpu": "x64" }, "sha512-JCTigedEksZk3tHTTthnMdVfGf61Fky8Ji2E4YjUTEQX14xiy/lTzXnu1vwiZe3bYe0q+SpsSH/CTeDXK6WHig=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-linux-arm-gnueabihf": ["[email protected]", "", { "os": "linux", "cpu": "arm" }, "sha512-x6rnnpRa2GL0zQOkt6rts3YDPzduLpWvwAF6EMhXFVZXD4tPrBkEFqzGowzCsIWsPjqSK+tyNEODUBXeeVHSkw=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-linux-arm64-gnu": ["[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-0nnMyoyOLRJXfbMOilaSRcLH3Jw5z9HDNGfT/gwCPgaDjnx0i8w7vBzFLFR1f6CMLKF8gVbebmkUN3fa/kQJpQ=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-linux-arm64-musl": ["[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-linux-x64-gnu": ["[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-linux-x64-musl": ["[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-win32-arm64-msvc": ["[email protected]", "", { "os": "win32", "cpu": "arm64" }, "sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw=="],
+
+ "@tailwindcss/node/lightningcss/lightningcss-win32-x64-msvc": ["[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q=="],
}
}
diff --git a/index.html b/index.html
index 68479c3..921fa16 100644
--- a/index.html
+++ b/index.html
@@ -3,7 +3,8 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
- <title>vgpu-react-starter</title>
+ <link rel="icon" href="/logo.svg" type="image/svg+xml" />
+ <title>OpenLight</title>
</head>
<body>
<div id="root"></div>
diff --git a/package.json b/package.json
index 6649c4e..3ee8406 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
{
- "name": "vgpu-react-starter",
+ "name": "openlight",
"private": true,
"type": "module",
"scripts": {
@@ -8,13 +8,18 @@
"check": "biome check --write"
},
"dependencies": {
+ "@tailwindcss/vite": "^4.3.3",
+ "cn": "^0.2.4",
"react": "^19.2.8",
"react-dom": "^19.2.8",
+ "tailwindcss": "^4.3.3",
"vgpu": "^0.3.1",
- "vgpu-react": "^0.1.2"
+ "vgpu-react": "^0.2.0"
},
"devDependencies": {
"@biomejs/biome": "2.5.11",
+ "@types/react": "^19.2.18",
+ "@types/react-dom": "^19.2.5",
"@vitejs/plugin-react": "^6.1.1",
"typescript": "^7.0.2",
"vite": "^8.2.2"
diff --git a/public/logo.svg b/public/logo.svg
new file mode 100644
index 0000000..bd423ee
--- /dev/null
+++ b/public/logo.svg
@@ -0,0 +1,7 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-labelledby="logo-title">
+ <title id="logo-title">OpenLight</title>
+ <rect width="64" height="64" rx="14" fill="#232323" />
+ <path d="M12 48c2-20 15-32 40-32" fill="none" opacity=".35" stroke="#f2f2f2" stroke-linecap="round" stroke-width="4" />
+ <path d="M12 48c18 0 22-32 40-32" fill="none" stroke="#f2f2f2" stroke-linecap="round" stroke-width="4" />
+ <path d="M12 48c25 0 38-13 40-32" fill="none" opacity=".35" stroke="#f2f2f2" stroke-linecap="round" stroke-width="4" />
+</svg>
diff --git a/src/app.tsx b/src/app.tsx
deleted file mode 100644
index b302471..0000000
--- a/src/app.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { useMemo, useRef } from "react";
-import { effect } from "vgpu";
-import { useFrameLoop, useGpu, useSurface } from "vgpu-react";
-import shader from "./shader.wgsl";
-
-export default function App() {
- const gpu = useGpu();
- const pass = useMemo(() => effect(gpu, shader), [gpu]);
- const canvas = useRef<HTMLCanvasElement>(null);
- const target = useSurface(canvas);
-
- useFrameLoop((frame) => {
- if (target.current) {
- frame.pass(target.current, pass);
- }
- });
-
- return <canvas ref={canvas} />;
-}
diff --git a/src/app/backdrop.tsx b/src/app/backdrop.tsx
new file mode 100644
index 0000000..0943389
--- /dev/null
+++ b/src/app/backdrop.tsx
@@ -0,0 +1,40 @@
+import { useRef } from "react";
+import { clock } from "vgpu";
+import { Canvas, useCanvas, useFrameLoop, useGpu, useShader } from "vgpu-react";
+import usePointer from "@/hooks/use-pointer";
+import shader from "./backdrop.wgsl";
+
+const strength = { none: 0, hover: 0.05, drag: 1 };
+
+function Glow() {
+ const target = useCanvas();
+ const time = clock(useGpu());
+ const glow = useShader(shader);
+ const pointer = usePointer();
+ const pull = useRef(0);
+
+ useFrameLoop((frame) => {
+ const { x, y, mode } = pointer.current;
+ const ease = 1 - Math.exp(-time.deltaTime * 8);
+ pull.current += (strength[mode] - pull.current) * ease;
+ glow.set({
+ params: {
+ pointer: [x, y],
+ size: target.size,
+ time: time.time,
+ pull: pull.current,
+ },
+ });
+ frame.pass(target, glow);
+ });
+
+ return null;
+}
+
+export default function Backdrop() {
+ return (
+ <Canvas className="absolute inset-0 -z-10 size-full" dpr={[1, 2]}>
+ <Glow />
+ </Canvas>
+ );
+}
diff --git a/src/app/backdrop.wgsl b/src/app/backdrop.wgsl
new file mode 100644
index 0000000..4f10918
--- /dev/null
+++ b/src/app/backdrop.wgsl
@@ -0,0 +1,73 @@
+import { tau } from "@vgpu/wgsl-std/constants";
+import { hash2, hash3 } from "@vgpu/wgsl-std/hash";
+import { rotate2d } from "@vgpu/wgsl-std/math";
+import { simplex3d } from "@vgpu/wgsl-std/noise/simplex";
+
+struct Params {
+ pointer: vec2f,
+ size: vec2f,
+ time: f32,
+ pull: f32,
+}
+@group(0) @binding(0) var<uniform> params: Params;
+
+const dark = vec3f(0.075);
+const light = vec3f(0.21, 0.2, 0.19);
+const mote = vec3f(1.0, 0.94, 0.82);
+
+// One drifting, twinkling mote per grid cell; each pixel checks its 3x3 neighborhood.
+fn motes(p: vec2f, t: f32, density: f32, rise: f32) -> f32 {
+ let q = p * density + vec2f(0.0, t * rise);
+ let cell = floor(q);
+ let f = q - cell;
+ var sum = 0.0;
+ for (var y = -1; y <= 1; y++) {
+ for (var x = -1; x <= 1; x++) {
+ let o = vec2f(f32(x), f32(y));
+ let h = hash3(vec3f(cell + o, density));
+ let sway = vec2f(sin(t * 0.5 + h.z * tau), cos(t * 0.4 + h.x * tau)) * 0.2;
+ let dist = distance(f, o + 0.3 + h.xy * 0.4 + sway);
+ let size = 0.03 + h.z * 0.05;
+ let twinkle = 0.55 + 0.45 * sin(t * (0.8 + h.y * 1.5) + h.x * tau);
+ let dot = 1.0 - smoothstep(0.0, size, dist);
+ sum += dot * dot * twinkle;
+ }
+ }
+ return sum;
+}
+
+@fragment fn fs_main(
+ @location(0) uv: vec2f,
+ @builtin(position) pixel: vec4f,
+) -> @location(0) vec4f {
+ let t = params.time;
+ // pull is 0.05 under a hovering mouse and 1 under a dragged file:
+ // the mouse only nudges the motes, the file gets the whole effect.
+ let pull = params.pull;
+ let drag = smoothstep(0.05, 1.0, pull);
+ let frame = vec2f(params.size.x / params.size.y, 1.0);
+ let p = (uv - 0.5) * frame;
+ let pointer = (params.pointer - 0.5) * frame;
+ let falloff = 1.0 - smoothstep(0.0, 0.3, distance(p, pointer));
+ let near = drag * falloff;
+
+ let drift = vec2f(sin(t * 0.5), cos(t * 0.37)) * 0.08;
+ let r = distance(p, mix(drift, pointer, drag * 0.4));
+ let wobble = simplex3d(vec3f(p * 1.2, t * 0.3)) * 0.15;
+ let radius = (0.55 + 0.12 * drag) * length(frame * 0.5) + 0.04 * sin(t * 0.7);
+ let beam = 1.0 - smoothstep(0.0, 1.0, r / radius + wobble);
+ let glow = beam + near * 0.4;
+
+ // Magnet: pixels near the pointer sample motes from farther out and rotated,
+ // so they crowd and spiral in. Only a dragged file gets the spiral.
+ let q = pointer + rotate2d(p - pointer, near * 1.6) * (1.0 + pull * falloff * 1.2);
+
+ // Dust shows where the light is: inside the beam, and around a dragged file.
+ let dust = motes(q, t, 7.0, 0.3) + motes(q, t, 12.0, 0.25) * 0.5;
+ let lit = 0.15 + 0.6 * beam + near * 0.6;
+
+ // Static per-pixel dither hides banding in the few gray levels the glow spans.
+ let dither = (hash2(pixel.xy).x - 0.5) / 255.0;
+ let color = mix(dark, light, glow) + mote * dust * lit;
+ return vec4f(color + dither, 1.0);
+}
diff --git a/src/app/editor.tsx b/src/app/editor.tsx
new file mode 100644
index 0000000..47f2579
--- /dev/null
+++ b/src/app/editor.tsx
@@ -0,0 +1,80 @@
+import { useEffect, useState } from "react";
+import { sampler } from "vgpu";
+import { Canvas, useCanvas, useFrameLoop, useGpu, useShader } from "vgpu-react";
+import ResizablePanel from "@/components/ui/resizable-panel";
+import Spinner from "@/components/ui/spinner";
+import usePanZoom, { type View } from "@/hooks/use-pan-zoom";
+import decode, { type Target } from "@/lib/decode";
+import shader from "./editor.wgsl";
+
+/** Decodes the file into the GPU, disposing it on cleanup. */
+function useDecode(file: File) {
+ const gpu = useGpu();
+ const [image, setImage] = useState<Target>();
+
+ useEffect(() => {
+ let cancelled = false;
+ const decoding = decode(gpu, file);
+ decoding.then((image) => !cancelled && setImage(image));
+ return () => {
+ cancelled = true;
+ decoding.then((image) => image.color.dispose());
+ setImage(undefined);
+ };
+ }, [gpu, file]);
+
+ return image;
+}
+
+type ImageProps = { image: Target; view: View };
+
+function Image({ image, view }: ImageProps) {
+ const gpu = useGpu();
+ const target = useCanvas();
+ const draw = useShader(shader, {
+ set: {
+ sourceSampler: sampler(gpu, { magFilter: "linear", minFilter: "linear" }),
+ },
+ });
+
+ useFrameLoop((frame) => {
+ draw.set({
+ source: image.color,
+ params: {
+ size: target.size,
+ image: image.size,
+ pan: view.pan.map((p) => p * target.dpr),
+ zoom: view.zoom,
+ },
+ });
+ frame.pass(target, draw);
+ });
+
+ return null;
+}
+
+type EditorProps = { file: File };
+
+export default function Editor({ file }: EditorProps) {
+ const image = useDecode(file);
+ const { ref, view, handlers } = usePanZoom(image?.size);
+
+ return (
+ <main className="flex h-full">
+ <div
+ className="grid min-w-0 flex-1 cursor-grab touch-none place-items-center active:cursor-grabbing"
+ ref={ref}
+ {...handlers}
+ >
+ {image ? (
+ <Canvas className="size-full min-h-0">
+ <Image image={image} view={view} />
+ </Canvas>
+ ) : (
+ <Spinner />
+ )}
+ </div>
+ <ResizablePanel />
+ </main>
+ );
+}
diff --git a/src/app/editor.wgsl b/src/app/editor.wgsl
new file mode 100644
index 0000000..c6bac68
--- /dev/null
+++ b/src/app/editor.wgsl
@@ -0,0 +1,30 @@
+import { linearToSrgb3 } from "@vgpu/wgsl-std/color";
+
+struct Params {
+ size: vec2f,
+ image: vec2f,
+ pan: vec2f,
+ zoom: f32,
+}
+@group(0) @binding(0) var<uniform> params: Params;
+@group(0) @binding(1) var source: texture_2d<f32>;
+@group(0) @binding(2) var sourceSampler: sampler;
+
+const background = vec3f(0.09);
+
+// Rec.2020, the working space, to linear sRGB primaries (column-major).
+const rec2020ToSrgb = mat3x3f(
+ 1.6605, -0.1246, -0.0182,
+ -0.5876, 1.1329, -0.1006,
+ -0.0728, -0.0083, 1.1187,
+);
+
+@fragment fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
+ // Zoom 1 fits the image (contain, capped at 1:1), scaled about the center, then shifted by pan.
+ let scale = min(min(params.size.x / params.image.x, params.size.y / params.image.y), 1.0) * params.zoom;
+ let p = ((uv - 0.5) * params.size - params.pan) / (params.image * scale) + 0.5;
+ let inside = all(p >= vec2f(0.0)) && all(p <= vec2f(1.0));
+ let linear = rec2020ToSrgb * textureSampleLevel(source, sourceSampler, p, 0.0).rgb;
+ let color = linearToSrgb3(clamp(linear, vec3f(0.0), vec3f(1.0)));
+ return vec4f(select(background, color, inside), 1.0);
+}
diff --git a/src/app/index.tsx b/src/app/index.tsx
new file mode 100644
index 0000000..58f4d1c
--- /dev/null
+++ b/src/app/index.tsx
@@ -0,0 +1,13 @@
+import { useState } from "react";
+import Editor from "./editor";
+import Landing from "./landing";
+
+export default function App() {
+ const [file, setFile] = useState<File>();
+
+ if (!file) {
+ return <Landing onOpen={setFile} />;
+ }
+
+ return <Editor file={file} />;
+}
diff --git a/src/app/landing.tsx b/src/app/landing.tsx
new file mode 100644
index 0000000..8e3cec0
--- /dev/null
+++ b/src/app/landing.tsx
@@ -0,0 +1,53 @@
+import { type DragEvent, useRef } from "react";
+import Button from "@/components/ui/button";
+import { accept, canDecode } from "@/lib/decode";
+import Backdrop from "./backdrop";
+
+type OpenProps = { onOpen: (files: FileList | null) => void };
+
+function OpenImage({ onOpen }: OpenProps) {
+ const input = useRef<HTMLInputElement>(null);
+ return (
+ <>
+ <Button className="mt-3" onClick={() => input.current?.click()}>
+ Open image
+ </Button>
+ <input
+ accept={accept}
+ hidden
+ onChange={(event) => onOpen(event.currentTarget.files)}
+ ref={input}
+ type="file"
+ />
+ </>
+ );
+}
+
+type LandingProps = { onOpen: (image: File) => void };
+
+export default function Landing({ onOpen }: LandingProps) {
+ const open = (files: FileList | null) => {
+ const image = files?.[0];
+ if (image && canDecode(image)) {
+ onOpen(image);
+ }
+ };
+ const drop = (event: DragEvent) => {
+ event.preventDefault();
+ open(event.dataTransfer.files);
+ };
+
+ return (
+ <main
+ className="relative isolate grid h-full place-content-center justify-items-center gap-3 bg-[radial-gradient(circle,#292929,#131313_55%)]"
+ onDragOver={(event) => event.preventDefault()}
+ onDrop={drop}
+ >
+ <Backdrop />
+ <img alt="" className="w-16" height="64" src="/logo.svg" width="64" />
+ <h1 className="text-2xl font-bold">OpenLight</h1>
+ <p className="text-neutral-400">Edit locally in your browser.</p>
+ <OpenImage onOpen={open} />
+ </main>
+ );
+}
diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx
new file mode 100644
index 0000000..f1bb567
--- /dev/null
+++ b/src/components/ui/button.tsx
@@ -0,0 +1,18 @@
+import { cn } from "cn";
+import type { ComponentProps } from "react";
+
+export default function Button({
+ className,
+ ...props
+}: ComponentProps<"button">) {
+ return (
+ <button
+ className={cn(
+ "cursor-pointer rounded-lg bg-neutral-100 px-4 py-2.5 text-neutral-900 focus-visible:outline-2 focus-visible:outline-offset-3 focus-visible:outline-neutral-400",
+ className,
+ )}
+ type="button"
+ {...props}
+ />
+ );
+}
diff --git a/src/components/ui/resizable-panel.tsx b/src/components/ui/resizable-panel.tsx
new file mode 100644
index 0000000..794275a
--- /dev/null
+++ b/src/components/ui/resizable-panel.tsx
@@ -0,0 +1,41 @@
+import { cn } from "cn";
+import { type ComponentProps, type PointerEvent, useState } from "react";
+
+type ResizablePanelProps = ComponentProps<"aside"> & {
+ width?: number;
+ min?: number;
+ max?: number;
+};
+
+/** Right-side panel resized by dragging its left edge. */
+export default function ResizablePanel({
+ width: initial = 288,
+ min = 240,
+ max = 400,
+ className,
+ style,
+ children,
+ ...props
+}: ResizablePanelProps) {
+ const [width, setWidth] = useState(initial);
+ const resize = (event: PointerEvent) =>
+ event.buttons === 1 &&
+ setWidth((width) => Math.min(max, Math.max(min, width - event.movementX)));
+
+ return (
+ <aside
+ className={cn("relative shrink-0", className)}
+ style={{ width, ...style }}
+ {...props}
+ >
+ <div
+ className="absolute inset-y-0 -left-1 w-2 cursor-col-resize touch-none after:absolute after:inset-y-0 after:left-1 after:w-px after:bg-neutral-800 hover:after:bg-neutral-700 after:transition-colors after:duration-200"
+ onPointerDown={(event) =>
+ event.currentTarget.setPointerCapture(event.pointerId)
+ }
+ onPointerMove={resize}
+ />
+ {children}
+ </aside>
+ );
+}
diff --git a/src/components/ui/spinner.tsx b/src/components/ui/spinner.tsx
new file mode 100644
index 0000000..c591bc9
--- /dev/null
+++ b/src/components/ui/spinner.tsx
@@ -0,0 +1,19 @@
+import { cn } from "cn";
+import type { ComponentProps } from "react";
+
+export default function Spinner({
+ className,
+ ...props
+}: ComponentProps<"div">) {
+ return (
+ <div
+ aria-label="Loading"
+ className={cn(
+ "size-5 animate-spin rounded-full border-2 border-neutral-600 border-t-neutral-100",
+ className,
+ )}
+ role="status"
+ {...props}
+ />
+ );
+}
diff --git a/src/hooks/use-pan-zoom.ts b/src/hooks/use-pan-zoom.ts
new file mode 100644
index 0000000..6b1dba6
--- /dev/null
+++ b/src/hooks/use-pan-zoom.ts
@@ -0,0 +1,108 @@
+import {
+ type PointerEvent,
+ useCallback,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
+
+type Size = readonly [number, number, ...unknown[]];
+type Point = readonly [number, number];
+/** `percent` is image px per screen px × 100: 100 is real size. */
+export type View = { zoom: number; pan: Point; percent: number };
+
+const fit: View = { zoom: 1, pan: [0, 0], percent: 0 };
+const maxZoom = 8;
+
+/** Keeps the content point under `focal` fixed while changing zoom. */
+function zoomAt(view: View, focal: Point, zoom: number): View {
+ const ratio = Math.min(Math.max(zoom, 1), maxZoom) / view.zoom;
+ return {
+ ...view,
+ zoom: view.zoom * ratio,
+ pan: [
+ focal[0] + (view.pan[0] - focal[0]) * ratio,
+ focal[1] + (view.pan[1] - focal[1]) * ratio,
+ ],
+ };
+}
+
+/** Axes smaller than the viewport stay centered; larger ones cannot pan past their edge. */
+function clamp(view: View, content: Size, viewport: Size): View {
+ const scale =
+ Math.min(
+ viewport[0] / content[0],
+ viewport[1] / content[1],
+ 1 / devicePixelRatio,
+ ) * view.zoom;
+ const axis = (i: 0 | 1) => {
+ const room = Math.max(0, (content[i] * scale - viewport[i]) / 2);
+ return Math.min(room, Math.max(-room, view.pan[i]));
+ };
+ return {
+ zoom: view.zoom,
+ pan: [axis(0), axis(1)],
+ percent: scale * devicePixelRatio * 100,
+ };
+}
+
+/**
+ * Pan and zoom over `content` inside the element given `ref`.
+ * Zoom 1 is the initial fit: contain, but no larger than real size. `pan` is in CSS px from the viewport center.
+ * Wheel pans, ctrl/cmd+wheel (and pinch) zooms at the cursor, drag pans, double-click resets.
+ */
+export default function usePanZoom(content?: Size) {
+ const ref = useRef<HTMLDivElement>(null);
+ const [view, setView] = useState(fit);
+
+ const update = useCallback(
+ (next: (view: View) => View) => {
+ const element = ref.current;
+ if (element && content) {
+ const viewport: Size = [element.clientWidth, element.clientHeight];
+ setView((view) => clamp(next(view), content, viewport));
+ }
+ },
+ [content],
+ );
+
+ useEffect(() => {
+ const element = ref.current;
+ if (!element) {
+ return;
+ }
+ update((view) => view);
+ const wheel = (event: WheelEvent) => {
+ event.preventDefault();
+ const { left, top, width, height } = element.getBoundingClientRect();
+ const focal: Point = [
+ event.clientX - left - width / 2,
+ event.clientY - top - height / 2,
+ ];
+ update((view) =>
+ event.ctrlKey || event.metaKey
+ ? zoomAt(view, focal, view.zoom * Math.exp(-event.deltaY / 100))
+ : {
+ ...view,
+ pan: [view.pan[0] - event.deltaX, view.pan[1] - event.deltaY],
+ },
+ );
+ };
+ element.addEventListener("wheel", wheel, { passive: false });
+ return () => element.removeEventListener("wheel", wheel);
+ }, [update]);
+
+ const handlers = {
+ onPointerDown: (event: PointerEvent<HTMLElement>) =>
+ event.currentTarget.setPointerCapture(event.pointerId),
+ onPointerMove: (event: PointerEvent<HTMLElement>) =>
+ event.buttons === 1 &&
+ update((view) => ({
+ ...view,
+ pan: [view.pan[0] + event.movementX, view.pan[1] + event.movementY],
+ })),
+ onDoubleClick: () => setView(fit),
+ };
+
+ return { ref, view, handlers };
+}
diff --git a/src/hooks/use-pointer.ts b/src/hooks/use-pointer.ts
new file mode 100644
index 0000000..645e911
--- /dev/null
+++ b/src/hooks/use-pointer.ts
@@ -0,0 +1,31 @@
+import { useEffect, useRef } from "react";
+
+type Mode = "none" | "hover" | "drag";
+type Pointer = { x: number; y: number; mode: Mode };
+
+/** Where the mouse or a dragged file last was, as fractions of the viewport. */
+export default function usePointer() {
+ const pointer = useRef<Pointer>({ x: 0, y: 0, mode: "none" });
+
+ useEffect(() => {
+ const controller = new AbortController();
+ const { signal } = controller;
+ const track =
+ (mode: Mode) =>
+ ({ clientX, clientY }: MouseEvent) => {
+ pointer.current = {
+ x: clientX / innerWidth,
+ y: clientY / innerHeight,
+ mode,
+ };
+ };
+ document.addEventListener("pointermove", track("hover"), { signal });
+ document.addEventListener("pointerleave", track("none"), { signal });
+ document.addEventListener("dragover", track("drag"), { signal });
+ document.addEventListener("dragleave", track("none"), { signal });
+ document.addEventListener("drop", track("none"), { signal });
+ return () => controller.abort();
+ }, []);
+
+ return pointer;
+}
diff --git a/src/index.css b/src/index.css
index 0cfa9d1..c00c0b6 100644
--- a/src/index.css
+++ b/src/index.css
@@ -1,12 +1,18 @@
-html,
-body,
-#root {
- height: 100%;
- margin: 0;
-}
+@import "tailwindcss";
+
+@layer base {
+ html,
+ body,
+ #root {
+ height: 100%;
+ }
-canvas {
- display: block;
- width: 100%;
- height: 100%;
+ body {
+ overflow: hidden;
+ font:
+ 15px system-ui,
+ sans-serif;
+ color: var(--color-neutral-100);
+ background: var(--color-neutral-900);
+ }
}
diff --git a/src/lib/decode/index.ts b/src/lib/decode/index.ts
new file mode 100644
index 0000000..dff964b
--- /dev/null
+++ b/src/lib/decode/index.ts
@@ -0,0 +1,70 @@
+import type { Gpu, Target } from "vgpu";
+import linearize from "./linearize";
+import decodeSvg from "./svg";
+import type { Decoder, Pixels } from "./types";
+
+export type { Target };
+
+/** Decoder backed by a worker module: post the file, receive transferred pixels or an error. */
+export function workerDecoder(
+ load: () => Promise<{ default: new () => Worker }>,
+) {
+ return async (): Promise<Decoder> => {
+ const { default: Spawn } = await load();
+ return (file) =>
+ new Promise((resolve, reject) => {
+ const worker = new Spawn();
+ worker.onmessage = ({
+ data,
+ }: MessageEvent<Pixels | { error: string }>) => {
+ "error" in data ? reject(new Error(data.error)) : resolve(data);
+ worker.terminate();
+ };
+ worker.postMessage(file);
+ });
+ };
+}
+
+type Format = {
+ types: string[];
+ extensions: string[];
+ load: () => Promise<Decoder>;
+};
+
+const native = async () => createImageBitmap;
+const svg = async () => decodeSvg;
+
+const formats: Format[] = [
+ { types: ["image/png"], extensions: ["png"], load: native },
+ { types: ["image/jpeg"], extensions: ["jpg", "jpeg"], load: native },
+ { types: ["image/gif"], extensions: ["gif"], load: native },
+ { types: ["image/webp"], extensions: ["webp"], load: native },
+ { types: ["image/avif"], extensions: ["avif"], load: native },
+ { types: ["image/bmp"], extensions: ["bmp"], load: native },
+ { types: ["image/svg+xml"], extensions: ["svg"], load: svg },
+];
+
+/** Matches by MIME type, then by extension for files the OS doesn't type. */
+function formatOf(file: File) {
+ const extension = file.name.split(".").pop()?.toLowerCase() ?? "";
+ return formats.find(
+ (f) => f.types.includes(file.type) || f.extensions.includes(extension),
+ );
+}
+
+/** Types and extensions `decode` accepts, for `<input accept>`. */
+export const accept = formats
+ .flatMap((f) => [...f.types, ...f.extensions.map((e) => `.${e}`)])
+ .join(",");
+
+export const canDecode = (file: File) => formatOf(file) !== undefined;
+
+/** Decodes the file into a linear rgba16float target: the format's decoder, then its GPU leg. */
+export default async function decode(gpu: Gpu, file: File): Promise<Target> {
+ const format = formatOf(file);
+ if (!format) {
+ throw new Error(`Unsupported image: ${file.name}`);
+ }
+ const decoder = await format.load();
+ return linearize(gpu, await decoder(file));
+}
diff --git a/src/lib/decode/linearize.ts b/src/lib/decode/linearize.ts
new file mode 100644
index 0000000..e18fda3
--- /dev/null
+++ b/src/lib/decode/linearize.ts
@@ -0,0 +1,40 @@
+import { effect, frame, type Gpu, target } from "vgpu";
+import shader from "./linearize.wgsl";
+import type { Decoded } from "./types";
+
+type Size = readonly [number, number];
+
+/** Stages the decoded bytes in a texture whose format decodes them to linear when read. */
+function stage(gpu: Gpu, decoded: Decoded, size: Size) {
+ const texture = gpu.device.createTexture({
+ size,
+ format: "rgba8unorm-srgb",
+ usage: ["texture_binding", "copy_dst", "render_attachment"],
+ });
+ if (decoded instanceof ImageBitmap) {
+ gpu.gpu.queue.copyExternalImageToTexture(
+ { source: decoded },
+ { texture: texture.gpu },
+ size,
+ );
+ decoded.close();
+ } else {
+ gpu.gpu.queue.writeTexture(
+ { texture: texture.gpu },
+ decoded.data,
+ { bytesPerRow: decoded.width * 4 },
+ size,
+ );
+ }
+ return texture;
+}
+
+/** GPU leg for sRGB-encoded decoders: renders the decoded image into a linear Rec.2020 rgba16float target. */
+export default function linearize(gpu: Gpu, decoded: Decoded) {
+ const size: Size = [decoded.width, decoded.height];
+ const source = stage(gpu, decoded, size);
+ const image = target(gpu, { size, format: "rgba16float" });
+ frame(gpu, (f) => f.pass(image, effect(gpu, shader, { set: { source } })));
+ source.dispose();
+ return image;
+}
diff --git a/src/lib/decode/linearize.wgsl b/src/lib/decode/linearize.wgsl
new file mode 100644
index 0000000..a84c812
--- /dev/null
+++ b/src/lib/decode/linearize.wgsl
@@ -0,0 +1,13 @@
+@group(0) @binding(0) var source: texture_2d<f32>;
+
+// Linear sRGB primaries to Rec.2020, the working space (column-major).
+const srgbToRec2020 = mat3x3f(
+ 0.6274, 0.0691, 0.0164,
+ 0.3293, 0.9195, 0.0880,
+ 0.0433, 0.0114, 0.8956,
+);
+
+@fragment fn fs_main(@builtin(position) position: vec4f) -> @location(0) vec4f {
+ let texel = textureLoad(source, vec2i(position.xy), 0);
+ return vec4f(srgbToRec2020 * texel.rgb, texel.a);
+}
diff --git a/src/lib/decode/svg.ts b/src/lib/decode/svg.ts
new file mode 100644
index 0000000..d5eb7cc
--- /dev/null
+++ b/src/lib/decode/svg.ts
@@ -0,0 +1,15 @@
+const fallbackSize = 1024;
+
+/** Rasterizes through an <img>, since SVGs without intrinsic size can't go straight to a bitmap. */
+export default async function decodeSvg(file: Blob) {
+ const image = new Image();
+ image.src = URL.createObjectURL(file);
+ await image.decode();
+ URL.revokeObjectURL(image.src);
+ const canvas = new OffscreenCanvas(
+ image.naturalWidth || fallbackSize,
+ image.naturalHeight || fallbackSize,
+ );
+ canvas.getContext("2d")?.drawImage(image, 0, 0, canvas.width, canvas.height);
+ return canvas.transferToImageBitmap();
+}
diff --git a/src/lib/decode/types.ts b/src/lib/decode/types.ts
new file mode 100644
index 0000000..823c0da
--- /dev/null
+++ b/src/lib/decode/types.ts
@@ -0,0 +1,8 @@
+/** Raw interleaved rgba8, for decoders that don't go through the browser's image pipeline. */
+export type Pixels = {
+ width: number;
+ height: number;
+ data: Uint8ClampedArray<ArrayBuffer>;
+};
+export type Decoded = ImageBitmap | Pixels;
+export type Decoder = (file: Blob) => Promise<Decoded>;
diff --git a/src/shader.wgsl b/src/shader.wgsl
deleted file mode 100644
index 63a3665..0000000
--- a/src/shader.wgsl
+++ /dev/null
@@ -1,3 +0,0 @@
-@fragment fn fs_main(@location(0) uv: vec2f) -> @location(0) vec4f {
- return vec4f(uv, 0.4, 1);
-}
diff --git a/tsconfig.json b/tsconfig.json
index fb3dc94..edd99aa 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -8,7 +8,10 @@
"strict": true,
"noEmit": true,
"skipLibCheck": true,
- "isolatedModules": true
+ "isolatedModules": true,
+ "paths": {
+ "@/*": ["./src/*"]
+ }
},
"include": ["src"]
}
diff --git a/vite.config.ts b/vite.config.ts
index 02c8bcb..93444f6 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,4 +1,8 @@
+import tailwindcss from "@tailwindcss/vite";
import { wgslVitePlugin } from "@vgpu/wgsl/loader-vite";
import react from "@vitejs/plugin-react";
-export default { plugins: [react(), wgslVitePlugin()] };
+export default {
+ plugins: [react(), tailwindcss(), wgslVitePlugin()],
+ resolve: { alias: { "@": "/src" } },
+};