UNPKG

@casoon/auditmysite

Version:

Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe

154 lines 4.72 kB
"use strict"; /** * 📊 HTML Report Utilities * * Shared utility functions for HTML report generation. * Extracted from html-generator.ts for better maintainability. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateWCAGLevel = calculateWCAGLevel; exports.calculateARIAIssues = calculateARIAIssues; exports.calculateMobilePerformanceScore = calculateMobilePerformanceScore; exports.extractMetricFromIssues = extractMetricFromIssues; exports.getIssueTypeIcon = getIssueTypeIcon; exports.extractLineNumber = extractLineNumber; exports.formatNumber = formatNumber; exports.formatBytes = formatBytes; exports.getGrade = getGrade; exports.getGradeColor = getGradeColor; /** * Calculate WCAG compliance level based on metrics */ function calculateWCAGLevel(score, errors, warnings) { if (errors === 0 && warnings === 0) return 'AAA'; if (errors === 0 && warnings <= 5) return 'AA'; if (errors <= 3 && warnings <= 10) return 'A'; return 'Needs Improvement'; } /** * Calculate ARIA issues count */ function calculateARIAIssues(accessibility, buttonsWithoutLabel, imagesWithoutAlt) { const ariaErrors = accessibility?.errors?.filter((e) => e.code?.includes('aria') || e.message?.toLowerCase().includes('aria')).length || 0; const ariaWarnings = accessibility?.warnings?.filter((w) => w.code?.includes('aria') || w.message?.toLowerCase().includes('aria')).length || 0; return ariaErrors + ariaWarnings + buttonsWithoutLabel + imagesWithoutAlt; } /** * Calculate mobile performance score */ function calculateMobilePerformanceScore(mobilePerf) { if (!mobilePerf) return 0; const metrics = mobilePerf.metrics || mobilePerf; const lcp = metrics.largestContentfulPaint || 0; const fid = metrics.firstInputDelay || metrics.interactionToNextPaint || 0; const cls = metrics.cumulativeLayoutShift || 0; let score = 100; // LCP scoring (50% weight) if (lcp > 4000) score -= 50; else if (lcp > 2500) score -= 25; // FID/INP scoring (30% weight) if (fid > 300) score -= 30; else if (fid > 100) score -= 15; // CLS scoring (20% weight) if (cls > 0.25) score -= 20; else if (cls > 0.1) score -= 10; return Math.max(0, score); } /** * Extract specific metric from issues */ function extractMetricFromIssues(accessibility, metricType) { if (!accessibility) return 0; const allIssues = [ ...(accessibility.errors || []), ...(accessibility.warnings || []) ]; const metricPatterns = { 'color-contrast': [/color.*contrast/i, /insufficient.*contrast/i], 'keyboard': [/keyboard/i, /focus/i, /tab.*index/i], 'screen-reader': [/screen.*reader/i, /aria.*label/i, /alt.*text/i], 'form': [/form.*label/i, /input.*label/i, /form.*field/i] }; const patterns = metricPatterns[metricType] || []; return allIssues.filter((issue) => patterns.some(pattern => pattern.test(issue.message) || pattern.test(issue.code || ''))).length; } /** * Get icon for issue type */ function getIssueTypeIcon(type) { const icons = { error: '❌', warning: '⚠️', notice: 'ℹ️', info: 'ℹ️' }; return icons[type.toLowerCase()] || '•'; } /** * Extract line number from context/selector */ function extractLineNumber(context, selector) { // Try to extract from context if it contains line info const lineMatch = context?.match(/line[:\s]+(\d+)/i); const colMatch = context?.match(/col(?:umn)?[:\s]+(\d+)/i); return { line: lineMatch ? parseInt(lineMatch[1], 10) : 0, column: colMatch ? parseInt(colMatch[1], 10) : 0 }; } /** * Format number with commas */ function formatNumber(num) { return num.toLocaleString(); } /** * Format bytes to human-readable format */ function formatBytes(bytes) { if (bytes === 0) return '0 B'; const k = 1024; const sizes = ['B', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i]; } /** * Get grade from score */ function getGrade(score) { if (score >= 90) return 'A'; if (score >= 80) return 'B'; if (score >= 70) return 'C'; if (score >= 60) return 'D'; return 'F'; } /** * Get color for grade */ function getGradeColor(grade) { const colors = { 'A': '#10b981', 'B': '#84cc16', 'C': '#f59e0b', 'D': '#f97316', 'F': '#ef4444' }; return colors[grade] || '#6b7280'; } //# sourceMappingURL=html-report-utils.js.map