Handwrite
Handwritten text laid down letter by letter on a quantized stop-motion clock, each glyph keeping its own slant and baseline wobble.
Source
components/kuchi/handwrite.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/Caveat";4import { useCurrentFrame } from "remotion";5import { DEFAULT_STEP, hashRange, qf, qstep } from "@/lib/kuchi/stop-motion";67const { fontFamily: HAND_FAMILY } = loadFont("normal", {8 subsets: ["latin"],9 weights: ["400", "500", "600", "700"],10});1112export interface HandwriteProps {13 text?: string;14 fontSize?: number;15 color?: string;16 delay?: number;17 perStep?: number;18 weight?: 400 | 500 | 600 | 700;19 align?: "left" | "center";20 fontFamily?: string;21 step?: number;22}2324export function Handwrite({25 text = "ship it today",26 fontSize = 54,27 color = "#26242c",28 delay = 0,29 perStep = 1.6,30 weight = 600,31 align = "center",32 fontFamily = HAND_FAMILY,33 step = DEFAULT_STEP,34}: HandwriteProps) {35 const frame = useCurrentFrame();36 const steps = Math.max(0, qstep(Math.max(0, qf(frame, step) - delay), step));37 const shown = Math.floor(steps * perStep);38 const chars = Array.from(text);39 const freshFrom = shown - Math.ceil(perStep);4041 return (42 <div43 style={{44 position: "absolute",45 inset: 0,46 display: "flex",47 alignItems: "center",48 justifyContent: align === "center" ? "center" : "flex-start",49 background: "transparent",50 }}51 >52 <span53 style={{54 display: "inline-block",55 fontFamily: `${fontFamily}, cursive`,56 fontWeight: weight,57 fontSize,58 lineHeight: 1.15,59 color,60 whiteSpace: "pre-wrap",61 textAlign: align,62 }}63 >64 {chars.map((char, i) => {65 const visible = i < shown;66 const slant = hashRange(`hw:${text}:${i}:r`, -3.2, 3.2);67 const dy = hashRange(`hw:${text}:${i}:y`, -1.8, 1.8);68 const fresh = visible && i >= freshFrom;69 return (70 <span71 key={i}72 style={{73 display: "inline-block",74 whiteSpace: "pre",75 opacity: visible ? 1 : 0,76 translate: visible ? `0 ${dy}px` : undefined,77 rotate: visible ? `${slant}deg` : undefined,78 scale: visible ? `${fresh ? 1.06 : 1}` : undefined,79 }}80 >81 {char}82 </span>83 );84 })}85 </span>86 </div>87 );88}8990export function handwriteDuration(91 text: string,92 options?: { perStep?: number; step?: number },93): number {94 const perStep = options?.perStep ?? 1.6;95 const step = options?.step ?? DEFAULT_STEP;96 return Math.ceil(Array.from(text).length / perStep) * step + step;97}









