{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"shadcnblocks/cover","title":"Cover - Hover sparkle cover","description":"An inline highlight that darkens on hover, sweeps beams, and fills the box with sparkle particles.","dependencies":["motion","cn"],"registryDependencies":[],"files":[{"path":"components/shadcnblocks/cover.tsx","content":"// Modified from Aceternity UI (https://ui.aceternity.com)\n// Updated to use custom sparkles component without tsparticles dependency\n\n\"use client\";\nimport React, { useEffect, useId, useState } from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport { useRef } from \"react\";\nimport { cn } from \"cn\";\nimport { SparklesCore } from \"@/components/shadcnblocks/sparkles\";\n\nexport const Cover = ({\n  children,\n  className,\n}: {\n  children?: React.ReactNode;\n  className?: string;\n}) => {\n  const [hovered, setHovered] = useState(false);\n\n  const ref = useRef<HTMLDivElement>(null);\n\n  const [containerWidth, setContainerWidth] = useState(0);\n  const [beamPositions, setBeamPositions] = useState<number[]>([]);\n\n  useEffect(() => {\n    if (ref.current) {\n      setContainerWidth(ref.current?.clientWidth ?? 0);\n\n      const height = ref.current?.clientHeight ?? 0;\n      const numberOfBeams = Math.floor(height / 10); // Adjust the divisor to control the spacing\n      const positions = Array.from(\n        { length: numberOfBeams },\n        (_, i) => (i + 1) * (height / (numberOfBeams + 1))\n      );\n      setBeamPositions(positions);\n    }\n  }, [ref.current]);\n\n  return (\n    <div\n      onMouseEnter={() => setHovered(true)}\n      onMouseLeave={() => setHovered(false)}\n      ref={ref}\n      className=\"relative hover:bg-neutral-900  group/cover inline-block dark:bg-neutral-900 bg-neutral-100 px-2 py-2  transition duration-200 rounded-sm\"\n    >\n      <AnimatePresence>\n        {hovered && (\n          <motion.div\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={{\n              opacity: {\n                duration: 0.2,\n              },\n            }}\n            className=\"h-full w-full overflow-hidden absolute inset-0\"\n          >\n            <motion.div\n              animate={{\n                translateX: [\"-50%\", \"0%\"],\n              }}\n              transition={{\n                translateX: {\n                  duration: 10,\n                  ease: \"linear\",\n                  repeat: Infinity,\n                },\n              }}\n              className=\"w-[200%] h-full flex\"\n            >\n              <SparklesCore\n                background=\"transparent\"\n                minSize={0.4}\n                maxSize={1}\n                particleDensity={500}\n                className=\"w-full h-full\"\n                particleColor=\"#FFFFFF\"\n              />\n              <SparklesCore\n                background=\"transparent\"\n                minSize={0.4}\n                maxSize={1}\n                particleDensity={500}\n                className=\"w-full h-full\"\n                particleColor=\"#FFFFFF\"\n              />\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n      {beamPositions.map((position, index) => (\n        <Beam\n          key={index}\n          hovered={hovered}\n          duration={Math.random() * 2 + 1}\n          delay={Math.random() * 2 + 1}\n          width={containerWidth}\n          style={{\n            top: `${position}px`,\n          }}\n        />\n      ))}\n      <motion.span\n        key={String(hovered)}\n        animate={{\n          scale: hovered ? 0.8 : 1,\n          x: hovered ? [0, -30, 30, -30, 30, 0] : 0,\n          y: hovered ? [0, 30, -30, 30, -30, 0] : 0,\n        }}\n        exit={{\n          filter: \"none\",\n          scale: 1,\n          x: 0,\n          y: 0,\n        }}\n        transition={{\n          duration: 0.2,\n          x: {\n            duration: 0.2,\n            repeat: Infinity,\n            repeatType: \"loop\",\n          },\n          y: {\n            duration: 0.2,\n            repeat: Infinity,\n            repeatType: \"loop\",\n          },\n          scale: {\n            duration: 0.2,\n          },\n          filter: {\n            duration: 0.2,\n          },\n        }}\n        className={cn(\n          \"dark:text-white inline-block text-neutral-900 relative z-20 group-hover/cover:text-white transition duration-200\",\n          className\n        )}\n      >\n        {children}\n      </motion.span>\n      <CircleIcon className=\"absolute -right-[2px] -top-[2px]\" />\n      <CircleIcon className=\"absolute -bottom-[2px] -right-[2px]\" delay={0.4} />\n      <CircleIcon className=\"absolute -left-[2px] -top-[2px]\" delay={0.8} />\n      <CircleIcon className=\"absolute -bottom-[2px] -left-[2px]\" delay={1.6} />\n    </div>\n  );\n};\n\nexport const Beam = ({\n  className,\n  delay,\n  duration,\n  hovered,\n  width = 600,\n  ...svgProps\n}: {\n  className?: string;\n  delay?: number;\n  duration?: number;\n  hovered?: boolean;\n  width?: number;\n} & React.ComponentProps<typeof motion.svg>) => {\n  const id = useId();\n\n  return (\n    <motion.svg\n      width={width ?? \"600\"}\n      height=\"1\"\n      viewBox={`0 0 ${width ?? \"600\"} 1`}\n      fill=\"none\"\n      xmlns=\"http://www.w3.org/2000/svg\"\n      className={cn(\"absolute inset-x-0 w-full\", className)}\n      {...svgProps}\n    >\n      <motion.path\n        d={`M0 0.5H${width ?? \"600\"}`}\n        stroke={`url(#svgGradient-${id})`}\n      />\n\n      <defs>\n        <motion.linearGradient\n          id={`svgGradient-${id}`}\n          key={String(hovered)}\n          gradientUnits=\"userSpaceOnUse\"\n          initial={{\n            x1: \"0%\",\n            x2: hovered ? \"-10%\" : \"-5%\",\n            y1: 0,\n            y2: 0,\n          }}\n          animate={{\n            x1: \"110%\",\n            x2: hovered ? \"100%\" : \"105%\",\n            y1: 0,\n            y2: 0,\n          }}\n          transition={{\n            duration: hovered ? 0.5 : duration ?? 2,\n            ease: \"linear\",\n            repeat: Infinity,\n            delay: hovered ? Math.random() * (1 - 0.2) + 0.2 : 0,\n            repeatDelay: hovered ? Math.random() * (2 - 1) + 1 : delay ?? 1,\n          }}\n        >\n          <stop stopColor=\"#2EB9DF\" stopOpacity=\"0\" />\n          <stop stopColor=\"#3b82f6\" />\n          <stop offset=\"1\" stopColor=\"#3b82f6\" stopOpacity=\"0\" />\n        </motion.linearGradient>\n      </defs>\n    </motion.svg>\n  );\n};\n\nexport const CircleIcon = ({\n  className,\n  delay,\n}: {\n  className?: string;\n  delay?: number;\n}) => {\n  return (\n    <div\n      className={cn(\n        `pointer-events-none animate-pulse group-hover/cover:hidden group-hover/cover:opacity-100 group h-2 w-2 rounded-full bg-neutral-600 dark:bg-white opacity-20 group-hover/cover:bg-white`,\n        className\n      )}\n    ></div>\n  );\n};\n","type":"registry:component"},{"path":"components/shadcnblocks/sparkles.tsx","content":"// Modified from Aceternity UI (https://ui.aceternity.com)\n// Rewritten to use native Canvas API instead of tsparticles\n\n\"use client\";\nimport React, { useRef, useEffect, useId, useCallback, useState } from \"react\";\nimport { cn } from \"cn\";\n\ntype ParticlesProps = {\n  id?: string;\n  className?: string;\n  background?: string;\n  particleSize?: number;\n  minSize?: number;\n  maxSize?: number;\n  speed?: number;\n  particleColor?: string;\n  particleDensity?: number;\n};\n\ninterface Particle {\n  x: number;\n  y: number;\n  size: number;\n  speedX: number;\n  speedY: number;\n  opacity: number;\n  opacitySpeed: number;\n  opacityDirection: number;\n}\n\nexport const SparklesCore = (props: ParticlesProps) => {\n  const {\n    id,\n    className,\n    background = \"transparent\",\n    minSize = 1,\n    maxSize = 3,\n    speed = 4,\n    particleColor = \"#ffffff\",\n    particleDensity = 120,\n  } = props;\n\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const containerRef = useRef<HTMLDivElement>(null);\n  const particlesRef = useRef<Particle[]>([]);\n  const animationFrameRef = useRef<number>(undefined);\n  const generatedId = useId();\n  const [isVisible, setIsVisible] = useState(false);\n\n  const createParticle = useCallback(\n    (width: number, height: number): Particle => {\n      const baseSpeed = speed * 0.02;\n      return {\n        x: Math.random() * width,\n        y: Math.random() * height,\n        size: Math.random() * (maxSize - minSize) + minSize,\n        speedX: (Math.random() - 0.5) * baseSpeed,\n        speedY: (Math.random() - 0.5) * baseSpeed,\n        opacity: Math.random(),\n        opacitySpeed: (Math.random() * 0.5 + 0.5) * speed * 0.01,\n        opacityDirection: Math.random() > 0.5 ? 1 : -1,\n      };\n    },\n    [minSize, maxSize, speed],\n  );\n\n  const initParticles = useCallback(\n    (width: number, height: number) => {\n      // Calculate particle count based on density and area\n      const area = width * height;\n      const baseArea = 400 * 400;\n      const count = Math.floor((particleDensity * area) / baseArea);\n\n      particlesRef.current = Array.from({ length: count }, () =>\n        createParticle(width, height),\n      );\n    },\n    [particleDensity, createParticle],\n  );\n\n  const hexToRgb = (hex: string): { r: number; g: number; b: number } => {\n    const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex);\n    return result\n      ? {\n          r: parseInt(result[1], 16),\n          g: parseInt(result[2], 16),\n          b: parseInt(result[3], 16),\n        }\n      : { r: 255, g: 255, b: 255 };\n  };\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    const container = containerRef.current;\n    if (!canvas || !container) return;\n\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n\n    const rgb = hexToRgb(particleColor);\n\n    const resizeCanvas = () => {\n      const rect = container.getBoundingClientRect();\n      const dpr = window.devicePixelRatio || 1;\n\n      canvas.width = rect.width * dpr;\n      canvas.height = rect.height * dpr;\n      canvas.style.width = `${rect.width}px`;\n      canvas.style.height = `${rect.height}px`;\n\n      ctx.scale(dpr, dpr);\n\n      initParticles(rect.width, rect.height);\n    };\n\n    const animate = () => {\n      const rect = container.getBoundingClientRect();\n      ctx.clearRect(0, 0, rect.width, rect.height);\n\n      particlesRef.current.forEach((particle) => {\n        // Update position\n        particle.x += particle.speedX;\n        particle.y += particle.speedY;\n\n        // Wrap around edges\n        if (particle.x < 0) particle.x = rect.width;\n        if (particle.x > rect.width) particle.x = 0;\n        if (particle.y < 0) particle.y = rect.height;\n        if (particle.y > rect.height) particle.y = 0;\n\n        // Update opacity (twinkling effect)\n        particle.opacity += particle.opacitySpeed * particle.opacityDirection;\n        if (particle.opacity >= 1) {\n          particle.opacity = 1;\n          particle.opacityDirection = -1;\n        } else if (particle.opacity <= 0.1) {\n          particle.opacity = 0.1;\n          particle.opacityDirection = 1;\n        }\n\n        // Draw particle\n        ctx.beginPath();\n        ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);\n        ctx.fillStyle = `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${particle.opacity})`;\n        ctx.fill();\n      });\n\n      animationFrameRef.current = requestAnimationFrame(animate);\n    };\n\n    resizeCanvas();\n    animate();\n\n    // Trigger fade in\n    requestAnimationFrame(() => setIsVisible(true));\n\n    const resizeObserver = new ResizeObserver(resizeCanvas);\n    resizeObserver.observe(container);\n\n    return () => {\n      if (animationFrameRef.current) {\n        cancelAnimationFrame(animationFrameRef.current);\n      }\n      resizeObserver.disconnect();\n    };\n  }, [particleColor, initParticles]);\n\n  return (\n    <div\n      ref={containerRef}\n      className={cn(\n        \"transition-opacity duration-1000\",\n        isVisible ? \"opacity-100\" : \"opacity-0\",\n        className,\n      )}\n      style={{ background }}\n    >\n      <canvas\n        ref={canvasRef}\n        id={id || generatedId}\n        className=\"h-full w-full\"\n      />\n    </div>\n  );\n};\n","type":"registry:component","target":""}],"type":"registry:component","meta":{"license":"https://www.shadcnblocks.com/license"}}