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: Genjutsu shows each swap as it happens, as big as Live edit
Adarsh15935efef45d
diff --git a/public/previews/home/genjutsu-1024.avif b/public/previews/home/genjutsu-1024.avifdeleted file mode 100644index 6fce9e3b..00000000Binary files a/public/previews/home/genjutsu-1024.avif and /dev/null differdiff --git a/public/previews/home/genjutsu-1024.jpg b/public/previews/home/genjutsu-1024.jpgdeleted file mode 100644index b48b0ff4..00000000Binary files a/public/previews/home/genjutsu-1024.jpg and /dev/null differdiff --git a/public/previews/home/genjutsu-1024.mp4 b/public/previews/home/genjutsu-1024.mp4deleted file mode 100644index 58e28861..00000000Binary files a/public/previews/home/genjutsu-1024.mp4 and /dev/null differdiff --git a/public/previews/home/genjutsu-640.avif b/public/previews/home/genjutsu-640.avifdeleted file mode 100644index bf2e1fcd..00000000Binary files a/public/previews/home/genjutsu-640.avif and /dev/null differdiff --git a/public/previews/home/genjutsu-640.mp4 b/public/previews/home/genjutsu-640.mp4deleted file mode 100644index 6f7c7992..00000000Binary files a/public/previews/home/genjutsu-640.mp4 and /dev/null differdiff --git a/public/previews/home/genjutsu-768.avif b/public/previews/home/genjutsu-768.avifdeleted file mode 100644index 7f8f4c90..00000000Binary files a/public/previews/home/genjutsu-768.avif and /dev/null differdiff --git a/public/previews/home/genjutsu-768.mp4 b/public/previews/home/genjutsu-768.mp4deleted file mode 100644index e338491d..00000000Binary files a/public/previews/home/genjutsu-768.mp4 and /dev/null differdiff --git a/public/previews/home/genjutsu-couple-1024.avif b/public/previews/home/genjutsu-couple-1024.avifnew file mode 100644index 00000000..20013eaaBinary files /dev/null and b/public/previews/home/genjutsu-couple-1024.avif differdiff --git a/public/previews/home/genjutsu-couple-1024.jpg b/public/previews/home/genjutsu-couple-1024.jpgnew file mode 100644index 00000000..c6887236Binary files /dev/null and b/public/previews/home/genjutsu-couple-1024.jpg differdiff --git a/public/previews/home/genjutsu-couple-1024.mp4 b/public/previews/home/genjutsu-couple-1024.mp4new file mode 100644index 00000000..5fdadbecBinary files /dev/null and b/public/previews/home/genjutsu-couple-1024.mp4 differdiff --git a/public/previews/home/genjutsu-couple-640.avif b/public/previews/home/genjutsu-couple-640.avifnew file mode 100644index 00000000..3a1c11b0Binary files /dev/null and b/public/previews/home/genjutsu-couple-640.avif differdiff --git a/public/previews/home/genjutsu-couple-640.mp4 b/public/previews/home/genjutsu-couple-640.mp4new file mode 100644index 00000000..97612738Binary files /dev/null and b/public/previews/home/genjutsu-couple-640.mp4 differdiff --git a/public/previews/home/genjutsu-couple-768.avif b/public/previews/home/genjutsu-couple-768.avifnew file mode 100644index 00000000..5007200bBinary files /dev/null and b/public/previews/home/genjutsu-couple-768.avif differdiff --git a/public/previews/home/genjutsu-couple-768.mp4 b/public/previews/home/genjutsu-couple-768.mp4new file mode 100644index 00000000..6a36d799Binary files /dev/null and b/public/previews/home/genjutsu-couple-768.mp4 differdiff --git a/public/previews/home/genjutsu-couple-split-1024.avif b/public/previews/home/genjutsu-couple-split-1024.avifnew file mode 100644index 00000000..298d3d90Binary files /dev/null and b/public/previews/home/genjutsu-couple-split-1024.avif differdiff --git a/public/previews/home/genjutsu-couple-split-640.avif b/public/previews/home/genjutsu-couple-split-640.avifnew file mode 100644index 00000000..2922c83fBinary files /dev/null and b/public/previews/home/genjutsu-couple-split-640.avif differdiff --git a/public/previews/home/genjutsu-couple-split-768.avif b/public/previews/home/genjutsu-couple-split-768.avifnew file mode 100644index 00000000..65a055a8Binary files /dev/null and b/public/previews/home/genjutsu-couple-split-768.avif differdiff --git a/public/previews/home/genjutsu-lakeside-1024.mp4 b/public/previews/home/genjutsu-lakeside-1024.mp4new file mode 100644index 00000000..8ad93966Binary files /dev/null and b/public/previews/home/genjutsu-lakeside-1024.mp4 differdiff --git a/public/previews/home/genjutsu-lakeside-640.mp4 b/public/previews/home/genjutsu-lakeside-640.mp4new file mode 100644index 00000000..84752fa3Binary files /dev/null and b/public/previews/home/genjutsu-lakeside-640.mp4 differdiff --git a/public/previews/home/genjutsu-lakeside-768.mp4 b/public/previews/home/genjutsu-lakeside-768.mp4new file mode 100644index 00000000..aa9aeb62Binary files /dev/null and b/public/previews/home/genjutsu-lakeside-768.mp4 differdiff --git a/public/previews/home/genjutsu-original-240.avif b/public/previews/home/genjutsu-original-240.avifdeleted file mode 100644index 786bb527..00000000Binary files a/public/previews/home/genjutsu-original-240.avif and /dev/null differdiff --git a/public/previews/home/genjutsu-original-480.avif b/public/previews/home/genjutsu-original-480.avifdeleted file mode 100644index 59ecb148..00000000Binary files a/public/previews/home/genjutsu-original-480.avif and /dev/null differdiff --git a/scripts/gen-home-bento.mjs b/scripts/gen-home-bento.mjsindex cc0f1963..7d26f576 100644--- a/scripts/gen-home-bento.mjs+++ b/scripts/gen-home-bento.mjs@@ -13,12 +13,16 @@* rotation-{640,1024,1536,2048}.{mp4,avif} the turning gown (the 3D tile) at four widths, and each one's first frame* reel-sand-storm-1024.jpg, rotation-1024.jpg the 1024 px clips' first frames, for a browser without AVIF* image-4-{480,768}.avif the Image studio's example 4- * genjutsu-{640,768,1024}.{mp4,avif} Genjutsu's group swap (the Genjutsu tile) at three widths, and each one's first frame- * genjutsu-1024.jpg the 1024 px clip's first frame, for a browser without AVIF- * genjutsu-original-{240,480}.avif the original clip's first frame, for the Genjutsu tile's window+ * genjutsu-<name>-{640,768,1024}.mp4 each clip of the Genjutsu tile's reel (WIPES): a swap shown as it happens, the+ * original clip and the swapped one under a divider that sweeps across them+ * genjutsu-couple-{640,768,1024}.avif the reel's first clip's first frame at each width: the tile's poster+ * genjutsu-couple-1024.jpg the 1024 px clip's first frame, for a browser without AVIF+ * genjutsu-couple-split-{640,768,1024}.avif a frame of that clip split down the middle (original | swapped): the+ * tile's still under reduced motion* 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, the reel (its clips in order, each one's length and- * framing, and where set how long it holds its last frame and fades out), each poster's mean colour, and the waveform.+ * framing, and where set how long it holds its last frame and fades out), the Genjutsu reel (each clip's labels and+ * where its divider is on every frame), each poster's mean colour, and the waveform.** The reel: the video tile plays these clips one after another, each once, and crossfades into the next (after the* last, back to the first). Each is a stretch of its preset's full-size render: `from` (its first frame in the render)@@ -38,7 +42,8 @@* <dir>/<preset>-2048.mkv the same render upscaled to 2048 x 1536, every frame (SeedVR2 7B, lossless FFV1,* BT.709), for the 1536 and 2048 px copies: the 3D clip needs it; a reel clip without* one comes at 640 and 1024 only- * <dir>/genjutsu-group-swap.mp4 Genjutsu's group swap at full size (1024 x 768, 24 fps): the Genjutsu tile's clip+ * <dir>/genjutsu-<name>-swap.mp4 each Genjutsu clip's swapped take as the model made it (24 fps)+ * <dir>/genjutsu-<name>-original.mp4 the clip it was made from, as it went in* Without it those files are kept as they are (and versioned; a reel clip in the widths it has), the posters are made* again from the clips kept, and so is the rest.*@@ -90,14 +95,102 @@ export const REEL = [*/const LOOPS = [{ key: "app-3d-rotation", name: "rotation", crf: { 640: 23, 1024: 23, 1536: 27, 2048: 28 } }];/**- * The Genjutsu tile's clip (BENTO_GENJUTSU in src/lib/home-bento.ts): `frames` frames of its render from frame `from`,- * at the widths its 1024 px render covers, and the CRF each is encoded at. It plays on a loop, and its last frame is- * nothing like its first, so it holds that last frame `hold` frames and fades it to the tiles' dark colour over the- * last `fadeOut` (a crossfade at the seam would lay one face over another); its first frame, the poster, stays as it is.+ * The Genjutsu tile's reel (BENTO_GENJUTSU in src/lib/home-bento.ts), in the order it plays: each clip shows a swap as+ * it happens. It opens on the original clip; then a divider sweeps across from the left with the swapped take behind+ * it (the two play in step, frame for frame), and the rest of the take plays swapped. Its masters are+ * `<name>-swap.mp4` and `<name>-original.mp4`. `render`: the size the model made the swap at; the original is fitted+ * to it as the model fitted it (scaled to cover it, centred), so the two line up to the pixel. `sweep`: where the+ * divider is, as [frame, share of the width swapped] keyframes, eased in and out between them (the couple's rests+ * between the two people, one swapped and one not, before it goes on). `labels`: the words either side of the divider+ * (the tile sets them over the clip, in step with it). Each clip holds its last frame `hold` frames and fades it to the+ * tiles' dark colour over the last `fadeOut`, so the next one comes in over dark (a crossfade would lay one face over+ * another). `still`: the frame of the first clip that is the tile's still under reduced motion (the sweep at rest, half+ * and half). The CRFs were chosen on close crops of the faces and the divider against the frames before encoding.*/-export const CUTS = [- { key: "genjutsu-group-swap", name: "genjutsu", from: 0, frames: 120, hold: 8, fadeOut: 8, widths: [640, 768, 1024], crf: { 640: 24, 768: 24, 1024: 23 } },+export const WIPES = [+ { name: "genjutsu-couple", render: [992, 736], labels: ["Original", "Swapped"], sweep: [[30, 0], [44, 0.5], [54, 0.5], [68, 1]], still: 46, frames: 124, hold: 8, fadeOut: 8, crf: { 640: 24, 768: 24, 1024: 23 } },+ { name: "genjutsu-lakeside", render: [1024, 768], labels: ["Original", "Swapped"], sweep: [[18, 0], [56, 1]], frames: 124, hold: 8, fadeOut: 8, crf: { 640: 24, 768: 24, 1024: 23 } },];+/** The widths the Genjutsu clips come in: their renders are about 1024 px wide, and nothing is made up past that. */+const WIPE_WIDTHS = [640, 768, 1024];+/**+ * The divider, in shares of the frame's width: a white line WIPE_LINE wide (at least 1.5 px) in a soft shade+ * WIPE_SHADE either side, over a seam feathered across WIPE_FEATHER. It starts and ends WIPE_MARGIN outside the frame,+ * shade and all, so the first and last frames are whole.+ */+const WIPE_LINE = 0.003;+const WIPE_SHADE = 0.011;+const WIPE_FEATHER = 0.004;+const WIPE_MARGIN = 0.03;++/** The share of the width swapped at frame `f` (cosine-eased between the keyframes of `sweep`). */+export function sweepAt(sweep, f) {+ if (f <= sweep[0][0]) return sweep[0][1];+ for (let i = 1; i < sweep.length; i++) {+ const [f0, p0] = sweep[i - 1];+ const [f1, p1] = sweep[i];+ if (f <= f1) return p0 + (p1 - p0) * (0.5 - 0.5 * Math.cos((Math.PI * (f - f0)) / (f1 - f0)));+ }+ return sweep.at(-1)[1];+}+/** Where the divider's middle is at frame `f`, as a share of the frame's width (outside 0..1 at either end). */+export const lineAt = (sweep, f) => sweepAt(sweep, f) * (1 + 2 * WIPE_MARGIN) - WIPE_MARGIN;++/**+ * A clip of the reel at `width` (4:3): the original and the swap fitted to the same frame, the swap left of the+ * divider and the original right of it, each frame's divider at lineAt(); then its last frame held and faded out.+ * Returns its y4m stream.+ */+export function wipeAt(c, width) {+ const height = (width * 3) / 4;+ const [rw, rh] = c.render;+ // Both are scaled to cover the 4:3 frame, centred.+ const cover = `scale=${width}:${height}:force_original_aspect_ratio=increase:flags=lanczos,crop=${width}:${height}`;+ const decode = (file, fit) =>+ readY4m(ffmpeg(["-v", "error", "-i", path.join(MASTERS, file), "-an", "-sn", "-dn", "-vf", `fps=${CLIP_FPS},trim=end_frame=${c.frames},setpts=PTS-STARTPTS,${fit}${cover},format=yuv420p`, "-f", "yuv4mpegpipe", "-"]));+ // The original, fitted to the render's size as the model fitted it (scaled to cover it, centred).+ const swap = decode(`${c.name}-swap.mp4`, `scale=${rw}:${rh}:flags=lanczos,`);+ const orig = decode(`${c.name}-original.mp4`, `scale=${rw}:${rh}:force_original_aspect_ratio=increase:flags=lanczos,crop=${rw}:${rh},`);+ if (swap.frames.length !== c.frames || orig.frames.length !== c.frames) throw new Error(`${c.name}: ${swap.frames.length} and ${orig.frames.length} frames, not ${c.frames}`);+ const W = width;+ const cw = W / 2;+ const ch = height / 2;+ const line = Math.max(1.5, WIPE_LINE * W);+ const shade = WIPE_SHADE * W;+ const feather = WIPE_FEATHER * W;+ const frames = swap.frames.map((s, f) => {+ const x = lineAt(c.sweep, f) * W;+ // Per column (x at its centre, in luma pixels): how much is the swap, how much shade, how much white line.+ const weights = (cx) => {+ const d = cx - x;+ const t = Math.min(1, Math.max(0, 0.5 - d / feather));+ const swapW = t * t * (3 - 2 * t);+ const dark = 0.32 * Math.exp(-((d / shade) ** 2));+ const white = Math.min(1, Math.max(0, Math.min(cx + 0.5, x + line / 2) - Math.max(cx - 0.5, x - line / 2)));+ return [swapW, dark, white];+ };+ const ly = Array.from({ length: W }, (_, i) => weights(i + 0.5));+ const lc = Array.from({ length: cw }, (_, i) => weights(2 * i + 1));+ const o = orig.frames[f];+ const out = Buffer.alloc(s.length);+ const mix = (a, b, [sw, dark, white], blackV, whiteV, i) => {+ let v = b[i] + (a[i] - b[i]) * sw;+ v = blackV + (v - blackV) * (1 - dark);+ v = v + (whiteV - v) * white;+ out[i] = Math.round(v);+ };+ for (let y = 0; y < height; y++) for (let i = 0; i < W; i++) mix(s, o, ly[i], 16, 235, y * W + i);+ for (const base of [W * height, W * height + cw * ch])+ for (let y = 0; y < ch; y++) for (let i = 0; i < cw; i++) mix(s, o, lc[i], 128, 128, base + y * cw + i);+ return out;+ });+ const y4m = Buffer.concat([Buffer.from(`${swap.header}\n`, "latin1"), ...frames.flatMap((fr) => [Buffer.from("FRAME\n"), fr])]);+ const total = c.frames + c.hold;+ return ffmpeg(+ ["-v", "error", "-f", "yuv4mpegpipe", "-i", "-", "-vf", `tpad=stop_mode=clone:stop=${c.hold},fade=t=out:start_frame=${total - c.fadeOut}:nb_frames=${c.fadeOut - 1}:color=${FADE_COLOR},format=yuv420p`, "-f", "yuv4mpegpipe", "-"],+ y4m,+ );+}/** The colour a clip fades out to before it loops: the tiles' dark media colour (globals.css --media). */const FADE_COLOR = "0x0d0d0f";/** The widths each clip and its poster are made at: a tile takes the first at least as wide as its box needs. */@@ -117,14 +210,16 @@ const BOARD_THUMBS = [const STILLS = [{ 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 },- // The original clip's first frame (GENJUTSU_ORIGINAL in src/lib/home-bento.ts), for the Genjutsu tile's window.- { name: "genjutsu-original-240.avif", from: "/examples/genjutsu-character/1/in-clip.jpg", width: 240 },- { name: "genjutsu-original-480.avif", from: "/examples/genjutsu-character/1/in-clip.jpg", width: 480 },];/** 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 clips' posters: close enough to the clip's own first frame that the swap from one to the other can't be seen. */const POSTER_QUALITY = 65;+/**+ * The Genjutsu reel's poster: its first frame is full of fine detail (stone steps, leaves, carved balconies), so it is+ * encoded finer, to stay as close to its clip's first frame as the other posters are to theirs.+ */+const WIPE_POSTER_QUALITY = 80;/** The colours every clip is tagged with (libx264 takes them as its own options): its poster is decoded the same way. */const BT709 = ["-x264-params", "colorprim=bt709:transfer=bt709:colormatrix=bt709", "-color_range", "tv"];/** The board's pictures show at 36 to 56 px: a 168 px square covers them on a 3x screen. */@@ -153,16 +248,13 @@ function loopAt(src, width) {}/**- * A clip at `width`: `frames` frames from frame `from` of the render (at CLIP_FPS). A reel clip plays once, no loop;- * the Genjutsu clip (CUTS) then holds its last frame `hold` frames and fades out over its last `fadeOut`, ending on- * the fade colour. Returns its y4m stream.+ * A reel clip at `width`: `frames` frames from frame `from` of the render (at CLIP_FPS), played once, no loop.+ * Returns its y4m stream.*/-function cutAt(src, width, from, frames, { hold = 0, fadeOut = 0 } = {}) {- const total = frames + hold;- const tail = (hold ? `,tpad=stop_mode=clone:stop=${hold}` : "") + (fadeOut ? `,fade=t=out:start_frame=${total - fadeOut}:nb_frames=${fadeOut - 1}:color=${FADE_COLOR}` : "");- const y4m = ffmpeg(["-v", "error", "-i", src, "-an", "-sn", "-dn", "-vf", `fps=${CLIP_FPS},trim=start_frame=${from}:end_frame=${from + frames},setpts=PTS-STARTPTS,scale=${width}:-2:flags=lanczos${tail},format=yuv420p`, "-f", "yuv4mpegpipe", "-"]);+function cutAt(src, width, from, frames) {+ const y4m = ffmpeg(["-v", "error", "-i", src, "-an", "-sn", "-dn", "-vf", `fps=${CLIP_FPS},trim=start_frame=${from}:end_frame=${from + frames},setpts=PTS-STARTPTS,scale=${width}:-2:flags=lanczos,format=yuv420p`, "-f", "yuv4mpegpipe", "-"]);const got = readY4m(y4m).frames.length;- if (got !== total) throw new Error(`${path.basename(src)} has ${got} frames from frame ${from}, not ${total}`);+ if (got !== frames) throw new Error(`${path.basename(src)} has ${got} frames from frame ${from}, not ${frames}`);return y4m;}@@ -181,11 +273,15 @@ 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", ...BT709, "-map_metadata", "-1", "-movflags", "+faststart", out], y4m);}-/** A clip's first frame as a PNG, decoded from the encoded file as a browser shows it. */-function firstFrame(file) {- return ffmpeg(["-v", "error", "-i", file, "-frames:v", "1", "-vf", "scale=in_color_matrix=bt709:in_range=tv:flags=accurate_rnd+full_chroma_int+lanczos,format=rgb24", "-c:v", "png", "-f", "image2pipe", "-"]);+/** Frame `n` of a clip as a PNG, decoded from the encoded file as a browser shows it. */+function frameAt(file, n) {+ const vf = `trim=start_frame=${n},scale=in_color_matrix=bt709:in_range=tv:flags=accurate_rnd+full_chroma_int+lanczos,format=rgb24`;+ return ffmpeg(["-v", "error", "-i", file, "-frames:v", "1", "-vf", vf, "-c:v", "png", "-f", "image2pipe", "-"]);}+/** A clip's first frame as a PNG, decoded from the encoded file as a browser shows it. */+const firstFrame = (file) => frameAt(file, 0);+/** 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);@@ -240,11 +336,11 @@ async function main() {make: () => encodeClipBuffer(loopAt(master(w >= HD_FROM ? `${c.key}-2048.mkv` : `${c.key}.mp4`), w).all, c.crf[w]),})),),- ...CUTS.flatMap((c) =>- c.widths.map((w) => ({+ ...WIPES.flatMap((c) =>+ WIPE_WIDTHS.map((w) => ({name: `${c.name}-${w}.mp4`,clip: true,- make: () => encodeClipBuffer(cutAt(master(`${c.key}.mp4`), w, c.from, c.frames, c), c.crf[w]),+ make: () => encodeClipBuffer(wipeAt(c, w), c.crf[w]),})),),];@@ -262,17 +358,23 @@ async function main() {}if (!DRY) versions[`/previews/home/${s.name}`] = contentVersion([out]);}- // Each poster, from its clip as it is now (just made, or kept): the reel's first clip's, the 3D clip's and Genjutsu's.- const posterSets = [{ name: reel[0].name, widths: reel[0].widths }, ...LOOPS.map((c) => ({ name: c.name, widths: CLIP_WIDTHS })), ...CUTS.map((c) => ({ name: c.name, widths: c.widths }))];- const posters = posterSets.flatMap((c) => c.widths.map((w) => ({ name: `${c.name}-${w}.avif`, clip: `${c.name}-${w}.mp4` })));+ // Each poster, from its clip as it is now (just made, or kept): the reel's first clip's, the 3D clip's and the+ // Genjutsu reel's first clip's.+ const posterSets = [{ name: reel[0].name, widths: reel[0].widths }, ...LOOPS.map((c) => ({ name: c.name, widths: CLIP_WIDTHS })), { name: WIPES[0].name, widths: WIPE_WIDTHS, quality: WIPE_POSTER_QUALITY }];+ const posters = posterSets.flatMap((c) => c.widths.map((w) => ({ name: `${c.name}-${w}.avif`, clip: `${c.name}-${w}.mp4`, quality: c.quality ?? POSTER_QUALITY })));const jobs = [...posters.map((p) => ({...p,make: () => {// A dry run writes no clip: it reads the one already here.- return sharp(firstFrame(path.join(OUT_DIR, p.clip))).avif({ quality: POSTER_QUALITY, effort: 6 }).toBuffer();+ return sharp(firstFrame(path.join(OUT_DIR, p.clip))).avif({ quality: p.quality, effort: 6 }).toBuffer();},})),+ // The Genjutsu tile's still under reduced motion: its first clip at rest, half and half, read from that clip.+ ...WIPE_WIDTHS.map((w) => ({+ name: `${WIPES[0].name}-split-${w}.avif`,+ make: () => sharp(frameAt(path.join(OUT_DIR, `${WIPES[0].name}-${w}.mp4`), WIPES[0].still)).avif({ quality: POSTER_QUALITY, effort: 6 }).toBuffer(),+ })),// For a browser without AVIF: the FALLBACK_WIDTH clip's first frame as a JPEG....posterSets.map((c) => ({name: `${c.name}-${FALLBACK_WIDTH}.jpg`,@@ -321,6 +423,22 @@ export const HOME_BENTO_REEL = ${JSON.stringify(2,)};+/**+ * The Genjutsu tile's reel, in the order it plays: each clip's copies' name, its length in frames (its held last frames+ * too), the words either side of its divider, where the divider is on each frame (a share of the frame's width, the+ * swap left of it), and the frame its fade out starts on.+ */+export const HOME_BENTO_GENJUTSU = ${JSON.stringify(+ WIPES.map((c) => ({+ name: c.name,+ frames: c.frames + c.hold,+ fps: CLIP_FPS,+ labels: c.labels,+ fadeFrom: c.frames + c.hold - c.fadeOut,+ line: Array.from({ length: c.frames + c.hold }, (_, f) => Math.round(lineAt(c.sweep, Math.min(f, c.frames - 1)) * 10000) / 10000),+ })),+ )};+/** Each poster's mean colour (by its clip's name): the tile shows it until the poster is in. */export const HOME_BENTO_TINT: Record<string, string> = ${JSON.stringify(tints, null, 2)};diff --git a/src/components/home/bento-islands.tsx b/src/components/home/bento-islands.tsxindex 21df8f18..9d4ca0ff 100644--- a/src/components/home/bento-islands.tsx+++ b/src/components/home/bento-islands.tsx@@ -5,7 +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 { REEL_STALL_MS, fadeDue, fadeOf, holdOf, nextInReel, reelProgress, reelSources, type ReelClip } from "@/lib/home-reel";+import { REEL_STALL_MS, fadeDue, fadeOf, holdOf, nextInReel, reelProgress, reelSources, wipeFrame, type ReelClip, type ReelWipe } from "@/lib/home-reel";import { coverWidth, pickWidth, type Sized } from "@/lib/media-pick";import { releaseVideo } from "@/lib/media-release";import { browserPlaybackEnv } from "@/lib/preview-playback";@@ -338,9 +338,10 @@ const later = (k: number) => (prev: number) => Math.max(prev, k);* the clip on screen loops instead. One that is slow lets the clip on screen play again rather than stop on its last* frame. Under reduced motion or Save-Data nothing plays by itself; a hover or keyboard focus plays the first clip* alone, on a loop (under Save-Data, the copy as wide as the still). `progress`: a line along the bottom follows the- * whole reel.+ * whole reel. `wipes` (one per clip, the Genjutsu tile's): each clip shows a swap under a divider, and the words for+ * either side ride along with it (followWipe).*/-export function BentoReel({ id, reel, progress }: { id: string; reel: ReelClip[]; progress?: boolean }) {+export function BentoReel({ id, reel, progress, wipes }: { id: string; reel: ReelClip[]; progress?: boolean; wipes?: ReelWipe[] }) {const [armed, setArmed] = useState(false);const [stillW, setStillW] = useState(0);const { ref, playing, handlers } = usePreviewPlayback<HTMLSpanElement>(id, armed ? { video: reel[0].clips[0].src } : {});@@ -485,6 +486,17 @@ export function BentoReel({ id, reel, progress }: { id: string; reel: ReelClip[]setRest(-1);};+ // The words over a wipe follow the clip on screen: the one coming in, from when it shows.+ const lk = incomingShown ? seq + 1 : seq;+ const wipe = wipes?.[lk % n];+ const wipeEl = useRef<HTMLSpanElement>(null);+ useEffect(() => {+ const v = els.current.get(lk);+ const el = wipeEl.current;+ if (!wipe || !v || !el || !playing) return;+ return followWipe(v, el, wipe);+ }, [wipe, lk, playing, loaded, started]);+const playingNow = plan ? [{ k: seq, i: seq % n }, ...(nextOn ? [{ k: seq + 1, i: nextInReel(seq % n, n) }] : [])] : [];return (<span ref={ref} aria-hidden className={s.clip} data-reel={plan ? seq % n : undefined} onPointerEnter={handlers.onPointerEnter} onPointerLeave={handlers.onPointerLeave}>@@ -511,6 +523,12 @@ export function BentoReel({ id, reel, progress }: { id: string; reel: ReelClip[]onFaded={advance}/>))}+ {wipe && (+ <span ref={wipeEl} className={s.wipe}>+ <span className={s.wipeAfter}>{wipe.labels[1]}</span>+ <span className={s.wipeBefore}>{wipe.labels[0]}</span>+ </span>+ )}{progress && (<span className={s.progress}><i ref={bar} />@@ -520,6 +538,45 @@ export function BentoReel({ id, reel, progress }: { id: string; reel: ReelClip[]);}+type FrameClock = HTMLVideoElement & {+ requestVideoFrameCallback?: (cb: (now: number, meta: { mediaTime: number }) => void) => number;+ cancelVideoFrameCallback?: (handle: number) => void;+};++/**+ * Keeps the words over a wipe on its divider (`el`'s --x, the divider's place on the frame on screen), and out of+ * sight while the clip fades to dark (data-out). Each frame the browser presents moves them, read from that frame's+ * own time where the browser says it (requestVideoFrameCallback), otherwise from the clip's time once per paint, so+ * they never drift from the line in the picture. Returns its stop.+ */+function followWipe(v: HTMLVideoElement, el: HTMLElement, wipe: ReelWipe): () => void {+ let last = -1;+ const show = (t: number) => {+ const f = wipeFrame(wipe, t);+ if (f === last) return;+ last = f;+ el.style.setProperty("--x", String(wipe.line[f]));+ el.toggleAttribute("data-out", f >= wipe.fadeFrom);+ };+ show(v.currentTime);+ const clock = v as FrameClock;+ let handle = 0;+ if (clock.requestVideoFrameCallback) {+ const onFrame = (_: number, meta: { mediaTime: number }) => {+ show(meta.mediaTime);+ handle = clock.requestVideoFrameCallback!(onFrame);+ };+ handle = clock.requestVideoFrameCallback(onFrame);+ return () => clock.cancelVideoFrameCallback?.(handle);+ }+ const tick = () => {+ show(v.currentTime);+ handle = requestAnimationFrame(tick);+ };+ handle = requestAnimationFrame(tick);+ return () => cancelAnimationFrame(handle);+}+/** How long each part of the live tile's loop takes, in ms. */const TYPE_MS = 55;const FADE_MS = 320;diff --git a/src/components/home/home-bento-classes.ts b/src/components/home/home-bento-classes.tsindex 61dc5dfd..34b752de 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 = ["accent","aside","audio","badge","bento","big","board","box","canvas","caret","clip","copy","corner","cta","edges","end","figures","fill","filmMark","foot","frame","genjutsu","grid","h1","head","image","kenburns","l2b","line1","line2","live","meta","node","nodeLabel","numbers","numbersFoot","numbersLine","original","originalLabel","out","pic","pill","playhead","progress","shade","step","three","tile","title","tsx","typed","video","wave"] as const;+const NAMES = ["accent","aside","audio","badge","bento","big","board","box","canvas","caret","clip","copy","corner","cta","edges","end","figures","fill","filmMark","foot","frame","genjutsu","grid","h1","head","image","kenburns","l2b","line1","line2","live","meta","node","nodeLabel","numbers","numbersFoot","numbersLine","out","pic","pill","playhead","progress","shade","step","three","tile","title","tsx","typed","video","wave","wipe","wipeAfter","wipeBefore"] 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 a4d2d2c2..49048808 100644--- a/src/components/home/home-bento.css+++ b/src/components/home/home-bento.css@@ -225,9 +225,9 @@/* ---------------------------------------------------------------- grid *//*- * The reel leads; Live edit, the highlight, is the next biggest and sits right by it (right under it on a phone), and- * Genjutsu comes next. From lg the grid is twelve narrow columns, so the top two rows (the reel, Live edit, then the- * image and 3D tiles stacked) and the bottom row (Genjutsu, audio, the numbers, canvas) each split it their own way.+ * The reel leads; Live edit, the highlight, and Genjutsu, whose swaps need room to be seen, are the next biggest, the+ * same size, right by it (right under it on a phone). From lg the grid is fourteen narrow columns, so the top two rows+ * (the reel, Live edit, Genjutsu) and the bottom row (image, 3D, audio, the numbers, canvas) each split it their own way.*/.hb-grid {display: grid;@@ -250,9 +250,9 @@.hb-live {aspect-ratio: 16 / 10;}- /* Shorter than the live tile above it, which is the bigger one; the couple's faces still show whole. */+ /* As big as the live tile above it: the swaps show whole, faces and all. */.hb-genjutsu {- aspect-ratio: 16 / 9;+ aspect-ratio: 16 / 10;}.hb-image,.hb-three {@@ -268,25 +268,25 @@@media (min-width: 768px) {.hb-grid {grid-template-columns: repeat(3, minmax(0, 1fr));- /* The reel and the live tile a little taller than the rows under them: the live tile is the bigger one. */- grid-template-rows: 230px 230px 210px 210px auto;+ /* Live edit one column two rows tall, Genjutsu two columns one row tall: the same size, each bigger than the rest. */+ grid-template-rows: 230px 230px 230px 210px auto;grid-template-areas:"video video live""video video live"- "genjutsu image three"- "audio canvas canvas"+ "genjutsu genjutsu image"+ "three audio canvas""numbers numbers numbers";}}@media (min-width: 1024px) {.hb-grid {- grid-template-columns: repeat(12, minmax(0, 1fr));+ grid-template-columns: repeat(14, minmax(0, 1fr));grid-template-rows: repeat(3, minmax(0, 1fr));height: clamp(var(--grid-min), calc(var(--content-h) - var(--bento-head) - var(--head-top) - 3.25rem), 760px);grid-template-areas:- "video video video video video video live live live live image image"- "video video video video video video live live live live three three"- "genjutsu genjutsu genjutsu genjutsu audio audio numbers numbers numbers canvas canvas canvas";+ "video video video video video video live live live live genjutsu genjutsu genjutsu genjutsu"+ "video video video video video video live live live live genjutsu genjutsu genjutsu genjutsu"+ "image image three three audio audio audio numbers numbers numbers canvas canvas canvas canvas";}}.hb-video {@@ -487,18 +487,22 @@font-size: 44px;}}-/* From a tablet the live tile is the second biggest: its title a size up from the small tiles', and from lg two. */+/* From a tablet the live and Genjutsu tiles are the second biggest: their titles a size up from the small tiles', and+ from lg two. */@media (min-width: 768px) {- .hb-live .hb-title {+ .hb-live .hb-title,+ .hb-genjutsu .hb-title {font-size: 28px;}}@media (min-width: 1024px) {- .hb-live .hb-title {+ .hb-live .hb-title,+ .hb-genjutsu .hb-title {font-size: 30px;}@container (min-width: 360px) {- .hb-live .hb-title {+ .hb-live .hb-title,+ .hb-genjutsu .hb-title {font-size: 34px;}}@@ -701,16 +705,14 @@height: 45%;}-/* ---------------------------------------------------------------- genjutsu: the swap, and the clip as it was */+/* ---------------------------------------------------------------- genjutsu: swaps, as they happen */-/* The couple's faces sit in the top half of the clip (from 16 % to 43 % of its height in every frame): a wide, short- tile keeps them in view. */+/* The faces sit in the top half of each clip (the couple's from 16 % to 43 % of its height in every frame): a tile+ wider than the clip keeps them in view. From lg the tile is squarer than the clip, so all of its height shows. */.hb-genjutsu > .hb-pic .hb-fill,.hb-genjutsu .hb-clip video {object-position: 50% 22%;}-/* From lg the tile is a short strip with its title over the lower half: the faces sit higher in it, clear of the- words, their heads still whole when the camera pushes in. */@media (min-width: 1024px) {.hb-genjutsu > .hb-pic .hb-fill,.hb-genjutsu .hb-clip video {@@ -718,49 +720,74 @@}}/*- * The original clip's first frame, in a small window in the tile's top corner: what went in, beside what came out. On- * a layer over the clip and the shade, its size from the tile's own width (the tile is a container), so it never lays- * out again.+ * The words either side of the divider in the picture, riding along with it (BentoReel moves --x, the divider's place+ * on the frame on screen, a share of the clip's width). The clip fills the tile under object-fit: cover, centred+ * across, so the divider is at --lx in the tile (--fw: the clip's width on screen). "Original" rides on its right and+ * keeps to the tile's left edge until the divider comes; "Swapped" rides on its left and stays at the right edge once+ * it has gone by. Before the tile plays the divider is off the frame to the left, so "Original" names the still; under+ * reduced motion it is half way across, as in that still. They go with the picture as a clip fades out.*/-.hb-original {+.hb-wipe {+ --x: -0.03;+ --fw: 100cqw;+ --lx: calc(var(--x) * var(--fw) - (var(--fw) - 100cqw) / 2);position: absolute;- z-index: 1;- top: 10px;- right: 10px;- width: clamp(76px, 27cqw, 132px);- aspect-ratio: 4 / 3;- overflow: hidden;- border-radius: 8px;- border: 1px solid rgb(255 255 255 / 55%);- background: #222228;- box-shadow: 0 6px 18px rgb(0 0 0 / 40%);+ inset: 0;pointer-events: none;+ transition: opacity 0.3s ease;+}+@media (min-width: 1024px) {+ .hb-wipe {+ --fw: max(100cqw, 133.333cqh);+ }+}+@media (prefers-reduced-motion: reduce) {+ .hb-wipe {+ --x: 0.5;+ }+}+.hb-wipe[data-out] {+ opacity: 0;}-.hb-original-label {+.hb-wipe-before,+.hb-wipe-after {position: absolute;- left: 5px;- bottom: 5px;- height: 16px;+ top: 12px;display: inline-flex;align-items: center;- padding: 0 6px;+ height: 24px;+ padding: 0 9px;border-radius: 999px;- background: rgb(13 13 15 / 78%);- font-size: 9.5px;+ background: rgb(13 13 15 / 72%);+ font-size: 10.5px;font-weight: 500;letter-spacing: 0.08em;text-transform: uppercase;+ white-space: nowrap;}-@container (min-width: 300px) {- .hb-original {- top: 12px;- right: 12px;- }+/* Moved, not laid out again: the words ride on a transform, so their trip is never a layout shift. */+.hb-wipe-before {+ left: 0;+ transform: translateX(max(12px, calc(var(--lx) + 8px)));}-/* From lg the strip is short: a smaller window keeps to its corner, clear of the man's face as the camera moves. */-@media (min-width: 1024px) {- .hb-original {- width: clamp(64px, 22cqw, 132px);+.hb-wipe-after {+ right: 0;+ transform: translateX(min(-12px, calc(var(--lx) - 100cqw - 8px)));+ background: color-mix(in oklch, var(--bento-accent) 82%, black);+}+@container (min-width: 340px) {+ .hb-wipe-before,+ .hb-wipe-after {+ top: 16px;+ height: 26px;+ padding: 0 11px;+ font-size: 11px;+ }+ .hb-wipe-before {+ transform: translateX(max(16px, calc(var(--lx) + 9px)));+ }+ .hb-wipe-after {+ transform: translateX(min(-16px, calc(var(--lx) - 100cqw - 9px)));}}/* The reel's clips and its still: a wide, short tile crops from the bottom, so the head always shows (a clip frameddiff --git a/src/components/home/home-bento.tsx b/src/components/home/home-bento.tsxindex d847e26a..4b51bc60 100644--- a/src/components/home/home-bento.tsx+++ b/src/components/home/home-bento.tsx@@ -22,16 +22,18 @@ const SIZES = {live: "(min-width: 1024px) 570px, (min-width: 768px) 630px, 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) 274px, (min-width: 768px) 320px, calc((100vw - 44px) * 0.667)",- /** The Genjutsu tile: a third of the grid wide from lg, one column on a tablet (its 4:3 clip under cover: 280 px), the full row on a phone. */- genjutsu: "(min-width: 1024px) 376px, (min-width: 768px) 280px, calc(100vw - 32px)",- /** The original's window in the Genjutsu tile (home-bento.css: at most 132 px wide). */- original: "132px",+ /**+ * The Genjutsu tile: from lg as big as the live tile, two rows tall and squarer than its 4:3 clip (so its height+ * times 4/3: up to 560 px on a 1920 x 1080 screen); two columns on a tablet; the full row on a phone.+ */+ genjutsu: "(min-width: 1024px) 560px, (min-width: 768px) 470px, calc(100vw - 32px)",};/*** A picture in AVIF where the browser takes it, its published JPEG or WebP where not. `position`: its object-position,* where it differs from its tile's. Its tint (a clip's poster) is its box's colour until it is in. `decoding`: "sync"- * for the picture that must land with the first screen. Decorative: the tile's link names it.+ * for the picture that must land with the first screen. `reduced`: the picture shown instead under reduced motion (in+ * AVIF; a browser without it keeps `pic`). Decorative: the tile's link names it.*/function Pic({pic,@@ -41,6 +43,7 @@ function Pic({fetchPriority,position,decoding = "async",+ reduced,}: {pic: BentoPicture;sizes: string;@@ -49,9 +52,11 @@ function Pic({fetchPriority?: "high" | "low";position?: string;decoding?: "async" | "sync";+ reduced?: BentoPicture;}) {return (<picture className={s.pic}>+ {reduced && <source media="(prefers-reduced-motion: reduce)" type="image/avif" srcSet={reduced.avif.map((a) => `${a.src} ${a.w}w`).join(", ")} sizes={sizes} />}<source type="image/avif" srcSet={pic.avif.map((a) => `${a.src} ${a.w}w`).join(", ")} sizes={sizes} /><imgsrc={pic.fallback}@@ -207,6 +212,15 @@ export function HomeBento({ bento }: { bento: Bento }) {<LiveTyping frames={bento.live.frames} phrases={bento.live.phrases} sizes={SIZES.live} /></Tile>+ {/*+ Swaps shown as they happen: each clip opens on the original, then a divider sweeps the swapped take in across+ it, "Original" and "Swapped" riding either side of it. Under reduced motion, the first one at rest half way.+ */}+ <Tile tile={tiles.genjutsu} area={s.genjutsu}>+ <Pic pic={bento.genjutsu.poster} reduced={bento.genjutsu.still} sizes={SIZES.genjutsu} fetchPriority="low" />+ <BentoReel id={bento.genjutsu.id} reel={bento.genjutsu.reel} wipes={bento.genjutsu.wipes} />+ </Tile>+<Tile tile={tiles.image} area={s.image}><Pic pic={bento.image} sizes={SIZES.square} className={s.kenburns} fetchPriority="low" /></Tile>@@ -216,16 +230,6 @@ export function HomeBento({ bento }: { bento: Bento }) {<BentoClip id={bento.threeD.id} clips={bento.threeD.clips} /></Tile>- <Tile tile={tiles.genjutsu} area={s.genjutsu}>- <Pic pic={bento.genjutsu.poster} sizes={SIZES.genjutsu} fetchPriority="low" />- <BentoClip id={bento.genjutsu.id} clips={bento.genjutsu.clips} />- {/* The clip as it was: both people in it are swapped in the one take behind it. */}- <span aria-hidden className={s.original}>- <Pic pic={bento.genjutsu.original} sizes={SIZES.original} fetchPriority="low" />- <span className={s.originalLabel}>Original</span>- </span>- </Tile>-<Tile tile={tiles.audio} area={s.audio}><span aria-hidden className={s.wave} style={{ "--wave-s": `${bento.wave.seconds}s` } as React.CSSProperties}>{bento.wave.bars.map((h, i) => (diff --git a/src/lib/home-bento.generated.ts b/src/lib/home-bento.generated.tsindex 3e103b37..d3c85b6c 100644--- a/src/lib/home-bento.generated.ts+++ b/src/lib/home-bento.generated.ts@@ -12,25 +12,29 @@ export const HOME_BENTO_MEDIA: Record<string, string> = {"/previews/home/rotation-1024.mp4": "3f5507ab","/previews/home/rotation-1536.mp4": "87d3d4f1","/previews/home/rotation-2048.mp4": "5804eda4",- "/previews/home/genjutsu-640.mp4": "dc3680bd",- "/previews/home/genjutsu-768.mp4": "003cd587",- "/previews/home/genjutsu-1024.mp4": "4a1c92ad",+ "/previews/home/genjutsu-couple-640.mp4": "e5853e3f",+ "/previews/home/genjutsu-couple-768.mp4": "8c5bd7e5",+ "/previews/home/genjutsu-couple-1024.mp4": "a167fe74",+ "/previews/home/genjutsu-lakeside-640.mp4": "620fd65a",+ "/previews/home/genjutsu-lakeside-768.mp4": "347a8d35",+ "/previews/home/genjutsu-lakeside-1024.mp4": "7bd2e563","/previews/home/reel-sand-storm-640.avif": "6e339255","/previews/home/reel-sand-storm-1024.avif": "13b5d74a","/previews/home/rotation-640.avif": "c69b0d7b","/previews/home/rotation-1024.avif": "23d2a89b","/previews/home/rotation-1536.avif": "b3df3778","/previews/home/rotation-2048.avif": "bcc9ccc5",- "/previews/home/genjutsu-640.avif": "5773faa7",- "/previews/home/genjutsu-768.avif": "be299a65",- "/previews/home/genjutsu-1024.avif": "c7c045c3",+ "/previews/home/genjutsu-couple-640.avif": "e050404a",+ "/previews/home/genjutsu-couple-768.avif": "4d693b3a",+ "/previews/home/genjutsu-couple-1024.avif": "1748efab",+ "/previews/home/genjutsu-couple-split-640.avif": "fc57af53",+ "/previews/home/genjutsu-couple-split-768.avif": "69d8990b",+ "/previews/home/genjutsu-couple-split-1024.avif": "0e726fb0","/previews/home/reel-sand-storm-1024.jpg": "cab53f24","/previews/home/rotation-1024.jpg": "61a2cbc9",- "/previews/home/genjutsu-1024.jpg": "1b5d1a56",+ "/previews/home/genjutsu-couple-1024.jpg": "5b931a56","/previews/home/image-4-480.avif": "5a6d07a1","/previews/home/image-4-768.avif": "ef9d1b4d",- "/previews/home/genjutsu-original-240.avif": "ecc3f2d0",- "/previews/home/genjutsu-original-480.avif": "c0db35a8","/previews/home/board-photo.webp": "47432641","/previews/home/board-film.webp": "db007869"};@@ -55,11 +59,18 @@ export const HOME_BENTO_REEL = [}];+/**+ * The Genjutsu tile's reel, in the order it plays: each clip's copies' name, its length in frames (its held last frames+ * too), the words either side of its divider, where the divider is on each frame (a share of the frame's width, the+ * swap left of it), and the frame its fade out starts on.+ */+export const HOME_BENTO_GENJUTSU = [{"name":"genjutsu-couple","frames":132,"fps":24,"labels":["Original","Swapped"],"fadeFrom":124,"line":[-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.0234,-0.0038,0.0278,0.0698,0.12,0.176,0.235,0.294,0.35,0.4002,0.4422,0.4738,0.4934,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5066,0.5262,0.5578,0.5998,0.65,0.706,0.765,0.824,0.88,0.9302,0.9722,1.0038,1.0234,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03]},{"name":"genjutsu-lakeside","frames":132,"fps":24,"labels":["Original","Swapped"],"fadeFrom":124,"line":[-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.0282,-0.0228,-0.0138,-0.0013,0.0146,0.0339,0.0563,0.0818,0.1101,0.141,0.1745,0.2101,0.2477,0.2871,0.3279,0.3699,0.4128,0.4562,0.5,0.5438,0.5872,0.6301,0.6721,0.7129,0.7523,0.7899,0.8255,0.859,0.8899,0.9182,0.9437,0.9661,0.9854,1.0013,1.0138,1.0228,1.0282,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03,1.03]}];+/** Each poster's mean colour (by its clip's name): the tile shows it until the poster is in. */export const HOME_BENTO_TINT: Record<string, string> = {"reel-sand-storm": "#b06c4c","rotation": "#bfbeb6",- "genjutsu": "#786b54"+ "genjutsu-couple": "#9f8a6b"};export const HOME_BENTO_WAVE = {diff --git a/src/lib/home-bento.ts b/src/lib/home-bento.tsindex 757dcb16..fc0409b2 100644--- a/src/lib/home-bento.ts+++ b/src/lib/home-bento.ts@@ -11,8 +11,8 @@ import { getTemplate } from "@/lib/catalog/canvas";import { runsOn } from "@/lib/catalog/engines";import type { ModelDef } from "@/lib/catalog/types";import { EXAMPLE_MEDIA } from "@/lib/examples/media.generated";-import { HOME_BENTO_MEDIA, HOME_BENTO_REEL, HOME_BENTO_TINT, HOME_BENTO_WAVE } from "@/lib/home-bento.generated";-import type { ReelClip } from "@/lib/home-reel";+import { HOME_BENTO_GENJUTSU, HOME_BENTO_MEDIA, HOME_BENTO_REEL, HOME_BENTO_TINT, HOME_BENTO_WAVE } from "@/lib/home-bento.generated";+import type { ReelClip, ReelWipe } from "@/lib/home-reel";import type { Demo } from "@/lib/live/demo";import { presetCover } from "@/lib/preset-covers";import { templateCover } from "@/lib/template-covers";@@ -34,17 +34,16 @@ export const BENTO_CLIP_FALLBACK = 1024;/** 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 Genjutsu tile: Genjutsu's own Group swap example (a couple, both people swapped in one take; the studio's cover- * "genjutsu-group-swap"), cut by scripts/gen-home-bento.mjs into `name`'s copies, with the original clip's first frame in- * a small window. Its id in the playback store is its own, so a card lower down can play the same clip.+ * The Genjutsu tile: a reel of swaps shown as they happen (HOME_BENTO_GENJUTSU, made by scripts/gen-home-bento.mjs):+ * Genjutsu's own Group swap example first (a couple, both people swapped in one take; the studio's cover+ * "genjutsu-group-swap"), then a character swap by the lake. Each opens on the original clip, and a divider sweeps the+ * swapped take in across it. Its id in the playback store is its own, so a card lower down can play the same cover.+ * Each clip ends faded to dark: after `hold` ms on that dark frame the next fades in over it, in `fade` ms (two faces+ * are never laid over each other).*/-export const BENTO_GENJUTSU = { id: "home-genjutsu", cover: "genjutsu-group-swap", name: "genjutsu", original: "genjutsu-original" } as const;-/** The widths the Genjutsu clip comes in: its render is 1024 px wide, and nothing is made up past that (768 for a 2x laptop). */+export const BENTO_GENJUTSU = { id: "home-genjutsu", cover: "genjutsu-group-swap", hold: 100, fade: 400 } as const;+/** The widths the Genjutsu clips come in: their renders are about 1024 px wide, and nothing is made up past that. */export const BENTO_GENJUTSU_WIDTHS = [640, 768, 1024] as const;-/** The widths of the original's window (it shows at up to about 130 px wide: 480 covers a 3x screen). */-export const BENTO_ORIGINAL_WIDTHS = [240, 480] as const;-/** The example whose original clip's first frame the window shows (Genjutsu's Character swap example, src/lib/examples). */-export const GENJUTSU_ORIGINAL = "/examples/genjutsu-character/1/in-clip.jpg";/** The Canvas board the canvas tile draws: the same film as /canvas's "What's a canvas?". */export const BENTO_BOARD = "effect-chain-pearl-earring";/** The Live edit steps the live tile plays: the session's first three changes (Home's Live edit section plays them all). */@@ -88,6 +87,15 @@ export interface BentoReelTile {reel: ReelClip[];}+/**+ * The Genjutsu tile: a reel whose clips each show a swap under a divider (`wipes`, one per clip), and `still`, the first+ * clip with its divider at rest half way across, which the tile shows instead of the poster under reduced motion.+ */+export interface BentoWipeTile extends BentoReelTile {+ still: BentoPicture;+ wipes: ReelWipe[];+}+export interface BentoTile {key: BentoKey;/** The small line over the title: what kind of media, and how much of it. */@@ -206,6 +214,24 @@ export async function homeBento(f: BentoFacts) {}),};};+ // The Genjutsu tile's reel: each clip in its three widths; the first one's first frame as the poster, and the same+ // clip at rest half way across as the reduced-motion still (a JPEG of the poster for a browser without AVIF).+ const genjutsu = (): BentoWipeTile => {+ const first = HOME_BENTO_GENJUTSU[0].name;+ const fallback = made(`/previews/home/${first}-${BENTO_CLIP_FALLBACK}.jpg`);+ return {+ id: BENTO_GENJUTSU.id,+ poster: { avif: BENTO_GENJUTSU_WIDTHS.map((w) => ({ src: made(`/previews/home/${first}-${w}.avif`), w })), fallback, tint: HOME_BENTO_TINT[first] },+ still: { avif: BENTO_GENJUTSU_WIDTHS.map((w) => ({ src: made(`/previews/home/${first}-split-${w}.avif`), w })), fallback, tint: HOME_BENTO_TINT[first] },+ reel: HOME_BENTO_GENJUTSU.map((c) => ({+ id: c.name,+ hold: BENTO_GENJUTSU.hold,+ fade: BENTO_GENJUTSU.fade,+ clips: BENTO_GENJUTSU_WIDTHS.map((w) => ({ src: made(`/previews/home/${c.name}-${w}.mp4`), w })),+ })),+ wipes: HOME_BENTO_GENJUTSU.map(({ labels, fps, fadeFrom, line }) => ({ labels, fps, fadeFrom, line })),+ };+ };// A moving tile: its poster (the clip's first frame) and its clip, each in every width it comes in; for a browser// without AVIF, the 1024 px clip's first frame as a JPEG.const moving = (id: string, name: string, widths: readonly number[] = BENTO_CLIP_WIDTHS): BentoMovingTile => ({@@ -247,13 +273,7 @@ export async function homeBento(f: BentoFacts) {fallback: example(BENTO_IMAGE_EXAMPLE.out),} satisfies BentoPicture,threeD: moving(BENTO_CLIPS.threeD, BENTO_CLIP_FILES.threeD),- genjutsu: {- ...moving(BENTO_GENJUTSU.id, BENTO_GENJUTSU.name, BENTO_GENJUTSU_WIDTHS),- original: {- avif: BENTO_ORIGINAL_WIDTHS.map((w) => ({ src: made(`/previews/home/${BENTO_GENJUTSU.original}-${w}.avif`), w })),- fallback: example(GENJUTSU_ORIGINAL),- } satisfies BentoPicture,- },+ genjutsu: genjutsu(),wave: { bars: HOME_BENTO_WAVE.bars, seconds: HOME_BENTO_WAVE.seconds },live: { frames: BENTO_LIVE_STEPS.map(frame), phrases: livePhrases(demo) },canvas: board(),diff --git a/src/lib/home-reel.ts b/src/lib/home-reel.tsindex 1723bb6f..2d9c6ef4 100644--- a/src/lib/home-reel.ts+++ b/src/lib/home-reel.ts@@ -6,14 +6,15 @@import { pickWidth, type Sized } from "@/lib/media-pick";/**- * One clip of the reel: its preset, where the tile anchors it (object-position), and its copies in each width.+ * One clip of the reel: its preset (or its name, for a clip made for the tile), where the tile anchors it+ * (object-position; without one, the tile's stylesheet frames it), and its copies in each width.* `hold`: how long its last frame stays once it ends, before the next clip fades in over it (ms). Without one, the fade* starts a fade's length before its end. `fade`: how long its crossfade into the next clip takes (ms; REEL_FADE_MS* unless set).*/export interface ReelClip {id: string;- position: string;+ position?: string;clips: Sized[];hold?: number;fade?: number;@@ -52,3 +53,19 @@ export const fadeDue = (t: number, d: number, c: Pick<ReelClip, "fade" | "hold">/** How far through the whole reel it is (0 to 1), playing clip `i` of `n` at `t` of its `d` seconds. */export const reelProgress = (i: number, n: number, t: number, d: number): number => (i + (d > 0 ? Math.min(1, Math.max(0, t / d)) : 0)) / n;++/**+ * A clip that shows a swap as it happens (the Genjutsu tile, scripts/gen-home-bento.mjs WIPES): a divider sweeps across+ * it, the swapped take left of it and the original right of it. `labels`: the words for either side (the original,+ * then the swap). `line`: where the divider is on each frame, a share of the frame's width (under 0 or over 1 when it+ * is outside the frame). `fadeFrom`: the frame its fade to dark starts on (the words go with the picture).+ */+export interface ReelWipe {+ labels: readonly string[];+ fps: number;+ fadeFrom: number;+ line: readonly number[];+}++/** The frame of wipe `w` on screen at `t` seconds into its clip (its first or its last outside the clip). */+export const wipeFrame = (w: Pick<ReelWipe, "fps" | "line">, t: number): number => Math.min(w.line.length - 1, Math.max(0, Math.floor(t * w.fps + 0.01)));diff --git a/tests/e2e/home-bento.mjs b/tests/e2e/home-bento.mjsindex 2a13527a..5f389f89 100644--- a/tests/e2e/home-bento.mjs+++ b/tests/e2e/home-bento.mjs@@ -20,7 +20,8 @@// plays (up to the widest copy of that clip). No play sign on a tile that plays by itself, at any moment from the// first paint until both tiles play, and nothing shifts as a clip takes over from its still.// 1c. The swap: each tile's still is its clip's first frame (the clip at frame 0 over it differs by under 3 levels in-// 255 on average), at 390@3x and 1440@2x.+// 255 on average, read at CSS pixels: a browser scales a video and a picture with different filters, which shows+// only in single device pixels of fine detail), at 390@3x and 1440@2x.// 1d. The video tile's reel, at 390@3x and 1440@2x, light and dark: its still is Sand Storm's first frame; it plays Sand// Storm, then One Take, and back to Sand Storm, each crossfading into the next; each// clip framed as listed (its object-position); never more than the clip playing and the next one loaded, the next@@ -29,6 +30,12 @@// 1e. The reel when its second clip can't be had, at 1440@2x (Chromium): when that clip fails, the first loops and never// stops on a frame; when it comes 6 s late, the first plays again rather than stop on its last frame (never stuck// on one frame longer than REEL_STALL_MS and a little), and the second still comes in, at the end of a pass.+// 1f. Genjutsu's swaps, at 390@3x and 1440@2x (light and dark): its still is the couple's first frame with "Original"+// on it; it plays the couple, then the lake, and back, each clip coming in only over the last one's dark end; the+// words ride with the divider on every frame (where the clip's frame puts it, placed as the stylesheet says);+// never more than two clips, the next asked for only once the current one plays. A picture of the tile every+// 0.38 s through the loop, and a sheet of them (--shots). Under reduced motion the still is the couple at rest half+// way, the words either side of the divider.// 2. Layout shift under 0.01 at 390 and 1440, through a load and a scroll to the bottom and back.// 2b. The headline holds still when its parts come late, at 390@3x, 768 and 1440@2x (Chromium): with every font file// 2.5 s late, and with the HTML in two parts (cut after the second line's first words, 1.5 s apart, by a proxy) and@@ -90,7 +97,7 @@ const WIDTHS = [{ w: 1440, h: 900 },{ w: 1920, h: 1080 },];-const TILES = ["video", "live", "image", "threeD", "genjutsu", "audio", "numbers", "canvas"];+const TILES = ["video", "live", "genjutsu", "image", "threeD", "audio", "numbers", "canvas"];/** The tiles that play a clip by themselves (the reel, the 3D clip, Genjutsu's swap): each only once it is on screen. */const MOVING = ["video", "threeD", "genjutsu"];/** The widest copy of a clip (scripts/gen-home-bento.mjs), where its element doesn't say (a reel clip's data-max). */@@ -249,14 +256,25 @@ if (run("1"))const out = first.filter((t) => l.tiles[t].top < 0 || l.tiles[t].bottom > bottom);check(`${tag}: the video tile and the live tile 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));+ // Genjutsu right under the live tile, the full row wide, at 16:9 or taller.+ const [lv, gj] = [l.tiles.live, l.tiles.genjutsu];+ check(+ `${tag}: Genjutsu right after the live tile, full width, 16:9 or taller`,+ gj.top > lv.bottom && gj.top - lv.bottom < 24 && Math.abs(gj.w - lv.w) < 1 && gj.h / gj.w >= 9 / 16 - 0.005,+ `live ${Math.round(lv.w)}x${Math.round(lv.h)} to ${Math.round(lv.bottom)}, genjutsu ${Math.round(gj.w)}x${Math.round(gj.h)} from ${Math.round(gj.top)}`,+ );}- // The live tile is the highlight: the biggest after the video tile, its title no smaller than any but the video's.+ // The live tile, the highlight, and Genjutsu are the biggest after the video tile, the same size (the live tile+ // never the smaller), and their titles no smaller than any but the video's.const area = (t) => l.tiles[t].w * l.tiles[t].h;- const rest = TILES.filter((t) => t !== "video" && t !== "live" && t !== "numbers");+ const rest = TILES.filter((t) => !["video", "live", "genjutsu", "numbers"].includes(t));check(- `${tag}: the live tile second only to the video tile`,- rest.every((t) => area("live") > area(t) && l.tiles.live.title >= l.tiles[t].title) && area("video") > area("live"),- ["video", "live", ...rest].map((t) => `${t} ${Math.round(l.tiles[t].w)}x${Math.round(l.tiles[t].h)}/${l.tiles[t].title}`).join(", "),+ `${tag}: the live and Genjutsu tiles the same size, second only to the video tile`,+ area("live") >= area("genjutsu") * 0.98 &&+ area("genjutsu") >= area("live") * 0.85 &&+ rest.every((t) => area("genjutsu") > area(t) && l.tiles.live.title >= l.tiles[t].title && l.tiles.genjutsu.title >= l.tiles[t].title) &&+ area("video") > area("live"),+ ["video", "live", "genjutsu", ...rest].map((t) => `${t} ${Math.round(l.tiles[t].w)}x${Math.round(l.tiles[t].h)}/${l.tiles[t].title}`).join(", "),);if (v.w >= 1024) {const out = TILES.filter((t) => l.tiles[t].bottom > l.vh || l.tiles[t].top < 0);@@ -346,8 +364,11 @@ if (run("1b"))}// ------------------------------------------------------------------------------------------- 1c. the swap-/** How far the clip at frame 0 is from the still under it: the tile's clip area shot with the clip shown and hidden. */-async function swapDiff(page, tile) {+/**+ * How far the clip at frame 0 is from the still under it: the tile's clip area shot with the clip shown and hidden,+ * both read at CSS pixels (`dpr` device pixels to one).+ */+async function swapDiff(page, tile, dpr = 1) {const clip = page.locator(`#home-bento [data-tile=${tile}] .hb-clip`);await page.evaluate(async (tile) => {const v = document.querySelector(`#home-bento [data-tile=${tile}] video`);@@ -363,7 +384,8 @@ async function swapDiff(page, tile) {await page.evaluate((tile) => (document.querySelector(`#home-bento [data-tile=${tile}] video`).style.visibility = "hidden"), tile);const still = await clip.screenshot({ animations: "disabled" });const sharp = createRequire(path.join(root, "package.json"))("sharp");- const [a, b] = await Promise.all([withClip, still].map((x) => sharp(x).removeAlpha().raw().toBuffer()));+ const width = Math.round((await sharp(withClip).metadata()).width / dpr);+ const [a, b] = await Promise.all([withClip, still].map((x) => sharp(x).removeAlpha().resize(width, null, { kernel: "cubic" }).raw().toBuffer()));let sum = 0;for (let i = 0; i < a.length; i++) sum += Math.abs(a[i] - b[i]);return { diff: sum / a.length, withClip, still };@@ -385,8 +407,8 @@ if (run("1c"))continue;}const src = await page.evaluate((tile) => new URL(document.querySelector(`#home-bento [data-tile=${tile}] video`).currentSrc).pathname.split("/").pop(), tile);- const r = await swapDiff(page, tile);- check(`the swap at ${v.w}@${dpr}x, ${tile}: the still is ${src}'s first frame`, r.diff < 3, `mean difference ${r.diff.toFixed(2)} of 255`);+ const r = await swapDiff(page, tile, dpr);+ check(`the swap at ${v.w}@${dpr}x, ${tile}: the still is ${src}'s first frame`, r.diff < 3, `mean difference ${r.diff.toFixed(2)} of 255 at CSS pixels`);if (shotsDir) {fs.writeFileSync(path.join(shotsDir, `swap-${tile}-${v.w}@${dpr}x-clip.png`), r.withClip);fs.writeFileSync(path.join(shotsDir, `swap-${tile}-${v.w}@${dpr}x-still.png`), r.still);@@ -587,6 +609,189 @@ if (run("1e") && ENGINE === "chromium") {}}+// ------------------------------------------------------------------------------------------- 1f. Genjutsu's swaps+/**+ * The Genjutsu tile's reel (HOME_BENTO_GENJUTSU, read from src/lib/home-bento.generated.ts): each clip's copies' name,+ * its labels, and where its divider is on each frame.+ */+const GENJUTSU = JSON.parse(/export const HOME_BENTO_GENJUTSU = (\[[\s\S]*?\]);\r?\n/.exec(fs.readFileSync(path.join(root, "src/lib/home-bento.generated.ts"), "utf8"))[1]);+/**+ * Logs the Genjutsu tile's reel from the first paint: the clip on screen each time it changes, the most clips it holds+ * at once, when each first plays, and every moment the clip coming in shows over the one going out (with where that+ * one is: it must be on its dark last frames by then).+ */+const watchWipe = () => {+ window.__gj = { turns: [], most: 0, overlap: [], playing: {} };+ const look = () => {+ const span = document.querySelector("#home-bento [data-tile=genjutsu] .hb-clip");+ const g = window.__gj;+ if (span) {+ const at = span.dataset.reel;+ if (at !== undefined && g.turns.at(-1)?.i !== at) g.turns.push({ i: at, t: Date.now() });+ const vids = [...span.querySelectorAll("video")];+ g.most = Math.max(g.most, vids.length);+ for (const v of vids) if (!v.paused && !g.playing[v.dataset.clip]) g.playing[v.dataset.clip] = Date.now();+ // The time of the frame each clip has on screen (its own clock runs a little ahead of what is shown).+ for (const v of vids)+ if (!v.__watched && v.requestVideoFrameCallback) {+ v.__watched = true;+ const onFrame = (_, m) => {+ v.__presented = m.mediaTime;+ v.requestVideoFrameCallback(onFrame);+ };+ v.requestVideoFrameCallback(onFrame);+ }+ const shown = vids.filter((v) => v.hasAttribute("data-ready"));+ if (shown.length > 1) {+ const o = Number(getComputedStyle(shown.at(-1)).opacity);+ if (o > 0.02 && g.overlap.length < 400) g.overlap.push({ clip: shown[0].dataset.clip, t: shown[0].currentTime, ended: shown[0].ended, over: o });+ }+ }+ requestAnimationFrame(look);+ };+ requestAnimationFrame(look);+};+/** The tile, its words and its clip as they are now, each word's box measured from the tile's padding box. */+const wipeState = (page) =>+ page.evaluate(() => {+ const tile = document.querySelector("#home-bento [data-tile=genjutsu]");+ const wipe = tile.querySelector(".hb-wipe");+ const r = tile.getBoundingClientRect();+ const x0 = r.left + tile.clientLeft;+ const box = (sel) => {+ const b = wipe.querySelector(sel).getBoundingClientRect();+ return { l: b.left - x0, r: b.right - x0, text: wipe.querySelector(sel).textContent };+ };+ const shown = [...tile.querySelectorAll("video[data-ready]")];+ const top = shown.at(-1);+ const img = tile.querySelector("picture img");+ return {+ W: tile.clientWidth,+ H: tile.clientHeight,+ lg: innerWidth >= 1024,+ clip: top?.dataset.clip,+ t: top ? (top.__presented ?? top.currentTime) : undefined,+ paused: top?.paused,+ n: shown.length,+ x: wipe.style.getPropertyValue("--x") === "" ? null : Number(wipe.style.getPropertyValue("--x")),+ cssX: Number(getComputedStyle(wipe).getPropertyValue("--x")),+ out: wipe.hasAttribute("data-out"),+ opacity: Number(getComputedStyle(wipe).opacity),+ before: box("[class~=hb-wipe-before]"),+ after: box("[class~=hb-wipe-after]"),+ still: new URL(img.currentSrc || img.src).pathname.split("/").pop(),+ };+ });+/** Where the words should be with the divider at `x` (a share of the clip's width), in a W x H tile (home-bento.css). */+const wipeExpect = ({ W, H, lg }, x) => {+ const fw = lg ? Math.max(W, (H * 4) / 3) : W;+ const lx = x * fw - (fw - W) / 2;+ const [pad, gap] = W >= 340 ? [16, 9] : [12, 8];+ return { beforeL: Math.max(pad, lx + gap), afterR: Math.min(W - pad, lx - gap) };+};+const wipeFrameAt = (c, t) => Math.min(c.line.length - 1, Math.max(0, Math.floor(t * c.fps + 0.01)));+if (run("1f")) {+ for (const [v, dpr, scheme] of [+ [WIDTHS[0], 3, "light"],+ [WIDTHS[4], 2, "light"],+ [WIDTHS[4], 2, "dark"],+ ]) {+ const tag = `${v.w}@${dpr}x ${scheme}`;+ const ctx = await browser.newContext({ ...(v.phone ? PHONE : {}), viewport: { width: v.w, height: v.h }, deviceScaleFactor: dpr, colorScheme: scheme });+ const page = await ctx.newPage();+ const asked = [];+ page.on("request", (r) => {+ const m = /\/previews\/home\/(genjutsu-[a-z]+)-(\d+)\.mp4/.exec(r.url());+ if (m) asked.push({ name: m[1], w: Number(m[2]), t: Date.now() });+ });+ await page.addInitScript(watchWipe);+ await open(page);+ // A phone's Genjutsu tile is under the live tile: it plays once it is on screen.+ await page.locator("#home-bento [data-tile=genjutsu]").scrollIntoViewIfNeeded();+ const first = await wipeState(page);+ check(+ `genjutsu ${tag}: the still is ${GENJUTSU[0].name}'s first frame, "${GENJUTSU[0].labels[0]}" on it at the left`,+ first.still.startsWith(`${GENJUTSU[0].name}-`) && !first.still.includes("split") && first.before.text === GENJUTSU[0].labels[0] && first.before.l < 20 && first.after.r <= 0,+ JSON.stringify(first),+ );+ // Round the reel once and into its first clip again, sampling the words against the clip as it plays.+ const off = [];+ const frames = [];+ let samples = 0;+ const deadline = Date.now() + 32_000;+ let shot = 0;+ while (Date.now() < deadline) {+ const st = await wipeState(page);+ const turns = await page.evaluate(() => window.__gj.turns.map((x) => x.i));+ if (turns.length > GENJUTSU.length) break;+ const c = GENJUTSU.find((g) => g.name === st.clip);+ if (c && st.n === 1 && !st.paused && st.x !== null && !st.out) {+ samples++;+ const f = wipeFrameAt(c, st.t);+ // The words are a frame behind the clip at most (they move on the frame the browser presents).+ const near = [f - 1, f, f + 1].filter((i) => i >= 0 && i < c.line.length).some((i) => Math.abs(c.line[i] - st.x) < 0.0002);+ const e = wipeExpect(st, st.x);+ const placed = Math.abs(st.before.l - e.beforeL) < 1.5 && Math.abs(st.after.r - e.afterR) < 1.5;+ if (!near || !placed) off.push({ clip: st.clip, t: +st.t.toFixed(3), f, x: st.x, want: c.line[f], before: Math.round(st.before.l), wantBefore: Math.round(e.beforeL), after: Math.round(st.after.r), wantAfter: Math.round(e.afterR) });+ }+ if (shotsDir && Date.now() >= shot) {+ shot = Date.now() + 380;+ const f = path.join(shotsDir, `genjutsu-${v.w}-${scheme}-${String(frames.length).padStart(2, "0")}.png`);+ await page.locator("#home-bento [data-tile=genjutsu]").screenshot({ path: f });+ frames.push(f);+ } else await page.waitForTimeout(60);+ }+ const g = await page.evaluate(() => window.__gj);+ const seen = g.turns.map((x) => Number(x.i));+ check(`genjutsu ${tag}: plays its clips in order and back to the first`, seen.join() === [...GENJUTSU.keys(), 0].join(), seen.join());+ check(`genjutsu ${tag}: the words ride with the divider on every frame`, samples > 40 && off.length === 0, `${samples} samples; ${JSON.stringify(off.slice(0, 4))}`);+ check(+ `genjutsu ${tag}: a clip comes in only over the last one's dark end (no two faces at once)`,+ g.overlap.length > 0 && g.overlap.every((o) => o.ended || o.t >= 130 / 24),+ JSON.stringify(g.overlap.filter((o) => !(o.ended || o.t >= 130 / 24)).slice(0, 3)) + ` of ${g.overlap.length}`,+ );+ check(`genjutsu ${tag}: never more than the clip playing and the next one`, g.most <= 2, String(g.most));+ const firstAsk = (name) => asked.find((a) => a.name === name)?.t;+ const nextOk = GENJUTSU.slice(1).every((c, i) => firstAsk(c.name) !== undefined && g.playing[GENJUTSU[i].name] !== undefined && firstAsk(c.name) >= g.playing[GENJUTSU[i].name] - 100);+ check(`genjutsu ${tag}: each clip loads only once the one before it plays`, nextOk, `asked ${asked.map((a) => `${a.name}-${a.w}`).join(" ")}; playing ${JSON.stringify(g.playing)}`);+ notes.push(`genjutsu ${tag}: ${[...new Set(asked.map((a) => `${a.name}-${a.w}`))].join(", ")}; ${frames.length} frames shot`);+ if (frames.length) {+ const sharp = createRequire(path.join(root, "package.json"))("sharp");+ const W = v.phone ? 300 : 260;+ const bufs = await Promise.all(frames.map((f) => sharp(f).resize({ width: W }).png().toBuffer({ resolveWithObject: true })));+ const h = Math.max(...bufs.map((b) => b.info.height));+ const cols = 6;+ const rows = Math.ceil(bufs.length / cols);+ await sharp({ create: { width: cols * (W + 6) + 6, height: rows * (h + 6) + 6, channels: 3, background: "#777" } })+ .composite(bufs.map((b, i) => ({ input: b.data, left: 6 + (i % cols) * (W + 6), top: 6 + Math.floor(i / cols) * (h + 6) })))+ .jpeg({ quality: 85 })+ .toFile(path.join(shotsDir, `genjutsu-${v.w}-${scheme}-loop.jpg`));+ }+ await ctx.close();+ }++ // Reduced motion: the still is the couple at rest half way, "Original" and "Swapped" either side of the divider.+ for (const [v, dpr] of [+ [WIDTHS[0], 3],+ [WIDTHS[4], 2],+ ]) {+ const ctx = await browser.newContext({ ...(v.phone ? PHONE : {}), viewport: { width: v.w, height: v.h }, deviceScaleFactor: dpr, reducedMotion: "reduce" });+ const page = await ctx.newPage();+ await open(page);+ await page.locator("#home-bento [data-tile=genjutsu]").scrollIntoViewIfNeeded();+ await page.waitForTimeout(1200);+ const st = await wipeState(page);+ const e = wipeExpect(st, 0.5);+ check(+ `genjutsu reduced motion ${v.w}@${dpr}x: the still is split half way, the words either side of it`,+ st.still.startsWith(`${GENJUTSU[0].name}-split-`) && st.cssX === 0.5 && Math.abs(st.before.l - e.beforeL) < 1.5 && Math.abs(st.after.r - e.afterR) < 1.5 && st.n === 0,+ JSON.stringify(st),+ );+ if (shotsDir) await page.locator("#home-bento [data-tile=genjutsu]").screenshot({ path: path.join(shotsDir, `genjutsu-${v.w}-reduced.png`) });+ await ctx.close();+ }+}+// ------------------------------------------------------------------------------------------- 2. layout shiftasync function cls(v) {const ctx = await browser.newContext(viewportOpts(v));diff --git a/tests/home-bento.test.ts b/tests/home-bento.test.tsindex cdad254d..1ca40d41 100644--- a/tests/home-bento.test.ts+++ b/tests/home-bento.test.ts@@ -12,6 +12,7 @@ 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 { WIPES, lineAt } from "../scripts/gen-home-bento.mjs";import sharp from "sharp";import type { BentoPicture } from "@/lib/home-bento";import { coverWidth, pickWidth } from "@/lib/media-pick";@@ -30,7 +31,7 @@ vi.mock("next/navigation", () => ({useSearchParams: () => new URLSearchParams(),}));-const { BENTO_BOARD, BENTO_CLIPS, BENTO_CLIP_WIDTHS, BENTO_GENJUTSU, BENTO_GENJUTSU_WIDTHS, BENTO_HREFS, BENTO_IMAGE_EXAMPLE, BENTO_REEL, BENTO_REEL_ID, GENJUTSU_ORIGINAL, livePhrases, openModelsOf } =+const { BENTO_BOARD, BENTO_CLIPS, BENTO_CLIP_WIDTHS, BENTO_GENJUTSU, BENTO_GENJUTSU_WIDTHS, BENTO_HREFS, BENTO_IMAGE_EXAMPLE, BENTO_REEL, BENTO_REEL_ID, 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");@@ -85,24 +86,56 @@ describe("Home's first screen", () => {}});- it("plays Genjutsu's group swap in the widths its render covers, faded out before it loops (no crossfade), beside the original", () => {+ it("shows Genjutsu's swaps as they happen: a divider sweeps each swapped take in over the original, in step", () => {const g = bento.genjutsu;expect(g.id).toBe(BENTO_GENJUTSU.id);// Its own id in the playback store: the studio's card lower down may play the same cover.expect(g.id).not.toBe(BENTO_GENJUTSU.cover);- expect(g.clips.map((c) => c.w)).toEqual([...BENTO_GENJUTSU_WIDTHS]);- for (const c of g.clips) {- expect(c.src).toMatch(new RegExp(`^/previews/home/genjutsu-${c.w}\\.mp4\\?v=[0-9a-f]{8}$`));- expect(mp4Size(file(c.src))).toEqual({ w: c.w, h: (c.w * 3) / 4 });- // Five seconds of the take (120 frames at 24 fps), then its last frame held a third of a second as it fades out.- expect(mp4Seconds(file(c.src))).toBeCloseTo(128 / 24, 1);+ // The couple's group swap first (the studio's own example), then the character swap by the lake.+ expect(g.reel.map((c) => c.id)).toEqual(["genjutsu-couple", "genjutsu-lakeside"]);+ expect(g.wipes).toHaveLength(g.reel.length);+ for (const [i, c] of g.reel.entries()) {+ expect(c.clips.map((x) => x.w)).toEqual([...BENTO_GENJUTSU_WIDTHS]);+ for (const x of c.clips) {+ expect(x.src).toMatch(new RegExp(`^/previews/home/${c.id}-${x.w}\\.mp4\\?v=[0-9a-f]{8}$`));+ expect(mp4Size(file(x.src))).toEqual({ w: x.w, h: (x.w * 3) / 4 });+ // The whole take (124 frames at 24 fps), then its last frame held a third of a second as it fades to dark.+ expect(mp4Seconds(file(x.src))).toBeCloseTo(132 / 24, 1);+ }+ // It rests on its dark last frame before the next one fades in: two faces are never laid over each other.+ expect(c.hold).toBeGreaterThan(0);+ // The tile's stylesheet frames it (the same framing as its still).+ expect(c.position).toBeUndefined();+ const w = g.wipes[i];+ expect(w.labels).toEqual(["Original", "Swapped"]);+ expect(w.fps).toBe(24);+ expect(w.line).toHaveLength(132);+ expect(w.fadeFrom).toBe(124);+ // The divider starts off the frame (the original whole, as the poster shows it), sweeps one way only, and ends off+ // it (the swap whole); on every frame where the script drew it.+ expect(w.line[0]).toBeLessThan(0);+ expect(w.line.at(-1)).toBeGreaterThan(1);+ for (let f = 1; f < w.line.length; f++) expect(w.line[f]).toBeGreaterThanOrEqual(w.line[f - 1]);+ const made = WIPES.find((m) => m.name === c.id)!;+ for (let f = 0; f < w.line.length; f++) expect(w.line[f]).toBeCloseTo(lineAt(made.sweep, Math.min(f, made.frames - 1)), 4);+ }+ // The couple's divider rests half way, between the two (one swapped, one not): the reduced-motion still is a frame of it.+ const still = WIPES[0].still!;+ expect(g.wipes[0].line[still]).toBe(0.5);+ for (const [pic, name] of [+ [g.poster, "genjutsu-couple"],+ [g.still, "genjutsu-couple-split"],+ ] as const) {+ expect(pic.avif.map((a) => a.w)).toEqual([...BENTO_GENJUTSU_WIDTHS]);+ for (const a of pic.avif) expect(a.src).toMatch(new RegExp(`^/previews/home/${name}-${a.w}\\.avif\\?v=`));+ expect(pic.fallback).toMatch(/^\/previews\/home\/genjutsu-couple-1024\.jpg\?v=/);}- expect(g.poster.avif.map((a) => a.w)).toEqual([...BENTO_GENJUTSU_WIDTHS]);- for (const a of g.poster.avif) expect(a.src).toMatch(new RegExp(`^/previews/home/genjutsu-${a.w}\\.avif\\?v=`));- expect(g.poster.fallback).toMatch(/^\/previews\/home\/genjutsu-1024\.jpg\?v=/);- // The window: the original clip's first frame, the example's own published input.- expect(g.original.fallback.split("?")[0]).toBe(GENJUTSU_ORIGINAL);+ // The words either side of the divider, in the HTML from the first paint; the still under reduced motion.expect(html).toContain(">Original<");+ expect(html).toContain(">Swapped<");+ expect(html).toContain('<source media="(prefers-reduced-motion: reduce)" type="image/avif" srcSet="/previews/home/genjutsu-couple-split-640.avif?v=');+ // No small window beside it any more: the swap fills the tile.+ expect(html).not.toContain("hb-original");expect(bento.tiles.genjutsu.href).toBe("/genjutsu");});@@ -132,7 +165,7 @@ describe("Home's first screen", () => {});it("lists every picture at its real width", async () => {- const pictures: BentoPicture[] = [bento.video.poster, bento.threeD.poster, bento.image, bento.genjutsu.poster, bento.genjutsu.original, ...bento.live.frames];+ const pictures: BentoPicture[] = [bento.video.poster, bento.threeD.poster, bento.image, bento.genjutsu.poster, bento.genjutsu.still, ...bento.live.frames];for (const p of pictures)for (const a of p.avif) {const m = await sharp(file(a.src)).metadata();@@ -165,11 +198,14 @@ describe("Home's first screen", () => {}// The live tile, the next biggest, covers a 3x phone (358 px wide) and its tile on a 2x 1440 screen (405 px under cover).for (const f of bento.live.frames) expect(Math.max(...f.avif.map((a) => a.w))).toBeGreaterThanOrEqual(Math.max(358 * 3, 405 * 2));- // Genjutsu's clip is never made up past its render's own 1024 px: a 2x laptop's tile (376 px) gets 768, a 3x phone 1024.- expect(pickWidth(bento.genjutsu.clips, 376 * 2).w).toBe(768);- expect(pickWidth(bento.genjutsu.clips, 358 * 3).w).toBe(1024);- // The original's window (at most 132 px) is covered on a 3x screen.- expect(Math.max(...bento.genjutsu.original.avif.map((a) => a.w))).toBeGreaterThanOrEqual(132 * 3);+ // Genjutsu's clips are never made up past their renders' own 1024 px: its tile on a 1x 1440 screen (319 x 308, so+ // 411 px under cover) gets 640, a box that needs 700 px 768, and a 2x laptop and a 3x phone 1024.+ for (const c of bento.genjutsu.reel) {+ expect(pickWidth(c.clips, coverWidth(319, 308, 4 / 3, 1)).w).toBe(640);+ expect(pickWidth(c.clips, 700).w).toBe(768);+ expect(pickWidth(c.clips, coverWidth(319, 308, 4 / 3, 2)).w).toBe(1024);+ expect(pickWidth(c.clips, 358 * 3).w).toBe(1024);+ }});it("opens a real page from every tile, named by the navigation or the catalog", () => {@@ -197,7 +233,7 @@ describe("Home's first screen", () => {it("makes every tile one link with a name, in the grid's reading order", () => {const links = [...html.matchAll(/<a [^>]*>/g)].map((m) => m[0]);const tiles = links.filter((a) => a.includes("data-tile="));- expect(tiles.map((a) => /data-tile="([^"]+)"/.exec(a)![1])).toEqual(["video", "live", "image", "threeD", "genjutsu", "audio", "numbers", "canvas"]);+ expect(tiles.map((a) => /data-tile="([^"]+)"/.exec(a)![1])).toEqual(["video", "live", "genjutsu", "image", "threeD", "audio", "numbers", "canvas"]);for (const a of tiles) {const label = /aria-label="([^"]+)"/.exec(a)?.[1];expect(label, a).toBeTruthy();