gbu-accessibility-package 1.5.0 โ†’ 3.0.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/README.md CHANGED
@@ -9,6 +9,7 @@
9
9
  ## โœจ Features
10
10
 
11
11
  - ๐Ÿ–ผ๏ธ **Smart Alt Text Generation** - Context-aware alt attributes for images
12
+ - ๐Ÿท๏ธ **Aria Label Support** - Automatic aria-label matching alt text
12
13
  - ๐ŸŒ **HTML Lang Attributes** - Automatic language attribute fixes
13
14
  - ๐ŸŽญ **Role Attributes** - WCAG-compliant role attribute management
14
15
  - ๐Ÿงน **Duplicate Cleanup** - Remove duplicate role attributes
@@ -32,7 +33,7 @@ npm install gbu-accessibility-package
32
33
  ### Basic Usage
33
34
 
34
35
  ```bash
35
- # Fix current directory
36
+ # Comprehensive fixes (default mode)
36
37
  gbu-a11y
37
38
 
38
39
  # Preview changes (dry run)
@@ -41,9 +42,6 @@ gbu-a11y --dry-run
41
42
  # Fix specific directory
42
43
  gbu-a11y ./src
43
44
 
44
- # Comprehensive fixes (recommended)
45
- gbu-a11y --comprehensive
46
-
47
45
  # Fix specific file
48
46
  gbu-a11y index.html
49
47
  ```
@@ -58,13 +56,14 @@ gbu-a11y [options] [directory/file]
58
56
  Options:
59
57
  -d, --directory <path> Target directory (default: current directory)
60
58
  -l, --language <lang> Language for lang attribute (default: ja)
59
+ --backup Create backup files (default: enabled)
61
60
  --no-backup Don't create backup files
62
61
  --dry-run Preview changes without applying
63
- --comprehensive, --all Run all fixes including cleanup (recommended)
62
+ --comprehensive, --all Run comprehensive fixes (same as default)
64
63
  --cleanup-only Only cleanup duplicate role attributes
65
- --alt-only Only fix alt attributes for images
66
- --lang-only Only fix HTML lang attributes
67
- --role-only Only fix role attributes
64
+ --alt-only Fix alt attributes + cleanup
65
+ --lang-only Fix HTML lang attributes + cleanup
66
+ --role-only Fix role attributes + cleanup
68
67
  -h, --help Show help message
69
68
  ```
70
69
 
@@ -74,44 +73,45 @@ Options:
74
73
  # Basic fixes for current directory (all standard fixes)
75
74
  gbu-a11y
76
75
 
77
- # Preview all changes
78
- gbu-a11y --dry-run --comprehensive
76
+ # Preview all changes (comprehensive by default)
77
+ gbu-a11y --dry-run
79
78
 
80
79
  # Fix with English language
81
80
  gbu-a11y -l en ./public
82
81
 
83
- # Individual fix types
84
- gbu-a11y --alt-only # Only fix alt attributes
85
- gbu-a11y --lang-only # Only fix lang attributes
86
- gbu-a11y --role-only # Only fix role attributes
82
+ # Individual fix types (all include cleanup)
83
+ gbu-a11y --alt-only # Fix alt attributes + cleanup
84
+ gbu-a11y --lang-only # Fix lang attributes + cleanup
85
+ gbu-a11y --role-only # Fix role attributes + cleanup
87
86
  gbu-a11y --cleanup-only # Only cleanup duplicates
88
87
 
89
88
  # Combine with other options
90
- gbu-a11y --alt-only --dry-run ./src # Preview alt fixes only
91
- gbu-a11y --role-only -l en ./public # Fix roles with English lang
89
+ gbu-a11y --alt-only --dry-run ./src # Preview alt fixes + cleanup
90
+ gbu-a11y --role-only -l en ./public # Role fixes + cleanup with English lang
92
91
 
93
- # Fix without creating backups
94
- gbu-a11y --no-backup ./dist
92
+ # Backup options
93
+ gbu-a11y --backup ./dist # Explicitly enable backups (default)
94
+ gbu-a11y --no-backup ./dist # Disable backups for faster processing
95
95
  ```
96
96
 
97
97
  ## ๐Ÿ”ง Programmatic Usage
98
98
 
99
99
  ```javascript
100
- const AccessibilityFixer = require('gbu-accessibility-package');
100
+ const AccessibilityFixer = require("gbu-accessibility-package");
101
101
 
102
102
  const fixer = new AccessibilityFixer({
103
- language: 'en',
103
+ language: "en",
104
104
  backupFiles: true,
105
- dryRun: false
105
+ dryRun: false,
106
106
  });
107
107
 
108
108
  // Fix all accessibility issues
109
109
  async function fixAccessibility() {
110
110
  try {
111
- const results = await fixer.fixAllAccessibilityIssues('./src');
112
- console.log('Fixed files:', results);
111
+ const results = await fixer.fixAllAccessibilityIssues("./src");
112
+ console.log("Fixed files:", results);
113
113
  } catch (error) {
114
- console.error('Error:', error);
114
+ console.error("Error:", error);
115
115
  }
116
116
  }
117
117
 
@@ -121,14 +121,16 @@ fixAccessibility();
121
121
  ## ๐ŸŽฏ Fix Modes
122
122
 
123
123
  ### Individual Fix Options
124
+
124
125
  You can now fix specific accessibility issues individually:
125
126
 
126
127
  - `--alt-only` - Only fix alt attributes for images
127
- - `--lang-only` - Only fix HTML lang attributes
128
+ - `--lang-only` - Only fix HTML lang attributes
128
129
  - `--role-only` - Only fix role attributes
129
130
  - `--cleanup-only` - Only cleanup duplicate role attributes
130
131
 
131
132
  ### Combined Modes
133
+
132
134
  - **Standard mode** (default) - Fixes alt, lang, and role attributes
133
135
  - `--comprehensive` - All fixes including duplicate cleanup
134
136
 
@@ -152,36 +154,41 @@ gbu-a11y --comprehensive
152
154
  ## ๐Ÿ”ง What Gets Fixed
153
155
 
154
156
  ### 1. Alt Attributes
157
+
155
158
  - **Missing alt attributes** โ†’ Adds contextual alt text
156
159
  - **Empty alt attributes** โ†’ Generates meaningful descriptions
157
160
  - **Context-aware generation** โ†’ Uses surrounding text, headings, captions
158
161
 
159
162
  ```html
160
163
  <!-- Before -->
161
- <img src="logo.png">
162
- <img src="chart.jpg" alt="">
164
+ <img src="logo.png" />
165
+ <img src="chart.jpg" alt="" />
163
166
 
164
167
  <!-- After -->
165
- <img src="logo.png" alt="ใƒญใ‚ด">
166
- <img src="chart.jpg" alt="ใ‚ฐใƒฉใƒ•">
168
+ <img src="logo.png" alt="ใƒญใ‚ด" />
169
+ <img src="chart.jpg" alt="ใ‚ฐใƒฉใƒ•" />
167
170
  ```
168
171
 
169
172
  ### 2. HTML Lang Attributes
173
+
170
174
  - **Missing lang attributes** โ†’ Adds specified language
171
175
  - **Empty lang attributes** โ†’ Sets proper language code
172
176
 
173
177
  ```html
174
178
  <!-- Before -->
175
179
  <html>
176
- <html lang="">
177
-
178
- <!-- After -->
179
- <html lang="ja">
180
- <html lang="ja">
180
+ <html lang="">
181
+ <!-- After -->
182
+ <html lang="ja">
183
+ <html lang="ja"></html>
184
+ </html>
185
+ </html>
186
+ </html>
181
187
  ```
182
188
 
183
- ### 3. Role Attributes
184
- - **Images** โ†’ `role="img"`
189
+ ### 3. Role Attributes & Aria Labels
190
+
191
+ - **Images** โ†’ `role="img"` + `aria-label` (matching alt text)
185
192
  - **Picture elements** โ†’ Moves `role="img"` from `<picture>` to `<img>` inside
186
193
  - **Links** โ†’ `role="link"`
187
194
  - **Clickable elements** โ†’ `role="button"`
@@ -190,33 +197,48 @@ gbu-a11y --comprehensive
190
197
 
191
198
  ```html
192
199
  <!-- Before -->
193
- <img src="icon.png" alt="Icon">
200
+ <img src="icon.png" alt="Icon" />
194
201
  <picture role="img">
195
- <img src="photo.jpg" alt="Photo">
202
+ <img src="photo.jpg" alt="Photo" />
196
203
  </picture>
197
204
  <a href="/home">Home</a>
198
205
  <div class="btn-click">Click me</div>
199
206
 
200
207
  <!-- After -->
201
- <img src="icon.png" alt="Icon" role="img">
208
+ <img src="icon.png" alt="Icon" role="img" aria-label="Icon" />
202
209
  <picture>
203
- <img src="photo.jpg" alt="Photo" role="img">
210
+ <img src="photo.jpg" alt="Photo" role="img" aria-label="Photo" />
204
211
  </picture>
205
212
  <a href="/home" role="link">Home</a>
206
213
  <div class="btn-click" role="button">Click me</div>
207
214
  ```
208
215
 
209
- ### 4. Duplicate Cleanup
216
+ ### 4. Aria Label Enhancement
217
+
218
+ - **Automatic aria-label** โ†’ Adds `aria-label` matching `alt` text for images
219
+ - **Preserves existing** โ†’ Won't override existing `aria-label` attributes
220
+ - **Smart detection** โ†’ Only adds when `alt` text exists and is not empty
221
+
222
+ ```html
223
+ <!-- Before -->
224
+ <img src="chart.jpg" alt="Sales Chart" />
225
+
226
+ <!-- After -->
227
+ <img src="chart.jpg" alt="Sales Chart" role="img" aria-label="Sales Chart" />
228
+ ```
229
+
230
+ ### 5. Duplicate Cleanup
231
+
210
232
  - **Removes duplicate role attributes**
211
233
  - **Preserves first occurrence**
212
234
  - **Handles mixed quote styles**
213
235
 
214
236
  ```html
215
237
  <!-- Before -->
216
- <img src="test.jpg" role="img" role="img" alt="Test">
238
+ <img src="test.jpg" role="img" role="img" alt="Test" />
217
239
 
218
240
  <!-- After -->
219
- <img src="test.jpg" role="img" alt="Test">
241
+ <img src="test.jpg" role="img" alt="Test" />
220
242
  ```
221
243
 
222
244
  ## ๐ŸŒŸ Smart Alt Text Generation
@@ -224,8 +246,9 @@ gbu-a11y --comprehensive
224
246
  The package uses intelligent context analysis to generate meaningful alt text:
225
247
 
226
248
  ### Context Sources
249
+
227
250
  1. **Title attributes**
228
- 2. **Aria-label attributes**
251
+ 2. **Aria-label attributes**
229
252
  3. **Definition terms (dt elements)**
230
253
  4. **Parent link text**
231
254
  5. **Nearby headings**
@@ -233,6 +256,7 @@ The package uses intelligent context analysis to generate meaningful alt text:
233
256
  7. **Surrounding text content**
234
257
 
235
258
  ### Fallback Patterns
259
+
236
260
  - `logo.png` โ†’ "ใƒญใ‚ด" (Logo)
237
261
  - `icon.svg` โ†’ "ใ‚ขใ‚คใ‚ณใƒณ" (Icon)
238
262
  - `banner.jpg` โ†’ "ใƒใƒŠใƒผ" (Banner)
@@ -242,6 +266,7 @@ The package uses intelligent context analysis to generate meaningful alt text:
242
266
  ## ๐Ÿ“Š Output Examples
243
267
 
244
268
  ### Standard Mode
269
+
245
270
  ```
246
271
  ๐Ÿš€ Starting Accessibility Fixer...
247
272
  ๐Ÿ“ Step 1: Fixing HTML lang attributes...
@@ -250,7 +275,7 @@ The package uses intelligent context analysis to generate meaningful alt text:
250
275
  ๐Ÿ–ผ๏ธ Step 2: Fixing alt attributes...
251
276
  โœ… Fixed alt attributes in 12 files (34 issues)
252
277
 
253
- ๐ŸŽญ Step 3: Fixing role attributes...
278
+ ๐ŸŽญ Step 3: Fixing role attributes...
254
279
  โœ… Fixed role attributes in 8 files (67 issues)
255
280
 
256
281
  ๐Ÿ“Š Summary:
@@ -262,6 +287,7 @@ The package uses intelligent context analysis to generate meaningful alt text:
262
287
  ```
263
288
 
264
289
  ### Comprehensive Mode
290
+
265
291
  ```
266
292
  ๐ŸŽฏ Running comprehensive accessibility fixes...
267
293
  ๐Ÿ“ Step 1: HTML lang attributes...
@@ -272,14 +298,32 @@ The package uses intelligent context analysis to generate meaningful alt text:
272
298
  ๐ŸŽ‰ All accessibility fixes completed!
273
299
  ๐Ÿ“Š Final Summary:
274
300
  Total files scanned: 25
275
- Files fixed: 15
301
+ Files fixed: 15
276
302
  Total issues resolved: 106
277
303
  ```
278
304
 
279
305
  ## ๐Ÿ”’ Safety Features
280
306
 
281
- - **Automatic backups** with `.backup` extension
282
- - **Dry run mode** for safe previewing
307
+ ### Backup Options
308
+
309
+ - **Default behavior**: Creates `.backup` files automatically for safety
310
+ - **Disable backups**: Use `--no-backup` for faster processing
311
+ - **Explicit enable**: Use `--backup` to be explicit about backup creation
312
+
313
+ ```bash
314
+ # Safe mode (default) - creates backups
315
+ gbu-a11y --comprehensive
316
+
317
+ # Fast mode - no backups
318
+ gbu-a11y --no-backup --comprehensive
319
+
320
+ # Explicit backup mode
321
+ gbu-a11y --backup --comprehensive
322
+ ```
323
+
324
+ ### Other Safety Features
325
+
326
+ - **Dry run mode** for safe previewing with `--dry-run`
283
327
  - **Non-destructive** - only adds missing attributes
284
328
  - **Duplicate prevention** - won't add existing attributes
285
329
  - **Error handling** - continues processing on individual file errors
@@ -287,6 +331,7 @@ The package uses intelligent context analysis to generate meaningful alt text:
287
331
  ## ๐Ÿ› ๏ธ Configuration
288
332
 
289
333
  ### Package.json Scripts
334
+
290
335
  ```json
291
336
  {
292
337
  "scripts": {
@@ -295,19 +340,20 @@ The package uses intelligent context analysis to generate meaningful alt text:
295
340
  "a11y:comprehensive": "gbu-a11y --comprehensive",
296
341
  "a11y:cleanup": "gbu-a11y --cleanup-only",
297
342
  "a11y:alt": "gbu-a11y --alt-only",
298
- "a11y:lang": "gbu-a11y --lang-only",
343
+ "a11y:lang": "gbu-a11y --lang-only",
299
344
  "a11y:role": "gbu-a11y --role-only"
300
345
  }
301
346
  }
302
347
  ```
303
348
 
304
349
  ### CI/CD Integration
350
+
305
351
  ```yaml
306
352
  # GitHub Actions example
307
353
  - name: Check Accessibility
308
354
  run: npx gbu-accessibility-package --dry-run
309
355
 
310
- - name: Fix Accessibility Issues
356
+ - name: Fix Accessibility Issues
311
357
  run: npx gbu-accessibility-package --comprehensive
312
358
  ```
313
359
 
@@ -340,4 +386,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
340
386
 
341
387
  ---
342
388
 
343
- Made with โค๏ธ by the GBU Team
389
+ Made with โค๏ธ by the GBU Team