Phone Stack
Stacked phone screens with video. Phone screens rise out of a blur from below one after another, and each new one pushes the stack back: the older screens shrink and step up so only their tops peek out above the newest.
Source
components/kuchi/phone-stack.tsx
1"use client";23import type { CSSProperties } from "react";4import {5 Easing,6 getRemotionEnvironment,7 interpolate,8 OffthreadVideo,9 Sequence,10 staticFile,11 useCurrentFrame,12 useVideoConfig,13} from "remotion";1415/**16 * A "phone stack": phone screens rise out of a blur from below, one after17 * another, and each new one pushes the stack back — the older screens shrink18 * and step up so only their tops peek out above the newest, which settles in19 * front. Every screen plays its own clip under an iOS status bar.20 *21 * Proportions were measured off a two-screen reference recording (716 × 398,22 * 30fps) by tracking each screen's Dynamic Island: a screen one step back is23 * 0.83× the size and its top sits 24.6 reference px higher. The rise is the24 * reference's long ease-out. Lengths are reference pixels (`REF_W` wide) and25 * scale with the frame.26 *27 * Like `announce-title` it paints a world rather than a surface — a cream page28 * with a lavender glow — so it takes no `theme`/`mode`; its colours are props.29 */3031export interface PhoneStackProps {32 /**33 * One clip per screen, in the order they arrive. Video URLs play muted;34 * images show as stills. Absolute URLs or paths under `public/`.35 */36 videos?: string[];37 /** Frames between one screen arriving and the next. */38 stagger?: number;39 /** The page. */40 background?: string;41 /** The glow the stack rises out of. */42 glowColor?: string;43 /** The status bar's ink over the clips. */44 statusColor?: string;45 /** The time in the status bar. */46 time?: string;47 speed?: number;48 className?: string;49}5051/** Creator-style clips, 12s each. Absolute, because a root-relative default52 * becomes `staticFile()` in a render and 404s in the project this file was53 * just copied into. */54const DEFAULT_VIDEOS = [2, 3, 4, 5, 6].map(55 (n) => `https://kuchi-media.kalarislabs.com/components/clips/clip-${n}.mp4`,56);5758// ─── Geometry, in reference pixels ────────────────────────────────────────────59export const REF_W = 716;60const REF_H = 398;61/** The front screen at rest: width, top edge, centre line. */62export const SCREEN = { w: 240, top: 74, cx: 358, radius: 26 } as const;63/** Each step back: the size it keeps, and how far its top climbs (at scale 1). */64export const STEP_SCALE = 0.83;65export const STEP_RISE = 24.6;66/** Screens deeper than this fade out as the next one arrives. */67const DEPTH = 3;68/** An arriving screen starts below the frame, larger, blurred and clear. */69const ENTER = { top: 400, scale: 1.12, blur: 9 } as const;7071// ─── Timeline (30fps frames) ──────────────────────────────────────────────────72/** One arrival or one step back. */73export const MOVE = 26;74const RISE = Easing.bezier(0.16, 1, 0.3, 1);7576/** Where a screen sits `depth` steps back: scale and top edge. */77function slot(depth: number) {78 const scale = STEP_SCALE ** depth;79 let top = SCREEN.top;80 for (let d = 1; d <= depth; d++) top -= STEP_RISE * STEP_SCALE ** (d - 1);81 return { scale, top };82}8384function resolveSrc(src: string): string {85 const isLocal = src.startsWith("/") && !src.startsWith("//");86 if (!isLocal || getRemotionEnvironment().isPlayer) return src;87 // A value that already came out of staticFile() carries the static base.88 const base = staticFile("_").slice(0, -2);89 if (base && src.startsWith(`${base}/`)) return src;90 try {91 return staticFile(src.replace(/^\/+/, ""));92 } catch {93 return src;94 }95}9697const isVideoSrc = (src: string) => /\.(mp4|webm|mov|m4v)(?:[?#]|$)/i.test(src);9899const cover: CSSProperties = {100 position: "absolute",101 inset: 0,102 width: "100%",103 height: "100%",104 maxWidth: "none",105 objectFit: "cover",106};107108/** Signal, Wi-Fi and battery, drawn in `currentColor`. */109function StatusIcons({ h }: { h: number }) {110 return (111 <svg112 height={h}113 viewBox="0 0 68 12"114 fill="currentColor"115 aria-hidden116 style={{ display: "block" }}117 >118 <rect x="0" y="8" width="3" height="4" rx="1" />119 <rect x="5" y="6" width="3" height="6" rx="1" />120 <rect x="10" y="3.5" width="3" height="8.5" rx="1" />121 <rect x="15" y="1" width="3" height="11" rx="1" />122 <path d="M31 2.2c2.6 0 5 1 6.8 2.7l-1.3 1.4A7.9 7.9 0 0 0 31 4.1a7.9 7.9 0 0 0-5.5 2.2l-1.3-1.4A9.8 9.8 0 0 1 31 2.2Zm0 3.8c1.6 0 3 .6 4.1 1.6L33.8 9a3.9 3.9 0 0 0-5.6 0l-1.3-1.4A5.8 5.8 0 0 1 31 6Zm0 3.7 1.6 1.7L31 12l-1.6-1.6L31 9.7Z" />123 <rect124 x="43.5"125 y="1.5"126 width="21"127 height="9"128 rx="2.6"129 fill="none"130 stroke="currentColor"131 opacity="0.45"132 />133 <rect x="45.5" y="3.5" width="17" height="5" rx="1.3" />134 <rect x="65.5" y="4.3" width="1.6" height="3.4" rx="0.8" opacity="0.45" />135 </svg>136 );137}138139export function PhoneStack({140 videos = DEFAULT_VIDEOS,141 stagger = 14,142 background = "#f3f3ee",143 glowColor = "#cdb4e6",144 statusColor = "#ffffff",145 time = "9:41",146 speed = 1,147 className,148}: PhoneStackProps) {149 const { width, height, fps } = useVideoConfig();150 const tick = (speed * 30) / fps;151 const frame = useCurrentFrame() * tick;152 const u = width / REF_W;153 const dy = (height - REF_H * u) / 2;154 const n = videos.length;155156 // How far a screen has come: 0 below the frame, 1 in front, 2 one step157 // back, … — every arrival after it adds one, on the same eased curve.158 const progress = (i: number) => {159 let p = 0;160 for (let k = i; k < n; k++) {161 p += interpolate(frame, [k * stagger, k * stagger + MOVE], [0, 1], {162 extrapolateLeft: "clamp",163 extrapolateRight: "clamp",164 easing: RISE,165 });166 }167 return p;168 };169170 return (171 <div172 className={className}173 style={{174 position: "absolute",175 inset: 0,176 overflow: "hidden",177 backgroundColor: background,178 }}179 >180 {/* The glow the stack rises out of. */}181 <div182 style={{183 position: "absolute",184 left: "50%",185 bottom: -0.55 * height,186 width: 1.5 * width,187 height: 1.1 * height,188 transform: "translateX(-50%)",189 borderRadius: "50%",190 background: glowColor,191 opacity: 0.55,192 filter: `blur(${70 * u}px)`,193 }}194 />195196 {videos.map((src, i) => {197 const p = progress(i);198 if (p <= 0) return null;199 // 0 → 1: the rise. Past 1: steps back, one per later arrival.200 const enter = Math.min(p, 1);201 const depth = Math.max(p - 1, 0);202 const lo = slot(Math.floor(depth));203 const hi = slot(Math.floor(depth) + 1);204 const f = depth - Math.floor(depth);205 const scale =206 enter < 1207 ? ENTER.scale + (1 - ENTER.scale) * enter208 : lo.scale + (hi.scale - lo.scale) * f;209 const top =210 enter < 1211 ? ENTER.top + (SCREEN.top - ENTER.top) * enter212 : lo.top + (hi.top - lo.top) * f;213 const blur = ENTER.blur * (1 - enter);214 const opacity =215 Math.min(1, enter * 2.5) *216 interpolate(depth, [DEPTH - 1, DEPTH], [1, 0], {217 extrapolateLeft: "clamp",218 extrapolateRight: "clamp",219 });220 if (opacity <= 0) return null;221222 const w = SCREEN.w * scale * u;223 const h = w * (852 / 393);224 const island = { w: 0.32 * w, h: 0.094 * w, top: 0.028 * w };225 const resolved = resolveSrc(src);226 return (227 <div228 key={`${i}-${src}`}229 style={{230 position: "absolute",231 left: SCREEN.cx * u - w / 2,232 top: dy + top * u,233 width: w,234 height: h,235 borderRadius: SCREEN.radius * scale * u,236 overflow: "hidden",237 backgroundColor: "#ffffff",238 boxShadow: `0 ${8 * u}px ${28 * u}px rgba(70, 50, 110, 0.14), 0 0 0 ${0.6 * u}px rgba(255, 255, 255, 0.9)`,239 opacity,240 filter: blur > 0.05 ? `blur(${blur * u}px)` : undefined,241 zIndex: i,242 }}243 >244 {isVideoSrc(src) ? (245 <Sequence from={Math.floor((i * stagger) / tick)} layout="none">246 <OffthreadVideo src={resolved} muted style={cover} />247 </Sequence>248 ) : (249 // biome-ignore lint/performance/noImgElement: Remotion still250 <img src={resolved} alt="" style={cover} />251 )}252 {/* Status bar and Dynamic Island over the clip. */}253 <div254 style={{255 position: "absolute",256 left: 0,257 right: 0,258 top: 0,259 height: island.top * 2 + island.h,260 background:261 "linear-gradient(to bottom, rgba(0,0,0,0.28), rgba(0,0,0,0))",262 }}263 />264 <div265 style={{266 position: "absolute",267 left: "50%",268 top: island.top,269 width: island.w,270 height: island.h,271 transform: "translateX(-50%)",272 borderRadius: island.h / 2,273 background: "#000000",274 }}275 />276 <div277 style={{278 position: "absolute",279 left: 0.09 * w,280 top: island.top,281 height: island.h,282 display: "flex",283 alignItems: "center",284 color: statusColor,285 fontFamily:286 '-apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif',287 fontWeight: 600,288 fontSize: 0.045 * w,289 }}290 >291 {time}292 </div>293 <div294 style={{295 position: "absolute",296 right: 0.07 * w,297 top: island.top,298 height: island.h,299 display: "flex",300 alignItems: "center",301 color: statusColor,302 }}303 >304 <StatusIcons h={0.034 * w} />305 </div>306 </div>307 );308 })}309310 {/* The stack's foot fades into the page and the glow. */}311 <div312 style={{313 position: "absolute",314 left: 0,315 right: 0,316 bottom: 0,317 height: 0.38 * height,318 background: `linear-gradient(to bottom, transparent 0%, color-mix(in srgb, ${background} 55%, transparent) 60%, ${background} 100%)`,319 zIndex: 100,320 }}321 />322 <div323 style={{324 position: "absolute",325 left: "50%",326 bottom: -0.45 * height,327 width: 1.1 * width,328 height: 0.7 * height,329 transform: "translateX(-50%)",330 borderRadius: "50%",331 background: glowColor,332 opacity: 0.35,333 filter: `blur(${60 * u}px)`,334 zIndex: 101,335 }}336 />337 </div>338 );339}









