Rim Draw Card
A settings card gets its rim drawn in light, revealing a brand-voice toggle and text field.
Source
components/kuchi/rim-draw-card.tsx
1"use client";23import { loadFont as loadMono } from "@remotion/google-fonts/GeistMono";4import { loadFont as loadHanken } from "@remotion/google-fonts/HankenGrotesk";5import type React from "react";6import {7 AbsoluteFill,8 Easing,9 interpolate,10 spring,11 useCurrentFrame,12 useVideoConfig,13} from "remotion";14import type { GradientParams } from "@/lib/kuchi/gsh/gradient-engine";15import { GshGround } from "@/lib/kuchi/gsh/gsh-ground";16import type { GshPresetId } from "@/lib/kuchi/gsh/presets";1718const hanken = loadHanken("normal", {19 weights: ["300", "400"],20 subsets: ["latin"],21});22const mono = loadMono("normal", { weights: ["400"], subsets: ["latin"] });2324const ENTER = Easing.bezier(0.32, 0.72, 0, 1);25const DRAW = Easing.bezier(0.22, 1, 0.36, 1);26const MOVE = Easing.bezier(0.65, 0, 0.35, 1);27const SWAY = Easing.bezier(0.45, 0, 0.55, 1);28const HEAVY = { mass: 1, damping: 26, stiffness: 120 };29const CHIP = { mass: 0.5, damping: 12, stiffness: 200 };30const PRESS = { mass: 0.5, damping: 14, stiffness: 260 };3132const B = {33 words: -8,34 stroke: 18,35 strokeLen: 30,36 erase: 20,37 slide: 18,38 chip: 24,39 tail: 32,40 tailLen: 16,41 body: 36,42 pan: 36,43 title: 42,44 field: 48,45 footer: 54,46 type: 60,47 chips: 66,48 preview: 78,49 press: 96,50 saved: 99,51 end: 138,52};5354export const RIM_DRAW_CARD_DURATION = B.end;5556const ramp = (f: number, start: number, dur: number, easing = ENTER) =>57 interpolate(f, [start, start + dur], [0, 1], {58 extrapolateLeft: "clamp",59 extrapolateRight: "clamp",60 easing,61 });6263const mix = (a: number, b: number, t: number) => a + (b - a) * t;6465export interface RimDrawCardProps {66 theme?: "dark" | "light";67 accent?: string;68 primary?: string;69 line?: string;70 command?: string;71 title?: string;72 subtitle?: string;73 label?: string;74 instructions?: string;75 action?: string;76 limit?: number;77 done?: string;78 uses?: string[];79 preview?: string;80 /** Secondary button next to the action. */81 cancelLabel?: string;82 /** Hint in the instructions field before typing starts. */83 placeholder?: string;84 /** Characters typed per frame in the instructions field. */85 typeRate?: number;86 /** Text color of the headline line; overrides the theme. */87 ink?: string;88 /** Solid fill in place of the gradient ground; "transparent" drops it. */89 background?: string;90 /** Typeface for the copy. Load it yourself; Hanken Grotesk by default. */91 fontFamily?: string;92 /** Size of the foreground around the frame's center. */93 scale?: number;94 /** Frames to hold the first frame before anything moves. */95 delay?: number;96 speed?: number;97 ground?: GshPresetId;98 groundParams?: Partial<GradientParams>;99}100101function Icon({102 d,103 size,104 color,105 width = 1.5,106}: {107 d: string;108 size: number;109 color: string;110 width?: number;111}) {112 return (113 <svg viewBox="0 0 24 24" width={size} height={size} aria-hidden>114 <path115 d={d}116 fill="none"117 stroke={color}118 strokeWidth={width}119 strokeLinecap="round"120 strokeLinejoin="round"121 />122 </svg>123 );124}125126const CHECK = "m5 12.5 4.5 4.5L19 7.5";127128/** The foreground at `scale`, around the frame's center; nothing extra at 1. */129function ScaleLayer({130 scale,131 children,132}: {133 scale: number;134 children: React.ReactNode;135}) {136 if (scale === 1) return children;137 return (138 <AbsoluteFill style={{ transform: `scale(${scale})` }}>139 {children}140 </AbsoluteFill>141 );142}143144export function RimDrawCard({145 theme = "dark",146 accent,147 primary,148 line = "Just tell it once.",149 command = "/brand-voice",150 title = "Brand voice",151 subtitle = "Used every time you write launch copy.",152 label = "Instructions",153 instructions = "Short, calm sentences. Name the feature first, then what it saves you.",154 action = "Save skill",155 limit = 600,156 done = "Saved",157 uses = ["Launch posts", "Changelog", "Release emails"],158 preview = "Scenes now render three times faster. Ship the reel tonight.",159 cancelLabel = "Cancel",160 placeholder = "Describe how this skill should write",161 typeRate = 2.2,162 ink,163 background,164 fontFamily = hanken.fontFamily,165 scale = 1,166 delay = 0,167 speed = 1,168 ground,169 groundParams,170}: RimDrawCardProps) {171 const frame = Math.max(0, useCurrentFrame() - delay) * speed;172 const { width, height, fps } = useVideoConfig();173 const dark = theme === "dark";174 const portrait = height > width * 1.2;175 const stageW = portrait ? 1080 : 1280;176 const stageH = portrait ? 1920 : 720;177 const sc = width / stageW;178179 const acc = accent ?? (dark ? "#9cc2ff" : "#2a5cff");180 const prim = primary ?? (dark ? "#3B5BFD" : "#1f4fff");181 const fg = ink ?? (dark ? "#f2f6ff" : "#0f1320");182 const cardInk = dark ? "#eef2fa" : "#121624";183 const muted = dark ? "rgba(222,230,246,0.58)" : "rgba(18,22,36,0.56)";184 const hair = dark ? "rgba(255,255,255,0.09)" : "rgba(16,22,48,0.11)";185186 const cw = portrait ? 880 : 680;187 const u = portrait ? 1.76 : 1.18;188 const ch = (portrait ? 622 : 368) * u;189 const r = 16 * u;190 const pad = 24 * u;191 const lead = stageW * 0.75;192 const fontSize = portrait ? 92 : 50;193194 const len1 = cw + lead - r;195 const total = len1 + 2 * Math.PI * r + 2 * (ch - 2 * r) + (cw - 2 * r);196 const tailEnd = lead + r;197 const pathD = `M ${cw + lead} 0 L ${r} 0 A ${r} ${r} 0 0 0 0 ${r} L 0 ${ch - r} A ${r} ${r} 0 0 0 ${r} ${ch} L ${cw - r} ${ch} A ${r} ${r} 0 0 0 ${cw} ${ch - r} L ${cw} ${r} A ${r} ${r} 0 0 0 ${cw - r} 0`;198199 const head = ramp(frame, B.stroke, B.strokeLen, DRAW) * total;200 const tail = ramp(frame, B.tail, B.tailLen, MOVE) * tailEnd;201 const drawn = ramp(frame, B.stroke + B.strokeLen - 6, 6, MOVE);202 const settle = ramp(frame, B.body + 6, 24, MOVE);203 const visible = Math.max(0, head - tail);204 const hotLen = Math.min(visible, 90 * u);205206 const bodyIn = ramp(frame, B.body, 12, DRAW);207 const chipIn = spring({ frame: frame - B.chip, fps, config: CHIP });208 const chipHot = ramp(frame, B.chip, 6) * (1 - 0.7 * bodyIn);209210 const pan = spring({ frame: frame - B.pan, fps, config: HEAVY });211 const slide = spring({ frame: frame - B.slide, fps, config: HEAVY });212 const offX = portrait ? 0 : mix(300, 0, pan);213 const offY = portrait ? mix(300, 0, pan) : 0;214 const lineX = portrait ? 0 : mix(0, -330, slide);215 const lineY = portrait ? mix(0, -560, slide) : 0;216217 const brighten = ramp(frame, B.body - 4, 24, SWAY);218 const push = 1 + 0.035 * ramp(frame, B.pan, B.end - B.pan, SWAY);219220 const typed = Math.round(221 interpolate(222 frame,223 [B.type, B.type + instructions.length / typeRate],224 [0, instructions.length],225 { extrapolateLeft: "clamp", extrapolateRight: "clamp" },226 ),227 );228 const caret =229 frame >= B.field + 6 &&230 frame < B.press &&231 (typed < instructions.length || Math.floor(frame / 8) % 2 === 0);232 const focus = ramp(frame, B.type - 6, 8) * (1 - ramp(frame, B.press, 8));233 const press =234 spring({ frame: frame - B.press, fps, config: PRESS }) -235 spring({ frame: frame - B.press - 4, fps, config: PRESS });236 const savedIn = spring({ frame: frame - B.saved, fps, config: CHIP });237 const savedOn = frame >= B.saved;238239 const item = (start: number) => {240 const p = ramp(frame, start, 12);241 return {242 opacity: p,243 transform: `translateY(${mix(10 * u, 0, p)}px)`,244 filter: p < 1 ? `blur(${(1 - p) * 4}px)` : undefined,245 };246 };247248 const letters = Array.from(line);249 const n = letters.length;250251 const resolvedGround: GshPresetId =252 ground ?? (dark ? "film-blue" : "paper-crease");253254 const surface = dark255 ? "linear-gradient(180deg, #131722 0%, #0d1018 100%)"256 : "#ffffff";257258 return (259 <AbsoluteFill style={{ fontFamily, overflow: "hidden" }}>260 {background === undefined ? (261 <>262 <GshGround263 preset={resolvedGround}264 params={groundParams}265 timeOffset={5}266 timeScale={0.55}267 />268 <AbsoluteFill269 style={{270 background: dark ? "#02050c" : "#f4f3f0",271 opacity: mix(dark ? 0.58 : 0.55, dark ? 0.12 : 0.3, brighten),272 }}273 />274 </>275 ) : (276 <AbsoluteFill277 style={{278 background: background === "transparent" ? undefined : background,279 }}280 />281 )}282 <ScaleLayer scale={scale}>283 <div284 style={{285 position: "absolute",286 left: 0,287 top: 0,288 width: stageW,289 height: stageH,290 transform: `scale(${sc})`,291 transformOrigin: "0 0",292 }}293 >294 <div295 style={{296 position: "absolute",297 inset: 0,298 transform: `scale(${push})`,299 transformOrigin: "50% 50%",300 }}301 >302 <div303 style={{304 position: "absolute",305 left: "50%",306 top: "50%",307 transform: `translate(-50%, -50%) translate(${lineX}px, ${lineY}px)`,308 display: "flex",309 whiteSpace: "pre",310 fontSize,311 fontWeight: 300,312 letterSpacing: "-0.035em",313 lineHeight: 1.1,314 color: fg,315 }}316 >317 {letters.map((ch_, i) => {318 const rise = ramp(frame, B.words + Math.floor(i / 3), 14);319 const k = n - 1 - i;320 const gone = ramp(frame, B.erase + k * 0.72, 7, MOVE);321 return (322 <span323 key={`${ch_}-${i.toString()}`}324 style={{325 display: "inline-block",326 opacity: rise * (1 - gone),327 transform: `translateY(${mix(0.5, 0, rise)}em) translateX(${gone * 0.18}em)`,328 filter:329 rise < 1 || gone > 0330 ? `blur(${(1 - rise) * 6 + gone * 10}px)`331 : undefined,332 }}333 >334 {ch_}335 </span>336 );337 })}338 </div>339340 <div341 style={{342 position: "absolute",343 left: stageW / 2 - cw / 2 + offX,344 top: stageH / 2 - ch / 2 + offY,345 width: cw,346 height: ch,347 }}348 >349 <div350 style={{351 position: "absolute",352 inset: 0,353 borderRadius: r,354 background: surface,355 boxShadow: dark356 ? `0 0 0 1px rgba(255,255,255,0.08), 0 ${28 * u}px ${70 * u}px -${10 * u}px rgba(0,2,10,0.6)`357 : `0 0 0 1px rgba(16,22,48,0.07), 0 1px 3px rgba(16,22,48,0.06), 0 ${26 * u}px ${60 * u}px -${14 * u}px rgba(16,22,48,0.22)`,358 opacity: bodyIn,359 transform: `scale(${mix(0.985, 1, bodyIn)})`,360 }}361 />362 <div363 style={{364 position: "absolute",365 inset: 0,366 padding: pad,367 display: "flex",368 flexDirection: "column",369 color: cardInk,370 }}371 >372 <div373 style={{374 display: "flex",375 alignItems: "center",376 justifyContent: "space-between",377 }}378 >379 <div380 style={{381 display: "flex",382 alignItems: "center",383 gap: 10 * u,384 height: 30 * u,385 padding: `0 ${10 * u}px`,386 borderRadius: 7 * u,387 fontFamily: mono.fontFamily,388 fontSize: 15 * u,389 color: dark390 ? `color-mix(in oklab, ${acc} 80%, white)`391 : acc,392 background: `color-mix(in oklab, ${acc} ${Math.round((dark ? 12 : 9) + 10 * chipHot)}%, transparent)`,393 opacity: ramp(frame, B.chip, 4),394 transform: `scale(${mix(0.7, 1, chipIn)})`,395 transformOrigin: "0% 50%",396 }}397 >398 {command}399 </div>400 </div>401402 <div403 style={{404 ...item(B.title),405 display: "flex",406 alignItems: "center",407 gap: 10 * u,408 marginTop: 22 * u,409 }}410 >411 <div412 style={{413 fontSize: 30 * u,414 letterSpacing: "-0.025em",415 lineHeight: 1.15,416 }}417 >418 {title}419 </div>420 </div>421 <div422 style={{423 ...item(B.title + 3),424 fontSize: 18 * u,425 color: muted,426 marginTop: 6 * u,427 textWrap: "pretty",428 }}429 >430 {subtitle}431 </div>432433 <div434 style={{435 ...item(B.field),436 fontSize: 16 * u,437 color: muted,438 marginTop: 22 * u,439 }}440 >441 {label}442 </div>443 <div444 style={{445 ...item(B.field + 2),446 marginTop: 8 * u,447 position: "relative",448 height: (portrait ? 112 : 96) * u,449 borderRadius: 10 * u,450 border: `1px solid ${focus > 0 ? `color-mix(in oklab, ${acc} ${Math.round(focus * 60)}%, ${hair})` : hair}`,451 boxShadow: `0 0 0 ${3 * u * focus}px color-mix(in oklab, ${acc} ${Math.round(focus * 16)}%, transparent)`,452 background: dark ? "rgba(255,255,255,0.035)" : "#fbfcff",453 padding: `${12 * u}px ${14 * u}px`,454 fontSize: 18 * u,455 lineHeight: 1.45,456 color: typed > 0 ? cardInk : muted,457 }}458 >459 {typed > 0 ? instructions.slice(0, typed) : placeholder}460 <span461 style={{462 display: "inline-block",463 width: 2 * u,464 height: 20 * u,465 marginLeft: 2 * u,466 verticalAlign: "-0.18em",467 background: acc,468 opacity: caret ? 1 : 0,469 }}470 />471 <div472 style={{473 position: "absolute",474 right: 12 * u,475 bottom: 9 * u,476 fontFamily: mono.fontFamily,477 fontSize: 14 * u,478 lineHeight: 1,479 color: muted,480 fontVariantNumeric: "tabular-nums",481 }}482 >483 {`${typed} / ${limit}`}484 </div>485 </div>486487 {portrait ? (488 <>489 <div490 style={{491 ...item(B.chips - 4),492 fontSize: 16 * u,493 color: muted,494 marginTop: 24 * u,495 }}496 >497 Use it for498 </div>499 <div500 style={{501 display: "flex",502 flexWrap: "wrap",503 gap: 8 * u,504 marginTop: 10 * u,505 }}506 >507 {uses.map((c, i) => {508 const s = spring({509 frame: frame - B.chips - i * 3,510 fps,511 config: CHIP,512 });513 return (514 <div515 key={c}516 style={{517 padding: `${7 * u}px ${12 * u}px`,518 borderRadius: 99,519 border: `1px solid ${hair}`,520 background: dark521 ? "rgba(255,255,255,0.04)"522 : "#f6f7fb",523 fontSize: 16 * u,524 opacity: ramp(frame, B.chips + i * 3, 4),525 transform: `scale(${mix(0.6, 1, s)})`,526 }}527 >528 {c}529 </div>530 );531 })}532 </div>533 <div534 style={{535 ...item(B.preview),536 fontSize: 16 * u,537 color: muted,538 marginTop: 24 * u,539 }}540 >541 Preview542 </div>543 <div544 style={{545 ...item(B.preview + 3),546 marginTop: 10 * u,547 display: "flex",548 gap: 12 * u,549 padding: `${14 * u}px ${16 * u}px`,550 borderRadius: 10 * u,551 background: `color-mix(in oklab, ${acc} ${dark ? 9 : 7}%, transparent)`,552 fontSize: 18 * u,553 lineHeight: 1.45,554 }}555 >556 <div557 style={{558 width: 3 * u,559 borderRadius: 2 * u,560 background: acc,561 flexShrink: 0,562 }}563 />564 {preview}565 </div>566 </>567 ) : null}568569 <div570 style={{571 ...item(B.footer),572 marginTop: "auto",573 display: "flex",574 alignItems: "center",575 justifyContent: "flex-end",576 fontSize: 17 * u,577 }}578 >579 <div580 style={{581 display: "flex",582 alignItems: "center",583 gap: 10 * u,584 }}585 >586 <div587 style={{588 padding: `${8 * u}px ${12 * u}px`,589 color: muted,590 }}591 >592 {cancelLabel}593 </div>594 <div595 style={{596 display: "flex",597 alignItems: "center",598 gap: 6 * u,599 padding: `${8 * u}px ${16 * u}px`,600 borderRadius: 8 * u,601 background: prim,602 color: "#fff",603 transform: `scale(${1 - 0.04 * press})`,604 boxShadow: `inset 0 1px 0 rgba(255,255,255,0.22), 0 1px 2px rgba(0,0,0,0.2)`,605 }}606 >607 <div608 style={{609 width: savedOn ? 18 * u : 0,610 overflow: "hidden",611 transform: `scale(${savedIn})`,612 display: "flex",613 }}614 >615 <Icon616 d={CHECK}617 size={18 * u}618 color="#fff"619 width={2.2}620 />621 </div>622 {savedOn ? done : action}623 </div>624 </div>625 </div>626 </div>627628 <svg629 width={cw + lead + 40}630 height={ch + 40}631 viewBox={`-20 -20 ${cw + lead + 40} ${ch + 40}`}632 style={{633 position: "absolute",634 left: -20,635 top: -20,636 overflow: "visible",637 pointerEvents: "none",638 }}639 aria-hidden640 >641 <defs>642 <filter643 id="rim-glow"644 x="-20%"645 y="-20%"646 width="140%"647 height="140%"648 >649 <feGaussianBlur stdDeviation={5 * u} />650 </filter>651 </defs>652 <g opacity={visible > 0.5 ? 1 : 0}>653 <path654 d={pathD}655 fill="none"656 stroke={acc}657 strokeWidth={7 * u}658 strokeLinecap="round"659 strokeDasharray={`${visible} ${total * 2}`}660 strokeDashoffset={-tail}661 filter="url(#rim-glow)"662 opacity={mix(dark ? 0.5 : 0.3, 0, settle)}663 />664 <path665 d={pathD}666 fill="none"667 stroke={668 dark ? `color-mix(in oklab, ${acc} 70%, white)` : acc669 }670 strokeWidth={mix(1.8, 1.1, settle)}671 strokeLinecap="round"672 strokeDasharray={`${visible} ${total * 2}`}673 strokeDashoffset={-tail}674 opacity={mix(1, 0, settle)}675 />676 <path677 d={pathD}678 fill="none"679 stroke={dark ? "#ffffff" : acc}680 strokeWidth={3 * u}681 strokeLinecap="round"682 strokeDasharray={`${hotLen} ${total * 2}`}683 strokeDashoffset={-(head - hotLen)}684 filter="url(#rim-glow)"685 opacity={1 - drawn}686 />687 <path688 d={pathD}689 fill="none"690 stroke="#ffffff"691 strokeWidth={2.2}692 strokeLinecap="round"693 strokeDasharray={`${hotLen * 0.5} ${total * 2}`}694 strokeDashoffset={-(head - hotLen * 0.5)}695 opacity={(1 - drawn) * (dark ? 1 : 0.9)}696 />697 </g>698 </svg>699 </div>700 </div>701 </div>702 </ScaleLayer>703 </AbsoluteFill>704 );705}706707export default RimDrawCard;







