Skip to content

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

docs: design rush type component (#270)

KapishDima68fe8e3dca64
diff --git a/components/FaultyTerminal.tsx b/components/FaultyTerminal.tsx
index 3f9d22c5..dc5f4d14 100644
--- a/components/FaultyTerminal.tsx
+++ b/components/FaultyTerminal.tsx
@@ -1,9 +1,11 @@
-import { Renderer, Program, Mesh, Color, Triangle } from 'ogl';
-import React, { useEffect, useRef, useMemo, useCallback } from 'react';
+import { Color, Mesh, Program, Renderer, Triangle } from "ogl";
+import type React from "react";
+import { useCallback, useEffect, useMemo, useRef } from "react";
type Vec2 = [number, number];
-export interface FaultyTerminalProps extends React.HTMLAttributes<HTMLDivElement> {
+export interface FaultyTerminalProps
+ extends React.HTMLAttributes<HTMLDivElement> {
scale?: number;
gridMul?: Vec2;
digitSize?: number;
@@ -241,14 +243,18 @@ void main() {
`;
function hexToRgb(hex: string): [number, number, number] {
- let h = hex.replace('#', '').trim();
+ let h = hex.replace("#", "").trim();
if (h.length === 3)
h = h
- .split('')
- .map(c => c + c)
- .join('');
+ .split("")
+ .map((c) => c + c)
+ .join("");
const num = parseInt(h.slice(0, 6), 16);
- return [((num >> 16) & 255) / 255, ((num >> 8) & 255) / 255, (num & 255) / 255];
+ return [
+ ((num >> 16) & 255) / 255,
+ ((num >> 8) & 255) / 255,
+ (num & 255) / 255,
+ ];
}
export default function FaultyTerminal({
@@ -264,7 +270,7 @@ export default function FaultyTerminal({
chromaticAberration = 0,
dither = 0,
curvature = 0.2,
- tint = '#ffffff',
+ tint = "#ffffff",
mouseReact = true,
mouseStrength = 0.2,
dpr = Math.min(window.devicePixelRatio || 1, 2),
@@ -288,7 +294,10 @@ export default function FaultyTerminal({
const tintVec = useMemo(() => hexToRgb(tint), [tint]);
- const ditherValue = useMemo(() => (typeof dither === 'boolean' ? (dither ? 1 : 0) : dither), [dither]);
+ const ditherValue = useMemo(
+ () => (typeof dither === "boolean" ? (dither ? 1 : 0) : dither),
+ [dither],
+ );
const handleMouseMove = useCallback((e: MouseEvent) => {
const ctn = containerRef.current;
@@ -299,6 +308,7 @@ export default function FaultyTerminal({
mouseRef.current = { x, y };
}, []);
+ // biome-ignore lint/correctness/useExhaustiveDependencies: timeOffset is only read in cleanup to reseed the ref — recreating the WebGL context on its change is not wanted
useEffect(() => {
const ctn = containerRef.current;
if (!ctn) return;
@@ -316,7 +326,11 @@ export default function FaultyTerminal({
uniforms: {
iTime: { value: 0 },
iResolution: {
- value: new Color(gl.canvas.width, gl.canvas.height, gl.canvas.width / gl.canvas.height)
+ value: new Color(
+ gl.canvas.width,
+ gl.canvas.height,
+ gl.canvas.width / gl.canvas.height,
+ ),
},
uScale: { value: scale },
@@ -331,15 +345,18 @@ export default function FaultyTerminal({
uCurvature: { value: curvature },
uTint: { value: new Color(tintVec[0], tintVec[1], tintVec[2]) },
uMouse: {
- value: new Float32Array([smoothMouseRef.current.x, smoothMouseRef.current.y])
+ value: new Float32Array([
+ smoothMouseRef.current.x,
+ smoothMouseRef.current.y,
+ ]),
},
uMouseStrength: { value: mouseStrength },
uUseMouse: { value: mouseReact ? 1 : 0 },
uPageLoadProgress: { value: pageLoadAnimation ? 0 : 1 },
uUsePageLoadAnimation: { value: pageLoadAnimation ? 1 : 0 },
uBrightness: { value: brightness },
- uLightMode: { value: lightMode ? 1 : 0 }
- }
+ uLightMode: { value: lightMode ? 1 : 0 },
+ },
});
programRef.current = program;
@@ -351,7 +368,7 @@ export default function FaultyTerminal({
program.uniforms.iResolution.value = new Color(
gl.canvas.width,
gl.canvas.height,
- gl.canvas.width / gl.canvas.height
+ gl.canvas.width / gl.canvas.height,
);
}
@@ -398,14 +415,14 @@ export default function FaultyTerminal({
rafRef.current = requestAnimationFrame(update);
ctn.appendChild(gl.canvas);
- if (mouseReact) ctn.addEventListener('mousemove', handleMouseMove);
+ if (mouseReact) ctn.addEventListener("mousemove", handleMouseMove);
return () => {
cancelAnimationFrame(rafRef.current);
resizeObserver.disconnect();
- if (mouseReact) ctn.removeEventListener('mousemove', handleMouseMove);
+ if (mouseReact) ctn.removeEventListener("mousemove", handleMouseMove);
if (gl.canvas.parentElement === ctn) ctn.removeChild(gl.canvas);
- gl.getExtension('WEBGL_lose_context')?.loseContext();
+ gl.getExtension("WEBGL_lose_context")?.loseContext();
loadAnimationStartRef.current = 0;
timeOffsetRef.current = timeOffset ?? Math.random() * 100;
};
@@ -429,10 +446,15 @@ export default function FaultyTerminal({
pageLoadAnimation,
brightness,
lightMode,
- handleMouseMove
+ handleMouseMove,
]);
return (
- <div ref={containerRef} className={`w-full h-full relative overflow-hidden ${className}`} style={style} {...rest} />
+ <div
+ ref={containerRef}
+ className={`w-full h-full relative overflow-hidden ${className}`}
+ style={style}
+ {...rest}
+ />
);
}
diff --git a/config/site.ts b/config/site.ts
index 641af81b..a9bd2a45 100644
--- a/config/site.ts
+++ b/config/site.ts
@@ -71,6 +71,7 @@ export const NEW_BADGE_PATHS = new Set<string>([
"/docs/typography/gradient-scale-cut-text",
"/docs/typography/inline-pill-takeover",
"/docs/typography/outline-fill-track-text",
+ "/docs/typography/rush-type",
"/docs/typography/shadow-sweep-text",
"/docs/typography/sheen-slide-in",
"/docs/typography/squeeze-in",
diff --git a/content/docs/typography/meta.json b/content/docs/typography/meta.json
index be2ce757..1996e538 100644
--- a/content/docs/typography/meta.json
+++ b/content/docs/typography/meta.json
@@ -27,6 +27,7 @@
"shadow-sweep-text",
"outline-fill-track-text",
"gradient-scale-cut-text",
+ "rush-type",
"fade-through",
"shared-axis-y",
"shared-axis-z",
diff --git a/content/docs/typography/rush-type.mdx b/content/docs/typography/rush-type.mdx
new file mode 100644
index 00000000..48059bc9
--- /dev/null
+++ b/content/docs/typography/rush-type.mdx
@@ -0,0 +1,149 @@
+---
+title: Rush Type
+description: White words blast into vertical RGB shutter trails generated entirely by motion
+component: rush-type
+vibe: tech
+length: 104
+useWhen:
+ - "A short phrase should cycle one forceful word at a time."
+ - "Chromatic separation should emerge from motion rather than tinting the text."
+ - "A kinetic-type beat needs a sharp readable rest between extreme blasts."
+avoidWhen:
+ - "The text must remain readable throughout the motion — use `word-push` or `zoom-words`."
+ - "You want a horizontal digital glitch — use `rgb-glitch-text`."
+ - "The background cannot be black or the component must remain transparent."
+---
+
+<ComponentPreview name="rush-type" />
+
+## Installation
+
+<InstallBlock name="rush-type" />
+
+## Usage
+
+`RushType` shows one word of a short phrase on a flat black frame. The word
+rests in pixel-sharp white, then grows rapidly through a vertical orbit. During
+that motion, the same monochrome glyph is accumulated into red, green, and blue
+channels over different shutter lengths. Green travels furthest, blue remains
+tightest, and red sits between them.
+
+The channels are divided by their accumulated sample weights, so the effect
+conserves energy instead of brightening as blur length increases. When motion
+stops, the shutter sweep collapses, all channels sample the same pixels, and the
+word resolves to white without a crossfade or a separately colored layer.
+
+```tsx
+// src/Root.tsx
+import { Composition } from "remotion";
+import {
+ RushType,
+ rushTypeLength,
+} from "@/components/remocn/rush-type";
+
+export const RemotionRoot = () => (
+ <Composition
+ id="RushType"
+ component={RushType}
+ durationInFrames={rushTypeLength}
+ fps={30}
+ width={1280}
+ height={720}
+ defaultProps={{ phrase: "gone before you look" }}
+ />
+);
+```
+
+### Controlling The Color Split
+
+`chromaticSpread` changes the distance between the three shutter lengths. At
+`0`, all three channels share the same shutter and no color appears. At `1`,
+the component uses the reference ratio of approximately `0.62 / 1 / 0.34` for
+red, green, and blue. Higher values widen that timing difference; they do not
+apply new colors to the word.
+
+```tsx
+<RushType
+ phrase="move before it settles"
+ verticalStretch={8}
+ chromaticSpread={1.25}
+ restDuration={15}
+ peakHoldDuration={4}
+/>
+```
+
+## Props
+
+<PropsTable
+ rows={[
+ {
+ name: "phrase",
+ type: "string",
+ default: '"gone before you look"',
+ description: "Whitespace-delimited phrase shown one word per cycle",
+ },
+ {
+ name: "fontSize",
+ type: "number",
+ default: "68",
+ description: "Cap height of the resting word in composition pixels",
+ },
+ {
+ name: "fontFamily",
+ type: "string",
+ default: '"Arial, Helvetica, sans-serif"',
+ description: "Canvas font-family used to rasterize the glyph atlas",
+ },
+ {
+ name: "fontWeight",
+ type: "number",
+ default: "400",
+ description: "Font weight used for every word",
+ },
+ {
+ name: "verticalStretch",
+ type: "number",
+ default: "7",
+ description: "Authored peak vertical scale before perspective",
+ },
+ {
+ name: "chromaticSpread",
+ type: "number",
+ default: "1",
+ description: "Distance between the three motion-shutter lengths",
+ },
+ {
+ name: "restDuration",
+ type: "number",
+ default: "12",
+ description: "Readable resting phase in frames",
+ },
+ {
+ name: "peakHoldDuration",
+ type: "number",
+ default: "3",
+ description: "Total near-point hang around each word swap in frames",
+ },
+ {
+ name: "speed",
+ type: "number",
+ default: "1",
+ description: "Global playback multiplier",
+ },
+ {
+ name: "className",
+ type: "string",
+ default: "—",
+ description: "Optional class name applied to the full-frame root",
+ },
+ ]}
+/>
+
+## Notes
+
+The blur is vertical-only and sweeps scale rather than position. Bloom, CRT
+modulation, the neutral ground, stroke thinning, and swap separation are all
+driven by motion progress and become exactly zero during the resting phase.
+The component uses deterministic frame time only: it has no timers, animation
+frames, pointer state, scroll state, random samples, or device-dependent quality
+switches.
diff --git a/docs/plans/2026-08-30-rush-type-design.md b/docs/plans/2026-08-30-rush-type-design.md
new file mode 100644
index 00000000..8e120631
--- /dev/null
+++ b/docs/plans/2026-08-30-rush-type-design.md
@@ -0,0 +1,83 @@
+# Rush Type
+
+## Reference
+
+Adapt the supplied `rush-type` WebGL study into a standalone, deterministic
+Remotion registry component. A lowercase word rests long enough to read on a
+flat black frame, then grows rapidly through a vertical orbit. Motion spreads
+the same white glyph into differently shuttered red, green, and blue channels
+before the next word resolves from the blur.
+
+The defining invariant is that every motion-dependent term is exactly zero at
+rest. A resting frame contains a pixel-sharp white word on black with coincident
+RGB channels. There is no authored color tint, chromatic-aberration pass,
+feedback buffer, horizontal blur, or crossfade to a separate white state.
+
+## Rendering
+
+`RushType` owns a full-frame WebGL canvas. The glyph atlas contains the current
+and next words. Each output channel samples the same monochrome texture over a
+different shutter length and divides by its accumulated sample weight. Green
+uses the longest shutter, red an intermediate shutter, and blue the shortest,
+producing color only while the scale changes.
+
+The shader sweeps vertical scale rather than position. It fits a quadratic
+through the shutter start, current instant, and shutter end so the blur remains
+defined around the near-point turn. Perspective, yaw, and limited pitch are
+evaluated once per output frame; rotation is not swept through the shutter, so
+vertical stems remain crisp. Bloom, CRT modulation, rolling shutter, along-word
+lag, swap separation, and the neutral ground are all multiplied by motion
+progress and therefore vanish exactly at rest.
+
+The supplied implementation's `GLOW_BASE = 0.03` contradicts the flat-black
+rest invariant. The Remotion adaptation removes that base contribution and
+gates the ground entirely on motion progress.
+
+## Timeline
+
+All state is a pure function of `useCurrentFrame()`, `fps`, component props, and
+the phrase. There are no animation frames, timers, wall clocks, scroll values,
+pointer state, visibility observers, device-dependent sample counts, or random
+draws. Rendering any frame directly must produce the same pixels as rendering
+the full sequence up to that frame.
+
+Each word cycle contains a short near-point hang, an arrival from the blast, a
+long readable rest, and a fast departure back toward the camera. The word swap
+occurs at the cycle boundary inside the near-point shutter. Incoming and
+outgoing samples receive opposite scale separation only while that shutter
+contains the swap, preventing a legible double exposure.
+
+## Component
+
+The registry item is named `rush-type` and exports `RushType`,
+`RushTypeProps`, timeline helpers, and a natural-length helper. The primary
+controls are:
+
+- `phrase`: whitespace-delimited words;
+- `fontSize`: resting glyph size;
+- `fontWeight`: 400, 500, 600, or 700;
+- `verticalStretch`: authored peak vertical scale before perspective;
+- `chromaticSpread`: separation between the three shutter lengths;
+- `restDuration`: readable rest in frames;
+- `peakHoldDuration`: near-point hang in frames;
+- `speed`: the shared remocn playback multiplier.
+
+The React API also accepts `fontFamily` and `className`. Technical shader
+constants stay internal until a demonstrated use case warrants expanding the
+public surface. Text and channel colors are intentionally not configurable.
+
+## Integration
+
+Add the component and customizer config, register it in the preview index and
+remocn registry, add its typography documentation and example, then regenerate
+the preview manifest and registry artifacts. The component is full-frame and
+does not declare element dimensions.
+
+## Verification
+
+Unit-test phrase normalization, cycle timing, word selection, shutter ratios,
+swap-window behavior, and the exact rest pose. Add a pixel-level or shader-state
+assertion proving that every effect strength is zero during rest and that the
+three channel scales coincide. Run focused Biome checks, TypeScript, the test
+suite, registry and manifest builds, and render representative rest, departure,
+peak-swap, and arrival frames for visual inspection.
diff --git a/registry-artifacts/elements/rush-type.json b/registry-artifacts/elements/rush-type.json
new file mode 100644
index 00000000..08940863
--- /dev/null
+++ b/registry-artifacts/elements/rush-type.json
@@ -0,0 +1,14 @@
+{
+ "type": "remotion-element",
+ "version": 1,
+ "element": {
+ "dependencies": [],
+ "dimensions": null,
+ "displayName": "Rush Type",
+ "durationInFrames": 104,
+ "installationMode": "component-owned-sequence",
+ "slug": "rush-type",
+ "sourceCode": "import { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState, type ComponentProps } from \"react\";\nimport { Interactive, Sequence, continueRender, delayRender, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ninterface RushTypeProps {\n /** A short phrase. One whitespace-delimited word is shown per cycle. */\n phrase?: string;\n /** Cap height of the resting word in composition pixels. */\n fontSize?: number;\n fontFamily?: string;\n fontWeight?: number;\n /** Authored vertical scale at the blast before perspective is applied. */\n verticalStretch?: number;\n /** 0 removes channel separation, 1 is the reference look, 2 exaggerates it. */\n chromaticSpread?: number;\n /** Readable resting phase, in frames. */\n restDuration?: number;\n /** Total near-point hang around the word swap, in frames. */\n peakHoldDuration?: number;\n /** Global playback multiplier. */\n speed?: number;\n className?: string;\n}\n\ntype RushTypePhase = \"hang\" | \"arrive\" | \"rest\" | \"depart\";\n\ninterface RushTypeFrameState {\n phase: RushTypePhase;\n wordIndex: number;\n beforeWordIndex: number;\n afterWordIndex: number;\n cycle: number;\n motion: number;\n isResting: boolean;\n swapAmount: number;\n shutterRatios: [number, number, number];\n thinAmount: number;\n bloomAmount: number;\n crtAmount: number;\n groundAmount: number;\n}\n\nconst rushTypeDefaultPhrase = \"gone before you look\";\n\nconst ARRIVE_FRAMES = 7;\nconst LEAVE_FRAMES = 4;\nconst DEFAULT_REST_FRAMES = 12;\nconst DEFAULT_HOLD_FRAMES = 3;\nconst SHUTTER_SECONDS = 0.04;\nconst SMEAR_GAIN = 1.6;\nconst SAMPLES = 28;\nconst SHUTTER_SHAPE = 0.85;\nconst ROLL_U = 0.38;\nconst LAG_U = 0.55;\nconst THIN = 0.55;\nconst BLOOM_GAIN = 0.5;\nconst BLOOM_SPREAD = 3.2;\nconst BLOOM_BIAS = 3.5;\nconst SPEED_GAIN = 0.95;\nconst EXPOSURE = 1.75;\nconst HORIZONTAL_STRETCH = 1.57;\nconst FOCAL = 1;\nconst ORBIT_DEPTH = 0.42;\nconst ORBIT_RISE = 0.16;\nconst ORBIT_YAW = 0.55;\nconst ORBIT_YAW_LAG = 0.6;\nconst ORBIT_PITCH = 0.26;\nconst ORBIT_PITCH_LAG = -0.9;\nconst ORBIT_HANG_ARC = 0.9;\nconst PIVOT_FRAC = 0.07;\nconst CRT_GAIN = 1;\nconst CRT_PITCH = 5;\nconst CRT_MASK = 0.16;\nconst CRT_SCAN_PITCH = 3;\nconst CRT_SCAN = 0.12;\nconst CRT_BEAM = 0.7;\nconst CRT_HUM = 0.035;\nconst CRT_HUM_SPEED = 0.14;\nconst GROUND_SPEED = 0.028;\nconst GLOW_SPREAD = 2.6;\nconst GLOW_MIN = 0.34;\nconst GLOW_MAX_Y = 1.2;\nconst SWAP_SPREAD = 0.35;\nconst SWAP_FLASH = 0.5;\n\nconst FALL = [1, 0.557, 0.121, 0.049, 0.014, 0];\nconst RISE = [0, 0.08, 0.8, 1];\nconst ORBIT_IN = [0, 0.5, 0.82, 0.95, 1, 1];\nconst ORBIT_OUT = [0, 0.05, 0.14, 0.38, 1];\nconst DRIFT_DIRECTION = [-1, 0.7, -0.45, 1];\nconst SWING_ARC = Math.PI - ORBIT_HANG_ARC;\n\nfunction positiveModulo(value: number, modulus: number): number {\n return ((value % modulus) + modulus) % modulus;\n}\n\nfunction sampleTable(table: readonly number[], progress: number): number {\n const last = table.length - 1;\n const x = Math.min(Math.max(progress, 0), 1) * last;\n const index = Math.min(Math.floor(x), last - 1);\n return table[index] + (table[index + 1] - table[index]) * (x - index);\n}\n\nfunction normalizeRushTypePhrase(phrase: string): string[] {\n const words = phrase.trim().split(/\\s+/).filter(Boolean);\n return words.length > 0 ? words : rushTypeDefaultPhrase.split(\" \");\n}\n\nfunction getRushTypeCycleLength(\n restDuration = DEFAULT_REST_FRAMES,\n peakHoldDuration = DEFAULT_HOLD_FRAMES,\n): number {\n return (\n ARRIVE_FRAMES +\n LEAVE_FRAMES +\n Math.max(restDuration, 1) +\n Math.max(peakHoldDuration, 0)\n );\n}\n\nfunction getRushTypeDuration({\n phrase = rushTypeDefaultPhrase,\n restDuration = DEFAULT_REST_FRAMES,\n peakHoldDuration = DEFAULT_HOLD_FRAMES,\n}: Pick<\n RushTypeProps,\n \"phrase\" | \"restDuration\" | \"peakHoldDuration\"\n> = {}): number {\n return Math.round(\n normalizeRushTypePhrase(phrase).length *\n getRushTypeCycleLength(restDuration, peakHoldDuration),\n );\n}\n\nconst rushTypeLength = getRushTypeDuration();\n\nfunction getRushTypeShutterRatios(\n chromaticSpread = 1,\n): [number, number, number] {\n const spread = Math.max(chromaticSpread, 0);\n return [0.62 ** spread, 1, 0.34 ** spread];\n}\n\ninterface TimelinePose {\n phase: RushTypePhase;\n p: number;\n psi: number;\n cycle: number;\n wordIndex: number;\n}\n\ninterface TimelineOptions {\n wordCount: number;\n restDuration: number;\n peakHoldDuration: number;\n}\n\nfunction getTimelinePose(\n frame: number,\n { wordCount, restDuration, peakHoldDuration }: TimelineOptions,\n): TimelinePose {\n const safeWordCount = Math.max(Math.floor(wordCount), 1);\n const safeRest = Math.max(restDuration, 1);\n const safeHold = Math.max(peakHoldDuration, 0);\n const halfHold = safeHold / 2;\n const cycleLength = getRushTypeCycleLength(safeRest, safeHold);\n const arriveEnd = halfHold + ARRIVE_FRAMES;\n const restEnd = arriveEnd + safeRest;\n const leaveEnd = restEnd + LEAVE_FRAMES;\n const startOffset = arriveEnd + safeRest / 2;\n const shifted = frame + startOffset;\n const cycle = Math.floor(shifted / cycleLength);\n const tau = positiveModulo(shifted, cycleLength);\n const wordIndex = positiveModulo(cycle, safeWordCount);\n\n if (tau < halfHold) {\n return {\n phase: \"hang\",\n p: 1,\n psi: ORBIT_HANG_ARC * (tau / Math.max(halfHold, 1e-6)),\n cycle,\n wordIndex,\n };\n }\n\n if (tau < arriveEnd) {\n const progress = (tau - halfHold) / ARRIVE_FRAMES;\n return {\n phase: \"arrive\",\n p: sampleTable(FALL, progress),\n psi: ORBIT_HANG_ARC + SWING_ARC * sampleTable(ORBIT_IN, progress),\n cycle,\n wordIndex,\n };\n }\n\n if (tau < restEnd) {\n return { phase: \"rest\", p: 0, psi: Math.PI, cycle, wordIndex };\n }\n\n if (tau < leaveEnd) {\n const progress = (tau - restEnd) / LEAVE_FRAMES;\n return {\n phase: \"depart\",\n p: sampleTable(RISE, progress),\n psi: Math.PI + SWING_ARC * sampleTable(ORBIT_OUT, progress),\n cycle,\n wordIndex,\n };\n }\n\n const progress = (tau - leaveEnd) / Math.max(halfHold, 1e-6);\n return {\n phase: \"hang\",\n p: 1,\n psi: 2 * Math.PI - ORBIT_HANG_ARC * (1 - progress),\n cycle,\n wordIndex,\n };\n}\n\ninterface ComputedFrame {\n before: TimelinePose;\n here: TimelinePose;\n after: TimelinePose;\n swapU: number;\n swapAmount: number;\n shutterRatios: [number, number, number];\n}\n\nfunction computeFrame({\n frame,\n fps,\n wordCount,\n restDuration,\n peakHoldDuration,\n chromaticSpread,\n}: {\n frame: number;\n fps: number;\n wordCount: number;\n restDuration: number;\n peakHoldDuration: number;\n chromaticSpread: number;\n}): ComputedFrame {\n const shutterFrames = SHUTTER_SECONDS * Math.max(fps, 1);\n const halfShutter = shutterFrames / 2;\n const options = { wordCount, restDuration, peakHoldDuration };\n const before = getTimelinePose(frame - halfShutter, options);\n const here = getTimelinePose(frame, options);\n const after = getTimelinePose(frame + halfShutter, options);\n const cycleLength = getRushTypeCycleLength(restDuration, peakHoldDuration);\n const halfHold = Math.max(peakHoldDuration, 0) / 2;\n const arriveEnd = halfHold + ARRIVE_FRAMES;\n const startOffset = arriveEnd + Math.max(restDuration, 1) / 2;\n const shifted = frame + startOffset;\n const nearestBoundary = Math.round(shifted / cycleLength) * cycleLength;\n const boundaryDistance = shifted - nearestBoundary;\n const crossesSwap = wordCount > 1 && after.cycle > before.cycle;\n const swapU = crossesSwap\n ? (after.cycle * cycleLength - shifted) / shutterFrames\n : 2;\n const swapAmount =\n wordCount > 1\n ? Math.max(0, 1 - (2 * boundaryDistance) ** 2 / shutterFrames ** 2)\n : 0;\n\n return {\n before,\n here,\n after,\n swapU,\n swapAmount,\n shutterRatios: getRushTypeShutterRatios(chromaticSpread),\n };\n}\n\nfunction getRushTypeFrameState({\n frame,\n fps = 30,\n phrase = rushTypeDefaultPhrase,\n restDuration = DEFAULT_REST_FRAMES,\n peakHoldDuration = DEFAULT_HOLD_FRAMES,\n chromaticSpread = 1,\n speed = 1,\n}: {\n frame: number;\n fps?: number;\n} & Pick<\n RushTypeProps,\n \"phrase\" | \"restDuration\" | \"peakHoldDuration\" | \"chromaticSpread\" | \"speed\"\n>): RushTypeFrameState {\n const words = normalizeRushTypePhrase(phrase);\n const computed = computeFrame({\n frame: frame * Math.max(speed, 0),\n fps,\n wordCount: words.length,\n restDuration,\n peakHoldDuration,\n chromaticSpread,\n });\n const motion = computed.here.p;\n\n return {\n phase: computed.here.phase,\n wordIndex: computed.here.wordIndex,\n beforeWordIndex: computed.before.wordIndex,\n afterWordIndex: computed.after.wordIndex,\n cycle: computed.here.cycle,\n motion,\n isResting:\n computed.here.phase === \"rest\" &&\n computed.before.p === 0 &&\n computed.after.p === 0,\n swapAmount: computed.swapAmount,\n shutterRatios: computed.shutterRatios,\n thinAmount: THIN * motion,\n bloomAmount: BLOOM_GAIN * motion,\n crtAmount: CRT_GAIN * motion,\n groundAmount: GROUND_SPEED * motion,\n };\n}\n\nfunction orbitTurn(psi: number, amplitude: number, lag: number): number {\n const pin = Math.sin(lag);\n return (amplitude * (Math.sin(psi - lag) - pin)) / (1 + Math.abs(pin));\n}\n\nconst VERTEX_SHADER = `\nattribute vec2 aPos;\nvarying vec2 vUv;\nvoid main() {\n vUv = aPos * 0.5 + 0.5;\n gl_Position = vec4(aPos, 0.0, 1.0);\n}\n`;\n\nconst FRAGMENT_SHADER = `\nprecision highp float;\nvarying vec2 vUv;\n\nuniform sampler2D uText;\nuniform vec2 uRes;\nuniform vec2 uHalfPx;\nuniform float uSx;\nuniform vec3 uSyQ;\nuniform float uCenterY;\nuniform float uSwapU;\nuniform float uHalfA;\nuniform float uHalfB;\nuniform vec3 uK;\nuniform vec2 uSwapScl;\nuniform float uShape;\nuniform float uRoll;\nuniform float uLag;\nuniform float uThin;\nuniform float uBloom;\nuniform float uGain;\nuniform float uExp;\nuniform float uFocal;\nuniform vec3 uPos;\nuniform vec4 uRot;\nuniform float uCrt;\nuniform float uTime;\nuniform vec4 uGlow;\nuniform float uGlowAmp;\n\n#define SAMPLES ${SAMPLES}\n#define BLOOM_TAPS 4\n#define BLOOM_SPREAD ${BLOOM_SPREAD.toFixed(3)}\n#define BLOOM_BIAS ${BLOOM_BIAS.toFixed(3)}\n#define TAU 6.2831853\n#define CRT_PITCH ${CRT_PITCH.toFixed(3)}\n#define CRT_MASK ${CRT_MASK.toFixed(4)}\n#define CRT_SCAN_PITCH ${CRT_SCAN_PITCH.toFixed(3)}\n#define CRT_SCAN ${CRT_SCAN.toFixed(4)}\n#define CRT_BEAM ${CRT_BEAM.toFixed(4)}\n#define CRT_HUM ${CRT_HUM.toFixed(4)}\n#define CRT_HUM_SPEED ${CRT_HUM_SPEED.toFixed(4)}\n\nvec2 atlasUv(float sy, float halfIdx, vec2 wordPoint, out float inside) {\n float sx = max(uSx, 1e-4);\n float sv = max(abs(sy), 1e-4);\n vec2 q = vec2(\n (wordPoint.x / sx + uHalfPx.x * 0.5) / uHalfPx.x,\n (wordPoint.y / sv + uHalfPx.y * 0.5) / uHalfPx.y\n );\n inside = step(0.0, q.x) * step(q.x, 1.0) * step(0.0, q.y) * step(q.y, 1.0);\n return vec2(\n clamp(q.x, 0.0, 1.0),\n (clamp(q.y, 0.0, 1.0) + halfIdx) * 0.5\n );\n}\n\nfloat tap(float sy, float halfIdx, vec2 wordPoint, float front) {\n float inside;\n vec2 texturePoint = atlasUv(sy, halfIdx, wordPoint, inside);\n float value = texture2D(uText, texturePoint).r * inside * front;\n return value * mix(1.0, value, uThin);\n}\n\nfloat tapBlur(float sy, float halfIdx, vec2 wordPoint, float front) {\n float inside;\n vec2 texturePoint = atlasUv(sy, halfIdx, wordPoint, inside);\n return texture2D(uText, texturePoint, BLOOM_BIAS).r * inside * front;\n}\n\nvoid main() {\n vec2 pixel = vUv * uRes;\n vec2 center = vec2(uRes.x * 0.5, uRes.y * uCenterY);\n vec2 screenPoint = pixel - center;\n\n float sinYaw = uRot.x;\n float cosYaw = uRot.y;\n float sinPitch = uRot.z;\n float cosPitch = uRot.w;\n float a1 = -(screenPoint.x * sinYaw + uFocal * cosYaw);\n float b1 = sinPitch * (screenPoint.x * cosYaw - uFocal * sinYaw);\n float c1 = uFocal * uPos.x - screenPoint.x * uPos.z;\n float a2 = -screenPoint.y * sinYaw;\n float b2 = screenPoint.y * sinPitch * cosYaw - uFocal * cosPitch;\n float c2 = uFocal * uPos.y - screenPoint.y * uPos.z;\n float determinant = a1 * b2 - a2 * b1;\n float inverse = 1.0 / (abs(determinant) < 1e-4 ? 1e-4 : determinant);\n float a = (c1 * b2 - c2 * b1) * inverse;\n float b = (a1 * c2 - a2 * c1) * inverse;\n float cameraZ = uPos.z - a * sinYaw + b * sinPitch * cosYaw;\n vec2 wordPoint = vec2(a, b);\n float front = step(uFocal * 0.05, cameraZ);\n vec3 accumulated = vec3(0.0);\n\n if (abs(uSyQ.y) + abs(uSyQ.z) < 1e-5) {\n accumulated = vec3(tap(uSyQ.x, uHalfA, wordPoint, front));\n } else {\n float offset =\n uLag * (wordPoint.x / uRes.x) - uRoll * (screenPoint.y / uRes.y);\n float weightSum = 0.0;\n\n for (int i = 0; i < SAMPLES; i++) {\n float u = float(i) / float(SAMPLES - 1) - 0.5;\n float weight = 1.0 - uShape * abs(u) * 2.0;\n weightSum += weight;\n float shiftedU = u + offset;\n vec3 shutterU = shiftedU * uK;\n vec3 sy = uSyQ.x + uSyQ.y * shutterU + uSyQ.z * shutterU * shutterU;\n accumulated.r += weight * tap(\n sy.r * (shutterU.r < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.r < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n accumulated.g += weight * tap(\n sy.g * (shutterU.g < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.g < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n accumulated.b += weight * tap(\n sy.b * (shutterU.b < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.b < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n }\n\n accumulated /= max(weightSum, 1e-4);\n\n vec3 halo = vec3(0.0);\n for (int j = 0; j < BLOOM_TAPS; j++) {\n float u =\n (float(j) / float(BLOOM_TAPS - 1) - 0.5) * BLOOM_SPREAD + offset;\n vec3 shutterU = u * uK;\n vec3 sy = uSyQ.x + uSyQ.y * shutterU + uSyQ.z * shutterU * shutterU;\n halo.r += tapBlur(\n sy.r * (shutterU.r < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.r < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n halo.g += tapBlur(\n sy.g * (shutterU.g < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.g < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n halo.b += tapBlur(\n sy.b * (shutterU.b < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.b < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n }\n accumulated += halo * (uBloom / float(BLOOM_TAPS));\n accumulated *= uGain;\n }\n\n accumulated =\n (1.0 - exp(-accumulated * uExp)) / (1.0 - exp(-uExp));\n\n vec2 glowDistance =\n (pixel - uGlow.xy) / max(uGlow.zw, vec2(1.0));\n float ground =\n uGlowAmp * (1.0 - smoothstep(0.0, 1.0, length(glowDistance)));\n accumulated += ground * (1.0 - accumulated);\n\n if (uCrt > 0.0) {\n float luminance = max(max(accumulated.r, accumulated.g), accumulated.b);\n vec3 maskWave = 0.5 + 0.5 * cos(\n TAU * (pixel.x / CRT_PITCH - vec3(0.0, 0.33333, 0.66667))\n );\n vec3 mask = mix(vec3(1.0), maskWave * 2.0, CRT_MASK * uCrt);\n float scanWave = 0.5 + 0.5 * cos(TAU * pixel.y / CRT_SCAN_PITCH);\n float scan =\n 1.0 - CRT_SCAN * uCrt * (1.0 - CRT_BEAM * luminance) * (1.0 - scanWave);\n float bar = 0.5 + 0.5 * cos(\n TAU * (pixel.y / uRes.y - uTime * CRT_HUM_SPEED)\n );\n float hum = 1.0 + CRT_HUM * uCrt * (bar * 2.0 - 1.0);\n accumulated *= mask * scan * hum;\n }\n\n gl_FragColor = vec4(accumulated, 1.0);\n}\n`;\n\nconst UNIFORM_NAMES = [\n \"uText\",\n \"uRes\",\n \"uHalfPx\",\n \"uSx\",\n \"uSyQ\",\n \"uCenterY\",\n \"uSwapU\",\n \"uHalfA\",\n \"uHalfB\",\n \"uK\",\n \"uSwapScl\",\n \"uShape\",\n \"uRoll\",\n \"uLag\",\n \"uThin\",\n \"uBloom\",\n \"uGain\",\n \"uExp\",\n \"uFocal\",\n \"uPos\",\n \"uRot\",\n \"uCrt\",\n \"uTime\",\n \"uGlow\",\n \"uGlowAmp\",\n] as const;\n\ninterface GlState {\n gl: WebGLRenderingContext;\n program: WebGLProgram;\n buffer: WebGLBuffer;\n texture: WebGLTexture;\n uniforms: Record<(typeof UNIFORM_NAMES)[number], WebGLUniformLocation | null>;\n atlasWidth: number;\n halfHeight: number;\n textureCapHeight: number;\n scratch: HTMLCanvasElement;\n pairKey: string;\n wordHalfWidth: number;\n}\n\nfunction compileShader(\n gl: WebGLRenderingContext,\n type: number,\n source: string,\n): WebGLShader {\n const shader = gl.createShader(type);\n if (!shader) throw new Error(\"RushTypeBase could not create a WebGL shader\");\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const message = gl.getShaderInfoLog(shader) ?? \"Unknown shader error\";\n gl.deleteShader(shader);\n throw new Error(`RushTypeBase shader compilation failed: ${message}`);\n }\n return shader;\n}\n\nfunction createGlState(canvas: HTMLCanvasElement): GlState | null {\n const gl = canvas.getContext(\"webgl\", {\n alpha: false,\n antialias: false,\n depth: false,\n stencil: false,\n preserveDrawingBuffer: true,\n powerPreference: \"high-performance\",\n });\n if (!gl) return null;\n\n const vertex = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);\n const fragment = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);\n const program = gl.createProgram();\n if (!program) throw new Error(\"RushTypeBase could not create a WebGL program\");\n gl.attachShader(program, vertex);\n gl.attachShader(program, fragment);\n gl.bindAttribLocation(program, 0, \"aPos\");\n gl.linkProgram(program);\n gl.deleteShader(vertex);\n gl.deleteShader(fragment);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n const message = gl.getProgramInfoLog(program) ?? \"Unknown link error\";\n gl.deleteProgram(program);\n throw new Error(`RushTypeBase shader linking failed: ${message}`);\n }\n\n const buffer = gl.createBuffer();\n const texture = gl.createTexture();\n if (!buffer || !texture) {\n throw new Error(\"RushTypeBase could not allocate WebGL resources\");\n }\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n gl.bufferData(\n gl.ARRAY_BUFFER,\n new Float32Array([-1, -1, 3, -1, -1, 3]),\n gl.STATIC_DRAW,\n );\n\n const atlasWidth = canvas.width >= 1800 ? 4096 : 2048;\n const halfHeight = atlasWidth / 4;\n const textureCapHeight = Math.round(halfHeight * 0.64);\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texImage2D(\n gl.TEXTURE_2D,\n 0,\n gl.RGBA,\n atlasWidth,\n halfHeight * 2,\n 0,\n gl.RGBA,\n gl.UNSIGNED_BYTE,\n null,\n );\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texParameteri(\n gl.TEXTURE_2D,\n gl.TEXTURE_MIN_FILTER,\n gl.LINEAR_MIPMAP_LINEAR,\n );\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n\n const scratch = document.createElement(\"canvas\");\n scratch.width = atlasWidth;\n scratch.height = halfHeight;\n const uniforms = Object.fromEntries(\n UNIFORM_NAMES.map((name) => [name, gl.getUniformLocation(program, name)]),\n ) as GlState[\"uniforms\"];\n gl.clearColor(0, 0, 0, 1);\n\n return {\n gl,\n program,\n buffer,\n texture,\n uniforms,\n atlasWidth,\n halfHeight,\n textureCapHeight,\n scratch,\n pairKey: \"\",\n wordHalfWidth: 1,\n };\n}\n\nfunction resolveFontFamily(fontFamily: string): string {\n if (typeof document === \"undefined\") return fontFamily;\n const probe = document.createElement(\"span\");\n probe.style.cssText =\n \"position:absolute;visibility:hidden;pointer-events:none\";\n probe.style.fontFamily = fontFamily;\n probe.textContent = \"Ag\";\n document.body.appendChild(probe);\n const resolved = getComputedStyle(probe).fontFamily;\n probe.remove();\n return resolved || fontFamily;\n}\n\nfunction rasterWord(\n state: GlState,\n word: string,\n half: 0 | 1,\n fontFamily: string,\n fontWeight: number,\n): number {\n const context = state.scratch.getContext(\"2d\");\n if (!context) return 1;\n context.fillStyle = \"#000\";\n context.fillRect(0, 0, state.atlasWidth, state.halfHeight);\n\n let rasterSize = state.textureCapHeight * 1.4;\n context.font = `${fontWeight} ${rasterSize}px ${fontFamily}`;\n const capHeight =\n context.measureText(\"H\").actualBoundingBoxAscent || rasterSize * 0.72;\n rasterSize *= state.textureCapHeight / capHeight;\n context.font = `${fontWeight} ${rasterSize}px ${fontFamily}`;\n\n const maxWidth = state.atlasWidth * 0.92;\n const measured = context.measureText(word).width;\n if (measured > maxWidth) {\n rasterSize *= maxWidth / measured;\n context.font = `${fontWeight} ${rasterSize}px ${fontFamily}`;\n }\n\n context.fillStyle = \"#fff\";\n context.textAlign = \"center\";\n context.textBaseline = \"alphabetic\";\n context.fillText(\n word,\n state.atlasWidth / 2,\n state.halfHeight / 2 + state.textureCapHeight / 2,\n );\n const halfWidth = context.measureText(word).width / 2;\n\n const { gl } = state;\n gl.bindTexture(gl.TEXTURE_2D, state.texture);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\n gl.texSubImage2D(\n gl.TEXTURE_2D,\n 0,\n 0,\n half * state.halfHeight,\n gl.RGBA,\n gl.UNSIGNED_BYTE,\n state.scratch,\n );\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n return halfWidth;\n}\n\nfunction updateAtlas(\n state: GlState,\n firstWord: string,\n secondWord: string,\n fontFamily: string,\n fontWeight: number,\n): void {\n const pairKey = `${fontFamily}\\u0000${fontWeight}\\u0000${firstWord}\\u0000${secondWord}`;\n if (state.pairKey === pairKey) return;\n const firstWidth = rasterWord(state, firstWord, 0, fontFamily, fontWeight);\n const secondWidth = rasterWord(state, secondWord, 1, fontFamily, fontWeight);\n state.gl.generateMipmap(state.gl.TEXTURE_2D);\n state.pairKey = pairKey;\n state.wordHalfWidth = Math.max(firstWidth, secondWidth);\n}\n\nfunction destroyGlState(state: GlState): void {\n const { gl } = state;\n gl.deleteProgram(state.program);\n gl.deleteBuffer(state.buffer);\n gl.deleteTexture(state.texture);\n}\n\nfunction drawRushType({\n state,\n computed,\n words,\n fontSize,\n fontFamily,\n fontWeight,\n verticalStretch,\n frame,\n fps,\n}: {\n state: GlState;\n computed: ComputedFrame;\n words: string[];\n fontSize: number;\n fontFamily: string;\n fontWeight: number;\n verticalStretch: number;\n frame: number;\n fps: number;\n}): void {\n const { gl, uniforms } = state;\n const beforeWord = words[computed.before.wordIndex] ?? words[0];\n const afterWord = words[computed.after.wordIndex] ?? words[0];\n updateAtlas(state, beforeWord, afterWord, fontFamily, fontWeight);\n\n const unit = Math.max(fontSize, 1) / state.textureCapHeight;\n const scaleY = (pose: TimelinePose) =>\n unit * (1 + pose.p * (Math.max(verticalStretch, 1) - 1));\n const scaleBefore = scaleY(computed.before);\n const scaleCurrent = scaleY(computed.here);\n const scaleAfter = scaleY(computed.after);\n const quadraticA = scaleCurrent;\n const quadraticC = 2 * (scaleAfter + scaleBefore - 2 * scaleCurrent);\n const tangent = scaleAfter - scaleBefore;\n const peakSmear = SMEAR_GAIN * computed.here.p * scaleCurrent;\n const magnitude = Math.sqrt(tangent * tangent + peakSmear * peakSmear);\n const quadraticB = tangent < 0 ? -magnitude : magnitude;\n const scaleX = unit * (1 + computed.here.p * (HORIZONTAL_STRETCH - 1));\n\n const direction =\n DRIFT_DIRECTION[\n positiveModulo(computed.here.cycle, DRIFT_DIRECTION.length)\n ] ?? 1;\n const psi = computed.here.psi * Math.sign(direction || 1);\n const orbitAmplitude = Math.abs(direction);\n const focal =\n state.scratch.height > 0 ? state.gl.drawingBufferHeight * FOCAL : 1;\n const z = focal * (1 - ORBIT_DEPTH * (1 + Math.cos(psi)) * 0.5);\n const x = 0;\n const y = focal * ORBIT_RISE * orbitAmplitude * Math.sin(psi);\n const yaw = orbitTurn(psi, ORBIT_YAW, ORBIT_YAW_LAG);\n const pitch = orbitTurn(psi, ORBIT_PITCH, ORBIT_PITCH_LAG);\n const pivot = PIVOT_FRAC * computed.here.p;\n const perspective = focal / z;\n const glowX = gl.drawingBufferWidth / 2 + (focal * x) / z;\n const glowY = gl.drawingBufferHeight * (0.5 + pivot) + (focal * y) / z;\n const wordWidth = state.wordHalfWidth * scaleX * perspective;\n const wordHeight = state.textureCapHeight * scaleCurrent * perspective;\n\n gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);\n // biome-ignore lint/correctness/useHookAtTopLevel: gl.useProgram is a WebGL method, not a React hook\n gl.useProgram(state.program);\n gl.bindBuffer(gl.ARRAY_BUFFER, state.buffer);\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(gl.TEXTURE_2D, state.texture);\n gl.uniform1i(uniforms.uText, 0);\n gl.uniform2f(uniforms.uRes, gl.drawingBufferWidth, gl.drawingBufferHeight);\n gl.uniform2f(uniforms.uHalfPx, state.atlasWidth, state.halfHeight);\n gl.uniform1f(uniforms.uSx, scaleX);\n gl.uniform3f(uniforms.uSyQ, quadraticA, quadraticB, quadraticC);\n gl.uniform1f(uniforms.uCenterY, 0.5 + pivot);\n gl.uniform1f(uniforms.uSwapU, computed.swapU);\n gl.uniform1f(uniforms.uHalfA, 0);\n gl.uniform1f(uniforms.uHalfB, 1);\n gl.uniform3f(\n uniforms.uK,\n computed.shutterRatios[0],\n computed.shutterRatios[1],\n computed.shutterRatios[2],\n );\n gl.uniform2f(\n uniforms.uSwapScl,\n 1 + SWAP_SPREAD * computed.swapAmount,\n 1 - SWAP_SPREAD * computed.swapAmount,\n );\n gl.uniform1f(uniforms.uShape, SHUTTER_SHAPE);\n gl.uniform1f(uniforms.uRoll, ROLL_U);\n gl.uniform1f(uniforms.uLag, LAG_U);\n gl.uniform1f(uniforms.uThin, THIN * computed.here.p);\n gl.uniform1f(uniforms.uBloom, BLOOM_GAIN * computed.here.p);\n gl.uniform1f(\n uniforms.uGain,\n (1 + SPEED_GAIN * computed.here.p) * (1 + SWAP_FLASH * computed.swapAmount),\n );\n gl.uniform1f(uniforms.uExp, EXPOSURE);\n gl.uniform1f(uniforms.uFocal, focal);\n gl.uniform3f(uniforms.uPos, x, y, z);\n gl.uniform4f(\n uniforms.uRot,\n Math.sin(yaw),\n Math.cos(yaw),\n Math.sin(pitch),\n Math.cos(pitch),\n );\n gl.uniform1f(uniforms.uCrt, CRT_GAIN * computed.here.p);\n gl.uniform1f(uniforms.uTime, frame / Math.max(fps, 1));\n gl.uniform4f(\n uniforms.uGlow,\n glowX,\n glowY,\n Math.max(wordWidth * GLOW_SPREAD, gl.drawingBufferWidth * GLOW_MIN),\n Math.min(\n Math.max(wordHeight * GLOW_SPREAD, gl.drawingBufferHeight * GLOW_MIN),\n gl.drawingBufferHeight * GLOW_MAX_Y,\n ),\n );\n gl.uniform1f(uniforms.uGlowAmp, GROUND_SPEED * computed.here.p);\n gl.clear(gl.COLOR_BUFFER_BIT);\n gl.drawArrays(gl.TRIANGLES, 0, 3);\n}\n\nfunction RushTypeBase({\n phrase = rushTypeDefaultPhrase,\n fontSize = 68,\n fontFamily = \"Arial, Helvetica, sans-serif\",\n fontWeight = 400,\n verticalStretch = 7,\n chromaticSpread = 1,\n restDuration = DEFAULT_REST_FRAMES,\n peakHoldDuration = DEFAULT_HOLD_FRAMES,\n speed = 1,\n className,\n}: RushTypeProps) {\n const frame = useCurrentFrame();\n const { fps, width, height } = useVideoConfig();\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const stateRef = useRef<GlState | null>(null);\n const [fontReady, setFontReady] = useState(false);\n const [webGlFailed, setWebGlFailed] = useState(false);\n const [renderHandle] = useState(() => delayRender(\"rush-type: first frame\"));\n const continuedRef = useRef(false);\n const words = normalizeRushTypePhrase(phrase);\n const effectiveFrame = frame * Math.max(speed, 0);\n const computed = computeFrame({\n frame: effectiveFrame,\n fps,\n wordCount: words.length,\n restDuration,\n peakHoldDuration,\n chromaticSpread,\n });\n\n useEffect(() => {\n let cancelled = false;\n setFontReady(false);\n const ready = () => {\n if (!cancelled) setFontReady(true);\n };\n if (typeof document === \"undefined\" || !document.fonts) {\n ready();\n return () => {\n cancelled = true;\n };\n }\n document.fonts\n .load(\n `${Number(fontWeight) || 400} ${Math.max(fontSize, 1)}px ${fontFamily}`,\n )\n .then(ready, ready);\n return () => {\n cancelled = true;\n };\n }, [fontFamily, fontSize, fontWeight]);\n\n useLayoutEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas || stateRef.current || webGlFailed) return;\n try {\n const state = createGlState(canvas);\n if (!state) {\n setWebGlFailed(true);\n return;\n }\n stateRef.current = state;\n } catch {\n setWebGlFailed(true);\n }\n return () => {\n if (stateRef.current) destroyGlState(stateRef.current);\n stateRef.current = null;\n };\n }, [webGlFailed]);\n\n useLayoutEffect(() => {\n const state = stateRef.current;\n if (!state || !fontReady) return;\n drawRushType({\n state,\n computed,\n words,\n fontSize,\n fontFamily: resolveFontFamily(fontFamily),\n fontWeight: Number(fontWeight) || 400,\n verticalStretch,\n frame: effectiveFrame,\n fps,\n });\n if (!continuedRef.current) {\n continuedRef.current = true;\n continueRender(renderHandle);\n }\n }, [\n computed,\n effectiveFrame,\n fontFamily,\n fontReady,\n fontSize,\n fontWeight,\n fps,\n renderHandle,\n verticalStretch,\n words,\n ]);\n\n useEffect(() => {\n if (!webGlFailed || continuedRef.current) return;\n continuedRef.current = true;\n continueRender(renderHandle);\n }, [renderHandle, webGlFailed]);\n\n const currentWord = words[computed.here.wordIndex] ?? words[0];\n\n return (\n <div\n className={className}\n role=\"img\"\n aria-label={`${phrase}: words stretching into vertical motion blur`}\n style={{\n position: \"absolute\",\n inset: 0,\n overflow: \"hidden\",\n backgroundColor: \"#000\",\n }}\n >\n <canvas\n ref={canvasRef}\n width={width}\n height={height}\n style={{\n display: webGlFailed ? \"none\" : \"block\",\n width: \"100%\",\n height: \"100%\",\n }}\n />\n {webGlFailed ? (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n color: \"#fff\",\n fontFamily,\n fontSize,\n fontWeight,\n }}\n >\n {currentWord}\n </div>\n ) : null}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n phrase: {\n type: \"text-content\",\n default: \"gone before you look\",\n description: \"Phrase\",\n },\n fontSize: {\n type: \"number\",\n default: 68,\n min: 32,\n max: 140,\n step: 2,\n description: \"Resting size\",\n hiddenFromList: false,\n },\n fontWeight: {\n type: \"enum\",\n default: \"400\",\n variants: {\n \"400\": {},\n \"500\": {},\n \"600\": {},\n \"700\": {},\n },\n description: \"Font weight\",\n },\n verticalStretch: {\n type: \"number\",\n default: 7,\n min: 3,\n max: 12,\n step: 0.25,\n description: \"Vertical stretch\",\n hiddenFromList: false,\n },\n chromaticSpread: {\n type: \"number\",\n default: 1,\n min: 0,\n max: 2,\n step: 0.05,\n description: \"Chromatic spread\",\n hiddenFromList: false,\n },\n restDuration: {\n type: \"number\",\n default: 12,\n min: 6,\n max: 30,\n step: 1,\n description: \"Rest duration\",\n hiddenFromList: false,\n },\n peakHoldDuration: {\n type: \"number\",\n default: 3,\n min: 0,\n max: 15,\n step: 1,\n description: \"Peak hold\",\n hiddenFromList: false,\n },\n speed: {\n type: \"number\",\n default: 1,\n min: 0.25,\n max: 4,\n step: 0.25,\n description: \"Speed\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"phrase\",\"fontSize\",\"fontWeight\",\"verticalStretch\",\"chromaticSpread\",\"restDuration\",\"peakHoldDuration\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n phrase: \"gone before you look\",\n fontSize: 68,\n fontWeight: \"400\",\n verticalStretch: 7,\n chromaticSpread: 1,\n restDuration: 12,\n peakHoldDuration: 3,\n speed: 1,\n};\n\ntype RushTypeElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof RushTypeBase>;\n\nconst RushTypeInner = forwardRef<\n HTMLDivElement,\n RushTypeElementProps & { 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 ?? \"<RushType>\"}\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 <RushTypeBase\n {...(componentProps as unknown as ComponentProps<typeof RushTypeBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const RushType = Interactive.withSchema({\n Component: RushTypeInner,\n componentName: \"<RushType>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n"
+ },
+ "durationInFrames": 104
+}
diff --git a/registry-artifacts/registry.json b/registry-artifacts/registry.json
index 69e97f96..54539895 100644
--- a/registry-artifacts/registry.json
+++ b/registry-artifacts/registry.json
@@ -353,6 +353,20 @@
],
"type": "registry:component"
},
+ {
+ "name": "rush-type",
+ "title": "Rush Type",
+ "description": "A resting white word blasts through vertical scale motion, separating into energy-conserving RGB shutter trails before the next word resolves.",
+ "dependencies": ["remotion"],
+ "files": [
+ {
+ "path": "registry/remocn/rush-type/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/rush-type.tsx"
+ }
+ ],
+ "type": "registry:component"
+ },
{
"name": "extrude-pop",
"title": "Extrude Pop",
diff --git a/registry-artifacts/rush-type.json b/registry-artifacts/rush-type.json
new file mode 100644
index 00000000..d5163016
--- /dev/null
+++ b/registry-artifacts/rush-type.json
@@ -0,0 +1,16 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "rush-type",
+ "title": "Rush Type",
+ "description": "A resting white word blasts through vertical scale motion, separating into energy-conserving RGB shutter trails before the next word resolves.",
+ "dependencies": ["remotion"],
+ "files": [
+ {
+ "path": "registry/remocn/rush-type/index.tsx",
+ "content": "\"use client\";\n\nimport { useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport {\n continueRender,\n delayRender,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\n\nexport interface RushTypeProps {\n /** A short phrase. One whitespace-delimited word is shown per cycle. */\n phrase?: string;\n /** Cap height of the resting word in composition pixels. */\n fontSize?: number;\n fontFamily?: string;\n fontWeight?: number;\n /** Authored vertical scale at the blast before perspective is applied. */\n verticalStretch?: number;\n /** 0 removes channel separation, 1 is the reference look, 2 exaggerates it. */\n chromaticSpread?: number;\n /** Readable resting phase, in frames. */\n restDuration?: number;\n /** Total near-point hang around the word swap, in frames. */\n peakHoldDuration?: number;\n /** Global playback multiplier. */\n speed?: number;\n className?: string;\n}\n\nexport type RushTypePhase = \"hang\" | \"arrive\" | \"rest\" | \"depart\";\n\nexport interface RushTypeFrameState {\n phase: RushTypePhase;\n wordIndex: number;\n beforeWordIndex: number;\n afterWordIndex: number;\n cycle: number;\n motion: number;\n isResting: boolean;\n swapAmount: number;\n shutterRatios: [number, number, number];\n thinAmount: number;\n bloomAmount: number;\n crtAmount: number;\n groundAmount: number;\n}\n\nexport const rushTypeDefaultPhrase = \"gone before you look\";\n\nconst ARRIVE_FRAMES = 7;\nconst LEAVE_FRAMES = 4;\nconst DEFAULT_REST_FRAMES = 12;\nconst DEFAULT_HOLD_FRAMES = 3;\nconst SHUTTER_SECONDS = 0.04;\nconst SMEAR_GAIN = 1.6;\nconst SAMPLES = 28;\nconst SHUTTER_SHAPE = 0.85;\nconst ROLL_U = 0.38;\nconst LAG_U = 0.55;\nconst THIN = 0.55;\nconst BLOOM_GAIN = 0.5;\nconst BLOOM_SPREAD = 3.2;\nconst BLOOM_BIAS = 3.5;\nconst SPEED_GAIN = 0.95;\nconst EXPOSURE = 1.75;\nconst HORIZONTAL_STRETCH = 1.57;\nconst FOCAL = 1;\nconst ORBIT_DEPTH = 0.42;\nconst ORBIT_RISE = 0.16;\nconst ORBIT_YAW = 0.55;\nconst ORBIT_YAW_LAG = 0.6;\nconst ORBIT_PITCH = 0.26;\nconst ORBIT_PITCH_LAG = -0.9;\nconst ORBIT_HANG_ARC = 0.9;\nconst PIVOT_FRAC = 0.07;\nconst CRT_GAIN = 1;\nconst CRT_PITCH = 5;\nconst CRT_MASK = 0.16;\nconst CRT_SCAN_PITCH = 3;\nconst CRT_SCAN = 0.12;\nconst CRT_BEAM = 0.7;\nconst CRT_HUM = 0.035;\nconst CRT_HUM_SPEED = 0.14;\nconst GROUND_SPEED = 0.028;\nconst GLOW_SPREAD = 2.6;\nconst GLOW_MIN = 0.34;\nconst GLOW_MAX_Y = 1.2;\nconst SWAP_SPREAD = 0.35;\nconst SWAP_FLASH = 0.5;\n\nconst FALL = [1, 0.557, 0.121, 0.049, 0.014, 0];\nconst RISE = [0, 0.08, 0.8, 1];\nconst ORBIT_IN = [0, 0.5, 0.82, 0.95, 1, 1];\nconst ORBIT_OUT = [0, 0.05, 0.14, 0.38, 1];\nconst DRIFT_DIRECTION = [-1, 0.7, -0.45, 1];\nconst SWING_ARC = Math.PI - ORBIT_HANG_ARC;\n\nfunction positiveModulo(value: number, modulus: number): number {\n return ((value % modulus) + modulus) % modulus;\n}\n\nfunction sampleTable(table: readonly number[], progress: number): number {\n const last = table.length - 1;\n const x = Math.min(Math.max(progress, 0), 1) * last;\n const index = Math.min(Math.floor(x), last - 1);\n return table[index] + (table[index + 1] - table[index]) * (x - index);\n}\n\nexport function normalizeRushTypePhrase(phrase: string): string[] {\n const words = phrase.trim().split(/\\s+/).filter(Boolean);\n return words.length > 0 ? words : rushTypeDefaultPhrase.split(\" \");\n}\n\nexport function getRushTypeCycleLength(\n restDuration = DEFAULT_REST_FRAMES,\n peakHoldDuration = DEFAULT_HOLD_FRAMES,\n): number {\n return (\n ARRIVE_FRAMES +\n LEAVE_FRAMES +\n Math.max(restDuration, 1) +\n Math.max(peakHoldDuration, 0)\n );\n}\n\nexport function getRushTypeDuration({\n phrase = rushTypeDefaultPhrase,\n restDuration = DEFAULT_REST_FRAMES,\n peakHoldDuration = DEFAULT_HOLD_FRAMES,\n}: Pick<\n RushTypeProps,\n \"phrase\" | \"restDuration\" | \"peakHoldDuration\"\n> = {}): number {\n return Math.round(\n normalizeRushTypePhrase(phrase).length *\n getRushTypeCycleLength(restDuration, peakHoldDuration),\n );\n}\n\nexport const rushTypeLength = getRushTypeDuration();\n\nexport function getRushTypeShutterRatios(\n chromaticSpread = 1,\n): [number, number, number] {\n const spread = Math.max(chromaticSpread, 0);\n return [0.62 ** spread, 1, 0.34 ** spread];\n}\n\ninterface TimelinePose {\n phase: RushTypePhase;\n p: number;\n psi: number;\n cycle: number;\n wordIndex: number;\n}\n\ninterface TimelineOptions {\n wordCount: number;\n restDuration: number;\n peakHoldDuration: number;\n}\n\nfunction getTimelinePose(\n frame: number,\n { wordCount, restDuration, peakHoldDuration }: TimelineOptions,\n): TimelinePose {\n const safeWordCount = Math.max(Math.floor(wordCount), 1);\n const safeRest = Math.max(restDuration, 1);\n const safeHold = Math.max(peakHoldDuration, 0);\n const halfHold = safeHold / 2;\n const cycleLength = getRushTypeCycleLength(safeRest, safeHold);\n const arriveEnd = halfHold + ARRIVE_FRAMES;\n const restEnd = arriveEnd + safeRest;\n const leaveEnd = restEnd + LEAVE_FRAMES;\n const startOffset = arriveEnd + safeRest / 2;\n const shifted = frame + startOffset;\n const cycle = Math.floor(shifted / cycleLength);\n const tau = positiveModulo(shifted, cycleLength);\n const wordIndex = positiveModulo(cycle, safeWordCount);\n\n if (tau < halfHold) {\n return {\n phase: \"hang\",\n p: 1,\n psi: ORBIT_HANG_ARC * (tau / Math.max(halfHold, 1e-6)),\n cycle,\n wordIndex,\n };\n }\n\n if (tau < arriveEnd) {\n const progress = (tau - halfHold) / ARRIVE_FRAMES;\n return {\n phase: \"arrive\",\n p: sampleTable(FALL, progress),\n psi: ORBIT_HANG_ARC + SWING_ARC * sampleTable(ORBIT_IN, progress),\n cycle,\n wordIndex,\n };\n }\n\n if (tau < restEnd) {\n return { phase: \"rest\", p: 0, psi: Math.PI, cycle, wordIndex };\n }\n\n if (tau < leaveEnd) {\n const progress = (tau - restEnd) / LEAVE_FRAMES;\n return {\n phase: \"depart\",\n p: sampleTable(RISE, progress),\n psi: Math.PI + SWING_ARC * sampleTable(ORBIT_OUT, progress),\n cycle,\n wordIndex,\n };\n }\n\n const progress = (tau - leaveEnd) / Math.max(halfHold, 1e-6);\n return {\n phase: \"hang\",\n p: 1,\n psi: 2 * Math.PI - ORBIT_HANG_ARC * (1 - progress),\n cycle,\n wordIndex,\n };\n}\n\ninterface ComputedFrame {\n before: TimelinePose;\n here: TimelinePose;\n after: TimelinePose;\n swapU: number;\n swapAmount: number;\n shutterRatios: [number, number, number];\n}\n\nfunction computeFrame({\n frame,\n fps,\n wordCount,\n restDuration,\n peakHoldDuration,\n chromaticSpread,\n}: {\n frame: number;\n fps: number;\n wordCount: number;\n restDuration: number;\n peakHoldDuration: number;\n chromaticSpread: number;\n}): ComputedFrame {\n const shutterFrames = SHUTTER_SECONDS * Math.max(fps, 1);\n const halfShutter = shutterFrames / 2;\n const options = { wordCount, restDuration, peakHoldDuration };\n const before = getTimelinePose(frame - halfShutter, options);\n const here = getTimelinePose(frame, options);\n const after = getTimelinePose(frame + halfShutter, options);\n const cycleLength = getRushTypeCycleLength(restDuration, peakHoldDuration);\n const halfHold = Math.max(peakHoldDuration, 0) / 2;\n const arriveEnd = halfHold + ARRIVE_FRAMES;\n const startOffset = arriveEnd + Math.max(restDuration, 1) / 2;\n const shifted = frame + startOffset;\n const nearestBoundary = Math.round(shifted / cycleLength) * cycleLength;\n const boundaryDistance = shifted - nearestBoundary;\n const crossesSwap = wordCount > 1 && after.cycle > before.cycle;\n const swapU = crossesSwap\n ? (after.cycle * cycleLength - shifted) / shutterFrames\n : 2;\n const swapAmount =\n wordCount > 1\n ? Math.max(0, 1 - (2 * boundaryDistance) ** 2 / shutterFrames ** 2)\n : 0;\n\n return {\n before,\n here,\n after,\n swapU,\n swapAmount,\n shutterRatios: getRushTypeShutterRatios(chromaticSpread),\n };\n}\n\nexport function getRushTypeFrameState({\n frame,\n fps = 30,\n phrase = rushTypeDefaultPhrase,\n restDuration = DEFAULT_REST_FRAMES,\n peakHoldDuration = DEFAULT_HOLD_FRAMES,\n chromaticSpread = 1,\n speed = 1,\n}: {\n frame: number;\n fps?: number;\n} & Pick<\n RushTypeProps,\n \"phrase\" | \"restDuration\" | \"peakHoldDuration\" | \"chromaticSpread\" | \"speed\"\n>): RushTypeFrameState {\n const words = normalizeRushTypePhrase(phrase);\n const computed = computeFrame({\n frame: frame * Math.max(speed, 0),\n fps,\n wordCount: words.length,\n restDuration,\n peakHoldDuration,\n chromaticSpread,\n });\n const motion = computed.here.p;\n\n return {\n phase: computed.here.phase,\n wordIndex: computed.here.wordIndex,\n beforeWordIndex: computed.before.wordIndex,\n afterWordIndex: computed.after.wordIndex,\n cycle: computed.here.cycle,\n motion,\n isResting:\n computed.here.phase === \"rest\" &&\n computed.before.p === 0 &&\n computed.after.p === 0,\n swapAmount: computed.swapAmount,\n shutterRatios: computed.shutterRatios,\n thinAmount: THIN * motion,\n bloomAmount: BLOOM_GAIN * motion,\n crtAmount: CRT_GAIN * motion,\n groundAmount: GROUND_SPEED * motion,\n };\n}\n\nfunction orbitTurn(psi: number, amplitude: number, lag: number): number {\n const pin = Math.sin(lag);\n return (amplitude * (Math.sin(psi - lag) - pin)) / (1 + Math.abs(pin));\n}\n\nconst VERTEX_SHADER = `\nattribute vec2 aPos;\nvarying vec2 vUv;\nvoid main() {\n vUv = aPos * 0.5 + 0.5;\n gl_Position = vec4(aPos, 0.0, 1.0);\n}\n`;\n\nconst FRAGMENT_SHADER = `\nprecision highp float;\nvarying vec2 vUv;\n\nuniform sampler2D uText;\nuniform vec2 uRes;\nuniform vec2 uHalfPx;\nuniform float uSx;\nuniform vec3 uSyQ;\nuniform float uCenterY;\nuniform float uSwapU;\nuniform float uHalfA;\nuniform float uHalfB;\nuniform vec3 uK;\nuniform vec2 uSwapScl;\nuniform float uShape;\nuniform float uRoll;\nuniform float uLag;\nuniform float uThin;\nuniform float uBloom;\nuniform float uGain;\nuniform float uExp;\nuniform float uFocal;\nuniform vec3 uPos;\nuniform vec4 uRot;\nuniform float uCrt;\nuniform float uTime;\nuniform vec4 uGlow;\nuniform float uGlowAmp;\n\n#define SAMPLES ${SAMPLES}\n#define BLOOM_TAPS 4\n#define BLOOM_SPREAD ${BLOOM_SPREAD.toFixed(3)}\n#define BLOOM_BIAS ${BLOOM_BIAS.toFixed(3)}\n#define TAU 6.2831853\n#define CRT_PITCH ${CRT_PITCH.toFixed(3)}\n#define CRT_MASK ${CRT_MASK.toFixed(4)}\n#define CRT_SCAN_PITCH ${CRT_SCAN_PITCH.toFixed(3)}\n#define CRT_SCAN ${CRT_SCAN.toFixed(4)}\n#define CRT_BEAM ${CRT_BEAM.toFixed(4)}\n#define CRT_HUM ${CRT_HUM.toFixed(4)}\n#define CRT_HUM_SPEED ${CRT_HUM_SPEED.toFixed(4)}\n\nvec2 atlasUv(float sy, float halfIdx, vec2 wordPoint, out float inside) {\n float sx = max(uSx, 1e-4);\n float sv = max(abs(sy), 1e-4);\n vec2 q = vec2(\n (wordPoint.x / sx + uHalfPx.x * 0.5) / uHalfPx.x,\n (wordPoint.y / sv + uHalfPx.y * 0.5) / uHalfPx.y\n );\n inside = step(0.0, q.x) * step(q.x, 1.0) * step(0.0, q.y) * step(q.y, 1.0);\n return vec2(\n clamp(q.x, 0.0, 1.0),\n (clamp(q.y, 0.0, 1.0) + halfIdx) * 0.5\n );\n}\n\nfloat tap(float sy, float halfIdx, vec2 wordPoint, float front) {\n float inside;\n vec2 texturePoint = atlasUv(sy, halfIdx, wordPoint, inside);\n float value = texture2D(uText, texturePoint).r * inside * front;\n return value * mix(1.0, value, uThin);\n}\n\nfloat tapBlur(float sy, float halfIdx, vec2 wordPoint, float front) {\n float inside;\n vec2 texturePoint = atlasUv(sy, halfIdx, wordPoint, inside);\n return texture2D(uText, texturePoint, BLOOM_BIAS).r * inside * front;\n}\n\nvoid main() {\n vec2 pixel = vUv * uRes;\n vec2 center = vec2(uRes.x * 0.5, uRes.y * uCenterY);\n vec2 screenPoint = pixel - center;\n\n float sinYaw = uRot.x;\n float cosYaw = uRot.y;\n float sinPitch = uRot.z;\n float cosPitch = uRot.w;\n float a1 = -(screenPoint.x * sinYaw + uFocal * cosYaw);\n float b1 = sinPitch * (screenPoint.x * cosYaw - uFocal * sinYaw);\n float c1 = uFocal * uPos.x - screenPoint.x * uPos.z;\n float a2 = -screenPoint.y * sinYaw;\n float b2 = screenPoint.y * sinPitch * cosYaw - uFocal * cosPitch;\n float c2 = uFocal * uPos.y - screenPoint.y * uPos.z;\n float determinant = a1 * b2 - a2 * b1;\n float inverse = 1.0 / (abs(determinant) < 1e-4 ? 1e-4 : determinant);\n float a = (c1 * b2 - c2 * b1) * inverse;\n float b = (a1 * c2 - a2 * c1) * inverse;\n float cameraZ = uPos.z - a * sinYaw + b * sinPitch * cosYaw;\n vec2 wordPoint = vec2(a, b);\n float front = step(uFocal * 0.05, cameraZ);\n vec3 accumulated = vec3(0.0);\n\n if (abs(uSyQ.y) + abs(uSyQ.z) < 1e-5) {\n accumulated = vec3(tap(uSyQ.x, uHalfA, wordPoint, front));\n } else {\n float offset =\n uLag * (wordPoint.x / uRes.x) - uRoll * (screenPoint.y / uRes.y);\n float weightSum = 0.0;\n\n for (int i = 0; i < SAMPLES; i++) {\n float u = float(i) / float(SAMPLES - 1) - 0.5;\n float weight = 1.0 - uShape * abs(u) * 2.0;\n weightSum += weight;\n float shiftedU = u + offset;\n vec3 shutterU = shiftedU * uK;\n vec3 sy = uSyQ.x + uSyQ.y * shutterU + uSyQ.z * shutterU * shutterU;\n accumulated.r += weight * tap(\n sy.r * (shutterU.r < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.r < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n accumulated.g += weight * tap(\n sy.g * (shutterU.g < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.g < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n accumulated.b += weight * tap(\n sy.b * (shutterU.b < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.b < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n }\n\n accumulated /= max(weightSum, 1e-4);\n\n vec3 halo = vec3(0.0);\n for (int j = 0; j < BLOOM_TAPS; j++) {\n float u =\n (float(j) / float(BLOOM_TAPS - 1) - 0.5) * BLOOM_SPREAD + offset;\n vec3 shutterU = u * uK;\n vec3 sy = uSyQ.x + uSyQ.y * shutterU + uSyQ.z * shutterU * shutterU;\n halo.r += tapBlur(\n sy.r * (shutterU.r < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.r < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n halo.g += tapBlur(\n sy.g * (shutterU.g < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.g < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n halo.b += tapBlur(\n sy.b * (shutterU.b < uSwapU ? uSwapScl.x : uSwapScl.y),\n shutterU.b < uSwapU ? uHalfA : uHalfB,\n wordPoint,\n front\n );\n }\n accumulated += halo * (uBloom / float(BLOOM_TAPS));\n accumulated *= uGain;\n }\n\n accumulated =\n (1.0 - exp(-accumulated * uExp)) / (1.0 - exp(-uExp));\n\n vec2 glowDistance =\n (pixel - uGlow.xy) / max(uGlow.zw, vec2(1.0));\n float ground =\n uGlowAmp * (1.0 - smoothstep(0.0, 1.0, length(glowDistance)));\n accumulated += ground * (1.0 - accumulated);\n\n if (uCrt > 0.0) {\n float luminance = max(max(accumulated.r, accumulated.g), accumulated.b);\n vec3 maskWave = 0.5 + 0.5 * cos(\n TAU * (pixel.x / CRT_PITCH - vec3(0.0, 0.33333, 0.66667))\n );\n vec3 mask = mix(vec3(1.0), maskWave * 2.0, CRT_MASK * uCrt);\n float scanWave = 0.5 + 0.5 * cos(TAU * pixel.y / CRT_SCAN_PITCH);\n float scan =\n 1.0 - CRT_SCAN * uCrt * (1.0 - CRT_BEAM * luminance) * (1.0 - scanWave);\n float bar = 0.5 + 0.5 * cos(\n TAU * (pixel.y / uRes.y - uTime * CRT_HUM_SPEED)\n );\n float hum = 1.0 + CRT_HUM * uCrt * (bar * 2.0 - 1.0);\n accumulated *= mask * scan * hum;\n }\n\n gl_FragColor = vec4(accumulated, 1.0);\n}\n`;\n\nconst UNIFORM_NAMES = [\n \"uText\",\n \"uRes\",\n \"uHalfPx\",\n \"uSx\",\n \"uSyQ\",\n \"uCenterY\",\n \"uSwapU\",\n \"uHalfA\",\n \"uHalfB\",\n \"uK\",\n \"uSwapScl\",\n \"uShape\",\n \"uRoll\",\n \"uLag\",\n \"uThin\",\n \"uBloom\",\n \"uGain\",\n \"uExp\",\n \"uFocal\",\n \"uPos\",\n \"uRot\",\n \"uCrt\",\n \"uTime\",\n \"uGlow\",\n \"uGlowAmp\",\n] as const;\n\ninterface GlState {\n gl: WebGLRenderingContext;\n program: WebGLProgram;\n buffer: WebGLBuffer;\n texture: WebGLTexture;\n uniforms: Record<(typeof UNIFORM_NAMES)[number], WebGLUniformLocation | null>;\n atlasWidth: number;\n halfHeight: number;\n textureCapHeight: number;\n scratch: HTMLCanvasElement;\n pairKey: string;\n wordHalfWidth: number;\n}\n\nfunction compileShader(\n gl: WebGLRenderingContext,\n type: number,\n source: string,\n): WebGLShader {\n const shader = gl.createShader(type);\n if (!shader) throw new Error(\"RushType could not create a WebGL shader\");\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const message = gl.getShaderInfoLog(shader) ?? \"Unknown shader error\";\n gl.deleteShader(shader);\n throw new Error(`RushType shader compilation failed: ${message}`);\n }\n return shader;\n}\n\nfunction createGlState(canvas: HTMLCanvasElement): GlState | null {\n const gl = canvas.getContext(\"webgl\", {\n alpha: false,\n antialias: false,\n depth: false,\n stencil: false,\n preserveDrawingBuffer: true,\n powerPreference: \"high-performance\",\n });\n if (!gl) return null;\n\n const vertex = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);\n const fragment = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);\n const program = gl.createProgram();\n if (!program) throw new Error(\"RushType could not create a WebGL program\");\n gl.attachShader(program, vertex);\n gl.attachShader(program, fragment);\n gl.bindAttribLocation(program, 0, \"aPos\");\n gl.linkProgram(program);\n gl.deleteShader(vertex);\n gl.deleteShader(fragment);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n const message = gl.getProgramInfoLog(program) ?? \"Unknown link error\";\n gl.deleteProgram(program);\n throw new Error(`RushType shader linking failed: ${message}`);\n }\n\n const buffer = gl.createBuffer();\n const texture = gl.createTexture();\n if (!buffer || !texture) {\n throw new Error(\"RushType could not allocate WebGL resources\");\n }\n gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n gl.bufferData(\n gl.ARRAY_BUFFER,\n new Float32Array([-1, -1, 3, -1, -1, 3]),\n gl.STATIC_DRAW,\n );\n\n const atlasWidth = canvas.width >= 1800 ? 4096 : 2048;\n const halfHeight = atlasWidth / 4;\n const textureCapHeight = Math.round(halfHeight * 0.64);\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texImage2D(\n gl.TEXTURE_2D,\n 0,\n gl.RGBA,\n atlasWidth,\n halfHeight * 2,\n 0,\n gl.RGBA,\n gl.UNSIGNED_BYTE,\n null,\n );\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texParameteri(\n gl.TEXTURE_2D,\n gl.TEXTURE_MIN_FILTER,\n gl.LINEAR_MIPMAP_LINEAR,\n );\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n\n const scratch = document.createElement(\"canvas\");\n scratch.width = atlasWidth;\n scratch.height = halfHeight;\n const uniforms = Object.fromEntries(\n UNIFORM_NAMES.map((name) => [name, gl.getUniformLocation(program, name)]),\n ) as GlState[\"uniforms\"];\n gl.clearColor(0, 0, 0, 1);\n\n return {\n gl,\n program,\n buffer,\n texture,\n uniforms,\n atlasWidth,\n halfHeight,\n textureCapHeight,\n scratch,\n pairKey: \"\",\n wordHalfWidth: 1,\n };\n}\n\nfunction resolveFontFamily(fontFamily: string): string {\n if (typeof document === \"undefined\") return fontFamily;\n const probe = document.createElement(\"span\");\n probe.style.cssText =\n \"position:absolute;visibility:hidden;pointer-events:none\";\n probe.style.fontFamily = fontFamily;\n probe.textContent = \"Ag\";\n document.body.appendChild(probe);\n const resolved = getComputedStyle(probe).fontFamily;\n probe.remove();\n return resolved || fontFamily;\n}\n\nfunction rasterWord(\n state: GlState,\n word: string,\n half: 0 | 1,\n fontFamily: string,\n fontWeight: number,\n): number {\n const context = state.scratch.getContext(\"2d\");\n if (!context) return 1;\n context.fillStyle = \"#000\";\n context.fillRect(0, 0, state.atlasWidth, state.halfHeight);\n\n let rasterSize = state.textureCapHeight * 1.4;\n context.font = `${fontWeight} ${rasterSize}px ${fontFamily}`;\n const capHeight =\n context.measureText(\"H\").actualBoundingBoxAscent || rasterSize * 0.72;\n rasterSize *= state.textureCapHeight / capHeight;\n context.font = `${fontWeight} ${rasterSize}px ${fontFamily}`;\n\n const maxWidth = state.atlasWidth * 0.92;\n const measured = context.measureText(word).width;\n if (measured > maxWidth) {\n rasterSize *= maxWidth / measured;\n context.font = `${fontWeight} ${rasterSize}px ${fontFamily}`;\n }\n\n context.fillStyle = \"#fff\";\n context.textAlign = \"center\";\n context.textBaseline = \"alphabetic\";\n context.fillText(\n word,\n state.atlasWidth / 2,\n state.halfHeight / 2 + state.textureCapHeight / 2,\n );\n const halfWidth = context.measureText(word).width / 2;\n\n const { gl } = state;\n gl.bindTexture(gl.TEXTURE_2D, state.texture);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\n gl.texSubImage2D(\n gl.TEXTURE_2D,\n 0,\n 0,\n half * state.halfHeight,\n gl.RGBA,\n gl.UNSIGNED_BYTE,\n state.scratch,\n );\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n return halfWidth;\n}\n\nfunction updateAtlas(\n state: GlState,\n firstWord: string,\n secondWord: string,\n fontFamily: string,\n fontWeight: number,\n): void {\n const pairKey = `${fontFamily}\\u0000${fontWeight}\\u0000${firstWord}\\u0000${secondWord}`;\n if (state.pairKey === pairKey) return;\n const firstWidth = rasterWord(state, firstWord, 0, fontFamily, fontWeight);\n const secondWidth = rasterWord(state, secondWord, 1, fontFamily, fontWeight);\n state.gl.generateMipmap(state.gl.TEXTURE_2D);\n state.pairKey = pairKey;\n state.wordHalfWidth = Math.max(firstWidth, secondWidth);\n}\n\nfunction destroyGlState(state: GlState): void {\n const { gl } = state;\n gl.deleteProgram(state.program);\n gl.deleteBuffer(state.buffer);\n gl.deleteTexture(state.texture);\n}\n\nfunction drawRushType({\n state,\n computed,\n words,\n fontSize,\n fontFamily,\n fontWeight,\n verticalStretch,\n frame,\n fps,\n}: {\n state: GlState;\n computed: ComputedFrame;\n words: string[];\n fontSize: number;\n fontFamily: string;\n fontWeight: number;\n verticalStretch: number;\n frame: number;\n fps: number;\n}): void {\n const { gl, uniforms } = state;\n const beforeWord = words[computed.before.wordIndex] ?? words[0];\n const afterWord = words[computed.after.wordIndex] ?? words[0];\n updateAtlas(state, beforeWord, afterWord, fontFamily, fontWeight);\n\n const unit = Math.max(fontSize, 1) / state.textureCapHeight;\n const scaleY = (pose: TimelinePose) =>\n unit * (1 + pose.p * (Math.max(verticalStretch, 1) - 1));\n const scaleBefore = scaleY(computed.before);\n const scaleCurrent = scaleY(computed.here);\n const scaleAfter = scaleY(computed.after);\n const quadraticA = scaleCurrent;\n const quadraticC = 2 * (scaleAfter + scaleBefore - 2 * scaleCurrent);\n const tangent = scaleAfter - scaleBefore;\n const peakSmear = SMEAR_GAIN * computed.here.p * scaleCurrent;\n const magnitude = Math.sqrt(tangent * tangent + peakSmear * peakSmear);\n const quadraticB = tangent < 0 ? -magnitude : magnitude;\n const scaleX = unit * (1 + computed.here.p * (HORIZONTAL_STRETCH - 1));\n\n const direction =\n DRIFT_DIRECTION[\n positiveModulo(computed.here.cycle, DRIFT_DIRECTION.length)\n ] ?? 1;\n const psi = computed.here.psi * Math.sign(direction || 1);\n const orbitAmplitude = Math.abs(direction);\n const focal =\n state.scratch.height > 0 ? state.gl.drawingBufferHeight * FOCAL : 1;\n const z = focal * (1 - ORBIT_DEPTH * (1 + Math.cos(psi)) * 0.5);\n const x = 0;\n const y = focal * ORBIT_RISE * orbitAmplitude * Math.sin(psi);\n const yaw = orbitTurn(psi, ORBIT_YAW, ORBIT_YAW_LAG);\n const pitch = orbitTurn(psi, ORBIT_PITCH, ORBIT_PITCH_LAG);\n const pivot = PIVOT_FRAC * computed.here.p;\n const perspective = focal / z;\n const glowX = gl.drawingBufferWidth / 2 + (focal * x) / z;\n const glowY = gl.drawingBufferHeight * (0.5 + pivot) + (focal * y) / z;\n const wordWidth = state.wordHalfWidth * scaleX * perspective;\n const wordHeight = state.textureCapHeight * scaleCurrent * perspective;\n\n gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);\n // biome-ignore lint/correctness/useHookAtTopLevel: gl.useProgram is a WebGL method, not a React hook\n gl.useProgram(state.program);\n gl.bindBuffer(gl.ARRAY_BUFFER, state.buffer);\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(gl.TEXTURE_2D, state.texture);\n gl.uniform1i(uniforms.uText, 0);\n gl.uniform2f(uniforms.uRes, gl.drawingBufferWidth, gl.drawingBufferHeight);\n gl.uniform2f(uniforms.uHalfPx, state.atlasWidth, state.halfHeight);\n gl.uniform1f(uniforms.uSx, scaleX);\n gl.uniform3f(uniforms.uSyQ, quadraticA, quadraticB, quadraticC);\n gl.uniform1f(uniforms.uCenterY, 0.5 + pivot);\n gl.uniform1f(uniforms.uSwapU, computed.swapU);\n gl.uniform1f(uniforms.uHalfA, 0);\n gl.uniform1f(uniforms.uHalfB, 1);\n gl.uniform3f(\n uniforms.uK,\n computed.shutterRatios[0],\n computed.shutterRatios[1],\n computed.shutterRatios[2],\n );\n gl.uniform2f(\n uniforms.uSwapScl,\n 1 + SWAP_SPREAD * computed.swapAmount,\n 1 - SWAP_SPREAD * computed.swapAmount,\n );\n gl.uniform1f(uniforms.uShape, SHUTTER_SHAPE);\n gl.uniform1f(uniforms.uRoll, ROLL_U);\n gl.uniform1f(uniforms.uLag, LAG_U);\n gl.uniform1f(uniforms.uThin, THIN * computed.here.p);\n gl.uniform1f(uniforms.uBloom, BLOOM_GAIN * computed.here.p);\n gl.uniform1f(\n uniforms.uGain,\n (1 + SPEED_GAIN * computed.here.p) * (1 + SWAP_FLASH * computed.swapAmount),\n );\n gl.uniform1f(uniforms.uExp, EXPOSURE);\n gl.uniform1f(uniforms.uFocal, focal);\n gl.uniform3f(uniforms.uPos, x, y, z);\n gl.uniform4f(\n uniforms.uRot,\n Math.sin(yaw),\n Math.cos(yaw),\n Math.sin(pitch),\n Math.cos(pitch),\n );\n gl.uniform1f(uniforms.uCrt, CRT_GAIN * computed.here.p);\n gl.uniform1f(uniforms.uTime, frame / Math.max(fps, 1));\n gl.uniform4f(\n uniforms.uGlow,\n glowX,\n glowY,\n Math.max(wordWidth * GLOW_SPREAD, gl.drawingBufferWidth * GLOW_MIN),\n Math.min(\n Math.max(wordHeight * GLOW_SPREAD, gl.drawingBufferHeight * GLOW_MIN),\n gl.drawingBufferHeight * GLOW_MAX_Y,\n ),\n );\n gl.uniform1f(uniforms.uGlowAmp, GROUND_SPEED * computed.here.p);\n gl.clear(gl.COLOR_BUFFER_BIT);\n gl.drawArrays(gl.TRIANGLES, 0, 3);\n}\n\nexport function RushType({\n phrase = rushTypeDefaultPhrase,\n fontSize = 68,\n fontFamily = \"Arial, Helvetica, sans-serif\",\n fontWeight = 400,\n verticalStretch = 7,\n chromaticSpread = 1,\n restDuration = DEFAULT_REST_FRAMES,\n peakHoldDuration = DEFAULT_HOLD_FRAMES,\n speed = 1,\n className,\n}: RushTypeProps) {\n const frame = useCurrentFrame();\n const { fps, width, height } = useVideoConfig();\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const stateRef = useRef<GlState | null>(null);\n const [fontReady, setFontReady] = useState(false);\n const [webGlFailed, setWebGlFailed] = useState(false);\n const [renderHandle] = useState(() => delayRender(\"rush-type: first frame\"));\n const continuedRef = useRef(false);\n const words = normalizeRushTypePhrase(phrase);\n const effectiveFrame = frame * Math.max(speed, 0);\n const computed = computeFrame({\n frame: effectiveFrame,\n fps,\n wordCount: words.length,\n restDuration,\n peakHoldDuration,\n chromaticSpread,\n });\n\n useEffect(() => {\n let cancelled = false;\n setFontReady(false);\n const ready = () => {\n if (!cancelled) setFontReady(true);\n };\n if (typeof document === \"undefined\" || !document.fonts) {\n ready();\n return () => {\n cancelled = true;\n };\n }\n document.fonts\n .load(\n `${Number(fontWeight) || 400} ${Math.max(fontSize, 1)}px ${fontFamily}`,\n )\n .then(ready, ready);\n return () => {\n cancelled = true;\n };\n }, [fontFamily, fontSize, fontWeight]);\n\n useLayoutEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas || stateRef.current || webGlFailed) return;\n try {\n const state = createGlState(canvas);\n if (!state) {\n setWebGlFailed(true);\n return;\n }\n stateRef.current = state;\n } catch {\n setWebGlFailed(true);\n }\n return () => {\n if (stateRef.current) destroyGlState(stateRef.current);\n stateRef.current = null;\n };\n }, [webGlFailed]);\n\n useLayoutEffect(() => {\n const state = stateRef.current;\n if (!state || !fontReady) return;\n drawRushType({\n state,\n computed,\n words,\n fontSize,\n fontFamily: resolveFontFamily(fontFamily),\n fontWeight: Number(fontWeight) || 400,\n verticalStretch,\n frame: effectiveFrame,\n fps,\n });\n if (!continuedRef.current) {\n continuedRef.current = true;\n continueRender(renderHandle);\n }\n }, [\n computed,\n effectiveFrame,\n fontFamily,\n fontReady,\n fontSize,\n fontWeight,\n fps,\n renderHandle,\n verticalStretch,\n words,\n ]);\n\n useEffect(() => {\n if (!webGlFailed || continuedRef.current) return;\n continuedRef.current = true;\n continueRender(renderHandle);\n }, [renderHandle, webGlFailed]);\n\n const currentWord = words[computed.here.wordIndex] ?? words[0];\n\n return (\n <div\n className={className}\n role=\"img\"\n aria-label={`${phrase}: words stretching into vertical motion blur`}\n style={{\n position: \"absolute\",\n inset: 0,\n overflow: \"hidden\",\n backgroundColor: \"#000\",\n }}\n >\n <canvas\n ref={canvasRef}\n width={width}\n height={height}\n style={{\n display: webGlFailed ? \"none\" : \"block\",\n width: \"100%\",\n height: \"100%\",\n }}\n />\n {webGlFailed ? (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n color: \"#fff\",\n fontFamily,\n fontSize,\n fontWeight,\n }}\n >\n {currentWord}\n </div>\n ) : null}\n </div>\n );\n}\n",
+ "type": "registry:component",
+ "target": "components/remocn/rush-type.tsx"
+ }
+ ],
+ "type": "registry:component"
+}
diff --git a/registry/__index__.tsx b/registry/__index__.tsx
index bf49b09d..45a716e1 100644
--- a/registry/__index__.tsx
+++ b/registry/__index__.tsx
@@ -150,6 +150,16 @@ const registry: Record<string, RegistryEntry> = {
(m) => m.gradientScaleCutTextConfig,
),
},
+ "rush-type": {
+ load: () =>
+ import("@/registry/remocn/rush-type").then((m) => ({
+ default: m.RushType,
+ })),
+ loadConfig: () =>
+ import("@/registry/remocn/rush-type/config").then(
+ (m) => m.rushTypeConfig,
+ ),
+ },
"per-character-rise": {
load: () =>
import("@/registry/remocn/per-character-rise").then((m) => ({
diff --git a/registry/__manifest__.ts b/registry/__manifest__.ts
index f2a21e4a..e5af075d 100644
--- a/registry/__manifest__.ts
+++ b/registry/__manifest__.ts
@@ -3235,6 +3235,26 @@ export const previewManifest: Record<string, PreviewManifestEntry> = {
speed: 1,
},
},
+ "rush-type": {
+ durationInFrames: 104,
+ fps: 30,
+ compositionWidth: 1280,
+ compositionHeight: 720,
+ previewBackdrop: {
+ type: "color",
+ value: "#000000",
+ },
+ defaults: {
+ phrase: "gone before you look",
+ fontSize: 68,
+ fontWeight: "400",
+ verticalStretch: 7,
+ chromaticSpread: 1,
+ restDuration: 12,
+ peakHoldDuration: 3,
+ speed: 1,
+ },
+ },
"scale-down-fade": {
durationInFrames: 90,
fps: 30,
@@ -4239,6 +4259,7 @@ export const previewManifest: Record<string, PreviewManifestEntry> = {
exitAt: 50,
exitFrames: 20,
wordStagger: 4,
+ anchorShift: -72,
fontSize: 42,
color: "#e8e8e8",
fontWeight: "400",
diff --git a/registry/remocn/registry.json b/registry/remocn/registry.json
index 2f8bf4c9..ea747a0d 100644
--- a/registry/remocn/registry.json
+++ b/registry/remocn/registry.json
@@ -353,6 +353,20 @@
}
]
},
+ {
+ "name": "rush-type",
+ "type": "registry:component",
+ "title": "Rush Type",
+ "description": "A resting white word blasts through vertical scale motion, separating into energy-conserving RGB shutter trails before the next word resolves.",
+ "dependencies": ["remotion"],
+ "files": [
+ {
+ "path": "rush-type/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/rush-type.tsx"
+ }
+ ]
+ },
{
"name": "extrude-pop",
"type": "registry:component",
diff --git a/registry/remocn/rush-type/__tests__/rush-type.test.ts b/registry/remocn/rush-type/__tests__/rush-type.test.ts
new file mode 100644
index 00000000..89a3f8bf
--- /dev/null
+++ b/registry/remocn/rush-type/__tests__/rush-type.test.ts
@@ -0,0 +1,101 @@
+import { describe, expect, it } from "bun:test";
+import {
+ getRushTypeCycleLength,
+ getRushTypeDuration,
+ getRushTypeFrameState,
+ getRushTypeShutterRatios,
+ normalizeRushTypePhrase,
+ rushTypeLength,
+} from "../index";
+
+describe("RushType phrase and duration", () => {
+ it("normalizes whitespace into a stable word sequence", () => {
+ expect(normalizeRushTypePhrase(" gone\n before you look ")).toEqual([
+ "gone",
+ "before",
+ "you",
+ "look",
+ ]);
+ });
+
+ it("falls back to the reference phrase when the input is empty", () => {
+ expect(normalizeRushTypePhrase(" ")).toEqual([
+ "gone",
+ "before",
+ "you",
+ "look",
+ ]);
+ });
+
+ it("derives the natural length from the phrase and timing controls", () => {
+ expect(getRushTypeCycleLength()).toBe(26);
+ expect(rushTypeLength).toBe(104);
+ expect(
+ getRushTypeDuration({
+ phrase: "one two",
+ restDuration: 20,
+ peakHoldDuration: 5,
+ }),
+ ).toBe(72);
+ });
+});
+
+describe("RushType shutter model", () => {
+ it("has coincident shutters when chromatic spread is zero", () => {
+ expect(getRushTypeShutterRatios(0)).toEqual([1, 1, 1]);
+ });
+
+ it("matches the reference shutter ratios at spread one", () => {
+ const [red, green, blue] = getRushTypeShutterRatios(1);
+ expect(red).toBeCloseTo(0.62);
+ expect(green).toBe(1);
+ expect(blue).toBeCloseTo(0.34);
+ });
+
+ it("widens the shutter separation without introducing channel colors", () => {
+ const normal = getRushTypeShutterRatios(1);
+ const strong = getRushTypeShutterRatios(2);
+ expect(strong[0]).toBeLessThan(normal[0]);
+ expect(strong[1]).toBe(1);
+ expect(strong[2]).toBeLessThan(normal[2]);
+ });
+});
+
+describe("RushType timeline", () => {
+ it("starts on a readable resting word", () => {
+ const state = getRushTypeFrameState({ frame: 0 });
+ expect(state.phase).toBe("rest");
+ expect(state.wordIndex).toBe(0);
+ expect(state.isResting).toBe(true);
+ });
+
+ it("advances one word after one complete cycle", () => {
+ const state = getRushTypeFrameState({
+ frame: getRushTypeCycleLength(),
+ });
+ expect(state.phase).toBe("rest");
+ expect(state.wordIndex).toBe(1);
+ });
+
+ it("makes every additive effect exactly zero at rest", () => {
+ const state = getRushTypeFrameState({ frame: 0 });
+ expect(state.motion).toBe(0);
+ expect(state.swapAmount).toBe(0);
+ expect(state.thinAmount).toBe(0);
+ expect(state.bloomAmount).toBe(0);
+ expect(state.crtAmount).toBe(0);
+ expect(state.groundAmount).toBe(0);
+ });
+
+ it("places the word swap inside the peak shutter", () => {
+ const state = getRushTypeFrameState({
+ frame: 11,
+ peakHoldDuration: 2,
+ });
+ expect(state.phase).toBe("hang");
+ expect(state.motion).toBe(1);
+ expect(state.beforeWordIndex).toBe(0);
+ expect(state.afterWordIndex).toBe(1);
+ expect(state.swapAmount).toBe(1);
+ });
+});
diff --git a/registry/remocn/rush-type/config.ts b/registry/remocn/rush-type/config.ts
new file mode 100644
index 00000000..879a08d9
--- /dev/null
+++ b/registry/remocn/rush-type/config.ts
@@ -0,0 +1,77 @@
+import {
+ type ComponentConfig,
+ enumVariants,
+ FONT_WEIGHT_OPTIONS,
+ FPS,
+ H,
+ W,
+} from "@/lib/customizer-config";
+import { rushTypeLength } from ".";
+
+export const rushTypeConfig: ComponentConfig = {
+ componentName: "RushType",
+ importPath: "@/components/remocn/rush-type",
+ controls: {
+ phrase: {
+ type: "text-content",
+ default: "gone before you look",
+ description: "Phrase",
+ },
+ fontSize: {
+ type: "number",
+ default: 68,
+ min: 32,
+ max: 140,
+ step: 2,
+ description: "Resting size",
+ hiddenFromList: false,
+ },
+ fontWeight: {
+ type: "enum",
+ default: "400",
+ variants: enumVariants(FONT_WEIGHT_OPTIONS),
+ description: "Font weight",
+ },
+ verticalStretch: {
+ type: "number",
+ default: 7,
+ min: 3,
+ max: 12,
+ step: 0.25,
+ description: "Vertical stretch",
+ hiddenFromList: false,
+ },
+ chromaticSpread: {
+ type: "number",
+ default: 1,
+ min: 0,
+ max: 2,
+ step: 0.05,
+ description: "Chromatic spread",
+ hiddenFromList: false,
+ },
+ restDuration: {
+ type: "number",
+ default: 12,
+ min: 6,
+ max: 30,
+ step: 1,
+ description: "Rest duration",
+ hiddenFromList: false,
+ },
+ peakHoldDuration: {
+ type: "number",
+ default: 3,
+ min: 0,
+ max: 15,
+ step: 1,
+ description: "Peak hold",
+ hiddenFromList: false,
+ },
+ },
+ durationInFrames: rushTypeLength,
+ fps: FPS,
+ compositionWidth: W,
+ compositionHeight: H,
+ previewBackdrop: { type: "color", value: "#000000" },
+};
diff --git a/registry/remocn/rush-type/index.tsx b/registry/remocn/rush-type/index.tsx
new file mode 100644
index 00000000..101886a1
--- /dev/null
+++ b/registry/remocn/rush-type/index.tsx
@@ -0,0 +1,1041 @@
+"use client";
+
+import { useEffect, useLayoutEffect, useRef, useState } from "react";
+import {
+ continueRender,
+ delayRender,
+ useCurrentFrame,
+ useVideoConfig,
+} from "remotion";
+
+export interface RushTypeProps {
+ /** A short phrase. One whitespace-delimited word is shown per cycle. */
+ phrase?: string;
+ /** Cap height of the resting word in composition pixels. */
+ fontSize?: number;
+ fontFamily?: string;
+ fontWeight?: number;
+ /** Authored vertical scale at the blast before perspective is applied. */
+ verticalStretch?: number;
+ /** 0 removes channel separation, 1 is the reference look, 2 exaggerates it. */
+ chromaticSpread?: number;
+ /** Readable resting phase, in frames. */
+ restDuration?: number;
+ /** Total near-point hang around the word swap, in frames. */
+ peakHoldDuration?: number;
+ /** Global playback multiplier. */
+ speed?: number;
+ className?: string;
+}
+
+export type RushTypePhase = "hang" | "arrive" | "rest" | "depart";
+
+export interface RushTypeFrameState {
+ phase: RushTypePhase;
+ wordIndex: number;
+ beforeWordIndex: number;
+ afterWordIndex: number;
+ cycle: number;
+ motion: number;
+ isResting: boolean;
+ swapAmount: number;
+ shutterRatios: [number, number, number];
+ thinAmount: number;
+ bloomAmount: number;
+ crtAmount: number;
+ groundAmount: number;
+}
+
+export const rushTypeDefaultPhrase = "gone before you look";
+
+const ARRIVE_FRAMES = 7;
+const LEAVE_FRAMES = 4;
+const DEFAULT_REST_FRAMES = 12;
+const DEFAULT_HOLD_FRAMES = 3;
+const SHUTTER_SECONDS = 0.04;
+const SMEAR_GAIN = 1.6;
+const SAMPLES = 28;
+const SHUTTER_SHAPE = 0.85;
+const ROLL_U = 0.38;
+const LAG_U = 0.55;
+const THIN = 0.55;
+const BLOOM_GAIN = 0.5;
+const BLOOM_SPREAD = 3.2;
+const BLOOM_BIAS = 3.5;
+const SPEED_GAIN = 0.95;
+const EXPOSURE = 1.75;
+const HORIZONTAL_STRETCH = 1.57;
+const FOCAL = 1;
+const ORBIT_DEPTH = 0.42;
+const ORBIT_RISE = 0.16;
+const ORBIT_YAW = 0.55;
+const ORBIT_YAW_LAG = 0.6;
+const ORBIT_PITCH = 0.26;
+const ORBIT_PITCH_LAG = -0.9;
+const ORBIT_HANG_ARC = 0.9;
+const PIVOT_FRAC = 0.07;
+const CRT_GAIN = 1;
+const CRT_PITCH = 5;
+const CRT_MASK = 0.16;
+const CRT_SCAN_PITCH = 3;
+const CRT_SCAN = 0.12;
+const CRT_BEAM = 0.7;
+const CRT_HUM = 0.035;
+const CRT_HUM_SPEED = 0.14;
+const GROUND_SPEED = 0.028;
+const GLOW_SPREAD = 2.6;
+const GLOW_MIN = 0.34;
+const GLOW_MAX_Y = 1.2;
+const SWAP_SPREAD = 0.35;
+const SWAP_FLASH = 0.5;
+
+const FALL = [1, 0.557, 0.121, 0.049, 0.014, 0];
+const RISE = [0, 0.08, 0.8, 1];
+const ORBIT_IN = [0, 0.5, 0.82, 0.95, 1, 1];
+const ORBIT_OUT = [0, 0.05, 0.14, 0.38, 1];
+const DRIFT_DIRECTION = [-1, 0.7, -0.45, 1];
+const SWING_ARC = Math.PI - ORBIT_HANG_ARC;
+
+function positiveModulo(value: number, modulus: number): number {
+ return ((value % modulus) + modulus) % modulus;
+}
+
+function sampleTable(table: readonly number[], progress: number): number {
+ const last = table.length - 1;
+ const x = Math.min(Math.max(progress, 0), 1) * last;
+ const index = Math.min(Math.floor(x), last - 1);
+ return table[index] + (table[index + 1] - table[index]) * (x - index);
+}
+
+export function normalizeRushTypePhrase(phrase: string): string[] {
+ const words = phrase.trim().split(/\s+/).filter(Boolean);
+ return words.length > 0 ? words : rushTypeDefaultPhrase.split(" ");
+}
+
+export function getRushTypeCycleLength(
+ restDuration = DEFAULT_REST_FRAMES,
+ peakHoldDuration = DEFAULT_HOLD_FRAMES,
+): number {
+ return (
+ ARRIVE_FRAMES +
+ LEAVE_FRAMES +
+ Math.max(restDuration, 1) +
+ Math.max(peakHoldDuration, 0)
+ );
+}
+
+export function getRushTypeDuration({
+ phrase = rushTypeDefaultPhrase,
+ restDuration = DEFAULT_REST_FRAMES,
+ peakHoldDuration = DEFAULT_HOLD_FRAMES,
+}: Pick<
+ RushTypeProps,
+ "phrase" | "restDuration" | "peakHoldDuration"
+> = {}): number {
+ return Math.round(
+ normalizeRushTypePhrase(phrase).length *
+ getRushTypeCycleLength(restDuration, peakHoldDuration),
+ );
+}
+
+export const rushTypeLength = getRushTypeDuration();
+
+export function getRushTypeShutterRatios(
+ chromaticSpread = 1,
+): [number, number, number] {
+ const spread = Math.max(chromaticSpread, 0);
+ return [0.62 ** spread, 1, 0.34 ** spread];
+}
+
+interface TimelinePose {
+ phase: RushTypePhase;
+ p: number;
+ psi: number;
+ cycle: number;
+ wordIndex: number;
+}
+
+interface TimelineOptions {
+ wordCount: number;
+ restDuration: number;
+ peakHoldDuration: number;
+}
+
+function getTimelinePose(
+ frame: number,
+ { wordCount, restDuration, peakHoldDuration }: TimelineOptions,
+): TimelinePose {
+ const safeWordCount = Math.max(Math.floor(wordCount), 1);
+ const safeRest = Math.max(restDuration, 1);
+ const safeHold = Math.max(peakHoldDuration, 0);
+ const halfHold = safeHold / 2;
+ const cycleLength = getRushTypeCycleLength(safeRest, safeHold);
+ const arriveEnd = halfHold + ARRIVE_FRAMES;
+ const restEnd = arriveEnd + safeRest;
+ const leaveEnd = restEnd + LEAVE_FRAMES;
+ const startOffset = arriveEnd + safeRest / 2;
+ const shifted = frame + startOffset;
+ const cycle = Math.floor(shifted / cycleLength);
+ const tau = positiveModulo(shifted, cycleLength);
+ const wordIndex = positiveModulo(cycle, safeWordCount);
+
+ if (tau < halfHold) {
+ return {
+ phase: "hang",
+ p: 1,
+ psi: ORBIT_HANG_ARC * (tau / Math.max(halfHold, 1e-6)),
+ cycle,
+ wordIndex,
+ };
+ }
+
+ if (tau < arriveEnd) {
+ const progress = (tau - halfHold) / ARRIVE_FRAMES;
+ return {
+ phase: "arrive",
+ p: sampleTable(FALL, progress),
+ psi: ORBIT_HANG_ARC + SWING_ARC * sampleTable(ORBIT_IN, progress),
+ cycle,
+ wordIndex,
+ };
+ }
+
+ if (tau < restEnd) {
+ return { phase: "rest", p: 0, psi: Math.PI, cycle, wordIndex };
+ }
+
+ if (tau < leaveEnd) {
+ const progress = (tau - restEnd) / LEAVE_FRAMES;
+ return {
+ phase: "depart",
+ p: sampleTable(RISE, progress),
+ psi: Math.PI + SWING_ARC * sampleTable(ORBIT_OUT, progress),
+ cycle,
+ wordIndex,
+ };
+ }
+
+ const progress = (tau - leaveEnd) / Math.max(halfHold, 1e-6);
+ return {
+ phase: "hang",
+ p: 1,
+ psi: 2 * Math.PI - ORBIT_HANG_ARC * (1 - progress),
+ cycle,
+ wordIndex,
+ };
+}
+
+interface ComputedFrame {
+ before: TimelinePose;
+ here: TimelinePose;
+ after: TimelinePose;
+ swapU: number;
+ swapAmount: number;
+ shutterRatios: [number, number, number];
+}
+
+function computeFrame({
+ frame,
+ fps,
+ wordCount,
+ restDuration,
+ peakHoldDuration,
+ chromaticSpread,
+}: {
+ frame: number;
+ fps: number;
+ wordCount: number;
+ restDuration: number;
+ peakHoldDuration: number;
+ chromaticSpread: number;
+}): ComputedFrame {
+ const shutterFrames = SHUTTER_SECONDS * Math.max(fps, 1);
+ const halfShutter = shutterFrames / 2;
+ const options = { wordCount, restDuration, peakHoldDuration };
+ const before = getTimelinePose(frame - halfShutter, options);
+ const here = getTimelinePose(frame, options);
+ const after = getTimelinePose(frame + halfShutter, options);
+ const cycleLength = getRushTypeCycleLength(restDuration, peakHoldDuration);
+ const halfHold = Math.max(peakHoldDuration, 0) / 2;
+ const arriveEnd = halfHold + ARRIVE_FRAMES;
+ const startOffset = arriveEnd + Math.max(restDuration, 1) / 2;
+ const shifted = frame + startOffset;
+ const nearestBoundary = Math.round(shifted / cycleLength) * cycleLength;
+ const boundaryDistance = shifted - nearestBoundary;
+ const crossesSwap = wordCount > 1 && after.cycle > before.cycle;
+ const swapU = crossesSwap
+ ? (after.cycle * cycleLength - shifted) / shutterFrames
+ : 2;
+ const swapAmount =
+ wordCount > 1
+ ? Math.max(0, 1 - (2 * boundaryDistance) ** 2 / shutterFrames ** 2)
+ : 0;
+
+ return {
+ before,
+ here,
+ after,
+ swapU,
+ swapAmount,
+ shutterRatios: getRushTypeShutterRatios(chromaticSpread),
+ };
+}
+
+export function getRushTypeFrameState({
+ frame,
+ fps = 30,
+ phrase = rushTypeDefaultPhrase,
+ restDuration = DEFAULT_REST_FRAMES,
+ peakHoldDuration = DEFAULT_HOLD_FRAMES,
+ chromaticSpread = 1,
+ speed = 1,
+}: {
+ frame: number;
+ fps?: number;
+} & Pick<
+ RushTypeProps,
+ "phrase" | "restDuration" | "peakHoldDuration" | "chromaticSpread" | "speed"
+>): RushTypeFrameState {
+ const words = normalizeRushTypePhrase(phrase);
+ const computed = computeFrame({
+ frame: frame * Math.max(speed, 0),
+ fps,
+ wordCount: words.length,
+ restDuration,
+ peakHoldDuration,
+ chromaticSpread,
+ });
+ const motion = computed.here.p;
+
+ return {
+ phase: computed.here.phase,
+ wordIndex: computed.here.wordIndex,
+ beforeWordIndex: computed.before.wordIndex,
+ afterWordIndex: computed.after.wordIndex,
+ cycle: computed.here.cycle,
+ motion,
+ isResting:
+ computed.here.phase === "rest" &&
+ computed.before.p === 0 &&
+ computed.after.p === 0,
+ swapAmount: computed.swapAmount,
+ shutterRatios: computed.shutterRatios,
+ thinAmount: THIN * motion,
+ bloomAmount: BLOOM_GAIN * motion,
+ crtAmount: CRT_GAIN * motion,
+ groundAmount: GROUND_SPEED * motion,
+ };
+}
+
+function orbitTurn(psi: number, amplitude: number, lag: number): number {
+ const pin = Math.sin(lag);
+ return (amplitude * (Math.sin(psi - lag) - pin)) / (1 + Math.abs(pin));
+}
+
+const VERTEX_SHADER = `
+attribute vec2 aPos;
+varying vec2 vUv;
+void main() {
+ vUv = aPos * 0.5 + 0.5;
+ gl_Position = vec4(aPos, 0.0, 1.0);
+}
+`;
+
+const FRAGMENT_SHADER = `
+precision highp float;
+varying vec2 vUv;
+
+uniform sampler2D uText;
+uniform vec2 uRes;
+uniform vec2 uHalfPx;
+uniform float uSx;
+uniform vec3 uSyQ;
+uniform float uCenterY;
+uniform float uSwapU;
+uniform float uHalfA;
+uniform float uHalfB;
+uniform vec3 uK;
+uniform vec2 uSwapScl;
+uniform float uShape;
+uniform float uRoll;
+uniform float uLag;
+uniform float uThin;
+uniform float uBloom;
+uniform float uGain;
+uniform float uExp;
+uniform float uFocal;
+uniform vec3 uPos;
+uniform vec4 uRot;
+uniform float uCrt;
+uniform float uTime;
+uniform vec4 uGlow;
+uniform float uGlowAmp;
+
+#define SAMPLES ${SAMPLES}
+#define BLOOM_TAPS 4
+#define BLOOM_SPREAD ${BLOOM_SPREAD.toFixed(3)}
+#define BLOOM_BIAS ${BLOOM_BIAS.toFixed(3)}
+#define TAU 6.2831853
+#define CRT_PITCH ${CRT_PITCH.toFixed(3)}
+#define CRT_MASK ${CRT_MASK.toFixed(4)}
+#define CRT_SCAN_PITCH ${CRT_SCAN_PITCH.toFixed(3)}
+#define CRT_SCAN ${CRT_SCAN.toFixed(4)}
+#define CRT_BEAM ${CRT_BEAM.toFixed(4)}
+#define CRT_HUM ${CRT_HUM.toFixed(4)}
+#define CRT_HUM_SPEED ${CRT_HUM_SPEED.toFixed(4)}
+
+vec2 atlasUv(float sy, float halfIdx, vec2 wordPoint, out float inside) {
+ float sx = max(uSx, 1e-4);
+ float sv = max(abs(sy), 1e-4);
+ vec2 q = vec2(
+ (wordPoint.x / sx + uHalfPx.x * 0.5) / uHalfPx.x,
+ (wordPoint.y / sv + uHalfPx.y * 0.5) / uHalfPx.y
+ );
+ inside = step(0.0, q.x) * step(q.x, 1.0) * step(0.0, q.y) * step(q.y, 1.0);
+ return vec2(
+ clamp(q.x, 0.0, 1.0),
+ (clamp(q.y, 0.0, 1.0) + halfIdx) * 0.5
+ );
+}
+
+float tap(float sy, float halfIdx, vec2 wordPoint, float front) {
+ float inside;
+ vec2 texturePoint = atlasUv(sy, halfIdx, wordPoint, inside);
+ float value = texture2D(uText, texturePoint).r * inside * front;
+ return value * mix(1.0, value, uThin);
+}
+
+float tapBlur(float sy, float halfIdx, vec2 wordPoint, float front) {
+ float inside;
+ vec2 texturePoint = atlasUv(sy, halfIdx, wordPoint, inside);
+ return texture2D(uText, texturePoint, BLOOM_BIAS).r * inside * front;
+}
+
+void main() {
+ vec2 pixel = vUv * uRes;
+ vec2 center = vec2(uRes.x * 0.5, uRes.y * uCenterY);
+ vec2 screenPoint = pixel - center;
+
+ float sinYaw = uRot.x;
+ float cosYaw = uRot.y;
+ float sinPitch = uRot.z;
+ float cosPitch = uRot.w;
+ float a1 = -(screenPoint.x * sinYaw + uFocal * cosYaw);
+ float b1 = sinPitch * (screenPoint.x * cosYaw - uFocal * sinYaw);
+ float c1 = uFocal * uPos.x - screenPoint.x * uPos.z;
+ float a2 = -screenPoint.y * sinYaw;
+ float b2 = screenPoint.y * sinPitch * cosYaw - uFocal * cosPitch;
+ float c2 = uFocal * uPos.y - screenPoint.y * uPos.z;
+ float determinant = a1 * b2 - a2 * b1;
+ float inverse = 1.0 / (abs(determinant) < 1e-4 ? 1e-4 : determinant);
+ float a = (c1 * b2 - c2 * b1) * inverse;
+ float b = (a1 * c2 - a2 * c1) * inverse;
+ float cameraZ = uPos.z - a * sinYaw + b * sinPitch * cosYaw;
+ vec2 wordPoint = vec2(a, b);
+ float front = step(uFocal * 0.05, cameraZ);
+ vec3 accumulated = vec3(0.0);
+
+ if (abs(uSyQ.y) + abs(uSyQ.z) < 1e-5) {
+ accumulated = vec3(tap(uSyQ.x, uHalfA, wordPoint, front));
+ } else {
+ float offset =
+ uLag * (wordPoint.x / uRes.x) - uRoll * (screenPoint.y / uRes.y);
+ float weightSum = 0.0;
+
+ for (int i = 0; i < SAMPLES; i++) {
+ float u = float(i) / float(SAMPLES - 1) - 0.5;
+ float weight = 1.0 - uShape * abs(u) * 2.0;
+ weightSum += weight;
+ float shiftedU = u + offset;
+ vec3 shutterU = shiftedU * uK;
+ vec3 sy = uSyQ.x + uSyQ.y * shutterU + uSyQ.z * shutterU * shutterU;
+ accumulated.r += weight * tap(
+ sy.r * (shutterU.r < uSwapU ? uSwapScl.x : uSwapScl.y),
+ shutterU.r < uSwapU ? uHalfA : uHalfB,
+ wordPoint,
+ front
+ );
+ accumulated.g += weight * tap(
+ sy.g * (shutterU.g < uSwapU ? uSwapScl.x : uSwapScl.y),
+ shutterU.g < uSwapU ? uHalfA : uHalfB,
+ wordPoint,
+ front
+ );
+ accumulated.b += weight * tap(
+ sy.b * (shutterU.b < uSwapU ? uSwapScl.x : uSwapScl.y),
+ shutterU.b < uSwapU ? uHalfA : uHalfB,
+ wordPoint,
+ front
+ );
+ }
+
+ accumulated /= max(weightSum, 1e-4);
+
+ vec3 halo = vec3(0.0);
+ for (int j = 0; j < BLOOM_TAPS; j++) {
+ float u =
+ (float(j) / float(BLOOM_TAPS - 1) - 0.5) * BLOOM_SPREAD + offset;
+ vec3 shutterU = u * uK;
+ vec3 sy = uSyQ.x + uSyQ.y * shutterU + uSyQ.z * shutterU * shutterU;
+ halo.r += tapBlur(
+ sy.r * (shutterU.r < uSwapU ? uSwapScl.x : uSwapScl.y),
+ shutterU.r < uSwapU ? uHalfA : uHalfB,
+ wordPoint,
+ front
+ );
+ halo.g += tapBlur(
+ sy.g * (shutterU.g < uSwapU ? uSwapScl.x : uSwapScl.y),
+ shutterU.g < uSwapU ? uHalfA : uHalfB,
+ wordPoint,
+ front
+ );
+ halo.b += tapBlur(
+ sy.b * (shutterU.b < uSwapU ? uSwapScl.x : uSwapScl.y),
+ shutterU.b < uSwapU ? uHalfA : uHalfB,
+ wordPoint,
+ front
+ );
+ }
+ accumulated += halo * (uBloom / float(BLOOM_TAPS));
+ accumulated *= uGain;
+ }
+
+ accumulated =
+ (1.0 - exp(-accumulated * uExp)) / (1.0 - exp(-uExp));
+
+ vec2 glowDistance =
+ (pixel - uGlow.xy) / max(uGlow.zw, vec2(1.0));
+ float ground =
+ uGlowAmp * (1.0 - smoothstep(0.0, 1.0, length(glowDistance)));
+ accumulated += ground * (1.0 - accumulated);
+
+ if (uCrt > 0.0) {
+ float luminance = max(max(accumulated.r, accumulated.g), accumulated.b);
+ vec3 maskWave = 0.5 + 0.5 * cos(
+ TAU * (pixel.x / CRT_PITCH - vec3(0.0, 0.33333, 0.66667))
+ );
+ vec3 mask = mix(vec3(1.0), maskWave * 2.0, CRT_MASK * uCrt);
+ float scanWave = 0.5 + 0.5 * cos(TAU * pixel.y / CRT_SCAN_PITCH);
+ float scan =
+ 1.0 - CRT_SCAN * uCrt * (1.0 - CRT_BEAM * luminance) * (1.0 - scanWave);
+ float bar = 0.5 + 0.5 * cos(
+ TAU * (pixel.y / uRes.y - uTime * CRT_HUM_SPEED)
+ );
+ float hum = 1.0 + CRT_HUM * uCrt * (bar * 2.0 - 1.0);
+ accumulated *= mask * scan * hum;
+ }
+
+ gl_FragColor = vec4(accumulated, 1.0);
+}
+`;
+
+const UNIFORM_NAMES = [
+ "uText",
+ "uRes",
+ "uHalfPx",
+ "uSx",
+ "uSyQ",
+ "uCenterY",
+ "uSwapU",
+ "uHalfA",
+ "uHalfB",
+ "uK",
+ "uSwapScl",
+ "uShape",
+ "uRoll",
+ "uLag",
+ "uThin",
+ "uBloom",
+ "uGain",
+ "uExp",
+ "uFocal",
+ "uPos",
+ "uRot",
+ "uCrt",
+ "uTime",
+ "uGlow",
+ "uGlowAmp",
+] as const;
+
+interface GlState {
+ gl: WebGLRenderingContext;
+ program: WebGLProgram;
+ buffer: WebGLBuffer;
+ texture: WebGLTexture;
+ uniforms: Record<(typeof UNIFORM_NAMES)[number], WebGLUniformLocation | null>;
+ atlasWidth: number;
+ halfHeight: number;
+ textureCapHeight: number;
+ scratch: HTMLCanvasElement;
+ pairKey: string;
+ wordHalfWidth: number;
+}
+
+function compileShader(
+ gl: WebGLRenderingContext,
+ type: number,
+ source: string,
+): WebGLShader {
+ const shader = gl.createShader(type);
+ if (!shader) throw new Error("RushType could not create a WebGL shader");
+ gl.shaderSource(shader, source);
+ gl.compileShader(shader);
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
+ const message = gl.getShaderInfoLog(shader) ?? "Unknown shader error";
+ gl.deleteShader(shader);
+ throw new Error(`RushType shader compilation failed: ${message}`);
+ }
+ return shader;
+}
+
+function createGlState(canvas: HTMLCanvasElement): GlState | null {
+ const gl = canvas.getContext("webgl", {
+ alpha: false,
+ antialias: false,
+ depth: false,
+ stencil: false,
+ preserveDrawingBuffer: true,
+ powerPreference: "high-performance",
+ });
+ if (!gl) return null;
+
+ const vertex = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
+ const fragment = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
+ const program = gl.createProgram();
+ if (!program) throw new Error("RushType could not create a WebGL program");
+ gl.attachShader(program, vertex);
+ gl.attachShader(program, fragment);
+ gl.bindAttribLocation(program, 0, "aPos");
+ gl.linkProgram(program);
+ gl.deleteShader(vertex);
+ gl.deleteShader(fragment);
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
+ const message = gl.getProgramInfoLog(program) ?? "Unknown link error";
+ gl.deleteProgram(program);
+ throw new Error(`RushType shader linking failed: ${message}`);
+ }
+
+ const buffer = gl.createBuffer();
+ const texture = gl.createTexture();
+ if (!buffer || !texture) {
+ throw new Error("RushType could not allocate WebGL resources");
+ }
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
+ gl.bufferData(
+ gl.ARRAY_BUFFER,
+ new Float32Array([-1, -1, 3, -1, -1, 3]),
+ gl.STATIC_DRAW,
+ );
+
+ const atlasWidth = canvas.width >= 1800 ? 4096 : 2048;
+ const halfHeight = atlasWidth / 4;
+ const textureCapHeight = Math.round(halfHeight * 0.64);
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.texImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ atlasWidth,
+ halfHeight * 2,
+ 0,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ null,
+ );
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(
+ gl.TEXTURE_2D,
+ gl.TEXTURE_MIN_FILTER,
+ gl.LINEAR_MIPMAP_LINEAR,
+ );
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+
+ const scratch = document.createElement("canvas");
+ scratch.width = atlasWidth;
+ scratch.height = halfHeight;
+ const uniforms = Object.fromEntries(
+ UNIFORM_NAMES.map((name) => [name, gl.getUniformLocation(program, name)]),
+ ) as GlState["uniforms"];
+ gl.clearColor(0, 0, 0, 1);
+
+ return {
+ gl,
+ program,
+ buffer,
+ texture,
+ uniforms,
+ atlasWidth,
+ halfHeight,
+ textureCapHeight,
+ scratch,
+ pairKey: "",
+ wordHalfWidth: 1,
+ };
+}
+
+function resolveFontFamily(fontFamily: string): string {
+ if (typeof document === "undefined") return fontFamily;
+ const probe = document.createElement("span");
+ probe.style.cssText =
+ "position:absolute;visibility:hidden;pointer-events:none";
+ probe.style.fontFamily = fontFamily;
+ probe.textContent = "Ag";
+ document.body.appendChild(probe);
+ const resolved = getComputedStyle(probe).fontFamily;
+ probe.remove();
+ return resolved || fontFamily;
+}
+
+function rasterWord(
+ state: GlState,
+ word: string,
+ half: 0 | 1,
+ fontFamily: string,
+ fontWeight: number,
+): number {
+ const context = state.scratch.getContext("2d");
+ if (!context) return 1;
+ context.fillStyle = "#000";
+ context.fillRect(0, 0, state.atlasWidth, state.halfHeight);
+
+ let rasterSize = state.textureCapHeight * 1.4;
+ context.font = `${fontWeight} ${rasterSize}px ${fontFamily}`;
+ const capHeight =
+ context.measureText("H").actualBoundingBoxAscent || rasterSize * 0.72;
+ rasterSize *= state.textureCapHeight / capHeight;
+ context.font = `${fontWeight} ${rasterSize}px ${fontFamily}`;
+
+ const maxWidth = state.atlasWidth * 0.92;
+ const measured = context.measureText(word).width;
+ if (measured > maxWidth) {
+ rasterSize *= maxWidth / measured;
+ context.font = `${fontWeight} ${rasterSize}px ${fontFamily}`;
+ }
+
+ context.fillStyle = "#fff";
+ context.textAlign = "center";
+ context.textBaseline = "alphabetic";
+ context.fillText(
+ word,
+ state.atlasWidth / 2,
+ state.halfHeight / 2 + state.textureCapHeight / 2,
+ );
+ const halfWidth = context.measureText(word).width / 2;
+
+ const { gl } = state;
+ gl.bindTexture(gl.TEXTURE_2D, state.texture);
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
+ gl.texSubImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ 0,
+ half * state.halfHeight,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ state.scratch,
+ );
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
+ return halfWidth;
+}
+
+function updateAtlas(
+ state: GlState,
+ firstWord: string,
+ secondWord: string,
+ fontFamily: string,
+ fontWeight: number,
+): void {
+ const pairKey = `${fontFamily}\u0000${fontWeight}\u0000${firstWord}\u0000${secondWord}`;
+ if (state.pairKey === pairKey) return;
+ const firstWidth = rasterWord(state, firstWord, 0, fontFamily, fontWeight);
+ const secondWidth = rasterWord(state, secondWord, 1, fontFamily, fontWeight);
+ state.gl.generateMipmap(state.gl.TEXTURE_2D);
+ state.pairKey = pairKey;
+ state.wordHalfWidth = Math.max(firstWidth, secondWidth);
+}
+
+function destroyGlState(state: GlState): void {
+ const { gl } = state;
+ gl.deleteProgram(state.program);
+ gl.deleteBuffer(state.buffer);
+ gl.deleteTexture(state.texture);
+}
+
+function drawRushType({
+ state,
+ computed,
+ words,
+ fontSize,
+ fontFamily,
+ fontWeight,
+ verticalStretch,
+ frame,
+ fps,
+}: {
+ state: GlState;
+ computed: ComputedFrame;
+ words: string[];
+ fontSize: number;
+ fontFamily: string;
+ fontWeight: number;
+ verticalStretch: number;
+ frame: number;
+ fps: number;
+}): void {
+ const { gl, uniforms } = state;
+ const beforeWord = words[computed.before.wordIndex] ?? words[0];
+ const afterWord = words[computed.after.wordIndex] ?? words[0];
+ updateAtlas(state, beforeWord, afterWord, fontFamily, fontWeight);
+
+ const unit = Math.max(fontSize, 1) / state.textureCapHeight;
+ const scaleY = (pose: TimelinePose) =>
+ unit * (1 + pose.p * (Math.max(verticalStretch, 1) - 1));
+ const scaleBefore = scaleY(computed.before);
+ const scaleCurrent = scaleY(computed.here);
+ const scaleAfter = scaleY(computed.after);
+ const quadraticA = scaleCurrent;
+ const quadraticC = 2 * (scaleAfter + scaleBefore - 2 * scaleCurrent);
+ const tangent = scaleAfter - scaleBefore;
+ const peakSmear = SMEAR_GAIN * computed.here.p * scaleCurrent;
+ const magnitude = Math.sqrt(tangent * tangent + peakSmear * peakSmear);
+ const quadraticB = tangent < 0 ? -magnitude : magnitude;
+ const scaleX = unit * (1 + computed.here.p * (HORIZONTAL_STRETCH - 1));
+
+ const direction =
+ DRIFT_DIRECTION[
+ positiveModulo(computed.here.cycle, DRIFT_DIRECTION.length)
+ ] ?? 1;
+ const psi = computed.here.psi * Math.sign(direction || 1);
+ const orbitAmplitude = Math.abs(direction);
+ const focal =
+ state.scratch.height > 0 ? state.gl.drawingBufferHeight * FOCAL : 1;
+ const z = focal * (1 - ORBIT_DEPTH * (1 + Math.cos(psi)) * 0.5);
+ const x = 0;
+ const y = focal * ORBIT_RISE * orbitAmplitude * Math.sin(psi);
+ const yaw = orbitTurn(psi, ORBIT_YAW, ORBIT_YAW_LAG);
+ const pitch = orbitTurn(psi, ORBIT_PITCH, ORBIT_PITCH_LAG);
+ const pivot = PIVOT_FRAC * computed.here.p;
+ const perspective = focal / z;
+ const glowX = gl.drawingBufferWidth / 2 + (focal * x) / z;
+ const glowY = gl.drawingBufferHeight * (0.5 + pivot) + (focal * y) / z;
+ const wordWidth = state.wordHalfWidth * scaleX * perspective;
+ const wordHeight = state.textureCapHeight * scaleCurrent * perspective;
+
+ gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
+ // biome-ignore lint/correctness/useHookAtTopLevel: gl.useProgram is a WebGL method, not a React hook
+ gl.useProgram(state.program);
+ gl.bindBuffer(gl.ARRAY_BUFFER, state.buffer);
+ gl.enableVertexAttribArray(0);
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, state.texture);
+ gl.uniform1i(uniforms.uText, 0);
+ gl.uniform2f(uniforms.uRes, gl.drawingBufferWidth, gl.drawingBufferHeight);
+ gl.uniform2f(uniforms.uHalfPx, state.atlasWidth, state.halfHeight);
+ gl.uniform1f(uniforms.uSx, scaleX);
+ gl.uniform3f(uniforms.uSyQ, quadraticA, quadraticB, quadraticC);
+ gl.uniform1f(uniforms.uCenterY, 0.5 + pivot);
+ gl.uniform1f(uniforms.uSwapU, computed.swapU);
+ gl.uniform1f(uniforms.uHalfA, 0);
+ gl.uniform1f(uniforms.uHalfB, 1);
+ gl.uniform3f(
+ uniforms.uK,
+ computed.shutterRatios[0],
+ computed.shutterRatios[1],
+ computed.shutterRatios[2],
+ );
+ gl.uniform2f(
+ uniforms.uSwapScl,
+ 1 + SWAP_SPREAD * computed.swapAmount,
+ 1 - SWAP_SPREAD * computed.swapAmount,
+ );
+ gl.uniform1f(uniforms.uShape, SHUTTER_SHAPE);
+ gl.uniform1f(uniforms.uRoll, ROLL_U);
+ gl.uniform1f(uniforms.uLag, LAG_U);
+ gl.uniform1f(uniforms.uThin, THIN * computed.here.p);
+ gl.uniform1f(uniforms.uBloom, BLOOM_GAIN * computed.here.p);
+ gl.uniform1f(
+ uniforms.uGain,
+ (1 + SPEED_GAIN * computed.here.p) * (1 + SWAP_FLASH * computed.swapAmount),
+ );
+ gl.uniform1f(uniforms.uExp, EXPOSURE);
+ gl.uniform1f(uniforms.uFocal, focal);
+ gl.uniform3f(uniforms.uPos, x, y, z);
+ gl.uniform4f(
+ uniforms.uRot,
+ Math.sin(yaw),
+ Math.cos(yaw),
+ Math.sin(pitch),
+ Math.cos(pitch),
+ );
+ gl.uniform1f(uniforms.uCrt, CRT_GAIN * computed.here.p);
+ gl.uniform1f(uniforms.uTime, frame / Math.max(fps, 1));
+ gl.uniform4f(
+ uniforms.uGlow,
+ glowX,
+ glowY,
+ Math.max(wordWidth * GLOW_SPREAD, gl.drawingBufferWidth * GLOW_MIN),
+ Math.min(
+ Math.max(wordHeight * GLOW_SPREAD, gl.drawingBufferHeight * GLOW_MIN),
+ gl.drawingBufferHeight * GLOW_MAX_Y,
+ ),
+ );
+ gl.uniform1f(uniforms.uGlowAmp, GROUND_SPEED * computed.here.p);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
+}
+
+export function RushType({
+ phrase = rushTypeDefaultPhrase,
+ fontSize = 68,
+ fontFamily = "Arial, Helvetica, sans-serif",
+ fontWeight = 400,
+ verticalStretch = 7,
+ chromaticSpread = 1,
+ restDuration = DEFAULT_REST_FRAMES,
+ peakHoldDuration = DEFAULT_HOLD_FRAMES,
+ speed = 1,
+ className,
+}: RushTypeProps) {
+ const frame = useCurrentFrame();
+ const { fps, width, height } = useVideoConfig();
+ const canvasRef = useRef<HTMLCanvasElement>(null);
+ const stateRef = useRef<GlState | null>(null);
+ const [fontReady, setFontReady] = useState(false);
+ const [webGlFailed, setWebGlFailed] = useState(false);
+ const [renderHandle] = useState(() => delayRender("rush-type: first frame"));
+ const continuedRef = useRef(false);
+ const words = normalizeRushTypePhrase(phrase);
+ const effectiveFrame = frame * Math.max(speed, 0);
+ const computed = computeFrame({
+ frame: effectiveFrame,
+ fps,
+ wordCount: words.length,
+ restDuration,
+ peakHoldDuration,
+ chromaticSpread,
+ });
+
+ useEffect(() => {
+ let cancelled = false;
+ setFontReady(false);
+ const ready = () => {
+ if (!cancelled) setFontReady(true);
+ };
+ if (typeof document === "undefined" || !document.fonts) {
+ ready();
+ return () => {
+ cancelled = true;
+ };
+ }
+ document.fonts
+ .load(
+ `${Number(fontWeight) || 400} ${Math.max(fontSize, 1)}px ${fontFamily}`,
+ )
+ .then(ready, ready);
+ return () => {
+ cancelled = true;
+ };
+ }, [fontFamily, fontSize, fontWeight]);
+
+ useLayoutEffect(() => {
+ const canvas = canvasRef.current;
+ if (!canvas || stateRef.current || webGlFailed) return;
+ try {
+ const state = createGlState(canvas);
+ if (!state) {
+ setWebGlFailed(true);
+ return;
+ }
+ stateRef.current = state;
+ } catch {
+ setWebGlFailed(true);
+ }
+ return () => {
+ if (stateRef.current) destroyGlState(stateRef.current);
+ stateRef.current = null;
+ };
+ }, [webGlFailed]);
+
+ useLayoutEffect(() => {
+ const state = stateRef.current;
+ if (!state || !fontReady) return;
+ drawRushType({
+ state,
+ computed,
+ words,
+ fontSize,
+ fontFamily: resolveFontFamily(fontFamily),
+ fontWeight: Number(fontWeight) || 400,
+ verticalStretch,
+ frame: effectiveFrame,
+ fps,
+ });
+ if (!continuedRef.current) {
+ continuedRef.current = true;
+ continueRender(renderHandle);
+ }
+ }, [
+ computed,
+ effectiveFrame,
+ fontFamily,
+ fontReady,
+ fontSize,
+ fontWeight,
+ fps,
+ renderHandle,
+ verticalStretch,
+ words,
+ ]);
+
+ useEffect(() => {
+ if (!webGlFailed || continuedRef.current) return;
+ continuedRef.current = true;
+ continueRender(renderHandle);
+ }, [renderHandle, webGlFailed]);
+
+ const currentWord = words[computed.here.wordIndex] ?? words[0];
+
+ return (
+ <div
+ className={className}
+ role="img"
+ aria-label={`${phrase}: words stretching into vertical motion blur`}
+ style={{
+ position: "absolute",
+ inset: 0,
+ overflow: "hidden",
+ backgroundColor: "#000",
+ }}
+ >
+ <canvas
+ ref={canvasRef}
+ width={width}
+ height={height}
+ style={{
+ display: webGlFailed ? "none" : "block",
+ width: "100%",
+ height: "100%",
+ }}
+ />
+ {webGlFailed ? (
+ <div
+ style={{
+ position: "absolute",
+ inset: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ color: "#fff",
+ fontFamily,
+ fontSize,
+ fontWeight,
+ }}
+ >
+ {currentWord}
+ </div>
+ ) : null}
+ </div>
+ );
+}
diff --git a/src/remotion/canvas-spike-root.tsx b/src/remotion/canvas-spike-root.tsx
index a1cea43c..6ca358db 100644
--- a/src/remotion/canvas-spike-root.tsx
+++ b/src/remotion/canvas-spike-root.tsx
@@ -33,6 +33,8 @@ import { halftonePrintConfig } from "@/registry/remocn/halftone-print/config";
import { hologramConfig } from "@/registry/remocn/hologram/config";
import { particleDissolveConfig } from "@/registry/remocn/particle-dissolve/config";
import { pixelateRegionConfig } from "@/registry/remocn/pixelate-region/config";
+import { RushType } from "@/registry/remocn/rush-type";
+import { rushTypeConfig } from "@/registry/remocn/rush-type/config";
import { securityCamConfig } from "@/registry/remocn/security-cam/config";
import { sustainedGlitchConfig } from "@/registry/remocn/sustained-glitch/config";
import { underwaterRippleConfig } from "@/registry/remocn/underwater-ripple/config";
@@ -84,6 +86,7 @@ const SCENES: Record<
"camera-lens": { Scene: CameraLensExampleScene, config: cameraLensConfig },
"security-cam": { Scene: SecurityCamExampleScene, config: securityCamConfig },
hologram: { Scene: HologramExampleScene, config: hologramConfig },
+ "rush-type": { Scene: RushType, config: rushTypeConfig },
};
function makeStage(Scene: ComponentType) {