Skip to content

πŸŽ₯ Make videos programmatically with React

Elements: Add caption styles to library template

Igor Samokhovetsdc025433e3e0
diff --git a/bun.lock b/bun.lock
index 0a5a6d73bf..bc33120a1e 100644
--- a/bun.lock
+++ b/bun.lock
@@ -2149,6 +2149,7 @@
"@heroicons/react": "2.2.0",
"@react-router/node": "8.3.0",
"@react-router/serve": "8.3.0",
+ "@remotion/captions": "workspace:*",
"@remotion/cli": "workspace:*",
"@remotion/player": "workspace:*",
"@remotion/studio-protocol": "workspace:*",
diff --git a/packages/docs/static/img/element-library-template.png b/packages/docs/static/img/element-library-template.png
index 3a8da6bb6a..efc5120592 100644
Binary files a/packages/docs/static/img/element-library-template.png and b/packages/docs/static/img/element-library-template.png differ
diff --git a/packages/promo-pages/public/img/element-library-template.png b/packages/promo-pages/public/img/element-library-template.png
index 3a8da6bb6a..efc5120592 100644
Binary files a/packages/promo-pages/public/img/element-library-template.png and b/packages/promo-pages/public/img/element-library-template.png differ
diff --git a/packages/template-element-library/README.md b/packages/template-element-library/README.md
index 442b5d3a21..15b1dc3710 100644
--- a/packages/template-element-library/README.md
+++ b/packages/template-element-library/README.md
@@ -1,6 +1,6 @@
# Remotion Element Library
-A React Router + Tailwind CSS starter for publishing [Remotion Elements](https://www.remotion.dev/elements). Includes server-side rendering, an authoring Studio, and three editable examples. See the [third-party Element libraries](https://www.remotion.dev/elements/libraries) for examples of published catalogs.
+A React Router + Tailwind CSS starter for publishing [Remotion Elements](https://www.remotion.dev/elements). Includes server-side rendering, an authoring Studio, and four editable examples. See the [third-party Element libraries](https://www.remotion.dev/elements/libraries) for examples of published catalogs.
## Develop
@@ -30,6 +30,12 @@ To add an Element, create `elements/<slug>/<slug>.tsx`, add it to `elements/regi
See the [Element guidelines](https://www.remotion.dev/elements/guidelines), [interactivity documentation](https://www.remotion.dev/docs/studio/interactivity), and [library integration guide](https://www.remotion.dev/docs/studio-protocol/component-library-integration) for layout, assets, dependencies, and installation requirements.
+## Caption styles
+
+`/captions` is a separate gallery and Studio caption-style picker. Library registration includes this URL as `captionStylesUrl`. In Studio's captions context, the page hides navigation, uses a transparent background, and reflects selection and Reset through [`subscribeToCaptionStyleSelection()`](https://www.remotion.dev/docs/studio-protocol/subscribe-to-caption-style-selection).
+
+Accent captions remixes [Word Highlight Captions](https://www.remotion.dev/elements/captions/word-highlight-captions) with a system font and warm accent. Caption Elements accept `Caption[]`, expose `Interactive.captionsSchema`, and use component-owned installation with `isCaptionStyle: true`. Set their registry category to `Captions` to include them in the picker.
+
## Build and deploy
```sh
diff --git a/packages/template-element-library/app/app.css b/packages/template-element-library/app/app.css
index 05c3ff1581..fdf8dcdc52 100644
--- a/packages/template-element-library/app/app.css
+++ b/packages/template-element-library/app/app.css
@@ -9,7 +9,27 @@
--color-accent: #c34228;
}
+@utility transparency-grid {
+ background-image: repeating-conic-gradient(
+ color-mix(in srgb, var(--color-ink) 5%, transparent) 0% 25%,
+ transparent 0% 50%
+ );
+ background-size: 16px 16px;
+}
+
@layer base {
+ html:has([data-caption-picker="true"]),
+ html:has([data-caption-picker="true"]) body {
+ background: transparent;
+ color-scheme: dark;
+ }
+
+ [data-caption-picker="true"] {
+ --color-ink: #f5f5f5;
+ --color-muted: #a3a3a3;
+ --color-accent: #f49982;
+ }
+
body {
@apply m-0 bg-white font-sans text-ink;
}
diff --git a/packages/template-element-library/app/components/caption-style-button.tsx b/packages/template-element-library/app/components/caption-style-button.tsx
new file mode 100644
index 0000000000..2b9d8bd815
--- /dev/null
+++ b/packages/template-element-library/app/components/caption-style-button.tsx
@@ -0,0 +1,74 @@
+import { CheckCircleIcon } from "@heroicons/react/16/solid";
+import { setStudioDragData } from "@remotion/studio-protocol";
+import { useState, type RefObject } from "react";
+import type { CatalogEntry } from "../../lib/element-payload";
+import { ElementPreview } from "./element-preview";
+
+export const CaptionStyleButton = ({
+ entry,
+ isSelected,
+ loading,
+ onClick,
+ triggerRef,
+}: {
+ entry: CatalogEntry;
+ isSelected: boolean;
+ loading: boolean;
+ onClick: () => void;
+ triggerRef: RefObject<HTMLButtonElement | null>;
+}) => {
+ const [hovered, setHovered] = useState(false);
+ const [focused, setFocused] = useState(false);
+
+ return (
+ <button
+ ref={triggerRef}
+ type="button"
+ aria-label={`Select ${entry.definition.displayName}`}
+ aria-pressed={isSelected}
+ aria-busy={loading}
+ disabled={loading}
+ className="group/caption grid w-full min-w-0 cursor-default gap-1 rounded-xl p-1 text-left text-ink ring-1 ring-ink/15 hover:bg-ink/5 focus-visible:outline-offset-2 aria-pressed:ring-2 aria-pressed:ring-accent aria-busy:opacity-100"
+ onPointerEnter={(event) => {
+ if (event.pointerType !== "touch") setHovered(true);
+ }}
+ onPointerLeave={() => setHovered(false)}
+ onFocus={() => setFocused(true)}
+ onBlur={() => setFocused(false)}
+ onClick={onClick}
+ draggable={!loading}
+ onDragStart={(event) =>
+ setStudioDragData({
+ dataTransfer: event.dataTransfer,
+ payload: entry.payload,
+ })
+ }
+ >
+ <div
+ aria-hidden
+ className="transparency-grid pointer-events-none flex aspect-video items-center overflow-hidden rounded-lg"
+ >
+ <ElementPreview
+ definition={entry.definition}
+ controls={false}
+ playing={hovered || focused}
+ />
+ </div>
+ <div className="flex min-w-0 items-center justify-between gap-2 px-2 py-2 text-base font-normal sm:text-sm">
+ <span className="min-w-0 text-balance">
+ {entry.definition.displayName}
+ </span>
+ <span
+ className="flex size-4 shrink-0 items-center justify-center"
+ aria-hidden
+ >
+ {loading ? (
+ <span className="size-4 animate-spin rounded-full border-2 border-ink/20 border-t-accent motion-reduce:animate-none" />
+ ) : (
+ <CheckCircleIcon className="size-4 shrink-0 fill-accent opacity-0 group-aria-pressed/caption:opacity-100" />
+ )}
+ </span>
+ </div>
+ </button>
+ );
+};
diff --git a/packages/template-element-library/app/components/category-navigation.tsx b/packages/template-element-library/app/components/category-navigation.tsx
new file mode 100644
index 0000000000..a29b707b54
--- /dev/null
+++ b/packages/template-element-library/app/components/category-navigation.tsx
@@ -0,0 +1,42 @@
+import { Link, useSearchParams } from "react-router";
+import { elements } from "../../elements/registry";
+
+export const CategoryNavigation = ({
+ category,
+}: {
+ category: string | null;
+}) => {
+ const [searchParams] = useSearchParams();
+ const categories = [...new Set(elements.map((element) => element.category))];
+
+ return (
+ <nav
+ className="flex min-w-0 gap-6 overflow-x-auto text-base sm:text-sm"
+ aria-label="Filter by category"
+ >
+ {[null, ...categories].map((item) => {
+ const params = new URLSearchParams(searchParams);
+ if (item === null || item === "Captions") {
+ params.delete("category");
+ } else {
+ params.set("category", item.toLowerCase());
+ }
+
+ return (
+ <Link
+ key={item ?? "all"}
+ to={{
+ pathname: item === "Captions" ? "/captions" : "/",
+ search: params.toString(),
+ }}
+ preventScrollReset
+ className="shrink-0 border-b-2 border-transparent py-4 font-medium whitespace-nowrap text-muted hover:text-ink focus-visible:-outline-offset-4 aria-[current=page]:border-ink aria-[current=page]:text-ink"
+ aria-current={category === item ? "page" : undefined}
+ >
+ {item ?? "All"}
+ </Link>
+ );
+ })}
+ </nav>
+ );
+};
diff --git a/packages/template-element-library/app/components/element-card.tsx b/packages/template-element-library/app/components/element-card.tsx
index 4a6a2d2612..59eaba2a61 100644
--- a/packages/template-element-library/app/components/element-card.tsx
+++ b/packages/template-element-library/app/components/element-card.tsx
@@ -36,7 +36,7 @@ export const ElementCard = ({ entry }: { entry: CatalogEntry }) => {
}
>
<div
- className="relative aspect-video overflow-hidden rounded-[min(1vw,8px)] bg-neutral-50 outline-1 -outline-offset-1 outline-black/5 [&>div]:pointer-events-none"
+ className={`relative flex aspect-video items-center overflow-hidden rounded-[min(1vw,8px)] bg-neutral-50 outline-1 -outline-offset-1 outline-black/5 [&>div]:pointer-events-none ${definition.previewBackground === "transparent" ? "transparency-grid" : ""}`}
aria-hidden
>
<ElementPreview
diff --git a/packages/template-element-library/app/components/studio-actions.tsx b/packages/template-element-library/app/components/studio-actions.tsx
index 43c8a5019c..529f63df69 100644
--- a/packages/template-element-library/app/components/studio-actions.tsx
+++ b/packages/template-element-library/app/components/studio-actions.tsx
@@ -7,6 +7,7 @@ import { PlusIcon, XMarkIcon } from "@heroicons/react/16/solid";
import { useRef, useState } from "react";
import type { CatalogEntry } from "../../lib/element-payload";
import { ElementUseButton } from "./element-use-button";
+import { CaptionStyleButton } from "./caption-style-button";
import {
StudioInstallFallback,
type StudioFailure,
@@ -16,18 +17,23 @@ type Status =
| { type: "idle" | "pending" | "success"; message: string }
| ({ type: "error" } & StudioFailure);
-export const StudioActions = ({
- entry,
- variant,
-}:
- | {
- entry: CatalogEntry;
- variant: "card";
- }
- | {
- entry: CatalogEntry | null;
- variant: "default";
- }) => {
+export const StudioActions = (
+ props:
+ | {
+ entry: CatalogEntry;
+ variant: "card";
+ }
+ | {
+ entry: CatalogEntry;
+ variant: "caption";
+ isSelected: boolean;
+ }
+ | {
+ entry: CatalogEntry | null;
+ variant: "default";
+ },
+) => {
+ const { entry, variant } = props;
const [status, setStatus] = useState<Status>({ type: "idle", message: "" });
const [fallback, setFallback] = useState({ isOpen: false, failureCount: 0 });
const triggerRef = useRef<HTMLButtonElement>(null);
@@ -40,12 +46,16 @@ export const StudioActions = ({
: await addElementLibraryToStudio({
url: new URL("/", window.location.origin).href,
displayName: "Studio Supply",
+ captionStylesUrl: new URL("/captions", window.location.origin).href,
});
if (result.success) {
setStatus({
type: "success",
- message: "Request sent. Confirm in Remotion Studio to finish.",
+ message:
+ variant === "caption"
+ ? "Caption style sent to Studio."
+ : "Request sent. Confirm in Remotion Studio to finish.",
});
setFallback({ isOpen: false, failureCount: 0 });
return;
@@ -67,7 +77,15 @@ export const StudioActions = ({
return (
<div className="min-w-0">
- {entry && variant === "default" ? (
+ {props.variant === "caption" ? (
+ <CaptionStyleButton
+ entry={props.entry}
+ isSelected={props.isSelected}
+ loading={status.type === "pending"}
+ onClick={sendToStudio}
+ triggerRef={triggerRef}
+ />
+ ) : entry && variant === "default" ? (
<ElementUseButton
entry={entry}
loading={status.type === "pending"}
@@ -140,7 +158,7 @@ export const StudioActions = ({
aria-live="polite"
aria-atomic="true"
className={
- variant === "card"
+ variant !== "default"
? "sr-only"
: "fixed inset-x-4 bottom-4 z-50 text-base/7 sm:right-6 sm:bottom-6 sm:left-auto sm:w-96 sm:text-sm/6"
}
diff --git a/packages/template-element-library/app/components/studio-install-fallback.tsx b/packages/template-element-library/app/components/studio-install-fallback.tsx
index 8f3c7b6e38..8635039fc9 100644
--- a/packages/template-element-library/app/components/studio-install-fallback.tsx
+++ b/packages/template-element-library/app/components/studio-install-fallback.tsx
@@ -58,7 +58,7 @@ export const StudioInstallFallback = ({
<dialog
ref={dialogRef}
aria-labelledby={titleId}
- className="m-auto max-h-[calc(100dvh_-_--spacing(8))] w-[calc(100%_-_--spacing(8))] max-w-lg overflow-y-auto rounded-xl bg-white p-6 text-base/7 text-ink shadow-xl ring-1 ring-black/10 backdrop:bg-black/30 sm:text-sm/6"
+ className="scheme-light m-auto max-h-[calc(100dvh_-_--spacing(8))] w-[calc(100%_-_--spacing(8))] max-w-lg overflow-y-auto rounded-xl bg-white p-6 text-base/7 text-ink shadow-xl ring-1 ring-black/10 backdrop:bg-black/30 sm:text-sm/6"
onCancel={(event) => {
event.preventDefault();
onClose();
@@ -277,6 +277,11 @@ export const StudioInstallFallback = ({
>
<code>Config.addElementLibrary()</code>
</a>
+ . To include caption styles, also set <code>captionStylesUrl</code>{" "}
+ to{" "}
+ <code className="break-all">
+ {new URL("/captions", window.location.origin).href}
+ </code>
.
</p>
</div>
diff --git a/packages/template-element-library/app/routes.ts b/packages/template-element-library/app/routes.ts
index 3ac7b3c4aa..ec7ede69c0 100644
--- a/packages/template-element-library/app/routes.ts
+++ b/packages/template-element-library/app/routes.ts
@@ -8,6 +8,7 @@ import {
export default [
layout("routes/layout.tsx", [
index("routes/library.tsx"),
+ route("captions", "routes/captions.tsx"),
route("elements/:slug", "routes/element.tsx"),
]),
] satisfies RouteConfig;
diff --git a/packages/template-element-library/app/routes/captions.tsx b/packages/template-element-library/app/routes/captions.tsx
new file mode 100644
index 0000000000..b432e4456a
--- /dev/null
+++ b/packages/template-element-library/app/routes/captions.tsx
@@ -0,0 +1,57 @@
+import { subscribeToCaptionStyleSelection } from "@remotion/studio-protocol";
+import { useEffect, useState } from "react";
+import { useOutletContext, type MetaFunction } from "react-router";
+import { catalog } from "../../lib/element-payload";
+import { CategoryNavigation } from "../components/category-navigation";
+import { ElementCard } from "../components/element-card";
+import { StudioActions } from "../components/studio-actions";
+
+export const meta: MetaFunction = () => [
+ { title: "Caption styles β€” Studio Supply" },
+ {
+ name: "description",
+ content: "Editable caption styles for your Remotion videos.",
+ },
+];
+
+export default function Captions() {
+ const { isCaptionPicker } = useOutletContext<{ isCaptionPicker: boolean }>();
+ const [selectedSlug, setSelectedSlug] = useState<string | null>(null);
+
+ useEffect(() => subscribeToCaptionStyleSelection(setSelectedSlug), []);
+
+ return (
+ <main
+ id="main"
+ className="pt-6 pb-12 group-data-[caption-picker=true]/site:py-3"
+ >
+ <h1 className="sr-only">Caption styles</h1>
+ {!isCaptionPicker && <CategoryNavigation category="Captions" />}
+ <ul
+ role="list"
+ aria-label="Caption styles"
+ className={
+ isCaptionPicker
+ ? "grid grid-cols-[repeat(auto-fill,minmax(min(100%,11rem),1fr))] gap-3"
+ : "grid grid-cols-1 gap-x-6 gap-y-10 pt-6 sm:grid-cols-2 lg:grid-cols-3"
+ }
+ >
+ {catalog
+ .filter(({ definition }) => definition.category === "Captions")
+ .map((entry) =>
+ isCaptionPicker ? (
+ <li key={entry.definition.slug} className="min-w-0">
+ <StudioActions
+ entry={entry}
+ variant="caption"
+ isSelected={selectedSlug === entry.definition.slug}
+ />
+ </li>
+ ) : (
+ <ElementCard key={entry.definition.slug} entry={entry} />
+ ),
+ )}
+ </ul>
+ </main>
+ );
+}
diff --git a/packages/template-element-library/app/routes/element.tsx b/packages/template-element-library/app/routes/element.tsx
index fa6e12874e..81115f0ca7 100644
--- a/packages/template-element-library/app/routes/element.tsx
+++ b/packages/template-element-library/app/routes/element.tsx
@@ -57,10 +57,13 @@ export default function ElementPage() {
<div className="text-base sm:text-sm">
<Link
className="inline-flex min-h-12 items-center gap-2 text-muted hover:text-ink sm:min-h-9"
- to={{ pathname: "/", search }}
+ to={{
+ pathname: definition.category === "Captions" ? "/captions" : "/",
+ search,
+ }}
>
- <ArrowLeftIcon className="size-4 shrink-0 fill-current" /> All
- elements
+ <ArrowLeftIcon className="size-4 shrink-0 fill-current" />
+ {definition.category === "Captions" ? "All captions" : "All elements"}
</Link>
</div>
<div className="pt-6 pb-8">
@@ -72,7 +75,9 @@ export default function ElementPage() {
</p>
</div>
<div className="grid grid-cols-1 items-start gap-6 lg:grid-cols-[minmax(0,1fr)_18rem]">
- <div className="min-w-0 overflow-hidden rounded-[min(1vw,8px)] outline-1 -outline-offset-1 outline-black/5">
+ <div
+ className={`min-w-0 overflow-hidden rounded-[min(1vw,8px)] outline-1 -outline-offset-1 outline-black/5 ${definition.previewBackground === "transparent" ? "transparency-grid" : ""}`}
+ >
<ElementPreview
key={slug}
definition={definition}
diff --git a/packages/template-element-library/app/routes/layout.tsx b/packages/template-element-library/app/routes/layout.tsx
index f95d7ae4f9..ccac5c6113 100644
--- a/packages/template-element-library/app/routes/layout.tsx
+++ b/packages/template-element-library/app/routes/layout.tsx
@@ -4,9 +4,14 @@ import { Link, Outlet, useLocation } from "react-router";
import { StudioActions } from "../components/studio-actions";
export default function LibraryLayout() {
- const [insideStudio, setInsideStudio] = useState(false);
const location = useLocation();
const search = location.search;
+ const [insideStudio, setInsideStudio] = useState(
+ new URLSearchParams(search).get("remotion-studio") === "true",
+ );
+ const isCaptionPicker =
+ insideStudio &&
+ new URLSearchParams(search).get("remotion-studio-context") === "captions";
useEffect(() => {
setInsideStudio(isInsideStudio());
}, []);
@@ -14,6 +19,7 @@ export default function LibraryLayout() {
return (
<div
data-embedded={insideStudio}
+ data-caption-picker={isCaptionPicker}
className="group/site isolate flex min-h-dvh flex-col"
>
<a
@@ -35,7 +41,8 @@ export default function LibraryLayout() {
Studio Supply
</Link>
</div>
- {location.pathname === "/" && (
+ {(location.pathname === "/" ||
+ location.pathname === "/captions") && (
<div className="w-full min-w-0 sm:w-auto sm:max-w-80">
<StudioActions entry={null} variant="default" />
</div>
@@ -43,8 +50,8 @@ export default function LibraryLayout() {
</div>
</header>
)}
- <div className="mx-auto w-full max-w-7xl flex-1 px-6 sm:px-8 lg:px-12">
- <Outlet context={{ insideStudio, search }} />
+ <div className="mx-auto w-full max-w-7xl flex-1 px-6 group-data-[caption-picker=true]/site:max-w-none group-data-[caption-picker=true]/site:px-3 sm:px-8 lg:px-12">
+ <Outlet context={{ insideStudio, isCaptionPicker, search }} />
</div>
</div>
);
diff --git a/packages/template-element-library/app/routes/library.tsx b/packages/template-element-library/app/routes/library.tsx
index 49aa0bc7a5..287d197e7f 100644
--- a/packages/template-element-library/app/routes/library.tsx
+++ b/packages/template-element-library/app/routes/library.tsx
@@ -1,4 +1,5 @@
-import { Link, useSearchParams, type MetaFunction } from "react-router";
+import { useSearchParams, type MetaFunction } from "react-router";
+import { CategoryNavigation } from "../components/category-navigation";
import { catalog } from "../../lib/element-payload";
import { ElementCard } from "../components/element-card";
@@ -28,33 +29,7 @@ export default function Library() {
<main id="main" className="pt-6 pb-12">
<h1 className="sr-only">Elements</h1>
<section aria-label="Elements">
- <div className="flex min-w-0 items-center justify-between gap-6">
- <nav
- className="flex min-w-0 gap-6 overflow-x-auto text-base sm:text-sm"
- aria-label="Filter by category"
- >
- {[null, ...categories].map((item) => {
- const params = new URLSearchParams(searchParams);
- if (item === null) {
- params.delete("category");
- } else {
- params.set("category", item.toLowerCase());
- }
-
- return (
- <Link
- key={item ?? "all"}
- to={{ pathname: "/", search: params.toString() }}
- preventScrollReset
- className="shrink-0 border-b-2 border-transparent py-4 font-medium whitespace-nowrap text-muted hover:text-ink focus-visible:-outline-offset-4 aria-[current=page]:border-ink aria-[current=page]:text-ink"
- aria-current={category === item ? "page" : undefined}
- >
- {item ?? "All"}
- </Link>
- );
- })}
- </nav>
- </div>
+ <CategoryNavigation category={category} />
<ul
role="list"
className="grid grid-cols-1 gap-x-6 gap-y-10 pt-6 sm:grid-cols-2 lg:grid-cols-3"
diff --git a/packages/template-element-library/elements/accent-captions/accent-captions.tsx b/packages/template-element-library/elements/accent-captions/accent-captions.tsx
new file mode 100644
index 0000000000..b53f59532e
--- /dev/null
+++ b/packages/template-element-library/elements/accent-captions/accent-captions.tsx
@@ -0,0 +1,109 @@
+import { createTikTokStyleCaptions, type Caption } from "@remotion/captions";
+import { Fragment, useMemo, type CSSProperties } from "react";
+import { Interactive, useCurrentFrame, useVideoConfig } from "remotion";
+
+type AccentCaptionsProps = {
+ captions?: Caption[];
+ combineTokensWithinMilliseconds?: number;
+ highlightColor?: string;
+ width?: number;
+ style?: CSSProperties;
+};
+
+const AccentCaptionsInner = ({
+ captions = [],
+ combineTokensWithinMilliseconds = 3000,
+ highlightColor = "#ffb27d",
+ width = 900,
+ style,
+}: AccentCaptionsProps) => {
+ const frame = useCurrentFrame();
+ const { fps } = useVideoConfig();
+ const pages = useMemo(
+ () =>
+ createTikTokStyleCaptions({
+ captions,
+ combineTokensWithinMilliseconds,
+ }).pages,
+ [captions, combineTokensWithinMilliseconds],
+ );
+ const currentTimeMs = (frame / fps) * 1000;
+ const page = pages.find(
+ (candidate) =>
+ currentTimeMs >= candidate.startMs &&
+ currentTimeMs < candidate.startMs + candidate.durationMs,
+ );
+
+ return (
+ <div
+ style={{
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ width,
+ color: "#ffffff",
+ fontFamily: "Arial, Helvetica, sans-serif",
+ fontSize: 72,
+ fontWeight: 700,
+ lineHeight: 1.25,
+ textAlign: "center",
+ paintOrder: "stroke fill",
+ WebkitTextStroke: "5px #202020",
+ ...style,
+ }}
+ >
+ <div
+ style={{
+ minWidth: 0,
+ whiteSpace: "pre-wrap",
+ overflowWrap: "anywhere",
+ }}
+ >
+ {page?.tokens.map((token, index) => {
+ const active =
+ currentTimeMs >= token.fromMs && currentTimeMs < token.toMs;
+ const text = token.text.trim();
+ const start = token.text.indexOf(text);
+ return (
+ <Fragment key={`${page.startMs}-${index}`}>
+ {token.text.slice(0, start)}
+ <span style={{ color: active ? highlightColor : "inherit" }}>
+ {text}
+ </span>
+ {token.text.slice(start + text.length)}
+ </Fragment>
+ );
+ })}
+ </div>
+ </div>
+ );
+};
+
+export const AccentCaptions = Interactive.create({
+ Component: AccentCaptionsInner,
+ layout: "none",
+ schema: {
+ ...Interactive.captionsSchema,
+ width: {
+ type: "number",
+ min: 1,
+ step: 1,
+ default: 900,
+ description: "Caption area width",
+ hiddenFromList: false,
+ },
+ combineTokensWithinMilliseconds: {
+ type: "number",
+ min: 0,
+ step: 50,
+ default: 3000,
+ description: "Time between caption pages",
+ hiddenFromList: false,
+ },
+ highlightColor: {
+ type: "color",
+ default: "#ffb27d",
+ description: "Active word color",
+ },
+ },
+});
diff --git a/packages/template-element-library/elements/registry.ts b/packages/template-element-library/elements/registry.ts
index 20d1fc4f2c..a8b9f66774 100644
--- a/packages/template-element-library/elements/registry.ts
+++ b/packages/template-element-library/elements/registry.ts
@@ -6,6 +6,7 @@ import type {
ElementInstallationMode,
} from "@remotion/studio-protocol";
import type { ComponentType } from "react";
+import { AccentCaptions } from "./accent-captions/accent-captions";
import { AnimatedTitle } from "./animated-title/animated-title";
import { LowerThird } from "./lower-third/lower-third";
import { AnimatedBackground } from "./animated-background/animated-background";
@@ -88,4 +89,80 @@ export const elements: readonly ElementDefinition[] = [
dependencies: [],
assets: [],
},
+ {
+ slug: "accent-captions",
+ displayName: "Accent captions",
+ category: "Captions",
+ description:
+ "Word-by-word captions with a warm highlight and a crisp outline.",
+ component: AccentCaptions,
+ width: 900,
+ height: 300,
+ fps: 30,
+ durationInFrames: 150,
+ posterFrame: 45,
+ previewBackground: "transparent",
+ dimensions: { width: 900, height: 160 },
+ installationMode: "component-owned-sequence",
+ initialProps: {
+ captions: [
+ {
+ text: "Make",
+ startMs: 0,
+ endMs: 600,
+ timestampMs: 300,
+ confidence: null,
+ },
+ {
+ text: " every",
+ startMs: 600,
+ endMs: 1300,
+ timestampMs: 950,
+ confidence: null,
+ },
+ {
+ text: " word",
+ startMs: 1300,
+ endMs: 2100,
+ timestampMs: 1700,
+ confidence: null,
+ },
+ {
+ text: " count.",
+ startMs: 2100,
+ endMs: 3000,
+ timestampMs: 2550,
+ confidence: null,
+ pageBreakAfter: true,
+ },
+ {
+ text: "Keep",
+ startMs: 3000,
+ endMs: 3600,
+ timestampMs: 3300,
+ confidence: null,
+ },
+ {
+ text: " it",
+ startMs: 3600,
+ endMs: 4000,
+ timestampMs: 3800,
+ confidence: null,
+ },
+ {
+ text: " moving.",
+ startMs: 4000,
+ endMs: 5000,
+ timestampMs: 4500,
+ confidence: null,
+ },
+ ],
+ width: 900,
+ combineTokensWithinMilliseconds: 3000,
+ highlightColor: "#ffb27d",
+ },
+ installationProps: null,
+ dependencies: [{ name: "@remotion/captions", version: null }],
+ assets: [],
+ },
];
diff --git a/packages/template-element-library/lib/element-payload.ts b/packages/template-element-library/lib/element-payload.ts
index 9ef3ac09dc..1a8f0094b8 100644
--- a/packages/template-element-library/lib/element-payload.ts
+++ b/packages/template-element-library/lib/element-payload.ts
@@ -21,6 +21,7 @@ export const catalog = elements.map((definition) => {
dimensions: definition.dimensions,
durationInFrames: definition.durationInFrames,
installationMode: definition.installationMode,
+ isCaptionStyle: definition.category === "Captions",
dependencies: definition.dependencies,
assets: definition.assets,
initialProps:
diff --git a/packages/template-element-library/package.json b/packages/template-element-library/package.json
index 3b74e97e85..71f0034940 100644
--- a/packages/template-element-library/package.json
+++ b/packages/template-element-library/package.json
@@ -20,6 +20,7 @@
"@heroicons/react": "2.2.0",
"@react-router/node": "8.3.0",
"@react-router/serve": "8.3.0",
+ "@remotion/captions": "workspace:*",
"@remotion/cli": "workspace:*",
"@remotion/player": "workspace:*",
"@remotion/studio-protocol": "workspace:*",
diff --git a/packages/template-element-library/remotion/ElementPreview.tsx b/packages/template-element-library/remotion/ElementPreview.tsx
index 882098256e..c06e1fd39e 100644
--- a/packages/template-element-library/remotion/ElementPreview.tsx
+++ b/packages/template-element-library/remotion/ElementPreview.tsx
@@ -30,6 +30,9 @@ export const ElementPreview = ({ slug }: { slug: string }) => {
<div
style={{
position: "relative",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
width: dimensions.width,
height: dimensions.height,
}}
diff --git a/packages/template-element-library/remotion/Root.tsx b/packages/template-element-library/remotion/Root.tsx
index 71088ebe3d..8773000488 100644
--- a/packages/template-element-library/remotion/Root.tsx
+++ b/packages/template-element-library/remotion/Root.tsx
@@ -1,4 +1,5 @@
import { Composition } from "remotion";
+import { AccentCaptions } from "../elements/accent-captions/accent-captions";
import { ElementPreview } from "./ElementPreview";
export const RemotionRoot = () => {
@@ -31,6 +32,72 @@ export const RemotionRoot = () => {
durationInFrames={150}
defaultProps={{ slug: "animated-background" }}
/>
+ <Composition
+ id="accent-captions"
+ component={AccentCaptions}
+ width={900}
+ height={300}
+ fps={30}
+ durationInFrames={150}
+ defaultProps={{
+ captions: [
+ {
+ text: "Make",
+ startMs: 0,
+ endMs: 600,
+ timestampMs: 300,
+ confidence: null,
+ },
+ {
+ text: " every",
+ startMs: 600,
+ endMs: 1300,
+ timestampMs: 950,
+ confidence: null,
+ },
+ {
+ text: " word",
+ startMs: 1300,
+ endMs: 2100,
+ timestampMs: 1700,
+ confidence: null,
+ },
+ {
+ text: " count.",
+ startMs: 2100,
+ endMs: 3000,
+ timestampMs: 2550,
+ confidence: null,
+ pageBreakAfter: true,
+ },
+ {
+ text: "Keep",
+ startMs: 3000,
+ endMs: 3600,
+ timestampMs: 3300,
+ confidence: null,
+ },
+ {
+ text: " it",
+ startMs: 3600,
+ endMs: 4000,
+ timestampMs: 3800,
+ confidence: null,
+ },
+ {
+ text: " moving.",
+ startMs: 4000,
+ endMs: 5000,
+ timestampMs: 4500,
+ confidence: null,
+ },
+ ],
+ width: 900,
+ combineTokensWithinMilliseconds: 3000,
+ highlightColor: "#ffb27d",
+ style: { height: "100%" },
+ }}
+ />
</>
);
};