import type { CSSProperties } from "react"; import Markdown from "react-markdown"; import remarkGfm from "remark-gfm"; import { parseProjectMentionHref } from "@paperclipai/shared"; import { cn } from "../lib/utils"; import { useTheme } from "../context/ThemeContext"; interface MarkdownBodyProps { children: string; className?: string; } function hexToRgb(hex: string): { r: number; g: number; b: number } | null { const match = /^#([0-9a-f]{6})$/i.exec(hex.trim()); if (!match) return null; const value = match[1]; return { r: parseInt(value.slice(0, 2), 16), g: parseInt(value.slice(2, 4), 16), b: parseInt(value.slice(4, 6), 16), }; } function mentionChipStyle(color: string | null): CSSProperties | undefined { if (!color) return undefined; const rgb = hexToRgb(color); if (!rgb) return undefined; const luminance = (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255; return { borderColor: color, backgroundColor: `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0.22)`, color: luminance > 0.55 ? "#111827" : "#f8fafc", }; } export function MarkdownBody({ children, className }: MarkdownBodyProps) { const { theme } = useTheme(); return (