Moodboard Reveal
Photo gallery reveal: a moodboard fly-through that lands on a hero image. A kinetic headline with a swapping inline image, then a scattered gallery of photos flies in, the camera pushes through it as the background lifts from near-black to off-white, and it lands on a single hero image.
Source
components/kuchi/moodboard-reveal.tsx
1"use client";23import type { CSSProperties } from "react";4import { forwardRef } from "react";5import {6 Easing,7 getRemotionEnvironment,8 Img,9 interpolate,10 interpolateColors,11 staticFile,12 useCurrentFrame,13 useVideoConfig,14} from "remotion";15import {16 Item,17 parseColor,18 resolveFont,19 type KuchiTheme,20 useKuchiTheme,21 withAlpha,22} from "@/lib/kuchi-ui";2324/**25 * A "moodboard reveal": a kinetic headline with a swapping inline image, then a26 * scattered gallery of image cards flies in, the camera pushes through it while27 * the background lifts from near-black to off-white, and it lands on a single28 * hero image. A camera-drives-through montage (see MOTION.md), replicated from a29 * reference reel and populated with the showcase assets.30 */3132export interface MoodboardRevealProps {33 /** Text before the inline image. */34 leadIn?: string;35 /** The emphasised (bold) word right after the inline image. */36 emphasis?: string;37 /** Text after the emphasised word. */38 tailIn?: string;39 /** Image URLs for the gallery + the intro swap. First-served covers the slots. */40 images?: string[];41 /** The image the montage lands on. Defaults to `images[3]`. */42 heroImage?: string;43 /** Near-black start background. Defaults to the dark theme's `background`. */44 darkColor?: string;45 /** Off-white end background. Defaults to the light theme's `background`. */46 lightColor?: string;47 /**48 * Design-system token overrides. Applied to both ends of the crossfade —49 * this scene spans light and dark, so it takes no `mode`.50 */51 theme?: Partial<KuchiTheme>;52 /**53 * The face this scene paints its words in — a label from `fonts.ts`54 * ("Inter", "Space Grotesk", "Instrument Serif") or a CSS family you have55 * loaded yourself. Unset, the scene keeps the face it was designed around.56 *57 * Overrides `theme.fontFamily`, which is how a brand kit re-skins a whole58 * timeline from one value.59 */60 fontFamily?: string;61 speed?: number;62 className?: string;63}6465const FONT_FAMILY =66 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';6768/** Sample images. Absolute, because a root-relative default becomes69 * `staticFile()` in a render and 404s in the project this file was just70 * copied into. Pass your own — root-relative or remote, both resolve. */71const DEFAULT_IMAGES = [72 "https://kuchi-media.kalarislabs.com/components/art/art-11.svg",73 "https://kuchi-media.kalarislabs.com/components/art/art-11.svg",74 "https://kuchi-media.kalarislabs.com/components/art/art-02.svg",75 "https://kuchi-media.kalarislabs.com/components/art/art-08.svg",76 "https://kuchi-media.kalarislabs.com/components/art/art-08.svg",77 "https://kuchi-media.kalarislabs.com/components/art/art-07.svg",78 "https://kuchi-media.kalarislabs.com/components/art/art-07.svg",79 "https://kuchi-media.kalarislabs.com/components/art/art-02.svg",80];8182// ─── Timeline (frames @ 30fps; ~5s to mirror the ~4.7s reference) ──────────────83// The sentence holds long enough that the last intro image lands and rests84// before it fades; the fade overlaps the first gallery positions appearing.85export const SENTENCE_OUT = 50;86export const COLLAGE_START = 46;87export const APPEAR_FRAMES = 12;88/** Each position swaps its image every `FLICKER_HOLD` frames — the shuffle. */89export const FLICKER_HOLD = 2;90/** The cluster orbits its centre from COLLAGE_START to here, sweeping ORBIT_DEG°. */91export const ORBIT_END = 88;92export const ORBIT_DEG = 130;93/** Then every position converges to the centre — the "merge into one". */94export const MERGE_START = 88;95// Fast collapse — the positions snap together, they don't drift in.96export const MERGE_END = 100;97export const BG_START = 88;98export const BG_END = 104;99/**100 * Every position collapses to this common width at the centre and un-rotates, so101 * the cards stack exactly on top of each other. They never fade — the topmost102 * card (the hero) simply covers the rest, so the merge *becomes* the one image.103 */104export const MERGE_W = 300;105106/** Moderate decelerate — not quint/expo-out, which freeze on a frame clock. */107export const EASE = Easing.bezier(0.2, 0.6, 0.35, 1);108const CLAMP = { extrapolateLeft: "clamp", extrapolateRight: "clamp" } as const;109110const CARD_RATIO = 1.34; // portrait cards (~3:4)111112/**113 * Gallery *positions* (offset from centre, width, tilt) — slots, not fixed114 * pictures. Each one flickers through the whole image set (see `flickerImage`).115 * Laid out as the spread moodboard the montage orbits and then collapses.116 */117export const SLOTS: ReadonlyArray<{118 x: number;119 y: number;120 w: number;121 rot: number;122}> = [123 { x: -401, y: -51, w: 188, rot: -5 },124 { x: -186, y: -191, w: 164, rot: 4 },125 { x: 44, y: -168, w: 214, rot: -2 },126 { x: 283, y: -79, w: 173, rot: 6 },127 { x: 377, y: 151, w: 169, rot: -4 },128 { x: -340, y: 179, w: 183, rot: 5 },129 { x: -101, y: 193, w: 214, rot: -3 },130 { x: 138, y: 193, w: 188, rot: 3 },131];132133/** The cluster's orbit angle (degrees) at `frame`. */134export function orbitAngle(frame: number): number {135 return interpolate(frame, [COLLAGE_START, ORBIT_END], [0, ORBIT_DEG], {136 ...CLAMP,137 easing: Easing.inOut(Easing.cubic),138 });139}140141/** How far the merge-to-centre has progressed (0 → 1). */142export function mergeProgress(frame: number): number {143 return interpolate(frame, [MERGE_START, MERGE_END], [0, 1], {144 ...CLAMP,145 easing: EASE,146 });147}148149/**150 * Which image a position shows. Positions don't hold one picture — they flicker151 * through the whole set every `FLICKER_HOLD` frames, staggered per slot, so it152 * reads as all the photos shuffling in place. The image freezes at `MERGE_START`153 * so the convergence isn't a strobe.154 */155export function flickerImage(156 frame: number,157 slot: number,158 count: number,159): number {160 const f = Math.min(frame, MERGE_START);161 const step = Math.max(0, Math.floor((f - COLLAGE_START) / FLICKER_HOLD));162 return (step * 3 + slot * 5) % count;163}164165export interface SlotPose {166 x: number;167 y: number;168 scale: number;169 opacity: number;170}171172/**173 * A position's live pose: it fades/scales in, orbits the centre, then converges174 * to the centre and to the common `MERGE_W` footprint during the merge. Opacity175 * is only the entrance fade — it NEVER fades on merge, so the positions stack on176 * top of each other and the topmost one (the hero) covers the rest.177 */178export function slotPose(179 frame: number,180 slot: { x: number; y: number; w: number },181 index: number,182): SlotPose {183 const appear = COLLAGE_START + index * 2;184 const opacity = interpolate(185 frame,186 [appear, appear + APPEAR_FRAMES],187 [0, 1],188 CLAMP,189 );190 const scIn = interpolate(frame, [appear, appear + APPEAR_FRAMES], [0.6, 1], {191 ...CLAMP,192 easing: EASE,193 });194 const a = (orbitAngle(frame) * Math.PI) / 180;195 const ox = slot.x * Math.cos(a) - slot.y * Math.sin(a);196 const oy = slot.x * Math.sin(a) + slot.y * Math.cos(a);197 const m = mergeProgress(frame);198 const target = MERGE_W / slot.w; // every card lands at the same width199 return {200 x: ox * (1 - m),201 y: oy * (1 - m),202 scale: scIn * (1 + (target - 1) * m),203 opacity,204 };205}206207/** Motion blur (px) as the positions converge — peaks mid-merge, zero at ends. */208export function mergeBlur(frame: number): number {209 return interpolate(210 frame,211 [MERGE_START, (MERGE_START + MERGE_END) / 2, MERGE_END],212 [0, 6, 0],213 CLAMP,214 );215}216217/** 0 = dark background, 1 = light background. */218export function bgProgress(frame: number): number {219 return interpolate(frame, [BG_START, BG_END], [0, 1], CLAMP);220}221222/** Intro image swap cadence, and the "drop" each new image lands with. */223export const INLINE_START = 8;224export const INLINE_HOLD = 12;225/** How many images cycle in the intro (kept small so each drop is legible). */226export const INLINE_COUNT = 3;227export const DROP_FRAMES = 9;228export const DROP_SCALE = 1.16;229230export interface InlineDrop {231 index: number;232 scale: number;233 opacity: number;234}235236/**237 * The inline image drops in — the *same* smooth landing the hero uses: each new238 * image fades in over a few frames while settling from a slight zoom239 * (`DROP_SCALE` → 1), so you actually see it drop into place rather than cut.240 * Past images stay stacked underneath so the swap never flashes empty; the241 * newest sits on top. `DROP_FRAMES` < `INLINE_HOLD`, so every image — the last242 * one included — fully lands before the next arrives.243 */244export function inlineImage(frame: number, count: number): InlineDrop {245 const index = Math.min(246 count - 1,247 Math.max(0, Math.floor((frame - INLINE_START) / INLINE_HOLD)),248 );249 const age = frame - (INLINE_START + index * INLINE_HOLD);250 const scale = interpolate(age, [0, DROP_FRAMES], [DROP_SCALE, 1], {251 ...CLAMP,252 easing: EASE,253 });254 const opacity = interpolate(age, [0, 5], [0, 1], { ...CLAMP, easing: EASE });255 return { index, scale, opacity };256}257258/**259 * Forwards its `ref` so Remotion Studio can outline an intro card (see `Item`);260 * its `style` already arrives with Studio's merged in.261 */262const Card = forwardRef<263 HTMLImageElement,264 { src: string; style: CSSProperties }265>(function Card({ src, style }, ref) {266 return (267 <Img268 ref={ref}269 src={resolveSrc(src)}270 style={{271 width: "100%",272 height: "100%",273 maxWidth: "none",274 objectFit: "cover",275 display: "block",276 ...style,277 }}278 />279 );280});281282/** Rewrite root-relative assets through staticFile everywhere but the Player. */283function resolveSrc(src: string): string {284 const isLocal = src.startsWith("/") && !src.startsWith("//");285 if (!isLocal || getRemotionEnvironment().isPlayer) return src;286 // A value that already came out of staticFile() carries the static base287 // (`/static-<hash>/…`); running it through again would prefix it twice.288 const base = staticFile("_").slice(0, -2);289 if (base && src.startsWith(`${base}/`)) return src;290 try {291 return staticFile(src.replace(/^\/+/, ""));292 } catch {293 return src;294 }295}296297/** Thin wireframe square/diamond marker that drifts and slowly rotates. */298function WireMarker({299 frame,300 cx,301 cy,302 size,303 spin,304 color,305 from,306 to,307}: {308 frame: number;309 cx: number;310 cy: number;311 size: number;312 spin: number;313 color: string;314 from: number;315 to: number;316}) {317 const opacity = interpolate(318 frame,319 [from, from + 8, to - 8, to],320 [0, 1, 1, 0],321 CLAMP,322 );323 if (opacity <= 0) return null;324 const drift = Math.sin((frame - from) / 22) * 8;325 const rot = spin + (frame - from) * 0.6;326 return (327 <div328 style={{329 position: "absolute",330 left: cx,331 top: cy + drift,332 width: size,333 height: size,334 border: `1px solid ${color}`,335 transform: `rotate(${rot}deg)`,336 opacity,337 }}338 />339 );340}341342export function MoodboardReveal({343 leadIn = "that lets you",344 emphasis = "filter",345 tailIn = "out AI.",346 images = DEFAULT_IMAGES,347 heroImage,348 darkColor,349 lightColor,350 theme,351 fontFamily,352 speed = 1,353 className,354}: MoodboardRevealProps) {355 const frame = useCurrentFrame() * speed;356 const { width, height } = useVideoConfig();357 // The scene crossfades a dark page into a light one, so it needs both ends of358 // the system at once rather than one resolved mode. Both still take a user's359 // `theme` override.360 const dark = useKuchiTheme(theme, "dark");361 const face = resolveFont(fontFamily ?? dark.fontFamily) ?? FONT_FAMILY;362 const light = useKuchiTheme(theme, "light");363 const cx = width / 2;364 const cy = height / 2;365366 const bg = bgProgress(frame);367 const bgColor = interpolateColors(368 bg,369 [0, 1],370 [darkColor ?? dark.background, lightColor ?? light.background],371 );372 // Both pages transparent — the scene as an overlay — asks for no page: no373 // dotted grid, and ink that reads on light footage from the first frame.374 const bare =375 parseColor(darkColor ?? dark.background).alpha === 0 &&376 parseColor(lightColor ?? light.background).alpha === 0;377 // The marker is always the opposite page: light ink on the dark half, dark on378 // the light one.379 const markerColor =380 bg < 0.5 && !bare381 ? withAlpha(light.background, 0.55)382 : withAlpha(dark.background, 0.5);383 const hero = heroImage ?? images[3] ?? images[0];384385 // ── Intro sentence ──────────────────────────────────────────────────────────386 const sentenceOp = interpolate(387 frame,388 [0, 8, SENTENCE_OUT - 6, SENTENCE_OUT],389 [0, 1, 1, 0],390 CLAMP,391 );392 const inline = inlineImage(frame, Math.min(INLINE_COUNT, images.length));393394 // ── Gallery (flicker + orbit + merge) ────────────────────────────────────────395 const mBlur = mergeBlur(frame);396 const merge = mergeProgress(frame);397 const isRendering = getRemotionEnvironment().isRendering;398 // The index into `images` each gallery position shows this frame; -1 when it399 // is hidden, or holds a `heroImage` that isn't one of `images`.400 const slotImage = SLOTS.map((s, i) => {401 if (slotPose(frame, s, i).opacity <= 0) return -1;402 if (i === SLOTS.length - 1 && frame >= MERGE_START)403 return hero ? images.indexOf(hero) : -1;404 return flickerImage(frame, i, images.length);405 });406 // One photo can be on screen twice — an intro card still fading as the407 // gallery opens, two positions on the same picture. Studio outlines the408 // front-most copy (drawn last); the others are only pictures of it.409 const front = new Map<number, string>();410 if (sentenceOp > 0)411 for (let i = 0; i <= inline.index; i++) front.set(i, `in-${i}`);412 slotImage.forEach((k, i) => {413 if (k >= 0) front.set(k, `slot-${i}`);414 });415416 return (417 <div418 className={className}419 style={{420 position: "absolute",421 inset: 0,422 overflow: "hidden",423 backgroundColor: bgColor,424 fontFamily: face,425 // Any scaled text renders as the outline, not re-hinted per frame.426 textRendering: "geometricPrecision",427 }}428 >429 {/* Dotted grid, only on the dark background */}430 <div431 style={{432 position: "absolute",433 inset: 0,434 opacity: bare ? 0 : 1 - bg,435 backgroundImage: `radial-gradient(circle, ${withAlpha(436 light.background,437 0.07,438 )} 1px, transparent 1.5px)`,439 backgroundSize: "20px 20px",440 }}441 />442443 {/* ── Intro sentence: "<leadIn> [img] <emphasis> <tailIn>" ── */}444 {sentenceOp > 0 && (445 <div446 style={{447 position: "absolute",448 inset: 0,449 display: "flex",450 alignItems: "center",451 justifyContent: "center",452 gap: 18,453 opacity: sentenceOp,454 color: bare ? light.foreground : dark.foreground,455 fontSize: 28,456 fontWeight: 400,457 letterSpacing: "-0.01em",458 }}459 >460 <span>{leadIn}</span>461 <div462 style={{463 position: "relative",464 width: 108,465 height: 108 * CARD_RATIO,466 overflow: "hidden",467 flexShrink: 0,468 }}469 >470 {images.slice(0, INLINE_COUNT).map((src, i) => {471 if (i > inline.index) return null; // future image, not yet dropped472 const isActive = i === inline.index;473 return (474 <Item key={src} index={i} primary={front.get(i) === `in-${i}`}>475 <Card476 src={src}477 style={{478 position: "absolute",479 inset: 0,480 zIndex: i,481 opacity: isActive ? inline.opacity : 1,482 transform: isActive483 ? `scale(${inline.scale})`484 : undefined,485 transformOrigin: "center center",486 }}487 />488 </Item>489 );490 })}491 </div>492 <span>493 <strong style={{ fontWeight: 700 }}>{emphasis}</strong> {tailIn}494 </span>495 </div>496 )}497498 {/* ── Gallery: positions that flicker, orbit, then merge to centre ── */}499 <div500 style={{501 position: "absolute",502 inset: 0,503 filter: mBlur > 0.1 ? `blur(${mBlur}px)` : undefined,504 ...(isRendering ? {} : { willChange: "filter" as const }),505 }}506 >507 {SLOTS.map((s, i) => {508 const pose = slotPose(frame, s, i);509 if (pose.opacity <= 0) return null;510 // The last-rendered position sits on top of the merged stack, so it is511 // the one that remains — freeze it to the hero as the merge begins.512 const isTop = i === SLOTS.length - 1;513 const src =514 isTop && frame >= MERGE_START515 ? hero516 : images[flickerImage(frame, i, images.length)];517 const h = s.w * CARD_RATIO;518 // Un-rotate as they merge so the stack aligns into one clean image.519 const rot = s.rot * (1 - merge);520 return (521 <Item522 key={`slot-${s.x}-${s.y}`}523 index={slotImage[i] ?? -1}524 primary={front.get(slotImage[i] ?? -1) === `slot-${i}`}525 >526 <div527 style={{528 position: "absolute",529 left: cx + pose.x - s.w / 2,530 top: cy + pose.y - h / 2,531 width: s.w,532 height: h,533 opacity: pose.opacity,534 transform: `rotate(${rot}deg) scale(${pose.scale})`,535 // Shadow gives depth in the spread, but 8 stacked shadows pile536 // into a dark halo — so fade it out as they merge to one.537 boxShadow:538 merge > 0.98539 ? "none"540 : `0 18px 40px ${withAlpha(dark.background, 0.28 * (1 - merge))}`,541 }}542 >543 <Card src={src} style={{}} />544 </div>545 </Item>546 );547 })}548 </div>549550 {/* ── Wireframe markers ── */}551 <WireMarker552 frame={frame}553 cx={cx + 150}554 cy={cy - 130}555 size={44}556 spin={0}557 color={markerColor}558 from={4}559 to={SENTENCE_OUT}560 />561 <WireMarker562 frame={frame}563 cx={cx - 240}564 cy={cy + 40}565 size={54}566 spin={45}567 color={markerColor}568 from={MERGE_END - 6}569 to={150}570 />571 <WireMarker572 frame={frame}573 cx={cx + 190}574 cy={cy + 70}575 size={40}576 spin={12}577 color={markerColor}578 from={MERGE_END + 8}579 to={150}580 />581 </div>582 );583}









