gbu-accessibility-package 1.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.
@@ -0,0 +1,191 @@
1
+ # 📦 Accessibility Fixer Package - Summary
2
+
3
+ ## 🎯 Mục đích
4
+
5
+ Tool tự động sửa các vấn đề accessibility phổ biến trong HTML files, giúp website tuân thủ WCAG guidelines.
6
+
7
+ ## 📁 Cấu trúc Package
8
+
9
+ ```
10
+ accessibility-package/
11
+ ├── lib/
12
+ │ └── fixer.js # Core logic
13
+ ├── demo/
14
+ │ └── sample.html # File demo để test
15
+ ├── cli.js # Command line interface
16
+ ├── example.js # Ví dụ sử dụng
17
+ ├── package.json # Package configuration
18
+ ├── README.md # Hướng dẫn đầy đủ
19
+ ├── QUICK_START.md # Hướng dẫn nhanh
20
+ └── PACKAGE_SUMMARY.md # File này
21
+
22
+ ```
23
+
24
+ ## ✨ Tính năng chính
25
+
26
+ ### 1. Alt Attributes
27
+
28
+ - ✅ Tự động thêm alt text cho images thiếu
29
+ - ✅ Sửa empty alt attributes
30
+ - ✅ Context-aware: phân tích nội dung xung quanh để tạo alt text phù hợp
31
+ - ✅ Hỗ trợ nhiều ngôn ngữ (ja, en, vi, zh, etc.)
32
+
33
+ ### 2. Lang Attributes
34
+
35
+ - ✅ Thêm lang attribute cho thẻ `<html>`
36
+ - ✅ Configurable language
37
+
38
+ ### 3. Role Attributes
39
+
40
+ - ✅ `role="img"` cho tất cả thẻ `<img>`
41
+ - ✅ `role="link"` cho thẻ `<a>`
42
+ - ✅ `role="button"` cho elements có onclick
43
+ - ✅ `role="menubar"` và `role="menuitem"` cho navigation
44
+ - ✅ Tự động detect clickable elements
45
+
46
+ ## 🚀 Cách sử dụng
47
+
48
+ ### Option 1: CLI (Đơn giản)
49
+
50
+ ```bash
51
+ node accessibility-package/cli.js
52
+ ```
53
+
54
+ ### Option 2: Node.js
55
+
56
+ ```javascript
57
+ const AccessibilityFixer = require("./accessibility-package/lib/fixer.js");
58
+ const fixer = new AccessibilityFixer({ language: "ja" });
59
+ await fixer.fixRoleAttributes(".");
60
+ ```
61
+
62
+ ### Option 3: NPM Scripts
63
+
64
+ ```json
65
+ {
66
+ "scripts": {
67
+ "fix-a11y": "node accessibility-package/cli.js",
68
+ "preview-a11y": "node accessibility-package/cli.js --dry-run"
69
+ }
70
+ }
71
+ ```
72
+
73
+ ## 📊 Kết quả Demo
74
+
75
+ Với file demo, tool đã tìm và sửa:
76
+
77
+ - **16 issues** tổng cộng
78
+ - **1 lang attribute** missing
79
+ - **3 alt attributes** missing/empty
80
+ - **12 role attributes** missing
81
+
82
+ ## ⚙️ Configuration
83
+
84
+ ```javascript
85
+ {
86
+ language: 'ja', // 'ja', 'en', 'vi', 'zh', etc.
87
+ backupFiles: true, // Tạo .backup files
88
+ dryRun: false // Preview mode
89
+ }
90
+ ```
91
+
92
+ ## 🎨 Before/After Example
93
+
94
+ ### Before:
95
+
96
+ ```html
97
+ <html>
98
+ <img src="logo.png" />
99
+ <a href="/about">About</a>
100
+ <button onclick="submit()">Submit</button>
101
+ </html>
102
+ ```
103
+
104
+ ### After:
105
+
106
+ ```html
107
+ <html lang="ja">
108
+ <img src="logo.png" alt="ロゴ" role="img" />
109
+ <a href="/about" role="link">About</a>
110
+ <button onclick="submit()" role="button">Submit</button>
111
+ </html>
112
+ ```
113
+
114
+ ## 🔧 Customization
115
+
116
+ ### Thay đổi alt text generation
117
+
118
+ Sửa method `generateAltText()` trong `lib/fixer.js`
119
+
120
+ ### Thêm role rules mới
121
+
122
+ Sửa method `fixRoleAttributesInContent()` trong `lib/fixer.js`
123
+
124
+ ### Thay đổi ngôn ngữ
125
+
126
+ Set `language` parameter trong config
127
+
128
+ ## 📈 Performance
129
+
130
+ - ✅ Xử lý hàng trăm files trong vài giây
131
+ - ✅ Memory efficient
132
+ - ✅ Backup tự động
133
+ - ✅ Error handling tốt
134
+
135
+ ## 🛡️ Safety Features
136
+
137
+ - ✅ Dry run mode để preview
138
+ - ✅ Automatic backups (.backup files)
139
+ - ✅ Duplicate attribute prevention
140
+ - ✅ Error handling và logging
141
+
142
+ ## 📋 Checklist sử dụng
143
+
144
+ 1. [ ] Copy package vào dự án
145
+ 2. [ ] `npm install` dependencies
146
+ 3. [ ] Backup code (git commit)
147
+ 4. [ ] Test với `--dry-run`
148
+ 5. [ ] Chạy tool
149
+ 6. [ ] Review kết quả
150
+ 7. [ ] Commit changes
151
+
152
+ ## 🎯 Use Cases
153
+
154
+ ### Dự án mới
155
+
156
+ ```bash
157
+ node accessibility-package/cli.js ./src
158
+ ```
159
+
160
+ ### Dự án có sẵn
161
+
162
+ ```bash
163
+ node accessibility-package/cli.js --dry-run ./public
164
+ # Review results, then:
165
+ node accessibility-package/cli.js ./public
166
+ ```
167
+
168
+ ### CI/CD Integration
169
+
170
+ ```bash
171
+ # In build script
172
+ node accessibility-package/cli.js --no-backup ./dist
173
+ ```
174
+
175
+ ## 📞 Support
176
+
177
+ - 📖 Đọc [README.md](./README.md) để biết chi tiết
178
+ - 🚀 Xem [QUICK_START.md](./QUICK_START.md) để bắt đầu nhanh
179
+ - 💡 Chạy [example.js](./example.js) để xem demos
180
+ - ❓ Chạy `node cli.js --help` để xem options
181
+
182
+ ## 🎉 Kết luận
183
+
184
+ Package này giúp bạn:
185
+
186
+ - ⚡ **Tiết kiệm thời gian**: Tự động fix thay vì manual
187
+ - 🎯 **Cải thiện accessibility**: Tuân thủ WCAG guidelines
188
+ - 🛡️ **An toàn**: Backup và preview trước khi apply
189
+ - 🔧 **Linh hoạt**: Dễ customize và integrate
190
+
191
+ **Ready to make your website more accessible! 🌟**
package/QUICK_START.md ADDED
@@ -0,0 +1,137 @@
1
+ # 🚀 Quick Start Guide
2
+
3
+ Hướng dẫn nhanh để sử dụng Accessibility Fixer trong 5 phút.
4
+
5
+ ## ⚡ Cài đặt nhanh
6
+
7
+ ```bash
8
+ # 1. Copy package vào dự án
9
+ cp -r accessibility-package /path/to/your/project/
10
+
11
+ # 2. Cài đặt dependencies
12
+ cd your-project/accessibility-package
13
+ npm install
14
+
15
+ # 3. Chạy ngay!
16
+ node cli.js
17
+ ```
18
+
19
+ ## 🎯 Sử dụng cơ bản
20
+
21
+ ### Cách 1: CLI (Đơn giản nhất)
22
+
23
+ ```bash
24
+ # Fix toàn bộ dự án (current directory)
25
+ node accessibility-package/cli.js
26
+
27
+ # Fix thư mục cụ thể
28
+ node accessibility-package/cli.js ./src
29
+
30
+ # Preview trước khi fix
31
+ node accessibility-package/cli.js --dry-run
32
+
33
+ # Fix với ngôn ngữ khác
34
+ node accessibility-package/cli.js -l en ./dist
35
+ ```
36
+
37
+ ### Cách 2: Node.js Script
38
+
39
+ Tạo file `fix.js`:
40
+
41
+ ```javascript
42
+ const AccessibilityFixer = require('./accessibility-package/lib/fixer.js');
43
+
44
+ const fixer = new AccessibilityFixer({
45
+ language: 'ja', // Thay đổi theo dự án
46
+ backupFiles: true,
47
+ dryRun: false
48
+ });
49
+
50
+ async function fix() {
51
+ await fixer.fixHtmlLang('.');
52
+ await fixer.fixEmptyAltAttributes('.');
53
+ await fixer.fixRoleAttributes('.');
54
+ console.log('✅ Done!');
55
+ }
56
+
57
+ fix();
58
+ ```
59
+
60
+ Chạy: `node fix.js`
61
+
62
+ ## 📋 Checklist nhanh
63
+
64
+ - [ ] Copy package vào dự án
65
+ - [ ] `npm install` trong thư mục package
66
+ - [ ] Backup code (git commit)
67
+ - [ ] Chạy `--dry-run` để preview
68
+ - [ ] Chạy tool để fix
69
+ - [ ] Kiểm tra kết quả
70
+ - [ ] Commit changes
71
+
72
+ ## 🎨 Kết quả mong đợi
73
+
74
+ ### Trước:
75
+ ```html
76
+ <html>
77
+ <body>
78
+ <img src="logo.png">
79
+ <a href="/about">About</a>
80
+ <button onclick="submit()">Submit</button>
81
+ </body>
82
+ </html>
83
+ ```
84
+
85
+ ### Sau:
86
+ ```html
87
+ <html lang="ja">
88
+ <body>
89
+ <img src="logo.png" alt="ロゴ" role="img">
90
+ <a href="/about" role="link">About</a>
91
+ <button onclick="submit()" role="button">Submit</button>
92
+ </body>
93
+ </html>
94
+ ```
95
+
96
+ ## 🔧 Tùy chỉnh nhanh
97
+
98
+ ### Thay đổi ngôn ngữ
99
+ ```javascript
100
+ // Trong config
101
+ language: 'en' // 'ja', 'vi', 'zh', etc.
102
+ ```
103
+
104
+ ### Không tạo backup
105
+ ```bash
106
+ node cli.js --no-backup
107
+ ```
108
+
109
+ ### Chỉ preview
110
+ ```bash
111
+ node cli.js --dry-run
112
+ ```
113
+
114
+ ## ❓ Troubleshooting
115
+
116
+ **Lỗi "Cannot find module"**
117
+ ```bash
118
+ cd accessibility-package && npm install
119
+ ```
120
+
121
+ **Duplicate attributes**
122
+ - Tool tự động tránh duplicate
123
+ - Nếu có, chạy lại tool sẽ tự clean up
124
+
125
+ **Performance chậm**
126
+ - Chạy từng thư mục nhỏ
127
+ - Exclude node_modules
128
+
129
+ ## 📞 Cần trợ giúp?
130
+
131
+ 1. Đọc [README.md](./README.md) đầy đủ
132
+ 2. Xem [example.js](./example.js)
133
+ 3. Chạy `node cli.js --help`
134
+
135
+ ---
136
+
137
+ **Chúc bạn coding vui vẻ! 🎉**
package/README.md ADDED
@@ -0,0 +1,305 @@
1
+ # GBU Accessibility Package
2
+
3
+ [![npm version](https://badge.fury.io/js/gbu-accessibility-package.svg)](https://badge.fury.io/js/gbu-accessibility-package)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Một công cụ tự động sửa các vấn đề accessibility phổ biến trong HTML, bao gồm alt attributes, lang attributes, và role attributes với khả năng phân tích context thông minh.
7
+
8
+ ## 🚀 Tính năng
9
+
10
+ - ✅ **Alt Attributes**: Tự động thêm alt text thông minh cho images
11
+ - ✅ **Lang Attributes**: Thêm lang attribute cho thẻ `<html>`
12
+ - ✅ **Role Attributes**: Thêm role attributes cho các elements
13
+ - `role="img"` cho tất cả thẻ `<img>`
14
+ - `role="link"` cho thẻ `<a>`
15
+ - `role="button"` cho elements có onclick
16
+ - `role="menubar"` và `role="menuitem"` cho navigation lists
17
+ - ✅ **Context-aware**: Phân tích nội dung xung quanh để tạo alt text phù hợp
18
+ - ✅ **Backup tự động**: Tạo backup files trước khi sửa
19
+ - ✅ **Dry run mode**: Xem preview trước khi apply changes
20
+
21
+ ## 📦 Cài đặt
22
+
23
+ ### NPM Install (Khuyến nghị)
24
+
25
+ ```bash
26
+ # Cài đặt global
27
+ npm install -g gbu-accessibility-package
28
+
29
+ # Hoặc cài đặt local cho dự án
30
+ npm install gbu-accessibility-package --save-dev
31
+ ```
32
+
33
+ ### Yarn Install
34
+
35
+ ```bash
36
+ # Global
37
+ yarn global add gbu-accessibility-package
38
+
39
+ # Local
40
+ yarn add gbu-accessibility-package --dev
41
+ ```
42
+
43
+ ## 🛠️ Sử dụng
44
+
45
+ ### Cách 1: Sử dụng CLI (Global Install)
46
+
47
+ ```bash
48
+ # Sau khi cài đặt global
49
+ gbu-a11y [options] [directory]
50
+
51
+ # Hoặc
52
+ accessibility-fixer [options] [directory]
53
+ ```
54
+
55
+ ### Cách 1b: CLI (Local Install)
56
+
57
+ ```bash
58
+ # Chạy từ node_modules
59
+ npx gbu-a11y [options] [directory]
60
+
61
+ # Hoặc thêm vào package.json scripts
62
+ {
63
+ "scripts": {
64
+ "fix-a11y": "gbu-a11y",
65
+ "preview-a11y": "gbu-a11y --dry-run"
66
+ }
67
+ }
68
+ ```
69
+
70
+ ### Cách 2: Sử dụng trong Node.js
71
+
72
+ ```javascript
73
+ const AccessibilityFixer = require('gbu-accessibility-package');
74
+
75
+ // Tạo instance với config
76
+ const fixer = new AccessibilityFixer({
77
+ language: 'ja', // Ngôn ngữ cho lang attribute
78
+ backupFiles: true, // Tạo backup files
79
+ dryRun: false // false = apply changes, true = preview only
80
+ });
81
+
82
+ // Sử dụng các methods
83
+ async function fixAccessibility() {
84
+ // Fix lang attributes
85
+ const langResults = await fixer.fixHtmlLang('.');
86
+
87
+ // Fix alt attributes
88
+ const altResults = await fixer.fixEmptyAltAttributes('.');
89
+
90
+ // Fix role attributes
91
+ const roleResults = await fixer.fixRoleAttributes('.');
92
+
93
+ console.log('Hoàn thành!');
94
+ }
95
+
96
+ fixAccessibility();
97
+ ```
98
+
99
+ ### Cách 3: Script nhanh
100
+
101
+ Tạo file `fix-accessibility.js` trong dự án:
102
+
103
+ ```javascript
104
+ const AccessibilityFixer = require('gbu-accessibility-package');
105
+
106
+ const fixer = new AccessibilityFixer({
107
+ language: 'ja', // Thay đổi theo ngôn ngữ dự án
108
+ backupFiles: true,
109
+ dryRun: false
110
+ });
111
+
112
+ async function fixAll() {
113
+ console.log('🚀 Bắt đầu fix accessibility...');
114
+
115
+ // Fix tất cả issues
116
+ await fixer.fixHtmlLang('.');
117
+ await fixer.fixEmptyAltAttributes('.');
118
+ await fixer.fixRoleAttributes('.');
119
+
120
+ console.log('✅ Hoàn thành!');
121
+ }
122
+
123
+ fixAll();
124
+ ```
125
+
126
+ Chạy script:
127
+ ```bash
128
+ node fix-accessibility.js
129
+ ```
130
+
131
+ ## ⚙️ Configuration Options
132
+
133
+ ```javascript
134
+ const config = {
135
+ language: 'ja', // Lang attribute value ('ja', 'en', 'vi', etc.)
136
+ backupFiles: true, // Tạo .backup files
137
+ dryRun: false // true = chỉ preview, false = apply changes
138
+ };
139
+
140
+ const fixer = new AccessibilityFixer(config);
141
+ ```
142
+
143
+ ## 📋 Các Methods có sẵn
144
+
145
+ ### 1. fixHtmlLang(directory)
146
+ Thêm lang attribute cho thẻ `<html>`
147
+
148
+ ```javascript
149
+ const results = await fixer.fixHtmlLang('./src');
150
+ ```
151
+
152
+ ### 2. fixEmptyAltAttributes(directory)
153
+ Sửa missing/empty alt attributes cho images
154
+
155
+ ```javascript
156
+ const results = await fixer.fixEmptyAltAttributes('./src');
157
+ ```
158
+
159
+ ### 3. fixRoleAttributes(directory)
160
+ Thêm role attributes cho các elements
161
+
162
+ ```javascript
163
+ const results = await fixer.fixRoleAttributes('./src');
164
+ ```
165
+
166
+ ### 4. addMainLandmarks(directory)
167
+ Phát hiện và suggest main landmarks
168
+
169
+ ```javascript
170
+ const suggestions = await fixer.addMainLandmarks('./src');
171
+ ```
172
+
173
+ ## 🎯 Ví dụ kết quả
174
+
175
+ ### Alt Attributes
176
+ ```html
177
+ <!-- Trước -->
178
+ <img src="logo.png">
179
+ <img src="icon.png" alt="">
180
+
181
+ <!-- Sau -->
182
+ <img src="logo.png" alt="ロゴ">
183
+ <img src="icon.png" alt="アイコン">
184
+ ```
185
+
186
+ ### Role Attributes
187
+ ```html
188
+ <!-- Trước -->
189
+ <img src="photo.jpg" alt="Beautiful sunset">
190
+ <a href="/about">About Us</a>
191
+ <button onclick="submit()">Submit</button>
192
+
193
+ <!-- Sau -->
194
+ <img src="photo.jpg" alt="Beautiful sunset" role="img">
195
+ <a href="/about" role="link">About Us</a>
196
+ <button onclick="submit()" role="button">Submit</button>
197
+ ```
198
+
199
+ ### Lang Attributes
200
+ ```html
201
+ <!-- Trước -->
202
+ <html>
203
+
204
+ <!-- Sau -->
205
+ <html lang="ja">
206
+ ```
207
+
208
+ ## 🔧 Customization
209
+
210
+ ### Thay đổi ngôn ngữ cho alt text
211
+
212
+ Sửa method `generateAltText` trong `lib/fixer.js`:
213
+
214
+ ```javascript
215
+ generateAltText(imgTag, htmlContent = '', imgIndex = 0) {
216
+ // Thay đổi các text này theo ngôn ngữ dự án
217
+ if (srcValue.includes('logo')) {
218
+ return 'Logo'; // Thay vì 'ロゴ'
219
+ } else if (srcValue.includes('icon')) {
220
+ return 'Icon'; // Thay vì 'アイコン'
221
+ }
222
+ // ... thêm các cases khác
223
+ }
224
+ ```
225
+
226
+ ### Thêm role rules mới
227
+
228
+ Sửa method `fixRoleAttributesInContent` để thêm rules:
229
+
230
+ ```javascript
231
+ // Ví dụ: thêm role cho form elements
232
+ fixed = fixed.replace(
233
+ /<form([^>]*)(?!.*role\s*=)([^>]*>)/gi,
234
+ '<form$1 role="form"$2'
235
+ );
236
+ ```
237
+
238
+ ## 🚨 Lưu ý quan trọng
239
+
240
+ 1. **Backup**: Luôn tạo backup trước khi chạy tool
241
+ 2. **Test**: Chạy với `dryRun: true` trước để xem preview
242
+ 3. **Review**: Kiểm tra kết quả sau khi chạy
243
+ 4. **Git**: Commit code trước khi chạy tool
244
+
245
+ ## 📊 Monitoring Results
246
+
247
+ Tool sẽ hiển thị:
248
+ - Số files được xử lý
249
+ - Số issues được tìm thấy và sửa
250
+ - Chi tiết từng file
251
+ - Thống kê tổng quan
252
+
253
+ ```
254
+ 📁 index.html:
255
+ 🖼️ Missing role: Image 1 should have role="img"
256
+ 🔗 Missing role: Anchor 1 should have role="link"
257
+ 🖼️ Added role="img" to image element
258
+ 🔗 Added role="link" to anchor element
259
+ ✅ Fixed role attributes in: index.html
260
+
261
+ 📊 Summary: Found 245 role attribute issues across 50 files
262
+ ```
263
+
264
+ ## 🛠️ Troubleshooting
265
+
266
+ ### Lỗi "Cannot find module"
267
+ ```bash
268
+ cd accessibility-package
269
+ npm install
270
+ ```
271
+
272
+ ### Duplicate role attributes
273
+ Chạy cleanup script:
274
+ ```javascript
275
+ // Tạo file cleanup.js
276
+ const fs = require('fs');
277
+ const path = require('path');
278
+
279
+ async function cleanup() {
280
+ // Code cleanup duplicate roles
281
+ const content = await fs.promises.readFile('file.html', 'utf8');
282
+ const fixed = content.replace(/role="([^"]+)"(\s+role="\1")+/g, 'role="$1"');
283
+ await fs.promises.writeFile('file.html', fixed);
284
+ }
285
+ ```
286
+
287
+ ### Performance với project lớn
288
+ - Chạy từng thư mục con
289
+ - Sử dụng `dryRun: true` để test trước
290
+ - Exclude thư mục không cần thiết
291
+
292
+ ## 📝 License
293
+
294
+ MIT License - Tự do sử dụng cho mọi dự án.
295
+
296
+ ## 🤝 Contributing
297
+
298
+ 1. Fork repository
299
+ 2. Tạo feature branch
300
+ 3. Commit changes
301
+ 4. Tạo Pull Request
302
+
303
+ ---
304
+
305
+ **Happy coding! 🚀**