{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "highlighter",
  "title": "Highlighter",
  "description": "Draws a marker highlight, hand-drawn underline, circle, box or strike-through behind a phrase when it scrolls into view, in six colors.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/text/highlighter.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useInView, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { GooduiTokens, ease as easing } from \"@/lib/goodui-motion\"\n\nconst CSS = `\n.pc-highlighter[data-color=\"amber\"] { --pc-hl-fill: oklch(0.9 0.15 95 / 0.8); --pc-hl-stroke: oklch(0.75 0.17 70) }\n.pc-highlighter[data-color=\"emerald\"] { --pc-hl-fill: oklch(0.91 0.1 160 / 0.8); --pc-hl-stroke: oklch(0.64 0.15 160) }\n.pc-highlighter[data-color=\"sky\"] { --pc-hl-fill: oklch(0.9 0.07 230 / 0.85); --pc-hl-stroke: oklch(0.64 0.15 240) }\n.pc-highlighter[data-color=\"rose\"] { --pc-hl-fill: oklch(0.9 0.07 10 / 0.85); --pc-hl-stroke: oklch(0.63 0.21 18) }\n.pc-highlighter[data-color=\"violet\"] { --pc-hl-fill: oklch(0.89 0.08 300 / 0.85); --pc-hl-stroke: oklch(0.58 0.21 295) }\n.pc-highlighter[data-color=\"primary\"] { --pc-hl-fill: color-mix(in oklch, var(--primary) 16%, transparent); --pc-hl-stroke: var(--primary) }\n:where(.dark) .pc-highlighter[data-color=\"amber\"] { --pc-hl-fill: oklch(0.8 0.15 85 / 0.3); --pc-hl-stroke: oklch(0.83 0.15 80) }\n:where(.dark) .pc-highlighter[data-color=\"emerald\"] { --pc-hl-fill: oklch(0.75 0.14 160 / 0.28); --pc-hl-stroke: oklch(0.79 0.15 160) }\n:where(.dark) .pc-highlighter[data-color=\"sky\"] { --pc-hl-fill: oklch(0.72 0.12 230 / 0.3); --pc-hl-stroke: oklch(0.78 0.12 230) }\n:where(.dark) .pc-highlighter[data-color=\"rose\"] { --pc-hl-fill: oklch(0.7 0.17 15 / 0.3); --pc-hl-stroke: oklch(0.75 0.16 15) }\n:where(.dark) .pc-highlighter[data-color=\"violet\"] { --pc-hl-fill: oklch(0.7 0.17 295 / 0.32); --pc-hl-stroke: oklch(0.76 0.15 295) }\n.pc-highlighter[data-action=\"highlight\"] {\n  background-image: linear-gradient(var(--pc-hl-fill), var(--pc-hl-fill));\n  background-repeat: no-repeat;\n  background-position: 0 88%;\n  background-size: 0% 72%;\n  padding: 0 0.12em; margin: 0 -0.12em;\n  border-radius: 0.2em;\n  transition: background-size var(--pc-hl-duration, 0.8s) var(--pc-ease-in-out) var(--pc-hl-delay, 0s);\n}\n.pc-highlighter[data-action=\"highlight\"][data-shown] { background-size: 100% 72% }\n@media (prefers-reduced-motion: reduce) { .pc-highlighter[data-action=\"highlight\"] { transition: none } }\n`\n\nexport type HighlighterAction = \"highlight\" | \"underline\" | \"circle\" | \"box\" | \"strike\"\nexport type HighlighterColor = \"amber\" | \"emerald\" | \"sky\" | \"rose\" | \"violet\" | \"primary\"\n\nexport type HighlighterProps = Omit<React.HTMLAttributes<HTMLSpanElement>, \"color\"> & {\n  /** Marker highlight (wraps across lines), or a hand-drawn underline, circle, box or strike-through. */\n  action?: HighlighterAction\n  /** Marker and stroke color, tuned for light and dark; \"primary\" follows the theme. */\n  color?: HighlighterColor\n  /** Controlled: true draws, false erases. Leave undefined to draw when scrolled into view. */\n  show?: boolean\n  /** With automatic triggering: draw only the first time it enters the viewport. */\n  once?: boolean\n  /** Seconds before drawing starts. */\n  delay?: number\n  /** Seconds the stroke takes. */\n  duration?: number\n  /** Stroke width in px for underline, circle, box and strike (not used by highlight). */\n  strokeWidth?: number\n  /** Extra space in px between the text and a circle or box. */\n  padding?: number\n}\n\n// Hand-drawn shapes, built in pixels from the measured size so strokes never stretch.\nfunction shapePath(action: HighlighterAction, w: number, h: number, p: number) {\n  switch (action) {\n    case \"underline\":\n      return `M ${-2} ${h + 1} Q ${w * 0.35} ${h - 1.5} ${w * 0.6} ${h + 0.5} T ${w + 3} ${h - 0.5}`\n    case \"strike\":\n      return `M ${-3} ${h * 0.56} Q ${w * 0.5} ${h * 0.5} ${w + 3} ${h * 0.53}`\n    case \"box\": {\n      const x0 = -p, y0 = -p * 0.55, x1 = w + p, y1 = h + p * 0.55\n      return `M ${x0 + 3} ${y0 + 1} L ${x1} ${y0 - 1} L ${x1 + 1} ${y1} L ${x0} ${y1 + 1} L ${x0 - 1} ${y0 - 1} L ${x0 + 10} ${y0 + 0.5}`\n    }\n    case \"circle\": {\n      const cx = w / 2, cy = h / 2, rx = w / 2 + p, ry = h / 2 + p * 0.7\n      const start = Math.PI * 1.08\n      const sweep = Math.PI * 2.18\n      const pts: string[] = []\n      for (let i = 0; i <= 64; i++) {\n        const t = i / 64\n        const a = start + sweep * t\n        const grow = 1 + 0.07 * t + 0.02 * Math.sin(a * 3)\n        pts.push(`${(cx + Math.cos(a) * rx * grow).toFixed(1)} ${(cy + Math.sin(a) * ry * grow).toFixed(1)}`)\n      }\n      return `M ${pts.join(\" L \")}`\n    }\n    default:\n      return \"\"\n  }\n}\n\n/** Draws a marker highlight, underline, circle, box or strike-through behind a phrase when it scrolls into view. */\nexport function Highlighter({\n  action = \"highlight\",\n  color = \"amber\",\n  show,\n  once = true,\n  delay = 0,\n  duration = 0.8,\n  strokeWidth = 2,\n  padding = 6,\n  className,\n  style,\n  children,\n  ...props\n}: HighlighterProps) {\n  const reduce = useReducedMotion() ?? false\n  const ref = React.useRef<HTMLSpanElement>(null)\n  const inView = useInView(ref, { once, amount: 0.8 })\n  const shown = show ?? inView\n  const [size, setSize] = React.useState<{ w: number; h: number } | null>(null)\n  const svg = action !== \"highlight\"\n  // The CSS marker needs one painted frame at 0% so it can transition in, even when it mounts already shown.\n  const [ready, setReady] = React.useState(false)\n  React.useEffect(() => {\n    const r = requestAnimationFrame(() => setReady(true))\n    return () => cancelAnimationFrame(r)\n  }, [])\n\n  React.useEffect(() => {\n    const el = ref.current\n    if (!el || !svg) return\n    const update = () => setSize({ w: el.offsetWidth, h: el.offsetHeight })\n    update()\n    const ro = new ResizeObserver(update)\n    ro.observe(el)\n    return () => ro.disconnect()\n  }, [svg])\n\n  return (\n    <>\n      <GooduiTokens />\n      <style href=\"pc-highlighter\" precedence=\"default\">\n        {CSS}\n      </style>\n      <span\n        ref={ref}\n        data-action={action}\n        data-color={color}\n        data-shown={shown && ready ? \"\" : undefined}\n        className={cn(\"pc-highlighter\", svg ? \"relative inline-block\" : \"[box-decoration-break:slice]\", className)}\n        style={{ ...style, [\"--pc-hl-delay\" as string]: `${delay}s`, [\"--pc-hl-duration\" as string]: `${duration}s` }}\n        {...props}\n      >\n        {children}\n        {svg && size && (\n          <svg aria-hidden=\"true\" className=\"pointer-events-none absolute top-0 left-0 overflow-visible\" width={size.w} height={size.h}>\n            <motion.path\n              d={shapePath(action, size.w, size.h, padding)}\n              fill=\"none\"\n              stroke=\"var(--pc-hl-stroke)\"\n              strokeWidth={strokeWidth}\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n              initial={{ pathLength: 0, opacity: 0 }}\n              animate={shown ? { pathLength: 1, opacity: 1 } : { pathLength: 0, opacity: 0 }}\n              transition={\n                reduce\n                  ? { duration: 0 }\n                  : { pathLength: { delay, duration, ease: easing.inOut }, opacity: { delay, duration: 0.05 } }\n              }\n            />\n          </svg>\n        )}\n      </span>\n    </>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/highlighter.tsx"
    }
  ],
  "categories": [
    "components",
    "text"
  ],
  "type": "registry:component"
}