{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "blur-text",
  "title": "Blur Text",
  "description": "Text that comes into focus one character at a time, and can blur back out.",
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/use-entrance"
  ],
  "files": [
    {
      "path": "registry/default/ui/blur-text.tsx",
      "content": "\"use client\";\n\nimport {\n  Fragment,\n  useMemo,\n  type AnimationEvent,\n  type ComponentProps,\n  type CSSProperties,\n  type Ref,\n} from \"react\";\n\nimport { useEntrance, type EntranceTrigger } from \"@/registry/default/hooks/use-entrance\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\nfunction mergeRefs<T>(...refs: (Ref<T> | undefined)[]) {\n  return (node: T | null) => {\n    for (const ref of refs) {\n      if (typeof ref === \"function\") ref(node);\n      else if (ref) ref.current = node;\n    }\n  };\n}\n\n/** Splits into user-perceived characters, so emoji and accents stay whole. */\nfunction graphemes(text: string) {\n  if (typeof Intl !== \"undefined\" && \"Segmenter\" in Intl) {\n    const segmenter = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\n    return Array.from(segmenter.segment(text), ({ segment }) => segment);\n  }\n  return Array.from(text);\n}\n\ntype BlurTextTag = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\" | \"p\" | \"span\" | \"div\";\n\ninterface BlurTextProps extends Omit<ComponentProps<\"p\">, \"children\" | \"onAnimationEnd\"> {\n  /** Plain text; every character comes in on its own. */\n  children: string;\n  as?: BlurTextTag;\n  /** \"load\" plays on first paint with CSS alone; \"in-view\" when the text scrolls into view. */\n  trigger?: EntranceTrigger;\n  /** In-view: play the first time only. */\n  once?: boolean;\n  /** Takes over from `trigger`: `false` holds the text hidden, `true` plays it. */\n  play?: boolean;\n  /** `false` blurs the text back out, last character first. */\n  show?: boolean;\n  /** Wait before the first character, in ms. */\n  delay?: number;\n  /** Time between characters, in ms. */\n  stagger?: number;\n  /** How long each character takes, in ms. */\n  duration?: number;\n  /** Called when the last character has come in, or gone out. */\n  onAnimationComplete?: () => void;\n}\n\n/**\n * Text that comes into focus one character at a time: each one rises a\n * little out of a blur. Screen readers get the sentence in one piece, and\n * with `prefers-reduced-motion` it is shown as is. Words never break\n * between characters.\n *\n * @example\n * <BlurText as=\"h1\" className=\"text-5xl\">Land ho.</BlurText>\n */\nfunction BlurText({\n  children,\n  as: Tag = \"p\",\n  trigger = \"load\",\n  once = true,\n  play,\n  show = true,\n  delay = 0,\n  stagger = 20,\n  duration = 600,\n  onAnimationComplete,\n  className,\n  ref,\n  ...props\n}: BlurTextProps) {\n  const [observe, phase] = useEntrance<HTMLElement>({ trigger, once, play });\n  const mergedRef = useMemo(() => mergeRefs(ref, observe), [ref, observe]);\n\n  const words = useMemo(() => {\n    let next = 0;\n    return children\n      .trim()\n      .split(/\\s+/)\n      .filter(Boolean)\n      .map((word) => graphemes(word).map((character) => ({ character, index: next++ })));\n  }, [children]);\n  const count = words.reduce((sum, word) => sum + word.length, 0);\n\n  const piece = ({ character, index }: { character: string; index: number }) => {\n    // Out goes in reverse, so the text folds away from where it ended.\n    const order = show ? index : count - 1 - index;\n    const style: CSSProperties =\n      phase === \"static\" && show\n        ? {}\n        : {\n            animationDelay: `${(show ? delay : 0) + order * stagger}ms`,\n            animationDuration: `${show ? duration : duration * 0.7}ms`,\n            animationPlayState: phase === \"armed\" && show ? \"paused\" : undefined,\n          };\n    return (\n      <span\n        key={index}\n        data-slot=\"blur-text-character\"\n        // The character that finishes last: the end coming in, the start going out.\n        data-last={index === (show ? count - 1 : 0) ? \"\" : undefined}\n        className={cn(\n          \"inline-block\",\n          !show && \"motion-safe:animate-blur-text-out motion-reduce:opacity-0\",\n          show && phase !== \"static\" && \"motion-safe:animate-blur-text\"\n        )}\n        style={style}\n      >\n        {character}\n      </span>\n    );\n  };\n\n  const handleAnimationEnd = (event: AnimationEvent<HTMLElement>) => {\n    const target = event.target as HTMLElement;\n    if (target.dataset.last !== undefined) onAnimationComplete?.();\n  };\n\n  return (\n    <Tag\n      ref={mergedRef as Ref<never>}\n      data-slot=\"blur-text\"\n      data-state={show ? phase : \"hidden\"}\n      aria-hidden={show ? undefined : true}\n      className={className}\n      onAnimationEnd={handleAnimationEnd}\n      {...props}\n    >\n      <span className=\"sr-only\">{children}</span>\n      <span aria-hidden=\"true\">\n        {words.map((word, wordIndex) => (\n          <Fragment key={wordIndex}>\n            {wordIndex > 0 ? \" \" : null}\n            <span className=\"inline-block whitespace-nowrap\">{word.map(piece)}</span>\n          </Fragment>\n        ))}\n      </span>\n    </Tag>\n  );\n}\n\nexport { BlurText, type BlurTextProps };\n",
      "type": "registry:ui"
    }
  ],
  "tailwind": {
    "config": {
      "theme": {
        "extend": {
          "keyframes": {
            "blur-text": {
              "from": {
                "opacity": "0",
                "filter": "blur(10px)",
                "transform": "translate3d(0, 0.3em, 0)"
              }
            },
            "blur-text-out": {
              "to": {
                "opacity": "0",
                "filter": "blur(10px)",
                "transform": "translate3d(0, 0.3em, 0)"
              }
            }
          },
          "animation": {
            "blur-text": "blur-text 600ms cubic-bezier(0.22, 1, 0.36, 1) both",
            "blur-text-out": "blur-text-out 420ms cubic-bezier(0.55, 0, 1, 0.45) both"
          }
        }
      }
    }
  },
  "cssVars": {
    "theme": {
      "animate-blur-text": "blur-text 600ms cubic-bezier(0.22, 1, 0.36, 1) both",
      "animate-blur-text-out": "blur-text-out 420ms cubic-bezier(0.55, 0, 1, 0.45) both"
    }
  },
  "css": {
    "@keyframes blur-text": {
      "from": {
        "opacity": "0",
        "filter": "blur(10px)",
        "transform": "translate3d(0, 0.3em, 0)"
      }
    },
    "@keyframes blur-text-out": {
      "to": {
        "opacity": "0",
        "filter": "blur(10px)",
        "transform": "translate3d(0, 0.3em, 0)"
      }
    }
  },
  "categories": [
    "text"
  ],
  "type": "registry:ui"
}