@atlaskit/ads-mcp 0.2.5 → 0.4.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +57 -1
  3. package/dist/cjs/index.js +16 -5
  4. package/dist/cjs/instructions.js +1 -1
  5. package/dist/cjs/tools/analyze-accessibility/index.js +483 -0
  6. package/dist/cjs/tools/get-accessibility-guidelines/index.js +204 -0
  7. package/dist/cjs/tools/{get-icons → get-all-icons}/index.js +6 -6
  8. package/dist/cjs/tools/{get-tokens → get-all-tokens}/index.js +7 -8
  9. package/dist/cjs/tools/search-icons/index.js +138 -0
  10. package/dist/cjs/tools/search-tokens/index.js +106 -0
  11. package/dist/cjs/tools/suggest-accessibility-fixes/fixes.js +387 -0
  12. package/dist/cjs/tools/suggest-accessibility-fixes/index.js +185 -0
  13. package/dist/cjs/tools/suggest-accessibility-fixes/keywords.js +34 -0
  14. package/dist/es2019/index.js +16 -5
  15. package/dist/es2019/instructions.js +12 -1
  16. package/dist/es2019/tools/analyze-accessibility/index.js +457 -0
  17. package/dist/es2019/tools/get-accessibility-guidelines/index.js +312 -0
  18. package/dist/es2019/tools/{get-icons → get-all-icons}/index.js +4 -4
  19. package/dist/es2019/tools/get-all-tokens/index.js +34 -0
  20. package/dist/es2019/tools/search-icons/index.js +126 -0
  21. package/dist/es2019/tools/search-tokens/index.js +96 -0
  22. package/dist/es2019/tools/suggest-accessibility-fixes/fixes.js +705 -0
  23. package/dist/es2019/tools/suggest-accessibility-fixes/index.js +143 -0
  24. package/dist/es2019/tools/suggest-accessibility-fixes/keywords.js +28 -0
  25. package/dist/esm/index.js +16 -5
  26. package/dist/esm/instructions.js +1 -1
  27. package/dist/esm/tools/analyze-accessibility/index.js +476 -0
  28. package/dist/esm/tools/get-accessibility-guidelines/index.js +197 -0
  29. package/dist/esm/tools/{get-icons → get-all-icons}/index.js +5 -5
  30. package/dist/esm/tools/{get-tokens → get-all-tokens}/index.js +6 -7
  31. package/dist/esm/tools/search-icons/index.js +131 -0
  32. package/dist/esm/tools/search-tokens/index.js +99 -0
  33. package/dist/esm/tools/suggest-accessibility-fixes/fixes.js +381 -0
  34. package/dist/esm/tools/suggest-accessibility-fixes/index.js +178 -0
  35. package/dist/esm/tools/suggest-accessibility-fixes/keywords.js +28 -0
  36. package/dist/types/instructions.d.ts +1 -1
  37. package/dist/types/tools/analyze-accessibility/index.d.ts +56 -0
  38. package/dist/types/tools/get-accessibility-guidelines/index.d.ts +26 -0
  39. package/dist/{types-ts4.5/tools/get-tokens → types/tools/get-all-icons}/index.d.ts +2 -2
  40. package/dist/types/tools/{get-tokens → get-all-tokens}/index.d.ts +2 -2
  41. package/dist/types/tools/search-icons/index.d.ts +38 -0
  42. package/dist/types/tools/search-tokens/index.d.ts +38 -0
  43. package/dist/types/tools/suggest-accessibility-fixes/fixes.d.ts +17 -0
  44. package/dist/types/tools/suggest-accessibility-fixes/index.d.ts +28 -0
  45. package/dist/types/tools/suggest-accessibility-fixes/keywords.d.ts +12 -0
  46. package/dist/types-ts4.5/instructions.d.ts +1 -1
  47. package/dist/types-ts4.5/tools/analyze-accessibility/index.d.ts +56 -0
  48. package/dist/types-ts4.5/tools/get-accessibility-guidelines/index.d.ts +26 -0
  49. package/dist/types-ts4.5/tools/{get-icons → get-all-icons}/index.d.ts +2 -2
  50. package/dist/{types/tools/get-icons → types-ts4.5/tools/get-all-tokens}/index.d.ts +2 -2
  51. package/dist/types-ts4.5/tools/search-icons/index.d.ts +38 -0
  52. package/dist/types-ts4.5/tools/search-tokens/index.d.ts +38 -0
  53. package/dist/types-ts4.5/tools/suggest-accessibility-fixes/fixes.d.ts +17 -0
  54. package/dist/types-ts4.5/tools/suggest-accessibility-fixes/index.d.ts +28 -0
  55. package/dist/types-ts4.5/tools/suggest-accessibility-fixes/keywords.d.ts +12 -0
  56. package/package.json +10 -3
  57. package/dist/es2019/tools/get-tokens/index.js +0 -35
@@ -0,0 +1,476 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ import { AxePuppeteer } from '@axe-core/puppeteer';
8
+ import axe from 'axe-core';
9
+ import puppeteer from 'puppeteer';
10
+ import { z } from 'zod';
11
+ import { zodToJsonSchema } from 'zod-to-json-schema';
12
+ var inputSchema = z.object({
13
+ code: z.string().describe('React component code to analyze for accessibility'),
14
+ componentName: z.string().optional().describe('Name of the component being analyzed'),
15
+ context: z.string().optional().describe('Additional context about the component usage'),
16
+ includePatternAnalysis: z.boolean().optional().default(true).describe('Include pattern-based analysis in addition to axe-core')
17
+ });
18
+ export var listAnalyzeAccessibilityTool = {
19
+ name: 'analyze_accessibility',
20
+ description: "Analyze React component code for accessibility violations using axe-core and intelligently generate Atlassian Design System specific suggestions. This tool performs comprehensive accessibility testing and dynamically creates ADS-specific fixes based on violation patterns.\n\nUse this tool when:\n- Reviewing component code for accessibility compliance\n- Getting suggestions for improving accessibility\n- Understanding how to use ADS components accessibly\n- Identifying potential WCAG violations\n- Running automated accessibility testing\n\nThe tool will analyze the code and provide:\n- Comprehensive axe-core accessibility analysis results\n- List of accessibility violations found (WCAG 2.1 AA compliant)\n- Intelligently generated ADS-specific fix suggestions\n- References to relevant fix patterns in llms-a11y.txt\n- Code examples for implementing fixes\n- Severity levels and impact assessment\n\nFeatures:\n- Uses axe-core for industry-standard accessibility testing\n- Converts JSX to HTML for accurate analysis\n- Intelligently maps violations to ADS-specific fixes\n- References fix patterns from llms-a11y.txt documentation\n- Includes fallback pattern analysis if axe-core fails\n- Provides detailed violation descriptions and help text\n- Dynamically generates fix suggestions based on violation type",
21
+ annotations: {
22
+ title: 'Analyze Accessibility',
23
+ readOnlyHint: true,
24
+ destructiveHint: false,
25
+ idempotentHint: true,
26
+ openWorldHint: true
27
+ },
28
+ inputSchema: zodToJsonSchema(inputSchema)
29
+ };
30
+ var urlInputSchema = z.object({
31
+ url: z.string().describe('The URL to analyze for accessibility (e.g. http://localhost:9000)'),
32
+ componentName: z.string().optional().describe('Name of the component being analyzed'),
33
+ context: z.string().optional().describe('Additional context about the component usage'),
34
+ selector: z.string().optional().describe('CSS selector to target a specific element for analysis (e.g. "#my-form", ".component-class")')
35
+ });
36
+ export var listAnalyzeLocalhostAccessibilityTool = {
37
+ name: 'analyze_localhost_accessibility',
38
+ description: "Analyze a live web page (e.g. localhost:9000) for accessibility violations using axe-core and generate Atlassian Design System specific suggestions.\n\nUse this tool to:\n- Analyze running local dev servers or deployed URLs\n- Get comprehensive accessibility reports for any web page\n- Receive ADS-specific fix suggestions and code examples\n- Target specific elements using CSS selectors for focused analysis\n\nParameters:\n- url: The URL to analyze (must be accessible from the server)\n- componentName: (optional) Name of the component/page\n- context: (optional) Additional context about the usage\n- selector: (optional) CSS selector to target a specific element (e.g. \"#my-form\", \".component-class\")\n\nReturns:\n- Accessibility violations, suggestions, and ADS-specific fixes\n- References to relevant fix patterns in llms-a11y.txt\n- Code examples for implementing fixes\n- Severity levels and impact assessment\n",
39
+ annotations: {
40
+ title: 'Analyze Localhost Accessibility',
41
+ readOnlyHint: true,
42
+ destructiveHint: false,
43
+ idempotentHint: true,
44
+ openWorldHint: true
45
+ },
46
+ inputSchema: zodToJsonSchema(urlInputSchema)
47
+ };
48
+
49
+ // Common accessibility patterns to detect in code
50
+ var accessibilityPatterns = [{
51
+ pattern: /<button[^>]*>(?!.*aria-label|.*>.*<\/button>)/g,
52
+ violation: 'Button without accessible text',
53
+ severity: 'error',
54
+ suggestion: 'Use the suggest-accessibility-fixes tool for ADS Button solutions. Describe the issue as "button missing label", "empty button", or "button needs text".'
55
+ }, {
56
+ pattern: /<img[^>]*>(?!.*alt=)/g,
57
+ violation: 'Image without alt text',
58
+ severity: 'error',
59
+ suggestion: 'Use the suggest-accessibility-fixes tool for ADS Image solutions. Describe the issue as "image missing alt", "missing alt text", or "image accessibility".'
60
+ }, {
61
+ pattern: /<div[^>]*onClick[^>]*>/g,
62
+ violation: 'Clickable div without accessibility',
63
+ severity: 'warning',
64
+ suggestion: 'Use the suggest-accessibility-fixes tool for ADS solutions. Describe the issue as "clickable div", "interactive div", or "div with click handler".'
65
+ }, {
66
+ pattern: /color:\s*['"]#[0-9a-fA-F]{3,6}['"]/g,
67
+ violation: 'Hardcoded color values',
68
+ severity: 'warning',
69
+ suggestion: 'Use the suggest-accessibility-fixes tool for design token solutions. Describe the issue as "hardcoded colors", "hex colors", or "design tokens".'
70
+ }, {
71
+ pattern: /<input[^>]*>(?!.*id=)/g,
72
+ violation: 'Input without associated label',
73
+ severity: 'error',
74
+ suggestion: 'Use the suggest-accessibility-fixes tool for ADS form solutions. Describe the issue as "input missing label", "form field without label", or "unlabeled input".'
75
+ }, {
76
+ pattern: /<div[^>]*role="button"[^>]*>/g,
77
+ violation: 'Custom button without full accessibility',
78
+ severity: 'warning',
79
+ suggestion: 'Use the suggest-accessibility-fixes tool for ADS Button/Focusable solutions. Describe the issue as "custom button", "div with button role", or "interactive element".'
80
+ }, {
81
+ pattern: /style=\{[^}]*color[^}]*\}/g,
82
+ violation: 'Inline color styles',
83
+ severity: 'warning',
84
+ suggestion: 'Use the suggest-accessibility-fixes tool for design token solutions. Describe the issue as "inline styles", "hardcoded colors", or "color tokens".'
85
+ }];
86
+
87
+ // ADS accessibility guidelines reference
88
+ var adsGuidelines = {
89
+ buttons: {
90
+ title: 'Button Accessibility',
91
+ guidelines: ['Always provide accessible labels for buttons', 'Use Button component for standard interactions', 'Use Focusable component for custom interactive elements', 'Avoid disabled buttons with tooltips', 'Ensure focus indicators are visible']
92
+ },
93
+ forms: {
94
+ title: 'Form Accessibility',
95
+ guidelines: ['Use TextField component for consistent labeling', 'Associate labels with inputs using id and htmlFor', 'Provide clear error messages with aria-describedby', 'Use MessageWrapper for form validation announcements']
96
+ },
97
+ images: {
98
+ title: 'Image Accessibility',
99
+ guidelines: ['Use Image component with proper alt text', 'Keep alt text under 125 characters', 'Leave alt="" for decorative images', 'Describe the purpose, not just the content']
100
+ },
101
+ colors: {
102
+ title: 'Color and Contrast',
103
+ guidelines: ['Use design tokens for consistent contrast ratios', 'Never rely on color alone for information', 'Use color.text tokens for proper contrast', 'Test with high contrast mode']
104
+ }
105
+ };
106
+
107
+ // Helper function to map axe-core violations to ADS-specific fixes
108
+ function mapAxeViolationsToADSFixes(violations) {
109
+ return violations.map(function (violation) {
110
+ var adsFix = generateADSFixForViolation(violation);
111
+ return _objectSpread(_objectSpread({}, violation), {}, {
112
+ type: adsFix.title,
113
+ // Use the specific fix key that matches fixes.ts
114
+ adsFix: adsFix,
115
+ severity: violation.impact === 'critical' || violation.impact === 'serious' ? 'error' : 'warning'
116
+ });
117
+ });
118
+ }
119
+
120
+ // Helper function to provide ADS-specific guidance for axe-core violations
121
+ function generateADSFixForViolation(violation) {
122
+ var id = violation.id,
123
+ description = violation.description,
124
+ help = violation.help,
125
+ tags = violation.tags;
126
+
127
+ // Provide general guidance without trying to map to specific fixes.ts keys
128
+ var adsFix = "Use the suggest-accessibility-fixes tool to get specific ADS component solutions. Describe the issue using the violation details: \"".concat(help, "\" or in your own words (e.g., \"button has no text\", \"missing alt text\", \"form field needs label\").");
129
+ return {
130
+ title: help,
131
+ // Use axe-core's human-readable description
132
+ description: description,
133
+ adsFix: adsFix,
134
+ example: 'The suggest-accessibility-fixes tool provides detailed code examples and ADS component solutions',
135
+ violationId: id,
136
+ axeHelp: help,
137
+ tags: tags,
138
+ wcagTags: tags.filter(function (tag) {
139
+ return tag.startsWith('wcag');
140
+ }),
141
+ // Extract WCAG compliance info
142
+ reference: "https://atlassian.design/llms-a11y.txt",
143
+ recommendations: ['Use ADS components for better accessibility out of the box', 'Reference the suggest-accessibility-fixes tool for specific solutions', 'Test with keyboard navigation and screen readers', 'Use automated accessibility testing tools']
144
+ };
145
+ }
146
+ export var analyzeAccessibilityTool = /*#__PURE__*/function () {
147
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
148
+ var code, componentName, context, _params$includePatter, includePatternAnalysis, violations, suggestions, axeResults, _axeResults$violation, _axeResults$passes, _axeResults$incomplet, results, adsViolations, relevantGuidelines, summary;
149
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
150
+ while (1) switch (_context.prev = _context.next) {
151
+ case 0:
152
+ code = params.code, componentName = params.componentName, context = params.context, _params$includePatter = params.includePatternAnalysis, includePatternAnalysis = _params$includePatter === void 0 ? true : _params$includePatter;
153
+ violations = [];
154
+ suggestions = [];
155
+ axeResults = {};
156
+ _context.prev = 4;
157
+ _context.next = 7;
158
+ return axe.run({
159
+ fromFrames: ['iframe', 'html']
160
+ });
161
+ case 7:
162
+ results = _context.sent;
163
+ // Process axe-core results
164
+ if (results.violations && results.violations.length > 0) {
165
+ adsViolations = mapAxeViolationsToADSFixes(results.violations);
166
+ violations.push.apply(violations, _toConsumableArray(adsViolations));
167
+ axeResults.violations = results.violations;
168
+ axeResults.passes = results.passes;
169
+ axeResults.incomplete = results.incomplete;
170
+ }
171
+
172
+ // Include pattern-based analysis if requested
173
+ if (includePatternAnalysis) {
174
+ accessibilityPatterns.forEach(function (pattern) {
175
+ var matches = code.match(pattern.pattern);
176
+ if (matches) {
177
+ violations.push({
178
+ type: pattern.violation,
179
+ severity: pattern.severity,
180
+ count: matches.length,
181
+ suggestion: pattern.suggestion,
182
+ adsFix: 'Use the suggest-accessibility-fixes tool for specific ADS component solutions',
183
+ example: 'The suggest-accessibility-fixes tool provides detailed code examples',
184
+ source: 'pattern-analysis'
185
+ });
186
+ }
187
+ });
188
+ }
189
+
190
+ // Generate ADS-specific suggestions
191
+ if (violations.length > 0) {
192
+ suggestions.push({
193
+ title: 'Accessibility Improvements Needed',
194
+ description: "Found ".concat(violations.length, " accessibility issues in your code."),
195
+ violations: violations,
196
+ nextSteps: ['Review each violation and apply the suggested fixes', 'Use ADS components instead of custom implementations', 'Test with screen readers and keyboard navigation', 'Run automated accessibility tests']
197
+ });
198
+ }
199
+
200
+ // Provide relevant ADS guidelines
201
+ relevantGuidelines = [];
202
+ if (code.includes('button') || code.includes('onClick')) {
203
+ relevantGuidelines.push(adsGuidelines.buttons);
204
+ }
205
+ if (code.includes('input') || code.includes('form')) {
206
+ relevantGuidelines.push(adsGuidelines.forms);
207
+ }
208
+ if (code.includes('img') || code.includes('image')) {
209
+ relevantGuidelines.push(adsGuidelines.images);
210
+ }
211
+ if (code.includes('color') || code.includes('style')) {
212
+ relevantGuidelines.push(adsGuidelines.colors);
213
+ }
214
+
215
+ // Generate summary
216
+ summary = {
217
+ componentName: componentName || 'Unknown component',
218
+ totalViolations: violations.length,
219
+ severityBreakdown: {
220
+ error: violations.filter(function (v) {
221
+ return v.severity === 'error';
222
+ }).length,
223
+ warning: violations.filter(function (v) {
224
+ return v.severity === 'warning';
225
+ }).length
226
+ },
227
+ context: context || 'No additional context provided',
228
+ axeResults: {
229
+ violations: ((_axeResults$violation = axeResults.violations) === null || _axeResults$violation === void 0 ? void 0 : _axeResults$violation.length) || 0,
230
+ passes: ((_axeResults$passes = axeResults.passes) === null || _axeResults$passes === void 0 ? void 0 : _axeResults$passes.length) || 0,
231
+ incomplete: ((_axeResults$incomplet = axeResults.incomplete) === null || _axeResults$incomplet === void 0 ? void 0 : _axeResults$incomplet.length) || 0
232
+ }
233
+ };
234
+ return _context.abrupt("return", {
235
+ content: [{
236
+ type: 'text',
237
+ text: JSON.stringify({
238
+ summary: summary,
239
+ violations: violations,
240
+ suggestions: suggestions,
241
+ relevantGuidelines: relevantGuidelines,
242
+ axeResults: axeResults,
243
+ recommendations: ['Use ADS components for better accessibility out of the box', 'Reference https://atlassian.design/llms-a11y.txt for detailed guidelines', 'Test with keyboard navigation and screen readers', 'Use automated accessibility testing tools']
244
+ }, null, 2)
245
+ }]
246
+ });
247
+ case 20:
248
+ _context.prev = 20;
249
+ _context.t0 = _context["catch"](4);
250
+ // Fallback to pattern-based analysis if axe-core fails
251
+ // console.warn('Axe-core analysis failed, falling back to pattern analysis:', error);
252
+
253
+ // Run pattern analysis as fallback
254
+ accessibilityPatterns.forEach(function (pattern) {
255
+ var matches = code.match(pattern.pattern);
256
+ if (matches) {
257
+ violations.push({
258
+ type: pattern.violation,
259
+ severity: pattern.severity,
260
+ count: matches.length,
261
+ suggestion: pattern.suggestion,
262
+ adsFix: 'Use the suggest-accessibility-fixes tool for specific ADS component solutions',
263
+ example: 'The suggest-accessibility-fixes tool provides detailed code examples',
264
+ source: 'pattern-analysis-fallback'
265
+ });
266
+ }
267
+ });
268
+ return _context.abrupt("return", {
269
+ content: [{
270
+ type: 'text',
271
+ text: JSON.stringify({
272
+ summary: {
273
+ componentName: componentName || 'Unknown component',
274
+ totalViolations: violations.length,
275
+ severityBreakdown: {
276
+ error: violations.filter(function (v) {
277
+ return v.severity === 'error';
278
+ }).length,
279
+ warning: violations.filter(function (v) {
280
+ return v.severity === 'warning';
281
+ }).length
282
+ },
283
+ context: context || 'No additional context provided',
284
+ note: 'Analysis completed using pattern matching (axe-core analysis failed)'
285
+ },
286
+ violations: violations,
287
+ suggestions: violations.length > 0 ? [{
288
+ title: 'Accessibility Improvements Needed',
289
+ description: "Found ".concat(violations.length, " accessibility issues in your code."),
290
+ violations: violations,
291
+ nextSteps: ['Review each violation and apply the suggested fixes', 'Use ADS components instead of custom implementations', 'Test with screen readers and keyboard navigation', 'Run automated accessibility tests']
292
+ }] : [],
293
+ error: 'Axe-core analysis failed, used pattern-based analysis as fallback',
294
+ recommendations: ['Use ADS components for better accessibility out of the box', 'Reference https://atlassian.design/llms-a11y.txt for detailed guidelines', 'Test with keyboard navigation and screen readers', 'Use automated accessibility testing tools']
295
+ }, null, 2)
296
+ }]
297
+ });
298
+ case 24:
299
+ case "end":
300
+ return _context.stop();
301
+ }
302
+ }, _callee, null, [[4, 20]]);
303
+ }));
304
+ return function analyzeAccessibilityTool(_x) {
305
+ return _ref.apply(this, arguments);
306
+ };
307
+ }();
308
+ export var analyzeLocalhostAccessibilityTool = /*#__PURE__*/function () {
309
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
310
+ var url, componentName, context, selector, violations, suggestions, axeResults, browser, page, _axeResults$violation2, _axeResults$passes2, _axeResults$incomplet2, elementExists, availableElements, axePuppeteer, results, adsViolations, relevantGuidelines, summary;
311
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
312
+ while (1) switch (_context2.prev = _context2.next) {
313
+ case 0:
314
+ url = params.url, componentName = params.componentName, context = params.context, selector = params.selector;
315
+ violations = [];
316
+ suggestions = [];
317
+ axeResults = {};
318
+ _context2.next = 6;
319
+ return puppeteer.launch();
320
+ case 6:
321
+ browser = _context2.sent;
322
+ _context2.next = 9;
323
+ return browser.newPage();
324
+ case 9:
325
+ page = _context2.sent;
326
+ _context2.prev = 10;
327
+ _context2.next = 13;
328
+ return page.goto(url, {
329
+ waitUntil: 'networkidle0'
330
+ });
331
+ case 13:
332
+ if (!selector) {
333
+ _context2.next = 22;
334
+ break;
335
+ }
336
+ _context2.next = 16;
337
+ return page.$(selector);
338
+ case 16:
339
+ elementExists = _context2.sent;
340
+ if (elementExists) {
341
+ _context2.next = 22;
342
+ break;
343
+ }
344
+ _context2.next = 20;
345
+ return page.evaluate(function () {
346
+ var elements = Array.from(document.querySelectorAll('[id]'));
347
+ return elements.map(function (el) {
348
+ return "#".concat(el.id);
349
+ });
350
+ });
351
+ case 20:
352
+ availableElements = _context2.sent;
353
+ throw new Error("Element with selector \"".concat(selector, "\" not found on the page after waiting. Available elements: ").concat(availableElements.join(', ')));
354
+ case 22:
355
+ // Run axe-core accessibility analysis
356
+ axePuppeteer = new AxePuppeteer(page); // If selector is provided, analyze only that element
357
+ if (selector) {
358
+ axePuppeteer.include(selector);
359
+ }
360
+ _context2.next = 26;
361
+ return axePuppeteer.analyze();
362
+ case 26:
363
+ results = _context2.sent;
364
+ if (results.violations && results.violations.length > 0) {
365
+ adsViolations = mapAxeViolationsToADSFixes(results.violations);
366
+ violations.push.apply(violations, _toConsumableArray(adsViolations));
367
+ axeResults.violations = results.violations;
368
+ axeResults.passes = results.passes;
369
+ axeResults.incomplete = results.incomplete;
370
+ }
371
+
372
+ // Generate ADS-specific suggestions
373
+ if (violations.length > 0) {
374
+ suggestions.push({
375
+ title: 'Accessibility Improvements Needed',
376
+ description: "Found ".concat(violations.length, " accessibility issues in your code."),
377
+ violations: violations,
378
+ nextSteps: ['Review each violation and apply the suggested fixes', 'Use ADS components instead of custom implementations', 'Test with screen readers and keyboard navigation', 'Run automated accessibility tests']
379
+ });
380
+ }
381
+
382
+ // Provide relevant ADS guidelines
383
+ relevantGuidelines = [];
384
+ if (url.includes('button') || url.includes('onClick')) {
385
+ relevantGuidelines.push(adsGuidelines.buttons);
386
+ }
387
+ if (url.includes('input') || url.includes('form')) {
388
+ relevantGuidelines.push(adsGuidelines.forms);
389
+ }
390
+ if (url.includes('img') || url.includes('image')) {
391
+ relevantGuidelines.push(adsGuidelines.images);
392
+ }
393
+ if (url.includes('color') || url.includes('style')) {
394
+ relevantGuidelines.push(adsGuidelines.colors);
395
+ }
396
+
397
+ // Generate summary
398
+ summary = {
399
+ url: url,
400
+ selector: selector || 'Entire page analyzed',
401
+ componentName: componentName || 'Unknown component',
402
+ totalViolations: violations.length,
403
+ severityBreakdown: {
404
+ error: violations.filter(function (v) {
405
+ return v.severity === 'error';
406
+ }).length,
407
+ warning: violations.filter(function (v) {
408
+ return v.severity === 'warning';
409
+ }).length
410
+ },
411
+ context: context || 'No additional context provided',
412
+ axeResults: {
413
+ violations: ((_axeResults$violation2 = axeResults.violations) === null || _axeResults$violation2 === void 0 ? void 0 : _axeResults$violation2.length) || 0,
414
+ passes: ((_axeResults$passes2 = axeResults.passes) === null || _axeResults$passes2 === void 0 ? void 0 : _axeResults$passes2.length) || 0,
415
+ incomplete: ((_axeResults$incomplet2 = axeResults.incomplete) === null || _axeResults$incomplet2 === void 0 ? void 0 : _axeResults$incomplet2.length) || 0
416
+ }
417
+ };
418
+ _context2.next = 37;
419
+ return browser.close();
420
+ case 37:
421
+ return _context2.abrupt("return", {
422
+ content: [{
423
+ type: 'text',
424
+ text: JSON.stringify({
425
+ summary: summary,
426
+ violations: violations,
427
+ suggestions: suggestions,
428
+ relevantGuidelines: relevantGuidelines,
429
+ axeResults: axeResults,
430
+ recommendations: ['Use ADS components for better accessibility out of the box', 'Reference https://atlassian.design/llms-a11y.txt for detailed guidelines', 'Test with keyboard navigation and screen readers', 'Use automated accessibility testing tools']
431
+ }, null, 2)
432
+ }]
433
+ });
434
+ case 40:
435
+ _context2.prev = 40;
436
+ _context2.t0 = _context2["catch"](10);
437
+ _context2.next = 44;
438
+ return browser.close();
439
+ case 44:
440
+ return _context2.abrupt("return", {
441
+ content: [{
442
+ type: 'text',
443
+ text: JSON.stringify({
444
+ summary: {
445
+ url: url,
446
+ selector: selector || 'Entire page analyzed',
447
+ componentName: componentName || 'Unknown component',
448
+ totalViolations: violations.length,
449
+ severityBreakdown: {
450
+ error: violations.filter(function (v) {
451
+ return v.severity === 'error';
452
+ }).length,
453
+ warning: violations.filter(function (v) {
454
+ return v.severity === 'warning';
455
+ }).length
456
+ },
457
+ context: context || 'No additional context provided',
458
+ note: 'Analysis failed to run on the provided URL'
459
+ },
460
+ violations: violations,
461
+ suggestions: [],
462
+ error: String(_context2.t0),
463
+ recommendations: ['Use ADS components for better accessibility out of the box', 'Reference https://atlassian.design/llms-a11y.txt for detailed guidelines', 'Test with keyboard navigation and screen readers', 'Use automated accessibility testing tools']
464
+ }, null, 2)
465
+ }]
466
+ });
467
+ case 45:
468
+ case "end":
469
+ return _context2.stop();
470
+ }
471
+ }, _callee2, null, [[10, 40]]);
472
+ }));
473
+ return function analyzeLocalhostAccessibilityTool(_x2) {
474
+ return _ref2.apply(this, arguments);
475
+ };
476
+ }();