Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"type": "remotion-element",
"version": 1,
"element": {
"assets": [],
"dependencies": [
{
"name": "@remotion/google-fonts",
"version": null
}
],
"dimensions": null,
"displayName": "Long Vowel",
"initialProps": null,
"slug": "long-vowel",
"sourceCode": "import { loadFont as loadFraunces } from \"@remotion/google-fonts/Fraunces\";\nimport React, { forwardRef, useEffect, useId, useImperativeHandle, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, continueRender, delayRender, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst fraunces = loadFraunces(\"normal\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\nloadFraunces(\"italic\", { weights: [\"400\"], subsets: [\"latin\"] });\n\ninterface LongVowelProps {\n word?: string;\n letter?: string;\n repeat?: number;\n rest?: string;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: {\n bg: \"#0A0A0B\",\n ink: \"#F4F3F0\",\n muted: \"#B4B2B9\",\n ramp: (a: string) => [\"#F4F3F0\", \"#fff4ec\", \"#ffb36b\", \"#e2457a\", a],\n grain: 0.05,\n },\n light: {\n bg: \"#F5F4F0\",\n ink: \"#111113\",\n muted: \"#5F5D58\",\n ramp: (a: string) => [\"#111113\", \"#2a2f8f\", a, \"#d93d73\", \"#e0702c\"],\n grain: 0.035,\n },\n} as const;\n\nconst TRACK = -0.035;\nconst REST_TRACK = -0.01;\nconst FONT_PX = 400;\n\nconst RISE_AT = 0;\nconst RISE_LEN = 16;\nconst RISE_GAP = 2;\nconst DRAWL_AT = 28;\nconst DRAWL_GAP = 4;\nconst REST_GAP_AFTER = 4;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n x: number[];\n width: number;\n rest: number;\n asc: number;\n desc: number;\n capTop: number;\n restAsc: number;\n restDesc: number;\n}\n\nfunction measure(drawn: string, rest: string): Metrics {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) throw new Error(\"long-vowel: no 2d context\");\n const fam = `\"${fraunces.fontFamily}\"`;\n ctx.font = `400 ${FONT_PX}px ${fam}`;\n const chars = Array.from(drawn);\n const x: number[] = [];\n let prefix = \"\";\n for (let i = 0; i < chars.length; i++) {\n x.push(ctx.measureText(prefix).width / FONT_PX + TRACK * i);\n prefix += chars[i];\n }\n const width =\n ctx.measureText(drawn).width / FONT_PX + TRACK * (chars.length - 1);\n const fm = ctx.measureText(drawn);\n const capTop = fm.actualBoundingBoxAscent / FONT_PX;\n const asc = fm.fontBoundingBoxAscent / FONT_PX;\n const desc = fm.fontBoundingBoxDescent / FONT_PX;\n ctx.font = `italic 400 ${FONT_PX}px ${fam}`;\n const rm = ctx.measureText(rest || \" \");\n return {\n x,\n width,\n rest:\n rest.length > 0\n ? rm.width / FONT_PX + REST_TRACK * Array.from(rest).length\n : 0,\n asc,\n desc,\n capTop,\n restAsc: rm.actualBoundingBoxAscent / FONT_PX,\n restDesc: rm.actualBoundingBoxDescent / FONT_PX,\n };\n}\n\nfunction useMetrics(drawn: string, rest: string) {\n const [metrics, setMetrics] = useState<Metrics | null>(null);\n const [handle] = useState(() => delayRender(\"long-vowel: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n fraunces.waitUntilDone(),\n document.fonts.load(`400 100px \"${fraunces.fontFamily}\"`),\n document.fonts.load(`italic 400 100px \"${fraunces.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setMetrics(measure(drawn, rest));\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [drawn, rest, handle]);\n return metrics;\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n const id = `lv${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n return (\n <svg\n width=\"100%\"\n height=\"100%\"\n style={{\n position: \"absolute\",\n inset: 0,\n opacity,\n mixBlendMode: \"overlay\",\n pointerEvents: \"none\",\n }}\n aria-hidden\n >\n <filter id={id}>\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.9\"\n numOctaves={2}\n seed={5}\n />\n <feColorMatrix type=\"saturate\" values=\"0\" />\n </filter>\n <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n </svg>\n );\n}\n\nfunction rampAt(ramp: readonly string[], u: number) {\n const s = Math.min(Math.max(u, 0), 1) * (ramp.length - 1);\n const i = Math.min(Math.floor(s), ramp.length - 2);\n const f = s - i;\n return `color-mix(in oklab, ${ramp[i]} ${((1 - f) * 100).toFixed(1)}%, ${ramp[i + 1]})`;\n}\n\nfunction LongVowelBase({\n word = \"Way\",\n letter,\n repeat = 5,\n rest = \"less keyframing.\",\n accent = \"#3B5BFD\",\n background,\n speed = 1,\n theme = \"dark\",\n}: LongVowelProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H, fps } = useVideoConfig();\n const c = THEMES[theme];\n const bg = background ?? c.bg;\n const ramp = c.ramp(accent);\n\n const chars = useMemo(() => Array.from(word), [word]);\n const hold = useMemo(() => {\n if (letter) {\n const i = chars.indexOf(letter);\n if (i >= 0) return i;\n }\n const v = chars.findIndex((ch) => /[aeiouyAEIOUY]/.test(ch));\n return v >= 0 ? v : Math.max(0, Math.floor((chars.length - 1) / 2));\n }, [chars, letter]);\n const copies = Math.max(1, Math.round(repeat));\n const drawn = useMemo(\n () =>\n [\n ...chars.slice(0, hold + 1),\n ...Array.from({ length: copies }, () => chars[hold]),\n ...chars.slice(hold + 1),\n ].join(\"\"),\n [chars, hold, copies],\n );\n const m = useMetrics(drawn, rest);\n\n if (!m) {\n return <div style={{ position: \"absolute\", inset: 0, background: bg }} />;\n }\n\n const F = Math.min(H * 0.4, (W * 0.88) / m.width);\n const R = rest\n ? Math.min(F * 0.36, (W * 0.84) / Math.max(0.1, m.rest), H * 0.1)\n : 0;\n const gap = rest ? F * 0.3 : 0;\n const blockTop = m.capTop * F;\n const blockBot = rest ? gap + (m.restAsc + m.restDesc) * R : 0;\n const baseY = H / 2 + (blockTop - blockBot) / 2;\n const restBase = baseY + gap + m.restAsc * R;\n\n const prog = Array.from({ length: copies }, (_, k) =>\n spring({\n frame: t - DRAWL_AT - k * DRAWL_GAP,\n fps,\n config: { damping: 15, stiffness: 140, mass: 0.8 },\n }),\n );\n const vel = prog.map((_, k) => {\n const a = spring({\n frame: t - DRAWL_AT - k * DRAWL_GAP - 1,\n fps,\n config: { damping: 15, stiffness: 140, mass: 0.8 },\n });\n return prog[k] - a;\n });\n\n const n = chars.length + copies;\n const fx = m.x;\n const step = (i: number) => (i + 1 < n ? fx[i + 1] - fx[i] : 0);\n const xs: number[] = [];\n let shrink = 0;\n for (let i = 0; i < n; i++) {\n if (i > hold && i <= hold + copies) {\n const k = i - hold - 1;\n shrink += (1 - prog[k]) * step(i - 1);\n }\n xs.push(fx[i] - shrink);\n }\n const curW = m.width - shrink;\n const left = (W - curW * F) / 2;\n\n const maskTop = baseY - m.asc * F;\n const maskH = (m.asc + m.desc) * F;\n const lineTop = baseY - (m.asc + (1 - m.asc - m.desc) / 2) * F;\n\n const drawnChars = Array.from(drawn);\n const glyphs: React.ReactNode[] = [];\n for (let i = n - 1; i >= 0; i--) {\n const ch = drawnChars[i];\n const isCopy = i > hold && i <= hold + copies;\n const k = isCopy ? i - hold - 1 : -1;\n const ri = i <= hold ? i : isCopy ? hold : i - copies;\n const rp = interpolate(\n t,\n [RISE_AT + ri * RISE_GAP, RISE_AT + ri * RISE_GAP + RISE_LEN],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n const dy = (1 - rp) * maskH * 1.05;\n let color: string = c.ink;\n let opacity = 1;\n let skew = 0;\n if (isCopy) {\n const u0 = (k + 1) / copies;\n const u1 = Math.min(1, (k + 1.6) / copies);\n color = rampAt(ramp, u0);\n opacity = interpolate(prog[k], [0, 0.25], [0, 1], CLAMP);\n skew = Math.max(-14, Math.min(14, -vel[k] * 90));\n glyphs.push(\n <div\n key={`g${i}`}\n style={{\n position: \"absolute\",\n left: left + xs[i] * F,\n top: lineTop - maskTop + dy,\n fontFamily: fraunces.fontFamily,\n fontWeight: 400,\n fontSize: F,\n lineHeight: `${F}px`,\n whiteSpace: \"pre\",\n opacity,\n transform: `skewX(${skew.toFixed(2)}deg)`,\n transformOrigin: `0 ${(m.asc * F).toFixed(1)}px`,\n backgroundImage: `linear-gradient(90deg, ${color}, ${rampAt(ramp, u1)})`,\n WebkitBackgroundClip: \"text\",\n backgroundClip: \"text\",\n color: \"transparent\",\n }}\n >\n {ch}\n </div>,\n );\n continue;\n }\n glyphs.push(\n <div\n key={`g${i}`}\n style={{\n position: \"absolute\",\n left: left + xs[i] * F,\n top: lineTop - maskTop + dy,\n fontFamily: fraunces.fontFamily,\n fontWeight: 400,\n fontSize: F,\n lineHeight: `${F}px`,\n whiteSpace: \"pre\",\n color,\n }}\n >\n {ch}\n </div>,\n );\n }\n\n const restAt = DRAWL_AT + (copies - 1) * DRAWL_GAP + 14 + REST_GAP_AFTER;\n const restWords = rest ? rest.split(\" \") : [];\n\n return (\n <AbsoluteFill style={{ background: bg, overflow: \"hidden\" }}>\n <div\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: maskTop,\n height: maskH,\n overflow: \"hidden\",\n }}\n >\n {glyphs}\n </div>\n {rest ? (\n <div\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: restBase - R,\n height: R * 1.3,\n overflow: \"hidden\",\n display: \"flex\",\n justifyContent: \"center\",\n fontFamily: fraunces.fontFamily,\n fontStyle: \"italic\",\n fontWeight: 400,\n fontSize: R,\n lineHeight: `${R}px`,\n letterSpacing: `${REST_TRACK}em`,\n color: c.muted,\n whiteSpace: \"pre\",\n }}\n >\n {restWords.map((w, k) => {\n const p = interpolate(\n t,\n [restAt + k * 3, restAt + k * 3 + 16],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n return (\n <span\n key={`${w}-${k}`}\n style={{\n display: \"inline-block\",\n transform: `translateY(${((1 - p) * R * 1.2).toFixed(2)}px)`,\n }}\n >\n {w}\n {k < restWords.length - 1 ? \" \" : \"\"}\n </span>\n );\n })}\n </div>\n ) : null}\n {bg === \"transparent\" ? null : <Grain opacity={c.grain} />}\n </AbsoluteFill>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n theme: {\n type: \"enum\",\n default: \"dark\",\n variants: {\n dark: {},\n light: {},\n },\n description: \"Theme\",\n },\n accent: {\n type: \"color\",\n default: \"#3B5BFD\",\n description: \"Accent\",\n },\n word: {\n type: \"text-content\",\n default: \"Way\",\n description: \"Word\",\n },\n rest: {\n type: \"text-content\",\n default: \"less keyframing.\",\n description: \"Rest\",\n },\n repeat: {\n type: \"number\",\n default: 5,\n min: 0,\n max: 15,\n step: 1,\n description: \"Repeat\",\n hiddenFromList: false,\n },\n speed: {\n type: \"number\",\n default: 1,\n min: 0.25,\n max: 4,\n step: 0.25,\n description: \"Speed\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"theme\",\"accent\",\"word\",\"rest\",\"repeat\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n accent: \"#3B5BFD\",\n word: \"Way\",\n rest: \"less keyframing.\",\n repeat: 5,\n speed: 1,\n};\n\ntype LongVowelElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof LongVowelBase>;\n\nconst LongVowelInner = forwardRef<\n HTMLDivElement,\n LongVowelElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<LongVowel>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <LongVowelBase\n {...(componentProps as unknown as ComponentProps<typeof LongVowelBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const LongVowel = Interactive.withSchema({\n Component: LongVowelInner,\n componentName: \"<LongVowel>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 81,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 81
}