{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "typing-text",
  "type": "registry:ui",
  "title": "Typing Text",
  "description": "Text typed character by character with a blinking caret.",
  "dependencies": [
    "motion",
    "lucide-react"
  ],
  "files": [
    {
      "path": "components/prequelui/motion.tsx",
      "type": "registry:lib",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport {\n  MotionConfig,\n  useInView as useMotionInView,\n  type Transition,\n} from \"motion/react\";\nimport { useHydratedReducedMotion } from \"@/lib/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\nconst TempoContext = React.createContext(1);\n\nexport function PrequelMotionProvider({\n  tempo = 1,\n  children,\n}: {\n  tempo?: number;\n  children: React.ReactNode;\n}) {\n  const value = React.useMemo(() => Math.max(0.4, tempo), [tempo]);\n  return (\n    <TempoContext.Provider value={value}>\n      <MotionConfig reducedMotion=\"user\">{children}</MotionConfig>\n    </TempoContext.Provider>\n  );\n}\n\nexport function useTempo() {\n  return React.useContext(TempoContext);\n}\n\nconst TIME_KEYS = [\n  \"duration\",\n  \"visualDuration\",\n  \"delay\",\n  \"repeatDelay\",\n  \"delayChildren\",\n] as const;\n\nfunction scaleValue(transition: Transition, tempo: number): Transition {\n  if (tempo === 1 || !transition || typeof transition !== \"object\") {\n    return transition;\n  }\n  const next: Record<string, unknown> = {};\n  for (const [key, value] of Object.entries(transition)) {\n    if (typeof value === \"number\" && (TIME_KEYS as readonly string[]).includes(key)) {\n      next[key] = value * tempo;\n    } else if (typeof value === \"number\" && key === \"stiffness\") {\n      next[key] = value / (tempo * tempo);\n    } else if (typeof value === \"number\" && key === \"damping\") {\n      next[key] = value / tempo;\n    } else if (value && typeof value === \"object\" && !Array.isArray(value)) {\n      next[key] = scaleValue(value as Transition, tempo);\n    } else {\n      next[key] = value;\n    }\n  }\n  return next as Transition;\n}\n\nexport function useTempoTransition(transition: Transition) {\n  const tempo = useTempo();\n  return React.useMemo(\n    () => scaleValue(transition, tempo),\n    [tempo, JSON.stringify(transition)],\n  );\n}\n\nexport function useReduceMotion() {\n  return useHydratedReducedMotion();\n}\n\nexport function usePageVisible() {\n  const [visible, setVisible] = React.useState(true);\n  React.useEffect(() => {\n    const update = () => setVisible(!document.hidden);\n    update();\n    document.addEventListener(\"visibilitychange\", update);\n    return () => document.removeEventListener(\"visibilitychange\", update);\n  }, []);\n  return visible;\n}\n\nexport function useMounted() {\n  return React.useSyncExternalStore(\n    () => () => {},\n    () => true,\n    () => false,\n  );\n}\n\nexport function useSeen(\n  ref: React.RefObject<Element | null>,\n  enabled = true,\n  once = true,\n) {\n  const inView = useMotionInView(ref, { once, amount: 0.35 });\n  return enabled ? inView : true;\n}\n\ntype SlotProps = React.HTMLAttributes<HTMLElement> & {\n  children?: React.ReactNode;\n  ref?: React.Ref<HTMLElement>;\n};\n\nexport function Slot({ children, ...props }: SlotProps) {\n  if (!React.isValidElement<Record<string, unknown>>(children)) {\n    return null;\n  }\n  const child = children as React.ReactElement<Record<string, unknown>>;\n  const childProps = child.props;\n  return React.cloneElement(child, {\n    ...props,\n    ...childProps,\n    className: cn(\n      String(props.className ?? \"\"),\n      String(childProps.className ?? \"\"),\n    ),\n    style: {\n      ...((props.style as React.CSSProperties) ?? {}),\n      ...((childProps.style as React.CSSProperties) ?? {}),\n    },\n  } as Record<string, unknown>);\n}\n\nexport function srOnlyStyle(): React.CSSProperties {\n  return {\n    position: \"absolute\",\n    width: 1,\n    height: 1,\n    padding: 0,\n    margin: -1,\n    overflow: \"hidden\",\n    clip: \"rect(0, 0, 0, 0)\",\n    whiteSpace: \"nowrap\",\n    borderWidth: 0,\n  };\n}\n\nlet segmenter: Intl.Segmenter | null | undefined;\n\nexport function splitGraphemes(text: string): string[] {\n  if (segmenter === undefined) {\n    segmenter =\n      typeof Intl !== \"undefined\" && typeof Intl.Segmenter === \"function\"\n        ? new Intl.Segmenter(undefined, { granularity: \"grapheme\" })\n        : null;\n  }\n  if (!segmenter) return Array.from(text);\n  return Array.from(segmenter.segment(text), (entry) => entry.segment);\n}\n\nexport const easeOut = [0.23, 1, 0.32, 1] as const;\nexport const easeSoft = [0.215, 0.61, 0.355, 1] as const;\nexport const easeInOut = [0.77, 0, 0.175, 1] as const;\nexport const easeEnter = [0.25, 0.1, 0.35, 1] as const;\nexport const easeLeave = [0, 0, 0.58, 1] as const;\nexport const easeResize = [0.4, 0, 0.1, 1] as const;\nexport const easeAway = [0.33, 0.17, 0.67, 0.5] as const;\n\nexport const pressSpring: Transition = {\n  type: \"spring\",\n  stiffness: 550,\n  damping: 30,\n  restSpeed: 10,\n};\n\nexport const selectionSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 30,\n};\n\nexport const highlightSpring: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 40,\n};\n\nexport const popSpring: Transition = {\n  type: \"spring\",\n  stiffness: 400,\n  damping: 29,\n};\n\nexport const tooltipSpring: Transition = {\n  type: \"spring\",\n  stiffness: 400,\n  damping: 31,\n};\n\nexport const dialogSpring: Transition = {\n  type: \"spring\",\n  stiffness: 150,\n  damping: 25,\n};\n\nexport const toastSpring: Transition = {\n  type: \"spring\",\n  stiffness: 280,\n  damping: 24,\n};\n\nexport const heightSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 30,\n  bounce: 0,\n  restDelta: 0.01,\n};\n\nexport const progressSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 35,\n  restDelta: 0.01,\n  restSpeed: 0.1,\n};\n\nexport const scrollSpring: Transition = {\n  type: \"spring\",\n  stiffness: 250,\n  damping: 40,\n  bounce: 0,\n};\n\nexport const avatarSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 17,\n};\n\nexport const pinnedSpring: Transition = {\n  type: \"spring\",\n  stiffness: 320,\n  damping: 25,\n  mass: 0.8,\n};\n\nexport const thumbSpring: Transition = {\n  type: \"spring\",\n  stiffness: 300,\n  damping: 25,\n};\n\nexport const checkSpring: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 24,\n};\n\nexport const cursorEntry: Transition = {\n  type: \"spring\",\n  stiffness: 550,\n  damping: 30,\n  restSpeed: 10,\n};\n\nexport const cursorExit: Transition = {\n  type: \"spring\",\n  stiffness: 550,\n  damping: 46.9,\n  restSpeed: 10,\n};\n\nexport const cursorLabel: Transition = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 50,\n  bounce: 0,\n};\n\nexport const swapTween: Transition = {\n  duration: 0.15,\n  ease: easeOut,\n};\n\nexport const overlayTween: Transition = {\n  duration: 0.4,\n  ease: easeSoft,\n};\n\nexport const disclosureTween: Transition = {\n  duration: 0.35,\n  ease: easeSoft,\n};\n\nexport const menuTween: Transition = {\n  duration: 0.22,\n  ease: easeSoft,\n};\n\nexport const panelOutTween: Transition = {\n  duration: 0.15,\n  ease: easeLeave,\n};\n\nexport const panelInTween: Transition = {\n  duration: 0.3,\n  ease: easeEnter,\n};\n\nexport const panelHeightTween: Transition = {\n  duration: 0.45,\n  ease: easeResize,\n};\n\nexport const exitTween: Transition = {\n  duration: 0.2,\n  ease: easeAway,\n};\n\nexport const faceSpring: Transition = {\n  type: \"spring\",\n  stiffness: 280,\n  damping: 20,\n};\n\nexport const blurIcon = \"blur(2px)\";\n\nexport function flipTransform(side: \"top\" | \"bottom\" | \"left\" | \"right\") {\n  const rotate =\n    side === \"top\"\n      ? \"rotateX(-20deg)\"\n      : side === \"bottom\"\n        ? \"rotateX(20deg)\"\n        : side === \"left\"\n          ? \"rotateY(20deg)\"\n          : \"rotateY(-20deg)\";\n  return `perspective(500px) ${rotate} scale(0.8)`;\n}\n\nexport function uprightTransform(side: \"top\" | \"bottom\" | \"left\" | \"right\") {\n  const rotate = side === \"left\" || side === \"right\" ? \"rotateY(0deg)\" : \"rotateX(0deg)\";\n  return `perspective(500px) ${rotate} scale(1)`;\n}\n",
      "target": "components/prequelui/motion.tsx"
    },
    {
      "path": "components/prequelui/typing-text.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useInView, type HTMLMotionProps } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\nimport {\n  splitGraphemes,\n  srOnlyStyle,\n  usePageVisible,\n  useReduceMotion,\n  useSeen,\n} from \"./motion\";\n\ntype Phase = \"typing\" | \"holding\" | \"erasing\" | \"done\";\ntype Cursor = { index: number; count: number; phase: Phase };\ntype TypingContextValue = { typing: boolean; canBlink: boolean };\n\nconst TypingContext = React.createContext<TypingContextValue | null>(null);\n\nexport type TypingTextProps = React.ComponentProps<\"span\"> & {\n  text: string | string[];\n  duration?: number;\n  delay?: number;\n  holdDelay?: number;\n  loop?: boolean;\n  inView?: boolean;\n  inViewOnce?: boolean;\n};\n\nexport function TypingText({\n  text,\n  duration = 100,\n  delay = 0,\n  holdDelay = 1000,\n  loop = false,\n  inView = false,\n  inViewOnce = true,\n  className,\n  children,\n  ...props\n}: TypingTextProps) {\n  const reduce = useReduceMotion();\n  const pageVisible = usePageVisible();\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const seen = useSeen(ref, inView, inViewOnce);\n  const onScreen = useInView(ref, { initial: true });\n\n  const texts = React.useMemo(() => (Array.isArray(text) ? text : [text]), [text]);\n  const segments = React.useMemo(() => texts.map(splitGraphemes), [texts]);\n  const [cursor, setCursor] = React.useState<Cursor>({\n    index: 0,\n    count: 0,\n    phase: \"typing\",\n  });\n  const [ready, setReady] = React.useState(delay === 0);\n\n  React.useEffect(() => {\n    setCursor({ index: 0, count: 0, phase: \"typing\" });\n    setReady(delay === 0);\n  }, [delay, segments]);\n\n  React.useEffect(() => {\n    if (ready) return;\n    if (inView && !seen) return;\n    const timer = setTimeout(() => setReady(true), delay);\n    return () => clearTimeout(timer);\n  }, [delay, inView, ready, seen]);\n\n  React.useEffect(() => {\n    if (reduce) {\n      const index = loop ? 0 : segments.length - 1;\n      const count = segments[index]?.length ?? 0;\n      setCursor((current) =>\n        current.index === index &&\n        current.count === count &&\n        current.phase === \"done\"\n          ? current\n          : { index, count, phase: \"done\" },\n      );\n      return;\n    }\n    if (!ready) return;\n    if (inView && !seen) return;\n    if (!pageVisible || (loop && !onScreen)) return;\n    if (cursor.phase === \"done\") return;\n\n    const length = segments[cursor.index]?.length ?? 0;\n    const isLast = cursor.index === segments.length - 1;\n    let timer: ReturnType<typeof setTimeout>;\n\n    if (cursor.phase === \"typing\") {\n      if (cursor.count < length) {\n        timer = setTimeout(\n          () =>\n            setCursor((current) => ({\n              ...current,\n              count: Math.min(current.count + 1, length),\n            })),\n          duration,\n        );\n      } else if (isLast && !loop) {\n        setCursor((current) => ({ ...current, phase: \"done\" }));\n      } else {\n        timer = setTimeout(\n          () => setCursor((current) => ({ ...current, phase: \"holding\" })),\n          holdDelay,\n        );\n      }\n    } else if (cursor.phase === \"holding\") {\n      timer = setTimeout(\n        () => setCursor((current) => ({ ...current, phase: \"erasing\" })),\n        Math.max(60, duration),\n      );\n    } else if (cursor.phase === \"erasing\") {\n      if (cursor.count > 0) {\n        timer = setTimeout(\n          () =>\n            setCursor((current) => ({\n              ...current,\n              count: Math.max(0, current.count - 1),\n            })),\n          Math.max(40, duration * 0.55),\n        );\n      } else {\n        timer = setTimeout(\n          () =>\n            setCursor({\n              index: isLast ? 0 : cursor.index + 1,\n              count: 0,\n              phase: \"typing\",\n            }),\n          Math.max(120, duration),\n        );\n      }\n    }\n\n    return () => clearTimeout(timer);\n  }, [cursor, duration, holdDelay, inView, loop, onScreen, pageVisible, ready, reduce, seen, segments]);\n\n  const typing =\n    !reduce && cursor.phase === \"typing\" && cursor.count > 0 && cursor.count < (segments[cursor.index]?.length ?? 0);\n  const value = React.useMemo(\n    () => ({ typing, canBlink: !reduce && pageVisible && onScreen && cursor.phase !== \"done\" }),\n    [cursor.phase, onScreen, pageVisible, reduce, typing],\n  );\n  const srText = texts.join(\", \");\n  const current = segments[cursor.index] ?? [];\n  const visible = current.slice(0, cursor.count).join(\"\");\n\n  return (\n    <TypingContext.Provider value={value}>\n      <span\n        ref={ref}\n        data-slot=\"typing-text\"\n        className={cn(\"inline\", className)}\n        {...props}\n      >\n        <span className=\"sr-only\" style={srOnlyStyle()}>\n          {srText}\n        </span>\n        <span aria-hidden=\"true\">{visible}</span>\n        {children}\n      </span>\n    </TypingContext.Provider>\n  );\n}\n\nexport type TypingTextCursorProps = Omit<HTMLMotionProps<\"span\">, \"children\">;\n\nexport function TypingTextCursor({ className, style, ...props }: TypingTextCursorProps) {\n  const context = React.useContext(TypingContext);\n  const typing = context?.typing ?? false;\n  const canBlink = context?.canBlink ?? true;\n\n  return (\n    <motion.span\n      data-slot=\"typing-text-cursor\"\n      aria-hidden=\"true\"\n      animate={typing || !canBlink ? { opacity: 1 } : { opacity: [1, 1, 0, 0] }}\n      transition={\n        typing || !canBlink\n          ? { duration: 0.1 }\n          : { duration: 1, repeat: Infinity, ease: \"linear\", times: [0, 0.5, 0.5, 1] }\n      }\n      className={cn(\n        \"ml-0.5 inline-block h-[1.05em] w-[2px] translate-y-[0.12em] bg-foreground\",\n        className,\n      )}\n      style={style}\n      {...props}\n    />\n  );\n}\n\nexport function useTypingText() {\n  return React.useContext(TypingContext);\n}\n",
      "target": "components/prequelui/typing-text.tsx"
    },
    {
      "path": "lib/use-reduced-motion.ts",
      "target": "lib/use-reduced-motion.ts",
      "type": "registry:lib",
      "content": "\"use client\";\n\nimport { useReducedMotion } from \"motion/react\";\nimport { useSyncExternalStore } from \"react\";\n\nconst subscribe = () => () => {};\n\nexport function useHydratedReducedMotion() {\n  const reduce = useReducedMotion() ?? false;\n  const mounted = useSyncExternalStore(\n    subscribe,\n    () => true,\n    () => false,\n  );\n  return mounted ? reduce : false;\n}\n"
    }
  ]
}
