{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"unblur-heading","type":"registry:ui","title":"Unblur Heading","description":"Words or letters drift in from above or below, sharpening out of a heavy blur as they scroll into view.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/unblur-heading.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { Fragment, useEffect, useRef, useState, type CSSProperties } from \"react\";\n\nconst css = `\n.blur-text-piece{display:inline-block;opacity:0;white-space:pre;will-change:transform,filter,opacity}\n[data-blur-shown] .blur-text-piece{animation:blur-text-in var(--bt-d) cubic-bezier(.2,.65,.3,1) both;animation-delay:calc(var(--i) * var(--bt-s))}\n@keyframes blur-text-in{0%{opacity:0;filter:blur(14px);transform:translateY(var(--bt-y))}55%{opacity:.65;filter:blur(4px);transform:translateY(calc(var(--bt-y) * -.12))}100%{opacity:1;filter:blur(0);transform:none}}\n@media (prefers-reduced-motion:reduce){.blur-text-piece{opacity:1;animation:none!important}}\n`;\n\nexport interface UnblurHeadingProps {\n  text?: string;\n  /** Animate each word or each letter. */\n  animateBy?: \"words\" | \"letters\";\n  /** Where pieces come from. */\n  direction?: \"top\" | \"bottom\";\n  /** Delay between pieces, in ms. */\n  delay?: number;\n  /** Duration of each piece, in ms. */\n  duration?: number;\n  /** Replay every time it re-enters the viewport. */\n  once?: boolean;\n  as?: \"p\" | \"h1\" | \"h2\" | \"h3\" | \"span\" | \"div\";\n  className?: string;\n}\n\nexport function UnblurHeading({\n  text = \"Isn't this so cool?!\",\n  animateBy = \"words\",\n  direction = \"top\",\n  delay = 90,\n  duration = 900,\n  once = true,\n  as: Tag = \"p\",\n  className,\n}: UnblurHeadingProps) {\n  const ref = useRef<HTMLElement>(null);\n  const [shown, setShown] = useState(false);\n\n  useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (entry.isIntersecting) {\n          setShown(true);\n          if (once) io.disconnect();\n        } else if (!once) setShown(false);\n      },\n      { threshold: 0.2 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, [once]);\n\n  const words = text.split(\" \");\n  let i = 0;\n  const piece = (content: string, key: number) => (\n    <span key={key} className=\"blur-text-piece\" style={{ \"--i\": i++ } as CSSProperties}>\n      {content}\n    </span>\n  );\n\n  return (\n    <Tag\n      ref={ref as never}\n      className={className}\n      data-blur-shown={shown || undefined}\n      style={\n        {\n          \"--bt-d\": `${duration}ms`,\n          \"--bt-s\": `${delay}ms`,\n          \"--bt-y\": direction === \"top\" ? \"-0.7em\" : \"0.7em\",\n        } as CSSProperties\n      }\n    >\n      <style href=\"unblur-heading\" precedence=\"default\">\n        {css}\n      </style>\n      <span className=\"sr-only\">{text}</span>\n      {/* Keyed so changing the options restarts the entrance. */}\n      <span aria-hidden key={`${text}|${animateBy}|${direction}|${delay}|${duration}`}>\n        {words.map((word, w) => (\n          <Fragment key={w}>\n            <span style={{ display: \"inline-block\", whiteSpace: \"nowrap\" }}>\n              {animateBy === \"words\" ? piece(word, 0) : Array.from(word).map(piece)}\n            </span>\n            {w < words.length - 1 && \" \"}\n          </Fragment>\n        ))}\n      </span>\n    </Tag>\n  );\n}\n"}]}