BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/Svelte Animations/animated-beam

Animated Beam

svelte-animations/animated-beam
FreeBlock

A component for creating animated beam effects between two elements with customizable gradients and paths.

Install it

npx shadcn@latest add https://sv-animations.vercel.app/r/animated-beam.json

Source

./src/lib/components/magic/animated-beam/animated-beam.sveltesv-animations.vercel.app/r/animated-beam.json
1<script lang="ts">
2 import { motion } from "motion-sv";
3 import { cn } from "$UTILS$";
4 import type { AnimatedBeamProps } from "./types";
5 import { usePathCalculator } from "./use-path-calculator.svelte";
6 import { useGradientCoordinates } from "./use-gradient-coordinates.svelte";
7 import { useResizeObserver } from "./use-resize-observer.svelte";
8
9 let {
10 class: className,
11 containerRef,
12 fromRef,
13 toRef,
14 curvature = 0,
15 reverse = false,
16 duration = Math.random() * 3 + 4,
17 delay = 0,
18 pathColor = "gray",
19 pathWidth = 2,
20 pathOpacity = 0.2,
21 gradientStartColor = "#ffaa40",
22 gradientStopColor = "#9c40ff",
23 startXOffset = 0,
24 startYOffset = 0,
25 endXOffset = 0,
26 endYOffset = 0,
27 }: AnimatedBeamProps = $props();
28
29 // Generate unique ID for gradient
30 // let id = $state(`gradient-${Math.random().toString(36).substring(2, 11)}`);
31 let id = $props.id();
32
33 // Use path calculator
34 const pathCalculator = usePathCalculator();
35
36 // Calculate gradient coordinates based on reverse prop
37 const gradientCoordinates = $derived(useGradientCoordinates(reverse));
38
39 // Update path function
40 const updatePath = () => {
41 pathCalculator.calculatePath(
42 containerRef,
43 fromRef,
44 toRef,
45 curvature,
46 startXOffset,
47 startYOffset,
48 endXOffset,
49 endYOffset
50 );
51 };
52
53 // Setup resize observer
54 useResizeObserver(() => containerRef, updatePath);
55
56 // Watch for changes in refs and offsets
57 $effect(() => {
58 updatePath();
59 });
60</script>
61
62<svg
63 fill="none"
64 width={pathCalculator.svgDimensions.width}
65 height={pathCalculator.svgDimensions.height}
66 xmlns="http://www.w3.org/2000/svg"
67 class={cn("pointer-events-none absolute top-0 left-0 transform-gpu stroke-2", className)}
68 viewBox={`0 0 ${pathCalculator.svgDimensions.width} ${pathCalculator.svgDimensions.height}`}
69>
70 <path
71 d={pathCalculator.pathD}
72 stroke={pathColor}
73 stroke-width={pathWidth}
74 stroke-opacity={pathOpacity}
75 stroke-linecap="round"
76 />
77 <path
78 d={pathCalculator.pathD}
79 stroke-width={pathWidth}
80 stroke={`url(#${id})`}
81 stroke-opacity="1"
82 stroke-linecap="round"
83 />
84 <defs>
85 <motion.linearGradient
86 class="transform-gpu"
87 {id}
88 gradientUnits="userSpaceOnUse"
89 initial={{
90 x1: "0%",
91 x2: "0%",
92 y1: "0%",
93 y2: "0%",
94 }}
95 animate={{
96 x1: gradientCoordinates.x1,
97 x2: gradientCoordinates.x2,
98 y1: gradientCoordinates.y1,
99 y2: gradientCoordinates.y2,
100 }}
101 transition={{
102 delay,
103 duration,
104 ease: [0.16, 1, 0.3, 1],
105 repeat: Infinity,
106// … truncated

What it pulls in

npm packages

  • motion-sv

Files it writes

  • ./src/lib/components/magic/animated-beam/animated-beam.svelte
  • ./src/lib/components/magic/animated-beam/index.ts
  • ./src/lib/components/magic/animated-beam/types.ts
  • ./src/lib/components/magic/animated-beam/use-gradient-coordinates.svelte.ts
  • ./src/lib/components/magic/animated-beam/use-path-calculator.svelte.ts
  • ./src/lib/components/magic/animated-beam/use-resize-observer.svelte.ts

Facts

Registry
Svelte Animations
Type
registry:block
Access
Free
Files written
6
Licence
MIT
First indexed
2026-08-01
Last confirmed
3 days ago

Go to the source

sv-animations.vercel.app SikandarJODD/animations on GitHub Raw registry item This item as JSON

More from Svelte Animations

All 66 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Animated Circular Progress Baranimated-circular-progress-barSvelte AnimationsBlocksFreeno deps · 2 files
Animated Gradient Textanimated-gradient-textSvelte AnimationsBlocksFreeno deps · 2 files
Animated Grid Patternanimated-grid-patternSvelte AnimationsBlocksFree1 dep · 2 files
Animated Listanimated-listSvelte AnimationsBlocksFree1 dep · 2 files
Animated Shiny Textanimated-shiny-textSvelte AnimationsBlocksFreeno deps
Animated Theme Toggleranimated-theme-togglerSvelte AnimationsBlocksFreeno deps · 2 files
Arc Timelinearc-timelineSvelte AnimationsBlocksFreeno deps · 3 files
Aurora Textaurora-textSvelte AnimationsBlocksFreeno deps · 2 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex