Achievement Pop
Stacked achievement toasts unlock one by one, the last a rare gradient-filled card.
Source
components/kuchi/achievement-pop.tsx
1"use client";23import { loadFont as loadGeist } from "@remotion/google-fonts/Geist";4import { loadFont as loadMono } from "@remotion/google-fonts/GeistMono";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: geist } = loadGeist("normal", {20 weights: ["300", "400"],21 subsets: ["latin"],22});23const { fontFamily: mono } = loadMono("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 type AchievementIcon = "trophy" | "bolt" | "star";5354export interface Achievement {55 label: string;56 title: string;57 points: number;58 icon?: AchievementIcon;59}6061export interface AchievementPopProps {62 achievements?: Achievement[];63 accent?: string;64 theme?: "dark" | "light";65 ground?: GshPresetId;66 groundParams?: Partial<GradientParams>;67 /** Small caps label above the running total (portrait only). */68 totalLabel?: string;69 /** Unit after each points value and the total. */70 unit?: string;71 /** Replaces the acme mark under the stack. */72 logo?: React.ReactNode;73 /** Text color of the titles and total; overrides the theme ink. */74 ink?: string;75 /** Solid fill in place of the gradient ground; "transparent" drops it. */76 background?: string;77 /** Typeface for the titles and numbers. Load it yourself; Geist by default. */78 fontFamily?: string;79 /** Size of the stack, around the frame's center. */80 scale?: number;81 /** Frames to hold the first frame before anything moves. */82 delay?: number;83 speed?: number;84}8586const BEATS = {87 starts: [4, 34, 58],88 open: 6,89 shiftLead: 6,90 poster: 30,91 logo: 10,92} as const;9394const ENTER = Easing.bezier(0.32, 0.72, 0, 1);95const CLAMP = {96 extrapolateLeft: "clamp",97 extrapolateRight: "clamp",98} as const;99100const CHIP = { mass: 0.5, damping: 12, stiffness: 200 };101const CARD = { mass: 0.8, damping: 18, stiffness: 160 };102const HEAVY = { mass: 1, damping: 26, stiffness: 120 };103const MORPH = { damping: 200 };104105const KILN = ["#5C0A02", "#E2340C", "#FF9A3A", "#FFE9C7"] as const;106const RARE_FILL = `linear-gradient(104deg, #2A0903 0%, ${KILN[0]} 30%, #A8260A 68%, ${KILN[1]} 100%)`;107108const DARK_GROUND: Partial<GradientParams> = {109 colors: ["#2A0601", "#7A1404", "#E2340C", "#FF9A3A"],110};111112const LIGHT_GROUND: Partial<GradientParams> = {113 kind: "mist",114 colors: ["#F08A4B", "#F7C39A", "#F3E3D3", "#7A2E12"],115 background: "#F2EEE8",116 speed: 0.8,117 loopSeconds: 14,118 scale: 0.8,119 warp: 0.4,120 blur: 0.65,121 grain: 0.3,122 seed: 4,123};124125const THEMES = {126 dark: {127 base: "#060201",128 scrim:129 "radial-gradient(64% 58% at 50% 44%, rgba(6,3,2,0.7) 0%, rgba(6,3,2,0) 100%)",130 pill: "#141112",131 depth:132 "inset 0 1px 0 rgba(255,255,255,0.07), 0 0 0 1px rgba(255,255,255,0.08), 0 18px 40px -14px rgba(0,0,0,0.7)",133 badge: "#1D191A",134 ring: "rgba(255,255,255,0.12)",135 ink: "#F4F1EC",136 dim: "#9A928C",137 rule: "rgba(255,255,255,0.1)",138 flash: KILN[3],139 logo: "#1A0803",140 },141 light: {142 base: "#F2EEE8",143 scrim:144 "radial-gradient(64% 58% at 50% 44%, rgba(246,243,238,0.7) 0%, rgba(246,243,238,0.2) 100%)",145 pill: "#FFFFFF",146 depth:147 "0 0 0 1px rgba(40,24,12,0.06), 0 1px 3px rgba(40,24,12,0.06), 0 16px 32px -14px rgba(90,40,10,0.22)",148 badge: "#F6F3EE",149 ring: "rgba(40,24,12,0.1)",150 ink: "#17120F",151 dim: "#857B73",152 rule: "rgba(40,24,12,0.1)",153 flash: KILN[1],154 logo: "#17120F",155 },156} as const;157158/** The foreground at `scale`, around the frame's center; nothing extra at 1. */159function ScaleLayer({160 scale,161 children,162}: {163 scale: number;164 children: React.ReactNode;165}) {166 if (scale === 1) return children;167 return (168 <AbsoluteFill style={{ transform: `scale(${scale})` }}>169 {children}170 </AbsoluteFill>171 );172}173174function Icon({175 name,176 size,177 color,178}: {179 name: AchievementIcon;180 size: number;181 color: string;182}) {183 const common = {184 fill: "none",185 stroke: color,186 strokeWidth: 1.5,187 strokeLinecap: "round" as const,188 strokeLinejoin: "round" as const,189 };190 return (191 <svg viewBox="0 0 24 24" width={size} height={size} aria-hidden>192 {name === "trophy" ? (193 <g {...common}>194 <path d="M7.5 4h9v4.5a4.5 4.5 0 0 1-9 0V4Z" />195 <path d="M7.5 6H5.2a2 2 0 0 0 0 4h2.6M16.5 6h2.3a2 2 0 0 1 0 4h-2.6" />196 <path d="M12 13v4M9 20h6M10 17h4" />197 </g>198 ) : name === "bolt" ? (199 <path {...common} d="M13.5 3 6 13.4h5.4L10.5 21 18 10.6h-5.4L13.5 3Z" />200 ) : (201 <path202 {...common}203 d="M12 3.6l2.6 5.3 5.8.8-4.2 4.1 1 5.8L12 16.9l-5.2 2.7 1-5.8-4.2-4.1 5.8-.8L12 3.6Z"204 />205 )}206 </svg>207 );208}209210export function AchievementPop({211 achievements = [212 {213 label: "Unlocked · 64% of makers",214 title: "Shipped in one day",215 points: 100,216 icon: "trophy",217 },218 {219 label: "Unlocked · 23% of makers",220 title: "Zero keyframes by hand",221 points: 50,222 icon: "bolt",223 },224 {225 label: "Rare · 1.8% of makers",226 title: "Launch video shipped",227 points: 250,228 icon: "star",229 },230 ],231 theme = "dark",232 ground,233 groundParams,234 totalLabel = "Launch week",235 unit = "XP",236 logo,237 ink: inkProp,238 background,239 fontFamily = geist,240 scale = 1,241 delay = 0,242 speed = 1,243}: AchievementPopProps) {244 const t = Math.max(0, useCurrentFrame() - delay) * speed;245 const { width: W, height: H, fps } = useVideoConfig();246 const tall = H > W;247 const dark = theme === "dark";248 const c = THEMES[theme];249 const fg = inkProp ?? c.ink;250 const u = tall ? (W * 0.88) / 820 : Math.min(W / 1280, H / 720);251 const resolvedGround: GshPresetId | undefined =252 ground ?? (groundParams ? undefined : dark ? "kiln" : undefined);253 const resolvedParams = groundParams ?? (dark ? DARK_GROUND : LIGHT_GROUND);254255 const list = achievements.slice(0, BEATS.starts.length);256 const n = list.length;257 const starts = BEATS.starts.slice(0, n);258 const lastStart = starts[n - 1] ?? BEATS.starts[0];259260 const ph = 116 * u;261 const D = ph;262 const pw = 820 * u;263 const gap = ph + 20 * u;264 const cy = tall ? 0.4 * H : 0.46 * H;265266 const sp = (from: number, config: Partial<typeof CARD>, dur?: number) =>267 spring({268 frame: t - from,269 fps,270 config,271 durationInFrames: dur,272 });273274 const kf =275 1 + starts.slice(1).reduce((a, s) => a + sp(s - BEATS.shiftLead, CARD), 0);276 const posterAt = lastStart + BEATS.poster;277 const poster = sp(posterAt, HEAVY);278 const stackK = interpolate(kf, [1, 2, 3], [1.26, 1.1, 1], CLAMP);279 const groupK = stackK * interpolate(poster, [0, 1], [1, tall ? 1.04 : 1.12]);280 const logoP = interpolate(281 t,282 [posterAt + BEATS.logo, posterAt + BEATS.logo + 14],283 [0, 1],284 { ...CLAMP, easing: ENTER },285 );286287 const total = list.reduce(288 (a, item, i) =>289 a +290 item.points *291 interpolate(t, [starts[i] + 10, starts[i] + 22], [0, 1], {292 ...CLAMP,293 easing: ENTER,294 }),295 0,296 );297 const totalIn = interpolate(t, [starts[0] + 8, starts[0] + 22], [0, 1], {298 ...CLAMP,299 easing: ENTER,300 });301302 return (303 <AbsoluteFill304 style={{305 background:306 background === undefined307 ? c.base308 : background === "transparent"309 ? undefined310 : background,311 overflow: "hidden",312 }}313 >314 {background === undefined ? (315 <>316 <GshGround317 preset={resolvedGround}318 params={resolvedParams}319 timeOffset={dark ? 5 : 3}320 timeScale={0.45}321 />322 <AbsoluteFill style={{ background: c.scrim }} />323 </>324 ) : null}325326 <ScaleLayer scale={scale}>327 <div328 style={{329 position: "absolute",330 inset: 0,331 transform: `scale(${groupK})`,332 transformOrigin: `50% ${(cy / H) * 100}%`,333 }}334 >335 {list.map((a, i) => {336 const s = starts[i];337 if (t < s) return null;338 const rare = i === n - 1 && n > 1;339 const y = cy + (i - (kf - 1) / 2) * gap;340 const pop = sp(s, CHIP);341 const badgeK = 0.5 + 0.5 * pop;342 const open = sp(s + BEATS.open, MORPH, 16);343 const pillW = D + (pw - D) * open;344 const left = W / 2 - pillW / 2;345 const textP = interpolate(346 t,347 [s + BEATS.open + 4, s + BEATS.open + 16],348 [0, 1],349 { ...CLAMP, easing: ENTER },350 );351 const ptsP = interpolate(352 t,353 [s + BEATS.open + 8, s + BEATS.open + 20],354 [0, 1],355 { ...CLAMP, easing: ENTER },356 );357 const flashP = interpolate(t, [s + 2, s + 16], [0, 1], {358 ...CLAMP,359 easing: ENTER,360 });361 const sheen = interpolate(362 t,363 [s + BEATS.open + 14, s + BEATS.open + 32],364 [0, 1],365 { ...CLAMP, easing: Easing.bezier(0.65, 0, 0.35, 1) },366 );367 const ink = rare ? "#FFF4E8" : fg;368 const dim = rare ? "rgba(255,233,199,0.72)" : c.dim;369 const bx = left + D / 2;370 const R = D / 2;371 const appear = interpolate(t, [s, s + 3], [0, 1], CLAMP);372 return (373 <div key={`${a.title}-${s}`}>374 <div375 style={{376 position: "absolute",377 left,378 top: y - ph / 2,379 width: pillW,380 height: ph,381 borderRadius: ph / 2,382 overflow: "hidden",383 background: rare ? RARE_FILL : c.pill,384 boxShadow: rare385 ? `inset 0 1px 0 rgba(255,233,199,0.28), 0 0 0 1px rgba(255,154,58,0.28), 0 22px 48px -14px rgba(120,24,4,${dark ? 0.8 : 0.45})`386 : c.depth,387 opacity: appear,388 }}389 >390 {rare && sheen > 0 && sheen < 1 ? (391 <div392 style={{393 position: "absolute",394 top: 0,395 bottom: 0,396 width: 160 * u,397 left: interpolate(398 sheen,399 [0, 1],400 [-200 * u, pw + 40 * u],401 ),402 background:403 "linear-gradient(100deg, transparent 0%, rgba(255,233,199,0.32) 50%, transparent 100%)",404 transform: "skewX(-20deg)",405 }}406 />407 ) : null}408 <div409 style={{410 position: "absolute",411 left: D + 22 * u,412 top: 0,413 bottom: 0,414 display: "flex",415 flexDirection: "column",416 justifyContent: "center",417 gap: 10 * u,418 opacity: textP,419 transform: `translateX(${(1 - textP) * -24 * u}px)`,420 whiteSpace: "nowrap",421 }}422 >423 <div424 style={{425 fontFamily: mono,426 fontWeight: 400,427 fontSize: 17 * u,428 lineHeight: 1,429 letterSpacing: "0.04em",430 textTransform: "uppercase",431 color: dim,432 }}433 >434 {a.label}435 </div>436 <div437 style={{438 fontFamily,439 fontWeight: 400,440 fontSize: 40 * u,441 lineHeight: 1,442 letterSpacing: "-0.03em",443 color: ink,444 }}445 >446 {a.title}447 </div>448 </div>449 <div450 style={{451 position: "absolute",452 left: pw - 220 * u,453 width: 180 * u,454 top: 0,455 bottom: 0,456 display: "flex",457 alignItems: "center",458 justifyContent: "flex-end",459 gap: 8 * u,460 opacity: ptsP,461 transform: `translateX(${(1 - ptsP) * -16 * u}px)`,462 whiteSpace: "nowrap",463 }}464 >465 <span466 style={{467 fontFamily,468 fontWeight: 300,469 fontSize: 40 * u,470 lineHeight: 1,471 letterSpacing: "-0.03em",472 fontVariantNumeric: "tabular-nums",473 color: ink,474 }}475 >476 +{a.points}477 </span>478 <span479 style={{480 fontFamily: mono,481 fontWeight: 400,482 fontSize: 17 * u,483 letterSpacing: "0.04em",484 color: dim,485 transform: `translateY(${4 * u}px)`,486 }}487 >488 {unit}489 </span>490 </div>491 </div>492493 {flashP > 0 && flashP < 1 ? (494 <svg495 width={W}496 height={H}497 style={{498 position: "absolute",499 inset: 0,500 overflow: "visible",501 }}502 aria-hidden503 >504 <circle505 cx={bx}506 cy={y}507 r={R * interpolate(flashP, [0, 1], [0.9, 1.7])}508 fill="none"509 stroke={rare ? KILN[2] : c.flash}510 strokeWidth={interpolate(flashP, [0, 1], [5, 0.5]) * u}511 opacity={(1 - flashP) * 0.9}512 />513 </svg>514 ) : null}515516 <div517 style={{518 position: "absolute",519 left: bx - R,520 top: y - R,521 width: D,522 height: D,523 transform: `scale(${badgeK})`,524 opacity: appear,525 }}526 >527 <div528 style={{529 position: "absolute",530 inset: 10 * u,531 borderRadius: "50%",532 background: rare ? "rgba(255,233,199,0.12)" : c.badge,533 boxShadow: rare534 ? "inset 0 0 0 1px rgba(255,233,199,0.45)"535 : `inset 0 0 0 1px ${c.ring}`,536 display: "flex",537 alignItems: "center",538 justifyContent: "center",539 }}540 >541 <Icon name={a.icon ?? "trophy"} size={40 * u} color={ink} />542 </div>543 </div>544 </div>545 );546 })}547 </div>548549 {tall ? (550 <div551 style={{552 position: "absolute",553 left: 0,554 right: 0,555 top: 0.66 * H,556 display: "flex",557 flexDirection: "column",558 alignItems: "center",559 gap: 18 * u,560 opacity: totalIn,561 transform: `translateY(${(1 - totalIn) * 24 * u}px)`,562 }}563 >564 <div565 style={{566 fontFamily: mono,567 fontWeight: 400,568 fontSize: 20 * u,569 letterSpacing: "0.06em",570 textTransform: "uppercase",571 color: c.dim,572 }}573 >574 {totalLabel}575 </div>576 <div577 style={{578 fontFamily,579 fontWeight: 300,580 fontSize: 170 * u,581 lineHeight: 1,582 letterSpacing: "-0.05em",583 fontVariantNumeric: "tabular-nums",584 color: fg,585 }}586 >587 {Math.round(total)}588 <span589 style={{ fontSize: 56 * u, letterSpacing: "0", color: c.dim }}590 >591 {" "}592 {unit}593 </span>594 </div>595 </div>596 ) : null}597598 <div599 style={{600 position: "absolute",601 left: 0,602 width: W,603 top: tall ? 0.88 * H : 0.885 * H,604 display: "flex",605 justifyContent: "center",606 opacity: logoP,607 transform: `translateY(${(1 - logoP) * 14 * u}px)`,608 }}609 >610 {logo ?? <KuchiLogo fontSize={30 * u} color={c.logo} />}611 </div>612 </ScaleLayer>613 </AbsoluteFill>614 );615}







