Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"type": "remotion-element",
"version": 1,
"element": {
"assets": [],
"dependencies": [],
"dimensions": null,
"displayName": "Trim Burst",
"initialProps": null,
"slug": "trim-burst",
"sourceCode": "import { forwardRef, useImperativeHandle, useMemo, useRef, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, random, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ntype TrimBurstCap = \"round\" | \"butt\";\n\ninterface TrimBurstProps {\n x?: number;\n y?: number;\n count?: number;\n innerRadius?: number;\n reach?: number;\n strokeLength?: number;\n weight?: number;\n rotation?: number;\n spread?: number;\n jitter?: number;\n dots?: boolean;\n cap?: TrimBurstCap;\n color?: string;\n seed?: number;\n delay?: number;\n speed?: number;\n className?: string;\n}\n\ntype Paint = \"color\" | \"className\";\n\ninterface TrimBurstOptions extends Omit<TrimBurstProps, Paint> {\n width?: number;\n height?: number;\n fps?: number;\n}\n\ninterface TrimBurstStroke {\n index: number;\n angle: number;\n scale: number;\n launch: number;\n}\n\ninterface TrimBurstTrim {\n start: number;\n end: number;\n length: number;\n}\n\ninterface TrimBurstLine {\n index: number;\n x1: number;\n y1: number;\n x2: number;\n y2: number;\n width: number;\n}\n\ninterface TrimBurstDot {\n index: number;\n cx: number;\n cy: number;\n r: number;\n}\n\nconst trimBurstDefaults: Required<Omit<TrimBurstProps, \"className\">> = {\n x: 0.5,\n y: 0.5,\n count: 8,\n innerRadius: 16,\n reach: 64,\n strokeLength: 56,\n weight: 2,\n rotation: 0,\n spread: 360,\n jitter: 0.5,\n dots: false,\n cap: \"round\",\n color: \"#ffffff\",\n seed: 1,\n delay: 0,\n speed: 1,\n};\n\nconst LIFE = 15;\nconst LAG = 3;\nconst STAGGER = 6;\nconst HOLD = 24;\nconst LEASH = 6;\nconst WOBBLE = 0.25;\nconst MAX_STEP = 45;\nconst SHRINK = 0.45;\nconst DOT_START = 4;\nconst DOT_POP = 4;\nconst DOT_BACK = 1.4;\nconst DOT_RADIUS = 1.25;\nconst DOT_GAP = 2;\nconst MAX_COUNT = 32;\nconst MAX_SIZE = 2000;\nconst MIN_STROKE = 1;\nconst MIN_WEIGHT = 0.25;\nconst MAX_WEIGHT = 24;\nconst VISIBLE = 0.001;\nconst END_EASE = Easing.bezier(0.16, 1, 0.3, 1);\nconst START_EASE = Easing.bezier(0.45, 0, 0.55, 1);\n\nconst finite = (value: number | undefined, fallback: number) =>\n typeof value === \"number\" && Number.isFinite(value) ? value : fallback;\nconst clamp = (value: number, min: number, max: number) =>\n Math.min(max, Math.max(min, value));\nconst within = (\n value: number | undefined,\n fallback: number,\n min: number,\n max: number,\n) => clamp(finite(value, fallback), min, max);\nconst round = (value: number) => Math.round(value * 1000) / 1000;\nconst rateOf = (speed: number | undefined) =>\n Math.max(0, finite(speed, trimBurstDefaults.speed));\nconst delayOf = (delay: number | undefined) =>\n Math.max(0, finite(delay, trimBurstDefaults.delay));\nconst countOf = (count: number | undefined) =>\n Math.round(within(count, trimBurstDefaults.count, 1, MAX_COUNT));\nconst jitterOf = (jitter: number | undefined) =>\n within(jitter, trimBurstDefaults.jitter, 0, 1);\nconst capOf = (cap: string | undefined): TrimBurstCap =>\n cap === \"butt\" ? cap : \"round\";\n\nfunction getTrimBurstTimeline(\n options: Pick<TrimBurstOptions, \"count\" | \"jitter\"> = {},\n) {\n const count = countOf(options.count);\n const stagger = count > 1 ? STAGGER * jitterOf(options.jitter) : 0;\n return { life: LIFE, lag: LAG, stagger, length: LIFE + stagger };\n}\n\ntype TrimBurstTimeline = ReturnType<typeof getTrimBurstTimeline>;\n\nconst trimBurstLength = getTrimBurstTimeline().length;\n\nfunction getTrimBurstDuration(\n options: Pick<TrimBurstOptions, \"count\" | \"jitter\" | \"delay\" | \"speed\"> = {},\n) {\n const rate = rateOf(options.speed);\n const { length } = getTrimBurstTimeline(options);\n const motion = rate === 0 ? 0 : length / rate;\n return Math.ceil(round(delayOf(options.delay) + motion)) + HOLD;\n}\n\nfunction getTrimBurstTime(\n frame: number,\n options: Pick<TrimBurstOptions, \"fps\" | \"delay\" | \"speed\"> = {},\n) {\n const fps = Math.max(1, finite(options.fps, 30));\n const elapsed = Math.max(0, finite(frame, 0) - delayOf(options.delay));\n return elapsed * (30 / fps) * rateOf(options.speed);\n}\n\nfunction getTrimBurstEndProgress(time: number) {\n if (Number.isNaN(time) || time <= 0) return 0;\n if (time >= LIFE) return 1;\n return END_EASE(time / LIFE);\n}\n\nfunction getTrimBurstStartProgress(time: number) {\n if (Number.isNaN(time) || time <= LAG) return 0;\n if (time >= LIFE) return 1;\n return START_EASE((time - LAG) / (LIFE - LAG));\n}\n\nfunction getTrimBurstLeash(gap: number, strokeLength: number) {\n if (!(gap > 0 && strokeLength > 0)) return 0;\n return gap / (1 + (gap / strokeLength) ** LEASH) ** (1 / LEASH);\n}\n\nfunction getTrimBurstTrim(\n time: number,\n reach: number,\n strokeLength: number,\n): TrimBurstTrim {\n const distance = Math.max(0, finite(reach, 0));\n const end = distance * getTrimBurstEndProgress(time);\n const own = distance * getTrimBurstStartProgress(time);\n const length = getTrimBurstLeash(end - own, strokeLength);\n return { start: end - length, end, length };\n}\n\nfunction getTrimBurstDotScale(time: number) {\n if (Number.isNaN(time) || time <= DOT_START || time >= LIFE) return 0;\n const pop = Math.min(1, (time - DOT_START) / DOT_POP) - 1;\n const grow = 1 + (DOT_BACK + 1) * pop ** 3 + DOT_BACK * pop ** 2;\n const settle = DOT_START + DOT_POP;\n const shrink = clamp((time - settle) / (LIFE - settle), 0, 1);\n return grow * (1 - shrink ** 3);\n}\n\nfunction getTrimBurstStrokes(\n options: Pick<\n TrimBurstOptions,\n \"count\" | \"rotation\" | \"spread\" | \"jitter\" | \"seed\"\n > = {},\n): TrimBurstStroke[] {\n const count = countOf(options.count);\n const rotation = finite(options.rotation, trimBurstDefaults.rotation);\n const spread = within(options.spread, trimBurstDefaults.spread, 0, 360);\n const jitter = jitterOf(options.jitter);\n const seed = finite(options.seed, trimBurstDefaults.seed);\n const fan = spread < 360 && count > 1;\n const step = fan ? spread / (count - 1) : 360 / count;\n const first = fan ? rotation - spread / 2 : rotation;\n const wobble = WOBBLE * jitter * Math.min(step, MAX_STEP);\n const { stagger } = getTrimBurstTimeline({ count, jitter });\n const keys = Array.from({ length: count }, (_, index) =>\n random(`trim-burst-${seed}-order-${index}`),\n );\n const order = keys.map((_, index) => index);\n order.sort((a, b) => keys[a] - keys[b]);\n const ranks: number[] = [];\n for (const [position, index] of order.entries()) ranks[index] = position;\n return keys.map((_, index) => {\n const turn = random(`trim-burst-${seed}-angle-${index}`) * 2 - 1;\n const shrink = random(`trim-burst-${seed}-scale-${index}`);\n return {\n index,\n angle: first + index * step + turn * wobble,\n scale: 1 - SHRINK * jitter * shrink,\n launch: count > 1 ? (stagger * ranks[index]) / (count - 1) : 0,\n };\n });\n}\n\nfunction getTrimBurstState(\n frame: number,\n options: TrimBurstOptions = {},\n strokes: TrimBurstStroke[] = getTrimBurstStrokes(options),\n) {\n const fallback = trimBurstDefaults;\n const width = Math.max(1, finite(options.width, 1280));\n const height = Math.max(1, finite(options.height, 720));\n const unit = height / 720;\n const time = getTrimBurstTime(frame, options);\n const originX = finite(options.x, fallback.x) * width;\n const originY = finite(options.y, fallback.y) * height;\n const inner = within(options.innerRadius, fallback.innerRadius, 0, MAX_SIZE);\n const reach = within(options.reach, fallback.reach, 0, MAX_SIZE);\n const strokeLength = within(\n options.strokeLength,\n fallback.strokeLength,\n MIN_STROKE,\n MAX_SIZE,\n );\n const size = within(options.weight, fallback.weight, MIN_WEIGHT, MAX_WEIGHT);\n const offset = inner * unit;\n const weight = size * unit;\n const gap = DOT_GAP * weight;\n const radius = DOT_RADIUS * weight;\n const lines: TrimBurstLine[] = [];\n const dots: TrimBurstDot[] = [];\n for (const stroke of strokes) {\n const local = time - stroke.launch;\n const trim = getTrimBurstTrim(\n local,\n reach * unit * stroke.scale,\n strokeLength * unit * stroke.scale,\n );\n const angle = (stroke.angle * Math.PI) / 180;\n const dx = Math.sin(angle);\n const dy = -Math.cos(angle);\n const along = (distance: number) => ({\n x: round(originX + dx * (offset + distance)),\n y: round(originY + dy * (offset + distance)),\n });\n if (trim.length > VISIBLE) {\n const from = along(trim.start);\n const to = along(trim.end);\n lines.push({\n index: stroke.index,\n x1: from.x,\n y1: from.y,\n x2: to.x,\n y2: to.y,\n width: round(Math.min(weight, trim.length)),\n });\n }\n const pop = options.dots === true ? getTrimBurstDotScale(local) : 0;\n if (pop > 0) {\n const center = along(trim.end + gap + radius);\n dots.push({\n index: stroke.index,\n cx: center.x,\n cy: center.y,\n r: round(radius * pop),\n });\n }\n }\n return {\n width,\n height,\n unit,\n time,\n originX,\n originY,\n weight,\n cap: capOf(options.cap),\n lines,\n dots,\n };\n}\n\ntype TrimBurstState = ReturnType<typeof getTrimBurstState>;\n\nfunction TrimBurstBase({\n x = trimBurstDefaults.x,\n y = trimBurstDefaults.y,\n count = trimBurstDefaults.count,\n innerRadius = trimBurstDefaults.innerRadius,\n reach = trimBurstDefaults.reach,\n strokeLength = trimBurstDefaults.strokeLength,\n weight = trimBurstDefaults.weight,\n rotation = trimBurstDefaults.rotation,\n spread = trimBurstDefaults.spread,\n jitter = trimBurstDefaults.jitter,\n dots = trimBurstDefaults.dots,\n cap = trimBurstDefaults.cap,\n color = trimBurstDefaults.color,\n seed = trimBurstDefaults.seed,\n delay = trimBurstDefaults.delay,\n speed = trimBurstDefaults.speed,\n className,\n}: TrimBurstProps) {\n const frame = useCurrentFrame();\n const { width, height, fps } = useVideoConfig();\n const strokes = useMemo(\n () => getTrimBurstStrokes({ count, rotation, spread, jitter, seed }),\n [count, rotation, spread, jitter, seed],\n );\n const state = getTrimBurstState(\n frame,\n {\n width,\n height,\n fps,\n x,\n y,\n innerRadius,\n reach,\n strokeLength,\n weight,\n dots,\n cap,\n delay,\n speed,\n },\n strokes,\n );\n\n return (\n <div\n className={className}\n style={{ position: \"absolute\", inset: 0, pointerEvents: \"none\" }}\n >\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox={`0 0 ${width} ${height}`}\n role=\"img\"\n aria-label=\"Trim burst\"\n style={{ display: \"block\", overflow: \"visible\" }}\n >\n <g fill=\"none\" stroke={color} strokeLinecap={state.cap}>\n {state.lines.map((line) => (\n <line\n key={line.index}\n x1={line.x1}\n y1={line.y1}\n x2={line.x2}\n y2={line.y2}\n strokeWidth={line.width}\n />\n ))}\n </g>\n <g fill={color}>\n {state.dots.map((dot) => (\n <circle key={dot.index} cx={dot.cx} cy={dot.cy} r={dot.r} />\n ))}\n </g>\n </svg>\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n count: {\n type: \"number\",\n default: 8,\n min: 1,\n max: 24,\n step: 1,\n description: \"Strokes\",\n hiddenFromList: false,\n },\n innerRadius: {\n type: \"number\",\n default: 16,\n min: 0,\n max: 160,\n step: 1,\n description: \"Inner radius\",\n hiddenFromList: false,\n },\n reach: {\n type: \"number\",\n default: 64,\n min: 8,\n max: 240,\n step: 1,\n description: \"Reach\",\n hiddenFromList: false,\n },\n strokeLength: {\n type: \"number\",\n default: 56,\n min: 4,\n max: 200,\n step: 1,\n description: \"Stroke length\",\n hiddenFromList: false,\n },\n weight: {\n type: \"number\",\n default: 2,\n min: 0.5,\n max: 8,\n step: 0.5,\n description: \"Stroke weight\",\n hiddenFromList: false,\n },\n rotation: {\n type: \"number\",\n default: 0,\n min: -180,\n max: 180,\n step: 1,\n description: \"Rotation\",\n hiddenFromList: false,\n },\n spread: {\n type: \"number\",\n default: 360,\n min: 15,\n max: 360,\n step: 5,\n description: \"Spread\",\n hiddenFromList: false,\n },\n jitter: {\n type: \"number\",\n default: 0.5,\n min: 0,\n max: 1,\n step: 0.05,\n description: \"Jitter\",\n hiddenFromList: false,\n },\n dots: {\n type: \"boolean\",\n default: false,\n description: \"Tip dots\",\n },\n cap: {\n type: \"enum\",\n default: \"round\",\n variants: {\n round: {},\n butt: {},\n },\n description: \"Caps\",\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Line color\",\n },\n seed: {\n type: \"number\",\n default: 1,\n min: 1,\n max: 99,\n step: 1,\n description: \"Seed\",\n hiddenFromList: false,\n },\n delay: {\n type: \"number\",\n default: 0,\n min: 0,\n max: 30,\n step: 1,\n description: \"Delay\",\n hiddenFromList: false,\n },\n x: {\n type: \"number\",\n default: 0.5,\n min: 0,\n max: 1,\n step: 0.01,\n description: \"Center x\",\n hiddenFromList: false,\n },\n y: {\n type: \"number\",\n default: 0.5,\n min: 0,\n max: 1,\n step: 0.01,\n description: \"Center y\",\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([\"count\",\"innerRadius\",\"reach\",\"strokeLength\",\"weight\",\"rotation\",\"spread\",\"jitter\",\"dots\",\"cap\",\"color\",\"seed\",\"delay\",\"x\",\"y\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n count: 8,\n innerRadius: 16,\n reach: 64,\n strokeLength: 56,\n weight: 2,\n rotation: 0,\n spread: 360,\n jitter: 0.5,\n dots: false,\n cap: \"round\",\n color: \"#ffffff\",\n seed: 1,\n delay: 0,\n x: 0.5,\n y: 0.5,\n speed: 1,\n};\n\ntype TrimBurstElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof TrimBurstBase>;\n\nconst TrimBurstInner = forwardRef<\n HTMLDivElement,\n TrimBurstElementProps & { 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 ?? \"<TrimBurst>\"}\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 <TrimBurstBase\n {...(componentProps as unknown as ComponentProps<typeof TrimBurstBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const TrimBurst = Interactive.withSchema({\n Component: TrimBurstInner,\n componentName: \"<TrimBurst>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 18,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 18
}