{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-slats",
  "type": "registry:component",
  "title": "Slats",
  "description": "Rows of thin vertical slats that turn and catch the light in a rolling wave. A bright crest follows the pointer across them.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "slats",
    "blinds",
    "wave",
    "pointer",
    "canvas"
  ],
  "docs": "https://hyperblur.dev/effects/bg-slats",
  "files": [
    {
      "path": "registry/hyperblur/bg-slats.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-slats.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgSlatsProps extends React.HTMLAttributes<HTMLDivElement> {\n  slatWidth?: number;\n  gap?: number;\n  color?: string;\n  accent?: string;\n  amplitude?: number;\n  skew?: number;\n  radius?: number;\n  fade?: number;\n  speed?: number;\n}\n\nconst css = `\n.hb-qo2 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-qo2-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-qo2-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nexport function BgSlats({\n  slatWidth = 6,\n  gap = 4,\n  color = \"#ffffff\",\n  accent = \"#2f7bff\",\n  amplitude = 0.75,\n  skew = 12,\n  radius = 90,\n  fade = 0.22,\n  speed = 1,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: BgSlatsProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const host = wrap?.parentElement;\n    const canvas = canvasRef.current;\n    const context = canvas?.getContext(\"2d\");\n    if (!wrap || !host || !canvas || !context) return;\n    const g = context;\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n\n    const sw = Math.max(2, slatWidth);\n    const pitch = sw + Math.max(0, gap);\n    const R = Math.max(20, radius);\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let inside = false;\n    let tx = 0;\n    let ty = 0;\n    let px = 0;\n    let py = 0;\n    let hover = 0;\n    let placed = false;\n    let count = 0;\n    let start = 0;\n    let mask: CanvasGradient | null = null;\n\n    const idleX = (tt: number) => w * (0.5 + 0.42 * Math.sin(tt * 0.45 + 0.4));\n    const idleY = (tt: number) => h * (0.5 + 0.2 * Math.sin(tt * 0.7));\n\n    const track = (dt: number) => {\n      const gx = inside ? tx : idleX(t);\n      const gy = inside ? ty : idleY(t);\n      if (!placed) {\n        px = gx;\n        py = gy;\n        placed = true;\n      } else {\n        const e = 1 - Math.exp(-dt * (inside ? 8 : 2));\n        px += (gx - px) * e;\n        py += (gy - py) * e;\n      }\n      hover += ((inside ? 1 : 0) - hover) * Math.min(1, dt * 4);\n    };\n\n    const layout = () => {\n      count = Math.floor((w + gap) / pitch) + 2;\n      start = (w - (count - 1) * pitch) / 2;\n      const f = Math.min(0.49, Math.max(0, fade));\n      mask = g.createLinearGradient(0, 0, 0, h);\n      mask.addColorStop(0, \"rgba(0,0,0,0)\");\n      mask.addColorStop(f, \"rgba(0,0,0,1)\");\n      mask.addColorStop(1 - f, \"rgba(0,0,0,1)\");\n      mask.addColorStop(1, \"rgba(0,0,0,0)\");\n    };\n\n    const draw = () => {\n      if (!w || !h) return;\n      g.globalCompositeOperation = \"source-over\";\n      g.clearRect(0, 0, w, h);\n      const crest = 0.75 + 0.25 * hover;\n      const lift = 0.5 + 0.5 * Math.sin(t * 0.4);\n      const yBias = (py / h - 0.5) * 2;\n      for (let i = 0; i < count; i++) {\n        const cx = start + i * pitch;\n        const d = (cx - px) / R;\n        const c = Math.exp(-d * d) * crest;\n        const wave = Math.sin(i * 0.32 - t * 1.8) * (0.6 + 0.4 * Math.sin(t * 0.4 + i * 0.05));\n        const theta = amplitude * wave + c * 0.9 * (d < 0 ? -1 : 1) * Math.min(1, Math.abs(d) * 3);\n        const width = sw * (0.28 + 0.72 * Math.abs(Math.cos(theta)));\n        const shift = Math.sin(theta) * skew;\n        const light = 0.5 + 0.5 * Math.sin(theta * 1.6 + 0.5 + lift * 0.3);\n        const tilt = yBias * c * skew * 0.6;\n        const x0 = cx - width / 2;\n        g.beginPath();\n        g.moveTo(x0 + shift + tilt, 0);\n        g.lineTo(x0 + width + shift + tilt, 0);\n        g.lineTo(x0 + width - shift - tilt, h);\n        g.lineTo(x0 - shift - tilt, h);\n        g.closePath();\n        g.fillStyle = color;\n        g.globalAlpha = 0.04 + 0.16 * light;\n        g.fill();\n        if (c > 0.03) {\n          g.fillStyle = accent;\n          g.globalAlpha = Math.min(1, c * (0.55 + 0.45 * light));\n          g.fill();\n        }\n        g.beginPath();\n        const edge = theta > 0 ? x0 + width : x0;\n        g.moveTo(edge + shift + tilt, 0);\n        g.lineTo(edge - shift - tilt, h);\n        g.strokeStyle = c > 0.2 ? accent : color;\n        g.globalAlpha = 0.05 + 0.3 * light * (0.4 + c);\n        g.lineWidth = 1;\n        g.stroke();\n      }\n      g.globalAlpha = 1;\n      if (mask) {\n        g.globalCompositeOperation = \"destination-in\";\n        g.fillStyle = mask;\n        g.fillRect(0, 0, w, h);\n        g.globalCompositeOperation = \"source-over\";\n      }\n    };\n\n    const resize = () => {\n      const nw = wrap.clientWidth;\n      const nh = wrap.clientHeight;\n      if (!nw || !nh) return;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      w = nw;\n      h = nh;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      g.setTransform(dpr, 0, 0, dpr, 0, 0);\n      layout();\n      if (motion.matches) still();\n      else {\n        track(0);\n        draw();\n      }\n    };\n\n    let visible = true;\n    let raf = 0;\n    let prev = 0;\n\n    const still = () => {\n      t = 1.7;\n      inside = false;\n      placed = false;\n      hover = 0;\n      track(0);\n      draw();\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.033, (now - prev) / 1000);\n      prev = now;\n      t += dt * speed;\n      track(dt);\n      draw();\n      raf = requestAnimationFrame(frame);\n    };\n\n    const sync = () => {\n      const run = visible && !document.hidden && !motion.matches;\n      if (run && !raf) {\n        prev = performance.now();\n        raf = requestAnimationFrame(frame);\n      } else if (!run && raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n      if (motion.matches) still();\n    };\n\n    const move = (e: PointerEvent) => {\n      if (motion.matches) return;\n      const rect = host.getBoundingClientRect();\n      const sx = rect.width ? host.clientWidth / rect.width : 1;\n      const sy = rect.height ? host.clientHeight / rect.height : 1;\n      tx = (e.clientX - rect.left) * sx;\n      ty = (e.clientY - rect.top) * sy;\n      inside = true;\n    };\n\n    const leave = (e: PointerEvent) => {\n      if (e.type === \"pointerup\" && e.pointerType === \"mouse\") return;\n      inside = false;\n    };\n\n    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n    ro.observe(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", sync);\n    host.addEventListener(\"pointermove\", move, { passive: true });\n    host.addEventListener(\"pointerdown\", move, { passive: true });\n    host.addEventListener(\"pointerleave\", leave);\n    host.addEventListener(\"pointerup\", leave);\n    host.addEventListener(\"pointercancel\", leave);\n    resize();\n    sync();\n\n    return () => {\n      if (raf) cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", sync);\n      motion.removeEventListener(\"change\", sync);\n      host.removeEventListener(\"pointermove\", move);\n      host.removeEventListener(\"pointerdown\", move);\n      host.removeEventListener(\"pointerleave\", leave);\n      host.removeEventListener(\"pointerup\", leave);\n      host.removeEventListener(\"pointercancel\", leave);\n    };\n  }, [slatWidth, gap, color, accent, amplitude, skew, radius, fade, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-qo2 ${className}`} style={style} {...rest}>\n      <style href=\"hb-bg-slats\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qo2-c\" aria-hidden=\"true\" />\n      {children != null && <div className=\"hb-qo2-in\">{children}</div>}\n    </div>\n  );\n}\n"
    }
  ]
}