{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "holo-foil",
  "type": "registry:component",
  "title": "Holo Foil",
  "description": "A holographic background: an iridescent film, a fine diffraction grating and a sheen that shift with the cursor's angle.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Backgrounds"
  ],
  "docs": "Installed in components/furin/holo-foil/. Docs, live controls and props table: https://furin.dev/components/holo-foil/",
  "files": [
    {
      "path": "registry/holo-foil/HoloFoil.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport \"./HoloFoil.css\";\n\nexport interface HoloFoilProps {\n  /** Fuerza de la iridiscencia (0 a 1.5). */\n  intensity?: number;\n  /** Densidad del patrón difractivo fino (0.5 a 3). */\n  density?: number;\n  /** Cuánto se inclina la lámina al seguir el cursor (0 a 1.5). */\n  tilt?: number;\n  /** Giro del tono general, en grados. */\n  hue?: number;\n  /** Color del metal base bajo la película. */\n  baseColor?: string;\n  /** Si no hay cursor encima, la lámina se mece sola. */\n  autoplay?: boolean;\n  /** Contenido que va encima de la lámina. */\n  children?: ReactNode;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\n/** Fondo holográfico: película iridiscente, rejilla difractiva y brillo que cambian con el ángulo del cursor. */\nexport function HoloFoil({\n  intensity = 1,\n  density = 1.4,\n  tilt = 1,\n  hue = 0,\n  baseColor = \"#0f1015\",\n  autoplay = true,\n  children,\n  className = \"\",\n  style,\n}: HoloFoilProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const opts = useRef({ tilt, autoplay });\n  opts.current = { tilt, autoplay };\n\n  useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    // Posición del \"reflejo\" (0..1) y objetivo; el cursor manda, si no hay cursor la lámina se mece sola.\n    const s = { x: 0.62, y: 0.38, tx: 0.62, ty: 0.38 };\n    let hover = false;\n    let visible = true;\n    let raf = 0;\n    let last = 0;\n    const t0 = performance.now();\n\n    const pintar = () => {\n      const k = opts.current.tilt;\n      const dx = (s.x - 0.5) * 2 * k;\n      const dy = (s.y - 0.5) * 2 * k;\n      el.style.setProperty(\"--hf-x\", `${(50 + dx * 50).toFixed(2)}%`);\n      el.style.setProperty(\"--hf-y\", `${(50 + dy * 50).toFixed(2)}%`);\n      el.style.setProperty(\"--hf-a\", `${(dx * 70 + dy * 40).toFixed(1)}deg`);\n      el.style.setProperty(\"--hf-ga\", `${(112 + dx * 16 - dy * 10).toFixed(1)}deg`);\n      el.style.setProperty(\"--hf-sx\", `${(dx * 38).toFixed(1)}%`);\n      el.style.setProperty(\"--hf-sy\", `${(dy * 38).toFixed(1)}%`);\n      el.style.setProperty(\"--hf-hue\", `${(dx * 46 - dy * 30).toFixed(1)}deg`);\n    };\n\n    const tick = (now: number) => {\n      raf = 0;\n      const dt = Math.min(0.05, (now - (last || now)) / 1000);\n      last = now;\n      if (!hover && opts.current.autoplay) {\n        const t = (now - t0) / 1000;\n        s.tx = 0.5 + 0.34 * Math.sin(t * 0.55) + 0.1 * Math.sin(t * 1.3 + 1);\n        s.ty = 0.5 + 0.3 * Math.cos(t * 0.43 + 0.6) + 0.08 * Math.sin(t * 1.1);\n      }\n      // Resorte amortiguado: la lámina tiene inercia, no salta.\n      const a = 1 - Math.exp(-dt * 6.5);\n      s.x += (s.tx - s.x) * a;\n      s.y += (s.ty - s.y) * a;\n      pintar();\n      const quieto = Math.abs(s.tx - s.x) < 0.0008 && Math.abs(s.ty - s.y) < 0.0008;\n      if (visible && !(quieto && !(opts.current.autoplay && !hover))) raf = requestAnimationFrame(tick);\n      else last = 0;\n    };\n    const wake = () => { if (!raf && visible && !reduce) raf = requestAnimationFrame(tick); };\n\n    const onMove = (e: PointerEvent) => {\n      const r = el.getBoundingClientRect();\n      s.tx = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width));\n      s.ty = Math.min(1, Math.max(0, (e.clientY - r.top) / r.height));\n      hover = true;\n      wake();\n    };\n    const onLeave = () => { hover = false; wake(); };\n    el.addEventListener(\"pointermove\", onMove);\n    el.addEventListener(\"pointerdown\", onMove);\n    el.addEventListener(\"pointerleave\", onLeave);\n    const io = new IntersectionObserver(([en]) => { visible = en.isIntersecting; if (visible) wake(); }, { threshold: 0.01 });\n    io.observe(el);\n    pintar();\n    wake();\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerdown\", onMove);\n      el.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, []);\n\n  const vars = {\n    \"--hf-int\": intensity,\n    \"--hf-den\": `${(3.6 / density).toFixed(2)}px`,\n    \"--hf-base\": baseColor,\n    \"--hf-hue0\": `${hue}deg`,\n  } as CSSProperties;\n\n  return (\n    <div ref={ref} className={`furin-holo-foil ${className}`} style={{ ...vars, ...style }}>\n      <span className=\"furin-holo-foil__metal\" aria-hidden />\n      <span className=\"furin-holo-foil__crinkle\" aria-hidden />\n      <span className=\"furin-holo-foil__film\" aria-hidden />\n      <span className=\"furin-holo-foil__film furin-holo-foil__film--b\" aria-hidden />\n      <span className=\"furin-holo-foil__grating\" aria-hidden />\n      <span className=\"furin-holo-foil__glint\" aria-hidden />\n      <span className=\"furin-holo-foil__sparkle\" aria-hidden />\n      <span className=\"furin-holo-foil__grain\" aria-hidden />\n      {children ? <div className=\"furin-holo-foil__content\">{children}</div> : null}\n    </div>\n  );\n}\n\nexport default HoloFoil;\n",
      "type": "registry:component",
      "target": "components/furin/holo-foil/HoloFoil.tsx"
    },
    {
      "path": "registry/holo-foil/HoloFoil.css",
      "content": ".furin-holo-foil {\n  --hf-x: 62%; --hf-y: 38%; --hf-a: 20deg; --hf-ga: 112deg; --hf-sx: 10%; --hf-sy: -8%; --hf-hue: 10deg;\n  /* Mapas de relieve y destellos generados una sola vez con SVG (ruido fractal + luz difusa). */\n  --hf-crinkle: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='640'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.007 0.011' numOctaves='5' seed='11'/%3E%3CfeDiffuseLighting lighting-color='%23fff' surfaceScale='14'%3E%3CfeDistantLight azimuth='215' elevation='52'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='640' height='640' filter='url(%23f)'/%3E%3C/svg%3E\");\n  --hf-crinkle-mask: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='640'%3E%3Cfilter id='g' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.006 0.009' numOctaves='4' seed='23'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9 0.9 0 0 -0.5'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='gamma' amplitude='2.6' exponent='1.7' offset='-0.2'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='640' height='640' filter='url(%23g)'/%3E%3C/svg%3E\");\n  --hf-sparkle: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='s' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 80 -58'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23s)'/%3E%3C/svg%3E\");\n  --hf-grain: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 .9 0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E\");\n  position: relative;\n  isolation: isolate;\n  overflow: hidden;\n  width: 100%;\n  height: 100%;\n  min-height: 160px;\n  background: var(--hf-base);\n  touch-action: pan-y;\n}\n.furin-holo-foil > span { position: absolute; inset: 0; pointer-events: none; }\n\n/* Metal de la lámina: bandas de reflejo de estudio que corren al inclinar. */\n.furin-holo-foil__metal {\n  background:\n    linear-gradient(var(--hf-ga),\n      color-mix(in srgb, var(--hf-base) 60%, #3a3c46) calc(var(--hf-x) - 70%),\n      color-mix(in srgb, var(--hf-base) 12%, #8a8e9c) calc(var(--hf-x) - 38%),\n      color-mix(in srgb, var(--hf-base) 80%, #1c1d24) calc(var(--hf-x) - 10%),\n      color-mix(in srgb, var(--hf-base) 15%, #7d8190) calc(var(--hf-x) + 22%),\n      color-mix(in srgb, var(--hf-base) 70%, #30323b) calc(var(--hf-x) + 60%));\n}\n.furin-holo-foil__crinkle {\n  background: var(--hf-crinkle) 0 0 / 620px 620px;\n  mix-blend-mode: overlay;\n  filter: contrast(1.15) brightness(0.9);\n  opacity: 0.7;\n}\n/* Película delgada: el tono manda (blend \"color\"), la luminancia sale del metal arrugado. */\n.furin-holo-foil__film {\n  background:\n    conic-gradient(from calc(var(--hf-a) * 1.6 + 200deg) at calc(var(--hf-x) - 85%) calc(var(--hf-y) + 95%),\n      #ff3d9a 0deg, #ff8f5a 40deg, #ffd86b 70deg, #66f2b4 120deg, #3cc3ff 170deg, #6a63ff 225deg, #c04dff 285deg, #ff3d9a 360deg);\n  filter: hue-rotate(calc(var(--hf-hue0) + var(--hf-hue))) saturate(1.05);\n  mix-blend-mode: color;\n  opacity: calc(0.78 * min(var(--hf-int), 1.2));\n}\n.furin-holo-foil__film--b {\n  background:\n    conic-gradient(from calc(var(--hf-a) * -1.9 + 40deg) at calc(var(--hf-x) + 85%) calc(var(--hf-y) - 95%),\n      #35e8d0 0deg, #4f86ff 60deg, #b24dff 125deg, #ff5aa0 190deg, #ffb86b 250deg, #86ec7a 310deg, #35e8d0 360deg);\n  filter: hue-rotate(calc(var(--hf-hue0) - var(--hf-hue) * 0.7)) saturate(1.05) blur(7px);\n  mix-blend-mode: color;\n  opacity: calc(0.62 * min(var(--hf-int), 1.2));\n  -webkit-mask-image: var(--hf-crinkle-mask);\n  mask-image: var(--hf-crinkle-mask);\n  -webkit-mask-size: 560px 560px;\n  mask-size: 560px 560px;\n}\n/* Rejilla difractiva: líneas finísimas cuyo arcoíris corre al inclinar. */\n.furin-holo-foil__grating {\n  background: linear-gradient(var(--hf-ga), #ff3d8b, #ffb347, #e5ff6a, #4dffc4, #4da6ff, #9a6bff, #ff3d8b, #ffb347, #e5ff6a, #4dffc4) calc(50% + var(--hf-sx)) calc(50% + var(--hf-sy)) / 240% 240%;\n  -webkit-mask-image: repeating-linear-gradient(var(--hf-ga), #0000 0 calc(var(--hf-den) * 0.45), #000 calc(var(--hf-den) * 0.5) calc(var(--hf-den) * 0.95), #0000 var(--hf-den));\n  mask-image: repeating-linear-gradient(var(--hf-ga), #0000 0 calc(var(--hf-den) * 0.45), #000 calc(var(--hf-den) * 0.5) calc(var(--hf-den) * 0.95), #0000 var(--hf-den));\n  mix-blend-mode: color-dodge;\n  opacity: calc(0.32 * var(--hf-int));\n  filter: hue-rotate(var(--hf-hue0));\n}\n.furin-holo-foil__glint {\n  background:\n    radial-gradient(30% 26% at var(--hf-x) var(--hf-y), rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 100%),\n    radial-gradient(80% 62% at var(--hf-x) var(--hf-y), rgba(255, 238, 225, 0.2), rgba(255, 255, 255, 0) 100%);\n  mix-blend-mode: overlay;\n  opacity: calc(0.45 + 0.4 * var(--hf-int));\n}\n/* Destellos puntuales que solo viven cerca del reflejo. */\n.furin-holo-foil__sparkle {\n  background: var(--hf-sparkle) 0 0 / 300px 300px;\n  mix-blend-mode: plus-lighter;\n  opacity: calc(0.3 * var(--hf-int));\n  -webkit-mask-image: radial-gradient(32% 28% at var(--hf-x) var(--hf-y), #000 15%, transparent 100%);\n  mask-image: radial-gradient(32% 28% at var(--hf-x) var(--hf-y), #000 15%, transparent 100%);\n}\n.furin-holo-foil__grain {\n  background: var(--hf-grain) 0 0 / 200px 200px;\n  mix-blend-mode: overlay;\n  opacity: 0.2;\n}\n.furin-holo-foil__content { position: relative; z-index: 2; width: 100%; height: 100%; display: grid; place-items: center; }\n",
      "type": "registry:file",
      "target": "components/furin/holo-foil/HoloFoil.css"
    }
  ]
}
