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": "opentype.js",
"version": "2.0.0"
}
],
"dimensions": null,
"displayName": "Stretch In",
"initialProps": null,
"slug": "stretch-in",
"sourceCode": "import { parse, type Font } from \"opentype.js\";\nimport { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, continueRender, delayRender, interpolate, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ninterface StretchInProps {\n className?: string;\n width?: number;\n height?: number;\n text?: string;\n fontUrl?: string;\n fontSize?: number;\n letterSpacing?: number;\n baselineY?: number;\n entryStart?: number;\n entryStagger?: number;\n travelFrames?: number;\n travelDistance?: number;\n vertexLagFrames?: number;\n curveSteps?: number;\n fill?: string;\n strokeWidth?: number;\n stroke?: string;\n}\n\ntype Contour = [number, number][];\n\nfunction flattenPath(\n commands: ReturnType<Font[\"getPath\"]>[\"commands\"],\n steps: number,\n): Contour[] {\n const contours: Contour[] = [];\n let current: Contour = [];\n let cx = 0;\n let cy = 0;\n\n for (const cmd of commands) {\n if (cmd.type === \"M\") {\n if (current.length > 0) contours.push(current);\n current = [[cmd.x, cmd.y]];\n cx = cmd.x;\n cy = cmd.y;\n } else if (cmd.type === \"L\") {\n current.push([cmd.x, cmd.y]);\n cx = cmd.x;\n cy = cmd.y;\n } else if (cmd.type === \"Q\") {\n for (let i = 1; i <= steps; i++) {\n const t = i / steps;\n const mt = 1 - t;\n current.push([\n mt * mt * cx + 2 * mt * t * cmd.x1 + t * t * cmd.x,\n mt * mt * cy + 2 * mt * t * cmd.y1 + t * t * cmd.y,\n ]);\n }\n cx = cmd.x;\n cy = cmd.y;\n } else if (cmd.type === \"C\") {\n for (let i = 1; i <= steps; i++) {\n const t = i / steps;\n const mt = 1 - t;\n current.push([\n mt * mt * mt * cx +\n 3 * mt * mt * t * cmd.x1 +\n 3 * mt * t * t * cmd.x2 +\n t * t * t * cmd.x,\n mt * mt * mt * cy +\n 3 * mt * mt * t * cmd.y1 +\n 3 * mt * t * t * cmd.y2 +\n t * t * t * cmd.y,\n ]);\n }\n cx = cmd.x;\n cy = cmd.y;\n } else if (cmd.type === \"Z\") {\n if (current.length > 0) contours.push(current);\n current = [];\n }\n }\n if (current.length > 0) contours.push(current);\n return contours;\n}\n\nfunction StretchInBase({\n className,\n width = 1920,\n height = 1080,\n text = \"REMOCN\",\n fontUrl = \"https://fonts.gstatic.com/s/anton/v27/1Ptgg87LROyAm0K0.ttf\",\n fontSize = 510,\n letterSpacing = 0,\n baselineY,\n entryStart = 0,\n entryStagger = 3,\n travelFrames = 33,\n travelDistance = 1500,\n vertexLagFrames = 3.5,\n curveSteps = 8,\n fill = \"#ffffff\",\n strokeWidth = 0,\n stroke = \"#ffffff\",\n}: StretchInProps) {\n const frame = useCurrentFrame();\n const [font, setFont] = useState<Font | null>(null);\n\n useEffect(() => {\n const handle = delayRender(\"stretch-in: loading font\");\n let cancelled = false;\n fetch(fontUrl)\n .then((res) => res.arrayBuffer())\n .then((buffer) => {\n if (!cancelled) setFont(parse(buffer));\n continueRender(handle);\n })\n .catch(() => {\n continueRender(handle);\n });\n return () => {\n cancelled = true;\n };\n }, [fontUrl]);\n\n const letters = useMemo(() => {\n if (!font) return null;\n const scale = fontSize / font.unitsPerEm;\n const glyphs = font.stringToGlyphs(text);\n let x = 0;\n const items = glyphs.map((glyph, i) => {\n if (i > 0) x += font.getKerningValue(glyphs[i - 1], glyph) * scale;\n const left = x;\n const advance = (glyph.advanceWidth ?? 0) * scale;\n const contours = flattenPath(\n glyph.getPath(x, 0, fontSize).commands,\n curveSteps,\n );\n x += advance + letterSpacing;\n return { left, width: advance, contours };\n });\n return { items, totalWidth: Math.max(0, x - letterSpacing) };\n }, [font, text, fontSize, letterSpacing, curveSteps]);\n\n if (!letters) return null;\n\n const startX = (width - letters.totalWidth) / 2;\n const resolvedBaseline = baselineY ?? (height + fontSize * 0.72) / 2;\n\n return (\n <div\n className={className}\n style={{ position: \"absolute\", inset: 0, overflow: \"hidden\" }}\n >\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox={`0 0 ${width} ${height}`}\n preserveAspectRatio=\"xMidYMid meet\"\n style={{ display: \"block\" }}\n >\n {letters.items.map((glyph, i) => {\n const entry = entryStart + entryStagger * i;\n const run = Math.max(1, travelFrames - vertexLagFrames);\n\n const d = glyph.contours\n .map((contour) => {\n const pts = contour.map(([px, py]) => {\n const u =\n glyph.width === 0\n ? 0\n : Math.min(1, Math.max(0, (px - glyph.left) / glyph.width));\n const start = entry + u * vertexLagFrames;\n const remaining = interpolate(\n frame,\n [start, start + run],\n [1, 0],\n {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n easing: Easing.bezier(0.2, 0.9, 0.25, 1),\n },\n );\n return [\n startX + px + travelDistance * remaining,\n resolvedBaseline + py,\n ];\n });\n return (\n `M${pts[0][0].toFixed(2)},${pts[0][1].toFixed(2)}` +\n pts\n .slice(1)\n .map((p) => `L${p[0].toFixed(2)},${p[1].toFixed(2)}`)\n .join(\"\") +\n \"Z\"\n );\n })\n .join(\" \");\n\n return (\n <path\n key={`${i}-${glyph.left}`}\n d={d}\n fill={fill}\n fillRule=\"evenodd\"\n stroke={strokeWidth > 0 ? stroke : \"none\"}\n strokeWidth={strokeWidth}\n />\n );\n })}\n </svg>\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n text: {\n type: \"text-content\",\n default: \"REMOCN\",\n description: \"Text\",\n },\n fill: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Fill\",\n },\n fontSize: {\n type: \"number\",\n min: 100,\n max: 700,\n step: 10,\n default: 510,\n description: \"Font size\",\n hiddenFromList: false,\n },\n entryStagger: {\n type: \"number\",\n min: 0,\n max: 12,\n step: 1,\n default: 3,\n description: \"Letter stagger\",\n hiddenFromList: false,\n },\n travelFrames: {\n type: \"number\",\n min: 4,\n max: 40,\n step: 1,\n default: 33,\n description: \"Travel (frames)\",\n hiddenFromList: false,\n },\n vertexLagFrames: {\n type: \"number\",\n min: 0,\n max: 8,\n step: 0.5,\n default: 3.5,\n description: \"Smear lag (frames)\",\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([\"text\",\"fill\",\"fontSize\",\"entryStagger\",\"travelFrames\",\"vertexLagFrames\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n text: \"REMOCN\",\n fill: \"#ffffff\",\n fontSize: 510,\n entryStagger: 3,\n travelFrames: 33,\n vertexLagFrames: 3.5,\n speed: 1,\n};\n\ntype StretchInElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof StretchInBase>;\n\nconst StretchInInner = forwardRef<\n HTMLDivElement,\n StretchInElementProps & { 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 ?? \"<StretchIn>\"}\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 <StretchInBase\n {...(componentProps as unknown as ComponentProps<typeof StretchInBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const StretchIn = Interactive.withSchema({\n Component: StretchInInner,\n componentName: \"<StretchIn>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 48,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 48
}