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: the video tiles open on their clip's first frame, with no play sign
Adarsh6fd9ad7445b3
diff --git a/public/previews/home/catwalk-1024.avif b/public/previews/home/catwalk-1024.avifindex e063c4bc..a87aec29 100644Binary files a/public/previews/home/catwalk-1024.avif and b/public/previews/home/catwalk-1024.avif differdiff --git a/public/previews/home/catwalk-1024.mp4 b/public/previews/home/catwalk-1024.mp4index 044050bd..e01197f1 100644Binary files a/public/previews/home/catwalk-1024.mp4 and b/public/previews/home/catwalk-1024.mp4 differdiff --git a/public/previews/home/catwalk-640.avif b/public/previews/home/catwalk-640.avifindex 54b7ffab..71439827 100644Binary files a/public/previews/home/catwalk-640.avif and b/public/previews/home/catwalk-640.avif differdiff --git a/public/previews/home/catwalk-640.mp4 b/public/previews/home/catwalk-640.mp4index ed21cad1..66c53cec 100644Binary files a/public/previews/home/catwalk-640.mp4 and b/public/previews/home/catwalk-640.mp4 differdiff --git a/public/previews/home/rotation-1024.avif b/public/previews/home/rotation-1024.avifindex ddb620fa..3f8e0cd5 100644Binary files a/public/previews/home/rotation-1024.avif and b/public/previews/home/rotation-1024.avif differdiff --git a/public/previews/home/rotation-1024.mp4 b/public/previews/home/rotation-1024.mp4index 6ac93483..4ff55f5e 100644Binary files a/public/previews/home/rotation-1024.mp4 and b/public/previews/home/rotation-1024.mp4 differdiff --git a/public/previews/home/rotation-640.avif b/public/previews/home/rotation-640.avifindex 5b583708..51626bf7 100644Binary files a/public/previews/home/rotation-640.avif and b/public/previews/home/rotation-640.avif differdiff --git a/public/previews/home/rotation-640.mp4 b/public/previews/home/rotation-640.mp4index 5bcad315..415905ef 100644Binary files a/public/previews/home/rotation-640.mp4 and b/public/previews/home/rotation-640.mp4 differdiff --git a/scripts/gen-home-bento.mjs b/scripts/gen-home-bento.mjsindex 667b5318..8269941c 100644--- a/scripts/gen-home-bento.mjs+++ b/scripts/gen-home-bento.mjs@@ -6,7 +6,7 @@* published clip was cut from, so the tiles show exactly what the studios show, only sharper.** 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+ * catwalk-{640,1024}.{mp4,avif} the catwalk clip at two widths, and each one's first frame as its 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)@@ -16,13 +16,19 @@** 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).+ * faststart, no sound), tagged BT.709 so every browser shows its colours the same way. Each tile picks the width its+ * box needs on the screen it is on (bento-islands.tsx).+ *+ * The posters: each clip's own first frame, decoded from the encoded file the way a browser shows it (BT.709, limited+ * range), at POSTER_QUALITY: the tile shows it until its clip plays, and the clip takes over on that same frame, so the+ * swap can't be seen. They are made again from the clips on every run, with or without masters.** 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.+ * Without it those files are kept as they are (and versioned), the posters are made again from the clips kept, and so+ * is the rest.** 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@@ -84,6 +90,10 @@ const MASTER_STILLS = ["before", "after"].flatMap((side) => []);/** 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 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. */const THUMB = 168;@@ -96,8 +106,8 @@ const ffmpeg = (args, input) => {/*** 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).+ * CLIP_SECONDS (and the frames the crossfade takes back), looped without a seam unless it loops already. Returns its+ * y4m stream.*/function loopAt(src, width) {const seconds = CLIP_SECONDS + LOOP_FADE / CLIP_FPS;@@ -106,7 +116,7 @@ function loopAt(src, width) {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 };+ return { all: stream(looped), 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. */@@ -121,7 +131,12 @@ function encodeClipBuffer(y4m, crf) {}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);+ 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", "-"]);}/** The sample's loudness in `bars` slices, 0..1, the loudest 1, none under `floor`. */@@ -151,15 +166,7 @@ async function main() {// 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() },- ];- }),+ CLIP_WIDTHS.map((w) => ({ name: `${c.name}-${w}.mp4`, clip: true, make: () => encodeClipBuffer(loopAt(master(`${c.key}.mp4`), w).all, c.crf) })),),...MASTER_STILLS.map((s) => ({...s,@@ -183,7 +190,16 @@ async function main() {}if (!DRY) versions[`/previews/home/${s.name}`] = contentVersion([out]);}+ // Each clip's poster, from the clip as it is now (just made, or kept).+ const posters = CLIPS.flatMap((c) => CLIP_WIDTHS.map((w) => ({ name: `${c.name}-${w}.avif`, clip: `${c.name}-${w}.mp4` })));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();+ },+ })),...STILLS.map((s) => ({...s,make: () => {diff --git a/src/components/home/bento-islands.tsx b/src/components/home/bento-islands.tsxindex 79c835a6..41ae18d6 100644--- a/src/components/home/bento-islands.tsx+++ b/src/components/home/bento-islands.tsx@@ -1,6 +1,6 @@"use client";-import { Play, Zap } from "lucide-react";+import { Zap } from "lucide-react";import { useEffect, useRef, useState, useSyncExternalStore } from "react";import { useNavUi } from "@/components/nav/nav-ui";import { usePreviewPlayback, usePreviewsPaused } from "@/components/preset-preview";@@ -15,7 +15,7 @@ import { s } from "./home-bento-classes";* tile and the numbers tile's launcher. Everything else on it is HTML from the server.*/-/** Whether the page has loaded (the clips wait for it) and whether the first screen may move now (BentoMotion). */+/** Whether the page has loaded (the first screen's animations wait for it) and whether it may move now (BentoMotion). */const motion = (() => {let loaded = false;let play = false;@@ -41,7 +41,6 @@ const motion = (() => {};})();-const useLoaded = () => useSyncExternalStore(motion.subscribe, motion.loaded, () => false);const usePlay = () => useSyncExternalStore(motion.subscribe, motion.play, () => false);/** Runs `cb` once the page has loaded and the browser is idle: the first screen's stills come first. */@@ -111,16 +110,51 @@ export function BentoMotion({ target }: { target: string }) {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: 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.+ * Calls `cb` once the tile's own still (the picture before `el` in its tile) has loaded and been painted, and the+ * browser has a moment: the still is the first thing the tile shows, and the clip never holds it up.*/-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: clips[0].src } : {});+function afterStill(el: HTMLElement, cb: () => void): () => void {+ const img = el.parentElement?.querySelector<HTMLImageElement>("picture img");+ let raf = 0;+ let idle = 0;+ const go = () => {+ raf = requestAnimationFrame(() => {+ if (typeof requestIdleCallback === "function") idle = requestIdleCallback(cb, { timeout: 600 });+ else idle = window.setTimeout(cb, 100);+ });+ };+ if (!img || (img.complete && img.naturalWidth > 0)) go();+ else {+ img.addEventListener("load", go, { once: true });+ img.addEventListener("error", go, { once: true });+ }+ return () => {+ img?.removeEventListener("load", go);+ img?.removeEventListener("error", go);+ cancelAnimationFrame(raf);+ if (typeof cancelIdleCallback === "function") cancelIdleCallback(idle);+ clearTimeout(idle);+ };+}++/**+ * A tile's clip, over its still: it joins the site's playback rules (preset-preview.tsx) as soon as the tile's still is+ * on screen (not only once the whole 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: 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. The still is that clip's own first frame+ * (scripts/gen-home-bento.mjs), and the clip shows only once it has that frame, so the change from one to the other+ * can't be seen: no sign, no flash, nothing moves. Once started it stays mounted and pauses on its frame. `progress`: a+ * line along the bottom follows the clip.+ */+export function BentoClip({ id, clips, progress }: { id: string; clips: Sized[]; progress?: boolean }) {+ const [armed, setArmed] = useState(false);+ const { ref, playing, handlers } = usePreviewPlayback<HTMLSpanElement>(id, armed ? { video: clips[0].src } : {});+ useEffect(() => {+ const el = ref.current;+ if (!el) return;+ return afterStill(el, () => setArmed(true));+ }, [ref]);// The pixels of width the tile needs, kept up to date with its size until the clip starts.const [need, setNeed] = useState(0);useEffect(() => {@@ -184,11 +218,6 @@ export function BentoClip({ id, clips, progress, glyph }: { id: string; clips: Sreturn (<span ref={ref} aria-hidden className={s.clip} onPointerEnter={handlers.onPointerEnter} onPointerLeave={handlers.onPointerLeave}>{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" />- </span>- )}{progress && (<span className={s.progress}><i ref={bar} />diff --git a/src/components/home/home-bento-classes.ts b/src/components/home/home-bento-classes.tsindex aafd6abb..b212428b 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","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;+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","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 fe8772da..fa34c316 100644--- a/src/components/home/home-bento.css+++ b/src/components/home/home-bento.css@@ -506,35 +506,6 @@text-transform: uppercase;pointer-events: none;}-.hb-play-glyph {- position: absolute;- left: 50%;- top: 42%;- display: grid;- place-items: center;- width: 64px;- height: 64px;- margin: -32px 0 0 -32px;- border-radius: 999px;- background: rgb(13 13 15 / 55%);- border: 1px solid rgb(255 255 255 / 35%);- backdrop-filter: blur(6px);- pointer-events: none;- transition: opacity 0.4s ease;-}-.hb-play-glyph svg {- margin-left: 3px;-}-.hb-play-glyph[data-on] {- opacity: 0;-}-@container (min-width: 460px) {- .hb-play-glyph {- width: 76px;- height: 76px;- margin: -38px 0 0 -38px;- }-}.hb-progress {position: absolute;inset: auto 0 0;@@ -1120,8 +1091,7 @@/* Reduced motion: whatever data-play says, nothing moves by itself, and a hover doesn't lift a tile. */@media (prefers-reduced-motion: reduce) {.hb-tile,- .hb-frame,- .hb-play-glyph {+ .hb-frame {transition: none;}.hb-tile:hover {diff --git a/src/components/home/home-bento.tsx b/src/components/home/home-bento.tsxindex 77bfeb4f..0b30b70a 100644--- a/src/components/home/home-bento.tsx+++ b/src/components/home/home-bento.tsx@@ -173,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} clips={bento.video.clips} progress glyph />+ <BentoClip id={bento.video.id} clips={bento.video.clips} progress /><span aria-hidden className={s.badge}><Video className="size-3.5" /> Video</span>diff --git a/src/lib/home-bento.generated.ts b/src/lib/home-bento.generated.tsindex a612bfac..57842d16 100644--- a/src/lib/home-bento.generated.ts+++ b/src/lib/home-bento.generated.ts@@ -4,14 +4,10 @@* scripts/gen-home-bento.mjs: run it again rather than editing.*/export const HOME_BENTO_MEDIA: Record<string, string> = {- "/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/catwalk-640.mp4": "195683c9",+ "/previews/home/catwalk-1024.mp4": "0cfc2824",+ "/previews/home/rotation-640.mp4": "3efbab2a",+ "/previews/home/rotation-1024.mp4": "3f5507ab","/previews/home/ba-before-640.avif": "8adbdbd7","/previews/home/ba-before-960.avif": "7f7f2735","/previews/home/ba-before-1280.avif": "7b757bc9",@@ -22,6 +18,10 @@ export const HOME_BENTO_MEDIA: Record<string, string> = {"/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/catwalk-640.avif": "a5c7089b",+ "/previews/home/catwalk-1024.avif": "be920778",+ "/previews/home/rotation-640.avif": "c69b0d7b",+ "/previews/home/rotation-1024.avif": "23d2a89b","/previews/home/image-4-480.avif": "5a6d07a1","/previews/home/image-4-768.avif": "ef9d1b4d","/previews/home/board-photo.webp": "47432641",diff --git a/tests/e2e/home-bento.mjs b/tests/e2e/home-bento.mjsindex 7644aed7..ed4a3e52 100644--- a/tests/e2e/home-bento.mjs+++ b/tests/e2e/home-bento.mjs@@ -13,14 +13,18 @@// 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.+// plays. No play sign on a tile that plays by itself, at any moment from the first paint until both clips 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.// 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 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 300 KB. The clips it fetches after load are reported on their own.+// stills stay under 340 KB (the clips' posters are encoded close to their clips' first frames). The clips 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";@@ -208,14 +212,41 @@ if (!weightOnly)}}+/**+ * Watches the first screen from the first paint: every play sign seen on a tile that plays by itself (the video and 3D+ * tiles), when each clip first showed, and every layout shift, with its time.+ */+const watchSwap = () => {+ window.__signs = [];+ window.__shown = {};+ window.__shifts2 = [];+ new PerformanceObserver((list) => {+ for (const e of list.getEntries()) if (!e.hadRecentInput) window.__shifts2.push({ v: e.value, at: Math.round(e.startTime) });+ }).observe({ type: "layout-shift", buffered: true });+ const look = () => {+ for (const t of ["video", "threeD"]) {+ const tile = document.querySelector(`#home-bento [data-tile=${t}]`);+ if (!tile) continue;+ for (const el of tile.querySelectorAll("svg.lucide-play, [class*=play-glyph]")) {+ const st = getComputedStyle(el);+ if (el.getBoundingClientRect().width > 0 && st.visibility !== "hidden" && Number(st.opacity) > 0) window.__signs.push({ t, at: Math.round(performance.now()) });+ }+ if (!window.__shown[t] && tile.querySelector("video[data-ready]")) window.__shown[t] = Math.round(performance.now());+ }+ if (performance.now() < 15_000 && !(window.__shown.video && window.__shown.threeD)) requestAnimationFrame(look);+ };+ requestAnimationFrame(look);+};+// ------------------------------------------------------------------------------------------- 1b. sharp at every ratioif (!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 page.addInitScript(watchSwap);await open(page);- // The clips start after load, once on screen: wait until each has its first frame.+ // The clips start once their tile's still is up and 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(() => {});@@ -229,9 +260,63 @@ if (!weightOnly)(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(", ")}`);+ const w = await page.evaluate(() => ({ signs: window.__signs, shown: window.__shown, shifts: window.__shifts2, load: Math.round(performance.getEntriesByType("navigation")[0]?.loadEventEnd ?? 0) }));+ check(`no play sign at ${v.w}@${dpr}x on the tiles that play by themselves`, w.signs.length === 0, JSON.stringify(w.signs.slice(0, 3)));+ // Nothing shifts as a clip takes over from its still (from 100 ms before it shows to 600 ms after).+ const atSwap = w.shifts.filter((x) => Object.values(w.shown).some((t) => x.at >= t - 100 && x.at <= t + 600));+ check(`no layout shift at the swap at ${v.w}@${dpr}x`, atSwap.length === 0 && Object.keys(w.shown).length === 2, `${JSON.stringify(w.shown)} load ${w.load}; ${JSON.stringify(atSwap)}`);+ if (dpr === 2 || (v.phone && dpr === 3)) notes.push(`clips shown at ${v.w}@${dpr}x: video ${w.shown.video} ms, 3D ${w.shown.threeD} ms (load ${w.load} ms)`);await ctx.close();}+// ------------------------------------------------------------------------------------------- 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) {+ 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`);+ v.pause();+ v.currentTime = 0;+ await new Promise((r) => (v.seeking ? v.addEventListener("seeked", r, { once: true }) : r()));+ // Then two frames of the page, so the seeked frame is on screen (a paused clip presents no further frames).+ await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(r, 100))));+ // The line along the bottom follows the clip: out of both shots.+ for (const el of document.querySelectorAll(`#home-bento [data-tile=${tile}] .hb-progress`)) el.style.visibility = "hidden";+ }, tile);+ const withClip = await clip.screenshot({ animations: "disabled" });+ 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()));+ 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 };+}+if (!weightOnly)+ 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 });+ const page = await ctx.newPage();+ await open(page);+ await page.waitForFunction(() => document.querySelectorAll("#home-bento [data-tile] video[data-ready]").length >= 2, null, { timeout: 12_000 }).catch(() => {});+ for (const tile of ["video", "threeD"]) {+ if (!(await page.locator(`#home-bento [data-tile=${tile}] video[data-ready]`).count())) {+ check(`the swap at ${v.w}@${dpr}x, ${tile}: its clip plays`, false);+ 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`);+ 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);+ }+ }+ await ctx.close();+ }+// ------------------------------------------------------------------------------------------- 2. layout shiftasync function cls(v) {const ctx = await browser.newContext(viewportOpts(v));@@ -352,7 +437,7 @@ if (!weightOnly) {return v && !v.paused && v.currentTime > 0.2;}, null, { timeout: 8000 }).catch(() => {});const before = await playing();- check("the catwalk plays by itself after load", !!before && !before.paused, JSON.stringify(before));+ check("the catwalk plays by itself", !!before && !before.paused, JSON.stringify(before));await page.getByRole("button", { name: "Pause previews" }).click();await page.waitForTimeout(400);const after = await page.evaluate(() => ({@@ -383,7 +468,7 @@ 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).+ // The clips come once their stills are up: 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) => {@@ -434,7 +519,7 @@ async function weight(v) {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"})`,+ 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 ${kb(clipBytes)} (${clipLine || "none"})`,media,};}@@ -442,7 +527,7 @@ 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 < 300 * 1024);+ check(`weight before load, clips aside: ${r.line}`, weightOnly || r.own < 340 * 1024);notes.push(`weight ${r.line}`);notes.push(` first screen's stills: ${r.media.join(" · ")}`);}