🎥 Make videos programmatically with React
Captions: Rename forced breaks to page breaks
Jonny Burgerc3d22f220128
diff --git a/packages/brand/src/Compose/Captions.tsx b/packages/brand/src/Compose/Captions.tsxindex 8e8b58ca24..a9156173f3 100644--- a/packages/brand/src/Compose/Captions.tsx+++ b/packages/brand/src/Compose/Captions.tsx@@ -12,8 +12,7 @@ import {const Token: React.FC<{readonly token: TikTokToken;readonly pageStart: number;- readonly isLast: boolean;-}> = ({token, pageStart, isLast}) => {+}> = ({token, pageStart}) => {const frame = useCurrentFrame();const {fps} = useVideoConfig();const start = ((token.fromMs - pageStart) / 1000) * 30;@@ -50,13 +49,10 @@ const Token: React.FC<{}, [active, jump]);return (- <>- <span>- {' '}- <span style={style}>{token.text.trim()}</span>- </span>- {token.lineBreakAfter && !isLast ? <br /> : null}- </>+ <span>+ {' '}+ <span style={style}>{token.text.trim()}</span>+ </span>);};@@ -99,13 +95,12 @@ export const Captions: React.FC = () => {layout="none"><div key={page.startMs}>- {page.tokens.map((t, index) => {+ {page.tokens.map((t) => {return (<Tokenkey={t.fromMs}pageStart={page.startMs}token={t}- isLast={index === page.tokens.length - 1}/>);})}diff --git a/packages/captions/src/caption.ts b/packages/captions/src/caption.tsindex a892b9d4cb..4083f7aa92 100644--- a/packages/captions/src/caption.ts+++ b/packages/captions/src/caption.ts@@ -4,5 +4,5 @@ export type Caption = {endMs: number;timestampMs: number | null;confidence: number | null;- lineBreakAfter?: boolean;+ pageBreakAfter?: boolean;};diff --git a/packages/captions/src/create-tiktok-style-captions.ts b/packages/captions/src/create-tiktok-style-captions.tsindex 5c1b23023c..4748d4c47d 100644--- a/packages/captions/src/create-tiktok-style-captions.ts+++ b/packages/captions/src/create-tiktok-style-captions.ts@@ -4,7 +4,7 @@ export type TikTokToken = {text: string;fromMs: number;toMs: number;- lineBreakAfter?: boolean;+ pageBreakAfter?: boolean;};export type TikTokPage = {@@ -75,7 +75,7 @@ export const createTikTokStyleCaptions = ({text: text.trimStart(),fromMs: item.startMs,toMs: item.endMs,- ...(item.lineBreakAfter ? {lineBreakAfter: true} : {}),+ ...(item.pageBreakAfter ? {pageBreakAfter: true} : {}),},].filter((t) => t.text !== '');currentFrom = item.startMs;@@ -96,14 +96,14 @@ export const createTikTokStyleCaptions = ({currentTokens.length === 0 ? currentText.trimStart() : textToAppend,fromMs: item.startMs,toMs: item.endMs,- ...(item.lineBreakAfter ? {lineBreakAfter: true} : {}),+ ...(item.pageBreakAfter ? {pageBreakAfter: true} : {}),});}currentTo = item.endMs;}- if (item.lineBreakAfter && currentText !== '') {+ if (item.pageBreakAfter && currentText !== '') {add();currentText = '';currentTokens = [];diff --git a/packages/captions/src/ensure-max-characters-per-line.ts b/packages/captions/src/ensure-max-characters-per-line.tsindex e105910f41..5c4e933324 100644--- a/packages/captions/src/ensure-max-characters-per-line.ts+++ b/packages/captions/src/ensure-max-characters-per-line.ts@@ -15,8 +15,8 @@ const splitWords = (inputCaptions: Caption[]): Caption[] => {endMs: w.endMs,confidence: w.confidence,timestampMs: w.timestampMs,- ...(j === words.length - 1 && w.lineBreakAfter- ? {lineBreakAfter: true}+ ...(j === words.length - 1 && w.pageBreakAfter+ ? {pageBreakAfter: true}: {}),});}@@ -62,7 +62,7 @@ export const ensureMaxCharactersPerLine = ({}currentSegment.push(w);- if (w.lineBreakAfter && i < splitted.length - 1) {+ if (w.pageBreakAfter && i < splitted.length - 1) {segments.push(currentSegment);currentSegment = [];}diff --git a/packages/captions/src/serialize-srt.ts b/packages/captions/src/serialize-srt.tsindex d241994052..0475397665 100644--- a/packages/captions/src/serialize-srt.ts+++ b/packages/captions/src/serialize-srt.ts@@ -18,33 +18,37 @@ export type SerializeSrtInput = {};export const serializeSrt = ({lines}: SerializeSrtInput) => {- let currentIndex = 0;+ const cues: Caption[][] = [];- return lines- .map((s) => {- currentIndex++;- if (s.length === 0) {- return null;+ for (const line of lines) {+ let currentCue: Caption[] = [];++ for (const caption of line) {+ currentCue.push(caption);++ if (caption.pageBreakAfter) {+ cues.push(currentCue);+ currentCue = [];}+ }++ if (currentCue.length > 0) {+ cues.push(currentCue);+ }+ }+ return cues+ .map((s, index) => {const firstTimestamp = s[0].startMs;const lastTimestamp = s[s.length - 1].endMs;return [// Index- currentIndex,+ index + 1,formatSrtTimestamp(firstTimestamp, lastTimestamp),// Text- s- .map((caption, index) => {- return (- caption.text +- (caption.lineBreakAfter && index < s.length - 1 ? '\n' : '')- );- })- .join(''),+ s.map((caption) => caption.text).join(''),].join('\n');})- .filter(Boolean).join('\n\n');};diff --git a/packages/captions/src/test/ensure-max-characters.test.ts b/packages/captions/src/test/ensure-max-characters.test.tsindex 5477485c6a..099de3582c 100644--- a/packages/captions/src/test/ensure-max-characters.test.ts+++ b/packages/captions/src/test/ensure-max-characters.test.ts@@ -184,14 +184,14 @@ test('Does not emit standalone whitespace captions', () => {});});-test('Preserves a forced line break on the final split word', () => {+test('Preserves a forced page break on the final split word', () => {const firstCaption: Caption = {confidence: 1,endMs: 1000,startMs: 0,text: ' Hello there',timestampMs: 500,- lineBreakAfter: true,+ pageBreakAfter: true,};const secondCaption: Caption = {confidence: 1,diff --git a/packages/captions/src/test/srt.test.ts b/packages/captions/src/test/srt.test.tsindex 4264070ba0..ac1db60338 100644--- a/packages/captions/src/test/srt.test.ts+++ b/packages/captions/src/test/srt.test.ts@@ -47,7 +47,7 @@ test('Should create captions', () => {expect(serialized).toEqual(input);});-test('Should serialize forced line breaks within an SRT cue', () => {+test('Should start a new SRT cue after a forced page break', () => {const serialized = serializeSrt({lines: [[@@ -57,7 +57,7 @@ test('Should serialize forced line breaks within an SRT cue', () => {endMs: 500,timestampMs: 250,confidence: 1,- lineBreakAfter: true,+ pageBreakAfter: true,},{text: 'Second line',@@ -71,6 +71,6 @@ test('Should serialize forced line breaks within an SRT cue', () => {});expect(serialized).toBe(- '1\n00:00:00,000 --> 00:00:01,000\nFirst line\nSecond line',+ '1\n00:00:00,000 --> 00:00:00,500\nFirst line\n\n2\n00:00:00,500 --> 00:00:01,000\nSecond line',);});diff --git a/packages/captions/src/test/tiktok.test.ts b/packages/captions/src/test/tiktok.test.tsindex 2bf77bd6cb..78caffda6c 100644--- a/packages/captions/src/test/tiktok.test.ts+++ b/packages/captions/src/test/tiktok.test.ts@@ -76,7 +76,7 @@ test('Should create captions', () => {]);});-test('Should start a new page after a forced line break', () => {+test('Should start a new page after a forced page break', () => {const {pages} = createTikTokStyleCaptions({captions: [{@@ -85,7 +85,7 @@ test('Should start a new page after a forced line break', () => {endMs: 200,timestampMs: 100,confidence: null,- lineBreakAfter: true,+ pageBreakAfter: true,},{text: ' there',@@ -108,7 +108,7 @@ test('Should start a new page after a forced line break', () => {text: 'hello',fromMs: 0,toMs: 200,- lineBreakAfter: true,+ pageBreakAfter: true,},],},diff --git a/packages/convert/app/components/transcribe/display.tsx b/packages/convert/app/components/transcribe/display.tsxindex ed240fa858..01fe3f4405 100644--- a/packages/convert/app/components/transcribe/display.tsx+++ b/packages/convert/app/components/transcribe/display.tsx@@ -1,7 +1,7 @@/* eslint-disable react/no-array-index-key */import type {Caption} from '@remotion/captions';import {Switch} from '@remotion/design';-import {Fragment, useEffect, useMemo, useRef, useState} from 'react';+import {useEffect, useMemo, useRef, useState} from 'react';import {Card} from '../ui/card';const SingleToken: React.FC<{@@ -95,16 +95,14 @@ export default function Display({}return (- <Fragment key={`${c.text}-${c.startMs}-${index}`}>- <span- data-active={time * 1000 >= c.startMs}- data-last-active={index === lastActiveIndex}- className="data-[active=true]:font-bold data-[last-active=true]:text-brand"- >- {c.text}- </span>- {c.lineBreakAfter && index < result.length - 1 ? <br /> : null}- </Fragment>+ <span+ key={`${c.text}-${c.startMs}-${index}`}+ data-active={time * 1000 >= c.startMs}+ data-last-active={index === lastActiveIndex}+ className="data-[active=true]:font-bold data-[last-active=true]:text-brand"+ >+ {c.text}+ </span>);})}</div>diff --git a/packages/docs/docs/captions/caption.mdx b/packages/docs/docs/captions/caption.mdxindex 9d1e4ba26f..c5e6e36469 100644--- a/packages/docs/docs/captions/caption.mdx+++ b/packages/docs/docs/captions/caption.mdx@@ -55,13 +55,13 @@ _number | null_A number between 0 and 1 that indicates how confident the transcription is, or `null` if no confidence value is available.-### `lineBreakAfter?`<AvailableFrom v="4.0.517" />+### `pageBreakAfter?`<AvailableFrom v="4.0.517" />_boolean_-When `true`, forces a break after this caption.+When `true`, forces a page break after this caption.-[`createTikTokStyleCaptions()`](/docs/captions/create-tiktok-style-captions) ends the current page after this caption, so the next caption starts a new page. Other consumers, such as [`serializeSrt()`](/docs/captions/serialize-srt), may represent the break as a newline.+[`createTikTokStyleCaptions()`](/docs/captions/create-tiktok-style-captions) ends the current page after this caption, so the next caption starts a new page. [`serializeSrt()`](/docs/captions/serialize-srt) starts a new subtitle cue.This field does not change caption timing. When it is `false` or omitted, page breaks are determined automatically.diff --git a/packages/docs/docs/captions/create-tiktok-style-captions.mdx b/packages/docs/docs/captions/create-tiktok-style-captions.mdxindex e5d1c7d714..ab5793df3e 100644--- a/packages/docs/docs/captions/create-tiktok-style-captions.mdx+++ b/packages/docs/docs/captions/create-tiktok-style-captions.mdx@@ -135,9 +135,9 @@ A page consists of:- `text`: The text of the token.- `fromMs`: The absolute start time of the token in milliseconds.- `toMs`: The absolute end time of the token in milliseconds.- - `lineBreakAfter`: Whether the source caption forced the page to end after this token (_from v4.0.517_).+ - `pageBreakAfter`: Whether the source caption forced the page to end after this token (_from v4.0.517_).-If a [`Caption`](/docs/captions/caption) has `lineBreakAfter: true`, the current page ends after the corresponding token and the next caption starts a new page. The token preserves the marker, while the page's `text` does not include a trailing newline.+If a [`Caption`](/docs/captions/caption) has `pageBreakAfter: true`, the current page ends after the corresponding token and the next caption starts a new page. The token preserves the marker, while the page's `text` does not include a trailing newline.## Whitespace sensitivitydiff --git a/packages/docs/docs/captions/displaying.mdx b/packages/docs/docs/captions/displaying.mdxindex 1c7fa759dc..77e6875070 100644--- a/packages/docs/docs/captions/displaying.mdx+++ b/packages/docs/docs/captions/displaying.mdx@@ -72,6 +72,8 @@ const {pages} = useMemo(() => {}, [captions]);```+If a caption has `pageBreakAfter: true`, the current page ends after that caption and the next caption starts a new page.+## Rendering with SequencesMap over the pages and render each one in a [`<Sequence>`](/docs/sequence). Calculate the start frame and duration from the page timing:diff --git a/packages/docs/docs/captions/ensure-max-characters-per-line.mdx b/packages/docs/docs/captions/ensure-max-characters-per-line.mdxindex 82bb7d3f38..a287fb58aa 100644--- a/packages/docs/docs/captions/ensure-max-characters-per-line.mdx+++ b/packages/docs/docs/captions/ensure-max-characters-per-line.mdx@@ -8,7 +8,7 @@ crumb: '@remotion/captions'This is an internal, undocumented API for now.-Captions with `lineBreakAfter: true` always end the current segment, even if the segment has not reached the maximum number of characters.+Captions with `pageBreakAfter: true` always end the current segment, even if the segment has not reached the maximum number of characters.## See alsodiff --git a/packages/docs/docs/captions/exporting.mdx b/packages/docs/docs/captions/exporting.mdxindex 1b16226027..44f9df3eb2 100644--- a/packages/docs/docs/captions/exporting.mdx+++ b/packages/docs/docs/captions/exporting.mdx@@ -92,7 +92,7 @@ const srtContent = serializeSrt({endMs: token.toMs,timestampMs: (token.fromMs + token.toMs) / 2,confidence: null,- lineBreakAfter: token.lineBreakAfter,+ pageBreakAfter: token.pageBreakAfter,}));}),});diff --git a/packages/docs/docs/captions/serialize-srt.mdx b/packages/docs/docs/captions/serialize-srt.mdxindex 75a15be0e3..80f1cb64c8 100644--- a/packages/docs/docs/captions/serialize-srt.mdx+++ b/packages/docs/docs/captions/serialize-srt.mdx@@ -58,15 +58,15 @@ You can use SRT files to add subtitles to your videos.### `lines`-An two-dimensional array of [`Caption`](/docs/captions/caption) items.+A two-dimensional array of [`Caption`](/docs/captions/caption) items.-Each top-level item represents a line in the SubRip file.+Each top-level item represents a subtitle cue in the SubRip file.-The second-level items represent the words in that line.-Words get concatenated together during serialization. No spaces are added between the words.-If a word has `lineBreakAfter: true`, a newline is inserted after it unless it is the final word in the subtitle cue.-The start timestamp is determined from the `startMs` value of the first word in the line.-The end timestamp is determined from the `endMs` value of the last word in the line.+The second-level items represent the words in that cue.+Words get concatenated together during serialization. No spaces are added between the words.+If a word has `pageBreakAfter: true`, the current cue ends after it and the next word starts a new cue. Use a newline in `text` to create multiple visual lines within one cue.+The start timestamp is determined from the `startMs` value of the first word in the cue.+The end timestamp is determined from the `endMs` value of the last word in the cue.Arrays with no items will be ignored.diff --git a/packages/docs/docs/interactivity-schema.mdx b/packages/docs/docs/interactivity-schema.mdxindex 379070a581..5c02ccded9 100644--- a/packages/docs/docs/interactivity-schema.mdx+++ b/packages/docs/docs/interactivity-schema.mdx@@ -119,7 +119,7 @@ Shows a list of values. Array fields are not keyframable.Marks a prop containing [`Caption[]`](/docs/captions/caption) data for the captions inspector. Caption fields are not keyframable.-The inspector can edit caption text and toggle [`lineBreakAfter`](/docs/captions/caption#linebreakafter) for each caption.+The inspector can edit caption text and toggle [`pageBreakAfter`](/docs/captions/caption#pagebreakafter) for each caption.### `rotation-css`diff --git a/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx b/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsxindex 0c0037d157..cffc69a941 100644--- a/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx+++ b/packages/docs/elements/captions/moving-pill-captions/moving-pill-captions.tsx@@ -337,9 +337,6 @@ const CaptionPage: React.FC<{{visibleText}</span>{trailingWhitespace}- {token.lineBreakAfter && tokenIndex < page.tokens.length - 1 ? (- <br />- ) : null}</React.Fragment>);})}diff --git a/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx b/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsxindex 6a5b90e19e..c73e077110 100644--- a/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx+++ b/packages/docs/elements/captions/popping-word-captions/popping-word-captions.tsx@@ -247,9 +247,6 @@ const CaptionPage: React.FC<{{visibleText}</span>{trailingWhitespace}- {token.lineBreakAfter && tokenIndex < page.tokens.length - 1 ? (- <br />- ) : null}</React.Fragment>);})}diff --git a/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx b/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsxindex eb92e9dbb5..adac3d873b 100644--- a/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx+++ b/packages/docs/elements/captions/word-highlight-captions/word-highlight-captions.tsx@@ -206,9 +206,6 @@ const CaptionPage: React.FC<{{visibleText}</span>{trailingWhitespace}- {token.lineBreakAfter && tokenIndex < page.tokens.length - 1 ? (- <br />- ) : null}</React.Fragment>);})}diff --git a/packages/example/e2e/captions-inspector.test.mts b/packages/example/e2e/captions-inspector.test.mtsindex 1a06792474..4431cb3c56 100644--- a/packages/example/e2e/captions-inspector.test.mts+++ b/packages/example/e2e/captions-inspector.test.mts@@ -26,7 +26,7 @@ test.describe('captions inspector', () => {fs.writeFileSync(inlineCaptionsFile, sourceBefore);});- test('persists a forced line break to an inline caption', async ({page}) => {+ test('persists a forced page break to an inline caption', async ({page}) => {await page.goto(`${STUDIO_URL}/captions-inspector-e2e`);await expect(page).toHaveURL(/captions-inspector-e2e/, {timeout: 15_000});await page.waitForFunction(@@ -37,23 +37,23 @@ test.describe('captions inspector', () => {const captionsSequence = page.getByText('<AnimatedCaptions>', {exact: true}).first();- const lineBreakAfterFirstCaption = page.getByRole('button', {- name: 'Add line break after caption 1',+ const pageBreakAfterFirstCaption = page.getByRole('button', {+ name: 'Add page break after caption 1',exact: true,});await expect(async () => {await captionsSequence.click();- await expect(lineBreakAfterFirstCaption).toBeVisible({timeout: 1_000});+ await expect(pageBreakAfterFirstCaption).toBeVisible({timeout: 1_000});}).toPass({timeout: 30_000});- await expect(lineBreakAfterFirstCaption).toHaveAttribute(+ await expect(pageBreakAfterFirstCaption).toHaveAttribute('aria-pressed','false',);- await lineBreakAfterFirstCaption.click();+ await pageBreakAfterFirstCaption.click();await expect(page.getByRole('button', {- name: 'Remove line break after caption 1',+ name: 'Remove page break after caption 1',exact: true,}),).toHaveAttribute('aria-pressed', 'true');@@ -61,7 +61,7 @@ test.describe('captions inspector', () => {.poll(() => {return fs.readFileSync(inlineCaptionsFile, 'utf-8')- .includes('lineBreakAfter: true');+ .includes('pageBreakAfter: true');}).toBe(true);});diff --git a/packages/example/src/CaptionsTester/AnimatedCaptions.tsx b/packages/example/src/CaptionsTester/AnimatedCaptions.tsxindex f0b0b10217..d8ab890953 100644--- a/packages/example/src/CaptionsTester/AnimatedCaptions.tsx+++ b/packages/example/src/CaptionsTester/AnimatedCaptions.tsx@@ -92,26 +92,20 @@ const CaptionPage: React.FC<{page: TikTokPage}> = ({page}) => {{page.tokens.map((token, tokenIndex) => {const isActive =token.fromMs <= absoluteTimeMs && token.toMs > absoluteTimeMs;- const startsLine =- tokenIndex === 0 || page.tokens[tokenIndex - 1]?.lineBreakAfter;return (- <React.Fragment key={`${token.fromMs}-${tokenIndex}`}>- <span- style={{- color: isActive ? HIGHLIGHT_COLOR : '#ffffff',- display: 'inline-block',- marginLeft: startsLine ? 0 : 26,- WebkitTextStroke: isActive- ? '3px rgba(0, 20, 28, 0.95)'- : '2px rgba(0, 0, 0, 0.85)',- }}- >- {token.text.trimStart()}- </span>- {token.lineBreakAfter && tokenIndex < page.tokens.length - 1 ? (- <br />- ) : null}- </React.Fragment>+ <span+ key={`${token.fromMs}-${tokenIndex}`}+ style={{+ color: isActive ? HIGHLIGHT_COLOR : '#ffffff',+ display: 'inline-block',+ marginLeft: tokenIndex === 0 ? 0 : 26,+ WebkitTextStroke: isActive+ ? '3px rgba(0, 20, 28, 0.95)'+ : '2px rgba(0, 0, 0, 0.85)',+ }}+ >+ {token.text.trimStart()}+ </span>);})}</div>diff --git a/packages/example/src/Compose/Captions.tsx b/packages/example/src/Compose/Captions.tsxindex dd772131c8..356f652cf6 100644--- a/packages/example/src/Compose/Captions.tsx+++ b/packages/example/src/Compose/Captions.tsx@@ -15,8 +15,7 @@ import {const Token: React.FC<{token: TikTokToken;pageStart: number;- isLast: boolean;-}> = ({token, pageStart, isLast}) => {+}> = ({token, pageStart}) => {const frame = useCurrentFrame();const {fps} = useVideoConfig();const start = ((token.fromMs - pageStart) / 1000) * 30;@@ -53,13 +52,10 @@ const Token: React.FC<{}, [active, jump]);return (- <>- <span>- {' '}- <span style={style}>{token.text.trim()}</span>- </span>- {token.lineBreakAfter && !isLast ? <br /> : null}- </>+ <span>+ {' '}+ <span style={style}>{token.text.trim()}</span>+ </span>);};@@ -100,14 +96,9 @@ export const Captions: React.FC = () => {key={page.startMs}><div key={page.startMs}>- {page.tokens.map((t, index) => {+ {page.tokens.map((t) => {return (- <Token- pageStart={page.startMs}- key={t.fromMs}- token={t}- isLast={index === page.tokens.length - 1}- />+ <Token pageStart={page.startMs} key={t.fromMs} token={t} />);})}</div>diff --git a/packages/jonnys-videos/src/components/AnimatedCaptions.tsx b/packages/jonnys-videos/src/components/AnimatedCaptions.tsxindex e9ed7d3e58..39838c8afb 100644--- a/packages/jonnys-videos/src/components/AnimatedCaptions.tsx+++ b/packages/jonnys-videos/src/components/AnimatedCaptions.tsx@@ -153,39 +153,33 @@ const CaptionPage: React.FC<CaptionPageProps> = ({}}>{page.tokens.map((token, tokenIndex) => {- const startsLine =- tokenIndex === 0 || page.tokens[tokenIndex - 1]?.lineBreakAfter;return (- <React.Fragment key={`${token.fromMs}-${tokenIndex}`}>- <span- ref={(element) => {- wordRefs.current[tokenIndex] = element;- }}- style={{- color:- tokenIndex === focusedTokenIndex+ <span+ key={`${token.fromMs}-${tokenIndex}`}+ ref={(element) => {+ wordRefs.current[tokenIndex] = element;+ }}+ style={{+ color:+ tokenIndex === focusedTokenIndex+ ? interpolateColors(+ focusProgress,+ [0, 1],+ ['#d9d9d9', '#ffffff'],+ )+ : tokenIndex === focusedTokenIndex - 1? interpolateColors(focusProgress,[0, 1],- ['#d9d9d9', '#ffffff'],+ ['#ffffff', '#d9d9d9'],)- : tokenIndex === focusedTokenIndex - 1- ? interpolateColors(- focusProgress,- [0, 1],- ['#ffffff', '#d9d9d9'],- )- : '#d9d9d9',- display: 'inline-block',- marginLeft: startsLine ? 0 : 26,- }}- >- {token.text.trimStart()}- </span>- {token.lineBreakAfter && tokenIndex < page.tokens.length - 1 ? (- <br />- ) : null}- </React.Fragment>+ : '#d9d9d9',+ display: 'inline-block',+ marginLeft: tokenIndex === 0 ? 0 : 26,+ }}+ >+ {token.text.trimStart()}+ </span>);})}</div>diff --git a/packages/jonnys-videos/src/components/paginate-captions.test.ts b/packages/jonnys-videos/src/components/paginate-captions.test.tsindex fdfefa0315..fdca03a9ff 100644--- a/packages/jonnys-videos/src/components/paginate-captions.test.ts+++ b/packages/jonnys-videos/src/components/paginate-captions.test.ts@@ -2,7 +2,7 @@ import {expect, test} from 'bun:test';import type {Caption} from '@remotion/captions';import {createSentenceAwareCaptionPages} from './paginate-captions';-test('treats a forced line break as a page boundary', () => {+test('treats a forced page break as a page boundary', () => {const captions = [{text: 'This',@@ -17,7 +17,7 @@ test('treats a forced line break as a page boundary', () => {endMs: 400,timestampMs: 300,confidence: null,- lineBreakAfter: true,+ pageBreakAfter: true,},{text: ' start',diff --git a/packages/jonnys-videos/src/components/paginate-captions.ts b/packages/jonnys-videos/src/components/paginate-captions.tsindex 0724c159ac..135000e6b1 100644--- a/packages/jonnys-videos/src/components/paginate-captions.ts+++ b/packages/jonnys-videos/src/components/paginate-captions.ts@@ -180,7 +180,7 @@ const splitIntoPageGroups = (captions: Caption[]): Caption[][] => {for (const caption of captions) {pageGroup.push(caption);- if (SENTENCE_END.test(caption.text.trim()) || caption.lineBreakAfter) {+ if (SENTENCE_END.test(caption.text.trim()) || caption.pageBreakAfter) {pageGroups.push(pageGroup);pageGroup = [];}@@ -197,7 +197,7 @@ const toToken = (caption: Caption, isFirst: boolean): TikTokToken => ({text: isFirst ? caption.text.trimStart() : caption.text,fromMs: caption.startMs,toMs: caption.endMs,- ...(caption.lineBreakAfter ? {lineBreakAfter: true} : {}),+ ...(caption.pageBreakAfter ? {pageBreakAfter: true} : {}),});const rebalanceSentence = ({@@ -412,18 +412,15 @@ const rebalanceSentence = ({const endMs = nextCaption? nextCaption.startMs: pageCaptions[pageCaptions.length - 1].endMs;- const tokens = pageCaptions.map((caption, tokenIndex) => {- const startsLine =- tokenIndex === 0 || pageCaptions[tokenIndex - 1]?.lineBreakAfter;- return toToken(caption, Boolean(startsLine));- });+ const tokens = pageCaptions.map((caption, tokenIndex) =>+ toToken(caption, tokenIndex === 0),+ );pages.push({text: tokens- .map((token) => token.text + (token.lineBreakAfter ? '\n' : ''))+ .map((token) => token.text).join('')- .trimStart()- .replace(/\n$/, ''),+ .trimStart(),startMs,tokens,durationMs: endMs - startMs,@@ -436,7 +433,7 @@ const rebalanceSentence = ({};/**- * Never crosses a sentence or forced line break boundary. When layout+ * Never crosses a sentence or forced page break boundary. When layout* information is supplied, the page count is derived from rendered width and* a duration ceiling. Dynamic programming then chooses boundaries based on* line balance, timing and natural phrase boundaries. Without layoutdiff --git a/packages/skills/skills/remotion-captions/SKILL.md b/packages/skills/skills/remotion-captions/SKILL.mdindex aa245f24c6..2fb3a88274 100644--- a/packages/skills/skills/remotion-captions/SKILL.md+++ b/packages/skills/skills/remotion-captions/SKILL.md@@ -19,7 +19,7 @@ type Caption = {endMs: number;timestampMs: number | null;confidence: number | null;- lineBreakAfter?: boolean;+ pageBreakAfter?: boolean;};```diff --git a/packages/skills/skills/remotion-captions/display-captions.md b/packages/skills/skills/remotion-captions/display-captions.mdindex a28b7f907f..c720d0c58e 100644--- a/packages/skills/skills/remotion-captions/display-captions.md+++ b/packages/skills/skills/remotion-captions/display-captions.md@@ -84,7 +84,7 @@ const { pages } = useMemo(() => {}, [captions]);```-If a caption has `lineBreakAfter: true`, the current page ends after that caption and the next caption starts a new page.+If a caption has `pageBreakAfter: true`, the current page ends after that caption and the next caption starts a new page.## Rendering with Sequencesdiff --git a/packages/studio-codemods/src/update-inline-caption-patches.ts b/packages/studio-codemods/src/update-inline-caption-patches.tsindex 6507655c79..619f0ce474 100644--- a/packages/studio-codemods/src/update-inline-caption-patches.ts+++ b/packages/studio-codemods/src/update-inline-caption-patches.ts@@ -10,7 +10,7 @@ const captionKeys = ['endMs','timestampMs','confidence',- 'lineBreakAfter',+ 'pageBreakAfter',] as const;type CaptionKey = (typeof captionKeys)[number];@@ -66,14 +66,14 @@ const getStaticCaption = (expression: ObjectExpression): StaticCaption => {const endMs = values.get('endMs');const timestampMs = values.get('timestampMs');const confidence = values.get('confidence');- const lineBreakAfter = values.get('lineBreakAfter');+ const pageBreakAfter = values.get('pageBreakAfter');if (typeof text !== 'string' ||typeof startMs !== 'number' ||typeof endMs !== 'number' ||(timestampMs !== null && typeof timestampMs !== 'number') ||(confidence !== null && typeof confidence !== 'number') ||- (lineBreakAfter !== undefined && typeof lineBreakAfter !== 'boolean')+ (pageBreakAfter !== undefined && typeof pageBreakAfter !== 'boolean')) {throw new Error('Captions must have the standard static caption shape to edit',@@ -86,7 +86,7 @@ const getStaticCaption = (expression: ObjectExpression): StaticCaption => {endMs,timestampMs,confidence,- ...(typeof lineBreakAfter === 'boolean' ? {lineBreakAfter} : {}),+ pageBreakAfter: pageBreakAfter ?? null,};};@@ -288,7 +288,7 @@ const updateCaption = ({((key === 'timestampMs' || key === 'confidence') &&value !== null &&(typeof value !== 'number' || !Number.isFinite(value))) ||- (key === 'lineBreakAfter' && typeof value !== 'boolean')+ (key === 'pageBreakAfter' && typeof value !== 'boolean')) {throw new Error(`Caption ${key} has an invalid value`);}@@ -301,7 +301,7 @@ const updateCaption = ({);});if (!property || property.type !== 'ObjectProperty') {- if (key === 'lineBreakAfter' && typeof value === 'boolean') {+ if (key === 'pageBreakAfter' && typeof value === 'boolean') {replacements.push(...getPropertyInsertionReplacements({input,diff --git a/packages/studio-server/src/test/save-sequence-props.test.ts b/packages/studio-server/src/test/save-sequence-props.test.tsindex 8b44e0c84a..79df6618a3 100644--- a/packages/studio-server/src/test/save-sequence-props.test.ts+++ b/packages/studio-server/src/test/save-sequence-props.test.ts@@ -275,8 +275,9 @@ test('saveSequenceProps saves inline caption patches as an undoable source edit'endMs: 1000,timestampMs: 500,confidence: null,+ pageBreakAfter: null,},- changes: {text: 'Updated', lineBreakAfter: true},+ changes: {text: 'Updated', pageBreakAfter: true},},],},@@ -305,7 +306,7 @@ test('saveSequenceProps saves inline caption patches as an undoable source edit'});expect(readFileSync(filePath, 'utf-8')).toContain("text: 'Updated'");- expect(readFileSync(filePath, 'utf-8')).toContain('lineBreakAfter: true');+ expect(readFileSync(filePath, 'utf-8')).toContain('pageBreakAfter: true');expect(getUndoStack()).toHaveLength(1);expect(getUndoStack()[0]?.suppressHmrOnFileRestore).toBe(false);diff --git a/packages/studio-server/src/test/update-inline-caption-patches.test.ts b/packages/studio-server/src/test/update-inline-caption-patches.test.tsindex e8f3e05f69..84deb2990e 100644--- a/packages/studio-server/src/test/update-inline-caption-patches.test.ts+++ b/packages/studio-server/src/test/update-inline-caption-patches.test.ts@@ -42,6 +42,7 @@ test('updates only the patched inline caption fields', () => {endMs: 2000,text: 'Second',timestampMs: 1500,+ pageBreakAfter: null,},changes: {startMs: 1100, endMs: 2100},},@@ -57,7 +58,7 @@ test('updates only the patched inline caption fields', () => {);});-test('adds and updates lineBreakAfter on inline captions', () => {+test('adds and updates pageBreakAfter on inline captions', () => {const added = updateInlineCaptionPatches({input,nodePath: lineColumnToNodePath(input, 5),@@ -70,15 +71,16 @@ test('adds and updates lineBreakAfter on inline captions', () => {endMs: 1000,timestampMs: 500,confidence: null,+ pageBreakAfter: null,},- changes: {lineBreakAfter: true},+ changes: {pageBreakAfter: true},},],});- expect(added.changedFields).toEqual([['lineBreakAfter']]);+ expect(added.changedFields).toEqual([['pageBreakAfter']]);expect(added.output).toContain(- '\t\t\t\t\tconfidence: null,\n\t\t\t\t\tlineBreakAfter: true,',+ '\t\t\t\t\tconfidence: null,\n\t\t\t\t\tpageBreakAfter: true,',);const updated = updateInlineCaptionPatches({@@ -93,17 +95,17 @@ test('adds and updates lineBreakAfter on inline captions', () => {endMs: 1000,timestampMs: 500,confidence: null,- lineBreakAfter: true,+ pageBreakAfter: true,},- changes: {lineBreakAfter: false},+ changes: {pageBreakAfter: false},},],});- expect(updated.output).toContain('lineBreakAfter: false,');+ expect(updated.output).toContain('pageBreakAfter: false,');});-test('adds lineBreakAfter to a single-line inline caption', () => {+test('adds pageBreakAfter to a single-line inline caption', () => {const singleLineInput = `export const Example = () => {return <TimedCaptions captions={[{text: 'First', startMs: 0, endMs: 1000, timestampMs: 500, confidence: null}]} />;};@@ -120,13 +122,14 @@ test('adds lineBreakAfter to a single-line inline caption', () => {endMs: 1000,timestampMs: 500,confidence: null,+ pageBreakAfter: null,},- changes: {lineBreakAfter: true},+ changes: {pageBreakAfter: true},},],});- expect(output).toContain('confidence: null, lineBreakAfter: true}]}');+ expect(output).toContain('confidence: null, pageBreakAfter: true}]}');});test('rejects a queued patch whose source caption has changed', () => {@@ -143,6 +146,7 @@ test('rejects a queued patch whose source caption has changed', () => {endMs: 1000,timestampMs: 500,confidence: null,+ pageBreakAfter: null,},changes: {endMs: 900},},@@ -170,6 +174,7 @@ test('rejects captions wrapped in a satisfies expression', () => {endMs: 1000,timestampMs: 500,confidence: null,+ pageBreakAfter: null,},changes: {text: 'Updated'},},diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.tsindex 78a584fa6d..d0e5ef8c33 100644--- a/packages/studio-shared/src/api-requests.ts+++ b/packages/studio-shared/src/api-requests.ts@@ -410,7 +410,7 @@ export type CaptionPatch = {endMs: number;timestampMs: number | null;confidence: number | null;- lineBreakAfter?: boolean;+ pageBreakAfter: boolean | null;};changes: Partial<{text: string;@@ -418,7 +418,7 @@ export type CaptionPatch = {endMs: number;timestampMs: number | null;confidence: number | null;- lineBreakAfter: boolean;+ pageBreakAfter: boolean;}>;};diff --git a/packages/studio/src/components/CaptionTextEditor.tsx b/packages/studio/src/components/CaptionTextEditor.tsxindex 9798004d35..346567b81e 100644--- a/packages/studio/src/components/CaptionTextEditor.tsx+++ b/packages/studio/src/components/CaptionTextEditor.tsx@@ -101,7 +101,7 @@ export const CaptionTextEditor: React.FC<{const updateCaption = useCallback((index: number,- changes: Partial<Pick<Caption, 'text' | 'lineBreakAfter'>>,+ changes: Partial<Pick<Caption, 'text' | 'pageBreakAfter'>>,) => {const currentCaption = latestRef.current.captions[index];if (!currentCaption) {@@ -131,16 +131,16 @@ export const CaptionTextEditor: React.FC<{[updateCaption],);- const updateLineBreakAfter = useCallback(- (index: number, lineBreakAfter: boolean) => {+ const updatePageBreakAfter = useCallback(+ (index: number, pageBreakAfter: boolean) => {if (- Boolean(latestRef.current.captions[index]?.lineBreakAfter) ===- lineBreakAfter+ Boolean(latestRef.current.captions[index]?.pageBreakAfter) ===+ pageBreakAfter) {return;}- updateCaption(index, {lineBreakAfter});+ updateCaption(index, {pageBreakAfter});},[updateCaption],);@@ -158,10 +158,10 @@ export const CaptionTextEditor: React.FC<{<div ref={listRef} style={list}>{captions.length === 0 ? <div style={empty}>No captions</div> : null}{captionRows.map(({caption, key}, index) => {- const hasLineBreakAfter = Boolean(caption.lineBreakAfter);- const lineBreakTitle = hasLineBreakAfter- ? `Remove line break after caption ${index + 1}`- : `Add line break after caption ${index + 1}`;+ const hasPageBreakAfter = Boolean(caption.pageBreakAfter);+ const pageBreakTitle = hasPageBreakAfter+ ? `Remove page break after caption ${index + 1}`+ : `Add page break after caption ${index + 1}`;return (<div key={key} style={row}>@@ -215,22 +215,22 @@ export const CaptionTextEditor: React.FC<{value={caption.text}/><InlineAction- aria-pressed={hasLineBreakAfter}+ aria-pressed={hasPageBreakAfter}className={FOCUS_VISIBLE_ONLY_CLASS_NAME}disabled={readOnly}onClick={() => {- updateLineBreakAfter(index, !hasLineBreakAfter);+ updatePageBreakAfter(index, !hasPageBreakAfter);commitPending();}}renderAction={(color) => (<EnterIconaria-hidden="true"- color={hasLineBreakAfter ? BLUE : color}+ color={hasPageBreakAfter ? BLUE : color}focusable="false"style={{height: 16, width: 16}}/>)}- title={lineBreakTitle}+ title={pageBreakTitle}variant={null}/></div>diff --git a/packages/studio/src/components/InlineCaptionInspector.tsx b/packages/studio/src/components/InlineCaptionInspector.tsxindex c26b032a3f..2591d1fc1e 100644--- a/packages/studio/src/components/InlineCaptionInspector.tsx+++ b/packages/studio/src/components/InlineCaptionInspector.tsx@@ -44,12 +44,19 @@ const getCaptionPatches = ({changes.text = after.text;}- if (Boolean(before.lineBreakAfter) !== Boolean(after.lineBreakAfter)) {- changes.lineBreakAfter = Boolean(after.lineBreakAfter);+ if (Boolean(before.pageBreakAfter) !== Boolean(after.pageBreakAfter)) {+ changes.pageBreakAfter = Boolean(after.pageBreakAfter);}if (Object.keys(changes).length > 0) {- patches.push({index, before, changes});+ patches.push({+ index,+ before: {+ ...before,+ pageBreakAfter: before.pageBreakAfter ?? null,+ },+ changes,+ });}}diff --git a/packages/template-audiogram/src/Audiogram/get-number-of-lines-for-text.ts b/packages/template-audiogram/src/Audiogram/get-number-of-lines-for-text.tsindex 35fff6b39b..091994c71a 100644--- a/packages/template-audiogram/src/Audiogram/get-number-of-lines-for-text.ts+++ b/packages/template-audiogram/src/Audiogram/get-number-of-lines-for-text.ts@@ -24,8 +24,8 @@ export const layoutText = ({for (const [index, caption] of captions.entries()) {const isFirstCaption = index === 0;const previousCaption = captions[index - 1];- const forcedLineBreak = Boolean(previousCaption?.lineBreakAfter);- if (forcedLineBreak) {+ const startsNewPage = Boolean(previousCaption?.pageBreakAfter);+ if (startsNewPage) {lines.push([]);box = fillTextBox({maxBoxWidth: textBoxWidth,@@ -34,7 +34,7 @@ export const layoutText = ({}const { newLine } = box.add({text:- isFirstCaption || forcedLineBreak+ isFirstCaption || startsNewPage? caption.text.trimStart(): caption.text,fontFamily,@@ -46,7 +46,7 @@ export const layoutText = ({}const newCaption = { ...caption };- if (newLine || isFirstCaption || forcedLineBreak) {+ if (newLine || isFirstCaption || startsNewPage) {newCaption.text = newCaption.text.trimStart();box.add({text: " ".repeat(caption.text.length - newCaption.text.length),@@ -74,6 +74,14 @@ export const filterCurrentlyDisplayedLines = ({});});+ const lastPageBreak = currentlyActiveLines.findLastIndex((line, index) => {+ return (+ index < currentlyActiveLines.length - 1 &&+ Boolean(line.at(-1)?.pageBreakAfter)+ );+ });+ const currentPageLines = currentlyActiveLines.slice(lastPageBreak + 1);+// Return the last 4 lines- return currentlyActiveLines.slice(-LINES_PER_PAGE);+ return currentPageLines.slice(-LINES_PER_PAGE);};diff --git a/packages/template-recorder/remotion/captions/boxed/components/SquareSubtitles.tsx b/packages/template-recorder/remotion/captions/boxed/components/SquareSubtitles.tsxindex a36bbc6a5e..1638773808 100644--- a/packages/template-recorder/remotion/captions/boxed/components/SquareSubtitles.tsx+++ b/packages/template-recorder/remotion/captions/boxed/components/SquareSubtitles.tsx@@ -1,4 +1,4 @@-import React, { Fragment, useMemo } from "react";+import React, { useMemo } from "react";import type { Theme } from "../../../../config/themes";import { getHorizontalPaddingForSubtitles } from "../../processing/layout-captions";import type { CaptionPage } from "../../types";@@ -37,17 +37,13 @@ export const SquareSubtitles: React.FC<{<span style={style}>{segment.captions.map((caption, index) => {return (- <Fragment key={caption.startMs + caption.text + index}>- <BoxedSingleCaption- isLast={index === segment.captions.length - 1}- caption={caption}- theme={theme}- startFrame={startFrame}- />- {caption.lineBreakAfter && index < segment.captions.length - 1 ? (- <br />- ) : null}- </Fragment>+ <BoxedSingleCaption+ key={caption.startMs + caption.text + index}+ isLast={index === segment.captions.length - 1}+ caption={caption}+ theme={theme}+ startFrame={startFrame}+ />);})}</span>diff --git a/packages/template-recorder/remotion/captions/processing/fix-backticks.ts b/packages/template-recorder/remotion/captions/processing/fix-backticks.tsindex a97beb0509..a8d83f5d84 100644--- a/packages/template-recorder/remotion/captions/processing/fix-backticks.ts+++ b/packages/template-recorder/remotion/captions/processing/fix-backticks.ts@@ -14,7 +14,7 @@ export const fixBackticks = (_captions: Caption[]): Caption[] => {const caption = captions[i] as Caption;const previousCaption = captions[i - 1] ?? null;- if (caption.text.startsWith(". ") && !previousCaption?.lineBreakAfter) {+ if (caption.text.startsWith(". ") && !previousCaption?.pageBreakAfter) {const lastAddedCaption = newCaptions[newCaptions.length - 1] as Caption;lastAddedCaption.text += ".";caption.text = caption.text.slice(1);@@ -23,13 +23,13 @@ export const fixBackticks = (_captions: Caption[]): Caption[] => {if (!caption.text.startsWith(" ") &&previousCaption &&- !previousCaption.lineBreakAfter+ !previousCaption.pageBreakAfter) {const lastAddedCaption = newCaptions[newCaptions.length - 1] as Caption;lastAddedCaption.text += caption.text;lastAddedCaption.endMs = caption.endMs;- if (caption.lineBreakAfter) {- lastAddedCaption.lineBreakAfter = true;+ if (caption.pageBreakAfter) {+ lastAddedCaption.pageBreakAfter = true;}} else {newCaptions.push(caption);diff --git a/packages/template-recorder/remotion/captions/processing/layout-captions.ts b/packages/template-recorder/remotion/captions/processing/layout-captions.tsindex 34f771644a..d8fa4cde83 100644--- a/packages/template-recorder/remotion/captions/processing/layout-captions.ts+++ b/packages/template-recorder/remotion/captions/processing/layout-captions.ts@@ -81,16 +81,15 @@ const cutCaptions = ({}): CaptionPage[] => {let textBox = fillTextBox({ maxBoxWidth: boxWidth, maxLines });let captionsFitted = 0;- let linesUsed = 1;- for (const [index, caption] of captions.entries()) {+ for (const caption of captions) {const { fontFamily, fontWeight, ...additionalStyles } = isCaptionMonospace(caption,)? MONOSPACE_FONT: REGULAR_FONT;- const { exceedsBox, newLine } = textBox.add({+ const { exceedsBox } = textBox.add({text: removeMonospaceTicks(caption).text,fontFamily: fontFamily as string,fontWeight: fontWeight as string,@@ -105,21 +104,6 @@ const cutCaptions = ({captionsFitted++;}- if (newLine) {- linesUsed++;- }-- if (caption.lineBreakAfter && index < captions.length - 1) {- linesUsed++;- if (linesUsed > maxLines) {- break;- }-- textBox = fillTextBox({- maxBoxWidth: boxWidth,- maxLines: maxLines - linesUsed + 1,- });- }}if (captionsFitted === captions.length) {@@ -150,14 +134,26 @@ export const layoutCaptions = ({maxLines: number;fontSize: number;}): LayoutedCaptions => {- const segments = cutCaptions({- captions: captions,- boxWidth:- boxWidth -- getHorizontalPaddingForSubtitles() * 2 -- getBorderWidthForSubtitles() * 2,- maxLines,- fontSize,+ const pageGroups: Caption[][] = [[]];++ for (const [index, caption] of captions.entries()) {+ pageGroups[pageGroups.length - 1]!.push(caption);++ if (caption.pageBreakAfter && index < captions.length - 1) {+ pageGroups.push([]);+ }+ }++ const segments = pageGroups.flatMap((pageCaptions) => {+ return cutCaptions({+ captions: pageCaptions,+ boxWidth:+ boxWidth -+ getHorizontalPaddingForSubtitles() * 2 -+ getBorderWidthForSubtitles() * 2,+ maxLines,+ fontSize,+ });});return {diff --git a/packages/template-recorder/remotion/captions/processing/split-caption-into-monospace-segments.ts b/packages/template-recorder/remotion/captions/processing/split-caption-into-monospace-segments.tsindex 43a607eb9e..99581caa10 100644--- a/packages/template-recorder/remotion/captions/processing/split-caption-into-monospace-segments.ts+++ b/packages/template-recorder/remotion/captions/processing/split-caption-into-monospace-segments.ts@@ -4,7 +4,7 @@ export const splitCaptionIntoMonospaceSegments = (caption: Caption,): Caption[] => {const result: Caption[] = [];- const { lineBreakAfter, ...captionWithoutLineBreak } = caption;+ const { pageBreakAfter, ...captionWithoutPageBreak } = caption;const regex = /`([^`]+)`/g; // regex pattern to find text enclosed in backtickslet lastIndex = 0;@@ -13,13 +13,13 @@ export const splitCaptionIntoMonospaceSegments = (while ((match = regex.exec(caption.text)) !== null) {if (match.index > lastIndex) {result.push({- ...captionWithoutLineBreak,+ ...captionWithoutPageBreak,text: caption.text.slice(lastIndex, match.index),});}result.push({- ...captionWithoutLineBreak,+ ...captionWithoutPageBreak,text: `${("`" + match[1]) as string}\``,});lastIndex = regex.lastIndex;@@ -27,14 +27,14 @@ export const splitCaptionIntoMonospaceSegments = (if (lastIndex < caption.text.length) {result.push({- ...captionWithoutLineBreak,+ ...captionWithoutPageBreak,text: caption.text.slice(lastIndex),});}const lastCaption = result[result.length - 1];- if (lineBreakAfter && lastCaption) {- lastCaption.lineBreakAfter = true;+ if (pageBreakAfter && lastCaption) {+ lastCaption.pageBreakAfter = true;}return result;diff --git a/packages/template-recorder/remotion/captions/srt/SrtPreviewAndEditor/SrtPreviewLine.tsx b/packages/template-recorder/remotion/captions/srt/SrtPreviewAndEditor/SrtPreviewLine.tsxindex 3ea5c99630..90de2843a4 100644--- a/packages/template-recorder/remotion/captions/srt/SrtPreviewAndEditor/SrtPreviewLine.tsx+++ b/packages/template-recorder/remotion/captions/srt/SrtPreviewAndEditor/SrtPreviewLine.tsx@@ -1,4 +1,4 @@-import React, { Fragment } from "react";+import React from "react";import { UnserializedSrt } from "../helpers/serialize-srt";import { SrtSingleCaption } from "./SingleCaption";@@ -32,12 +32,10 @@ export const SrtPreviewLine: React.FC<{<div style={inner}>{segment.captions.map((caption, index) => {return (- <Fragment key={caption.startMs}>- <SrtSingleCaption caption={caption}></SrtSingleCaption>- {caption.lineBreakAfter && index < segment.captions.length - 1 ? (- <br />- ) : null}- </Fragment>+ <SrtSingleCaption+ key={`${caption.startMs}-${index}`}+ caption={caption}+ />);})}</div>diff --git a/packages/template-recorder/remotion/captions/srt/helpers/calculate-srt.ts b/packages/template-recorder/remotion/captions/srt/helpers/calculate-srt.tsindex bf2f67fd35..9afd562b25 100644--- a/packages/template-recorder/remotion/captions/srt/helpers/calculate-srt.ts+++ b/packages/template-recorder/remotion/captions/srt/helpers/calculate-srt.ts@@ -32,9 +32,16 @@ const segmentCaptions = (caption: Caption[]) => {currentSegment = [];}currentSegment.push(w);++ if (w.pageBreakAfter && i < caption.length - 1) {+ segments.push(currentSegment);+ currentSegment = [];+ }}- segments.push(currentSegment);+ if (currentSegment.length > 0) {+ segments.push(currentSegment);+ }return segments;};@@ -86,11 +93,7 @@ export const calculateSrt = ({firstTimestampMs,lastTimestampMs,text: segment- .map((s, captionIndex) => {- const separator =- s.lineBreakAfter && captionIndex < segment.length - 1 ? "\n" : " ";- return s.text.trim() + separator;- })+ .map((s) => s.text.trim() + " ").join("").trim(),captions: segment,diff --git a/packages/template-recorder/tests/fix-backticks.test.ts b/packages/template-recorder/tests/fix-backticks.test.tsindex e70162ce0f..76e787b9df 100644--- a/packages/template-recorder/tests/fix-backticks.test.ts+++ b/packages/template-recorder/tests/fix-backticks.test.ts@@ -83,7 +83,7 @@ test("join captions correctly", () => {]);});-test("does not join captions across a forced line break", () => {+test("does not join captions across a forced page break", () => {const captions = fixBackticks([{text: " `dev`",@@ -91,7 +91,7 @@ test("does not join captions across a forced line break", () => {startMs: 0,confidence: null,timestampMs: 0,- lineBreakAfter: true,+ pageBreakAfter: true,},{text: ". It",@@ -109,7 +109,7 @@ test("does not join captions across a forced line break", () => {startMs: 0,confidence: null,timestampMs: 0,- lineBreakAfter: true,+ pageBreakAfter: true,},{text: ". It",diff --git a/packages/template-recorder/tests/make-monospace-captions.test.ts b/packages/template-recorder/tests/make-monospace-captions.test.tsindex 9982c64468..2e97a86ebb 100644--- a/packages/template-recorder/tests/make-monospace-captions.test.ts+++ b/packages/template-recorder/tests/make-monospace-captions.test.ts@@ -38,19 +38,19 @@ test("Should split up into monospace words", () => {]);});-test("preserves a forced line break on the final segment", () => {+test("preserves a forced page break on the final segment", () => {const caption: Caption = {text: "This is a `monospace` word",startMs: 0,endMs: 0,confidence: null,timestampMs: 0,- lineBreakAfter: true,+ pageBreakAfter: true,};const segments = splitCaptionIntoMonospaceSegments(caption);- expect(segments.map((segment) => segment.lineBreakAfter)).toEqual([+ expect(segments.map((segment) => segment.pageBreakAfter)).toEqual([undefined,undefined,true,diff --git a/packages/template-tiktok/src/CaptionedVideo/Page.tsx b/packages/template-tiktok/src/CaptionedVideo/Page.tsxindex 42537cdd59..a84908e461 100644--- a/packages/template-tiktok/src/CaptionedVideo/Page.tsx+++ b/packages/template-tiktok/src/CaptionedVideo/Page.tsx@@ -73,20 +73,16 @@ export const Page: React.FC<{endRelativeToSequence > timeInMs;return (- <React.Fragment key={`${t.fromMs}-${index}`}>- <span- style={{- display: "inline",- whiteSpace: "pre",- color: active ? HIGHLIGHT_COLOR : "white",- }}- >- {t.text}- </span>- {t.lineBreakAfter && index < page.tokens.length - 1 ? (- <br />- ) : null}- </React.Fragment>+ <span+ key={`${t.fromMs}-${index}`}+ style={{+ display: "inline",+ whiteSpace: "pre",+ color: active ? HIGHLIGHT_COLOR : "white",+ }}+ >+ {t.text}+ </span>);})}</span>