Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

feat: Remotion Studio caption picker fitted to the Styles panel (#301)

KapishDima126221ae00ba
diff --git a/app/studio/captions/caption-picker.tsx b/app/studio/captions/caption-picker.tsx
new file mode 100644
index 00000000..deb360af
--- /dev/null
+++ b/app/studio/captions/caption-picker.tsx
@@ -0,0 +1,313 @@
+"use client";
+
+import { Player, type PlayerRef } from "@remotion/player";
+import {
+ isInsideStudio,
+ type StudioElementPayload,
+ subscribeToCaptionStyleSelection,
+} from "@remotion/studio-protocol";
+import { ArrowLeftIcon, ArrowUpRightIcon, CheckIcon } from "lucide-react";
+import { parseAsString, useQueryState } from "nuqs";
+import { useEffect, useLayoutEffect, useRef, useState } from "react";
+import { useAutoplay } from "@/app/(home)/components/use-autoplay";
+import { ComponentPreview } from "@/components/docs/component-preview";
+import captionsMeta from "@/content/docs/captions/components/meta.json";
+import {
+ getCachedStudioElement,
+ loadStudioElement,
+} from "@/lib/studio-element";
+import { usePrefersReducedMotion } from "@/lib/use-prefers-reduced-motion";
+import { cn } from "@/lib/utils";
+import components from "@/registry/__index__";
+import { previewManifest } from "@/registry/__manifest__";
+import registry from "@/registry/remocn/registry.json";
+
+// Same order as the Captions sidebar in the docs.
+const styles = captionsMeta.pages.flatMap((page) => {
+ const item = registry.items.find(
+ (entry) => entry.type === "registry:component" && entry.name === page,
+ );
+ return item
+ ? [
+ {
+ name: item.name,
+ title: item.title?.replace(/^Caption /, "") ?? item.name,
+ description: item.description ?? "",
+ },
+ ]
+ : [];
+});
+
+const thinScrollbar =
+ "[scrollbar-color:color-mix(in_oklab,currentColor_25%,transparent)_transparent] [scrollbar-width:thin]";
+
+// Studio's current caption style, only while this page is its caption picker.
+function useStudioCaptionStyle() {
+ const [slug, setSlug] = useState<string | null>(null);
+ useEffect(() => {
+ const context = new URLSearchParams(window.location.search).get(
+ "remotion-studio-context",
+ );
+ if (!isInsideStudio() || context !== "captions") return;
+ return subscribeToCaptionStyleSelection(setSlug);
+ }, []);
+ return slug;
+}
+
+export function StudioCaptionPicker() {
+ const [requestedName, setName] = useQueryState(
+ "caption_style",
+ parseAsString,
+ );
+ const style = styles.find((item) => item.name === requestedName);
+ const name = style?.name ?? null;
+ const selectedSlug = useStudioCaptionStyle();
+ const [loaded, setLoaded] = useState<{
+ name: string;
+ payload: StudioElementPayload | null;
+ } | null>(null);
+ const gridRef = useRef<HTMLDivElement>(null);
+ const scrollRef = useRef(0);
+ const lastOpenedRef = useRef<string | null>(null);
+
+ useEffect(() => {
+ if (!name) return;
+ let cancelled = false;
+ loadStudioElement(name).then((payload) => {
+ if (!cancelled) setLoaded({ name, payload });
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [name]);
+
+ // Back on the grid: restore the scroll position and focus the card the
+ // user came from.
+ useLayoutEffect(() => {
+ if (name || !gridRef.current) return;
+ gridRef.current.scrollTop = scrollRef.current;
+ if (lastOpenedRef.current) {
+ gridRef.current
+ .querySelector<HTMLButtonElement>(
+ `[data-caption-style="${lastOpenedRef.current}"]`,
+ )
+ ?.focus({ preventScroll: true });
+ }
+ }, [name]);
+
+ // A previous payload must never be installable while another style loads.
+ const cached = name ? getCachedStudioElement(name) : null;
+ const loadedStyle =
+ loaded?.name === name
+ ? loaded
+ : name && cached
+ ? { name, payload: cached }
+ : null;
+
+ return (
+ <main className="flex h-dvh min-h-0 flex-col overflow-hidden bg-background text-foreground">
+ {style && name ? (
+ <div className="flex min-h-0 flex-1 flex-col p-3">
+ {loadedStyle?.payload ? (
+ <ComponentPreview
+ key={loadedStyle.name}
+ name={loadedStyle.name}
+ studioElement={loadedStyle.payload}
+ layout="caption-picker"
+ header={{
+ start: <BackLink onClick={() => setName(null)} />,
+ title: style.title,
+ end: <DocsLink name={name} />,
+ }}
+ />
+ ) : (
+ <div className="flex min-h-0 flex-1 flex-col gap-2">
+ <div className="grid shrink-0 grid-cols-[1fr_auto_1fr] items-center gap-2">
+ <div className="justify-self-start">
+ <BackLink onClick={() => setName(null)} />
+ </div>
+ <h1 className="truncate text-center text-sm font-semibold tracking-tight">
+ {style.title}
+ </h1>
+ </div>
+ <output className="flex aspect-video w-[40%] items-center justify-center rounded-xl bg-muted text-xs text-muted-foreground">
+ {loadedStyle ? "Could not load this style." : "Loading…"}
+ </output>
+ </div>
+ )}
+ </div>
+ ) : (
+ <div
+ ref={gridRef}
+ className={cn("min-h-0 flex-1 overflow-y-auto p-4", thinScrollbar)}
+ >
+ <ul
+ aria-label="Caption styles"
+ className="grid grid-cols-2 gap-x-2 gap-y-3 min-[400px]:grid-cols-3 min-[540px]:grid-cols-4 min-[900px]:grid-cols-5 min-[1200px]:grid-cols-6"
+ >
+ {styles.map((item) => (
+ <li key={item.name} className="min-w-0">
+ <CaptionStyleCard
+ name={item.name}
+ title={item.title}
+ description={item.description}
+ selectedInStudio={item.name === selectedSlug}
+ onOpen={() => {
+ scrollRef.current = gridRef.current?.scrollTop ?? 0;
+ lastOpenedRef.current = item.name;
+ setName(item.name);
+ }}
+ />
+ </li>
+ ))}
+ </ul>
+ </div>
+ )}
+ </main>
+ );
+}
+
+// A live thumbnail of the style. Players mount only near the viewport and
+// play on hover or keyboard focus, so 31 cards never animate at once.
+function CaptionStyleCard({
+ name,
+ title,
+ description,
+ selectedInStudio,
+ onOpen,
+}: {
+ name: string;
+ title: string;
+ description: string;
+ selectedInStudio: boolean;
+ onOpen: () => void;
+}) {
+ const preview = previewManifest[name];
+ const entry = components[name];
+ const playerRef = useRef<PlayerRef>(null);
+ const buttonRef = useRef<HTMLButtonElement>(null);
+ const [visible, setVisible] = useState(false);
+ const [hovered, setHovered] = useState(false);
+ const [focused, setFocused] = useState(false);
+ const reducedMotion = usePrefersReducedMotion();
+ const playing = visible && !reducedMotion && (hovered || focused);
+ const { containerRef } = useAutoplay(playerRef, playing);
+ const initialFrame = Math.min(96, (preview?.durationInFrames ?? 1) - 1);
+
+ useEffect(() => {
+ const el = buttonRef.current;
+ if (!el) return;
+ const observer = new IntersectionObserver(
+ ([item]) => setVisible(item.isIntersecting),
+ { rootMargin: "200px" },
+ );
+ observer.observe(el);
+ return () => observer.disconnect();
+ }, []);
+
+ useEffect(() => {
+ if (playing) return;
+ playerRef.current?.pause();
+ playerRef.current?.seekTo(initialFrame);
+ }, [playing, initialFrame]);
+
+ return (
+ <button
+ ref={buttonRef}
+ type="button"
+ data-caption-style={name}
+ aria-label={`Customize ${title}${selectedInStudio ? " (selected in Studio)" : ""}`}
+ title={description}
+ onClick={onOpen}
+ onPointerEnter={(event) => {
+ if (event.pointerType !== "touch") setHovered(true);
+ }}
+ onPointerLeave={() => setHovered(false)}
+ onFocus={() => setFocused(true)}
+ onBlur={() => setFocused(false)}
+ className="group/card flex w-full flex-col gap-1.5 rounded-2xl text-left outline-none focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:ring-offset-4 focus-visible:ring-offset-background"
+ >
+ <div
+ aria-hidden="true"
+ className={cn(
+ "surface-card pointer-events-none aspect-video w-full overflow-hidden rounded-lg transition-[transform,box-shadow] group-hover/card:-translate-y-0.5 group-hover/card:[box-shadow:var(--elevation-raised-hover)] motion-reduce:transition-none motion-reduce:group-hover/card:translate-y-0",
+ selectedInStudio && "ring-2 ring-foreground",
+ )}
+ >
+ <div ref={containerRef} className="size-full bg-[#262626]">
+ {visible && entry && preview ? (
+ <Player
+ ref={playerRef}
+ lazyComponent={entry.load}
+ // Bigger type keeps the sample legible at thumbnail size; the
+ // installed style keeps its own defaults.
+ inputProps={{
+ ...preview.defaults,
+ fontSize: Math.max(
+ 150,
+ Number(preview.defaults.fontSize) || 150,
+ ),
+ }}
+ durationInFrames={preview.durationInFrames}
+ fps={preview.fps}
+ compositionWidth={preview.compositionWidth}
+ compositionHeight={preview.compositionHeight}
+ initialFrame={initialFrame}
+ style={{ width: "100%", height: "100%" }}
+ controls={false}
+ clickToPlay={false}
+ doubleClickToFullscreen={false}
+ spaceKeyToPlayOrPause={false}
+ loop
+ acknowledgeRemotionLicense
+ />
+ ) : null}
+ </div>
+ </div>
+ <span className="flex items-center gap-1.5 px-0.5 text-xs tracking-[-0.01em]">
+ <span
+ className={cn(
+ "min-w-0 flex-1 truncate",
+ selectedInStudio
+ ? "font-medium text-foreground"
+ : "text-muted-foreground group-hover/card:text-foreground",
+ )}
+ >
+ {title}
+ </span>
+ {selectedInStudio ? (
+ <CheckIcon
+ aria-hidden="true"
+ className="size-3.5 shrink-0 text-foreground"
+ />
+ ) : null}
+ </span>
+ </button>
+ );
+}
+
+const linkClass =
+ "flex items-center gap-1 rounded-md px-1 py-0.5 text-xs text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40";
+
+function BackLink({ onClick }: { onClick: () => void }) {
+ return (
+ <button type="button" onClick={onClick} className={cn("-ml-1", linkClass)}>
+ <ArrowLeftIcon className="size-3.5" />
+ All styles
+ </button>
+ );
+}
+
+function DocsLink({ name }: { name: string }) {
+ return (
+ <a
+ href={`/docs/captions/components/${name}`}
+ target="_blank"
+ rel="noreferrer"
+ className={linkClass}
+ >
+ Docs
+ <ArrowUpRightIcon className="size-3.5" />
+ </a>
+ );
+}
diff --git a/app/studio/captions/page.tsx b/app/studio/captions/page.tsx
new file mode 100644
index 00000000..49ae117d
--- /dev/null
+++ b/app/studio/captions/page.tsx
@@ -0,0 +1,16 @@
+import type { Metadata } from "next";
+import { Suspense } from "react";
+import { StudioCaptionPicker } from "./caption-picker";
+
+export const metadata: Metadata = {
+ title: "Caption styles for Remotion Studio",
+ robots: { index: false, follow: false },
+};
+
+export default function CaptionStylesPage() {
+ return (
+ <Suspense fallback={<div className="h-dvh bg-background" />}>
+ <StudioCaptionPicker />
+ </Suspense>
+ );
+}
diff --git a/bun.lock b/bun.lock
index 3b5eee1e..7c96ecd6 100644
--- a/bun.lock
+++ b/bun.lock
@@ -21,7 +21,7 @@
"@remotion/paths": "4.0.530",
"@remotion/player": "4.0.530",
"@remotion/renderer": "4.0.530",
- "@remotion/studio-protocol": "4.0.530",
+ "@remotion/studio-protocol": "4.0.535",
"@remotion/transitions": "4.0.530",
"@remotion/zod-types": "4.0.530",
"@shadcn/react": "^0.1.0",
@@ -501,7 +501,7 @@
"@remotion/studio": ["@remotion/[email protected]", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.31", "@remotion/canvas": "4.0.530", "@remotion/captions": "4.0.530", "@remotion/codemods": "4.0.530", "@remotion/elevenlabs": "4.0.530", "@remotion/media": "4.0.530", "@remotion/media-utils": "4.0.530", "@remotion/openai-whisper": "4.0.530", "@remotion/paths": "4.0.530", "@remotion/player": "4.0.530", "@remotion/renderer": "4.0.530", "@remotion/studio-protocol": "4.0.530", "@remotion/studio-shared": "4.0.530", "@remotion/timeline-utils": "4.0.530", "@remotion/web-renderer": "4.0.530", "@remotion/zod-types": "4.0.530", "@tanstack/react-virtual": "3.14.9", "mediabunny": "1.56.1", "memfs": "3.4.3", "open": "8.4.2", "prismjs": "1.30.0", "remotion": "4.0.530", "semver": "7.5.3", "zod": "4.5.4" }, "peerDependencies": { "@remotion/video-matting": "4.0.530", "@remotion/whisper-webgpu": "4.0.530", "react": ">=16.8.0", "react-dom": ">=16.8.0" }, "optionalPeers": ["@remotion/video-matting", "@remotion/whisper-webgpu"] }, "sha512-Yki1b9nT3uWhVhzjASVH3AaWGEE4rqIRAoAHo67FCOgXSROpwWMNOc7AECPTsdVF8xyaI113hgYsACwsRv1ziQ=="],
- "@remotion/studio-protocol": ["@remotion/[email protected]", "", { "dependencies": { "zod": "4.5.4" } }, "sha512-vHhvU0aKVFrQa7SWBFTEd9m2kiyZtgsf8dxzkO7h5JhzCyJBN1SGmxukjptt/ok5BFYWyixNBAnTyic12T3oww=="],
+ "@remotion/studio-protocol": ["@remotion/[email protected]", "", { "dependencies": { "zod": "4.5.4" } }, "sha512-yPMMlrAcz8K79HyILMGtIvH+6x00c8KuBHpLCD3BSCDEXNqp20IOgoBVI8AZZD82vO1f90Jv3ePenRI2kVhL5Q=="],
"@remotion/studio-server": ["@remotion/[email protected]", "", { "dependencies": { "@babel/parser": "7.24.1", "@babel/types": "7.24.0", "@remotion/bundler": "4.0.530", "@remotion/codemods": "4.0.530", "@remotion/renderer": "4.0.530", "@remotion/studio-protocol": "4.0.530", "@remotion/studio-shared": "4.0.530", "@svgr/core": "8.1.0", "@svgr/plugin-jsx": "8.1.0", "kiwi-schema": "0.5.0", "memfs": "3.4.3", "open": "8.4.2", "recast": "0.23.21", "remotion": "4.0.530", "semver": "7.5.3", "zod": "4.5.4" } }, "sha512-VCa1lh7/qyeW5UtXhU6g65RpCbjBYG0tDF4aY6zxCNjCLmQUUEHiDST/pGhnm1nCAT/bQW3SUynitrw5yn/Afg=="],
@@ -1801,12 +1801,18 @@
"@radix-ui/react-primitive/@radix-ui/react-slot": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/react-compose-refs": "1.1.2" }, "peerDependencies": { "@types/react": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-aeNmHnBxbi2St0au6VBVC7JXFlhLlOnvIIlePNniyUNAClzmtAUEY8/pBiK3iHjufOlwA+c20/8jngo7xcrg8A=="],
+ "@remotion/codemods/@remotion/studio-protocol": ["@remotion/[email protected]", "", { "dependencies": { "zod": "4.5.4" } }, "sha512-vHhvU0aKVFrQa7SWBFTEd9m2kiyZtgsf8dxzkO7h5JhzCyJBN1SGmxukjptt/ok5BFYWyixNBAnTyic12T3oww=="],
+
"@remotion/codemods/recast": ["[email protected]", "", { "dependencies": { "ast-types": "^0.16.1", "esprima": "~4.0.0", "source-map": "~0.6.1", "tiny-invariant": "^1.3.3", "tslib": "^2.0.1" } }, "sha512-mFAyJq9vUbSTARLZUvAEf1z3YxlvAwswbmxMx2mPA/MSm4KmpwvwvhsH/NIrZhyOuwD60Lzyw2qh83uCbgTPYw=="],
"@remotion/renderer/execa": ["[email protected]", "", { "dependencies": { "cross-spawn": "^7.0.3", "get-stream": "^6.0.0", "human-signals": "^2.1.0", "is-stream": "^2.0.0", "merge-stream": "^2.0.0", "npm-run-path": "^4.0.1", "onetime": "^5.1.2", "signal-exit": "^3.0.3", "strip-final-newline": "^2.0.0" } }, "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg=="],
+ "@remotion/studio/@remotion/studio-protocol": ["@remotion/[email protected]", "", { "dependencies": { "zod": "4.5.4" } }, "sha512-vHhvU0aKVFrQa7SWBFTEd9m2kiyZtgsf8dxzkO7h5JhzCyJBN1SGmxukjptt/ok5BFYWyixNBAnTyic12T3oww=="],
+
"@remotion/studio/open": ["[email protected]", "", { "dependencies": { "define-lazy-prop": "^2.0.0", "is-docker": "^2.1.1", "is-wsl": "^2.2.0" } }, "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ=="],
+ "@remotion/studio-server/@remotion/studio-protocol": ["@remotion/[email protected]", "", { "dependencies": { "zod": "4.5.4" } }, "sha512-vHhvU0aKVFrQa7SWBFTEd9m2kiyZtgsf8dxzkO7h5JhzCyJBN1SGmxukjptt/ok5BFYWyixNBAnTyic12T3oww=="],
+
"@remotion/studio-server/open": ["[email protected]", "", { "dependencies": { "define-lazy-prop": "^2.0.0", "is-docker": "^2.1.1", "is-wsl": "^2.2.0" } }, "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ=="],
"@remotion/studio-server/recast": ["[email protected]", "", { "dependencies": { "ast-types": "^0.16.1", "esprima": "~4.0.0", "source-map": "~0.6.1", "tiny-invariant": "^1.3.3", "tslib": "^2.0.1" } }, "sha512-mFAyJq9vUbSTARLZUvAEf1z3YxlvAwswbmxMx2mPA/MSm4KmpwvwvhsH/NIrZhyOuwD60Lzyw2qh83uCbgTPYw=="],
diff --git a/components/docs/component-customizer.tsx b/components/docs/component-customizer.tsx
index 4dbee56e..e255f49c 100644
--- a/components/docs/component-customizer.tsx
+++ b/components/docs/component-customizer.tsx
@@ -15,8 +15,21 @@ import type { ControlConfig, ControlType } from "@/lib/customizer-config";
import { cn } from "@/lib/utils";
/** Shared pill surface so every non-slider control matches the elastic slider. */
+// `customizer-pill` is a hook for the compact density below.
const PILL =
- "flex h-9 items-center gap-3 rounded-xl control-surface px-3 text-sm transition-colors";
+ "customizer-pill flex h-9 items-center gap-3 rounded-xl control-surface px-3 text-sm transition-colors";
+
+// Compact density for tight hosts (Remotion Studio's caption picker): shorter
+// pills and sliders, smaller type. Scoped here so every control type follows.
+const COMPACT = [
+ "gap-1.5",
+ "[&_.customizer-pill]:h-7 [&_.customizer-pill]:gap-2 [&_.customizer-pill]:rounded-lg [&_.customizer-pill]:px-2.5 [&_.customizer-pill]:text-xs [&_.customizer-pill]:whitespace-nowrap [&_.customizer-pill>:first-child]:min-w-0 [&_.customizer-pill>:first-child]:truncate",
+ "[&_.customizer-pill_input]:text-xs [&_.customizer-pill_span]:text-xs",
+ // The swatch already shows the colour; the hex would crowd out the label.
+ "[&_.customizer-pill_span.uppercase]:hidden",
+ "[&_[data-slot=elastic-slider]]:[--elastic-slider-height:--spacing(7)] [&_[data-slot=elastic-slider]]:[--elastic-slider-radius:var(--radius-lg)]",
+ "[&_[data-slot=elastic-slider-label]]:text-xs [&_[data-slot=elastic-slider-value]]:text-xs",
+].join(" ");
/** Strip trailing zeros so the value reads like the reference (1, 0.8, 0.1). */
function formatNumber(v: number) {
@@ -229,13 +242,20 @@ export function ComponentCustomizer({
controls,
values,
onChange,
+ density = "default",
}: {
controls: ControlConfig;
values: Record<string, unknown>;
onChange: (key: string, value: unknown) => void;
+ density?: "default" | "compact";
}) {
return (
- <div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
+ <div
+ className={cn(
+ "grid gap-3 sm:grid-cols-2 lg:grid-cols-3",
+ density === "compact" && COMPACT,
+ )}
+ >
{Object.entries(controls).map(([key, ctrl]) => (
<Control
key={key}
diff --git a/components/docs/component-preview-mdx.tsx b/components/docs/component-preview-mdx.tsx
index d642f078..ac5bfcd1 100644
--- a/components/docs/component-preview-mdx.tsx
+++ b/components/docs/component-preview-mdx.tsx
@@ -14,6 +14,10 @@ function loadStudioElement(name: string): StudioElementPayload | undefined {
export function ComponentPreviewMdx({ name }: { name: string }) {
return (
- <ComponentPreview name={name} studioElement={loadStudioElement(name)} />
+ <ComponentPreview
+ name={name}
+ studioElement={loadStudioElement(name)}
+ layout={null}
+ />
);
}
diff --git a/components/docs/component-preview.tsx b/components/docs/component-preview.tsx
index 8b1f5cc4..5c11788f 100644
--- a/components/docs/component-preview.tsx
+++ b/components/docs/component-preview.tsx
@@ -23,12 +23,23 @@ import registry, { loadComponentConfig } from "@/registry/__index__";
import { ComponentCustomizer } from "./component-customizer";
import { StudioActions } from "./studio-actions";
+type PickerHeader = {
+ start: React.ReactNode;
+ title: string;
+ end?: React.ReactNode;
+};
+
export function ComponentPreview({
name,
studioElement,
+ layout,
+ header,
}: {
name: string;
studioElement?: StudioElementPayload;
+ layout: "caption-picker" | null;
+ /** Caption picker only: the header row around the style's actions. */
+ header?: PickerHeader;
}) {
const entry = registry[name];
@@ -43,10 +54,22 @@ export function ComponentPreview({
return (
<Suspense
fallback={
- <div className="not-prose mb-6 aspect-[1.9/1] w-full animate-pulse rounded-2xl bg-muted" />
+ <div
+ className={
+ layout === "caption-picker"
+ ? "min-h-0 flex-1 animate-pulse rounded-2xl bg-muted"
+ : "not-prose mb-6 aspect-[1.9/1] w-full animate-pulse rounded-2xl bg-muted"
+ }
+ />
}
>
- <Preview name={name} load={entry.load} studioElement={studioElement} />
+ <Preview
+ name={name}
+ load={entry.load}
+ studioElement={studioElement}
+ layout={layout}
+ header={header}
+ />
</Suspense>
);
}
@@ -55,9 +78,13 @@ function Preview({
name,
load,
studioElement,
+ layout,
+ header,
}: {
name: string;
studioElement?: StudioElementPayload;
+ layout: "caption-picker" | null;
+ header?: PickerHeader;
// biome-ignore lint/suspicious/noExplicitAny: dynamically-loaded Remotion composition, props shape varies per component
load: () => Promise<{ default: React.ComponentType<any> }>;
}) {
@@ -86,6 +113,15 @@ function Preview({
);
const code = useMemo(() => generateCode(config, values), [config, values]);
+ const installPayload = useMemo(() => {
+ if (!studioElement?.element.isCaptionStyle) return studioElement;
+ // The generated transcript comes from Studio, never from the demo fixture.
+ const { captions: _captions, ...styleProps } = values;
+ return {
+ ...studioElement,
+ element: { ...studioElement.element, initialProps: styleProps },
+ } as StudioElementPayload;
+ }, [studioElement, values]);
const [copied, setCopied] = useState(false);
const handleCopyLink = () => {
@@ -128,6 +164,77 @@ function Preview({
);
};
+ const stage = (className: string, controls = true) => (
+ <PreviewStage
+ name={name}
+ load={load}
+ inputProps={values}
+ durationInFrames={
+ config.getDurationInFrames?.(values) ?? config.durationInFrames
+ }
+ fps={config.fps}
+ compositionWidth={config.compositionWidth}
+ compositionHeight={config.compositionHeight}
+ previewBackdrop={config.previewBackdrop}
+ className={className}
+ controls={controls}
+ />
+ );
+ const studioActions = installPayload ? (
+ <StudioActions name={name} payload={installPayload} />
+ ) : null;
+
+ // Remotion Studio's caption picker is a small fixed panel (~600x290), so
+ // everything has to fit without scrolling the page: one header row with the
+ // actions, then the preview beside compact options. The transcript control
+ // is hidden: Studio supplies the captions.
+ if (layout === "caption-picker") {
+ return (
+ <div className="flex min-h-0 flex-1 flex-col gap-2">
+ <div className="grid shrink-0 grid-cols-[1fr_auto_1fr] items-center gap-2">
+ <div className="justify-self-start">{header?.start}</div>
+ <h1 className="min-w-0 truncate text-center text-sm font-semibold tracking-tight">
+ {header?.title}
+ </h1>
+ <div className="flex items-center gap-1 justify-self-end">
+ {header?.end}
+ <Button
+ variant="ghost"
+ size="icon-sm"
+ onClick={handleReset}
+ disabled={isDefault}
+ aria-label="Reset options"
+ title="Reset options"
+ className="text-muted-foreground hover:text-foreground disabled:opacity-40"
+ >
+ <RotateCcwIcon className="size-3.5" />
+ </Button>
+ {studioActions}
+ </div>
+ </div>
+ <div className="flex min-h-0 flex-1 gap-3">
+ <div className="surface-card aspect-video w-[40%] shrink-0 self-start overflow-hidden rounded-xl">
+ {stage("aspect-auto h-full rounded-none", false)}
+ </div>
+ <div className="@container min-h-0 flex-1 overflow-x-hidden overflow-y-auto [scrollbar-color:color-mix(in_oklab,currentColor_25%,transparent)_transparent] [scrollbar-width:thin]">
+ <div className="[&>div]:grid-cols-1 @min-[280px]:[&>div]:grid-cols-2">
+ <ComponentCustomizer
+ density="compact"
+ controls={Object.fromEntries(
+ Object.entries(config.controls).filter(
+ ([key]) => key !== "captions",
+ ),
+ )}
+ values={values as Record<string, unknown>}
+ onChange={handleCustomizeChange}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+ }
+
return (
<div className="not-prose mb-6 flex w-full flex-col gap-4">
<Frame>
@@ -137,26 +244,11 @@ function Preview({
<TabsTrigger value="preview">Preview</TabsTrigger>
<TabsTrigger value="code">Code</TabsTrigger>
</TabsList>
- {studioElement ? (
- <StudioActions name={name} payload={studioElement} />
- ) : null}
+ {studioActions}
</FrameHeader>
<FramePanel className="overflow-hidden p-0">
<TabsContent value="preview" className="mt-0">
- <PreviewStage
- name={name}
- load={load}
- inputProps={values}
- durationInFrames={
- config.getDurationInFrames?.(values) ??
- config.durationInFrames
- }
- fps={config.fps}
- compositionWidth={config.compositionWidth}
- compositionHeight={config.compositionHeight}
- previewBackdrop={config.previewBackdrop}
- className="rounded-none"
- />
+ {stage("rounded-none")}
</TabsContent>
<TabsContent value="code" className="mt-0">
<CodeBlock code={code} />
diff --git a/components/docs/studio-actions.tsx b/components/docs/studio-actions.tsx
index 85c2c9a3..2ad8efd3 100644
--- a/components/docs/studio-actions.tsx
+++ b/components/docs/studio-actions.tsx
@@ -5,6 +5,7 @@ import {
isInsideStudio,
type StudioElementPayload,
setStudioDragData,
+ subscribeToCaptionStyleSelection,
} from "@remotion/studio-protocol";
import { GripVerticalIcon, Loader2Icon } from "lucide-react";
import { useEffect, useLayoutEffect, useRef, useState } from "react";
@@ -27,6 +28,18 @@ export function StudioActions({
const [isEmbeddedInStudio, setIsEmbeddedInStudio] = useState<boolean | null>(
null,
);
+ const [selectedSlug, setSelectedSlug] = useState<string | null>(null);
+ const isCaptionPicker =
+ isEmbeddedInStudio === true &&
+ payload.element.isCaptionStyle === true &&
+ new URLSearchParams(window.location.search).get(
+ "remotion-studio-context",
+ ) === "captions";
+ const isSelected = isCaptionPicker && selectedSlug === payload.element.slug;
+ useEffect(() => {
+ if (!isCaptionPicker) return;
+ return subscribeToCaptionStyleSelection(setSelectedSlug);
+ }, [isCaptionPicker]);
const resetTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
useLayoutEffect(() => {
@@ -48,7 +61,9 @@ export function StudioActions({
if (result.success) {
setStatus("success");
setMessage(
- `Sent to Remotion Studio${result.target.projectName === null ? "" : ` (${result.target.projectName})`}.`,
+ isCaptionPicker
+ ? null
+ : `Sent to Remotion Studio${result.target.projectName === null ? "" : ` (${result.target.projectName})`}.`,
);
} else {
setStatus("error");
@@ -81,6 +96,7 @@ export function StudioActions({
size="sm"
onClick={handleInstall}
disabled={status === "pending"}
+ aria-pressed={isCaptionPicker ? isSelected : undefined}
className="text-muted-foreground hover:text-foreground"
>
{status === "pending" ? (
@@ -88,9 +104,13 @@ export function StudioActions({
) : (
<Remotion className="size-3.5" />
)}
- {status === "success"
- ? "Sent to Remotion Studio"
- : "Add to Remotion Studio"}
+ {isCaptionPicker
+ ? isSelected
+ ? "Update style"
+ : "Use this style"
+ : status === "success"
+ ? "Sent to Remotion Studio"
+ : "Add to Remotion Studio"}
</Button>
{isEmbeddedInStudio === false ? (
<Button
diff --git a/lib/ui-preview-internals.tsx b/lib/ui-preview-internals.tsx
index 76e77b90..3aa75a1a 100644
--- a/lib/ui-preview-internals.tsx
+++ b/lib/ui-preview-internals.tsx
@@ -76,6 +76,7 @@ export function PreviewStage({
compositionHeight,
previewBackdrop,
className,
+ controls = true,
}: {
name: string;
// biome-ignore lint/suspicious/noExplicitAny: dynamically-loaded Remotion composition, props shape varies per component
@@ -89,6 +90,8 @@ export function PreviewStage({
compositionHeight: number;
previewBackdrop?: BackdropFill;
className?: string;
+ /** Player control bar. Without it a click still toggles playback. */
+ controls?: boolean;
}) {
const [mounted, setMounted] = useState(false);
const frameRef = useRef<HTMLDivElement>(null);
@@ -216,7 +219,8 @@ export function PreviewStage({
compositionWidth={compositionWidth}
compositionHeight={compositionHeight}
style={{ width: "100%", height: "100%" }}
- controls
+ controls={controls}
+ clickToPlay
loop
acknowledgeRemotionLicense
/>
diff --git a/package.json b/package.json
index 45911a8f..f388be6c 100644
--- a/package.json
+++ b/package.json
@@ -61,7 +61,7 @@
"@remotion/paths": "4.0.530",
"@remotion/player": "4.0.530",
"@remotion/renderer": "4.0.530",
- "@remotion/studio-protocol": "4.0.530",
+ "@remotion/studio-protocol": "4.0.535",
"@remotion/transitions": "4.0.530",
"@remotion/zod-types": "4.0.530",
"@shadcn/react": "^0.1.0",
diff --git a/registry-artifacts/elements/caption-active-pop.json b/registry-artifacts/elements/caption-active-pop.json
index 01a2ca6d..72dbbe07 100644
--- a/registry-artifacts/elements/caption-active-pop.json
+++ b/registry-artifacts/elements/caption-active-pop.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-active-pop",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, interpolateColors, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionActivePopProps extends CaptionBaseProps {\n activeColor?: string;\n popScale?: number;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst POP_SPRING = { damping: 12, stiffness: 220, mass: 0.6 };\nconst RELEASE_SPRING = { damping: 20, stiffness: 200, mass: 0.6 };\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionActivePopBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n activeColor = \"#facc15\",\n popScale = 1.12,\n shadow = true,\n className,\n}: CaptionActivePopProps) {\n const { fps } = useVideoConfig();\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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\n const words = groupCaptionWords(state.tokens);\n const activeWord = words.findIndex((word) =>\n word.some(({ index }) => index === state.activeIndex),\n );\n const toFrames = (ms: number) => (ms / 1000) * fps;\n\n const emphasis = (w: number): number => {\n if (activeWord < 0 || w > activeWord) return 0;\n const startMs = words[w][0].token.fromMs;\n if (w === activeWord) {\n return spring({\n frame: toFrames(state.timeMs - startMs),\n fps,\n config: POP_SPRING,\n });\n }\n if (w < activeWord - 1) return 0;\n const releaseMs = words[w + 1][0].token.fromMs;\n const peak = spring({\n frame: toFrames(releaseMs - startMs),\n fps,\n config: POP_SPRING,\n });\n const release = spring({\n frame: toFrames(state.timeMs - releaseMs),\n fps,\n config: RELEASE_SPRING,\n });\n return peak * (1 - release);\n };\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: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {words.map((word, w) => {\n const amount = emphasis(w);\n return (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n style={{\n position: \"relative\",\n zIndex: w === activeWord ? 1 : 0,\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n transform: `scale(${1 + (popScale - 1) * amount})`,\n transformOrigin: \"50% 60%\",\n color: interpolateColors(\n Math.min(1, Math.max(0, amount)),\n [0, 1],\n [color, activeColor],\n ),\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {word.map(({ index, token }) => (\n <span key={index}>{token.text}</span>\n ))}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n activeColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Active word color\",\n },\n popScale: {\n type: \"number\",\n min: 1,\n max: 1.5,\n step: 0.01,\n default: 1.12,\n description: \"Pop scale\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"activeColor\",\"popScale\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n activeColor: \"#facc15\",\n popScale: 1.12,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionActivePopElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionActivePopBase>;\n\nconst CaptionActivePopInner = forwardRef<\n HTMLDivElement,\n CaptionActivePopElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionActivePop>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionActivePopBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionActivePopBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionActivePop = Interactive.withSchema({\n Component: CaptionActivePopInner,\n componentName: \"<CaptionActivePop>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-blur-in.json b/registry-artifacts/elements/caption-blur-in.json
index a0fa6999..8b4e452c 100644
--- a/registry-artifacts/elements/caption-blur-in.json
+++ b/registry-artifacts/elements/caption-blur-in.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-blur-in",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionBlurInProps extends CaptionBaseProps {\n blur?: number;\n shadow?: boolean;\n}\n\nconst EXIT_MS = 220;\nconst RESOLVE_MS = 220;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst resolveEasing = Easing.bezier(0.25, 0.6, 0.3, 1);\n\nfunction CaptionBlurInBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n blur = 12,\n shadow = true,\n className,\n}: CaptionBlurInProps) {\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 {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n },\n )\n : 1;\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 const p =\n sinceMs < 0\n ? 0\n : interpolate(sinceMs, [0, RESOLVE_MS], [0, 1], {\n easing: resolveEasing,\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n const radius = (1 - p) * blur;\n return (\n <span\n key={index}\n style={{\n display: \"inline-block\",\n opacity: p,\n filter: radius > 0.01 ? `blur(${radius}px)` : undefined,\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {token.text}\n </span>\n );\n })}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n blur: {\n type: \"number\",\n min: 0,\n max: 32,\n step: 1,\n default: 12,\n description: \"Blur (px)\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"blur\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n blur: 12,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionBlurInElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionBlurInBase>;\n\nconst CaptionBlurInInner = forwardRef<\n HTMLDivElement,\n CaptionBlurInElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionBlurIn>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionBlurInBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionBlurInBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionBlurIn = Interactive.withSchema({\n Component: CaptionBlurInInner,\n componentName: \"<CaptionBlurIn>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-bounce-in.json b/registry-artifacts/elements/caption-bounce-in.json
index 08b7212f..1851ea06 100644
--- a/registry-artifacts/elements/caption-bounce-in.json
+++ b/registry-artifacts/elements/caption-bounce-in.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-bounce-in",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Interactive, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionBounceInProps extends CaptionBaseProps {\n bounce?: number;\n shadow?: boolean;\n}\n\nconst EXIT_MS = 220;\nconst FADE_IN_MS = 90;\nconst DROP_EM = 0.35;\nconst START_SCALE = 0.7;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nfunction CaptionBounceInBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n bounce = 0.6,\n shadow = true,\n className,\n}: CaptionBounceInProps) {\n const { fps } = useVideoConfig();\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const damping = interpolate(bounce, [0, 1], [22, 7], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n const exit = state.endsInSilence\n ? interpolate(\n state.untilEndMs,\n [0, getExitWindowMs(state, EXIT_MS)],\n [0, 1],\n {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n },\n )\n : 1;\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 const arrived = sinceMs >= 0;\n const p = arrived\n ? spring({\n frame: (sinceMs / 1000) * fps,\n fps,\n config: { damping, stiffness: 220, mass: 0.6 },\n })\n : 0;\n const opacity = arrived\n ? interpolate(sinceMs, [0, FADE_IN_MS], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n })\n : 0;\n return (\n <span\n key={index}\n style={{\n display: \"inline-block\",\n opacity,\n transform: `translateY(${(1 - p) * DROP_EM}em) scale(${\n START_SCALE + (1 - START_SCALE) * p\n })`,\n transformOrigin: \"50% 80%\",\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {token.text}\n </span>\n );\n })}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n bounce: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.05,\n default: 0.6,\n description: \"Bounce\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"bounce\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n bounce: 0.6,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionBounceInElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionBounceInBase>;\n\nconst CaptionBounceInInner = forwardRef<\n HTMLDivElement,\n CaptionBounceInElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionBounceIn>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionBounceInBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionBounceInBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionBounceIn = Interactive.withSchema({\n Component: CaptionBounceInInner,\n componentName: \"<CaptionBounceIn>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-cube.json b/registry-artifacts/elements/caption-cube.json
index 268fd2b4..dc4a8c6f 100644
--- a/registry-artifacts/elements/caption-cube.json
+++ b/registry-artifacts/elements/caption-cube.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-cube",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionCubeProps extends CaptionBaseProps {\n tintActive?: boolean;\n activeColor?: string;\n shadow?: boolean;\n}\n\nconst LINE_HEIGHT = 1.3;\nconst DEPTH_EM = LINE_HEIGHT / 2;\nconst TURN_MS = 320;\nconst EXIT_MS = 280;\nconst PERSPECTIVE_EM = 10;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst turnEasing = Easing.bezier(0.65, 0, 0.35, 1);\nconst exitEasing = Easing.bezier(0.7, 0, 0.84, 0);\n\nfunction CubeFace({\n tokens,\n activeIndex,\n activeColor,\n angle,\n before,\n style,\n}: {\n tokens: CaptionTokenState[];\n activeIndex: number;\n activeColor: string | undefined;\n angle: number;\n before: string;\n style?: CSSProperties;\n}) {\n const facing = Math.max(0, Math.cos((angle * Math.PI) / 180));\n return (\n <div\n style={{\n whiteSpace: \"nowrap\",\n backfaceVisibility: \"hidden\",\n WebkitBackfaceVisibility: \"hidden\",\n opacity: 0.35 + 0.65 * facing,\n transform: `${before}rotateX(${angle}deg) translateZ(${DEPTH_EM}em)`,\n ...style,\n }}\n >\n {groupCaptionWords(tokens).map((word, w) => (\n <Fragment key={word[0].index}>\n {w > 0 && \" \"}\n {word.map(({ index, token }) => (\n <span\n key={index}\n style={{\n color:\n activeColor !== undefined && index === activeIndex\n ? activeColor\n : undefined,\n }}\n >\n {token.text}\n </span>\n ))}\n </Fragment>\n ))}\n </div>\n );\n}\n\nfunction CaptionCubeBase({\n captions,\n combineTokensWithinMilliseconds = 800,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n tintActive = false,\n activeColor = \"#facc15\",\n shadow = true,\n className,\n}: CaptionCubeProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const turnMs = Math.max(\n 1,\n Math.min(TURN_MS, state.sinceStartMs + state.untilEndMs),\n );\n const turn = interpolate(state.sinceStartMs, [0, turnMs], [0, 1], {\n easing: turnEasing,\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n const exitProgress = state.endsInSilence\n ? exitEasing(\n Math.min(\n 1,\n Math.max(0, 1 - state.untilEndMs / getExitWindowMs(state, EXIT_MS)),\n ),\n )\n : 0;\n const currentAngle = (turn - 1) * 90 + exitProgress * 90;\n\n return (\n <div\n className={className}\n style={{\n position: \"relative\",\n fontSize,\n fontWeight,\n color,\n lineHeight: LINE_HEIGHT,\n height: `${LINE_HEIGHT}em`,\n textAlign: \"center\",\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n perspective: `${PERSPECTIVE_EM}em`,\n }}\n >\n <div\n style={{\n position: \"relative\",\n height: \"100%\",\n transformStyle: \"preserve-3d\",\n transform: `translateZ(${-DEPTH_EM}em)`,\n }}\n >\n {state.previous && turn < 1 ? (\n <CubeFace\n key={`page-${state.previous.pageIndex}`}\n tokens={state.previous.tokens}\n activeIndex={-1}\n activeColor={undefined}\n angle={turn * 90}\n before=\"translateX(-50%) \"\n style={{ position: \"absolute\", top: 0, left: \"50%\" }}\n />\n ) : null}\n <CubeFace\n key={`page-${state.pageIndex}`}\n tokens={state.tokens}\n activeIndex={state.activeIndex}\n activeColor={tintActive ? activeColor : undefined}\n angle={currentAngle}\n before=\"\"\n />\n </div>\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n tintActive: {\n type: \"boolean\",\n default: false,\n description: \"Tint active word\",\n },\n activeColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Active color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 800,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"tintActive\",\"activeColor\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n tintActive: false,\n activeColor: \"#facc15\",\n combineTokensWithinMilliseconds: 800,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionCubeElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionCubeBase>;\n\nconst CaptionCubeInner = forwardRef<\n HTMLDivElement,\n CaptionCubeElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionCube>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionCubeBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionCubeBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionCube = Interactive.withSchema({\n Component: CaptionCubeInner,\n componentName: \"<CaptionCube>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-dim-progress.json b/registry-artifacts/elements/caption-dim-progress.json
index 0d653e19..5f566c54 100644
--- a/registry-artifacts/elements/caption-dim-progress.json
+++ b/registry-artifacts/elements/caption-dim-progress.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-dim-progress",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionDimProgressProps extends CaptionBaseProps {\n dimOpacity?: number;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst BRIGHTEN_MS = 90;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionDimProgressBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n dimOpacity = 0.35,\n shadow = true,\n className,\n}: CaptionDimProgressProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.2,\n textAlign: \"center\",\n opacity: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\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 <span\n key={index}\n style={{\n opacity: interpolate(\n state.timeMs - token.fromMs,\n [0, BRIGHTEN_MS],\n [dimOpacity, 1],\n clamp,\n ),\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {token.text}\n </span>\n ))}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n dimOpacity: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.05,\n default: 0.35,\n description: \"Upcoming opacity\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"dimOpacity\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n dimOpacity: 0.35,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionDimProgressElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionDimProgressBase>;\n\nconst CaptionDimProgressInner = forwardRef<\n HTMLDivElement,\n CaptionDimProgressElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionDimProgress>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionDimProgressBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionDimProgressBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionDimProgress = Interactive.withSchema({\n Component: CaptionDimProgressInner,\n componentName: \"<CaptionDimProgress>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-drop.json b/registry-artifacts/elements/caption-drop.json
index 30dbcb9d..bf255cb5 100644
--- a/registry-artifacts/elements/caption-drop.json
+++ b/registry-artifacts/elements/caption-drop.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-drop",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Interactive, Sequence, interpolate, random, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionDropProps extends CaptionBaseProps {\n bounce?: number;\n shadow?: boolean;\n}\n\nconst EXIT_MS = 360;\nconst EXIT_STAGGER_MS = 120;\nconst FADE_IN_MS = 80;\nconst FALL_EM = 1.4;\nconst EXIT_FALL_EM = 1.8;\nconst MAX_TILT_DEG = 6;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionDropBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n bounce = 0.6,\n shadow = true,\n className,\n}: CaptionDropProps) {\n const { fps } = useVideoConfig();\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const damping = interpolate(bounce, [0, 1], [20, 6], clamp);\n const words = groupCaptionWords(state.tokens);\n const exitWindow = getExitWindowMs(state, EXIT_MS);\n const exitElapsed = state.endsInSilence\n ? Math.max(0, exitWindow - state.untilEndMs)\n : 0;\n const stagger = Math.min(EXIT_STAGGER_MS, exitWindow * 0.4);\n const fallSpan = Math.max(1, exitWindow - stagger);\n\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.2,\n textAlign: \"center\",\n }}\n >\n {words.map((word, w) => {\n const first = word[0];\n const sinceMs = state.timeMs - first.token.fromMs;\n const arrived = sinceMs >= 0;\n const landed = arrived\n ? spring({\n frame: (sinceMs / 1000) * fps,\n fps,\n config: { damping, stiffness: 180, mass: 0.7 },\n })\n : 0;\n const fadeIn = arrived\n ? interpolate(sinceMs, [0, FADE_IN_MS], [0, 1], clamp)\n : 0;\n const tilt =\n (random(`${state.pageIndex}-${first.index}-tilt`) * 2 - 1) *\n MAX_TILT_DEG;\n const delay = words.length > 1 ? (w / (words.length - 1)) * stagger : 0;\n const out = state.endsInSilence\n ? Math.min(1, Math.max(0, (exitElapsed - delay) / fallSpan))\n : 0;\n const gravity = out * out;\n const y = -(1 - landed) * FALL_EM + gravity * EXIT_FALL_EM;\n const rotate = tilt * (1 - landed) - tilt * 0.6 * gravity;\n return (\n <Fragment key={`${state.pageIndex}-${first.index}`}>\n {w > 0 && \" \"}\n <span\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n opacity: fadeIn * (1 - out ** 1.5),\n transform: `translateY(${y}em) rotate(${rotate}deg)`,\n transformOrigin: \"50% 100%\",\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {word.map(({ index, token }) => (\n <span key={index}>{token.text}</span>\n ))}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n bounce: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.05,\n default: 0.6,\n description: \"Bounce\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"bounce\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n bounce: 0.6,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionDropElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionDropBase>;\n\nconst CaptionDropInner = forwardRef<\n HTMLDivElement,\n CaptionDropElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionDrop>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionDropBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionDropBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionDrop = Interactive.withSchema({\n Component: CaptionDropInner,\n componentName: \"<CaptionDrop>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-emoji.json b/registry-artifacts/elements/caption-emoji.json
index d26ecff8..4ac32324 100644
--- a/registry-artifacts/elements/caption-emoji.json
+++ b/registry-artifacts/elements/caption-emoji.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-emoji",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionEmojiProps extends CaptionBaseProps {\n emoji?: Record<string, string>;\n emojiSize?: number;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst POP_SPRING = { damping: 9, stiffness: 180, mass: 0.6 };\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionEmojiBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n emoji = {},\n emojiSize = 0.9,\n shadow = true,\n className,\n}: CaptionEmojiProps) {\n const { fps } = useVideoConfig();\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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\n const lookup = new Map(\n Object.entries(emoji).map(([word, glyph]) => [\n normalizeCaptionWord(word),\n glyph,\n ]),\n );\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: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {groupCaptionWords(state.tokens).map((word, w) => {\n const first = word[0].token;\n const glyph = lookup.get(normalizeCaptionWord(captionWordText(word)));\n const pop =\n glyph && first.status !== \"upcoming\"\n ? spring({\n frame: ((state.timeMs - first.fromMs) / 1000) * fps,\n fps,\n config: POP_SPRING,\n })\n : 0;\n return (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n style={{\n position: \"relative\",\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {glyph && pop > 0 && (\n <span\n aria-hidden\n style={{\n position: \"absolute\",\n left: \"50%\",\n bottom: \"92%\",\n fontSize: `${emojiSize}em`,\n lineHeight: 1,\n textShadow: \"none\",\n transformOrigin: \"50% 100%\",\n transform: `translateX(-50%) rotate(${14 - 20 * pop}deg) scale(${pop})`,\n }}\n >\n {glyph}\n </span>\n )}\n {word.map(({ index, token }) => (\n <span key={index}>{token.text}</span>\n ))}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n emojiSize: {\n type: \"number\",\n min: 0.4,\n max: 2,\n step: 0.05,\n default: 0.9,\n description: \"Emoji size (em)\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"emojiSize\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n emojiSize: 0.9,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionEmojiElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionEmojiBase>;\n\nconst CaptionEmojiInner = forwardRef<\n HTMLDivElement,\n CaptionEmojiElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionEmoji>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionEmojiBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionEmojiBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionEmoji = Interactive.withSchema({\n Component: CaptionEmojiInner,\n componentName: \"<CaptionEmoji>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-handwrite.json b/registry-artifacts/elements/caption-handwrite.json
index c048cf23..c7bb401d 100644
--- a/registry-artifacts/elements/caption-handwrite.json
+++ b/registry-artifacts/elements/caption-handwrite.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-handwrite",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, random, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionHandwriteProps extends CaptionBaseProps {\n wobble?: number;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst MIN_WRITE_MS = 200;\nconst EDGE_PERCENT = 22;\nconst MASK_PAD_EM = 0.4;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionHandwriteBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n wobble = 1,\n shadow = true,\n className,\n}: CaptionHandwriteProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n { ...clamp, easing: enterEasing },\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: Math.min(enter, exit),\n }}\n >\n {groupCaptionWords(state.tokens).map((word, w) => {\n const text = captionWordText(word);\n const fromMs = word[0].token.fromMs;\n const toMs = word[word.length - 1].token.toMs;\n const writeMs = Math.max(toMs - fromMs, MIN_WRITE_MS);\n const written = interpolate(\n state.timeMs - fromMs,\n [0, writeMs],\n [0, 1],\n clamp,\n );\n const seed = `caption-handwrite-${state.pageIndex}-${word[0].index}`;\n const tilt = (random(`${seed}-tilt`) * 3 - 1.5) * wobble;\n const lift = (random(`${seed}-lift`) * 0.08 - 0.04) * wobble;\n const head = written * (100 + EDGE_PERCENT);\n const stop = (percent: number): string =>\n `calc(${MASK_PAD_EM}em + (100% - ${MASK_PAD_EM * 2}em) * ${percent / 100})`;\n const mask =\n written > 0 && written < 1\n ? `linear-gradient(90deg, #000 ${stop(head - EDGE_PERCENT)}, transparent ${stop(head)})`\n : undefined;\n return (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n opacity: written > 0 ? 1 : 0,\n padding: `${MASK_PAD_EM}em`,\n margin: `-${MASK_PAD_EM}em`,\n transform: `translateY(${lift}em) rotate(${tilt}deg)`,\n WebkitMaskImage: mask,\n maskImage: mask,\n textShadow,\n }}\n >\n {Array.from(text).map((char, c) => (\n <span\n key={c}\n style={{\n display: \"inline-block\",\n whiteSpace: \"pre\",\n transform: `rotate(${(random(`${seed}-${c}`) * 6 - 3) * wobble}deg)`,\n }}\n >\n {char}\n </span>\n ))}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n wobble: {\n type: \"number\",\n min: 0,\n max: 2,\n step: 0.1,\n default: 1,\n description: \"Wobble\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"wobble\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n wobble: 1,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionHandwriteElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionHandwriteBase>;\n\nconst CaptionHandwriteInner = forwardRef<\n HTMLDivElement,\n CaptionHandwriteElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionHandwrite>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionHandwriteBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionHandwriteBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionHandwrite = Interactive.withSchema({\n Component: CaptionHandwriteInner,\n componentName: \"<CaptionHandwrite>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-highlight-box.json b/registry-artifacts/elements/caption-highlight-box.json
index 87479576..abbb02bd 100644
--- a/registry-artifacts/elements/caption-highlight-box.json
+++ b/registry-artifacts/elements/caption-highlight-box.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-highlight-box",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, interpolateColors, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionHighlightBoxProps extends CaptionBaseProps {\n activeColor?: string;\n boxColor?: string;\n boxRadius?: number;\n boxPadding?: number;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst TRAVEL_MS = 120;\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst travelEasing = Easing.bezier(0.3, 0, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction legibilityShadow(strength: number): string | undefined {\n if (strength <= 0) return undefined;\n return `0 2px 3px rgba(0, 0, 0, ${0.5 * strength}), 0 4px 16px rgba(0, 0, 0, ${0.35 * strength})`;\n}\n\nfunction mix(a: number, b: number, t: number): number {\n return a + (b - a) * t;\n}\n\nfunction CaptionHighlightBoxBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n activeColor = \"#0a0a0a\",\n boxColor = \"#facc15\",\n boxRadius = 0.16,\n boxPadding = 0.14,\n shadow = true,\n className,\n}: CaptionHighlightBoxProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n const words = state ? groupCaptionWords(state.tokens) : [];\n const pageIndex = state ? state.pageIndex : -1;\n const { wordRef, rects } = useCaptionWordRects(pageIndex, words.length);\n\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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\n const activeWord = words.findIndex((word) =>\n word.some(({ index }) => index === state.activeIndex),\n );\n const travel =\n activeWord >= 0\n ? interpolate(\n state.timeMs - words[activeWord][0].token.fromMs,\n [0, TRAVEL_MS],\n [0, 1],\n { ...clamp, easing: travelEasing },\n )\n : 0;\n\n const target = rects && activeWord >= 0 ? rects[activeWord] : null;\n const origin = rects && activeWord > 0 ? rects[activeWord - 1] : null;\n const padX = boxPadding * fontSize;\n const padY = boxPadding * 0.3 * fontSize;\n const box = target\n ? {\n left: origin ? mix(origin.left, target.left, travel) : target.left,\n top: origin ? mix(origin.top, target.top, travel) : target.top,\n width: origin ? mix(origin.width, target.width, travel) : target.width,\n height: origin\n ? mix(origin.height, target.height, travel)\n : target.height,\n opacity: origin ? 1 : travel,\n }\n : null;\n\n const coverage = (w: number): number => {\n if (!box) return 0;\n if (w === activeWord) {\n return origin ? interpolate(travel, [0.3, 0.8], [0, 1], clamp) : travel;\n }\n if (origin && w === activeWord - 1) {\n return 1 - interpolate(travel, [0.2, 0.7], [0, 1], clamp);\n }\n return 0;\n };\n\n return (\n <div\n className={className}\n style={{\n position: \"relative\",\n isolation: \"isolate\",\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.2,\n textAlign: \"center\",\n opacity: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {box && (\n <span\n aria-hidden\n style={{\n position: \"absolute\",\n left: box.left - padX,\n top: box.top - padY,\n width: box.width + padX * 2,\n height: box.height + padY * 2,\n borderRadius: boxRadius * fontSize,\n background: boxColor,\n opacity: box.opacity,\n }}\n />\n )}\n {words.map((word, w) => {\n const covered = coverage(w);\n return (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n ref={wordRef(w)}\n style={{\n position: \"relative\",\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n color: interpolateColors(covered, [0, 1], [color, activeColor]),\n textShadow: legibilityShadow(shadow ? 1 - covered : 0),\n }}\n >\n {word.map(({ index, token }) => (\n <span key={index}>{token.text}</span>\n ))}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n activeColor: {\n type: \"color\",\n default: \"#0a0a0a\",\n description: \"Text on box\",\n },\n boxColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Box color\",\n },\n boxRadius: {\n type: \"number\",\n min: 0,\n max: 0.5,\n step: 0.01,\n default: 0.16,\n description: \"Box radius (em)\",\n hiddenFromList: false,\n },\n boxPadding: {\n type: \"number\",\n min: 0,\n max: 0.4,\n step: 0.01,\n default: 0.14,\n description: \"Box padding (em)\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"activeColor\",\"boxColor\",\"boxRadius\",\"boxPadding\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n activeColor: \"#0a0a0a\",\n boxColor: \"#facc15\",\n boxRadius: 0.16,\n boxPadding: 0.14,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionHighlightBoxElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionHighlightBoxBase>;\n\nconst CaptionHighlightBoxInner = forwardRef<\n HTMLDivElement,\n CaptionHighlightBoxElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionHighlightBox>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionHighlightBoxBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionHighlightBoxBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionHighlightBox = Interactive.withSchema({\n Component: CaptionHighlightBoxInner,\n componentName: \"<CaptionHighlightBox>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-karaoke.json b/registry-artifacts/elements/caption-karaoke.json
index cd04c257..39cb9457 100644
--- a/registry-artifacts/elements/caption-karaoke.json
+++ b/registry-artifacts/elements/caption-karaoke.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-karaoke",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionKaraokeProps extends CaptionBaseProps {\n activeColor?: string;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nfunction CaptionKaraokeBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n activeColor = \"#facc15\",\n shadow = true,\n className,\n}: CaptionKaraokeProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n easing: enterEasing,\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n },\n );\n const exit = state.endsInSilence\n ? interpolate(\n state.untilEndMs,\n [0, getExitWindowMs(state, EXIT_MS)],\n [0, 1],\n {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n },\n )\n : 1;\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: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\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 <span\n key={index}\n style={{ position: \"relative\", display: \"inline-block\" }}\n >\n <span\n style={{ textShadow: shadow ? LEGIBILITY_SHADOW : undefined }}\n >\n {token.text}\n </span>\n <span\n aria-hidden\n style={{\n position: \"absolute\",\n inset: 0,\n color: activeColor,\n clipPath: `inset(0 ${(1 - token.progress) * 100}% 0 0)`,\n }}\n >\n {token.text}\n </span>\n </span>\n ))}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n activeColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Fill color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"activeColor\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n activeColor: \"#facc15\",\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionKaraokeElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionKaraokeBase>;\n\nconst CaptionKaraokeInner = forwardRef<\n HTMLDivElement,\n CaptionKaraokeElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionKaraoke>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionKaraokeBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionKaraokeBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionKaraoke = Interactive.withSchema({\n Component: CaptionKaraokeInner,\n componentName: \"<CaptionKaraoke>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-knockout.json b/registry-artifacts/elements/caption-knockout.json
index 7ab9dcfd..66761f8b 100644
--- a/registry-artifacts/elements/caption-knockout.json
+++ b/registry-artifacts/elements/caption-knockout.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-knockout",
"sourceCode": "import { Fragment, forwardRef, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionKnockoutProps extends Omit<CaptionBaseProps, \"color\"> {\n plateColor?: string;\n upcomingOpacity?: number;\n radius?: number;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst PUNCH_MS = 120;\nconst PAD_Y_EM = 0.22;\nconst PAD_X_EM = 0.42;\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst punchEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction holeFill(\n token: CaptionTokenState,\n timeMs: number,\n upcomingOpacity: number,\n): string {\n const since = timeMs - token.fromMs;\n const hole =\n since < 0\n ? upcomingOpacity\n : interpolate(since, [0, PUNCH_MS], [upcomingOpacity, 1], {\n ...clamp,\n easing: punchEasing,\n });\n const level = Math.round(255 * (1 - Math.min(1, Math.max(0, hole))));\n return `rgb(${level}, ${level}, ${level})`;\n}\n\nfunction CaptionKnockoutBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n plateColor = \"#ffffff\",\n upcomingOpacity = 0.15,\n radius = 0.16,\n className,\n}: CaptionKnockoutProps) {\n const maskId = `caption-knockout-${useId().replace(/[^a-zA-Z0-9-]/g, \"\")}`;\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n const words = state ? groupCaptionWords(state.tokens) : [];\n const { wordRef, rects } = useCaptionWordRects(\n state ? state.pageIndex : -1,\n words.length,\n );\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n { ...clamp, easing: enterEasing },\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\n return (\n <div\n className={className}\n style={{\n position: \"relative\",\n fontSize,\n fontWeight,\n lineHeight: 1.2,\n textAlign: \"center\",\n padding: `${PAD_Y_EM}em ${PAD_X_EM}em`,\n opacity: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {rects && (\n <svg\n aria-hidden\n width=\"100%\"\n height=\"100%\"\n style={{\n position: \"absolute\",\n inset: 0,\n width: \"100%\",\n height: \"100%\",\n overflow: \"visible\",\n }}\n >\n <defs>\n <mask\n id={maskId}\n maskUnits=\"userSpaceOnUse\"\n x=\"0\"\n y=\"0\"\n width=\"100%\"\n height=\"100%\"\n >\n <rect width=\"100%\" height=\"100%\" fill=\"#ffffff\" />\n {words.map((word, w) => {\n const rect = rects[w];\n if (!rect) return null;\n return (\n <text\n key={`${state.pageIndex}-${word[0].index}`}\n x={rect.left}\n y={rect.top + rect.height / 2}\n dominantBaseline=\"central\"\n >\n {word.map(({ index, token }) => (\n <tspan\n key={index}\n fill={holeFill(token, state.timeMs, upcomingOpacity)}\n >\n {token.text}\n </tspan>\n ))}\n </text>\n );\n })}\n </mask>\n </defs>\n <rect\n width=\"100%\"\n height=\"100%\"\n rx={radius * fontSize}\n fill={plateColor}\n mask={`url(#${maskId})`}\n />\n </svg>\n )}\n {words.map((word, w) => (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n ref={wordRef(w)}\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n color: \"transparent\",\n }}\n >\n {word.map(({ index, token }) => (\n <span key={index}>{token.text}</span>\n ))}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n plateColor: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Plate color\",\n },\n upcomingOpacity: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.05,\n default: 0.15,\n description: \"Upcoming words\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"plateColor\",\"upcomingOpacity\",\"combineTokensWithinMilliseconds\",\"holdMs\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n plateColor: \"#ffffff\",\n upcomingOpacity: 0.15,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n};\n\ntype CaptionKnockoutElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionKnockoutBase>;\n\nconst CaptionKnockoutInner = forwardRef<\n HTMLDivElement,\n CaptionKnockoutElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionKnockout>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionKnockoutBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionKnockoutBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionKnockout = Interactive.withSchema({\n Component: CaptionKnockoutInner,\n componentName: \"<CaptionKnockout>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-label-maker.json b/registry-artifacts/elements/caption-label-maker.json
index b3099701..78541680 100644
--- a/registry-artifacts/elements/caption-label-maker.json
+++ b/registry-artifacts/elements/caption-label-maker.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-label-maker",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionLabelMakerProps extends CaptionBaseProps {\n tapeColor?: string;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst PRESS_MS = 50;\nconst PRESS_SCALE = 0.92;\nconst TILT_DEG = -1.5;\nconst PAD_Y = 0.16;\nconst LEAD_EM = 0.42;\nconst RADIUS = 0.16;\nconst EMBOSS = \"0 1px 0 rgba(0, 0, 0, 0.55)\";\nconst RELIEF =\n \"inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 -1px 0 rgba(0, 0, 0, 0.5)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction revealedCount(\n count: number,\n fromMs: number,\n toMs: number,\n timeMs: number,\n): number {\n if (timeMs < fromMs) return 0;\n const duration = Math.max(toMs - fromMs, 1);\n return Math.min(\n count,\n Math.floor(((timeMs - fromMs) / duration) * count) + 1,\n );\n}\n\nfunction CaptionLabelMakerBase({\n captions,\n combineTokensWithinMilliseconds = 1000,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n tapeColor = \"#18181b\",\n className,\n}: CaptionLabelMakerProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n { ...clamp, easing: enterEasing },\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\n const segment: CSSProperties = {\n display: \"inline-block\",\n verticalAlign: \"top\",\n background: tapeColor,\n paddingBlock: `${PAD_Y}em`,\n paddingRight: 1,\n marginRight: -1,\n boxShadow: RELIEF,\n };\n\n const words = groupCaptionWords(state.tokens).map((word) => {\n const chars = Array.from(captionWordText(word));\n const fromMs = word[0].token.fromMs;\n const toMs = word[word.length - 1].token.toMs;\n return {\n key: `${state.pageIndex}-${word[0].index}`,\n chars,\n fromMs,\n toMs,\n revealed: revealedCount(chars.length, fromMs, toMs, state.timeMs),\n };\n });\n const last = words[words.length - 1];\n const finished = last !== undefined && last.revealed === last.chars.length;\n\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.1,\n textAlign: \"center\",\n opacity: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n <span\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n transform: `rotate(${TILT_DEG}deg)`,\n filter: \"drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35))\",\n }}\n >\n <span\n style={{\n ...segment,\n width: `${LEAD_EM}em`,\n borderRadius: `${RADIUS}em 0 0 ${RADIUS}em`,\n }}\n >\n {\"\\u00a0\"}\n </span>\n {words.map((word, w) => {\n const duration = Math.max(word.toMs - word.fromMs, 1);\n return (\n <Fragment key={word.key}>\n {w > 0 && (\n <span\n style={{\n ...segment,\n visibility: word.revealed > 0 ? \"visible\" : \"hidden\",\n }}\n >\n {\"\\u00a0\"}\n </span>\n )}\n {word.chars.map((char, c) => {\n const pressedAt =\n word.fromMs + (c / word.chars.length) * duration;\n const press = interpolate(\n state.timeMs - pressedAt,\n [0, PRESS_MS],\n [PRESS_SCALE, 1],\n clamp,\n );\n return (\n <span\n key={c}\n style={{\n ...segment,\n visibility: c < word.revealed ? \"visible\" : \"hidden\",\n }}\n >\n <span\n style={{\n display: \"inline-block\",\n transform: `scale(${press})`,\n textShadow: EMBOSS,\n }}\n >\n {char}\n </span>\n </span>\n );\n })}\n </Fragment>\n );\n })}\n <span\n style={{\n ...segment,\n width: `${LEAD_EM}em`,\n borderRadius: `0 ${RADIUS}em ${RADIUS}em 0`,\n visibility: finished ? \"visible\" : \"hidden\",\n }}\n >\n {\"\\u00a0\"}\n </span>\n </span>\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Letter color\",\n },\n tapeColor: {\n type: \"color\",\n default: \"#18181b\",\n description: \"Tape color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1000,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"tapeColor\",\"combineTokensWithinMilliseconds\",\"holdMs\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n tapeColor: \"#18181b\",\n combineTokensWithinMilliseconds: 1000,\n holdMs: 600,\n};\n\ntype CaptionLabelMakerElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionLabelMakerBase>;\n\nconst CaptionLabelMakerInner = forwardRef<\n HTMLDivElement,\n CaptionLabelMakerElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionLabelMaker>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionLabelMakerBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionLabelMakerBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionLabelMaker = Interactive.withSchema({\n Component: CaptionLabelMakerInner,\n componentName: \"<CaptionLabelMaker>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-marker.json b/registry-artifacts/elements/caption-marker.json
index c012a1fa..9e4b113e 100644
--- a/registry-artifacts/elements/caption-marker.json
+++ b/registry-artifacts/elements/caption-marker.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-marker",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionMarkerProps extends CaptionBaseProps {\n keywords?: string[];\n markerColor?: string;\n markerTextColor?: string;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst MIN_DRAW_MS = 220;\nconst PAD_EM = 0.12;\nconst RADIUS_EM = 0.18;\nconst TILT_DEG = -1;\nconst BAND_TOP = \"12%\";\nconst BAND_BOTTOM = \"2%\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst drawEasing = Easing.bezier(0.25, 1, 0.5, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction legibilityShadow(strength: number): string | undefined {\n if (strength <= 0) return undefined;\n return `0 2px 3px rgba(0, 0, 0, ${0.5 * strength}), 0 4px 16px rgba(0, 0, 0, ${0.35 * strength})`;\n}\n\nfunction CaptionMarkerBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n keywords,\n markerColor = \"#facc15\",\n markerTextColor = \"#0a0a0a\",\n shadow = true,\n className,\n}: CaptionMarkerProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const isKeyword = createKeywordMatcher(keywords);\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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 baseShadow = shadow ? 1 : 0;\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: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {groupCaptionWords(state.tokens).map((word, w) => {\n const key = `${state.pageIndex}-${word[0].index}`;\n const text = word.map(({ index, token }) => (\n <span key={index}>{token.text}</span>\n ));\n if (!isKeyword(captionWordText(word))) {\n return (\n <Fragment key={key}>\n {w > 0 && \" \"}\n <span\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n textShadow: legibilityShadow(baseShadow),\n }}\n >\n {text}\n </span>\n </Fragment>\n );\n }\n const fromMs = word[0].token.fromMs;\n const toMs = word[word.length - 1].token.toMs;\n const drawMs = Math.max(toMs - fromMs, MIN_DRAW_MS);\n const drawn = interpolate(state.timeMs - fromMs, [0, drawMs], [0, 1], {\n ...clamp,\n easing: drawEasing,\n });\n const hidden = `${(1 - drawn) * 100}%`;\n return (\n <Fragment key={key}>\n {w > 0 && \" \"}\n <span\n style={{\n position: \"relative\",\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n padding: `0 ${PAD_EM}em`,\n margin: `0 -${PAD_EM}em`,\n }}\n >\n <span\n aria-hidden\n style={{\n position: \"absolute\",\n left: 0,\n right: 0,\n top: BAND_TOP,\n bottom: BAND_BOTTOM,\n background: markerColor,\n borderRadius: `${RADIUS_EM}em`,\n transform: `rotate(${TILT_DEG}deg)`,\n clipPath: `inset(0 ${hidden} 0 0 round ${RADIUS_EM}em)`,\n }}\n />\n <span\n style={{\n position: \"relative\",\n textShadow: legibilityShadow(baseShadow * (1 - drawn)),\n }}\n >\n {text}\n </span>\n <span\n aria-hidden\n style={{\n position: \"absolute\",\n inset: 0,\n padding: `0 ${PAD_EM}em`,\n color: markerTextColor,\n clipPath: `inset(${BAND_TOP} ${hidden} ${BAND_BOTTOM} 0)`,\n }}\n >\n {text}\n </span>\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n markerColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Marker color\",\n },\n markerTextColor: {\n type: \"color\",\n default: \"#0a0a0a\",\n description: \"Marked text color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"markerColor\",\"markerTextColor\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n markerColor: \"#facc15\",\n markerTextColor: \"#0a0a0a\",\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionMarkerElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionMarkerBase>;\n\nconst CaptionMarkerInner = forwardRef<\n HTMLDivElement,\n CaptionMarkerElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionMarker>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionMarkerBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionMarkerBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionMarker = Interactive.withSchema({\n Component: CaptionMarkerInner,\n componentName: \"<CaptionMarker>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-outline.json b/registry-artifacts/elements/caption-outline.json
index 10435612..301472b1 100644
--- a/registry-artifacts/elements/caption-outline.json
+++ b/registry-artifacts/elements/caption-outline.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-outline",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, interpolateColors, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionOutlineProps extends CaptionBaseProps {\n activeColor?: string;\n strokeColor?: string;\n strokeWidth?: number;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst SWITCH_MS = 70;\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionOutlineBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n activeColor = \"#facc15\",\n strokeColor = \"#000000\",\n strokeWidth = 0.12,\n className,\n}: CaptionOutlineProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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\n const words = groupCaptionWords(state.tokens);\n const activeWord = words.findIndex((word) =>\n word.some(({ index }) => index === state.activeIndex),\n );\n const activeSince =\n activeWord >= 0 ? state.timeMs - words[activeWord][0].token.fromMs : 0;\n const highlight = (w: number): number => {\n if (w === activeWord) {\n return interpolate(activeSince, [0, SWITCH_MS], [0, 1], clamp);\n }\n if (w === activeWord - 1) {\n return 1 - interpolate(activeSince, [0, SWITCH_MS], [0, 1], clamp);\n }\n return 0;\n };\n\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.2,\n textAlign: \"center\",\n WebkitTextStroke: `${strokeWidth * 2}em ${strokeColor}`,\n paintOrder: \"stroke fill\",\n opacity: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {words.map((word, w) => (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n color: interpolateColors(\n highlight(w),\n [0, 1],\n [color, activeColor],\n ),\n }}\n >\n {captionWordText(word)}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n activeColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Active color\",\n },\n strokeColor: {\n type: \"color\",\n default: \"#000000\",\n description: \"Stroke color\",\n },\n strokeWidth: {\n type: \"number\",\n min: 0,\n max: 0.3,\n step: 0.01,\n default: 0.12,\n description: \"Stroke width (em)\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"activeColor\",\"strokeColor\",\"strokeWidth\",\"combineTokensWithinMilliseconds\",\"holdMs\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n activeColor: \"#facc15\",\n strokeColor: \"#000000\",\n strokeWidth: 0.12,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n};\n\ntype CaptionOutlineElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionOutlineBase>;\n\nconst CaptionOutlineInner = forwardRef<\n HTMLDivElement,\n CaptionOutlineElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionOutline>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionOutlineBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionOutlineBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionOutline = Interactive.withSchema({\n Component: CaptionOutlineInner,\n componentName: \"<CaptionOutline>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-prosody.json b/registry-artifacts/elements/caption-prosody.json
index 56dce9d6..eef1fe36 100644
--- a/registry-artifacts/elements/caption-prosody.json
+++ b/registry-artifacts/elements/caption-prosody.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-prosody",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionProsodyProps extends CaptionBaseProps {\n minScale?: number;\n maxScale?: number;\n activeColor?: string;\n shadow?: boolean;\n}\n\nconst EXIT_MS = 220;\nconst WORD_IN_MS = 180;\nconst RISE_EM = 0.2;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst appearEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction letterCount(text: string): number {\n return Math.max(1, text.match(/[\\p{L}\\p{N}]/gu)?.length ?? 0);\n}\n\nfunction median(values: number[]): number {\n const sorted = [...values].sort((a, b) => a - b);\n const mid = sorted.length >> 1;\n return sorted.length % 2 === 1\n ? sorted[mid]\n : (sorted[mid - 1] + sorted[mid]) / 2;\n}\n\nfunction getProsodyScales(\n words: { token: CaptionTokenState }[][],\n minScale: number,\n maxScale: number,\n): number[] {\n const paces = words.map((word) => {\n const fromMs = word[0].token.fromMs;\n const toMs = word[word.length - 1].token.toMs;\n return Math.max(0, toMs - fromMs) / letterCount(captionWordText(word));\n });\n const typical = median(paces);\n if (!(typical > 0)) return words.map(() => 1);\n return paces.map((pace) => {\n const t = Math.max(-1, Math.min(1, Math.log2(Math.max(pace, 1) / typical)));\n return t >= 0 ? 1 + t * (maxScale - 1) : 1 + t * (1 - minScale);\n });\n}\n\nfunction CaptionProsodyBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n minScale = 0.75,\n maxScale = 1.6,\n activeColor = \"#facc15\",\n shadow = true,\n className,\n}: CaptionProsodyProps) {\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 words = groupCaptionWords(state.tokens);\n const scales = getProsodyScales(words, minScale, maxScale);\n\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.1,\n textAlign: \"center\",\n opacity: exit,\n }}\n >\n {words.map((word, w) => {\n const appear = interpolate(\n state.timeMs - word[0].token.fromMs,\n [0, WORD_IN_MS],\n [0, 1],\n { ...clamp, easing: appearEasing },\n );\n const active = word.some(({ index }) => index === state.activeIndex);\n return (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n fontSize: `${scales[w]}em`,\n color: active ? activeColor : color,\n opacity: appear,\n transform: `translateY(${(1 - appear) * RISE_EM}em)`,\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {captionWordText(word)}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n activeColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Active word color\",\n },\n minScale: {\n type: \"number\",\n min: 0.4,\n max: 1,\n step: 0.05,\n default: 0.75,\n description: \"Rushed word scale\",\n hiddenFromList: false,\n },\n maxScale: {\n type: \"number\",\n min: 1,\n max: 2.5,\n step: 0.05,\n default: 1.6,\n description: \"Drawn-out word scale\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"activeColor\",\"minScale\",\"maxScale\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n activeColor: \"#facc15\",\n minScale: 0.75,\n maxScale: 1.6,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionProsodyElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionProsodyBase>;\n\nconst CaptionProsodyInner = forwardRef<\n HTMLDivElement,\n CaptionProsodyElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionProsody>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionProsodyBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionProsodyBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionProsody = Interactive.withSchema({\n Component: CaptionProsodyInner,\n componentName: \"<CaptionProsody>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-redact.json b/registry-artifacts/elements/caption-redact.json
index 5d4eba7a..3699f60c 100644
--- a/registry-artifacts/elements/caption-redact.json
+++ b/registry-artifacts/elements/caption-redact.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-redact",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionRedactProps extends CaptionBaseProps {\n barColor?: string;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst MIN_REVEAL_MS = 180;\nconst OVERHANG_EM = 0.06;\nconst RADIUS_EM = 0.06;\nconst BAR_TOP = \"14%\";\nconst BAR_BOTTOM = \"6%\";\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst revealEasing = Easing.inOut(Easing.cubic);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionRedactBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n barColor = \"#0a0a0a\",\n shadow = true,\n className,\n}: CaptionRedactProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n { ...clamp, easing: enterEasing },\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: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {groupCaptionWords(state.tokens).map((word, w) => {\n const fromMs = word[0].token.fromMs;\n const toMs = word[word.length - 1].token.toMs;\n const revealMs = Math.max(toMs - fromMs, MIN_REVEAL_MS);\n const revealed = interpolate(\n state.timeMs - fromMs,\n [0, revealMs],\n [0, 1],\n { ...clamp, easing: revealEasing },\n );\n return (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n style={{\n position: \"relative\",\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n }}\n >\n <span\n style={{\n textShadow,\n visibility: revealed > 0 ? \"visible\" : \"hidden\",\n clipPath:\n revealed >= 1\n ? undefined\n : `inset(-50% ${(1 - revealed) * 100}% -50% -50%)`,\n }}\n >\n {captionWordText(word)}\n </span>\n {revealed < 1 && (\n <span\n aria-hidden\n style={{\n position: \"absolute\",\n left: `-${OVERHANG_EM}em`,\n right: `-${OVERHANG_EM}em`,\n top: BAR_TOP,\n bottom: BAR_BOTTOM,\n background: barColor,\n borderRadius: `${RADIUS_EM}em`,\n transformOrigin: \"right center\",\n transform: `scaleX(${1 - revealed})`,\n }}\n />\n )}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n barColor: {\n type: \"color\",\n default: \"#0a0a0a\",\n description: \"Bar color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"barColor\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n barColor: \"#0a0a0a\",\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionRedactElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionRedactBase>;\n\nconst CaptionRedactInner = forwardRef<\n HTMLDivElement,\n CaptionRedactElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionRedact>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionRedactBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionRedactBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionRedact = Interactive.withSchema({\n Component: CaptionRedactInner,\n componentName: \"<CaptionRedact>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-rise.json b/registry-artifacts/elements/caption-rise.json
index fe365ddd..8b28849b 100644
--- a/registry-artifacts/elements/caption-rise.json
+++ b/registry-artifacts/elements/caption-rise.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-rise",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionRiseProps extends CaptionBaseProps {\n shadow?: boolean;\n}\n\nconst EXIT_MS = 220;\nconst RISE_MS = 260;\nconst START_EM = 1.6;\nconst CLIP = \"inset(-0.2em -0.6em -0.35em -0.6em)\";\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst riseEasing = Easing.bezier(0.16, 1, 0.3, 1);\n\nfunction CaptionRiseBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n shadow = true,\n className,\n}: CaptionRiseProps) {\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 {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n },\n )\n : 1;\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 const p =\n sinceMs < 0\n ? 0\n : interpolate(sinceMs, [0, RISE_MS], [0, 1], {\n easing: riseEasing,\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n return (\n <span\n key={index}\n style={{\n display: \"inline-block\",\n clipPath: CLIP,\n }}\n >\n <span\n style={{\n display: \"inline-block\",\n opacity: sinceMs < 0 ? 0 : 1,\n transform: `translateY(${(1 - p) * START_EM}em)`,\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {token.text}\n </span>\n </span>\n );\n })}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionRiseElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionRiseBase>;\n\nconst CaptionRiseInner = forwardRef<\n HTMLDivElement,\n CaptionRiseElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionRise>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionRiseBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionRiseBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionRise = Interactive.withSchema({\n Component: CaptionRiseInner,\n componentName: \"<CaptionRise>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-scramble.json b/registry-artifacts/elements/caption-scramble.json
index 0b9c7d16..a7fcd0e3 100644
--- a/registry-artifacts/elements/caption-scramble.json
+++ b/registry-artifacts/elements/caption-scramble.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-scramble",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, random, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionScrambleProps extends CaptionBaseProps {\n glyphColor?: string;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst MAX_RESOLVE_MS = 300;\nconst FRAMES_PER_ROLL = 2;\nconst GLYPHS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#%&*/+=\";\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction resolveProgress(sinceMs: number, fromMs: number, toMs: number) {\n const duration = Math.min(toMs - fromMs, MAX_RESOLVE_MS);\n if (duration <= 0) return 1;\n return Math.min(1, sinceMs / duration);\n}\n\nfunction CaptionScrambleBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n glyphColor = \"#a3a3a3\",\n shadow = true,\n className,\n}: CaptionScrambleProps) {\n const { fps } = useVideoConfig();\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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 step = Math.floor(((state.timeMs / 1000) * fps) / FRAMES_PER_ROLL);\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: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\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 key={index} style={{ opacity: 0 }}>\n {token.text}\n </span>\n );\n }\n const progress = resolveProgress(\n sinceMs,\n token.fromMs,\n token.toMs,\n );\n if (progress >= 1) {\n return (\n <span key={index} style={{ textShadow }}>\n {token.text}\n </span>\n );\n }\n const chars = Array.from(token.text);\n const resolved = Math.floor(progress * chars.length);\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 left: 0,\n right: 0,\n top: 0,\n whiteSpace: \"nowrap\",\n clipPath: \"inset(-50% 0 -50% 0)\",\n textShadow,\n }}\n >\n <span>{chars.slice(0, resolved).join(\"\")}</span>\n <span style={{ color: glyphColor }}>\n {chars\n .slice(resolved)\n .map((char, c) =>\n /\\s/.test(char)\n ? char\n : GLYPHS[\n Math.floor(\n random(\n `${state.pageIndex}-${index}-${resolved + c}-${step}`,\n ) * GLYPHS.length,\n )\n ],\n )\n .join(\"\")}\n </span>\n </span>\n </span>\n );\n })}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n glyphColor: {\n type: \"color\",\n default: \"#a3a3a3\",\n description: \"Glyph color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"glyphColor\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n glyphColor: \"#a3a3a3\",\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionScrambleElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionScrambleBase>;\n\nconst CaptionScrambleInner = forwardRef<\n HTMLDivElement,\n CaptionScrambleElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionScramble>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionScrambleBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionScrambleBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionScramble = Interactive.withSchema({\n Component: CaptionScrambleInner,\n componentName: \"<CaptionScramble>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-slice.json b/registry-artifacts/elements/caption-slice.json
index f2c4e060..da205e43 100644
--- a/registry-artifacts/elements/caption-slice.json
+++ b/registry-artifacts/elements/caption-slice.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-slice",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface 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\nfunction CaptionSliceBase({\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\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n distance: {\n type: \"number\",\n min: 0.1,\n max: 2,\n step: 0.05,\n default: 0.6,\n description: \"Slide distance (em)\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"distance\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n distance: 0.6,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionSliceElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionSliceBase>;\n\nconst CaptionSliceInner = forwardRef<\n HTMLDivElement,\n CaptionSliceElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionSlice>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionSliceBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionSliceBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionSlice = Interactive.withSchema({\n Component: CaptionSliceInner,\n componentName: \"<CaptionSlice>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-slot.json b/registry-artifacts/elements/caption-slot.json
index 94795b61..367b07a0 100644
--- a/registry-artifacts/elements/caption-slot.json
+++ b/registry-artifacts/elements/caption-slot.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-slot",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionSlotProps extends CaptionBaseProps {\n activeColor?: string;\n shadow?: boolean;\n}\n\nconst LINE_HEIGHT = 1.3;\nconst CLIP_MARGIN_EM = 0.2;\nconst TRAVEL_EM = LINE_HEIGHT + CLIP_MARGIN_EM * 2;\nconst ROLL_MS = 260;\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)\";\n\nconst rollIn = Easing.bezier(0.16, 1, 0.3, 1);\nconst rollOut = Easing.bezier(0.7, 0, 0.84, 0);\n\nfunction SlotLine({\n tokens,\n activeIndex,\n activeColor,\n style,\n}: {\n tokens: CaptionTokenState[];\n activeIndex: number;\n activeColor?: string;\n style: CSSProperties;\n}) {\n return (\n <div style={{ whiteSpace: \"nowrap\", ...style }}>\n {groupCaptionWords(tokens).map((word, w) => (\n <Fragment key={word[0].index}>\n {w > 0 && \" \"}\n {word.map(({ index, token }) => (\n <span\n key={index}\n style={{\n color:\n activeColor !== undefined && index === activeIndex\n ? activeColor\n : undefined,\n }}\n >\n {token.text}\n </span>\n ))}\n </Fragment>\n ))}\n </div>\n );\n}\n\nfunction CaptionSlotBase({\n captions,\n combineTokensWithinMilliseconds = 800,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n activeColor,\n shadow = true,\n className,\n}: CaptionSlotProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const roll = interpolate(state.sinceStartMs, [0, ROLL_MS], [0, 1], {\n easing: rollIn,\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n const exitProgress = Math.min(\n 1,\n Math.max(0, 1 - state.untilEndMs / getExitWindowMs(state, EXIT_MS)),\n );\n const exit = state.endsInSilence ? rollOut(exitProgress) : 0;\n\n return (\n <div\n className={className}\n style={{\n position: \"relative\",\n fontSize,\n fontWeight,\n color,\n lineHeight: LINE_HEIGHT,\n height: `${LINE_HEIGHT}em`,\n textAlign: \"center\",\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n clipPath: `inset(-${CLIP_MARGIN_EM}em -100000px)`,\n }}\n >\n {state.previous && roll < 1 ? (\n <SlotLine\n key={`page-${state.previous.pageIndex}`}\n tokens={state.previous.tokens}\n activeIndex={-1}\n style={{\n position: \"absolute\",\n top: 0,\n left: \"50%\",\n transform: `translate(-50%, ${-roll * TRAVEL_EM}em)`,\n }}\n />\n ) : null}\n <SlotLine\n key={`page-${state.pageIndex}`}\n tokens={state.tokens}\n activeIndex={state.activeIndex}\n activeColor={activeColor}\n style={{\n transform: `translateY(${(1 - roll - exit) * TRAVEL_EM}em)`,\n }}\n />\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 100,\n default: 800,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n combineTokensWithinMilliseconds: 800,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionSlotElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionSlotBase>;\n\nconst CaptionSlotInner = forwardRef<\n HTMLDivElement,\n CaptionSlotElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionSlot>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionSlotBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionSlotBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionSlot = Interactive.withSchema({\n Component: CaptionSlotInner,\n componentName: \"<CaptionSlot>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-speaker.json b/registry-artifacts/elements/caption-speaker.json
index 794f2b1d..19e10702 100644
--- a/registry-artifacts/elements/caption-speaker.json
+++ b/registry-artifacts/elements/caption-speaker.json
@@ -14,6 +14,7 @@
"durationInFrames": 282,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-speaker",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionSpeakerProps extends CaptionBaseProps {\n captions: SpeakerCaption[];\n speakerColors?: Record<string, string>;\n upcomingOpacity?: number;\n shadow?: boolean;\n}\n\nconst SPEAKER_PALETTE = [\"#facc15\", \"#38bdf8\", \"#f472b6\", \"#4ade80\"];\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst REVEAL_MS = 100;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionSpeakerBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n speakerColors,\n upcomingOpacity = 0.4,\n shadow = true,\n className,\n}: CaptionSpeakerProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n const autoColors = useMemo(() => {\n const pinned = new Set(Object.values(speakerColors ?? {}));\n const free = SPEAKER_PALETTE.filter((c) => !pinned.has(c));\n const palette = free.length > 0 ? free : SPEAKER_PALETTE;\n const assigned = new Map<string, string>();\n for (const caption of captions) {\n const { speaker } = caption;\n if (\n speaker === undefined ||\n speakerColors?.[speaker] !== undefined ||\n assigned.has(speaker)\n ) {\n continue;\n }\n assigned.set(speaker, palette[assigned.size % palette.length]);\n }\n return assigned;\n }, [captions, speakerColors]);\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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\n const { speaker } = state;\n const speakerColor =\n speaker === undefined\n ? color\n : (speakerColors?.[speaker] ?? autoColors.get(speaker) ?? color);\n\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color: speakerColor,\n lineHeight: 1.2,\n textAlign: \"center\",\n opacity: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {groupCaptionWords(state.tokens).map((word, w) => (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {word.map(({ index, token }) => (\n <span\n key={index}\n style={{\n opacity: interpolate(\n state.timeMs - token.fromMs,\n [0, REVEAL_MS],\n [upcomingOpacity, 1],\n clamp,\n ),\n }}\n >\n {token.text}\n </span>\n ))}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" what\",\n startMs: 460,\n endMs: 640,\n timestampMs: 550,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" made\",\n startMs: 640,\n endMs: 860,\n timestampMs: 750,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" you\",\n startMs: 860,\n endMs: 980,\n timestampMs: 920,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" add\",\n startMs: 980,\n endMs: 1180,\n timestampMs: 1080,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" captions?\",\n startMs: 1180,\n endMs: 1800,\n timestampMs: 1490,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" Most\",\n startMs: 2300,\n endMs: 2560,\n timestampMs: 2430,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" people\",\n startMs: 2560,\n endMs: 2900,\n timestampMs: 2730,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" watch\",\n startMs: 2900,\n endMs: 3160,\n timestampMs: 3030,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" with\",\n startMs: 3160,\n endMs: 3280,\n timestampMs: 3220,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" the\",\n startMs: 3280,\n endMs: 3380,\n timestampMs: 3330,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" sound\",\n startMs: 3380,\n endMs: 3720,\n timestampMs: 3550,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" off.\",\n startMs: 3720,\n endMs: 4240,\n timestampMs: 3980,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" Really?\",\n startMs: 4800,\n endMs: 5400,\n timestampMs: 5100,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" Almost\",\n startMs: 5800,\n endMs: 6140,\n timestampMs: 5970,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" everyone.\",\n startMs: 6140,\n endMs: 6760,\n timestampMs: 6450,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" Captions\",\n startMs: 7000,\n endMs: 7480,\n timestampMs: 7240,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" keep\",\n startMs: 7480,\n endMs: 7700,\n timestampMs: 7590,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" them\",\n startMs: 7700,\n endMs: 7860,\n timestampMs: 7780,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" watching.\",\n startMs: 7860,\n endMs: 8400,\n timestampMs: 8130,\n confidence: 0.96,\n speaker: \"guest\",\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n upcomingOpacity: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.05,\n default: 0.4,\n description: \"Upcoming opacity\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"upcomingOpacity\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" what\",\n startMs: 460,\n endMs: 640,\n timestampMs: 550,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" made\",\n startMs: 640,\n endMs: 860,\n timestampMs: 750,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" you\",\n startMs: 860,\n endMs: 980,\n timestampMs: 920,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" add\",\n startMs: 980,\n endMs: 1180,\n timestampMs: 1080,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" captions?\",\n startMs: 1180,\n endMs: 1800,\n timestampMs: 1490,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" Most\",\n startMs: 2300,\n endMs: 2560,\n timestampMs: 2430,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" people\",\n startMs: 2560,\n endMs: 2900,\n timestampMs: 2730,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" watch\",\n startMs: 2900,\n endMs: 3160,\n timestampMs: 3030,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" with\",\n startMs: 3160,\n endMs: 3280,\n timestampMs: 3220,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" the\",\n startMs: 3280,\n endMs: 3380,\n timestampMs: 3330,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" sound\",\n startMs: 3380,\n endMs: 3720,\n timestampMs: 3550,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" off.\",\n startMs: 3720,\n endMs: 4240,\n timestampMs: 3980,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" Really?\",\n startMs: 4800,\n endMs: 5400,\n timestampMs: 5100,\n confidence: 0.96,\n speaker: \"host\",\n }, {\n text: \" Almost\",\n startMs: 5800,\n endMs: 6140,\n timestampMs: 5970,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" everyone.\",\n startMs: 6140,\n endMs: 6760,\n timestampMs: 6450,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" Captions\",\n startMs: 7000,\n endMs: 7480,\n timestampMs: 7240,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" keep\",\n startMs: 7480,\n endMs: 7700,\n timestampMs: 7590,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" them\",\n startMs: 7700,\n endMs: 7860,\n timestampMs: 7780,\n confidence: 0.96,\n speaker: \"guest\",\n }, {\n text: \" watching.\",\n startMs: 7860,\n endMs: 8400,\n timestampMs: 8130,\n confidence: 0.96,\n speaker: \"guest\",\n }],\n fontSize: 64,\n fontWeight: 800,\n upcomingOpacity: 0.4,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionSpeakerElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionSpeakerBase>;\n\nconst CaptionSpeakerInner = forwardRef<\n HTMLDivElement,\n CaptionSpeakerElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionSpeaker>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionSpeakerBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionSpeakerBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionSpeaker = Interactive.withSchema({\n Component: CaptionSpeakerInner,\n componentName: \"<CaptionSpeaker>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-split-flap.json b/registry-artifacts/elements/caption-split-flap.json
index 65e291d5..005338e7 100644
--- a/registry-artifacts/elements/caption-split-flap.json
+++ b/registry-artifacts/elements/caption-split-flap.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-split-flap",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, random, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionSplitFlapProps extends CaptionBaseProps {\n tileColor?: string;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst FLIP_MS = 60;\nconst MIN_SETTLE_MS = 350;\nconst TILE_W = 0.78;\nconst TILE_H = 1.2;\nconst TILE_GAP = 0.06;\nconst GLYPH_SCALE = 0.8;\nconst RADIUS = 0.08;\nconst GLYPHS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface FlapFrame {\n current: string;\n next: string;\n progress: number | null;\n}\n\nfunction flapFrame(\n target: string,\n seed: string,\n index: number,\n count: number,\n fromMs: number,\n windowMs: number,\n timeMs: number,\n): FlapFrame {\n const flips = 3 + Math.floor(random(`${seed}-flips`) * 4);\n const share = count > 1 ? index / (count - 1) : 1;\n const endMs = fromMs + windowMs * (0.55 + 0.45 * share);\n const flipMs = Math.min(FLIP_MS, (endMs - fromMs) / flips);\n const startMs = endMs - flips * flipMs;\n if (timeMs < startMs) return { current: \"\", next: \"\", progress: null };\n if (timeMs >= endMs) return { current: target, next: target, progress: null };\n const glyphAt = (k: number): string => {\n if (k <= 0) return \"\";\n if (k >= flips) return target;\n return GLYPHS[Math.floor(random(`${seed}-${k}`) * GLYPHS.length)];\n };\n const elapsed = (timeMs - startMs) / flipMs;\n const k = Math.floor(elapsed);\n return { current: glyphAt(k), next: glyphAt(k + 1), progress: elapsed - k };\n}\n\nconst TOP_HALF = \"inset(0 0 50% 0)\";\nconst BOTTOM_HALF = \"inset(50% 0 0 0)\";\n\nfunction Leaf({\n char,\n tileColor,\n clipPath,\n transform,\n brightness = 1,\n}: {\n char: string;\n tileColor: string;\n clipPath?: string;\n transform?: string;\n brightness?: number;\n}) {\n const style: CSSProperties = {\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: tileColor,\n borderRadius: `${RADIUS}em`,\n clipPath,\n transform,\n transformOrigin: \"50% 50%\",\n filter: brightness < 1 ? `brightness(${brightness})` : undefined,\n };\n return (\n <span style={style}>\n <span style={{ fontSize: `${GLYPH_SCALE}em`, lineHeight: 1 }}>\n {char}\n </span>\n </span>\n );\n}\n\nfunction Tile({ frame, tileColor }: { frame: FlapFrame; tileColor: string }) {\n const perspective = `perspective(${TILE_H * 4}em)`;\n const { current, next, progress } = frame;\n return (\n <span\n style={{\n position: \"relative\",\n display: \"inline-block\",\n width: `${TILE_W}em`,\n height: `${TILE_H}em`,\n flexShrink: 0,\n }}\n >\n {progress === null ? (\n <Leaf char={current} tileColor={tileColor} />\n ) : (\n <>\n <Leaf char={next} tileColor={tileColor} clipPath={TOP_HALF} />\n <Leaf char={current} tileColor={tileColor} clipPath={BOTTOM_HALF} />\n {progress < 0.5 ? (\n <Leaf\n char={current}\n tileColor={tileColor}\n clipPath={TOP_HALF}\n transform={`${perspective} rotateX(${-180 * progress}deg)`}\n brightness={1 - 0.7 * progress}\n />\n ) : (\n <Leaf\n char={next}\n tileColor={tileColor}\n clipPath={BOTTOM_HALF}\n transform={`${perspective} rotateX(${180 * (1 - progress)}deg)`}\n brightness={0.65 + 0.7 * (progress - 0.5)}\n />\n )}\n </>\n )}\n <span\n aria-hidden\n style={{\n position: \"absolute\",\n left: 0,\n right: 0,\n top: \"50%\",\n height: \"max(1px, 0.025em)\",\n transform: \"translateY(-50%)\",\n background: \"rgba(0, 0, 0, 0.6)\",\n }}\n />\n </span>\n );\n}\n\nfunction CaptionSplitFlapBase({\n captions,\n combineTokensWithinMilliseconds = 1000,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 56,\n fontWeight = 800,\n color = \"#ffffff\",\n tileColor = \"#111111\",\n className,\n}: CaptionSplitFlapProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n { ...clamp, easing: enterEasing },\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\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n lineHeight: TILE_H + 0.24,\n textAlign: \"center\",\n opacity: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {groupCaptionWords(state.tokens).map((word, w) => {\n const first = word[0];\n const fromMs = first.token.fromMs;\n const toMs = word[word.length - 1].token.toMs;\n const windowMs = Math.max(toMs - fromMs, MIN_SETTLE_MS);\n const chars = Array.from(captionWordText(word));\n return (\n <Fragment key={`${state.pageIndex}-${first.index}`}>\n {w > 0 && \" \"}\n <span\n style={{\n display: \"inline-flex\",\n gap: `${TILE_GAP}em`,\n verticalAlign: \"top\",\n paddingInline: `${TILE_GAP}em`,\n }}\n >\n {chars.map((char, c) => (\n <Tile\n key={c}\n tileColor={tileColor}\n frame={flapFrame(\n char,\n `${state.pageIndex}-${first.index}-${c}`,\n c,\n chars.length,\n fromMs,\n windowMs,\n state.timeMs,\n )}\n />\n ))}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 120,\n step: 1,\n default: 56,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Glyph color\",\n },\n tileColor: {\n type: \"color\",\n default: \"#111111\",\n description: \"Tile color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1000,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"tileColor\",\"combineTokensWithinMilliseconds\",\"holdMs\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 56,\n fontWeight: 800,\n color: \"#ffffff\",\n tileColor: \"#111111\",\n combineTokensWithinMilliseconds: 1000,\n holdMs: 600,\n};\n\ntype CaptionSplitFlapElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionSplitFlapBase>;\n\nconst CaptionSplitFlapInner = forwardRef<\n HTMLDivElement,\n CaptionSplitFlapElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionSplitFlap>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionSplitFlapBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionSplitFlapBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionSplitFlap = Interactive.withSchema({\n Component: CaptionSplitFlapInner,\n componentName: \"<CaptionSplitFlap>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-stack.json b/registry-artifacts/elements/caption-stack.json
index b338d802..3632b90c 100644
--- a/registry-artifacts/elements/caption-stack.json
+++ b/registry-artifacts/elements/caption-stack.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-stack",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionStackProps extends CaptionBaseProps {\n keywords?: string[];\n emphasisScale?: number;\n emphasisColor?: string;\n shadow?: boolean;\n}\n\ntype CaptionWord = ReturnType<typeof groupCaptionWords>[number];\n\ninterface StackLine {\n words: CaptionWord[];\n emphasis: boolean;\n}\n\nconst WORDS_PER_LINE = 2;\nconst EXIT_MS = 220;\nconst FADE_IN_MS = 120;\nconst RISE_MS = 220;\nconst RISE_EM = 0.3;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst riseEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction buildLines(\n words: CaptionWord[],\n isEmphasis: (word: CaptionWord, index: number) => boolean,\n): StackLine[] {\n const lines: StackLine[] = [];\n let current: CaptionWord[] = [];\n const flush = () => {\n if (current.length > 0) {\n lines.push({ words: current, emphasis: false });\n current = [];\n }\n };\n words.forEach((word, i) => {\n if (isEmphasis(word, i)) {\n flush();\n lines.push({ words: [word], emphasis: true });\n return;\n }\n current.push(word);\n if (current.length >= WORDS_PER_LINE) flush();\n });\n flush();\n return lines;\n}\n\nfunction longestWordIndex(words: CaptionWord[]): number {\n let longest = -1;\n let longestLength = 0;\n words.forEach((word, i) => {\n const length = normalizeCaptionWord(captionWordText(word)).length;\n if (length > longestLength) {\n longest = i;\n longestLength = length;\n }\n });\n return longest;\n}\n\nfunction CaptionStackBase({\n captions,\n combineTokensWithinMilliseconds = 1600,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n keywords,\n emphasisScale = 1.7,\n emphasisColor = \"#facc15\",\n shadow = true,\n className,\n}: CaptionStackProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const words = groupCaptionWords(state.tokens);\n const hasKeywords = keywords !== undefined && keywords.length > 0;\n const isKeyword = createKeywordMatcher(keywords);\n const longest = hasKeywords ? -1 : longestWordIndex(words);\n const lines = buildLines(words, (word, i) =>\n hasKeywords ? isKeyword(captionWordText(word)) : i === longest,\n );\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\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n lineHeight: 1,\n textAlign: \"center\",\n opacity: exit,\n }}\n >\n {lines.map((line) => (\n <div\n key={`${state.pageIndex}-${line.words[0][0].index}`}\n style={{\n fontSize: line.emphasis ? `${emphasisScale}em` : undefined,\n color: line.emphasis ? emphasisColor : undefined,\n }}\n >\n {line.words.map((word, w) => {\n const sinceMs = state.timeMs - word[0].token.fromMs;\n const arrived = sinceMs >= 0;\n const rise = arrived\n ? interpolate(sinceMs, [0, RISE_MS], [0, 1], {\n ...clamp,\n easing: riseEasing,\n })\n : 0;\n const opacity = arrived\n ? interpolate(sinceMs, [0, FADE_IN_MS], [0, 1], clamp)\n : 0;\n return (\n <Fragment key={word[0].index}>\n {w > 0 && \" \"}\n <span\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n opacity,\n transform: `translateY(${(1 - rise) * RISE_EM}em)`,\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {word.map(({ index, token }) => (\n <span key={index}>{token.text}</span>\n ))}\n </span>\n </Fragment>\n );\n })}\n </div>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n emphasisColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Emphasis color\",\n },\n emphasisScale: {\n type: \"number\",\n min: 1,\n max: 2.5,\n step: 0.05,\n default: 1.7,\n description: \"Emphasis scale\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1600,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"emphasisColor\",\"emphasisScale\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n emphasisColor: \"#facc15\",\n emphasisScale: 1.7,\n combineTokensWithinMilliseconds: 1600,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionStackElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionStackBase>;\n\nconst CaptionStackInner = forwardRef<\n HTMLDivElement,\n CaptionStackElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionStack>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionStackBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionStackBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionStack = Interactive.withSchema({\n Component: CaptionStackInner,\n componentName: \"<CaptionStack>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-stamp.json b/registry-artifacts/elements/caption-stamp.json
index 09973f28..d3afc236 100644
--- a/registry-artifacts/elements/caption-stamp.json
+++ b/registry-artifacts/elements/caption-stamp.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-stamp",
"sourceCode": "import { Fragment, forwardRef, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, random, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionStampProps extends CaptionBaseProps {\n keywords?: string[];\n stampColor?: string;\n texture?: boolean;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst SLAM_MS = 90;\nconst SETTLE_MS = 170;\nconst INK_MS = 50;\nconst PAD_EM = 0.16;\nconst BORDER_EM = 0.06;\nconst RADIUS_EM = 0.08;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst slamEasing = Easing.in(Easing.quad);\nconst settleEasing = Easing.out(Easing.quad);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction stampScale(sinceMs: number): number {\n if (sinceMs <= SLAM_MS) {\n return interpolate(sinceMs, [0, SLAM_MS], [1.8, 0.96], {\n ...clamp,\n easing: slamEasing,\n });\n }\n return interpolate(sinceMs, [SLAM_MS, SETTLE_MS], [0.96, 1], {\n ...clamp,\n easing: settleEasing,\n });\n}\n\nfunction CaptionStampBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n keywords,\n stampColor = \"#ef4444\",\n texture = true,\n shadow = true,\n className,\n}: CaptionStampProps) {\n const filterId = `caption-stamp-${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n { ...clamp, easing: enterEasing },\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\n const words = groupCaptionWords(state.tokens);\n const isKeyword = createKeywordMatcher(keywords);\n const byKeyword = keywords !== undefined && keywords.length > 0;\n let longest = -1;\n let longestLength = 0;\n if (!byKeyword) {\n words.forEach((word, w) => {\n const length = normalizeCaptionWord(captionWordText(word)).length;\n if (length > longestLength) {\n longest = w;\n longestLength = length;\n }\n });\n }\n const textShadow = shadow ? LEGIBILITY_SHADOW : undefined;\n\n return (\n <div\n className={className}\n style={{\n position: \"relative\",\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.2,\n textAlign: \"center\",\n opacity: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {texture && (\n <svg\n aria-hidden\n width={0}\n height={0}\n style={{ position: \"absolute\", overflow: \"hidden\" }}\n >\n <filter id={filterId} x=\"-10%\" y=\"-20%\" width=\"120%\" height=\"140%\">\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.45\"\n numOctaves={2}\n seed={4}\n result=\"warp\"\n />\n <feDisplacementMap\n in=\"SourceGraphic\"\n in2=\"warp\"\n scale={fontSize * 0.035}\n xChannelSelector=\"R\"\n yChannelSelector=\"G\"\n result=\"rough\"\n />\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.8\"\n numOctaves={1}\n seed={9}\n result=\"grain\"\n />\n <feColorMatrix\n in=\"grain\"\n type=\"matrix\"\n values=\"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -10 6.8\"\n result=\"holes\"\n />\n <feComposite in=\"rough\" in2=\"holes\" operator=\"in\" />\n </filter>\n </svg>\n )}\n {words.map((word, w) => {\n const key = `${state.pageIndex}-${word[0].index}`;\n const text = captionWordText(word);\n const stamped = byKeyword ? isKeyword(text) : w === longest;\n if (!stamped) {\n return (\n <Fragment key={key}>\n {w > 0 && \" \"}\n <span\n style={{\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n textShadow,\n }}\n >\n {text}\n </span>\n </Fragment>\n );\n }\n const sinceMs = state.timeMs - word[0].token.fromMs;\n const rotation =\n -8 + random(`caption-stamp-${state.pageIndex}-${word[0].index}`) * 5;\n return (\n <Fragment key={key}>\n {w > 0 && \" \"}\n <span\n style={{\n position: \"relative\",\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n }}\n >\n <span\n style={{\n opacity: interpolate(\n sinceMs,\n [SLAM_MS * 0.6, SLAM_MS],\n [1, 0],\n clamp,\n ),\n textShadow,\n }}\n >\n {text}\n </span>\n {sinceMs >= 0 && (\n <span\n aria-hidden\n style={{\n position: \"absolute\",\n left: `-${PAD_EM}em`,\n right: `-${PAD_EM}em`,\n top: \"8%\",\n bottom: \"4%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n lineHeight: 1,\n color: stampColor,\n border: `${BORDER_EM}em solid ${stampColor}`,\n borderRadius: `${RADIUS_EM}em`,\n opacity: interpolate(sinceMs, [0, INK_MS], [0, 1], clamp),\n transform: `rotate(${rotation}deg) scale(${stampScale(sinceMs)})`,\n filter: texture ? `url(#${filterId})` : undefined,\n }}\n >\n {text}\n </span>\n )}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n stampColor: {\n type: \"color\",\n default: \"#ef4444\",\n description: \"Stamp color\",\n },\n texture: {\n type: \"boolean\",\n default: true,\n description: \"Ink texture\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"stampColor\",\"texture\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n stampColor: \"#ef4444\",\n texture: true,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionStampElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionStampBase>;\n\nconst CaptionStampInner = forwardRef<\n HTMLDivElement,\n CaptionStampElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionStamp>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionStampBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionStampBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionStamp = Interactive.withSchema({\n Component: CaptionStampInner,\n componentName: \"<CaptionStamp>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-subtitle.json b/registry-artifacts/elements/caption-subtitle.json
index 3b4a92a2..fbf28ba8 100644
--- a/registry-artifacts/elements/caption-subtitle.json
+++ b/registry-artifacts/elements/caption-subtitle.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-subtitle",
"sourceCode": "import { Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\nimport { forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionSubtitleProps extends CaptionBaseProps {\n box?: boolean;\n boxColor?: string;\n boxOpacity?: number;\n}\n\nconst ENTER_MS = 120;\nconst EXIT_MS = 160;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nfunction CaptionSubtitleBase({\n captions,\n combineTokensWithinMilliseconds = 2500,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 44,\n fontWeight = 600,\n color = \"#ffffff\",\n box = true,\n boxColor = \"#000000\",\n boxOpacity = 0.72,\n className,\n}: CaptionSubtitleProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = state.previous\n ? 1\n : interpolate(state.sinceStartMs, [0, ENTER_MS], [0, 1], {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n });\n const exit = state.endsInSilence\n ? interpolate(\n state.untilEndMs,\n [0, getExitWindowMs(state, EXIT_MS)],\n [0, 1],\n {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n },\n )\n : 1;\n const opacityPercent = Math.round(Math.min(1, Math.max(0, boxOpacity)) * 100);\n\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.4,\n textAlign: \"center\",\n textWrap: \"balance\",\n opacity: Math.min(enter, exit),\n }}\n >\n <span\n style={\n box\n ? {\n backgroundColor: `color-mix(in srgb, ${boxColor} ${opacityPercent}%, transparent)`,\n padding: \"0.06em 0.36em\",\n borderRadius: \"0.16em\",\n boxDecorationBreak: \"clone\",\n WebkitBoxDecorationBreak: \"clone\",\n }\n : { textShadow: LEGIBILITY_SHADOW }\n }\n >\n {state.page.text}\n </span>\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 16,\n max: 100,\n step: 1,\n default: 44,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 600,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 6000,\n step: 100,\n default: 2500,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n box: {\n type: \"boolean\",\n default: true,\n description: \"Box\",\n },\n boxColor: {\n type: \"color\",\n default: \"#000000\",\n description: \"Box color\",\n },\n boxOpacity: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.02,\n default: 0.72,\n description: \"Box opacity\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"box\",\"boxColor\",\"boxOpacity\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 44,\n fontWeight: 600,\n color: \"#ffffff\",\n combineTokensWithinMilliseconds: 2500,\n holdMs: 600,\n box: true,\n boxColor: \"#000000\",\n boxOpacity: 0.72,\n};\n\ntype CaptionSubtitleElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionSubtitleBase>;\n\nconst CaptionSubtitleInner = forwardRef<\n HTMLDivElement,\n CaptionSubtitleElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionSubtitle>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionSubtitleBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionSubtitleBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionSubtitle = Interactive.withSchema({\n Component: CaptionSubtitleInner,\n componentName: \"<CaptionSubtitle>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-teleprompter.json b/registry-artifacts/elements/caption-teleprompter.json
index 306539f7..2b5a302c 100644
--- a/registry-artifacts/elements/caption-teleprompter.json
+++ b/registry-artifacts/elements/caption-teleprompter.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-teleprompter",
"sourceCode": "import { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\nimport { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionTeleprompterProps extends CaptionBaseProps {\n visibleLines?: number;\n pastOpacity?: number;\n futureOpacity?: number;\n upcomingOpacity?: number;\n shadow?: boolean;\n}\n\ninterface PrompterWord {\n key: number;\n text: string;\n fromMs: number;\n}\n\nconst LINE_HEIGHT = 1.3;\nconst LINE_GAP_EM = 0.2;\nconst SCROLL_MS = 320;\nconst LIGHT_MS = 80;\nconst EDGE_FADE_LINES = 0.66;\n\nfunction edgeFade(visibleLines: number): string | undefined {\n const fadeLines = Math.min(\n EDGE_FADE_LINES,\n Math.max(0, visibleLines - 1) / 3,\n );\n if (fadeLines <= 0) return undefined;\n const pct = (fadeLines / visibleLines) * 100;\n return `linear-gradient(to bottom, transparent, #000 ${pct}%, #000 ${100 - pct}%, transparent)`;\n}\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst scrollEasing = Easing.bezier(0.45, 0, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction lineWords(page: TikTokPage): PrompterWord[] {\n const words: PrompterWord[] = [];\n page.tokens.forEach((token, i) => {\n const last = words[words.length - 1];\n if (last && !/^\\s/.test(token.text)) {\n last.text += token.text;\n } else {\n words.push({ key: i, text: token.text.trim(), fromMs: token.fromMs });\n }\n });\n return words;\n}\n\nfunction CaptionTeleprompterBase({\n captions,\n combineTokensWithinMilliseconds = 1500,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n visibleLines = 3,\n pastOpacity = 0.35,\n futureOpacity = 0.35,\n upcomingOpacity = 0.55,\n shadow = true,\n className,\n}: CaptionTeleprompterProps) {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const timeMs = (frame / fps) * 1000;\n const lines = useMemo(\n () =>\n buildCaptionPages(captions, {\n combineTokensWithinMilliseconds,\n holdMs,\n }).map((line) => ({ ...line, words: lineWords(line.page) })),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n const { wordRef: lineRef, rects } = useCaptionWordRects(0, lines.length);\n\n const step = (LINE_HEIGHT + LINE_GAP_EM) * fontSize;\n const windowHeight = visibleLines * step;\n const center = (i: number): number => {\n const rect = rects?.[i];\n return rect\n ? rect.top + rect.height / 2\n : i * step + (LINE_HEIGHT * fontSize) / 2;\n };\n\n const scrollMsAt = (i: number): number => {\n const before =\n i > 0\n ? lines[i].startMs - lines[i - 1].startMs\n : Number.POSITIVE_INFINITY;\n const after =\n i < lines.length - 1\n ? lines[i + 1].startMs - lines[i].startMs\n : Number.POSITIVE_INFINITY;\n return Math.max(1, Math.min(SCROLL_MS, before, after));\n };\n let k = -1;\n lines.forEach((line, i) => {\n if (line.startMs - scrollMsAt(i) / 2 <= timeMs) k = i;\n });\n const scrollMs = k > 0 ? scrollMsAt(k) : SCROLL_MS;\n const progress =\n k <= 0\n ? 1\n : interpolate(\n timeMs - (lines[k].startMs - scrollMs / 2),\n [0, scrollMs],\n [0, 1],\n { ...clamp, easing: scrollEasing },\n );\n const focus = Math.max(k, 0);\n const centerY =\n lines.length === 0\n ? 0\n : k <= 0\n ? center(0)\n : center(k - 1) + (center(k) - center(k - 1)) * progress;\n\n return (\n <div\n className={className}\n style={{\n position: \"relative\",\n height: windowHeight,\n fontSize,\n fontWeight,\n color,\n textAlign: \"center\",\n overflow: \"hidden\",\n maskImage: edgeFade(visibleLines),\n WebkitMaskImage: edgeFade(visibleLines),\n }}\n >\n <div\n style={{\n position: \"absolute\",\n left: 0,\n right: 0,\n top: 0,\n transform: `translateY(${windowHeight / 2 - centerY}px)`,\n }}\n >\n {lines.map((line, i) => {\n const weight =\n i === focus ? progress : i === focus - 1 ? 1 - progress : 0;\n const rest = i < focus ? pastOpacity : futureOpacity;\n return (\n <div\n key={line.index}\n ref={lineRef(i)}\n style={{\n lineHeight: LINE_HEIGHT,\n marginBottom: `${LINE_GAP_EM}em`,\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {line.words.map((word, w) => {\n const lit = interpolate(\n timeMs - word.fromMs,\n [-LIGHT_MS, 0],\n [upcomingOpacity, 1],\n clamp,\n );\n return (\n <Fragment key={word.key}>\n {w > 0 && \" \"}\n <span style={{ opacity: rest + (lit - rest) * weight }}>\n {word.text}\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n visibleLines: {\n type: \"number\",\n min: 1,\n max: 6,\n step: 1,\n default: 3,\n description: \"Visible lines\",\n hiddenFromList: false,\n },\n pastOpacity: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.05,\n default: 0.35,\n description: \"Past line opacity\",\n hiddenFromList: false,\n },\n futureOpacity: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.05,\n default: 0.35,\n description: \"Next line opacity\",\n hiddenFromList: false,\n },\n upcomingOpacity: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.05,\n default: 0.55,\n description: \"Unspoken word opacity\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 4000,\n step: 100,\n default: 1500,\n description: \"Line window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Silence break (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"visibleLines\",\"pastOpacity\",\"futureOpacity\",\"upcomingOpacity\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n visibleLines: 3,\n pastOpacity: 0.35,\n futureOpacity: 0.35,\n upcomingOpacity: 0.55,\n combineTokensWithinMilliseconds: 1500,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionTeleprompterElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionTeleprompterBase>;\n\nconst CaptionTeleprompterInner = forwardRef<\n HTMLDivElement,\n CaptionTeleprompterElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionTeleprompter>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionTeleprompterBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionTeleprompterBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionTeleprompter = Interactive.withSchema({\n Component: CaptionTeleprompterInner,\n componentName: \"<CaptionTeleprompter>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-timeline.json b/registry-artifacts/elements/caption-timeline.json
index 982958b1..862ae7e9 100644
--- a/registry-artifacts/elements/caption-timeline.json
+++ b/registry-artifacts/elements/caption-timeline.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-timeline",
"sourceCode": "import { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\nimport { forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionTimelineProps extends CaptionBaseProps {\n width?: number;\n pxPerSecond?: number;\n playheadPosition?: number;\n playheadColor?: string;\n upcomingOpacity?: number;\n shadow?: boolean;\n}\n\ninterface TimelineWord {\n id: number;\n text: string;\n startMs: number;\n endMs: number;\n}\n\nconst LINE_HEIGHT = 1.3;\nconst GAP_EM = 0.32;\nconst LIGHT_MS = 80;\nconst EDGE_FADE =\n \"linear-gradient(to right, transparent, #000 12%, #000 88%, transparent)\";\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction getTimelineWords(captions: Caption[]): TimelineWord[] {\n const words: TimelineWord[] = [];\n for (const caption of captions) {\n if (caption.text.trim() === \"\") continue;\n const last = words[words.length - 1];\n if (last && !/^\\s/.test(caption.text)) {\n last.text += caption.text;\n last.endMs = caption.endMs;\n } else {\n words.push({\n id: words.length,\n text: caption.text.trim(),\n startMs: caption.startMs,\n endMs: caption.endMs,\n });\n }\n }\n return words;\n}\n\nfunction layoutTimeline(\n words: TimelineWord[],\n widths: number[],\n pxPerSecond: number,\n gap: number,\n): number[] {\n const xs: number[] = [];\n words.forEach((word, i) => {\n const ideal = (word.startMs / 1000) * pxPerSecond;\n xs.push(i === 0 ? ideal : Math.max(ideal, xs[i - 1] + widths[i - 1] + gap));\n });\n return xs;\n}\n\nfunction timelineOffset(\n words: TimelineWord[],\n xs: number[],\n timeMs: number,\n pxPerSecond: number,\n): number {\n if (words.length === 0) return (timeMs / 1000) * pxPerSecond;\n let i = -1;\n while (i + 1 < words.length && words[i + 1].startMs <= timeMs) i++;\n if (i === -1) {\n return xs[0] - ((words[0].startMs - timeMs) / 1000) * pxPerSecond;\n }\n const next = words[i + 1];\n if (!next) {\n return xs[i] + ((timeMs - words[i].startMs) / 1000) * pxPerSecond;\n }\n const span = next.startMs - words[i].startMs;\n const t = span > 0 ? (timeMs - words[i].startMs) / span : 1;\n return xs[i] + (xs[i + 1] - xs[i]) * t;\n}\n\nfunction sameWidths(a: number[], b: number[]): boolean {\n return a.length === b.length && a.every((w, i) => w === b[i]);\n}\n\nfunction CaptionTimelineBase({\n captions,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n width = 1100,\n pxPerSecond = 260,\n playheadPosition = 0.35,\n playheadColor = \"#facc15\",\n upcomingOpacity = 0.4,\n shadow = true,\n className,\n}: CaptionTimelineProps) {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const timeMs = (frame / fps) * 1000;\n const words = useMemo(() => getTimelineWords(captions), [captions]);\n const elements = useRef<(HTMLSpanElement | null)[]>([]);\n const [widths, setWidths] = useState<number[]>([]);\n\n useLayoutEffect(() => {\n const measured = words.map((_, i) => elements.current[i]?.offsetWidth ?? 0);\n setWidths((prev) => (sameWidths(prev, measured) ? prev : measured));\n });\n\n const gap = fontSize * GAP_EM;\n const resolved =\n widths.length === words.length\n ? widths\n : words.map((word) => word.text.length * fontSize * 0.55);\n const xs = layoutTimeline(words, resolved, pxPerSecond, gap);\n const playheadX = width * playheadPosition;\n const offset = timelineOffset(words, xs, timeMs, pxPerSecond);\n const thickness = Math.max(2, Math.round(fontSize * 0.04));\n\n if (words.length === 0) return null;\n\n return (\n <div\n className={className}\n style={{\n position: \"relative\",\n width,\n height: `${LINE_HEIGHT}em`,\n fontSize,\n fontWeight,\n color,\n lineHeight: LINE_HEIGHT,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n overflow: \"hidden\",\n maskImage: EDGE_FADE,\n WebkitMaskImage: EDGE_FADE,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n transform: `translateX(${playheadX - offset}px)`,\n }}\n >\n {words.map((word, i) => (\n <span\n key={word.id}\n ref={(el) => {\n elements.current[i] = el;\n }}\n style={{\n position: \"absolute\",\n left: xs[i],\n top: 0,\n whiteSpace: \"nowrap\",\n opacity: interpolate(\n timeMs - word.startMs,\n [-LIGHT_MS, 0],\n [upcomingOpacity, 1],\n clamp,\n ),\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {word.text}\n </span>\n ))}\n </div>\n </div>\n <div\n aria-hidden\n style={{\n position: \"absolute\",\n top: \"8%\",\n bottom: \"8%\",\n left: playheadX - thickness / 2,\n width: thickness,\n borderRadius: thickness,\n background: playheadColor,\n }}\n />\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n playheadColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Playhead color\",\n },\n width: {\n type: \"number\",\n min: 400,\n max: 1800,\n step: 10,\n default: 1100,\n description: \"Strip width (px)\",\n hiddenFromList: false,\n },\n pxPerSecond: {\n type: \"number\",\n min: 100,\n max: 600,\n step: 10,\n default: 260,\n description: \"Pixels per second\",\n hiddenFromList: false,\n },\n playheadPosition: {\n type: \"number\",\n min: 0.1,\n max: 0.9,\n step: 0.05,\n default: 0.35,\n description: \"Playhead position\",\n hiddenFromList: false,\n },\n upcomingOpacity: {\n type: \"number\",\n min: 0,\n max: 1,\n step: 0.05,\n default: 0.4,\n description: \"Upcoming opacity\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"playheadColor\",\"width\",\"pxPerSecond\",\"playheadPosition\",\"upcomingOpacity\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n playheadColor: \"#facc15\",\n width: 1100,\n pxPerSecond: 260,\n playheadPosition: 0.35,\n upcomingOpacity: 0.4,\n shadow: true,\n};\n\ntype CaptionTimelineElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionTimelineBase>;\n\nconst CaptionTimelineInner = forwardRef<\n HTMLDivElement,\n CaptionTimelineElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionTimeline>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionTimelineBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionTimelineBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionTimeline = Interactive.withSchema({\n Component: CaptionTimelineInner,\n componentName: \"<CaptionTimeline>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-typewriter.json b/registry-artifacts/elements/caption-typewriter.json
index e895b8c9..18427b16 100644
--- a/registry-artifacts/elements/caption-typewriter.json
+++ b/registry-artifacts/elements/caption-typewriter.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-typewriter",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionTypewriterProps extends CaptionBaseProps {\n caret?: boolean;\n shadow?: boolean;\n}\n\nconst EXIT_MS = 220;\nconst BLINK_MS = 500;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\nconst CARET_SHADOW = \"0 2px 6px rgba(0, 0, 0, 0.45)\";\n\nfunction typedCount(text: string, progress: number): number {\n const length = Array.from(text).length;\n return Math.min(length, Math.ceil(progress * length));\n}\n\nfunction CaptionTypewriterBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n caret = true,\n shadow = true,\n className,\n}: CaptionTypewriterProps) {\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 {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n },\n )\n : 1;\n\n const active = state.tokens[state.activeIndex];\n const typing = active !== undefined && active.progress < 1;\n const idleMs = active ? state.timeMs - active.toMs : 0;\n const caretOn = typing || Math.floor(idleMs / BLINK_MS) % 2 === 0;\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 chars = Array.from(token.text);\n const typed = typedCount(token.text, token.progress);\n return (\n <Fragment key={index}>\n <span\n style={{\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {chars.slice(0, typed).join(\"\")}\n </span>\n {caret && index === state.activeIndex ? (\n <span style={{ position: \"relative\" }}>\n <span\n style={{\n position: \"absolute\",\n left: \"0.03em\",\n top: \"0.1em\",\n bottom: \"0.1em\",\n width: \"0.07em\",\n backgroundColor: color,\n boxShadow: shadow ? CARET_SHADOW : undefined,\n opacity: caretOn ? 1 : 0,\n }}\n />\n </span>\n ) : null}\n <span aria-hidden style={{ color: \"transparent\" }}>\n {chars.slice(typed).join(\"\")}\n </span>\n </Fragment>\n );\n })}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n caret: {\n type: \"boolean\",\n default: true,\n description: \"Caret\",\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"caret\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n caret: true,\n shadow: true,\n};\n\ntype CaptionTypewriterElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionTypewriterBase>;\n\nconst CaptionTypewriterInner = forwardRef<\n HTMLDivElement,\n CaptionTypewriterElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionTypewriter>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionTypewriterBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionTypewriterBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionTypewriter = Interactive.withSchema({\n Component: CaptionTypewriterInner,\n componentName: \"<CaptionTypewriter>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-underline.json b/registry-artifacts/elements/caption-underline.json
index 52a5f5da..032f61a9 100644
--- a/registry-artifacts/elements/caption-underline.json
+++ b/registry-artifacts/elements/caption-underline.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-underline",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionUnderlineProps extends CaptionBaseProps {\n underlineColor?: string;\n thickness?: number;\n underlineOffset?: number;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst TRAVEL_MS = 120;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst travelEasing = Easing.bezier(0.3, 0, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction mix(a: number, b: number, t: number): number {\n return a + (b - a) * t;\n}\n\nfunction CaptionUnderlineBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 800,\n color = \"#ffffff\",\n underlineColor = \"#facc15\",\n thickness = 0.08,\n underlineOffset = 0.02,\n shadow = true,\n className,\n}: CaptionUnderlineProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n const words = state ? groupCaptionWords(state.tokens) : [];\n const pageIndex = state ? state.pageIndex : -1;\n const { wordRef, rects } = useCaptionWordRects(pageIndex, words.length);\n\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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\n const activeWord = words.findIndex((word) =>\n word.some(({ index }) => index === state.activeIndex),\n );\n const travel =\n activeWord >= 0\n ? interpolate(\n state.timeMs - words[activeWord][0].token.fromMs,\n [0, TRAVEL_MS],\n [0, 1],\n { ...clamp, easing: travelEasing },\n )\n : 0;\n\n const target = rects && activeWord >= 0 ? rects[activeWord] : null;\n const origin = rects && activeWord > 0 ? rects[activeWord - 1] : null;\n const barHeight = thickness * fontSize;\n const gap = underlineOffset * fontSize;\n const bar = target\n ? origin\n ? {\n left: mix(origin.left, target.left, travel),\n top: mix(\n origin.top + origin.height,\n target.top + target.height,\n travel,\n ),\n width: mix(origin.width, target.width, travel),\n opacity: 1,\n }\n : {\n left: target.left,\n top: target.top + target.height,\n width: target.width * travel,\n opacity: travel,\n }\n : null;\n\n return (\n <div\n className={className}\n style={{\n position: \"relative\",\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.2,\n textAlign: \"center\",\n opacity: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {words.map((word, w) => (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span\n ref={wordRef(w)}\n style={{\n position: \"relative\",\n display: \"inline-block\",\n whiteSpace: \"nowrap\",\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {word.map(({ index, token }) => (\n <span key={index}>{token.text}</span>\n ))}\n </span>\n </Fragment>\n ))}\n {bar && (\n <span\n aria-hidden\n style={{\n position: \"absolute\",\n left: bar.left,\n top: bar.top + gap,\n width: bar.width,\n height: barHeight,\n borderRadius: barHeight / 2,\n background: underlineColor,\n opacity: bar.opacity,\n }}\n />\n )}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n underlineColor: {\n type: \"color\",\n default: \"#facc15\",\n description: \"Underline color\",\n },\n thickness: {\n type: \"number\",\n min: 0.02,\n max: 0.3,\n step: 0.01,\n default: 0.08,\n description: \"Thickness (em)\",\n hiddenFromList: false,\n },\n underlineOffset: {\n type: \"number\",\n min: -0.2,\n max: 0.4,\n step: 0.01,\n default: 0.02,\n description: \"Offset (em)\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"underlineColor\",\"thickness\",\"underlineOffset\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 800,\n color: \"#ffffff\",\n underlineColor: \"#facc15\",\n thickness: 0.08,\n underlineOffset: 0.02,\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionUnderlineElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionUnderlineBase>;\n\nconst CaptionUnderlineInner = forwardRef<\n HTMLDivElement,\n CaptionUnderlineElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionUnderline>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionUnderlineBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionUnderlineBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionUnderline = Interactive.withSchema({\n Component: CaptionUnderlineInner,\n componentName: \"<CaptionUnderline>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-weight.json b/registry-artifacts/elements/caption-weight.json
index 006eb0f1..2d655681 100644
--- a/registry-artifacts/elements/caption-weight.json
+++ b/registry-artifacts/elements/caption-weight.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-weight",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionWeightProps extends CaptionBaseProps {\n activeWeight?: number;\n shadow?: boolean;\n}\n\nconst ENTER_MS = 160;\nconst EXIT_MS = 220;\nconst RISE_EM = 0.14;\nconst RAMP_MS = 150;\nconst RELEASE_MS = 220;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst enterEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst rampEasing = Easing.bezier(0.2, 0.8, 0.3, 1);\nconst releaseEasing = Easing.bezier(0.4, 0, 0.2, 1);\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionWeightBase({\n captions,\n combineTokensWithinMilliseconds = 1200,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 64,\n fontWeight = 400,\n activeWeight = 900,\n color = \"#ffffff\",\n shadow = true,\n className,\n}: CaptionWeightProps) {\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const enter = interpolate(\n state.previous ? ENTER_MS : state.sinceStartMs,\n [0, ENTER_MS],\n [0, 1],\n {\n ...clamp,\n easing: enterEasing,\n },\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\n const words = groupCaptionWords(state.tokens);\n const activeWord = words.findIndex((word) =>\n word.some(({ index }) => index === state.activeIndex),\n );\n\n const emphasis = (w: number): number => {\n if (activeWord < 0 || w > activeWord) return 0;\n const startMs = words[w][0].token.fromMs;\n const rise = interpolate(state.timeMs - startMs, [0, RAMP_MS], [0, 1], {\n ...clamp,\n easing: rampEasing,\n });\n if (w === activeWord) return rise;\n const releaseMs = words[w + 1][0].token.fromMs;\n const peak = interpolate(releaseMs - startMs, [0, RAMP_MS], [0, 1], {\n ...clamp,\n easing: rampEasing,\n });\n const release = interpolate(\n state.timeMs - releaseMs,\n [0, RELEASE_MS],\n [0, 1],\n { ...clamp, easing: releaseEasing },\n );\n return peak * (1 - release);\n };\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: Math.min(enter, exit),\n transform: `translateY(${(1 - enter) * RISE_EM}em)`,\n }}\n >\n {words.map((word, w) => {\n const weight = fontWeight + (activeWeight - fontWeight) * emphasis(w);\n return (\n <Fragment key={`${state.pageIndex}-${word[0].index}`}>\n {w > 0 && \" \"}\n <span style={{ display: \"inline-grid\", whiteSpace: \"nowrap\" }}>\n <span\n aria-hidden\n style={{\n gridArea: \"1 / 1\",\n fontWeight: Math.max(fontWeight, activeWeight),\n visibility: \"hidden\",\n }}\n >\n {captionWordText(word)}\n </span>\n <span\n style={{\n gridArea: \"1 / 1\",\n justifySelf: \"center\",\n fontWeight: weight,\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\n }}\n >\n {word.map(({ index, token }) => (\n <span key={index}>{token.text}</span>\n ))}\n </span>\n </span>\n </Fragment>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 140,\n step: 1,\n default: 64,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 100,\n max: 900,\n step: 100,\n default: 400,\n description: \"Resting weight\",\n hiddenFromList: false,\n },\n activeWeight: {\n type: \"number\",\n min: 100,\n max: 900,\n step: 100,\n default: 900,\n description: \"Active weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 1200,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"activeWeight\",\"color\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 64,\n fontWeight: 400,\n activeWeight: 900,\n color: \"#ffffff\",\n combineTokensWithinMilliseconds: 1200,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionWeightElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionWeightBase>;\n\nconst CaptionWeightInner = forwardRef<\n HTMLDivElement,\n CaptionWeightElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionWeight>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionWeightBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionWeightBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionWeight = Interactive.withSchema({\n Component: CaptionWeightInner,\n componentName: \"<CaptionWeight>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/registry-artifacts/elements/caption-word-pop.json b/registry-artifacts/elements/caption-word-pop.json
index c011f383..03539c0e 100644
--- a/registry-artifacts/elements/caption-word-pop.json
+++ b/registry-artifacts/elements/caption-word-pop.json
@@ -14,6 +14,7 @@
"durationInFrames": 279,
"initialProps": null,
"installationMode": "component-owned-sequence",
+ "isCaptionStyle": true,
"slug": "caption-word-pop",
"sourceCode": "import { Fragment, forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Interactive, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { createTikTokStyleCaptions, type Caption, type TikTokPage } from \"@remotion/captions\";\n\ntype SpeakerCaption = Caption & { speaker?: string };\n\ninterface CaptionBaseProps {\n captions: Caption[];\n combineTokensWithinMilliseconds?: number;\n holdMs?: number;\n fontSize?: number;\n fontWeight?: number;\n color?: string;\n className?: string;\n}\n\nconst DEFAULT_HOLD_MS = 600;\nconst MIN_SILENCE_BREAK_MS = 300;\n\ninterface CaptionPageWindow {\n page: TikTokPage;\n index: number;\n speaker: string | undefined;\n startMs: number;\n speechEndMs: number;\n endMs: number;\n endsInSilence: boolean;\n}\n\ntype CaptionTokenStatus = \"upcoming\" | \"active\" | \"spoken\";\n\ninterface CaptionTokenState {\n text: string;\n spaceBefore: boolean;\n fromMs: number;\n toMs: number;\n progress: number;\n status: CaptionTokenStatus;\n}\n\ninterface CaptionPreviousPage {\n page: TikTokPage;\n pageIndex: number;\n tokens: CaptionTokenState[];\n}\n\ninterface CaptionsState {\n page: TikTokPage;\n pageIndex: number;\n speaker: string | undefined;\n timeMs: number;\n activeIndex: number;\n tokens: CaptionTokenState[];\n sinceStartMs: number;\n untilEndMs: number;\n holdRoomMs: number;\n endsInSilence: boolean;\n previous: CaptionPreviousPage | null;\n}\n\ninterface CaptionPagingOptions {\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}\n\nconst SENTENCE_END = /[.!?…][\"')\\]]*$/;\n\nfunction markPageBreaks(captions: SpeakerCaption[]): Caption[] {\n return captions.map((caption, i) => {\n if (caption.pageBreakAfter !== undefined) return caption;\n const next = captions[i + 1];\n const speakerChanges =\n next !== undefined && next.speaker !== caption.speaker;\n return speakerChanges || SENTENCE_END.test(caption.text.trim())\n ? { ...caption, pageBreakAfter: true }\n : caption;\n });\n}\n\nfunction buildCaptionPages(\n captions: SpeakerCaption[],\n {\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n }: CaptionPagingOptions,\n): CaptionPageWindow[] {\n if (captions.length === 0) return [];\n const { pages } = createTikTokStyleCaptions({\n captions: markPageBreaks(captions),\n combineTokensWithinMilliseconds,\n breakOnSilenceAfterMilliseconds: Math.max(holdMs, MIN_SILENCE_BREAK_MS),\n });\n const speakers = new Map<number, string | undefined>();\n for (const caption of captions) {\n if (!speakers.has(caption.startMs)) {\n speakers.set(caption.startMs, caption.speaker);\n }\n }\n const spoken = pages.filter((page) => page.tokens.length > 0);\n return spoken.map((page, index) => {\n const last = page.tokens[page.tokens.length - 1];\n const speechEndMs = last ? last.toMs : page.startMs;\n const heldUntil = speechEndMs + Math.max(0, holdMs);\n const next = spoken[index + 1];\n const endsInSilence = !next || next.startMs > heldUntil;\n const endMs = endsInSilence\n ? heldUntil\n : Math.max(page.startMs, next.startMs);\n return {\n page,\n index,\n speaker: speakers.get(page.tokens[0].fromMs),\n startMs: page.startMs,\n speechEndMs,\n endMs,\n endsInSilence,\n };\n });\n}\n\nfunction findWindowIndex(windows: CaptionPageWindow[], timeMs: number): number {\n let lo = 0;\n let hi = windows.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (windows[mid].startMs <= timeMs) {\n found = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n if (found === -1) return -1;\n return timeMs < windows[found].endMs ? found : -1;\n}\n\nfunction tokenProgress(fromMs: number, toMs: number, timeMs: number): number {\n if (timeMs < fromMs) return 0;\n if (toMs <= fromMs) return 1;\n return Math.min(1, (timeMs - fromMs) / (toMs - fromMs));\n}\n\nfunction getTokenStates(\n page: TikTokPage,\n timeMs: number,\n): { activeIndex: number; tokens: CaptionTokenState[] } {\n let activeIndex = -1;\n page.tokens.forEach((token, i) => {\n if (token.fromMs <= timeMs) activeIndex = i;\n });\n const tokens = page.tokens.map(\n (token, i): CaptionTokenState => ({\n text: token.text.trim(),\n spaceBefore: i > 0 && /^\\s/.test(token.text),\n fromMs: token.fromMs,\n toMs: token.toMs,\n progress: tokenProgress(token.fromMs, token.toMs, timeMs),\n status:\n i < activeIndex ? \"spoken\" : i === activeIndex ? \"active\" : \"upcoming\",\n }),\n );\n return { activeIndex, tokens };\n}\n\nfunction getCaptionsState(\n windows: CaptionPageWindow[],\n timeMs: number,\n): CaptionsState | null {\n const found = findWindowIndex(windows, timeMs);\n if (found === -1) return null;\n const window = windows[found];\n const { activeIndex, tokens } = getTokenStates(window.page, timeMs);\n const before = found > 0 ? windows[found - 1] : null;\n const previous =\n before && !before.endsInSilence\n ? {\n page: before.page,\n pageIndex: before.index,\n tokens: getTokenStates(before.page, before.endMs).tokens,\n }\n : null;\n return {\n page: window.page,\n pageIndex: window.index,\n speaker: window.speaker,\n timeMs,\n activeIndex,\n tokens,\n sinceStartMs: timeMs - window.startMs,\n untilEndMs: window.endMs - timeMs,\n holdRoomMs: window.endMs - window.speechEndMs,\n endsInSilence: window.endsInSilence,\n previous,\n };\n}\n\nfunction getExitWindowMs(state: CaptionsState, exitMs: number): number {\n return Math.max(1, Math.min(exitMs, state.holdRoomMs));\n}\n\nfunction groupCaptionWords(\n tokens: CaptionTokenState[],\n): { index: number; token: CaptionTokenState }[][] {\n const words: { index: number; token: CaptionTokenState }[][] = [];\n tokens.forEach((token, index) => {\n const current = words[words.length - 1];\n if (!current || token.spaceBefore) {\n words.push([{ index, token }]);\n } else {\n current.push({ index, token });\n }\n });\n return words;\n}\n\nfunction normalizeCaptionWord(text: string): string {\n return text\n .toLowerCase()\n .replace(/[\\u2018\\u2019]/g, \"'\")\n .replace(/[^\\p{L}\\p{N}']/gu, \"\");\n}\n\nfunction createKeywordMatcher(\n keywords: readonly string[] = [],\n): (text: string) => boolean {\n const set = new Set(keywords.map(normalizeCaptionWord).filter(Boolean));\n return (text) => set.has(normalizeCaptionWord(text));\n}\n\nfunction captionWordText(word: { token: CaptionTokenState }[]): string {\n return word.map(({ token }) => token.text).join(\"\");\n}\n\ninterface CaptionWordRect {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\nfunction sameRects(a: CaptionWordRect[], b: CaptionWordRect[]): boolean {\n return (\n a.length === b.length &&\n a.every(\n (r, i) =>\n r.left === b[i].left &&\n r.top === b[i].top &&\n r.width === b[i].width &&\n r.height === b[i].height,\n )\n );\n}\n\nfunction useCaptionWordRects(\n pageIndex: number,\n count: number,\n): {\n wordRef: (index: number) => (el: HTMLElement | null) => void;\n rects: CaptionWordRect[] | null;\n} {\n const elements = useRef<(HTMLElement | null)[]>([]);\n const [measured, setMeasured] = useState<{\n pageIndex: number;\n rects: CaptionWordRect[];\n } | null>(null);\n\n useLayoutEffect(() => {\n if (pageIndex === -1) return;\n const rects = elements.current.slice(0, count).map((el) =>\n el\n ? {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n }\n : { left: 0, top: 0, width: 0, height: 0 },\n );\n setMeasured((prev) =>\n prev && prev.pageIndex === pageIndex && sameRects(prev.rects, rects)\n ? prev\n : { pageIndex, rects },\n );\n });\n\n return {\n wordRef: (index) => (el) => {\n elements.current[index] = el;\n },\n rects: measured && measured.pageIndex === pageIndex ? measured.rects : null,\n };\n}\n\nfunction useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs = DEFAULT_HOLD_MS,\n}: {\n captions: SpeakerCaption[];\n combineTokensWithinMilliseconds: number;\n holdMs?: number;\n}): CaptionsState | null {\n const frame = useCurrentFrame();\n const { fps } = useVideoConfig();\n const windows = useMemo(\n () =>\n buildCaptionPages(captions, { combineTokensWithinMilliseconds, holdMs }),\n [captions, combineTokensWithinMilliseconds, holdMs],\n );\n return getCaptionsState(windows, (frame / fps) * 1000);\n}\n\ninterface CaptionWordPopProps extends CaptionBaseProps {\n popScale?: number;\n shadow?: boolean;\n}\n\nconst FADE_MS = 50;\nconst EXIT_MS = 180;\nconst LEGIBILITY_SHADOW =\n \"0 2px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35)\";\n\nconst POP_SPRING = { damping: 11, stiffness: 240, mass: 0.6 };\n\nconst clamp = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction CaptionWordPopBase({\n captions,\n combineTokensWithinMilliseconds = 0,\n holdMs = DEFAULT_HOLD_MS,\n fontSize = 96,\n fontWeight = 800,\n color = \"#ffffff\",\n popScale = 0.6,\n shadow = true,\n className,\n}: CaptionWordPopProps) {\n const { fps } = useVideoConfig();\n const state = useCaptions({\n captions,\n combineTokensWithinMilliseconds,\n holdMs,\n });\n if (!state) return null;\n\n const pop = spring({\n frame: (state.sinceStartMs / 1000) * fps,\n fps,\n config: POP_SPRING,\n });\n const fadeIn = state.previous\n ? 1\n : interpolate(state.sinceStartMs, [0, FADE_MS], [0, 1], clamp);\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\n return (\n <div\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n lineHeight: 1.1,\n textAlign: \"center\",\n opacity: Math.min(fadeIn, exit),\n transform: `scale(${popScale + (1 - popScale) * pop})`,\n textShadow: shadow ? LEGIBILITY_SHADOW : undefined,\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 <span key={index}>{token.text}</span>\n ))}\n </span>\n </Fragment>\n ))}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n captions: {\n type: \"remotion-captions\",\n default: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n description: \"Transcript\",\n keyframable: false,\n },\n fontSize: {\n type: \"number\",\n min: 24,\n max: 220,\n step: 1,\n default: 96,\n description: \"Font size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"number\",\n min: 400,\n max: 900,\n step: 100,\n default: 800,\n description: \"Font weight\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#ffffff\",\n description: \"Text color\",\n },\n popScale: {\n type: \"number\",\n min: 0.2,\n max: 1,\n step: 0.05,\n default: 0.6,\n description: \"Start scale\",\n hiddenFromList: false,\n },\n combineTokensWithinMilliseconds: {\n type: \"number\",\n min: 0,\n max: 3000,\n step: 100,\n default: 0,\n description: \"Page window (ms)\",\n hiddenFromList: false,\n },\n holdMs: {\n type: \"number\",\n min: 0,\n max: 2000,\n step: 50,\n default: 600,\n description: \"Hold (ms)\",\n hiddenFromList: false,\n },\n shadow: {\n type: \"boolean\",\n default: true,\n description: \"Shadow\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"captions\",\"fontSize\",\"fontWeight\",\"color\",\"popScale\",\"combineTokensWithinMilliseconds\",\"holdMs\",\"shadow\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n captions: [{\n text: \" So\",\n startMs: 300,\n endMs: 460,\n timestampMs: 380,\n confidence: 0.97,\n }, {\n text: \" here's\",\n startMs: 460,\n endMs: 700,\n timestampMs: 580,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 700,\n endMs: 820,\n timestampMs: 760,\n confidence: 0.97,\n }, {\n text: \" thing.\",\n startMs: 820,\n endMs: 1240,\n timestampMs: 1030,\n confidence: 0.97,\n }, {\n text: \" Most\",\n startMs: 1700,\n endMs: 1960,\n timestampMs: 1830,\n confidence: 0.97,\n }, {\n text: \" demo\",\n startMs: 1960,\n endMs: 2240,\n timestampMs: 2100,\n confidence: 0.97,\n }, {\n text: \" videos\",\n startMs: 2240,\n endMs: 2680,\n timestampMs: 2460,\n confidence: 0.97,\n }, {\n text: \" lose\",\n startMs: 2680,\n endMs: 2960,\n timestampMs: 2820,\n confidence: 0.97,\n }, {\n text: \" people\",\n startMs: 2960,\n endMs: 3320,\n timestampMs: 3140,\n confidence: 0.97,\n }, {\n text: \" in\",\n startMs: 3320,\n endMs: 3420,\n timestampMs: 3370,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 3420,\n endMs: 3520,\n timestampMs: 3470,\n confidence: 0.97,\n }, {\n text: \" first\",\n startMs: 3520,\n endMs: 3820,\n timestampMs: 3670,\n confidence: 0.97,\n }, {\n text: \" three\",\n startMs: 3820,\n endMs: 4100,\n timestampMs: 3960,\n confidence: 0.97,\n }, {\n text: \" seconds.\",\n startMs: 4100,\n endMs: 4780,\n timestampMs: 4440,\n confidence: 0.97,\n }, {\n text: \" Captions\",\n startMs: 5400,\n endMs: 5920,\n timestampMs: 5660,\n confidence: 0.97,\n }, {\n text: \" keep\",\n startMs: 5920,\n endMs: 6140,\n timestampMs: 6030,\n confidence: 0.97,\n }, {\n text: \" them\",\n startMs: 6140,\n endMs: 6300,\n timestampMs: 6220,\n confidence: 0.97,\n }, {\n text: \" watching,\",\n startMs: 6300,\n endMs: 6860,\n timestampMs: 6580,\n confidence: 0.97,\n }, {\n text: \" even\",\n startMs: 6960,\n endMs: 7180,\n timestampMs: 7070,\n confidence: 0.97,\n }, {\n text: \" with\",\n startMs: 7180,\n endMs: 7320,\n timestampMs: 7250,\n confidence: 0.97,\n }, {\n text: \" the\",\n startMs: 7320,\n endMs: 7420,\n timestampMs: 7370,\n confidence: 0.97,\n }, {\n text: \" sound\",\n startMs: 7420,\n endMs: 7760,\n timestampMs: 7590,\n confidence: 0.97,\n }, {\n text: \" off.\",\n startMs: 7760,\n endMs: 8300,\n timestampMs: 8030,\n confidence: 0.97,\n }],\n fontSize: 96,\n fontWeight: 800,\n color: \"#ffffff\",\n popScale: 0.6,\n combineTokensWithinMilliseconds: 0,\n holdMs: 600,\n shadow: true,\n};\n\ntype CaptionWordPopElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CaptionWordPopBase>;\n\nconst CaptionWordPopInner = forwardRef<\n HTMLDivElement,\n CaptionWordPopElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CaptionWordPop>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CaptionWordPopBase\n {...(componentProps as unknown as ComponentProps<typeof CaptionWordPopBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CaptionWordPop = Interactive.withSchema({\n Component: CaptionWordPopInner,\n componentName: \"<CaptionWordPop>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
},
diff --git a/scripts/build-elements.mts b/scripts/build-elements.mts
index 6c5ed0e4..2ef2711c 100644
--- a/scripts/build-elements.mts
+++ b/scripts/build-elements.mts
@@ -527,6 +527,9 @@ for (const file of readdirSync(ARTIFACTS_DIR).sort()) {
dimensions,
durationInFrames,
installationMode,
+ ...(regDeps.includes("@remocn/caption-core")
+ ? { isCaptionStyle: true }
+ : {}),
});
writeFileSync(