{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-split-lines",
  "title": "useSplitLines",
  "description": "Measures how text wraps into lines so each line can animate on its own.",
  "files": [
    {
      "path": "registry/khaeli/hooks/use-split-lines.ts",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nexport type SplitLine = string[]\n\n/**\n * Splits an element's text into visual lines by measuring word wrap — the same\n * job GSAP's SplitText does, minus the dependency. Render `words` into a hidden\n * measuring node (attach `measureRef`); once measured, `lines` holds the words\n * grouped by the row they wrapped onto. Re-measures when the container resizes\n * and after web fonts finish loading. Returns `lines: null` until the first\n * client-side measurement so callers can guard against a flash of split content.\n */\nexport function useSplitLines(text: string): {\n  measureRef: React.RefObject<HTMLElement | null>\n  words: string[]\n  lines: SplitLine[] | null\n} {\n  const measureRef = React.useRef<HTMLElement | null>(null)\n\n  const words = React.useMemo(\n    () => text.split(/\\s+/).filter((word) => word.length > 0),\n    [text]\n  )\n\n  const [lines, setLines] = React.useState<SplitLine[] | null>(null)\n\n  React.useEffect(() => {\n    const node = measureRef.current\n    if (!node) return\n\n    const measure = () => {\n      const children = Array.from(node.children) as HTMLElement[]\n      if (children.length === 0) {\n        setLines([])\n        return\n      }\n\n      const grouped: SplitLine[] = []\n      let current: string[] = []\n      let lastTop: number | null = null\n\n      children.forEach((child, index) => {\n        const word = words[index]\n        if (word === undefined) return\n        const top = child.offsetTop\n        if (lastTop === null || Math.abs(top - lastTop) < 1) {\n          current.push(word)\n        } else {\n          grouped.push(current)\n          current = [word]\n        }\n        lastTop = top\n      })\n      if (current.length > 0) grouped.push(current)\n\n      setLines((prev) => (linesEqual(prev, grouped) ? prev : grouped))\n    }\n\n    measure()\n\n    let observer: ResizeObserver | undefined\n    if (typeof ResizeObserver !== \"undefined\") {\n      observer = new ResizeObserver(() => measure())\n      if (node.parentElement) observer.observe(node.parentElement)\n    }\n\n    let cancelled = false\n    if (typeof document !== \"undefined\" && document.fonts?.ready) {\n      document.fonts.ready.then(() => {\n        if (!cancelled) measure()\n      })\n    }\n\n    return () => {\n      cancelled = true\n      observer?.disconnect()\n    }\n  }, [words])\n\n  return { measureRef, words, lines }\n}\n\nfunction linesEqual(a: SplitLine[] | null, b: SplitLine[]): boolean {\n  if (!a || a.length !== b.length) return false\n  return a.every((line, i) => {\n    const other = b[i]\n    if (other === undefined) return false\n    return line.length === other.length && line.every((w, j) => w === other[j])\n  })\n}\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}