{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"comet-cursor-trail-drawn-on-one-canvas","type":"registry:block","title":"Comet Cursor Trail on Canvas","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/comet-cursor-trail-drawn-on-one-canvas.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\nconst LEN = 40; // points in the tail; longer means a longer comet\nconst WIDTH = 11; // tail thickness at the head, in px\nconst RGB = \"255,232,190\"; // tail colour\nconst dates = [\n  { d: \"Fri 7 Nov\", what: \"The Moon and Saturn\" },\n  { d: \"Sat 13 Dec\", what: \"Watching for meteors\" },\n  { d: \"Fri 9 Jan\", what: \"The Orion Nebula\" },\n];\nconst STARS = [[12, 18, 2], [33, 72, 1.6], [58, 26, 2.2], [76, 64, 1.6], [88, 14, 2], [46, 88, 1.6], [92, 82, 1.6], [22, 48, 2], [68, 44, 1.6], [4, 86, 1.6]]\n  .map(([x, y, r]) => `radial-gradient(${r}px ${r}px at ${x}% ${y}%, #fff 50%, transparent 51%)`)\n  .join(\",\");\n\nexport default function CometCursorTrailDrawnOnOneCanvas() {\n  const reduce = useReducedMotion();\n  const rootRef = useRef<HTMLElement>(null);\n  const cvRef = useRef<HTMLCanvasElement>(null);\n\n  useEffect(() => {\n    const root = rootRef.current, cv = cvRef.current;\n    if (!root || !cv || reduce || !matchMedia(\"(hover: hover) and (pointer: fine)\").matches) return;\n    const ctx = cv.getContext(\"2d\");\n    if (!ctx) return;\n    const dpr = Math.min(window.devicePixelRatio || 1, 2);\n    const pts: number[] = [];\n    let W = 0, H = 0, hx = 0, hy = 0, tx = 0, ty = 0, live = false, frame = 0, idle = 0;\n    const t0 = performance.now();\n    const size = () => { W = root.clientWidth; H = root.clientHeight; cv.width = W * dpr; cv.height = H * dpr; ctx.setTransform(dpr, 0, 0, dpr, 0, 0); };\n    const loop = (now: number) => {\n      if (!live) {\n        const t = (now - t0) / 1000;\n        tx = W * (0.55 + 0.4 * Math.cos(t * 1.1)); ty = H * (0.5 + 0.34 * Math.sin(t * 1.65));\n      }\n      hx += (tx - hx) * 0.22; hy += (ty - hy) * 0.22;\n      pts.push(hx, hy);\n      if (pts.length > LEN * 2) pts.splice(0, 2);\n      ctx.clearRect(0, 0, W, H);\n      ctx.lineCap = \"round\";\n      const n = pts.length / 2;\n      for (let i = 1; i < n; i++) {\n        const k = i / n;\n        ctx.strokeStyle = `rgba(${RGB},${k * k * 0.9})`;\n        ctx.lineWidth = WIDTH * k;\n        ctx.beginPath(); ctx.moveTo(pts[i * 2 - 2], pts[i * 2 - 1]); ctx.lineTo(pts[i * 2], pts[i * 2 + 1]); ctx.stroke();\n      }\n      const g = ctx.createRadialGradient(hx, hy, 0, hx, hy, 30);\n      g.addColorStop(0, \"rgba(255,255,255,.95)\"); g.addColorStop(0.25, `rgba(${RGB},.5)`); g.addColorStop(1, `rgba(${RGB},0)`);\n      ctx.fillStyle = g; ctx.fillRect(hx - 30, hy - 30, 60, 60);\n      frame = requestAnimationFrame(loop);\n    };\n    const start = () => { if (!frame) frame = requestAnimationFrame(loop); };\n    const stop = () => { cancelAnimationFrame(frame); frame = 0; };\n    const onMove = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\") return;\n      const r = root.getBoundingClientRect(); tx = e.clientX - r.left; ty = e.clientY - r.top;\n      live = true; clearTimeout(idle); root.removeAttribute(\"data-kb\");\n    };\n    const onLeave = () => { idle = window.setTimeout(() => { live = false; }, 1500); };\n    const onFocus = () => { if (root.querySelector(\":focus-visible\")) root.setAttribute(\"data-kb\", \"\"); };\n    const onBlur = () => root.removeAttribute(\"data-kb\");\n    size();\n    const ro = new ResizeObserver(size);\n    ro.observe(root);\n    const io = new IntersectionObserver(([e]) => (e.isIntersecting ? start() : stop()));\n    io.observe(root);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"focusin\", onFocus);\n    root.addEventListener(\"focusout\", onBlur);\n    return () => {\n      stop(); io.disconnect(); ro.disconnect(); clearTimeout(idle);\n      ctx.clearRect(0, 0, W, H);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"focusin\", onFocus);\n      root.removeEventListener(\"focusout\", onBlur);\n    };\n  }, [reduce]);\n\n  return (\n    <section ref={rootRef} className=\"w2cmt-root relative overflow-hidden px-5 py-14 text-[#eef2fb] sm:px-12 sm:py-[72px]\" style={{ background: `${STARS}, radial-gradient(90% 70% at 80% 0%, #1b2d5c 0%, transparent 70%), #0b1630` }}>\n      <style>{`\n        .w2cmt-cv { transition: opacity .4s ease; }\n        .w2cmt-root[data-kb] .w2cmt-cv { opacity: 0; }\n        @media (prefers-reduced-motion: reduce) { .w2cmt-cv { display: none; } }\n      `}</style>\n      <canvas ref={cvRef} className=\"w2cmt-cv pointer-events-none absolute inset-0 h-full w-full\" aria-hidden=\"true\" />\n      <div className=\"relative mx-auto max-w-5xl\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.22em] text-[#f2cf8a]\">Kestrel Hill Observatory</p>\n        <h2 className=\"mt-3.5 max-w-[34rem] font-serif text-[clamp(2rem,5vw,3.25rem)] font-normal leading-[1.08]\">Public nights on the hill this winter</h2>\n        <p className=\"mt-4 max-w-[30rem] leading-relaxed text-[#c9d3ea]\">Bring warm layers. Our volunteers set up the big refractor on the lawn and walk you through whatever the sky gives us.</p>\n        <ul className=\"mt-7 max-w-[26rem] border-t border-[#eef2fb]/20\">\n          {dates.map((x) => (\n            <li key={x.d} className=\"flex gap-4 border-b border-[#eef2fb]/20 py-3 text-[15px]\">\n              <span className=\"w-24 shrink-0 tabular-nums text-[#f2cf8a]\">{x.d}</span>{x.what}\n            </li>\n          ))}\n        </ul>\n        <a href=\"#\" className=\"mt-7 inline-flex min-h-[46px] items-center rounded-full bg-[#f2cf8a] px-[22px] text-sm font-bold text-[#0b1630] hover:bg-[#f7dca6] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-[#0b1630]\">Reserve a telescope slot</a>\n      </div>\n    </section>\n  );\n}\n"}]}
