{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "caption-weight",
  "title": "Caption Weight",
  "description": "The word being spoken swells from a light weight to a heavy one and relaxes as the voice moves on, with no layout shift.",
  "dependencies": ["remotion", "@remotion/captions"],
  "registryDependencies": ["@remocn/caption-core"],
  "files": [
    {
      "path": "registry/remocn/caption-weight/index.tsx",
      "content": "\"use client\";\n\nimport { Fragment } from \"react\";\nimport { Easing, interpolate } from \"remotion\";\nimport {\n  type CaptionBaseProps,\n  captionWordText,\n  DEFAULT_HOLD_MS,\n  getExitWindowMs,\n  groupCaptionWords,\n  useCaptions,\n} from \"@/lib/remocn/caption-core\";\n\nexport interface CaptionWeightProps extends CaptionBaseProps {\n  activeWeight?: number;\n  shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst RAMP_MS = 150;\nconst RELEASE_MS = 220;\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 rampEasing = Easing.bezier(0.2, 0.8, 0.3, 1);\nconst releaseEasing = Easing.bezier(0.4, 0, 0.2, 1);\n\nconst clamp = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nexport function CaptionWeight({\n  captions,\n  combineTokensWithinMilliseconds = 1200,\n  holdMs = DEFAULT_HOLD_MS,\n  fontSize = 64,\n  fontWeight = 400,\n  activeWeight = 900,\n  color = \"#ffffff\",\n  shadow = true,\n  className,\n}: CaptionWeightProps) {\n  const state = useCaptions({\n    captions,\n    combineTokensWithinMilliseconds,\n    holdMs,\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 words = groupCaptionWords(state.tokens);\n  const activeWord = words.findIndex((word) =>\n    word.some(({ index }) => index === state.activeIndex),\n  );\n\n  const emphasis = (w: number): number => {\n    if (activeWord < 0 || w > activeWord) return 0;\n    const startMs = words[w][0].token.fromMs;\n    const rise = interpolate(state.timeMs - startMs, [0, RAMP_MS], [0, 1], {\n      ...clamp,\n      easing: rampEasing,\n    });\n    if (w === activeWord) return rise;\n    const releaseMs = words[w + 1][0].token.fromMs;\n    const peak = interpolate(releaseMs - startMs, [0, RAMP_MS], [0, 1], {\n      ...clamp,\n      easing: rampEasing,\n    });\n    const release = interpolate(\n      state.timeMs - releaseMs,\n      [0, RELEASE_MS],\n      [0, 1],\n      { ...clamp, easing: releaseEasing },\n    );\n    return peak * (1 - release);\n  };\n\n  return (\n    <div\n      className={className}\n      style={{\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        const weight = fontWeight + (activeWeight - fontWeight) * emphasis(w);\n        return (\n          <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n            {w > 0 && \" \"}\n            <span style={{ display: \"inline-grid\", whiteSpace: \"nowrap\" }}>\n              <span\n                aria-hidden\n                style={{\n                  gridArea: \"1 / 1\",\n                  fontWeight: Math.max(fontWeight, activeWeight),\n                  visibility: \"hidden\",\n                }}\n              >\n                {captionWordText(word)}\n              </span>\n              <span\n                style={{\n                  gridArea: \"1 / 1\",\n                  justifySelf: \"center\",\n                  fontWeight: weight,\n                  textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n                }}\n              >\n                {word.map(({ index, token }) => (\n                  <span key={index}>{token.text}</span>\n                ))}\n              </span>\n            </span>\n          </Fragment>\n        );\n      })}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/caption-weight.tsx"
    }
  ],
  "type": "registry:component"
}
