{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "stars-background", "type": "registry:ui", "title": "Stars Background", "description": "A dark, interactive background featuring animated dots of varying sizes and speeds, simulating a dynamic and immersive starry space effect.", "dependencies": [ "motion" ], "files": [ { "path": "registry/backgrounds/stars/index.tsx", "content": "'use client';\n\nimport * as React from 'react';\nimport {\n type HTMLMotionProps,\n motion,\n type SpringOptions,\n type Transition,\n useMotionValue,\n useSpring,\n} from 'motion/react';\n\nimport { cn } from '@/lib/utils';\n\ntype StarLayerProps = HTMLMotionProps<'div'> & {\n count: number;\n size: number;\n transition: Transition;\n starColor: string;\n};\n\nfunction generateStars(count: number, starColor: string) {\n const shadows: string[] = [];\n for (let i = 0; i < count; i++) {\n const x = Math.floor(Math.random() * 4000) - 2000;\n const y = Math.floor(Math.random() * 4000) - 2000;\n shadows.push(`${x}px ${y}px ${starColor}`);\n }\n return shadows.join(', ');\n}\n\nfunction StarLayer({\n count = 1000,\n size = 1,\n transition = { repeat: Infinity, duration: 50, ease: 'linear' },\n starColor = '#fff',\n className,\n ...props\n}: StarLayerProps) {\n const [boxShadow, setBoxShadow] = React.useState('');\n\n React.useEffect(() => {\n setBoxShadow(generateStars(count, starColor));\n }, [count, starColor]);\n\n return (\n \n \n \n \n );\n}\n\ntype StarsBackgroundProps = React.ComponentProps<'div'> & {\n factor?: number;\n speed?: number;\n transition?: SpringOptions;\n starColor?: string;\n pointerEvents?: boolean;\n};\n\nfunction StarsBackground({\n children,\n className,\n factor = 0.05,\n speed = 50,\n transition = { stiffness: 50, damping: 20 },\n starColor = '#fff',\n pointerEvents = true,\n ...props\n}: StarsBackgroundProps) {\n const offsetX = useMotionValue(1);\n const offsetY = useMotionValue(1);\n\n const springX = useSpring(offsetX, transition);\n const springY = useSpring(offsetY, transition);\n\n const handleMouseMove = React.useCallback(\n (e: React.MouseEvent) => {\n const centerX = window.innerWidth / 2;\n const centerY = window.innerHeight / 2;\n const newOffsetX = -(e.clientX - centerX) * factor;\n const newOffsetY = -(e.clientY - centerY) * factor;\n offsetX.set(newOffsetX);\n offsetY.set(newOffsetY);\n },\n [offsetX, offsetY, factor],\n );\n\n return (\n \n \n \n \n \n \n {children}\n \n );\n}\n\nexport {\n StarLayer,\n StarsBackground,\n type StarLayerProps,\n type StarsBackgroundProps,\n};\n", "type": "registry:ui", "target": "components/animate-ui/backgrounds/stars.tsx" } ] }