{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-underline-draw",
  "type": "registry:component",
  "title": "Text Underline Draw",
  "description": "A wavy or straight underline that draws itself under the text on hover, focus or when it scrolls into view.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "text",
    "underline",
    "link",
    "wavy",
    "hover",
    "draw"
  ],
  "docs": "https://hyperblur.dev/effects/text-underline-draw",
  "files": [
    {
      "path": "registry/hyperblur/text-underline-draw.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-underline-draw.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextUnderlineDrawProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text: string;\n  variant?: \"wavy\" | \"straight\";\n  trigger?: \"hover\" | \"view\";\n  color?: string;\n  thickness?: number;\n  duration?: number;\n  autoplay?: boolean;\n  once?: boolean;\n}\n\nconst wave =\n  \"url(\\\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 6' preserveAspectRatio='none'%3E%3Cpath d='M0 3Q4 0.2 8 3T16 3' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E\\\")\";\n\nconst css = `\n@keyframes hb-qd7-flow {\n  from { -webkit-mask-position: 0 0; mask-position: 0 0; }\n  to { -webkit-mask-position: calc(var(--hb-qd7-tile) * -1) 0; mask-position: calc(var(--hb-qd7-tile) * -1) 0; }\n}\n.hb-qd7 {\n  position: relative;\n  display: inline-block;\n  padding-bottom: calc(var(--hb-qd7-h) * 0.55);\n  font-family: inherit;\n  box-sizing: border-box;\n  cursor: default;\n}\n.hb-qd7-l {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  height: var(--hb-qd7-h);\n  background: var(--hb-qd7-c);\n  clip-path: inset(0 100% 0 0);\n  transition: clip-path var(--hb-qd7-dur) cubic-bezier(.65, 0, .25, 1);\n  pointer-events: none;\n}\n.hb-qd7[data-v=\"wavy\"] .hb-qd7-l {\n  -webkit-mask-image: ${wave};\n  mask-image: ${wave};\n  -webkit-mask-repeat: repeat-x;\n  mask-repeat: repeat-x;\n  -webkit-mask-size: var(--hb-qd7-tile) 100%;\n  mask-size: var(--hb-qd7-tile) 100%;\n  animation: hb-qd7-flow 1.1s linear infinite;\n}\n.hb-qd7[data-v=\"straight\"] .hb-qd7-l { border-radius: 999px; }\n.hb-qd7[data-on] .hb-qd7-l { clip-path: inset(0 0 0 0); }\n.hb-qd7[data-t=\"hover\"]:hover .hb-qd7-l,\n.hb-qd7[data-t=\"hover\"]:focus-visible .hb-qd7-l { clip-path: inset(0 0 0 0); }\n.hb-qd7:focus-visible { outline: 2px solid var(--hb-qd7-c); outline-offset: 4px; border-radius: 4px; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qd7-l { transition: none; animation: none !important; }\n}\n`;\n\nexport function TextUnderlineDraw({\n  text,\n  variant = \"wavy\",\n  trigger = \"hover\",\n  color = \"#7fb3ff\",\n  thickness = 3,\n  duration = 0.7,\n  autoplay = true,\n  once = true,\n  className = \"\",\n  style,\n  ...rest\n}: TextUnderlineDrawProps) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const [seen, setSeen] = React.useState(false);\n  const [auto, setAuto] = React.useState(false);\n\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el || trigger !== \"view\") return;\n    if (typeof IntersectionObserver === \"undefined\") {\n      const id = requestAnimationFrame(() => setSeen(true));\n      return () => cancelAnimationFrame(id);\n    }\n    const io = new IntersectionObserver(\n      (entries) => {\n        for (const entry of entries) {\n          if (entry.isIntersecting) {\n            setSeen(true);\n            if (once) io.disconnect();\n          } else if (!once) {\n            setSeen(false);\n          }\n        }\n      },\n      { threshold: 0.6 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, [trigger, once]);\n\n  React.useEffect(() => {\n    if (trigger !== \"hover\" || !autoplay) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const first = setTimeout(() => setAuto(true), 500);\n    const id = setInterval(() => setAuto((a) => !a), 1900);\n    return () => {\n      clearTimeout(first);\n      clearInterval(id);\n    };\n  }, [trigger, autoplay]);\n\n  const h = variant === \"wavy\" ? thickness * 3.75 : thickness;\n  const vars = {\n    \"--hb-qd7-c\": color,\n    \"--hb-qd7-h\": `${h.toFixed(2)}px`,\n    \"--hb-qd7-tile\": `${((h * 16) / 6).toFixed(2)}px`,\n    \"--hb-qd7-dur\": `${duration}s`,\n    ...style,\n  } as React.CSSProperties;\n\n  const on = trigger === \"view\" ? seen : auto;\n\n  return (\n    <span\n      ref={ref}\n      className={`hb-qd7 ${className}`}\n      style={vars}\n      data-v={variant}\n      data-t={trigger}\n      data-on={on ? \"\" : undefined}\n      {...rest}\n    >\n      <style href=\"hb-text-underline-draw\" precedence=\"default\">{css}</style>\n      {text}\n      <span className=\"hb-qd7-l\" aria-hidden=\"true\" />\n    </span>\n  );\n}\n"
    }
  ]
}