import React, { useState } from 'react'; import { AppState, PaperSize } from './types'; import { FileUpload } from './components/FileUpload'; import { StyleSelector } from './components/StyleSelector'; import { Preview } from './components/Preview'; // @ts-ignore import { parse } from 'marked'; import { Sparkles, Loader2, FileType } from 'lucide-react'; const App: React.FC = () => { const [appState, setAppState] = useState(AppState.UPLOAD); const [content, setContent] = useState(''); const [selectedStyle, setSelectedStyle] = useState(null); const [paperSize, setPaperSize] = useState('Letter'); const [generatedHtml, setGeneratedHtml] = useState(''); const [error, setError] = useState(null); const handleFileLoaded = (text: string) => { setContent(text); setAppState(AppState.CONFIG); }; const handleGenerate = async () => { if (!selectedStyle || !content) return; setAppState(AppState.GENERATING); setError(null); try { // Small artificial delay to show the "Processing" state for better UX, // otherwise it flickers too fast since local parsing is instant. await new Promise(resolve => setTimeout(resolve, 800)); // Parse markdown to HTML using the local 'marked' library const html = await parse(content); if (!html) throw new Error("No content generated"); setGeneratedHtml(html); setAppState(AppState.PREVIEW); } catch (err) { console.error(err); setError("Failed to process the document. Please check your file format and try again."); setAppState(AppState.CONFIG); } }; const handleReset = () => { setAppState(AppState.UPLOAD); setContent(''); setGeneratedHtml(''); setSelectedStyle(null); }; const handleBackToConfig = () => { setAppState(AppState.CONFIG); }; // Render Logic if (appState === AppState.PREVIEW) { // Pass selectedStyleId to Preview so it can lookup font config // We add the prop via spread or explicit return ( // @ts-ignore - Adding prop dynamically if interface not fully updated in previous file change block (it was) ); } return (
{/* Header */}

TypoGenie

{appState !== AppState.UPLOAD && (
Configure / Generate / Preview
)}
{/* Main Content */}
{appState === AppState.UPLOAD && (

Turn Markdown into
Professional Word Docs.

Upload your raw text. Select a style. Get a formatted DOCX file ready for Microsoft Word.

)} {appState === AppState.CONFIG && (
{error && (
{error}
)}
)} {appState === AppState.GENERATING && (

Formatting Document

Applying typographic rules and preparing print-ready layout...

)}
); }; export default App;