{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"letters-cut-from-light-with-moving-rays","type":"registry:block","title":"Letters Cut From Light With Moving Rays","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/letters-cut-from-light-with-moving-rays.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\nconst WORD = \"VESPER\";\nconst LIGHT = [\"#fff1d6\", \"#ffc77d\"]; // top and bottom of the lit letters\nconst RAYS = 26; // copies stacked to build the light shafts; fewer is cheaper\nconst DRIFT = 0.00022; // how fast the light source wanders behind the wall\n\nexport default function LettersCutFromLightWithMovingRays() {\n  const box = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const reduce = useReducedMotion();\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    const host = box.current;\n    if (!canvas || !host) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n    const mask = document.createElement(\"canvas\");\n    const m = mask.getContext(\"2d\");\n    const rays = document.createElement(\"canvas\");\n    const r4 = rays.getContext(\"2d\");\n    if (!m || !r4) return;\n\n    let w = 0;\n    let h = 0;\n    let frame = 0;\n    let visible = true;\n    const start = performance.now();\n\n    const build = () => {\n      const r = host.getBoundingClientRect();\n      w = Math.max(1, r.width);\n      h = Math.max(1, r.height);\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      canvas.width = Math.round(w * dpr);\n      canvas.height = Math.round(h * dpr);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      mask.width = Math.round(w);\n      mask.height = Math.round(h);\n      rays.width = Math.max(1, Math.round(w / 3));\n      rays.height = Math.max(1, Math.round(h / 3));\n      let fs = h * 0.62;\n      const font = (s: number) => `800 ${s}px ui-sans-serif, system-ui, \"Helvetica Neue\", Arial, sans-serif`;\n      m.font = font(fs);\n      const spacing = fs * 0.08;\n      const tw = m.measureText(WORD).width + spacing * (WORD.length - 1);\n      if (tw > w * 0.84) fs *= (w * 0.84) / tw;\n      m.font = font(fs);\n      const sp = fs * 0.08;\n      const total = m.measureText(WORD).width + sp * (WORD.length - 1);\n      const g = m.createLinearGradient(0, h * 0.5 - fs * 0.4, 0, h * 0.5 + fs * 0.4);\n      g.addColorStop(0, LIGHT[0]);\n      g.addColorStop(1, LIGHT[1]);\n      m.clearRect(0, 0, mask.width, mask.height);\n      m.fillStyle = g;\n      m.textBaseline = \"middle\";\n      let x = (w - total) / 2;\n      for (const ch of WORD) {\n        m.fillText(ch, x, h * 0.52);\n        x += m.measureText(ch).width + sp;\n      }\n    };\n\n    const draw = (now: number) => {\n      const t = now - start;\n      const lx = w / 2 + Math.cos(t * DRIFT) * w * 0.28;\n      const ly = h * 0.42 + Math.sin(t * DRIFT * 1.7) * h * 0.22;\n      const dpr = canvas.width / w;\n      const q = rays.width / w;\n      r4.setTransform(1, 0, 0, 1, 0, 0);\n      r4.clearRect(0, 0, rays.width, rays.height);\n      r4.globalCompositeOperation = \"lighter\";\n      for (let i = RAYS; i >= 1; i -= 1) {\n        const s = 1 + i * 0.032;\n        r4.globalAlpha = 0.1 * (1 - i / (RAYS + 1));\n        r4.setTransform(q * s, 0, 0, q * s, q * lx * (1 - s), q * ly * (1 - s));\n        r4.drawImage(mask, 0, 0, w, h);\n      }\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, w, h);\n      ctx.globalCompositeOperation = \"source-over\";\n      ctx.imageSmoothingEnabled = true;\n      ctx.filter = \"blur(5px)\";\n      ctx.drawImage(rays, 0, 0, w, h);\n      ctx.filter = \"none\";\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.globalCompositeOperation = \"source-over\";\n      ctx.globalAlpha = 1;\n      ctx.shadowColor = \"rgba(255, 190, 110, 0.65)\";\n      ctx.shadowBlur = 24;\n      ctx.drawImage(mask, 0, 0, w, h);\n      ctx.shadowBlur = 0;\n    };\n\n    const loop = (now: number) => {\n      draw(now);\n      frame = requestAnimationFrame(loop);\n    };\n    const play = () => {\n      if (!frame && visible && !reduce) frame = requestAnimationFrame(loop);\n    };\n    const stop = () => {\n      cancelAnimationFrame(frame);\n      frame = 0;\n    };\n\n    build();\n    if (reduce) draw(start + 1200);\n    else play();\n    const ro = new ResizeObserver(() => {\n      build();\n      if (reduce) draw(start + 1200);\n    });\n    ro.observe(host);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) play();\n      else stop();\n    });\n    io.observe(host);\n    return () => {\n      stop();\n      ro.disconnect();\n      io.disconnect();\n    };\n  }, [reduce]);\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#0d1016] px-5 py-16 sm:px-10 sm:py-20\">\n      <style>{`\n        .w10lcut-canvas { -webkit-mask-image: linear-gradient(to right, transparent, #000 7%, #000 93%, transparent), linear-gradient(to bottom, transparent, #000 16%, #000 84%, transparent); -webkit-mask-composite: source-in; mask-image: linear-gradient(to right, transparent, #000 7%, #000 93%, transparent), linear-gradient(to bottom, transparent, #000 16%, #000 84%, transparent); mask-composite: intersect; }\n        @media (prefers-reduced-motion: reduce) { .w10lcut-canvas { will-change: auto; } }\n      `}</style>\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 bg-[radial-gradient(70%_60%_at_50%_35%,#1b2130_0%,#0d1016_70%)]\" />\n      <div className=\"relative mx-auto max-w-5xl text-center\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.34em] text-[#b8b2a6]\">St. Aldric&apos;s chapel · evening series</p>\n        <h1 className=\"sr-only\">Vesper</h1>\n        <div ref={box} className=\"relative mx-auto mt-2 h-[170px] w-full sm:h-[260px] lg:h-[300px]\">\n          <canvas ref={canvasRef} aria-hidden=\"true\" className=\"w10lcut-canvas absolute inset-0 h-full w-full\" />\n        </div>\n        <p className=\"mx-auto mt-2 max-w-lg text-base leading-relaxed text-[#cfc8bb] sm:text-lg\">\n          Candlelit chamber music under the old timber roof, every Thursday at eight from October to March.\n        </p>\n        <a\n          href=\"#\"\n          className=\"mt-8 inline-flex h-12 items-center rounded-full border border-[#ffc77d]/70 px-7 text-sm font-semibold text-[#ffe2b3] transition hover:bg-[#ffc77d] hover:text-[#0d1016] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#ffc77d] focus-visible:ring-offset-2 focus-visible:ring-offset-[#0d1016]\"\n        >\n          See the season\n        </a>\n      </div>\n    </section>\n  );\n}\n"}]}
