{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-morph",
  "title": "Text morph",
  "description": "Morphs between strings letter by letter: shared characters spring to their new positions while the rest blur in and out.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/text/text-morph.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { spring } from \"@/lib/goodui-motion\"\n\nexport type TextMorphProps = Omit<React.HTMLAttributes<HTMLSpanElement>, \"children\"> & {\n  /** The current string; change it to morph. Characters both strings share slide into place. */\n  text: string\n}\n\n/**\n * Morphs between strings character by character: characters both strings share slide to their new place,\n * the rest fade and blur in or out. Screen readers get the current string.\n */\nexport function TextMorph({ text, className, ...props }: TextMorphProps) {\n  const reduce = useReducedMotion() ?? false\n  const id = React.useId()\n\n  // Key each character by itself plus its occurrence (\"o-0\", \"o-1\") so shared letters keep their identity.\n  const chars = React.useMemo(() => {\n    const seen: Record<string, number> = {}\n    return Array.from(text).map((ch) => {\n      const n = (seen[ch] = (seen[ch] ?? -1) + 1)\n      return { ch, key: `${id}-${ch}-${n}` }\n    })\n  }, [text, id])\n\n  const layout = reduce ? { duration: 0 } : spring.ui\n\n  return (\n    <span className={cn(\"relative inline-flex whitespace-pre\", className)} {...props}>\n      <span className=\"sr-only\">{text}</span>\n      <span aria-hidden=\"true\" className=\"relative inline-flex\">\n        <AnimatePresence mode=\"popLayout\" initial={false}>\n          {chars.map(({ ch, key }) => (\n            <motion.span\n              key={key}\n              layout=\"position\"\n              className=\"inline-block\"\n              initial={reduce ? { opacity: 0 } : { opacity: 0, filter: \"blur(4px)\", scale: 0.9 }}\n              animate={{ opacity: 1, filter: \"blur(0px)\", scale: 1 }}\n              exit={reduce ? { opacity: 0 } : { opacity: 0, filter: \"blur(4px)\", scale: 0.9 }}\n              transition={{ layout, default: reduce ? { duration: 0 } : { duration: 0.22, ease: \"easeOut\" } }}\n            >\n              {ch === \" \" ? \" \" : ch}\n            </motion.span>\n          ))}\n        </AnimatePresence>\n      </span>\n    </span>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/text-morph.tsx"
    }
  ],
  "categories": [
    "components",
    "text"
  ],
  "type": "registry:component"
}