Duet Split
A split screen contrasts a slow grey side with a crisp gradient side: '1 day' versus '$0'.
Source
components/kuchi/duet-split.tsx
1"use client";23import { loadFont as loadSans } from "@remotion/google-fonts/BricolageGrotesque";4import { loadFont as loadSerif } from "@remotion/google-fonts/InstrumentSerif";5import { loadFont as loadManrope } from "@remotion/google-fonts/Manrope";6import type React from "react";7import {8 AbsoluteFill,9 Easing,10 interpolate,11 spring,12 useCurrentFrame,13 useVideoConfig,14} from "remotion";15import type { GradientParams } from "@/lib/kuchi/gsh/gradient-engine";16import { GshGround } from "@/lib/kuchi/gsh/gsh-ground";17import type { GshPresetId } from "@/lib/kuchi/gsh/presets";1819const { fontFamily: sans } = loadSans("normal", {20 weights: ["300", "400"],21 subsets: ["latin"],22});23const { fontFamily: serif } = loadSerif("normal", {24 weights: ["400"],25 subsets: ["latin"],26});27const manrope = loadManrope("normal", {28 weights: ["600"],29 subsets: ["latin"],30});313233function KuchiLogo({ fontSize, color }: { fontSize: number; color: string }) {34 return (35 <div36 style={{37 display: "flex",38 alignItems: "baseline",39 color,40 fontFamily: manrope.fontFamily,41 fontWeight: 600,42 fontSize,43 letterSpacing: "-0.025em",44 lineHeight: 1,45 }}46 >47 <span>Acme</span>48 </div>49 );50}5152export interface DuetRow {53 before: string;54 after: string;55}5657export interface DuetSplitProps {58 beforeLabel?: string;59 afterLabel?: string;60 rows?: DuetRow[];61 accent?: string;62 /** Text color of the after side and the mark; overrides the theme ink. */63 ink?: string;64 /** Solid fill in place of the gradient ground; "transparent" drops it. */65 background?: string;66 /** Typeface for the labels and the after side. Load it yourself; Bricolage Grotesque by default. */67 fontFamily?: string;68 /** Frames between rows. */69 stagger?: number;70 /** Frames the last row holds before the after side takes over. */71 hold?: number;72 /** Replaces the acme mark. */73 logo?: React.ReactNode;74 /** Size of the split and the mark, around the frame's center. */75 scale?: number;76 /** Frames to hold the first frame before anything moves. */77 delay?: number;78 theme?: "dark" | "light";79 ground?: GshPresetId;80 groundParams?: Partial<GradientParams>;81 speed?: number;82}8384const LABEL_AT = 6;85const ROW_AT = 18;86const ROW_GAP = 16;87const TRICKLE = 3;88const GLYPH_LEN = 14;89const PUSH_DELAY = 24;90const PUSH_LEN = 16;9192const HEAVY = { mass: 1, damping: 26, stiffness: 120 };93const CARD = { mass: 0.8, damping: 18, stiffness: 160 };94const CHIP = { mass: 0.5, damping: 12, stiffness: 200 };95const MORPH = { damping: 200 };96const ENTER = Easing.bezier(0.22, 1, 0.36, 1);97const MOVE = Easing.bezier(0.65, 0, 0.35, 1);98const EXIT = Easing.bezier(0.55, 0, 1, 0.45);99const CLAMP = {100 extrapolateLeft: "clamp",101 extrapolateRight: "clamp",102} as const;103104const THEMES = {105 dark: {106 ground: "film-blue" as GshPresetId,107 base: "#03070F",108 slab: "#161618",109 seam: "rgba(255,255,255,0.10)",110 ink: "#F4F5F8",111 muted: "rgba(244,245,248,0.62)",112 grey: "#6B6A70",113 greyLabel: "#7E7D83",114 scrim: "3,7,15",115 scrimA: 0.5,116 shadow: "0 1px 18px rgba(3,7,15,0.45)",117 },118 light: {119 ground: "paper-crease" as GshPresetId,120 base: "#EEECE8",121 slab: "#D9D6CF",122 seam: "rgba(0,0,0,0.10)",123 ink: "#121318",124 muted: "rgba(18,19,24,0.6)",125 grey: "#A29F97",126 greyLabel: "#8D8A82",127 scrim: "238,236,232",128 scrimA: 0.45,129 shadow: "none",130 },131} as const;132133function ramp(t: number, from: number, len: number) {134 return interpolate(t, [from, from + len], [0, 1], CLAMP);135}136137function kick(d: number) {138 if (d < 0) return 0;139 if (d < 2) return d / 2;140 const k = Math.max(0, 1 - (d - 2) / 8);141 return k * k;142}143144function Wobbly({145 text,146 at,147 t,148 fontSize,149 color,150 seed,151}: {152 text: string;153 at: number;154 t: number;155 fontSize: number;156 color: string;157 seed: number;158}) {159 return (160 <div161 style={{162 display: "flex",163 fontFamily: serif,164 fontWeight: 400,165 fontSize,166 lineHeight: 1,167 letterSpacing: "-0.01em",168 color,169 whiteSpace: "pre",170 }}171 >172 {[...text].map((ch, k) => {173 const p = MOVE(ramp(t, at + k * TRICKLE, GLYPH_LEN));174 const ph = seed * 2.3 + k * 1.1;175 const wy = Math.sin(t * 0.13 + ph) * 0.035 * fontSize;176 const rot = Math.sin(t * 0.09 + ph * 0.7) * 3;177 return (178 <span179 key={k}180 style={{181 display: "inline-block",182 opacity: p,183 transform: `translateY(${(1 - p) * 0.35 * fontSize + wy}px) rotate(${rot * (0.4 + 0.6 * p)}deg)`,184 filter:185 p < 0.98 ? `blur(${(1 - p) * 0.05 * fontSize}px)` : undefined,186 }}187 >188 {ch}189 </span>190 );191 })}192 </div>193 );194}195196function Label({197 text,198 fs,199 color,200 dot,201 fontFamily,202}: {203 text: string;204 fs: number;205 color: string;206 dot: string;207 fontFamily: string;208}) {209 return (210 <div211 style={{212 display: "flex",213 alignItems: "center",214 gap: fs * 0.5,215 fontFamily,216 fontWeight: 400,217 fontSize: fs,218 lineHeight: 1,219 letterSpacing: "-0.005em",220 color,221 whiteSpace: "nowrap",222 }}223 >224 <div225 style={{226 width: fs * 0.36,227 height: fs * 0.36,228 borderRadius: fs,229 background: dot,230 }}231 />232 {text}233 </div>234 );235}236237/** The foreground at `scale`, around the frame's center; nothing extra at 1. */238function ScaleLayer({239 scale,240 children,241}: {242 scale: number;243 children: React.ReactNode;244}) {245 if (scale === 1) return children;246 return (247 <AbsoluteFill style={{ transform: `scale(${scale})` }}>248 {children}249 </AbsoluteFill>250 );251}252253export function DuetSplit({254 beforeLabel = "Before",255 afterLabel = "With acme",256 rows = [257 { before: "3 weeks", after: "1 day" },258 { before: "an agency", after: "you" },259 { before: "$12K", after: "$0" },260 ],261 accent = "#3B5BFD",262 ink,263 background,264 fontFamily = sans,265 stagger = ROW_GAP,266 hold = PUSH_DELAY,267 logo,268 scale = 1,269 delay = 0,270 theme = "dark",271 ground,272 groundParams,273 speed = 1,274}: DuetSplitProps) {275 const t = Math.max(0, useCurrentFrame() - delay) * speed;276 const { width: W, height: H, fps } = useVideoConfig();277 const c = THEMES[theme];278 const fg = ink ?? c.ink;279 const tall = H > W;280281 const sp = (at: number, config: object, durationInFrames?: number) =>282 spring({283 frame: t - at,284 fps,285 config,286 ...(durationInFrames ? { durationInFrames } : {}),287 });288289 const open = sp(-5, HEAVY);290 const lastRowAt = ROW_AT + (rows.length - 1) * stagger;291 const pushAt = lastRowAt + hold;292 const push = sp(pushAt, MORPH, PUSH_LEN);293 const logoAt = pushAt + PUSH_LEN - 4;294 const pLogo = sp(logoAt, CARD);295296 const fs = tall ? 0.135 * W : 0.15 * H;297 const gap = fs * 1.18;298 const labelFs = tall ? 0.024 * H : 0.034 * H;299 const margin = tall ? 0.07 * W : 0.05 * W;300301 const half = tall ? H / 2 : W / 2;302 const slabStyle = tall303 ? {304 left: 0,305 top: 0,306 width: W,307 height: H / 2,308 transform: `translateY(${-(1 - open) * half - push * half}px)`,309 }310 : {311 left: 0,312 top: 0,313 width: W / 2,314 height: H,315 transform: `translate(${-push * half}px, ${-(1 - open) * H}px)`,316 };317318 const beforeC = tall319 ? { x: W / 2, y: H * 0.27 }320 : { x: W * 0.25, y: H * 0.54 };321 const afterStart = tall322 ? { x: W / 2, y: H * 0.77 }323 : { x: W * 0.75, y: H * 0.54 };324 const afterEnd = tall ? { x: W / 2, y: H * 0.46 } : { x: W / 2, y: H * 0.45 };325 const ac = {326 x: afterStart.x + (afterEnd.x - afterStart.x) * push,327 y: afterStart.y + (afterEnd.y - afterStart.y) * push,328 };329 const grow = 1 + (tall ? 0.16 : 0.2) * push;330 const rowY = (i: number) => (i - (rows.length - 1) / 2) * gap;331332 const bump = Math.max(333 ...rows.map((_, i) => 0.6 * kick(t - ROW_AT - i * stagger - 3)),334 kick(t - pushAt - PUSH_LEN + 4),335 );336 const camScale =337 1 + 0.016 * bump + interpolate(t, [0, 160], [0, 0.02], CLAMP);338339 const afterOpen = sp(2, HEAVY);340 const labelIn = ENTER(ramp(t, LABEL_AT, 12));341 const labelOut = EXIT(ramp(t, pushAt, 8));342343 const crisp = (text: string, at: number) => {344 const p = sp(at, CHIP);345 return (346 <div347 style={{348 fontFamily,349 fontWeight: 300,350 fontSize: fs,351 lineHeight: 1,352 letterSpacing: "-0.045em",353 whiteSpace: "nowrap",354 color: fg,355 textShadow: c.shadow,356 opacity: ENTER(ramp(t, at, 3)),357 transform: `translateY(${(1 - p) * 0.22 * fs}px) scale(${1.1 - 0.1 * p})`,358 }}359 >360 {text}361 </div>362 );363 };364365 const place = (x: number, y: number, child: React.ReactNode, key: string) => (366 <div367 key={key}368 style={{369 position: "absolute",370 left: x,371 top: y,372 width: 0,373 height: 0,374 display: "flex",375 alignItems: "center",376 justifyContent: "center",377 }}378 >379 {child}380 </div>381 );382383 const afterLabelPos = tall384 ? { left: margin, top: H / 2 + margin }385 : { left: W / 2 + margin, top: margin * 1.2 };386 const scrimAt = tall387 ? `50% ${(ac.y / H) * 100}%`388 : `${(ac.x / W) * 100}% 54%`;389390 return (391 <AbsoluteFill392 style={{393 background: background === undefined ? c.base : undefined,394 overflow: "hidden",395 }}396 >397 {background === undefined ? (398 <>399 <GshGround400 preset={groundParams ? undefined : (ground ?? c.ground)}401 params={groundParams}402 timeOffset={theme === "dark" ? 4 : 6}403 timeScale={0.5}404 />405 <AbsoluteFill406 style={{407 background: `radial-gradient(${tall ? "80% 34%" : "40% 60%"} at ${scrimAt}, rgba(${c.scrim},${c.scrimA}) 0%, rgba(${c.scrim},0) 100%)`,408 }}409 />410 </>411 ) : (412 <AbsoluteFill413 style={{414 background: background === "transparent" ? undefined : background,415 }}416 />417 )}418 <ScaleLayer scale={scale}>419 <AbsoluteFill420 style={{421 transform: `scale(${camScale})`,422 transformOrigin: "50% 50%",423 }}424 >425 <div426 style={{427 position: "absolute",428 ...afterLabelPos,429 opacity: labelIn * (1 - labelOut),430 transform: `translateY(${(1 - labelIn) * labelFs * 0.6}px)`,431 }}432 >433 <Label434 text={afterLabel}435 fs={labelFs}436 color={fg}437 dot={accent}438 fontFamily={fontFamily}439 />440 </div>441 <div442 style={{443 position: "absolute",444 inset: 0,445 transformOrigin: `${ac.x}px ${ac.y}px`,446 transform: `translateY(${(1 - afterOpen) * 0.08 * H}px) scale(${grow})`,447 }}448 >449 {rows.map((r, i) => {450 const at = ROW_AT + i * stagger;451 return t >= at452 ? place(ac.x, ac.y + rowY(i), crisp(r.after, at), `a-${i}`)453 : null;454 })}455 </div>456457 <div458 style={{459 position: "absolute",460 ...slabStyle,461 background: c.slab,462 boxShadow: tall463 ? `inset 0 -1px 0 ${c.seam}`464 : `inset -1px 0 0 ${c.seam}`,465 overflow: "hidden",466 }}467 >468 <div469 style={{470 position: "absolute",471 left: margin,472 top: tall ? margin : margin * 1.2,473 opacity: labelIn,474 transform: `translateY(${(1 - labelIn) * labelFs * 0.6}px)`,475 }}476 >477 <Label478 text={beforeLabel}479 fs={labelFs}480 color={c.greyLabel}481 dot={c.grey}482 fontFamily={fontFamily}483 />484 </div>485 {rows.map((r, i) =>486 place(487 tall ? W / 2 : W * 0.25,488 beforeC.y + rowY(i),489 <Wobbly490 text={r.before}491 at={ROW_AT + i * stagger}492 t={t}493 fontSize={fs * 1.04}494 color={c.grey}495 seed={i + 1}496 />,497 `b-${i}`,498 ),499 )}500 </div>501 </AbsoluteFill>502503 <div504 style={{505 position: "absolute",506 left: 0,507 right: 0,508 bottom: tall ? 0.08 * H : 0.085 * H,509 display: "flex",510 justifyContent: "center",511 opacity: ENTER(ramp(t, logoAt, 6)),512 transform: `translateY(${(1 - pLogo) * 0.05 * H}px)`,513 }}514 >515 {logo ?? (516 <KuchiLogo fontSize={tall ? 0.04 * H : 0.055 * H} color={fg} />517 )}518 </div>519 </ScaleLayer>520 </AbsoluteFill>521 );522}









