{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-ink-draw",
  "type": "registry:component",
  "title": "Text Ink Draw",
  "description": "The outline of each glyph draws itself like a pen stroke, then ink floods the letters from left to right and the outline settles into a faint keyline. Rendered in SVG and sized to the text.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "outline",
    "stroke",
    "draw",
    "fill",
    "svg",
    "signature"
  ],
  "docs": "https://hyperblur.dev/effects/text-ink-draw",
  "files": [
    {
      "path": "registry/hyperblur/text-ink-draw.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-ink-draw.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextInkDrawProps extends React.HTMLAttributes<HTMLDivElement> {\n  text: string;\n  stroke?: string;\n  fill?: string;\n  strokeWidth?: number;\n  weight?: number;\n  drawDuration?: number;\n  fillDuration?: number;\n  trigger?: \"view\" | \"hover\" | \"mount\";\n  loop?: number;\n}\n\nconst FS = 100;\n\nconst css = `\n@keyframes hb-vi11-draw {\n  0% { stroke-dashoffset: var(--hb-vi11-dash); stroke-opacity: 1; }\n  80% { stroke-opacity: 1; }\n  100% { stroke-dashoffset: 0; stroke-opacity: 1; }\n}\n@keyframes hb-vi11-settle {\n  0% { stroke-opacity: 1; }\n  100% { stroke-opacity: 0.38; }\n}\n@keyframes hb-vi11-flood {\n  0% { transform: translateX(-100%); }\n  100% { transform: translateX(0%); }\n}\n.hb-vi11 { display: block; width: 100%; font-family: inherit; box-sizing: border-box; }\n.hb-vi11-svg { display: block; width: 100%; height: auto; overflow: visible; }\n.hb-vi11-t { font-family: inherit; }\n.hb-vi11-s {\n  fill: none;\n  stroke: var(--hb-vi11-stroke);\n  stroke-linejoin: round;\n  stroke-linecap: round;\n  stroke-dasharray: var(--hb-vi11-dash) var(--hb-vi11-dash);\n  stroke-dashoffset: var(--hb-vi11-dash);\n}\n.hb-vi11-f { fill: var(--hb-vi11-fill); }\n.hb-vi11-sweep { transform: translateX(-100%); }\n.hb-vi11[data-active] .hb-vi11-s {\n  animation:\n    hb-vi11-draw var(--hb-vi11-dd) cubic-bezier(.55, .1, .3, 1) both,\n    hb-vi11-settle 0.8s ease var(--hb-vi11-settle) both;\n}\n.hb-vi11[data-active] .hb-vi11-sweep {\n  animation: hb-vi11-flood var(--hb-vi11-fd) cubic-bezier(.65, 0, .25, 1) both;\n  animation-delay: calc(var(--hb-vi11-dd) * 0.72);\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vi11 .hb-vi11-s { animation: none !important; stroke-dashoffset: 0; stroke-opacity: 0.38; }\n  .hb-vi11 .hb-vi11-sweep { animation: none !important; transform: none; }\n}\n`;\n\nexport function TextInkDraw({\n  text,\n  stroke = \"#7fb3ff\",\n  fill = \"#ededed\",\n  strokeWidth = 2.2,\n  weight = 700,\n  drawDuration = 1.8,\n  fillDuration = 0.9,\n  trigger = \"view\",\n  loop = 0,\n  className = \"\",\n  style,\n  onMouseEnter,\n  ...rest\n}: TextInkDrawProps) {\n  const uid = React.useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const maskId = `hb-vi11-m${uid}`;\n  const gradId = `hb-vi11-g${uid}`;\n  const ref = React.useRef<HTMLDivElement>(null);\n  const probe = React.useRef<SVGTextElement>(null);\n  const [box, setBox] = React.useState<{ x: number; y: number; w: number; h: number }>(() => ({\n    x: 0,\n    y: -FS * 0.8,\n    w: Math.max(1, Array.from(text).length) * FS * 0.6,\n    h: FS * 1.05,\n  }));\n  const [active, setActive] = React.useState(false);\n  const [cycle, setCycle] = React.useState(0);\n\n  React.useLayoutEffect(() => {\n    const el = probe.current;\n    if (!el) return;\n    const measure = () => {\n      try {\n        const b = el.getBBox();\n        if (b.width > 0) {\n          const pad = strokeWidth * 2 + 2;\n          setBox((prev) => {\n            const next = { x: b.x - pad, y: b.y - pad, w: b.width + pad * 2, h: b.height + pad * 2 };\n            return Math.abs(prev.w - next.w) < 0.5 && Math.abs(prev.h - next.h) < 0.5 && Math.abs(prev.x - next.x) < 0.5 ? prev : next;\n          });\n        }\n      } catch {\n        return;\n      }\n    };\n    measure();\n    if (document.fonts?.ready) document.fonts.ready.then(measure).catch(() => undefined);\n  }, [text, weight, strokeWidth]);\n\n  const play = React.useCallback(() => {\n    setActive(false);\n    requestAnimationFrame(() =>\n      requestAnimationFrame(() => {\n        setCycle((c) => c + 1);\n        setActive(true);\n      }),\n    );\n  }, []);\n\n  React.useEffect(() => {\n    if (trigger === \"hover\") return;\n    if (trigger === \"mount\") {\n      const id = requestAnimationFrame(() => setActive(true));\n      return () => cancelAnimationFrame(id);\n    }\n    const el = ref.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") {\n      const id = requestAnimationFrame(() => setActive(true));\n      return () => cancelAnimationFrame(id);\n    }\n    const io = new IntersectionObserver(\n      (entries) => {\n        if (entries.some((e) => e.isIntersecting)) {\n          setActive(true);\n          io.disconnect();\n        }\n      },\n      { threshold: 0.35 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, [trigger]);\n\n  React.useEffect(() => {\n    if (!active || loop <= 0) return;\n    const id = setTimeout(play, (drawDuration + fillDuration + 0.8 + loop) * 1000);\n    return () => clearTimeout(id);\n  }, [active, loop, cycle, drawDuration, fillDuration, play]);\n\n  const dash = FS * 7;\n  const vars = {\n    \"--hb-vi11-stroke\": stroke,\n    \"--hb-vi11-fill\": fill,\n    \"--hb-vi11-dash\": dash,\n    \"--hb-vi11-dd\": `${drawDuration}s`,\n    \"--hb-vi11-fd\": `${fillDuration}s`,\n    \"--hb-vi11-settle\": `${(drawDuration * 0.72 + fillDuration).toFixed(2)}s`,\n    ...style,\n  } as React.CSSProperties;\n\n  const textProps = {\n    x: 0,\n    y: 0,\n    fontSize: FS,\n    fontWeight: weight,\n    className: \"hb-vi11-t\",\n    style: { whiteSpace: \"pre\" } as React.CSSProperties,\n  };\n\n  return (\n    <div\n      ref={ref}\n      className={`hb-vi11 ${className}`}\n      style={vars}\n      data-active={active ? \"\" : undefined}\n      onMouseEnter={(e) => {\n        if (trigger === \"hover\") play();\n        onMouseEnter?.(e);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-text-ink-draw\" precedence=\"default\">{css}</style>\n      <svg\n        className=\"hb-vi11-svg\"\n        viewBox={`${box.x.toFixed(1)} ${box.y.toFixed(1)} ${box.w.toFixed(1)} ${box.h.toFixed(1)}`}\n        role=\"img\"\n        aria-label={text}\n      >\n        <title>{text}</title>\n        <defs>\n          <linearGradient id={gradId} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\n            <stop offset=\"0\" stopColor=\"#fff\" />\n            <stop offset=\"0.86\" stopColor=\"#fff\" />\n            <stop offset=\"1\" stopColor=\"#fff\" stopOpacity=\"0\" />\n          </linearGradient>\n          <mask id={maskId} maskUnits=\"userSpaceOnUse\" x={box.x} y={box.y} width={box.w} height={box.h}>\n            <rect\n              key={cycle}\n              className=\"hb-vi11-sweep\"\n              x={box.x}\n              y={box.y}\n              width={box.w * 1.16}\n              height={box.h}\n              fill={`url(#${gradId})`}\n              style={{ transformBox: \"fill-box\" }}\n            />\n          </mask>\n        </defs>\n        <text ref={probe} {...textProps} opacity=\"0\" aria-hidden=\"true\">{text}</text>\n        <g aria-hidden=\"true\" key={cycle}>\n          <text {...textProps} className=\"hb-vi11-t hb-vi11-f\" mask={`url(#${maskId})`}>{text}</text>\n          <text {...textProps} className=\"hb-vi11-t hb-vi11-s\" strokeWidth={strokeWidth}>{text}</text>\n        </g>\n      </svg>\n    </div>\n  );\n}\n"
    }
  ]
}