{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"meteors","type":"registry:ui","title":"Meteors","description":"Diagonal meteor streaks with glowing heads, launched at random intervals over a faint starry sky.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/meteors.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useReducedMotion } from \"motion/react\";\nimport { useEffect, useRef } from \"react\";\n\ntype MeteorsProps = {\n  /** Meteors that can be in the sky at once. */\n  count?: number;\n  /** Meteor color as a hex value. */\n  color?: string;\n  /** Fall angle in degrees from vertical. Positive values slant to the left, negative to the right. */\n  angle?: number;\n  /** Fall speed multiplier. */\n  speed?: number;\n  /** Draw a few faint, twinkling stars behind the meteors. */\n  stars?: boolean;\n  className?: string;\n};\n\ntype Meteor = { x: number; y: number; len: number; v: number; w: number; wait: number; age: number };\ntype Star = { x: number; y: number; r: number; phase: number };\n\nfunction hexToRgb(hex: string) {\n  let h = hex.replace(\"#\", \"\");\n  if (h.length === 3) h = h.replace(/./g, (c) => c + c);\n  const n = parseInt(h, 16) || 0;\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\n/** Diagonal meteor streaks with glowing heads, launched at random intervals. */\nexport function Meteors({ count = 10, color = \"#ffa585\", angle = 35, speed = 1, stars = true, className = \"\" }: MeteorsProps) {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const reduce = useReducedMotion();\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!canvas || !ctx) return;\n\n    const [r, g, b] = hexToRgb(color);\n    const rgb = `${r},${g},${b}`;\n    // The head is a whiter version of the color, like a hot core.\n    const core = `rgb(${Math.round(r + (255 - r) * 0.7)},${Math.round(g + (255 - g) * 0.7)},${Math.round(b + (255 - b) * 0.7)})`;\n    const rad = (Math.max(-75, Math.min(75, angle)) * Math.PI) / 180;\n    const dx = -Math.sin(rad);\n    const dy = Math.cos(rad);\n    let width = 0;\n    let height = 0;\n    let frame = 0;\n    let visible = true;\n    let last = 0;\n    let sky: Star[] = [];\n\n    const launch = (m: Meteor, wait: number) => {\n      // Start anywhere along the top edge, widened so slanted meteors still cover the whole area.\n      const drift = (height * dx) / dy;\n      const minX = Math.min(0, -drift);\n      const maxX = Math.max(width, width - drift);\n      m.x = minX + Math.random() * (maxX - minX);\n      m.y = -10 - Math.random() * height * 0.25;\n      m.len = 80 + Math.random() * 170;\n      m.v = (0.45 + Math.random() * 0.55) * speed;\n      m.w = 1 + Math.random() * 1.1;\n      m.wait = wait;\n      m.age = 0;\n    };\n    const meteors: Meteor[] = Array.from({ length: Math.max(1, Math.round(count)) }, () => ({\n      x: 0,\n      y: 0,\n      len: 0,\n      v: 0,\n      w: 1,\n      wait: 0,\n      age: 0,\n    }));\n\n    const draw = (t: number) => {\n      const dt = last ? Math.min(50, t - last) : 16;\n      last = t;\n      ctx.clearRect(0, 0, width, height);\n\n      for (const s of sky) {\n        const tw = reduce ? 0.6 : 0.55 + 0.45 * Math.sin(t * 0.0012 + s.phase);\n        ctx.fillStyle = `rgba(244,237,227,${0.12 + tw * 0.28})`;\n        ctx.fillRect(s.x, s.y, s.r, s.r);\n      }\n\n      ctx.globalCompositeOperation = \"lighter\";\n      ctx.lineCap = \"round\";\n      for (const m of meteors) {\n        if (!reduce) {\n          if (m.wait > 0) {\n            m.wait -= dt;\n            continue;\n          }\n          m.age += dt;\n          m.x += dx * m.v * dt;\n          m.y += dy * m.v * dt;\n          const tailX = m.x - dx * m.len;\n          const tailY = m.y - dy * m.len;\n          if (tailY > height + 10 || tailX < -m.len - 10 || tailX > width + m.len + 10) {\n            launch(m, 300 + Math.random() * 3200);\n            continue;\n          }\n        }\n        const fadeIn = reduce ? 1 : Math.min(1, m.age / 180);\n        const tx = m.x - dx * m.len;\n        const ty = m.y - dy * m.len;\n        const tail = ctx.createLinearGradient(m.x, m.y, tx, ty);\n        tail.addColorStop(0, `rgba(${rgb},${0.9 * fadeIn})`);\n        tail.addColorStop(0.3, `rgba(${rgb},${0.35 * fadeIn})`);\n        tail.addColorStop(1, `rgba(${rgb},0)`);\n        ctx.strokeStyle = tail;\n        ctx.lineWidth = m.w;\n        ctx.beginPath();\n        ctx.moveTo(m.x, m.y);\n        ctx.lineTo(tx, ty);\n        ctx.stroke();\n\n        const glowR = m.w * 7;\n        const glow = ctx.createRadialGradient(m.x, m.y, 0, m.x, m.y, glowR);\n        glow.addColorStop(0, `rgba(${rgb},${0.75 * fadeIn})`);\n        glow.addColorStop(0.35, `rgba(${rgb},${0.2 * fadeIn})`);\n        glow.addColorStop(1, `rgba(${rgb},0)`);\n        ctx.fillStyle = glow;\n        ctx.beginPath();\n        ctx.arc(m.x, m.y, glowR, 0, Math.PI * 2);\n        ctx.fill();\n        ctx.globalAlpha = fadeIn;\n        ctx.fillStyle = core;\n        ctx.beginPath();\n        ctx.arc(m.x, m.y, m.w * 0.9, 0, Math.PI * 2);\n        ctx.fill();\n        ctx.globalAlpha = 1;\n      }\n      ctx.globalCompositeOperation = \"source-over\";\n\n      if (!reduce && visible) frame = requestAnimationFrame(draw);\n      else frame = 0;\n    };\n\n    const resize = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      const first = width === 0;\n      width = canvas.clientWidth;\n      height = canvas.clientHeight;\n      canvas.width = Math.round(width * dpr);\n      canvas.height = Math.round(height * dpr);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      sky = stars\n        ? Array.from({ length: Math.round(Math.min(160, (width * height) / 9000)) }, () => ({\n            x: Math.random() * width,\n            y: Math.random() * height,\n            r: Math.random() < 0.2 ? 1.6 : 1,\n            phase: Math.random() * Math.PI * 2,\n          }))\n        : [];\n      if (first) {\n        for (const m of meteors) {\n          launch(m, Math.random() * 2600);\n          // With reduced motion, freeze a few meteors mid-flight instead of animating them.\n          if (reduce) {\n            const along = (0.25 + Math.random() * 0.6) * (height / dy);\n            m.x += dx * along;\n            m.y += dy * along;\n          }\n        }\n      }\n      if (reduce) draw(0);\n    };\n\n    resize();\n    const observer = new ResizeObserver(resize);\n    observer.observe(canvas);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible && !reduce && !frame) {\n        last = 0;\n        frame = requestAnimationFrame(draw);\n      }\n    });\n    io.observe(canvas);\n    if (!reduce) frame = requestAnimationFrame(draw);\n\n    return () => {\n      cancelAnimationFrame(frame);\n      observer.disconnect();\n      io.disconnect();\n    };\n  }, [count, color, angle, speed, stars, reduce]);\n\n  return (\n    <canvas\n      ref={canvasRef}\n      className={`pointer-events-none absolute inset-0 block size-full ${className}`}\n      aria-hidden=\"true\"\n    />\n  );\n}\n"}]}