Skip to content

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

5.8 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": {
      "width": 340,
      "height": 100
    },
    "displayName": "Matrix Decode",
    "initialProps": null,
    "slug": "matrix-decode",
    "sourceCode": "import { Interactive, Sequence, random, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ninterface MatrixDecodeProps {\n  text: string;\n  charset?: string;\n  fontSize?: number;\n  color?: string;\n  fontWeight?: number;\n  revealDuration?: number;\n  speed?: number;\n  className?: string;\n}\n\nfunction MatrixDecodeBase({\n  text,\n  charset = \"!@#$%^&*()_+-=<>?/\\\\|\",\n  fontSize = 72,\n  color = \"#22c55e\",\n  fontWeight = 600,\n  revealDuration = 60,\n  speed = 1,\n  className,\n}: MatrixDecodeProps) {\n  const frame = useCurrentFrame() * speed;\n  // useVideoConfig kept for consistency with sibling primitives\n  useVideoConfig();\n\n  let output = \"\";\n  for (let i = 0; i < text.length; i++) {\n    const revealFrame = (i / Math.max(text.length, 1)) * revealDuration;\n    if (text[i] === \" \") {\n      output += \" \";\n    } else if (frame >= revealFrame) {\n      output += text[i];\n    } else {\n      const r = random(`${i}-${Math.floor(frame / 2)}`);\n      const ch = charset[Math.floor(r * charset.length)];\n      output += ch;\n    }\n  }\n\n  return (\n    <div\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        display: \"flex\",\n        alignItems: \"center\",\n        justifyContent: \"center\",\n        background: \"white\",\n      }}\n    >\n      <span\n        className={className}\n        style={{\n          fontSize,\n          fontWeight,\n          color,\n          letterSpacing: \"0.05em\",\n          whiteSpace: \"pre\",\n          fontFamily:\n            \"var(--font-geist-mono), ui-monospace, SFMono-Regular, Menlo, monospace\",\n        }}\n      >\n        {output}\n      </span>\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  text: {\n    type: \"text-content\",\n    default: \"DECRYPTED\",\n    description: \"Text\",\n  },\n  charset: {\n    type: \"text-content\",\n    default: \"!@#$%^&*()_+-=<>?/\\\\|\",\n    description: \"Charset\",\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  color: {\n    type: \"color\",\n    default: \"#22c55e\",\n    description: \"Color\",\n  },\n  fontWeight: {\n    type: \"enum\",\n    default: \"600\",\n    variants: {\n      \"400\": {},\n      \"500\": {},\n      \"600\": {},\n      \"700\": {},\n    },\n    description: \"Font weight\",\n  },\n  revealDuration: {\n    type: \"number\",\n    min: 10,\n    max: 240,\n    step: 1,\n    default: 60,\n    description: \"Reveal duration\",\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  width: {\n    type: \"number\",\n    default: 340,\n    min: 10,\n    step: 10,\n    description: \"Width\",\n  },\n  height: {\n    type: \"number\",\n    default: 100,\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\",\"charset\",\"fontSize\",\"color\",\"fontWeight\",\"revealDuration\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  text: \"DECRYPTED\",\n  charset: \"!@#$%^&*()_+-=<>?/\\\\|\",\n  fontSize: 72,\n  color: \"#22c55e\",\n  fontWeight: \"600\",\n  revealDuration: 60,\n  speed: 1,\n};\n\ntype MatrixDecodeElementProps = InteractiveBaseProps &\n  InteractiveTransformProps & { readonly width?: number; readonly height?: number } &\n  ComponentProps<typeof MatrixDecodeBase>;\n\nconst MatrixDecodeInner = forwardRef<\n  HTMLDivElement,\n  MatrixDecodeElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, width = 340, height = 100, ...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 ?? \"<MatrixDecode>\"}\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          <MatrixDecodeBase\n            {...(componentProps as unknown as ComponentProps<typeof MatrixDecodeBase>)}\n          />\n        </div>\n      </div>\n    </Sequence>\n  );\n});\n\nexport const MatrixDecode = Interactive.withSchema({\n  Component: MatrixDecodeInner,\n  componentName: \"<MatrixDecode>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 90,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 90
}