Lexical Diversity Analyzer Lexical Diversity Analyzer Measure the richness and variety of vocabulary in your text. 1. Input Text 2. Diversity Analysis 3. Export Report Paste your text below to get started: Download Your Report Export the complete lexical analysis as a professional PDF document. Download Analysis Report (PDF) Previous Analyze Text A higher lexical diversity score indicates a wider range of vocabulary. Scores typically range from 40-60% for varied texts. Most Frequent Words ${analysisData.mostFrequent.map(([word, count]) => `${word}: ${count} times`).join('')} `; elements.analysisResults.innerHTML = html; maxUnlockedTab = Math.max(maxUnlockedTab, 2); // Unlock final tab after display }; // --- PDF UTILITY --- const downloadPDF = () => { // Ensure analysis has been run if (!analysisData.totalWords) { alert("Please analyze some text before downloading the report."); return; } const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const title = "Lexical Diversity Report"; const PAGE_WIDTH = pdf.internal.pageSize.getWidth(); const MARGIN = 50; let y = 0; // Header pdf.setFillColor(55, 48, 163); // indigo-800 pdf.rect(0, 0, PAGE_WIDTH, 70, 'F'); pdf.setFont('helvetica', 'bold'); pdf.setFontSize(22); pdf.setTextColor(255, 255, 255); pdf.text(title, MARGIN, 45); y = 110; const addSection = (secTitle, secContent) => { if (y > pdf.internal.pageSize.getHeight() - 80) { pdf.addPage(); y = MARGIN; } pdf.setFont('helvetica', 'bold'); pdf.setFontSize(14); pdf.setTextColor(67, 56, 202); // indigo-700 pdf.text(secTitle, MARGIN, y); y += 20; pdf.setFont('helvetica', 'normal'); pdf.setFontSize(10); pdf.setTextColor(51, 65, 85); // slate-700 const lines = pdf.splitTextToSize(secContent, PAGE_WIDTH - MARGIN * 2); pdf.text(lines, MARGIN, y); y += lines.length * 12 + 25; }; const summary = `Total Words: ${analysisData.totalWords}\nUnique Words: ${analysisData.uniqueWords}\nLexical Diversity Score: ${analysisData.lexicalDiversity}%`; addSection("Analysis Summary", summary); const frequentWords = analysisData.mostFrequent.map(([word, count]) => `• ${word} (${count} times)`).join('\n'); addSection("Most Frequent Words", frequentWords); pdf.addPage(); y = MARGIN; addSection("Original Text Analyzed", analysisData.text); pdf.save(`Lexical_Diversity_Report.pdf`); }; // --- EVENT LISTENERS --- elements.prevBtn.addEventListener('click', () => nextPrev(-1)); elements.nextBtn.addEventListener('click', () => nextPrev(1)); elements.tabs.forEach((tab, i) => { tab.addEventListener('click', () => { if (i <= maxUnlockedTab) { // Special case: if clicking tab 2 and analysis hasn't run, run it. if (i === 1 && !analysisData.totalWords) { if (!performAnalysis()) return; // Don't switch tab if analysis fails } showTab(i); } }); }); elements.downloadPdfBtn.addEventListener('click', downloadPDF); // Initialize showTab(currentTab); });