← All edits
← All edits
Component · Text/Hooks · 4:5
by CutshipVerified
One quiet line of small monospace caps gliding sideways across a clean white frame, with tiny full-body lookbook cutouts between the phrases that flick through outfits as they pass, like a fashion store's end-of-season banner.
1 taken · 2 views
Included with Pro
Sign up free to unlock the spec, agent prompt and Make this.
Make it mine
Pro+Drop in your clip, photos and words and watch this asset play with them, styled with your brand kit. Then hand it to your agent for the full-quality render.
Make it mine is part of Pro+components/remotion/cutout-ticker/component.tsx
import React, { useEffect, useMemo, useState } from "react";
import { AbsoluteFill, Img, continueRender, delayRender, staticFile, useCurrentFrame, useVideoConfig } from "remotion";
import { loadFont as loadRobotoMono } from "@remotion/google-fonts/RobotoMono";
import { loadFont as loadPlexMono } from "@remotion/google-fonts/IBMPlexMono";
import { loadFont as loadSpaceMono } from "@remotion/google-fonts/SpaceMono";
import { getAvailableFonts } from "@remotion/google-fonts";
import type { CutoutTickerProps } from "./schema";
const FONTS = {
"roboto-mono": loadRobotoMono("normal", { weights: ["400"], subsets: ["latin", "latin-ext"] }),
"ibm-plex-mono": loadPlexMono("normal", { weights: ["400"], subsets: ["latin", "latin-ext"] }),
"space-mono": loadSpaceMono("normal", { weights: ["400"], subsets: ["latin", "latin-ext"] }),
} as const;
const resolve = (s: string) => (/^(https?:|data:|blob:|\/)/.test(s) ? s : staticFile(s));
/** Loads a brand-kit Google Font by family name; returns it once ready. */
const useBrandFont = (family?: string) => {
const [ready, setReady] = useState<string | null>(null);
useEffect(() => {
if (!family) return setReady(null);
const entry = getAvailableFonts().find((f) => f.fontFamily.toLowerCase() === family.toLowerCase());
if (!entry) return;
const handle = delayRender(`Loading font ${family}`);
entry
.load()
.then((mod) => {
const weights = Object.keys(mod.getInfo().fonts.normal ?? {});
const keep = ["400", "500"].filter((w) => weights.includes(w));
return mod.loadFont("normal", { subsets: ["latin"], weights: keep.length ? keep : undefined }).waitUntilDone();
})
.then(() => setReady(entry.fontFamily))
.catch(() => setReady(null))
.finally(() => continueRender(handle));
}, [family]);
return ready;
};
/**
* Measures each phrase with canvas once its font has loaded, so the strip knows exactly how
* wide one repeat is and can wrap without a visible jump. Holds the render until it has.
*/
const usePhraseWidths = (texts: string[], family: string, fontPx: number, trackingPx: number, fontReady: Promise<unknown>) => {
const key = JSON.stringify([texts, family, fontPx, trackingPx]);
const [widths, setWidths] = useState<{ key: string; w: number[] } | null>(null);
useEffect(() => {
const handle = delayRender("Measuring ticker phrases");
let live = true;
const font = `400 ${fontPx}px "${family}"`;
Promise.all([fontReady, document.fonts.load(font, texts.join(""))])
.catch(() => undefined)
.then(() => {
if (!live) return;
const ctx = document.createElement("canvas").getContext("2d");
if (!ctx) return;
ctx.font = font;
// Canvas has no letter-spacing in every browser; add it per glyph like CSS does.
const w = texts.map((t) => ctx.measureText(t).width + trackingPx * [...t].length);
setWidths({ key, w });
})
.finally(() => continueRender(handle));
return () => {
live = false;
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [key]);
return widths?.key === key ? widths.w : null;
};
const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a);
/**
* One line of small monospace caps scrolling sideways at a steady pace, with little cut-out
* figures or products standing between the phrases, like a shop's sale banner.
*/
export const CutoutTicker: React.FC<CutoutTickerProps> = ({
phrases,
cutouts,
flip,
flipEvery,
flipRipple,
separator,
background,
bandColor,
textColor: baseTextColor,
font,
fontSize,
letterSpacing,
uppercase,
cutoutHeight,
cutoutWidth,
gap,
speed,
direction,
seamlessLoop,
positionY: basePositionY,
brandKit,
}) => {
const frame = useCurrentFrame();
const { fps, width, height, durationInFrames } = useVideoConfig();
const s = width / 1080;
const brandFont = useBrandFont(brandKit?.fonts[0]);
const loaded = FONTS[font] ?? FONTS["roboto-mono"];
const fontFamily = brandFont ?? loaded.fontFamily;
const fontReady = useMemo(() => (brandFont ? Promise.resolve() : loaded.waitUntilDone()), [brandFont, loaded]);
const textColor = brandKit?.colors[0] ?? baseTextColor;
const positionY =
brandKit?.captionPosition === "top" ? 0.2 : brandKit?.captionPosition === "bottom" ? 0.75 : basePositionY;
const fontPx = fontSize * s;
const trackingPx = letterSpacing * fontPx;
const imgH = cutoutHeight * s;
const slotW = imgH * cutoutWidth;
const gapPx = gap * s;
const texts = phrases.map((p) => (uppercase ? p.toUpperCase() : p));
const sepText = separator || "·";
const measured = usePhraseWidths([...texts, sepText], fontFamily, fontPx, trackingPx, fontReady);
// One repeat of the strip. Static cutouts repeat with the phrases every lcm(phrases, cutouts) pairs;
// flipping cutouts are picked per slot (cutoutFor), so the strip only repeats with the phrases.
const P = Math.max(1, texts.length);
const C = cutouts.length;
const flipping = flip && C > 1;
const pairs = C && !flipping ? (P * C) / gcd(P, C) : P;
const unit = Array.from({ length: Math.min(pairs, 48) }, (_, i) => ({ phrase: i % P, cutout: C ? i % C : -1 }));
if (!measured) return <AbsoluteFill style={{ backgroundColor: background }} />;
const sepW = measured[measured.length - 1];
const itemW = C ? slotW : sepW;
const unitW = unit.reduce((sum, u) => sum + measured[u.phrase] + gapPx * 2 + itemW, 0);
// Steady, linear scroll. With seamlessLoop the speed is nudged so the clip ends on a whole repeat.
const seconds = durationInFrames / fps;
let pxPerSec = speed * s;
if (seamlessLoop && unitW > 0) {
const looped = (Math.max(1, Math.round((pxPerSec * seconds) / unitW)) * unitW) / seconds;
// Only nudge when it stays close to the asked speed; a clip shorter than one repeat keeps its pace instead.
if (Math.abs(looped / pxPerSec - 1) <= 0.25) pxPerSec = looped;
}
const t = frame / fps;
const travelled = t * pxPerSec;
const offset = unitW > 0 ? travelled % unitW : 0;
const x = direction === "left" ? -offset : offset - unitW;
const wraps = unitW > 0 ? Math.floor(travelled / unitW) : 0;
// Every cutout slot keeps one identity as the strip wraps (its index along the endless line), so its
// image only changes on a flip. With flip on, each slot steps through the set every `flipEvery`
// seconds, neighbours offset by `flipRipple`, like flicking through a lookbook.
const cutoutFor = (c: number, i: number) => {
const slot = (direction === "left" ? c + wraps : c - wraps) * unit.length + i;
const step = flipping ? Math.floor((t + slot * flipRipple) / flipEvery) : 0;
return cutouts[(((slot + step) % C) + C) % C];
};
const copies = unitW > 0 ? Math.ceil(width / unitW) + 2 : 1;
const bandH = Math.max(imgH, fontPx * 1.2) + fontPx * 0.9;
return (
<AbsoluteFill style={{ backgroundColor: background }}>
{/* Load the whole set up front so a flip never waits on (or blanks for) an image. */}
{flipping ? (
<div style={{ position: "absolute", width: 1, height: 1, overflow: "hidden", opacity: 0 }}>
{cutouts.map((src) => (
<Img key={src} src={resolve(src)} style={{ height: imgH }} />
))}
</div>
) : null}
<div
style={{
position: "absolute",
left: 0,
right: 0,
top: positionY * height - bandH / 2,
height: bandH,
backgroundColor: bandColor,
overflow: "hidden",
}}
>
<div
style={{
position: "absolute",
top: 0,
bottom: 0,
left: 0,
display: "flex",
alignItems: "center",
translate: `${x}px 0px`,
whiteSpace: "nowrap",
}}
>
{Array.from({ length: copies }).flatMap((_, c) =>
unit.map((u, i) => (
<React.Fragment key={`${c}-${i}`}>
<span
style={{
flex: "none",
width: measured[u.phrase],
fontFamily,
fontWeight: 400,
fontSize: fontPx,
letterSpacing: trackingPx,
lineHeight: 1,
color: textColor,
}}
>
{texts[u.phrase]}
</span>
<span style={{ flex: "none", width: gapPx }} />
{u.cutout >= 0 ? (
<Img
src={resolve(cutoutFor(c, i))}
style={{ flex: "none", width: slotW, height: imgH, objectFit: "contain", objectPosition: "50% 100%" }}
/>
) : (
<span
style={{
flex: "none",
width: sepW,
fontFamily,
fontSize: fontPx,
letterSpacing: trackingPx,
lineHeight: 1,
color: textColor,
}}
>
{sepText}
</span>
)}
<span style={{ flex: "none", width: gapPx }} />
</React.Fragment>
)),
)}
</div>
</div>
</AbsoluteFill>
);
};
Remotion code you can paste anywhere, or install it: npx cutship add cutout-ticker
MIT License: use it in any video, personal or commercial. License
More from Cutship
Creator page →