Query Cascade
Search queries rush past until the hero query lands and its answer line resolves.
Source
components/kuchi/query-cascade.tsx
1"use client";23import { loadFont as loadManrope } from "@remotion/google-fonts/Manrope";4import { loadFont } from "@remotion/google-fonts/SchibstedGrotesk";5import type React from "react";6import { useMemo } from "react";7import {8 AbsoluteFill,9 Easing,10 interpolate,11 interpolateColors,12 spring,13 useCurrentFrame,14 useVideoConfig,15} from "remotion";16import type { GradientParams } from "@/lib/kuchi/gsh/gradient-engine";17import { GshGround } from "@/lib/kuchi/gsh/gsh-ground";18import type { GshPresetId } from "@/lib/kuchi/gsh/presets";1920const { fontFamily: grotesk } = loadFont("normal", {21 weights: ["400"],22 subsets: ["latin"],23});24const manrope = loadManrope("normal", {25 weights: ["600"],26 subsets: ["latin"],27});2829export interface QueryCascadeProps {30 queries?: string[];31 hero?: string;32 term?: string;33 answerBefore?: string;34 answerAfter?: string;35 showLogo?: boolean;36 /** Replaces the acme mark under the answer. */37 logo?: React.ReactNode;38 /** Highlight color of the term and its underline; overrides the theme. */39 accent?: string;40 /** Text color of the queries and the answer; overrides the theme. */41 ink?: string;42 /** Solid fill in place of the gradient ground; "transparent" drops it. */43 background?: string;44 /** Typeface for the copy. Spacing is measured for Schibsted Grotesk, so pick a face of similar width. */45 fontFamily?: string;46 /** Strength of the motion smear while the list scrolls; 0 turns it off. */47 motionBlur?: number;48 /** Size of the foreground around the frame's center. */49 scale?: number;50 /** Frames to hold the first frame before anything moves. */51 delay?: number;52 theme?: "dark" | "light";53 ground?: GshPresetId;54 groundParams?: Partial<GradientParams>;55 speed?: number;56}5758function KuchiLogo({ fontSize, color }: { fontSize: number; color: string }) {59 return (60 <div61 style={{62 display: "flex",63 alignItems: "baseline",64 color,65 fontFamily: manrope.fontFamily,66 fontWeight: 600,67 fontSize,68 letterSpacing: "-0.025em",69 lineHeight: 1,70 }}71 >72 <span>Acme</span>73 </div>74 );75}76const ADV = [77 254, 240, 353, 654, 564, 850, 686, 199, 309, 309, 443, 635, 265, 488, 280,78 444, 611, 343, 572, 576, 584, 580, 595, 531, 579, 594, 280, 268, 635, 635,79 635, 529, 885, 700, 645, 703, 697, 585, 561, 718, 720, 354, 536, 660, 545,80 868, 729, 770, 615, 770, 633, 613, 644, 673, 678, 935, 652, 623, 595, 310,81 444, 310, 635, 500, 500, 551, 589, 551, 589, 573, 341, 555, 567, 242, 272,82 552, 262, 873, 581, 597, 590, 590, 401, 513, 340, 581, 554, 812, 559, 548,83 504, 327, 239, 327, 635,84];85const HERO_TRACK = -0.025;86const BASELINE = 0.8594;8788const QUERIES = [89 "launch video ideas",90 "how long should a launch video be",91 "launch video in a day",92 "product demo video template",93 "best saas launch videos",94 "how to animate text in react",95 "launch video music no copyright",96 "make a demo video fast",97 "motion design for developers",98 "how to cut a video to the beat",99 "product hunt launch video",100 "launch trailer for an app",101 "motion graphics without after effects",102 "how to make a product video",103 "launch video script",104 "animated logo reveal",105 "how to record a screen demo",106 "launch video for developers",107 "kinetic typography in react",108 "launch video checklist",109 "how to make an explainer video",110 "best launch videos 2026",111 "launch video examples",112 "react video components",113 "how to make a teaser video",114 "launch video before friday",115 "video templates for startups",116 "how to make a launch film",117 "launch video in an afternoon",118 "how to edit a launch video",119 "product launch video cost",120 "launch video with code",121 "how to make a launch video fast",122 "launch video templates free",123 "how to make a launch video in react",124 "launch video for a startup",125 "launch video length",126 "launch video agency",127 "how to make a launch video with ai",128];129const HERO_FROM_END = 6;130const LIGHT_GROUND: Partial<GradientParams> = {131 kind: "mist",132 colors: ["#EE8550", "#F5C29C", "#F2E4D6", "#5E1E12"],133 background: "#F2EEE8",134 speed: 0.8,135 loopSeconds: 14,136 scale: 0.8,137 warp: 0.4,138 blur: 0.65,139 grain: 0.3,140 seed: 6,141};142143const THEMES = {144 dark: {145 base: "#0A0302",146 scrim:147 "radial-gradient(70% 55% at 50% 46%, rgba(10,3,2,0.78) 0%, rgba(10,3,2,0.5) 70%, rgba(10,3,2,0.3) 100%)",148 fg: "#F4F1EC",149 term: "#FFB27A",150 field: "rgba(20,14,12,0.92)",151 fieldDepth:152 "inset 0 1px 0 rgba(255,255,255,0.06), 0 0 0 1px rgba(255,255,255,0.09), 0 24px 50px -18px rgba(0,0,0,0.8)",153 icon: "#8F8780",154 keyRing: "rgba(255,255,255,0.14)",155 },156 light: {157 base: "#F2EEE8",158 scrim:159 "radial-gradient(70% 55% at 50% 46%, rgba(246,243,238,0.72) 0%, rgba(246,243,238,0.3) 100%)",160 fg: "#17120F",161 term: "#C2410C",162 field: "rgba(255,255,255,0.95)",163 fieldDepth:164 "0 0 0 1px rgba(40,24,12,0.07), 0 1px 3px rgba(40,24,12,0.05), 0 24px 50px -20px rgba(90,40,10,0.25)",165 icon: "#857B73",166 keyRing: "rgba(40,24,12,0.16)",167 },168} as const;169170const EASE_OUT = Easing.bezier(0.32, 0.72, 0, 1);171const EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);172const EXIT = Easing.bezier(0.55, 0, 1, 0.45);173const CLAMP = {174 extrapolateLeft: "clamp",175 extrapolateRight: "clamp",176} as const;177const CHIP = { mass: 0.5, damping: 12, stiffness: 200 };178const STOP = 54;179const GROW = [42, 68] as const;180const CLEAR = [40, 62] as const;181const TINT = [72, 88] as const;182const RULE = [78, 96] as const;183const RESOLVE = 104;184const LOGO_IN = 132;185186function width(text: string) {187 let x = 0;188 for (const ch of text) {189 const code = ch.charCodeAt(0);190 x += (code >= 32 && code < 127 ? ADV[code - 32] : 560) / 1000 + HERO_TRACK;191 }192 return x;193}194function split(q: string, term: string) {195 if (!term) return [{ text: q, hit: false }];196 const parts: { text: string; hit: boolean }[] = [];197 let rest = q;198 for (;;) {199 const at = rest.indexOf(term);200 if (at < 0) break;201 if (at > 0) parts.push({ text: rest.slice(0, at), hit: false });202 parts.push({ text: term, hit: true });203 rest = rest.slice(at + term.length);204 }205 if (rest) parts.push({ text: rest, hit: false });206 return parts;207}208209/** The foreground at `scale`, around the frame's center; nothing extra at 1. */210function ScaleLayer({211 scale,212 children,213}: {214 scale: number;215 children: React.ReactNode;216}) {217 if (scale === 1) return children;218 return (219 <AbsoluteFill style={{ transform: `scale(${scale})` }}>220 {children}221 </AbsoluteFill>222 );223}224225export function QueryCascade({226 queries = QUERIES,227 hero = "how to make a launch video",228 term = "launch video",229 answerBefore = "Your",230 answerAfter = "is ready.",231 showLogo = true,232 logo,233 accent,234 ink,235 background,236 fontFamily = grotesk,237 motionBlur = 1,238 scale = 1,239 delay = 0,240 theme = "dark",241 ground,242 groundParams,243 speed = 1,244}: QueryCascadeProps) {245 const t = Math.max(0, useCurrentFrame() - delay) * speed;246 const { width: W, height: H, fps } = useVideoConfig();247 const tall = H > W;248 const u = tall ? W / 1000 : H / 720;249 const c = THEMES[theme];250 const fg = ink ?? c.fg;251 const hi = accent ?? c.term;252 const dark = theme === "dark";253 const resolvedGround: GshPresetId | undefined =254 ground ?? (groundParams ? undefined : dark ? "ember" : undefined);255 const resolvedParams = groundParams ?? (dark ? undefined : LIGHT_GROUND);256257 const list = useMemo(() => {258 const at = Math.max(0, queries.length - HERO_FROM_END + 1);259 return [...queries.slice(0, at), hero, ...queries.slice(at)];260 }, [queries, hero]);261 const K = list.indexOf(hero);262263 const widest = Math.max(...list.map(width));264 const f = Math.min(50 * u, (W * (tall ? 0.76 : 0.84)) / widest);265 const pitch = 76 * u;266 const s0 = H / 2 / pitch + 0.6;267 const scroll = (x: number) => {268 const p = Math.min(1, Math.max(0, x / STOP));269 return s0 + (K - s0) * (1 - (1 - p) ** 3.2);270 };271 const s = scroll(t);272 const vel = Math.abs(scroll(t + 0.5) - scroll(t - 0.5)) * pitch;273 const smear = Math.min(110 * u, vel * 0.6 * motionBlur);274 const taps = smear < 1.5 ? 1 : Math.min(28, Math.ceil(smear / (2 * u)) + 1);275 const tapOffsets = Array.from({ length: taps }, (_, j) =>276 taps === 1 ? 0 : (j / (taps - 1) - 0.5) * smear,277 );278 const tapOpacity = taps === 1 ? 1 : Math.min(1, 2.4 / taps);279 const termAt = hero.indexOf(term);280 const qLeft = termAt >= 0 ? hero.slice(0, termAt) : hero;281 const qRight = termAt >= 0 ? hero.slice(termAt + term.length) : "";282 const wTerm = width(term);283 const totalQ = width(qLeft) + wTerm + width(qRight);284 const aLeft = answerBefore ? `${answerBefore} ` : "";285 const aRight = answerAfter ? ` ${answerAfter}` : "";286 const totalA = width(aLeft) + wTerm + width(aRight);287 const Fh = Math.min(288 (tall ? 96 : 80) * u,289 (W * (tall ? 0.6 : 0.58)) / Math.max(totalQ, totalA),290 );291292 const grow = interpolate(t, [GROW[0], GROW[1]], [0, 1], {293 ...CLAMP,294 easing: EASE_IO,295 });296 const fs = f + (Fh - f) * grow;297 const clear = interpolate(t, [CLEAR[0], CLEAR[1]], [0, 1], {298 ...CLAMP,299 easing: EASE_IO,300 });301 const tint = interpolate(t, [TINT[0], TINT[1]], [0, 1], {302 ...CLAMP,303 easing: EASE_IO,304 });305 const rule = interpolate(t, [RULE[0], RULE[1]], [0, 1], {306 ...CLAMP,307 easing: EASE_OUT,308 });309 const move = interpolate(t, [RESOLVE + 2, RESOLVE + 24], [0, 1], {310 ...CLAMP,311 easing: EASE_IO,312 });313 const leave = interpolate(t, [RESOLVE, RESOLVE + 12], [0, 1], {314 ...CLAMP,315 easing: EXIT,316 });317 const logoIn = interpolate(t, [LOGO_IN, LOGO_IN + 16], [0, 1], {318 ...CLAMP,319 easing: EASE_OUT,320 });321322 const cx = W / 2;323 const heroY = H / 2 + (K - s) * pitch + fs * 0.27 - grow * 18 * u;324 const termQ = -totalQ / 2 + width(qLeft);325 const termA = -totalA / 2 + width(aLeft);326 const termX = termQ + (termA - termQ) * move;327328 const dim = theme === "dark" ? 0.42 : 0.5;329 const heroBright = interpolate(t, [32, 54], [dim, 1], CLAMP);330 const heroEdge = Math.min(331 1,332 Math.max(0, Math.min(heroY, H - heroY) / (H * 0.3)),333 );334335 const fieldIn = spring({336 frame: t - (STOP - 10),337 fps,338 config: { mass: 0.8, damping: 18, stiffness: 160 },339 });340 const fieldOut = interpolate(t, [RESOLVE - 4, RESOLVE + 6], [0, 1], {341 ...CLAMP,342 easing: EXIT,343 });344 const fieldVis = Math.min(1, fieldIn * 1.4) * (1 - fieldOut);345 const fieldH = fs * 1.9;346 const iconS = fs * 0.62;347 const keyS = fs * 0.92;348 const fieldW = totalQ * fs + fs * 2.0 + iconS + keyS + fs * 0.5;349 const enter = Math.max(350 0,351 spring({ frame: t - (RESOLVE - 12), fps, config: CHIP }) -352 spring({ frame: t - (RESOLVE - 5), fps, config: CHIP }),353 );354 const fieldLeft = cx - (totalQ * fs) / 2 - fs * 0.5 - iconS - fs * 0.8;355356 const textStyle = {357 position: "absolute" as const,358 whiteSpace: "pre" as const,359 lineHeight: 1,360 fontFamily,361 fontWeight: 400,362 };363364 const word = (365 text: string,366 x: number,367 anchorRight: boolean,368 opacity: number,369 extra?: React.CSSProperties,370 ) =>371 opacity > 0.001 ? (372 <div373 style={{374 ...textStyle,375 left: cx + x * fs,376 top: heroY - fs * BASELINE,377 fontSize: fs,378 letterSpacing: `${HERO_TRACK}em`,379 color: fg,380 opacity,381 transform: anchorRight ? "translateX(-100%)" : undefined,382 ...extra,383 }}384 >385 {text}386 </div>387 ) : null;388 const arrive = (d: number) =>389 interpolate(t, [RESOLVE + 10 + d, RESOLVE + 26 + d], [0, 1], {390 ...CLAMP,391 easing: EASE_OUT,392 });393 const before = arrive(0);394 const after = arrive(5);395396 return (397 <AbsoluteFill398 style={{ background: background ?? c.base, overflow: "hidden" }}399 >400 {background === undefined ? (401 <>402 <GshGround403 preset={resolvedGround}404 params={resolvedParams}405 timeOffset={dark ? 4 : 2}406 timeScale={0.45}407 />408 <AbsoluteFill style={{ background: c.scrim }} />409 </>410 ) : null}411 <ScaleLayer scale={scale}>412 {clear < 1 ? (413 <div414 style={{415 position: "absolute",416 inset: 0,417 filter: taps > 1 ? `blur(${1.2 * u}px)` : undefined,418 WebkitMaskImage:419 "linear-gradient(180deg, transparent 0%, #000 30%, #000 70%, transparent 100%)",420 maskImage:421 "linear-gradient(180deg, transparent 0%, #000 30%, #000 70%, transparent 100%)",422 }}423 >424 {list.map((q, i) => {425 if (i === K) return null;426 const y0 = H / 2 + (i - s) * pitch;427 const spread = (i - K) * pitch * clear * 1.4;428 const y = y0 + spread;429 if (y < -pitch - smear || y > H + pitch + smear) return null;430 return tapOffsets.map((o) => (431 <div432 key={`${i}-${o.toFixed(2)}`}433 style={{434 ...textStyle,435 left: 0,436 right: 0,437 top: y + o + f * 0.27 - f * BASELINE,438 textAlign: "center",439 fontSize: f,440 letterSpacing: "-0.015em",441 color: fg,442 opacity: (1 - clear) * tapOpacity,443 }}444 >445 {split(q, term).map((p, j) => (446 <span447 key={`${j}-${p.text}`}448 style={{ opacity: p.hit ? 0.78 : dim }}449 >450 {p.text}451 </span>452 ))}453 </div>454 ));455 })}456 </div>457 ) : null}458 {fieldVis > 0.001 ? (459 <div460 style={{461 position: "absolute",462 left: fieldLeft,463 top: heroY - fs * 0.3 - fieldH / 2,464 width: fieldW,465 height: fieldH,466 borderRadius: fieldH / 2,467 background: c.field,468 boxShadow: c.fieldDepth,469 opacity: fieldVis,470 transform: `scale(${0.94 + 0.06 * fieldIn - 0.02 * fieldOut})`,471 }}472 >473 <svg474 viewBox="0 0 24 24"475 width={iconS}476 height={iconS}477 style={{478 position: "absolute",479 left: fs * 0.8,480 top: (fieldH - iconS) / 2,481 }}482 aria-hidden483 >484 <g485 fill="none"486 stroke={c.icon}487 strokeWidth={1.5}488 strokeLinecap="round"489 >490 <circle cx="10.5" cy="10.5" r="6.5" />491 <path d="m15.5 15.5 5 5" />492 </g>493 </svg>494 <div495 style={{496 position: "absolute",497 right: fs * 0.55,498 top: (fieldH - keyS) / 2,499 width: keyS,500 height: keyS,501 borderRadius: keyS * 0.26,502 display: "flex",503 alignItems: "center",504 justifyContent: "center",505 background: interpolateColors(506 enter,507 [0, 1],508 [dark ? "rgba(255,255,255,0.04)" : "#F7F4F0", hi],509 ),510 boxShadow: `inset 0 0 0 1px ${c.keyRing}`,511 transform: `scale(${1 - enter * 0.04})`,512 }}513 >514 <svg515 viewBox="0 0 24 24"516 width={keyS * 0.56}517 height={keyS * 0.56}518 aria-hidden519 >520 <path521 d="M19 5.5v6a3 3 0 0 1-3 3H5.5m4-4-4 4 4 4"522 fill="none"523 stroke={interpolateColors(524 enter,525 [0, 1],526 [c.icon, dark ? "#1A0E06" : "#FFFFFF"],527 )}528 strokeWidth={1.5}529 strokeLinecap="round"530 strokeLinejoin="round"531 />532 </svg>533 </div>534 </div>535 ) : null}536537 {tapOffsets.map((o) => (538 <div539 key={o.toFixed(2)}540 style={{541 position: "absolute",542 inset: 0,543 opacity: heroEdge * tapOpacity,544 transform: o ? `translateY(${o}px)` : undefined,545 }}546 >547 {word(qLeft, termX, true, heroBright * (1 - leave), {548 filter: leave > 0 ? `blur(${leave * 10 * u}px)` : undefined,549 transform: `translateX(calc(-100% - ${leave * 30 * u}px))`,550 })}551 {word(qRight, termX + wTerm, false, heroBright * (1 - leave), {552 filter: leave > 0 ? `blur(${leave * 10 * u}px)` : undefined,553 transform: `translateX(${leave * 30 * u}px)`,554 })}555 {word(aLeft, termX, true, before, {556 filter:557 before < 1 ? `blur(${(1 - before) * 10 * u}px)` : undefined,558 transform: `translateX(calc(-100% + ${(1 - before) * -24 * u}px))`,559 })}560 {word(aRight, termX + wTerm, false, after, {561 filter: after < 1 ? `blur(${(1 - after) * 10 * u}px)` : undefined,562 transform: `translateX(${(1 - after) * 24 * u}px)`,563 })}564 <div565 style={{566 ...textStyle,567 left: cx + termX * fs,568 top: heroY - fs * BASELINE,569 fontSize: fs,570 letterSpacing: `${HERO_TRACK}em`,571 color: interpolateColors(tint, [0, 1], [fg, hi]),572 opacity: Math.max(heroBright, tint),573 }}574 >575 {term}576 </div>577 <div578 style={{579 position: "absolute",580 left: cx + termX * fs,581 top: heroY + fs * 0.16,582 width: wTerm * fs,583 height: Math.max(2, fs * 0.05),584 borderRadius: 99,585 background: hi,586 transform: `scaleX(${rule})`,587 transformOrigin: "0 50%",588 }}589 />590 </div>591 ))}592593 {showLogo && logoIn > 0 ? (594 <div595 style={{596 position: "absolute",597 left: 0,598 right: 0,599 top: heroY + Fh * 0.9,600 display: "flex",601 justifyContent: "center",602 opacity: logoIn,603 transform: `translateY(${(1 - logoIn) * 10 * u}px)`,604 }}605 >606 {logo ?? <KuchiLogo fontSize={26 * u} color={fg} />}607 </div>608 ) : null}609 </ScaleLayer>610 </AbsoluteFill>611 );612}









