Skip to content

🎥 Make videos programmatically with React

Place caption styles at the bottom center like Basic captions

Igor Samokhovetse02a27cf1cf9
diff --git a/packages/codemods/src/insert-basic-captions.ts b/packages/codemods/src/insert-basic-captions.ts
index 903ab58776..216f55186d 100644
--- a/packages/codemods/src/insert-basic-captions.ts
+++ b/packages/codemods/src/insert-basic-captions.ts
@@ -227,6 +227,7 @@ export const insertBasicCaptions = ({
)
.join(formattingConfig.endOfLine);
} else {
+ const {style, ...initialProps} = element.initialProps ?? {};
const jsx = buildJsxElement({
ast,
element: createElementFromInsertable({
@@ -237,13 +238,22 @@ export const insertBasicCaptions = ({
importPath,
position: null,
props: [
- ...Object.entries(element.initialProps ?? {})
+ ...Object.entries(initialProps)
.filter(
([name]) => name !== 'captions' && !timingProps.includes(name),
)
.map(([name, value]) => ({name, value})),
{name: 'captions', value: captions},
...fallbackTimingProps,
+ {
+ name: 'style',
+ value: {
+ bottom: 120,
+ left: '50%',
+ transform: 'translateX(-50%)',
+ ...(typeof style === 'object' ? style : {}),
+ },
+ },
],
},
from: null,
diff --git a/packages/codemods/src/test/insert-basic-captions.test.ts b/packages/codemods/src/test/insert-basic-captions.test.ts
index ce30069ecc..f4a0f1f85a 100644
--- a/packages/codemods/src/test/insert-basic-captions.test.ts
+++ b/packages/codemods/src/test/insert-basic-captions.test.ts
@@ -55,7 +55,7 @@ export const Comp = (${parameter}) => {
? 'BasicCaptions3'
: 'BasicCaptions2';
expect(output).toContain(`BasicCaptions as ${alias}`);
- expect(output).toContain(`<${alias} captions={[]}`);
+ expect(output).toMatch(new RegExp(`<${alias}\\s+captions=\\{\\[\\]\\}`));
if (!declarations.startsWith('import')) {
expect(output).toContain(declarations);
}
diff --git a/packages/docs/docs/studio-protocol/add-element-library-to-studio.mdx b/packages/docs/docs/studio-protocol/add-element-library-to-studio.mdx
index 554d52076e..01ead40fa1 100644
--- a/packages/docs/docs/studio-protocol/add-element-library-to-studio.mdx
+++ b/packages/docs/docs/studio-protocol/add-element-library-to-studio.mdx
@@ -107,7 +107,7 @@ A project without a loaded `remotion.config.ts` returns `no-config-file`.
The function supports HTTPS websites. HTTP is supported only on `localhost` and `127.0.0.1` for local development. The Element Library itself must use HTTP or HTTPS.
-The confirmation shows the requesting website and the Element Library and caption styles URLs. The Element Library is not added or loaded before confirmation. Adding an Element Library does not install Element source code or dependencies; each Element installation keeps its own confirmation.
+The confirmation shows the requesting website and the Element Library and caption styles URLs. The Element Library is not added or loaded before confirmation. Adding an Element Library does not install Element source code or dependencies; each Element installation keeps its own [confirmation](/docs/studio-protocol/security#confirmation-boundary).
## Compatibility
diff --git a/packages/docs/docs/studio-protocol/create-element-payload.mdx b/packages/docs/docs/studio-protocol/create-element-payload.mdx
index 39e1ae6022..49ff9884a9 100644
--- a/packages/docs/docs/studio-protocol/create-element-payload.mdx
+++ b/packages/docs/docs/studio-protocol/create-element-payload.mdx
@@ -123,7 +123,7 @@ Set to `true` to let the Element be selected in the Styles tab when generating c
Caption styles must use `installationMode: 'component-owned-sequence'`, accept a `captions` prop containing [`Caption[]`](/docs/captions/caption), and expose it through [`Interactive.captionsSchema`](/docs/interactivity-schema#interactivecaptionsschema). Use [`Interactive.withSchema()`](/docs/interactive-with-schema) with `wrapInSequence: true` to support `from`, `durationInFrames`, `trimBefore`, `playbackRate`, `premountFor`, and `postmountFor`.
-Studio replaces preview captions with the generated transcript and copies timing from the selected media. Other initial props are preserved. Choosing a style does not install it; clicking Generate captions starts transcription, after which Studio installs its source, dependencies, and assets. The flag describes compatibility, not trust: an Element can execute arbitrary code.
+Studio replaces preview captions with the generated transcript. Timing props in `initialProps` are ignored: Studio copies timing from the selected media so the captions stay in sync. To place the captions at the bottom center, Studio adds `bottom: 120`, `left: '50%'`, and `transform: 'translateX(-50%)'` to `style`; values from `initialProps.style` take precedence. Other initial props are preserved. Choosing a style does not install it; clicking Generate captions starts transcription, after which Studio installs its source, dependencies, and assets. The flag describes compatibility, not trust: an Element can execute arbitrary code.
## Return value
diff --git a/packages/docs/docs/studio-protocol/security.mdx b/packages/docs/docs/studio-protocol/security.mdx
index ff128e94f7..d65dd3ec02 100644
--- a/packages/docs/docs/studio-protocol/security.mdx
+++ b/packages/docs/docs/studio-protocol/security.mdx
@@ -23,9 +23,9 @@ Before confirming, Studio shows the requesting source, destination choice, sourc
Declining the confirmation does not write source files or install packages.
-In the caption style picker, an Element request selects a style without installing it. Studio shows an installation notice with source and dependency details. Clicking <kbd>Generate captions</kbd> starts transcription and installs the chosen style afterward.
+In the caption style picker, an Element request selects a style instead of asking for confirmation, and the caption styles page can send it without user interaction. Studio shows the selected style's origin and dependencies, but not its source code. Clicking <kbd>Generate captions</kbd> transcribes the media and then installs the selected style, so only add a caption styles URL whose Elements you trust.
-An Element Library request made with [`addElementLibraryToStudio()`](/docs/studio-protocol/add-element-library-to-studio) shows the requesting origin, exact Element Library URL, and caption styles URL if provided. The Element Library is not loaded before confirmation. Confirming persists a [`Config.addElementLibrary()`](/docs/config#addelementlibrary) call in `remotion.config.ts`; it does not install Element source code or dependencies. Individual Element installations still require confirmation.
+An Element Library request made with [`addElementLibraryToStudio()`](/docs/studio-protocol/add-element-library-to-studio) shows the requesting origin, exact Element Library URL, and caption styles URL if provided. The Element Library is not loaded before confirmation. Confirming persists a [`Config.addElementLibrary()`](/docs/config#addelementlibrary) call in `remotion.config.ts`; it does not install Element source code or dependencies. Installing its Elements still requires confirmation as described above.
Declining or closing the Element Library confirmation does not change the config.
diff --git a/packages/studio/src/components/RenderQueue/CaptionQueueProcessor.tsx b/packages/studio/src/components/RenderQueue/CaptionQueueProcessor.tsx
index 0dde68d659..910d463eb2 100644
--- a/packages/studio/src/components/RenderQueue/CaptionQueueProcessor.tsx
+++ b/packages/studio/src/components/RenderQueue/CaptionQueueProcessor.tsx
@@ -122,7 +122,12 @@ export const CaptionQueueProcessor: React.FC = () => {
contents: JSON.stringify(captions, null, 2),
filePath: job.outName,
});
- } else if (job.captionStyle !== null) {
+ } else if (
+ job.captionStyle !== null &&
+ // The built-in path owns basic-captions.element.tsx, so the
+ // library's Basic Captions must not be installed under that name.
+ job.captionStyle.element.slug !== 'captions/basic-captions'
+ ) {
const {element} = job.captionStyle;
updateCaptionJobProgress(job.id, {
message: `Adding ${element.displayName}...`,