Skip to content

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

feat: added message primitives, chat-flow

dev_wandryb814574db758
diff --git a/app/(home)/components/sections/ui-registry.tsx b/app/(home)/components/sections/ui-registry.tsx
index 550e124e..d523657b 100644
--- a/app/(home)/components/sections/ui-registry.tsx
+++ b/app/(home)/components/sections/ui-registry.tsx
@@ -63,6 +63,8 @@ const PRIMITIVE_CHIPS = [
"slider",
"tooltip",
"stepper",
+ "message-bubble",
+ "typing-indicator",
];
function ScenePlayer({ entry }: { entry: SceneEntry | undefined }) {
diff --git a/bun.lock b/bun.lock
index 6cabe959..cdf85d5b 100644
--- a/bun.lock
+++ b/bun.lock
@@ -11,9 +11,9 @@
"@react-three/postprocessing": "^3.0.4",
"@remotion/bundler": "4.0.473",
"@remotion/google-fonts": "4.0.473",
- "@remotion/motion-blur": "4.0.473",
"@remotion/player": "4.0.473",
"@remotion/renderer": "4.0.473",
+ "@shadcn/react": "^0.1.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
@@ -449,8 +449,6 @@
"@remotion/media-utils": ["@remotion/[email protected]", "", { "dependencies": { "mediabunny": "1.45.0", "remotion": "4.0.473" }, "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-f4Ip10pkawlUBTunE++DZ6J/TrPtKalkxoTx7qQGBlhz3BcWRK7AbEGouZtcAmkLFVxq80hpH/1cBFOMF6FVfA=="],
- "@remotion/motion-blur": ["@remotion/[email protected]", "", { "dependencies": { "remotion": "4.0.473" }, "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-SmeTVJT0sYrpKvaWKTEfgAdQRGaR/LqbHWMe9bQhtSQasBxwZ44v9m8d5u6chZ90SCYYI99WL4TaZleqjzaCiQ=="],
-
"@remotion/player": ["@remotion/[email protected]", "", { "dependencies": { "remotion": "4.0.473" }, "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-giJ8cIQEdVxftpcX4m+9jWYCbIvpcdKRGVUc3ownxYEsJ30WUSP2+TuQ6aqqLXFAfwhY/SdBVLfopylh3BgMXA=="],
"@remotion/renderer": ["@remotion/[email protected]", "", { "dependencies": { "@remotion/licensing": "4.0.473", "@remotion/streaming": "4.0.473", "execa": "5.1.1", "remotion": "4.0.473", "source-map": "0.8.0-beta.0", "ws": "8.20.1" }, "optionalDependencies": { "@remotion/compositor-darwin-arm64": "4.0.473", "@remotion/compositor-darwin-x64": "4.0.473", "@remotion/compositor-linux-arm64-gnu": "4.0.473", "@remotion/compositor-linux-arm64-musl": "4.0.473", "@remotion/compositor-linux-x64-gnu": "4.0.473", "@remotion/compositor-linux-x64-musl": "4.0.473", "@remotion/compositor-win32-x64-msvc": "4.0.473" }, "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-WOOmT38O3ax78oDIE75FnsDi8eUMBKOdnqiXU3NeArNoA/xQZv7yDUgV3e1SxFaCHS7IbWHIATXUfVgS8TIXBA=="],
@@ -501,6 +499,8 @@
"@sec-ant/readable-stream": ["@sec-ant/[email protected]", "", {}, "sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg=="],
+ "@shadcn/react": ["@shadcn/[email protected]", "", { "peerDependencies": { "@types/react": ">=19", "react": ">=19" }, "optionalPeers": ["@types/react", "react"] }, "sha512-6i67TEnqValsZY7e4exJ4rkHo2OdHXmDH152YulwSpuEUnTQYumHkXzFsaje7HB7GbMTWuI9x1Jn6sSduCYdeA=="],
+
"@shikijs/core": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/primitive": "4.0.2", "@shikijs/types": "4.0.2", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4", "hast-util-to-html": "^9.0.5" } }, "sha512-hxT0YF4ExEqB8G/qFdtJvpmHXBYJ2lWW7qTHDarVkIudPFE6iCIrqdgWxGn5s+ppkGXI0aEGlibI0PAyzP3zlw=="],
"@shikijs/engine-javascript": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/types": "4.0.2", "@shikijs/vscode-textmate": "^10.0.2", "oniguruma-to-es": "^4.3.4" } }, "sha512-7PW0Nm49DcoUIQEXlJhNNBHyoGMjalRETTCcjMqEaMoJRLljy1Bi/EGV3/qLBgLKQejdspiiYuHGQW6dX94Nag=="],
diff --git a/components/docs/examples/blocks/index.tsx b/components/docs/examples/blocks/index.tsx
index 0aa82f05..41150404 100644
--- a/components/docs/examples/blocks/index.tsx
+++ b/components/docs/examples/blocks/index.tsx
@@ -21,6 +21,10 @@ import {
SettingsToggleFlowExampleScene,
settingsToggleFlowExampleCode,
} from "../settings-toggle-flow-example";
+import {
+ ChatFlowExampleScene,
+ chatFlowExampleCode,
+} from "../chat-flow-example";
import {
BackdropColorScene,
BackdropGradientScene,
@@ -85,6 +89,16 @@ export const blockExamples: Record<string, BlockExampleEntry> = {
height: H,
previewBackdrop: { type: "color", value: "oklch(1 0 0)" },
},
+ "chat-flow": {
+ Component: ChatFlowExampleScene,
+ code: chatFlowExampleCode,
+ // 3 default messages: last reaction pop ~314 + ~28 tail then loop.
+ durationInFrames: 360,
+ fps: FPS,
+ width: 432,
+ height: 768,
+ previewBackdrop: { type: "color", value: "oklch(1 0 0)" },
+ },
"checkout-flow": {
Component: CheckoutFlowExampleScene,
code: checkoutFlowExampleCode,
@@ -174,6 +188,7 @@ export const BLOCK_SCENE_META: Record<
> = {
"signup-flow": { code: signupFlowExampleCode },
"ai-prompt-flow": { code: aiPromptFlowExampleCode },
+ "chat-flow": { code: chatFlowExampleCode },
"checkout-flow": { code: checkoutFlowExampleCode },
"onboarding-stepper-flow": { code: onboardingStepperFlowExampleCode },
"settings-toggle-flow": { code: settingsToggleFlowExampleCode },
diff --git a/components/docs/examples/chat-flow-example.tsx b/components/docs/examples/chat-flow-example.tsx
new file mode 100644
index 00000000..3fad59f0
--- /dev/null
+++ b/components/docs/examples/chat-flow-example.tsx
@@ -0,0 +1,24 @@
+"use client";
+
+import { ChatFlow } from "@/registry/remocn-ui/chat-flow";
+
+export const ChatFlowExampleScene = () => (
+ <ChatFlow
+ contact={{ name: "shadcn", avatar: "https://unavatar.io/x/shadcn" }}
+ />
+);
+
+export const chatFlowExampleCode = (): string => {
+ return `import { ChatFlow } from "@/components/remocn/chat-flow";
+
+export const Scene = () => (
+ <ChatFlow
+ 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/index.tsx b/components/docs/examples/index.tsx
index 65f00245..062b699b 100644
--- a/components/docs/examples/index.tsx
+++ b/components/docs/examples/index.tsx
@@ -28,6 +28,14 @@ import {
import { TabsExampleScene, tabsExampleCode } from "./tabs-example";
import { CursorExampleScene, cursorExampleCode } from "./cursor-example";
import { ToastExampleScene, toastExampleCode } from "./toast-example";
+import {
+ MessageBubbleExampleScene,
+ messageBubbleExampleCode,
+} from "./message-bubble-example";
+import {
+ TypingIndicatorExampleScene,
+ typingIndicatorExampleCode,
+} from "./typing-indicator-example";
import {
CommandMenuExampleScene,
commandMenuExampleCode,
@@ -250,6 +258,26 @@ export const examples: Record<string, ExampleEntry> = {
height: H,
previewBackdrop: { type: "color", value: "oklch(1 0 0)" },
},
+ "message-bubble-example": {
+ Component: MessageBubbleExampleScene,
+ code: messageBubbleExampleCode,
+ // Bubble reveal 16 + reaction pop ~44 + settle, then loop.
+ durationInFrames: 90,
+ fps: FPS,
+ width: W,
+ height: H,
+ previewBackdrop: { type: "color", value: "oklch(1 0 0)" },
+ },
+ "typing-indicator-example": {
+ Component: TypingIndicatorExampleScene,
+ code: typingIndicatorExampleCode,
+ // Continuous loop; one bounce cycle is ~27 frames at 1.1 cps.
+ durationInFrames: 90,
+ fps: FPS,
+ width: W,
+ height: H,
+ previewBackdrop: { type: "color", value: "oklch(1 0 0)" },
+ },
"command-menu-example": {
Component: CommandMenuExampleScene,
code: commandMenuExampleCode,
diff --git a/components/docs/examples/message-bubble-example.tsx b/components/docs/examples/message-bubble-example.tsx
new file mode 100644
index 00000000..54be5073
--- /dev/null
+++ b/components/docs/examples/message-bubble-example.tsx
@@ -0,0 +1,103 @@
+"use client";
+
+import { interpolate, spring, useCurrentFrame, useVideoConfig } from "remotion";
+import {
+ MessageBubble,
+ type MessageBubbleReactionStyle,
+ type MessageBubbleVariant,
+} from "@/registry/remocn-ui/message-bubble";
+import { useMessageBubbleTransition } from "@/registry/remocn-ui/message-bubble/use-message-bubble-transition";
+
+const REVEAL_AT = 16;
+const REACT_AT = 44;
+
+export const messageBubbleExampleControls = ["text", "variant", "reaction"] as const;
+
+export interface MessageBubbleExampleProps {
+ text?: string;
+ variant?: MessageBubbleVariant;
+ reaction?: string;
+}
+
+export const MessageBubbleExampleScene = (
+ p: MessageBubbleExampleProps = {},
+) => {
+ const frame = useCurrentFrame();
+ const { fps } = useVideoConfig();
+ const variant = p.variant ?? "incoming";
+ const text = p.text ?? "Yep, pushing it live now";
+ const reaction = p.reaction === "" ? undefined : p.reaction ?? "πŸ”₯";
+
+ const bubbleStyle = useMessageBubbleTransition([
+ { at: REVEAL_AT, state: "visible", duration: 14 },
+ ]);
+
+ const reactionStyle: MessageBubbleReactionStyle | undefined =
+ reaction !== undefined
+ ? {
+ opacity: interpolate(frame, [REACT_AT, REACT_AT + 5], [0, 1], {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+ }),
+ scale: spring({
+ fps,
+ frame: frame - REACT_AT,
+ config: { damping: 11, stiffness: 220, mass: 0.6 },
+ }),
+ }
+ : undefined;
+
+ return (
+ <div
+ style={{
+ position: "relative",
+ width: "100%",
+ height: "100%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ padding: 96,
+ }}
+ >
+ <div style={{ width: 560 }}>
+ <MessageBubble
+ variant={variant}
+ style={bubbleStyle}
+ reaction={reaction}
+ reactionStyle={reactionStyle}
+ >
+ {text}
+ </MessageBubble>
+ </div>
+ </div>
+ );
+};
+
+export const messageBubbleExampleCode = (
+ values: Record<string, unknown> = {},
+): string => {
+ const text = (values.text as string | undefined) ?? "Yep, pushing it live now";
+ const variant = (values.variant as string | undefined) ?? "incoming";
+ const reaction = values.reaction as string | undefined;
+
+ const props: string[] = [` variant="${variant}"`, " style={bubbleStyle}"];
+ if (reaction !== undefined && reaction !== "")
+ props.push(` reaction="${reaction}"`);
+
+ return `import { MessageBubble } from "@/components/remocn/message-bubble";
+import { useMessageBubbleTransition } from "@/components/remocn/use-message-bubble-transition";
+
+export const Scene = () => {
+ const bubbleStyle = useMessageBubbleTransition([
+ { at: 16, state: "visible", duration: 14 },
+ ]);
+
+ return (
+ <MessageBubble
+${props.join("\n")}
+ >
+ ${text}
+ </MessageBubble>
+ );
+};`;
+};
diff --git a/components/docs/examples/typing-indicator-example.tsx b/components/docs/examples/typing-indicator-example.tsx
new file mode 100644
index 00000000..dfae8069
--- /dev/null
+++ b/components/docs/examples/typing-indicator-example.tsx
@@ -0,0 +1,81 @@
+"use client";
+
+import { useRemocnTheme } from "@/lib/remocn-ui";
+import { TypingIndicator } from "@/registry/remocn-ui/typing-indicator";
+
+export const typingIndicatorExampleControls = [
+ "dotCount",
+ "size",
+ "amplitude",
+] as const;
+
+export interface TypingIndicatorExampleProps {
+ dotCount?: number;
+ size?: number;
+ amplitude?: number;
+}
+
+export const TypingIndicatorExampleScene = (
+ p: TypingIndicatorExampleProps = {},
+) => {
+ const theme = useRemocnTheme(undefined, "light");
+
+ return (
+ <div
+ style={{
+ position: "relative",
+ width: "100%",
+ height: "100%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ }}
+ >
+ <div
+ style={{
+ display: "inline-flex",
+ alignItems: "center",
+ padding: "18px 22px",
+ background: theme.muted,
+ borderRadius: 18,
+ color: theme.mutedForeground,
+ }}
+ >
+ <TypingIndicator
+ dotCount={p.dotCount ?? 3}
+ size={p.size ?? 8}
+ amplitude={p.amplitude ?? 5}
+ />
+ </div>
+ </div>
+ );
+};
+
+export const typingIndicatorExampleCode = (
+ values: Record<string, unknown> = {},
+): string => {
+ const dotCount = (values.dotCount as number | undefined) ?? 3;
+ const size = (values.size as number | undefined) ?? 8;
+ const amplitude = (values.amplitude as number | undefined) ?? 5;
+
+ const props: string[] = [];
+ if (dotCount !== 3) props.push(` dotCount={${dotCount}}`);
+ if (size !== 8) props.push(` size={${size}}`);
+ if (amplitude !== 5) props.push(` amplitude={${amplitude}}`);
+ const body = props.length > 0 ? `\n${props.join("\n")}\n ` : " ";
+
+ return `import { TypingIndicator } from "@/components/remocn/typing-indicator";
+
+export const Scene = () => (
+ <div
+ style={{
+ display: "inline-flex",
+ padding: "18px 22px",
+ background: "var(--muted)",
+ borderRadius: 18,
+ }}
+ >
+ <TypingIndicator${body}/>
+ </div>
+);`;
+};
diff --git a/components/docs/ui-component-preview.tsx b/components/docs/ui-component-preview.tsx
index bdf885e5..80d1d3ef 100644
--- a/components/docs/ui-component-preview.tsx
+++ b/components/docs/ui-component-preview.tsx
@@ -15,6 +15,14 @@ import { type ExampleEntry, examples } from "./examples";
import { buttonExampleCode, buttonExampleControls } from "./examples/button-example";
import { inputExampleCode, inputExampleControls } from "./examples/input-example";
import { toastExampleCode, toastExampleControls } from "./examples/toast-example";
+import {
+ messageBubbleExampleCode,
+ messageBubbleExampleControls,
+} from "./examples/message-bubble-example";
+import {
+ typingIndicatorExampleCode,
+ typingIndicatorExampleControls,
+} from "./examples/typing-indicator-example";
import { popoverExampleCode, popoverExampleControls } from "./examples/popover-example";
import {
accordionExampleCode,
@@ -94,6 +102,14 @@ const UI_SCENE_META: Record<string, UiSceneMeta> = {
button: { controls: buttonExampleControls, code: buttonExampleCode },
input: { controls: inputExampleControls, code: inputExampleCode },
toast: { controls: toastExampleControls, code: toastExampleCode },
+ "message-bubble": {
+ controls: messageBubbleExampleControls,
+ code: messageBubbleExampleCode,
+ },
+ "typing-indicator": {
+ controls: typingIndicatorExampleControls,
+ code: typingIndicatorExampleCode,
+ },
popover: { controls: popoverExampleControls, code: popoverExampleCode },
accordion: { controls: accordionExampleControls, code: accordionExampleCode },
tooltip: { controls: tooltipExampleControls, code: tooltipExampleCode },
diff --git a/components/ui/bubble.tsx b/components/ui/bubble.tsx
new file mode 100644
index 00000000..5e7a2908
--- /dev/null
+++ b/components/ui/bubble.tsx
@@ -0,0 +1,128 @@
+import * as React from "react"
+import { mergeProps } from "@base-ui/react/merge-props"
+import { useRender } from "@base-ui/react/use-render"
+import { cva, type VariantProps } from "class-variance-authority"
+
+import { cn } from "@/lib/utils"
+
+function BubbleGroup({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="bubble-group"
+ className={cn("flex min-w-0 flex-col gap-2", className)}
+ {...props}
+ />
+ )
+}
+
+const bubbleVariants = cva(
+ "group/bubble relative flex w-fit max-w-[80%] min-w-0 flex-col gap-1 group-data-[align=end]/message:self-end data-[align=end]:self-end data-[variant=ghost]:max-w-full",
+ {
+ variants: {
+ variant: {
+ default:
+ "*:data-[slot=bubble-content]:bg-primary *:data-[slot=bubble-content]:text-primary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-primary/80",
+ secondary:
+ "*:data-[slot=bubble-content]:bg-secondary *:data-[slot=bubble-content]:text-secondary-foreground [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)]",
+ muted:
+ "*:data-[slot=bubble-content]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[color-mix(in_oklch,var(--muted),var(--foreground)_5%)]",
+ tinted:
+ "*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.93_calc(c*0.4)_h)] *:data-[slot=bubble-content]:text-foreground dark:*:data-[slot=bubble-content]:bg-[oklch(from_var(--primary)_0.3_calc(c*0.4)_h)] [&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.88_calc(c*0.5)_h)] dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-[oklch(from_var(--primary)_0.35_calc(c*0.5)_h)]",
+ outline:
+ "*:data-[slot=bubble-content]:border-border *:data-[slot=bubble-content]:bg-background [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-input/30",
+ ghost:
+ "border-none *:data-[slot=bubble-content]:rounded-none *:data-[slot=bubble-content]:bg-transparent *:data-[slot=bubble-content]:p-0 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted [&>[data-slot=bubble-content]:is(button,a):hover]:text-foreground dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-muted/50",
+ destructive:
+ "*:data-[slot=bubble-content]:bg-destructive/10 *:data-[slot=bubble-content]:text-destructive dark:*:data-[slot=bubble-content]:bg-destructive/20 [&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/20 dark:[&>[data-slot=bubble-content]:is(button,a):hover]:bg-destructive/30",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ },
+ }
+)
+
+function Bubble({
+ variant = "default",
+ align = "start",
+ className,
+ ...props
+}: React.ComponentProps<"div"> &
+ VariantProps<typeof bubbleVariants> & {
+ align?: "start" | "end"
+ }) {
+ return (
+ <div
+ data-slot="bubble"
+ data-variant={variant}
+ data-align={align}
+ className={cn(bubbleVariants({ variant }), className)}
+ {...props}
+ />
+ )
+}
+
+function BubbleContent({
+ className,
+ render,
+ ...props
+}: useRender.ComponentProps<"div">) {
+ return useRender({
+ defaultTagName: "div",
+ props: mergeProps<"div">(
+ {
+ className: cn(
+ "w-fit max-w-full min-w-0 overflow-hidden rounded-3xl border border-transparent px-3.5 py-2.5 text-sm leading-relaxed wrap-break-word group-data-[align=end]/bubble:self-end [button]:text-left [button,a]:transition-colors [button,a]:outline-none [button,a]:focus-visible:border-ring [button,a]:focus-visible:ring-3 [button,a]:focus-visible:ring-ring/30",
+ className
+ ),
+ },
+ props
+ ),
+ render,
+ state: {
+ slot: "bubble-content",
+ },
+ })
+}
+
+const bubbleReactionsVariants = cva(
+ "absolute z-10 flex w-fit shrink-0 items-center justify-center gap-1 rounded-full bg-muted px-1.5 py-0.5 text-sm ring-3 ring-card has-[button]:p-0",
+ {
+ variants: {
+ side: {
+ top: "top-0 -translate-y-3/4",
+ bottom: "bottom-0 translate-y-3/4",
+ },
+ align: {
+ start: "left-3",
+ end: "right-3",
+ },
+ },
+ defaultVariants: {
+ side: "bottom",
+ align: "end",
+ },
+ }
+)
+
+function BubbleReactions({
+ side = "bottom",
+ align = "end",
+ className,
+ ...props
+}: React.ComponentProps<"div"> & {
+ align?: "start" | "end"
+ side?: "top" | "bottom"
+}) {
+ return (
+ <div
+ data-slot="bubble-reactions"
+ data-align={align}
+ data-side={side}
+ className={cn(bubbleReactionsVariants({ side, align }), className)}
+ {...props}
+ />
+ )
+}
+
+export { BubbleGroup, Bubble, BubbleContent, BubbleReactions }
diff --git a/components/ui/message-scroller.tsx b/components/ui/message-scroller.tsx
new file mode 100644
index 00000000..d7226a82
--- /dev/null
+++ b/components/ui/message-scroller.tsx
@@ -0,0 +1,131 @@
+"use client"
+
+import * as React from "react"
+import {
+ MessageScroller as MessageScrollerPrimitive,
+ useMessageScroller,
+ useMessageScrollerScrollable,
+ useMessageScrollerVisibility,
+} from "@shadcn/react/message-scroller"
+
+import { cn } from "@/lib/utils"
+import { Button } from "@/components/ui/button"
+import { ArrowDownIcon } from "lucide-react"
+
+function MessageScrollerProvider(
+ props: React.ComponentProps<typeof MessageScrollerPrimitive.Provider>
+) {
+ return <MessageScrollerPrimitive.Provider {...props} />
+}
+
+function MessageScroller({
+ className,
+ ...props
+}: React.ComponentProps<typeof MessageScrollerPrimitive.Root>) {
+ return (
+ <MessageScrollerPrimitive.Root
+ data-slot="message-scroller"
+ className={cn(
+ "group/message-scroller relative flex size-full min-h-0 flex-col overflow-hidden",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function MessageScrollerViewport({
+ className,
+ ...props
+}: React.ComponentProps<typeof MessageScrollerPrimitive.Viewport>) {
+ return (
+ <MessageScrollerPrimitive.Viewport
+ data-slot="message-scroller-viewport"
+ className={cn(
+ "size-full min-h-0 min-w-0 scroll-fade-b scrollbar-thin scrollbar-gutter-stable overflow-y-auto overscroll-contain contain-content data-autoscrolling:scrollbar-none",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function MessageScrollerContent({
+ className,
+ ...props
+}: React.ComponentProps<typeof MessageScrollerPrimitive.Content>) {
+ return (
+ <MessageScrollerPrimitive.Content
+ data-slot="message-scroller-content"
+ className={cn("flex h-max min-h-full flex-col gap-8", className)}
+ {...props}
+ />
+ )
+}
+
+function MessageScrollerItem({
+ className,
+ scrollAnchor = false,
+ ...props
+}: React.ComponentProps<typeof MessageScrollerPrimitive.Item>) {
+ return (
+ <MessageScrollerPrimitive.Item
+ data-slot="message-scroller-item"
+ scrollAnchor={scrollAnchor}
+ className={cn(
+ "min-w-0 shrink-0 [contain-intrinsic-size:auto_10rem] [content-visibility:auto]",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function MessageScrollerButton({
+ direction = "end",
+ className,
+ children,
+ render,
+ variant = "secondary",
+ size = "icon-sm",
+ ...props
+}: React.ComponentProps<typeof MessageScrollerPrimitive.Button> &
+ Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
+ return (
+ <MessageScrollerPrimitive.Button
+ data-slot="message-scroller-button"
+ data-direction={direction}
+ data-variant={variant}
+ data-size={size}
+ direction={direction}
+ className={cn(
+ "absolute inset-s-1/2 -translate-x-1/2 border-border bg-background text-foreground transition-[translate,scale,opacity] duration-200 hover:bg-muted hover:text-foreground data-[active=false]:pointer-events-none data-[active=false]:scale-95 data-[active=false]:opacity-0 data-[active=false]:duration-400 data-[active=false]:ease-[cubic-bezier(0.7,0,0.84,0)] data-[active=true]:translate-y-0 data-[active=true]:scale-100 data-[active=true]:opacity-100 data-[active=true]:ease-[cubic-bezier(0.23,1,0.32,1)] data-[direction=end]:bottom-4 data-[direction=end]:data-[active=false]:translate-y-full data-[direction=start]:top-4 data-[direction=start]:data-[active=false]:-translate-y-full rtl:translate-x-1/2 data-[direction=start]:[&_svg]:rotate-180",
+ className
+ )}
+ render={render ?? <Button variant={variant} size={size} />}
+ {...props}
+ >
+ {children ?? (
+ <>
+ <ArrowDownIcon
+ />
+ <span className="sr-only">
+ {direction === "end" ? "Scroll to end" : "Scroll to start"}
+ </span>
+ </>
+ )}
+ </MessageScrollerPrimitive.Button>
+ )
+}
+
+export {
+ MessageScrollerProvider,
+ MessageScroller,
+ MessageScrollerViewport,
+ MessageScrollerContent,
+ MessageScrollerItem,
+ MessageScrollerButton,
+ useMessageScroller,
+ useMessageScrollerScrollable,
+ useMessageScrollerVisibility,
+}
diff --git a/components/ui/message.tsx b/components/ui/message.tsx
new file mode 100644
index 00000000..fbc5e9fc
--- /dev/null
+++ b/components/ui/message.tsx
@@ -0,0 +1,92 @@
+import * as React from "react"
+
+import { cn } from "@/lib/utils"
+
+function MessageGroup({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="message-group"
+ className={cn("flex min-w-0 flex-col gap-2", className)}
+ {...props}
+ />
+ )
+}
+
+function Message({
+ className,
+ align = "start",
+ ...props
+}: React.ComponentProps<"div"> & { align?: "start" | "end" }) {
+ return (
+ <div
+ data-slot="message"
+ data-align={align}
+ className={cn(
+ "group/message relative flex w-full min-w-0 gap-2 text-sm data-[align=end]:flex-row-reverse",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function MessageAvatar({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="message-avatar"
+ className={cn(
+ "flex w-fit min-w-8 shrink-0 items-center justify-center self-end overflow-hidden rounded-full bg-muted group-has-data-[slot=message-footer]/message:-translate-y-8",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function MessageContent({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="message-content"
+ className={cn(
+ "flex w-full min-w-0 flex-col gap-2.5 wrap-break-word group-data-[align=end]/message:*:data-slot:self-end",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function MessageHeader({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="message-header"
+ className={cn(
+ "flex max-w-full min-w-0 items-center px-3.5 text-xs font-medium text-muted-foreground group-has-data-[variant=ghost]/message:px-0",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function MessageFooter({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="message-footer"
+ className={cn(
+ "flex max-w-full min-w-0 items-center px-3.5 text-xs font-medium text-muted-foreground group-has-data-[variant=ghost]/message:px-0 group-data-[align=end]/message:justify-end",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+export {
+ MessageGroup,
+ Message,
+ MessageAvatar,
+ MessageContent,
+ MessageFooter,
+ MessageHeader,
+}
diff --git a/content/docs/ui/blocks/chat-flow.mdx b/content/docs/ui/blocks/chat-flow.mdx
new file mode 100644
index 00000000..9875cc8f
--- /dev/null
+++ b/content/docs/ui/blocks/chat-flow.mdx
@@ -0,0 +1,61 @@
+---
+title: Chat Flow
+description: A messaging conversation that types outgoing messages, shows typing indicators, and pops in incoming replies with reactions
+---
+
+<BlockPreview name="chat-flow" />
+
+A composition scene that renders a full chat conversation β€” a contact header, a message thread, and a composer input. Outgoing messages type themselves into the input field then send; incoming replies are preceded by a typing indicator that swaps to the reply bubble; reaction emojis pop in after each reply lands.
+
+## Installation
+
+<InstallBlock name="chat-flow" />
+
+<Note>
+Installing `chat-flow` automatically installs the shared `remocn-ui` core and all composed primitives via `registryDependencies`: `caret`, `message-bubble`, and `typing-indicator`. You do not need to install them separately.
+</Note>
+
+## Composed primitives
+
+- **MessageBubble** β€” state-driven speech bubble with incoming/outgoing variants and optional reaction badges, styled to match the shadcn `Bubble`
+- **TypingIndicator** β€” bouncing dots that play inside an incoming bubble before the reply text appears
+- **Caret** β€” blinking caret in the composer; the outgoing message reveals character by character into a shadcn-style textarea before sending
+
+The layout is a mobile-width column β€” a contact header, the message thread, and a textarea composer with a `+` action and a send button.
+
+## Timeline narrative
+
+The scene opens with the composer focused. The first outgoing message ("Hey β€” ready for the demo?") types into the input, then sends β€” the bubble enters from below and settles into the thread. The contact's typing indicator appears inside an incoming bubble; after a beat the indicator swaps to the reply text ("Yep, pushing it live now") and the πŸ”₯ reaction badge pops in. The second outgoing message types and sends ("Perfect, sending the link over"), and its πŸ‘ reaction badge follows. `chatFlowDuration` returns the total frame count for the default script at a given speed; `chatFlowSchedule` exposes the per-message frame offsets for synchronisation with other scene elements.
+
+## Props
+
+<PropsTable
+ rows={[
+ {
+ name: "messages",
+ type: "ChatMessage[]",
+ description: "Array of messages to animate. Each item has {from: 'me' | 'them', text: string, reaction?: string}. Defaults to the built-in three-message demo script.",
+ },
+ {
+ name: "contact",
+ type: "{ name: string; avatar?: string }",
+ description: "Display name and optional avatar URL shown in the contact header above the thread.",
+ },
+ {
+ name: "accentColor",
+ type: "string",
+ description: "Override for the outgoing bubble color. 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 e3fdd98d..49d5731d 100644
--- a/content/docs/ui/blocks/index.mdx
+++ b/content/docs/ui/blocks/index.mdx
@@ -7,6 +7,12 @@ Complete, shippable video compositions built from remocn-ui primitives. Each blo
<ComponentCardGrid
items={[
+ {
+ name: "ChatFlow",
+ description: "Messaging conversation with outgoing typing, incoming replies, and reaction badges",
+ status: "stable",
+ href: "/docs/ui/blocks/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 30f068c2..16e0746c 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", "signup-flow", "checkout-flow", "settings-toggle-flow"]
+ "pages": ["index", "chat-flow", "signup-flow", "checkout-flow", "settings-toggle-flow"]
}
diff --git a/content/docs/ui/components/message-bubble.mdx b/content/docs/ui/components/message-bubble.mdx
new file mode 100644
index 00000000..c1698e6f
--- /dev/null
+++ b/content/docs/ui/components/message-bubble.mdx
@@ -0,0 +1,143 @@
+---
+title: Message Bubble
+description: A state-driven speech bubble with incoming and outgoing variants and an optional reaction badge
+---
+
+<UiComponentPreview name="message-bubble" />
+
+A state atom whose appearance (`hidden`, `visible`) is a pure function of the `state` prop. The bubble enters from 12 px below at 0.94 scale, fades and scales up to rest. Incoming bubbles align to the left on `theme.muted`; outgoing bubbles align to the right on `theme.primary`. An optional reaction emoji badge pops in via the `reactionStyle` channel.
+
+## Installation
+
+<InstallBlock name="message-bubble" />
+
+<Note>
+Installing `message-bubble` automatically installs the shared `remocn-ui` core (`lib/remocn-ui/`) via `registryDependencies` (`["remocn-ui"]`). You do not need to install it separately. Both `message-bubble` (the renderer) and `use-message-bubble-transition` (the hook) are copied into your project.
+</Note>
+
+## States
+
+`MessageBubbleState` is:
+
+```ts
+type MessageBubbleState =
+ | "hidden"
+ | "visible"
+```
+
+`hidden` rests at opacity 0, translateY 12 px, and scale 0.94. `visible` brings the bubble to full opacity, translateY 0, and scale 1.
+
+## Smooth transitions
+
+For animated enter, use `useMessageBubbleTransition` from the copied `use-message-bubble-transition.ts` file. It reads the frame, interpolates between state presets, and returns a resolved `MessageBubbleStyle` β€” pass it to the `style` prop:
+
+```tsx
+import { MessageBubble } from "@/components/remocn/message-bubble";
+import { useMessageBubbleTransition } from "@/components/remocn/use-message-bubble-transition";
+
+export const Scene = () => {
+ const style = useMessageBubbleTransition([
+ { at: 20, state: "visible", duration: 14 },
+ { at: 80, state: "hidden", duration: 14 },
+ ]);
+
+ return (
+ <div style={{ position: "relative", width: "100%", height: "100%" }}>
+ <MessageBubble style={style} variant="incoming">Hey β€” ready for the demo?</MessageBubble>
+ </div>
+ );
+};
+```
+
+The `duration` field overrides the file's `DEFAULT_DURATION` (= `14`) for that specific transition. To globally tune timing and easing, edit `use-message-bubble-transition.ts` directly in your project β€” that file is yours (shadcn "own your code" philosophy).
+
+`style` takes precedence over `state` when both are provided.
+
+## Variants
+
+The `variant` prop sets the color and alignment of the bubble.
+
+```ts
+type MessageBubbleVariant =
+ | "incoming"
+ | "outgoing"
+```
+
+`incoming` uses `theme.muted` as the background and `theme.foreground` as text, aligned to the left. `outgoing` uses `theme.primary` as the background and `theme.primaryForeground` as text, aligned to the right.
+
+```tsx
+<MessageBubble variant="incoming">Hey β€” ready for the demo?</MessageBubble>
+<MessageBubble variant="outgoing">Yep, pushing it live now</MessageBubble>
+```
+
+## Reactions
+
+Pass a reaction emoji string to the `reaction` prop to render an emoji badge anchored to the bottom corner of the bubble. Drive the badge's animated entrance via the `reactionStyle` channel β€” a separate style object that controls the badge opacity and scale independently from the bubble body.
+
+```tsx
+<MessageBubble
+ variant="incoming"
+ state="visible"
+ reaction="πŸ”₯"
+ reactionStyle={{ opacity: 1, scale: 1 }}
+>
+ Yep, pushing it live now
+</MessageBubble>
+```
+
+When `reaction` is omitted no badge is rendered.
+
+## Props
+
+<PropsTable
+ rows={[
+ {
+ name: "state",
+ type: "\"hidden\" | \"visible\"",
+ default: "\"hidden\"",
+ description: "Current visual state (snap path). State changes snap β€” no automatic cross-fade.",
+ },
+ {
+ name: "style",
+ type: "MessageBubbleStyle",
+ description: "Resolved animated visual (smooth path). Pass an interpolated MessageBubbleStyle from useMessageBubbleTransition. Takes precedence over state when provided.",
+ },
+ {
+ name: "variant",
+ type: "\"incoming\" | \"outgoing\"",
+ default: "\"incoming\"",
+ description: "Sets the bubble color and alignment. incoming uses theme.muted and left-aligns; outgoing uses theme.primary and right-aligns.",
+ },
+ {
+ name: "children",
+ type: "React.ReactNode",
+ description: "The message text or content rendered inside the bubble.",
+ },
+ {
+ name: "reaction",
+ type: "string",
+ description: "Optional emoji string rendered as a badge anchored to the bottom corner of the bubble.",
+ },
+ {
+ name: "reactionStyle",
+ type: "MessageBubbleStyle",
+ description: "Animated style for the reaction badge. Controls opacity and scale independently from the bubble body.",
+ },
+ {
+ name: "maxWidth",
+ type: "number",
+ default: "460",
+ description: "Maximum width of the bubble in pixels.",
+ },
+ {
+ name: "theme",
+ type: "Partial<RemocnTheme>",
+ description: "Per-component theme override. Merges with the active RemocnUIProvider theme and the mode defaults. Must be concrete oklch/hex/rgb values β€” not CSS custom properties.",
+ },
+ {
+ name: "className",
+ type: "string",
+ description: "Optional className applied to the bubble wrapper element.",
+ },
+ ]}
+/>
diff --git a/content/docs/ui/components/meta.json b/content/docs/ui/components/meta.json
index 1713166e..93027f3b 100644
--- a/content/docs/ui/components/meta.json
+++ b/content/docs/ui/components/meta.json
@@ -1,5 +1,5 @@
{
"title": "Components",
"collapsible": false,
- "pages": ["accordion", "alert-dialog", "blur-in", "button", "caret", "checkbox", "combobox", "command-menu", "context-menu", "cursor", "dialog", "drawer", "sheet", "dropdown-menu", "input", "popover", "progress", "radio", "resizable", "select", "skeleton", "slider", "spinner", "stepper", "switch", "tabs", "toast", "toggle-group", "tooltip"]
+ "pages": ["accordion", "alert-dialog", "blur-in", "button", "caret", "checkbox", "combobox", "command-menu", "context-menu", "cursor", "dialog", "drawer", "sheet", "dropdown-menu", "input", "message-bubble", "popover", "progress", "radio", "resizable", "select", "skeleton", "slider", "spinner", "stepper", "switch", "tabs", "toast", "toggle-group", "tooltip", "typing-indicator"]
}
diff --git a/content/docs/ui/components/typing-indicator.mdx b/content/docs/ui/components/typing-indicator.mdx
new file mode 100644
index 00000000..86de0d08
--- /dev/null
+++ b/content/docs/ui/components/typing-indicator.mdx
@@ -0,0 +1,89 @@
+---
+title: Typing Indicator
+description: A motion atom that renders N bouncing dots driven directly by useCurrentFrame
+---
+
+<UiComponentPreview name="typing-indicator" />
+
+A motion atom that reads `useCurrentFrame` directly and produces N dots bouncing with staggered sine offsets. No state prop β€” the animation runs continuously as long as the component is mounted on the timeline. Drop it into any bubble or container to signal that a message is being composed.
+
+## Installation
+
+<InstallBlock name="typing-indicator" />
+
+<Note>
+`typing-indicator` is a motion atom β€” it reads the Remotion frame internally. Installing it pulls the shared `remocn-ui` core (`lib/remocn-ui/`) via `registryDependencies` (`["remocn-ui"]`). You do not need to install the core separately.
+</Note>
+
+## Usage
+
+Place `TypingIndicator` inside a `MessageBubble` (or any container) to show the typing state before a reply bubble enters:
+
+```tsx
+import { MessageBubble } from "@/components/remocn/message-bubble";
+import { TypingIndicator } from "@/components/remocn/typing-indicator";
+
+export const Scene = () => (
+ <div style={{ position: "relative", width: "100%", height: "100%" }}>
+ <MessageBubble variant="incoming" state="visible">
+ <TypingIndicator />
+ </MessageBubble>
+ </div>
+);
+```
+
+The helper `typingDotOffset(frame, index, opts)` is exported for cases where you want to drive individual dot positions from your own layout.
+
+## Props
+
+<PropsTable
+ rows={[
+ {
+ name: "dotCount",
+ type: "number",
+ default: "3",
+ description: "Number of bouncing dots to render.",
+ },
+ {
+ name: "color",
+ type: "string",
+ default: "\"currentColor\"",
+ description: "Fill color of the dots. Inherits the parent text color by default.",
+ },
+ {
+ name: "size",
+ type: "number",
+ default: "8",
+ description: "Diameter of each dot in pixels.",
+ },
+ {
+ name: "gap",
+ type: "number",
+ default: "5",
+ description: "Horizontal gap between dots in pixels.",
+ },
+ {
+ name: "amplitude",
+ type: "number",
+ default: "5",
+ description: "Vertical bounce amplitude in pixels.",
+ },
+ {
+ name: "speed",
+ type: "number",
+ default: "1",
+ description: "Multiplier on the overall animation speed. Values above 1 speed up; below 1 slow down.",
+ },
+ {
+ name: "cyclesPerSecond",
+ type: "number",
+ default: "1.1",
+ description: "Number of full bounce cycles per second.",
+ },
+ {
+ name: "className",
+ type: "string",
+ description: "Optional className applied to the dots container element.",
+ },
+ ]}
+/>
diff --git a/package.json b/package.json
index fed6b4c7..8150630b 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
"@remotion/google-fonts": "4.0.473",
"@remotion/player": "4.0.473",
"@remotion/renderer": "4.0.473",
+ "@shadcn/react": "^0.1.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
diff --git a/registry/__index__.tsx b/registry/__index__.tsx
index 5ec7ea79..a4044d6c 100644
--- a/registry/__index__.tsx
+++ b/registry/__index__.tsx
@@ -193,6 +193,10 @@ import { CursorPreview } from "@/registry/remocn-ui/cursor/preview";
import { cursorConfig } from "@/registry/remocn-ui/cursor/config";
import { ToastPreview } from "@/registry/remocn-ui/toast/preview";
import { toastConfig } from "@/registry/remocn-ui/toast/config";
+import { MessageBubblePreview } from "@/registry/remocn-ui/message-bubble/preview";
+import { messageBubbleConfig } from "@/registry/remocn-ui/message-bubble/config";
+import { TypingIndicatorPreview } from "@/registry/remocn-ui/typing-indicator/preview";
+import { typingIndicatorConfig } from "@/registry/remocn-ui/typing-indicator/config";
import { CommandMenuItem } from "@/registry/remocn-ui/command-menu-item";
import { commandMenuItemConfig } from "@/registry/remocn-ui/command-menu-item/config";
import { CommandMenu } from "@/registry/remocn-ui/command-menu";
@@ -445,6 +449,14 @@ const registry: Record<string, RegistryEntry> = {
// centers the toast on a theme-background stage); the shipped Toast is a
// placement-agnostic card the caller positions.
"toast": { Component: ToastPreview, config: toastConfig },
+ "message-bubble": {
+ Component: MessageBubblePreview,
+ config: messageBubbleConfig,
+ },
+ "typing-indicator": {
+ Component: TypingIndicatorPreview,
+ config: typingIndicatorConfig,
+ },
"command-menu-item": {
Component: CommandMenuItem,
config: commandMenuItemConfig,
diff --git a/registry/remocn-ui/chat-flow/__tests__/chat-flow.test.ts b/registry/remocn-ui/chat-flow/__tests__/chat-flow.test.ts
new file mode 100644
index 00000000..e06d8ee8
--- /dev/null
+++ b/registry/remocn-ui/chat-flow/__tests__/chat-flow.test.ts
@@ -0,0 +1,188 @@
+
+import { describe, expect, it } from "bun:test";
+import {
+ chatFlowSchedule,
+ chatFlowDuration,
+ sendPulse,
+ type ChatMessage,
+} from "../index";
+
+const MESSAGES: ChatMessage[] = [
+ { from: "me", text: "hi" },
+ { from: "them", text: "yo", reaction: "πŸ”₯" },
+];
+
+describe("chatFlowSchedule: items length", () => {
+ it("returns 2 items for 2 messages", () => {
+ const { items } = chatFlowSchedule(MESSAGES);
+ expect(items.length).toBe(2);
+ });
+});
+
+describe("chatFlowSchedule: item 0 (from='me', text='hi')", () => {
+ const { items } = chatFlowSchedule(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("chatFlowSchedule: item 1 (from='them', text='yo', reaction='πŸ”₯')", () => {
+ const { items } = chatFlowSchedule(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)", () => {
+ expect(item1.presenceStart).toBe(72);
+ expect(item1.presenceStart).toBe(item1.typingStart);
+ });
+});
+
+describe("chatFlowSchedule: monotonic ordering", () => {
+ const { items } = chatFlowSchedule(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("chatFlowSchedule: duration", () => {
+ const { duration } = chatFlowSchedule(MESSAGES);
+
+ it("duration is a positive integer", () => {
+ expect(duration).toBeGreaterThan(0);
+ expect(Number.isInteger(duration)).toBe(true);
+ });
+
+ it("duration (170) is greater than all revealAt values", () => {
+ const { items } = chatFlowSchedule(MESSAGES);
+ expect(duration).toBe(170);
+ for (const item of items) {
+ expect(duration).toBeGreaterThan(item.revealAt);
+ }
+ });
+
+ it("duration is 170", () => {
+ expect(duration).toBe(170);
+ });
+});
+
+describe("chatFlowDuration", () => {
+ it("chatFlowDuration(messages) with default speed=1 equals schedule duration (170)", () => {
+ expect(chatFlowDuration(MESSAGES)).toBe(170);
+ });
+
+ it("chatFlowDuration(messages) equals chatFlowSchedule(messages).duration", () => {
+ expect(chatFlowDuration(MESSAGES)).toBe(chatFlowSchedule(MESSAGES).duration);
+ });
+
+ it("chatFlowDuration(messages, 2) equals Math.ceil(schedule.duration / 2)", () => {
+ const raw = chatFlowSchedule(MESSAGES).duration;
+ expect(chatFlowDuration(MESSAGES, 2)).toBe(Math.ceil(raw / 2));
+ });
+
+ it("chatFlowDuration(messages, 2) is 85", () => {
+ expect(chatFlowDuration(MESSAGES, 2)).toBe(85);
+ });
+});
+
+describe("sendPulse: at sendAt of a 'me' item (eff === sendAt)", () => {
+ const { items } = chatFlowSchedule(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 } = chatFlowSchedule(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 } = chatFlowSchedule(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("chatFlowSchedule: empty messages", () => {
+ it("returns empty items array", () => {
+ expect(chatFlowSchedule([]).items).toEqual([]);
+ });
+
+ it("duration is positive (LEAD_IN + TAIL)", () => {
+ expect(chatFlowSchedule([]).duration).toBeGreaterThan(0);
+ });
+});
diff --git a/registry/remocn-ui/chat-flow/index.tsx b/registry/remocn-ui/chat-flow/index.tsx
new file mode 100644
index 00000000..a973dd74
--- /dev/null
+++ b/registry/remocn-ui/chat-flow/index.tsx
@@ -0,0 +1,577 @@
+"use client";
+
+import { interpolate, spring, useCurrentFrame, useVideoConfig } from "remotion";
+import {
+ type RemocnTheme,
+ mixOklch,
+ revealedText,
+ useRemocnTheme,
+} from "@/lib/remocn-ui";
+import { Caret } from "@/components/remocn/caret";
+import {
+ MessageBubble,
+ type MessageBubbleReactionStyle,
+ type MessageBubbleStyle,
+} from "@/components/remocn/message-bubble";
+import { useMessageBubbleTransition } from "@/components/remocn/use-message-bubble-transition";
+import { TypingIndicator } from "@/components/remocn/typing-indicator";
+
+export interface ChatMessage {
+ from: "me" | "them";
+ text: string;
+ reaction?: string;
+}
+
+export interface ChatContact {
+ name: string;
+ avatar?: string;
+}
+
+export interface ChatFlowProps {
+ messages?: ChatMessage[];
+ contact?: ChatContact;
+ 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 DEFAULT_MESSAGES: ChatMessage[] = [
+ { 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 ChatFlowSchedule {
+ items: ScheduledMessage[];
+ duration: number;
+}
+
+export function chatFlowSchedule(messages: ChatMessage[]): ChatFlowSchedule {
+ 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 chatFlowDuration(
+ messages: ChatMessage[] = DEFAULT_MESSAGES,
+ speed = 1,
+): number {
+ const raw = chatFlowSchedule(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 typingBubbleStyle(
+ eff: number,
+ typingStart: number,
+ revealAt: number,
+): MessageBubbleStyle {
+ const inOpacity = interpolate(eff, [typingStart, typingStart + 8], [0, 1], {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+ });
+ const outOpacity = interpolate(eff, [revealAt - 6, revealAt], [1, 0], {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+ });
+ const translateY = interpolate(eff, [typingStart, typingStart + 8], [10, 0], {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+ });
+ return { opacity: inOpacity * outOpacity, translateY, scale: 1 };
+}
+
+function Avatar({
+ contact,
+ theme,
+}: {
+ contact: ChatContact;
+ theme: RemocnTheme;
+}) {
+ const initial = contact.name.trim().charAt(0).toUpperCase();
+ return (
+ <div
+ style={{
+ flexShrink: 0,
+ width: 32,
+ height: 32,
+ minWidth: 32,
+ borderRadius: "50%",
+ overflow: "hidden",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ background: theme.muted,
+ color: theme.mutedForeground,
+ fontSize: 14,
+ 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 SendIcon({ color }: { color: string }) {
+ return (
+ <svg width={20} height={20} viewBox="0 0 24 24" fill="none">
+ <path
+ d="M12 19V5M12 5l-6 6M12 5l6 6"
+ stroke={color}
+ strokeWidth={2.2}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ />
+ </svg>
+ );
+}
+
+function PlusIcon({ color }: { color: string }) {
+ return (
+ <svg width={20} height={20} viewBox="0 0 24 24" fill="none">
+ <path
+ d="M12 5v14M5 12h14"
+ stroke={color}
+ strokeWidth={2.2}
+ strokeLinecap="round"
+ />
+ </svg>
+ );
+}
+
+export function ChatFlow({
+ messages = DEFAULT_MESSAGES,
+ contact,
+ accentColor,
+ speed = 1,
+ theme: themeOverride,
+}: ChatFlowProps) {
+ const frame = useCurrentFrame();
+ const eff = frame * speed;
+
+ const themeProp = {
+ ...themeOverride,
+ ...(accentColor ? { primary: accentColor } : {}),
+ };
+ const resolved = useRemocnTheme(themeProp, "light");
+
+ const { items } = chatFlowSchedule(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);
+
+ const composerBackground = mixOklch(
+ resolved.background,
+ resolved.muted,
+ 0.55,
+ );
+
+ 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%",
+ padding: "24px 16px 18px",
+ boxSizing: "border-box",
+ }}
+ >
+ {contact !== undefined && (
+ <div
+ style={{
+ display: "flex",
+ alignItems: "center",
+ gap: 10,
+ paddingBottom: 16,
+ marginBottom: 8,
+ borderBottom: `1px solid ${resolved.border}`,
+ }}
+ >
+ <Avatar contact={contact} theme={resolved} />
+ <div style={{ display: "flex", flexDirection: "column", gap: 2 }}>
+ <span
+ style={{
+ fontSize: 15,
+ fontWeight: 600,
+ lineHeight: 1.25,
+ letterSpacing: "-0.01em",
+ color: resolved.foreground,
+ }}
+ >
+ {contact.name}
+ </span>
+ <span
+ style={{
+ display: "flex",
+ alignItems: "center",
+ gap: 5,
+ fontSize: 12,
+ lineHeight: 1.2,
+ color: "oklch(0.62 0.17 150)",
+ }}
+ >
+ <span
+ style={{
+ width: 6,
+ height: 6,
+ borderRadius: "50%",
+ background: "oklch(0.62 0.17 150)",
+ }}
+ />
+ online
+ </span>
+ </div>
+ </div>
+ )}
+
+ <div
+ style={{
+ position: "relative",
+ flex: 1,
+ minHeight: 0,
+ overflow: "hidden",
+ WebkitMaskImage:
+ "linear-gradient(to bottom, transparent 0, #000 48px, #000 100%)",
+ maskImage:
+ "linear-gradient(to bottom, transparent 0, #000 48px, #000 100%)",
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ justifyContent: "flex-end",
+ gap: 20,
+ minHeight: "100%",
+ paddingTop: 24,
+ paddingBottom: 22,
+ }}
+ >
+ {present.map((item) => (
+ <ChatRow
+ key={item.index}
+ item={item}
+ eff={eff}
+ speed={speed}
+ contact={contact}
+ themeProp={themeProp}
+ theme={resolved}
+ />
+ ))}
+ </div>
+ </div>
+
+ <div
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ gap: 10,
+ marginTop: 14,
+ padding: 14,
+ borderRadius: 24,
+ background: composerBackground,
+ border: `1px solid ${resolved.border}`,
+ }}
+ >
+ <div
+ style={{
+ display: "flex",
+ alignItems: "flex-start",
+ minHeight: 24,
+ fontSize: 15,
+ lineHeight: 1.45,
+ letterSpacing: "-0.01em",
+ color: sendActive
+ ? resolved.foreground
+ : resolved.mutedForeground,
+ }}
+ >
+ <span style={{ whiteSpace: "pre-wrap", wordBreak: "break-word" }}>
+ {sendActive ? composerText : "Message"}
+ </span>
+ {typing && (
+ <Caret
+ color={resolved.foreground}
+ height={18}
+ radius={1}
+ blink
+ marginLeft={composerText.length > 0 ? 2 : 0}
+ />
+ )}
+ </div>
+ <div
+ style={{
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "space-between",
+ }}
+ >
+ <div
+ style={{
+ width: 38,
+ height: 38,
+ borderRadius: "50%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ border: `1px solid ${resolved.border}`,
+ background: "transparent",
+ }}
+ >
+ <PlusIcon color={resolved.mutedForeground} />
+ </div>
+ <div
+ style={{
+ width: 38,
+ height: 38,
+ borderRadius: "50%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ background: sendActive
+ ? resolved.primary
+ : mixOklch(resolved.background, resolved.muted, 0.6),
+ transform: `scale(${sendScale})`,
+ }}
+ >
+ <SendIcon
+ color={
+ sendActive
+ ? resolved.primaryForeground
+ : resolved.mutedForeground
+ }
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function ChatRow({
+ item,
+ eff,
+ speed,
+ contact,
+ themeProp,
+ theme,
+}: {
+ item: ScheduledMessage;
+ eff: number;
+ speed: number;
+ contact?: ChatContact;
+ themeProp: Partial<RemocnTheme>;
+ theme: RemocnTheme;
+}) {
+ const { fps } = useVideoConfig();
+ const variant = item.from === "me" ? "outgoing" : "incoming";
+ const showTyping =
+ item.from === "them" &&
+ item.typingStart !== undefined &&
+ eff < item.revealAt;
+
+ const bubbleStyle = useMessageBubbleTransition(
+ [{ at: item.revealAt, state: "visible", duration: REVEAL }],
+ { speed },
+ );
+
+ let reactionStyle: MessageBubbleReactionStyle | undefined;
+ if (item.reactAt !== undefined) {
+ const reactAt = item.reactAt;
+ const pop = spring({
+ fps,
+ frame: eff - reactAt,
+ config: { damping: 11, stiffness: 220, mass: 0.6 },
+ });
+ const opacity = interpolate(eff, [reactAt, reactAt + 5], [0, 1], {
+ extrapolateLeft: "clamp",
+ extrapolateRight: "clamp",
+ });
+ reactionStyle = { opacity, scale: pop };
+ }
+
+ const bubbleNode = showTyping ? (
+ <MessageBubble
+ variant="incoming"
+ style={typingBubbleStyle(eff, item.typingStart ?? 0, item.revealAt)}
+ theme={themeProp}
+ >
+ <TypingIndicator color={theme.mutedForeground} />
+ </MessageBubble>
+ ) : (
+ <MessageBubble
+ variant={variant}
+ style={bubbleStyle}
+ reaction={item.reaction}
+ reactionStyle={reactionStyle}
+ theme={themeProp}
+ >
+ {item.text}
+ </MessageBubble>
+ );
+
+ if (item.from === "them" && contact !== undefined) {
+ return (
+ <div style={{ display: "flex", alignItems: "flex-end", gap: 8 }}>
+ <Avatar contact={contact} theme={theme} />
+ <div style={{ flex: 1, minWidth: 0 }}>{bubbleNode}</div>
+ </div>
+ );
+ }
+
+ return bubbleNode;
+}
diff --git a/registry/remocn-ui/message-bubble/__tests__/message-bubble.test.ts b/registry/remocn-ui/message-bubble/__tests__/message-bubble.test.ts
new file mode 100644
index 00000000..f94f7a3f
--- /dev/null
+++ b/registry/remocn-ui/message-bubble/__tests__/message-bubble.test.ts
@@ -0,0 +1,546 @@
+
+import { describe, expect, it } from "bun:test";
+import {
+ messageBubbleStyle,
+ messageBubbleStyleContext,
+ messageBubbleReactionStyle,
+ type MessageBubbleState,
+ type MessageBubbleVariant,
+} from "../index";
+import {
+ tweenMessageBubbleStyle,
+ DEFAULT_DURATION,
+} from "../use-message-bubble-transition";
+import { messageBubbleConfig } from "../config";
+import { defaultLightTheme, defaultDarkTheme, easings, clamp01 } from "@/lib/remocn-ui";
+import type { Step } from "@/lib/remocn-ui";
+
+const VALID_STATES: readonly MessageBubbleState[] = ["hidden", "visible"];
+const VALID_VARIANTS: readonly MessageBubbleVariant[] = ["incoming", "outgoing"];
+
+type SnippetValues = {
+ state?: string;
+ variant?: string;
+ text?: string;
+ reaction?: string;
+};
+const snippet = (values: SnippetValues): string =>
+ messageBubbleConfig.snippet(values as Record<string, unknown>);
+
+describe("DEFAULT_DURATION", () => {
+ it("is 14 frames", () => {
+ expect(DEFAULT_DURATION).toBe(14);
+ });
+});
+
+describe("messageBubbleStyle: hidden state β€” off-screen keyframe", () => {
+ const s = messageBubbleStyle("hidden");
+
+ it("opacity is 0 (invisible)", () => {
+ expect(s.opacity).toBe(0);
+ });
+
+ it("translateY is 12 (enters from 12px below)", () => {
+ expect(s.translateY).toBe(12);
+ });
+
+ it("scale is 0.94 (slightly shrunken at rest-hidden)", () => {
+ expect(s.scale).toBeCloseTo(0.94, 10);
+ });
+});
+
+describe("messageBubbleStyle: visible state β€” resting keyframe", () => {
+ const s = messageBubbleStyle("visible");
+
+ it("opacity is 1 (fully visible)", () => {
+ expect(s.opacity).toBe(1);
+ });
+
+ it("translateY is 0 (at rest position)", () => {
+ expect(s.translateY).toBe(0);
+ });
+
+ it("scale is 1 (full size)", () => {
+ expect(s.scale).toBe(1);
+ });
+});
+
+describe("messageBubbleStyle: both states are complete keyframes", () => {
+ it("every MessageBubbleStyle field is defined and numeric for every state", () => {
+ for (const state of VALID_STATES) {
+ const s = messageBubbleStyle(state);
+ expect(typeof s.opacity).toBe("number");
+ expect(typeof s.translateY).toBe("number");
+ expect(typeof s.scale).toBe("number");
+ }
+ });
+
+ it("hidden and visible have distinct opacity (0 vs 1)", () => {
+ expect(messageBubbleStyle("hidden").opacity).toBe(0);
+ expect(messageBubbleStyle("visible").opacity).toBe(1);
+ });
+
+ it("hidden and visible have distinct translateY (12 vs 0)", () => {
+ expect(messageBubbleStyle("hidden").translateY).toBe(12);
+ expect(messageBubbleStyle("visible").translateY).toBe(0);
+ });
+
+ it("hidden and visible have distinct scale (0.94 vs 1)", () => {
+ expect(messageBubbleStyle("hidden").scale).toBeCloseTo(0.94, 10);
+ expect(messageBubbleStyle("visible").scale).toBe(1);
+ });
+});
+
+describe("messageBubbleStyleContext: incoming variant (light theme)", () => {
+ const ctx = messageBubbleStyleContext("incoming", defaultLightTheme);
+
+ it("background equals theme.muted", () => {
+ expect(ctx.background).toBe(defaultLightTheme.muted);
+ });
+
+ it("color equals theme.foreground", () => {
+ expect(ctx.color).toBe(defaultLightTheme.foreground);
+ });
+
+ it("align is 'flex-start'", () => {
+ expect(ctx.align).toBe("flex-start");
+ });
+
+ it("reactionSide is 'left'", () => {
+ expect(ctx.reactionSide).toBe("left");
+ });
+});
+
+describe("messageBubbleStyleContext: outgoing variant (light theme)", () => {
+ const ctx = messageBubbleStyleContext("outgoing", defaultLightTheme);
+
+ it("background equals theme.primary", () => {
+ expect(ctx.background).toBe(defaultLightTheme.primary);
+ });
+
+ it("color equals theme.primaryForeground", () => {
+ expect(ctx.color).toBe(defaultLightTheme.primaryForeground);
+ });
+
+ it("align is 'flex-end'", () => {
+ expect(ctx.align).toBe("flex-end");
+ });
+
+ it("reactionSide is 'right'", () => {
+ expect(ctx.reactionSide).toBe("right");
+ });
+});
+
+describe("messageBubbleStyleContext: incoming variant (dark theme)", () => {
+ const ctx = messageBubbleStyleContext("incoming", defaultDarkTheme);
+
+ it("background equals dark theme.muted", () => {
+ expect(ctx.background).toBe(defaultDarkTheme.muted);
+ });
+
+ it("color equals dark theme.foreground", () => {
+ expect(ctx.color).toBe(defaultDarkTheme.foreground);
+ });
+
+ it("align is 'flex-start'", () => {
+ expect(ctx.align).toBe("flex-start");
+ });
+
+ it("reactionSide is 'left'", () => {
+ expect(ctx.reactionSide).toBe("left");
+ });
+});
+
+describe("messageBubbleStyleContext: outgoing variant (dark theme)", () => {
+ const ctx = messageBubbleStyleContext("outgoing", defaultDarkTheme);
+
+ it("background equals dark theme.primary", () => {
+ expect(ctx.background).toBe(defaultDarkTheme.primary);
+ });
+
+ it("color equals dark theme.primaryForeground", () => {
+ expect(ctx.color).toBe(defaultDarkTheme.primaryForeground);
+ });
+
+ it("align is 'flex-end'", () => {
+ expect(ctx.align).toBe("flex-end");
+ });
+
+ it("reactionSide is 'right'", () => {
+ expect(ctx.reactionSide).toBe("right");
+ });
+});
+
+describe("messageBubbleStyleContext: light and dark muted colors differ", () => {
+ it("incoming background differs between light and dark themes", () => {
+ const light = messageBubbleStyleContext("incoming", defaultLightTheme);
+ const dark = messageBubbleStyleContext("incoming", defaultDarkTheme);
+ expect(light.background).not.toBe(dark.background);
+ });
+});
+
+describe("messageBubbleReactionStyle: visible state", () => {
+ const r = messageBubbleReactionStyle("visible");
+
+ it("opacity is 1", () => {
+ expect(r.opacity).toBe(1);
+ });
+
+ it("scale is 1", () => {
+ expect(r.scale).toBe(1);
+ });
+});
+
+describe("messageBubbleReactionStyle: hidden state", () => {
+ const r = messageBubbleReactionStyle("hidden");
+
+ it("opacity is 0", () => {
+ expect(r.opacity).toBe(0);
+ });
+
+ it("scale is 0", () => {
+ expect(r.scale).toBe(0);
+ });
+});
+
+describe("tweenMessageBubbleStyle: t=0 returns values equal to `a`", () => {
+ const a = messageBubbleStyle("hidden");
+ const b = messageBubbleStyle("visible");
+ const r = tweenMessageBubbleStyle(a, b, 0);
+
+ it("opacity equals a.opacity at t=0", () => {
+ expect(r.opacity).toBeCloseTo(a.opacity, 10);
+ });
+
+ it("translateY equals a.translateY at t=0", () => {
+ expect(r.translateY).toBeCloseTo(a.translateY, 10);
+ });
+
+ it("scale equals a.scale at t=0", () => {
+ expect(r.scale).toBeCloseTo(a.scale, 10);
+ });
+});
+
+describe("tweenMessageBubbleStyle: t=1 returns values equal to `b`", () => {
+ const a = messageBubbleStyle("hidden");
+ const b = messageBubbleStyle("visible");
+ const r = tweenMessageBubbleStyle(a, b, 1);
+
+ it("opacity equals b.opacity at t=1", () => {
+ expect(r.opacity).toBeCloseTo(b.opacity, 10);
+ });
+
+ it("translateY equals b.translateY at t=1", () => {
+ expect(r.translateY).toBeCloseTo(b.translateY, 10);
+ });
+
+ it("scale equals b.scale at t=1", () => {
+ expect(r.scale).toBeCloseTo(b.scale, 10);
+ });
+});
+
+describe("tweenMessageBubbleStyle: t=0.5 midpoint (hidden β†’ visible)", () => {
+ const a = messageBubbleStyle("hidden");
+ const b = messageBubbleStyle("visible");
+ const r = tweenMessageBubbleStyle(a, b, 0.5);
+
+ it("opacity midpoint: 0 β†’ 1 gives 0.5", () => {
+ expect(r.opacity).toBeCloseTo(0.5, 10);
+ });
+
+ it("translateY midpoint: 12 β†’ 0 gives 6", () => {
+ expect(r.translateY).toBeCloseTo(6, 10);
+ });
+
+ it("scale midpoint: 0.94 β†’ 1 gives 0.97", () => {
+ expect(r.scale).toBeCloseTo(0.97, 10);
+ });
+});
+
+describe("tweenMessageBubbleStyle: identity (a === b, any t)", () => {
+ const s = messageBubbleStyle("visible");
+
+ it("opacity is unchanged when both endpoints are the same", () => {
+ expect(tweenMessageBubbleStyle(s, s, 0.5).opacity).toBeCloseTo(s.opacity, 10);
+ });
+
+ it("translateY is unchanged when both endpoints are the same", () => {
+ expect(tweenMessageBubbleStyle(s, s, 0.5).translateY).toBeCloseTo(s.translateY, 10);
+ });
+
+ it("scale is unchanged when both endpoints are the same", () => {
+ expect(tweenMessageBubbleStyle(s, s, 0.5).scale).toBeCloseTo(s.scale, 10);
+ });
+});
+
+describe("tweenMessageBubbleStyle: t=0.25 quarter-point (hidden β†’ visible)", () => {
+ const a = messageBubbleStyle("hidden");
+ const b = messageBubbleStyle("visible");
+ const r = tweenMessageBubbleStyle(a, b, 0.25);
+
+ it("opacity at t=0.25 is 0.25", () => {
+ expect(r.opacity).toBeCloseTo(0.25, 10);
+ });
+
+ it("translateY at t=0.25 is 9", () => {
+ expect(r.translateY).toBeCloseTo(9, 10);
+ });
+
+ it("scale at t=0.25 is 0.955", () => {
+ expect(r.scale).toBeCloseTo(0.955, 10);
+ });
+});
+
+function clamp01Mirror(t: number): number {
+ return Math.max(0, Math.min(1, t));
+}
+
+function easingOut(t: number): number {
+ return 1 - (1 - t) ** 3;
+}
+
+function resolveStateTransition<S extends string>(
+ raw: number,
+ steps: Step<S>[],
+ defaultState: S,
+ speed = 1,
+ defaultDuration = 8,
+): { from: S; to: S; progress: number } {
+ const effectiveFrame = raw * speed;
+ const started = steps
+ .map((step, index) => ({ step, index }))
+ .sort((a, b) => a.step.at - b.step.at || a.index - b.index)
+ .filter((e) => e.step.at <= effectiveFrame);
+ if (started.length === 0)
+ return { from: defaultState, to: defaultState, progress: 1 };
+ const to = started[started.length - 1].step;
+ const from = started.length >= 2 ? started[started.length - 2].step : null;
+ const dur = to.duration ?? defaultDuration;
+ const progress = dur > 0 ? clamp01Mirror((effectiveFrame - to.at) / dur) : 1;
+ return { from: from ? from.state : defaultState, to: to.state, progress };
+}
+
+function resolveMessageBubbleTransition(
+ raw: number,
+ steps: Step<MessageBubbleState>[],
+ speed = 1,
+ defaultDuration = DEFAULT_DURATION,
+): { style: ReturnType<typeof tweenMessageBubbleStyle>; progress: number; from: MessageBubbleState; to: MessageBubbleState } {
+ const { from, to, progress } = resolveStateTransition(
+ raw,
+ steps,
+ "hidden",
+ speed,
+ defaultDuration,
+ );
+ const t = easingOut(progress);
+ const style = tweenMessageBubbleStyle(
+ messageBubbleStyle(from as MessageBubbleState),
+ messageBubbleStyle(to as MessageBubbleState),
+ t,
+ );
+ return { style, progress, from: from as MessageBubbleState, to: to as MessageBubbleState };
+}
+
+describe("resolveMessageBubbleTransition: before any step β€” holds at hidden", () => {
+ it("returns the hidden style when no steps have started", () => {
+ const { style } = resolveMessageBubbleTransition(0, []);
+ const hidden = messageBubbleStyle("hidden");
+ expect(style.opacity).toBeCloseTo(hidden.opacity, 10);
+ expect(style.translateY).toBeCloseTo(hidden.translateY, 10);
+ expect(style.scale).toBeCloseTo(hidden.scale, 10);
+ });
+
+ it("from and to are both 'hidden' before any step", () => {
+ const { from, to } = resolveMessageBubbleTransition(0, []);
+ expect(from).toBe("hidden");
+ expect(to).toBe("hidden");
+ });
+});
+
+describe("resolveMessageBubbleTransition: exactly at hidden→visible step boundary", () => {
+ const steps: Step<MessageBubbleState>[] = [{ at: 10, state: "visible" }];
+
+ it("at raw=10 exactly, progress=0, t=out(0)=0 β†’ style equals hidden (from)", () => {
+ const { style, progress } = resolveMessageBubbleTransition(10, steps);
+ expect(progress).toBe(0);
+ const hidden = messageBubbleStyle("hidden");
+ expect(style.opacity).toBeCloseTo(hidden.opacity, 10);
+ expect(style.translateY).toBeCloseTo(hidden.translateY, 10);
+ expect(style.scale).toBeCloseTo(hidden.scale, 10);
+ });
+
+ it("from='hidden', to='visible' at the step boundary", () => {
+ const { from, to } = resolveMessageBubbleTransition(10, steps);
+ expect(from).toBe("hidden");
+ expect(to).toBe("visible");
+ });
+});
+
+describe("resolveMessageBubbleTransition: mid-window uses easings.out (not linear)", () => {
+ const steps: Step<MessageBubbleState>[] = [{ at: 0, state: "visible" }];
+
+ it("opacity at raw=7 is tween(0,1,out(0.5)) β‰ˆ 0.875 (not linear 0.5)", () => {
+ const { style } = resolveMessageBubbleTransition(7, steps, 1, 14);
+ const expectedT = easingOut(0.5);
+ expect(style.opacity).toBeCloseTo(expectedT, 8);
+ });
+
+ it("translateY at raw=7 is tween(12,0,out(0.5)): 12*(1-out(0.5))", () => {
+ const { style } = resolveMessageBubbleTransition(7, steps, 1, 14);
+ const t = easingOut(0.5);
+ const expected = 12 * (1 - t);
+ expect(style.translateY).toBeCloseTo(expected, 8);
+ });
+
+ it("scale at raw=7 is tween(0.94,1,out(0.5))", () => {
+ const { style } = resolveMessageBubbleTransition(7, steps, 1, 14);
+ const t = easingOut(0.5);
+ const expected = 0.94 + (1 - 0.94) * t;
+ expect(style.scale).toBeCloseTo(expected, 8);
+ });
+});
+
+describe("resolveMessageBubbleTransition: past the transition window β†’ fully visible", () => {
+ const steps: Step<MessageBubbleState>[] = [{ at: 0, state: "visible" }];
+
+ it("opacity is 1 after DEFAULT_DURATION frames", () => {
+ const { style } = resolveMessageBubbleTransition(DEFAULT_DURATION, steps);
+ expect(style.opacity).toBeCloseTo(1, 10);
+ });
+
+ it("translateY is 0 after DEFAULT_DURATION frames", () => {
+ const { style } = resolveMessageBubbleTransition(DEFAULT_DURATION, steps);
+ expect(style.translateY).toBeCloseTo(0, 10);
+ });
+
+ it("scale is 1 after DEFAULT_DURATION frames", () => {
+ const { style } = resolveMessageBubbleTransition(DEFAULT_DURATION, steps);
+ expect(style.scale).toBeCloseTo(1, 10);
+ });
+});
+
+describe("resolveMessageBubbleTransition: speed contract", () => {
+ const steps: Step<MessageBubbleState>[] = [{ at: 14, state: "visible" }];
+
+ it("speed=2: step at=14 fires at raw=7 (eff=14)", () => {
+ const { to } = resolveMessageBubbleTransition(7, steps, 2);
+ expect(to).toBe("visible");
+ });
+
+ it("speed=2: step at=14 has NOT fired at raw=6 (eff=12 < 14)", () => {
+ const { to } = resolveMessageBubbleTransition(6, steps, 2);
+ expect(to).toBe("hidden");
+ });
+});
+
+describe("messageBubbleConfig.controls: variant", () => {
+ it("variant is a select control", () => {
+ expect(messageBubbleConfig.controls.variant.type).toBe("select");
+ });
+
+ it("variant options are ['incoming', 'outgoing']", () => {
+ const ctrl = messageBubbleConfig.controls.variant;
+ if (ctrl.type !== "select") throw new Error("expected select");
+ expect(ctrl.options).toEqual(["incoming", "outgoing"]);
+ });
+
+ it("variant default is 'incoming'", () => {
+ expect(messageBubbleConfig.controls.variant.default).toBe("incoming");
+ });
+
+ it("every variant option is a valid MessageBubbleVariant", () => {
+ const ctrl = messageBubbleConfig.controls.variant;
+ if (ctrl.type !== "select") throw new Error("expected select");
+ for (const opt of ctrl.options) {
+ expect(VALID_VARIANTS).toContain(opt as MessageBubbleVariant);
+ }
+ });
+});
+
+describe("messageBubbleConfig.controls: state", () => {
+ it("state is a select control", () => {
+ expect(messageBubbleConfig.controls.state.type).toBe("select");
+ });
+
+ it("state options are ['hidden', 'visible']", () => {
+ const ctrl = messageBubbleConfig.controls.state;
+ if (ctrl.type !== "select") throw new Error("expected select");
+ expect(ctrl.options).toEqual(["hidden", "visible"]);
+ });
+
+ it("state default is 'visible'", () => {
+ expect(messageBubbleConfig.controls.state.default).toBe("visible");
+ });
+
+ it("every state option is a valid MessageBubbleState", () => {
+ const ctrl = messageBubbleConfig.controls.state;
+ if (ctrl.type !== "select") throw new Error("expected select");
+ for (const opt of ctrl.options) {
+ expect(VALID_STATES).toContain(opt as MessageBubbleState);
+ }
+ });
+});
+
+describe("messageBubbleConfig.controls: text and reaction", () => {
+ it("text is a text control", () => {
+ expect(messageBubbleConfig.controls.text.type).toBe("text");
+ });
+
+ it("reaction is a text control", () => {
+ expect(messageBubbleConfig.controls.reaction.type).toBe("text");
+ });
+});
+
+describe("messageBubbleConfig.snippet: import line", () => {
+ it("includes 'import { MessageBubble }' from the correct path", () => {
+ const out = snippet({ state: "visible", variant: "incoming" });
+ expect(out).toContain("import { MessageBubble }");
+ expect(out).toContain('from "@/components/remocn/message-bubble"');
+ });
+});
+
+describe("messageBubbleConfig.snippet: structural invariants", () => {
+ it("contains a <MessageBubble JSX element", () => {
+ expect(snippet({ state: "visible", variant: "incoming" })).toContain("<MessageBubble");
+ });
+
+ it("state prop is always emitted", () => {
+ expect(snippet({ state: "visible", variant: "incoming" })).toContain('state="visible"');
+ expect(snippet({ state: "hidden", variant: "outgoing" })).toContain('state="hidden"');
+ });
+
+ it("variant prop is always emitted", () => {
+ expect(snippet({ state: "visible", variant: "incoming" })).toContain('variant="incoming"');
+ expect(snippet({ state: "visible", variant: "outgoing" })).toContain('variant="outgoing"');
+ });
+});
+
+describe("messageBubbleConfig.snippet: reaction omitted when empty string", () => {
+ it("does not emit reaction prop when reaction is empty string", () => {
+ const out = snippet({ state: "visible", variant: "incoming", reaction: "" });
+ expect(out).not.toContain("reaction=");
+ });
+});
+
+describe("messageBubbleConfig.snippet: reaction emitted when provided", () => {
+ it("emits reaction prop when reaction is a non-empty string", () => {
+ const out = snippet({ state: "visible", variant: "incoming", reaction: "πŸ”₯" });
+ expect(out).toContain('reaction="πŸ”₯"');
+ });
+
+ it("emits reaction prop for any non-empty value", () => {
+ const out = snippet({ state: "visible", variant: "outgoing", reaction: "πŸ‘" });
+ expect(out).toContain('reaction="πŸ‘"');
+ });
+});
+
+describe("messageBubbleConfig.snippet: state options round-trip", () => {
+ it("emits the correct state for every control option", () => {
+ const ctrl = messageBubbleConfig.controls.state;
+ if (ctrl.type !== "select") throw new Error("expected select");
+ for (const state of ctrl.options) {
+ expect(snippet({ state })).toContain(`state="${state}"`);
+ }
+ });
+});
diff --git a/registry/remocn-ui/message-bubble/config.ts b/registry/remocn-ui/message-bubble/config.ts
new file mode 100644
index 00000000..53b1c076
--- /dev/null
+++ b/registry/remocn-ui/message-bubble/config.ts
@@ -0,0 +1,52 @@
+import { type ComponentConfig, FPS, H, W } from "@/lib/customizer-config";
+import type {
+ MessageBubbleState,
+ MessageBubbleVariant,
+} from "@/registry/remocn-ui/message-bubble";
+
+const DEFAULT_TEXT = "Yep, pushing it live now";
+const DEFAULT_REACTION = "πŸ”₯";
+
+export const messageBubbleConfig: ComponentConfig = {
+ componentName: "MessageBubble",
+ importPath: "@/components/remocn/message-bubble",
+ controls: {
+ text: { type: "text", default: DEFAULT_TEXT, label: "Text" },
+ variant: {
+ type: "select",
+ default: "incoming",
+ options: ["incoming", "outgoing"],
+ label: "Variant",
+ },
+ reaction: { type: "text", default: DEFAULT_REACTION, label: "Reaction" },
+ state: {
+ type: "select",
+ default: "visible",
+ options: ["hidden", "visible"],
+ label: "State",
+ },
+ },
+ durationInFrames: 120,
+ fps: FPS,
+ compositionWidth: W,
+ compositionHeight: H,
+ previewBackdrop: { type: "color", value: "oklch(1 0 0)" },
+ snippet: (values) => {
+ const state = (values.state as MessageBubbleState) ?? "visible";
+ const variant = (values.variant as MessageBubbleVariant) ?? "incoming";
+ const text = (values.text as string | undefined) ?? DEFAULT_TEXT;
+ const reaction = values.reaction as string | undefined;
+
+ const props: string[] = [` state="${state}"`, ` variant="${variant}"`];
+ if (reaction !== undefined && reaction !== "")
+ props.push(` reaction="${reaction}"`);
+
+ return `import { MessageBubble } from "@/components/remocn/message-bubble";
+
+<MessageBubble
+${props.join("\n")}
+>
+ ${text}
+</MessageBubble>`;
+ },
+};
diff --git a/registry/remocn-ui/message-bubble/index.tsx b/registry/remocn-ui/message-bubble/index.tsx
new file mode 100644
index 00000000..568f0d2c
--- /dev/null
+++ b/registry/remocn-ui/message-bubble/index.tsx
@@ -0,0 +1,165 @@
+"use client";
+
+import type { ReactNode } from "react";
+import { type RemocnTheme, useRemocnTheme } from "@/lib/remocn-ui";
+
+export type MessageBubbleState = "hidden" | "visible";
+
+export type MessageBubbleVariant = "incoming" | "outgoing";
+
+export interface MessageBubbleProps {
+ state?: MessageBubbleState;
+ style?: MessageBubbleStyle;
+ variant?: MessageBubbleVariant;
+ children?: ReactNode;
+ reaction?: string;
+ reactionStyle?: MessageBubbleReactionStyle;
+ maxWidth?: number | string;
+ theme?: Partial<RemocnTheme>;
+ className?: string;
+}
+
+export interface MessageBubbleStyle {
+ opacity: number;
+ translateY: number;
+ scale: number;
+}
+
+export interface MessageBubbleReactionStyle {
+ opacity: number;
+ scale: number;
+}
+
+export interface MessageBubbleStyleContext {
+ background: string;
+ color: string;
+ align: "flex-start" | "flex-end";
+ reactionSide: "left" | "right";
+ reactionBackground: string;
+ reactionColor: string;
+ reactionRing: string;
+}
+
+export function messageBubbleStyleContext(
+ variant: MessageBubbleVariant,
+ theme: RemocnTheme,
+): MessageBubbleStyleContext {
+ const reaction = {
+ reactionBackground: theme.muted,
+ reactionColor: theme.foreground,
+ reactionRing: theme.card,
+ };
+ if (variant === "outgoing") {
+ return {
+ background: theme.primary,
+ color: theme.primaryForeground,
+ align: "flex-end",
+ reactionSide: "right",
+ ...reaction,
+ };
+ }
+ return {
+ background: theme.muted,
+ color: theme.foreground,
+ align: "flex-start",
+ reactionSide: "left",
+ ...reaction,
+ };
+}
+
+export function messageBubbleStyle(state: MessageBubbleState): MessageBubbleStyle {
+ switch (state) {
+ case "visible":
+ return { opacity: 1, translateY: 0, scale: 1 };
+ default:
+ return { opacity: 0, translateY: 12, scale: 0.94 };
+ }
+}
+
+export function messageBubbleReactionStyle(
+ state: MessageBubbleState,
+): MessageBubbleReactionStyle {
+ return state === "visible"
+ ? { opacity: 1, scale: 1 }
+ : { opacity: 0, scale: 0 };
+}
+
+export function MessageBubble({
+ state = "hidden",
+ style,
+ variant = "incoming",
+ children,
+ reaction,
+ reactionStyle,
+ maxWidth = "80%",
+ theme: themeOverride,
+ className,
+}: MessageBubbleProps) {
+ const theme = useRemocnTheme(themeOverride, "light");
+ const ctx = messageBubbleStyleContext(variant, theme);
+ const v = style ?? messageBubbleStyle(state);
+ const reaction_ = reactionStyle ?? messageBubbleReactionStyle(state);
+
+ return (
+ <div
+ className={className}
+ style={{
+ display: "flex",
+ justifyContent: ctx.align,
+ width: "100%",
+ opacity: v.opacity,
+ transform: `translateY(${v.translateY}px) scale(${v.scale})`,
+ transformOrigin: ctx.align === "flex-end" ? "bottom right" : "bottom left",
+ }}
+ >
+ <div style={{ position: "relative", maxWidth, minWidth: 0 }}>
+ <div
+ style={{
+ display: "inline-block",
+ maxWidth: "100%",
+ padding: "10px 14px",
+ background: ctx.background,
+ color: ctx.color,
+ border: "1px solid transparent",
+ borderRadius: 24,
+ fontFamily:
+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",
+ fontSize: 14,
+ lineHeight: 1.625,
+ overflowWrap: "break-word",
+ wordBreak: "break-word",
+ }}
+ >
+ {children}
+ </div>
+ {reaction !== undefined && (
+ <div
+ style={{
+ position: "absolute",
+ bottom: 0,
+ left: ctx.reactionSide === "left" ? 12 : undefined,
+ right: ctx.reactionSide === "right" ? 12 : undefined,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ gap: 4,
+ minWidth: 24,
+ padding: "2px 6px",
+ background: ctx.reactionBackground,
+ color: ctx.reactionColor,
+ borderRadius: 999,
+ fontSize: 14,
+ lineHeight: 1,
+ boxShadow: `0 0 0 3px ${ctx.reactionRing}`,
+ opacity: reaction_.opacity,
+ transform: `translateY(75%) scale(${reaction_.scale})`,
+ transformOrigin: "center",
+ }}
+ >
+ {reaction}
+ </div>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/registry/remocn-ui/message-bubble/preview.tsx b/registry/remocn-ui/message-bubble/preview.tsx
new file mode 100644
index 00000000..bd53b534
--- /dev/null
+++ b/registry/remocn-ui/message-bubble/preview.tsx
@@ -0,0 +1,45 @@
+"use client";
+
+import {
+ MessageBubble,
+ type MessageBubbleState,
+ type MessageBubbleVariant,
+} from "@/registry/remocn-ui/message-bubble";
+
+export interface MessageBubblePreviewProps {
+ text?: string;
+ variant?: MessageBubbleVariant;
+ reaction?: string;
+ state?: MessageBubbleState;
+}
+
+export function MessageBubblePreview({
+ text = "Yep, pushing it live now",
+ variant = "incoming",
+ reaction = "πŸ”₯",
+ state = "visible",
+}: MessageBubblePreviewProps) {
+ return (
+ <div
+ style={{
+ position: "absolute",
+ inset: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ padding: 80,
+ background: "transparent",
+ }}
+ >
+ <div style={{ width: 520 }}>
+ <MessageBubble
+ state={state}
+ variant={variant}
+ reaction={reaction === "" ? undefined : reaction}
+ >
+ {text}
+ </MessageBubble>
+ </div>
+ </div>
+ );
+}
diff --git a/registry/remocn-ui/message-bubble/use-message-bubble-transition.ts b/registry/remocn-ui/message-bubble/use-message-bubble-transition.ts
new file mode 100644
index 00000000..3b92c138
--- /dev/null
+++ b/registry/remocn-ui/message-bubble/use-message-bubble-transition.ts
@@ -0,0 +1,42 @@
+"use client";
+
+import { easings, type Step, useStateTransition } from "@/lib/remocn-ui";
+import {
+ messageBubbleStyle,
+ type MessageBubbleState,
+ type MessageBubbleStyle,
+} from "@/components/remocn/message-bubble";
+
+export const DEFAULT_DURATION = 14;
+
+export function tweenMessageBubbleStyle(
+ a: MessageBubbleStyle,
+ b: MessageBubbleStyle,
+ t: number,
+): MessageBubbleStyle {
+ return {
+ opacity: a.opacity + (b.opacity - a.opacity) * t,
+ translateY: a.translateY + (b.translateY - a.translateY) * t,
+ scale: a.scale + (b.scale - a.scale) * t,
+ };
+}
+
+export interface MessageBubbleTransitionOptions {
+ speed?: number;
+ defaultDuration?: number;
+}
+
+export function useMessageBubbleTransition(
+ steps: Step<MessageBubbleState>[],
+ opts: MessageBubbleTransitionOptions = {},
+): MessageBubbleStyle {
+ const { speed = 1, defaultDuration = DEFAULT_DURATION } = opts;
+ const { from, to, progress } = useStateTransition(
+ steps,
+ "hidden",
+ speed,
+ defaultDuration,
+ );
+ const t = easings.out(progress);
+ return tweenMessageBubbleStyle(messageBubbleStyle(from), messageBubbleStyle(to), t);
+}
diff --git a/registry/remocn-ui/registry.json b/registry/remocn-ui/registry.json
index e8935cdb..3394e8ca 100644
--- a/registry/remocn-ui/registry.json
+++ b/registry/remocn-ui/registry.json
@@ -776,6 +776,56 @@
"target": "components/remocn/settings-toggle-flow.tsx"
}
]
+ },
+ {
+ "name": "message-bubble",
+ "type": "registry:component",
+ "title": "UI Message Bubble",
+ "description": "A chat message bubble whose hidden/visible state is a pure function of the timeline. The renderer is a pure function of a MessageBubbleStyle (opacity, translateY, scale); useMessageBubbleTransition eases the rise-in enter. The incoming/outgoing variant resolves bubble color and alignment from the theme, and an optional reaction badge pops in on its own channel.",
+ "dependencies": ["remotion"],
+ "registryDependencies": ["@remocn/remocn-ui"],
+ "files": [
+ {
+ "path": "message-bubble/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/message-bubble.tsx"
+ },
+ {
+ "path": "message-bubble/use-message-bubble-transition.ts",
+ "type": "registry:component",
+ "target": "components/remocn/use-message-bubble-transition.ts"
+ }
+ ]
+ },
+ {
+ "name": "typing-indicator",
+ "type": "registry:component",
+ "title": "UI Typing Indicator",
+ "description": "A continuous typing animation: N dots bounce with a staggered sine wave. A motion atom β€” it reads the frame and takes color, size, gap, and speed props, defaulting to currentColor so it inherits the bubble it sits in.",
+ "dependencies": ["remotion"],
+ "registryDependencies": ["@remocn/remocn-ui"],
+ "files": [
+ {
+ "path": "typing-indicator/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/typing-indicator.tsx"
+ }
+ ]
+ },
+ {
+ "name": "chat-flow",
+ "type": "registry:component",
+ "title": "UI Chat Flow",
+ "description": "A messaging composition: an outgoing message types into the composer, the send button presses, and the bubble rises in; the other side shows a typing indicator that swaps into the reply, and reactions pop in. A pure orchestrator β€” every channel comes from a composed primitive's hook (Input, MessageBubble, TypingIndicator).",
+ "dependencies": ["remotion"],
+ "registryDependencies": ["@remocn/remocn-ui", "@remocn/caret", "@remocn/message-bubble", "@remocn/typing-indicator"],
+ "files": [
+ {
+ "path": "chat-flow/index.tsx",
+ "type": "registry:component",
+ "target": "components/remocn/chat-flow.tsx"
+ }
+ ]
}
]
}
diff --git a/registry/remocn-ui/typing-indicator/__tests__/typing-indicator.test.ts b/registry/remocn-ui/typing-indicator/__tests__/typing-indicator.test.ts
new file mode 100644
index 00000000..2d8857fb
--- /dev/null
+++ b/registry/remocn-ui/typing-indicator/__tests__/typing-indicator.test.ts
@@ -0,0 +1,196 @@
+
+import { describe, expect, it } from "bun:test";
+import { typingDotOffset, type TypingDotOptions } from "../index";
+import { typingIndicatorConfig } from "../config";
+
+const BASE_OPTS: TypingDotOptions = {
+ fps: 30,
+ dotCount: 3,
+ amplitude: 5,
+ speed: 1,
+ cyclesPerSecond: 1.1,
+};
+
+describe("typingDotOffset: return shape", () => {
+ it("returns translateY and opacity as numbers for frame=0 index=0", () => {
+ const r = typingDotOffset(0, 0, BASE_OPTS);
+ expect(typeof r.translateY).toBe("number");
+ expect(typeof r.opacity).toBe("number");
+ });
+
+ it("returns translateY and opacity as numbers for frame=15 index=1", () => {
+ const r = typingDotOffset(15, 1, BASE_OPTS);
+ expect(typeof r.translateY).toBe("number");
+ expect(typeof r.opacity).toBe("number");
+ });
+
+ it("returns translateY and opacity as numbers for frame=90 index=2", () => {
+ const r = typingDotOffset(90, 2, BASE_OPTS);
+ expect(typeof r.translateY).toBe("number");
+ expect(typeof r.opacity).toBe("number");
+ });
+});
+
+describe("typingDotOffset: translateY bounds [-amplitude, 0]", () => {
+ const frames = [0, 1, 5, 7, 10, 13, 15, 20, 27, 30, 45, 60, 90];
+
+ it("translateY is always >= -amplitude for index=0", () => {
+ for (const frame of frames) {
+ const { translateY } = typingDotOffset(frame, 0, BASE_OPTS);
+ expect(translateY).toBeGreaterThanOrEqual(-BASE_OPTS.amplitude);
+ }
+ });
+
+ it("translateY is always <= 0 for index=0", () => {
+ for (const frame of frames) {
+ const { translateY } = typingDotOffset(frame, 0, BASE_OPTS);
+ expect(translateY).toBeLessThanOrEqual(0);
+ }
+ });
+
+ it("translateY is always >= -amplitude for index=2", () => {
+ for (const frame of frames) {
+ const { translateY } = typingDotOffset(frame, 2, BASE_OPTS);
+ expect(translateY).toBeGreaterThanOrEqual(-BASE_OPTS.amplitude);
+ }
+ });
+
+ it("translateY is always <= 0 for index=2", () => {
+ for (const frame of frames) {
+ const { translateY } = typingDotOffset(frame, 2, BASE_OPTS);
+ expect(translateY).toBeLessThanOrEqual(0);
+ }
+ });
+});
+
+describe("typingDotOffset: opacity bounds [0.45, 1.0]", () => {
+ const frames = [0, 1, 5, 7, 10, 13, 15, 20, 27, 30, 45, 60, 90];
+
+ it("opacity is always >= 0.45 for index=0", () => {
+ for (const frame of frames) {
+ const { opacity } = typingDotOffset(frame, 0, BASE_OPTS);
+ expect(opacity).toBeGreaterThanOrEqual(0.45);
+ }
+ });
+
+ it("opacity is always <= 1.0 for index=0", () => {
+ for (const frame of frames) {
+ const { opacity } = typingDotOffset(frame, 0, BASE_OPTS);
+ expect(opacity).toBeLessThanOrEqual(1.0);
+ }
+ });
+
+ it("opacity is always >= 0.45 for index=1", () => {
+ for (const frame of frames) {
+ const { opacity } = typingDotOffset(frame, 1, BASE_OPTS);
+ expect(opacity).toBeGreaterThanOrEqual(0.45);
+ }
+ });
+
+ it("opacity is always <= 1.0 for index=1", () => {
+ for (const frame of frames) {
+ const { opacity } = typingDotOffset(frame, 1, BASE_OPTS);
+ expect(opacity).toBeLessThanOrEqual(1.0);
+ }
+ });
+});
+
+describe("typingDotOffset: dots are staggered (index 0 β‰  index 1 at frame 15)", () => {
+ it("translateY of index=0 and index=1 differ at frame=15", () => {
+ const r0 = typingDotOffset(15, 0, BASE_OPTS);
+ const r1 = typingDotOffset(15, 1, BASE_OPTS);
+ expect(r0.translateY).not.toBeCloseTo(r1.translateY, 3);
+ });
+
+ it("opacity of index=0 and index=1 differ at frame=15", () => {
+ const r0 = typingDotOffset(15, 0, BASE_OPTS);
+ const r1 = typingDotOffset(15, 1, BASE_OPTS);
+ expect(r0.opacity).not.toBeCloseTo(r1.opacity, 3);
+ });
+});
+
+describe("typingDotOffset: speed scales phase (speed=2, frame=f equals speed=1, frame=2f)", () => {
+ it("translateY matches for frame=10 speed=2 vs frame=20 speed=1 (index=0)", () => {
+ const fast = typingDotOffset(10, 0, { ...BASE_OPTS, speed: 2 });
+ const slow = typingDotOffset(20, 0, { ...BASE_OPTS, speed: 1 });
+ expect(fast.translateY).toBeCloseTo(slow.translateY, 10);
+ });
+
+ it("opacity matches for frame=10 speed=2 vs frame=20 speed=1 (index=0)", () => {
+ const fast = typingDotOffset(10, 0, { ...BASE_OPTS, speed: 2 });
+ const slow = typingDotOffset(20, 0, { ...BASE_OPTS, speed: 1 });
+ expect(fast.opacity).toBeCloseTo(slow.opacity, 10);
+ });
+
+ it("translateY matches for frame=5 speed=2 vs frame=10 speed=1 (index=0)", () => {
+ const fast = typingDotOffset(5, 0, { ...BASE_OPTS, speed: 2 });
+ const slow = typingDotOffset(10, 0, { ...BASE_OPTS, speed: 1 });
+ expect(fast.translateY).toBeCloseTo(slow.translateY, 10);
+ });
+
+ it("opacity matches for frame=5 speed=2 vs frame=10 speed=1 (index=0)", () => {
+ const fast = typingDotOffset(5, 0, { ...BASE_OPTS, speed: 2 });
+ const slow = typingDotOffset(10, 0, { ...BASE_OPTS, speed: 1 });
+ expect(fast.opacity).toBeCloseTo(slow.opacity, 10);
+ });
+});
+
+describe("typingIndicatorConfig.controls: dotCount", () => {
+ it("dotCount is a number control", () => {
+ expect(typingIndicatorConfig.controls.dotCount.type).toBe("number");
+ });
+
+ it("dotCount has a step property", () => {
+ const ctrl = typingIndicatorConfig.controls.dotCount;
+ if (ctrl.type !== "number") throw new Error("expected number");
+ expect(typeof ctrl.step).toBe("number");
+ });
+
+ it("dotCount default is 3", () => {
+ expect(typingIndicatorConfig.controls.dotCount.default).toBe(3);
+ });
+});
+
+describe("typingIndicatorConfig.controls: size", () => {
+ it("size is a number control", () => {
+ expect(typingIndicatorConfig.controls.size.type).toBe("number");
+ });
+
+ it("size has a step property", () => {
+ const ctrl = typingIndicatorConfig.controls.size;
+ if (ctrl.type !== "number") throw new Error("expected number");
+ expect(typeof ctrl.step).toBe("number");
+ });
+
+ it("size default is 8", () => {
+ expect(typingIndicatorConfig.controls.size.default).toBe(8);
+ });
+});
+
+describe("typingIndicatorConfig.controls: amplitude", () => {
+ it("amplitude is a number control", () => {
+ expect(typingIndicatorConfig.controls.amplitude.type).toBe("number");
+ });
+
+ it("amplitude has a step property", () => {
+ const ctrl = typingIndicatorConfig.controls.amplitude;
+ if (ctrl.type !== "number") throw new Error("expected number");
+ expect(typeof ctrl.step).toBe("number");
+ });
+
+ it("amplitude default is 5", () => {
+ expect(typingIndicatorConfig.controls.amplitude.default).toBe(5);
+ });
+});
+
+describe("typingIndicatorConfig.snippet: import and element", () => {
+ it("includes 'import { TypingIndicator }' from the correct path", () => {
+ const out = typingIndicatorConfig.snippet({});
+ expect(out).toContain("import { TypingIndicator }");
+ expect(out).toContain('from "@/components/remocn/typing-indicator"');
+ });
+
+ it("contains a <TypingIndicator JSX element", () => {
+ expect(typingIndicatorConfig.snippet({})).toContain("<TypingIndicator");
+ });
+});
diff --git a/registry/remocn-ui/typing-indicator/config.ts b/registry/remocn-ui/typing-indicator/config.ts
new file mode 100644
index 00000000..f6673659
--- /dev/null
+++ b/registry/remocn-ui/typing-indicator/config.ts
@@ -0,0 +1,54 @@
+import { type ComponentConfig, FPS, H, W } from "@/lib/customizer-config";
+
+export const typingIndicatorConfig: ComponentConfig = {
+ componentName: "TypingIndicator",
+ importPath: "@/components/remocn/typing-indicator",
+ controls: {
+ dotCount: {
+ type: "number",
+ default: 3,
+ min: 2,
+ max: 5,
+ step: 1,
+ label: "Dots",
+ },
+ size: {
+ type: "number",
+ default: 8,
+ min: 4,
+ max: 16,
+ step: 1,
+ label: "Dot size",
+ },
+ amplitude: {
+ type: "number",
+ default: 5,
+ min: 0,
+ max: 14,
+ step: 1,
+ label: "Bounce",
+ },
+ },
+ durationInFrames: 90,
+ fps: FPS,
+ compositionWidth: W,
+ compositionHeight: H,
+ previewBackdrop: { type: "color", value: "oklch(1 0 0)" },
+ snippet: (values) => {
+ const dotCount = (values.dotCount as number | undefined) ?? 3;
+ const size = (values.size as number | undefined) ?? 8;
+ const amplitude = (values.amplitude as number | undefined) ?? 5;
+ const speed = (values.speed as number | undefined) ?? 1;
+
+ const props: string[] = [];
+ if (dotCount !== 3) props.push(` dotCount={${dotCount}}`);
+ if (size !== 8) props.push(` size={${size}}`);
+ if (amplitude !== 5) props.push(` amplitude={${amplitude}}`);
+ if (speed !== 1) props.push(` speed={${speed}}`);
+
+ const body = props.length > 0 ? `\n${props.join("\n")}\n` : " ";
+ return `import { TypingIndicator } from "@/components/remocn/typing-indicator";
+
+<TypingIndicator${body}/>`;
+ },
+};
diff --git a/registry/remocn-ui/typing-indicator/index.tsx b/registry/remocn-ui/typing-indicator/index.tsx
new file mode 100644
index 00000000..643bb8d5
--- /dev/null
+++ b/registry/remocn-ui/typing-indicator/index.tsx
@@ -0,0 +1,90 @@
+"use client";
+
+import { useCurrentFrame, useVideoConfig } from "remotion";
+
+export interface TypingIndicatorProps {
+ dotCount?: number;
+ color?: string;
+ size?: number;
+ gap?: number;
+ amplitude?: number;
+ speed?: number;
+ cyclesPerSecond?: number;
+ className?: string;
+}
+
+export interface TypingDotOptions {
+ fps: number;
+ dotCount: number;
+ amplitude: number;
+ speed: number;
+ cyclesPerSecond: number;
+}
+
+export function typingDotOffset(
+ frame: number,
+ index: number,
+ opts: TypingDotOptions,
+): { translateY: number; opacity: number } {
+ const cps = opts.cyclesPerSecond <= 0 ? 1 : opts.cyclesPerSecond;
+ const periodFrames = opts.fps / cps;
+ const stagger = opts.dotCount > 0 ? periodFrames / (opts.dotCount * 2) : 0;
+ const phase =
+ ((frame * opts.speed - index * stagger) / periodFrames) * Math.PI * 2;
+ const wave = (Math.sin(phase) + 1) / 2;
+ return {
+ translateY: -opts.amplitude * wave,
+ opacity: 0.45 + 0.55 * wave,
+ };
+}
+
+export function TypingIndicator({
+ dotCount = 3,
+ color = "currentColor",
+ size = 8,
+ gap = 5,
+ amplitude = 5,
+ speed = 1,
+ cyclesPerSecond = 1.1,
+ className,
+}: TypingIndicatorProps) {
+ const frame = useCurrentFrame();
+ const { fps } = useVideoConfig();
+ const opts: TypingDotOptions = {
+ fps,
+ dotCount,
+ amplitude,
+ speed,
+ cyclesPerSecond,
+ };
+
+ return (
+ <div
+ className={className}
+ style={{
+ display: "inline-flex",
+ alignItems: "center",
+ gap,
+ height: size + amplitude * 2,
+ }}
+ >
+ {Array.from({ length: dotCount }, (_, i) => {
+ const { translateY, opacity } = typingDotOffset(frame, i, opts);
+ return (
+ <span
+ key={i}
+ style={{
+ display: "inline-block",
+ width: size,
+ height: size,
+ borderRadius: "50%",
+ background: color,
+ opacity,
+ transform: `translateY(${translateY}px)`,
+ }}
+ />
+ );
+ })}
+ </div>
+ );
+}
diff --git a/registry/remocn-ui/typing-indicator/preview.tsx b/registry/remocn-ui/typing-indicator/preview.tsx
new file mode 100644
index 00000000..6c995de2
--- /dev/null
+++ b/registry/remocn-ui/typing-indicator/preview.tsx
@@ -0,0 +1,51 @@
+"use client";
+
+import { useRemocnTheme } from "@/lib/remocn-ui";
+import { TypingIndicator } from "@/registry/remocn-ui/typing-indicator";
+
+export interface TypingIndicatorPreviewProps {
+ dotCount?: number;
+ size?: number;
+ amplitude?: number;
+ speed?: number;
+}
+
+export function TypingIndicatorPreview({
+ dotCount = 3,
+ size = 8,
+ amplitude = 5,
+ speed = 1,
+}: TypingIndicatorPreviewProps) {
+ const theme = useRemocnTheme(undefined, "light");
+
+ return (
+ <div
+ style={{
+ position: "absolute",
+ inset: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ background: "transparent",
+ }}
+ >
+ <div
+ style={{
+ display: "inline-flex",
+ alignItems: "center",
+ padding: "16px 20px",
+ background: theme.muted,
+ borderRadius: 18,
+ color: theme.mutedForeground,
+ }}
+ >
+ <TypingIndicator
+ dotCount={dotCount}
+ size={size}
+ amplitude={amplitude}
+ speed={speed}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/tsconfig.json b/tsconfig.json
index 6ed9e858..d78c00c1 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -36,6 +36,7 @@
"@/components/remocn/use-select-item-transition": ["./registry/remocn-ui/select-item/use-select-item-transition.ts"],
"@/components/remocn/use-slider-transition": ["./registry/remocn-ui/slider/use-slider-transition.ts"],
"@/components/remocn/use-blur-in-transition": ["./registry/remocn-ui/blur-in/use-blur-in-transition.ts"],
+ "@/components/remocn/use-message-bubble-transition": ["./registry/remocn-ui/message-bubble/use-message-bubble-transition.ts"],
"@/components/remocn/confetti": ["./registry/remocn/confetti/index.tsx"],
"@/components/remocn/glass-code-block": ["./registry/remocn/glass-code-block/index.tsx"],
"@/components/remocn/number-wheel": ["./registry/remocn/number-wheel/index.tsx"],