Text

Full Bleed Type

Huge condensed caps words slam in one at a time, the last lit by a sunrise gradient.

Full Bleed Type preview, rendered with Remotion.

Source

components/kuchi/full-bleed-type.tsx
"use client";
import { loadFont } from "@remotion/google-fonts/BarlowCondensed";
import type React from "react";
import { useId } from "react";
import {
AbsoluteFill,
Easing,
interpolate,
useCurrentFrame,
useVideoConfig,
} from "remotion";
const { fontFamily: display } = loadFont("normal", {
weights: ["500"],
subsets: ["latin"],
});
export interface FullBleedTypeProps {
/** Words in reading order, one slam each. Set in caps; the last one is lit by the sunrise gradient. */
words?: string[];
/** Frames between two slams. */
beat?: number;
/** Frames a word takes to slam in, before it settles. */
slam?: number;
/** Kept for the shared draft API; the hero word takes the "rise" gradient instead. */
accent?: string;
/** Color of every word but the last; overrides the theme ink. */
ink?: string;
background?: string;
/** Typeface for the words. Load it yourself; Barlow Condensed by default. Row widths are fitted to Barlow Condensed. */
fontFamily?: string;
/** Size of the word stack, around the frame's center. */
scale?: number;
/** Frames to hold the first frame before anything moves. */
delay?: number;
theme?: "dark" | "light";
speed?: number;
}
// Barlow Condensed 500, per 1000 em, chars 32–126 (harfbuzz): advance, left and right side bearing.
const ADV = [
200, 261, 274, 599, 426, 776, 564, 137, 254, 254, 361, 440, 189, 320, 202,
363, 447, 266, 415, 418, 440, 420, 420, 381, 429, 414, 234, 207, 440, 440,
440, 394, 759, 436, 456, 452, 469, 432, 410, 457, 475, 220, 435, 466, 407,
530, 501, 462, 451, 450, 453, 426, 439, 477, 457, 646, 449, 442, 401, 318,
363, 318, 406, 392, 194, 425, 431, 413, 431, 417, 285, 423, 432, 212, 206,
421, 191, 657, 432, 424, 435, 435, 304, 387, 275, 432, 399, 575, 398, 387,
365, 298, 159, 298, 471,
];
const LSB = [
0, 67, 20, 48, 36, 62, 36, 20, -1, 61, 19, 29, 34, 29, 37, 21, 44, 10, 33, 32,
19, 45, 45, 19, 44, 26, 54, 38, 29, 29, 29, 24, 43, 12, 62, 48, 62, 62, 62,
48, 62, 62, 19, 62, 62, 60, 62, 48, 61, 48, 62, 36, 30, 57, 31, 26, 32, 32,
29, 27, 50, 96, 30, 19, 25, 34, 52, 43, 43, 43, 25, 43, 52, 41, -39, 52, 48,
52, 52, 43, 57, 43, 52, 35, 21, 48, 21, 21, 18, 16, 28, 27, 31, 27, 29,
];
const RSB = [
200, 66, 21, 48, 35, 62, 42, 21, 62, -1, 19, 29, 38, 29, 37, 50, 44, 51, 24,
45, 19, 32, 31, 15, 45, 45, 52, 38, 29, 29, 29, 26, 43, 13, 30, 43, 52, 35,
14, 48, 62, 62, 62, 18, 11, 59, 62, 48, 29, 48, 26, 35, 30, 57, 29, 24, 32,
30, 33, 96, 21, 27, 32, 19, 23, 43, 44, 33, 53, 38, 29, 45, 47, 43, 41, 25,
47, 48, 47, 42, 43, 57, 9, 25, 24, 53, 20, 19, 18, 15, 27, 26, 32, 26, 29,
];
const KERN = new Map(
[
"+2-9 +7-22 ,--6 ,0-38 ,7-29 ,K-11 ,L-11 ,T-49 ,V-28 ,W-28 ,X10 ,Y-62",
",c-6 ,d-6 ,e-6 ,g-6 ,o-6 ,q-6 ,v-13 ,w-13 ,y-13 -,-6 -.-6 -v-15 -w-15",
"-x-12 -y-15 .--6 .0-38 .7-29 .K-11 .L-11 .T-49 .V-28 .W-28 .X10 .Y-62",
".c-6 .d-6 .e-6 .g-6 .o-6 .q-6 .v-13 .w-13 .y-13 /--49 /A-68 /B-12 /C-29",
"/D-12 /E-12 /F-12 /G-29 /K-17 /L-22 /N-12 /O-29 /P-12 /Q-29 /R-11 /S-11",
"/a-52 /c-49 /d-49 /e-49 /g-14 /m-9 /n-9 /o-49 /p-9 /q-14 /r-9 /s-22",
"/u-13 /v-18 /w-18 /y-18 /z-13 11-17 21-27 31-32 41-48 47-50 51-17 61-22",
"7,-51 7.-51 7/-72 71-6 81-28 91-28 A/7 AA28 AC-13 AG-13 AO-13 AQ-13",
"AS-21 AT-60 AV-63 AW-63 AX6 AY-42 Au-9 Av-26 Aw-26 Ax17 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 n.-11 nx-9",
"o,-6 o.-6 ov-15 ow-15 ox-12 oy-15 p,-11 p.-11 px-9 qv-11 qw-11 qy-11",
"rg-8 rq-8 rv11 rw11 ry11 ss-19 sv-13 sw-13 sx-9 sy-13 v,-13 v--10 v.-13",
"v/-18 va-9 vc-10 vd-10 ve-10 vg-18 vo-10 vq-18 vs-10 vv11 vw11 vy11",
"w,-13 w--10 w.-13 w/-18 wa-9 wc-10 wd-10 we-10 wg-18 wo-10 wq-18 ws-10",
"wv11 ww11 wy11 x--13 xc-13 xd-13 xe-13 xo-13 y,-13 y--10 y.-13 y/-18",
"ya-9 yc-10 yd-10 ye-10 yg-18 yo-10 yq-18 ys-10 yv11 yw11 yy11 z/9",
]
.join(" ")
.split(" ")
.map((p) => [p.slice(0, 2), Number(p.slice(2)) / 1000] as const),
);
const CAP = 0.7;
const TRACK = -0.01;
// Beat sheet (30fps, speed 1, beat 11):
// -2–45 one word per beat slams in from alternating sides, already at its
// final size, overshoots by ~1% of the frame and settles; rows are
// justified edge to edge, so each word lands in a fixed grid slot
// 46–58 the stack locks: the open leading between rows closes up
// 58– poster hold
const FIRST_AT = -2;
const SLAM_LEN = 8;
const SETTLE_LEN = 6;
const LOCK_LEN = 12;
const SLAM = Easing.bezier(0.2, 0.9, 0.35, 1);
const SETTLE = Easing.bezier(0.45, 0, 0.55, 1);
const LOCK = Easing.bezier(0.65, 0, 0.2, 1);
const CLAMP = {
extrapolateLeft: "clamp",
extrapolateRight: "clamp",
} as const;
// gradients.sh "rise" (bg #030306): a sunrise lighting the hero word from below.
// The light stage drops the palest stop so the word keeps its edge on off-white.
const THEMES = {
dark: {
stage: "#0A0A0B",
ink: "#F3F2EF",
rise: ["#fff1e2", "#ff8a3d", "#a3301a"],
},
light: {
stage: "#F5F4F0",
ink: "#121214",
rise: ["#ff8a3d", "#a3301a", "#2a0d0a"],
},
} as const;
function code(ch: string) {
const c = ch.charCodeAt(0);
if (c >= 32 && c < 127) return c - 32;
if (ch === "’" || ch === "‘") return 7;
return 46;
}
function advance(text: string) {
let adv = 0;
for (let i = 0; i < text.length; i++) {
adv += ADV[code(text[i])] / 1000;
if (i > 0) adv += (KERN.get(text[i - 1] + text[i]) ?? 0) + TRACK;
}
return adv;
}
// A tight word space: the rows read as blocks, not sentences.
const SPACE = 0.15;
interface Row {
words: number[];
/** Pen offset of each word from the row's pen start, in em. */
offsets: number[];
lsb: number;
ink: number;
}
function buildRow(words: string[], ids: number[]): Row {
const offsets: number[] = [];
let pen = 0;
for (const id of ids) {
offsets.push(pen);
pen += advance(words[id]) + SPACE;
}
pen -= SPACE;
const first = words[ids[0]];
const last = words[ids[ids.length - 1]];
const lsb = LSB[code(first[0] ?? " ")] / 1000;
const rsb = RSB[code(last[last.length - 1] ?? " ")] / 1000;
return { words: ids, offsets, lsb, ink: Math.max(0.2, pen - lsb - rsb) };
}
/**
* Groups consecutive words into rows so that, with every row scaled to the
* full measure, the stack fills the frame height as closely as possible.
*/
function layoutRows(
words: string[],
measure: number,
room: number,
gap: number,
) {
const n = words.length;
let best: Row[] = [];
let bestScore = Number.POSITIVE_INFINITY;
for (let mask = 0; mask < 1 << Math.max(0, n - 1); mask++) {
const rows: Row[] = [];
let ids: number[] = [];
for (let i = 0; i < n; i++) {
ids.push(i);
if (i === n - 1 || mask & (1 << i)) {
rows.push(buildRow(words, ids));
ids = [];
}
}
const height =
rows.reduce((h, r) => h + (CAP * measure) / r.ink, 0) +
gap * (rows.length - 1);
const score = height > room ? (height - room) * 2.5 : room - height;
if (score < bestScore) {
bestScore = score;
best = rows;
}
}
return best;
}
/** The foreground at `scale`, around the frame's center; nothing extra at 1. */
function ScaleLayer({
scale,
children,
}: {
scale: number;
children: React.ReactNode;
}) {
if (scale === 1) return children;
return (
<AbsoluteFill style={{ transform: `scale(${scale})` }}>
{children}
</AbsoluteFill>
);
}
export function FullBleedType({
words = ["NO", "DAYS", "OFF", "SHIP"],
beat = 11,
slam: slamLen = SLAM_LEN,
ink,
background,
fontFamily = display,
scale = 1,
delay = 0,
theme = "dark",
speed = 1,
}: FullBleedTypeProps) {
const t = Math.max(0, useCurrentFrame() - delay) * speed;
const { width: W, height: H } = useVideoConfig();
const c = THEMES[theme];
const fg = ink ?? c.ink;
const stage =
background === "transparent" ? "transparent" : (background ?? c.stage);
const gradId = `fb${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
const list = words.map((w) => w.trim().toUpperCase()).filter(Boolean);
const margin = 0.036 * W;
const lockGap = 0.026 * H;
const openGap = 0.075 * H;
const room = H - 2 * 0.07 * H;
const rows = layoutRows(list, W - 2 * margin, room, lockGap);
const sizes0 = rows.map((r) => (W - 2 * margin) / r.ink);
const height0 =
sizes0.reduce((h, s) => h + CAP * s, 0) + lockGap * (rows.length - 1);
// Too tall even at the best grouping: shrink the whole stack, keep it centered.
const fit = Math.min(1, room / height0);
const sizes = sizes0.map((s) => s * fit);
const measure = (W - 2 * margin) * fit;
const left = (W - measure) / 2;
const lastAt = FIRST_AT + (list.length - 1) * beat;
const lockAt = lastAt + slamLen + SETTLE_LEN;
const lock = LOCK(interpolate(t, [lockAt, lockAt + LOCK_LEN], [0, 1], CLAMP));
const gap = openGap + (lockGap * fit - openGap) * lock;
const stackH =
sizes.reduce((h, s) => h + CAP * s, 0) + gap * (rows.length - 1);
let y = (H - stackH) / 2;
const glyphs = rows.flatMap((row, r) => {
const fs = sizes[r];
const baseline = y + CAP * fs;
y = baseline + gap;
const penX = left - row.lsb * fs;
return row.words.map((id, j) => {
const word = list[id];
const x = penX + row.offsets[j] * fs;
const w = advance(word) * fs;
const fromLeft = id % 2 === 0;
const at = FIRST_AT + id * beat;
const enter = fromLeft ? -(x + w) - 0.04 * W : W - x + 0.04 * W;
const over = (fromLeft ? 1 : -1) * 0.011 * W;
const slam = SLAM(interpolate(t, [at, at + slamLen], [0, 1], CLAMP));
const settle = SETTLE(
interpolate(
t,
[at + slamLen, at + slamLen + SETTLE_LEN],
[0, 1],
CLAMP,
),
);
const dx = enter + (over - enter) * slam - over * settle;
return {
key: `${id}-${word}`,
word,
x: x + dx,
baseline,
fs,
hero: id === list.length - 1,
visible: t >= at,
};
});
});
// The sunrise sits on the hero word's baseline and climbs a little over the
// shot, so the word warms up while it holds.
const hero = glyphs[glyphs.length - 1];
const heroCap = hero ? CAP * hero.fs : 0;
const climb = interpolate(t, [lastAt, lockAt + LOCK_LEN + 30], [0, 1], {
...CLAMP,
easing: Easing.bezier(0.33, 0, 0.3, 1),
});
const sunY = hero ? hero.baseline + heroCap * (0.14 - 0.12 * climb) : 0;
return (
<AbsoluteFill style={{ background: stage }}>
<ScaleLayer scale={scale}>
<svg
width={W}
height={H}
viewBox={`0 0 ${W} ${H}`}
style={{ position: "absolute", inset: 0 }}
aria-label={list.join(" ")}
role="img"
>
<defs>
<linearGradient
id={gradId}
gradientUnits="userSpaceOnUse"
x1={0}
y1={sunY}
x2={0}
y2={sunY - heroCap * 1.12}
>
<stop offset="0" stopColor={c.rise[0]} />
<stop offset="0.42" stopColor={c.rise[1]} />
<stop offset="1" stopColor={c.rise[2]} />
</linearGradient>
</defs>
{glyphs.map((g) =>
g.visible ? (
<text
key={g.key}
x={g.x}
y={g.baseline}
fill={g.hero ? `url(#${gradId})` : fg}
fontFamily={fontFamily}
fontWeight={500}
fontSize={g.fs}
style={{ letterSpacing: `${TRACK}em`, fontKerning: "normal" }}
>
{g.word}
</text>
) : null,
)}
</svg>
</ScaleLayer>
</AbsoluteFill>
);
}