@fragments-sdk/cli 0.10.0 → 0.11.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 (167) hide show
  1. package/dist/bin.js +26 -8
  2. package/dist/bin.js.map +1 -1
  3. package/dist/{chunk-ZDA3PLQ6.js → chunk-5G3VZH43.js} +2 -2
  4. package/dist/{chunk-566BNPQZ.js → chunk-HRFUSSZI.js} +25 -6
  5. package/dist/chunk-HRFUSSZI.js.map +1 -0
  6. package/dist/{chunk-CAMXG5HJ.js → chunk-ZM4ZQZWZ.js} +2 -2
  7. package/dist/{generate-BGKTKO6E.js → generate-FBHSXR3D.js} +2 -2
  8. package/dist/index.js +2 -2
  9. package/dist/{init-Q53R5Q2T.js → init-UFGK5TCN.js} +77 -6
  10. package/dist/init-UFGK5TCN.js.map +1 -0
  11. package/dist/{scan-OQU7M4GH.js → scan-CJF2DOQW.js} +3 -3
  12. package/dist/{scan-generate-T5QNUG7N.js → scan-generate-SJAN5MVI.js} +2 -2
  13. package/dist/snapshot-SV2JOFZH.js +139 -0
  14. package/dist/snapshot-SV2JOFZH.js.map +1 -0
  15. package/dist/{test-2CSOSS3B.js → test-Z5LVO724.js} +2 -2
  16. package/dist/{tokens-DXEGYTOJ.js → tokens-CE46OTMD.js} +2 -2
  17. package/dist/{viewer-DBEPYM3G.js → viewer-DLLJIMCK.js} +69 -47
  18. package/dist/viewer-DLLJIMCK.js.map +1 -0
  19. package/package.json +6 -14
  20. package/src/bin.ts +30 -0
  21. package/src/commands/init.ts +76 -1
  22. package/src/commands/snapshot.ts +197 -0
  23. package/src/core/loader.ts +38 -8
  24. package/src/viewer/__tests__/viewer-integration.test.ts +85 -74
  25. package/src/viewer/server.ts +37 -22
  26. package/src/viewer/vite-plugin.ts +25 -9
  27. package/dist/chunk-566BNPQZ.js.map +0 -1
  28. package/dist/init-Q53R5Q2T.js.map +0 -1
  29. package/dist/viewer-DBEPYM3G.js.map +0 -1
  30. package/src/viewer/__tests__/a11y-fixes.test.ts +0 -358
  31. package/src/viewer/__tests__/jsx-parser.test.ts +0 -502
  32. package/src/viewer/__tests__/render-utils.test.ts +0 -232
  33. package/src/viewer/__tests__/style-utils.test.ts +0 -404
  34. package/src/viewer/assets/fragments-logo.ts +0 -4
  35. package/src/viewer/components/AccessibilityPanel.tsx +0 -1457
  36. package/src/viewer/components/ActionCapture.tsx +0 -172
  37. package/src/viewer/components/ActionsPanel.tsx +0 -332
  38. package/src/viewer/components/AllVariantsPreview.tsx +0 -78
  39. package/src/viewer/components/App.tsx +0 -582
  40. package/src/viewer/components/BottomPanel.tsx +0 -288
  41. package/src/viewer/components/CodePanel.naming.test.tsx +0 -59
  42. package/src/viewer/components/CodePanel.tsx +0 -118
  43. package/src/viewer/components/CommandPalette.tsx +0 -392
  44. package/src/viewer/components/ComponentDocView.tsx +0 -164
  45. package/src/viewer/components/ComponentGraph.tsx +0 -380
  46. package/src/viewer/components/ComponentHeader.tsx +0 -88
  47. package/src/viewer/components/ContractPanel.tsx +0 -241
  48. package/src/viewer/components/EmptyVariantMessage.tsx +0 -54
  49. package/src/viewer/components/ErrorBoundary.tsx +0 -97
  50. package/src/viewer/components/FigmaEmbed.tsx +0 -238
  51. package/src/viewer/components/FragmentEditor.tsx +0 -525
  52. package/src/viewer/components/FragmentRenderer.tsx +0 -61
  53. package/src/viewer/components/HeaderSearch.tsx +0 -24
  54. package/src/viewer/components/HealthDashboard.tsx +0 -441
  55. package/src/viewer/components/HmrStatusIndicator.tsx +0 -61
  56. package/src/viewer/components/Icons.tsx +0 -479
  57. package/src/viewer/components/InteractionsPanel.tsx +0 -757
  58. package/src/viewer/components/IsolatedPreviewFrame.tsx +0 -346
  59. package/src/viewer/components/IsolatedRender.tsx +0 -113
  60. package/src/viewer/components/KeyboardShortcutsHelp.tsx +0 -53
  61. package/src/viewer/components/LandingPage.tsx +0 -421
  62. package/src/viewer/components/Layout.tsx +0 -27
  63. package/src/viewer/components/LeftSidebar.tsx +0 -472
  64. package/src/viewer/components/LoadErrorMessage.tsx +0 -102
  65. package/src/viewer/components/MultiViewportPreview.tsx +0 -522
  66. package/src/viewer/components/NoVariantsMessage.tsx +0 -59
  67. package/src/viewer/components/PanelShell.tsx +0 -161
  68. package/src/viewer/components/PerformancePanel.tsx +0 -304
  69. package/src/viewer/components/PreviewArea.tsx +0 -472
  70. package/src/viewer/components/PreviewAside.tsx +0 -168
  71. package/src/viewer/components/PreviewFrameHost.tsx +0 -303
  72. package/src/viewer/components/PreviewPane.tsx +0 -149
  73. package/src/viewer/components/PreviewToolbar.tsx +0 -80
  74. package/src/viewer/components/PropsEditor.tsx +0 -506
  75. package/src/viewer/components/PropsTable.tsx +0 -111
  76. package/src/viewer/components/RelationsSection.tsx +0 -88
  77. package/src/viewer/components/ResizablePanel.tsx +0 -271
  78. package/src/viewer/components/RightSidebar.tsx +0 -102
  79. package/src/viewer/components/RuntimeToolsRegistrar.tsx +0 -17
  80. package/src/viewer/components/ScreenshotButton.tsx +0 -90
  81. package/src/viewer/components/Sidebar.tsx +0 -169
  82. package/src/viewer/components/SkeletonLoader.tsx +0 -161
  83. package/src/viewer/components/ThemeProvider.tsx +0 -42
  84. package/src/viewer/components/Toast.tsx +0 -3
  85. package/src/viewer/components/TokenStylePanel.tsx +0 -699
  86. package/src/viewer/components/TopToolbar.tsx +0 -159
  87. package/src/viewer/components/UsageSection.tsx +0 -95
  88. package/src/viewer/components/VariantMatrix.tsx +0 -388
  89. package/src/viewer/components/VariantRenderer.tsx +0 -131
  90. package/src/viewer/components/VariantTabs.tsx +0 -40
  91. package/src/viewer/components/ViewerHeader.tsx +0 -69
  92. package/src/viewer/components/ViewerStateSync.tsx +0 -52
  93. package/src/viewer/components/ViewportSelector.tsx +0 -172
  94. package/src/viewer/components/WebMCPDevTools.tsx +0 -503
  95. package/src/viewer/components/WebMCPIntegration.tsx +0 -47
  96. package/src/viewer/components/WebMCPStatusIndicator.tsx +0 -60
  97. package/src/viewer/components/_future/CreatePage.tsx +0 -836
  98. package/src/viewer/components/viewer-utils.ts +0 -16
  99. package/src/viewer/composition-renderer.ts +0 -381
  100. package/src/viewer/constants/index.ts +0 -1
  101. package/src/viewer/constants/ui.ts +0 -166
  102. package/src/viewer/entry.tsx +0 -335
  103. package/src/viewer/hooks/index.ts +0 -2
  104. package/src/viewer/hooks/useA11yCache.ts +0 -383
  105. package/src/viewer/hooks/useA11yService.ts +0 -364
  106. package/src/viewer/hooks/useActions.ts +0 -138
  107. package/src/viewer/hooks/useAppState.ts +0 -147
  108. package/src/viewer/hooks/useCompiledFragments.ts +0 -42
  109. package/src/viewer/hooks/useFigmaIntegration.ts +0 -132
  110. package/src/viewer/hooks/useHmrStatus.ts +0 -109
  111. package/src/viewer/hooks/useKeyboardShortcuts.ts +0 -270
  112. package/src/viewer/hooks/usePreviewBridge.ts +0 -347
  113. package/src/viewer/hooks/useScrollSpy.ts +0 -78
  114. package/src/viewer/hooks/useUrlState.ts +0 -318
  115. package/src/viewer/hooks/useViewSettings.ts +0 -111
  116. package/src/viewer/index.html +0 -28
  117. package/src/viewer/intelligence/healthReport.ts +0 -505
  118. package/src/viewer/intelligence/styleDrift.ts +0 -340
  119. package/src/viewer/intelligence/usageScanner.ts +0 -309
  120. package/src/viewer/jsx-parser.ts +0 -486
  121. package/src/viewer/preview-frame-entry.tsx +0 -25
  122. package/src/viewer/preview-frame.html +0 -125
  123. package/src/viewer/public/favicon.ico +0 -0
  124. package/src/viewer/render-template.html +0 -68
  125. package/src/viewer/styles/globals.css +0 -278
  126. package/src/viewer/types/a11y.ts +0 -197
  127. package/src/viewer/utils/a11y-fixes.ts +0 -509
  128. package/src/viewer/utils/actionExport.ts +0 -372
  129. package/src/viewer/utils/colorSchemes.ts +0 -201
  130. package/src/viewer/utils/detectRelationships.ts +0 -256
  131. package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss +0 -10
  132. package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss.d.ts +0 -2
  133. package/src/viewer/vendor/shared/src/ComponentDocContent.tsx +0 -274
  134. package/src/viewer/vendor/shared/src/DocsHeaderBar.tsx +0 -129
  135. package/src/viewer/vendor/shared/src/DocsPageAsideHost.tsx +0 -89
  136. package/src/viewer/vendor/shared/src/DocsPageShell.tsx +0 -124
  137. package/src/viewer/vendor/shared/src/DocsSearchCommand.tsx +0 -99
  138. package/src/viewer/vendor/shared/src/DocsSidebarNav.tsx +0 -66
  139. package/src/viewer/vendor/shared/src/PropsTable.module.scss +0 -68
  140. package/src/viewer/vendor/shared/src/PropsTable.module.scss.d.ts +0 -2
  141. package/src/viewer/vendor/shared/src/PropsTable.tsx +0 -76
  142. package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss +0 -114
  143. package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss.d.ts +0 -2
  144. package/src/viewer/vendor/shared/src/VariantPreviewCard.tsx +0 -134
  145. package/src/viewer/vendor/shared/src/docs-data/index.ts +0 -32
  146. package/src/viewer/vendor/shared/src/docs-data/mcp-configs.ts +0 -72
  147. package/src/viewer/vendor/shared/src/docs-data/palettes.ts +0 -75
  148. package/src/viewer/vendor/shared/src/docs-data/setup-examples.ts +0 -55
  149. package/src/viewer/vendor/shared/src/docs-layout.scss +0 -28
  150. package/src/viewer/vendor/shared/src/docs-layout.scss.d.ts +0 -2
  151. package/src/viewer/vendor/shared/src/index.ts +0 -34
  152. package/src/viewer/vendor/shared/src/types.ts +0 -53
  153. package/src/viewer/webmcp/__tests__/analytics.test.ts +0 -108
  154. package/src/viewer/webmcp/analytics.ts +0 -165
  155. package/src/viewer/webmcp/index.ts +0 -3
  156. package/src/viewer/webmcp/posthog-bridge.ts +0 -39
  157. package/src/viewer/webmcp/runtime-tools.ts +0 -152
  158. package/src/viewer/webmcp/scan-utils.ts +0 -135
  159. package/src/viewer/webmcp/use-tool-analytics.ts +0 -69
  160. package/src/viewer/webmcp/viewer-state.ts +0 -45
  161. /package/dist/{chunk-ZDA3PLQ6.js.map → chunk-5G3VZH43.js.map} +0 -0
  162. /package/dist/{chunk-CAMXG5HJ.js.map → chunk-ZM4ZQZWZ.js.map} +0 -0
  163. /package/dist/{generate-BGKTKO6E.js.map → generate-FBHSXR3D.js.map} +0 -0
  164. /package/dist/{scan-OQU7M4GH.js.map → scan-CJF2DOQW.js.map} +0 -0
  165. /package/dist/{scan-generate-T5QNUG7N.js.map → scan-generate-SJAN5MVI.js.map} +0 -0
  166. /package/dist/{test-2CSOSS3B.js.map → test-Z5LVO724.js.map} +0 -0
  167. /package/dist/{tokens-DXEGYTOJ.js.map → tokens-CE46OTMD.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
- }