{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "highlight-text",
  "title": "Highlight Text",
  "description": "A marker that slides in behind a phrase, or a hand-drawn line drawn under it.",
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/use-entrance"
  ],
  "files": [
    {
      "path": "registry/default/ui/highlight-text.tsx",
      "content": "\"use client\";\n\nimport { useMemo, type ComponentProps, type CSSProperties, type Ref } from \"react\";\n\nimport { useEntrance, type EntranceTrigger } from \"@/registry/default/hooks/use-entrance\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\nfunction mergeRefs<T>(...refs: (Ref<T> | undefined)[]) {\n  return (node: T | null) => {\n    for (const ref of refs) {\n      if (typeof ref === \"function\") ref(node);\n      else if (ref) ref.current = node;\n    }\n  };\n}\n\nconst FROM = {\n  left: \"translate3d(-101%, 0, 0)\",\n  right: \"translate3d(101%, 0, 0)\",\n  top: \"translate3d(0, -101%, 0)\",\n  bottom: \"translate3d(0, 101%, 0)\",\n};\n\n// Hand-drawn strokes in a box 100 wide and `height` tall; the svg stretches\n// them across the phrase. The inset keeps round caps inside the box.\nfunction scribblePaths(shape: \"underline\" | \"double\", height: number, inset: number) {\n  const y = (fraction: number) => Math.round((inset + fraction * (height - inset * 2)) * 100) / 100;\n  if (shape === \"double\") {\n    return [\n      `M1 ${y(0.3)} C 22 ${y(0)}, 48 ${y(0.45)}, 70 ${y(0.2)} S 94 ${y(0.1)}, 99 ${y(0.25)}`,\n      `M4 ${y(0.9)} C 28 ${y(0.65)}, 55 ${y(1)}, 78 ${y(0.75)} S 96 ${y(0.7)}, 98 ${y(0.8)}`,\n    ];\n  }\n  return [`M1 ${y(0.7)} C 18 ${y(0.1)}, 32 ${y(1)}, 50 ${y(0.5)} S 82 ${y(0)}, 99 ${y(0.45)}`];\n}\n\ninterface HighlightTextProps extends ComponentProps<\"span\"> {\n  /**\n   * \"marker\" slides a block of colour in behind the text; \"scribble\" draws a\n   * hand-drawn line under it and leaves the text as it is.\n   */\n  variant?: \"marker\" | \"scribble\";\n  /** Scribble: one wavy underline, or two strokes. */\n  scribble?: \"underline\" | \"double\";\n  /** Scribble: width of the line, in px. */\n  strokeWidth?: number;\n  /** Marker: the side the marker slides in from. */\n  from?: keyof typeof FROM;\n  /**\n   * Invert the text where the marker covers it, with a difference blend.\n   * Turn it off for a translucent marker (`markerClassName=\"bg-yellow-300/50\"`)\n   * that leaves the text colour alone.\n   */\n  inverse?: boolean;\n  /**\n   * Classes for the marker or the scribble, e.g. its colour. The marker\n   * defaults to the foreground colour; the scribble to\n   * `--highlight-text-color`, else the text colour (`text-primary` changes it).\n   */\n  markerClassName?: string;\n  /** \"load\" plays on first paint with CSS alone; \"in-view\" when the text scrolls into view. */\n  trigger?: EntranceTrigger;\n  /** In-view: play the first time only. */\n  once?: boolean;\n  /** Takes over from `trigger`: `false` holds the marker out of sight, `true` plays it. */\n  play?: boolean;\n  /** Wait before the marker moves or the line starts, in ms. */\n  delay?: number;\n  /** How long the marker or the line takes, in ms. */\n  duration?: number;\n}\n\n/**\n * A marker stroke that slides in behind a word or phrase. By default it is\n * the foreground colour and the text inverts where it passes, so it works\n * in light and dark themes without picking colours. Use it inline; it keeps\n * the baseline of the surrounding text. With `variant=\"scribble\"` a\n * hand-drawn line is drawn under the phrase instead, and the text keeps its\n * colour. Both are decorative; the text reads the same to screen readers.\n * With `prefers-reduced-motion` the marker or line is simply there.\n *\n * @example\n * <p>Every item is <HighlightText>yours to edit</HighlightText>.</p>\n *\n * @example\n * <h2>\n *   Built to <HighlightText variant=\"scribble\" markerClassName=\"text-primary\">last</HighlightText>\n * </h2>\n */\nfunction HighlightText({\n  variant = \"marker\",\n  scribble = \"underline\",\n  strokeWidth = 3,\n  from = \"bottom\",\n  inverse = true,\n  markerClassName,\n  trigger = \"load\",\n  once = true,\n  play,\n  delay = 0,\n  duration = 600,\n  className,\n  style,\n  ref,\n  children,\n  ...props\n}: HighlightTextProps) {\n  const [observe, phase] = useEntrance<HTMLSpanElement>({ trigger, once, play });\n  const mergedRef = useMemo(() => mergeRefs(ref, observe), [ref, observe]);\n\n  if (variant === \"scribble\") {\n    const width = Math.max(strokeWidth, 0);\n    // The box is sized in px, so the line keeps its width however the phrase stretches it.\n    const height = Math.round((scribble === \"double\" ? 12 : 8) + width * 2);\n    const strokes = scribblePaths(scribble, height, width / 2 + 0.5);\n    // Two strokes share the time: the second starts as the first ends.\n    const share = strokes.length > 1 ? 0.55 : 1;\n    return (\n      <span\n        ref={mergedRef}\n        data-slot=\"highlight-text\"\n        data-variant=\"scribble\"\n        data-state={phase}\n        className={cn(\"relative inline-flex px-[0.15em] align-baseline\", className)}\n        style={style}\n        {...props}\n      >\n        <svg\n          aria-hidden=\"true\"\n          data-slot=\"highlight-text-scribble\"\n          viewBox={`0 0 100 ${height}`}\n          preserveAspectRatio=\"none\"\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeWidth={width}\n          strokeLinecap=\"round\"\n          strokeLinejoin=\"round\"\n          className={cn(\n            \"pointer-events-none absolute inset-x-0 top-[calc(100%-0.2em)] w-full overflow-visible text-[color:var(--highlight-text-color,currentColor)]\",\n            markerClassName\n          )}\n          style={{ height: `${height}px` }}\n        >\n          {strokes.map((d, index) => (\n            <path\n              key={index}\n              d={d}\n              pathLength={1}\n              className={cn(phase !== \"static\" && \"motion-safe:animate-highlight-text-draw\")}\n              style={{\n                strokeDasharray: \"1 2\",\n                strokeDashoffset: 0,\n                ...(phase === \"static\"\n                  ? null\n                  : {\n                      animationDelay: `${Math.round(delay + index * (1 - share) * duration)}ms`,\n                      animationDuration: `${Math.round(share * duration)}ms`,\n                      animationPlayState: phase === \"armed\" ? \"paused\" : undefined,\n                    }),\n              }}\n            />\n          ))}\n        </svg>\n        <span className=\"relative\">{children}</span>\n      </span>\n    );\n  }\n\n  return (\n    <span\n      ref={mergedRef}\n      data-slot=\"highlight-text\"\n      data-variant=\"marker\"\n      data-state={phase}\n      // inline-flex keeps the text baseline, which an inline-block with clipping would lose.\n      className={cn(\"relative inline-flex overflow-clip px-[0.15em] align-baseline\", className)}\n      style={style}\n      {...props}\n    >\n      <span\n        aria-hidden=\"true\"\n        data-slot=\"highlight-text-marker\"\n        className={cn(\n          \"bg-foreground absolute inset-0\",\n          phase !== \"static\" && \"motion-safe:animate-highlight-text\",\n          markerClassName\n        )}\n        style={\n          phase === \"static\"\n            ? undefined\n            : ({\n                \"--highlight-text-from\": FROM[from],\n                animationDelay: `${delay}ms`,\n                animationDuration: `${duration}ms`,\n                animationPlayState: phase === \"armed\" ? \"paused\" : undefined,\n              } as CSSProperties)\n        }\n      />\n      <span className={cn(\"relative\", inverse && \"text-white mix-blend-difference\")}>\n        {children}\n      </span>\n    </span>\n  );\n}\n\nexport { HighlightText, type HighlightTextProps };\n",
      "type": "registry:ui"
    }
  ],
  "tailwind": {
    "config": {
      "theme": {
        "extend": {
          "keyframes": {
            "highlight-text": {
              "from": {
                "transform": "var(--highlight-text-from)"
              }
            },
            "highlight-text-draw": {
              "from": {
                "stroke-dashoffset": "1.01"
              },
              "to": {
                "stroke-dashoffset": "0"
              }
            }
          },
          "animation": {
            "highlight-text": "highlight-text 600ms cubic-bezier(0.22, 1, 0.36, 1) both",
            "highlight-text-draw": "highlight-text-draw 600ms cubic-bezier(0.65, 0, 0.35, 1) both"
          }
        }
      }
    }
  },
  "cssVars": {
    "theme": {
      "animate-highlight-text": "highlight-text 600ms cubic-bezier(0.22, 1, 0.36, 1) both",
      "animate-highlight-text-draw": "highlight-text-draw 600ms cubic-bezier(0.65, 0, 0.35, 1) both"
    }
  },
  "css": {
    "@keyframes highlight-text": {
      "from": {
        "transform": "var(--highlight-text-from)"
      }
    },
    "@keyframes highlight-text-draw": {
      "from": {
        "stroke-dashoffset": "1.01"
      },
      "to": {
        "stroke-dashoffset": "0"
      }
    }
  },
  "categories": [
    "text"
  ],
  "type": "registry:ui"
}