Skip to content

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

5.4 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": null,
    "displayName": "Infinite Marquee",
    "initialProps": null,
    "slug": "infinite-marquee",
    "sourceCode": "import { Interactive, Sequence, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ninterface InfiniteMarqueeProps {\n  text?: string;\n  fontSize?: number;\n  color?: string;\n  fontWeight?: number;\n  pixelsPerFrame?: number;\n  stroke?: boolean;\n  strokeColor?: string;\n  speed?: number;\n  className?: string;\n}\n\nfunction InfiniteMarqueeBase({\n  text = \"ship · build · animate · \",\n  fontSize = 120,\n  color = \"#171717\",\n  fontWeight = 900,\n  pixelsPerFrame = 4,\n  stroke = false,\n  strokeColor = \"#171717\",\n  speed = 1,\n  className,\n}: InfiniteMarqueeProps) {\n  const frame = useCurrentFrame() * speed;\n\n  const approxWidth = text.length * fontSize * 0.55;\n  const offset = -((frame * pixelsPerFrame) % approxWidth);\n\n  const spanStyle: React.CSSProperties = {\n    fontSize,\n    fontWeight,\n    fontFamily:\n      \"var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif\",\n    color: stroke ? \"transparent\" : color,\n    WebkitTextStroke: stroke ? `2px ${strokeColor}` : undefined,\n    paddingRight: \"0.4em\",\n    letterSpacing: \"-0.03em\",\n  };\n\n  return (\n    <div\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        display: \"flex\",\n        alignItems: \"center\",\n        justifyContent: \"center\",\n      }}\n    >\n      <div\n        className={className}\n        style={{\n          display: \"flex\",\n          whiteSpace: \"nowrap\",\n          translate: `${offset}px`,\n        }}\n      >\n        <span style={spanStyle}>{text}</span>\n        <span style={spanStyle}>{text}</span>\n        <span style={spanStyle}>{text}</span>\n      </div>\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  text: {\n    type: \"text-content\",\n    default: \"ship · build · animate · \",\n    description: \"Text\",\n  },\n  fontSize: {\n    type: \"number\",\n    min: 12,\n    max: 240,\n    step: 1,\n    default: 120,\n    description: \"Font size\",\n    hiddenFromList: false,\n  },\n  color: {\n    type: \"color\",\n    default: \"#171717\",\n    description: \"Color\",\n  },\n  fontWeight: {\n    type: \"enum\",\n    default: \"700\",\n    variants: {\n      \"400\": {},\n      \"500\": {},\n      \"600\": {},\n      \"700\": {},\n    },\n    description: \"Font weight\",\n  },\n  pixelsPerFrame: {\n    type: \"number\",\n    min: 1,\n    max: 30,\n    step: 1,\n    default: 4,\n    description: \"Pixels / frame\",\n    hiddenFromList: false,\n  },\n  stroke: {\n    type: \"boolean\",\n    default: false,\n    description: \"Stroke\",\n  },\n  strokeColor: {\n    type: \"color\",\n    default: \"#171717\",\n    description: \"Stroke color\",\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\",\"fontSize\",\"color\",\"fontWeight\",\"pixelsPerFrame\",\"stroke\",\"strokeColor\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  text: \"ship · build · animate · \",\n  fontSize: 120,\n  color: \"#171717\",\n  fontWeight: \"700\",\n  pixelsPerFrame: 4,\n  stroke: false,\n  strokeColor: \"#171717\",\n  speed: 1,\n};\n\ntype InfiniteMarqueeElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof InfiniteMarqueeBase>;\n\nconst InfiniteMarqueeInner = forwardRef<\n  HTMLDivElement,\n  InfiniteMarqueeElementProps & { 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 ?? \"<InfiniteMarquee>\"}\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        <InfiniteMarqueeBase\n          {...(componentProps as unknown as ComponentProps<typeof InfiniteMarqueeBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const InfiniteMarquee = Interactive.withSchema({\n  Component: InfiniteMarqueeInner,\n  componentName: \"<InfiniteMarquee>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 180,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 180
}