import React, { useState, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { FileText, Code, Eye, ArrowLeft, Download, Copy, Check, Maximize2, ZoomIn, ZoomOut, Search } from 'lucide-react';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { atomDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
import { marked } from 'marked';
const TextViewer = () => {
const [text, setText] = useState('');
const [fileName, setFileName] = useState('');
const [viewMode, setViewMode] = useState('text');
const [copied, setCopied] = useState(false);
const [fontSize, setFontSize] = useState(16);
const [searchTerm, setSearchTerm] = useState('');
const [isSearching, setIsSearching] = useState(false);
useEffect(() => {
// Get text from URL params or localStorage
const urlParams = new URLSearchParams(window.location.search);
const textParam = urlParams.get('text');
const fileParam = urlParams.get('file');
if (textParam) {
setText(decodeURIComponent(textParam));
} else {
const savedText = localStorage.getItem('extractedText');
if (savedText) setText(savedText);
}
if (fileParam) {
setFileName(decodeURIComponent(fileParam));
} else {
setFileName(localStorage.getItem('fileName') || 'extracted-text');
}
}, []);
const viewModes = [
{ id: 'text', label: 'Text', icon: , ext: '.md' },
{ id: 'html', label: 'Rendered', icon:
, ext: '.json' }
];
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error('Failed to copy text:', err);
}
};
const handleBack = () => {
window.history.back();
};
const adjustFontSize = (delta) => {
setFontSize(prev => Math.max(12, Math.min(24, prev + delta)));
}; cons
t renderContent = () => {
const baseStyle = { fontSize: `${fontSize}px`, lineHeight: 1.7 };
switch (viewMode) {
case 'text':
return (
{text}