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.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Studios: a clear step between the composer and the example cards
Adarsh54cbacfa3ac7
diff --git a/src/components/examples/example-cards.tsx b/src/components/examples/example-cards.tsxindex 1171e6c3..ea8f692d 100644--- a/src/components/examples/example-cards.tsx+++ b/src/components/examples/example-cards.tsx@@ -10,6 +10,7 @@ import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "import { useIsMobile } from "@/hooks/use-mobile";import { exampleKey, type ExampleCard, type ExampleInput, type ExampleMedia, type ExampleRowData } from "@/lib/examples/types";import { hasHdStill } from "@/lib/preset-hd";+import { ROW_GAP, ROW_HEADING, rowColumns, rowSection, rowWidth, type ExampleAspect, type RowLayout } from "./example-row-frame";import { staggered } from "@/lib/preview-playback";import { cn } from "@/lib/utils";@@ -22,8 +23,7 @@ import { cn } from "@/lib/utils";/** What a card does when tapped. */export type ExamplePick = (card: ExampleCard) => void;-/** A card's shape: 4:3, or 3:4 on the vertical studios. */-export type ExampleAspect = "4/3" | "3/4";+export type { ExampleAspect };/** A real cover's still has a 320 px copy beside it (thumbs/), used on small screens, or larger copies (preset-hd.ts). */const hasCopies = (src: string) => /^\/previews\/presets\/(peak\/)?[^/]+\.(jpg|webp)\?/.test(src) || hasHdStill(src);@@ -233,18 +233,27 @@ function gridSizes(n: number): string {return "(min-width: 1032px) 240px, (min-width: 640px) 25vw, 50vw";}-/** Cards in a grid: two across a phone, four across a desktop (1000 px at most; one or two cards centred, one alone at 360 px). */-export function ExampleGrid({ cards, activeId, onPick, aspect, className }: { cards: ExampleCard[]; activeId?: string; onPick: ExamplePick; aspect?: ExampleAspect; className?: string }) {+/**+ * Cards in a grid: two across a phone, up to four across a desktop. On its own (the Examples sheet) one to three cards+ * stay centred at a card's width; inside a row (`bare`) the row's frame sets the width, so its heading lines up with it.+ */+export function ExampleGrid({+ cards,+ activeId,+ onPick,+ aspect,+ bare = false,+ className,+}: {+ cards: ExampleCard[];+ activeId?: string;+ onPick: ExamplePick;+ aspect?: ExampleAspect;+ bare?: boolean;+ className?: string;+}) {return (- <div- className={cn(- "grid gap-3 sm:gap-4",- // One card: one column, centred, never half a row with the other half empty.- cards.length === 1 ? "mx-auto max-w-[360px] grid-cols-1" : "grid-cols-2",- cards.length > 3 ? "sm:grid-cols-4" : cards.length === 3 ? "mx-auto max-w-[760px] sm:grid-cols-3" : cards.length === 2 && "mx-auto max-w-[520px]",- className,- )}- >+ <div data-example-grid className={cn("grid", ROW_GAP, rowColumns(cards.length), !bare && rowWidth(cards.length), className)}>{cards.map((c, i) => (<ExampleCardView key={c.id} card={c} index={i} active={!!activeId && exampleKey(c) === activeId} onPick={onPick} aspect={aspect} sizes={gridSizes(cards.length)} />))}@@ -252,12 +261,16 @@ export function ExampleGrid({ cards, activeId, onPick, aspect, className }: { ca);}-/** A row under a composer or an upload box: its line, and its cards. Look-only cards open their sheet here. */+/**+ * A row under a composer or an upload box: its heading on the cards' left edge, and its cards. Look-only cards open+ * their sheet here. Its frame (example-row-frame.tsx) is the one its skeleton draws while this code loads.+ */export function ExampleRow({row,activeId,onPick,aspect,+ layout = "centred",className,}: {row: ExampleRowData;@@ -265,6 +278,8 @@ export function ExampleRow({/** Loads a card into the page's composer; left out, every card is looked at. */onPick?: ExamplePick;aspect?: ExampleAspect;+ /** "column" under a studio's composer (the row fills the composer's column), "centred" as a section of its own. */+ layout?: RowLayout;className?: string;}) {const heading = useId();@@ -272,11 +287,13 @@ export function ExampleRow({if (!row.cards.length) return null;const pick: ExamplePick = (c) => (c.load.via === "look" || !onPick ? setLooking(c) : onPick(c));return (- <section aria-labelledby={heading} data-examples className={cn("mx-auto w-full max-w-[1000px]", className)}>- <h2 id={heading} className="mb-3 text-center text-[12.5px] font-medium text-muted-foreground">- {row.heading}- </h2>- <ExampleGrid cards={row.cards} activeId={activeId} onPick={pick} aspect={aspect} />+ <section aria-labelledby={heading} data-examples className={cn(rowSection(layout), className)}>+ <div className={rowWidth(row.cards.length, layout)}>+ <h2 id={heading} className={ROW_HEADING}>+ {row.heading}+ </h2>+ <ExampleGrid cards={row.cards} activeId={activeId} onPick={pick} aspect={aspect} bare />+ </div><ExampleSheet card={looking} onOpenChange={(o) => !o && setLooking(null)} /></section>);diff --git a/src/components/examples/example-row-frame.tsx b/src/components/examples/example-row-frame.tsxnew file mode 100644index 00000000..51e08368--- /dev/null+++ b/src/components/examples/example-row-frame.tsx@@ -0,0 +1,108 @@+import type { ExampleCard, ExampleRowData } from "@/lib/examples/types";+import { cn } from "@/lib/utils";++/**+ * The frame of a row of example cards, shared by the row and by its skeleton so the two always take the same place:+ * the space above it, its heading on the cards' left edge, and the cards' columns and width. Kept free of the cards'+ * code (and the clip player it brings): a studio page draws the skeleton before that chunk arrives.+ */++/**+ * How a row sits on its page:+ * - "column": under a studio's composer. The row fills the composer's column (its caller gives it the composer's+ * width), so the heading and the cards line up with the composer's edges.+ * - "centred": a section of its own on a wider page. One to three cards stay centred at a card's comfortable width.+ */+export type RowLayout = "column" | "centred";++/** A card's shape: 4:3, or 3:4 on the vertical studios. */+export type ExampleAspect = "4/3" | "3/4";++/** The cards' columns: two across a phone, up to four across a larger screen. */+export function rowColumns(count: number): string {+ if (count === 1) return "grid-cols-1";+ return cn("grid-cols-2", count === 3 ? "sm:grid-cols-3" : count > 3 && "sm:grid-cols-4");+}++/** The cards' width: one card is never wider than 360 px; a centred row of two or three keeps them card-sized. */+export function rowWidth(count: number, layout: RowLayout = "centred"): string | undefined {+ if (count === 1) return cn("max-w-[360px]", layout === "centred" && "mx-auto");+ if (layout === "column") return undefined;+ if (count === 2) return "mx-auto max-w-[520px]";+ if (count === 3) return "mx-auto max-w-[760px]";+ return undefined;+}++/** The row's own box: a centred row is at most 1000 px across its page; a column row takes its column's width. */+export const rowSection = (layout: RowLayout = "centred") => cn("w-full", layout === "centred" && "mx-auto max-w-[1000px]");++/** The row's heading ("Start from an example", "More to try"): a section title on the cards' left edge. */+export const ROW_HEADING = "mb-4 text-left text-[15px] leading-6 font-medium text-foreground";++/** The gap between the cards. */+export const ROW_GAP = "gap-3 sm:gap-4";++/** A line of text in a card's skeleton: the line's own height, with a bar in it. */+function Line({ h, bar, w }: { h: string; bar: string; w: string }) {+ return (+ <span className={cn("flex items-center", h)}>+ <span className={cn("rounded-full bg-muted", bar, w)} />+ </span>+ );+}++/** A card's skeleton: its picture, then the lines it has (its title, its line, its words, its settings). */+function CardSkeleton({ card, aspect }: { card: ExampleCard; aspect: ExampleAspect }) {+ return (+ <div data-example-skeleton className="min-w-0">+ <div className={cn("skeleton-sweep animate-skeleton rounded-xl bg-muted", aspect === "3/4" ? "aspect-[3/4]" : "aspect-[4/3]")} />+ <div className="mt-2 flex flex-col gap-1">+ {card.title && <Line h="h-[18px]" bar="h-3" w="w-4/5" />}+ <span className="flex flex-col">+ <Line h="h-[18px]" bar="h-3" w={card.title ? "w-11/12" : "w-full"} />+ {!card.title && <Line h="h-[18px]" bar="h-3" w="w-1/2" />}+ </span>+ {card.words && (+ <span className="flex flex-col">+ <Line h="h-[16.5px]" bar="h-2.5" w="w-full" />+ <Line h="h-[16.5px]" bar="h-2.5" w="w-2/3" />+ </span>+ )}+ {card.chips?.length ? <span className="h-5 w-9 rounded-full bg-muted" /> : null}+ </div>+ </div>+ );+}++/**+ * The row while its cards' code loads: the same heading, and a skeleton of each card (its picture and the lines it will+ * have) in the cards' own grid, so nothing moves when they arrive.+ */+export function ExampleRowSkeleton({+ row,+ aspect = "4/3",+ layout = "centred",+ className,+}: {+ row: ExampleRowData;+ aspect?: ExampleAspect;+ layout?: RowLayout;+ className?: string;+}) {+ const n = row.cards.length;+ if (!n) return null;+ return (+ <section aria-busy="true" aria-label={row.heading} data-examples-loading className={cn(rowSection(layout), className)}>+ <div className={rowWidth(n, layout)}>+ <p aria-hidden className={ROW_HEADING}>+ {row.heading}+ </p>+ <div aria-hidden className={cn("grid", ROW_GAP, rowColumns(n))}>+ {row.cards.map((c) => (+ <CardSkeleton key={c.id} card={c} aspect={aspect} />+ ))}+ </div>+ </div>+ </section>+ );+}diff --git a/src/components/moodboards/soul-preset-cards.tsx b/src/components/moodboards/soul-preset-cards.tsxindex 4ae39874..30e21d43 100644--- a/src/components/moodboards/soul-preset-cards.tsx+++ b/src/components/moodboards/soul-preset-cards.tsx@@ -3,7 +3,9 @@import { Images, UserRoundPlus } from "lucide-react";import Link from "next/link";import { useStudio } from "@/components/studio/studio-context";+import { ROW_HEADING } from "@/components/examples/example-row-frame";import { SOUL_MODEL_IDS } from "@/lib/catalog/soul-cards";+import { cn } from "@/lib/utils";/** The models the cards show for: Fuobe Soul and Soul HD, which take your own look (Soul Cinema has one fixed look). */const TAKES_OWN_LOOK = new Set<string>([SOUL_MODEL_IDS.soul, SOUL_MODEL_IDS.hd]);@@ -11,16 +13,17 @@ const TAKES_OWN_LOOK = new Set<string>([SOUL_MODEL_IDS.soul, SOUL_MODEL_IDS.hd])/*** The empty Image studio on Fuobe Soul: two cards for a look of your own — a character (Character Sheet, then a* Fuobe Soul ID from its page) and a moodboard (trained as a style LoRA). Kept free of the moodboard logic (and the- * look list it imports): every studio page loads it.+ * look list it imports): every studio page loads it. It sits in the composer's column, its heading styled like the+ * example row's.*/-export function SoulPresetCards() {+export function SoulPresetCards({ className }: { className?: string }) {const { draft } = useStudio();if (!TAKES_OWN_LOOK.has(draft.modelId)) return null;const card ="group flex min-w-0 items-center gap-3 rounded-2xl border bg-background p-3 text-left outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/50";return (- <section aria-label="Make your own Soul look" className="mx-auto w-full max-w-[760px] px-3 pb-10">- <p className="mb-2 text-center text-[12.5px] font-medium text-muted-foreground">Make your own Soul look</p>+ <section aria-label="Make your own Soul look" className={cn("w-full", className)}>+ <p className={ROW_HEADING}>Make your own Soul look</p><div className="grid gap-2 sm:grid-cols-2"><Link href="/character-sheet" className={card}><span className="grid size-10 shrink-0 place-items-center rounded-xl bg-brand-faint text-brand-text">diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsxindex 5bece4b0..e6b226de 100644--- a/src/components/studio/studio-page.tsx+++ b/src/components/studio/studio-page.tsx@@ -4,7 +4,7 @@ import { ArrowRight, ArrowUp, Loader2, Upload, Zap } from "lucide-react";import Link from "next/link";import dynamic from "next/dynamic";import { useSearchParams } from "next/navigation";-import { createContext, Suspense, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";+import { createContext, lazy, Suspense, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";import { useQuery } from "@tanstack/react-query";import { toast } from "sonner";import { PhoneNavButton } from "@/components/nav/phone-nav-button";@@ -20,6 +20,7 @@ import { migrateRequest } from "@/lib/catalog/replaced";import { SoulPresetCards } from "@/components/moodboards/soul-preset-cards";import type { StudioCatalog } from "@/lib/studio-catalog";import { EXAMPLE_PARAM, exampleFits, exampleKey, type ExampleCard, type ExampleRowData } from "@/lib/examples/types";+import { ExampleRowSkeleton } from "@/components/examples/example-row-frame";import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";import { cn } from "@/lib/utils";import { ComposerBridgeCtx, useComposerBridge, type ComposerBridge } from "./attachments";@@ -31,23 +32,10 @@ import { Feed } from "./feed";import { applyExample, draftFromGeneration, initialDraft, slot } from "./draft";import { PresetUrlCtx, StartRequestCtx, StudioProvider, usePresetUrl, useStudio, useStudioActions, type Draft, type StudioConfig } from "./studio-context";-/**- * The example cards while their chunk loads (a page reached by a tap): empty covers in the row's place, so the rest of the- * page draws at once. A `loading` option is what gives a dynamic() its own Suspense boundary: without it the chunk's load- * suspends the whole page up to the route's skeleton.- */-function ExampleCardsPlaceholder() {- return (- <div aria-hidden className="mx-auto grid w-full max-w-[1000px] grid-cols-2 gap-3 px-4 pb-10 sm:grid-cols-4 sm:gap-4 sm:px-6">- {[0, 1, 2, 3].map((i) => (- <div key={i} className={cn("aspect-[4/5] rounded-xl bg-muted", i >= 2 && "max-sm:hidden")} />- ))}- </div>- );-}-// The example cards (and the clip player they bring) are their own chunk: a page with no examples never loads them.-const ExampleRow = dynamic(() => import("@/components/examples/example-cards").then((m) => m.ExampleRow), { loading: ExampleCardsPlaceholder });+// The row loads under its own Suspense boundary (StudioExamples), whose fallback is the row's skeleton: the same heading+// and card shapes, sized from the row itself, so nothing moves when the cards arrive.+const ExampleRow = lazy(() => import("@/components/examples/example-cards").then((m) => ({ default: m.ExampleRow })));const ExampleStrip = dynamic(() => import("@/components/examples/example-cards").then((m) => m.ExampleStrip), { loading: () => null });const ExamplesButton = dynamic(() => import("@/components/examples/example-cards").then((m) => m.ExamplesButton), { loading: () => null });@@ -372,7 +360,7 @@ function PromptSuggestions({ suggestions }: { suggestions: string[] }) {const model = catalog.getModel(draft.modelId);if (!promptShown(config.hidePrompt, preset?.userPrompt, model?.options.promptless)) return null;return (- <div className="mx-auto mt-4 flex w-full max-w-[760px] min-w-0 flex-wrap justify-center gap-2 px-3 pb-10">+ <div className="mt-4 flex w-full min-w-0 flex-wrap justify-center gap-2">{suggestions.map((s) => (<buttonkey={s}@@ -386,17 +374,37 @@ function PromptSuggestions({ suggestions }: { suggestions: string[] }) {);}+/** The space between the composer (or what sits right under it) and each section below it. */+const UNDER_COMPOSER = "mt-10 sm:mt-12";++/** How long the row waits for the feed's answer before it shows its cards anyway: a slow feed never leaves grey tiles. */+const FEED_WAIT_MS = 3000;+/*** "Start from an example" under the empty composer (src/lib/examples): each card loads its own files, words and settings* into this composer. Hidden while a motion or effect is picked: its own examples are in its card above the composer.+ * The row fills the composer's column, so its heading and cards line up with the composer. Until the feed has answered+ * (`ready`, or FEED_WAIT_MS at most) and while the cards' code loads, its skeleton holds the same place.*/-function StudioExamples({ row }: { row: ExampleRowData }) {+function StudioExamples({ row, ready }: { row: ExampleRowData; ready: boolean }) {const { draft, config } = useStudio();const loader = useContext(ExamplesCtx);+ const [waited, setWaited] = useState(false);+ useEffect(() => {+ if (ready) return;+ const timer = setTimeout(() => setWaited(true), FEED_WAIT_MS);+ return () => clearTimeout(timer);+ }, [ready]);if (draft.presetId && draft.presetId !== config.preset?.id) return null;// An app's page shows its examples in its card above the composer.if (config.preset && row.cards.some((c) => c.load.via !== "look")) return null;- return <ExampleRow row={row} activeId={loader?.activeId} onPick={(c) => loader?.use(c)} className="px-4 pb-10 sm:px-6" />;+ const skeleton = <ExampleRowSkeleton row={row} layout="column" className={UNDER_COMPOSER} />;+ if (!ready && !waited) return skeleton;+ return (+ <Suspense fallback={skeleton}>+ <ExampleRow row={row} activeId={loader?.activeId} onPick={(c) => loader?.use(c)} layout="column" className={UNDER_COMPOSER} />+ </Suspense>+ );}/** Once there are results, "Examples" beside the composer opens the cards: a picked motion's or effect's, else the page's. */@@ -626,13 +634,17 @@ function StudioBody({ header, tabs, examples }: { header?: React.ReactNode; tabs</div></div>- {/* Hidden, not unmounted, while Live is on: the page around the panel keeps its state. */}- <div className={live ? "hidden" : "contents"}>- {/* Examples that load into the composer take the suggestions' place: they come first on a phone. */}- {!hasItems && config.suggestions && !examples?.cards.some((c) => c.load.via !== "look") && <PromptSuggestions suggestions={config.suggestions} />}- {!hasItems && config.signature && <SoulPresetCards />}- {/* Only once the feed is known to be empty: a studio with results would show the row, fetch its covers, then drop it. */}- {feed.isSuccess && !hasItems && !!examples?.cards.length && <StudioExamples row={examples} />}+ {/* What sits under the empty composer, in the composer's own column: its suggestions right under it, then each+ section a clear step below. Hidden, not unmounted, while Live is on: the page around the panel keeps its state. */}+ <div className={cn("px-4 pb-10 sm:px-6 sm:pb-16", (live || hasItems) && "hidden")}>+ <div data-under-composer className="mx-auto flex w-full max-w-[760px] min-w-0 flex-col">+ {/* Examples that load into the composer take the suggestions' place: they come first on a phone. */}+ {!hasItems && config.suggestions && !examples?.cards.some((c) => c.load.via !== "look") && <PromptSuggestions suggestions={config.suggestions} />}+ {!hasItems && config.signature && <SoulPresetCards className={UNDER_COMPOSER} />}+ {/* The cards once the feed has answered (a studio with results would show the row, fetch its covers, then drop+ it); its skeleton until then, never a blank gap that fills in. */}+ {!hasItems && !!examples?.cards.length && <StudioExamples row={examples} ready={!feed.isPending} />}+ </div></div>{dragging && (diff --git a/tests/e2e/composer-rows.mjs b/tests/e2e/composer-rows.mjsnew file mode 100644index 00000000..18dfef86--- /dev/null+++ b/tests/e2e/composer-rows.mjs@@ -0,0 +1,258 @@+// The rows under a composer ("Start from an example", "More to try", Make your own Soul look): on every studio page with+// a row, at 390, 768 and 1440 px, in light and dark, the row sits a fixed step below the composer (or the suggestions+// right under it), its heading is on the cards' left edge with a fixed step to the cards, and the row lines up with the+// composer's column. On the pages where the row is a section of its own (Genjutsu, Katana, Ads Studio…) the heading is+// on the cards' edge and the row stays inside the page. After load no card is grey or empty and no skeleton is left; while+// the cards' code loads, the skeleton has the row's heading and the cards' place, so nothing moves when they arrive.+// Usage: node tests/e2e/composer-rows.mjs <appUrl> [--shots <dir>] [--account] [--owner <password>] [--engine webkit]+// (--account signs up a new account first: the app needs FUOBE_PUBLIC_SIGNUP=1; --owner signs in with the password;+// --engine runs it in WebKit, Safari's engine, or Firefox instead of Chromium.)+// Exits 1 on a failed check.+import fs from "node:fs";+import path from "node:path";+import { launch, loadPlaywright, openRoute } from "./_browser.mjs";++const argv = process.argv.slice(2);+const valueOf = (flag) => (argv.includes(flag) ? argv[argv.indexOf(flag) + 1] : undefined);+const given = argv.find((a, i) => !a.startsWith("--") && !["--shots", "--owner", "--engine"].includes(argv[i - 1]));+if (!given) {+ console.error("usage: node tests/e2e/composer-rows.mjs <appUrl> [--shots <dir>] [--account] [--owner <password>] [--engine webkit]");+ process.exit(2);+}+const app = given.replace(/\/$/, "");+const shots = valueOf("--shots");+const engine = valueOf("--engine") ?? "chromium";+if (!["chromium", "webkit", "firefox"].includes(engine)) {+ console.error(`unknown engine: ${engine}`);+ process.exit(2);+}+if (shots) fs.mkdirSync(shots, { recursive: true });++const failures = [];+const check = (label, ok, extra = "") => {+ console.log(`${ok ? "ok " : "FAIL"} ${label.padEnd(84)}${extra ? ` ${extra}` : ""}`);+ if (!ok) failures.push(label);+};++/** Studio pages: the row is in the composer's column. */+const STUDIOS = [+ "/image",+ "/edit",+ "/inpaint",+ "/video",+ "/video-edit",+ "/extend",+ "/lipsync",+ "/motion-control",+ "/reframe",+ "/upscale",+ "/audio",+ "/audio/dialogue",+ "/audio/sfx",+ "/video-tools",+ "/video-tools/relight",+];+/** Pages whose row is a section of its own under an upload box or a project list. */+const SECTIONS = ["/genjutsu", "/katana", "/image-to-3d", "/layers", "/cinema", "/ads", "/ads/multiplier", "/character-swap"];+const SIZES = [+ { name: "390", viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true },+ { name: "768", viewport: { width: 768, height: 1024 } },+ { name: "1440", viewport: { width: 1440, height: 900 } },+];+const SCHEMES = ["light", "dark"];+/** The step between the composer (or its suggestions) and a row: Tailwind mt-10 on a phone, mt-12 from 640 px. */+const stepFor = (width) => (width >= 640 ? 48 : 40);+/** The step between a row's heading and its cards (mb-4). */+const HEADING_STEP = 16;+const near = (a, b, tol = 1.5) => a != null && b != null && Math.abs(a - b) <= tol;++const cookieOf = (res) => /fuobe_session=[^;]+/.exec(res.headers.get("set-cookie") ?? "")?.[0];+async function session() {+ const headers = { "Content-Type": "application/json", Origin: app };+ if (argv.includes("--owner")) {+ const res = await fetch(`${app}/api/auth/login`, { method: "POST", headers, body: JSON.stringify({ password: valueOf("--owner") }) });+ return { who: "owner", cookie: cookieOf(res) };+ }+ if (argv.includes("--account")) {+ const res = await fetch(`${app}/api/auth/signup`, { method: "POST", headers, body: JSON.stringify({ email: `rows-${Date.now()}@example.com`, password: `Rows-${Date.now()}-check!` }) });+ return { who: "account", cookie: cookieOf(res) };+ }+ return { who: "guest" };+}++/** Where the row and what is above it sit (page coordinates). */+function measure() {+ const box = (el) => {+ if (!el) return null;+ const r = el.getBoundingClientRect();+ return { l: r.left, r: r.right, t: r.top + scrollY, b: r.bottom + scrollY, w: r.width };+ };+ const section = document.querySelector("[data-examples]") ?? document.querySelector("[data-examples-loading]");+ const heading = section?.querySelector("h2, p");+ const grid = section?.querySelector("[data-example-grid], .grid");+ const composer = document.querySelector("[data-studio] [data-composer]");+ // What sits right above the row in the composer's column: the composer, or what is under it (suggestions, Soul cards).+ let above = composer ? box(composer) : null;+ const column = section?.closest("[data-under-composer]");+ if (column && section) {+ for (const el of column.children) {+ if (el === section || el.contains(section)) break;+ const b = box(el);+ if (b && b.w > 0 && (!above || b.b > above.b)) above = b;+ }+ }+ // A section of its own: the nearest box above it on the page.+ let previous = null;+ if (!composer && section) {+ let el = section;+ while (el && !previous) {+ let sib = el.previousElementSibling;+ while (sib && !previous) {+ const b = box(sib);+ if (b && b.w > 0 && b.b - b.t > 0) previous = b;+ sib = sib.previousElementSibling;+ }+ el = el.parentElement;+ }+ }+ const firstCard = grid?.firstElementChild;+ return {+ loading: !!section?.hasAttribute("data-examples-loading"),+ headingText: heading?.textContent?.trim() ?? "",+ headingAlign: heading ? getComputedStyle(heading).textAlign : "",+ heading: box(heading),+ grid: box(grid),+ firstCard: box(firstCard),+ composer: box(composer),+ above,+ previous,+ page: { w: innerWidth, scrollW: document.documentElement.scrollWidth },+ };+}++/** Every card shows its picture (or its clip's still); no skeleton is left. */+async function cardsFilled(page) {+ const cards = page.locator("[data-examples] [data-example]");+ const n = await cards.count();+ for (let i = 0; i < n; i++) await cards.nth(i).scrollIntoViewIfNeeded().catch(() => {});+ await page.waitForTimeout(1200);+ return page.evaluate(() => {+ const cards = [...document.querySelectorAll("[data-examples] [data-example]")];+ const empty = cards.filter((c) => {+ const media = [...c.querySelectorAll("img, video")];+ if (!media.length) return true;+ return !media.some((m) => (m.tagName === "IMG" ? m.complete && m.naturalWidth > 0 : !!m.poster || m.readyState > 0));+ });+ return { cards: cards.length, empty: empty.map((c) => c.getAttribute("data-example")), skeletons: document.querySelectorAll("[data-example-skeleton]").length };+ });+}++const { who, cookie } = await session();+if (who !== "guest") check(`${who}: signed in`, !!cookie);+console.log(`as ${who}, in ${engine}`);+const browser = engine === "chromium" ? await launch() : await loadPlaywright()[engine].launch();+/** Shots in another engine carry its name. */+const tag = engine === "chromium" ? who : `${who}-${engine}`;++for (const size of SIZES) {+ for (const scheme of SCHEMES) {+ // Firefox has no mobile emulation: its phone is the phone's width and touch.+ const mobile = engine === "firefox" ? {} : { isMobile: size.isMobile };+ const context = await browser.newContext({ viewport: size.viewport, ...mobile, hasTouch: size.hasTouch, colorScheme: scheme });+ if (cookie) {+ const [name, value] = cookie.split("=");+ await context.addCookies([{ name, value, url: app }]);+ }+ const page = await context.newPage();+ page.setDefaultTimeout(30_000);+ const step = stepFor(size.viewport.width);+ for (const url of [...STUDIOS, ...SECTIONS]) {+ const label = `${url} (${size.name}, ${scheme})`;+ await openRoute(page, `${app}${url}`, { settleMs: 1500 });+ await page.locator("[data-examples]").first().waitFor({ timeout: 20_000 }).catch(() => {});+ const m = await page.evaluate(measure);+ if (!m.heading) {+ // An owner or an account with results sees the feed instead: nothing to check here.+ const hasFeed = (await page.locator("[data-studio] [data-composer]").count()) && !(await page.locator("[data-studio] h2.text-display").count());+ console.log(`skip ${label}: no row${hasFeed ? " (results shown)" : ""}`);+ continue;+ }+ check(`${label}: no sideways scroll`, m.page.scrollW <= m.page.w + 1, `${m.page.scrollW} > ${m.page.w}`);+ check(`${label}: the heading is on the cards' left edge`, near(m.heading.l, m.grid?.l) && m.headingAlign !== "center", `${m.heading.l} vs ${m.grid?.l} (${m.headingAlign})`);+ check(`${label}: a fixed step from the heading to the cards`, near(m.grid?.t - m.heading.b, HEADING_STEP), `${Math.round(m.grid?.t - m.heading.b)} px`);+ if (m.composer) {+ check(`${label}: a fixed step under the composer`, near(m.heading.t - m.above.b, step), `${Math.round(m.heading.t - m.above.b)} px, want ${step}`);+ check(`${label}: the row starts at the composer's left edge`, near(m.grid.l, m.composer.l), `${m.grid.l} vs ${m.composer.l}`);+ check(`${label}: the row is no wider than the composer`, m.grid.r <= m.composer.r + 1.5, `${m.grid.r} vs ${m.composer.r}`);+ } else {+ check(`${label}: clear space above the row`, m.previous && m.heading.t - m.previous.b >= 32, m.previous ? `${Math.round(m.heading.t - m.previous.b)} px` : "nothing above");+ check(`${label}: the row stays inside the page`, m.grid.l >= 15 && m.grid.r <= m.page.w - 15, `${m.grid.l}-${m.grid.r}`);+ }+ const filled = await cardsFilled(page);+ check(`${label}: no grey or empty card after load`, filled.cards > 0 && !filled.empty.length && !filled.skeletons, `${filled.cards} cards, empty ${filled.empty.join(",") || "none"}, skeletons ${filled.skeletons}`);+ if (shots && (url === "/image" || url === "/genjutsu")) {+ await page.evaluate(() => {+ const c = document.querySelector("[data-studio] [data-composer]") ?? document.querySelector("[data-examples]");+ if (c) window.scrollTo(0, Math.max(0, c.getBoundingClientRect().top + scrollY - 140));+ });+ await page.waitForTimeout(300);+ await page.screenshot({ path: path.join(shots, `${url.replace(/\W+/g, "_").replace(/^_/, "")}-${tag}-${size.name}-${scheme}.png`) });+ }+ }++ // The loading state on /image: hold every script that starts after the feed answers (the cards' code among them),+ // once, until the skeleton is measured.+ {+ const label = `/image loading (${size.name}, ${scheme})`;+ const held = await context.newPage();+ let hold = false;+ let fed = false;+ let released = false;+ const waiting = [];+ await held.route("**/_next/static/chunks/**", async (route) => {+ if (hold) await new Promise((r) => waiting.push(r));+ await route.continue().catch(() => {});+ });+ held.on("response", (r) => {+ if (new URL(r.url()).pathname !== "/api/generations") return;+ fed = true;+ // A feed that answers after the release (a slow first answer) holds nothing: the release is for good.+ if (!released) hold = true;+ });+ // Not "load": when the feed answers first, the held scripts can be ones the load event waits for.+ await held.goto(`${app}/image`, { waitUntil: "commit", timeout: 60_000 });+ await held.locator("[data-examples-loading], [data-examples]").first().waitFor({ timeout: 30_000 }).catch(() => {});+ for (let waited = 0; !fed && waited < 15_000; waited += 250) await held.waitForTimeout(250);+ await held.waitForTimeout(1500);+ const before = await held.evaluate(measure);+ const loading = before.loading;+ if (!before.heading) console.log(`skip ${label}: no row (results shown)`);+ else {+ check(`${label}: the skeleton has the row's heading`, loading ? before.headingText.length > 0 : true, before.headingText);+ if (shots && loading) await held.screenshot({ path: path.join(shots, `image-loading-${tag}-${size.name}-${scheme}.png`) });+ hold = false;+ released = true;+ waiting.splice(0).forEach((r) => r());+ await held.locator("[data-examples]").first().waitFor({ timeout: 30_000 }).catch(() => {});+ await held.waitForTimeout(500);+ const after = await held.evaluate(measure);+ check(`${label}: the cards replace the skeleton`, !after.loading && after.headingText === before.headingText, `${before.headingText} -> ${after.headingText}${fed ? "" : " (the feed never answered)"}`);+ check(+ `${label}: nothing moves when the cards arrive`,+ near(before.heading.t, after.heading.t) && near(before.grid.t, after.grid.t) && near(before.grid.l, after.grid.l) && near(before.grid.r, after.grid.r) && near(before.firstCard?.w, after.firstCard?.w),+ `heading ${Math.round(before.heading.t)}->${Math.round(after.heading.t)}, grid ${Math.round(before.grid.l)}-${Math.round(before.grid.r)} -> ${Math.round(after.grid.l)}-${Math.round(after.grid.r)}`,+ );+ if (!loading) console.log(`note ${label}: the cards were already there (no skeleton seen)`);+ }+ hold = false;+ released = true;+ waiting.splice(0).forEach((r) => r());+ await held.close();+ }+ await context.close();+ }+}++await browser.close();+console.log(failures.length ? `\n${failures.length} failed` : "\nall passed");+process.exit(failures.length ? 1 : 0);