Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Layers: tablets get a layer strip, the header always fits, Edit text reloads its rows

Claude7a3c8964667a
diff --git a/src/components/layers/layers-editor.tsx b/src/components/layers/layers-editor.tsx
index faedd70e..27ce60bb 100644
--- a/src/components/layers/layers-editor.tsx
+++ b/src/components/layers/layers-editor.tsx
@@ -102,8 +102,8 @@ export function LayersEditor({ id, models }: { id: string; models: Record<string
}
/**
- * Below 1280 px the app's sidebar folds to icons while the editor is open, so the canvas keeps its
- * room next to a tool's form and the Layers panel; it opens again when you leave.
+ * Below 1440 px the app's sidebar folds to icons while the editor is open, so the canvas keeps its
+ * room next to a tool's form and the Layers panel (and the top bar its labels); it opens again when you leave.
*/
function useRoomyCanvas() {
const sidebar = useSidebar();
@@ -113,7 +113,7 @@ function useRoomyCanvas() {
});
useEffect(() => {
const s = ref.current;
- if (s.isMobile || !s.open || window.innerWidth >= 1280) return;
+ if (s.isMobile || !s.open || window.innerWidth >= 1440) return;
s.setOpen(false);
return () => ref.current.setOpen(true);
}, []);
diff --git a/src/components/layers/layers-panel.tsx b/src/components/layers/layers-panel.tsx
index 1f4bbf25..5688ef42 100644
--- a/src/components/layers/layers-panel.tsx
+++ b/src/components/layers/layers-panel.tsx
@@ -15,6 +15,8 @@ import {
Library,
Loader2,
MoreHorizontal,
+ PanelRightClose,
+ PanelRightOpen,
Pencil,
Plus,
RotateCcw,
@@ -29,7 +31,7 @@ import {
X,
} from "lucide-react";
import { nanoid } from "nanoid";
-import { useMemo, useRef, useState } from "react";
+import { useMemo, useRef, useState, useSyncExternalStore } from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
@@ -40,6 +42,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
import { Slider } from "@/components/ui/slider";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
+import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { LibraryGrid } from "@/components/studio/media-slot";
import { uploadFile } from "@/lib/api";
import {
@@ -695,11 +698,70 @@ function Geometry({ node }: { node: LayerNode }) {
);
}
+const NARROW = "(max-width: 1023px)";
+const useNarrow = () =>
+ useSyncExternalStore(
+ (cb) => {
+ const mql = window.matchMedia(NARROW);
+ mql.addEventListener("change", cb);
+ return () => mql.removeEventListener("change", cb);
+ },
+ () => window.matchMedia(NARROW).matches,
+ () => false,
+ );
+
+/**
+ * Below 1024 px, while a tool's form is open, the panel folds to a strip of thumbnails (pick the
+ * layer the tool works on; the button on top unfolds it), so the canvas keeps its room.
+ */
+function LayerStrip({ rows, onExpand }: { rows: LayerNode[]; onExpand: () => void }) {
+ const { selected, select, busyJob, failedJob } = useEditor();
+ return (
+ <aside className="flex min-h-0 w-[56px] shrink-0 flex-col items-center border-l bg-background" aria-label="Layers panel">
+ <div className="flex h-12 shrink-0 items-center">
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button size="icon-sm" variant="ghost" aria-label={`Show the Layers panel (${rows.length} layers)`} onClick={onExpand}>
+ <PanelRightOpen />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent side="left">Layers · {rows.length}</TooltipContent>
+ </Tooltip>
+ </div>
+ <ul className="min-h-0 w-full flex-1 space-y-1 overflow-x-hidden overflow-y-auto overscroll-contain px-1.5 pb-2" aria-label="Layers, front to back">
+ {rows.map((n) => (
+ <li key={n.id} className="relative">
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <button
+ type="button"
+ aria-pressed={selected?.id === n.id}
+ aria-label={`Select layer ${n.name}`}
+ onClick={() => select(n.id)}
+ className={cn("grid w-full place-items-center rounded-lg p-0.5 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50", selected?.id === n.id ? "bg-brand-faint ring-2 ring-primary" : "hover:bg-accent", n.hidden && "opacity-50")}
+ >
+ <LayerThumb node={n} className="size-9" />
+ </button>
+ </TooltipTrigger>
+ <TooltipContent side="left">{n.name}</TooltipContent>
+ </Tooltip>
+ {busyJob(n.id) ? <Loader2 className="pointer-events-none absolute -top-0.5 -right-0.5 size-3.5 animate-spin rounded-full bg-background text-brand-text" aria-hidden /> : failedJob(n.id) ? <TriangleAlert className="pointer-events-none absolute -top-0.5 -right-0.5 size-3.5 rounded-full bg-background text-destructive" aria-hidden /> : null}
+ </li>
+ ))}
+ </ul>
+ </aside>
+ );
+}
+
export function LayersPanel() {
- const { doc, commit, selected, busyJob } = useEditor();
+ const { doc, commit, selected, busyJob, tool } = useEditor();
const rows = useMemo(() => [...doc.nodes].sort((a, b) => b.z - a.z), [doc.nodes]);
const list = useRef<HTMLUListElement>(null);
const [dragging, setDragging] = useState<{ id: string; before: number } | null>(null);
+ const narrow = useNarrow();
+ /** The tool the panel was unfolded for (a new tool folds it again). */
+ const [openFor, setOpenFor] = useState<string | null>(null);
+ const strip = narrow && !!tool && openFor !== tool;
// Drag a row by its handle: drop it between two rows (top of the list = front).
const onDragHandle = (e: React.PointerEvent, id: string) => {
@@ -738,9 +800,16 @@ export function LayersPanel() {
target.addEventListener("pointercancel", up);
};
+ if (strip) return <LayerStrip rows={rows} onExpand={() => setOpenFor(tool)} />;
+
return (
<aside className="flex min-h-0 w-[232px] shrink-0 flex-col border-l bg-background lg:w-[264px] xl:w-[300px]" aria-label="Layers panel">
<div className="flex h-12 shrink-0 items-center gap-2 px-3">
+ {narrow && tool && (
+ <Button size="icon-xs" variant="ghost" className="-ml-1" aria-label="Fold the Layers panel" onClick={() => setOpenFor(null)}>
+ <PanelRightClose />
+ </Button>
+ )}
<h2 className="text-[13px] font-semibold">Layers</h2>
<span className="font-mono text-[12px] text-subtle-foreground">{doc.nodes.length}</span>
<div className="ml-auto">
diff --git a/src/components/layers/projects-view.tsx b/src/components/layers/projects-view.tsx
index 4638ae63..0ee93229 100644
--- a/src/components/layers/projects-view.tsx
+++ b/src/components/layers/projects-view.tsx
@@ -109,13 +109,13 @@ function ProjectCard({ p, onRename, onDelete }: { p: LayerProject; onRename: ()
)}
>
{p.status === "processing" ? <Loader2 className="size-3 shrink-0 animate-spin" /> : p.status === "unopened" ? <Layers className="size-3 shrink-0" /> : null}
- <span className="truncate">{p.status === "processing" ? "Processing…" : p.status === "unopened" ? "Layers ready — open to see them" : "Couldn't be processed"}</span>
+ <span className="truncate">{p.status === "processing" ? "Processing…" : p.status === "unopened" ? "Layers ready" : "Couldn't be processed"}</span>
</span>
)}
</div>
<h3 className="mt-2 truncate pr-9 text-[14px] font-medium">{p.name}</h3>
- <p className="text-[12px] text-muted-foreground">
- {timeAgo(p.updatedAt)} · {p.status === "unopened" && p.pendingLayers ? `${p.pendingLayers} layers ready` : `${p.layers} layer${p.layers === 1 ? "" : "s"}`}
+ <p className={cn("truncate pr-9 text-[12px]", p.status === "unopened" ? "text-brand-text" : "text-muted-foreground")}>
+ {timeAgo(p.updatedAt)} · {p.status === "unopened" ? `${p.pendingLayers ? `${p.pendingLayers} layers` : "Layers"} ready — open to see them` : `${p.layers} layer${p.layers === 1 ? "" : "s"}`}
</p>
</Link>
<DropdownMenu>
diff --git a/src/components/layers/tools.tsx b/src/components/layers/tools.tsx
index 8c83b8fb..a50da179 100644
--- a/src/components/layers/tools.tsx
+++ b/src/components/layers/tools.tsx
@@ -440,36 +440,36 @@ function EditTextTool() {
const { busy, go } = useRun();
const [rows, setRows] = useState<{ from: string; to: string; box: Box | null }[]>([]);
const [restored, setRestored] = useState(false);
- const loadedFor = useRef<string | null>(null);
+ /** The detection whose rows are in the list (set once they've loaded). */
+ const [loadedFor, setLoadedFor] = useState<string | null>(null);
- // Rows from the newest finished detection (boxes measured on its image, placed in its frame).
+ // Rows from the newest finished detection (boxes measured on its image, placed in its frame). A
+ // refetch (or React's strict-mode re-run) mid-load just loads it again.
useEffect(() => {
- if (!detect || detect.result?.status !== "succeeded" || loadedFor.current === detect.id) return;
- loadedFor.current = detect.id;
+ if (!detect || detect.result?.status !== "succeeded" || loadedFor === detect.id) return;
const out = detect.result.outputs[0];
- if (!out) return;
let gone = false;
- void loadImage(out.url)
- .then((img) => sizeOf(img))
+ void (out ? loadImage(out.url).then((img) => sizeOf(img)) : Promise.reject(new Error("no output")))
.catch(() => undefined)
.then((natural) => {
if (gone) return;
- const blocks: TextBlock[] = textBlocksFrom(out.meta, natural);
+ const blocks: TextBlock[] = out ? textBlocksFrom(out.meta, natural) : [];
const f = detect.frame;
setRows(blocks.map((b) => ({ from: b.text, to: b.text, box: b.box ? [f[0] + b.box[0] * f[2], f[1] + b.box[1] * f[3], b.box[2] * f[2], b.box[3] * f[3]] : null })));
setRestored(detect.state === "applied");
+ setLoadedFor(detect.id);
if (detect.state === "pending") endJob(detect.id, "applied");
});
return () => {
gone = true;
};
- }, [detect, endJob]);
+ }, [detect, endJob, loadedFor]);
useEffect(() => () => setHighlight(null), [setHighlight]);
const changes = textChanges(rows);
const detecting = detect && isRunning(detect);
const startDetect = () => {
- loadedFor.current = null;
+ setLoadedFor(null);
setRestored(false);
void go({ tool: "text-detect", target, label: "Detect text" });
};
@@ -487,7 +487,7 @@ function EditTextTool() {
{detecting ? <Loader2 className="animate-spin" /> : <Type />} {detecting ? "Reading the text…" : "Detect text"}
</Button>
<p className="text-center font-mono text-[11px] text-subtle-foreground">{costLabel(detectModel, isDemo(detectModel))}</p>
- {detect?.result?.status === "succeeded" && !rows.length && <p className="text-center text-[12px] text-muted-foreground">No text was found on this image.</p>}
+ {detect?.result?.status === "succeeded" && loadedFor === detect.id && !rows.length && <p className="text-center text-[12px] text-muted-foreground">No text was found on this image.</p>}
{detect && isFailed(detect) && <JobState job={detect} failedTitle="Could not read the text on this image." onRetry={startDetect} />}
</div>
)
diff --git a/src/components/layers/top-bar.tsx b/src/components/layers/top-bar.tsx
index db9332fa..56869c80 100644
--- a/src/components/layers/top-bar.tsx
+++ b/src/components/layers/top-bar.tsx
@@ -113,11 +113,15 @@ export function DownloadMenu({ doc, name, jobs, compact }: { doc: LayerDoc; name
/** The autosave state: an icon at every width, its words from 1280 px (and in its tooltip). A failed save can be retried now. */
function SaveBadge({ state, onRetry }: { state: SaveState; onRetry: () => void }) {
const text = { saved: "Saved", saving: "Saving…", dirty: "Saving…", error: "Not saved — retrying", conflict: "Changed in another tab" }[state];
+ const short = { error: "Not saved", conflict: "Changed elsewhere" }[state as "error" | "conflict"] ?? text;
const bad = state === "error" || state === "conflict";
const body = (
<>
{state === "saved" ? <Check className="size-3.5 shrink-0" /> : bad ? <CloudOff className="size-3.5 shrink-0" /> : <Loader2 className="size-3.5 shrink-0 animate-spin" />}
- <span className="sr-only xl:not-sr-only">{text}</span>
+ <span className="sr-only">{text}</span>
+ <span className="hidden xl:inline" aria-hidden>
+ {short}
+ </span>
</>
);
const cls = cn("inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-1 text-[12px] whitespace-nowrap", bad ? "text-warning" : "text-subtle-foreground");
@@ -202,11 +206,12 @@ export function TopBar(p: {
e.currentTarget.blur();
}
}}
- className="h-8 w-[clamp(6rem,16vw,16rem)] min-w-0 truncate rounded-md border border-transparent bg-transparent px-2 font-heading text-[19px] outline-none hover:border-border focus:border-primary focus:ring-4 focus:ring-brand-faint"
+ className="h-8 w-[clamp(6rem,14vw,15rem)] min-w-0 truncate rounded-md border border-transparent bg-transparent px-2 font-heading text-[19px] outline-none hover:border-border focus:border-primary focus:ring-4 focus:ring-brand-faint"
/>
<SaveBadge state={p.save} onRetry={p.onRetrySave} />
- <div className="ml-auto flex items-center gap-1">
+ {/* The actions keep their size; the project name gives way when room is short. */}
+ <div className="ml-auto flex shrink-0 items-center gap-1">
<Tooltip>
<TooltipTrigger asChild>
<Button variant="ghost" size="icon-sm" aria-label="Undo" disabled={!p.canUndo} onClick={p.onUndo}>
@@ -233,7 +238,7 @@ export function TopBar(p: {
<Button variant="ghost" size="sm" className="rounded-full" onClick={() => setHistoryOpen(true)} aria-label="Edit history">
<History /> <span className="hidden xl:inline">Edit history</span>
</Button>
- <Button variant={p.compare ? "default" : "ghost"} size="sm" className="rounded-full" aria-pressed={p.compare} onClick={() => p.onCompare(!p.compare)}>
+ <Button variant={p.compare ? "default" : "ghost"} size="sm" className="rounded-full" aria-label="Compare" aria-pressed={p.compare} onClick={() => p.onCompare(!p.compare)}>
<Columns2 /> <span className="hidden xl:inline">Compare</span>
</Button>
<span className="mx-1 hidden h-5 w-px bg-border sm:block" />
@@ -241,7 +246,7 @@ export function TopBar(p: {
<Tooltip>
<TooltipTrigger asChild>
<span>
- <Button variant="ghost" size="sm" className="rounded-full" disabled={!p.doc.nodes.length} onClick={() => void copyJson()}>
+ <Button variant="ghost" size="sm" className="rounded-full" aria-label="Copy JSON" disabled={!p.doc.nodes.length} onClick={() => void copyJson()}>
<Braces /> <span className="hidden xl:inline">Copy JSON</span>
</Button>
</span>
diff --git a/src/lib/layers.ts b/src/lib/layers.ts
index 3d4a9707..91485b47 100644
--- a/src/lib/layers.ts
+++ b/src/lib/layers.ts
@@ -500,13 +500,20 @@ export function layerDensity(node: Pick<LayerNode, "w" | "crop" | "natural">): n
return src && node.w > 0 && src[2] > 0 ? src[2] / node.w : 1;
}
+/** The share of the canvas a layer covers (its rotation-aware box inside the document), 0–1. */
+export function coverage(node: Pick<LayerNode, "x" | "y" | "w" | "h" | "rotation">, doc: Pick<LayerDoc, "width" | "height">): number {
+ const b = intersect(rotatedBounds(node.x, node.y, node.w, node.h, node.rotation), [0, 0, doc.width, doc.height]);
+ return b ? (b[2] * b[3]) / (doc.width * doc.height) : 0;
+}
+
/**
- * The scale an export renders at so no visible layer loses detail (an upscaled layer makes the
- * whole picture bigger): the densest layer's, never below 1, kept to `max` px on the long side.
+ * The scale a full-detail export renders at: the densest of the visible layers that cover at least
+ * half of the canvas (a whole-picture upscale makes the export bigger; a small layer a model
+ * returned at 2K doesn't blow up the picture around it), never below 1, kept to `max` px on the long side.
*/
export function exportScale(doc: Pick<LayerDoc, "width" | "height" | "nodes">, max = EXPORT_MAX_PX): number {
let d = 1;
- for (const n of doc.nodes) if (!n.hidden) d = Math.max(d, layerDensity(n));
+ for (const n of doc.nodes) if (!n.hidden && coverage(n, doc) >= 0.5) d = Math.max(d, layerDensity(n));
return Math.max(1, Math.min(d, max / Math.max(doc.width, doc.height)));
}
diff --git a/tests/layers.test.ts b/tests/layers.test.ts
index 231e6e62..a7538c52 100644
--- a/tests/layers.test.ts
+++ b/tests/layers.test.ts
@@ -42,6 +42,7 @@ import {
toLocal,
TOOL_MODELS,
zipPlan,
+ coverage,
defaultLayers,
exportScale,
layerDensity,
@@ -510,6 +511,10 @@ describe("exports keep every layer's detail", () => {
expect(scaledSize(960, 720, exportScale(up))).toEqual([3840, 2880]);
// Hidden layers don't count; a crop counts its own pixels.
expect(exportScale(updateNode(up, "up", { hidden: true }))).toBe(1);
+ // Nor do small layers: a model's 2K answer for a corner of the picture keeps the picture's size.
+ expect(exportScale(addNodes(d, [node("corner", 0, { x: 0, y: 0, w: 400, h: 300, natural: [2048, 1536] })]))).toBe(1);
+ expect(coverage(node("half", 0, { x: 0, y: 0, w: 960, h: 360 }), d)).toBeCloseTo(0.5);
+ expect(coverage(node("off", 0, { x: 2000, y: 0 }), d)).toBe(0);
expect(layerDensity(node("c", 0, { w: 100, crop: [0, 0, 300, 150], natural: [1000, 1000] }))).toBe(3);
// Enlarged past its pixels: the document's own size, never smaller.
expect(exportScale(doc([node("big", 0, { w: 400, natural: [100, 50] })]))).toBe(1);