{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"grid-tiles-light-up-under-pointer","type":"registry:block","title":"Grid Tiles Light Up Under the Pointer","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/grid-tiles-light-up-under-pointer.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// Same markup, styles and script as the plain HTML version. The CSS comments name the values to change.\nconst STYLES = `\n  /* Change these: --w7til-size (tile size), --w7til-glow (light colour), --w7til-bg, --w7til-ink. Reach and brightness are in the script. */\n  .w7til { --w7til-size: 56px; --w7til-glow: #f2d39d; --w7til-bg: #141518; --w7til-ink: #f1ede4;\n    position: relative; height: 560px; overflow: hidden; background: var(--w7til-bg); color: var(--w7til-ink); touch-action: pan-y;\n    font-family: ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; display: flex; align-items: center; justify-content: center; }\n  .w7til-grid { position: absolute; inset: 0; pointer-events: none;\n    background-image: linear-gradient(rgba(241,237,228,.06) 1px, transparent 1px), linear-gradient(90deg, rgba(241,237,228,.06) 1px, transparent 1px);\n    background-size: var(--w7til-size) var(--w7til-size); }\n  .w7til-grid i { position: absolute; left: 0; top: 0; width: calc(var(--w7til-size) - 1px); height: calc(var(--w7til-size) - 1px); margin: 1px 0 0 1px; background: var(--w7til-glow); opacity: 0; }\n  .w7til-body { position: relative; max-width: 42rem; padding: 32px 20px; text-align: center; }\n  .w7til-eye { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; color: var(--w7til-glow); }\n  .w7til-h { margin: 14px 0 0; font-size: clamp(2.2rem, 5.8vw, 4rem); font-weight: 600; line-height: 1.04; letter-spacing: -.03em; text-shadow: 0 2px 24px rgba(20,21,24,.9); }\n  .w7til-p { margin: 18px auto 0; max-width: 30rem; font-size: 16px; line-height: 1.65; color: #cfc9bd; text-shadow: 0 1px 12px rgba(20,21,24,.95); }\n  .w7til-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 30px; }\n  .w7til-btn, .w7til-ghost { display: inline-flex; align-items: center; min-height: 48px; padding: 0 24px; border-radius: 999px; font-weight: 600; font-size: 15px; text-decoration: none; }\n  .w7til-btn { background: var(--w7til-glow); color: #1d1608; }\n  .w7til-btn:hover { background: #f8e2bb; }\n  .w7til-ghost { background: rgba(20,21,24,.7); color: var(--w7til-ink); border: 1px solid rgba(241,237,228,.3); }\n  .w7til-ghost:hover { border-color: var(--w7til-ink); }\n  .w7til-btn:focus-visible, .w7til-ghost:focus-visible { outline: 3px solid var(--w7til-ink); outline-offset: 3px; }\n`;\n\nexport default function GridTilesLightUpUnderPointer() {\n  const rootRef = useRef<any>(null);\n  const prefersReduced = useReducedMotion();\n\n  useEffect(() => {\n    const root: any = rootRef.current;\n    if (!root) return;\n    const off: Array<() => void> = [];\n    \n      var REACH = 150, MAX = .42, FADE = .05, IDLE_AFTER = 1800; // px radius of light, brightest tile, fade-out speed per frame, ms before the demo resumes\n      var reduce = matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n      var grid = root.querySelector(\".w7til-grid\"), tiles = [], cx = [], cy = [], cur = [];\n      var tx = -999, ty = -999, real = 0, raf = 0, seen = true;\n      function build() {\n        grid.textContent = \"\"; tiles = []; cx = []; cy = []; cur = [];\n        var S = parseFloat(getComputedStyle(root).getPropertyValue(\"--w7til-size\")) || 56;\n        for (var y = 0; y < root.clientHeight; y += S) for (var x = 0; x < root.clientWidth; x += S) {\n          var t = document.createElement(\"i\");\n          t.style.transform = \"translate(\" + x + \"px,\" + y + \"px)\";\n          grid.appendChild(t); tiles.push(t); cx.push(x + S / 2); cy.push(y + S / 2); cur.push(0);\n        }\n      }\n      function light(px, py, ease) {\n        for (var i = 0; i < tiles.length; i++) {\n          var d = Math.hypot(cx[i] - px, cy[i] - py), g = d < REACH ? Math.pow(1 - d / REACH, 2) * MAX : 0;\n          var n = ease ? cur[i] + (g - cur[i]) * (g > cur[i] ? .3 : FADE) : g;\n          if (Math.abs(n - cur[i]) > .003 || !ease) { cur[i] = n; tiles[i].style.opacity = n.toFixed(3); }\n        }\n      }\n      build();\n      off.push(function () { grid.textContent = \"\"; });\n      if (reduce) { light(root.clientWidth * .78, root.clientHeight * .3, false); return; }\n      function path(t) { return [root.clientWidth * (.5 + .4 * Math.sin(t * .0006)), root.clientHeight * (.5 + .34 * Math.cos(t * .0011))]; }\n      function tick(t) {\n        raf = requestAnimationFrame(tick);\n        if (!real || t - real > IDLE_AFTER) { var q = path(t); tx = q[0]; ty = q[1]; }\n        light(tx, ty, true);\n      }\n      for (var j = 40; j > 0; j--) { var q = path(performance.now() - j * 17); light(q[0], q[1], true); }\n      function aim(x, y, hold) { var b = root.getBoundingClientRect(); tx = x - b.left; ty = y - b.top; real = performance.now() + (hold || 0); }\n      function move(e) { aim(e.clientX, e.clientY); }\n      function focus(e) { var r = e.target.getBoundingClientRect(); aim(r.left + r.width / 2, r.top + r.height / 2, 4000); }\n      function leave() { real = 0; }\n      root.addEventListener(\"pointermove\", move);\n      root.addEventListener(\"pointerdown\", move);\n      root.addEventListener(\"pointerleave\", leave);\n      root.addEventListener(\"focusin\", focus);\n      var once = true, ro = new ResizeObserver(function () { if (once) once = false; else build(); });\n      ro.observe(root);\n      off.push(function () { root.removeEventListener(\"pointermove\", move); root.removeEventListener(\"pointerdown\", move); root.removeEventListener(\"pointerleave\", leave); root.removeEventListener(\"focusin\", focus); ro.disconnect(); });\n      function play() { if (!raf && seen) raf = requestAnimationFrame(tick); }\n      function stop() { cancelAnimationFrame(raf); raf = 0; }\n      var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; if (seen) play(); else stop(); });\n      io.observe(root);\n      off.push(stop, function () { io.disconnect(); });\n      play();\n    return () => off.forEach((f) => f());\n  }, [prefersReduced]);\n\n  return (\n    <section className=\"w7til\" data-w7til=\"\" ref={rootRef} aria-label=\"Fieldlight Studio lighting design\">\n      <style>{STYLES}</style>\n      <div className=\"w7til-grid\" aria-hidden=\"true\"></div>\n      <div className=\"w7til-body\">\n        <p className=\"w7til-eye\">Fieldlight Studio</p>\n        <h2 className=\"w7til-h\">Lighting for rooms that are lived in after dark</h2>\n        <p className=\"w7til-p\">We plan light the way a cabinetmaker plans joints: a lamp where you read, a low wash where you cook, and nothing glaring at the sofa.</p>\n        <div className=\"w7til-row\">\n          <a className=\"w7til-btn\" href=\"#\">Book a night visit</a>\n          <a className=\"w7til-ghost\" href=\"#\">See finished rooms</a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
