Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

7.9 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": null,
    "displayName": "Inflate",
    "initialProps": null,
    "slug": "inflate",
    "sourceCode": "import { AbsoluteFill, Easing, Interactive, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport React, { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ntype InflateProps = {\n  /** Wordmark revealed beside the mark once it settles. */\n  children?: React.ReactNode;\n  backgroundColor?: string;\n  /** Body color of the mark. */\n  color?: string;\n  /** Specular highlight color. */\n  highlight?: string;\n  /** Dot inside the mark. */\n  dotColor?: string;\n  speed?: number;\n};\n\nconst inflateDefaults = {\n  backgroundColor: \"#111111\",\n  color: \"#E5322D\",\n  highlight: \"#FFFFFF\",\n  dotColor: \"#111111\",\n  speed: 1,\n};\n\nconst PUFF = 3;\nconst WOBBLE = 10;\nconst DOT = 15;\nconst SLIDE = 22;\nconst clamp = {\n  extrapolateLeft: \"clamp\" as const,\n  extrapolateRight: \"clamp\" as const,\n};\n\nfunction InflateBase(props: InflateProps) {\n  const { children, backgroundColor, color, highlight, dotColor, speed } = {\n    ...inflateDefaults,\n    ...props,\n  };\n  const frame = useCurrentFrame();\n  const { width, height, fps } = useVideoConfig();\n  const t = frame * Math.max(0, speed);\n  const size = Math.round(Math.min(width, height) * 0.22);\n\n  // Main puff: an underdamped spring overshoots the final size.\n  const puff = spring({\n    frame: t - PUFF,\n    fps,\n    config: { damping: 8, stiffness: 150, mass: 0.6 },\n  });\n  // After the peak the body squashes wide and rings out like a balloon.\n  const w0 = t - WOBBLE;\n  const wobble =\n    w0 > 0 ? 0.2 * Math.exp(-w0 / 6) * Math.sin((w0 / 9) * Math.PI * 2) : 0;\n\n  const grow = Math.max(0, puff);\n  const sliverW = interpolate(t, [0, PUFF], [0.7, 1], {\n    ...clamp,\n    easing: Easing.out(Easing.quad),\n  });\n  const bodyH = size * (0.05 + 0.95 * grow) * (1 - wobble);\n  const bodyW = size * (sliverW + (Math.max(1, grow) - 1) * 0.8) * (1 + wobble);\n  const roundness = interpolate(t, [PUFF, PUFF + 7, 26], [0.5, 0.46, 0.27], {\n    ...clamp,\n    easing: Easing.inOut(Easing.quad),\n  });\n  const radius = Math.min(bodyW, bodyH) * roundness;\n  const gloss = interpolate(t, [PUFF + 2, PUFF + 9], [0, 1], clamp);\n  const appear = interpolate(t, [0, 2], [0, 1], clamp);\n\n  const dot = spring({\n    frame: t - DOT,\n    fps,\n    config: { damping: 10, stiffness: 220, mass: 0.5 },\n  });\n  const slide = interpolate(t, [SLIDE, SLIDE + 11], [0, 1], {\n    ...clamp,\n    easing: Easing.inOut(Easing.cubic),\n  });\n  const reveal = interpolate(t, [SLIDE + 2, SLIDE + 13], [0, 1], {\n    ...clamp,\n    easing: Easing.out(Easing.cubic),\n  });\n\n  return (\n    <AbsoluteFill\n      style={{\n        backgroundColor,\n        alignItems: \"center\",\n        justifyContent: \"center\",\n      }}\n    >\n      <div\n        style={{\n          display: \"flex\",\n          alignItems: \"center\",\n          gap: size * 0.24,\n          transform: `translateX(calc((50% - ${size / 2}px) * ${children ? 1 - slide : 0}))`,\n        }}\n      >\n        <div\n          style={{\n            width: size,\n            height: size,\n            flexShrink: 0,\n            display: \"flex\",\n            alignItems: \"center\",\n            justifyContent: \"center\",\n          }}\n        >\n          <div\n            style={{\n              position: \"relative\",\n              flexShrink: 0,\n              width: bodyW,\n              height: bodyH,\n              borderRadius: radius,\n              backgroundColor: color,\n              opacity: appear,\n              overflow: \"hidden\",\n              display: \"flex\",\n              alignItems: \"center\",\n              justifyContent: \"center\",\n              boxShadow: `inset ${-size * 0.06}px ${-size * 0.08}px ${size * 0.14}px rgba(0,0,0,${0.28 * gloss})`,\n            }}\n          >\n            <div\n              style={{\n                position: \"absolute\",\n                left: \"14%\",\n                top: \"10%\",\n                width: \"46%\",\n                height: \"28%\",\n                borderRadius: \"50%\",\n                background: `radial-gradient(ellipse at 45% 40%, ${highlight} 0%, transparent 70%)`,\n                opacity: 0.55 * gloss,\n                transform: \"rotate(-18deg)\",\n              }}\n            />\n            <div\n              style={{\n                width: size * 0.3,\n                height: size * 0.3,\n                borderRadius: \"50%\",\n                backgroundColor: dotColor,\n                transform: `scale(${dot})`,\n              }}\n            />\n          </div>\n        </div>\n        {children && (\n          <div\n            style={{\n              opacity: reveal,\n              clipPath: `inset(-30% ${(1 - reveal) * 100}% -30% -5%)`,\n              transform: `translateX(${(1 - reveal) * -size * 0.3}px)`,\n            }}\n          >\n            {children}\n          </div>\n        )}\n      </div>\n    </AbsoluteFill>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  color: {\n    type: \"color\",\n    default: \"#E5322D\",\n    description: \"Body\",\n  },\n  highlight: {\n    type: \"color\",\n    default: \"#FFFFFF\",\n    description: \"Highlight\",\n  },\n  dotColor: {\n    type: \"color\",\n    default: \"#111111\",\n    description: \"Dot\",\n  },\n  backgroundColor: {\n    type: \"color\",\n    default: \"#111111\",\n    description: \"Background\",\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([\"color\",\"highlight\",\"dotColor\",\"backgroundColor\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  color: \"#E5322D\",\n  highlight: \"#FFFFFF\",\n  dotColor: \"#111111\",\n  backgroundColor: \"#111111\",\n  speed: 1,\n};\n\ntype InflateElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof InflateBase>;\n\nconst InflateInner = forwardRef<\n  HTMLDivElement,\n  InflateElementProps & { 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 ?? \"<Inflate>\"}\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        <InflateBase\n          {...(componentProps as unknown as ComponentProps<typeof InflateBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const Inflate = Interactive.withSchema({\n  Component: InflateInner,\n  componentName: \"<Inflate>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 35,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 35
}