{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "masonry-reveal",
  "type": "registry:component",
  "title": "Masonry Reveal",
  "description": "A column masonry grid that appears piece by piece as it scrolls into view, with a soft bounce and a flash; hovering a piece zooms it in and shows its title.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Galleries"
  ],
  "docs": "Installed in components/furin/masonry-reveal/. Docs, live controls and props table: https://furin.dev/components/masonry-reveal/",
  "files": [
    {
      "path": "registry/masonry-reveal/MasonryReveal.tsx",
      "content": "\"use client\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport type { CSSProperties } from \"react\";\nimport \"./MasonryReveal.css\";\n\nexport interface MasonryItem {\n  /** Título de la pieza. */\n  title: string;\n  /** Línea secundaria bajo el título. */\n  subtitle?: string;\n  /** Alto de la pieza respecto a su ancho (1 = cuadrada). */\n  ratio?: number;\n}\n\nexport interface MasonryRevealProps {\n  /** Piezas del mosaico (si no pasas ninguna se usan siete de ejemplo). */\n  items?: MasonryItem[];\n  /** Cuántas columnas tiene el mosaico. */\n  columns?: number;\n  /** Separación entre piezas, en px. */\n  gap?: number;\n  /** Radio de las esquinas de cada pieza, en px. */\n  radius?: number;\n  /** Milisegundos entre la aparición de una pieza y la siguiente. */\n  stagger?: number;\n  /** Segundos entre reapariciones del mosaico (0 lo deja quieto). */\n  replayEvery?: number;\n  /** Cambia las escenas generadas de las piezas. */\n  seed?: number;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\n// Escenas generadas por código (sin imágenes externas): degradados, formas y grano, deterministas por semilla.\nconst PALETAS = [\n  [\"#1b1340\", \"#6a3df0\", \"#ff7ab6\", \"#ffd6a5\"],\n  [\"#06202f\", \"#0d5f7a\", \"#27c2b5\", \"#f4f1de\"],\n  [\"#2a0e0e\", \"#b3341f\", \"#ff9d4d\", \"#ffe8b8\"],\n  [\"#0e231a\", \"#2f6b4f\", \"#9ad1a0\", \"#f2f5d0\"],\n  [\"#14162e\", \"#3a46a8\", \"#7aa2ff\", \"#e8f0ff\"],\n  [\"#2d1b2e\", \"#9a3f6f\", \"#f2789f\", \"#ffe0e6\"],\n  [\"#101216\", \"#4a4f5c\", \"#c8ccd6\", \"#ffffff\"],\n  [\"#2b1a05\", \"#a8651b\", \"#f0b44c\", \"#fff3d1\"],\n];\nconst MODOS = [\"orbes\", \"arcos\", \"sol\", \"cintas\", \"bauhaus\", \"anillos\"] as const;\nconst hacerRnd = (semilla: number) => {\n  let a = (semilla * 2654435761) >>> 0;\n  return () => {\n    a = (a + 0x6d2b79f5) >>> 0;\n    let t = a;\n    t = Math.imul(t ^ (t >>> 15), t | 1);\n    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n  };\n};\nlet GRANO: HTMLCanvasElement | null = null;\nfunction grano() {\n  if (GRANO) return GRANO;\n  const c = document.createElement(\"canvas\");\n  c.width = c.height = 96;\n  const g = c.getContext(\"2d\")!;\n  const d = g.createImageData(96, 96);\n  const r = hacerRnd(99);\n  for (let i = 0; i < d.data.length; i += 4) { const v = r() * 255; d.data[i] = d.data[i + 1] = d.data[i + 2] = v; d.data[i + 3] = 255; }\n  g.putImageData(d, 0, 0);\n  return (GRANO = c);\n}\nfunction pintarEscena(cv: HTMLCanvasElement, W: number, H: number, semilla: number) {\n  const dpr = Math.min(window.devicePixelRatio || 1, 2);\n  cv.width = Math.round(W * dpr);\n  cv.height = Math.round(H * dpr);\n  const g = cv.getContext(\"2d\");\n  if (!g) return;\n  g.scale(dpr, dpr);\n  const rnd = hacerRnd(semilla + 3);\n  const pal = PALETAS[(semilla * 3 + 1) % PALETAS.length];\n  const modo = MODOS[semilla % MODOS.length];\n  const lin = (x0: number, y0: number, x1: number, y1: number, cols: string[]) => {\n    const l = g.createLinearGradient(x0, y0, x1, y1);\n    cols.forEach((c, i) => l.addColorStop(i / (cols.length - 1), c));\n    return l;\n  };\n  const M = Math.max(W, H);\n  g.fillStyle = lin(0, 0, W * 0.4, H, [pal[0], pal[1]]);\n  g.fillRect(0, 0, W, H);\n\n  if (modo === \"orbes\") {\n    g.globalCompositeOperation = \"screen\";\n    for (let i = 0; i < 4; i++) {\n      const x = W * (0.15 + rnd() * 0.7), y = H * (0.15 + rnd() * 0.7), r = M * (0.35 + rnd() * 0.4);\n      const c = pal[1 + (i % 3)];\n      const rg = g.createRadialGradient(x, y, 0, x, y, r);\n      rg.addColorStop(0, c + \"ee\"); rg.addColorStop(0.5, c + \"55\"); rg.addColorStop(1, c + \"00\");\n      g.fillStyle = rg; g.fillRect(0, 0, W, H);\n    }\n    g.globalCompositeOperation = \"source-over\";\n    const x = W * (0.3 + rnd() * 0.4), y = H * (0.3 + rnd() * 0.3), r = M * 0.1;\n    const rg = g.createRadialGradient(x - r * 0.3, y - r * 0.3, 0, x, y, r);\n    rg.addColorStop(0, \"#fff\"); rg.addColorStop(0.5, pal[3]); rg.addColorStop(1, pal[2]);\n    g.shadowColor = pal[3]; g.shadowBlur = r * 2.2; g.fillStyle = rg;\n    g.beginPath(); g.arc(x, y, r, 0, 7); g.fill(); g.shadowBlur = 0;\n  } else if (modo === \"arcos\") {\n    const cx = W * (0.4 + rnd() * 0.2), base = H * 1.02, n = 5;\n    for (let k = 0; k < n; k++) {\n      const r = (W * 0.52) * (1 - k / (n + 0.4));\n      g.shadowColor = \"rgba(0,0,0,0.35)\"; g.shadowBlur = M * 0.05; g.shadowOffsetY = M * 0.012;\n      g.fillStyle = lin(cx - r, base - r * 1.5, cx + r, base, [pal[(k + 1) % 4 === 0 ? 3 : (k + 1) % 4], pal[(k + 2) % 4]]);\n      g.beginPath(); g.moveTo(cx - r, base); g.lineTo(cx - r, base - r); g.arc(cx, base - r, r, Math.PI, 0); g.lineTo(cx + r, base); g.closePath(); g.fill();\n    }\n    g.shadowBlur = 0; g.shadowOffsetY = 0;\n  } else if (modo === \"sol\") {\n    g.fillStyle = lin(0, 0, 0, H * 0.8, [pal[0], pal[1], pal[2], pal[3]]);\n    g.fillRect(0, 0, W, H);\n    const sx = W * (0.3 + rnd() * 0.4), sy = H * 0.42, sr = M * 0.1;\n    const gl = g.createRadialGradient(sx, sy, sr * 0.3, sx, sy, sr * 6);\n    gl.addColorStop(0, pal[3] + \"dd\"); gl.addColorStop(0.3, pal[2] + \"55\"); gl.addColorStop(1, pal[2] + \"00\");\n    g.fillStyle = gl; g.fillRect(0, 0, W, H);\n    g.fillStyle = \"#fffaf0\"; g.beginPath(); g.arc(sx, sy, sr, 0, 7); g.fill();\n    for (let l = 0; l < 3; l++) {\n      const by = H * (0.6 + l * 0.14), amp = H * (0.16 - l * 0.03), ph = rnd() * 9;\n      g.fillStyle = lin(0, by - amp, 0, H, [pal[(l + 1) % 4], pal[0]]);\n      g.globalAlpha = 0.55 + l * 0.2;\n      g.beginPath(); g.moveTo(0, H);\n      for (let x = 0; x <= W; x += 3) g.lineTo(x, by - amp * (0.5 + 0.5 * (Math.sin(x / W * 5 + ph) * 0.6 + Math.sin(x / W * 11 + ph * 2) * 0.4)));\n      g.lineTo(W, H); g.fill();\n    }\n    g.globalAlpha = 1;\n  } else if (modo === \"cintas\") {\n    g.globalCompositeOperation = \"screen\";\n    for (let k = 0; k < 7; k++) {\n      const y0 = H * (0.1 + k * 0.14), a = H * (0.25 + rnd() * 0.3), th = H * (0.07 + rnd() * 0.09);\n      g.fillStyle = lin(0, y0, W, y0 + a, [pal[1 + (k % 3)] + \"cc\", pal[3] + \"55\"]);\n      g.beginPath(); g.moveTo(-10, y0);\n      g.bezierCurveTo(W * 0.3, y0 - a, W * 0.65, y0 + a, W + 10, y0 + a * 0.2);\n      g.lineTo(W + 10, y0 + a * 0.2 + th);\n      g.bezierCurveTo(W * 0.65, y0 + a + th, W * 0.3, y0 - a + th, -10, y0 + th);\n      g.closePath(); g.fill();\n    }\n    g.globalCompositeOperation = \"source-over\";\n  } else if (modo === \"bauhaus\") {\n    g.fillStyle = pal[3]; g.fillRect(0, 0, W, H);\n    g.fillStyle = pal[1]; g.beginPath(); g.arc(W * 0.34, H * 0.34, M * 0.3, 0, 7); g.fill();\n    g.fillStyle = pal[2]; g.beginPath(); g.arc(W * 0.78, H * 0.78, M * 0.26, Math.PI, 0, true); g.lineTo(W * 0.78 - M * 0.26, H * 0.78); g.fill();\n    g.fillStyle = pal[0]; g.fillRect(W * 0.52, H * 0.12, W * 0.22, H * 0.46);\n    g.fillStyle = pal[2]; g.beginPath(); g.moveTo(0, H); g.lineTo(0, H * 0.62); g.arc(0, H, H * 0.38, -Math.PI / 2, 0); g.closePath(); g.fill();\n  } else {\n    const cx = W * (0.35 + rnd() * 0.3), cy = H * (0.4 + rnd() * 0.2);\n    const rg = g.createRadialGradient(cx, cy, 0, cx, cy, M * 0.8);\n    rg.addColorStop(0, pal[2]); rg.addColorStop(0.6, pal[1]); rg.addColorStop(1, pal[0]);\n    g.fillStyle = rg; g.fillRect(0, 0, W, H);\n    for (let k = 0; k < 7; k++) {\n      const r = M * (0.1 + k * 0.1);\n      g.strokeStyle = pal[(k % 2) ? 3 : 2] + (k % 2 ? \"88\" : \"cc\");\n      g.lineWidth = M * (0.012 + 0.014 * rnd());\n      g.beginPath(); g.arc(cx, cy, r, 0, 7); g.stroke();\n    }\n    const gr = g.createRadialGradient(cx - M * 0.03, cy - M * 0.03, 0, cx, cy, M * 0.1);\n    gr.addColorStop(0, \"#fff\"); gr.addColorStop(1, pal[3]);\n    g.fillStyle = gr; g.shadowColor = pal[3]; g.shadowBlur = M * 0.12;\n    g.beginPath(); g.arc(cx, cy, M * 0.075, 0, 7); g.fill(); g.shadowBlur = 0;\n  }\n\n  // Viñeta suave y grano fino para que se sienta fotográfico.\n  const vg = g.createRadialGradient(W / 2, H / 2, M * 0.25, W / 2, H / 2, M * 0.8);\n  vg.addColorStop(0, \"rgba(0,0,0,0)\"); vg.addColorStop(1, \"rgba(0,0,0,0.34)\");\n  g.fillStyle = vg; g.fillRect(0, 0, W, H);\n  g.globalAlpha = 0.06; g.globalCompositeOperation = \"overlay\";\n  g.fillStyle = g.createPattern(grano(), \"repeat\")!;\n  g.fillRect(0, 0, W, H);\n  g.globalAlpha = 1; g.globalCompositeOperation = \"source-over\";\n}\n\nconst EJEMPLO: MasonryItem[] = [\n  { title: \"Aurora\", subtitle: \"Series 01\", ratio: 0.85 },\n  { title: \"Tide\", subtitle: \"Series 02\", ratio: 1.1 },\n  { title: \"Amber\", subtitle: \"Series 03\", ratio: 1.2 },\n  { title: \"Haze\", subtitle: \"Series 04\", ratio: 0.78 },\n  { title: \"Cobalt\", subtitle: \"Series 05\", ratio: 1.3 },\n  { title: \"Dune\", subtitle: \"Series 06\", ratio: 1.2 },\n  { title: \"Aether\", subtitle: \"Series 07\", ratio: 0.78 },\n];\n\n/** Mosaico de columnas: las piezas aparecen una por una, en orden de lectura, con un rebote suave y un destello; al pasar el cursor la pieza se acerca y muestra su título. */\nexport function MasonryReveal({\n  items,\n  columns = 3,\n  gap = 10,\n  radius = 14,\n  stagger = 95,\n  replayEvery = 0,\n  seed = 0,\n  className = \"\",\n  style,\n}: MasonryRevealProps) {\n  const lista = useMemo(() => (items && items.length > 0 ? items : EJEMPLO), [items]);\n  const cols = Math.max(1, Math.min(6, Math.round(columns)));\n  const [visible, setVisible] = useState(false);\n  const [vuelta, setVuelta] = useState(0);\n  const raiz = useRef<HTMLDivElement>(null);\n  const lienzos = useRef<(HTMLCanvasElement | null)[]>([]);\n\n  // Reparto: cada pieza va a la columna más baja (como un mosaico real) y se calcula su orden de lectura.\n  const modelo = useMemo(() => {\n    const alturas = new Array(cols).fill(0);\n    const col: number[][] = Array.from({ length: cols }, () => []);\n    const arriba: number[] = [];\n    lista.forEach((it, i) => {\n      let c = 0;\n      for (let k = 1; k < cols; k++) if (alturas[k] < alturas[c] - 1e-6) c = k;\n      col[c].push(i);\n      arriba[i] = alturas[c];\n      alturas[c] += it.ratio ?? 1;\n    });\n    const orden = lista.map((_, i) => i).sort((a, b) => arriba[a] - arriba[b] || a - b);\n    const rango: number[] = [];\n    orden.forEach((i, r) => { rango[i] = r; });\n    return { col, rango };\n  }, [lista, cols]);\n\n  useEffect(() => {\n    lista.forEach((it, i) => {\n      const c = lienzos.current[i];\n      if (c) pintarEscena(c, 320, Math.round(320 * (it.ratio ?? 1)), i + seed * 13 + 1);\n    });\n  }, [lista, seed]);\n\n  // Aparece al entrar en vista; con replayEvery se esconde y vuelve a aparecer cada cierto tiempo.\n  useEffect(() => {\n    const el = raiz.current;\n    if (!el) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) { setVisible(true); return; }\n    let timer = 0;\n    let visto = false;\n    let hecho = false;\n    const ciclo = () => {\n      window.clearTimeout(timer);\n      if (replayEvery <= 0) return;\n      timer = window.setTimeout(() => {\n        if (visto) {\n          setVisible(false);\n          timer = window.setTimeout(() => { setVuelta((v) => v + 1); setVisible(true); ciclo(); }, 750);\n        } else ciclo();\n      }, (replayEvery + (lista.length * stagger) / 1000 + 0.8) * 1000);\n    };\n    const io = new IntersectionObserver(([e]) => {\n      visto = e.isIntersecting;\n      if (e.isIntersecting && !hecho) { hecho = true; setVisible(true); ciclo(); }\n    }, { threshold: 0.2 });\n    io.observe(el);\n    return () => { io.disconnect(); window.clearTimeout(timer); };\n  }, [replayEvery, stagger, lista.length]);\n\n  const vars = { \"--furin-mr-gap\": `${gap}px`, \"--furin-mr-radius\": `${radius}px` } as CSSProperties;\n  return (\n    <div\n      ref={raiz}\n      className={`furin-masonry-reveal${visible ? \" is-in\" : \"\"} ${className}`}\n      style={{ ...vars, ...style }}\n      data-vuelta={vuelta}\n      role=\"group\"\n      aria-label=\"Image mosaic\"\n    >\n      {modelo.col.map((idx, c) => (\n        <div key={c} className=\"furin-masonry-reveal__col\">\n          {idx.map((i) => {\n            const it = lista[i];\n            return (\n              <figure\n                key={it.title + i}\n                className=\"furin-masonry-reveal__tile\"\n                style={{ aspectRatio: `1 / ${it.ratio ?? 1}`, \"--furin-mr-d\": `${modelo.rango[i] * stagger}ms` } as CSSProperties}\n                role=\"img\"\n                aria-label={`${it.title}${it.subtitle ? `, ${it.subtitle}` : \"\"}`}\n              >\n                <canvas ref={(el) => { lienzos.current[i] = el; }} className=\"furin-masonry-reveal__art\" aria-hidden=\"true\" />\n                <i className=\"furin-masonry-reveal__shine\" />\n                <figcaption className=\"furin-masonry-reveal__cap\">\n                  <b>{it.title}</b>\n                  {it.subtitle ? <span>{it.subtitle}</span> : null}\n                </figcaption>\n              </figure>\n            );\n          })}\n        </div>\n      ))}\n    </div>\n  );\n}\n\nexport default MasonryReveal;\n",
      "type": "registry:component",
      "target": "components/furin/masonry-reveal/MasonryReveal.tsx"
    },
    {
      "path": "registry/masonry-reveal/MasonryReveal.css",
      "content": ".furin-masonry-reveal {\n  --furin-mr-gap: 10px;\n  --furin-mr-radius: 14px;\n  display: flex;\n  align-items: flex-start;\n  gap: var(--furin-mr-gap);\n  width: min(460px, 94%);\n  font-family: \"Geist\", ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif;\n  color: #f3f5f8;\n}\n.furin-masonry-reveal__col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: var(--furin-mr-gap); }\n\n.furin-masonry-reveal__tile {\n  position: relative;\n  margin: 0;\n  width: 100%;\n  overflow: hidden;\n  border-radius: var(--furin-mr-radius);\n  background: #14161b;\n  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1), 0 14px 30px -14px rgba(0, 0, 0, 0.8);\n  isolation: isolate;\n  /* Estado oculto: abajo, un poco más chica y desenfocada. */\n  opacity: 0;\n  transform: translateY(30px) scale(0.9);\n  filter: blur(10px);\n  transition: opacity 0.35s ease, transform 0.45s ease, filter 0.35s ease, box-shadow 0.3s ease;\n}\n.furin-masonry-reveal.is-in .furin-masonry-reveal__tile {\n  opacity: 1;\n  transform: none;\n  filter: none;\n  transition:\n    opacity 0.55s ease var(--furin-mr-d),\n    transform 0.95s cubic-bezier(0.2, 0.95, 0.25, 1.08) var(--furin-mr-d),\n    filter 0.7s ease var(--furin-mr-d),\n    box-shadow 0.3s ease;\n}\n.furin-masonry-reveal__art {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  display: block;\n  transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n/* Destello que cruza la pieza justo al aparecer. */\n.furin-masonry-reveal__shine {\n  position: absolute;\n  inset: -20%;\n  pointer-events: none;\n  background: linear-gradient(110deg, transparent 38%, rgba(255, 255, 255, 0.34) 50%, transparent 62%);\n  transform: translateX(-120%);\n  mix-blend-mode: soft-light;\n}\n.furin-masonry-reveal.is-in .furin-masonry-reveal__shine {\n  animation: furin-masonry-reveal-shine 1.1s cubic-bezier(0.3, 0.6, 0.3, 1) both;\n  animation-delay: calc(var(--furin-mr-d) + 0.35s);\n}\n@keyframes furin-masonry-reveal-shine { from { transform: translateX(-120%); } to { transform: translateX(120%); } }\n\n.furin-masonry-reveal__cap {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  display: grid;\n  gap: 2px;\n  padding: 26px 12px 11px;\n  background: linear-gradient(180deg, transparent, rgba(5, 6, 9, 0.72));\n  opacity: 0;\n  transform: translateY(8px);\n  transition: opacity 0.3s ease, transform 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.1);\n}\n.furin-masonry-reveal__cap b { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }\n.furin-masonry-reveal__cap span { font-size: 11px; color: rgba(243, 245, 248, 0.65); letter-spacing: 0.04em; }\n.furin-masonry-reveal.is-in .furin-masonry-reveal__tile:hover { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.28), 0 22px 40px -14px rgba(0, 0, 0, 0.9); }\n.furin-masonry-reveal.is-in .furin-masonry-reveal__tile:hover .furin-masonry-reveal__art { transform: scale(1.07); }\n.furin-masonry-reveal.is-in .furin-masonry-reveal__tile:hover .furin-masonry-reveal__cap { opacity: 1; transform: none; }\n\n@media (prefers-reduced-motion: reduce) {\n  .furin-masonry-reveal__tile { opacity: 1; transform: none; filter: none; transition: none; }\n  .furin-masonry-reveal.is-in .furin-masonry-reveal__tile { transition: box-shadow 0.3s ease; }\n  .furin-masonry-reveal__shine { display: none; }\n  .furin-masonry-reveal__art, .furin-masonry-reveal__cap { transition: none; }\n}\n",
      "type": "registry:file",
      "target": "components/furin/masonry-reveal/MasonryReveal.css"
    }
  ]
}
