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/paths",
"version": null
}
],
"dimensions": {
"width": 48,
"height": 48
},
"displayName": "Package",
"initialProps": null,
"slug": "icon-package",
"sourceCode": "import { Easing, Interactive, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { evolvePath } from \"@remotion/paths\";\nimport { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ninterface IconAnimationProps {\n animation?: \"draw\" | \"action\" | \"both\";\n loop?: boolean;\n speed?: number;\n size?: number;\n color?: string;\n strokeWidth?: number;\n className?: string;\n}\n\ninterface IconTimings {\n drawDurationInFrames?: number;\n actionDelayInFrames?: number;\n actionDurationInFrames?: number;\n loop?: boolean;\n}\n\ninterface IconTimeline {\n drawProgress: number;\n scaleIn: number;\n actionFrame: number;\n actionProgress: number;\n cycleIndex: number;\n}\n\nfunction clamp01(t: number): number {\n return t < 0 ? 0 : t > 1 ? 1 : t;\n}\n\nfunction easeOut(t: number): number {\n return 1 - (1 - t) ** 3;\n}\n\nfunction iconTimeline(\n frame: number,\n fps: number,\n props: IconAnimationProps,\n timings: IconTimings,\n): IconTimeline {\n const animation = props.animation ?? \"both\";\n const loop = props.loop ?? timings.loop ?? false;\n const drawDuration = timings.drawDurationInFrames ?? 14;\n const actionDelay = timings.actionDelayInFrames ?? 2;\n const actionDuration = timings.actionDurationInFrames ?? 20;\n\n const drawProgress =\n animation === \"action\"\n ? 1\n : easeOut(clamp01(drawDuration > 0 ? frame / drawDuration : 1));\n\n const scaleIn = clamp01(\n spring({\n frame,\n fps,\n config: { damping: 18, stiffness: 220, mass: 0.7 },\n durationInFrames: Math.max(1, drawDuration),\n }),\n );\n\n const actionStart = animation === \"action\" ? 0 : drawDuration + actionDelay;\n const sinceStart = frame - actionStart;\n\n if (animation === \"draw\" || sinceStart < 0) {\n return {\n drawProgress,\n scaleIn,\n actionFrame: sinceStart,\n actionProgress: 0,\n cycleIndex: 0,\n };\n }\n\n if (actionDuration <= 0) {\n return {\n drawProgress,\n scaleIn,\n actionFrame: sinceStart,\n actionProgress: 1,\n cycleIndex: 0,\n };\n }\n\n if (loop) {\n const cycleIndex = Math.floor(sinceStart / actionDuration);\n const local = sinceStart - cycleIndex * actionDuration;\n return {\n drawProgress,\n scaleIn,\n actionFrame: local,\n actionProgress: local / actionDuration,\n cycleIndex,\n };\n }\n\n return {\n drawProgress,\n scaleIn,\n actionFrame: sinceStart,\n actionProgress: clamp01(sinceStart / actionDuration),\n cycleIndex: 0,\n };\n}\n\nfunction useIconAnimation(\n props: IconAnimationProps,\n timings: IconTimings,\n): IconTimeline {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const speed = props.speed ?? 1;\n return iconTimeline(frame * speed, fps, props, timings);\n}\n\nfunction staggeredProgress(\n progress: number,\n index: number,\n count: number,\n overlap = 0.5,\n): number {\n if (count <= 1) return clamp01(progress);\n const o = clamp01(overlap);\n const width = 1 / (count - (count - 1) * o);\n const start = index * width * (1 - o);\n return clamp01((progress - start) / width);\n}\n\nfunction drawnPathProps(\n d: string,\n progress: number,\n): { strokeDasharray: string; strokeDashoffset: number } {\n return evolvePath(clamp01(progress), d);\n}\n\nconst BOX_PATH =\n \"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z\";\nconst CENTER_PATH = \"M12 22V12\";\nconst EDGE_PATH = \"M7.5 4.27 16.5 9.42\";\nconst SEAM_PATH = \"M3.29 7 12 12 20.71 7\";\n\nconst BASE_Y = 22;\n\nconst TIMINGS = {\n drawDurationInFrames: 16,\n actionDelayInFrames: 2,\n actionDurationInFrames: 26,\n loop: false,\n} as const;\n\nfunction PackageIconBase({\n animation = \"both\",\n loop,\n speed,\n size = 48,\n color = \"currentColor\",\n strokeWidth = 2,\n className,\n}: IconAnimationProps) {\n const { drawProgress, scaleIn, actionProgress, actionFrame } =\n useIconAnimation({ animation, loop, speed }, TIMINGS);\n\n const linearDraw = 1 - (1 - drawProgress) ** (1 / 3);\n const acting = animation !== \"draw\" && actionFrame >= 0;\n\n const boxDraw = interpolate(linearDraw, [0, 0.7], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n easing: Easing.out(Easing.quad),\n });\n const edgesDraw = interpolate(linearDraw, [0.45, 0.8], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n easing: Easing.out(Easing.quad),\n });\n const seamDraw = interpolate(linearDraw, [0.7, 1], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n easing: Easing.out(Easing.quad),\n });\n\n const drop = acting\n ? interpolate(actionProgress, [0, 0.25, 0.5], [0, 2, 0], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n easing: Easing.inOut(Easing.quad),\n })\n : 0;\n const squashY = acting\n ? interpolate(\n actionProgress,\n [0, 0.25, 0.5, 0.7, 1],\n [1, 0.95, 1.04, 1, 1],\n {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n easing: Easing.inOut(Easing.quad),\n },\n )\n : 1;\n const box = drawnPathProps(BOX_PATH, acting ? 1 : boxDraw);\n const center = drawnPathProps(CENTER_PATH, acting ? 1 : edgesDraw);\n const edge = drawnPathProps(EDGE_PATH, acting ? 1 : edgesDraw);\n const seam = drawnPathProps(SEAM_PATH, acting ? 1 : seamDraw);\n\n const scale = 0.85 + 0.15 * scaleIn;\n const bodyTransform = `translate(0 ${drop + BASE_Y * (1 - squashY)}) scale(1 ${squashY})`;\n\n return (\n <svg\n className={className}\n width={size}\n height={size}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke={color}\n strokeWidth={strokeWidth}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n style={{\n overflow: \"visible\",\n transformOrigin: \"center\",\n transform: `scale(${scale})`,\n }}\n >\n <g transform={bodyTransform}>\n <path\n d={BOX_PATH}\n strokeDasharray={box.strokeDasharray}\n strokeDashoffset={box.strokeDashoffset}\n />\n <path\n d={CENTER_PATH}\n strokeDasharray={center.strokeDasharray}\n strokeDashoffset={center.strokeDashoffset}\n />\n <path\n d={EDGE_PATH}\n strokeDasharray={edge.strokeDasharray}\n strokeDashoffset={edge.strokeDashoffset}\n />\n <path\n d={SEAM_PATH}\n strokeDasharray={seam.strokeDasharray}\n strokeDashoffset={seam.strokeDashoffset}\n />\n </g>\n </svg>\n );\n}\n\nfunction PackageIconStatic({\n size = 48,\n color = \"currentColor\",\n strokeWidth = 2,\n className,\n}: {\n size?: number;\n color?: string;\n strokeWidth?: number;\n className?: string;\n}) {\n return (\n <svg\n className={className}\n width={size}\n height={size}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke={color}\n strokeWidth={strokeWidth}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d={BOX_PATH} />\n <path d={CENTER_PATH} />\n <polyline points=\"3.29 7 12 12 20.71 7\" />\n <path d=\"m7.5 4.27 9 5.15\" />\n </svg>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n animation: {\n type: \"enum\",\n default: \"both\",\n variants: {\n draw: {},\n action: {},\n both: {},\n },\n description: \"Animation\",\n },\n loop: {\n type: \"boolean\",\n default: false,\n description: \"Loop\",\n },\n size: {\n type: \"number\",\n min: 24,\n max: 200,\n step: 4,\n default: 48,\n description: \"Size\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#171717\",\n description: \"Color\",\n },\n strokeWidth: {\n type: \"number\",\n min: 1,\n max: 3,\n step: 0.25,\n default: 2,\n description: \"Stroke width\",\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 width: {\n type: \"number\",\n default: 48,\n min: 10,\n step: 10,\n description: \"Width\",\n },\n height: {\n type: \"number\",\n default: 48,\n min: 10,\n step: 10,\n description: \"Height\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"animation\",\"loop\",\"size\",\"color\",\"strokeWidth\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n animation: \"both\",\n loop: false,\n size: 48,\n color: \"#171717\",\n strokeWidth: 2,\n speed: 1,\n};\n\ntype PackageIconElementProps = InteractiveBaseProps &\n InteractiveTransformProps & { readonly width?: number; readonly height?: number } &\n ComponentProps<typeof PackageIconBase>;\n\nconst PackageIconInner = forwardRef<\n HTMLDivElement,\n PackageIconElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, width = 48, height = 48, ...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 ?? \"<PackageIcon>\"}\n outlineRef={outlineRef}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n }}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width,\n height,\n ...style,\n }}\n >\n <PackageIconBase\n {...(componentProps as unknown as ComponentProps<typeof PackageIconBase>)}\n />\n </div>\n </div>\n </Sequence>\n );\n});\n\nexport const PackageIcon = Interactive.withSchema({\n Component: PackageIconInner,\n componentName: \"<PackageIcon>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 80,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 80
}