{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "lens-cursor",
  "type": "registry:component",
  "title": "Lens Cursor",
  "description": "A glass magnifier that enlarges whatever is underneath it.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Cursors"
  ],
  "docs": "Installed in components/furin/lens-cursor/. Docs, live controls and props table: https://furin.dev/components/lens-cursor/",
  "files": [
    {
      "path": "registry/lens-cursor/LensCursor.tsx",
      "content": "\"use client\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport \"./LensCursor.css\";\n\n/* ---------- Refracción real (solo Chromium): mapa de desplazamiento generado en canvas ---------- */\n\n/** Solo Chromium acepta url(#filtro) dentro de backdrop-filter; el resto cae al desenfoque simple. */\nfunction canRefract(): boolean {\n  if (typeof CSS === \"undefined\" || typeof navigator === \"undefined\") return false;\n  return /Chrome\\//.test(navigator.userAgent) && CSS.supports(\"backdrop-filter\", \"url(#a)\");\n}\n\ninterface RefractionMap { url: string; scale: number; w: number; h: number }\n\n/** Mapa de desplazamiento: en el bisel la luz se curva hacia adentro y, con zoom > 1, el centro también amplía. */\nfunction buildRefractionMap(w: number, h: number, radius: number, bezel: number, zoom = 1): RefractionMap | null {\n  if (w < 4 || h < 4) return null;\n  const c = document.createElement(\"canvas\");\n  c.width = w;\n  c.height = h;\n  const ctx = c.getContext(\"2d\");\n  if (!ctx) return null;\n  const img = ctx.createImageData(w, h);\n  const vx = new Float32Array(w * h);\n  const vy = new Float32Array(w * h);\n  const hw = w / 2, hh = h / 2, r = Math.min(radius, hw, hh);\n  const k = 1 - 1 / zoom;\n  let max = 0.001;\n  for (let y = 0; y < h; y++) {\n    for (let x = 0; x < w; x++) {\n      const px = x + 0.5 - hw, py = y + 0.5 - hh;\n      const qx = Math.abs(px) - (hw - r), qy = Math.abs(py) - (hh - r);\n      const sdf = Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) + Math.min(Math.max(qx, qy), 0) - r;\n      if (sdf > 0) continue;\n      let nx: number, ny: number;\n      if (qx > 0 && qy > 0) { const l = Math.hypot(qx, qy) || 1; nx = (Math.sign(px) * qx) / l; ny = (Math.sign(py) * qy) / l; }\n      else if (qx > qy) { nx = Math.sign(px); ny = 0; }\n      else { nx = 0; ny = Math.sign(py); }\n      const t = Math.min(1, -sdf / bezel);\n      const m = Math.pow(1 - t, 2.2) * bezel;\n      const dx = -nx * m - px * k, dy = -ny * m - py * k;\n      const i = y * w + x;\n      vx[i] = dx;\n      vy[i] = dy;\n      max = Math.max(max, Math.abs(dx), Math.abs(dy));\n    }\n  }\n  const d = img.data;\n  for (let i = 0; i < w * h; i++) {\n    d[i * 4] = Math.round(127.5 + (127.5 * vx[i]) / max);\n    d[i * 4 + 1] = Math.round(127.5 + (127.5 * vy[i]) / max);\n    d[i * 4 + 2] = 128;\n    d[i * 4 + 3] = 255;\n  }\n  ctx.putImageData(img, 0, 0);\n  return { url: c.toDataURL(\"image/png\"), scale: max * 2, w, h };\n}\n\n/** Mide el elemento y mantiene su mapa de refracción al día (solo si el navegador lo soporta). */\nfunction useRefractionMap(ref: React.RefObject<HTMLElement | null>, radius: number, bezel: number, zoom = 1): RefractionMap | null {\n  const [mapa, setMapa] = useState<RefractionMap | null>(null);\n  useEffect(() => {\n    if (!canRefract()) return;\n    const el = ref.current;\n    if (!el) return;\n    let raf = 0;\n    const run = () => {\n      const m = buildRefractionMap(el.offsetWidth, el.offsetHeight, radius, bezel, zoom);\n      if (m) setMapa((p) => (p && p.w === m.w && p.h === m.h ? p : m));\n    };\n    const ro = new ResizeObserver(() => { cancelAnimationFrame(raf); raf = requestAnimationFrame(run); });\n    ro.observe(el);\n    run();\n    return () => { ro.disconnect(); cancelAnimationFrame(raf); };\n  }, [ref, radius, bezel, zoom]);\n  return mapa;\n}\n\n/** Filtro SVG: desenfoque, desplazamiento por el mapa y saturación; con dispersión separa los canales RGB como un cristal real. */\nfunction RefractionFilter({ id, mapa, strength, blur = 0, saturate = 1.6, dispersion = 0 }: { id: string; mapa: RefractionMap; strength: number; blur?: number; saturate?: number; dispersion?: number }) {\n  const s = mapa.scale * strength;\n  const disp = (scale: number, result: string) => (\n    <feDisplacementMap in=\"src\" in2=\"mapa\" scale={scale} xChannelSelector=\"R\" yChannelSelector=\"G\" result={result} />\n  );\n  return (\n    <svg width=\"0\" height=\"0\" style={{ position: \"absolute\" }} aria-hidden=\"true\" focusable=\"false\">\n      <filter id={id} x=\"0\" y=\"0\" width={mapa.w} height={mapa.h} filterUnits=\"userSpaceOnUse\" colorInterpolationFilters=\"sRGB\">\n        <feImage href={mapa.url} x=\"0\" y=\"0\" width={mapa.w} height={mapa.h} preserveAspectRatio=\"none\" result=\"mapa\" />\n        <feGaussianBlur in=\"SourceGraphic\" stdDeviation={Math.max(blur, 0.01)} result=\"src\" />\n        {dispersion > 0 ? (\n          <>\n            {disp(s * (1 + dispersion), \"dr\")}\n            <feColorMatrix in=\"dr\" type=\"matrix\" values=\"1 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 1 0\" result=\"r\" />\n            {disp(s, \"dg\")}\n            <feColorMatrix in=\"dg\" type=\"matrix\" values=\"0 0 0 0 0  0 1 0 0 0  0 0 0 0 0  0 0 0 1 0\" result=\"g\" />\n            {disp(s * (1 - dispersion), \"db\")}\n            <feColorMatrix in=\"db\" type=\"matrix\" values=\"0 0 0 0 0  0 0 0 0 0  0 0 1 0 0  0 0 0 1 0\" result=\"b\" />\n            <feBlend in=\"r\" in2=\"g\" mode=\"screen\" result=\"rg\" />\n            <feBlend in=\"rg\" in2=\"b\" mode=\"screen\" result=\"rgb\" />\n          </>\n        ) : (\n          disp(s, \"rgb\")\n        )}\n        <feColorMatrix in=\"rgb\" type=\"saturate\" values={String(saturate)} />\n      </filter>\n    </svg>\n  );\n}\n\n/** Valor de backdrop-filter: el filtro SVG si hay refracción; desenfoque + saturación si no. */\nfunction glassBackdrop(id: string, mapa: RefractionMap | null, blur: number, saturate = 1.6): string {\n  return mapa ? `url(#${id})` : `blur(${blur}px) saturate(${saturate}) brightness(1.06)`;\n}\n\n\nexport interface LensCursorProps {\n  /** Contenido que la lupa amplía (se muestra dos veces: el real y el de la lente). */\n  children?: ReactNode;\n  /** Cuánto amplía la lupa. */\n  zoom?: number;\n  /** Diámetro de la lupa, en px. */\n  size?: number;\n  /** Fuerza de la refracción en el borde de la lente (0 = sin curvar la luz). */\n  refraction?: number;\n  /** Rigidez del resorte con el que la lupa persigue al cursor. */\n  stiffness?: number;\n  /** Oculta el cursor del sistema dentro del área. */\n  hideCursor?: boolean;\n  /** Pinta una lámina con texto diminuto y formas de color para ver la ampliación. */\n  scene?: boolean;\n  /** Texto de la lámina (con `scene`): se repite hasta llenarla. */\n  sceneText?: string;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nconst MICRO =\n  \"Glass is not a material so much as a state: a liquid that stopped flowing. Passing through it, light bends, and what seemed far away comes closer. A lens is just glass with curvature, and the curvature decides how close the world gets. This magnifier chases the cursor on a spring, enlarges what lies beneath with real text, never pixelating it, and bends light at its rim like true crystal.\";\n\nfunction Mundo({ scene, text, children }: { scene: boolean; text: string; children?: ReactNode }) {\n  return (\n    <div className=\"furin-lens-cursor__mundo-contenido\">\n      {scene ? (\n        <>\n          <div className=\"furin-lens-cursor__rejilla\" />\n          <div className=\"furin-lens-cursor__formas\"><i /><i /><i /><i /></div>\n          <div className=\"furin-lens-cursor__micro\">{(text.trimEnd() + \" \").repeat(14)}</div>\n        </>\n      ) : null}\n      <div className=\"furin-lens-cursor__titulo\">{children}</div>\n    </div>\n  );\n}\n\n/** Lupa de vidrio que persigue al cursor con un resorte y amplía el contenido de debajo con texto real y borde refractante. */\nexport function LensCursor({\n  children,\n  zoom = 2.2,\n  size = 176,\n  refraction = 1,\n  stiffness = 420,\n  hideCursor = true,\n  scene = false,\n  sceneText = MICRO,\n  className = \"\",\n  style,\n}: LensCursorProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const lente = useRef<HTMLDivElement>(null);\n  const dentro = useRef<HTMLDivElement>(null);\n  const cristal = useRef<HTMLSpanElement>(null);\n  const fid = \"furin-lens-cursor-\" + useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const mapa = useRefractionMap(cristal, size / 2, size * 0.14);\n  const [caja, setCaja] = useState({ w: 0, h: 0 });\n\n  // El mundo de la lente debe medir lo mismo que el área real para que la ampliación caiga exacta.\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const ro = new ResizeObserver(() => setCaja({ w: el.offsetWidth, h: el.offsetHeight }));\n    ro.observe(el);\n    setCaja({ w: el.offsetWidth, h: el.offsetHeight });\n    return () => ro.disconnect();\n  }, []);\n\n  useEffect(() => {\n    const el = root.current, len = lente.current, int = dentro.current;\n    if (!el || !len || !int) return;\n    const quieto = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const R = size / 2;\n    const s = { x: 0, y: 0, vx: 0, vy: 0, k: 0, vk: 0, tx: 0, ty: 0, dentro: false, init: false };\n    let raf = 0, t0 = 0;\n    const pinta = () => {\n      len.style.transform = `translate(${(s.x - R).toFixed(2)}px, ${(s.y - R).toFixed(2)}px) scale(${Math.max(s.k, 0.001).toFixed(3)})`;\n      len.style.opacity = String(Math.min(1, s.k * 1.6));\n      int.style.transform = `translate(${(R - s.x * zoom).toFixed(2)}px, ${(R - s.y * zoom).toFixed(2)}px) scale(${zoom})`;\n    };\n    const tick = (t: number) => {\n      const dt = Math.min(0.032, (t - t0) / 1000 || 0.016);\n      t0 = t;\n      const c = 2 * Math.sqrt(stiffness) * 0.85;\n      for (let i = 0; i < 2; i++) {\n        s.vx += (stiffness * (s.tx - s.x) - c * s.vx) * (dt / 2);\n        s.vy += (stiffness * (s.ty - s.y) - c * s.vy) * (dt / 2);\n        s.x += s.vx * (dt / 2);\n        s.y += s.vy * (dt / 2);\n        const ko = s.dentro ? 1 : 0;\n        s.vk += (260 * (ko - s.k) - 19 * s.vk) * (dt / 2);\n        s.k += s.vk * (dt / 2);\n      }\n      pinta();\n      const ko = s.dentro ? 1 : 0;\n      const quietoYa = Math.abs(s.tx - s.x) + Math.abs(s.ty - s.y) < 0.15 && Math.abs(s.vx) + Math.abs(s.vy) < 0.5 && Math.abs(ko - s.k) < 0.004 && Math.abs(s.vk) < 0.02;\n      if (quietoYa && !s.dentro) { s.k = 0; pinta(); raf = 0; return; }\n      raf = quietoYa ? 0 : requestAnimationFrame(tick);\n    };\n    const wake = () => { if (!raf) { t0 = performance.now(); raf = requestAnimationFrame(tick); } };\n    const aim = (e: PointerEvent) => {\n      const b = el.getBoundingClientRect();\n      s.tx = e.clientX - b.left;\n      s.ty = e.clientY - b.top;\n      if (!s.init || !s.dentro) { s.x = s.tx; s.y = s.ty; s.vx = s.vy = 0; s.init = true; }\n      s.dentro = true;\n      if (quieto) { s.x = s.tx; s.y = s.ty; s.k = 1; pinta(); } else wake();\n    };\n    const out = () => { s.dentro = false; if (quieto) { s.k = 0; pinta(); } else wake(); };\n    el.addEventListener(\"pointermove\", aim);\n    el.addEventListener(\"pointerdown\", aim);\n    el.addEventListener(\"pointerleave\", out);\n    el.addEventListener(\"pointercancel\", out);\n    pinta();\n    return () => {\n      el.removeEventListener(\"pointermove\", aim);\n      el.removeEventListener(\"pointerdown\", aim);\n      el.removeEventListener(\"pointerleave\", out);\n      el.removeEventListener(\"pointercancel\", out);\n      cancelAnimationFrame(raf);\n    };\n  }, [size, zoom, stiffness]);\n\n  const vars = { \"--furin-lens-cursor-size\": `${size}px` } as CSSProperties;\n  const back = glassBackdrop(fid, mapa, 0.3, 1.3);\n  return (\n    <div ref={root} className={`furin-lens-cursor${hideCursor ? \" is-sin-cursor\" : \"\"} ${className}`} style={{ ...vars, ...style }}>\n      {mapa ? <RefractionFilter id={fid} mapa={mapa} strength={refraction} blur={0.3} saturate={1.3} dispersion={0.05} /> : null}\n      <Mundo scene={scene} text={sceneText}>{children}</Mundo>\n      <div ref={lente} className=\"furin-lens-cursor__lente\" aria-hidden=\"true\">\n        <div ref={dentro} className=\"furin-lens-cursor__mundo\" style={{ width: caja.w, height: caja.h }} {...({ inert: true } as object)}>\n          <Mundo scene={scene} text={sceneText}>{children}</Mundo>\n        </div>\n        <span ref={cristal} className=\"furin-lens-cursor__cristal\" style={{ backdropFilter: back, WebkitBackdropFilter: back }} />\n        <span className=\"furin-lens-cursor__brillo\" />\n        <span className=\"furin-lens-cursor__rim\" />\n      </div>\n    </div>\n  );\n}\n\nexport default LensCursor;\n",
      "type": "registry:component",
      "target": "components/furin/lens-cursor/LensCursor.tsx"
    },
    {
      "path": "registry/lens-cursor/LensCursor.css",
      "content": ".furin-lens-cursor {\n  position: relative;\n  width: 100%;\n  height: 100%;\n  overflow: hidden;\n  font-family: Geist, system-ui, -apple-system, sans-serif;\n  color: #fff;\n  touch-action: none;\n}\n.furin-lens-cursor.is-sin-cursor { cursor: none; }\n.furin-lens-cursor__mundo-contenido {\n  position: absolute;\n  inset: 0;\n  display: grid;\n  place-items: center;\n  overflow: hidden;\n  background: linear-gradient(155deg, #10163a 0%, #1c1046 55%, #0b2638 100%);\n}\n.furin-lens-cursor__rejilla {\n  position: absolute;\n  inset: 0;\n  background-image: linear-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px);\n  background-size: 14px 14px;\n}\n.furin-lens-cursor__formas i { position: absolute; border-radius: 50%; }\n.furin-lens-cursor__formas i:nth-child(1) { width: 150px; height: 150px; left: 4%; top: 8%; background: radial-gradient(circle at 32% 28%, #ffd0ea, #ff5aa5 45%, #c21f78); }\n.furin-lens-cursor__formas i:nth-child(2) { width: 190px; height: 190px; right: 2%; bottom: -8%; background: radial-gradient(circle at 34% 30%, #bcd3ff, #4f7dff 45%, #2437c9); }\n.furin-lens-cursor__formas i:nth-child(3) { width: 90px; height: 90px; right: 24%; top: 6%; background: radial-gradient(circle at 34% 30%, #fff2cc, #ffb347 50%, #e6700f); }\n.furin-lens-cursor__formas i:nth-child(4) { width: 70px; height: 70px; left: 26%; bottom: 6%; background: radial-gradient(circle at 34% 30%, #d3fff3, #37e0b9 45%, #0a8e86); }\n.furin-lens-cursor__micro {\n  position: absolute;\n  inset: 0;\n  padding: 10px 12px;\n  column-count: 4;\n  column-gap: 12px;\n  overflow: hidden;\n  font-size: 7px;\n  line-height: 1.5;\n  font-weight: 500;\n  text-align: justify;\n  color: rgba(255, 255, 255, 0.55);\n  user-select: none;\n}\n.furin-lens-cursor__titulo {\n  position: relative;\n  padding: 10px 18px;\n  border-radius: 16px;\n  font-size: 34px;\n  font-weight: 700;\n  letter-spacing: -0.03em;\n  line-height: 1.05;\n  text-align: center;\n  text-shadow: 0 2px 18px rgba(5, 8, 40, 0.75), 0 0 2px rgba(5, 8, 40, 0.6);\n  background: rgba(10, 14, 50, 0.28);\n}\n.furin-lens-cursor__titulo:empty { display: none; }\n.furin-lens-cursor__lente {\n  position: absolute;\n  left: 0;\n  top: 0;\n  width: var(--furin-lens-cursor-size);\n  height: var(--furin-lens-cursor-size);\n  border-radius: 50%;\n  overflow: hidden;\n  opacity: 0;\n  transform: translate(-999px, -999px) scale(0.001);\n  pointer-events: none;\n  /* La sombra va en otra capa porque el overflow la recortaría: ver __rim. */\n}\n.furin-lens-cursor__mundo { position: absolute; left: 0; top: 0; transform-origin: 0 0; }\n.furin-lens-cursor__cristal {\n  position: absolute;\n  inset: 0;\n  border-radius: 50%;\n  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0) 55%, rgba(255, 255, 255, 0.1) 100%);\n  box-shadow: inset 0 -14px 22px -10px rgba(255, 255, 255, 0.28), inset 0 12px 18px -12px rgba(255, 255, 255, 0.4), inset 0 0 26px rgba(10, 14, 60, 0.28);\n}\n.furin-lens-cursor__brillo {\n  position: absolute;\n  inset: 0;\n  border-radius: 50%;\n  background:\n    radial-gradient(ellipse 34% 20% at 30% 18%, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 100%),\n    radial-gradient(ellipse 30% 14% at 74% 88%, rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0) 100%);\n}\n.furin-lens-cursor__rim {\n  position: absolute;\n  inset: 0;\n  border-radius: 50%;\n  padding: 2px;\n  background: conic-gradient(from 210deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.15) 20%, rgba(255, 255, 255, 0.05) 45%, rgba(255, 255, 255, 0.65) 75%, rgba(255, 255, 255, 0.95));\n  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);\n  -webkit-mask-composite: xor;\n  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);\n}\n",
      "type": "registry:file",
      "target": "components/furin/lens-cursor/LensCursor.css"
    }
  ]
}
