# AnimatedBeam

> Fibre-optic connector between two elements: a light packet with a dispersing chromatic tail runs along a glass fibre and blooms behind the destination on arrival; theme-aware, seeded and still under reduced motion.

- Package: `fancy-ui-svelte` (Svelte 5 + Tailwind CSS v4)
- Category: Effects
- Tags: animation, svg, beam, gradient, connection
- Types: `AnimatedBeamProps`
- Docs: https://fancy-ui.rama.app/docs/components/animated-beam
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/src/lib/fancy-ui/animated-beam

## Import

```svelte
<script lang="ts">
  import { AnimatedBeam } from 'fancy-ui-svelte';
</script>
```

Setup (once per project): `npm install fancy-ui-svelte`, then add `@import "fancy-ui-svelte/tailwind.css";` after `@import "tailwindcss";` in your main CSS file. Full guide: https://fancy-ui.rama.app/llms.txt

React: `import { AnimatedBeam } from 'fancy-ui-react';` (`class` becomes `className`, snippets become `ReactNode`, DOM callbacks are camel-cased; exact names on https://fancy-ui.rama.app/docs/components/react/animated-beam.md).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `containerRef` (required) | `HTMLElement` | — | Reference to the container element that holds both endpoints |
| `fromRef` (required) | `HTMLElement` | — | Reference to the source element |
| `toRef` (required) | `HTMLElement` | — | Reference to the destination element |
| `curvature` | `number` | `0` | Vertical curvature of the beam path |
| `reverse` | `boolean` | `false` | Reverse the animation direction |
| `pathColor` | `string` | `theme-aware glass` | CHANGED DEFAULT (was "gray"): unset draws the theme-aware glass fibre; a colour draws a plain line in that colour, as before. |
| `pathWidth` | `number` | `2` | Stroke width of the path |
| `pathOpacity` | `number` | `1 (glass) / 0.2 (with pathColor)` | CHANGED DEFAULT (was 0.2): fibre opacity; stays 0.2 whenever pathColor is set. |
| `gradientStartColor` | `string` | `"#FFAA40"` | Start color of the animated gradient |
| `gradientStopColor` | `string` | `"#9C40FF"` | End color of the animated gradient |
| `delay` | `number` | `0` | Animation delay in seconds |
| `duration` | `number` | `from seed` | CHANGED DEFAULT (was random): seconds per packet cycle; unset = mulberry32(seed)*3+4. |
| `pulses` | `number` | `1` | Packets in flight at once (1–12), spaced evenly over one cycle. |
| `tail` | `number` | `0.35` | Length of the packet's dispersing tail as a fraction of the fibre (0.05–0.9). |
| `glow` | `number` | `0.6` | Strength of the blurred glow under the packet and of the arrival bloom (0–1). |
| `seed` | `number` | `1` | Seed for the default duration (between 4 and 7 s), so server and browser agree. |
| `startXOffset` | `number` | `0` | Horizontal offset for the start point |
| `startYOffset` | `number` | `0` | Vertical offset for the start point |
| `endXOffset` | `number` | `0` | Horizontal offset for the end point |
| `endYOffset` | `number` | `0` | Vertical offset for the end point |

## Examples

### Basic Usage

Three fibres converge on a hub that feeds a fourth; packets arrive and bloom.

```svelte
<script lang="ts">
	import { AnimatedBeam } from "fancy-ui-svelte";
	import FileText from "@lucide/svelte/icons/file-text";
	import Database from "@lucide/svelte/icons/database";
	import MessageSquare from "@lucide/svelte/icons/message-square";
	import Sparkles from "@lucide/svelte/icons/sparkles";
	import User from "@lucide/svelte/icons/user";

	let containerRef = $state<HTMLElement>();
	let docsRef = $state<HTMLElement>();
	let dataRef = $state<HTMLElement>();
	let chatRef = $state<HTMLElement>();
	let hubRef = $state<HTMLElement>();
	let userRef = $state<HTMLElement>();

	// Nested frame: a hairline shell around a darker inner well.
	const node =
		"relative z-10 rounded-2xl border border-black/[0.08] bg-[#fafafa] p-1 shadow-[0_1px_2px_rgba(0,0,0,0.06)] dark:border-white/[0.08] dark:bg-[#141416] dark:shadow-none";
	const well =
		"flex items-center justify-center rounded-xl border border-black/[0.06] bg-white text-neutral-700 dark:border-white/[0.06] dark:bg-[#0b0b0c] dark:text-neutral-300";
</script>

<div
	class="w-full rounded-[22px] border border-black/[0.08] bg-[#f4f4f5] p-1.5 dark:border-white/[0.08] dark:bg-[#0b0b0c]"
>
	<div
		bind:this={containerRef}
		class="relative flex h-[420px] w-full items-center justify-center overflow-hidden rounded-2xl border border-black/[0.06] bg-[#fafafa] dark:border-white/[0.06] dark:bg-[#111113]"
	>
		<!-- faint dot field -->
		<div
			aria-hidden="true"
			class="pointer-events-none absolute inset-0 [background-image:radial-gradient(rgba(0,0,0,0.07)_1px,transparent_1px)] [mask-image:radial-gradient(ellipse_at_center,black,transparent_75%)] [background-size:18px_18px] dark:[background-image:radial-gradient(rgba(255,255,255,0.06)_1px,transparent_1px)]"
		></div>

		<div class="flex w-full max-w-xl items-center justify-between px-8 sm:px-12">
			<div class="flex flex-col gap-10">
				<div bind:this={docsRef} class={node}>
					<div class="{well} size-11"><FileText class="size-[18px]" strokeWidth={1.6} /></div>
				</div>
				<div bind:this={dataRef} class={node}>
					<div class="{well} size-11"><Database class="size-[18px]" strokeWidth={1.6} /></div>
				</div>
				<div bind:this={chatRef} class={node}>
					<div class="{well} size-11"><MessageSquare class="size-[18px]" strokeWidth={1.6} /></div>
				</div>
			</div>

			<div bind:this={hubRef} class="{node} rounded-[22px] p-1.5">
				<div class="{well} size-16 rounded-[16px]">
					<Sparkles class="size-6" strokeWidth={1.5} />
				</div>
			</div>

			<div bind:this={userRef} class={node}>
				<div class="{well} size-11"><User class="size-[18px]" strokeWidth={1.6} /></div>
			</div>
		</div>

		{#if containerRef && hubRef}
			{#if docsRef}
				<AnimatedBeam
					{containerRef}
					fromRef={docsRef}
					toRef={hubRef}
					curvature={-60}
					endYOffset={-12}
					gradientStartColor="#f2b880"
					gradientStopColor="#a78bfa"
					seed={3}
				/>
			{/if}
			{#if dataRef}
				<AnimatedBeam
					{containerRef}
					fromRef={dataRef}
					toRef={hubRef}
					gradientStartColor="#f2b880"
					gradientStopColor="#a78bfa"
					seed={7}
					delay={0.9}
				/>
			{/if}
			{#if chatRef}
				<AnimatedBeam
					{containerRef}
					fromRef={chatRef}
					toRef={hubRef}
					curvature={60}
					endYOffset={12}
					gradientStartColor="#f2b880"
					gradientStopColor="#a78bfa"
					seed={11}
					delay={1.7}
				/>
			{/if}
			{#if userRef}
				<AnimatedBeam
					{containerRef}
					fromRef={hubRef}
					toRef={userRef}
					gradientStartColor="#f2b880"
					gradientStopColor="#a78bfa"
					seed={5}
					delay={2.4}
				/>
			{/if}
		{/if}
	</div>
</div>
```

### Dispersion

Three packets in flight with a long cool tail and strong glow, and a short warm tail run in reverse.

```svelte
<script lang="ts">
	import { AnimatedBeam } from "fancy-ui-svelte";
	import Cloud from "@lucide/svelte/icons/cloud";
	import Laptop from "@lucide/svelte/icons/laptop";

	let containerRef = $state<HTMLElement>();
	let leftRef = $state<HTMLElement>();
	let rightRef = $state<HTMLElement>();

	const node =
		"relative z-10 rounded-2xl border border-black/[0.08] bg-[#fafafa] p-1 shadow-[0_1px_2px_rgba(0,0,0,0.06)] dark:border-white/[0.08] dark:bg-[#141416] dark:shadow-none";
	const well =
		"flex size-14 items-center justify-center rounded-xl border border-black/[0.06] bg-white text-neutral-700 dark:border-white/[0.06] dark:bg-[#0b0b0c] dark:text-neutral-300";
</script>

<div
	class="w-full rounded-[22px] border border-black/[0.08] bg-[#f4f4f5] p-1.5 dark:border-white/[0.08] dark:bg-[#0b0b0c]"
>
	<div
		bind:this={containerRef}
		class="relative flex h-[300px] w-full items-center justify-between overflow-hidden rounded-2xl border border-black/[0.06] bg-[#fafafa] px-10 sm:px-20 dark:border-white/[0.06] dark:bg-[#111113]"
	>
		<div bind:this={leftRef} class={node}>
			<div class={well}><Laptop class="size-5" strokeWidth={1.5} /></div>
		</div>
		<div bind:this={rightRef} class={node}>
			<div class={well}><Cloud class="size-5" strokeWidth={1.5} /></div>
		</div>

		{#if containerRef && leftRef && rightRef}
			<!-- Upload: three packets in flight, long cool tail, strong glow. -->
			<AnimatedBeam
				{containerRef}
				fromRef={leftRef}
				toRef={rightRef}
				curvature={70}
				startYOffset={-10}
				endYOffset={-10}
				pulses={3}
				tail={0.5}
				glow={0.9}
				duration={4.5}
				gradientStartColor="#7dd3fc"
				gradientStopColor="#a78bfa"
			/>
			<!-- Download: the same fibre run backwards, short warm tail, faint glow. -->
			<AnimatedBeam
				{containerRef}
				fromRef={leftRef}
				toRef={rightRef}
				curvature={-70}
				startYOffset={10}
				endYOffset={10}
				reverse
				pulses={2}
				tail={0.22}
				glow={0.35}
				duration={5.5}
				delay={0.8}
				gradientStartColor="#fcd34d"
				gradientStopColor="#f472b6"
			/>
		{/if}
	</div>
</div>
```
