@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,372 +0,0 @@
1
- /**
2
- * Action Export Utilities
3
- *
4
- * Generate test assertions from recorded user interactions.
5
- * Supports multiple export formats: JSON, Jest, Playwright
6
- */
7
-
8
- import type { ActionLog } from '../hooks/useActions.js';
9
-
10
- export type ExportFormat = 'json' | 'jest' | 'playwright';
11
-
12
- export interface ExportOptions {
13
- /** Component name for generated test */
14
- componentName?: string;
15
- /** Variant name for generated test */
16
- variantName?: string;
17
- /** Include timestamps in export */
18
- includeTimestamps?: boolean;
19
- /** Include event details in comments */
20
- includeComments?: boolean;
21
- }
22
-
23
- /**
24
- * Export actions as JSON
25
- */
26
- export function exportActionsAsJson(
27
- logs: ActionLog[],
28
- options: ExportOptions = {}
29
- ): string {
30
- const { includeTimestamps = false } = options;
31
-
32
- const exportData = logs.map((log) => ({
33
- action: log.name,
34
- args: serializeArgs(log.args),
35
- count: log.count > 1 ? log.count : undefined,
36
- timestamp: includeTimestamps ? log.timestamp : undefined,
37
- }));
38
-
39
- return JSON.stringify(exportData, null, 2);
40
- }
41
-
42
- /**
43
- * Export actions as Jest test assertions
44
- */
45
- export function exportActionsAsJest(
46
- logs: ActionLog[],
47
- options: ExportOptions = {}
48
- ): string {
49
- const {
50
- componentName = 'Component',
51
- variantName = 'Default',
52
- includeComments = true,
53
- } = options;
54
-
55
- const lines: string[] = [];
56
-
57
- // Import statements
58
- lines.push("import { render, screen, fireEvent } from '@testing-library/react';");
59
- lines.push("import userEvent from '@testing-library/user-event';");
60
- lines.push(`import { ${componentName} } from './${componentName}';`);
61
- lines.push('');
62
-
63
- // Test block
64
- lines.push(`describe('${componentName}', () => {`);
65
- lines.push(` it('${variantName} - recorded interactions', async () => {`);
66
- lines.push(' const user = userEvent.setup();');
67
- lines.push('');
68
-
69
- // Mock handlers
70
- const actionNames = [...new Set(logs.map((l) => l.name))];
71
- for (const name of actionNames) {
72
- const handlerName = `mock${capitalize(name)}`;
73
- lines.push(` const ${handlerName} = jest.fn();`);
74
- }
75
- lines.push('');
76
-
77
- // Render
78
- lines.push(` render(`);
79
- lines.push(` <${componentName}`);
80
- for (const name of actionNames) {
81
- lines.push(` ${name}={mock${capitalize(name)}}`);
82
- }
83
- lines.push(` />`);
84
- lines.push(` );`);
85
- lines.push('');
86
-
87
- // Assertions for each action
88
- if (includeComments) {
89
- lines.push(' // Recorded interactions:');
90
- }
91
-
92
- for (const log of logs) {
93
- const handlerName = `mock${capitalize(log.name)}`;
94
-
95
- if (includeComments && log.args.length > 0) {
96
- lines.push(` // ${log.name} called with: ${summarizeArgs(log.args)}`);
97
- }
98
-
99
- if (log.count > 1) {
100
- lines.push(` expect(${handlerName}).toHaveBeenCalledTimes(${log.count});`);
101
- } else {
102
- const serializedArgs = serializeArgsForJest(log.args);
103
- if (serializedArgs.length > 0) {
104
- lines.push(` expect(${handlerName}).toHaveBeenCalledWith(${serializedArgs});`);
105
- } else {
106
- lines.push(` expect(${handlerName}).toHaveBeenCalled();`);
107
- }
108
- }
109
- }
110
-
111
- lines.push(' });');
112
- lines.push('});');
113
-
114
- return lines.join('\n');
115
- }
116
-
117
- /**
118
- * Export actions as Playwright test assertions
119
- */
120
- export function exportActionsAsPlaywright(
121
- logs: ActionLog[],
122
- options: ExportOptions = {}
123
- ): string {
124
- const {
125
- componentName = 'Component',
126
- variantName = 'Default',
127
- includeComments = true,
128
- } = options;
129
-
130
- const lines: string[] = [];
131
-
132
- // Import statements
133
- lines.push("import { test, expect } from '@playwright/test';");
134
- lines.push('');
135
-
136
- // Test block
137
- lines.push(`test('${componentName} - ${variantName}', async ({ page }) => {`);
138
- lines.push(` // Navigate to component`);
139
- lines.push(` await page.goto('/?component=${encodeURIComponent(componentName)}&variant=${encodeURIComponent(variantName)}');`);
140
- lines.push('');
141
- lines.push(` // Wait for component to render`);
142
- lines.push(` await page.waitForSelector('[data-preview-container="true"]');`);
143
- lines.push('');
144
-
145
- if (includeComments) {
146
- lines.push(' // Recorded interactions:');
147
- }
148
-
149
- // Generate interaction replay
150
- for (const log of logs) {
151
- if (includeComments) {
152
- lines.push(` // ${log.name}${log.count > 1 ? ` (×${log.count})` : ''}: ${summarizeArgs(log.args)}`);
153
- }
154
-
155
- // Generate appropriate Playwright command based on action type
156
- const playwrightCode = generatePlaywrightAction(log);
157
- if (playwrightCode) {
158
- lines.push(` ${playwrightCode}`);
159
- }
160
- }
161
-
162
- lines.push('');
163
- lines.push(' // Add assertions here based on expected state changes');
164
- lines.push(' // Example: await expect(page.getByRole("button")).toBeDisabled();');
165
-
166
- lines.push('});');
167
-
168
- return lines.join('\n');
169
- }
170
-
171
- /**
172
- * Export actions in specified format
173
- */
174
- export function exportActions(
175
- logs: ActionLog[],
176
- format: ExportFormat,
177
- options: ExportOptions = {}
178
- ): string {
179
- switch (format) {
180
- case 'json':
181
- return exportActionsAsJson(logs, options);
182
- case 'jest':
183
- return exportActionsAsJest(logs, options);
184
- case 'playwright':
185
- return exportActionsAsPlaywright(logs, options);
186
- default:
187
- throw new Error(`Unknown export format: ${format}`);
188
- }
189
- }
190
-
191
- /**
192
- * Copy text to clipboard
193
- */
194
- export async function copyToClipboard(text: string): Promise<boolean> {
195
- try {
196
- await navigator.clipboard.writeText(text);
197
- return true;
198
- } catch {
199
- // Fallback for older browsers
200
- const textarea = document.createElement('textarea');
201
- textarea.value = text;
202
- textarea.style.position = 'fixed';
203
- textarea.style.opacity = '0';
204
- document.body.appendChild(textarea);
205
- textarea.select();
206
- try {
207
- document.execCommand('copy');
208
- return true;
209
- } catch {
210
- return false;
211
- } finally {
212
- document.body.removeChild(textarea);
213
- }
214
- }
215
- }
216
-
217
- /**
218
- * Download text as a file
219
- */
220
- export function downloadAsFile(content: string, filename: string): void {
221
- const blob = new Blob([content], { type: 'text/plain' });
222
- const url = URL.createObjectURL(blob);
223
- const a = document.createElement('a');
224
- a.href = url;
225
- a.download = filename;
226
- document.body.appendChild(a);
227
- a.click();
228
- document.body.removeChild(a);
229
- URL.revokeObjectURL(url);
230
- }
231
-
232
- /**
233
- * Get file extension for export format
234
- */
235
- export function getFileExtension(format: ExportFormat): string {
236
- switch (format) {
237
- case 'json':
238
- return '.json';
239
- case 'jest':
240
- return '.test.tsx';
241
- case 'playwright':
242
- return '.spec.ts';
243
- default:
244
- return '.txt';
245
- }
246
- }
247
-
248
- // Helper functions
249
-
250
- function capitalize(str: string): string {
251
- return str.charAt(0).toUpperCase() + str.slice(1);
252
- }
253
-
254
- function serializeArgs(args: unknown[]): unknown[] {
255
- return args.map((arg) => {
256
- if (arg instanceof Event) {
257
- return {
258
- __type: 'Event',
259
- type: arg.type,
260
- target: arg.target instanceof Element ? describeElement(arg.target) : null,
261
- };
262
- }
263
- if (arg instanceof Element) {
264
- return {
265
- __type: 'Element',
266
- ...describeElement(arg),
267
- };
268
- }
269
- if (typeof arg === 'function') {
270
- return { __type: 'function' };
271
- }
272
- return arg;
273
- });
274
- }
275
-
276
- function describeElement(el: Element): object {
277
- return {
278
- tagName: el.tagName.toLowerCase(),
279
- id: el.id || undefined,
280
- className: el.className || undefined,
281
- textContent: el.textContent?.slice(0, 50) || undefined,
282
- };
283
- }
284
-
285
- function serializeArgsForJest(args: unknown[]): string {
286
- if (args.length === 0) return '';
287
-
288
- const parts: string[] = [];
289
- for (const arg of args) {
290
- if (arg instanceof Event) {
291
- parts.push('expect.any(Event)');
292
- } else if (arg instanceof Element) {
293
- parts.push('expect.any(HTMLElement)');
294
- } else if (typeof arg === 'function') {
295
- parts.push('expect.any(Function)');
296
- } else if (typeof arg === 'object' && arg !== null) {
297
- parts.push(`expect.objectContaining(${JSON.stringify(arg)})`);
298
- } else {
299
- parts.push(JSON.stringify(arg));
300
- }
301
- }
302
- return parts.join(', ');
303
- }
304
-
305
- function summarizeArgs(args: unknown[]): string {
306
- if (args.length === 0) return '(no args)';
307
-
308
- const summaries = args.map((arg) => {
309
- if (arg instanceof Event) {
310
- return `${arg.type} event`;
311
- }
312
- if (arg instanceof Element) {
313
- return `<${arg.tagName.toLowerCase()}>`;
314
- }
315
- if (typeof arg === 'function') {
316
- return 'ƒ()';
317
- }
318
- if (typeof arg === 'object' && arg !== null) {
319
- return '{...}';
320
- }
321
- return JSON.stringify(arg);
322
- });
323
-
324
- return summaries.join(', ');
325
- }
326
-
327
- function generatePlaywrightAction(log: ActionLog): string | null {
328
- const name = log.name.toLowerCase();
329
-
330
- // Common click handlers
331
- if (name.includes('click') || name === 'onpress') {
332
- return "await page.getByRole('button').click(); // Adjust selector as needed";
333
- }
334
-
335
- // Change handlers
336
- if (name.includes('change')) {
337
- const value = log.args[0];
338
- if (typeof value === 'string') {
339
- return `await page.getByRole('textbox').fill(${JSON.stringify(value)});`;
340
- }
341
- return "await page.getByRole('textbox').fill('...'); // Add value";
342
- }
343
-
344
- // Submit handlers
345
- if (name.includes('submit')) {
346
- return "await page.getByRole('button', { name: 'Submit' }).click();";
347
- }
348
-
349
- // Focus/blur handlers
350
- if (name.includes('focus')) {
351
- return "await page.getByRole('textbox').focus();";
352
- }
353
- if (name.includes('blur')) {
354
- return "await page.getByRole('textbox').blur();";
355
- }
356
-
357
- // Mouse events
358
- if (name.includes('mouseenter') || name.includes('mouseover')) {
359
- return "await page.getByRole('button').hover();";
360
- }
361
-
362
- // Keyboard events
363
- if (name.includes('keydown') || name.includes('keyup') || name.includes('keypress')) {
364
- const event = log.args[0] as { key?: string } | undefined;
365
- if (event?.key) {
366
- return `await page.keyboard.press(${JSON.stringify(event.key)});`;
367
- }
368
- }
369
-
370
- // Default: add as comment
371
- return `// ${log.name}: ${summarizeArgs(log.args)}`;
372
- }
@@ -1,201 +0,0 @@
1
- export type ColorSchemeType =
2
- | 'monochromatic'
3
- | 'complementary'
4
- | 'analogous'
5
- | 'triadic'
6
- | 'split-complementary'
7
- | 'tetradic';
8
-
9
- export const COLOR_SCHEME_OPTIONS = [
10
- { value: 'monochromatic', label: 'Monochromatic', description: 'Variations of a single hue' },
11
- { value: 'complementary', label: 'Complementary', description: 'Two opposite colors' },
12
- { value: 'analogous', label: 'Analogous', description: 'Three adjacent colors' },
13
- { value: 'triadic', label: 'Triadic', description: 'Three evenly spaced colors' },
14
- { value: 'split-complementary', label: 'Split Complementary', description: 'Base + two adjacent to complement' },
15
- { value: 'tetradic', label: 'Tetradic (Square)', description: 'Four evenly spaced colors' },
16
- ] as const;
17
-
18
- /**
19
- * Convert hex color to HSL
20
- */
21
- function hexToHsl(hex: string): [number, number, number] {
22
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
23
- if (!result) return [0, 0, 0];
24
-
25
- const r = parseInt(result[1], 16) / 255;
26
- const g = parseInt(result[2], 16) / 255;
27
- const b = parseInt(result[3], 16) / 255;
28
-
29
- const max = Math.max(r, g, b);
30
- const min = Math.min(r, g, b);
31
- let h = 0;
32
- let s = 0;
33
- const l = (max + min) / 2;
34
-
35
- if (max !== min) {
36
- const d = max - min;
37
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
38
-
39
- switch (max) {
40
- case r:
41
- h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
42
- break;
43
- case g:
44
- h = ((b - r) / d + 2) / 6;
45
- break;
46
- case b:
47
- h = ((r - g) / d + 4) / 6;
48
- break;
49
- }
50
- }
51
-
52
- return [Math.round(h * 360), Math.round(s * 100), Math.round(l * 100)];
53
- }
54
-
55
- /**
56
- * Convert HSL to hex color
57
- */
58
- function hslToHex(h: number, s: number, l: number): string {
59
- h = h / 360;
60
- s = s / 100;
61
- l = l / 100;
62
-
63
- let r: number, g: number, b: number;
64
-
65
- if (s === 0) {
66
- r = g = b = l;
67
- } else {
68
- const hue2rgb = (p: number, q: number, t: number) => {
69
- if (t < 0) t += 1;
70
- if (t > 1) t -= 1;
71
- if (t < 1 / 6) return p + (q - p) * 6 * t;
72
- if (t < 1 / 2) return q;
73
- if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
74
- return p;
75
- };
76
-
77
- const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
78
- const p = 2 * l - q;
79
- r = hue2rgb(p, q, h + 1 / 3);
80
- g = hue2rgb(p, q, h);
81
- b = hue2rgb(p, q, h - 1 / 3);
82
- }
83
-
84
- const toHex = (x: number) => {
85
- const hex = Math.round(x * 255).toString(16);
86
- return hex.length === 1 ? '0' + hex : hex;
87
- };
88
-
89
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
90
- }
91
-
92
- /**
93
- * Normalize hue to 0-360 range
94
- */
95
- function normalizeHue(h: number): number {
96
- h = h % 360;
97
- return h < 0 ? h + 360 : h;
98
- }
99
-
100
- /**
101
- * Generate a color scheme based on the type
102
- */
103
- export function generateColorScheme(baseColor: string, type: ColorSchemeType): string[] {
104
- const [h, s, l] = hexToHsl(baseColor);
105
-
106
- switch (type) {
107
- case 'monochromatic':
108
- // Same hue, varying saturation and lightness
109
- return [
110
- hslToHex(h, Math.max(s - 20, 10), Math.min(l + 30, 90)),
111
- hslToHex(h, s, Math.min(l + 15, 85)),
112
- hslToHex(h, s, l), // Base
113
- hslToHex(h, Math.min(s + 10, 100), Math.max(l - 15, 15)),
114
- hslToHex(h, Math.min(s + 20, 100), Math.max(l - 30, 10)),
115
- ];
116
-
117
- case 'complementary':
118
- // Base and opposite on color wheel
119
- return [
120
- hslToHex(h, s, Math.min(l + 20, 85)),
121
- hslToHex(h, s, l), // Base
122
- hslToHex(h, s, Math.max(l - 20, 15)),
123
- hslToHex(normalizeHue(h + 180), s, Math.min(l + 10, 80)),
124
- hslToHex(normalizeHue(h + 180), s, Math.max(l - 10, 20)),
125
- ];
126
-
127
- case 'analogous':
128
- // Adjacent colors on the wheel (30° apart)
129
- return [
130
- hslToHex(normalizeHue(h - 30), s, l),
131
- hslToHex(normalizeHue(h - 15), s, l),
132
- hslToHex(h, s, l), // Base
133
- hslToHex(normalizeHue(h + 15), s, l),
134
- hslToHex(normalizeHue(h + 30), s, l),
135
- ];
136
-
137
- case 'triadic':
138
- // Three colors 120° apart
139
- return [
140
- hslToHex(h, s, l), // Base
141
- hslToHex(h, s, Math.min(l + 20, 85)),
142
- hslToHex(normalizeHue(h + 120), s, l),
143
- hslToHex(normalizeHue(h + 120), s, Math.max(l - 15, 20)),
144
- hslToHex(normalizeHue(h + 240), s, l),
145
- ];
146
-
147
- case 'split-complementary':
148
- // Base + two colors adjacent to the complement
149
- return [
150
- hslToHex(h, s, l), // Base
151
- hslToHex(h, s, Math.min(l + 20, 85)),
152
- hslToHex(normalizeHue(h + 150), s, l),
153
- hslToHex(normalizeHue(h + 180), s, Math.min(l + 15, 80)),
154
- hslToHex(normalizeHue(h + 210), s, l),
155
- ];
156
-
157
- case 'tetradic':
158
- // Four colors 90° apart (square)
159
- return [
160
- hslToHex(h, s, l), // Base
161
- hslToHex(normalizeHue(h + 90), s, l),
162
- hslToHex(normalizeHue(h + 180), s, l),
163
- hslToHex(normalizeHue(h + 270), s, l),
164
- hslToHex(h, s, Math.min(l + 25, 85)), // Lighter base
165
- ];
166
-
167
- default:
168
- return [baseColor];
169
- }
170
- }
171
-
172
- /**
173
- * Generate CSS variables for a color scheme
174
- */
175
- export function generateCssVariables(colors: string[], prefix = 'color'): Record<string, string> {
176
- const vars: Record<string, string> = {};
177
- const names = ['primary', 'secondary', 'tertiary', 'accent', 'muted'];
178
-
179
- colors.forEach((color, index) => {
180
- if (names[index]) {
181
- vars[`--${prefix}-${names[index]}`] = color;
182
- }
183
- });
184
-
185
- return vars;
186
- }
187
-
188
- /**
189
- * Check if a color is light or dark
190
- */
191
- export function isLightColor(hex: string): boolean {
192
- const [, , l] = hexToHsl(hex);
193
- return l > 50;
194
- }
195
-
196
- /**
197
- * Get a contrasting text color (black or white)
198
- */
199
- export function getContrastColor(hex: string): string {
200
- return isLightColor(hex) ? '#000000' : '#ffffff';
201
- }