{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"chalk-dust-cursor-trail-on-a-slate-menu-board","type":"registry:block","title":"Chalk Dust Cursor Trail","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/chalk-dust-cursor-trail-on-a-slate-menu-board.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\nconst DUST = 6; // specks shed per frame of movement\nconst MAX = 500; // speck pool size\nconst RGB = \"240,237,228\"; // chalk colour\nconst menu = [\n  { dish: \"Leek and potato soup, sourdough\", price: \"7\" },\n  { dish: \"Smoked mackerel, beetroot, horseradish\", price: \"11\" },\n  { dish: \"Mushrooms on toast, thyme butter\", price: \"9\" },\n  { dish: \"Pear and almond tart, cream\", price: \"6\" },\n];\nconst hand = { fontFamily: '\"Chalkboard SE\", \"Segoe Print\", Georgia, serif' };\n\nexport default function ChalkDustCursorTrailOnASlateMenuBoard() {\n  const reduce = useReducedMotion();\n  const rootRef = useRef<HTMLElement>(null);\n  const boardRef = useRef<HTMLDivElement>(null);\n  const cvRef = useRef<HTMLCanvasElement>(null);\n\n  useEffect(() => {\n    const root = rootRef.current, board = boardRef.current, cv = cvRef.current;\n    if (!root || !board || !cv || reduce) return;\n    const ctx = cv.getContext(\"2d\");\n    if (!ctx) return;\n    const fine = matchMedia(\"(hover: hover) and (pointer: fine)\").matches;\n    const dpr = Math.min(window.devicePixelRatio || 1, 2);\n    const px = new Float32Array(MAX), py = new Float32Array(MAX), vx = new Float32Array(MAX), vy = new Float32Array(MAX), life = new Float32Array(MAX), sz = new Float32Array(MAX);\n    let W = 0, H = 0, n = 0, hx = -1, hy = -1, tx = 0, ty = 0, live = false, frame = 0, idle = 0, vis = true;\n    const t0 = performance.now();\n    const size = () => { W = board.clientWidth; H = board.clientHeight; cv.width = W * dpr; cv.height = H * dpr; ctx.setTransform(dpr, 0, 0, dpr, 0, 0); };\n    const add = (x: number, y: number, spread: number) => {\n      const i = n++ % MAX;\n      px[i] = x + (Math.random() - 0.5) * spread; py[i] = y + (Math.random() - 0.5) * spread;\n      vx[i] = (Math.random() - 0.5) * 0.5; vy[i] = Math.random() * 0.4; life[i] = 1; sz[i] = 0.6 + Math.random() * 1.8;\n    };\n    const loop = (now: number) => {\n      let alive = 0;\n      if (fine) {\n        if (!live) {\n          const t = (now - t0) / 1000;\n          tx = W * (0.66 + 0.2 * Math.sin(t * 0.7)) + 28 * Math.cos(t * 4.2);\n          ty = H * (0.5 + 0.26 * Math.sin(t * 1.1)) + 22 * Math.sin(t * 4.2);\n        }\n        if (hx < 0) { hx = tx; hy = ty; }\n        const dx = tx - hx, dy = ty - hy, d = Math.min(1, Math.hypot(dx, dy) / 6);\n        for (let k = 0; k < DUST * d; k++) { const f = Math.random(); add(hx + dx * f, hy + dy * f, 6); }\n        hx = tx; hy = ty;\n      }\n      ctx.clearRect(0, 0, W, H);\n      for (let i = 0; i < MAX; i++) {\n        if (life[i] <= 0) continue;\n        alive++;\n        vy[i] += 0.03; px[i] += vx[i]; py[i] += vy[i]; life[i] -= 0.01;\n        ctx.fillStyle = `rgba(${RGB},${life[i] * 0.8})`;\n        ctx.fillRect(px[i], py[i], sz[i], sz[i]);\n      }\n      frame = vis && (fine || alive) ? requestAnimationFrame(loop) : 0;\n    };\n    const start = () => { if (!frame && vis) frame = requestAnimationFrame(loop); };\n    const stop = () => { cancelAnimationFrame(frame); frame = 0; };\n    const at = (e: PointerEvent) => { const r = board.getBoundingClientRect(); tx = e.clientX - r.left; ty = e.clientY - r.top; };\n    // Touch: each tap knocks a small puff of dust off the board.\n    const onTap = (e: PointerEvent) => { at(e); for (let k = 0; k < 40; k++) add(tx, ty, 18); start(); };\n    const onMove = (e: PointerEvent) => { if (e.pointerType !== \"touch\") { at(e); live = true; clearTimeout(idle); root.removeAttribute(\"data-kb\"); } };\n    const onLeave = () => { idle = window.setTimeout(() => { live = false; hx = -1; }, 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(board);\n    const io = new IntersectionObserver(([e]) => { vis = e.isIntersecting; if (vis && fine) start(); else stop(); });\n    io.observe(root);\n    if (fine) {\n      board.addEventListener(\"pointermove\", onMove);\n      board.addEventListener(\"pointerleave\", onLeave);\n      root.addEventListener(\"focusin\", onFocus);\n      root.addEventListener(\"focusout\", onBlur);\n    } else board.addEventListener(\"pointerdown\", onTap);\n    return () => {\n      stop(); io.disconnect(); ro.disconnect(); clearTimeout(idle);\n      board.removeEventListener(\"pointermove\", onMove);\n      board.removeEventListener(\"pointerleave\", onLeave);\n      board.removeEventListener(\"pointerdown\", onTap);\n      root.removeEventListener(\"focusin\", onFocus);\n      root.removeEventListener(\"focusout\", onBlur);\n    };\n  }, [reduce]);\n\n  return (\n    <section ref={rootRef} className=\"w2chk-root bg-[#d9cfbf] px-4 py-10 sm:px-10 sm:py-14\">\n      <style>{`\n        .w2chk-cv { transition: opacity .4s ease; }\n        .w2chk-root[data-kb] .w2chk-cv { opacity: 0; }\n        @media (prefers-reduced-motion: reduce) { .w2chk-cv { display: none; } }\n      `}</style>\n      <div\n        ref={boardRef}\n        className=\"relative mx-auto max-w-[60rem] overflow-hidden rounded-md border-[12px] border-[#7b5a3c] text-[#f0ede4] shadow-[inset_0_0_0_1px_rgba(0,0,0,.35),inset_0_0_60px_rgba(0,0,0,.45),0_24px_50px_-24px_rgba(40,28,16,.6)]\"\n        style={{ background: \"radial-gradient(40% 30% at 70% 30%, rgba(255,255,255,.06), transparent 70%), radial-gradient(30% 25% at 20% 80%, rgba(255,255,255,.05), transparent 70%), #2c3633\" }}\n      >\n        <canvas ref={cvRef} className=\"w2chk-cv pointer-events-none absolute inset-0 h-full w-full\" aria-hidden=\"true\" />\n        <div className=\"relative px-6 pb-10 pt-9 sm:px-14 sm:pb-[52px] sm:pt-12\">\n          <p className=\"text-xs uppercase tracking-[0.24em] text-[#cfd8d2]\">Corner Table, Mill Street</p>\n          <h2 className=\"mt-3 text-[clamp(2rem,5vw,3.2rem)] font-normal italic leading-[1.1] [text-shadow:0_0_1px_rgba(240,237,228,.6)]\" style={hand}>On the board today</h2>\n          <ul className=\"mt-6 max-w-lg\">\n            {menu.map((m) => (\n              <li key={m.dish} className=\"flex items-baseline justify-between gap-4 border-b border-dashed border-[#f0ede4]/30 py-2.5 text-[17px]\" style={hand}>\n                <span>{m.dish}</span>\n                <b className=\"text-xl font-normal\">{m.price}</b>\n              </li>\n            ))}\n          </ul>\n          <a href=\"#\" className=\"mt-7 inline-flex min-h-[44px] items-center rounded border-2 border-[#f0ede4] px-5 text-sm font-semibold hover:bg-[#f0ede4]/10 focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-[#f2c94c] focus-visible:ring-offset-2 focus-visible:ring-offset-[#2c3633]\">Book a table for lunch</a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
