{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-pin-board",
  "type": "registry:component",
  "title": "Pin Board",
  "description": "A pin art board drawn on canvas: the pointer presses the pins down, they glow in the accent where pushed and rise back slowly, so every stroke leaves an imprint that fades.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "canvas",
    "pin art",
    "imprint",
    "background",
    "pointer",
    "tactile"
  ],
  "docs": "https://hyperblur.dev/effects/hover-pin-board",
  "files": [
    {
      "path": "registry/hyperblur/hover-pin-board.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hover-pin-board.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HoverPinBoardProps extends React.HTMLAttributes<HTMLDivElement> {\n  spacing?: number;\n  radius?: number;\n  recovery?: number;\n  accent?: string;\n  pinColor?: string;\n  autoPlay?: boolean;\n}\n\nconst css = `\n.hb-wg9 { position: relative; box-sizing: border-box; width: 100%; height: 100%; overflow: hidden; font-family: inherit; background: radial-gradient(120% 90% at 50% 0%, #161616 0%, #0b0b0b 70%); isolation: isolate; touch-action: pan-y; }\n.hb-wg9 *, .hb-wg9 *::before, .hb-wg9 *::after { box-sizing: border-box; }\n.hb-wg9-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }\n.hb-wg9-content { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: none; }\n.hb-wg9-content > * { pointer-events: auto; }\n`;\n\nfunction parse(hex: string) {\n  const m = hex.replace(\"#\", \"\");\n  const v = m.length === 3 ? m.split(\"\").map((c) => c + c).join(\"\") : m.padEnd(6, \"0\").slice(0, 6);\n  const n = parseInt(v, 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nexport function HoverPinBoard({\n  spacing = 13,\n  radius = 46,\n  recovery = 2.6,\n  accent = \"#2f7bff\",\n  pinColor = \"#d9d9d9\",\n  autoPlay = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: HoverPinBoardProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !canvas) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const [ar, ag, ab] = parse(accent);\n    const [pr, pg, pb] = parse(pinColor);\n    let w = 0;\n    let h = 0;\n    let cols = 0;\n    let rowsN = 0;\n    let ox = 0;\n    let oy = 0;\n    let depth = new Float32Array(0);\n    let px = -999;\n    let py = -999;\n    let lpx = -999;\n    let lpy = -999;\n    let inside = false;\n    let t = 0;\n    let raf = 0;\n    let last = performance.now();\n    let visible = true;\n    let dirty = true;\n\n    const resize = () => {\n      w = root.offsetWidth;\n      h = root.offsetHeight;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      cols = Math.max(1, Math.floor(w / spacing));\n      rowsN = Math.max(1, Math.floor(h / spacing));\n      ox = (w - (cols - 1) * spacing) / 2;\n      oy = (h - (rowsN - 1) * spacing) / 2;\n      depth = new Float32Array(cols * rowsN);\n      dirty = true;\n    };\n\n    const press = (x: number, y: number, x0: number, y0: number) => {\n      const steps = Math.max(1, Math.ceil(Math.hypot(x - x0, y - y0) / (spacing * 0.5)));\n      for (let s = 1; s <= steps; s++) {\n        const sx = x0 + ((x - x0) * s) / steps;\n        const sy = y0 + ((y - y0) * s) / steps;\n        const c0 = Math.max(0, Math.floor((sx - ox - radius) / spacing));\n        const c1 = Math.min(cols - 1, Math.ceil((sx - ox + radius) / spacing));\n        const r0 = Math.max(0, Math.floor((sy - oy - radius) / spacing));\n        const r1 = Math.min(rowsN - 1, Math.ceil((sy - oy + radius) / spacing));\n        for (let r = r0; r <= r1; r++) {\n          for (let c = c0; c <= c1; c++) {\n            const d = Math.hypot(ox + c * spacing - sx, oy + r * spacing - sy);\n            if (d >= radius) continue;\n            const f = 1 - d / radius;\n            const v = f * f * (3 - 2 * f);\n            const i = r * cols + c;\n            if (v > depth[i]) depth[i] = v;\n          }\n        }\n      }\n      dirty = true;\n    };\n\n    const draw = () => {\n      ctx.clearRect(0, 0, w, h);\n      const head = spacing * 0.3;\n      const rise = spacing * 0.22;\n      for (let r = 0; r < rowsN; r++) {\n        for (let c = 0; c < cols; c++) {\n          const v = depth[r * cols + c];\n          const x = ox + c * spacing;\n          const y = oy + r * spacing;\n          const up = 1 - v;\n          ctx.fillStyle = \"rgba(0,0,0,0.55)\";\n          ctx.beginPath();\n          ctx.arc(x + rise * up * 0.6, y + rise * up * 0.9, head * (0.9 + up * 0.25), 0, Math.PI * 2);\n          ctx.fill();\n          const lift = rise * up;\n          const hx = x - lift * 0.35;\n          const hy = y - lift;\n          const lum = 0.32 + 0.68 * up;\n          const mixA = v * 0.85;\n          const cr = Math.round((pr * lum) * (1 - mixA) + ar * mixA);\n          const cg = Math.round((pg * lum) * (1 - mixA) + ag * mixA);\n          const cb = Math.round((pb * lum) * (1 - mixA) + ab * mixA);\n          const g = ctx.createRadialGradient(hx - head * 0.35, hy - head * 0.4, head * 0.1, hx, hy, head);\n          g.addColorStop(0, `rgb(${Math.min(255, cr + 70)},${Math.min(255, cg + 70)},${Math.min(255, cb + 70)})`);\n          g.addColorStop(1, `rgb(${cr},${cg},${cb})`);\n          ctx.fillStyle = g;\n          ctx.beginPath();\n          ctx.arc(hx, hy, head, 0, Math.PI * 2);\n          ctx.fill();\n          if (v > 0.35) {\n            ctx.fillStyle = `rgba(${ar},${ag},${ab},${((v - 0.35) * 0.35).toFixed(3)})`;\n            ctx.beginPath();\n            ctx.arc(hx, hy, head * 2.1, 0, Math.PI * 2);\n            ctx.fill();\n          }\n        }\n      }\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      t += dt;\n      if (!inside && autoPlay) {\n        const ax = w * (0.5 + 0.4 * Math.sin(t * 0.9));\n        const ay = h * (0.5 + 0.3 * Math.sin(t * 1.8 + 0.6));\n        if (lpx < -900) {\n          lpx = ax;\n          lpy = ay;\n        }\n        press(ax, ay, lpx, lpy);\n        lpx = ax;\n        lpy = ay;\n      } else if (inside) {\n        press(px, py, lpx < -900 ? px : lpx, lpy < -900 ? py : lpy);\n        lpx = px;\n        lpy = py;\n      }\n      const dec = dt / Math.max(0.2, recovery);\n      let any = false;\n      for (let i = 0; i < depth.length; i++) {\n        if (depth[i] > 0) {\n          depth[i] = Math.max(0, depth[i] - dec * (0.35 + depth[i]));\n          any = true;\n        }\n      }\n      if (any || dirty) {\n        draw();\n        dirty = false;\n      }\n      raf = requestAnimationFrame(frame);\n    };\n    const start = () => {\n      if (raf || !visible) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    };\n    const stop = () => {\n      if (raf) cancelAnimationFrame(raf);\n      raf = 0;\n    };\n    const onMove = (e: PointerEvent) => {\n      const b = root.getBoundingClientRect();\n      const s = b.width ? root.offsetWidth / b.width : 1;\n      px = (e.clientX - b.left) * s;\n      py = (e.clientY - b.top) * s;\n      if (!inside) {\n        lpx = px;\n        lpy = py;\n      }\n      inside = true;\n      if (reduce) {\n        depth.fill(0);\n        press(px, py, px, py);\n        draw();\n      }\n    };\n    const onLeave = () => {\n      inside = false;\n      lpx = -999;\n      lpy = -999;\n      if (reduce) {\n        depth.fill(0);\n        draw();\n      }\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\") window.setTimeout(onLeave, 600);\n    };\n    resize();\n    draw();\n    const ro = new ResizeObserver(() => {\n      resize();\n      draw();\n    });\n    ro.observe(root);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointerup\", onUp);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible && !reduce) start();\n      else stop();\n    });\n    io.observe(root);\n    if (!reduce) start();\n    return () => {\n      stop();\n      io.disconnect();\n      ro.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointerup\", onUp);\n    };\n  }, [spacing, radius, recovery, accent, pinColor, autoPlay]);\n\n  return (\n    <div ref={rootRef} className={`hb-wg9 ${className}`} style={style} {...rest}>\n      <style href=\"hb-hover-pin-board\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-wg9-canvas\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-wg9-content\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}