Skip to content

🎥 Make videos programmatically with React

remotion.dev/brand: Remove orphaned Element files (#10977)

Igor Samokhovets4c19f46a484f
diff --git a/packages/brand/src/bottom-up-letters.element.tsx b/packages/brand/src/bottom-up-letters.element.tsx
deleted file mode 100644
index ef9be14270..0000000000
--- a/packages/brand/src/bottom-up-letters.element.tsx
+++ /dev/null
@@ -1,235 +0,0 @@
-import { Easing, Interactive, Sequence, interpolate, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from "remotion";
-import { forwardRef, useImperativeHandle, useRef, type ComponentProps } from "react";
-
-interface BottomUpLettersProps {
- text: string;
- staggerDelay?: number;
- distance?: number;
- fontSize?: number;
- color?: string;
- fontWeight?: number;
- speed?: number;
- className?: string;
-}
-
-function BottomUpLettersBase({
- text,
- staggerDelay = 3,
- distance = 46,
- fontSize = 72,
- color = "#171717",
- fontWeight = 600,
- speed = 1,
- className,
-}: BottomUpLettersProps) {
- const frame = useCurrentFrame() * speed;
-
- const chars = Array.from(text);
- const charDurationFrames = 12;
- const charTravelFrames = 7;
-
- return (
- <div
- style={{
- position: "absolute",
- inset: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- background: "transparent",
- }}
- >
- <span
- className={className}
- style={{
- fontSize,
- fontWeight,
- color,
- letterSpacing: "-0.05em",
- fontFamily:
- "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",
- }}
- >
- {chars.map((char, i) => {
- const local = frame - i * staggerDelay;
- const easing = Easing.bezier(0.18, 1, 0.32, 1);
- const opacity = interpolate(local, [0, charDurationFrames], [0, 1], {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing,
- });
- const y = interpolate(local, [0, charTravelFrames], [distance, 0], {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing,
- });
- return (
- <span
- key={i}
- style={{
- display: "inline-block",
- whiteSpace: "pre",
- backfaceVisibility: "hidden",
- transformOrigin: "50% 55%",
- opacity,
- translate: `0 ${y}px`,
- }}
- >
- {char}
- </span>
- );
- })}
- </span>
- </div>
- );
-}
-
-const elementSchema = {
- ...Interactive.baseSchema,
- text: {
- type: "text-content",
- default: "Shift",
- description: "Text",
- },
- staggerDelay: {
- type: "number",
- min: 1,
- max: 12,
- step: 1,
- default: 3,
- description: "Stagger",
- hiddenFromList: false,
- },
- distance: {
- type: "number",
- min: 0,
- max: 120,
- step: 1,
- default: 46,
- description: "Distance",
- hiddenFromList: false,
- },
- fontSize: {
- type: "number",
- min: 12,
- max: 160,
- step: 1,
- default: 72,
- description: "Font size",
- hiddenFromList: false,
- },
- color: {
- type: "color",
- default: "#171717",
- description: "Color",
- },
- fontWeight: {
- type: "enum",
- default: "600",
- variants: {
- "400": {},
- "500": {},
- "600": {},
- "700": {},
- },
- description: "Font weight",
- },
- speed: {
- type: "number",
- default: 1,
- min: 0.25,
- max: 4,
- step: 0.25,
- description: "Speed",
- hiddenFromList: false,
- },
- width: {
- type: "number",
- default: 190,
- min: 10,
- step: 10,
- description: "Width",
- },
- height: {
- type: "number",
- default: 100,
- min: 10,
- step: 10,
- description: "Height",
- },
- ...Interactive.transformSchema,
-} as const satisfies InteractivitySchema;
-
-const ELEMENT_PROP_KEYS = new Set(["text","staggerDelay","distance","fontSize","color","fontWeight","speed"]);
-
-const ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {
- text: "Shift",
- staggerDelay: 3,
- distance: 46,
- fontSize: 72,
- color: "#171717",
- fontWeight: "600",
- speed: 1,
-};
-
-type BottomUpLettersElementProps = InteractiveBaseProps &
- InteractiveTransformProps & { readonly width?: number; readonly height?: number } &
- ComponentProps<typeof BottomUpLettersBase>;
-
-const BottomUpLettersInner = forwardRef<
- HTMLDivElement,
- BottomUpLettersElementProps & { readonly controls: SequenceControls | undefined }
->(({ controls, name, style, width = 190, height = 100, ...rest }, ref) => {
- const outlineRef = useRef<HTMLDivElement>(null);
- useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);
- const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };
- const sequenceProps: Record<string, unknown> = {};
- for (const [key, value] of Object.entries(rest)) {
- if (ELEMENT_PROP_KEYS.has(key)) {
- if (value !== undefined) componentProps[key] = value;
- } else {
- sequenceProps[key] = value;
- }
- }
- return (
- <Sequence
- layout="none"
- {...sequenceProps}
- controls={controls}
- name={name ?? "<BottomUpLetters>"}
- outlineRef={outlineRef}
- >
- <div
- style={{
- position: "absolute",
- inset: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <div
- ref={outlineRef}
- style={{
- position: "relative",
- width,
- height,
- ...style,
- }}
- >
- <BottomUpLettersBase
- {...(componentProps as unknown as ComponentProps<typeof BottomUpLettersBase>)}
- />
- </div>
- </div>
- </Sequence>
- );
-});
-
-export const BottomUpLetters = Interactive.withSchema({
- Component: BottomUpLettersInner,
- componentName: "<BottomUpLetters>",
- componentIdentity: null,
- schema: elementSchema,
- supportsEffects: false,
-});
diff --git a/packages/brand/src/line-by-line-slide.element.tsx b/packages/brand/src/line-by-line-slide.element.tsx
deleted file mode 100644
index 65248a0f05..0000000000
--- a/packages/brand/src/line-by-line-slide.element.tsx
+++ /dev/null
@@ -1,267 +0,0 @@
-import { Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from "remotion";
-import { forwardRef, useImperativeHandle, useRef, type ComponentProps } from "react";
-
-interface LineByLineSlideProps {
- text: string;
- distance?: number;
- fontSize?: number;
- color?: string;
- fontWeight?: number;
- speed?: number;
- className?: string;
-}
-
-function LineByLineSlideBase({
- text,
- distance = 48,
- fontSize = 72,
- color = "#171717",
- fontWeight = 600,
- speed = 1,
- className,
-}: LineByLineSlideProps) {
- const frame = useCurrentFrame() * speed;
- const { durationInFrames } = useVideoConfig();
-
- const lines = text.split("\n");
-
- const enterDur = 27;
- const enterTravel = 14;
- const exitDur = 18;
- const exitTravelFrom = 8;
- const enterStagger = 4;
- const exitStagger = 2;
-
- const enterEasing = Easing.bezier(0.22, 1, 0.36, 1);
- const exitEasing = Easing.bezier(0.64, 0, 0.78, 0);
-
- const enterEnd = enterDur + (lines.length - 1) * enterStagger;
- const exitStart = Math.max(
- enterEnd,
- durationInFrames - exitDur - (lines.length - 1) * exitStagger,
- );
-
- return (
- <div
- style={{
- position: "absolute",
- inset: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- background: "transparent",
- }}
- >
- <span
- className={className}
- style={{
- fontSize,
- fontWeight,
- color,
- letterSpacing: "-0.03em",
- lineHeight: 1.1,
- textAlign: "left",
- fontFamily:
- "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",
- }}
- >
- {lines.map((line, i) => {
- const enterLocal = frame - i * enterStagger;
- const exitLocal = frame - exitStart - i * exitStagger;
-
- const enterP = interpolate(enterLocal, [0, enterDur], [0, 1], {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: enterEasing,
- });
-
- const exitP = interpolate(exitLocal, [0, exitDur], [0, 1], {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: exitEasing,
- });
-
- const opacity = enterP * (1 - exitP);
-
- const xEnter = interpolate(
- enterLocal,
- [0, enterTravel],
- [-distance, 0],
- {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: enterEasing,
- },
- );
-
- const xExit = interpolate(
- exitLocal,
- [exitTravelFrom, exitDur],
- [0, distance],
- {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: exitEasing,
- },
- );
-
- const x = xEnter + xExit;
-
- return (
- <span
- key={i}
- style={{
- display: "block",
- transformOrigin: "0% 50%",
- opacity,
- translate: `${x}px`,
- }}
- >
- {line}
- </span>
- );
- })}
- </span>
- </div>
- );
-}
-
-const elementSchema = {
- ...Interactive.baseSchema,
- text: {
- type: "text-content",
- default: "Think different.\nDo more.",
- description: "Text",
- },
- distance: {
- type: "number",
- min: 0,
- max: 160,
- step: 1,
- default: 48,
- description: "Distance",
- hiddenFromList: false,
- },
- fontSize: {
- type: "number",
- min: 12,
- max: 160,
- step: 1,
- default: 72,
- description: "Font size",
- hiddenFromList: false,
- },
- color: {
- type: "color",
- default: "#171717",
- description: "Color",
- },
- fontWeight: {
- type: "enum",
- default: "600",
- variants: {
- "400": {},
- "500": {},
- "600": {},
- "700": {},
- },
- description: "Font weight",
- },
- speed: {
- type: "number",
- default: 1,
- min: 0.25,
- max: 4,
- step: 0.25,
- description: "Speed",
- hiddenFromList: false,
- },
- width: {
- type: "number",
- default: 600,
- min: 10,
- step: 10,
- description: "Width",
- },
- height: {
- type: "number",
- default: 200,
- min: 10,
- step: 10,
- description: "Height",
- },
- ...Interactive.transformSchema,
-} as const satisfies InteractivitySchema;
-
-const ELEMENT_PROP_KEYS = new Set(["text","distance","fontSize","color","fontWeight","speed"]);
-
-const ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {
- text: "Think different.\nDo more.",
- distance: 48,
- fontSize: 72,
- color: "#171717",
- fontWeight: "600",
- speed: 1,
-};
-
-type LineByLineSlideElementProps = InteractiveBaseProps &
- InteractiveTransformProps & { readonly width?: number; readonly height?: number } &
- ComponentProps<typeof LineByLineSlideBase>;
-
-const LineByLineSlideInner = forwardRef<
- HTMLDivElement,
- LineByLineSlideElementProps & { readonly controls: SequenceControls | undefined }
->(({ controls, name, style, width = 600, height = 200, ...rest }, ref) => {
- const outlineRef = useRef<HTMLDivElement>(null);
- useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);
- const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };
- const sequenceProps: Record<string, unknown> = {};
- for (const [key, value] of Object.entries(rest)) {
- if (ELEMENT_PROP_KEYS.has(key)) {
- if (value !== undefined) componentProps[key] = value;
- } else {
- sequenceProps[key] = value;
- }
- }
- return (
- <Sequence
- layout="none"
- {...sequenceProps}
- controls={controls}
- name={name ?? "<LineByLineSlide>"}
- outlineRef={outlineRef}
- >
- <div
- style={{
- position: "absolute",
- inset: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <div
- ref={outlineRef}
- style={{
- position: "relative",
- width,
- height,
- ...style,
- }}
- >
- <LineByLineSlideBase
- {...(componentProps as unknown as ComponentProps<typeof LineByLineSlideBase>)}
- />
- </div>
- </div>
- </Sequence>
- );
-});
-
-export const LineByLineSlide = Interactive.withSchema({
- Component: LineByLineSlideInner,
- componentName: "<LineByLineSlide>",
- componentIdentity: null,
- schema: elementSchema,
- supportsEffects: false,
-});
diff --git a/packages/brand/src/per-word-crossfade.element.tsx b/packages/brand/src/per-word-crossfade.element.tsx
deleted file mode 100644
index d0b63ef618..0000000000
--- a/packages/brand/src/per-word-crossfade.element.tsx
+++ /dev/null
@@ -1,288 +0,0 @@
-import { Easing, Interactive, Sequence, interpolate, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from "remotion";
-import { forwardRef, useImperativeHandle, useRef, type ComponentProps } from "react";
-
-interface PerWordCrossfadeProps {
- fromText: string;
- toText: string;
- fontSize?: number;
- color?: string;
- fontWeight?: number;
- speed?: number;
- className?: string;
-}
-
-function PerWordCrossfadeBase({
- fromText,
- toText,
- fontSize = 72,
- color = "#171717",
- fontWeight = 600,
- speed = 1,
- className,
-}: PerWordCrossfadeProps) {
- const frame = useCurrentFrame() * speed;
-
- const fromWords = fromText.split(" ");
- const toWords = toText.split(" ");
-
- const enterDur = 21;
- const enterTravel = 5;
- const exitDur = 15;
- const exitTravelFrom = 6;
- const enterStagger = 2;
- const exitStagger = 1;
- const overlapF = 5;
- const microDelayF = 2;
-
- const enterEasing = Easing.bezier(0.16, 1, 0.3, 1);
- const exitEasing = Easing.bezier(0.7, 0, 0.84, 0);
-
- const exitTotal = exitDur + (fromWords.length - 1) * exitStagger;
- const newStart = Math.max(0, exitTotal - overlapF + microDelayF);
-
- const fontStack =
- "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif";
-
- return (
- <div
- className={className}
- style={{
- position: "absolute",
- inset: 0,
- background: "transparent",
- }}
- >
- <div
- style={{
- position: "absolute",
- inset: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <span
- style={{
- fontSize,
- fontWeight,
- color,
- letterSpacing: "-0.03em",
- fontFamily: fontStack,
- }}
- >
- {fromWords.map((word, i) => {
- const local = frame - i * exitStagger;
- const opacity = interpolate(local, [0, exitDur], [1, 0], {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: exitEasing,
- });
- const y = interpolate(local, [exitTravelFrom, exitDur], [0, -6], {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: exitEasing,
- });
- return (
- <span
- key={i}
- style={{
- display: "inline-block",
- marginRight: "0.25em",
- transformOrigin: "50% 55%",
- opacity,
- translate: `0 ${y}px`,
- }}
- >
- {word}
- </span>
- );
- })}
- </span>
- </div>
-
- <div
- style={{
- position: "absolute",
- inset: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <span
- style={{
- fontSize,
- fontWeight,
- color,
- letterSpacing: "-0.03em",
- fontFamily: fontStack,
- }}
- >
- {toWords.map((word, j) => {
- const local = frame - newStart - j * enterStagger;
- const opacity = interpolate(local, [0, enterDur], [0, 1], {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: enterEasing,
- });
- const y = interpolate(local, [0, enterTravel], [8, 0], {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: enterEasing,
- });
- return (
- <span
- key={j}
- style={{
- display: "inline-block",
- marginRight: "0.25em",
- transformOrigin: "50% 55%",
- opacity,
- translate: `0 ${y}px`,
- }}
- >
- {word}
- </span>
- );
- })}
- </span>
- </div>
- </div>
- );
-}
-
-const elementSchema = {
- ...Interactive.baseSchema,
- fromText: {
- type: "text-content",
- default: "Beautifully simple.",
- description: "From text",
- },
- toText: {
- type: "text-content",
- default: "Designed for focus.",
- description: "To text",
- },
- fontSize: {
- type: "number",
- min: 12,
- max: 160,
- step: 1,
- default: 72,
- description: "Font size",
- hiddenFromList: false,
- },
- color: {
- type: "color",
- default: "#171717",
- description: "Color",
- },
- fontWeight: {
- type: "enum",
- default: "600",
- variants: {
- "400": {},
- "500": {},
- "600": {},
- "700": {},
- },
- description: "Font weight",
- },
- speed: {
- type: "number",
- default: 1,
- min: 0.25,
- max: 4,
- step: 0.25,
- description: "Speed",
- hiddenFromList: false,
- },
- width: {
- type: "number",
- default: 720,
- min: 10,
- step: 10,
- description: "Width",
- },
- height: {
- type: "number",
- default: 100,
- min: 10,
- step: 10,
- description: "Height",
- },
- ...Interactive.transformSchema,
-} as const satisfies InteractivitySchema;
-
-const ELEMENT_PROP_KEYS = new Set(["fromText","toText","fontSize","color","fontWeight","speed"]);
-
-const ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {
- fromText: "Beautifully simple.",
- toText: "Designed for focus.",
- fontSize: 72,
- color: "#171717",
- fontWeight: "600",
- speed: 1,
-};
-
-type PerWordCrossfadeElementProps = InteractiveBaseProps &
- InteractiveTransformProps & { readonly width?: number; readonly height?: number } &
- ComponentProps<typeof PerWordCrossfadeBase>;
-
-const PerWordCrossfadeInner = forwardRef<
- HTMLDivElement,
- PerWordCrossfadeElementProps & { readonly controls: SequenceControls | undefined }
->(({ controls, name, style, width = 720, height = 100, ...rest }, ref) => {
- const outlineRef = useRef<HTMLDivElement>(null);
- useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);
- const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };
- const sequenceProps: Record<string, unknown> = {};
- for (const [key, value] of Object.entries(rest)) {
- if (ELEMENT_PROP_KEYS.has(key)) {
- if (value !== undefined) componentProps[key] = value;
- } else {
- sequenceProps[key] = value;
- }
- }
- return (
- <Sequence
- layout="none"
- {...sequenceProps}
- controls={controls}
- name={name ?? "<PerWordCrossfade>"}
- outlineRef={outlineRef}
- >
- <div
- style={{
- position: "absolute",
- inset: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <div
- ref={outlineRef}
- style={{
- position: "relative",
- width,
- height,
- ...style,
- }}
- >
- <PerWordCrossfadeBase
- {...(componentProps as unknown as ComponentProps<typeof PerWordCrossfadeBase>)}
- />
- </div>
- </div>
- </Sequence>
- );
-});
-
-export const PerWordCrossfade = Interactive.withSchema({
- Component: PerWordCrossfadeInner,
- componentName: "<PerWordCrossfade>",
- componentIdentity: null,
- schema: elementSchema,
- supportsEffects: false,
-});
diff --git a/packages/brand/src/word-stream.element.tsx b/packages/brand/src/word-stream.element.tsx
deleted file mode 100644
index 95f69c4443..0000000000
--- a/packages/brand/src/word-stream.element.tsx
+++ /dev/null
@@ -1,338 +0,0 @@
-import { Easing, Interactive, Sequence, interpolate, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from "remotion";
-import { forwardRef, useImperativeHandle, useRef, type ComponentProps } from "react";
-
-interface WordStreamProps {
- text: string;
- fontSize?: number;
- color?: string;
- fontWeight?: number;
- wordGap?: number;
- hold?: number;
- drift?: number;
- speed?: number;
- className?: string;
-}
-
-interface PhraseSchedule {
- words: string[];
- start: number;
- exitStart: number;
- last: boolean;
-}
-
-const REVEAL_FRAMES = 3;
-const ENTRY_FRAMES = 8;
-const RUN_OUT_FRAMES = 5;
-const SWAP_OVERLAP = 0;
-
-function wordStreamLength(text: string, wordGap = 6, hold = 18): number {
- const schedule = schedulePhrases(text, wordGap, hold);
- const finalPhrase = schedule[schedule.length - 1];
- if (!finalPhrase) return 0;
- return (
- finalPhrase.start + (finalPhrase.words.length - 1) * wordGap + REVEAL_FRAMES
- );
-}
-
-function schedulePhrases(
- text: string,
- wordGap: number,
- hold: number,
-): PhraseSchedule[] {
- const phrases = text
- .split("|")
- .map((phrase) => phrase.trim())
- .filter(Boolean);
- let cursor = 0;
- return phrases.map((phrase, i) => {
- const words = phrase.split(/\s+/);
- const start = cursor;
- const complete = start + (words.length - 1) * wordGap + REVEAL_FRAMES;
- const exitStart = complete + hold;
- cursor = exitStart + SWAP_OVERLAP;
- return { words, start, exitStart, last: i === phrases.length - 1 };
- });
-}
-
-const revealEasing = Easing.bezier(0.2, 0.8, 0.2, 1);
-const entryEasing = Easing.bezier(0.2, 0.8, 0.3, 1);
-const runOutEasing = Easing.bezier(0.7, 0, 0.9, 0.4);
-
-function WordStreamBase({
- text,
- fontSize = 72,
- color = "#171717",
- fontWeight = 400,
- wordGap = 6,
- hold = 18,
- drift = 2,
- speed = 1,
- className,
-}: WordStreamProps) {
- const frame = useCurrentFrame() * speed;
-
- const schedule = schedulePhrases(text, wordGap, hold);
-
- return (
- <div
- style={{
- position: "absolute",
- inset: 0,
- background: "transparent",
- }}
- >
- {schedule.map((phrase, i) => {
- if (frame < phrase.start) return null;
- if (!phrase.last && frame >= phrase.exitStart) return null;
-
- const scale = fontSize / 72;
- const crawl = scale * drift;
- const life = phrase.exitStart - phrase.start;
-
- const entryX = interpolate(
- frame,
- [phrase.start, phrase.start + ENTRY_FRAMES],
- [scale * 30, 0],
- {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: entryEasing,
- },
- );
- const crawlX =
- crawl *
- (life / 2 - (Math.min(frame, phrase.exitStart) - phrase.start));
- const runOutX = phrase.last
- ? 0
- : interpolate(
- frame,
- [phrase.exitStart - RUN_OUT_FRAMES, phrase.exitStart],
- [0, -scale * 80],
- {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: runOutEasing,
- },
- );
- const x = entryX + crawlX + runOutX;
-
- return (
- <div
- key={i}
- style={{
- position: "absolute",
- inset: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- whiteSpace: "nowrap",
- translate: `${x}px 0`,
- }}
- >
- <span
- className={className}
- style={{
- fontSize,
- fontWeight,
- color,
- letterSpacing: "-0.02em",
- fontFamily:
- "var(--font-geist-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif)",
- }}
- >
- {phrase.words.map((word, j) => {
- const revealAt = phrase.start + j * wordGap;
-
- const opacity = interpolate(
- frame,
- [revealAt, revealAt + REVEAL_FRAMES],
- [0, 1],
- {
- extrapolateLeft: "clamp",
- extrapolateRight: "clamp",
- easing: revealEasing,
- },
- );
-
- return (
- <span
- key={j}
- style={{
- display: "inline-block",
- whiteSpace: "pre",
- marginRight:
- j < phrase.words.length - 1 ? "0.28em" : undefined,
- opacity,
- }}
- >
- {word}
- </span>
- );
- })}
- </span>
- </div>
- );
- })}
- </div>
- );
-}
-
-const elementSchema = {
- ...Interactive.baseSchema,
- text: {
- type: "text-content",
- default: "introducing | one-tap checkout | for your store",
- description: "Phrases (| separated)",
- },
- fontSize: {
- type: "number",
- min: 12,
- max: 160,
- step: 1,
- default: 72,
- description: "Font size",
- hiddenFromList: false,
- },
- wordGap: {
- type: "number",
- min: 2,
- max: 30,
- step: 1,
- default: 6,
- description: "Frames / word",
- hiddenFromList: false,
- },
- hold: {
- type: "number",
- min: 6,
- max: 90,
- step: 3,
- default: 18,
- description: "Phrase hold",
- hiddenFromList: false,
- },
- drift: {
- type: "number",
- min: 0,
- max: 6,
- step: 0.5,
- default: 2,
- description: "Drift px / frame",
- hiddenFromList: false,
- },
- color: {
- type: "color",
- default: "#171717",
- description: "Color",
- },
- fontWeight: {
- type: "enum",
- default: "400",
- variants: {
- "400": {},
- "500": {},
- "600": {},
- "700": {},
- },
- description: "Font weight",
- },
- speed: {
- type: "number",
- default: 1,
- min: 0.25,
- max: 4,
- step: 0.25,
- description: "Speed",
- hiddenFromList: false,
- },
- width: {
- type: "number",
- default: 700,
- min: 10,
- step: 10,
- description: "Width",
- },
- height: {
- type: "number",
- default: 110,
- min: 10,
- step: 10,
- description: "Height",
- },
- ...Interactive.transformSchema,
-} as const satisfies InteractivitySchema;
-
-const ELEMENT_PROP_KEYS = new Set(["text","fontSize","wordGap","hold","drift","color","fontWeight","speed"]);
-
-const ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {
- text: "introducing | one-tap checkout | for your store",
- fontSize: 72,
- wordGap: 6,
- hold: 18,
- drift: 2,
- color: "#171717",
- fontWeight: "400",
- speed: 1,
-};
-
-type WordStreamElementProps = InteractiveBaseProps &
- InteractiveTransformProps & { readonly width?: number; readonly height?: number } &
- ComponentProps<typeof WordStreamBase>;
-
-const WordStreamInner = forwardRef<
- HTMLDivElement,
- WordStreamElementProps & { readonly controls: SequenceControls | undefined }
->(({ controls, name, style, width = 700, height = 110, ...rest }, ref) => {
- const outlineRef = useRef<HTMLDivElement>(null);
- useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);
- const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };
- const sequenceProps: Record<string, unknown> = {};
- for (const [key, value] of Object.entries(rest)) {
- if (ELEMENT_PROP_KEYS.has(key)) {
- if (value !== undefined) componentProps[key] = value;
- } else {
- sequenceProps[key] = value;
- }
- }
- return (
- <Sequence
- layout="none"
- {...sequenceProps}
- controls={controls}
- name={name ?? "<WordStream>"}
- outlineRef={outlineRef}
- >
- <div
- style={{
- position: "absolute",
- inset: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <div
- ref={outlineRef}
- style={{
- position: "relative",
- width,
- height,
- ...style,
- }}
- >
- <WordStreamBase
- {...(componentProps as unknown as ComponentProps<typeof WordStreamBase>)}
- />
- </div>
- </div>
- </Sequence>
- );
-});
-
-export const WordStream = Interactive.withSchema({
- Component: WordStreamInner,
- componentName: "<WordStream>",
- componentIdentity: null,
- schema: elementSchema,
- supportsEffects: false,
-});