#!/usr/bin/env python3 """ SVG Validation and Documentation Mapping Script Checks all SVG files for readability issues and shows where they're used in the documentation """ import os import re from collections import defaultdict from pathlib import Path def analyze_svg(filepath): """Analyze an SVG file for potential readability issues""" issues = [] info = {} try: with open(filepath, "r", encoding="utf-8") as f: content = f.read() # Check file size file_size = os.path.getsize(filepath) info["size"] = f"{file_size:,} bytes" # Extract viewBox/dimensions viewbox_match = re.search(r'viewBox="([^"]+)"', content) width_match = re.search(r'width="(\d+)"', content) height_match = re.search(r'height="(\d+)"', content) if viewbox_match: info["viewBox"] = viewbox_match.group(1) elif width_match and height_match: info["dimensions"] = f"{width_match.group(1)}x{height_match.group(1)}" # Check if responsive if 'style="max-width: 100%' in content: info["responsive"] = "āœ“" else: info["responsive"] = "āœ—" issues.append("Not responsive (missing max-width: 100%)") # Find all font sizes font_sizes = re.findall(r'font-size="(\d+)"', content) if font_sizes: sizes = [int(s) for s in font_sizes] info["font_sizes"] = f"min:{min(sizes)}px, max:{max(sizes)}px" # Check for too small fonts small_fonts = [s for s in sizes if s < 12] if small_fonts: issues.append( f"Small fonts found: {small_fonts}px (mobile needs ≄14px)" ) # Check text colors for contrast text_colors = re.findall(r']*fill="([^"]+)"', content) light_colors = [] for color in text_colors: if any( light in color.upper() for light in [ "#CBD5E0", "#A0AEC0", "#E2E8F0", "#EDF2F7", "#F7FAFC", "#9CA3AF", "#D1D5DB", ] ): light_colors.append(color) if light_colors: unique_colors = list(set(light_colors)) issues.append(f"Low contrast text colors: {', '.join(unique_colors[:3])}") # Check for background if ( 'fill="#FAFAFA"' in content or 'fill="white"' in content or 'fill="#FFFFFF"' in content ): if re.search( r']*width="[^"]*"[^>]*height="[^"]*"[^>]*fill="(white|#FAFAFA|#FFFFFF)"', content, ): issues.append("Has white/light background") # Count elements info["texts"] = content.count(" 5: print(f" ... and {len(references[svg_name]) - 5} more") else: print(f"\n ā“ No references found in documentation") # Summary print("\n" + "=" * 80) print("SUMMARY") print("=" * 80) print(f"Total SVG files analyzed: {len(svg_files)}") print(f"Total issues found: {total_issues}") if total_issues > 0: print("\nšŸ”§ RECOMMENDED FIXES:") print("1. Increase all font sizes to minimum 14px for mobile readability") print("2. Replace light gray text colors with darker ones for better contrast") print("3. Remove white backgrounds or make them transparent") print("4. Add responsive styling (max-width: 100%; height: auto)") print("5. Consider using system fonts for better cross-platform support") if __name__ == "__main__": main()