Skip to content

🎥 Make videos programmatically with React

Merge origin/main into codex/caption-line-break-after

Jonny Burger7d5fe5b0a442
diff --cc packages/jonnys-videos/src/components/AnimatedCaptions.tsx
index 87393cba37,f204b28b4a..e9ed7d3e58
--- a/packages/jonnys-videos/src/components/AnimatedCaptions.tsx
+++ b/packages/jonnys-videos/src/components/AnimatedCaptions.tsx
@@@ -47,30 -153,33 +153,39 @@@ const CaptionPage: React.FC<CaptionPage
}}
>
{page.tokens.map((token, tokenIndex) => {
- const isActive =
- token.fromMs <= absoluteTimeMs && token.toMs > absoluteTimeMs;
+ const startsLine =
+ tokenIndex === 0 || page.tokens[tokenIndex - 1]?.lineBreakAfter;
return (
- <span
- ref={(element) => {
- wordRefs.current[tokenIndex] = element;
- }}
- key={`${token.fromMs}-${tokenIndex}`}
- style={{
- color:
- tokenIndex === focusedTokenIndex
- ? interpolateColors(
- focusProgress,
- [0, 1],
- ['#d9d9d9', '#ffffff'],
- )
- : tokenIndex === focusedTokenIndex - 1
+ <React.Fragment key={`${token.fromMs}-${tokenIndex}`}>
+ <span
++ ref={(element) => {
++ wordRefs.current[tokenIndex] = element;
++ }}
+ style={{
- color: isActive ? HIGHLIGHT_COLOR : '#ffffff',
++ color:
++ tokenIndex === focusedTokenIndex
+ ? interpolateColors(
+ focusProgress,
+ [0, 1],
- ['#ffffff', '#d9d9d9'],
++ ['#d9d9d9', '#ffffff'],
+ )
- : '#d9d9d9',
- display: 'inline-block',
- marginLeft: tokenIndex === 0 ? 0 : 26,
- }}
- >
- {token.text.trimStart()}
- </span>
++ : tokenIndex === focusedTokenIndex - 1
++ ? interpolateColors(
++ focusProgress,
++ [0, 1],
++ ['#ffffff', '#d9d9d9'],
++ )
++ : '#d9d9d9',
+ display: 'inline-block',
+ marginLeft: startsLine ? 0 : 26,
- WebkitTextStroke: isActive
- ? '3px rgba(38, 4, 0, 0.95)'
- : '2px rgba(0, 0, 0, 0.85)',
+ }}
+ >
+ {token.text.trimStart()}
+ </span>
+ {token.lineBreakAfter && tokenIndex < page.tokens.length - 1 ? (
+ <br />
+ ) : null}
+ </React.Fragment>
);
})}
</div>