UNPKG

gbu-accessibility-package

Version:

Comprehensive accessibility fixes and project optimization for HTML files. Smart context-aware alt text generation, form labels, button names, link names, landmarks, heading analysis, WCAG-compliant role attributes, unused files detection, dead code analy

476 lines (363 loc) โ€ข 16.3 kB
# GBU Accessibility Package ๐Ÿš€ **Automated accessibility fixes for HTML files** - Smart, context-aware accessibility improvements with zero configuration. [![npm version](https://badge.fury.io/js/gbu-accessibility-package.svg)](https://www.npmjs.com/package/gbu-accessibility-package) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Node.js Version](https://img.shields.io/badge/node-%3E%3D12.0.0-brightgreen)](https://nodejs.org/) ## โœจ Features ### ๐ŸŽฏ **Core Accessibility Fixes** - ๐Ÿ–ผ๏ธ **Smart Alt Text Generation** - Context-aware alt attributes for images - ๐Ÿท๏ธ **Aria Label Support** - Automatic aria-label matching alt text - ๐ŸŒ **HTML Lang Attributes** - Automatic language attribute fixes - ๐ŸŽญ **Role Attributes** - WCAG-compliant role attribute management - ๐Ÿท๏ธ **Aria Labels** - Automatic aria-label generation from alt text and content - ๐Ÿ“‹ **Form Labels** - Fix missing labels with intelligent aria-label generation - ๐Ÿ”˜ **Button Names** - Fix empty buttons and input buttons without names - ๐Ÿ”— **Link Names** - Fix empty links and detect generic link text - ๐Ÿ›๏ธ **Landmarks** - Add missing main and navigation landmarks - ๐Ÿ“‘ **Heading Analysis & Auto-Fix** - Analyze heading structure with optional auto-fix using `--auto-fix-headings` - ๐ŸŽฏ **Nested Controls Detection** - Detect and fix nested interactive controls - ๐Ÿ” **Broken Links Detection** - Detect broken external links - ๐Ÿ“ **404 Resources Detection** - Detect missing local resources (images, CSS, JS, etc.) - ๐Ÿ—‚๏ธ **Unused Files Detection** - Find files not referenced anywhere in the project - โ˜ ๏ธ **Dead Code Analysis** - Detect unused CSS rules and JavaScript functions - ๐Ÿ“ **File Size Analysis** - Check file sizes and suggest optimizations - ๐Ÿงน **Duplicate Cleanup** - Remove duplicate role attributes ### ๐Ÿš€ **Enhanced Alt Attribute Features (Integrated!)** - ๐Ÿ” **Comprehensive Analysis** - Image type classification and quality checking built-in - ๐ŸŽจ **Diverse Alt Generation** - Multiple strategies for creative alt text integrated in core - ๐ŸŒ **Multi-language Support** - Japanese, English, Vietnamese vocabulary built-in - ๐ŸŽญ **Creativity Levels** - Conservative, Balanced, Creative modes - ๐Ÿง  **Context Awareness** - Brand, emotional, and technical context integration - ๐Ÿ“Š **Data Visualization** - Specialized descriptions for charts and graphs - ๐Ÿงน **Clean Architecture** - All enhanced features integrated in a single file ### ๐Ÿ› ๏ธ **Utility Features** - ๐Ÿ“ **Batch Processing** - Process entire directories recursively - ๐Ÿ’พ **Optional Backups** - Create backup files when needed with --backup flag - ๐Ÿ” **Dry Run Mode** - Preview changes before applying - ๐Ÿ“Š **Detailed Reports** - Comprehensive fix summaries - โšก **Individual Fix Modes** - Target specific accessibility issues ## ๐Ÿš€ Quick Start ### Installation ```bash # Global installation (recommended) npm install -g gbu-accessibility-package # Local installation npm install gbu-accessibility-package ``` ### Uninstall and Reinstall ```bash # Uninstall global package npm uninstall -g gbu-accessibility-package # Uninstall local package npm uninstall gbu-accessibility-package # Clear npm cache (recommended when having issues) npm cache clean --force # Reinstall latest version npm install -g gbu-accessibility-package@latest # Check installed version npm list -g gbu-accessibility-package gbu-a11y --version # Install specific version npm install -g gbu-accessibility-package@3.2.1 ``` ### Installation Troubleshooting ```bash # If permission errors (macOS/Linux) sudo npm install -g gbu-accessibility-package # If cache issues npm cache clean --force npm install -g gbu-accessibility-package --force # Verify installation which gbu-a11y gbu-a11y --help # Update to latest version npm update -g gbu-accessibility-package ``` ### Basic Usage ```bash # Comprehensive fixes (default mode) gbu-a11y # Preview changes (dry run) gbu-a11y --dry-run # Fix specific directory gbu-a11y ./src # Fix specific file gbu-a11y index.html ``` ### Enhanced Alt Attribute Mode ```bash # Enable enhanced alt attribute analysis gbu-a11y --enhanced-alt # Creative alt text generation with emotions gbu-a11y --enhanced-alt --alt-creativity creative --include-emotions # Strict quality checking gbu-a11y --enhanced-alt --strict-alt # English with creative mode gbu-a11y -l en --enhanced-alt --alt-creativity creative ``` ## ๐Ÿ“– Detailed Usage ### Command Line Options ```bash gbu-a11y [options] [directory/file] Basic Options: -d, --directory <path> Target directory (default: current directory) -l, --language <lang> Language for lang attribute (default: ja) --backup Create backup files --no-backup Don't create backup files (default) --dry-run Preview changes without applying Fix Modes: --comprehensive, --all Run comprehensive fixes (default) --alt-only Fix alt attributes + cleanup --lang-only Fix HTML lang attributes + cleanup --role-only Fix role attributes + cleanup --aria-label-only Fix aria-label attributes + cleanup --forms-only Fix form labels + cleanup --buttons-only Fix button names + cleanup --links-only Fix link names + cleanup --landmarks-only Fix landmarks + cleanup --headings-only Analyze heading structure with optional auto-fix --auto-fix-headings Enable automatic heading structure fixes --links-check Check for broken links and 404 resources (comprehensive, no auto-fix) --broken-links Check for broken external links only (no auto-fix) --404-resources Check for missing local resources only (no auto-fix) --unused-files Check for unused files in project --dead-code Check for dead code in CSS and JavaScript --file-size, --size-check Check file sizes and suggest optimizations --cleanup-only Only cleanup duplicate role attributes Enhanced Alt Options: --enhanced-alt Use enhanced alt attribute analysis and generation --alt-creativity <mode> Alt text creativity: conservative, balanced, creative --include-emotions Include emotional descriptors in alt text --strict-alt Enable strict alt attribute quality checking Help: -h, --help Show help message -v, --version Show version number ``` ### Examples ```bash # Basic comprehensive fixes gbu-a11y # Preview all changes gbu-a11y --dry-run # Fix with English language gbu-a11y -l en ./public # Individual fix types gbu-a11y --alt-only # Fix alt attributes + cleanup gbu-a11y --aria-label-only # Fix aria-label attributes + cleanup gbu-a11y --forms-only # Fix form labels + cleanup gbu-a11y --buttons-only # Fix button names + cleanup gbu-a11y --headings-only # Analyze heading structure gbu-a11y --headings-only --auto-fix-headings # Auto-fix heading structure gbu-a11y --links-check # Check broken links and missing resources + cleanup gbu-a11y --broken-links # Check broken external links only + cleanup gbu-a11y --404-resources # Check missing local resources only + cleanup gbu-a11y --unused-files # Check for unused files in project gbu-a11y --dead-code # Check for dead CSS and JavaScript code gbu-a11y --file-size # Check file sizes and suggest optimizations # Enhanced alt attribute features gbu-a11y --enhanced-alt # Basic enhanced mode gbu-a11y --enhanced-alt --alt-creativity creative # Creative descriptions gbu-a11y --enhanced-alt --include-emotions # Include emotional context gbu-a11y --enhanced-alt --strict-alt # Strict quality checking gbu-a11y -l en --enhanced-alt --alt-creativity creative # English creative mode # Combine with other options gbu-a11y --enhanced-alt --backup ./src # Enhanced mode with backups gbu-a11y --enhanced-alt --dry-run # Preview enhanced fixes ``` ## ๐ŸŽจ Enhanced Alt Attribute Features ### Creativity Levels #### Conservative - Simple, factual descriptions - Focus on basic functionality - Minimal vocabulary variation **Example**: `alt="Chart"`, `alt="Logo"` #### Balanced (Default) - Context-aware descriptions - Moderate creativity - Balance between simple and detailed **Example**: `alt="Sales performance chart"`, `alt="Company logo"` #### Creative - Rich, detailed descriptions - Emotional context integration - High brand and context awareness **Example**: `alt="Dynamic sales performance chart showing impressive 25% quarterly growth"`, `alt="Innovative technology company logo representing digital transformation"` ### Image Type Classification - **Decorative Images**: Automatically detected and marked with `alt=""` - **Functional Icons**: Described by their action (e.g., "Open chat", "Search") - **Data Visualizations**: Include chart type, trends, and key data points - **Complex Images**: Short alt + recommendation for detailed description - **Logos**: Include brand name and "logo" keyword - **Content Images**: Context-aware descriptions based on surrounding content ### Quality Checks - โŒ **Error Level**: Missing alt, empty alt for content, generic text - โš ๏ธ **Warning Level**: Too long/short, redundant words, filename in alt - โ„น๏ธ **Info Level**: Optimization suggestions, consistency checks ## ๐Ÿ“‹ Programmatic Usage ### Basic Usage ```javascript const { AccessibilityFixer } = require('gbu-accessibility-package'); const fixer = new AccessibilityFixer({ language: 'ja', backupFiles: true, dryRun: false }); // Fix all accessibility issues fixer.fixAllAccessibilityIssues('./src').then(results => { console.log('Accessibility fixes completed:', results); }); // Fix specific issues await fixer.fixEmptyAltAttributes('./src'); await fixer.fixFormLabels('./src'); await fixer.fixButtonNames('./src'); ``` ### Enhanced Alt Attribute Mode (Integrated) ```javascript const { AccessibilityFixer } = require('gbu-accessibility-package'); // Use AccessibilityFixer with enhanced mode (integrated) const fixer = new AccessibilityFixer({ language: 'en', enhancedAltMode: true, altCreativity: 'creative', includeEmotions: true, strictAltChecking: true }); await fixer.fixEmptyAltAttributes('./src'); // All enhanced features are now integrated in AccessibilityFixer // No need to import separate classes const results = await fixer.fixAllAccessibilityIssues('./src'); console.log('Accessibility fixes completed with enhanced features:', results); // New: Check for unused files await fixer.checkUnusedFiles('./src'); // New: Check for dead code await fixer.checkDeadCode('./src'); // New: Check file sizes await fixer.checkFileSizes('./src'); ``` ## ๐ŸŽฏ What Gets Fixed ### Alt Attributes (Enhanced Mode) - **Missing alt attributes** โ†’ Context-aware alt text generation - **Empty alt attributes** โ†’ Smart content-based descriptions - **Generic alt text** โ†’ Specific, meaningful descriptions - **Too long alt text** โ†’ Optimized length with key information - **Redundant words** โ†’ Clean, concise descriptions - **Data visualizations** โ†’ Chart type + trends + key data ### Form Accessibility - **Missing form labels** โ†’ Intelligent aria-label generation - **Unlabeled inputs** โ†’ Context-based label suggestions - **Form structure** โ†’ Proper label associations ### Interactive Elements - **Empty buttons** โ†’ Action-based button names - **Generic link text** โ†’ Descriptive link purposes - **Missing button names** โ†’ Function-based descriptions ### Document Structure - **Missing lang attributes** โ†’ Automatic language detection - **Missing landmarks** โ†’ Main and navigation landmarks - **Heading structure** โ†’ Analysis and auto-fix with `--auto-fix-headings` - Fix multiple h1 elements - Fix heading level skipping (h2 โ†’ h4) - Add text to empty headings - Fix duplicate headings - **Nested interactive controls** โ†’ Detect and fix nested controls - **Role attributes** โ†’ WCAG-compliant role assignments ### Link Validation - **Broken External Links** โ†’ Detect HTTP 404, 500, timeout errors on external URLs - Invalid URLs โ†’ Detect malformed URL formats - Slow links โ†’ Warn about timeouts and slow responses - Network errors โ†’ Connection failures and unreachable hosts - **404 Missing Resources** โ†’ Check for missing local files - Images (img src), CSS files (link href), JavaScript files (script src) - Video/audio sources, other local assets - Relative and absolute path checking ### Project Optimization - **Unused Files** โ†’ Detect files not referenced anywhere in the project - Images, CSS, SCSS/Sass, JavaScript, JSX, TypeScript, Vue, PHP, JSON, Markdown, XML, PDF, Video, Audio files - Local file references analysis - Heuristic detection with manual review recommendations - **Dead Code Analysis** โ†’ Find unused CSS rules and JavaScript functions - CSS selectors not used in HTML - JavaScript functions never called - Variables declared but never used - Smart skipping of dynamic patterns - **File Size Analysis** โ†’ Check file sizes and suggest optimizations - Detect large files exceeding recommended thresholds - Type-specific optimization suggestions (images, CSS, JS, etc.) - File size breakdown by type - Top 10 largest files reporting ## ๐Ÿ”ง Package Management ### Check package information ```bash # Check current version gbu-a11y --version npm list -g gbu-accessibility-package # View package info npm info gbu-accessibility-package # Verify installation which gbu-a11y npm list -g | grep gbu-accessibility-package ``` ### Update package ```bash # Check for new versions npm outdated -g gbu-accessibility-package # Update to latest version npm update -g gbu-accessibility-package # Or reinstall latest version npm uninstall -g gbu-accessibility-package npm install -g gbu-accessibility-package@latest ``` ### Cache management ```bash # Verify cache npm cache verify # Clean cache (when having issues) npm cache clean --force # View cache location npm config get cache ``` ## ๐Ÿงช Testing and Demo ```bash # Test the package npm test # Demo basic features npm run demo # Demo enhanced alt features npm run demo-enhanced # Demo creative alt generation npm run demo-creative # Test enhanced alt features npm run test-enhanced-alt ``` ## ๐Ÿ“Š Performance - **Basic Mode**: Fast processing, suitable for large projects - **Enhanced Mode**: ~20-30% slower but 85-90% improvement in alt text quality - **Memory Usage**: +15-20% for enhanced vocabulary and analysis - **Accuracy**: 95%+ detection of accessibility issues ## ๐ŸŒ Language Support - **Japanese (ja)**: Default language with rich vocabulary - **English (en)**: Comprehensive English support - **Vietnamese (vi)**: Vietnamese language support Enhanced alt features include language-specific vocabulary and grammar rules for natural, contextually appropriate descriptions. ## ๐Ÿ“š Documentation - [Enhanced Alt Features Guide](./ENHANCED_ALT_FEATURES.md) - Detailed documentation for enhanced alt attribute features - [Quick Start Guide](./QUICK_START.md) - Get started quickly - [Package Summary](./PACKAGE_SUMMARY.md) - Overview of all features - [Changelog](./CHANGELOG.md) - Version history and updates ## ๐Ÿค Contributing Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change. ### Development Setup ```bash git clone https://github.com/dangpv94/gbu-accessibility-tool.git cd gbu-accessibility-tool/accessibility-package npm install npm test ``` ## ๐Ÿ“„ License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## ๐Ÿ™ Acknowledgments - Built with accessibility best practices in mind - Follows WCAG guidelines - Inspired by the need for automated accessibility improvements - Community feedback and contributions --- **Made with โค๏ธ by the GBU Team** For more information, visit our [GitHub repository](https://github.com/dangpv94/gbu-accessibility-tool).