{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fit-text",
  "title": "Fit text",
  "description": "Scales one line of text to fill its parent's width.",
  "registryDependencies": [
    "@khaeli/utils"
  ],
  "files": [
    {
      "path": "registry/khaeli/ui/fit-text.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/**\n * Scales its own font-size up or down until a single line of text fills the\n * inner width of its parent, and keeps it filled as that width changes. Give\n * each line of a stacked headline its own `FitText` so every line sizes\n * independently. The parent should be a block-level container sized to the\n * width the text should span (its horizontal padding is respected).\n */\nfunction FitText({ className, children, ...props }: React.ComponentProps<\"span\">) {\n  const ref = React.useRef<HTMLSpanElement>(null)\n\n  React.useEffect(() => {\n    const el = ref.current\n    const parent = el?.parentElement\n    if (!el || !parent) return\n\n    const availableWidth = () => {\n      const styles = getComputedStyle(parent)\n      return (\n        parent.clientWidth -\n        parseFloat(styles.paddingLeft || \"0\") -\n        parseFloat(styles.paddingRight || \"0\")\n      )\n    }\n\n    const fit = () => {\n      const available = availableWidth()\n      if (available <= 0) return\n      let size = parseFloat(getComputedStyle(el).fontSize) || 16\n      for (let i = 0; i < 5; i++) {\n        const width = el.getBoundingClientRect().width\n        if (width <= 0) break\n        const ratio = available / width\n        if (Math.abs(ratio - 1) < 0.002) break\n        size *= ratio\n        el.style.fontSize = `${size}px`\n      }\n    }\n\n    let frame: number | null = null\n    const schedule = () => {\n      if (frame) return\n      frame = requestAnimationFrame(() => {\n        frame = null\n        fit()\n      })\n    }\n\n    let observer: ResizeObserver | undefined\n    if (typeof ResizeObserver !== \"undefined\") {\n      observer = new ResizeObserver(schedule)\n      observer.observe(parent)\n    }\n    window.addEventListener(\"resize\", schedule)\n\n    fit()\n    if (typeof document !== \"undefined\" && document.fonts?.ready) {\n      document.fonts.ready.then(fit)\n    }\n\n    return () => {\n      if (frame) cancelAnimationFrame(frame)\n      observer?.disconnect()\n      window.removeEventListener(\"resize\", schedule)\n    }\n  }, [children])\n\n  return (\n    <span\n      ref={ref}\n      data-slot=\"fit-text\"\n      className={cn(\"inline-block whitespace-nowrap\", className)}\n      {...props}\n    >\n      {children}\n    </span>\n  )\n}\n\nexport { FitText }\n",
      "type": "registry:ui"
    }
  ],
  "docs": "Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.",
  "type": "registry:ui"
}