@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,383 +0,0 @@
1
- /**
2
- * Shared A11y Cache
3
- *
4
- * Provides a global cache for accessibility scan results that:
5
- * 1. Persists in sessionStorage across page navigations
6
- * 2. Is shared between Dashboard and AccessibilityPanel
7
- * 3. Stores full violation details for rich UI display
8
- * 4. Supports component-level invalidation
9
- */
10
-
11
- import { BRAND } from '../../core/index.js';
12
- import type {
13
- CachedA11yResult,
14
- SerializedViolation,
15
- A11ySummary,
16
- } from '../types/a11y.js';
17
-
18
- const CACHE_KEY = `${BRAND.storagePrefix}a11y-cache`;
19
- const CACHE_VERSION = 2; // Bumped for new schema with full violations
20
-
21
- /**
22
- * Legacy interface for backward compatibility
23
- * @deprecated Use CachedA11yResult instead
24
- */
25
- export interface ComponentA11yData {
26
- violations: number;
27
- passes: number;
28
- incomplete: number;
29
- critical: number;
30
- serious: number;
31
- moderate: number;
32
- minor: number;
33
- scannedAt: number;
34
- variant?: string;
35
- }
36
-
37
- interface A11yCacheData {
38
- version: number;
39
- components: Record<string, CachedA11yResult>;
40
- lastFullScan?: number;
41
- }
42
-
43
- /**
44
- * Load cache from sessionStorage
45
- */
46
- function loadCache(): A11yCacheData {
47
- try {
48
- const stored = sessionStorage.getItem(CACHE_KEY);
49
- if (stored) {
50
- const data = JSON.parse(stored) as A11yCacheData;
51
- if (data.version === CACHE_VERSION) {
52
- return data;
53
- }
54
- // Version mismatch - clear old cache
55
- sessionStorage.removeItem(CACHE_KEY);
56
- }
57
- } catch (e) {
58
- // Ignore parse errors
59
- }
60
- return { version: CACHE_VERSION, components: {} };
61
- }
62
-
63
- /**
64
- * Save cache to sessionStorage
65
- */
66
- function saveCache(data: A11yCacheData): void {
67
- try {
68
- sessionStorage.setItem(CACHE_KEY, JSON.stringify(data));
69
- } catch (e) {
70
- // Storage might be full - try clearing old data
71
- try {
72
- sessionStorage.removeItem(CACHE_KEY);
73
- sessionStorage.setItem(CACHE_KEY, JSON.stringify(data));
74
- } catch {
75
- // Ignore storage errors
76
- }
77
- }
78
- }
79
-
80
- /**
81
- * Get cached a11y result for a component (full data)
82
- */
83
- export function getComponentA11yResult(componentName: string): CachedA11yResult | null {
84
- const cache = loadCache();
85
- return cache.components[componentName] || null;
86
- }
87
-
88
- /**
89
- * Get cached a11y data for a component (legacy format for backward compatibility)
90
- */
91
- export function getComponentA11y(componentName: string): ComponentA11yData | null {
92
- const result = getComponentA11yResult(componentName);
93
- if (!result) return null;
94
-
95
- return {
96
- violations: result.violations.length,
97
- passes: result.passes,
98
- incomplete: result.incomplete,
99
- critical: result.counts.critical,
100
- serious: result.counts.serious,
101
- moderate: result.counts.moderate,
102
- minor: result.counts.minor,
103
- scannedAt: result.scannedAt,
104
- variant: result.variant,
105
- };
106
- }
107
-
108
- /**
109
- * Get all cached a11y data (full results)
110
- */
111
- export function getAllA11yResults(): Record<string, CachedA11yResult> {
112
- const cache = loadCache();
113
- return cache.components;
114
- }
115
-
116
- /**
117
- * Get all cached a11y data (legacy format)
118
- */
119
- export function getAllA11yData(): Record<string, ComponentA11yData> {
120
- const cache = loadCache();
121
- const result: Record<string, ComponentA11yData> = {};
122
-
123
- for (const [name, data] of Object.entries(cache.components)) {
124
- result[name] = {
125
- violations: data.violations.length,
126
- passes: data.passes,
127
- incomplete: data.incomplete,
128
- critical: data.counts.critical,
129
- serious: data.counts.serious,
130
- moderate: data.counts.moderate,
131
- minor: data.counts.minor,
132
- scannedAt: data.scannedAt,
133
- variant: data.variant,
134
- };
135
- }
136
-
137
- return result;
138
- }
139
-
140
- /**
141
- * Get timestamp of last full scan
142
- */
143
- export function getLastFullScanTime(): number | undefined {
144
- const cache = loadCache();
145
- return cache.lastFullScan;
146
- }
147
-
148
- /**
149
- * Update cache with full a11y result for a component
150
- */
151
- export function updateComponentA11yResult(
152
- componentName: string,
153
- result: Omit<CachedA11yResult, 'componentName' | 'scannedAt'> & { scannedAt?: number }
154
- ): void {
155
- const cache = loadCache();
156
- cache.components[componentName] = {
157
- componentName,
158
- ...result,
159
- scannedAt: result.scannedAt || Date.now(),
160
- };
161
- saveCache(cache);
162
-
163
- // Dispatch event for listeners
164
- window.dispatchEvent(new CustomEvent('a11y-cache-updated', {
165
- detail: {
166
- componentName,
167
- data: cache.components[componentName],
168
- // Include legacy format for backward compatibility
169
- legacyData: {
170
- violations: result.violations.length,
171
- passes: result.passes,
172
- incomplete: result.incomplete,
173
- critical: result.counts.critical,
174
- serious: result.counts.serious,
175
- moderate: result.counts.moderate,
176
- minor: result.counts.minor,
177
- scannedAt: result.scannedAt || Date.now(),
178
- variant: result.variant,
179
- },
180
- },
181
- }));
182
- }
183
-
184
- /**
185
- * Update cache for a single component (legacy format, converted to new format)
186
- */
187
- export function updateComponentA11y(
188
- componentName: string,
189
- data: Omit<ComponentA11yData, 'scannedAt'> & { scannedAt?: number },
190
- violations?: SerializedViolation[]
191
- ): void {
192
- const cache = loadCache();
193
-
194
- // Convert to new format
195
- cache.components[componentName] = {
196
- componentName,
197
- violations: violations || [], // Use provided violations or empty array
198
- passes: data.passes,
199
- incomplete: data.incomplete,
200
- scannedAt: data.scannedAt || Date.now(),
201
- variant: data.variant,
202
- counts: {
203
- critical: data.critical,
204
- serious: data.serious,
205
- moderate: data.moderate,
206
- minor: data.minor,
207
- },
208
- };
209
- saveCache(cache);
210
-
211
- // Dispatch event for listeners
212
- window.dispatchEvent(new CustomEvent('a11y-cache-updated', {
213
- detail: { componentName, data: cache.components[componentName] },
214
- }));
215
- }
216
-
217
- /**
218
- * Invalidate cache for specific components
219
- * This marks them for re-scan without removing the data
220
- */
221
- export function invalidateComponents(componentNames: string[]): void {
222
- const cache = loadCache();
223
- let changed = false;
224
-
225
- for (const name of componentNames) {
226
- if (cache.components[name]) {
227
- // Set scannedAt to 0 to mark as stale
228
- cache.components[name].scannedAt = 0;
229
- changed = true;
230
- }
231
- }
232
-
233
- if (changed) {
234
- saveCache(cache);
235
-
236
- // Dispatch event for listeners
237
- window.dispatchEvent(new CustomEvent('a11y-cache-invalidated', {
238
- detail: { components: componentNames },
239
- }));
240
- }
241
- }
242
-
243
- /**
244
- * Check if a component's cache is stale (needs re-scan)
245
- */
246
- export function isComponentStale(componentName: string, maxAgeMs: number = 30000): boolean {
247
- const cache = loadCache();
248
- const data = cache.components[componentName];
249
-
250
- if (!data) return true;
251
- if (data.scannedAt === 0) return true; // Explicitly invalidated
252
-
253
- return Date.now() - data.scannedAt > maxAgeMs;
254
- }
255
-
256
- /**
257
- * Mark that a full scan was completed
258
- */
259
- export function markFullScanComplete(): void {
260
- const cache = loadCache();
261
- cache.lastFullScan = Date.now();
262
- saveCache(cache);
263
- }
264
-
265
- /**
266
- * Clear all cached data
267
- */
268
- export function clearA11yCache(): void {
269
- try {
270
- sessionStorage.removeItem(CACHE_KEY);
271
- } catch (e) {
272
- // Ignore
273
- }
274
- window.dispatchEvent(new CustomEvent('a11y-cache-cleared'));
275
- }
276
-
277
- /**
278
- * Clear cache for a specific component
279
- */
280
- export function clearComponentCache(componentName: string): void {
281
- const cache = loadCache();
282
- if (cache.components[componentName]) {
283
- delete cache.components[componentName];
284
- saveCache(cache);
285
-
286
- window.dispatchEvent(new CustomEvent('a11y-cache-updated', {
287
- detail: { componentName, data: null },
288
- }));
289
- }
290
- }
291
-
292
- /**
293
- * Calculate summary from cached data
294
- */
295
- export function getA11ySummary(): A11ySummary {
296
- const cache = loadCache();
297
- const components = Object.values(cache.components);
298
-
299
- const summary: A11ySummary = {
300
- accessibleComponents: 0,
301
- totalComponents: components.length,
302
- violationsByImpact: {
303
- critical: 0,
304
- serious: 0,
305
- moderate: 0,
306
- minor: 0,
307
- },
308
- topViolations: [],
309
- };
310
-
311
- // Track violations by rule ID for top violations
312
- const violationsByRule = new Map<string, {
313
- ruleId: string;
314
- description: string;
315
- impact: 'critical' | 'serious' | 'moderate' | 'minor' | null;
316
- affectedComponents: Set<string>;
317
- }>();
318
-
319
- for (const comp of components) {
320
- // Count by impact
321
- summary.violationsByImpact.critical += comp.counts.critical;
322
- summary.violationsByImpact.serious += comp.counts.serious;
323
- summary.violationsByImpact.moderate += comp.counts.moderate;
324
- summary.violationsByImpact.minor += comp.counts.minor;
325
-
326
- // Check if accessible (no critical/serious)
327
- if (comp.counts.critical === 0 && comp.counts.serious === 0) {
328
- summary.accessibleComponents++;
329
- }
330
-
331
- // Aggregate violations by rule
332
- for (const violation of comp.violations) {
333
- const existing = violationsByRule.get(violation.id);
334
- if (existing) {
335
- existing.affectedComponents.add(comp.componentName);
336
- } else {
337
- violationsByRule.set(violation.id, {
338
- ruleId: violation.id,
339
- description: violation.description,
340
- impact: violation.impact,
341
- affectedComponents: new Set([comp.componentName]),
342
- });
343
- }
344
- }
345
- }
346
-
347
- // Sort by number of affected components and take top 5
348
- summary.topViolations = Array.from(violationsByRule.values())
349
- .sort((a, b) => b.affectedComponents.size - a.affectedComponents.size)
350
- .slice(0, 5)
351
- .map(v => ({
352
- ruleId: v.ruleId,
353
- description: v.description,
354
- impact: v.impact,
355
- affectedComponents: Array.from(v.affectedComponents),
356
- }));
357
-
358
- return summary;
359
- }
360
-
361
- /**
362
- * Get legacy summary format for backward compatibility
363
- */
364
- export function getLegacyA11ySummary(): {
365
- totalComponents: number;
366
- accessibleComponents: number;
367
- totalViolations: number;
368
- totalCritical: number;
369
- totalSerious: number;
370
- } {
371
- const summary = getA11ySummary();
372
- return {
373
- totalComponents: summary.totalComponents,
374
- accessibleComponents: summary.accessibleComponents,
375
- totalViolations:
376
- summary.violationsByImpact.critical +
377
- summary.violationsByImpact.serious +
378
- summary.violationsByImpact.moderate +
379
- summary.violationsByImpact.minor,
380
- totalCritical: summary.violationsByImpact.critical,
381
- totalSerious: summary.violationsByImpact.serious,
382
- };
383
- }