Skip to content

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

4.7 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [
      {
        "name": "@paper-design/shaders-react",
        "version": "0.0.76"
      }
    ],
    "dimensions": null,
    "displayName": "Shader Water",
    "initialProps": null,
    "slug": "shader-water",
    "sourceCode": "import { Water, type WaterProps } from \"@paper-design/shaders-react\";\nimport { forwardRef, useCallback, useImperativeHandle, useRef, useState, type ComponentProps } from \"react\";\nimport { Interactive, Sequence, continueRender, delayRender, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ninterface ShaderWaterProps extends Omit<WaterProps, \"frame\" | \"ref\"> {}\n\nfunction ShaderWaterBase({\n  speed = 1,\n  colorBack = \"#16202b\",\n  colorHighlight = \"#5a6a7a\",\n  highlights = 0.06,\n  waves = 0.3,\n  caustic = 0.08,\n  className,\n  ...rest\n}: ShaderWaterProps) {\n  const frame = useCurrentFrame();\n  const { fps, width, height } = useVideoConfig();\n\n  const [handle] = useState(() => delayRender(\"shader-water\"));\n  const gate = useCallback(\n    (element: HTMLDivElement | null) => {\n      if (!element) return;\n      requestAnimationFrame(() =>\n        requestAnimationFrame(() => continueRender(handle)),\n      );\n    },\n    [handle],\n  );\n\n  return (\n    <div\n      ref={gate}\n      className={className}\n      style={{ position: \"absolute\", inset: 0 }}\n    >\n      <Water\n        speed={0}\n        frame={(frame / fps) * speed * 1000}\n        colorBack={colorBack}\n        colorHighlight={colorHighlight}\n        highlights={highlights}\n        waves={waves}\n        caustic={caustic}\n        fit=\"cover\"\n        width={width}\n        height={height}\n        {...rest}\n      />\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\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  waves: {\n    type: \"number\",\n    min: 0,\n    max: 1,\n    step: 0.05,\n    default: 0.3,\n    description: \"Waves\",\n    hiddenFromList: false,\n  },\n  caustic: {\n    type: \"number\",\n    min: 0,\n    max: 1,\n    step: 0.02,\n    default: 0.08,\n    description: \"Caustic\",\n    hiddenFromList: false,\n  },\n  highlights: {\n    type: \"number\",\n    min: 0,\n    max: 1,\n    step: 0.02,\n    default: 0.06,\n    description: \"Highlights\",\n    hiddenFromList: false,\n  },\n  colorBack: {\n    type: \"color\",\n    default: \"#16202b\",\n    description: \"Background\",\n  },\n  ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"speed\",\"waves\",\"caustic\",\"highlights\",\"colorBack\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  speed: 1,\n  waves: 0.3,\n  caustic: 0.08,\n  highlights: 0.06,\n  colorBack: \"#16202b\",\n};\n\ntype ShaderWaterElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof ShaderWaterBase>;\n\nconst ShaderWaterInner = forwardRef<\n  HTMLDivElement,\n  ShaderWaterElementProps & { 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 ?? \"<ShaderWater>\"}\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        <ShaderWaterBase\n          {...(componentProps as unknown as ComponentProps<typeof ShaderWaterBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const ShaderWater = Interactive.withSchema({\n  Component: ShaderWaterInner,\n  componentName: \"<ShaderWater>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 150,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 150
}