{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"bleed-reveal","type":"registry:ui","title":"Bleed Reveal","description":"A media card that grows from an inset, rounded frame to full-bleed as you scroll, splitting its headline apart.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/bleed-reveal.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef, type ReactNode, type RefObject } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface BleedRevealProps {\n  /** Image URL. */\n  src: string;\n  alt?: string;\n  /** Headline; its halves slide apart as the media expands. */\n  title?: string;\n  /** Content faded in once the media is full-bleed. */\n  children?: ReactNode;\n  /** Starting inset as a percent of the width. */\n  startInset?: number;\n  /** Starting corner radius in px. */\n  radius?: number;\n  /** Scroll distance to fully expand, in viewport heights. */\n  scrollLength?: number;\n  /** Element that scrolls. Defaults to the window. */\n  scrollContainerRef?: RefObject<HTMLElement | null>;\n  className?: string;\n}\n\nexport function BleedReveal({\n  src,\n  alt = \"\",\n  title = \"Into the wild\",\n  children,\n  startInset = 24,\n  radius = 32,\n  scrollLength = 1.5,\n  scrollContainerRef,\n  className,\n}: BleedRevealProps) {\n  const section = useRef<HTMLElement>(null);\n  const media = useRef<HTMLDivElement>(null);\n  const image = useRef<HTMLImageElement>(null);\n  const left = useRef<HTMLSpanElement>(null);\n  const right = useRef<HTMLSpanElement>(null);\n  const hint = useRef<HTMLDivElement>(null);\n  const reveal = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const container = scrollContainerRef?.current ?? null;\n    const target: HTMLElement | Window = container ?? window;\n    let raf = 0;\n\n    const update = () => {\n      raf = 0;\n      if (!section.current || !media.current || !image.current || !left.current || !right.current || !hint.current || !reveal.current) return; // unmounted\n      const el = section.current;\n      const vh = container ? container.clientHeight : window.innerHeight;\n      el.style.setProperty(\"--se-vh\", `${vh}px`);\n      const top = container ? container.getBoundingClientRect().top : 0;\n      const r = el.getBoundingClientRect();\n      const p = Math.min(1, Math.max(0, (top - r.top) / Math.max(1, r.height - vh)));\n      const e = 1 - Math.pow(1 - p, 3);\n      const ix = startInset * (1 - e);\n      // Corners round off faster than the inset closes, so the last stretch is a clean full-bleed.\n      const rad = radius * Math.pow(1 - p, 2);\n      media.current!.style.clipPath = `inset(${ix * 0.75}% ${ix}% round ${rad}px)`;\n      image.current!.style.transform = `scale(${1.25 - 0.25 * e})`;\n      const shift = e * r.width * 0.3;\n      left.current!.style.transform = `translateX(${-shift}px)`;\n      right.current!.style.transform = `translateX(${shift}px)`;\n      left.current!.style.opacity = right.current!.style.opacity = `${1 - Math.max(0, p - 0.6) / 0.4}`;\n      hint.current!.style.opacity = `${1 - Math.min(1, p * 8)}`;\n      reveal.current!.style.opacity = `${Math.max(0, (p - 0.8) / 0.2)}`;\n      reveal.current!.style.transform = `translateY(${(1 - Math.max(0, (p - 0.8) / 0.2)) * 16}px)`;\n    };\n    const schedule = () => {\n      if (!raf) raf = requestAnimationFrame(update);\n    };\n\n    update();\n    target.addEventListener(\"scroll\", schedule, { passive: true });\n    const ro = new ResizeObserver(schedule);\n    ro.observe(container ?? document.documentElement);\n    return () => {\n      cancelAnimationFrame(raf);\n      target.removeEventListener(\"scroll\", schedule);\n      ro.disconnect();\n    };\n  }, [scrollContainerRef, startInset, radius, scrollLength]);\n\n  const words = title.split(\" \");\n  const cut = Math.ceil(words.length / 2);\n\n  return (\n    <section\n      ref={section}\n      className={cn(\"relative w-full\", className)}\n      style={{ height: `calc(var(--se-vh, 100dvh) * ${1 + scrollLength})` }}\n    >\n      <div className=\"sticky top-0 w-full overflow-hidden\" style={{ height: \"var(--se-vh, 100dvh)\" }}>\n        <div ref={media} className=\"absolute inset-0 overflow-hidden\" style={{ willChange: \"clip-path\" }}>\n          {/* eslint-disable-next-line @next/next/no-img-element */}\n          <img ref={image} src={src} alt={alt} className=\"size-full object-cover\" style={{ willChange: \"transform\" }} />\n          <div className=\"absolute inset-0 bg-gradient-to-t from-black/60 via-black/10 to-black/20\" />\n        </div>\n        {title && (\n          <h2 className=\"pointer-events-none absolute inset-0 flex items-center justify-center gap-[0.25em] px-4 text-center text-4xl font-semibold tracking-tight text-white [text-shadow:0_2px_24px_rgb(0_0_0/0.45)] sm:text-6xl\">\n            <span ref={left} className=\"inline-block whitespace-nowrap\">\n              {words.slice(0, cut).join(\" \")}\n            </span>\n            <span ref={right} className=\"inline-block whitespace-nowrap\">\n              {words.slice(cut).join(\" \")}\n            </span>\n          </h2>\n        )}\n        <div\n          ref={hint}\n          aria-hidden\n          className=\"pointer-events-none absolute inset-x-0 bottom-4 text-center text-xs uppercase tracking-[0.25em] text-muted-foreground\"\n        >\n          Scroll to expand\n        </div>\n        <div ref={reveal} className=\"absolute inset-x-0 bottom-0 p-6 sm:p-10\" style={{ opacity: 0 }}>\n          {children}\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}