Skip to content

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

feat: create telegram, imessage chat

dev_wandry6a0c172f3418
diff --git a/components/docs/examples/blocks/index.tsx b/components/docs/examples/blocks/index.tsx
index 41150404..9da90bfa 100644
--- a/components/docs/examples/blocks/index.tsx
+++ b/components/docs/examples/blocks/index.tsx
@@ -25,6 +25,14 @@ import {
ChatFlowExampleScene,
chatFlowExampleCode,
} from "../chat-flow-example";
+import {
+ TelegramChatFlowExampleScene,
+ telegramChatFlowExampleCode,
+} from "../telegram-chat-flow-example";
+import {
+ ImessageChatFlowExampleScene,
+ imessageChatFlowExampleCode,
+} from "../imessage-chat-flow-example";
import {
BackdropColorScene,
BackdropGradientScene,
@@ -99,6 +107,29 @@ export const blockExamples: Record<string, BlockExampleEntry> = {
height: 768,
previewBackdrop: { type: "color", value: "oklch(1 0 0)" },
},
+ "telegram-chat-flow": {
+ Component: TelegramChatFlowExampleScene,
+ code: telegramChatFlowExampleCode,
+ // Same 3-message schedule as chat-flow: ~314 + ~28 tail then loop.
+ durationInFrames: 360,
+ fps: FPS,
+ width: 432,
+ height: 768,
+ previewBackdrop: {
+ type: "gradient",
+ value: "linear-gradient(180deg, #cfe0ec 0%, #a7c6e0 100%)",
+ },
+ },
+ "imessage-chat-flow": {
+ Component: ImessageChatFlowExampleScene,
+ code: imessageChatFlowExampleCode,
+ // Same 3-message schedule: ~314 + ~28 tail then loop.
+ durationInFrames: 360,
+ fps: FPS,
+ width: 432,
+ height: 768,
+ previewBackdrop: { type: "color", value: "#ffffff" },
+ },
"checkout-flow": {
Component: CheckoutFlowExampleScene,
code: checkoutFlowExampleCode,
@@ -189,6 +220,8 @@ export const BLOCK_SCENE_META: Record<
"signup-flow": { code: signupFlowExampleCode },
"ai-prompt-flow": { code: aiPromptFlowExampleCode },
"chat-flow": { code: chatFlowExampleCode },
+ "telegram-chat-flow": { code: telegramChatFlowExampleCode },
+ "imessage-chat-flow": { code: imessageChatFlowExampleCode },
"checkout-flow": { code: checkoutFlowExampleCode },
"onboarding-stepper-flow": { code: onboardingStepperFlowExampleCode },
"settings-toggle-flow": { code: settingsToggleFlowExampleCode },
diff --git a/components/docs/examples/imessage-chat-flow-example.tsx b/components/docs/examples/imessage-chat-flow-example.tsx
new file mode 100644
index 00000000..6c6626e9
--- /dev/null
+++ b/components/docs/examples/imessage-chat-flow-example.tsx
@@ -0,0 +1,24 @@
+"use client";
+
+import { ImessageChatFlow } from "@/registry/remocn-ui/imessage-chat-flow";
+
+export const ImessageChatFlowExampleScene = () => (
+ <ImessageChatFlow
+ contact={{ name: "shadcn", avatar: "https://unavatar.io/x/shadcn" }}
+ />
+);
+
+export const imessageChatFlowExampleCode = (): string => {
+ return `import { ImessageChatFlow } from "@/components/remocn/imessage-chat-flow";
+
+export const Scene = () => (
+ <ImessageChatFlow
+ contact={{ name: "shadcn", avatar: "https://unavatar.io/x/shadcn" }}
+ messages={[
+ { from: "me", text: "Hey — ready for the demo?" },
+ { from: "them", text: "Yep, pushing it live now", reaction: "❤️" },
+ { from: "me", text: "Perfect, sending the link over", reaction: "👍" },
+ ]}
+ />
+);`;
+};
diff --git a/components/docs/examples/telegram-chat-flow-example.tsx b/components/docs/examples/telegram-chat-flow-example.tsx
new file mode 100644
index 00000000..8e953908
--- /dev/null
+++ b/components/docs/examples/telegram-chat-flow-example.tsx
@@ -0,0 +1,24 @@
+"use client";
+
+import { TelegramChatFlow } from "@/registry/remocn-ui/telegram-chat-flow";
+
+export const TelegramChatFlowExampleScene = () => (
+ <TelegramChatFlow
+ contact={{ name: "shadcn", avatar: "https://unavatar.io/x/shadcn" }}
+ />
+);
+
+export const telegramChatFlowExampleCode = (): string => {
+ return `import { TelegramChatFlow } from "@/components/remocn/telegram-chat-flow";
+
+export const Scene = () => (
+ <TelegramChatFlow
+ contact={{ name: "shadcn", avatar: "https://unavatar.io/x/shadcn" }}
+ messages={[
+ { from: "me", text: "Hey — ready for the demo?", time: "9:40" },
+ { from: "them", text: "Yep, pushing it live now", reaction: "🔥", time: "9:41" },
+ { from: "me", text: "Perfect, sending the link over", reaction: "👍", time: "9:41" },
+ ]}
+ />
+);`;
+};
diff --git a/content/docs/ui/blocks/imessage-chat-flow.mdx b/content/docs/ui/blocks/imessage-chat-flow.mdx
new file mode 100644
index 00000000..6e78c654
--- /dev/null
+++ b/content/docs/ui/blocks/imessage-chat-flow.mdx
@@ -0,0 +1,60 @@
+---
+title: iMessage Chat Flow
+description: iMessage-styled conversation with gray incoming and blue outgoing bubbles, typing indicator, Delivered label, and tapback reactions
+---
+
+<BlockPreview name="imessage-chat-flow" />
+
+An iMessage-skinned composition scene — a tailed-bubble message thread, a native-feeling composer bar, and a contact header with FaceTime video icon. Outgoing messages type into the composer then send as blue tailed bubbles with a "Delivered" label underneath; incoming replies are preceded by a gray typing bubble (three bouncing dots) that swaps to the reply text; tapback reaction badges pop in at the top outer corner of their parent bubble.
+
+## Installation
+
+<InstallBlock name="imessage-chat-flow" />
+
+<Note>
+Installing `imessage-chat-flow` automatically installs the shared `remocn-ui` core and all composed primitives via `registryDependencies`: `caret`, and `typing-indicator`. You do not need to install them separately. The block also pulls `lucide-react` for chrome icons (back chevron, FaceTime video button, composer apps-plus, and up-arrow send button).
+</Note>
+
+## Composed primitives
+
+- **Caret** — blinking caret inside the composer text field; outgoing text reveals character by character before sending
+- **TypingIndicator** — three bouncing dots rendered inside a gray incoming bubble before the reply text arrives
+
+The block is otherwise self-contained: it owns its tailed bubble layout (gray `#e9e9eb` for incoming, iMessage blue for outgoing), the "Delivered" delivery label under the last outgoing bubble, tapback reaction badges at the top outer corner of each bubble, the composer bar (apps-plus icon + text field + circular up-arrow send button), and the contact header with avatar, display name, and lucide-react chrome icons.
+
+## Timeline narrative
+
+The scene opens with a focused iMessage composer. The first outgoing message types into the input field, then sends — a blue tailed bubble enters from below and settles into the thread with a "Delivered" label underneath. A gray typing bubble with three bouncing dots appears on the incoming side; after a beat the dots swap to the reply text and the tapback reaction badge pops in at the top outer corner. Subsequent outgoing messages follow the same pattern — typing, sending, Delivered — each reply preceded by the typing bubble. The composer returns to idle at the end.
+
+## Props
+
+<PropsTable
+ rows={[
+ {
+ name: "messages",
+ type: "ImessageMessage[]",
+ description: "Array of messages to animate. Each item has {from: 'me' | 'them', text: string, reaction?: string}. Defaults to the built-in demo script.",
+ },
+ {
+ name: "contact",
+ type: "{ name: string; avatar?: string }",
+ description: "Display name and optional avatar URL shown in the contact header.",
+ },
+ {
+ name: "accentColor",
+ type: "string",
+ description: "Override for the outgoing bubble color and send button. Defaults to iMessage blue. Accepts any concrete color value (oklch, hex, rgb).",
+ },
+ {
+ name: "speed",
+ type: "number",
+ default: "1",
+ description: "Multiplier on the overall animation speed. Values above 1 speed up the whole conversation; below 1 slow it down.",
+ },
+ {
+ name: "theme",
+ type: "RemocnTheme",
+ description: "Optional theme override (concrete oklch/hex/rgb values).",
+ },
+ ]}
+/>
diff --git a/content/docs/ui/blocks/index.mdx b/content/docs/ui/blocks/index.mdx
index 49d5731d..6ec5ab7b 100644
--- a/content/docs/ui/blocks/index.mdx
+++ b/content/docs/ui/blocks/index.mdx
@@ -13,6 +13,18 @@ Complete, shippable video compositions built from remocn-ui primitives. Each blo
status: "stable",
href: "/docs/ui/blocks/chat-flow",
},
+ {
+ name: "TelegramChatFlow",
+ description: "Telegram-styled conversation with tailed bubbles, delivery checks, typing status, and reaction chips",
+ status: "stable",
+ href: "/docs/ui/blocks/telegram-chat-flow",
+ },
+ {
+ name: "ImessageChatFlow",
+ description: "iMessage-styled conversation with gray incoming and blue outgoing bubbles, typing indicator, Delivered label, and tapback reactions",
+ status: "stable",
+ href: "/docs/ui/blocks/imessage-chat-flow",
+ },
{
name: "SignupFlow",
description: "Account creation with email input, agreement, and success toast",
diff --git a/content/docs/ui/blocks/meta.json b/content/docs/ui/blocks/meta.json
index 16e0746c..4b418ddb 100644
--- a/content/docs/ui/blocks/meta.json
+++ b/content/docs/ui/blocks/meta.json
@@ -1,5 +1,5 @@
{
"title": "Blocks",
"collapsible": false,
- "pages": ["index", "chat-flow", "signup-flow", "checkout-flow", "settings-toggle-flow"]
+ "pages": ["index", "chat-flow", "telegram-chat-flow", "imessage-chat-flow", "signup-flow", "checkout-flow", "settings-toggle-flow"]
}
diff --git a/content/docs/ui/blocks/telegram-chat-flow.mdx b/content/docs/ui/blocks/telegram-chat-flow.mdx
new file mode 100644
index 00000000..48fa7b3c
--- /dev/null
+++ b/content/docs/ui/blocks/telegram-chat-flow.mdx
@@ -0,0 +1,59 @@
+---
+title: Telegram Chat Flow
+description: Telegram-styled conversation with tailed bubbles, delivery checks, typing status, and reaction chips
+---
+
+<BlockPreview name="telegram-chat-flow" />
+
+A Telegram-skinned composition scene — a tailed-bubble message thread, a Telegram-style composer pill, and a contact header that flips to "typing…" while the other side replies. Outgoing messages type into the composer then send with blue double-check delivery marks; incoming replies are preceded by a "typing…" status in the header before the bubble arrives; reaction chips pop in after each message lands.
+
+## Installation
+
+<InstallBlock name="telegram-chat-flow" />
+
+<Note>
+Installing `telegram-chat-flow` automatically installs the shared `remocn-ui` core and all composed primitives via `registryDependencies`: `caret`. You do not need to install them separately.
+</Note>
+
+## Composed primitives
+
+- **Caret** — blinking caret inside the Telegram composer pill; outgoing text reveals character by character before sending
+
+The block is otherwise self-contained: it owns its tailed bubble layout, in-bubble timestamps, delivery-check marks, reaction chips, the composer pill (emoji + text field + attach icon + blue circular send button), and the contact header with avatar and typing-status logic.
+
+## Timeline narrative
+
+The scene opens with a focused Telegram composer. The first outgoing message types into the input pill, then sends — a blue tailed bubble enters from below and settles into the thread, its timestamp and double-check marks visible inside the bubble. The contact header switches to "typing…"; after a beat the reply bubble arrives (white, left-tailed) and a reaction chip pops in beneath it. The second outgoing message follows the same pattern, sending with delivery checks and its own reaction. The composer returns to idle.
+
+## Props
+
+<PropsTable
+ rows={[
+ {
+ name: "messages",
+ type: "TelegramMessage[]",
+ description: "Array of messages to animate. Each item has {from: 'me' | 'them', text: string, reaction?: string, time?: string}. Defaults to the built-in demo script.",
+ },
+ {
+ name: "contact",
+ type: "{ name: string; avatar?: string }",
+ description: "Display name and optional avatar URL shown in the contact header.",
+ },
+ {
+ name: "accentColor",
+ type: "string",
+ description: "Override for the outgoing bubble color and send button. Defaults to Telegram blue. Accepts any concrete color value (oklch, hex, rgb).",
+ },
+ {
+ name: "speed",
+ type: "number",
+ default: "1",
+ description: "Multiplier on the overall animation speed. Values above 1 speed up the whole conversation; below 1 slow it down.",
+ },
+ {
+ name: "theme",
+ type: "RemocnTheme",
+ description: "Optional theme override (concrete oklch/hex/rgb values).",
+ },
+ ]}
+/>
diff --git a/registry/remocn-ui/imessage-chat-flow/__tests__/imessage-chat-flow.test.ts b/registry/remocn-ui/imessage-chat-flow/__tests__/imessage-chat-flow.test.ts
new file mode 100644
index 00000000..055bb1d9
--- /dev/null
+++ b/registry/remocn-ui/imessage-chat-flow/__tests__/imessage-chat-flow.test.ts
@@ -0,0 +1,189 @@
+
+import { describe, expect, it } from "bun:test";
+import {
+ imessageChatFlowSchedule,
+ imessageChatFlowDuration,
+ sendPulse,
+ type ImessageMessage,
+} from "../index";
+
+const MESSAGES: ImessageMessage[] = [
+ { from: "me", text: "hi" },
+ { from: "them", text: "yo", reaction: "❤️" },
+];
+
+describe("imessageChatFlowSchedule: items length", () => {
+ it("returns 2 items for 2 messages", () => {
+ const { items } = imessageChatFlowSchedule(MESSAGES);
+ expect(items.length).toBe(2);
+ });
+});
+
+describe("imessageChatFlowSchedule: item 0 (from='me', text='hi')", () => {
+ const { items } = imessageChatFlowSchedule(MESSAGES);
+ const item0 = items[0];
+
+ it("from is 'me'", () => {
+ expect(item0.from).toBe("me");
+ });
+
+ it("typeStart is 12 (LEAD_IN)", () => {
+ expect(item0.typeStart).toBe(12);
+ });
+
+ it("sendAt is 40 (typeStart + MIN_TYPE + SEND_GAP = 12 + 18 + 10)", () => {
+ expect(item0.sendAt).toBe(40);
+ });
+
+ it("revealAt equals sendAt (40)", () => {
+ expect(item0.revealAt).toBe(40);
+ expect(item0.revealAt).toBe(item0.sendAt);
+ });
+
+ it("presenceStart equals sendAt - 2 (38)", () => {
+ expect(item0.presenceStart).toBe(38);
+ expect(item0.presenceStart).toBe((item0.sendAt ?? 0) - 2);
+ });
+
+ it("reaction is undefined (no reaction)", () => {
+ expect(item0.reaction).toBeUndefined();
+ });
+
+ it("reactAt is undefined (no reaction)", () => {
+ expect(item0.reactAt).toBeUndefined();
+ });
+});
+
+describe("imessageChatFlowSchedule: item 1 (from='them', text='yo', reaction='❤️')", () => {
+ const { items } = imessageChatFlowSchedule(MESSAGES);
+ const item1 = items[1];
+
+ it("from is 'them'", () => {
+ expect(item1.from).toBe("them");
+ });
+
+ it("typingStart is 72 (after item 0 window)", () => {
+ expect(item1.typingStart).toBe(72);
+ });
+
+ it("revealAt is 106 (typingStart + TYPING_MIN = 72 + 34)", () => {
+ expect(item1.revealAt).toBe(106);
+ });
+
+ it("revealAt equals typingStart + typingDur (72 + 34)", () => {
+ expect(item1.revealAt).toBe((item1.typingStart ?? 0) + 34);
+ });
+
+ it("reactAt is 128 (revealAt + REVEAL + REACT_DELAY = 106 + 14 + 8)", () => {
+ expect(item1.reactAt).toBe(128);
+ });
+
+ it("reaction is '❤️'", () => {
+ expect(item1.reaction).toBe("❤️");
+ });
+
+ it("presenceStart equals typingStart (72) — iMessage in-thread typing bubble", () => {
+ expect(item1.presenceStart).toBe(72);
+ expect(item1.presenceStart).toBe(item1.typingStart);
+ });
+});
+
+describe("imessageChatFlowSchedule: monotonic ordering", () => {
+ const { items } = imessageChatFlowSchedule(MESSAGES);
+
+ it("item1.typingStart >= item0.revealAt", () => {
+ expect(items[1].typingStart ?? 0).toBeGreaterThanOrEqual(items[0].revealAt);
+ });
+
+ it("item1.revealAt > item0.revealAt", () => {
+ expect(items[1].revealAt).toBeGreaterThan(items[0].revealAt);
+ });
+
+ it("item1.reactAt > item1.revealAt", () => {
+ expect(items[1].reactAt ?? 0).toBeGreaterThan(items[1].revealAt);
+ });
+});
+
+describe("imessageChatFlowSchedule: duration", () => {
+ const { duration } = imessageChatFlowSchedule(MESSAGES);
+
+ it("duration is a positive integer", () => {
+ expect(duration).toBeGreaterThan(0);
+ expect(Number.isInteger(duration)).toBe(true);
+ });
+
+ it("duration is 170 (cursor 160 - MSG_GAP 18 + TAIL 28)", () => {
+ expect(duration).toBe(170);
+ });
+
+ it("duration is greater than all revealAt values", () => {
+ const { items } = imessageChatFlowSchedule(MESSAGES);
+ for (const item of items) {
+ expect(duration).toBeGreaterThan(item.revealAt);
+ }
+ });
+});
+
+describe("imessageChatFlowDuration", () => {
+ it("imessageChatFlowDuration(messages) with default speed=1 equals schedule duration (170)", () => {
+ expect(imessageChatFlowDuration(MESSAGES)).toBe(170);
+ });
+
+ it("imessageChatFlowDuration(messages) equals imessageChatFlowSchedule(messages).duration", () => {
+ expect(imessageChatFlowDuration(MESSAGES)).toBe(
+ imessageChatFlowSchedule(MESSAGES).duration,
+ );
+ });
+
+ it("imessageChatFlowDuration(messages, 2) equals Math.ceil(schedule.duration / 2)", () => {
+ const raw = imessageChatFlowSchedule(MESSAGES).duration;
+ expect(imessageChatFlowDuration(MESSAGES, 2)).toBe(Math.ceil(raw / 2));
+ });
+
+ it("imessageChatFlowDuration(messages, 2) is 85", () => {
+ expect(imessageChatFlowDuration(MESSAGES, 2)).toBe(85);
+ });
+});
+
+describe("sendPulse: at sendAt of a 'me' item (eff === sendAt)", () => {
+ const { items } = imessageChatFlowSchedule(MESSAGES);
+
+ it("sendPulse equals 1 when eff exactly equals sendAt (40)", () => {
+ expect(sendPulse(items, 40)).toBeCloseTo(1, 10);
+ });
+});
+
+describe("sendPulse: far from any sendAt", () => {
+ const { items } = imessageChatFlowSchedule(MESSAGES);
+
+ it("sendPulse is 0 when eff is 100 frames away from the only sendAt", () => {
+ expect(sendPulse(items, 140)).toBe(0);
+ });
+
+ it("sendPulse is 0 at eff=0 (before any sendAt and outside PRESS_WINDOW)", () => {
+ expect(sendPulse(items, 0)).toBe(0);
+ });
+});
+
+describe("sendPulse: partial pulse within PRESS_WINDOW", () => {
+ const { items } = imessageChatFlowSchedule(MESSAGES);
+
+ it("sendPulse is > 0 and < 1 when eff is within 7 frames of sendAt", () => {
+ expect(sendPulse(items, 43)).toBeGreaterThan(0);
+ expect(sendPulse(items, 43)).toBeLessThan(1);
+ });
+
+ it("sendPulse is 0 when eff is exactly PRESS_WINDOW+1 frames past sendAt", () => {
+ expect(sendPulse(items, 48)).toBe(0);
+ });
+});
+
+describe("imessageChatFlowSchedule: empty messages", () => {
+ it("returns empty items array", () => {
+ expect(imessageChatFlowSchedule([]).items).toEqual([]);
+ });
+
+ it("duration is positive (LEAD_IN + TAIL)", () => {
+ expect(imessageChatFlowSchedule([]).duration).toBeGreaterThan(0);
+ });
+});
diff --git a/registry/remocn-ui/imessage-chat-flow/index.tsx b/registry/remocn-ui/imessage-chat-flow/index.tsx
new file mode 100644
index 00000000..4894990a
--- /dev/null
+++ b/registry/remocn-ui/imessage-chat-flow/index.tsx
@@ -0,0 +1,571 @@
+"use client";
+
+import {
+ interpolate,
+ spring,
+ useCurrentFrame,
+ useVideoConfig,
+} from "remotion";
+import { ArrowUp, ChevronLeft, Plus, Video } from "lucide-react";
+import { type RemocnTheme, revealedText } from "@/lib/remocn-ui";
+import { Caret } from "@/components/remocn/caret";
+import { TypingIndicator } from "@/components/remocn/typing-indicator";
+
+export interface ImessageMessage {
+ from: "me" | "them";
+ text: string;
+ reaction?: string;
+}
+
+export interface ImessageContact {
+ name: string;
+ avatar?: string;
+}
+
+export interface ImessageChatFlowProps {
+ messages?: ImessageMessage[];
+ contact?: ImessageContact;
+ accentColor?: string;
+ speed?: number;
+ theme?: Partial<RemocnTheme>;
+}
+
+const MOBILE_WIDTH = 460;
+const LEAD_IN = 12;
+const FRAMES_PER_CHAR = 2.2;
+const MIN_TYPE = 18;
+const MAX_TYPE = 86;
+const SEND_GAP = 10;
+const REVEAL = 14;
+const REACT_DELAY = 8;
+const REACT_DUR = 14;
+const MSG_GAP = 18;
+const TYPING_MIN = 34;
+const TYPING_MAX = 70;
+const TAIL = 28;
+const PRESS_WINDOW = 7;
+
+const IMESSAGE_BLUE = "#0a7cff";
+const SYSTEM_BLUE = "#007aff";
+const INCOMING_BG = "#e9e9eb";
+const INCOMING_FG = "#000000";
+const OUTGOING_FG = "#ffffff";
+const META_GRAY = "#8e8e93";
+
+const DEFAULT_MESSAGES: ImessageMessage[] = [
+ { from: "me", text: "Hey — ready for the demo?" },
+ { from: "them", text: "Yep, pushing it live now", reaction: "❤️" },
+ { from: "me", text: "Perfect, sending the link over", reaction: "👍" },
+];
+
+function clamp(value: number, lo: number, hi: number): number {
+ return Math.max(lo, Math.min(hi, value));
+}
+
+export interface ScheduledMessage {
+ index: number;
+ from: "me" | "them";
+ text: string;
+ reaction?: string;
+ presenceStart: number;
+ typeStart?: number;
+ sendAt?: number;
+ typingStart?: number;
+ revealAt: number;
+ reactAt?: number;
+}
+
+export interface ImessageChatFlowSchedule {
+ items: ScheduledMessage[];
+ duration: number;
+}
+
+export function imessageChatFlowSchedule(
+ messages: ImessageMessage[],
+): ImessageChatFlowSchedule {
+ const items: ScheduledMessage[] = [];
+ let cursor = LEAD_IN;
+
+ messages.forEach((message, index) => {
+ const hasReaction = message.reaction !== undefined && message.reaction !== "";
+ if (message.from === "me") {
+ const typeStart = cursor;
+ const typeDur = clamp(
+ Math.round(message.text.length * FRAMES_PER_CHAR),
+ MIN_TYPE,
+ MAX_TYPE,
+ );
+ const sendAt = typeStart + typeDur + SEND_GAP;
+ const revealAt = sendAt;
+ const reactAt = hasReaction ? revealAt + REVEAL + REACT_DELAY : undefined;
+ items.push({
+ index,
+ from: "me",
+ text: message.text,
+ reaction: hasReaction ? message.reaction : undefined,
+ presenceStart: sendAt - 2,
+ typeStart,
+ sendAt,
+ revealAt,
+ reactAt,
+ });
+ cursor =
+ revealAt + REVEAL + (hasReaction ? REACT_DELAY + REACT_DUR : 0) + MSG_GAP;
+ } else {
+ const typingStart = cursor;
+ const typingDur = clamp(
+ Math.round(message.text.length * FRAMES_PER_CHAR),
+ TYPING_MIN,
+ TYPING_MAX,
+ );
+ const revealAt = typingStart + typingDur;
+ const reactAt = hasReaction ? revealAt + REVEAL + REACT_DELAY : undefined;
+ items.push({
+ index,
+ from: "them",
+ text: message.text,
+ reaction: hasReaction ? message.reaction : undefined,
+ presenceStart: typingStart,
+ typingStart,
+ revealAt,
+ reactAt,
+ });
+ cursor =
+ revealAt + REVEAL + (hasReaction ? REACT_DELAY + REACT_DUR : 0) + MSG_GAP;
+ }
+ });
+
+ const duration = Math.max(cursor - MSG_GAP + TAIL, LEAD_IN + TAIL);
+ return { items, duration };
+}
+
+export function imessageChatFlowDuration(
+ messages: ImessageMessage[] = DEFAULT_MESSAGES,
+ speed = 1,
+): number {
+ const raw = imessageChatFlowSchedule(messages).duration;
+ return Math.ceil(raw / (speed <= 0 ? 1 : speed));
+}
+
+export function sendPulse(items: ScheduledMessage[], eff: number): number {
+ let best = 0;
+ for (const item of items) {
+ if (item.sendAt === undefined) continue;
+ const distance = Math.abs(eff - item.sendAt);
+ if (distance <= PRESS_WINDOW) {
+ best = Math.max(best, 1 - distance / PRESS_WINDOW);
+ }
+ }
+ return best;
+}
+
+function Avatar({ contact, size }: { contact: ImessageContact; size: number }) {
+ const initial = contact.name.trim().charAt(0).toUpperCase();
+ return (
+ <div
+ style={{
+ flexShrink: 0,
+ width: size,
+ height: size,
+ minWidth: size,
+ borderRadius: "50%",
+ overflow: "hidden",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ background: "linear-gradient(180deg, #b8c0c9 0%, #8e99a4 100%)",
+ color: "#ffffff",
+ fontSize: size * 0.42,
+ fontWeight: 600,
+ fontFamily:
+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",
+ }}
+ >
+ {contact.avatar !== undefined ? (
+ <img
+ src={contact.avatar}
+ alt={contact.name}
+ style={{ width: "100%", height: "100%", objectFit: "cover" }}
+ />
+ ) : (
+ initial
+ )}
+ </div>
+ );
+}
+
+function BubbleTail({ side, color }: { side: "left" | "right"; color: string }) {
+ const path =
+ side === "right"
+ ? "M0 0 C2 8 6 12 12 13 C7 14 1 13 0 8 Z"
+ : "M13 0 C11 8 7 12 1 13 C6 14 12 13 13 8 Z";
+ return (
+ <svg
+ width={13}
+ height={14}
+ viewBox="0 0 13 14"
+ style={{
+ position: "absolute",
+ bottom: 0,
+ left: side === "left" ? -5 : undefined,
+ right: side === "right" ? -5 : undefined,
+ }}
+ >
+ <path d={path} fill={color} />
+ </svg>
+ );
+}
+
+export function ImessageChatFlow({
+ messages = DEFAULT_MESSAGES,
+ contact,
+ accentColor,
+ speed = 1,
+}: ImessageChatFlowProps) {
+ const frame = useCurrentFrame();
+ const eff = frame * speed;
+ const accent = accentColor ?? IMESSAGE_BLUE;
+
+ const { items } = imessageChatFlowSchedule(messages);
+
+ const activeMe = items.find(
+ (item) =>
+ item.from === "me" &&
+ item.typeStart !== undefined &&
+ item.sendAt !== undefined &&
+ eff >= item.typeStart &&
+ eff < item.sendAt,
+ );
+ let composerText = "";
+ let typing = false;
+ if (
+ activeMe &&
+ activeMe.typeStart !== undefined &&
+ activeMe.sendAt !== undefined
+ ) {
+ const typeDur = Math.max(activeMe.sendAt - SEND_GAP - activeMe.typeStart, 1);
+ const progress = clamp((eff - activeMe.typeStart) / typeDur, 0, 1);
+ composerText = revealedText(
+ activeMe.text,
+ Math.floor(progress * activeMe.text.length),
+ );
+ typing = true;
+ }
+
+ const sendActive = composerText.length > 0;
+ const sendScale = 1 - 0.16 * sendPulse(items, eff);
+ const present = items.filter((item) => eff >= item.presenceStart);
+
+ let lastMeIndex = -1;
+ items.forEach((item) => {
+ if (item.from === "me") lastMeIndex = item.index;
+ });
+ const deliveredIndex =
+ lastMeIndex === messages.length - 1 ? lastMeIndex : -1;
+
+ return (
+ <div
+ style={{
+ position: "relative",
+ width: "100%",
+ height: "100%",
+ display: "flex",
+ justifyContent: "center",
+ background: "transparent",
+ fontFamily:
+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ width: "100%",
+ maxWidth: MOBILE_WIDTH,
+ height: "100%",
+ boxSizing: "border-box",
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ alignItems: "center",
+ gap: 6,
+ padding: "10px 12px",
+ background: "rgba(255,255,255,0.82)",
+ backdropFilter: "blur(12px)",
+ borderBottom: "1px solid rgba(0,0,0,0.08)",
+ }}
+ >
+ <ChevronLeft size={28} color={SYSTEM_BLUE} strokeWidth={2.25} />
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ gap: 2,
+ flex: 1,
+ }}
+ >
+ {contact !== undefined && <Avatar contact={contact} size={30} />}
+ <span
+ style={{
+ fontSize: 12,
+ fontWeight: 600,
+ color: "#000000",
+ }}
+ >
+ {contact?.name ?? "Chat"}
+ </span>
+ </div>
+ <Video size={24} color={SYSTEM_BLUE} strokeWidth={2} />
+ </div>
+
+ <div
+ style={{
+ position: "relative",
+ flex: 1,
+ minHeight: 0,
+ overflow: "hidden",
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ justifyContent: "flex-end",
+ gap: 18,
+ minHeight: "100%",
+ padding: "16px 14px 12px",
+ }}
+ >
+ {present.map((item) => (
+ <ImessageRow
+ key={item.index}
+ item={item}
+ eff={eff}
+ contact={contact}
+ accent={accent}
+ showDelivered={item.index === deliveredIndex}
+ />
+ ))}
+ </div>
+ </div>
+
+ <div
+ style={{
+ display: "flex",
+ alignItems: "flex-end",
+ gap: 8,
+ padding: "8px 12px 12px",
+ }}
+ >
+ <div
+ style={{
+ width: 34,
+ height: 34,
+ borderRadius: "50%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ background: "#e9e9eb",
+ }}
+ >
+ <Plus size={22} color="#3c3c43" strokeWidth={2} />
+ </div>
+ <div
+ style={{
+ flex: 1,
+ display: "flex",
+ alignItems: "center",
+ gap: 6,
+ minHeight: 36,
+ padding: "0 6px 0 14px",
+ borderRadius: 18,
+ border: "1px solid #d1d1d6",
+ background: "#ffffff",
+ }}
+ >
+ <div
+ style={{
+ flex: 1,
+ display: "flex",
+ alignItems: "center",
+ fontSize: 16,
+ color: sendActive ? "#000000" : "#9b9ba1",
+ }}
+ >
+ <span style={{ whiteSpace: "pre-wrap", wordBreak: "break-word" }}>
+ {sendActive ? composerText : "iMessage"}
+ </span>
+ {typing && (
+ <Caret
+ color={accent}
+ height={18}
+ radius={1}
+ blink
+ marginLeft={composerText.length > 0 ? 2 : 0}
+ />
+ )}
+ </div>
+ <div
+ style={{
+ flexShrink: 0,
+ width: 28,
+ height: 28,
+ borderRadius: "50%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ background: sendActive ? accent : "#c6c6cc",
+ transform: `scale(${sendScale})`,
+ }}
+ >
+ <ArrowUp size={20} color="#ffffff" strokeWidth={2.75} />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function ImessageRow({
+ item,
+ eff,
+ contact,
+ accent,
+ showDelivered,
+}: {
+ item: ScheduledMessage;
+ eff: number;
+ contact?: ImessageContact;
+ accent: string;
+ showDelivered: boolean;
+}) {
+ const { fps } = useVideoConfig();
+ const outgoing = item.from === "me";
+ const showTyping =
+ item.from === "them" &&
+ item.typingStart !== undefined &&
+ eff < item.revealAt;
+
+ const enter = spring({
+ fps,
+ frame: eff - (showTyping ? (item.typingStart ?? 0) : item.revealAt),
+ config: { damping: 16, stiffness: 200, mass: 0.7 },
+ });
+ const opacity = interpolate(enter, [0, 1], [0, 1]);
+ const translateY = interpolate(enter, [0, 1], [10, 0]);
+ const scale = interpolate(enter, [0, 1], [0.92, 1]);
+
+ let reactionScale = 0;
+ let reactionOpacity = 0;
+ if (item.reactAt !== undefined) {
+ reactionScale = spring({
+ fps,
+ frame: eff - item.reactAt,
+ config: { damping: 11, stiffness: 220, mass: 0.6 },
+ });
+ reactionOpacity = interpolate(eff, [item.reactAt, item.reactAt + 5], [0, 1], {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+ });
+ }
+
+ const bg = outgoing ? accent : INCOMING_BG;
+ const fg = outgoing ? OUTGOING_FG : INCOMING_FG;
+ const delivered =
+ showDelivered && !showTyping && eff > item.revealAt + REVEAL;
+
+ const bubble = (
+ <div
+ style={{
+ position: "relative",
+ maxWidth: "72%",
+ padding: showTyping ? "11px 14px" : "7px 13px 8px",
+ background: bg,
+ color: fg,
+ borderRadius: 19,
+ borderBottomRightRadius: outgoing ? 7 : 19,
+ borderBottomLeftRadius: outgoing ? 19 : 7,
+ fontSize: 16,
+ lineHeight: 1.32,
+ }}
+ >
+ {showTyping ? (
+ <TypingIndicator color={META_GRAY} />
+ ) : (
+ <span style={{ wordBreak: "break-word", overflowWrap: "break-word" }}>
+ {item.text}
+ </span>
+ )}
+ {!showTyping && <BubbleTail side={outgoing ? "right" : "left"} color={bg} />}
+ {item.reaction !== undefined && (
+ <div
+ style={{
+ position: "absolute",
+ top: -16,
+ left: outgoing ? -14 : undefined,
+ right: outgoing ? undefined : -14,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ width: 30,
+ height: 30,
+ borderRadius: "50%",
+ background: INCOMING_BG,
+ fontSize: 15,
+ boxShadow: "0 1px 2px rgba(0,0,0,0.12)",
+ opacity: reactionOpacity,
+ transform: `scale(${reactionScale})`,
+ transformOrigin: outgoing ? "bottom left" : "bottom right",
+ }}
+ >
+ {item.reaction}
+ </div>
+ )}
+ </div>
+ );
+
+ return (
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ alignItems: outgoing ? "flex-end" : "flex-start",
+ gap: 2,
+ width: "100%",
+ opacity,
+ transform: `translateY(${translateY}px) scale(${scale})`,
+ transformOrigin: outgoing ? "bottom right" : "bottom left",
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ alignItems: "flex-end",
+ justifyContent: outgoing ? "flex-end" : "flex-start",
+ gap: 7,
+ width: "100%",
+ }}
+ >
+ {!outgoing && contact !== undefined && (
+ <Avatar contact={contact} size={28} />
+ )}
+ {bubble}
+ </div>
+ {delivered && (
+ <span
+ style={{
+ fontSize: 11,
+ color: META_GRAY,
+ paddingRight: 4,
+ }}
+ >
+ Delivered
+ </span>
+ )}
+ </div>
+ );
+}
diff --git a/registry/remocn-ui/registry.json b/registry/remocn-ui/registry.json
index 3394e8ca..9b2e2eaf 100644
--- a/registry/remocn-ui/registry.json
+++ b/registry/remocn-ui/registry.json
@@ -826,6 +826,36 @@
"target": "components/remocn/chat-flow.tsx"
}
]
+ },
+ {
+ "name": "telegram-chat-flow",
+ "type": "registry:component",
+ "title": "UI Telegram Chat Flow",
+ "description": "A Telegram-styled messaging composition: tailed bubbles (white incoming, blue outgoing) with in-bubble timestamps and delivery checks, a header that flips to 'typing…' while the other side replies, reaction chips, and a Telegram composer that types the outgoing message before sending. Self-contained — it owns its timeline and only composes the caret primitive.",
+ "dependencies": ["remotion"],
+ "registryDependencies": ["@remocn/remocn-ui", "@remocn/caret"],
+ "files": [
+ {
+ "path": "telegram-chat-flow/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/telegram-chat-flow.tsx"
+ }
+ ]
+ },
+ {
+ "name": "imessage-chat-flow",
+ "type": "registry:component",
+ "title": "UI iMessage Chat Flow",
+ "description": "An iMessage-styled messaging composition: gray incoming and blue outgoing bubbles with tails, an in-thread typing bubble with dots, a Delivered label, and tapback-style reaction badges. The composer types the outgoing message before sending. Chrome icons come from lucide-react; self-contained otherwise, composing the caret and typing-indicator primitives.",
+ "dependencies": ["remotion", "lucide-react"],
+ "registryDependencies": ["@remocn/remocn-ui", "@remocn/caret", "@remocn/typing-indicator"],
+ "files": [
+ {
+ "path": "imessage-chat-flow/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/imessage-chat-flow.tsx"
+ }
+ ]
}
]
}
diff --git a/registry/remocn-ui/telegram-chat-flow/__tests__/telegram-chat-flow.test.ts b/registry/remocn-ui/telegram-chat-flow/__tests__/telegram-chat-flow.test.ts
new file mode 100644
index 00000000..fec49a5e
--- /dev/null
+++ b/registry/remocn-ui/telegram-chat-flow/__tests__/telegram-chat-flow.test.ts
@@ -0,0 +1,183 @@
+
+import { describe, expect, it } from "bun:test";
+import { telegramChatFlowSchedule, telegramChatFlowDuration, sendPulse, type TelegramMessage } from "../index";
+
+const MESSAGES: TelegramMessage[] = [
+ { from: "me", text: "hi" },
+ { from: "them", text: "yo", reaction: "🔥" },
+];
+
+describe("telegramChatFlowSchedule: items length", () => {
+ it("returns 2 items for 2 messages", () => {
+ const { items } = telegramChatFlowSchedule(MESSAGES);
+ expect(items.length).toBe(2);
+ });
+});
+
+describe("telegramChatFlowSchedule: item 0 (from='me', text='hi')", () => {
+ const { items } = telegramChatFlowSchedule(MESSAGES);
+ const item0 = items[0];
+
+ it("from is 'me'", () => {
+ expect(item0.from).toBe("me");
+ });
+
+ it("typeStart is 12 (LEAD_IN)", () => {
+ expect(item0.typeStart).toBe(12);
+ });
+
+ it("sendAt is 40 (typeStart + MIN_TYPE + SEND_GAP = 12 + 18 + 10)", () => {
+ expect(item0.sendAt).toBe(40);
+ });
+
+ it("revealAt equals sendAt (40)", () => {
+ expect(item0.revealAt).toBe(40);
+ expect(item0.revealAt).toBe(item0.sendAt);
+ });
+
+ it("presenceStart equals sendAt - 2 (38)", () => {
+ expect(item0.presenceStart).toBe(38);
+ expect(item0.presenceStart).toBe((item0.sendAt ?? 0) - 2);
+ });
+
+ it("reactAt is undefined (no reaction)", () => {
+ expect(item0.reactAt).toBeUndefined();
+ });
+
+ it("reaction is undefined", () => {
+ expect(item0.reaction).toBeUndefined();
+ });
+});
+
+describe("telegramChatFlowSchedule: item 1 (from='them', text='yo', reaction='🔥')", () => {
+ const { items } = telegramChatFlowSchedule(MESSAGES);
+ const item1 = items[1];
+
+ it("from is 'them'", () => {
+ expect(item1.from).toBe("them");
+ });
+
+ it("typingStart is 70 (after item 0 window)", () => {
+ expect(item1.typingStart).toBe(70);
+ });
+
+ it("revealAt is 104 (typingStart + TYPING_MIN = 70 + 34)", () => {
+ expect(item1.revealAt).toBe(104);
+ });
+
+ it("revealAt equals typingStart + typingDur (70 + 34)", () => {
+ expect(item1.revealAt).toBe((item1.typingStart ?? 0) + 34);
+ });
+
+ it("reactAt is 126 (revealAt + REVEAL + REACT_DELAY = 104 + 14 + 8)", () => {
+ expect(item1.reactAt).toBe(126);
+ });
+
+ it("reaction is '🔥'", () => {
+ expect(item1.reaction).toBe("🔥");
+ });
+
+ it("presenceStart equals revealAt (104), not typingStart", () => {
+ expect(item1.presenceStart).toBe(104);
+ expect(item1.presenceStart).toBe(item1.revealAt);
+ });
+});
+
+describe("telegramChatFlowSchedule: monotonic ordering", () => {
+ const { items } = telegramChatFlowSchedule(MESSAGES);
+
+ it("item1.typingStart >= item0.revealAt", () => {
+ expect(items[1].typingStart ?? 0).toBeGreaterThanOrEqual(items[0].revealAt);
+ });
+
+ it("item1.revealAt > item0.revealAt", () => {
+ expect(items[1].revealAt).toBeGreaterThan(items[0].revealAt);
+ });
+
+ it("item1.reactAt > item1.revealAt", () => {
+ expect(items[1].reactAt ?? 0).toBeGreaterThan(items[1].revealAt);
+ });
+});
+
+describe("telegramChatFlowSchedule: duration", () => {
+ const { duration } = telegramChatFlowSchedule(MESSAGES);
+
+ it("duration is a positive integer", () => {
+ expect(duration).toBeGreaterThan(0);
+ expect(Number.isInteger(duration)).toBe(true);
+ });
+
+ it("duration (168) is greater than all revealAt values", () => {
+ const { items } = telegramChatFlowSchedule(MESSAGES);
+ expect(duration).toBe(168);
+ for (const item of items) {
+ expect(duration).toBeGreaterThan(item.revealAt);
+ }
+ });
+
+ it("duration is 168", () => {
+ expect(duration).toBe(168);
+ });
+});
+
+describe("telegramChatFlowDuration", () => {
+ it("telegramChatFlowDuration(messages) with default speed=1 equals schedule duration (168)", () => {
+ expect(telegramChatFlowDuration(MESSAGES)).toBe(168);
+ });
+
+ it("telegramChatFlowDuration(messages) equals telegramChatFlowSchedule(messages).duration", () => {
+ expect(telegramChatFlowDuration(MESSAGES)).toBe(telegramChatFlowSchedule(MESSAGES).duration);
+ });
+
+ it("telegramChatFlowDuration(messages, 2) equals Math.ceil(schedule.duration / 2)", () => {
+ const raw = telegramChatFlowSchedule(MESSAGES).duration;
+ expect(telegramChatFlowDuration(MESSAGES, 2)).toBe(Math.ceil(raw / 2));
+ });
+
+ it("telegramChatFlowDuration(messages, 2) is 84", () => {
+ expect(telegramChatFlowDuration(MESSAGES, 2)).toBe(84);
+ });
+});
+
+describe("sendPulse: at sendAt of a 'me' item (eff === sendAt)", () => {
+ const { items } = telegramChatFlowSchedule(MESSAGES);
+
+ it("sendPulse equals 1 when eff exactly equals sendAt (40)", () => {
+ expect(sendPulse(items, 40)).toBeCloseTo(1, 10);
+ });
+});
+
+describe("sendPulse: far from any sendAt", () => {
+ const { items } = telegramChatFlowSchedule(MESSAGES);
+
+ it("sendPulse is 0 when eff is 100 frames away from the only sendAt", () => {
+ expect(sendPulse(items, 140)).toBe(0);
+ });
+
+ it("sendPulse is 0 at eff=0 (before any sendAt and outside PRESS_WINDOW)", () => {
+ expect(sendPulse(items, 0)).toBe(0);
+ });
+});
+
+describe("sendPulse: partial pulse within PRESS_WINDOW", () => {
+ const { items } = telegramChatFlowSchedule(MESSAGES);
+
+ it("sendPulse is > 0 when eff is within 7 frames of sendAt", () => {
+ expect(sendPulse(items, 43)).toBeGreaterThan(0);
+ expect(sendPulse(items, 43)).toBeLessThan(1);
+ });
+
+ it("sendPulse is 0 when eff is exactly PRESS_WINDOW+1 frames past sendAt", () => {
+ expect(sendPulse(items, 48)).toBe(0);
+ });
+});
+
+describe("telegramChatFlowSchedule: empty messages", () => {
+ it("returns empty items array", () => {
+ expect(telegramChatFlowSchedule([]).items).toEqual([]);
+ });
+
+ it("duration is positive (LEAD_IN + TAIL)", () => {
+ expect(telegramChatFlowSchedule([]).duration).toBeGreaterThan(0);
+ });
+});
diff --git a/registry/remocn-ui/telegram-chat-flow/index.tsx b/registry/remocn-ui/telegram-chat-flow/index.tsx
new file mode 100644
index 00000000..54cec9a0
--- /dev/null
+++ b/registry/remocn-ui/telegram-chat-flow/index.tsx
@@ -0,0 +1,705 @@
+"use client";
+
+import {
+ interpolate,
+ spring,
+ useCurrentFrame,
+ useVideoConfig,
+} from "remotion";
+import { type RemocnTheme, revealedText } from "@/lib/remocn-ui";
+import { Caret } from "@/components/remocn/caret";
+
+export interface TelegramMessage {
+ from: "me" | "them";
+ text: string;
+ reaction?: string;
+ time?: string;
+}
+
+export interface TelegramContact {
+ name: string;
+ avatar?: string;
+}
+
+export interface TelegramChatFlowProps {
+ messages?: TelegramMessage[];
+ contact?: TelegramContact;
+ accentColor?: string;
+ speed?: number;
+ theme?: Partial<RemocnTheme>;
+}
+
+const MOBILE_WIDTH = 460;
+const LEAD_IN = 12;
+const FRAMES_PER_CHAR = 2.2;
+const MIN_TYPE = 18;
+const MAX_TYPE = 86;
+const SEND_GAP = 10;
+const REVEAL = 14;
+const REACT_DELAY = 8;
+const REACT_DUR = 14;
+const MSG_GAP = 16;
+const TYPING_MIN = 34;
+const TYPING_MAX = 70;
+const TAIL = 28;
+const PRESS_WINDOW = 7;
+
+const TELEGRAM_BLUE = "#3390ec";
+const INCOMING_BG = "#ffffff";
+const INCOMING_FG = "#0f1419";
+const INCOMING_META = "#8a99a5";
+const OUTGOING_FG = "#ffffff";
+const OUTGOING_META = "rgba(255,255,255,0.82)";
+
+const DEFAULT_MESSAGES: TelegramMessage[] = [
+ { from: "me", text: "Hey — ready for the demo?", time: "9:40" },
+ { from: "them", text: "Yep, pushing it live now", reaction: "🔥", time: "9:41" },
+ { from: "me", text: "Perfect, sending the link over", reaction: "👍", time: "9:41" },
+];
+
+function clamp(value: number, lo: number, hi: number): number {
+ return Math.max(lo, Math.min(hi, value));
+}
+
+export interface ScheduledMessage {
+ index: number;
+ from: "me" | "them";
+ text: string;
+ reaction?: string;
+ time?: string;
+ presenceStart: number;
+ typeStart?: number;
+ sendAt?: number;
+ typingStart?: number;
+ revealAt: number;
+ reactAt?: number;
+}
+
+export interface TelegramChatFlowSchedule {
+ items: ScheduledMessage[];
+ duration: number;
+}
+
+export function telegramChatFlowSchedule(
+ messages: TelegramMessage[],
+): TelegramChatFlowSchedule {
+ const items: ScheduledMessage[] = [];
+ let cursor = LEAD_IN;
+
+ messages.forEach((message, index) => {
+ const hasReaction = message.reaction !== undefined && message.reaction !== "";
+ if (message.from === "me") {
+ const typeStart = cursor;
+ const typeDur = clamp(
+ Math.round(message.text.length * FRAMES_PER_CHAR),
+ MIN_TYPE,
+ MAX_TYPE,
+ );
+ const sendAt = typeStart + typeDur + SEND_GAP;
+ const revealAt = sendAt;
+ const reactAt = hasReaction ? revealAt + REVEAL + REACT_DELAY : undefined;
+ items.push({
+ index,
+ from: "me",
+ text: message.text,
+ reaction: hasReaction ? message.reaction : undefined,
+ time: message.time,
+ presenceStart: sendAt - 2,
+ typeStart,
+ sendAt,
+ revealAt,
+ reactAt,
+ });
+ cursor =
+ revealAt + REVEAL + (hasReaction ? REACT_DELAY + REACT_DUR : 0) + MSG_GAP;
+ } else {
+ const typingStart = cursor;
+ const typingDur = clamp(
+ Math.round(message.text.length * FRAMES_PER_CHAR),
+ TYPING_MIN,
+ TYPING_MAX,
+ );
+ const revealAt = typingStart + typingDur;
+ const reactAt = hasReaction ? revealAt + REVEAL + REACT_DELAY : undefined;
+ items.push({
+ index,
+ from: "them",
+ text: message.text,
+ reaction: hasReaction ? message.reaction : undefined,
+ time: message.time,
+ presenceStart: revealAt,
+ typingStart,
+ revealAt,
+ reactAt,
+ });
+ cursor =
+ revealAt + REVEAL + (hasReaction ? REACT_DELAY + REACT_DUR : 0) + MSG_GAP;
+ }
+ });
+
+ const duration = Math.max(cursor - MSG_GAP + TAIL, LEAD_IN + TAIL);
+ return { items, duration };
+}
+
+export function telegramChatFlowDuration(
+ messages: TelegramMessage[] = DEFAULT_MESSAGES,
+ speed = 1,
+): number {
+ const raw = telegramChatFlowSchedule(messages).duration;
+ return Math.ceil(raw / (speed <= 0 ? 1 : speed));
+}
+
+export function sendPulse(items: ScheduledMessage[], eff: number): number {
+ let best = 0;
+ for (const item of items) {
+ if (item.sendAt === undefined) continue;
+ const distance = Math.abs(eff - item.sendAt);
+ if (distance <= PRESS_WINDOW) {
+ best = Math.max(best, 1 - distance / PRESS_WINDOW);
+ }
+ }
+ return best;
+}
+
+function Avatar({ contact, size }: { contact: TelegramContact; size: number }) {
+ const initial = contact.name.trim().charAt(0).toUpperCase();
+ return (
+ <div
+ style={{
+ flexShrink: 0,
+ width: size,
+ height: size,
+ minWidth: size,
+ borderRadius: "50%",
+ overflow: "hidden",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ background: `linear-gradient(180deg, #72d5fd 0%, ${TELEGRAM_BLUE} 100%)`,
+ color: "#ffffff",
+ fontSize: size * 0.42,
+ fontWeight: 600,
+ fontFamily:
+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",
+ }}
+ >
+ {contact.avatar !== undefined ? (
+ <img
+ src={contact.avatar}
+ alt={contact.name}
+ style={{ width: "100%", height: "100%", objectFit: "cover" }}
+ />
+ ) : (
+ initial
+ )}
+ </div>
+ );
+}
+
+function DoubleCheck({ color }: { color: string }) {
+ return (
+ <svg
+ width={16}
+ height={16}
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke={color}
+ strokeWidth={2}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ <path d="M18 6 7 17l-5-5" />
+ <path d="m22 10-7.5 7.5L13 16" />
+ </svg>
+ );
+}
+
+function PaperPlane({ color }: { color: string }) {
+ return (
+ <svg
+ width={20}
+ height={20}
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke={color}
+ strokeWidth={2}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ <path d="M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z" />
+ <path d="m21.854 2.147-10.94 10.939" />
+ </svg>
+ );
+}
+
+function MicIcon({ color }: { color: string }) {
+ return (
+ <svg
+ width={22}
+ height={22}
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke={color}
+ strokeWidth={2}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ <path d="M12 19v3" />
+ <path d="M19 10v2a7 7 0 0 1-14 0v-2" />
+ <rect x={9} y={2} width={6} height={13} rx={3} />
+ </svg>
+ );
+}
+
+function SmileIcon({ color }: { color: string }) {
+ return (
+ <svg
+ width={22}
+ height={22}
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke={color}
+ strokeWidth={2}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ <circle cx={12} cy={12} r={10} />
+ <path d="M8 14s1.5 2 4 2 4-2 4-2" />
+ <line x1={9} x2={9.01} y1={9} y2={9} />
+ <line x1={15} x2={15.01} y1={9} y2={9} />
+ </svg>
+ );
+}
+
+function AttachIcon({ color }: { color: string }) {
+ return (
+ <svg
+ width={22}
+ height={22}
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke={color}
+ strokeWidth={2}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ <path d="m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551" />
+ </svg>
+ );
+}
+
+function PhoneIcon({ color }: { color: string }) {
+ return (
+ <svg
+ width={22}
+ height={22}
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke={color}
+ strokeWidth={2}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ <path d="M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384" />
+ </svg>
+ );
+}
+
+function MoreIcon({ color }: { color: string }) {
+ return (
+ <svg
+ width={22}
+ height={22}
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke={color}
+ strokeWidth={2}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ <circle cx={12} cy={12} r={1} />
+ <circle cx={12} cy={5} r={1} />
+ <circle cx={12} cy={19} r={1} />
+ </svg>
+ );
+}
+
+function BubbleTail({ side, color }: { side: "left" | "right"; color: string }) {
+ const path =
+ side === "right"
+ ? "M0 0 H4 C4 7 7 12 13 13 C6 13 0 9 0 0 Z"
+ : "M13 0 H9 C9 7 6 12 0 13 C7 13 13 9 13 0 Z";
+ return (
+ <svg
+ width={13}
+ height={13}
+ viewBox="0 0 13 13"
+ style={{
+ position: "absolute",
+ bottom: 0,
+ left: side === "left" ? -6 : undefined,
+ right: side === "right" ? -6 : undefined,
+ }}
+ >
+ <path d={path} fill={color} />
+ </svg>
+ );
+}
+
+export function TelegramChatFlow({
+ messages = DEFAULT_MESSAGES,
+ contact,
+ accentColor,
+ speed = 1,
+}: TelegramChatFlowProps) {
+ const frame = useCurrentFrame();
+ const eff = frame * speed;
+ const accent = accentColor ?? TELEGRAM_BLUE;
+
+ const { items } = telegramChatFlowSchedule(messages);
+
+ const activeMe = items.find(
+ (item) =>
+ item.from === "me" &&
+ item.typeStart !== undefined &&
+ item.sendAt !== undefined &&
+ eff >= item.typeStart &&
+ eff < item.sendAt,
+ );
+ let composerText = "";
+ let typing = false;
+ if (
+ activeMe &&
+ activeMe.typeStart !== undefined &&
+ activeMe.sendAt !== undefined
+ ) {
+ const typeDur = Math.max(activeMe.sendAt - SEND_GAP - activeMe.typeStart, 1);
+ const progress = clamp((eff - activeMe.typeStart) / typeDur, 0, 1);
+ composerText = revealedText(
+ activeMe.text,
+ Math.floor(progress * activeMe.text.length),
+ );
+ typing = true;
+ }
+
+ const themTyping = items.some(
+ (item) =>
+ item.from === "them" &&
+ item.typingStart !== undefined &&
+ eff >= item.typingStart &&
+ eff < item.revealAt,
+ );
+
+ const sendActive = composerText.length > 0;
+ const sendScale = 1 - 0.16 * sendPulse(items, eff);
+ const present = items.filter((item) => eff >= item.presenceStart);
+
+ return (
+ <div
+ style={{
+ position: "relative",
+ width: "100%",
+ height: "100%",
+ display: "flex",
+ justifyContent: "center",
+ background: "transparent",
+ fontFamily:
+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ width: "100%",
+ maxWidth: MOBILE_WIDTH,
+ height: "100%",
+ boxSizing: "border-box",
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ alignItems: "center",
+ gap: 12,
+ padding: "12px 14px",
+ background: "#ffffff",
+ boxShadow: "0 1px 0 rgba(0,0,0,0.06)",
+ }}
+ >
+ {contact !== undefined && (
+ <Avatar contact={contact} size={38} />
+ )}
+ <div style={{ display: "flex", flexDirection: "column", gap: 0, flex: 1 }}>
+ <span
+ style={{
+ fontSize: 15,
+ fontWeight: 600,
+ lineHeight: 1.2,
+ letterSpacing: "-0.01em",
+ color: "#0f1419",
+ }}
+ >
+ {contact?.name ?? "Chat"}
+ </span>
+ <span
+ style={{
+ fontSize: 13,
+ lineHeight: 1.15,
+ color: accent,
+ fontStyle: themTyping ? "italic" : "normal",
+ }}
+ >
+ {themTyping ? "typing…" : "online"}
+ </span>
+ </div>
+ <div style={{ display: "flex", alignItems: "center", gap: 18 }}>
+ <PhoneIcon color="#8a99a5" />
+ <MoreIcon color="#8a99a5" />
+ </div>
+ </div>
+
+ <div
+ style={{
+ position: "relative",
+ flex: 1,
+ minHeight: 0,
+ overflow: "hidden",
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ justifyContent: "flex-end",
+ gap: 4,
+ minHeight: "100%",
+ padding: "16px 12px 14px",
+ }}
+ >
+ <div style={{ display: "flex", justifyContent: "center", marginBottom: 8 }}>
+ <span
+ style={{
+ padding: "3px 11px",
+ borderRadius: 14,
+ background: "rgba(0,0,0,0.18)",
+ color: "#ffffff",
+ fontSize: 12,
+ fontWeight: 500,
+ }}
+ >
+ Today
+ </span>
+ </div>
+ {present.map((item) => (
+ <TelegramRow
+ key={item.index}
+ item={item}
+ eff={eff}
+ contact={contact}
+ accent={accent}
+ />
+ ))}
+ </div>
+ </div>
+
+ <div
+ style={{
+ display: "flex",
+ alignItems: "flex-end",
+ gap: 8,
+ padding: "8px 10px 12px",
+ background: "#ffffff",
+ boxShadow: "0 -1px 0 rgba(0,0,0,0.06)",
+ }}
+ >
+ <div
+ style={{
+ flex: 1,
+ display: "flex",
+ alignItems: "center",
+ gap: 8,
+ minHeight: 44,
+ padding: "0 12px",
+ borderRadius: 22,
+ background: "#f1f3f5",
+ }}
+ >
+ <SmileIcon color="#8a99a5" />
+ <div
+ style={{
+ flex: 1,
+ display: "flex",
+ alignItems: "center",
+ fontSize: 15,
+ color: sendActive ? "#0f1419" : "#8a99a5",
+ }}
+ >
+ <span style={{ whiteSpace: "pre-wrap", wordBreak: "break-word" }}>
+ {sendActive ? composerText : "Message"}
+ </span>
+ {typing && (
+ <Caret
+ color={accent}
+ height={18}
+ radius={1}
+ blink
+ marginLeft={composerText.length > 0 ? 2 : 0}
+ />
+ )}
+ </div>
+ <AttachIcon color="#8a99a5" />
+ </div>
+ <div
+ style={{
+ flexShrink: 0,
+ width: 46,
+ height: 46,
+ borderRadius: "50%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ background: accent,
+ transform: `scale(${sendScale})`,
+ }}
+ >
+ {sendActive ? (
+ <PaperPlane color="#ffffff" />
+ ) : (
+ <MicIcon color="#ffffff" />
+ )}
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function TelegramRow({
+ item,
+ eff,
+ contact,
+ accent,
+}: {
+ item: ScheduledMessage;
+ eff: number;
+ contact?: TelegramContact;
+ accent: string;
+}) {
+ const { fps } = useVideoConfig();
+ const outgoing = item.from === "me";
+
+ const enter = spring({
+ fps,
+ frame: eff - item.revealAt,
+ config: { damping: 16, stiffness: 200, mass: 0.7 },
+ });
+ const opacity = interpolate(enter, [0, 1], [0, 1]);
+ const translateY = interpolate(enter, [0, 1], [10, 0]);
+ const scale = interpolate(enter, [0, 1], [0.92, 1]);
+
+ let reactionScale = 0;
+ let reactionOpacity = 0;
+ if (item.reactAt !== undefined) {
+ reactionScale = spring({
+ fps,
+ frame: eff - item.reactAt,
+ config: { damping: 11, stiffness: 220, mass: 0.6 },
+ });
+ reactionOpacity = interpolate(eff, [item.reactAt, item.reactAt + 5], [0, 1], {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+ });
+ }
+
+ const bg = outgoing ? accent : INCOMING_BG;
+ const fg = outgoing ? OUTGOING_FG : INCOMING_FG;
+ const metaColor = outgoing ? OUTGOING_META : INCOMING_META;
+ const tailColor = outgoing ? accent : INCOMING_BG;
+
+ const bubble = (
+ <div
+ style={{
+ position: "relative",
+ maxWidth: "76%",
+ padding: "6px 11px 7px",
+ background: bg,
+ color: fg,
+ borderRadius: 16,
+ borderBottomRightRadius: outgoing ? 6 : 16,
+ borderBottomLeftRadius: outgoing ? 16 : 6,
+ boxShadow: outgoing ? "none" : "0 1px 1px rgba(0,0,0,0.1)",
+ fontSize: 15,
+ lineHeight: 1.35,
+ }}
+ >
+ <span style={{ wordBreak: "break-word", overflowWrap: "break-word" }}>
+ {item.text}
+ </span>
+ <div
+ style={{
+ display: "flex",
+ alignItems: "center",
+ justifyContent: item.reaction !== undefined ? "space-between" : "flex-end",
+ gap: 8,
+ marginTop: 2,
+ }}
+ >
+ {item.reaction !== undefined && (
+ <span
+ style={{
+ display: "inline-flex",
+ alignItems: "center",
+ gap: 4,
+ padding: "1px 7px",
+ borderRadius: 11,
+ background: outgoing ? "rgba(255,255,255,0.22)" : "rgba(51,144,236,0.12)",
+ color: outgoing ? "#ffffff" : accent,
+ fontSize: 13,
+ fontWeight: 600,
+ opacity: reactionOpacity,
+ transform: `scale(${reactionScale})`,
+ transformOrigin: "left center",
+ }}
+ >
+ {item.reaction} 1
+ </span>
+ )}
+ <span
+ style={{
+ display: "inline-flex",
+ alignItems: "center",
+ gap: 3,
+ fontSize: 12,
+ color: metaColor,
+ whiteSpace: "nowrap",
+ }}
+ >
+ {item.time ?? "9:41"}
+ {outgoing && <DoubleCheck color={metaColor} />}
+ </span>
+ </div>
+ <BubbleTail side={outgoing ? "right" : "left"} color={tailColor} />
+ </div>
+ );
+
+ return (
+ <div
+ style={{
+ display: "flex",
+ alignItems: "flex-end",
+ justifyContent: outgoing ? "flex-end" : "flex-start",
+ gap: 7,
+ width: "100%",
+ opacity,
+ transform: `translateY(${translateY}px) scale(${scale})`,
+ transformOrigin: outgoing ? "bottom right" : "bottom left",
+ }}
+ >
+ {!outgoing && contact !== undefined && (
+ <Avatar contact={contact} size={30} />
+ )}
+ {bubble}
+ </div>
+ );
+}