Skip to content

Free open-source image editor for the browser

Add control components and improve UI

Rodrigocb1eed6376bd
diff --git a/AGENTS.md b/AGENTS.md
index 538047a..c11113f 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -23,6 +23,10 @@ The `src/` root holds entrypoints, ambient types, and global styles. Import acro
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.
+## Styling
+
+Tailwind classes stay inline in the component that renders them; reuse styling by composing React components or repeating classes (whichever is fewer lines), never by sharing class-string constants across files. Use `cva` for a component's variants; promote a style to a token in `src/index.css` only when it is app-global, like a shadow or a font style.
+
## GPU
All React bindings come from `vgpu-react`; everything else comes from `vgpu`.
diff --git a/biome.json b/biome.json
index 2d29a95..518ba9e 100644
--- a/biome.json
+++ b/biome.json
@@ -3,6 +3,11 @@
"files": {
"includes": ["**", "!dist"]
},
+ "css": {
+ "parser": {
+ "tailwindDirectives": true
+ }
+ },
"linter": {
"rules": {
"style": {
diff --git a/bun.lock b/bun.lock
index 9716012..0649425 100644
--- a/bun.lock
+++ b/bun.lock
@@ -5,7 +5,9 @@
"": {
"name": "openlight",
"dependencies": {
+ "@fontsource-variable/geist": "^5.3.0",
"@tailwindcss/vite": "^4.3.3",
+ "class-variance-authority": "^0.7.1",
"cn": "^0.2.4",
"react": "^19.2.8",
"react-dom": "^19.2.8",
@@ -43,6 +45,8 @@
"@biomejs/cli-win32-x64": ["@biomejs/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-QSQr/KjOgXA7OzXJUWS+oguKyAZ3Q0l/lnlDGbu397eKo83atuWUjBPJrsqbKNF6CARGw8XXJLGzpHC8Ryhd4Q=="],
+ "@fontsource-variable/geist": ["@fontsource-variable/[email protected]", "", {}, "sha512-j0m+vLQuG5XAYoHtGCVu0spvlGreR3EzpECUVzkFmI1mTVnAO38l/NEPDCFgZ177JxzYJCLSmTQibIiYPilGrA=="],
+
"@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=="],
@@ -183,6 +187,10 @@
"@webgpu/types": ["@webgpu/[email protected]", "", {}, "sha512-0cF7RFM2edNoiIS1ODJp0/Gzv4/xSXhwoR0YCza+OWpJWtn4wmo9DvK91aLlH9+uUnwIriP7ZiC3WitmyhuzBw=="],
+ "class-variance-authority": ["[email protected]", "", { "dependencies": { "clsx": "^2.1.1" } }, "sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg=="],
+
+ "clsx": ["[email protected]", "", {}, "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA=="],
+
"cn": ["[email protected]", "", { "bin": { "cn": "bin/cn.mjs" } }, "sha512-SzQvoh5FwizWtQg9+JueKdjWhlfCZMdu5DqNHm9q1wUlRVmKb9WXlepR9bTTbPwzEOyX1ujJ6lcCppmn3bNUCg=="],
"csstype": ["[email protected]", "", {}, "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ=="],
diff --git a/package.json b/package.json
index e28c535..9bb58d0 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,9 @@
"test": "playwright test"
},
"dependencies": {
+ "@fontsource-variable/geist": "^5.3.0",
"@tailwindcss/vite": "^4.3.3",
+ "class-variance-authority": "^0.7.1",
"cn": "^0.2.4",
"react": "^19.2.8",
"react-dom": "^19.2.8",
diff --git a/src/app/landing.tsx b/src/app/landing.tsx
index 8e3cec0..1a9c64d 100644
--- a/src/app/landing.tsx
+++ b/src/app/landing.tsx
@@ -46,7 +46,7 @@ export default function Landing({ onOpen }: LandingProps) {
<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>
+ <p className="text-neutral-400">Edit photos in your browser.</p>
<OpenImage onOpen={open} />
</main>
);
diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx
index f1bb567..4bcb88c 100644
--- a/src/components/ui/button.tsx
+++ b/src/components/ui/button.tsx
@@ -8,7 +8,7 @@ export default function 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",
+ "cursor-pointer rounded border border-black bg-neutral-700 px-4 py-2.5 text-neutral-100 shadow-ridge hover:bg-neutral-600 active:bg-neutral-800 active:shadow-groove focus-visible:outline-2 focus-visible:outline-offset-3 focus-visible:outline-neutral-400",
className,
)}
type="button"
diff --git a/src/components/ui/field.tsx b/src/components/ui/field.tsx
new file mode 100644
index 0000000..9d5b9b0
--- /dev/null
+++ b/src/components/ui/field.tsx
@@ -0,0 +1,28 @@
+import { cva } from "class-variance-authority";
+import { cn } from "cn";
+import type { ComponentProps } from "react";
+
+type FieldProps = ComponentProps<"span"> & {
+ /** "box" always shows the chrome; "text" reads as plain text until focused. */
+ variant?: "box" | "text";
+};
+
+const chrome = cva(
+ "rounded border px-1 py-0.5 focus-within:ring-1 focus-within:ring-neutral-400/30",
+ {
+ variants: {
+ variant: {
+ box: "border-black bg-neutral-900 shadow-groove",
+ text: "border-transparent focus-within:border-black focus-within:bg-neutral-900 focus-within:shadow-groove",
+ },
+ },
+ },
+);
+
+/**
+ * Sunken chrome around a bare form control (input, select, textarea).
+ * The child styles itself with `w-full bg-transparent outline-none`.
+ */
+export function Field({ variant = "box", className, ...props }: FieldProps) {
+ return <span className={cn(chrome({ variant }), className)} {...props} />;
+}
diff --git a/src/components/ui/resizable-panel.tsx b/src/components/ui/resizable-panel.tsx
index 794275a..e3c59c3 100644
--- a/src/components/ui/resizable-panel.tsx
+++ b/src/components/ui/resizable-panel.tsx
@@ -24,12 +24,12 @@ export default function ResizablePanel({
return (
<aside
- className={cn("relative shrink-0", className)}
+ className={cn("relative shrink-0 bg-neutral-800 shadow-ridge", 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"
+ 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-black hover:after:bg-neutral-600 after:transition-colors after:duration-200"
onPointerDown={(event) =>
event.currentTarget.setPointerCapture(event.pointerId)
}
diff --git a/src/components/ui/scrub-input.tsx b/src/components/ui/scrub-input.tsx
new file mode 100644
index 0000000..2ee9c01
--- /dev/null
+++ b/src/components/ui/scrub-input.tsx
@@ -0,0 +1,121 @@
+import { cva } from "class-variance-authority";
+import {
+ type ComponentProps,
+ type PointerEvent,
+ useRef,
+ useState,
+} from "react";
+import { Field } from "./field";
+
+type ScrubInputProps = Omit<
+ ComponentProps<"input">,
+ "onChange" | "type" | "value" | "min" | "max" | "step"
+> & {
+ /** Rendered inline before the field; omit it inside an already-labeled row. */
+ label?: string;
+ value: number;
+ onChange: (value: number) => void;
+ min: number;
+ max: number;
+ step?: number;
+ /** "box" always shows the field chrome; "text" reads as plain text until edited. */
+ variant?: "box" | "text";
+};
+
+const input = cva(
+ "w-full cursor-ew-resize bg-transparent text-neutral-100 tabular-nums outline-none focus:cursor-text",
+ {
+ variants: {
+ variant: {
+ box: "text-center",
+ text: "text-right focus:text-center",
+ },
+ },
+ },
+);
+
+type Drag = { dx: number; lastX: number; value: number; moved: boolean };
+
+/** Numeric field that edits on click and scrubs the value on horizontal drag. */
+export function ScrubInput({
+ label,
+ value,
+ onChange,
+ min,
+ max,
+ step = 1,
+ variant = "box",
+ ...props
+}: ScrubInputProps) {
+ const decimals = `${step}`.split(".")[1]?.length ?? 0;
+ const [draft, setDraft] = useState<string>();
+ const drag = useRef<Drag | undefined>(undefined);
+
+ const clamp = (next: number) =>
+ Math.min(max, Math.max(min, Number(next.toFixed(decimals))));
+
+ const commit = () => {
+ if (draft && !Number.isNaN(Number(draft))) onChange(clamp(Number(draft)));
+ setDraft(undefined);
+ };
+
+ const startScrub = (event: PointerEvent<HTMLInputElement>) => {
+ if (document.activeElement === event.currentTarget) return;
+ event.preventDefault();
+ event.currentTarget.setPointerCapture(event.pointerId);
+ drag.current = { dx: 0, lastX: event.clientX, value, moved: false };
+ };
+
+ const scrub = (event: PointerEvent<HTMLInputElement>) => {
+ const state = drag.current;
+ if (!state) return;
+ // Under pointer lock clientX freezes, so deltas come from movementX.
+ const locked = document.pointerLockElement === event.currentTarget;
+ state.dx += locked ? event.movementX : event.clientX - state.lastX;
+ state.lastX = event.clientX;
+ if (!state.moved && Math.abs(state.dx) > 2) {
+ state.moved = true;
+ // Lock hides the cursor so the drag is unbounded by screen edges.
+ Promise.resolve(event.currentTarget.requestPointerLock()).catch(() => {});
+ }
+ // Range-based speed so every control sweeps its full range in ~250px.
+ if (state.moved)
+ onChange(clamp(state.value + (state.dx * (max - min)) / 250));
+ };
+
+ const endScrub = (event: PointerEvent<HTMLInputElement>) => {
+ const state = drag.current;
+ drag.current = undefined;
+ if (!state) return;
+ if (state.moved) {
+ document.exitPointerLock();
+ return;
+ }
+ // A press that never moved is a click: enter text editing.
+ event.currentTarget.focus();
+ event.currentTarget.select();
+ };
+
+ return (
+ <label className="flex items-center gap-2 text-neutral-400 text-sm">
+ {label}
+ <Field className="w-16" variant={variant}>
+ <input
+ {...props}
+ className={input({ variant })}
+ inputMode="decimal"
+ onBlur={commit}
+ onChange={(event) => setDraft(event.currentTarget.value)}
+ onKeyDown={(event) =>
+ event.key === "Enter" && event.currentTarget.blur()
+ }
+ onPointerDown={startScrub}
+ onPointerMove={scrub}
+ onPointerUp={endScrub}
+ type="text"
+ value={draft ?? value.toFixed(decimals)}
+ />
+ </Field>
+ </label>
+ );
+}
diff --git a/src/components/ui/slider.tsx b/src/components/ui/slider.tsx
new file mode 100644
index 0000000..00ae6ae
--- /dev/null
+++ b/src/components/ui/slider.tsx
@@ -0,0 +1,61 @@
+import { ScrubInput } from "./scrub-input";
+
+type SliderProps = {
+ label: string;
+ value: number;
+ onChange: (value: number) => void;
+ min: number;
+ max: number;
+ step?: number;
+ /** Restored by double-clicking the bar. */
+ defaultValue?: number;
+ /** CSS color stops painting the bar left to right, e.g. ["#46f", "#fc3"]. */
+ stops?: string[];
+};
+
+const track =
+ "col-span-2 my-1 h-[4px] appearance-none rounded-full bg-neutral-900 shadow-groove outline-none focus-visible:ring-1 focus-visible:ring-neutral-100/50 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:size-3 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-neutral-100 [&::-webkit-slider-thumb]:ring-1 [&::-webkit-slider-thumb]:ring-neutral-800 [&::-moz-range-thumb]:size-2.5 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0 [&::-moz-range-thumb]:bg-neutral-100 [&::-moz-range-thumb]:ring-1 [&::-moz-range-thumb]:ring-neutral-800";
+
+/** Labeled slider paired with a scrubbable numeric field. */
+export function Slider({
+ label,
+ value,
+ onChange,
+ min,
+ max,
+ step = 1,
+ defaultValue,
+ stops,
+}: SliderProps) {
+ const gradient = stops && {
+ background: `linear-gradient(to right, ${stops.join()})`,
+ };
+ const reset = () => defaultValue !== undefined && onChange(defaultValue);
+
+ return (
+ <div className="grid grid-cols-[1fr_auto] items-center gap-y-0.5 text-neutral-400 text-sm">
+ <span>{label}</span>
+ <ScrubInput
+ aria-label={label}
+ max={max}
+ min={min}
+ onChange={onChange}
+ step={step}
+ value={value}
+ variant="text"
+ />
+ <input
+ aria-label={label}
+ className={track}
+ max={max}
+ min={min}
+ onChange={(event) => onChange(event.currentTarget.valueAsNumber)}
+ onDoubleClick={reset}
+ step={step}
+ style={gradient}
+ type="range"
+ value={value}
+ />
+ </div>
+ );
+}
diff --git a/src/index.css b/src/index.css
index c00c0b6..675e3dc 100644
--- a/src/index.css
+++ b/src/index.css
@@ -1,5 +1,19 @@
@import "tailwindcss";
+@theme {
+ --font-sans: "Geist Variable", system-ui, sans-serif;
+}
+
+/* `optional` never swaps after first paint, so the font can't cause layout shift. */
+@font-face {
+ font-family: "Geist Variable";
+ font-style: normal;
+ font-display: optional;
+ font-weight: 100 900;
+ src: url("@fontsource-variable/geist/files/geist-latin-wght-normal.woff2")
+ format("woff2-variations");
+}
+
@layer base {
html,
body,
@@ -9,10 +23,28 @@
body {
overflow: hidden;
- font:
- 15px system-ui,
- sans-serif;
+ font: 15px var(--font-sans);
color: var(--color-neutral-100);
background: var(--color-neutral-900);
+ text-shadow: 0 1px 1px rgb(0 0 0 / 0.25);
}
}
+
+/* Raised-surface relief: light catching the inner top edge. Composes through --tw-shadow. */
+@utility shadow-ridge {
+ --tw-shadow: inset 0 1px 0 rgb(255 255 255 / 0.07);
+ box-shadow:
+ var(--tw-inset-shadow, 0 0 #0000), var(--tw-inset-ring-shadow, 0 0 #0000),
+ var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
+ var(--tw-shadow);
+}
+
+/* Composes through --tw-shadow so it stacks with ring utilities. */
+@utility shadow-groove {
+ --tw-shadow:
+ inset 0 1px 2px rgb(0 0 0 / 0.25), 0 1px 0 rgb(255 255 255 / 0.07);
+ box-shadow:
+ var(--tw-inset-shadow, 0 0 #0000), var(--tw-inset-ring-shadow, 0 0 #0000),
+ var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
+ var(--tw-shadow);
+}