'use client'; import * as React from 'react'; import { toPng } from 'html-to-image'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle, } from "@/components/ui/empty" import { Copy, Download, Share2, Image as ImageIcon, AlignLeft, AlignCenter, AlignRight, Type } from 'lucide-react'; import { cn } from '@/lib/utils/cn'; import { toast } from 'sonner'; export interface FontPreviewProps { text: string; font?: string; isLoading?: boolean; onCopy?: () => void; onDownload?: () => void; onShare?: () => void; className?: string; } type TextAlign = 'left' | 'center' | 'right'; export function FontPreview({ text, font, isLoading, onCopy, onDownload, onShare, className }: FontPreviewProps) { const lineCount = text ? text.split('\n').length : 0; const charCount = text ? text.length : 0; const previewRef = React.useRef(null); const [textAlign, setTextAlign] = React.useState('left'); const [fontSize, setFontSize] = React.useState<'xs' | 'sm' | 'base'>('sm'); const handleExportPNG = async () => { if (!previewRef.current || !text) return; try { const dataUrl = await toPng(previewRef.current, { backgroundColor: getComputedStyle(previewRef.current).backgroundColor, pixelRatio: 2, }); const link = document.createElement('a'); link.download = `figlet-${font || 'export'}-${Date.now()}.png`; link.href = dataUrl; link.click(); toast.success('Exported as PNG!'); } catch (error) { console.error('Failed to export PNG:', error); toast.error('Failed to export PNG'); } }; return (
Preview {font && ( {font} )}
{onCopy && ( )} {onShare && ( )} {onDownload && ( )}
{/* Controls */}
{!isLoading && text && (
{lineCount} lines {charCount} chars
)}
{isLoading ? (
) : text ? (
              {text}
            
) : ( Start typing to see your ASCII art Enter text in the input field above to generate ASCII art with the selected font )}
); }