Skip to content

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

6.5 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": {
      "width": 620,
      "height": 110
    },
    "displayName": "Squeeze In",
    "initialProps": null,
    "slug": "squeeze-in",
    "sourceCode": "import { Easing, Interactive, Sequence, interpolate, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ninterface SqueezeInProps {\n  text: string;\n  fontSize?: number;\n  color?: string;\n  fontWeight?: number;\n  stagger?: number;\n  squeeze?: number;\n  speed?: number;\n  className?: string;\n}\n\nconst SQUEEZE_FRAMES = 16;\n\nfunction squeezeInLength(text: string, stagger = 3): number {\n  const chars = Array.from(text);\n  if (chars.length === 0) return 0;\n  return chars.length * stagger + SQUEEZE_FRAMES;\n}\n\nconst squeezeEasing = Easing.out(Easing.cubic);\n\nfunction SqueezeInBase({\n  text,\n  fontSize = 72,\n  color = \"#171717\",\n  fontWeight = 400,\n  stagger = 3,\n  squeeze = 0.03,\n  speed = 1,\n  className,\n}: SqueezeInProps) {\n  const frame = useCurrentFrame() * speed;\n\n  const chars = Array.from(text);\n  const lastRevealAt = chars.length * stagger;\n\n  const squeezeProgress = interpolate(\n    frame,\n    [lastRevealAt, lastRevealAt + SQUEEZE_FRAMES],\n    [0, 1],\n    {\n      extrapolateLeft: \"clamp\",\n      extrapolateRight: \"clamp\",\n      easing: squeezeEasing,\n    },\n  );\n\n  const gap = squeeze * fontSize * (1 - squeezeProgress);\n  const wipe = interpolate(frame, [0, lastRevealAt], [100, 0], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n  });\n  const anchorX =\n    (-squeeze * fontSize * squeezeProgress * (chars.length - 1)) / 2;\n\n  return (\n    <div\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        display: \"flex\",\n        alignItems: \"center\",\n        justifyContent: \"center\",\n        whiteSpace: \"nowrap\",\n        background: \"transparent\",\n      }}\n    >\n      <span\n        className={className}\n        style={{\n          translate: `${anchorX}px 0`,\n          clipPath: `inset(-0.2em ${wipe}% -0.25em -0.1em)`,\n          fontSize,\n          fontWeight,\n          color,\n          letterSpacing: \"-0.02em\",\n          lineHeight: 1.1,\n          fontFamily:\n            \"var(--font-geist-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif)\",\n        }}\n      >\n        {chars.map((char, j) => (\n          <span\n            key={j}\n            style={{\n              display: \"inline-block\",\n              whiteSpace: \"pre\",\n              marginRight: j < chars.length - 1 ? gap : undefined,\n            }}\n          >\n            {char}\n          </span>\n        ))}\n      </span>\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  text: {\n    type: \"text-content\",\n    default: \"Remocn\",\n    description: \"Text\",\n  },\n  fontSize: {\n    type: \"number\",\n    min: 12,\n    max: 160,\n    step: 1,\n    default: 72,\n    description: \"Font size\",\n    hiddenFromList: false,\n  },\n  stagger: {\n    type: \"number\",\n    min: 1,\n    max: 8,\n    step: 1,\n    default: 3,\n    description: \"Frames / char\",\n    hiddenFromList: false,\n  },\n  squeeze: {\n    type: \"number\",\n    min: 0,\n    max: 0.2,\n    step: 0.01,\n    default: 0.03,\n    description: \"Extra gap (em)\",\n    hiddenFromList: false,\n  },\n  color: {\n    type: \"color\",\n    default: \"#171717\",\n    description: \"Color\",\n  },\n  fontWeight: {\n    type: \"enum\",\n    default: \"400\",\n    variants: {\n      \"400\": {},\n      \"500\": {},\n      \"600\": {},\n      \"700\": {},\n    },\n    description: \"Font weight\",\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: 620,\n    min: 10,\n    step: 10,\n    description: \"Width\",\n  },\n  height: {\n    type: \"number\",\n    default: 110,\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([\"text\",\"fontSize\",\"stagger\",\"squeeze\",\"color\",\"fontWeight\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  text: \"Remocn\",\n  fontSize: 72,\n  stagger: 3,\n  squeeze: 0.03,\n  color: \"#171717\",\n  fontWeight: \"400\",\n  speed: 1,\n};\n\ntype SqueezeInElementProps = InteractiveBaseProps &\n  InteractiveTransformProps & { readonly width?: number; readonly height?: number } &\n  ComponentProps<typeof SqueezeInBase>;\n\nconst SqueezeInInner = forwardRef<\n  HTMLDivElement,\n  SqueezeInElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, width = 620, height = 110, ...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 ?? \"<SqueezeIn>\"}\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          <SqueezeInBase\n            {...(componentProps as unknown as ComponentProps<typeof SqueezeInBase>)}\n          />\n        </div>\n      </div>\n    </Sequence>\n  );\n});\n\nexport const SqueezeIn = Interactive.withSchema({\n  Component: SqueezeInInner,\n  componentName: \"<SqueezeIn>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 34,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 34
}