{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-highlight-marker",
  "type": "registry:component",
  "title": "Text Highlight Marker",
  "description": "Chosen words get a hand-drawn marker stroke that sweeps across them one after another.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "text",
    "highlight",
    "marker",
    "scroll",
    "emphasis",
    "paragraph"
  ],
  "docs": "https://hyperblur.dev/effects/text-highlight-marker",
  "files": [
    {
      "path": "registry/hyperblur/text-highlight-marker.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-highlight-marker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextHighlightMarkerProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text: string;\n  marks?: string[];\n  colors?: string[];\n  coverage?: number;\n  stagger?: number;\n  duration?: number;\n  delay?: number;\n  once?: boolean;\n  loop?: number;\n}\n\nconst shapes = [\n  \"polygon(0% 18%, 4% 6%, 22% 12%, 48% 2%, 76% 10%, 100% 0%, 98% 62%, 100% 96%, 72% 88%, 44% 100%, 20% 92%, 3% 98%)\",\n  \"polygon(2% 8%, 30% 0%, 58% 8%, 86% 2%, 100% 14%, 97% 52%, 100% 90%, 74% 100%, 46% 92%, 18% 100%, 0% 86%, 3% 46%)\",\n  \"polygon(0% 4%, 18% 12%, 42% 0%, 68% 10%, 100% 6%, 96% 40%, 100% 100%, 70% 90%, 40% 98%, 12% 88%, 2% 100%)\",\n];\n\nconst angles = [-1.4, 0.9, -0.5, 1.2, -1];\n\nconst css = `\n.hb-qd6 { display: inline; font-family: inherit; }\n.hb-qd6-k {\n  position: relative;\n  display: inline-block;\n  white-space: nowrap;\n  isolation: isolate;\n}\n.hb-qd6-b {\n  position: absolute;\n  z-index: -1;\n  left: -0.16em;\n  right: -0.16em;\n  top: var(--hb-qd6-top);\n  bottom: -0.06em;\n  background: var(--hb-qd6-c);\n  clip-path: var(--hb-qd6-shape);\n  transform: scaleX(0) rotate(var(--hb-qd6-r));\n  transform-origin: 0 60%;\n  transition: transform var(--hb-qd6-dur) cubic-bezier(.62, .04, .2, 1);\n  transition-delay: calc(var(--hb-qd6-delay) + var(--hb-qd6-n) * var(--hb-qd6-stagger));\n  pointer-events: none;\n}\n.hb-qd6[data-active] .hb-qd6-b { transform: scaleX(1) rotate(var(--hb-qd6-r)); }\n.hb-qd6[data-reset] .hb-qd6-b { transition: none; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qd6 .hb-qd6-b { transition: none; transform: scaleX(1) rotate(var(--hb-qd6-r)); }\n}\n`;\n\nfunction escapeRegExp(s: string) {\n  return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nexport function TextHighlightMarker({\n  text,\n  marks = [],\n  colors = [\"rgba(255, 214, 10, 0.5)\", \"rgba(255, 92, 168, 0.45)\", \"rgba(52, 211, 235, 0.42)\"],\n  coverage = 0.62,\n  stagger = 0.5,\n  duration = 0.75,\n  delay = 0.1,\n  once = true,\n  loop = 0,\n  className = \"\",\n  style,\n  ...rest\n}: TextHighlightMarkerProps) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const [inView, setInView] = React.useState(false);\n  const [phase, setPhase] = React.useState(0);\n\n  const segments = React.useMemo(() => {\n    const list = marks.filter(Boolean).sort((a, b) => b.length - a.length);\n    if (list.length === 0) return [{ value: text, marked: false }];\n    const re = new RegExp(`(${list.map(escapeRegExp).join(\"|\")})`, \"gi\");\n    return text\n      .split(re)\n      .filter((part) => part !== \"\")\n      .map((value) => ({ value, marked: list.some((m) => m.toLowerCase() === value.toLowerCase()) }));\n  }, [text, marks]);\n\n  const markCount = segments.filter((s) => s.marked).length;\n\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    if (typeof IntersectionObserver === \"undefined\") {\n      const id = requestAnimationFrame(() => setInView(true));\n      return () => cancelAnimationFrame(id);\n    }\n    const io = new IntersectionObserver(\n      (entries) => {\n        for (const entry of entries) {\n          if (entry.isIntersecting) {\n            setInView(true);\n            if (once) io.disconnect();\n          } else if (!once) {\n            setInView(false);\n          }\n        }\n      },\n      { threshold: 0.3 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, [once]);\n\n  React.useEffect(() => {\n    if (!inView || loop <= 0) return;\n    const total = (delay + duration + stagger * markCount + loop) * 1000;\n    const wait = phase === 1 ? 80 : phase === 2 ? 60 : total;\n    const id = setTimeout(() => setPhase((p) => (p + 1) % 3), wait);\n    return () => clearTimeout(id);\n  }, [inView, loop, phase, delay, duration, stagger, markCount]);\n\n  const vars = {\n    \"--hb-qd6-dur\": `${duration}s`,\n    \"--hb-qd6-delay\": `${delay}s`,\n    \"--hb-qd6-stagger\": `${stagger}s`,\n    \"--hb-qd6-top\": `${((1 - Math.min(1, Math.max(0.15, coverage))) * 100).toFixed(1)}%`,\n    ...style,\n  } as React.CSSProperties;\n\n  let order = 0;\n\n  return (\n    <span\n      ref={ref}\n      className={`hb-qd6 ${className}`}\n      style={vars}\n      data-active={inView && phase === 0 ? \"\" : undefined}\n      data-reset={phase === 1 ? \"\" : undefined}\n      {...rest}\n    >\n      <style href=\"hb-text-highlight-marker\" precedence=\"default\">{css}</style>\n      {segments.map((seg, i) => {\n        if (!seg.marked) return <React.Fragment key={i}>{seg.value}</React.Fragment>;\n        const n = order++;\n        const bar = {\n          \"--hb-qd6-n\": n,\n          \"--hb-qd6-c\": colors.length ? colors[n % colors.length] : \"rgba(255, 214, 10, 0.5)\",\n          \"--hb-qd6-shape\": shapes[n % shapes.length],\n          \"--hb-qd6-r\": `${angles[n % angles.length]}deg`,\n        } as React.CSSProperties;\n        return (\n          <span key={i} className=\"hb-qd6-k\" style={bar}>\n            <span className=\"hb-qd6-b\" aria-hidden=\"true\" />\n            {seg.value}\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n"
    }
  ]
}