Logo Collapse
Logo reveal intro: a stack of photos flicks through and collapses into your logo. A stack of shots flicked through, collapsing into your mark, and the wordmark landing beside it.
Source
components/kuchi/logo-collapse.tsx
1"use client";23import { loadFont as loadSans } from "@remotion/google-fonts/InterTight";4import type { CSSProperties } from "react";5import { forwardRef, useCallback, useState } from "react";6import {7 AbsoluteFill,8 continueRender,9 delayRender,10 getRemotionEnvironment,11 staticFile,12 useCurrentFrame,13 useVideoConfig,14} from "remotion";15import {16 Item,17 resolveFont,18 type KuchiTheme,19 useKuchiTheme,20} from "@/lib/kuchi-ui";2122/**23 * A stack of shots flicked through, collapsing into the mark, and the wordmark24 * landing beside it.25 *26 * One square card holds the middle of the frame and cuts to the next shot, each27 * one smaller and each held for less time than the last, so the sequence winds28 * itself up rather than running at a constant clip. At the end of the run the29 * card does not shrink away — it *collapses*, overshooting past its resting size30 * in a frame and settling back. Then the mark steps aside and the wordmark takes31 * the space it made.32 *33 * ## The cuts are cuts34 *35 * Nothing cross-fades and nothing tweens between shots. The reference holds each36 * card at a fixed size for its whole beat — measured, the box is constant to the37 * pixel across every frame of a hold, and then a different size on the next one.38 * A card that eased between sizes would read as a zoom; a card that cuts reads as39 * a stack of prints being dealt, which is the whole idea.40 *41 * That is also why `sizes` and `holds` are parallel lists of literals rather than42 * a ratio and a duration. The reference's own run is 0.512, 0.476, 0.458, 0.414,43 * 0.339 of the frame height on beats of 1, 6, 5, 4, 2 and 4 frames — neither44 * series is geometric, and a formula that fitted one would miss the other.45 *46 * ## The collapse overshoots47 *48 * 30px, then 24, then 22, on three consecutive frames. Two frames of overshoot is49 * the difference between a mark that lands and a mark that is simply smaller than50 * the card was — and it is the only place in the scene where anything moves51 * between frames rather than cutting.52 *53 * ## The mark steps aside in two54 *55 * Centred alone at 294.5; then 282.0 for four frames; then 248.5 as the wordmark56 * appears whole. Two steps, held, not an ease — the same grammar as the cards.57 */5859const { fontFamily: SANS } = loadSans("normal", {60 weights: ["600", "700"],61 subsets: ["latin"],62});6364/* ─────────────────────────────────────────────────────────────────────────65 The stage, in the recording's own 592 × 336 pixels66 ───────────────────────────────────────────────────────────────────────── */6768export const REF_W = 592;69export const REF_H = 336;7071/** Where the card, and then the mark, sits. */72export const STAGE_X = 294;73export const STAGE_Y = 167.5;7475/**76 * The mark's box, frame by frame, from the moment the stack runs out.77 *78 * It lands oversized and settles in three steps rather than easing: 32, 25, 24,79 * then 23 for the rest of the scene. Measured on the mark's orange core, which80 * is the only part of it a threshold can find honestly — the glow around it81 * reads as ink to anything looser and makes the landing look 40% bigger than it82 * is.83 */84export const MARK = 22;85export const LAND: readonly number[] = [32, 25, 24, 24];8687/**88 * The tile the stack collapses onto, before the mark is left alone.89 *90 * This is the beat that is easy to miss and impossible to unsee: the photo card91 * does not shrink into the mark, it *cuts* to a plain light tile of 60px with92 * the mark sitting on it, holds for two frames, and only then does the tile go.93 * It is very faint — luma 233 against the page's 247, which is why nothing94 * thresholded at 200 finds it — and it is what makes the collapse read as a95 * stack of prints resolving into a logo rather than as a card that shrank.96 */97export const TILE = 60;98export const TILE_FRAMES = 2;99100/** Left edge of the finished lockup, and where the word starts inside it. */101export const LOCK_X = 237;102export const WORD_X = 264;103104/** Cap height of the wordmark, measured on its own ink. */105export const WORD_CAP = 19.37;106/** Top of the wordmark's box. Measured, not derived from a line-height ratio. */107export const WORD_TOP = 155.74;108/**109 * Cap height → font-size, and the tracking a logotype is set at.110 *111 * A wordmark is lettering, not type: the reference's is 4.149 cap-widths for six112 * glyphs, and the nearest face on the shelf sets the same six at 4.634 — twelve113 * per cent loose. That gap is tracking, not the wrong face. Inter Tight at114 * −0.073em closes it; every other candidate measured wider still (Archivo 4.786,115 * Plus Jakarta 4.877, Space Grotesk 4.975, Manrope 5.011, Poppins 5.715).116 */117export const WORD_EM = 1.326;118export const WORD_TRACK = -0.073;119120/** The mark's waypoint: where it waits before the wordmark arrives. */121export const STEP_X = 281.5;122123/** Frames, on the scene's own 30fps clock. */124export const STEP_AT = 28;125export const WORD_AT = 30;126export const DOT_AT: readonly number[] = [37, 42];127128/**129 * The two marks that bracket the lockup, and the ping each one arrives on.130 *131 * They do not simply appear: each lands at 7px in full accent and settles to 4px132 * and about a third of its ink over five frames. Measured on both — the upper133 * one is already pale and small by the frame the lower one lands, which is the134 * only reason you can tell they are two beats and not one.135 */136export const DOTS: readonly (readonly [number, number])[] = [137 [229, 147],138 [229, 191],139];140export const DOT_IN = 7;141export const DOT_OUT = 4;142export const DOT_SETTLE = 5;143export const DOT_FADE = 0.34;144145export interface LogoCollapseProps {146 /**147 * The shots, split by `|`. The card cuts through them in order.148 *149 * Not by comma: a `data:` URL has one of its own right after the encoding, and150 * splitting on it hands the browser half a URL and a card that renders as a151 * broken-image glyph.152 */153 images?: string;154 /**155 * Each shot's card, as a share of the frame height.156 *157 * `0.48` is a square; `0.515x0.5625` is a portrait one. Real photo sets are158 * not all one shape, and the reference's second shot is measurably taller159 * than it is wide — forcing it square crops fifteen pixels off a print that160 * was never square.161 */162 sizes?: string;163 /** Frames each shot is held for. */164 holds?: string;165 /** The mark the stack collapses into. */166 mark?: string;167 /** The word that lands beside it. */168 wordmark?: string;169 /** Optional plate behind everything — a paper, a gradient, a still. */170 background?: string;171 /** The brand colour the two bracket marks ping in. Blank uses the accent. */172 accent?: string;173 theme?: Partial<KuchiTheme>;174 mode?: "light" | "dark";175 fontFamily?: string;176}177178export function LogoCollapse({179 images = "https://kuchi-media.kalarislabs.com/components/art/art-08.svg|https://kuchi-media.kalarislabs.com/components/art/art-01.svg|https://kuchi-media.kalarislabs.com/components/art/art-07.svg|https://kuchi-media.kalarislabs.com/components/art/art-04.svg|https://kuchi-media.kalarislabs.com/components/art/art-04.svg|https://kuchi-media.kalarislabs.com/components/art/art-01.svg",180 sizes = "0.82x0.461,0.72x0.405,0.63x0.354,0.55x0.309,0.46x0.259,0.36x0.203",181 holds = "1,5,5,4,2,5",182 mark = "https://kuchi-media.kalarislabs.com/components/art/mark.svg",183 wordmark = "kuchi",184 background = "",185 accent = "",186 theme,187 mode = "light",188 fontFamily = "Default",189}: LogoCollapseProps) {190 const frame = useCurrentFrame();191 const { width, height } = useVideoConfig();192 const t = useKuchiTheme(theme, mode);193 const face = resolveFont(fontFamily) ?? SANS;194195 const u = height / REF_H;196 const ox = (width - REF_W * u) / 2;197198 const shots = images199 .split("|")200 .map((s) => s.trim())201 .filter(Boolean);202 const size = sizes.split(",").map((s) => {203 const [w, h] = s.trim().split("x");204 const sw = Number(w);205 return [sw, h === undefined ? sw : Number(h)] as const;206 });207 const hold = holds.split(",").map((s) => Number(s.trim()));208209 // Which shot is up, and the frame the stack runs out on.210 let at = 0;211 let shot = -1;212 for (let i = 0; i < shots.length; i++) {213 const end = at + (hold[i] ?? 0);214 if (frame < end) {215 shot = i;216 break;217 }218 at = end;219 }220 const collapseAt = hold221 .slice(0, shots.length)222 .reduce((a, b) => a + (b || 0), 0);223224 const ink = t.foreground;225226 return (227 <AbsoluteFill style={{ backgroundColor: t.background }}>228 {background && (229 <Plate230 src={background}231 style={{ position: "absolute", inset: 0, objectFit: "cover" }}232 />233 )}234 <div235 style={{236 position: "absolute",237 left: ox,238 top: 0,239 width: REF_W * u,240 height: REF_H * u,241 fontFamily: face,242 textRendering: "geometricPrecision",243 }}244 >245 {shot >= 0 ? (246 <Item key={shot} index={shot}>247 <Plate248 src={shots[shot] ?? ""}249 style={box(250 (size[shot]?.[0] ?? 0.4) * REF_H,251 (size[shot]?.[1] ?? 0.4) * REF_H,252 STAGE_X,253 STAGE_Y,254 u,255 )}256 />257 </Item>258 ) : (259 <Lockup260 frame={frame}261 since={frame - collapseAt}262 mark={mark}263 word={wordmark}264 ink={ink}265 accent={accent || t.primary}266 tile={t.muted}267 u={u}268 />269 )}270 </div>271 </AbsoluteFill>272 );273}274275/** A box of `w × h` reference pixels centred on `(cx, cy)`, in real pixels. */276function box(277 w: number,278 h: number,279 cx: number,280 cy: number,281 u: number,282): CSSProperties {283 return {284 position: "absolute",285 left: (cx - w / 2) * u,286 top: (cy - h / 2) * u,287 width: w * u,288 height: h * u,289 objectFit: "cover",290 };291}292293/** The tile, the mark landing, stepping aside, and the word arriving. */294function Lockup({295 frame,296 since,297 mark,298 word,299 ink,300 accent,301 tile,302 u,303}: {304 /** The scene's own frame, which the beats below are written in. */305 frame: number;306 /** Frames since the stack ran out, which the landing is written in. */307 since: number;308 mark: string;309 word: string;310 ink: string;311 accent: string;312 tile: string;313 u: number;314}) {315 const size = LAND[since] ?? MARK;316 const worded = frame >= WORD_AT;317 const cx = worded ? LOCK_X + MARK / 2 : frame >= STEP_AT ? STEP_X : STAGE_X;318 return (319 <>320 {since < TILE_FRAMES && (321 <div322 style={{323 ...box(TILE, TILE, STAGE_X, STAGE_Y, u),324 background: tile,325 }}326 />327 )}328 <Plate src={mark} style={box(size, size, cx, STAGE_Y, u)} />329 {worded && (330 <div331 style={{332 position: "absolute",333 left: WORD_X * u,334 top: WORD_TOP * u,335 fontSize: WORD_CAP * WORD_EM * u,336 lineHeight: 1,337 fontWeight: 700,338 letterSpacing: `${WORD_TRACK}em`,339 color: ink,340 whiteSpace: "nowrap",341 }}342 >343 {word}344 </div>345 )}346 {DOTS.map(([dx, dy], i) => {347 const since = frame - (DOT_AT[i] ?? Number.POSITIVE_INFINITY);348 if (since < 0) return null;349 const k = Math.min(1, since / DOT_SETTLE);350 const d = DOT_IN + (DOT_OUT - DOT_IN) * k;351 return (352 <div353 key={`${dx}-${dy}`}354 style={{355 position: "absolute",356 left: (dx - d / 2) * u,357 top: (dy - d / 2) * u,358 width: d * u,359 height: d * u,360 background: accent,361 opacity: 1 + (DOT_FADE - 1) * k,362 }}363 />364 );365 })}366 </>367 );368}369370/**371 * A root-relative asset is a `public/` file. Only the site's own Player serves372 * it at that path; Remotion Studio and a render know its URL through373 * `staticFile()` alone — so every environment but the Player rewrites it.374 */375function resolveSrc(src: string): string {376 const isLocal = src.startsWith("/") && !src.startsWith("//");377 if (!isLocal || getRemotionEnvironment().isPlayer) return src;378 // A value that already came out of staticFile() carries the static base379 // (`/static-<hash>/…`); running it through again would prefix it twice.380 const base = staticFile("_").slice(0, -2);381 if (base && src.startsWith(`${base}/`)) return src;382 try {383 return staticFile(src.replace(/^\/+/, ""));384 } catch {385 return src;386 }387}388389/**390 * An image that holds the render until it has actually loaded.391 *392 * Without it a frame can be captured before the picture arrives and the card393 * comes out empty — invisible in the Player, where an image simply appears, and394 * silent in an mp4 until somebody watches it. Remotion's own `Img` is avoided for395 * the reason `hero-launch` documents: it awaits `decode()`, which the headless396 * compositor rejects for some progressive JPEGs and hangs the export.397 *398 * Takes a `ref` so Remotion Studio can outline a shot (see `Item`); its `style`399 * already arrives with Studio's merged in.400 */401const Plate = forwardRef<402 HTMLImageElement,403 {404 src: string;405 style: CSSProperties;406 }407>(function Plate({ src, style }, ref) {408 const [handle] = useState(() => delayRender(`logo-collapse: ${src}`));409 const release = useCallback(() => continueRender(handle), [handle]);410 return (411 // biome-ignore lint/performance/noImgElement: Remotion frame, not a Next route.412 <img // eslint-disable-line @remotion/warn-native-media-tag -- onLoad releases the frame; <Img> hangs on some JPEGs413 ref={ref}414 src={resolveSrc(src)}415 alt=""416 // Tailwind's preflight sets `img { max-width: 100% }`, which collapses an417 // image inside a shrink-to-fit box to zero pixels wide on the site while418 // rendering perfectly in an mp4. Size it here and say so.419 style={{ ...style, maxWidth: "none" }}420 onLoad={release}421 onError={release}422 />423 );424});






