{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "caption-slice",
  "title": "Caption Slice",
  "description": "Each word arrives cut in two, the top half sliding in from the left and the bottom from the right, locking together the moment it is spoken.",
  "dependencies": ["remotion", "@remotion/captions"],
  "registryDependencies": ["@remocn/caption-core"],
  "files": [
    {
      "path": "registry/remocn/caption-slice/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} from \"@/lib/remocn/caption-core\";\n\nexport interface CaptionSliceProps extends CaptionBaseProps {\n  distance?: number;\n  shadow?: boolean;\n}\n\nconst SLIDE_MS = 240;\nconst FADE_MS = 90;\nconst EXIT_MS = 220;\nconst LEGIBILITY_SHADOW =\n  \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\nconst TOP_HALF = \"inset(-0.5em -0.5em 50% -0.5em)\";\nconst BOTTOM_HALF = \"inset(50% -0.5em -0.5em -0.5em)\";\n\nconst slideEasing = Easing.bezier(0.16, 1, 0.3, 1);\n\nconst clamp = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nexport function CaptionSlice({\n  captions,\n  combineTokensWithinMilliseconds = 1200,\n  holdMs = DEFAULT_HOLD_MS,\n  fontSize = 64,\n  fontWeight = 800,\n  color = \"#ffffff\",\n  distance = 0.6,\n  shadow = true,\n  className,\n}: CaptionSliceProps) {\n  const state = useCaptions({\n    captions,\n    combineTokensWithinMilliseconds,\n    holdMs,\n  });\n  if (!state) return null;\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  const textShadow = shadow ? LEGIBILITY_SHADOW : undefined;\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: exit,\n      }}\n    >\n      {groupCaptionWords(state.tokens).map((word, w) => (\n        <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n          {w > 0 && \" \"}\n          <span style={{ display: \"inline-block\", whiteSpace: \"nowrap\" }}>\n            {word.map(({ index, token }) => {\n              const sinceMs = state.timeMs - token.fromMs;\n              if (sinceMs < 0) {\n                return (\n                  <span\n                    key={index}\n                    style={{ display: \"inline-block\", color: \"transparent\" }}\n                  >\n                    {token.text}\n                  </span>\n                );\n              }\n              const slide = interpolate(sinceMs, [0, SLIDE_MS], [0, 1], {\n                ...clamp,\n                easing: slideEasing,\n              });\n              if (slide >= 1) {\n                return (\n                  <span\n                    key={index}\n                    style={{ display: \"inline-block\", textShadow }}\n                  >\n                    {token.text}\n                  </span>\n                );\n              }\n              const opacity = interpolate(sinceMs, [0, FADE_MS], [0, 1], clamp);\n              const offset = (1 - slide) * distance;\n              return (\n                <span\n                  key={index}\n                  style={{ position: \"relative\", display: \"inline-block\" }}\n                >\n                  <span style={{ color: \"transparent\" }}>{token.text}</span>\n                  <span\n                    aria-hidden\n                    style={{\n                      position: \"absolute\",\n                      inset: 0,\n                      whiteSpace: \"nowrap\",\n                      clipPath: TOP_HALF,\n                      opacity,\n                      transform: `translateX(${-offset}em)`,\n                      textShadow,\n                    }}\n                  >\n                    {token.text}\n                  </span>\n                  <span\n                    aria-hidden\n                    style={{\n                      position: \"absolute\",\n                      inset: 0,\n                      whiteSpace: \"nowrap\",\n                      clipPath: BOTTOM_HALF,\n                      opacity,\n                      transform: `translateX(${offset}em)`,\n                      textShadow,\n                    }}\n                  >\n                    {token.text}\n                  </span>\n                </span>\n              );\n            })}\n          </span>\n        </Fragment>\n      ))}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/caption-slice.tsx"
    }
  ],
  "type": "registry:component"
}
