Skip to content

Free open-source image editor for the browser

Open the editor without a document (#31)

Rodrigo Belfiorec8364afd516d
diff --git a/AGENTS.md b/AGENTS.md
index c86d6b9..38cd901 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -2,7 +2,7 @@
Build a professional photo editor with little, readable code. Vite, React, vgpu, Bun, and Biome.
-Write committed code, comments, documentation, and UI text in English. Use [CONTEXT.md](CONTEXT.md) for domain terms. [README.md](README.md#development) covers setup; [API.md](API.md) documents browser commands; [REVIEW.md](REVIEW.md) guides reviews.
+Write committed code, comments, documentation, and UI text in English. Use [CONTEXT.md](CONTEXT.md) for domain terms. [CONTRIBUTING.md](CONTRIBUTING.md#development) covers setup; [API.md](API.md) documents browser commands; [REVIEW.md](REVIEW.md) guides reviews.
## Simplicity
@@ -64,7 +64,7 @@ Check meaningful output using a few representative samples, expected relationshi
Core algorithms also merit focused unit tests, especially rendering order, branch/merge connections, and resource reuse. Use Bun and real application modules with `vgpu/mock` for engine orchestration; the mock does not execute shaders. Use Playwright for rendered pixels, DOM interaction, and real format fixtures. Maintain the semantic [control API](API.md) for local, CI, and remote use. Wait for observable results; avoid production completion tracking added only for tests.
-For code changes, run `bun run check`, `bun run build`, `bun run test`, and `bun run test:browser` before a commit. Browser setup and focused commands are in [README.md](README.md#validation). For documentation-only changes, check the diff and affected references.
+For code changes, run `bun run check`, `bun run build`, `bun run test`, and `bun run test:browser` before a commit. Browser setup and focused commands are in [CONTRIBUTING.md](CONTRIBUTING.md#validation). For documentation-only changes, check the diff and affected references.
Prepare evidence during implementation and include it in the initial PR description, using the [PR template](.github/pull_request_template.md). Lead with the problem and resulting behavior. Keep prose short and use compact comparison tables. Generated screenshots, logs, reports, and benchmark samples belong in ignored output directories and PR/CI attachments, not in Git. Commit test fixtures when maintained tests need them. Omit work logs and repeated explanations.
diff --git a/API.md b/API.md
index b32f506..f9fbac7 100644
--- a/API.md
+++ b/API.md
@@ -28,6 +28,7 @@ These methods accept browser `File` objects and return `Promise<void>`. Await th
| `openFile(file)` | Opens one image or imports one Camera Raw XMP file. |
| `openFiles(files)` | Opens the first recognized image, then imports recognized XMP files in order. Unsupported files are ignored. |
| `loadImage(file)` | Loads a file as an image, replacing the current document and its history. |
+| `loadUrl(url)` | Fetches an image from a same-origin URL and loads it; `/demo` uses it for the bundled sample. |
| `importXmp(file)` | Applies supported Camera Raw adjustments as one undoable edit. |
Loading calls are queued. XMP import is skipped if no document is ready; an invalid XMP import can reject without blocking later loads. Image decoding failures appear in the workspace's error state and do not reject the loading promise. Check `getState().documentId` to confirm success. Loading completion does not guarantee the preview has rendered.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..da1981e
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,54 @@
+# Contributing
+
+OpenLight is built with TypeScript, React, [vgpu](https://vgpu.sh), Bun, and Biome. [AGENTS.md](AGENTS.md) describes the architecture, ownership rules, and completion requirements; [CONTEXT.md](CONTEXT.md) holds the domain vocabulary; [REVIEW.md](REVIEW.md) guides reviews; [PERFORMANCE.md](PERFORMANCE.md) covers render nodes and performance measurements.
+
+## Development
+
+```sh
+bun install
+bun dev
+```
+
+### Browser setup
+
+Install the Chromium version matching the project's Playwright dependency:
+
+```sh
+bunx --no-install playwright install --with-deps chromium
+```
+
+On Linux, installing system dependencies requires administrator access. If Chromium is already installed but libraries such as `libnspr4.so` are missing, run `bunx --no-install playwright install-deps chromium`. In environments without administrator access, use a browser environment with those dependencies supplied. See [Playwright's setup instructions](https://playwright.dev/docs/browsers#install-system-dependencies).
+
+[playwright.config.ts](playwright.config.ts) starts Vite automatically and selects Chromium's bundled SwiftShader on Linux and Windows. Linux uses SwiftShader's Vulkan backend for image transfers and ANGLE's SwiftShader backend for canvas presentation. These tests execute WebGPU on the CPU without a physical GPU or a separate SwiftShader installation. Use this configuration when testing; another browser session does not inherit its launch flags.
+
+If the environment blocks local ports or browser processes, use its permitted execution mechanism. A launch failure or missing system library is an environment problem, not a shader failure.
+
+## Validation
+
+| Command | Checks |
+| --- | --- |
+| `bun run check` | Format and lint; writes fixes. |
+| `bun run build` | Type-check and production build. |
+| `bun run test` | Browser-free integration and core unit tests using real modules and `vgpu/mock`. |
+| `bun run test:browser` | GPU pixels, UI, and codec integration in Chromium. |
+
+Run all four for code changes before committing. [CI](.github/workflows/ci.yml) checks formatting/lint, Bun tests, and the build; browser tests run locally.
+
+During development, select an existing test by path:
+
+```sh
+bun run test tests/renderer.test.ts
+bun run test:browser tests/rendering.e2e.ts --workers=1
+```
+
+One browser worker reduces CPU contention with SwiftShader. The mock does not execute shaders; use browser tests to check actual pixels. Reuse [browser fixtures](tests/fixtures.ts), [image readers](tests/images.ts), and existing [editing steps](tests/editing.e2e.ts). Follow the [testing guidance](AGENTS.md#tests-and-completion) to keep coverage proportional to the change.
+
+The HEIC browser test reports a skip when the browser has no WebCodecs HEVC decoder.
+
+## Scripting
+
+`window.openlight` exposes commands for loading, editing, undo/redo, and export. See the [API reference](API.md).
+
+## Pull requests
+
+Code PRs include visual evidence: UI additions or changes require screenshots of the actual interface for visual review. GPU changes also need a reproducible performance comparison; [PERFORMANCE.md](PERFORMANCE.md#running-the-benchmark) explains how to run the benchmark. Use the [PR template](.github/pull_request_template.md) and the evidence rules in [AGENTS.md](AGENTS.md#tests-and-completion).
diff --git a/PERFORMANCE.md b/PERFORMANCE.md
index 6ccb383..cdcbe6c 100644
--- a/PERFORMANCE.md
+++ b/PERFORMANCE.md
@@ -34,3 +34,13 @@ The [benchmark](tests/rendering-benchmark.ts) measures uninstrumented repeated r
Fused shader operations share a pass duration; they are not individually timed. Compute dispatches and opaque package operations need supported instrumentation before claiming GPU timing coverage. Editing must work when profiling is unavailable.
Reuse the existing [benchmark](tests/rendering.bench.ts) and timing helpers for the affected workload. An isolated benchmark explains cost; the complete workload establishes application impact. Summarize reproducible results and their interpretation in the PR; follow the [evidence rules](AGENTS.md#tests-and-completion) for detailed artifacts. An environment failure is a verification gap, not evidence of unchanged performance.
+
+## Running the benchmark
+
+After [browser setup](CONTRIBUTING.md#browser-setup), run `bun run test:browser --config playwright.bench.config.ts` separately from other GPU/browser work. Workloads cover neutral effects, color mixing, vignette, detail filters, and the combined pipeline. The fixture is a deterministic 2400×1600 linear Rec.2020 gradient containing neutrals, saturated colors, and HDR values; exposure is 0.25 and contrast is 10. Each workload uses 8 warmups and 40 measured samples. Settings live in [the benchmark](tests/rendering-benchmark.ts); select a workload with e.g. `--grep 'rendering vignette'`.
+
+Results and rendered PNGs are written under `test-results/benchmarks`; keep generated artifacts out of Git. JSON includes environment details, samples, median/p95, setup, first render, completed-render latency, intermediate texture storage, and per-node GPU timestamps when supported. Timestamp profiling runs separately from the latency comparison. Decoding, display, readback, and image encoding run outside the measured loop. Software-adapter results describe that backend only. A hardware measurement requires a browser configuration that does not force SwiftShader; record the adapter actually used.
+
+Compare `pipeline` with `pipeline-input` to measure the curve input histogram: the latter retains the image entering the base curve and computes its histogram. Completed latency includes histogram compute and its buffer copy; per-node timestamps cover only image processing.
+
+For revision comparisons, use identical fixtures, settings, sampling, and browser configuration in both checkouts. The benchmark is opt-in and excluded from the regular test suite; correctness remains covered by GPU pixel tests and the editing session.
diff --git a/README.md b/README.md
index 8fb91ba..5382585 100644
--- a/README.md
+++ b/README.md
@@ -1,91 +1,57 @@
# OpenLight
-**An open-source photo editor for the browser, built with [vgpu.sh](https://vgpu.sh).**
+**An open-source photo editor for the browser.** Try it at [openlight.app](https://openlight.app), or start with a sample photo at [openlight.app/demo](https://openlight.app/demo).
-Image processing runs locally with WebGPU. Built with TypeScript and React; requires a WebGPU-capable browser.
+Image processing runs on your own GPU with WebGPU. Photos never leave your device.
+
+![The OpenLight editor with a mountain trail photo open and a gradient mask layer](public/og.png)
## Features
-- Light and color adjustments, tone curves, clarity, sharpening, and vignette.
+**Adjust**
+
+- Exposure, contrast, highlights, shadows, whites, blacks, temperature, tint, vibrance, and saturation.
+- Tone curves with a live input histogram.
+- Clarity and sharpening.
- Color Mixer with eight hue, saturation, and luminance ranges.
-- Image adjustments, draggable effect layers, and editable linear/radial masks with child effects and Add/Subtract submasks.
-- Crop, rotate, straighten, flip, pan, and zoom.
-- Undo/redo, before/after comparison, RGB histogram, and clipping overlays.
-- Camera Raw XMP import; HEIC, TIFF at 16-bit and floating-point precision, and camera RAW/DNG with absolute white balance and As Shot reset.
-- PNG, JPEG, and WebP export with resizing, live preview, and file size.
+- Vignette.
-Documents currently live in memory; export saves a flattened image. Layers support one locked base image and two levels of effects and masks. Color Mixer, Details, Exposure, and Vignette can be added independently.
+**Layers and masks**
-RAW decoding and GPU development use [raw-webgpu](https://github.com/roprgm/raw-webgpu), which documents format support and limitations. OpenLight owns editing, history and preview/export lifetimes.
+- Draggable effect layers: Details, Exposure, Color Mixer, and Vignette.
+- Linear and radial masks with their own adjustments and child effects.
+- Add and Subtract submasks to shape a mask's coverage.
-HEIC decoding requires a browser with a WebCodecs HEVC decoder. The HEIC browser test reports a skip when that decoder is unavailable.
+**Compose**
-## Development
+- Crop with aspect presets, rotate, straighten, and flip.
+- Pan and zoom the canvas.
-```sh
-bun install
-bun dev
-```
+**Review**
-### Browser setup
+- Undo and redo, before/after comparison, RGB histogram, and clipping overlays.
-Install the Chromium version matching the project's Playwright dependency:
+**Files**
-```sh
-bunx --no-install playwright install --with-deps chromium
-```
-
-On Linux, installing system dependencies requires administrator access. If Chromium is already installed but libraries such as `libnspr4.so` are missing, run `bunx --no-install playwright install-deps chromium`. In environments without administrator access, use a browser environment with those dependencies supplied. See [Playwright's setup instructions](https://playwright.dev/docs/browsers#install-system-dependencies).
+- Open JPEG, PNG, WebP, AVIF, GIF, BMP, SVG, HEIC, TIFF at 8-bit, 16-bit, and floating-point precision, and camera RAW/DNG with absolute white balance and As Shot reset.
+- Import Camera Raw XMP settings.
+- Export PNG, JPEG, or WebP with resizing, a live preview, and the resulting file size.
-[playwright.config.ts](playwright.config.ts) starts Vite automatically and selects Chromium's bundled SwiftShader on Linux and Windows. Linux uses SwiftShader's Vulkan backend for image transfers and ANGLE's SwiftShader backend for canvas presentation. These tests execute WebGPU on the CPU without a physical GPU or a separate SwiftShader installation. Use this configuration when testing; another browser session does not inherit its launch flags.
+Documents live in memory for now; export saves a flattened image. HEIC needs a browser with a WebCodecs HEVC decoder. RAW decoding uses [raw-webgpu](https://github.com/roprgm/raw-webgpu), which documents format support and limitations.
-If the environment blocks local ports or browser processes, use its permitted execution mechanism. A launch failure or missing system library is an environment problem, not a shader failure.
+## Browser support
-### Validation
+OpenLight requires WebGPU: a recent Chrome, Edge, Safari, or Firefox.
-| Command | Checks |
-| --- | --- |
-| `bun run check` | Format and lint; writes fixes. |
-| `bun run build` | Type-check and production build. |
-| `bun run test` | Browser-free integration and core unit tests using real modules and `vgpu/mock`. |
-| `bun run test:browser` | GPU pixels, UI, and codec integration in Chromium. |
-
-Run all four for code changes before committing. [CI](.github/workflows/ci.yml) checks formatting/lint, Bun tests, and the build; browser tests run locally.
-
-During development, select an existing test by path:
+## Development
```sh
-bun run test tests/renderer.test.ts
-bun run test:browser tests/rendering.e2e.ts --workers=1
+bun install
+bun dev
```
-One browser worker reduces CPU contention with SwiftShader. The mock does not execute shaders; use browser tests to check actual pixels. Reuse [browser fixtures](tests/fixtures.ts), [image readers](tests/images.ts), and existing [editing steps](tests/editing.e2e.ts). Follow the [testing guidance](AGENTS.md#tests-and-completion) to keep coverage proportional to the change.
-
-### Rendering benchmarks
-
-After [browser setup](#browser-setup), run `bun run test:browser --config playwright.bench.config.ts` separately from other GPU/browser work. Workloads cover neutral effects, color mixing, vignette, detail filters, and the combined pipeline. The fixture is a deterministic 2400×1600 linear Rec.2020 gradient containing neutrals, saturated colors, and HDR values; exposure is 0.25 and contrast is 10. Each workload uses 8 warmups and 40 measured samples. Settings live in [the benchmark](tests/rendering-benchmark.ts); select a workload with e.g. `--grep 'rendering vignette'`.
-
-Results and rendered PNGs are written under `test-results/benchmarks`; keep generated artifacts out of Git. JSON includes environment details, samples, median/p95, setup, first render, completed-render latency, intermediate texture storage, and per-node GPU timestamps when supported. Timestamp profiling runs separately from the latency comparison. Decoding, display, readback, and image encoding run outside the measured loop. Software-adapter results describe that backend only. A hardware measurement requires a browser configuration that does not force SwiftShader; record the adapter actually used.
-
-Compare `pipeline` with `pipeline-input` to measure the curve input histogram: the latter retains the image entering the base curve and computes its histogram. Completed latency includes histogram compute and its buffer copy; per-node timestamps cover only image processing.
-
-For revision comparisons, use identical fixtures, settings, sampling, and browser configuration in both checkouts. The benchmark is opt-in and excluded from the regular test suite; correctness remains covered by GPU pixel tests and the editing session. See [PERFORMANCE.md](PERFORMANCE.md) for the node contract, measurement scope, and interpretation.
-
-## Scripting
-
-`window.openlight` exposes commands for loading, editing, undo/redo, and export. See the [API reference](API.md).
-
-## Contributing
-
-- [AGENTS.md](AGENTS.md): architecture, ownership, coding rules, and completion requirements.
-- [CONTEXT.md](CONTEXT.md): domain vocabulary.
-- [REVIEW.md](REVIEW.md): review questions and actionable findings.
-- [PERFORMANCE.md](PERFORMANCE.md): render nodes and performance measurements.
-
-Code PRs include visual evidence: UI additions or changes require screenshots of the actual interface for visual review. GPU changes also need a reproducible performance comparison. Use the [PR template](.github/pull_request_template.md) and the evidence rules in [AGENTS.md](AGENTS.md#tests-and-completion).
+See [CONTRIBUTING.md](CONTRIBUTING.md) for browser setup, validation, benchmarks, and the pull request checklist. `window.openlight` exposes a scripting [API](API.md).
## License
[MIT](LICENSE)
-
-The bundled RAW decoder includes separately licensed libraries. See [NOTICE](NOTICE).
diff --git a/bun.lock b/bun.lock
index 47332b5..9118f2b 100644
--- a/bun.lock
+++ b/bun.lock
@@ -13,7 +13,7 @@
"@vercel/speed-insights": "^2.0.0",
"class-variance-authority": "^0.7.1",
"cn": "^0.2.4",
- "raw-webgpu": "0.1.0-alpha.2",
+ "raw-webgpu": "0.1.1",
"react": "^19.2.8",
"react-dom": "^19.2.8",
"tailwindcss": "^4.3.3",
@@ -292,7 +292,7 @@
"postcss": ["[email protected]", "", { "dependencies": { "nanoid": "^3.3.17", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ=="],
- "raw-webgpu": ["[email protected]", "", {}, "sha512-YajtCnv1h/KUDPQdsn+nuYvs9IGBoVvlR6YNJveIP4gwh54rfYMDmGv8nG+SWtWhnUyoLMX0xDhwkvOjBUpzzA=="],
+ "raw-webgpu": ["[email protected]", "", {}, "sha512-JqFqFax+IAKb+Frlh5QTFD8viowAvBJ2ofY1lWSq76t1mjXa09oYuLYoClraaCuK1tOPpB9zOfr1Mmn7+aqLag=="],
"react": ["[email protected]", "", {}, "sha512-PWaYA1L/q9u2u7xYQi+Y3L3Yfnie7XyLeaJICV1MGD6LprsBxcAqGjYyr0eY3p+QdsA+x/Irkt4Qif8D63+Sbw=="],
diff --git a/index.html b/index.html
index 463ff94..7c80a50 100644
--- a/index.html
+++ b/index.html
@@ -3,8 +3,27 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="color-scheme" content="dark" />
+ <meta name="theme-color" content="#171717" />
<link rel="icon" href="/logo.svg" type="image/svg+xml" />
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
+ <link rel="canonical" href="https://openlight.app/" />
<title>OpenLight</title>
+ <meta name="description" content="Edit photos in your browser. An open-source photo editor built on WebGPU." />
+ <meta property="og:type" content="website" />
+ <meta property="og:site_name" content="OpenLight" />
+ <meta property="og:title" content="OpenLight" />
+ <meta property="og:description" content="Edit photos in your browser. An open-source photo editor built on WebGPU." />
+ <meta property="og:url" content="https://openlight.app/" />
+ <meta property="og:image" content="https://openlight.app/og.png" />
+ <meta property="og:image:width" content="2400" />
+ <meta property="og:image:height" content="1260" />
+ <meta property="og:image:alt" content="The OpenLight editor with a mountain trail photo open and a gradient mask layer." />
+ <meta name="twitter:card" content="summary_large_image" />
+ <meta name="twitter:title" content="OpenLight" />
+ <meta name="twitter:description" content="Edit photos in your browser. An open-source photo editor built on WebGPU." />
+ <meta name="twitter:image" content="https://openlight.app/og.png" />
+ <meta name="twitter:image:alt" content="The OpenLight editor with a mountain trail photo open and a gradient mask layer." />
</head>
<body>
<div id="root"></div>
diff --git a/package.json b/package.json
index a3ee486..10d6ead 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,8 @@
{
"name": "openlight",
"private": true,
+ "homepage": "https://openlight.app",
+ "repository": "github:roprgm/openlight",
"type": "module",
"scripts": {
"dev": "vite",
@@ -18,7 +20,7 @@
"@vercel/speed-insights": "^2.0.0",
"class-variance-authority": "^0.7.1",
"cn": "^0.2.4",
- "raw-webgpu": "0.1.0-alpha.2",
+ "raw-webgpu": "0.1.1",
"react": "^19.2.8",
"react-dom": "^19.2.8",
"tailwindcss": "^4.3.3",
diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png
new file mode 100644
index 0000000..e3125cb
Binary files /dev/null and b/public/apple-touch-icon.png differ
diff --git a/public/images/demo.jpg b/public/images/demo.jpg
new file mode 100644
index 0000000..eb21ace
Binary files /dev/null and b/public/images/demo.jpg differ
diff --git a/public/llms.txt b/public/llms.txt
new file mode 100644
index 0000000..c3c51ae
--- /dev/null
+++ b/public/llms.txt
@@ -0,0 +1,32 @@
+# OpenLight
+
+> OpenLight is a free, open-source photo editor that runs entirely in the browser on WebGPU. Photos stay on the device. Every editing action is also exposed as a JavaScript API on `window.openlight`, so an AI agent with browser access can open, edit, and export images programmatically.
+
+Site: https://openlight.app
+Demo with a sample photo already loaded: https://openlight.app/demo
+Source (MIT): https://github.com/roprgm/openlight
+
+## Using the API from a browser agent
+
+Open https://openlight.app in a WebGPU-capable browser (recent Chrome, Edge, Safari, or Firefox). `window.openlight` is available once the page initializes. Load an image before editing or exporting. The UI and the API share the same document edits, so changes made by script appear in the interface and in undo history.
+
+```js
+const editor = window.openlight;
+await editor.loadImage(file); // a File; or loadUrl("/images/demo.jpg") for a same-origin URL
+editor.setAdjustments({ exposure: 0.5, contrast: 10, highlights: -30, shadows: 20, vibrance: 15 });
+editor.setToneCurve([{ x: 0, y: 0 }, { x: 0.25, y: 0.2 }, { x: 0.75, y: 0.8 }, { x: 1, y: 1 }]);
+editor.addLayer("mask"); // linear gradient mask; also "details", "exposure", "color-mixer", "vignette"
+editor.setFrame({ ...editor.getState().frame, angle: 2 });
+const jpeg = await editor.exportImage({ format: "jpeg", quality: 90 }); // returns a File
+editor.getState(); // scene, layers, history counts, selected layer
+editor.undo(); editor.redo();
+```
+
+Adjustments use UI units: exposure in stops, other sliders in -100..100. RAW files expose `setWhiteBalance({ temperature, tint })`. Camera Raw XMP files import through `importXmp(file)`.
+
+## Reference
+
+- [Control API](https://github.com/roprgm/openlight/blob/main/API.md): every command, its arguments, and the state shape.
+- [README](https://github.com/roprgm/openlight/blob/main/README.md): features and supported formats (JPEG, PNG, WebP, AVIF, GIF, BMP, SVG, HEIC, TIFF, camera RAW and DNG).
+- [Architecture](https://github.com/roprgm/openlight/blob/main/AGENTS.md): layers, ownership, and coding rules for contributors.
+- [Domain vocabulary](https://github.com/roprgm/openlight/blob/main/CONTEXT.md): document, scene, layer, mask, and frame terms.
diff --git a/public/og.png b/public/og.png
new file mode 100644
index 0000000..ee5c83c
Binary files /dev/null and b/public/og.png differ
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000..c2a49f4
--- /dev/null
+++ b/public/robots.txt
@@ -0,0 +1,2 @@
+User-agent: *
+Allow: /
diff --git a/src/app/controls.ts b/src/app/controls.ts
index de86e47..7cbee36 100644
--- a/src/app/controls.ts
+++ b/src/app/controls.ts
@@ -65,6 +65,7 @@ export function createControls(gpu: Gpu, workspace: Workspace) {
openFiles: files.openFiles,
openFile: (file: File) => files.openFiles([file]),
loadImage: (file: File) => files.loadFile(image, file),
+ loadUrl: image.loadUrl,
importXmp: (file: File) => files.loadFile(xmp, file),
setDetails(change: Partial<Details>, id?: string) {
const document = workspace.getDocument();
diff --git a/src/app/editor/adjust/index.tsx b/src/app/editor/adjust/index.tsx
index 1deb49b..b42e5c0 100644
--- a/src/app/editor/adjust/index.tsx
+++ b/src/app/editor/adjust/index.tsx
@@ -44,7 +44,6 @@ function LayerCurve({ id, toneCurve }: { id: string; toneCurve: ToneCurve }) {
const document = useDocument();
return (
<div className="px-3 pb-3">
- <hr className="mb-3 border-black/50" />
<ToneCurves
points={toneCurve}
onChange={(points) => setToneCurve(document, points, id)}
diff --git a/src/app/landing/backdrop.tsx b/src/app/editor/backdrop.tsx
similarity index 100%
rename from src/app/landing/backdrop.tsx
rename to src/app/editor/backdrop.tsx
diff --git a/src/app/landing/backdrop.wgsl b/src/app/editor/backdrop.wgsl
similarity index 92%
rename from src/app/landing/backdrop.wgsl
rename to src/app/editor/backdrop.wgsl
index ced4d44..f1b0557 100644
--- a/src/app/landing/backdrop.wgsl
+++ b/src/app/editor/backdrop.wgsl
@@ -11,8 +11,8 @@ struct Params {
}
@group(0) @binding(0) var<uniform> params: Params;
-const dark = vec3f(0.075);
-const light = vec3f(0.17, 0.163, 0.156);
+const dark = vec3f(0.07);
+const light = vec3f(0.115, 0.112, 0.108);
const mote = vec3f(1.0, 0.94, 0.82);
// One drifting, twinkling mote per grid cell; each pixel checks its 3x3 neighborhood.
@@ -56,15 +56,15 @@ fn motes(p: vec2f, t: f32, density: f32, rise: f32) -> f32 {
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;
+ let glow = beam + near * 0.25;
// 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.15) + motes(q, t, 12.0, 0.125) * 0.5;
- let lit = 0.15 + 0.6 * beam + near * 0.6;
+ let dust = motes(q, t, 5.0, 0.12) + motes(q, t, 9.0, 0.1) * 0.5;
+ let lit = 0.06 + 0.22 * beam + near * 0.45;
// Static per-pixel dither hides banding in the few gray levels the glow spans.
let dither = (hash2(pixel.xy).x - 0.5) / 255.0;
diff --git a/src/app/editor/empty.tsx b/src/app/editor/empty.tsx
new file mode 100644
index 0000000..d1838f8
--- /dev/null
+++ b/src/app/editor/empty.tsx
@@ -0,0 +1,124 @@
+import { useEffect, useMemo, useRef } from "react";
+import { type Gpu, target } from "vgpu";
+import { useGpu } from "vgpu-react";
+import type { Workspace } from "@/app/workspace";
+import { RendererProvider } from "@/components/editor/pipeline";
+import { DocumentProvider } from "@/components/editor/session";
+import Spinner from "@/components/ui/spinner";
+import { createDocument, createResources } from "@/core/document";
+import { createImageSource } from "@/core/image";
+import { accept } from "@/core/image/decode";
+import { imageFrame } from "@/core/image/frame";
+import { GradientProvider } from "@/features/layers/gradient-tool";
+import { AdjustPanel } from "./adjust";
+import Backdrop from "./backdrop";
+import { EditorHeader } from "./header";
+import { createImageLayer } from "./layers";
+import { ModeTabList } from "./mode-rail";
+import { modes } from "./modes";
+import { createEditorRenderer } from "./renderer";
+import { EditorSidebar } from "./sidebar";
+
+type OpenProps = { onOpen: (files: File[]) => void };
+
+/** The drop hint doubles as the picker: "choose a file" opens the input. */
+function OpenImage({ onOpen }: OpenProps) {
+ const input = useRef<HTMLInputElement>(null);
+ return (
+ <p className="mt-8 rounded-full border border-neutral-700 border-dashed px-5 py-2.5 text-neutral-500">
+ Drop an image here or{" "}
+ <button
+ type="button"
+ onClick={() => input.current?.click()}
+ className="cursor-pointer text-neutral-200 underline decoration-neutral-600 underline-offset-4 transition-colors hover:decoration-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-3 focus-visible:outline-neutral-400"
+ >
+ choose a file
+ </button>
+ <input
+ accept={accept}
+ hidden
+ multiple
+ onChange={(event) => {
+ const files = event.currentTarget.files;
+ if (files?.length) {
+ onOpen(Array.from(files));
+ }
+ }}
+ ref={input}
+ type="file"
+ />
+ </p>
+ );
+}
+
+type EmptyState = Exclude<
+ ReturnType<Workspace["state"]["getState"]>,
+ { status: "ready" }
+>;
+
+function Status({ state, onOpen }: { state: EmptyState } & OpenProps) {
+ if (state.status === "loading") {
+ return <Spinner />;
+ }
+ if (state.status === "error") {
+ return (
+ <>
+ <p className="max-w-md text-center text-neutral-400">
+ Couldn't open {state.file}: {state.error}
+ </p>
+ <OpenImage onOpen={onOpen} />
+ </>
+ );
+ }
+ return (
+ <>
+ <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 photos in your browser.</p>
+ <OpenImage onOpen={onOpen} />
+ </>
+ );
+}
+
+/** A scene over a blank pixel, so the real panels mount with defaults; it never enters the workspace. */
+function createEmptyDocument(gpu: Gpu) {
+ const resources = createResources();
+ const image = target(gpu, { size: [1, 1], format: "rgba16float" });
+ const source = resources.add(new File([], ""), createImageSource(image));
+ return createDocument(
+ {
+ frame: imageFrame([1, 1]),
+ layers: [createImageLayer(source, "Untitled")],
+ },
+ resources,
+ );
+}
+
+/** The editor shell without a document: the light backdrop and workspace status fill the canvas area. */
+export function EmptyEditor({
+ state,
+ onOpen,
+}: { state: EmptyState } & OpenProps) {
+ const gpu = useGpu();
+ const document = useMemo(() => createEmptyDocument(gpu), [gpu]);
+ useEffect(() => () => document.dispose(), [document]);
+ return (
+ <DocumentProvider value={document}>
+ <RendererProvider createRenderer={createEditorRenderer}>
+ <GradientProvider onCreate={() => {}}>
+ <EditorHeader file={state.file} />
+ <div className="flex min-h-0 flex-1 flex-col md:flex-row">
+ <ModeTabList selected={modes[0]} />
+ <div className="relative isolate grid min-h-0 min-w-0 flex-1 place-content-center justify-items-center gap-3 overflow-hidden bg-[radial-gradient(circle,#292929,#131313_55%)] p-6">
+ <Backdrop />
+ <Status state={state} onOpen={onOpen} />
+ </div>
+ <EditorSidebar inert>
+ <AdjustPanel />
+ </EditorSidebar>
+ </div>
+ </GradientProvider>
+ </RendererProvider>
+ </DocumentProvider>
+ );
+}
diff --git a/src/app/editor/index.tsx b/src/app/editor/index.tsx
index 68a0519..444e09b 100644
--- a/src/app/editor/index.tsx
+++ b/src/app/editor/index.tsx
@@ -1,14 +1,9 @@
-import type { ReactNode } from "react";
import type { Workspace } from "@/app/workspace";
-import { EditorPanel } from "@/components/editor/panel";
import { RendererProvider } from "@/components/editor/pipeline";
import { DocumentProvider, useDocument } from "@/components/editor/session";
import Button from "@/components/ui/button";
-import ResizablePanel from "@/components/ui/resizable-panel";
-import Spinner from "@/components/ui/spinner";
-import type { EffectLayer, Gradient } from "@/core/document";
+import type { Gradient } from "@/core/document";
import { findLayer } from "@/core/document";
-import { LayersControls } from "@/features/layers/controls";
import { addLayer } from "@/features/layers/edits";
import {
GradientProvider,
@@ -17,35 +12,14 @@ import {
import { useShortcuts } from "@/hooks/use-shortcuts";
import { EditorCanvas } from "./canvas";
import { ComparisonControl } from "./comparison-control";
+import { EmptyEditor } from "./empty";
import { EditorHeader } from "./header";
-import { ImageHistogram } from "./histogram";
import { HistoryControls } from "./history";
-import { createLayer, createMask } from "./layers";
+import { createMask } from "./layers";
import { ModeRail } from "./mode-rail";
import { type Mode, ModeProvider, modes, useMode } from "./modes";
import { createEditorRenderer } from "./renderer";
-
-function EditorSidebar({ children }: { children: ReactNode }) {
- const document = useDocument();
- function add(kind: EffectLayer["kind"]) {
- const scene = document.scene.getState();
- const selected = document.selection.getState().layerId;
- const layer = findLayer(scene.layers, selected);
- const placement =
- layer?.kind === "mask" && scene.layers.includes(layer)
- ? { inside: selected }
- : { above: selected };
- addLayer(document, createLayer(kind), placement);
- }
- return (
- <EditorPanel
- header={<ImageHistogram />}
- footer={<LayersControls onAdd={add} />}
- >
- {children}
- </EditorPanel>
- );
-}
+import { EditorSidebar } from "./sidebar";
/** A View replaces the canvas and sidebar; a Panel fills the sidebar beside the canvas. */
function ModeView() {
@@ -133,43 +107,26 @@ function DocumentEditor({ file }: { file: string }) {
);
}
-type EditorProps = { state: ReturnType<Workspace["state"]["getState"]> };
-function LoadingStatus({ state }: EditorProps) {
- if (state.status !== "error") {
- return <Spinner />;
- }
- return (
- <p className="max-w-md text-center text-neutral-400">
- Couldn't open {state.file}: {state.error}
- </p>
- );
-}
-function EditorContent({ state }: EditorProps) {
- if (state.status === "ready") {
- return (
- <DocumentProvider key={state.document.id} value={state.document}>
- <RendererProvider createRenderer={createEditorRenderer}>
- <DocumentEditor file={state.file} />
- </RendererProvider>
- </DocumentProvider>
- );
+type EditorProps = {
+ state: ReturnType<Workspace["state"]["getState"]>;
+ onOpen: (files: File[]) => void;
+};
+function EditorContent({ state, onOpen }: EditorProps) {
+ if (state.status !== "ready") {
+ return <EmptyEditor state={state} onOpen={onOpen} />;
}
return (
- <>
- <EditorHeader file={state.file} />
- <div className="flex min-h-0 flex-1 flex-col md:flex-row">
- <div className="grid flex-1 place-items-center">
- <LoadingStatus state={state} />
- </div>
- <ResizablePanel />
- </div>
- </>
+ <DocumentProvider key={state.document.id} value={state.document}>
+ <RendererProvider createRenderer={createEditorRenderer}>
+ <DocumentEditor file={state.file} />
+ </RendererProvider>
+ </DocumentProvider>
);
}
-export default function Editor({ state }: EditorProps) {
+export default function Editor(props: EditorProps) {
return (
<main className="flex h-dvh flex-col">
- <EditorContent state={state} />
+ <EditorContent {...props} />
</main>
);
}
diff --git a/src/app/editor/mode-rail.tsx b/src/app/editor/mode-rail.tsx
index bdc44b3..0488ec4 100644
--- a/src/app/editor/mode-rail.tsx
+++ b/src/app/editor/mode-rail.tsx
@@ -1,39 +1,55 @@
+import { GithubIcon } from "@/components/icons/github";
import { Tab, TabList } from "@/components/ui/tabs";
import { useShortcuts } from "@/hooks/use-shortcuts";
import { type Mode, modes, useMode } from "./modes";
-function ModeTab({ entry }: { entry: Mode }) {
- const { mode, setMode } = useMode();
+/** Icon tabs in a column at the window's left edge on desktop, a bar above the canvas on mobile; titles carry the label and shortcut. Without a handler the tabs are inert. */
+export function ModeTabList({
+ selected,
+ onSelect,
+}: {
+ selected: Mode;
+ onSelect?: (mode: Mode) => void;
+}) {
+ const editing = modes.filter((entry) => entry.group === "edit");
return (
- <Tab
- selected={entry === mode}
- size="icon"
- aria-label={entry.label}
- title={`${entry.label} (${entry.key.toUpperCase()})`}
- onClick={() => setMode(entry)}
- >
- <entry.Icon className="size-5" />
- </Tab>
+ <div className="flex shrink-0 gap-1 overflow-auto border-black border-b bg-panel p-1.5 md:w-11 md:flex-col md:border-r md:border-b-0">
+ <TabList aria-label="Editor mode" className="md:flex-col">
+ {editing.map((entry) => (
+ <Tab
+ key={entry.id}
+ selected={entry === selected}
+ disabled={!onSelect}
+ size="icon"
+ className="disabled:pointer-events-none disabled:opacity-40"
+ aria-label={entry.label}
+ title={`${entry.label} (${entry.key.toUpperCase()})`}
+ onClick={() => onSelect?.(entry)}
+ >
+ <entry.Icon className="size-5" />
+ </Tab>
+ ))}
+ </TabList>
+ <a
+ href="https://github.com/roprgm/openlight"
+ target="_blank"
+ rel="noreferrer"
+ aria-label="OpenLight on GitHub"
+ title="OpenLight on GitHub"
+ className="ml-auto grid place-items-center rounded-md p-1.5 text-neutral-500 transition-colors hover:bg-neutral-700/50 hover:text-neutral-100 md:mt-auto md:ml-0"
+ >
+ <GithubIcon className="size-5" />
+ </a>
+ </div>
);
}
-/** Icon tabs in a column at the window's left edge on desktop, a bar above the canvas on mobile; titles carry the label and shortcut. */
export function ModeRail() {
- const { setMode } = useMode();
+ const { mode, setMode } = useMode();
useShortcuts(
Object.fromEntries(
modes.map((entry) => [entry.key, () => setMode(entry)] as const),
),
);
- const editing = modes.filter((entry) => entry.group === "edit");
- return (
- <TabList
- aria-label="Editor mode"
- className="shrink-0 overflow-auto border-black border-b bg-panel p-1.5 md:w-11 md:flex-col md:border-r md:border-b-0"
- >
- {editing.map((entry) => (
- <ModeTab key={entry.id} entry={entry} />
- ))}
- </TabList>
- );
+ return <ModeTabList selected={mode} onSelect={setMode} />;
}
diff --git a/src/app/editor/sidebar.tsx b/src/app/editor/sidebar.tsx
new file mode 100644
index 0000000..5827014
--- /dev/null
+++ b/src/app/editor/sidebar.tsx
@@ -0,0 +1,39 @@
+import type { ReactNode } from "react";
+import { EditorPanel } from "@/components/editor/panel";
+import { useDocument } from "@/components/editor/session";
+import type { EffectLayer } from "@/core/document";
+import { findLayer } from "@/core/document";
+import { LayersControls } from "@/features/layers/controls";
+import { addLayer } from "@/features/layers/edits";
+import { ImageHistogram } from "./histogram";
+import { createLayer } from "./layers";
+
+/** Histogram above, the mode's controls in the middle, the layer stack below. */
+export function EditorSidebar({
+ children,
+ inert,
+}: {
+ children: ReactNode;
+ inert?: boolean;
+}) {
+ const document = useDocument();
+ function add(kind: EffectLayer["kind"]) {
+ const scene = document.scene.getState();
+ const selected = document.selection.getState().layerId;
+ const layer = findLayer(scene.layers, selected);
+ const placement =
+ layer?.kind === "mask" && scene.layers.includes(layer)
+ ? { inside: selected }
+ : { above: selected };
+ addLayer(document, createLayer(kind), placement);
+ }
+ return (
+ <EditorPanel
+ inert={inert}
+ header={<ImageHistogram />}
+ footer={<LayersControls onAdd={add} />}
+ >
+ {children}
+ </EditorPanel>
+ );
+}
diff --git a/src/app/index.tsx b/src/app/index.tsx
index 4f0d148..c9dcae1 100644
--- a/src/app/index.tsx
+++ b/src/app/index.tsx
@@ -1,15 +1,14 @@
import { useStore } from "zustand";
import Editor from "@/app/editor";
-import Landing from "@/app/landing";
import { useWorkspace } from "@/app/workspace/use-workspace";
import { useFileDrop } from "@/hooks/use-file-drop";
+/** Visiting /demo opens a bundled photo instead of the empty state. */
+const startup = location.pathname === "/demo" ? "/images/demo.jpg" : undefined;
+
export default function App() {
- const { workspace, controls } = useWorkspace();
+ const { workspace, controls } = useWorkspace(startup);
useFileDrop(controls.openFiles);
const state = useStore(workspace.state);
- if (state.status === "empty") {
- return <Landing onOpen={controls.openFiles} />;
- }
- return <Editor state={state} />;
+ return <Editor state={state} onOpen={controls.openFiles} />;
}
diff --git a/src/app/landing/index.tsx b/src/app/landing/index.tsx
deleted file mode 100644
index ce9b204..0000000
--- a/src/app/landing/index.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import { useRef } from "react";
-import Button from "@/components/ui/button";
-import { accept } from "@/core/image/decode";
-import Backdrop from "./backdrop";
-
-type OpenProps = { onOpen: (files: File[]) => 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
- multiple
- onChange={(event) => {
- const files = event.currentTarget.files;
- if (files?.length) {
- onOpen(Array.from(files));
- }
- }}
- ref={input}
- type="file"
- />
- </>
- );
-}
-
-export default function Landing({ onOpen }: OpenProps) {
- return (
- <main className="relative isolate grid h-full place-content-center justify-items-center gap-3 bg-[radial-gradient(circle,#292929,#131313_55%)]">
- <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 photos in your browser.</p>
- <OpenImage onOpen={onOpen} />
- </main>
- );
-}
diff --git a/src/app/loaders/image.ts b/src/app/loaders/image.ts
index edb3a51..9ec6f22 100644
--- a/src/app/loaders/image.ts
+++ b/src/app/loaders/image.ts
@@ -4,27 +4,39 @@ import type { Workspace } from "@/app/workspace";
import { createDocument, createResources } from "@/core/document";
import decode, { canDecode } from "@/core/image/decode";
import { imageFrame } from "@/core/image/frame";
-import type { FileLoader } from "./registry";
-export function createImageLoader(gpu: Gpu, workspace: Workspace): FileLoader {
+async function loadDocument(gpu: Gpu, file: File) {
+ const decoded = await decode(gpu, file);
+ const resources = createResources();
+ const source = resources.add(file, decoded);
+ return createDocument(
+ {
+ frame: imageFrame(decoded.image.size),
+ layers: [createImageLayer(source, file.name, decoded.raw?.asShot)],
+ },
+ resources,
+ );
+}
+
+export function createImageLoader(gpu: Gpu, workspace: Workspace) {
return {
- kind: "document",
+ kind: "document" as const,
accepts: canDecode,
- async load(file) {
+ async load(file: File) {
if (!(file instanceof File)) {
throw new Error("loadImage requires a File.");
}
- await workspace.open(file.name, async () => {
- const decoded = await decode(gpu, file);
- const resources = createResources();
- const source = resources.add(file, decoded);
- return createDocument(
- {
- frame: imageFrame(decoded.image.size),
- layers: [createImageLayer(source, file.name, decoded.raw?.asShot)],
- },
- resources,
- );
+ await workspace.open(file.name, () => loadDocument(gpu, file));
+ },
+ /** Enters the loading state before the fetch starts, so the empty state never shows. */
+ loadUrl(url: string) {
+ const name = url.slice(url.lastIndexOf("/") + 1);
+ return workspace.open(name, async () => {
+ const response = await fetch(url);
+ if (!response.ok) {
+ throw new Error(`${response.status} ${response.statusText}`);
+ }
+ return loadDocument(gpu, new File([await response.blob()], name));
});
},
};
diff --git a/src/app/workspace/use-workspace.ts b/src/app/workspace/use-workspace.ts
index ad80f2b..c158315 100644
--- a/src/app/workspace/use-workspace.ts
+++ b/src/app/workspace/use-workspace.ts
@@ -3,13 +3,20 @@ import { useGpu } from "vgpu-react";
import { createControls } from "@/app/controls";
import { createWorkspace } from ".";
-/** Connects an imperative workspace and its browser commands to the app lifetime. */
-export function useWorkspace() {
+/**
+ * Connects an imperative workspace and its browser commands to the app lifetime.
+ * A startup URL opens while the session is created, so the first paint is already loading.
+ */
+export function useWorkspace(startup?: string) {
const gpu = useGpu();
const session = useMemo(() => {
const workspace = createWorkspace();
- return { workspace, controls: createControls(gpu, workspace) };
- }, [gpu]);
+ const controls = createControls(gpu, workspace);
+ if (startup) {
+ void controls.loadUrl(startup);
+ }
+ return { workspace, controls };
+ }, [gpu, startup]);
useEffect(() => {
window.openlight = session.controls;
return () => {
diff --git a/src/components/editor/panel.tsx b/src/components/editor/panel.tsx
index 00cf388..b86fa56 100644
--- a/src/components/editor/panel.tsx
+++ b/src/components/editor/panel.tsx
@@ -1,3 +1,4 @@
+import { cn } from "cn";
import type { KeyboardEventHandler, ReactNode } from "react";
import { CloseIcon } from "@/components/icons/close";
import Button from "@/components/ui/button";
@@ -10,11 +11,14 @@ export function EditorPanel({
header,
children,
footer,
+ inert,
onKeyDown,
}: {
header?: ReactNode;
children: ReactNode;
footer?: ReactNode;
+ /** Contents shown but unresponsive, as when the document is a placeholder; the panel still scrolls. */
+ inert?: boolean;
onKeyDown?: KeyboardEventHandler<HTMLElement>;
}) {
const { width, onWidthChange } = useEditorSession();
@@ -22,19 +26,23 @@ export function EditorPanel({
<ResizablePanel
width={width}
onWidthChange={onWidthChange}
- className="flex min-h-0 flex-col"
+ className={cn("flex min-h-0 flex-col", inert && "opacity-50")}
onKeyDown={onKeyDown}
>
- {header}
+ <div inert={inert} className="contents">
+ {header}
+ </div>
<ScrollArea
fade
className="flex-1"
role="region"
aria-label="Editor controls"
>
- {children}
+ <div inert={inert}>{children}</div>
</ScrollArea>
- {footer}
+ <div inert={inert} className="contents">
+ {footer}
+ </div>
</ResizablePanel>
);
}
diff --git a/src/components/icons/github.tsx b/src/components/icons/github.tsx
new file mode 100644
index 0000000..6d7c761
--- /dev/null
+++ b/src/components/icons/github.tsx
@@ -0,0 +1,9 @@
+import { Icon, type IconProps } from "./icon";
+
+export function GithubIcon(props: IconProps) {
+ return (
+ <Icon fill="currentColor" stroke="none" {...props}>
+ <path d="M12 .5C5.65.5.5 5.65.5 12c0 5.08 3.29 9.39 7.86 10.91.58.1.79-.25.79-.56v-2.17c-3.2.7-3.87-1.37-3.87-1.37-.52-1.33-1.28-1.68-1.28-1.68-1.04-.71.08-.7.08-.7 1.15.08 1.76 1.19 1.76 1.19 1.03 1.76 2.69 1.25 3.35.96.1-.75.4-1.25.73-1.54-2.55-.29-5.24-1.28-5.24-5.68 0-1.26.45-2.28 1.19-3.09-.12-.29-.52-1.46.11-3.05 0 0 .97-.31 3.17 1.18a11 11 0 0 1 5.78 0c2.2-1.49 3.17-1.18 3.17-1.18.63 1.59.23 2.76.11 3.05.74.81 1.19 1.83 1.19 3.09 0 4.41-2.69 5.38-5.25 5.67.41.36.78 1.06.78 2.14v3.17c0 .31.21.67.8.56C20.21 21.39 23.5 17.08 23.5 12 23.5 5.65 18.35.5 12 .5Z" />
+ </Icon>
+ );
+}
diff --git a/src/features/adjustments/controls.tsx b/src/features/adjustments/controls.tsx
index e41ad04..4a3b449 100644
--- a/src/features/adjustments/controls.tsx
+++ b/src/features/adjustments/controls.tsx
@@ -75,7 +75,6 @@ export function AdjustmentControls({
return (
<section className="flex flex-col gap-2 p-3">
<AdjustmentSliders id={id} adjustments={adjustments} controls={tone} />
- <hr className="my-1 border-black/50" />
{temperature}
<AdjustmentSliders
id={id}
diff --git a/src/features/layers/controls.tsx b/src/features/layers/controls.tsx
index 7852ad6..1ae7b07 100644
--- a/src/features/layers/controls.tsx
+++ b/src/features/layers/controls.tsx
@@ -282,7 +282,7 @@ export function LayersControls({
return (
<section
aria-label="Layers"
- className="grid max-h-1/2 min-h-30 shrink-0 grid-rows-[auto_minmax(0,1fr)] border-t border-black bg-panel"
+ className="grid max-h-1/2 min-h-36 shrink-0 grid-rows-[auto_minmax(0,1fr)] border-t border-black bg-panel"
>
<PanelHeader title="Layers">
<button
diff --git a/src/main.tsx b/src/main.tsx
index 35d18d6..ff8ea42 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -1,19 +1,55 @@
import { Analytics } from "@vercel/analytics/react";
import { SpeedInsights } from "@vercel/speed-insights/react";
+import { Component, type ReactNode } from "react";
import { createRoot } from "react-dom/client";
import { GpuProvider } from "vgpu-react";
import App from "@/app";
import "./index.css";
+/** GPU initialization throws during render; without WebGPU the page would otherwise stay blank. */
+class GpuBoundary extends Component<
+ { children: ReactNode },
+ { error?: unknown }
+> {
+ state: { error?: unknown } = {};
+ static getDerivedStateFromError(error: unknown) {
+ return { error };
+ }
+ render() {
+ if (!("error" in this.state)) {
+ return this.props.children;
+ }
+ return (
+ <main className="grid h-dvh place-content-center justify-items-center gap-3 p-6 text-center">
+ <img alt="" className="w-16" height="64" src="/logo.svg" width="64" />
+ <h1 className="text-2xl font-bold">OpenLight</h1>
+ <p className="max-w-md text-neutral-400">
+ OpenLight needs WebGPU, which this browser does not provide. Open it
+ in a recent Chrome, Edge, Safari, or Firefox.
+ </p>
+ <p className="text-neutral-500">{String(this.state.error)}</p>
+ <a
+ href="https://github.com/roprgm/openlight"
+ className="text-neutral-200 underline decoration-neutral-600 underline-offset-4 hover:decoration-neutral-200"
+ >
+ github.com/roprgm/openlight
+ </a>
+ </main>
+ );
+ }
+}
+
const root = document.getElementById("root");
if (root) {
createRoot(root).render(
<>
- <GpuProvider>
- <App />
- </GpuProvider>
+ <GpuBoundary>
+ <GpuProvider>
+ <App />
+ </GpuProvider>
+ </GpuBoundary>
<Analytics />
<SpeedInsights />
</>,
diff --git a/tests/editing.e2e.ts b/tests/editing.e2e.ts
index 13ac75f..214f4fe 100644
--- a/tests/editing.e2e.ts
+++ b/tests/editing.e2e.ts
@@ -34,7 +34,11 @@ test("edit a photo, inspect the preview and histograms, undo changes, and export
test.setTimeout(180_000);
const state = () => page.evaluate(() => window.openlight.getState());
await page.goto("/");
- await expect(page.getByRole("button", { name: "Open image" })).toBeVisible();
+ await expect(
+ page.getByRole("button", { name: "choose a file" }),
+ ).toBeVisible();
+ await expect(page.getByRole("heading", { name: "Layers" })).toBeVisible();
+ await expect(page.getByRole("tab", { name: "Adjust" })).toBeDisabled();
await page
.locator('input[type="file"]')
.setInputFiles("tests/fixtures/photo.svg");
diff --git a/vercel.json b/vercel.json
new file mode 100644
index 0000000..ea48146
--- /dev/null
+++ b/vercel.json
@@ -0,0 +1,3 @@
+{
+ "rewrites": [{ "source": "/demo", "destination": "/" }]
+}