@fragments-sdk/cli 0.10.1 → 0.12.1

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 (223) hide show
  1. package/dist/ai-client-I6MDWNYA.js +21 -0
  2. package/dist/bin.js +292 -367
  3. package/dist/bin.js.map +1 -1
  4. package/dist/{chunk-PW7QTQA6.js → chunk-4OC7FTJB.js} +2 -2
  5. package/dist/{chunk-HRFUSSZI.js → chunk-AM4MRTMN.js} +2 -2
  6. package/dist/{chunk-5G3VZH43.js → chunk-GVDSFQ4E.js} +281 -351
  7. package/dist/chunk-GVDSFQ4E.js.map +1 -0
  8. package/dist/chunk-JJ2VRTBU.js +626 -0
  9. package/dist/chunk-JJ2VRTBU.js.map +1 -0
  10. package/dist/{chunk-D5PYOXEI.js → chunk-LVWFOLUZ.js} +148 -13
  11. package/dist/{chunk-D5PYOXEI.js.map → chunk-LVWFOLUZ.js.map} +1 -1
  12. package/dist/{chunk-WXSR2II7.js → chunk-OQKMEFOS.js} +58 -6
  13. package/dist/chunk-OQKMEFOS.js.map +1 -0
  14. package/dist/chunk-SXTKFDCR.js +104 -0
  15. package/dist/chunk-SXTKFDCR.js.map +1 -0
  16. package/dist/chunk-T5OMVL7E.js +443 -0
  17. package/dist/chunk-T5OMVL7E.js.map +1 -0
  18. package/dist/{chunk-ZM4ZQZWZ.js → chunk-TPWGL2XS.js} +39 -37
  19. package/dist/chunk-TPWGL2XS.js.map +1 -0
  20. package/dist/{chunk-OQO55NKV.js → chunk-WFS63PCW.js} +85 -11
  21. package/dist/chunk-WFS63PCW.js.map +1 -0
  22. package/dist/core/index.js +9 -1
  23. package/dist/{discovery-NEOY4MPN.js → discovery-ZJQSXF56.js} +3 -3
  24. package/dist/{generate-FBHSXR3D.js → generate-RJFS2JWA.js} +4 -4
  25. package/dist/index.js +7 -6
  26. package/dist/index.js.map +1 -1
  27. package/dist/init-ZSX3NRCZ.js +636 -0
  28. package/dist/init-ZSX3NRCZ.js.map +1 -0
  29. package/dist/mcp-bin.js +2 -2
  30. package/dist/{scan-CJF2DOQW.js → scan-3PMCJ4RB.js} +6 -6
  31. package/dist/scan-generate-SYU4PYZD.js +1115 -0
  32. package/dist/scan-generate-SYU4PYZD.js.map +1 -0
  33. package/dist/{service-TQYWY65E.js → service-VMGNJZ42.js} +3 -3
  34. package/dist/snapshot-XOISO2IS.js +139 -0
  35. package/dist/snapshot-XOISO2IS.js.map +1 -0
  36. package/dist/{static-viewer-NUBFPKWH.js → static-viewer-5GXH2MGE.js} +3 -3
  37. package/dist/static-viewer-5GXH2MGE.js.map +1 -0
  38. package/dist/{test-Z5LVO724.js → test-SI4NSHQX.js} +4 -4
  39. package/dist/{tokens-CE46OTMD.js → tokens-T6SIVUT5.js} +5 -5
  40. package/dist/{viewer-DNMNC5VS.js → viewer-7ZEAFBVN.js} +80 -58
  41. package/dist/viewer-7ZEAFBVN.js.map +1 -0
  42. package/package.json +6 -14
  43. package/src/ai-client.ts +156 -0
  44. package/src/bin.ts +74 -2
  45. package/src/build.ts +95 -33
  46. package/src/commands/__tests__/drift-sync.test.ts +252 -0
  47. package/src/commands/__tests__/scan-generate.test.ts +497 -45
  48. package/src/commands/enhance.ts +11 -35
  49. package/src/commands/init.ts +296 -193
  50. package/src/commands/scan-generate.ts +740 -139
  51. package/src/commands/scan.ts +37 -32
  52. package/src/commands/setup.ts +143 -52
  53. package/src/commands/snapshot.ts +197 -0
  54. package/src/commands/sync.ts +357 -0
  55. package/src/commands/validate.ts +43 -1
  56. package/src/core/component-extractor.test.ts +282 -0
  57. package/src/core/component-extractor.ts +1030 -0
  58. package/src/core/discovery.ts +93 -7
  59. package/src/service/enhance/props-extractor.ts +235 -13
  60. package/src/validators.ts +236 -0
  61. package/src/viewer/__tests__/viewer-integration.test.ts +85 -74
  62. package/src/viewer/server.ts +37 -22
  63. package/src/viewer/vite-plugin.ts +25 -9
  64. package/dist/chunk-5G3VZH43.js.map +0 -1
  65. package/dist/chunk-OQO55NKV.js.map +0 -1
  66. package/dist/chunk-WXSR2II7.js.map +0 -1
  67. package/dist/chunk-ZM4ZQZWZ.js.map +0 -1
  68. package/dist/init-NDQXUWDU.js +0 -796
  69. package/dist/init-NDQXUWDU.js.map +0 -1
  70. package/dist/scan-generate-SJAN5MVI.js +0 -691
  71. package/dist/scan-generate-SJAN5MVI.js.map +0 -1
  72. package/dist/viewer-DNMNC5VS.js.map +0 -1
  73. package/src/ai.ts +0 -266
  74. package/src/commands/init-framework.ts +0 -414
  75. package/src/mcp/bin.ts +0 -36
  76. package/src/migrate/bin.ts +0 -114
  77. package/src/theme/index.ts +0 -77
  78. package/src/viewer/__tests__/a11y-fixes.test.ts +0 -358
  79. package/src/viewer/__tests__/jsx-parser.test.ts +0 -502
  80. package/src/viewer/__tests__/render-utils.test.ts +0 -232
  81. package/src/viewer/__tests__/style-utils.test.ts +0 -404
  82. package/src/viewer/assets/fragments-logo.ts +0 -4
  83. package/src/viewer/assets/fragments_logo.png +0 -0
  84. package/src/viewer/bin.ts +0 -86
  85. package/src/viewer/cli/health.ts +0 -256
  86. package/src/viewer/cli/index.ts +0 -33
  87. package/src/viewer/cli/scan.ts +0 -124
  88. package/src/viewer/cli/utils.ts +0 -174
  89. package/src/viewer/components/AccessibilityPanel.tsx +0 -1457
  90. package/src/viewer/components/ActionCapture.tsx +0 -172
  91. package/src/viewer/components/ActionsPanel.tsx +0 -332
  92. package/src/viewer/components/AllVariantsPreview.tsx +0 -78
  93. package/src/viewer/components/App.tsx +0 -582
  94. package/src/viewer/components/BottomPanel.tsx +0 -288
  95. package/src/viewer/components/CodePanel.naming.test.tsx +0 -59
  96. package/src/viewer/components/CodePanel.tsx +0 -118
  97. package/src/viewer/components/CommandPalette.tsx +0 -392
  98. package/src/viewer/components/ComponentDocView.tsx +0 -164
  99. package/src/viewer/components/ComponentGraph.tsx +0 -380
  100. package/src/viewer/components/ComponentHeader.tsx +0 -88
  101. package/src/viewer/components/ContractPanel.tsx +0 -241
  102. package/src/viewer/components/EmptyVariantMessage.tsx +0 -54
  103. package/src/viewer/components/ErrorBoundary.tsx +0 -97
  104. package/src/viewer/components/FigmaEmbed.tsx +0 -238
  105. package/src/viewer/components/FragmentEditor.tsx +0 -525
  106. package/src/viewer/components/FragmentRenderer.tsx +0 -61
  107. package/src/viewer/components/HeaderSearch.tsx +0 -24
  108. package/src/viewer/components/HealthDashboard.tsx +0 -441
  109. package/src/viewer/components/HmrStatusIndicator.tsx +0 -61
  110. package/src/viewer/components/Icons.tsx +0 -479
  111. package/src/viewer/components/InteractionsPanel.tsx +0 -757
  112. package/src/viewer/components/IsolatedPreviewFrame.tsx +0 -346
  113. package/src/viewer/components/IsolatedRender.tsx +0 -113
  114. package/src/viewer/components/KeyboardShortcutsHelp.tsx +0 -53
  115. package/src/viewer/components/LandingPage.tsx +0 -421
  116. package/src/viewer/components/Layout.tsx +0 -27
  117. package/src/viewer/components/LeftSidebar.tsx +0 -472
  118. package/src/viewer/components/LoadErrorMessage.tsx +0 -102
  119. package/src/viewer/components/MultiViewportPreview.tsx +0 -522
  120. package/src/viewer/components/NoVariantsMessage.tsx +0 -59
  121. package/src/viewer/components/PanelShell.tsx +0 -161
  122. package/src/viewer/components/PerformancePanel.tsx +0 -304
  123. package/src/viewer/components/PreviewArea.tsx +0 -472
  124. package/src/viewer/components/PreviewAside.tsx +0 -168
  125. package/src/viewer/components/PreviewFrameHost.tsx +0 -303
  126. package/src/viewer/components/PreviewPane.tsx +0 -149
  127. package/src/viewer/components/PreviewToolbar.tsx +0 -80
  128. package/src/viewer/components/PropsEditor.tsx +0 -506
  129. package/src/viewer/components/PropsTable.tsx +0 -111
  130. package/src/viewer/components/RelationsSection.tsx +0 -88
  131. package/src/viewer/components/ResizablePanel.tsx +0 -271
  132. package/src/viewer/components/RightSidebar.tsx +0 -102
  133. package/src/viewer/components/RuntimeToolsRegistrar.tsx +0 -17
  134. package/src/viewer/components/ScreenshotButton.tsx +0 -90
  135. package/src/viewer/components/Sidebar.tsx +0 -169
  136. package/src/viewer/components/SkeletonLoader.tsx +0 -161
  137. package/src/viewer/components/ThemeProvider.tsx +0 -42
  138. package/src/viewer/components/Toast.tsx +0 -3
  139. package/src/viewer/components/TokenStylePanel.tsx +0 -699
  140. package/src/viewer/components/TopToolbar.tsx +0 -159
  141. package/src/viewer/components/UsageSection.tsx +0 -95
  142. package/src/viewer/components/VariantMatrix.tsx +0 -388
  143. package/src/viewer/components/VariantRenderer.tsx +0 -131
  144. package/src/viewer/components/VariantTabs.tsx +0 -40
  145. package/src/viewer/components/ViewerHeader.tsx +0 -69
  146. package/src/viewer/components/ViewerStateSync.tsx +0 -52
  147. package/src/viewer/components/ViewportSelector.tsx +0 -172
  148. package/src/viewer/components/WebMCPDevTools.tsx +0 -503
  149. package/src/viewer/components/WebMCPIntegration.tsx +0 -47
  150. package/src/viewer/components/WebMCPStatusIndicator.tsx +0 -60
  151. package/src/viewer/components/_future/CreatePage.tsx +0 -836
  152. package/src/viewer/components/viewer-utils.ts +0 -16
  153. package/src/viewer/composition-renderer.ts +0 -381
  154. package/src/viewer/constants/index.ts +0 -1
  155. package/src/viewer/constants/ui.ts +0 -166
  156. package/src/viewer/entry.tsx +0 -335
  157. package/src/viewer/hooks/index.ts +0 -2
  158. package/src/viewer/hooks/useA11yCache.ts +0 -383
  159. package/src/viewer/hooks/useA11yService.ts +0 -364
  160. package/src/viewer/hooks/useActions.ts +0 -138
  161. package/src/viewer/hooks/useAppState.ts +0 -147
  162. package/src/viewer/hooks/useCompiledFragments.ts +0 -42
  163. package/src/viewer/hooks/useFigmaIntegration.ts +0 -132
  164. package/src/viewer/hooks/useHmrStatus.ts +0 -109
  165. package/src/viewer/hooks/useKeyboardShortcuts.ts +0 -270
  166. package/src/viewer/hooks/usePreviewBridge.ts +0 -347
  167. package/src/viewer/hooks/useScrollSpy.ts +0 -78
  168. package/src/viewer/hooks/useUrlState.ts +0 -318
  169. package/src/viewer/hooks/useViewSettings.ts +0 -111
  170. package/src/viewer/index.html +0 -28
  171. package/src/viewer/intelligence/healthReport.ts +0 -505
  172. package/src/viewer/intelligence/styleDrift.ts +0 -340
  173. package/src/viewer/intelligence/usageScanner.ts +0 -309
  174. package/src/viewer/jsx-parser.ts +0 -486
  175. package/src/viewer/preview-frame-entry.tsx +0 -25
  176. package/src/viewer/preview-frame.html +0 -125
  177. package/src/viewer/public/favicon.ico +0 -0
  178. package/src/viewer/render-template.html +0 -68
  179. package/src/viewer/styles/globals.css +0 -278
  180. package/src/viewer/types/a11y.ts +0 -197
  181. package/src/viewer/utils/a11y-fixes.ts +0 -509
  182. package/src/viewer/utils/actionExport.ts +0 -372
  183. package/src/viewer/utils/colorSchemes.ts +0 -201
  184. package/src/viewer/utils/detectRelationships.ts +0 -256
  185. package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss +0 -10
  186. package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss.d.ts +0 -2
  187. package/src/viewer/vendor/shared/src/ComponentDocContent.tsx +0 -274
  188. package/src/viewer/vendor/shared/src/DocsHeaderBar.tsx +0 -129
  189. package/src/viewer/vendor/shared/src/DocsPageAsideHost.tsx +0 -89
  190. package/src/viewer/vendor/shared/src/DocsPageShell.tsx +0 -124
  191. package/src/viewer/vendor/shared/src/DocsSearchCommand.tsx +0 -99
  192. package/src/viewer/vendor/shared/src/DocsSidebarNav.tsx +0 -66
  193. package/src/viewer/vendor/shared/src/PropsTable.module.scss +0 -68
  194. package/src/viewer/vendor/shared/src/PropsTable.module.scss.d.ts +0 -2
  195. package/src/viewer/vendor/shared/src/PropsTable.tsx +0 -76
  196. package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss +0 -114
  197. package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss.d.ts +0 -2
  198. package/src/viewer/vendor/shared/src/VariantPreviewCard.tsx +0 -137
  199. package/src/viewer/vendor/shared/src/docs-data/index.ts +0 -32
  200. package/src/viewer/vendor/shared/src/docs-data/mcp-configs.ts +0 -72
  201. package/src/viewer/vendor/shared/src/docs-data/palettes.ts +0 -75
  202. package/src/viewer/vendor/shared/src/docs-data/setup-examples.ts +0 -55
  203. package/src/viewer/vendor/shared/src/docs-layout.scss +0 -28
  204. package/src/viewer/vendor/shared/src/docs-layout.scss.d.ts +0 -2
  205. package/src/viewer/vendor/shared/src/index.ts +0 -34
  206. package/src/viewer/vendor/shared/src/types.ts +0 -53
  207. package/src/viewer/webmcp/__tests__/analytics.test.ts +0 -108
  208. package/src/viewer/webmcp/analytics.ts +0 -165
  209. package/src/viewer/webmcp/index.ts +0 -3
  210. package/src/viewer/webmcp/posthog-bridge.ts +0 -39
  211. package/src/viewer/webmcp/runtime-tools.ts +0 -152
  212. package/src/viewer/webmcp/scan-utils.ts +0 -135
  213. package/src/viewer/webmcp/use-tool-analytics.ts +0 -69
  214. package/src/viewer/webmcp/viewer-state.ts +0 -45
  215. /package/dist/{discovery-NEOY4MPN.js.map → ai-client-I6MDWNYA.js.map} +0 -0
  216. /package/dist/{chunk-PW7QTQA6.js.map → chunk-4OC7FTJB.js.map} +0 -0
  217. /package/dist/{chunk-HRFUSSZI.js.map → chunk-AM4MRTMN.js.map} +0 -0
  218. /package/dist/{scan-CJF2DOQW.js.map → discovery-ZJQSXF56.js.map} +0 -0
  219. /package/dist/{generate-FBHSXR3D.js.map → generate-RJFS2JWA.js.map} +0 -0
  220. /package/dist/{service-TQYWY65E.js.map → scan-3PMCJ4RB.js.map} +0 -0
  221. /package/dist/{static-viewer-NUBFPKWH.js.map → service-VMGNJZ42.js.map} +0 -0
  222. /package/dist/{test-Z5LVO724.js.map → test-SI4NSHQX.js.map} +0 -0
  223. /package/dist/{tokens-CE46OTMD.js.map → tokens-T6SIVUT5.js.map} +0 -0
@@ -1,509 +0,0 @@
1
- /**
2
- * A11y Fixes - Static Fix Generators
3
- *
4
- * Rule-specific fix suggestions without AI. Provides:
5
- * - "Why it matters" explanations
6
- * - Before/after code examples
7
- * - WCAG references
8
- * - Specific fixes based on violation data
9
- */
10
-
11
- import type { ImpactValue } from 'axe-core';
12
- import type { StaticFixSuggestion, ElementFix, SerializedNode } from '../types/a11y.js';
13
- import { parseColor, suggestFix, rgbToHex } from '../../theme/contrast.js';
14
-
15
- /**
16
- * WCAG criteria references
17
- */
18
- const WCAG_CRITERIA: Record<string, { id: string; name: string; level: 'A' | 'AA' | 'AAA'; url: string }> = {
19
- // Level A
20
- '1.1.1': {
21
- id: '1.1.1',
22
- name: 'Non-text Content',
23
- level: 'A',
24
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/non-text-content',
25
- },
26
- '1.3.1': {
27
- id: '1.3.1',
28
- name: 'Info and Relationships',
29
- level: 'A',
30
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships',
31
- },
32
- '2.1.1': {
33
- id: '2.1.1',
34
- name: 'Keyboard',
35
- level: 'A',
36
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/keyboard',
37
- },
38
- '2.4.4': {
39
- id: '2.4.4',
40
- name: 'Link Purpose (In Context)',
41
- level: 'A',
42
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/link-purpose-in-context',
43
- },
44
- '4.1.2': {
45
- id: '4.1.2',
46
- name: 'Name, Role, Value',
47
- level: 'A',
48
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/name-role-value',
49
- },
50
- // Level AA
51
- '1.4.3': {
52
- id: '1.4.3',
53
- name: 'Contrast (Minimum)',
54
- level: 'AA',
55
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum',
56
- },
57
- '1.4.4': {
58
- id: '1.4.4',
59
- name: 'Resize Text',
60
- level: 'AA',
61
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/resize-text',
62
- },
63
- '2.4.6': {
64
- id: '2.4.6',
65
- name: 'Headings and Labels',
66
- level: 'AA',
67
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/headings-and-labels',
68
- },
69
- '2.5.8': {
70
- id: '2.5.8',
71
- name: 'Target Size (Minimum)',
72
- level: 'AA',
73
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum',
74
- },
75
- // Level AAA
76
- '1.4.6': {
77
- id: '1.4.6',
78
- name: 'Contrast (Enhanced)',
79
- level: 'AAA',
80
- url: 'https://www.w3.org/WAI/WCAG22/Understanding/contrast-enhanced',
81
- },
82
- };
83
-
84
- /**
85
- * Static fix suggestions for common accessibility rules
86
- */
87
- const STATIC_FIXES: Record<string, StaticFixSuggestion> = {
88
- 'color-contrast': {
89
- whyItMatters:
90
- 'Low contrast text is difficult to read for users with low vision, color blindness, or in bright environments like outdoor settings.',
91
- howToFix:
92
- 'Increase the contrast ratio between text and background colors. Normal text requires 4.5:1, large text (18pt or 14pt bold) requires 3:1.',
93
- badExample: '<button style="color: #888; background: #fff">Submit</button>',
94
- goodExample: '<button style="color: #333; background: #fff">Submit</button>',
95
- wcagCriterion: WCAG_CRITERIA['1.4.3'],
96
- },
97
- 'image-alt': {
98
- whyItMatters:
99
- 'Screen reader users cannot perceive images and rely on alternative text to understand visual content.',
100
- howToFix:
101
- 'Add descriptive alt text that conveys the purpose or content of the image. For decorative images, use alt="".',
102
- badExample: '<img src="hero.jpg">',
103
- goodExample: '<img src="hero.jpg" alt="Team collaboration in modern office">',
104
- wcagCriterion: WCAG_CRITERIA['1.1.1'],
105
- },
106
- 'button-name': {
107
- whyItMatters:
108
- 'Screen reader users need accessible names to understand what a button does. Without a name, they hear "button" with no context.',
109
- howToFix:
110
- 'Add text content, an aria-label, or aria-labelledby attribute to give the button an accessible name.',
111
- badExample: '<button><svg>...</svg></button>',
112
- goodExample: '<button aria-label="Close dialog"><svg>...</svg></button>',
113
- wcagCriterion: WCAG_CRITERIA['4.1.2'],
114
- },
115
- 'link-name': {
116
- whyItMatters:
117
- 'Screen reader users navigate by links and need descriptive text to understand each link\'s destination or purpose.',
118
- howToFix:
119
- 'Use descriptive link text instead of generic phrases. Avoid "click here" or "read more" without context.',
120
- badExample: '<a href="/docs">Click here</a>',
121
- goodExample: '<a href="/docs">View documentation</a>',
122
- wcagCriterion: WCAG_CRITERIA['2.4.4'],
123
- },
124
- 'label': {
125
- whyItMatters:
126
- 'Form inputs without labels are difficult for screen reader users to understand and for all users to identify.',
127
- howToFix:
128
- 'Associate a <label> element with the input using the for/id attributes, or wrap the input in a label element.',
129
- badExample: '<input type="text" placeholder="Email">',
130
- goodExample: '<label for="email">Email</label>\n<input type="text" id="email">',
131
- wcagCriterion: WCAG_CRITERIA['1.3.1'],
132
- },
133
- 'aria-valid-attr': {
134
- whyItMatters:
135
- 'Invalid ARIA attributes are ignored by assistive technologies and may indicate other accessibility issues.',
136
- howToFix:
137
- 'Use only valid ARIA attributes from the WAI-ARIA specification. Check spelling and ensure attributes apply to the element type.',
138
- badExample: '<button aria-expanded="true" aria-describedby="">Submit</button>',
139
- goodExample: '<button aria-expanded="true" aria-describedby="help-text">Submit</button>',
140
- wcagCriterion: WCAG_CRITERIA['4.1.2'],
141
- },
142
- 'aria-valid-attr-value': {
143
- whyItMatters:
144
- 'ARIA attributes with invalid values are ignored or misinterpreted by assistive technologies.',
145
- howToFix:
146
- 'Ensure ARIA attribute values match the expected format (boolean, ID reference, token, etc.).',
147
- badExample: '<div aria-hidden="yes">Hidden content</div>',
148
- goodExample: '<div aria-hidden="true">Hidden content</div>',
149
- wcagCriterion: WCAG_CRITERIA['4.1.2'],
150
- },
151
- 'aria-required-attr': {
152
- whyItMatters:
153
- 'ARIA roles require specific attributes to function correctly with assistive technologies.',
154
- howToFix:
155
- 'Add all required ARIA attributes for the role being used.',
156
- badExample: '<div role="checkbox">Accept terms</div>',
157
- goodExample: '<div role="checkbox" aria-checked="false">Accept terms</div>',
158
- wcagCriterion: WCAG_CRITERIA['4.1.2'],
159
- },
160
- 'heading-order': {
161
- whyItMatters:
162
- 'Screen reader users navigate by headings. Skipped heading levels make it harder to understand document structure.',
163
- howToFix:
164
- 'Use headings in sequential order (h1 → h2 → h3). Don\'t skip levels for styling purposes.',
165
- badExample: '<h1>Page Title</h1>\n<h4>Section</h4>',
166
- goodExample: '<h1>Page Title</h1>\n<h2>Section</h2>',
167
- wcagCriterion: WCAG_CRITERIA['1.3.1'],
168
- },
169
- 'tabindex': {
170
- whyItMatters:
171
- 'Positive tabindex values create unexpected keyboard navigation order, confusing keyboard-only users.',
172
- howToFix:
173
- 'Use tabindex="0" to add elements to natural tab order, or tabindex="-1" to remove them. Avoid positive values.',
174
- badExample: '<button tabindex="5">First</button>\n<button tabindex="1">Second</button>',
175
- goodExample: '<button>First</button>\n<button>Second</button>',
176
- wcagCriterion: WCAG_CRITERIA['2.1.1'],
177
- },
178
- 'duplicate-id': {
179
- whyItMatters:
180
- 'Duplicate IDs can cause aria-labelledby, aria-describedby, and label associations to reference the wrong element.',
181
- howToFix:
182
- 'Ensure each id attribute value is unique within the page.',
183
- badExample: '<input id="name">\n<input id="name">',
184
- goodExample: '<input id="first-name">\n<input id="last-name">',
185
- wcagCriterion: WCAG_CRITERIA['4.1.2'],
186
- },
187
- 'target-size-minimum': {
188
- whyItMatters:
189
- 'Small touch targets are difficult to activate for users with motor impairments or when using touch input.',
190
- howToFix:
191
- 'Increase the interactive target to at least 24x24 CSS pixels, or add sufficient padding around the control.',
192
- badExample: '<button style="width: 16px; height: 16px">×</button>',
193
- goodExample: '<button style="min-width: 24px; min-height: 24px; padding: 4px">×</button>',
194
- wcagCriterion: WCAG_CRITERIA['2.5.8'],
195
- },
196
- };
197
-
198
- /**
199
- * Get static fix suggestion for a rule
200
- */
201
- export function getStaticFix(ruleId: string): StaticFixSuggestion | null {
202
- return STATIC_FIXES[ruleId] || null;
203
- }
204
-
205
- /**
206
- * Parse contrast ratio data from axe-core node data
207
- */
208
- function parseContrastData(node: SerializedNode): {
209
- fgColor?: string;
210
- bgColor?: string;
211
- contrastRatio?: number;
212
- requiredRatio?: number;
213
- fontSize?: string;
214
- fontWeight?: string;
215
- } | null {
216
- const anyData = node.any?.[0]?.data as Record<string, unknown> | undefined;
217
- if (!anyData) return null;
218
-
219
- return {
220
- fgColor: anyData.fgColor as string | undefined,
221
- bgColor: anyData.bgColor as string | undefined,
222
- contrastRatio: anyData.contrastRatio as number | undefined,
223
- requiredRatio: anyData.expectedContrastRatio as number | undefined,
224
- fontSize: anyData.fontSize as string | undefined,
225
- fontWeight: anyData.fontWeight as string | undefined,
226
- };
227
- }
228
-
229
- /**
230
- * Generate a specific fix for a color-contrast violation
231
- */
232
- function generateContrastFix(node: SerializedNode): ElementFix | null {
233
- const data = parseContrastData(node);
234
- if (!data?.fgColor || !data?.bgColor) return null;
235
-
236
- const { fgColor, bgColor, contrastRatio: ratio, requiredRatio } = data;
237
-
238
- // Safely convert to number and format
239
- const currentRatioNum = typeof ratio === 'number' ? ratio : parseFloat(String(ratio || ''));
240
- const requiredRatioNum = typeof requiredRatio === 'number' ? requiredRatio : parseFloat(String(requiredRatio || ''));
241
-
242
- const currentRatio = !isNaN(currentRatioNum) ? currentRatioNum.toFixed(2) : 'unknown';
243
- const required = !isNaN(requiredRatioNum) ? requiredRatioNum : 4.5;
244
-
245
- // Use real color math to suggest a corrected foreground color
246
- try {
247
- const fgRgb = parseColor(fgColor);
248
- const bgRgb = parseColor(bgColor);
249
- const correctedHex = suggestFix(fgRgb, bgRgb, required);
250
-
251
- return {
252
- originalHtml: node.html,
253
- fixedHtml: node.html,
254
- explanation: `Text color ${fgColor} on background ${bgColor} has insufficient contrast (${currentRatio}:1, need ${required}:1). Suggested foreground: ${correctedHex}`,
255
- autoFixable: true,
256
- };
257
- } catch {
258
- // Fall back to non-auto-fixable if color parsing fails
259
- return {
260
- originalHtml: node.html,
261
- fixedHtml: node.html,
262
- explanation: `Text color ${fgColor} on background ${bgColor} has insufficient contrast (${currentRatio}:1, need ${required}:1). Adjust the foreground color to meet the required ratio.`,
263
- autoFixable: false,
264
- };
265
- }
266
- }
267
-
268
- /**
269
- * Generate a specific fix for an image-alt violation
270
- */
271
- function generateAltTextFix(node: SerializedNode): ElementFix | null {
272
- const html = node.html;
273
-
274
- // Extract src to help generate meaningful alt text suggestion
275
- const srcMatch = html.match(/src=["']([^"']+)["']/);
276
- const src = srcMatch?.[1] || '';
277
- const filename = src.split('/').pop()?.replace(/\.[^.]+$/, '') || 'image';
278
-
279
- // Generate suggested alt text based on filename
280
- const suggestedAlt = filename
281
- .replace(/[-_]/g, ' ')
282
- .replace(/([a-z])([A-Z])/g, '$1 $2')
283
- .toLowerCase();
284
-
285
- // Create fixed HTML
286
- let fixedHtml = html;
287
- if (html.includes('alt=""') || html.includes("alt=''")) {
288
- // Decorative image marked correctly, but flagged - might need real alt
289
- fixedHtml = html.replace(/alt=["'][^"']*["']/, `alt="${suggestedAlt}"`);
290
- } else if (html.includes('alt=')) {
291
- // Has alt but it's not descriptive enough
292
- fixedHtml = html.replace(/alt=["'][^"']*["']/, `alt="${suggestedAlt}"`);
293
- } else {
294
- // Missing alt entirely
295
- fixedHtml = html.replace(/<img/, `<img alt="${suggestedAlt}"`);
296
- }
297
-
298
- return {
299
- originalHtml: html,
300
- fixedHtml,
301
- explanation: `Add descriptive alt text that describes the image content or purpose. If decorative, use alt="".`,
302
- autoFixable: true,
303
- };
304
- }
305
-
306
- /**
307
- * Generate a specific fix for a button-name violation
308
- */
309
- function generateButtonNameFix(node: SerializedNode): ElementFix | null {
310
- const html = node.html;
311
-
312
- // Check if it's an icon-only button
313
- const hasOnlySvg = /<button[^>]*>[\s]*<svg[^>]*>[\s\S]*<\/svg>[\s]*<\/button>/i.test(html);
314
- const hasOnlyImg = /<button[^>]*>[\s]*<img[^>]*\/?>\s*<\/button>/i.test(html);
315
-
316
- let fixedHtml = html;
317
- let explanation = '';
318
-
319
- if (hasOnlySvg || hasOnlyImg) {
320
- // Add aria-label for icon buttons
321
- fixedHtml = html.replace(/<button/, '<button aria-label="[describe action]"');
322
- explanation = 'Add aria-label to describe the button\'s action for screen reader users.';
323
- } else {
324
- // Add visible text content
325
- fixedHtml = html.replace(/<\/button>/, '[Button text]</button>');
326
- explanation = 'Add visible text content or aria-label that describes the button\'s purpose.';
327
- }
328
-
329
- return {
330
- originalHtml: html,
331
- fixedHtml,
332
- explanation,
333
- autoFixable: false, // Requires human decision on button purpose
334
- };
335
- }
336
-
337
- /**
338
- * Generate a specific fix for a link-name violation
339
- */
340
- function generateLinkNameFix(node: SerializedNode): ElementFix | null {
341
- const html = node.html;
342
-
343
- // Check common patterns
344
- const hasOnlySvg = /<a[^>]*>[\s]*<svg[^>]*>[\s\S]*<\/svg>[\s]*<\/a>/i.test(html);
345
- const hasOnlyImg = /<a[^>]*>[\s]*<img[^>]*\/?>\s*<\/a>/i.test(html);
346
- const isEmpty = /<a[^>]*>\s*<\/a>/i.test(html);
347
-
348
- let fixedHtml = html;
349
- let explanation = '';
350
-
351
- if (hasOnlySvg || hasOnlyImg) {
352
- fixedHtml = html.replace(/<a/, '<a aria-label="[describe destination]"');
353
- explanation = 'Add aria-label to describe where the link goes.';
354
- } else if (isEmpty) {
355
- fixedHtml = html.replace(/<\/a>/, '[Link text]</a>');
356
- explanation = 'Add descriptive text content that indicates the link\'s destination.';
357
- } else {
358
- explanation = 'Ensure link text is descriptive. Avoid generic text like "click here" or "read more".';
359
- }
360
-
361
- return {
362
- originalHtml: html,
363
- fixedHtml,
364
- explanation,
365
- autoFixable: false,
366
- };
367
- }
368
-
369
- /**
370
- * Generate a specific fix for a label violation
371
- */
372
- function generateLabelFix(node: SerializedNode): ElementFix | null {
373
- const html = node.html;
374
-
375
- // Extract input type and any existing identifiers
376
- const typeMatch = html.match(/type=["']([^"']+)["']/);
377
- const type = typeMatch?.[1] || 'text';
378
- const idMatch = html.match(/id=["']([^"']+)["']/);
379
- const id = idMatch?.[1];
380
-
381
- let fixedHtml = html;
382
- let explanation = '';
383
-
384
- if (id) {
385
- // Has ID, suggest adding label element
386
- const labelText = type.charAt(0).toUpperCase() + type.slice(1);
387
- explanation = `Add a <label for="${id}">${labelText}</label> element before this input.`;
388
- } else {
389
- // No ID, add one and suggest label
390
- const suggestedId = `input-${type}-${Date.now()}`;
391
- fixedHtml = html.replace(/<input/, `<input id="${suggestedId}"`);
392
- explanation = `Add an id attribute and associate with a label: <label for="${suggestedId}">Label text</label>`;
393
- }
394
-
395
- return {
396
- originalHtml: html,
397
- fixedHtml,
398
- explanation,
399
- autoFixable: false,
400
- };
401
- }
402
-
403
- /**
404
- * Fix generator registry
405
- */
406
- type FixGenerator = (node: SerializedNode) => ElementFix | null;
407
-
408
- const FIX_GENERATORS: Record<string, FixGenerator> = {
409
- 'color-contrast': generateContrastFix,
410
- 'image-alt': generateAltTextFix,
411
- 'button-name': generateButtonNameFix,
412
- 'link-name': generateLinkNameFix,
413
- 'label': generateLabelFix,
414
- };
415
-
416
- /**
417
- * Generate a specific fix for a violation node
418
- */
419
- export function generateElementFix(ruleId: string, node: SerializedNode): ElementFix | null {
420
- const generator = FIX_GENERATORS[ruleId];
421
- if (!generator) return null;
422
- return generator(node);
423
- }
424
-
425
- /**
426
- * Get impact description for UI display
427
- */
428
- export function getImpactDescription(impact: ImpactValue | null): string {
429
- switch (impact) {
430
- case 'critical':
431
- return 'Critical issues completely block access for some users';
432
- case 'serious':
433
- return 'Serious issues make content very difficult to access';
434
- case 'moderate':
435
- return 'Moderate issues cause some difficulty for users';
436
- case 'minor':
437
- return 'Minor issues may cause slight inconvenience';
438
- default:
439
- return 'Impact level not determined';
440
- }
441
- }
442
-
443
- /**
444
- * Get impact styling for inline styles and Badge variant mapping
445
- */
446
- export function getImpactColorClass(impact: ImpactValue | null): {
447
- variant: 'error' | 'warning' | 'info' | 'default';
448
- color: string;
449
- bg: string;
450
- text: string;
451
- border: string;
452
- borderLeft: string;
453
- } {
454
- switch (impact) {
455
- case 'critical':
456
- return {
457
- variant: 'error',
458
- color: 'var(--color-danger)',
459
- bg: 'var(--color-danger-bg)',
460
- text: 'var(--color-danger)',
461
- border: 'var(--color-danger)',
462
- borderLeft: 'var(--color-danger)',
463
- };
464
- case 'serious':
465
- return {
466
- variant: 'error',
467
- color: 'var(--color-danger)',
468
- bg: 'var(--color-danger-bg)',
469
- text: 'var(--color-danger)',
470
- border: 'var(--color-danger)',
471
- borderLeft: 'var(--color-danger)',
472
- };
473
- case 'moderate':
474
- return {
475
- variant: 'warning',
476
- color: 'var(--color-warning)',
477
- bg: 'var(--color-warning-bg)',
478
- text: 'var(--color-warning)',
479
- border: 'var(--color-warning)',
480
- borderLeft: 'var(--color-warning)',
481
- };
482
- case 'minor':
483
- default:
484
- return {
485
- variant: 'info',
486
- color: 'var(--color-info)',
487
- bg: 'var(--color-info-bg)',
488
- text: 'var(--color-info)',
489
- border: 'var(--color-info)',
490
- borderLeft: 'var(--color-info)',
491
- };
492
- }
493
- }
494
-
495
- /**
496
- * Extract WCAG tags from a violation's tags array
497
- */
498
- export function extractWcagTags(tags: string[]): string[] {
499
- return tags.filter(tag => tag.startsWith('wcag'));
500
- }
501
-
502
- /**
503
- * Get readable WCAG criterion from tag (e.g., 'wcag143' -> '1.4.3')
504
- */
505
- export function parseWcagTag(tag: string): string | null {
506
- const match = tag.match(/wcag(\d)(\d)(\d)/);
507
- if (!match) return null;
508
- return `${match[1]}.${match[2]}.${match[3]}`;
509
- }