{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "caption-underline",
  "title": "Caption Underline",
  "description": "A bar slides under the word being spoken, travelling from word to word while the text itself stays untouched.",
  "dependencies": ["remotion", "@remotion/captions"],
  "registryDependencies": ["@remocn/caption-core"],
  "files": [
    {
      "path": "registry/remocn/caption-underline/index.tsx",
      "content": "\"use client\";\n\nimport { Fragment } from \"react\";\nimport { Easing, interpolate } from \"remotion\";\nimport {\n  type CaptionBaseProps,\n  DEFAULT_HOLD_MS,\n  getExitWindowMs,\n  groupCaptionWords,\n  useCaptions,\n  useCaptionWordRects,\n} from \"@/lib/remocn/caption-core\";\n\nexport interface CaptionUnderlineProps extends CaptionBaseProps {\n  underlineColor?: string;\n  thickness?: number;\n  underlineOffset?: number;\n  shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst TRAVEL_MS = 120;\nconst LEGIBILITY_SHADOW =\n  \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst travelEasing = Easing.bezier(0.3, 0, 0.2, 1);\n\nconst clamp = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nfunction mix(a: number, b: number, t: number): number {\n  return a + (b - a) * t;\n}\n\nexport function CaptionUnderline({\n  captions,\n  combineTokensWithinMilliseconds = 1200,\n  holdMs = DEFAULT_HOLD_MS,\n  fontSize = 64,\n  fontWeight = 800,\n  color = \"#ffffff\",\n  underlineColor = \"#facc15\",\n  thickness = 0.08,\n  underlineOffset = 0.02,\n  shadow = true,\n  className,\n}: CaptionUnderlineProps) {\n  const state = useCaptions({\n    captions,\n    combineTokensWithinMilliseconds,\n    holdMs,\n  });\n  const words = state ? groupCaptionWords(state.tokens) : [];\n  const pageIndex = state ? state.pageIndex : -1;\n  const { wordRef, rects } = useCaptionWordRects(pageIndex, words.length);\n\n  if (!state) return null;\n\n  const enter = interpolate(\n    state.previous ? ENTER_MS : state.sinceStartMs,\n    [0, ENTER_MS],\n    [0, 1],\n    {\n      ...clamp,\n      easing: enterEasing,\n    },\n  );\n  const exit = state.endsInSilence\n    ? interpolate(\n        state.untilEndMs,\n        [0, getExitWindowMs(state, EXIT_MS)],\n        [0, 1],\n        clamp,\n      )\n    : 1;\n\n  const activeWord = words.findIndex((word) =>\n    word.some(({ index }) => index === state.activeIndex),\n  );\n  const travel =\n    activeWord >= 0\n      ? interpolate(\n          state.timeMs - words[activeWord][0].token.fromMs,\n          [0, TRAVEL_MS],\n          [0, 1],\n          { ...clamp, easing: travelEasing },\n        )\n      : 0;\n\n  const target = rects && activeWord >= 0 ? rects[activeWord] : null;\n  const origin = rects && activeWord > 0 ? rects[activeWord - 1] : null;\n  const barHeight = thickness * fontSize;\n  const gap = underlineOffset * fontSize;\n  const bar = target\n    ? origin\n      ? {\n          left: mix(origin.left, target.left, travel),\n          top: mix(\n            origin.top + origin.height,\n            target.top + target.height,\n            travel,\n          ),\n          width: mix(origin.width, target.width, travel),\n          opacity: 1,\n        }\n      : {\n          left: target.left,\n          top: target.top + target.height,\n          width: target.width * travel,\n          opacity: travel,\n        }\n    : null;\n\n  return (\n    <div\n      className={className}\n      style={{\n        position: \"relative\",\n        fontSize,\n        fontWeight,\n        color,\n        lineHeight: 1.2,\n        textAlign: \"center\",\n        opacity: Math.min(enter, exit),\n        transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n      }}\n    >\n      {words.map((word, w) => (\n        <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n          {w > 0 && \" \"}\n          <span\n            ref={wordRef(w)}\n            style={{\n              position: \"relative\",\n              display: \"inline-block\",\n              whiteSpace: \"nowrap\",\n              textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n            }}\n          >\n            {word.map(({ index, token }) => (\n              <span key={index}>{token.text}</span>\n            ))}\n          </span>\n        </Fragment>\n      ))}\n      {bar && (\n        <span\n          aria-hidden\n          style={{\n            position: \"absolute\",\n            left: bar.left,\n            top: bar.top + gap,\n            width: bar.width,\n            height: barHeight,\n            borderRadius: barHeight / 2,\n            background: underlineColor,\n            opacity: bar.opacity,\n          }}\n        />\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/caption-underline.tsx"
    }
  ],
  "type": "registry:component"
}
