gbu-accessibility-package 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/fixer.js CHANGED
@@ -6,15 +6,37 @@
6
6
  const fs = require('fs').promises;
7
7
  const path = require('path');
8
8
  const chalk = require('chalk');
9
+ const EnhancedAltChecker = require('./enhanced-alt-checker.js');
10
+ const EnhancedAltGenerator = require('./enhanced-alt-generator.js');
9
11
 
10
12
  class AccessibilityFixer {
11
13
  constructor(config = {}) {
12
14
  this.config = {
13
- backupFiles: config.backupFiles !== false,
15
+ backupFiles: config.backupFiles === true,
14
16
  language: config.language || 'ja',
15
17
  dryRun: config.dryRun || false,
18
+ enhancedAltMode: config.enhancedAltMode || false,
19
+ altCreativity: config.altCreativity || 'balanced', // conservative, balanced, creative
20
+ includeEmotions: config.includeEmotions || false,
21
+ strictAltChecking: config.strictAltChecking || false,
16
22
  ...config
17
23
  };
24
+
25
+ // Initialize enhanced alt tools
26
+ this.enhancedAltChecker = new EnhancedAltChecker({
27
+ language: this.config.language,
28
+ strictMode: this.config.strictAltChecking,
29
+ checkDecorative: true,
30
+ checkInformative: true,
31
+ checkComplex: true
32
+ });
33
+
34
+ this.enhancedAltGenerator = new EnhancedAltGenerator({
35
+ language: this.config.language,
36
+ creativity: this.config.altCreativity,
37
+ includeEmotions: this.config.includeEmotions,
38
+ includeBrandContext: true
39
+ });
18
40
  }
19
41
 
20
42
  async fixHtmlLang(directory = '.') {
@@ -57,18 +79,50 @@ class AccessibilityFixer {
57
79
  const htmlFiles = await this.findHtmlFiles(directory);
58
80
  const results = [];
59
81
  let totalIssuesFound = 0;
82
+ let enhancedIssues = []; // Declare here to avoid scope issues
60
83
 
61
84
  for (const file of htmlFiles) {
62
85
  try {
63
86
  const content = await fs.readFile(file, 'utf8');
64
- const issues = this.analyzeAltAttributes(content);
65
87
 
66
- if (issues.length > 0) {
67
- console.log(chalk.cyan(`\nšŸ“ ${file}:`));
68
- issues.forEach(issue => {
69
- console.log(chalk.yellow(` ${issue.type}: ${issue.description}`));
70
- totalIssuesFound++;
71
- });
88
+ // Use enhanced alt checker if enabled
89
+ if (this.config.enhancedAltMode) {
90
+ enhancedIssues = this.enhancedAltChecker.analyzeAltAttributes(content);
91
+
92
+ if (enhancedIssues.length > 0) {
93
+ console.log(chalk.cyan(`\nšŸ“ ${file}:`));
94
+ enhancedIssues.forEach(issue => {
95
+ console.log(chalk.yellow(` šŸ” Image ${issue.imageIndex} (${issue.src}):`));
96
+ issue.issues.forEach(subIssue => {
97
+ const icon = subIssue.severity === 'ERROR' ? 'āŒ' :
98
+ subIssue.severity === 'WARNING' ? 'āš ļø' : 'ā„¹ļø';
99
+ console.log(chalk.yellow(` ${icon} ${subIssue.message}`));
100
+ console.log(chalk.gray(` ${subIssue.description}`));
101
+ });
102
+
103
+ // Show recommendations
104
+ if (issue.recommendations.length > 0) {
105
+ console.log(chalk.blue(` šŸ’” Recommendations:`));
106
+ issue.recommendations.forEach(rec => {
107
+ console.log(chalk.blue(` ${rec.suggestion}`));
108
+ console.log(chalk.gray(` ${rec.reason}`));
109
+ });
110
+ }
111
+ totalIssuesFound += issue.issues.length;
112
+ });
113
+ }
114
+ } else {
115
+ // Use original analysis
116
+ const issues = this.analyzeAltAttributes(content);
117
+
118
+ if (issues.length > 0) {
119
+ console.log(chalk.cyan(`\nšŸ“ ${file}:`));
120
+ issues.forEach(issue => {
121
+ console.log(chalk.yellow(` ${issue.type}: ${issue.description}`));
122
+ totalIssuesFound++;
123
+ });
124
+ }
125
+ enhancedIssues = issues; // For consistency in results calculation
72
126
  }
73
127
 
74
128
  const fixed = this.fixAltAttributes(content);
@@ -83,9 +137,11 @@ class AccessibilityFixer {
83
137
  }
84
138
 
85
139
  console.log(chalk.green(`āœ… Fixed alt attributes in: ${file}`));
86
- results.push({ file, status: 'fixed', issues: issues.length });
140
+ results.push({ file, status: 'fixed', issues: this.config.enhancedAltMode ?
141
+ enhancedIssues.reduce((sum, ei) => sum + (ei.issues ? ei.issues.length : 1), 0) : enhancedIssues.length });
87
142
  } else {
88
- results.push({ file, status: 'no-change', issues: issues.length });
143
+ results.push({ file, status: 'no-change', issues: this.config.enhancedAltMode ?
144
+ enhancedIssues.reduce((sum, ei) => sum + (ei.issues ? ei.issues.length : 1), 0) : enhancedIssues.length });
89
145
  }
90
146
  } catch (error) {
91
147
  console.error(chalk.red(`āŒ Error processing ${file}: ${error.message}`));
@@ -94,6 +150,9 @@ class AccessibilityFixer {
94
150
  }
95
151
 
96
152
  console.log(chalk.blue(`\nšŸ“Š Summary: Found ${totalIssuesFound} alt attribute issues across ${results.length} files`));
153
+ if (this.config.enhancedAltMode) {
154
+ console.log(chalk.gray(` šŸ” Enhanced analysis mode: Comprehensive quality checking enabled`));
155
+ }
97
156
  return results;
98
157
  }
99
158
 
@@ -245,6 +304,21 @@ class AccessibilityFixer {
245
304
  }
246
305
 
247
306
  generateAltText(imgTag, htmlContent = '', imgIndex = 0) {
307
+ // Use enhanced alt generator if enabled
308
+ if (this.config.enhancedAltMode) {
309
+ try {
310
+ const analysis = this.enhancedAltChecker.analyzeImageContext(imgTag, htmlContent, imgIndex);
311
+ const enhancedAlt = this.enhancedAltGenerator.generateDiverseAltText(imgTag, htmlContent, analysis);
312
+
313
+ if (enhancedAlt && enhancedAlt.trim().length > 0) {
314
+ return enhancedAlt;
315
+ }
316
+ } catch (error) {
317
+ console.warn(chalk.yellow(`āš ļø Enhanced alt generation failed, falling back to basic mode: ${error.message}`));
318
+ }
319
+ }
320
+
321
+ // Fallback to original method
248
322
  const src = imgTag.match(/src\s*=\s*["']([^"']+)["']/i);
249
323
  const srcValue = src ? src[1].toLowerCase() : '';
250
324
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gbu-accessibility-package",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Comprehensive accessibility fixes for HTML files. Smart context-aware alt text generation, form labels, button names, link names, landmarks, heading analysis, and WCAG-compliant role attributes. Covers major axe DevTools issues with individual fix modes.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -24,7 +24,10 @@
24
24
  "no-backup": "node cli.js --no-backup",
25
25
  "cleanup-backups": "find . -name '*.backup' -type f -delete",
26
26
  "test": "node test-package.js",
27
+ "test-enhanced-alt": "node test-enhanced-alt.js",
27
28
  "demo": "node cli.js --dry-run demo",
29
+ "demo-enhanced": "node cli.js --enhanced-alt --dry-run demo",
30
+ "demo-creative": "node cli.js --enhanced-alt --alt-creativity creative --include-emotions --dry-run demo",
28
31
  "prepublishOnly": "npm run test"
29
32
  },
30
33
  "keywords": [
@@ -74,6 +77,7 @@
74
77
  "CHANGELOG.md",
75
78
  "QUICK_START.md",
76
79
  "PACKAGE_SUMMARY.md",
80
+ "ENHANCED_ALT_FEATURES.md",
77
81
  "LICENSE"
78
82
  ],
79
83
  "dependencies": {
@@ -1,44 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Advanced Accessibility Test</title>
6
- </head>
7
- <body>
8
- <h1>Advanced Accessibility Test</h1>
9
-
10
- <!-- Form issues -->
11
- <form>
12
- <input type="text" placeholder="Name">
13
- <input type="email" id="email">
14
- <input type="password">
15
- <input type="submit">
16
- </form>
17
-
18
- <!-- Button issues -->
19
- <button></button>
20
- <button onclick="alert('test')"></button>
21
- <input type="button">
22
-
23
- <!-- Link issues -->
24
- <a href="/home"></a>
25
- <a href="/more">Click here</a>
26
- <a href="/read">Read more</a>
27
- <a href="/image"><img src="icon.png"></a>
28
-
29
- <!-- Heading issues -->
30
- <h3>Skipped h2</h3>
31
- <h1>Second h1</h1>
32
- <h4></h4>
33
-
34
- <!-- Landmark issues -->
35
- <div class="content">
36
- <p>Main content without landmark</p>
37
- </div>
38
-
39
- <ul class="navigation">
40
- <li><a href="/home">Home</a></li>
41
- <li><a href="/about">About</a></li>
42
- </ul>
43
- </body>
44
- </html>
@@ -1,18 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Backup Test</title>
6
- </head>
7
- <body>
8
- <h1>Backup Test File</h1>
9
-
10
- <!-- This will be fixed -->
11
- <img src="test.jpg" alt="Test image" role="img" aria-label="Test image">
12
-
13
- <!-- This will also be fixed -->
14
- <a href="/home" role="link">Home Link</a>
15
-
16
- <p>This file is used to test backup functionality.</p>
17
- </body>
18
- </html>
@@ -1,13 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>No Backup Test</title>
6
- </head>
7
- <body>
8
- <h1>No Backup Test File</h1>
9
-
10
- <img src="test2.jpg" alt="Test image 2" role="img" aria-label="Test image 2">
11
- <a href="/about" role="link">About Link</a>
12
- </body>
13
- </html>
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Explicit Backup Test</title>
6
- </head>
7
- <body>
8
- <h1>Explicit Backup Test File</h1>
9
-
10
- <img src="test3.jpg" alt="Test image 3" role="img" aria-label="Test image 3">
11
- </body>
12
- </html>
@@ -1,21 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Comprehensive Test</title>
6
- </head>
7
- <body>
8
- <h1>Comprehensive Test File</h1>
9
-
10
- <!-- Missing alt -->
11
- <img src="test.jpg">
12
-
13
- <!-- Missing role -->
14
- <a href="/home">Home</a>
15
-
16
- <!-- Duplicate roles -->
17
- <img src="dup.jpg" alt="Duplicate" role="img" role="img">
18
-
19
- <p>This tests comprehensive mode as default.</p>
20
- </body>
21
- </html>