gbu-accessibility-package 3.8.8 → 3.8.9

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.
Files changed (2) hide show
  1. package/lib/fixer.js +179 -18
  2. package/package.json +1 -1
package/lib/fixer.js CHANGED
@@ -5841,7 +5841,7 @@ class AccessibilityFixer {
5841
5841
  return referencedFiles;
5842
5842
  }
5843
5843
 
5844
- // Find HTML and CSS/SCSS files to scan for references
5844
+ // Find HTML, CSS/SCSS, JS, and other source files to scan for references
5845
5845
  async findSourceFiles(directory) {
5846
5846
  const sourceFiles = [];
5847
5847
 
@@ -5858,9 +5858,11 @@ class AccessibilityFixer {
5858
5858
  await walk(filePath);
5859
5859
  }
5860
5860
  } else {
5861
- // Include HTML (main entry) and CSS/SCSS (for background images)
5861
+ // Include HTML, CSS/SCSS, JavaScript, TypeScript, Vue, PHP, JSON, XML, SVG
5862
5862
  const ext = path.extname(file).toLowerCase();
5863
- if (['.html', '.htm', '.css', '.scss', '.sass'].includes(ext)) {
5863
+ if (['.html', '.htm', '.css', '.scss', '.sass',
5864
+ '.js', '.jsx', '.ts', '.tsx', '.mjs',
5865
+ '.vue', '.php', '.json', '.xml', '.svg'].includes(ext)) {
5864
5866
  sourceFiles.push(filePath);
5865
5867
  }
5866
5868
  }
@@ -5874,7 +5876,7 @@ class AccessibilityFixer {
5874
5876
  return sourceFiles;
5875
5877
  }
5876
5878
 
5877
- // Enhanced reference extraction from HTML and CSS files
5879
+ // Enhanced reference extraction from HTML, CSS, JS, and other source files
5878
5880
  extractAllReferences(content, baseDir, sourceFile) {
5879
5881
  const references = [];
5880
5882
  const ext = path.extname(sourceFile).toLowerCase();
@@ -5888,6 +5890,31 @@ class AccessibilityFixer {
5888
5890
  // Extract from CSS/SCSS files - background images
5889
5891
  const cssRefs = this.extractCssReferences(content, baseDir);
5890
5892
  references.push(...cssRefs);
5893
+
5894
+ } else if (['.js', '.jsx', '.ts', '.tsx', '.mjs'].includes(ext)) {
5895
+ // Extract from JavaScript/TypeScript files - imports, requires, dynamic imports
5896
+ const jsRefs = this.extractJsReferences(content, baseDir);
5897
+ references.push(...jsRefs);
5898
+
5899
+ } else if (ext === '.vue') {
5900
+ // Extract from Vue files - template, script, and style sections
5901
+ const vueRefs = this.extractVueReferences(content, baseDir);
5902
+ references.push(...vueRefs);
5903
+
5904
+ } else if (ext === '.json') {
5905
+ // Extract from JSON files - config files, manifests
5906
+ const jsonRefs = this.extractJsonReferences(content, baseDir);
5907
+ references.push(...jsonRefs);
5908
+
5909
+ } else if (['.xml', '.svg'].includes(ext)) {
5910
+ // Extract from XML/SVG files - embedded references
5911
+ const xmlRefs = this.extractXmlReferences(content, baseDir);
5912
+ references.push(...xmlRefs);
5913
+
5914
+ } else if (ext === '.php') {
5915
+ // Extract from PHP files - mixed HTML/PHP content
5916
+ const phpRefs = this.extractPhpReferences(content, baseDir);
5917
+ references.push(...phpRefs);
5891
5918
  }
5892
5919
 
5893
5920
  return references;
@@ -5922,7 +5949,10 @@ class AccessibilityFixer {
5922
5949
  // Iframe
5923
5950
  /<iframe[^>]*src\s*=\s*["']([^"']+)["']/gi,
5924
5951
  // Meta (for icons)
5925
- /<meta[^>]*content\s*=\s*["']([^"']+\.(ico|png|jpg|jpeg|svg))["']/gi
5952
+ /<meta[^>]*content\s*=\s*["']([^"']+\.(ico|png|jpg|jpeg|svg))["']/gi,
5953
+ // Server Side Includes (SSI)
5954
+ /<!--#include\s+virtual\s*=\s*["']([^"']+)["']\s*-->/gi,
5955
+ /<!--#include\s+file\s*=\s*["']([^"']+)["']\s*-->/gi
5926
5956
  ];
5927
5957
 
5928
5958
  for (const pattern of patterns) {
@@ -5990,16 +6020,22 @@ class AccessibilityFixer {
5990
6020
  extractJsReferences(content, baseDir) {
5991
6021
  const references = [];
5992
6022
 
5993
- // JavaScript patterns for file references
6023
+ // JavaScript/TypeScript patterns for file references
5994
6024
  const patterns = [
5995
- // require() calls
5996
- /require\s*\(\s*["']([^"']+)["']\s*\)/gi,
5997
- // import statements
6025
+ // ES6 import statements
5998
6026
  /import\s+.*?from\s+["']([^"']+)["']/gi,
5999
- // fetch() calls with local files
6000
- /fetch\s*\(\s*["']([^"']*\.(html|css|js|json|xml))["']\s*\)/gi,
6027
+ // Dynamic imports
6028
+ /import\s*\(\s*["']([^"']+)["']\s*\)/gi,
6029
+ // CommonJS require
6030
+ /require\s*\(\s*["']([^"']+)["']\s*\)/gi,
6031
+ // fetch() API calls
6032
+ /fetch\s*\(\s*["']([^"']+)["']\s*\)/gi,
6001
6033
  // XMLHttpRequest
6002
- /\.open\s*\(\s*["'][^"']*["']\s*,\s*["']([^"']*\.(html|css|js|json|xml))["']/gi
6034
+ /\.open\s*\(\s*["'][^"']*["']\s*,\s*["']([^"']+)["']/gi,
6035
+ // String literals that look like paths
6036
+ /["']([^"']*\.(html|css|js|json|xml|jpg|jpeg|png|gif|svg|webp|ico))["']/gi,
6037
+ // Template literals with paths
6038
+ /`([^`]*\.(html|css|js|json|xml|jpg|jpeg|png|gif|svg|webp|ico))`/gi
6003
6039
  ];
6004
6040
 
6005
6041
  for (const pattern of patterns) {
@@ -6007,13 +6043,76 @@ class AccessibilityFixer {
6007
6043
  while ((match = pattern.exec(content)) !== null) {
6008
6044
  const url = match[1];
6009
6045
  if (this.isLocalFile(url)) {
6010
- // Store both original URL and normalized versions for matching
6011
- references.push(url);
6012
- if (url.startsWith('/')) {
6013
- references.push(url.substring(1)); // Remove leading slash
6046
+ this.addNormalizedUrl(references, url);
6047
+ }
6048
+ }
6049
+ }
6050
+
6051
+ return references;
6052
+ }
6053
+
6054
+ extractVueReferences(content, baseDir) {
6055
+ const references = [];
6056
+
6057
+ // Extract from template section (HTML-like)
6058
+ const templateMatch = content.match(/<template[^>]*>([\s\S]*?)<\/template>/i);
6059
+ if (templateMatch) {
6060
+ const htmlRefs = this.extractHtmlReferences(templateMatch[1], baseDir);
6061
+ references.push(...htmlRefs);
6062
+ }
6063
+
6064
+ // Extract from script section (JS-like)
6065
+ const scriptMatch = content.match(/<script[^>]*>([\s\S]*?)<\/script>/i);
6066
+ if (scriptMatch) {
6067
+ const jsRefs = this.extractJsReferences(scriptMatch[1], baseDir);
6068
+ references.push(...jsRefs);
6069
+ }
6070
+
6071
+ // Extract from style section (CSS-like)
6072
+ const styleMatch = content.match(/<style[^>]*>([\s\S]*?)<\/style>/i);
6073
+ if (styleMatch) {
6074
+ const cssRefs = this.extractCssReferences(styleMatch[1], baseDir);
6075
+ references.push(...cssRefs);
6076
+ }
6077
+
6078
+ return references;
6079
+ }
6080
+
6081
+ extractJsonReferences(content, baseDir) {
6082
+ const references = [];
6083
+
6084
+ try {
6085
+ // Parse JSON and look for string values that might be file paths
6086
+ const data = JSON.parse(content);
6087
+
6088
+ const findPaths = (obj) => {
6089
+ if (typeof obj === 'string') {
6090
+ // Check if string looks like a file path
6091
+ if (/\.(html|css|js|json|xml|jpg|jpeg|png|gif|svg|webp|ico)$/i.test(obj)) {
6092
+ if (this.isLocalFile(obj)) {
6093
+ this.addNormalizedUrl(references, obj);
6094
+ }
6014
6095
  }
6015
- if (!url.startsWith('./') && !url.startsWith('/')) {
6016
- references.push('./' + url); // Add leading ./
6096
+ } else if (Array.isArray(obj)) {
6097
+ obj.forEach(item => findPaths(item));
6098
+ } else if (obj && typeof obj === 'object') {
6099
+ Object.values(obj).forEach(value => findPaths(value));
6100
+ }
6101
+ };
6102
+
6103
+ findPaths(data);
6104
+ } catch (error) {
6105
+ // If JSON parsing fails, try regex patterns
6106
+ const patterns = [
6107
+ /["']([^"']*\.(html|css|js|json|xml|jpg|jpeg|png|gif|svg|webp|ico))["']/gi
6108
+ ];
6109
+
6110
+ for (const pattern of patterns) {
6111
+ let match;
6112
+ while ((match = pattern.exec(content)) !== null) {
6113
+ const url = match[1];
6114
+ if (this.isLocalFile(url)) {
6115
+ this.addNormalizedUrl(references, url);
6017
6116
  }
6018
6117
  }
6019
6118
  }
@@ -6022,6 +6121,68 @@ class AccessibilityFixer {
6022
6121
  return references;
6023
6122
  }
6024
6123
 
6124
+ extractXmlReferences(content, baseDir) {
6125
+ const references = [];
6126
+
6127
+ // XML/SVG patterns for file references
6128
+ const patterns = [
6129
+ // href attributes
6130
+ /href\s*=\s*["']([^"']+)["']/gi,
6131
+ // src attributes
6132
+ /src\s*=\s*["']([^"']+)["']/gi,
6133
+ // xlink:href (SVG)
6134
+ /xlink:href\s*=\s*["']([^"']+)["']/gi,
6135
+ // file attributes
6136
+ /file\s*=\s*["']([^"']+)["']/gi,
6137
+ // path attributes with file extensions
6138
+ /path\s*=\s*["']([^"']*\.(html|css|js|jpg|jpeg|png|gif|svg))["']/gi
6139
+ ];
6140
+
6141
+ for (const pattern of patterns) {
6142
+ let match;
6143
+ while ((match = pattern.exec(content)) !== null) {
6144
+ const url = match[1];
6145
+ if (this.isLocalFile(url)) {
6146
+ this.addNormalizedUrl(references, url);
6147
+ }
6148
+ }
6149
+ }
6150
+
6151
+ return references;
6152
+ }
6153
+
6154
+ extractPhpReferences(content, baseDir) {
6155
+ const references = [];
6156
+
6157
+ // PHP can contain HTML, so extract HTML references first
6158
+ const htmlRefs = this.extractHtmlReferences(content, baseDir);
6159
+ references.push(...htmlRefs);
6160
+
6161
+ // PHP-specific patterns
6162
+ const patterns = [
6163
+ // include/require statements
6164
+ /(?:include|require|include_once|require_once)\s*\(\s*["']([^"']+)["']\s*\)/gi,
6165
+ // file_get_contents
6166
+ /file_get_contents\s*\(\s*["']([^"']+)["']\s*\)/gi,
6167
+ // readfile
6168
+ /readfile\s*\(\s*["']([^"']+)["']\s*\)/gi,
6169
+ // fopen
6170
+ /fopen\s*\(\s*["']([^"']+)["']\s*,/gi
6171
+ ];
6172
+
6173
+ for (const pattern of patterns) {
6174
+ let match;
6175
+ while ((match = pattern.exec(content)) !== null) {
6176
+ const url = match[1];
6177
+ if (this.isLocalFile(url)) {
6178
+ this.addNormalizedUrl(references, url);
6179
+ }
6180
+ }
6181
+ }
6182
+
6183
+ return references;
6184
+ }
6185
+
6025
6186
  async findCssFiles(directory) {
6026
6187
  const files = [];
6027
6188
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gbu-accessibility-package",
3
- "version": "3.8.8",
3
+ "version": "3.8.9",
4
4
  "description": "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 analysis, broken external links detection, and missing local resources detection. Covers major axe DevTools issues with individual fix modes.",
5
5
  "main": "index.js",
6
6
  "bin": {