Toolbar Unfurl
A round tap button unfurls into a tool strip while captions list each tool over a glowing ribbon.
Source
components/kuchi/toolbar-unfurl.tsx
1"use client";23import { loadFont as loadFigtree } from "@remotion/google-fonts/Figtree";4import type React from "react";5import type { CSSProperties } from "react";6import {7 AbsoluteFill,8 Easing,9 interpolate,10 interpolateColors,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 figtree = loadFigtree("normal", {20 weights: ["300", "400"],21 subsets: ["latin"],22});2324const ENTER = Easing.bezier(0.32, 0.72, 0, 1);25const LIGHT = Easing.bezier(0.22, 1, 0.36, 1);26const EXIT = Easing.bezier(0.55, 0, 1, 0.45);27const SWAY = Easing.bezier(0.45, 0, 0.55, 1);28const HEAVY = { mass: 1, damping: 26, stiffness: 120 };29const TILE = { mass: 0.8, damping: 18, stiffness: 160 };30const CHIP = { mass: 0.5, damping: 12, stiffness: 200 };31const GLIDE = { mass: 0.8, damping: 22, stiffness: 150 };3233const B = {34 pop: -8,35 unfurl: [6, 10, 14],36 disc: 18,37 hops: [42, 62, 78],38 retract: 94,39 punch: 106,40 caption: 100,41 end: 150,42};4344export const TOOLBAR_UNFURL_DURATION = B.end;4546const CLAMP = {47 extrapolateLeft: "clamp",48 extrapolateRight: "clamp",49} as const;5051const ramp = (f: number, start: number, dur: number, easing = ENTER) =>52 interpolate(f, [start, start + dur], [0, 1], { ...CLAMP, easing });5354const mix = (a: number, b: number, t: number) => a + (b - a) * t;5556const ICONS = {57 select:58 "M9 3.75H7.75a4 4 0 0 0-4 4V9M3.75 13.25v1M14.5 3.75h1.75a4 4 0 0 1 4 4V9M9 20.25H7.75a4 4 0 0 1-4-4V15M12 11.5l7.5 2.9-3.3 1.2-1.3 3.4z",59 text: "M5.5 6.5V4.75h13V6.5M12 4.75v14.5M9.25 19.25h5.5",60 draw: "M15.25 4.75l4 4L8.5 19.5H4.5v-4zM13 7l4 4",61 comment:62 "M5.25 5h13.5a1.75 1.75 0 0 1 1.75 1.75v8.5A1.75 1.75 0 0 1 18.75 17H12l-4.25 3.25V17h-2.5A1.75 1.75 0 0 1 3.5 15.25v-8.5A1.75 1.75 0 0 1 5.25 5z",63};6465type ToolId = keyof typeof ICONS;66const ORDER: ToolId[] = ["select", "text", "draw", "comment"];6768function ToolIcon({69 id,70 size,71 color,72}: {73 id: ToolId;74 size: number;75 color: string;76}) {77 return (78 <svg79 viewBox="0 0 24 24"80 width={size}81 height={size}82 style={{ display: "block" }}83 aria-hidden84 >85 <path86 d={ICONS[id]}87 fill="none"88 stroke={color}89 strokeWidth={1.5}90 strokeLinecap="round"91 strokeLinejoin="round"92 />93 </svg>94 );95}9697export interface ToolbarUnfurlProps {98 theme?: "dark" | "light";99 accent?: string;100 lines?: string[];101 finalLine?: string;102 /** Weight of the captions. */103 fontWeight?: number;104 /** Show the cursor that clicks through the tools. */105 cursor?: boolean;106 /** Text color of the captions; overrides the theme. */107 ink?: string;108 /** Solid fill in place of the gradient ground; "transparent" drops it. */109 background?: string;110 /** Typeface for the captions. Load it yourself; Figtree by default. */111 fontFamily?: string;112 /** Size of the foreground around the frame's center. */113 scale?: number;114 /** Frames to hold the first frame before anything moves. */115 delay?: number;116 speed?: number;117 ground?: GshPresetId;118 groundParams?: Partial<GradientParams>;119}120121/** The foreground at `scale`, around the frame's center; nothing extra at 1. */122function ScaleLayer({123 scale,124 children,125}: {126 scale: number;127 children: React.ReactNode;128}) {129 if (scale === 1) return children;130 return (131 <AbsoluteFill style={{ transform: `scale(${scale})` }}>132 {children}133 </AbsoluteFill>134 );135}136137export function ToolbarUnfurl({138 theme = "dark",139 accent = "#3B5BFD",140 lines = [141 "Leave a note.",142 "Sketch the shot.",143 "Type on the frame.",144 "Select any layer.",145 ],146 finalLine = "Every tool, one tap away.",147 fontWeight = 300,148 cursor = true,149 ink,150 background,151 fontFamily = figtree.fontFamily,152 scale = 1,153 delay = 0,154 speed = 1,155 ground,156 groundParams,157}: ToolbarUnfurlProps) {158 const frame = Math.max(0, useCurrentFrame() - delay) * speed;159 const { width, height, fps } = useVideoConfig();160 const dark = theme === "dark";161 const portrait = height > width * 1.2;162 const stageW = portrait ? 1080 : 1280;163 const stageH = portrait ? 1920 : 720;164 const sc = width / stageW;165166 const fg = ink ?? (dark ? "#f2f3f7" : "#13151b");167 const iconIdle = dark ? "rgba(236,238,245,0.82)" : "rgba(20,22,30,0.78)";168 const pillBg = dark ? "rgba(22,23,28,0.84)" : "rgba(255,255,255,0.9)";169 const pillShadow = dark170 ? "0 0 0 1px rgba(255,255,255,0.08), inset 0 1px 0 rgba(255,255,255,0.06), 0 12px 32px rgba(0,0,0,0.45)"171 : "0 0 0 1px rgba(16,18,30,0.06), 0 1px 2px rgba(16,20,40,0.06), 0 14px 36px rgba(16,20,40,0.12)";172173 const slot = portrait ? 176 : 96;174 const pad = portrait ? 16 : 9;175 const thick = slot + pad * 2;176 const disc = slot - (portrait ? 12 : 6);177 const outerR = portrait ? 56 : 30;178 const discR = outerR - pad - (slot - disc) / 2;179 const iconSize = portrait ? 64 : 34;180 const capSize = portrait ? 108 : 66;181 const N = ORDER.length;182 const last = N - 1;183184 const centerX = stageW / 2;185 const centerY = portrait ? 1150 : 278;186 const captionTop = portrait ? 686 : centerY + 118;187 const caretW = portrait ? 92 : 50;188189 const pop = spring({ frame: frame - B.pop, fps, config: CHIP });190 const unfurl = ORDER.slice(0, last).map((_, i) =>191 spring({ frame: frame - B.unfurl[i], fps, config: TILE }),192 );193 const retract = Math.min(194 1,195 spring({ frame: frame - B.retract, fps, config: HEAVY }),196 );197198 const spanOut = Math.max(199 0,200 ...ORDER.slice(0, last).map((_, i) => (last - i) * slot * unfurl[i]),201 );202 const span = spanOut * (1 - retract);203 const pillLen = slot + pad * 2 + span;204 const extra = caretW * Math.max(0, retract);205 const caretIn = ramp(frame, B.retract + 8, 12, LIGHT);206207 const pos = (i: number) => {208 const retracted = i * slot * (1 - retract);209 if (retract > 0) return -span / 2 + retracted;210 const off = i < last ? -(last - i) * slot * unfurl[i] : 0;211 return span / 2 + off;212 };213214 const discK = B.hops.reduce(215 (acc, h) => acc + spring({ frame: frame - h, fps, config: CHIP }),216 0,217 );218 const discKPrev = B.hops.reduce(219 (acc, h) => acc + spring({ frame: frame - 1 - h, fps, config: CHIP }),220 0,221 );222 const discSlot = last - discK;223 const vel = Math.abs(discK - discKPrev);224 const discIn = spring({ frame: frame - B.disc, fps, config: CHIP });225 const discPos =226 retract > 0227 ? pos(0)228 : interpolate(229 discSlot,230 ORDER.map((_, i) => i),231 ORDER.map((_, i) => pos(i)),232 { extrapolateLeft: "extend", extrapolateRight: "extend" },233 );234 const stretch = 1 + Math.min(0.22, vel * 0.6);235 const squash = 1 - Math.min(0.1, vel * 0.3);236 const punch = spring({ frame: frame - B.punch, fps, config: CHIP });237 const punchS =238 frame >= B.punch ? 1 + 0.05 * Math.sin(Math.min(1, punch) * Math.PI) : 1;239240 const toolPresence = (i: number) => {241 const anchor = retract > 0 ? 0 : last;242 if (i === anchor) return 1;243 return interpolate(244 Math.abs(pos(i) - pos(anchor)),245 [slot * 0.2, slot * 0.85],246 [0, 1],247 CLAMP,248 );249 };250251 const along = (v: number) => `translate(${v}px, 0px)`;252253 const lineStarts = [B.disc, ...B.hops];254 const capItems = lines.slice(0, N).map((text, i) => {255 const start = lineStarts[i];256 const nextStart = i < N - 1 ? lineStarts[i + 1] : B.retract;257 const enter = ramp(frame, start + (i === 0 ? 0 : 3), 12);258 const exit = ramp(frame, nextStart, 7, EXIT);259 return { text, enter, exit, key: `l${i.toString()}` };260 });261 const finalEnter = ramp(frame, B.caption, 14);262263 const push = 1 + 0.04 * ramp(frame, 0, B.end, SWAY);264 const lift = Math.min(265 1,266 spring({ frame: frame - B.retract - 2, fps, config: HEAVY }),267 );268 const groupY = mix(0, portrait ? 0 : 24, lift);269 const fold = 1 + 0.16 * lift;270271 const cursorPts = [272 { f: -4, x: centerX + 260, y: centerY + 260 },273 { f: B.disc - 4, x: 0, y: 0, tool: last },274 { f: B.disc + 2, x: 0, y: 0, tool: last },275 ...B.hops.flatMap((h, i) => [276 { f: h - 5, x: 0, y: 0, tool: last - 1 - i },277 { f: h + 2, x: 0, y: 0, tool: last - 1 - i },278 ]),279 { f: B.retract + 14, x: centerX + 220, y: centerY + 230 },280 ];281 const resolvePt = (p: (typeof cursorPts)[number]) => {282 if (p.tool === undefined) return { x: p.x, y: p.y };283 const o = pos(p.tool);284 return { x: centerX + o + slot * 0.12, y: centerY + slot * 0.12 };285 };286 let cx = cursorPts[0].x;287 let cy = cursorPts[0].y;288 for (let i = 0; i < cursorPts.length - 1; i++) {289 const a = cursorPts[i];290 const b = cursorPts[i + 1];291 if (frame >= a.f) {292 const t = spring({293 frame: frame - a.f,294 fps,295 config: GLIDE,296 durationInFrames: Math.max(4, b.f - a.f),297 });298 const pa = resolvePt(a);299 const pb = resolvePt(b);300 const dx = pb.x - pa.x;301 const dy = pb.y - pa.y;302 const bow = Math.sin(Math.PI * Math.min(1, t)) * 0.16;303 cx = mix(pa.x, pb.x, t) - dy * bow;304 cy = mix(pa.y, pb.y, t) + dx * bow;305 }306 }307 const clicks = [B.disc, ...B.hops];308 const pressAt = (c: number) =>309 Math.max(310 0,311 spring({ frame: frame - c + 2, fps, config: CHIP }) -312 spring({ frame: frame - c - 2, fps, config: CHIP }),313 );314 const press = clicks.reduce((acc, c) => Math.max(acc, pressAt(c)), 0);315 const cursorFade = 1 - ramp(frame, B.retract + 4, 10, EXIT);316317 const resolvedGround: GshPresetId | undefined =318 ground ?? (groundParams ? undefined : dark ? "afterhours" : "glasswork");319320 const pillStyle: CSSProperties = {321 left: centerX - pillLen / 2,322 top: centerY - thick / 2,323 width: pillLen + extra,324 height: thick,325 };326327 const discColor = accent;328329 return (330 <AbsoluteFill style={{ fontFamily, overflow: "hidden" }}>331 {background === undefined ? (332 <>333 <GshGround334 preset={resolvedGround}335 params={groundParams}336 timeOffset={dark ? 9 : 5}337 timeScale={0.45}338 style={339 portrait340 ? { transform: "scaleY(1.55)", transformOrigin: "50% 0%" }341 : undefined342 }343 />344 <AbsoluteFill345 style={{346 background: dark347 ? "linear-gradient(180deg, rgba(8,9,12,0.62) 0%, rgba(8,9,12,0.42) 55%, rgba(8,9,12,0.3) 100%)"348 : "linear-gradient(180deg, rgba(248,248,250,0.5) 0%, rgba(248,248,250,0.15) 70%, rgba(248,248,250,0) 100%)",349 }}350 />351 </>352 ) : (353 <AbsoluteFill354 style={{355 background: background === "transparent" ? undefined : background,356 }}357 />358 )}359 <ScaleLayer scale={scale}>360 <div361 style={{362 position: "absolute",363 left: 0,364 top: 0,365 width: stageW,366 height: stageH,367 transform: `scale(${sc})`,368 transformOrigin: "0 0",369 }}370 >371 <div372 style={{373 position: "absolute",374 inset: 0,375 transform: `scale(${push}) translateY(${groupY}px)`,376 transformOrigin: `50% ${(centerY / stageH) * 100}%`,377 }}378 >379 <div380 style={{381 position: "absolute",382 inset: 0,383 transform: `translateX(${-extra / 2}px) scale(${fold})`,384 transformOrigin: `${centerX}px ${centerY}px`,385 }}386 >387 <div388 style={{389 position: "absolute",390 ...pillStyle,391 borderRadius: outerR,392 background: pillBg,393 boxShadow: pillShadow,394 backdropFilter: "blur(24px)",395 transform: `scale(${mix(0.55, 1, pop) * punchS})`,396 opacity: ramp(frame, B.pop, 6, LIGHT),397 }}398 />399 <div400 style={{401 position: "absolute",402 left: centerX - disc / 2,403 top: centerY - disc / 2,404 width: disc,405 height: disc,406 borderRadius: discR,407 background: discColor,408 boxShadow: `inset 0 1px 0 rgba(255,255,255,0.22), 0 1px 2px rgba(0,0,0,${dark ? 0.35 : 0.14})`,409 transform: `${along(discPos)} scale(${stretch * discIn * punchS}, ${squash * discIn * punchS})`,410 opacity: Math.min(1, discIn * 1.4),411 }}412 />413 <div414 style={{415 position: "absolute",416 left: 0,417 top: 0,418 width: stageW,419 height: stageH,420 clipPath: `inset(0 ${stageW - centerX - pillLen / 2 + 2}px 0 ${centerX - pillLen / 2 + 2}px round ${outerR}px)`,421 }}422 >423 {ORDER.map((id, i) => {424 const near = Math.max(425 0,426 1 -427 Math.abs((retract > 0 ? 0 : discSlot) - i) *428 (retract > 0 ? 99 : 1.6),429 );430 const lit = (retract > 0 ? (i === 0 ? 1 : 0) : near) * discIn;431 const c = interpolateColors(432 lit,433 [0, 1],434 [iconIdle, "#ffffff"],435 );436 const hit =437 last - i < clicks.length ? pressAt(clicks[last - i]) : 0;438 return (439 <div440 key={id}441 style={{442 position: "absolute",443 left: centerX - slot / 2,444 top: centerY - slot / 2,445 width: slot,446 height: slot,447 display: "flex",448 alignItems: "center",449 justifyContent: "center",450 transform: `${along(pos(i))} scale(${mix(0.55, 1, pop) * (1 - 0.04 * hit)})`,451 opacity: toolPresence(i),452 zIndex: i === last ? 2 : 1,453 }}454 >455 <ToolIcon id={id} size={iconSize} color={c} />456 </div>457 );458 })}459 </div>460 {caretIn > 0 ? (461 <div462 style={{463 position: "absolute",464 left: centerX + pillLen / 2 - pad,465 top: centerY - slot / 2,466 width: caretW,467 height: slot,468 display: "flex",469 alignItems: "center",470 justifyContent: "center",471 opacity: caretIn,472 transform: `translateY(${mix(-6, 0, caretIn)}px) scale(${punchS})`,473 }}474 >475 <svg476 viewBox="0 0 24 24"477 width={iconSize * 0.72}478 height={iconSize * 0.72}479 style={{ display: "block" }}480 aria-hidden481 >482 <path483 d="M7 10l5 5 5-5"484 fill="none"485 stroke={iconIdle}486 strokeWidth={1.8}487 strokeLinecap="round"488 strokeLinejoin="round"489 />490 </svg>491 </div>492 ) : null}493 </div>494 <div495 style={{496 position: "absolute",497 left: 0,498 right: 0,499 top: captionTop,500 height: capSize * (portrait ? 2.5 : 1.3),501 textAlign: "center",502 fontSize: capSize,503 fontWeight,504 letterSpacing: "-0.035em",505 lineHeight: 1.15,506 textWrap: "balance",507 color: fg,508 }}509 >510 {capItems.map((c) =>511 c.enter > 0 && c.exit < 1 ? (512 <div513 key={c.key}514 style={{515 position: "absolute",516 inset: 0,517 overflow: "hidden",518 padding: portrait ? "0 80px 0.12em" : "0 0 0.12em",519 display: "flex",520 flexDirection: "column",521 justifyContent: portrait ? "flex-end" : "flex-start",522 }}523 >524 <div525 style={{526 transform: `translateY(${mix(105, 0, c.enter) - 110 * c.exit}%)`,527 filter:528 c.enter < 1 || c.exit > 0529 ? `blur(${(1 - c.enter) * 6 + c.exit * 6}px)`530 : undefined,531 opacity: 1 - c.exit,532 }}533 >534 {c.text}535 </div>536 </div>537 ) : null,538 )}539 {finalEnter > 0 ? (540 <div541 style={{542 position: "absolute",543 inset: 0,544 overflow: "hidden",545 padding: portrait ? "0 80px 0.12em" : "0 0 0.12em",546 display: "flex",547 flexDirection: "column",548 justifyContent: portrait ? "flex-end" : "flex-start",549 }}550 >551 <div552 style={{553 transform: `translateY(${mix(100, 0, finalEnter)}%)`,554 filter:555 finalEnter < 1556 ? `blur(${(1 - finalEnter) * 6}px)`557 : undefined,558 }}559 >560 {finalLine}561 </div>562 </div>563 ) : null}564 </div>565 {cursor ? (566 <div567 style={{568 position: "absolute",569 left: cx - 6,570 top: cy - 4,571 opacity: cursorFade * ramp(frame, -4, 6, LIGHT),572 transform: `scale(${1 - 0.04 * press})`,573 transformOrigin: "20% 15%",574 }}575 >576 <svg577 viewBox="0 0 24 24"578 width={portrait ? 56 : 30}579 height={portrait ? 56 : 30}580 style={{581 display: "block",582 filter: "drop-shadow(0 3px 5px rgba(0,0,0,0.35))",583 }}584 aria-hidden585 >586 <path587 d="M5 3.2v15.6l4.3-4.1 2.7 6.1 2.6-1.1-2.7-6h6z"588 fill="#0d0f10"589 stroke="#fff"590 strokeWidth={1.4}591 strokeLinejoin="round"592 />593 </svg>594 </div>595 ) : null}596 </div>597 </div>598 </ScaleLayer>599 </AbsoluteFill>600 );601}602603export default ToolbarUnfurl;









