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
Home: a larger headline and sharper first-screen media
Adarsh4de94381b083
diff --git a/public/previews/home/ba-after-1280.avif b/public/previews/home/ba-after-1280.avifnew file mode 100644index 00000000..0d733fb3Binary files /dev/null and b/public/previews/home/ba-after-1280.avif differdiff --git a/public/previews/home/ba-after-640.avif b/public/previews/home/ba-after-640.avifindex 39f08510..02399566 100644Binary files a/public/previews/home/ba-after-640.avif and b/public/previews/home/ba-after-640.avif differdiff --git a/public/previews/home/ba-after-960.avif b/public/previews/home/ba-after-960.avifindex 5127d3da..1716a374 100644Binary files a/public/previews/home/ba-after-960.avif and b/public/previews/home/ba-after-960.avif differdiff --git a/public/previews/home/ba-after-tall-360.avif b/public/previews/home/ba-after-tall-360.avifdeleted file mode 100644index 07278d28..00000000Binary files a/public/previews/home/ba-after-tall-360.avif and /dev/null differdiff --git a/public/previews/home/ba-after-tall-432.avif b/public/previews/home/ba-after-tall-432.avifnew file mode 100644index 00000000..fbc97620Binary files /dev/null and b/public/previews/home/ba-after-tall-432.avif differdiff --git a/public/previews/home/ba-after-tall-576.avif b/public/previews/home/ba-after-tall-576.avifdeleted file mode 100644index ea58f463..00000000Binary files a/public/previews/home/ba-after-tall-576.avif and /dev/null differdiff --git a/public/previews/home/ba-after-tall-691.avif b/public/previews/home/ba-after-tall-691.avifnew file mode 100644index 00000000..d2b3df26Binary files /dev/null and b/public/previews/home/ba-after-tall-691.avif differdiff --git a/public/previews/home/ba-before-1280.avif b/public/previews/home/ba-before-1280.avifnew file mode 100644index 00000000..95d72761Binary files /dev/null and b/public/previews/home/ba-before-1280.avif differdiff --git a/public/previews/home/ba-before-640.avif b/public/previews/home/ba-before-640.avifindex 17205b8a..80b71132 100644Binary files a/public/previews/home/ba-before-640.avif and b/public/previews/home/ba-before-640.avif differdiff --git a/public/previews/home/ba-before-960.avif b/public/previews/home/ba-before-960.avifindex cc6326fa..09a9d198 100644Binary files a/public/previews/home/ba-before-960.avif and b/public/previews/home/ba-before-960.avif differdiff --git a/public/previews/home/ba-before-tall-360.avif b/public/previews/home/ba-before-tall-360.avifdeleted file mode 100644index a1aa2ae1..00000000Binary files a/public/previews/home/ba-before-tall-360.avif and /dev/null differdiff --git a/public/previews/home/ba-before-tall-432.avif b/public/previews/home/ba-before-tall-432.avifnew file mode 100644index 00000000..4b35e921Binary files /dev/null and b/public/previews/home/ba-before-tall-432.avif differdiff --git a/public/previews/home/ba-before-tall-576.avif b/public/previews/home/ba-before-tall-576.avifdeleted file mode 100644index a7048325..00000000Binary files a/public/previews/home/ba-before-tall-576.avif and /dev/null differdiff --git a/public/previews/home/ba-before-tall-691.avif b/public/previews/home/ba-before-tall-691.avifnew file mode 100644index 00000000..1f67db46Binary files /dev/null and b/public/previews/home/ba-before-tall-691.avif differdiff --git a/public/previews/home/catwalk-1024.avif b/public/previews/home/catwalk-1024.avifnew file mode 100644index 00000000..e063c4bcBinary files /dev/null and b/public/previews/home/catwalk-1024.avif differdiff --git a/public/previews/home/catwalk-1024.mp4 b/public/previews/home/catwalk-1024.mp4new file mode 100644index 00000000..044050bdBinary files /dev/null and b/public/previews/home/catwalk-1024.mp4 differdiff --git a/public/previews/home/catwalk-512.avif b/public/previews/home/catwalk-512.avifdeleted file mode 100644index 9688f848..00000000Binary files a/public/previews/home/catwalk-512.avif and /dev/null differdiff --git a/public/previews/home/catwalk-640.avif b/public/previews/home/catwalk-640.avifnew file mode 100644index 00000000..54b7ffabBinary files /dev/null and b/public/previews/home/catwalk-640.avif differdiff --git a/public/previews/home/catwalk-640.mp4 b/public/previews/home/catwalk-640.mp4new file mode 100644index 00000000..ed21cad1Binary files /dev/null and b/public/previews/home/catwalk-640.mp4 differdiff --git a/public/previews/home/rotation-1024.avif b/public/previews/home/rotation-1024.avifnew file mode 100644index 00000000..ddb620faBinary files /dev/null and b/public/previews/home/rotation-1024.avif differdiff --git a/public/previews/home/rotation-1024.mp4 b/public/previews/home/rotation-1024.mp4new file mode 100644index 00000000..6ac93483Binary files /dev/null and b/public/previews/home/rotation-1024.mp4 differdiff --git a/public/previews/home/rotation-640.avif b/public/previews/home/rotation-640.avifnew file mode 100644index 00000000..5b583708Binary files /dev/null and b/public/previews/home/rotation-640.avif differdiff --git a/public/previews/home/rotation-640.mp4 b/public/previews/home/rotation-640.mp4new file mode 100644index 00000000..5bcad315Binary files /dev/null and b/public/previews/home/rotation-640.mp4 differdiff --git a/scripts/eval/lib/covers.mjs b/scripts/eval/lib/covers.mjsindex eb292643..514486c0 100644--- a/scripts/eval/lib/covers.mjs+++ b/scripts/eval/lib/covers.mjs@@ -22,15 +22,15 @@ export const MANIFEST_FILE = path.join(REPO_DIR, "src", "lib", "preset-previews./** Longest side of a cover still, and of a cover clip (px); a clip's first seconds, at CLIP_FPS. */const STILL_PX = 768;const CLIP_PX = 512;-const CLIP_SECONDS = 4;-const CLIP_FPS = 24;+export const CLIP_SECONDS = 4;+export const CLIP_FPS = 24;/*** Longest a clip that rests on its last frame keeps (s): a reveal is cut at its own end, not at CLIP_SECONDS. A clip* that keeps its whole length (`length: "full"`) is cut here too.*/const REST_CLIP_SECONDS = 8;/** Frames at a clip's end crossfaded into its first ones: the cards play clips with `loop`, and this hides the jump. */-const LOOP_FADE = 6;+export const LOOP_FADE = 6;/** Width of a poster's small copy (px), which the pickers' tiles show: enough for a 136 px tile on a 2x screen. */const THUMB_PX = 320;@@ -244,7 +244,7 @@ function run(args, input) {}/** A y4m stream (ffmpeg's yuv4mpegpipe, 4:2:0) as its header line and each frame's bytes. */-function readY4m(buf) {+export function readY4m(buf) {const nl = buf.indexOf(0x0a);const header = buf.subarray(0, Math.max(nl, 0)).toString("latin1");const w = Number(/ W(\d+)/.exec(header)?.[1]);diff --git a/scripts/gen-home-bento.mjs b/scripts/gen-home-bento.mjsindex bddeea0f..667b5318 100644--- a/scripts/gen-home-bento.mjs+++ b/scripts/gen-home-bento.mjs@@ -1,16 +1,28 @@#!/usr/bin/env node/**- * Stills and data for Home's first screen (src/components/home/home-bento.tsx): small AVIF copies of pictures the site- * already publishes, and the Audio tile's waveform, read from the Audio studio's own sample. Nothing is rendered: every- * picture is a resized copy of a published one, so the tiles show exactly what the studios show.+ * Media and data for Home's first screen (src/components/home/home-bento.tsx): its two clips and their posters in two+ * widths, AVIF copies of pictures the site already publishes, and the Audio tile's waveform, read from the Audio+ * studio's own sample. Nothing is rendered: every file is a copy of a published picture or of the full-size render a+ * published clip was cut from, so the tiles show exactly what the studios show, only sharper.*- * Output:- * public/previews/home/catwalk-512.avif the catwalk clip's poster (its first frame), the video tile's still- * public/previews/home/image-4-{480,768}.avif the Image studio's example 4- * public/previews/home/ba-{before,after}-{640,960}.avif Colorize's before and after (4:3)- * public/previews/home/ba-{before,after}-tall-{360,576}.avif the same pair, a 3:5 crop for the tall tile- * public/previews/home/board-{photo,film}.webp the Canvas board's photo and a frame of its film, 168 px squares- * src/lib/home-bento.generated.ts each file's content version, and the waveform+ * Output (public/previews/home/):+ * catwalk-{640,1024}.{mp4,avif} the catwalk clip at two widths, and its first frame as the video tile's poster+ * rotation-{640,1024}.{mp4,avif} the turning gown (the 3D tile), the same way+ * image-4-{480,768}.avif the Image studio's example 4+ * ba-{before,after}-{640,960,1280}.avif Colorize's before and after (4:3)+ * ba-{before,after}-tall-{432,691}.avif the same pair, a 3:5 crop for the tall tile+ * board-{photo,film}.webp the Canvas board's photo and a frame of its film, 168 px squares+ * and src/lib/home-bento.generated.ts: each file's content version, and the waveform.+ *+ * The clips: the published clip's own cut (scripts/eval/lib/covers.mjs: its first CLIP_SECONDS at CLIP_FPS, looped+ * the same way), made again from the full-size render instead of the 512 px copy, in H.264 High (a CRF per clip,+ * faststart, no sound). Each tile picks the width its box needs on the screen it is on (bento-islands.tsx).+ *+ * Masters: the full-size renders are not in the repo. With --masters <dir> (or FUOBE_HOME_MASTERS) the clips, their+ * posters and the before/after copies are made from the files in it:+ * <dir>/motion-catwalk.mp4, <dir>/app-3d-rotation.mp4 the renders the published clips were cut from+ * <dir>/app-colorize-before.png, <dir>/app-colorize-after.png Colorize's pair at full size (1536 x 1152)+ * Without it those files are kept as they are (and versioned); only the rest is made again.** The waveform: the Clean up voice sample decoded to 8 kHz mono, its loudness (RMS) in WAVE_BARS equal slices, scaled* so the loudest is 1, with a floor of WAVE_FLOOR so a pause still shows a bar. It is keyed by the sample's own@@ -22,16 +34,19 @@*/import { spawnSync } from "node:child_process";import fs from "node:fs";+import os from "node:os";import path from "node:path";import { fileURLToPath } from "node:url";import sharp from "sharp";-import { contentVersion } from "./eval/lib/covers.mjs";+import { CLIP_FPS, CLIP_SECONDS, LOOP_FADE, contentVersion, loopsAlready, readY4m, seamless } from "./eval/lib/covers.mjs";const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");const PUBLIC = path.join(ROOT, "public");const OUT_DIR = path.join(PUBLIC, "previews", "home");const OUT_TS = path.join(ROOT, "src", "lib", "home-bento.generated.ts");const DRY = process.argv.includes("--dry-run");+const argAt = process.argv.indexOf("--masters");+const MASTERS = argAt > 0 ? process.argv[argAt + 1] : process.env.FUOBE_HOME_MASTERS;export const WAVE_BARS = 48;export const WAVE_FLOOR = 0.12;@@ -41,9 +56,17 @@ const WAVE_SOURCE = "/samples/clean-voice/clean.m4a";const BA_APP = "app-colorize";/*** The before/after tile is wide on a phone and a tablet (the 4:3 pair) and tall from lg: there it takes a 3:5 crop of- * the 1280 pair around the subject, so it is never stretched past its own pixels and her face stays in the frame.+ * the full-size pair (1536 x 1152) around the subject, so it is never stretched past its own pixels and her face stays+ * in the frame.*/-const BA_TALL = { left: 352, top: 0, width: 576, height: 960 };+const BA_TALL = { left: 422, top: 0, width: 691, height: 1152 };+/** The two clips: their published preset, the name of their copies here, and the CRF each is encoded at. */+const CLIPS = [+ { key: "motion-catwalk", name: "catwalk", crf: 24 },+ { key: "app-3d-rotation", name: "rotation", crf: 23 },+];+/** The widths each clip and its poster are made at: a tile takes the first at least as wide as its box needs. */+const CLIP_WIDTHS = [640, 1024];/** The Canvas board's two pictures (src/lib/home-bento.ts, BENTO_BOARD): the photo going in and a frame of the film. */const BOARD_THUMBS = [{ name: "board-photo.webp", from: "/examples/effect-pearl-earring/1/in-image.jpg" },@@ -51,26 +74,56 @@ const BOARD_THUMBS = [];/** Each copy: its name under previews/home, the published file it comes from, its width, and a crop where it has one. */const STILLS = [- { name: "catwalk-512.avif", from: "/previews/presets/motion-catwalk.jpg", width: 512 },{ name: "image-4-480.avif", from: "/examples/image/4/out.jpg", width: 480 },{ name: "image-4-768.avif", from: "/examples/image/4/out.jpg", width: 768 },- ...["before", "after"].flatMap((side) => [- ...[640, 960].map((width) => ({ name: `ba-${side}-${width}.avif`, from: `/previews/presets/ba/1280/${BA_APP}-${side}.jpg`, width })),- ...[360, 576].map((width) => ({ name: `ba-${side}-tall-${width}.avif`, from: `/previews/presets/ba/1280/${BA_APP}-${side}.jpg`, width, crop: BA_TALL })),- ]),];-/** AVIF quality: the copies sit under a dark shade and are never shown larger than their own pixels. */+/** Copies made from a master (`master`: its file name in the masters folder). */+const MASTER_STILLS = ["before", "after"].flatMap((side) => [+ ...[640, 960, 1280].map((width) => ({ name: `ba-${side}-${width}.avif`, master: `${BA_APP}-${side}.png`, width })),+ ...[432, 691].map((width) => ({ name: `ba-${side}-tall-${width}.avif`, master: `${BA_APP}-${side}.png`, width, crop: BA_TALL })),+]);+/** AVIF quality: the copies sit under a dark shade, and each tile takes one at least as wide as it shows. */const QUALITY = 55;/** The board's pictures show at 36 to 56 px: a 168 px square covers them on a 3x screen. */const THUMB = 168;-const ffmpeg = (args) => {- const r = spawnSync(process.env.FUOBE_FFMPEG ?? "ffmpeg", args, { maxBuffer: 64 << 20 });+const ffmpeg = (args, input) => {+ const r = spawnSync(process.env.FUOBE_FFMPEG ?? "ffmpeg", args, { input, maxBuffer: 1 << 30 });if (r.error?.code === "ENOENT") throw new Error("gen-home-bento needs ffmpeg on PATH");if (r.status !== 0) throw new Error(`ffmpeg failed: ${String(r.stderr).trim().split("\n").at(-1)}`);return r.stdout;};+/**+ * A clip's loop at `width`, cut as covers.mjs encode() cuts the published one: decoded at CLIP_FPS, its first+ * CLIP_SECONDS (and the frames the crossfade takes back), looped without a seam unless it loops already. Returns the+ * y4m stream of it and of its first frame alone (the poster).+ */+function loopAt(src, width) {+ const seconds = CLIP_SECONDS + LOOP_FADE / CLIP_FPS;+ const y4m = ffmpeg(["-v", "error", "-i", src, "-t", String(seconds), "-an", "-sn", "-dn", "-vf", `scale=${width}:-2:flags=lanczos,fps=${CLIP_FPS},format=yuv420p`, "-f", "yuv4mpegpipe", "-"]);+ const { header, frames, luma } = readY4m(y4m);+ const cut = frames.slice(0, CLIP_SECONDS * CLIP_FPS);+ const looped = loopsAlready(cut, luma) ? cut : seamless(frames, Math.min(LOOP_FADE, Math.floor(frames.length / 4)));+ const stream = (list) => Buffer.concat([Buffer.from(`${header}\n`, "latin1"), ...list.flatMap((fr) => [Buffer.from("FRAME\n"), fr])]);+ return { all: stream(looped), first: stream([looped[0]]), frames: looped.length };+}++/** H.264 High, the published clip's loop, muted, its index at the front so it starts before it has all loaded. */+function encodeClipBuffer(y4m, crf) {+ const out = path.join(os.tmpdir(), `gen-home-bento-${process.pid}.mp4`);+ try {+ encodeClip(y4m, crf, out);+ return fs.readFileSync(out);+ } finally {+ fs.rmSync(out, { force: true });+ }+}++function encodeClip(y4m, crf, out) {+ ffmpeg(["-v", "error", "-y", "-f", "yuv4mpegpipe", "-i", "-", "-an", "-c:v", "libx264", "-profile:v", "high", "-preset", "slow", "-tune", "film", "-crf", String(crf), "-g", String(2 * CLIP_FPS), "-pix_fmt", "yuv420p", "-map_metadata", "-1", "-movflags", "+faststart", out], y4m);+}+/** The sample's loudness in `bars` slices, 0..1, the loudest 1, none under `floor`. */export function waveform(samples, bars = WAVE_BARS, floor = WAVE_FLOOR) {const per = Math.floor(samples.length / bars);@@ -91,8 +144,45 @@ function readWave() {async function main() {if (!DRY) fs.mkdirSync(OUT_DIR, { recursive: true });+ if (MASTERS && !fs.existsSync(MASTERS)) throw new Error(`no masters folder at ${MASTERS}`);+ const master = (name) => path.join(MASTERS, name);const versions = {};let total = 0;+ // Made from the masters when there are any; without them the files already here are kept (and versioned).+ const fromMasters = [+ ...CLIPS.flatMap((c) =>+ CLIP_WIDTHS.flatMap((w) => {+ let loop;+ const at = () => (loop ??= loopAt(master(`${c.key}.mp4`), w));+ const poster = () => ffmpeg(["-v", "error", "-f", "yuv4mpegpipe", "-i", "-", "-frames:v", "1", "-c:v", "png", "-f", "image2pipe", "-"], at().first);+ return [+ { name: `${c.name}-${w}.mp4`, clip: true, make: () => encodeClipBuffer(at().all, c.crf) },+ { name: `${c.name}-${w}.avif`, make: () => sharp(poster()).avif({ quality: QUALITY, effort: 6 }).toBuffer() },+ ];+ }),+ ),+ ...MASTER_STILLS.map((s) => ({+ ...s,+ make: () => {+ const img = sharp(master(s.master));+ return (s.crop ? img.extract(s.crop) : img).resize(s.width).avif({ quality: QUALITY, effort: 6 }).toBuffer();+ },+ })),+ ];+ for (const s of fromMasters) {+ const out = path.join(OUT_DIR, s.name);+ if (!MASTERS) {+ if (!fs.existsSync(out)) throw new Error(`${s.name} is made from the full-size renders: run with --masters <dir>`);+ console.log(`${s.name} kept (no --masters)`);+ } else {+ const buf = await s.make();+ if (!s.clip) total += buf.length;+ console.log(`${s.name} ${(buf.length / 1024).toFixed(1)} KB`);+ if (DRY) continue;+ if (!fs.existsSync(out) || !fs.readFileSync(out).equals(buf)) fs.writeFileSync(out, buf);+ }+ if (!DRY) versions[`/previews/home/${s.name}`] = contentVersion([out]);+ }const jobs = [...STILLS.map((s) => ({...s,@@ -114,7 +204,7 @@ async function main() {versions[`/previews/home/${s.name}`] = contentVersion([out]);}const { wave, seconds } = readWave();- console.log(`stills ${(total / 1024).toFixed(1)} KB · waveform ${wave.length} bars over ${seconds.toFixed(2)} s`);+ console.log(`stills ${(total / 1024).toFixed(1)} KB (clips aside) · waveform ${wave.length} bars over ${seconds.toFixed(2)} s`);if (DRY) return;const source = contentVersion([path.join(PUBLIC, WAVE_SOURCE)]);const body = `/**diff --git a/src/components/home/bento-islands.tsx b/src/components/home/bento-islands.tsxindex efa4acb0..79c835a6 100644--- a/src/components/home/bento-islands.tsx+++ b/src/components/home/bento-islands.tsx@@ -5,6 +5,7 @@ import { useEffect, useRef, useState, useSyncExternalStore } from "react";import { useNavUi } from "@/components/nav/nav-ui";import { usePreviewPlayback, usePreviewsPaused } from "@/components/preset-preview";import type { BentoPicture } from "@/lib/home-bento";+import { coverWidth, pickWidth, type Sized } from "@/lib/media-pick";import { releaseVideo } from "@/lib/media-release";import { browserPlaybackEnv } from "@/lib/preview-playback";import { s } from "./home-bento-classes";@@ -106,17 +107,32 @@ export function BentoMotion({ target }: { target: string }) {return null;}+/** The clips' shape (width / height): both tiles play 4:3 renders (scripts/gen-home-bento.mjs). */+const CLIP_ASPECT = 4 / 3;+/*** A tile's clip, over its still: it joins the site's playback rules (preset-preview.tsx) once the page has loaded, so* it plays in view, at most a few at once, never under reduced motion, Save-Data or Pause previews, and a hover or- * keyboard focus on its tile still plays it. Its source is set only when it first plays. Once started it stays mounted- * and pauses on its frame. `progress`: a line along the bottom follows the clip; `glyph`: a play sign until it plays.+ * keyboard focus on its tile still plays it. Its source is set only when it first plays: the narrowest of `clips` at+ * least as wide as the tile shows it on this screen (its box under `object-fit: cover`, times the pixel ratio), and+ * that one stays. Once started it stays mounted and pauses on its frame. `progress`: a line along the bottom follows+ * the clip; `glyph`: a play sign until it plays.*/-export function BentoClip({ id, clip, progress, glyph }: { id: string; clip: string; progress?: boolean; glyph?: boolean }) {+export function BentoClip({ id, clips, progress, glyph }: { id: string; clips: Sized[]; progress?: boolean; glyph?: boolean }) {const loaded = useLoaded();- const { ref, playing, handlers } = usePreviewPlayback<HTMLSpanElement>(id, loaded ? { video: clip } : {});- const [started, setStarted] = useState(false);- if (playing && !started) setStarted(true);+ const { ref, playing, handlers } = usePreviewPlayback<HTMLSpanElement>(id, loaded ? { video: clips[0].src } : {});+ // The pixels of width the tile needs, kept up to date with its size until the clip starts.+ const [need, setNeed] = useState(0);+ useEffect(() => {+ const el = ref.current;+ if (!el) return;+ const ro = new ResizeObserver(([e]) => setNeed(coverWidth(e.contentRect.width, e.contentRect.height, CLIP_ASPECT, window.devicePixelRatio || 1)));+ ro.observe(el);+ return () => ro.disconnect();+ }, [ref]);+ const [clip, setClip] = useState<string | null>(null);+ if (playing && !clip) setClip(pickWidth(clips, need).src);+ const started = clip !== null;const [ready, setReady] = useState(false);const video = useRef<HTMLVideoElement>(null);const bar = useRef<HTMLElement>(null);@@ -167,7 +183,7 @@ export function BentoClip({ id, clip, progress, glyph }: { id: string; clip: strreturn (<span ref={ref} aria-hidden className={s.clip} onPointerEnter={handlers.onPointerEnter} onPointerLeave={handlers.onPointerLeave}>- {started && <video ref={video} src={clip} muted loop playsInline preload="auto" data-ready={ready || undefined} onLoadedData={() => setReady(true)} />}+ {clip && <video ref={video} src={clip} muted loop playsInline preload="auto" data-ready={ready || undefined} onLoadedData={() => setReady(true)} />}{glyph && (<span className={s.playGlyph} data-on={(playing && ready) || undefined}><Play className="size-6" fill="#fff" stroke="#fff" />diff --git a/src/components/home/home-bento-classes.ts b/src/components/home/home-bento-classes.tsindex 1d135cee..aafd6abb 100644--- a/src/components/home/home-bento-classes.ts+++ b/src/components/home/home-bento-classes.ts@@ -3,6 +3,6 @@* stylesheet in this app is (next.config.ts runs each .css file through Tailwind as plain CSS), so the prefix keeps its* names to itself.*/-const NAMES = ["aside","audio","badge","before","bento","big","board","box","canvas","caret","clip","copy","corner","cta","edges","figures","fill","filmMark","foot","frame","grid","h1","head","image","kenburns","left","line1","line2","live","meta","node","nodeLabel","numbers","numbersFoot","numbersLine","out","pic","pill","playGlyph","playhead","progress","restore","right","shade","side","split","step","three","tile","title","tsx","typed","video","wave"] as const;+const NAMES = ["accent","aside","audio","badge","before","bento","big","board","box","canvas","caret","clip","copy","corner","cta","edges","figures","fill","filmMark","foot","frame","grid","h1","head","image","kenburns","l2b","left","line1","line2","live","meta","node","nodeLabel","numbers","numbersFoot","numbersLine","out","pic","pill","playGlyph","playhead","progress","restore","right","shade","side","split","step","three","tile","title","tsx","typed","video","wave"] as const;export const s = Object.fromEntries(NAMES.map((n) => [n, `hb-${n.replace(/[A-Z]/g, (c) => "-" + c.toLowerCase())}`])) as Record<(typeof NAMES)[number], string>;diff --git a/src/components/home/home-bento.css b/src/components/home/home-bento.cssindex 9453b4e9..fe8772da 100644--- a/src/components/home/home-bento.css+++ b/src/components/home/home-bento.css@@ -9,96 +9,207 @@* screen, the page has loaded and previews aren't paused; "0" once paused or scrolled away (the animations freeze where* they are). Without it (before load, reduced motion, Save-Data) every tile rests on its still frame.*- * Accent: every glow, line, caret, dot and edge is the theme's --primary.+ * Accent: every glow, line, caret, dot and edge in the grid is the theme's --primary; the headline's accent is its own.*/.hb-bento {--bento-gap: 12px;--bento-accent: var(--primary);--bento-glow: color-mix(in oklch, var(--primary) 30%, transparent);- --bento-head: 0px;- /* PageShell's top padding is 48 px from md: the grid starts 24 px under the bar, as the design does. */+ /*+ * The headline's two sizes (--l1 "Make anything:", --l2 the line under it): 68 / 28 px at 390, 112 / 42 at 768,+ * 150 / 54 at 1024 and 190 / 68 from 1280, in a straight line between those widths, so nothing jumps.+ */+ --l1: 17.44vw;+ --l2: 7.18vw;+ /* From the bar to "Make anything:", and from the headline to the grid. */+ --head-top: 28px;+ --head-gap: 20px;scroll-margin-top: 1rem;+ /*+ * PageShell's top padding (16 px; 48 px from md) is taken back, so the tops of the headline's letters sit --head-top+ * under the bar (they start 0.026 of the size into the line).+ */+ margin-top: calc(var(--head-top) - 1rem - var(--l1) * 0.026);+}+@media (min-width: 390px) {+ .hb-bento {+ --l1: calc(68px + (100vw - 390px) * 0.1164);+ --l2: calc(28px + (100vw - 390px) * 0.037);+ }}@media (min-width: 768px) {.hb-bento {- margin-top: -1.5rem;+ --l1: calc(112px + (100vw - 768px) * 0.1484);+ --l2: calc(42px + (100vw - 768px) * 0.0469);+ --head-top: 40px;+ --head-gap: 28px;+ margin-top: calc(var(--head-top) - 3rem - var(--l1) * 0.026);}}@media (min-width: 1024px) {.hb-bento {--bento-gap: 14px;- --bento-head: 6.5rem;+ /*+ * All eight tiles stay on the first screen, the grid at least --grid-min tall: on a short screen (under about 860+ * px of page) the headline gives way first, at the same proportions. --l1-room: the most "Make anything:" can be+ * for that, 1.33 being the headline's height in --l1 (both lines: see --bento-head, with --l2 at 0.358 of it).+ */+ --grid-min: 450px;+ --l1-room: calc((var(--content-h) - var(--grid-min) - 16px - var(--head-top) - var(--head-gap)) / 1.33);+ --l1: min(calc(150px + (100vw - 1024px) * 0.1563), var(--l1-room));+ --l2: calc(var(--l1) * 0.358);+ /* The headline's height (line 1's box, the gap under its descenders, line 2's box), which the grid takes off the screen's. */+ --bento-head: calc(var(--l1) * 0.986 + var(--l2) * 0.96 + var(--head-gap));+ }+}+@media (min-width: 1280px) {+ .hb-bento {+ --l1: min(190px, var(--l1-room));}}/* ---------------------------------------------------------------- headline */+/*+ * "Make anything:" at display size, set tight and a touch heavier than the face's one weight (a hairline stroke in its+ * own colour); the second line in italic under it, right-aligned to the grid's edge from 768, with only "finished+ * film," in the accent. Each line rises into place once as the page opens (transform and opacity only, from 40 %, so+ * the words are on the first paint), and the accent's glow fades in after; none of it under reduced motion.+ */.hb-head {- display: flex;- align-items: flex-end;- justify-content: space-between;- gap: 2rem;- margin-bottom: 16px;-}-@media (min-width: 768px) {- .hb-head {- margin-bottom: 20px;- }+ position: relative;+ margin-bottom: var(--head-gap);+ --ink-1: #0b0b0f;+ --ink-2: #0b0b0f;+ --ink-accent: #5b45e0;+ --ink-note: #6b6875;+}+.dark .hb-head {+ --ink-1: #fff;+ --ink-2: #f4f1ff;+ --ink-accent: #c9bfff;+ --ink-note: #8a8794;}.hb-h1 {+ margin: 0;font-family: var(--font-heading);font-weight: 400;- font-size: 30px;- line-height: 1.06;+ font-size: var(--l1);+ line-height: 0.86;+ letter-spacing: -0.035em;+ color: var(--ink-1);+}+.hb-line1,+.hb-line2 {+ display: block;+}+.hb-line1 {+ /* The M's stem on the grid's left edge (the face's side bearing, taken back). */+ margin-left: -0.04em;+ white-space: nowrap;+ -webkit-text-stroke: 0.008em currentColor;+}+/* Line 2 tucks in just under the descenders of "anything" (0.126 of line 1's size under its line), clear of them. */+.hb-line2 {+ margin-top: calc(var(--l1) * 0.126 + var(--l2) * 0.06);+ font-size: var(--l2);+ font-style: italic;+ line-height: 1.04;letter-spacing: -0.01em;- text-wrap: balance;- margin: 0;+ color: var(--ink-2);+}+/* A phone: two lines, the second starting at "finished". */+.hb-l2b {+ display: block;+}+.hb-accent {+ position: relative;+ color: var(--ink-accent);}-/* Two lines from md: "Make anything:" over the rest, which keeps to one line. */@media (min-width: 768px) {- .hb-h1 {- font-size: 40px;- line-height: 1.04;- }- .hb-line1,- .hb-line2 {- display: block;- }.hb-line2 {+ text-align: right;white-space: nowrap;+ line-height: 0.9;}-}-@media (min-width: 1024px) {- .hb-h1 {- font-size: 46px;+ .hb-l2b {+ display: inline;}}-@media (min-width: 1280px) {- .hb-h1 {- font-size: 50px;- }++/* The glow, on a layer of its own (the same words, see-through) so it can fade in on opacity alone. */+.dark .hb-accent::after {+ content: attr(data-glow) / "";+ position: absolute;+ inset: 0;+ white-space: nowrap;+ color: transparent;+ text-shadow: 0 0 40px rgb(185 173 255 / 0.22);+ pointer-events: none;+}++.hb-line1 {+ animation: hb-rise 700ms var(--ease-enter, cubic-bezier(0.08, 0.82, 0.17, 1)) both;}.hb-line2 {- font-style: italic;- color: color-mix(in oklch, var(--primary) 85%, var(--foreground));+ animation: hb-rise 900ms var(--ease-enter, cubic-bezier(0.08, 0.82, 0.17, 1)) 120ms both;+}+.dark .hb-accent::after {+ animation: hb-glow 1.2s ease 500ms both;+}+@keyframes hb-rise {+ from {+ opacity: 0.4;+ transform: translateY(0.12em);+ }+ to {+ opacity: 1;+ transform: none;+ }+}+@keyframes hb-glow {+ from {+ opacity: 0;+ }+ to {+ opacity: 1;+ }}-.dark .hb-line2 {- color: #b9adff;+@media (prefers-reduced-motion: reduce) {+ .hb-line1,+ .hb-line2,+ .dark .hb-accent::after {+ animation: none;+ }}++/*+ * The note under the headline: in the flow under the second line up to lg; from lg in the room right of+ * "Make anything:", its last line on that line's baseline, so it takes no height from the grid.+ */.hb-aside {- display: none;- max-width: 340px;- margin: 0 0 6px;- font-size: 14px;+ max-width: 300px;+ margin: 10px 0 0;+ font-size: 13px;line-height: 1.45;- text-align: right;- color: var(--muted-foreground);+ color: var(--ink-note);text-wrap: pretty;}-@media (min-width: 1280px) {+@media (min-width: 1024px) {.hb-aside {- display: block;+ position: absolute;+ top: 0;+ right: 0;+ /* Down to line 1's baseline (0.768 of its size under the top of its line), and the note's own descent. */+ height: calc(var(--l1) * 0.768 + 5px);+ width: min(300px, calc(100% - var(--l1) * 4.86 - 32px));+ max-width: none;+ margin: 0;+ display: flex;+ flex-direction: column;+ justify-content: flex-end;+ font-size: 14px;}}@@ -149,7 +260,7 @@.hb-grid {grid-template-columns: repeat(4, minmax(0, 1fr));grid-template-rows: repeat(3, minmax(0, 1fr));- height: clamp(520px, calc(var(--content-h) - var(--bento-head) - 6.5rem), 760px);+ height: clamp(var(--grid-min), calc(var(--content-h) - var(--bento-head) - var(--head-top) - 3.25rem), 760px);grid-template-areas:"video video image audio""video video three restore"diff --git a/src/components/home/home-bento.tsx b/src/components/home/home-bento.tsxindex 9d7a0b78..77bfeb4f 100644--- a/src/components/home/home-bento.tsx+++ b/src/components/home/home-bento.tsx@@ -7,12 +7,16 @@ import { cn } from "@/lib/utils";import { s } from "./home-bento-classes";import "./home-bento.css";-/** How wide each tile's picture shows, per width (the grid's columns: home-bento.css). */+/**+ * How wide each tile's picture shows, per width (the grid's columns: home-bento.css): under object-fit: cover, the+ * tile's width or, where the tile is the squarer shape, its height times 4/3, so the browser picks a copy that sharp.+ */const SIZES = {- video: "(min-width: 1024px) 562px, (min-width: 768px) 466px, 100vw",- square: "(min-width: 1024px) 274px, (min-width: 768px) 227px, 50vw",+ video: "(min-width: 1024px) 572px, (min-width: 768px) 576px, calc(100vw - 32px)",+ /** A 4:3 picture in a square tile on a phone (half the row): cropped at its sides, so 4/3 of the tile's width. */+ square: "(min-width: 1024px) 290px, (min-width: 768px) 280px, calc((100vw - 44px) * 0.667)",/** The before/after tile: wide (its 4:3 pair) below lg; from lg it is tall and takes the pair's 3:5 crop (`tall`). */- wide: "(min-width: 768px) 466px, 100vw",+ wide: "(min-width: 768px) 476px, calc(100vw - 32px)",tall: "290px",};/** From lg the before/after tile is tall (home-bento.css). */@@ -150,8 +154,18 @@ export function HomeBento({ bento }: { bento: Bento }) {return (<section id="home-bento" aria-labelledby="home-bento-title" className={s.bento}><div className={s.head}>+ {/* No-break spaces keep "finished film," and "one place." whole when the line wraps. */}<h1 id="home-bento-title" className={s.h1}>- <span className={s.line1}>Make anything:</span> <span className={s.line2}>From an idea to a finished film, in one place.</span>+ <span className={s.line1}>Make anything:</span>{" "}+ <span className={s.line2}>+ From an idea to a{" "}+ <span className={s.l2b}>+ <span className={s.accent} data-glow={"finished film,"}>+ finished film,+ </span>{" "}+ in one place.+ </span>+ </span></h1><p className={s.aside}>Film, stills, sound, 3D, live edits and whole pipelines. Each tile opens the studio that makes it.</p></div>@@ -159,7 +173,7 @@ export function HomeBento({ bento }: { bento: Bento }) {<div className={s.grid}><Tile tile={tiles.video} area={s.video} bigMeta><Pic pic={bento.video.poster} sizes={SIZES.video} fetchPriority="high" />- <BentoClip id={bento.video.id} clip={bento.video.clip} progress glyph />+ <BentoClip id={bento.video.id} clips={bento.video.clips} progress glyph /><span aria-hidden className={s.badge}><Video className="size-3.5" /> Video</span>@@ -179,9 +193,8 @@ export function HomeBento({ bento }: { bento: Bento }) {</Tile><Tile tile={tiles.threeD} area={s.three}>- {/* eslint-disable-next-line @next/next/no-img-element */}- <img src={bento.threeD.poster} alt="" width={512} height={384} loading="eager" fetchPriority="low" decoding="async" draggable={false} className={s.fill} />- <BentoClip id={bento.threeD.id} clip={bento.threeD.clip} />+ <Pic pic={bento.threeD.poster} sizes={SIZES.square} fetchPriority="low" />+ <BentoClip id={bento.threeD.id} clips={bento.threeD.clips} /></Tile><Tile tile={tiles.restore} area={s.restore}>diff --git a/src/lib/home-bento.generated.ts b/src/lib/home-bento.generated.tsindex c7a2a8d0..a612bfac 100644--- a/src/lib/home-bento.generated.ts+++ b/src/lib/home-bento.generated.ts@@ -4,17 +4,26 @@* scripts/gen-home-bento.mjs: run it again rather than editing.*/export const HOME_BENTO_MEDIA: Record<string, string> = {- "/previews/home/catwalk-512.avif": "35a5ee32",+ "/previews/home/catwalk-640.mp4": "2c1048b0",+ "/previews/home/catwalk-640.avif": "1e1ef41f",+ "/previews/home/catwalk-1024.mp4": "0ef4a570",+ "/previews/home/catwalk-1024.avif": "939dab0d",+ "/previews/home/rotation-640.mp4": "090f1205",+ "/previews/home/rotation-640.avif": "a527ea80",+ "/previews/home/rotation-1024.mp4": "769fa634",+ "/previews/home/rotation-1024.avif": "cc93fd0a",+ "/previews/home/ba-before-640.avif": "8adbdbd7",+ "/previews/home/ba-before-960.avif": "7f7f2735",+ "/previews/home/ba-before-1280.avif": "7b757bc9",+ "/previews/home/ba-before-tall-432.avif": "af0e8f74",+ "/previews/home/ba-before-tall-691.avif": "aaafef5d",+ "/previews/home/ba-after-640.avif": "4ad38a6c",+ "/previews/home/ba-after-960.avif": "670dbb52",+ "/previews/home/ba-after-1280.avif": "61952772",+ "/previews/home/ba-after-tall-432.avif": "71f125b7",+ "/previews/home/ba-after-tall-691.avif": "46271396","/previews/home/image-4-480.avif": "5a6d07a1","/previews/home/image-4-768.avif": "ef9d1b4d",- "/previews/home/ba-before-640.avif": "2c0698c9",- "/previews/home/ba-before-960.avif": "68bab1a7",- "/previews/home/ba-before-tall-360.avif": "8def3f0c",- "/previews/home/ba-before-tall-576.avif": "8e2686ce",- "/previews/home/ba-after-640.avif": "85e66bec",- "/previews/home/ba-after-960.avif": "9b17b907",- "/previews/home/ba-after-tall-360.avif": "403e1563",- "/previews/home/ba-after-tall-576.avif": "29994802","/previews/home/board-photo.webp": "47432641","/previews/home/board-film.webp": "db007869"};diff --git a/src/lib/home-bento.ts b/src/lib/home-bento.tsindex 7e7dcc8c..d517322c 100644--- a/src/lib/home-bento.ts+++ b/src/lib/home-bento.ts@@ -19,6 +19,9 @@ import { templateCover } from "@/lib/template-covers";/** The preset whose clip each moving tile plays (no other card on Home plays these: tests/home-showcase.test.ts). */export const BENTO_CLIPS = { video: "motion-catwalk", threeD: "app-3d-rotation" } as const;+/** Each clip's copies here (scripts/gen-home-bento.mjs): its name, and the widths it and its poster come in. */+export const BENTO_CLIP_FILES = { video: "catwalk", threeD: "rotation" } as const;+export const BENTO_CLIP_WIDTHS = [640, 1024] as const;/** The Image studio's example the image tile shows and opens with (src/lib/examples/plan.json). */export const BENTO_IMAGE_EXAMPLE = { id: "image.4", out: "/examples/image/4/out.jpg" };/** The app the before/after tile shows and opens: black and white to colour reads at a glance. */@@ -43,7 +46,7 @@ export const BENTO_HREFS = {export type BentoKey = keyof typeof BENTO_HREFS;/**- * A picture in two widths: AVIF for the browsers that take it, the published JPEG for the rest. `tall`: a portrait+ * A picture in two or three widths: AVIF for the browsers that take it, the published JPEG for the rest. `tall`: a portrait* crop of it for a tile that is tall from lg (home-bento.tsx), so the picture is never stretched past its own pixels.*/export interface BentoPicture {@@ -52,6 +55,13 @@ export interface BentoPicture {tall?: { src: string; w: number }[];}+/** A tile's clip: its id in the playback store, its poster, and the clip in each width (the tile picks one). */+export interface BentoMovingTile {+ id: string;+ poster: BentoPicture;+ clips: { src: string; w: number }[];+}+export interface BentoTile {key: BentoKey;/** The small line over the title: what kind of media, and how much of it. */@@ -153,10 +163,20 @@ export async function homeBento(f: BentoFacts) {return { avif: [{ src: fr.small, w: 512 }, { src: fr.mid, w: 768 }], fallback: fr.webp } satisfies BentoPicture;};const restoreSide = (side: "before" | "after"): BentoPicture => ({- avif: [640, 960].map((w) => ({ src: made(`/previews/home/ba-${side}-${w}.avif`), w })),- tall: [360, 576].map((w) => ({ src: made(`/previews/home/ba-${side}-tall-${w}.avif`), w })),+ avif: [640, 960, 1280].map((w) => ({ src: made(`/previews/home/ba-${side}-${w}.avif`), w })),+ tall: [432, 691].map((w) => ({ src: made(`/previews/home/ba-${side}-tall-${w}.avif`), w })),fallback: `/previews/presets/ba/960/${BENTO_BEFORE_AFTER}-${side}.jpg?v=${baV}`,});+ // A moving tile: its poster (the clip's first frame) and its clip, each in every width; the published JPEG poster is+ // the fallback for a browser without AVIF.+ const moving = (key: keyof typeof BENTO_CLIPS, fallback: string): BentoMovingTile => {+ const name = BENTO_CLIP_FILES[key];+ return {+ id: BENTO_CLIPS[key],+ poster: { avif: BENTO_CLIP_WIDTHS.map((w) => ({ src: made(`/previews/home/${name}-${w}.avif`), w })), fallback },+ clips: BENTO_CLIP_WIDTHS.map((w) => ({ src: made(`/previews/home/${name}-${w}.mp4`), w })),+ };+ };const tile = (key: BentoKey, kind: string, meta: string, title: string, cta: string): BentoTile => ({key,meta,@@ -181,12 +201,12 @@ export async function homeBento(f: BentoFacts) {live: tile("live", "Live edit", "Live edit", "Type it, watch it change", "Open Live edit"),canvas: tile("canvas", "Canvas", "Canvas", "Chain any step, end to end", "Open Canvas"),},- video: { id: BENTO_CLIPS.video, poster: { avif: [{ src: made("/previews/home/catwalk-512.avif"), w: 512 }], fallback: video.poster } satisfies BentoPicture, clip: video.video },+ video: moving("video", video.poster),image: {avif: [480, 768].map((w) => ({ src: made(`/previews/home/image-4-${w}.avif`), w })),fallback: example(BENTO_IMAGE_EXAMPLE.out),} satisfies BentoPicture,- threeD: { id: BENTO_CLIPS.threeD, poster: threeD.poster, clip: threeD.video },+ threeD: moving("threeD", threeD.poster),restore: { before: restoreSide("before"), after: restoreSide("after") },wave: { bars: HOME_BENTO_WAVE.bars, seconds: HOME_BENTO_WAVE.seconds },live: { frames: BENTO_LIVE_STEPS.map(frame), phrases: livePhrases(demo) },diff --git a/src/lib/media-pick.ts b/src/lib/media-pick.tsnew file mode 100644index 00000000..6436b926--- /dev/null+++ b/src/lib/media-pick.ts@@ -0,0 +1,25 @@+/**+ * Which copy of a picture or clip a box needs, for the media that come in several widths (Home's first screen,+ * src/components/home/bento-islands.tsx). A `<picture>`'s srcset lets the browser choose; a `<video>` has no srcset,+ * so its tile chooses with these.+ */++/** One copy of a picture or clip, and its width in pixels. */+export interface Sized {+ src: string;+ w: number;+}++/**+ * The device pixels of width a box asks of media `aspect` (width / height) wide when it covers the box+ * (`object-fit: cover`): the box's width, or more when the box is the taller shape and the media is cropped at its sides.+ */+export function coverWidth(boxW: number, boxH: number, aspect: number, dpr: number): number {+ return Math.ceil(Math.max(boxW, boxH * aspect) * dpr);+}++/** The narrowest copy at least `need` pixels wide, or the widest there is (a copy is never shown past its own size). */+export function pickWidth<T extends Sized>(copies: readonly T[], need: number): T {+ const byWidth = [...copies].sort((a, b) => a.w - b.w);+ return byWidth.find((c) => c.w >= need) ?? byWidth[byWidth.length - 1];+}diff --git a/tests/e2e/home-bento.mjs b/tests/e2e/home-bento.mjsindex 67e4f6a1..7644aed7 100644--- a/tests/e2e/home-bento.mjs+++ b/tests/e2e/home-bento.mjs@@ -7,16 +7,20 @@// --weight-only: only measure what the first screen downloads (to compare another build, such as main's).//// 1. Every width (390, 768, 1024, 1280, 1440, 1920), light and dark, as a guest and as the owner: no sideways scroll,-// one h1, the headline (two lines from 768, its second line whole), and the first screen holds what it should-// (a phone: the video tile and the three under it; from 1024: all eight). A picture of each (--shots), and a contact-// sheet of them all.+// one h1, the headline in its own words ("Make anything:" on one line; the second line whole from 768, and on a+// phone two lines that break before "finished film,"), it rose into place once, and the first screen holds what it+// should (a phone: the video tile and the two under it; from 1024: all eight). A picture of each (--shots), and a+// contact sheet of them all.+// 1b. Sharp at every width and pixel ratio (1x, 2x, 3x): every picture on the first screen is at least as wide as its+// box shows it (object-fit: cover, times the ratio), up to the widest copy there is, and so is each clip once it+// plays.// 2. Layout shift under 0.01 at 390 and 1440, through a load and a scroll to the bottom and back.// 3. Every tile's link answers 200, and the numbers tile opens every studio (the launcher; a phone's sheet).-// 4. Reduced motion and Save-Data: no clip is fetched or played, nothing moves by itself (the split rests at 50 %, the-// live words stay), and the tiles keep their stills.+// 4. Reduced motion and Save-Data: no clip is fetched or played, nothing moves by itself (the headline is still, the+// split rests at 50 %, the live words stay), and the tiles keep their stills.// 5. Pause previews stops the catwalk and freezes every animation; pressed again, they go on.// 6. Weight: what the page downloads before `load` (clips aside), at 390 and 1440, reported; the first screen's own-// stills stay under 280 KB.+// stills stay under 300 KB. The clips it fetches after load are reported on their own.// 7. The composer: /?new=1 brings it into view with the focus; a plain visit stays at the top (no autofocus jump).// 8. Every tile is a named link, and Tab reaches them in the grid's reading order with a visible ring.import assert from "node:assert/strict";@@ -84,15 +88,27 @@ const layout = (page) =>return { top: r.top, bottom: r.bottom, left: r.left, right: r.right, w: r.width, h: r.height };};const h1 = document.querySelector("#home-bento h1");- const line2 = h1.querySelector("span:last-child");- const lh = parseFloat(getComputedStyle(h1).lineHeight);+ const [line1, line2] = h1.querySelectorAll(":scope > span");+ // The lines a span's words fall on: its text's boxes, grouped by their top.+ const lines = (el) => {+ const r = document.createRange();+ r.selectNodeContents(el);+ const tops = [];+ for (const b of r.getClientRects()) if (b.width > 0 && !tops.some((t) => Math.abs(t - b.top) < b.height / 2)) tops.push(b.top);+ return tops.length;+ };+ const accent = line2.querySelector("[data-glow]");+ const rise = (el) =>+ el.getAnimations().map((a) => ({ name: a.animationName, state: a.playState, ms: a.effect.getTiming().duration, delay: a.effect.getTiming().delay, from: a.effect.getKeyframes()[0]?.opacity }));return {h1s: document.querySelectorAll("h1").length,text: h1.textContent.replace(/\s+/g, " ").trim(),- h1Lines: Math.round(h1.getBoundingClientRect().height / lh),- line2Lines: Math.round(line2.getBoundingClientRect().height / lh),+ line1Lines: lines(line1),+ line2Lines: lines(line2),line2Italic: getComputedStyle(line2).fontStyle,- line2Color: getComputedStyle(line2).color,+ // On a phone the second line breaks before "finished film,": the accent starts its own line, at the left.+ accentStartsLine: Math.abs(accent.getClientRects()[0].left - line2.getBoundingClientRect().left) < 2,+ rise: { line1: rise(line1), line2: rise(line2) },scroll: [document.documentElement.scrollWidth, document.documentElement.clientWidth],vh: innerHeight,tiles: Object.fromEntries(tiles.map((t) => [t, box(document.querySelector(`#home-bento [data-tile="${t}"]`))])),@@ -100,8 +116,51 @@ const layout = (page) =>};}, TILES);+/**+ * Each picture and playing clip on the first screen against what its box needs: the box under object-fit: cover (its+ * width, or its height times the picture's shape when that is more), times the pixel ratio, up to the widest copy the+ * page offers for it.+ */+const sharpness = (page) =>+ page.evaluate(() => {+ const dpr = devicePixelRatio;+ // The copies the browser could choose from for an img: its <picture>'s matching source, or its own srcset, each as+ // its URL and its width. (naturalWidth is no help here: under a w-descriptor it is scaled by the pixel ratio.)+ const copies = (img) => {+ const pic = img.closest("picture");+ const srcset = (pic ? [...pic.querySelectorAll("source")].find((s) => !s.media || matchMedia(s.media).matches)?.srcset : undefined) ?? img.srcset ?? "";+ return srcset+ .split(",")+ .map((c) => /^(\S+)\s+(\d+)w$/.exec(c.trim()))+ .filter(Boolean)+ .map((m) => ({ url: new URL(m[1], location.href).href, w: Number(m[2]) }));+ };+ const out = [];+ for (const img of document.querySelectorAll("#home-bento [data-tile] img")) {+ const r = img.getBoundingClientRect();+ if (!img.complete || !img.naturalWidth || r.width < 2) continue;+ const list = copies(img);+ const chosen = list.find((c) => c.url === img.currentSrc);+ const has = chosen?.w ?? img.naturalWidth;+ const ratio = img.naturalWidth / img.naturalHeight;+ const need = Math.ceil(Math.max(r.width, r.height * ratio) * dpr);+ const max = list.length ? Math.max(...list.map((c) => c.w)) : has;+ const what = new URL(img.currentSrc || img.src).pathname.split("/").pop();+ out.push({ what, tile: img.closest("[data-tile]").dataset.tile, has, need, max, ok: has >= Math.min(need, max) * 0.98 });+ }+ for (const v of document.querySelectorAll("#home-bento [data-tile] video")) {+ if (!v.videoWidth) continue;+ const r = v.getBoundingClientRect();+ const need = Math.ceil(Math.max(r.width, (r.height * v.videoWidth) / v.videoHeight) * dpr);+ const what = new URL(v.currentSrc).pathname.split("/").pop();+ out.push({ what, tile: v.closest("[data-tile]").dataset.tile, has: v.videoWidth, need, max: 1024, ok: v.videoWidth >= Math.min(need, 1024) * 0.98 });+ }+ return out;+ });+// ------------------------------------------------------------------------------------------- 1. every widthconst shots = [];+const sharpNotes = [];if (!weightOnly)for (const who of ["guest", "owner"]) {for (const scheme of ["light", "dark"]) {@@ -119,12 +178,20 @@ if (!weightOnly)check(`${tag}: no sideways scroll`, l.scroll[0] === l.scroll[1], l.scroll.join(" vs "));check(`${tag}: one h1, the headline`, l.h1s === 1 && l.text === HEADLINE, `${l.h1s} · ${l.text}`);check(`${tag}: theme`, l.dark === (scheme === "dark"));- if (v.w >= 768) check(`${tag}: headline on two lines, the second whole and italic`, l.h1Lines === 2 && l.line2Lines === 1 && l.line2Italic === "italic", `${l.h1Lines}/${l.line2Lines}`);+ check(`${tag}: "Make anything:" on one line, the second line in italic`, l.line1Lines === 1 && l.line2Italic === "italic", String(l.line1Lines));+ if (v.w >= 768) check(`${tag}: the second line whole`, l.line2Lines === 1, String(l.line2Lines));+ else check(`${tag}: the second line on two, the second starting at "finished film,"`, l.line2Lines === 2 && l.accentStartsLine, `${l.line2Lines} ${l.accentStartsLine}`);+ const [r1, r2] = [l.rise.line1[0], l.rise.line2[0]];+ check(+ `${tag}: the headline rose once, from 40 % (its words on the first paint)`,+ r1?.name === "hb-rise" && r1.ms === 700 && r2?.ms === 900 && r2.delay === 120 && [r1, r2].every((r) => r.state === "finished" && Number(r.from) === 0.4),+ JSON.stringify(l.rise),+ );if (v.phone) {const bottom = l.vh - 64;- const first = ["video", "image", "threeD", "restore"];+ const first = ["video", "image", "threeD"];const out = first.filter((t) => l.tiles[t].top < 0 || l.tiles[t].bottom > bottom);- check(`${tag}: the video tile and three more on the first screen`, out.length === 0, first.map((t) => `${t} ${Math.round(l.tiles[t].bottom)}`).join(", ") + ` ≤ ${bottom}`);+ check(`${tag}: the video tile and the two under it on the first screen`, out.length === 0, first.map((t) => `${t} ${Math.round(l.tiles[t].bottom)}`).join(", ") + ` ≤ ${bottom}`);check(`${tag}: every tile at least 44 px to tap`, TILES.every((t) => l.tiles[t].w >= 44 && l.tiles[t].h >= 44));}if (v.w >= 1024) {@@ -141,6 +208,30 @@ if (!weightOnly)}}+// ------------------------------------------------------------------------------------------- 1b. sharp at every ratio+if (!weightOnly)+ for (const v of WIDTHS)+ for (const dpr of [1, 2, 3]) {+ const ctx = await browser.newContext({ ...(v.phone ? PHONE : {}), viewport: { width: v.w, height: v.h }, deviceScaleFactor: dpr });+ const page = await ctx.newPage();+ await open(page);+ // The clips start after load, once on screen: wait until each has its first frame.+ await page+ .waitForFunction(() => [...document.querySelectorAll("#home-bento [data-tile] video")].filter((x) => x.videoWidth > 0).length >= 2, null, { timeout: 12_000 })+ .catch(() => {});+ await page.waitForTimeout(300);+ const s = await sharpness(page);+ const bad = s.filter((x) => !x.ok);+ const clips = s.filter((x) => x.what.endsWith(".mp4"));+ check(+ `sharp at ${v.w}@${dpr}x: ${s.length} pictures and clips at least their box x ratio`,+ bad.length === 0 && clips.length === 2,+ (bad.length ? bad : clips).map((x) => `${x.tile} ${x.what} ${x.has} for ${x.need} (max ${x.max})`).join("; "),+ );+ sharpNotes.push(`${v.w}@${dpr}x: ${s.map((x) => `${x.tile} ${x.what} ${x.has}/${x.need}`).join(", ")}`);+ await ctx.close();+ }+// ------------------------------------------------------------------------------------------- 2. layout shiftasync function cls(v) {const ctx = await browser.newContext(viewportOpts(v));@@ -224,8 +315,9 @@ if (!weightOnly) {play: document.getElementById("home-bento").dataset.play ?? null,videos: [...document.querySelectorAll("#home-bento video")].filter((v) => v.getAttribute("src") && !v.paused).length,split: getComputedStyle(document.querySelector("#home-bento [data-tile=restore] picture:nth-of-type(2) img")).clipPath,+ headline: document.querySelector("#home-bento h1").parentElement.getAnimations({ subtree: true }).length,}));- check("reduced motion: nothing moves by itself", state.play === null && state.videos === 0 && clips.length === 0, JSON.stringify({ ...state, clips: clips.length }));+ check("reduced motion: nothing moves by itself", state.play === null && state.videos === 0 && clips.length === 0 && state.headline === 0, JSON.stringify({ ...state, clips: clips.length }));check("reduced motion: the split rests at 50 %", /inset\(0(px)? 50%/.test(state.split), state.split);check("reduced motion: the live words stay", a === b, `${JSON.stringify(a)} / ${JSON.stringify(b)}`);await ctx.close();@@ -291,7 +383,13 @@ async function weight(v) {await cdp.send("Network.setCacheDisabled", { cacheDisabled: true });const reqs = new Map();let loaded = false;+ // The clips come after load: every byte of a video response, counted as it arrives (a clip may come in ranges).+ const clips = new Map();cdp.on("Network.responseReceived", (e) => reqs.set(e.requestId, { url: e.response.url, type: e.type, mime: e.response.mimeType, bytes: 0, done: false }));+ cdp.on("Network.dataReceived", (e) => {+ const r = reqs.get(e.requestId);+ if (r?.mime.startsWith("video/")) clips.set(r.url, (clips.get(r.url) ?? 0) + e.encodedDataLength);+ });cdp.on("Network.loadingFinished", (e) => {const r = reqs.get(e.requestId);if (r && !loaded) Object.assign(r, { bytes: e.encodedDataLength, done: true });@@ -299,12 +397,24 @@ async function weight(v) {await page.goto(app + "/", { waitUntil: "load", timeout: 90_000 });loaded = true;await page.waitForTimeout(300);+ // The first screen's own pictures: the tiles' stills (anything else is the page's, below it).+ const ownUrls = new Set(await page.evaluate(() => [...document.querySelectorAll("#home-bento img")].map((i) => new URL(i.currentSrc || i.src, location.href).pathname)));+ // Then the clips, until both tiles have theirs whole (or 15 s).+ await page+ .waitForFunction(+ () => {+ const v = [...document.querySelectorAll("#home-bento [data-tile] video")];+ return v.length >= 2 && v.every((x) => x.readyState >= 4 && x.buffered.length > 0 && x.buffered.end(0) >= x.duration - 0.05);+ },+ null,+ { timeout: 15_000 },+ )+ .catch(() => {});+ await page.waitForTimeout(500);const by = {};let total = 0;let own = 0;const media = [];- // The first screen's own pictures: the tiles' stills (anything else is the page's, below it).- const ownUrls = new Set(await page.evaluate(() => [...document.querySelectorAll("#home-bento img")].map((i) => new URL(i.currentSrc || i.src, location.href).pathname)));for (const r of reqs.values()) {if (!r.done || r.mime.startsWith("video/")) continue;const kind = r.type === "Document" ? "html" : r.type === "Stylesheet" ? "css" : r.type === "Script" ? "js" : r.type === "Font" ? "fonts" : r.type === "Image" ? "images" : "other";@@ -318,13 +428,21 @@ async function weight(v) {}await ctx.close();const kb = (n) => `${(n / 1024).toFixed(0)} KB`;- return { total, own, line: `${v.w}@${viewportOpts(v).deviceScaleFactor}x: ${kb(total)} (${Object.entries(by).map(([k, n]) => `${k} ${kb(n)}`).join(", ")}); the first screen's own stills ${kb(own)}`, media };+ const clipBytes = [...clips.values()].reduce((a, b) => a + b, 0);+ const clipLine = [...clips].map(([u, n]) => `${new URL(u).pathname.split("/").pop()} ${kb(n)}`).join(" · ");+ return {+ total,+ own,+ clipBytes,+ line: `${v.w}@${viewportOpts(v).deviceScaleFactor}x: ${kb(total)} (${Object.entries(by).map(([k, n]) => `${k} ${kb(n)}`).join(", ")}); the first screen's own stills ${kb(own)}; clips after load ${kb(clipBytes)} (${clipLine || "none"})`,+ media,+ };}-for (const v of [WIDTHS[0], WIDTHS[4]]) {+for (const v of [WIDTHS[0], WIDTHS[3], WIDTHS[4], WIDTHS[5]]) {const r = await weight(v);// The whole page's total is reported (main's own script and fonts are most of it: compare with --weight-only on// main's build); the first screen's own stills have a budget of their own.- check(`weight before load, clips aside: ${r.line}`, weightOnly || r.own < 280 * 1024);+ check(`weight before load, clips aside: ${r.line}`, weightOnly || r.own < 300 * 1024);notes.push(`weight ${r.line}`);notes.push(` first screen's stills: ${r.media.join(" · ")}`);}@@ -402,7 +520,7 @@ if (shotsDir && shots.length) {console.log(`contact sheet: ${path.join(shotsDir, "contact-sheet.jpg")}`);}-console.log("\n" + notes.join("\n"));+console.log("\n" + [...notes, ...sharpNotes.map((n) => `sharp ${n}`)].join("\n"));if (failures.length) {console.log(`\n${failures.length} failed:\n- ${failures.join("\n- ")}`);process.exit(1);diff --git a/tests/helpers/mp4-length.ts b/tests/helpers/mp4-length.tsindex 28942b61..f2f377f0 100644--- a/tests/helpers/mp4-length.ts+++ b/tests/helpers/mp4-length.ts@@ -10,3 +10,11 @@ export function mp4Seconds(file: string): number {const length = v1 ? Number(buf.readBigUInt64BE(at + 28)) : buf.readUInt32BE(at + 20);return length / scale;}++/** An MP4's first track's picture size in pixels, from its track header box (tkhd, version 0). */+export function mp4Size(file: string): { w: number; h: number } {+ const buf = fs.readFileSync(file);+ const at = buf.indexOf("tkhd");+ if (at < 0 || buf[at + 4] !== 0) throw new Error(`${file} has no version 0 track header`);+ return { w: buf.readUInt32BE(at + 80) >>> 16, h: buf.readUInt32BE(at + 84) >>> 16 };+}diff --git a/tests/home-bento.test.ts b/tests/home-bento.test.tsindex ab6ba5c7..931ff713 100644--- a/tests/home-bento.test.ts+++ b/tests/home-bento.test.ts@@ -12,7 +12,10 @@ import { HUB_MODES } from "@/lib/hubs";import { studioCount } from "@/lib/nav-model";import { HOME_BENTO_MEDIA, HOME_BENTO_WAVE } from "@/lib/home-bento.generated";import { contentVersion } from "../scripts/eval/lib/covers.mjs";-import { mp4Seconds } from "./helpers/mp4-length";+import sharp from "sharp";+import type { BentoPicture } from "@/lib/home-bento";+import { coverWidth, pickWidth } from "@/lib/media-pick";+import { mp4Seconds, mp4Size } from "./helpers/mp4-length";/** Home's first screen (src/components/home/home-bento.tsx, src/lib/home-bento.ts): every tile's media is a published@@ -27,7 +30,7 @@ vi.mock("next/navigation", () => ({useSearchParams: () => new URLSearchParams(),}));-const { BENTO_BOARD, BENTO_CLIPS, BENTO_HREFS, BENTO_BEFORE_AFTER, BENTO_IMAGE_EXAMPLE, livePhrases, openModelsOf } = await import("@/lib/home-bento");+const { BENTO_BOARD, BENTO_CLIPS, BENTO_CLIP_WIDTHS, BENTO_HREFS, BENTO_BEFORE_AFTER, BENTO_IMAGE_EXAMPLE, livePhrases, openModelsOf } = await import("@/lib/home-bento");const { HOME_BEFORE_AFTER, HOME_EFFECTS, HOME_MOTIONS, HOME_REVEALS, HOME_STUDIOS, homeShowcase, navLabel } = await import("@/lib/home-showcase");const { HomeBento } = await import("@/components/home/home-bento");@@ -54,15 +57,65 @@ describe("Home's first screen", () => {expect(contentVersion([file(f)]), f).toBe(v);expect(urls).toContain(`${f}?v=${v}`);}+ // Nothing else is left in its folder: a copy no longer listed goes with the list.+ const folder = path.join(process.cwd(), "public", "previews", "home");+ expect(fs.readdirSync(folder).map((n) => `/previews/home/${n}`).sort()).toEqual(Object.keys(HOME_BENTO_MEDIA).sort());// And the page's HTML asks for them as listed (no URL without its version).for (const m of html.matchAll(/(?:src|srcSet)="([^"]+)"/g)) for (const part of m[1].split(", ")) expect(part.split(" ")[0], part).toMatch(versioned);});- it("plays the catwalk and the turning gown, at the length of their published clips", () => {- expect(bento.video.clip).toMatch(/^\/previews\/presets\/motion-catwalk\.mp4\?v=/);- expect(bento.threeD.clip).toMatch(/^\/previews\/presets\/app-3d-rotation\.mp4\?v=/);- expect(mp4Seconds(file(bento.video.clip))).toBeCloseTo(4, 1);- expect(mp4Seconds(file(bento.threeD.clip))).toBeCloseTo(3.04, 1);+ it("plays the catwalk and the turning gown in two widths, at the length of their published clips", () => {+ const tiles = [+ { tile: bento.video, name: "catwalk", published: "motion-catwalk", seconds: 4 },+ { tile: bento.threeD, name: "rotation", published: "app-3d-rotation", seconds: 3.04 },+ ];+ for (const { tile, name, published, seconds } of tiles) {+ expect(tile.id).toBe(published);+ expect(tile.clips.map((c) => c.w)).toEqual([...BENTO_CLIP_WIDTHS]);+ for (const c of tile.clips) {+ expect(c.src).toMatch(new RegExp(`^/previews/home/${name}-${c.w}\\.mp4\\?v=[0-9a-f]{8}$`));+ // Each is as wide as it says, 4:3, and as long as the published clip it stands in for (the same cut and loop).+ expect(mp4Size(file(c.src))).toEqual({ w: c.w, h: (c.w * 3) / 4 });+ expect(mp4Seconds(file(c.src))).toBeCloseTo(seconds, 1);+ expect(mp4Seconds(file(`/previews/presets/${published}.mp4`))).toBeCloseTo(seconds, 1);+ }+ // Its poster comes in the same widths (the clip's first frame); the published JPEG for a browser without AVIF.+ expect(tile.poster.avif.map((a) => a.w)).toEqual([...BENTO_CLIP_WIDTHS]);+ for (const a of tile.poster.avif) expect(a.src).toMatch(new RegExp(`^/previews/home/${name}-${a.w}\\.avif\\?v=`));+ expect(tile.poster.fallback).toMatch(new RegExp(`^/previews/presets/${published}\\.jpg\\?v=`));+ }+ });++ it("lists every picture at its real width", async () => {+ const pictures: BentoPicture[] = [bento.video.poster, bento.threeD.poster, bento.image, bento.restore.before, bento.restore.after];+ for (const p of pictures)+ for (const a of [...p.avif, ...(p.tall ?? [])]) {+ const m = await sharp(file(a.src)).metadata();+ expect(m.width, a.src).toBe(a.w);+ }+ // The tall crop is 3:5.+ for (const a of bento.restore.after.tall ?? []) {+ const m = await sharp(file(a.src)).metadata();+ expect(m.width! / m.height!).toBeCloseTo(0.6, 2);+ }+ });++ it("gives each tile a copy at least as wide as it shows, up to the widest there is", () => {+ // object-fit: cover: a 4:3 clip in a square box needs its height x 4/3 of width, times the pixel ratio.+ expect(coverWidth(173, 173, 4 / 3, 3)).toBe(692);+ expect(coverWidth(569, 419, 4 / 3, 2)).toBe(1138);+ expect(coverWidth(476, 210, 4 / 3, 2)).toBe(952);+ const clips = bento.video.clips;+ expect(pickWidth(clips, 300).w).toBe(640);+ expect(pickWidth(clips, 640).w).toBe(640);+ expect(pickWidth(clips, 641).w).toBe(1024);+ // Past the widest copy (the render's own size): the widest, never stretched further.+ expect(pickWidth(clips, 1339).w).toBe(1024);+ // The widest of each is its master's own width: the clips are 1024 x 768 renders, the before/after pair 1536.+ for (const t of [bento.video, bento.threeD]) expect(Math.max(...t.clips.map((c) => c.w))).toBe(1024);+ // The before/after pair covers a 3x phone (358 px wide) and the tall tile on a 2x 1920 screen.+ expect(Math.max(...bento.restore.after.avif.map((a) => a.w))).toBeGreaterThanOrEqual(358 * 3);+ expect(Math.max(...(bento.restore.after.tall ?? []).map((a) => a.w))).toBeGreaterThanOrEqual(602);});it("opens a real page from every tile, named by the navigation or the catalog", () => {@@ -107,9 +160,15 @@ describe("Home's first screen", () => {expect(tiles.find((a) => a.includes('data-tile="numbers"'))).toContain('aria-haspopup="dialog"');// No link or button inside a tile: the whole tile is the one target.for (const chunk of html.split("data-tile=").slice(1)) expect(chunk.split("</a>")[0]).not.toMatch(/<(a|button)\b/);- // The page's only h1: the headline.+ // The page's only h1: the headline, in its own words; "finished film," and "one place." never break apart.expect(html.match(/<h1\b/g)).toHaveLength(1);- expect(html.replace(/<[^>]+>/g, "")).toContain("Make anything: From an idea to a finished film, in one place.");+ const h1 = /<h1\b[^>]*>([\s\S]*?)<\/h1>/.exec(html)![1].replace(/<[^>]+>/g, "");+ expect(h1.replace(/ /g, " ")).toBe("Make anything: From an idea to a finished film, in one place.");+ expect(h1).toContain("finished film,");+ expect(h1).toContain("one place.");+ // The note under it, both sentences whole, and nothing hidden shipped with it.+ expect(html).toContain("Film, stills, sound, 3D, live edits and whole pipelines. Each tile opens the studio that makes it.");+ expect(html).not.toMatch(/data-hero|hb-eyebrow|hb-vignette/);});it("quotes the catalog's numbers, never typed in", () => {diff --git a/tests/preset-covers.test.ts b/tests/preset-covers.test.tsindex 66ee2935..5715ccc9 100644--- a/tests/preset-covers.test.ts+++ b/tests/preset-covers.test.ts@@ -8,6 +8,7 @@ import { SOUL_LOOK_CARDS } from "@/lib/catalog/soul-looks.generated";import { previewFor, toPresetCard } from "@/lib/preset-card-data";import { isCover, onPeak, presetCard } from "@/lib/preset-cards";import { coverPreview, presetCover, thumbOf } from "@/lib/preset-covers";+import { HOME_BENTO_MEDIA } from "@/lib/home-bento.generated";import { PRESET_BEFORE_AFTER } from "@/lib/preset-before-after.generated";import { PRESET_COVERS } from "@/lib/preset-covers.generated";import { PRESET_PEAKS } from "@/lib/preset-peaks.generated";@@ -85,6 +86,8 @@ describe("the preset covers manifest", () => {const named = new Set(entries.flatMap(([, e]) => [e.poster, thumbOf(e.poster), e.video].filter((u): u is string => !!u).map((u) => u.split("?")[0])));for (const id of Object.keys(PRESET_PEAKS)) for (const f of [`/previews/presets/peak/${id}.jpg`, thumbOf(`/previews/presets/peak/${id}.jpg`)]) named.add(f);for (const id of Object.keys(PRESET_BEFORE_AFTER)) for (const f of beforeAfterFiles(id)) named.add(f);+ // Home's first screen makes its own clips and stills (scripts/gen-home-bento.mjs, tests/home-bento.test.ts).+ for (const f of Object.keys(HOME_BENTO_MEDIA)) named.add(f);const dir = path.join(root, "public", "previews");const files = fs.existsSync(dir) ? fs.readdirSync(dir, { recursive: true, encoding: "utf8" }).filter((f) => /\.(jpg|mp4)$/.test(f)) : [];// public/previews/templates is the template covers' (tests/template-covers.test.ts checks it).