import { Children, cloneElement, isValidElement, type ReactElement, type ReactNode, type VideoHTMLAttributes, } from 'react'; import { Hand } from '@/components/icons'; import { renderInlineMarkdown } from '@/lib/inline-markdown'; import { styles } from './styles'; export interface FrameProps { caption?: ReactNode; hint?: ReactNode; children?: ReactNode; } function renderFrameText(value: ReactNode) { return typeof value === 'string' ? renderInlineMarkdown(value) : value; } function enhanceAutoplayVideos(children: ReactNode) { return Children.map(children, child => { if (!isValidElement(child) || child.type !== 'video') { return child; } const video = child as ReactElement, 'video'>; return video.props.autoPlay ? cloneElement(video, { playsInline: true, loop: true, muted: true }) : video; }); } export function Frame({ caption, hint, children }: FrameProps) { return (
{hint ? (
{renderFrameText(hint)}
) : null}
{enhanceAutoplayVideos(children)}
{caption ? (
{renderFrameText(caption)}
) : null}
); }