Skip to content

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

6.6 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": null,
    "displayName": "Extrude Pop",
    "initialProps": null,
    "slug": "extrude-pop",
    "sourceCode": "import { forwardRef, useImperativeHandle, useMemo, useRef, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ninterface ExtrudePopProps {\n  className?: string;\n  width?: number;\n  height?: number;\n  letter?: string;\n  fontFamily?: string;\n  fontWeight?: number | string;\n  fontSize?: number;\n  basePosition?: [number, number];\n  maxTextWidth?: number;\n  minimaxRadius?: number;\n  extrudeAngleDeg?: number;\n  extrudeSteps?: number;\n  extrudeStartFrame?: number;\n  extrudeEndFrame?: number;\n  bodyColor?: string;\n  faceColor?: string;\n}\n\nfunction ExtrudePopBase({\n  className,\n  width = 1920,\n  height = 1080,\n  letter = \"WIN\",\n  fontFamily = \"'Helvetica Neue', Helvetica, Arial, sans-serif\",\n  fontWeight = 700,\n  fontSize = 603,\n  basePosition = [959.2, 752.5],\n  maxTextWidth = 1660,\n  minimaxRadius = 80,\n  extrudeAngleDeg = -58.6,\n  extrudeSteps = 200,\n  extrudeStartFrame = 0,\n  extrudeEndFrame = 48,\n  bodyColor = \"#e8192b\",\n  faceColor = \"#ffffff\",\n}: ExtrudePopProps) {\n  const frame = useCurrentFrame();\n\n  const fit = useMemo(() => {\n    if (typeof document === \"undefined\") return 1;\n    const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n    if (!ctx) return 1;\n    ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;\n    const measured = ctx.measureText(letter).width;\n    if (measured <= 0) return 1;\n    return Math.min(1, maxTextWidth / measured);\n  }, [letter, fontFamily, fontWeight, fontSize, maxTextWidth]);\n\n  const fitFontSize = fontSize * fit;\n  const fitRadius = minimaxRadius * fit;\n\n  const radius = interpolate(\n    frame,\n    [extrudeStartFrame, extrudeEndFrame],\n    [0, fitRadius],\n    {\n      extrapolateLeft: \"clamp\",\n      extrapolateRight: \"clamp\",\n      easing: Easing.bezier(0.16, 1, 0.3, 1),\n    },\n  );\n\n  const depth = radius * 2;\n\n  const theta = (extrudeAngleDeg * Math.PI) / 180;\n  const stepX = (depth * Math.sin(theta)) / extrudeSteps;\n  const stepY = (depth * Math.cos(theta)) / extrudeSteps;\n\n  const glyph = (fill: string, dx: number, dy: number, key?: string) => (\n    <text\n      key={key}\n      x={basePosition[0] + dx}\n      y={basePosition[1] + dy}\n      textAnchor=\"middle\"\n      fontFamily={fontFamily}\n      fontWeight={fontWeight}\n      fontSize={fitFontSize}\n      fill={fill}\n    >\n      {letter}\n    </text>\n  );\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        <g>\n          {Array.from(\n            { length: extrudeSteps + 1 },\n            (_, i) => extrudeSteps - i,\n          ).map((i) => glyph(bodyColor, stepX * i, stepY * i, `body-${i}`))}\n        </g>\n\n        {glyph(faceColor, stepX * extrudeSteps, stepY * extrudeSteps)}\n      </svg>\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  letter: {\n    type: \"text-content\",\n    default: \"WIN\",\n    description: \"Text\",\n  },\n  bodyColor: {\n    type: \"color\",\n    default: \"#e8192b\",\n    description: \"Body color\",\n  },\n  faceColor: {\n    type: \"color\",\n    default: \"#ffffff\",\n    description: \"Face color\",\n  },\n  minimaxRadius: {\n    type: \"number\",\n    min: 0,\n    max: 200,\n    step: 5,\n    default: 80,\n    description: \"Extrude radius\",\n    hiddenFromList: false,\n  },\n  extrudeAngleDeg: {\n    type: \"number\",\n    min: -180,\n    max: 180,\n    step: 1,\n    default: -58.6,\n    description: \"Extrude angle\",\n    hiddenFromList: false,\n  },\n  extrudeEndFrame: {\n    type: \"number\",\n    min: 10,\n    max: 90,\n    step: 1,\n    default: 48,\n    description: \"Extrude ends (frame)\",\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([\"letter\",\"bodyColor\",\"faceColor\",\"minimaxRadius\",\"extrudeAngleDeg\",\"extrudeEndFrame\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  letter: \"WIN\",\n  bodyColor: \"#e8192b\",\n  faceColor: \"#ffffff\",\n  minimaxRadius: 80,\n  extrudeAngleDeg: -58.6,\n  extrudeEndFrame: 48,\n  speed: 1,\n};\n\ntype ExtrudePopElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof ExtrudePopBase>;\n\nconst ExtrudePopInner = forwardRef<\n  HTMLDivElement,\n  ExtrudePopElementProps & { 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 ?? \"<ExtrudePop>\"}\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        <ExtrudePopBase\n          {...(componentProps as unknown as ComponentProps<typeof ExtrudePopBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const ExtrudePop = Interactive.withSchema({\n  Component: ExtrudePopInner,\n  componentName: \"<ExtrudePop>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 48,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 48
}