@fragments-sdk/viewer 0.2.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 (141) hide show
  1. package/LICENSE +84 -0
  2. package/index.html +28 -0
  3. package/package.json +71 -0
  4. package/src/__tests__/a11y-fixes.test.ts +358 -0
  5. package/src/__tests__/jsx-parser.test.ts +502 -0
  6. package/src/__tests__/render-utils.test.ts +232 -0
  7. package/src/__tests__/style-utils.test.ts +404 -0
  8. package/src/app/index.ts +1 -0
  9. package/src/assets/fragments-logo.ts +4 -0
  10. package/src/assets/fragments_logo.png +0 -0
  11. package/src/components/AccessibilityPanel.tsx +1457 -0
  12. package/src/components/ActionCapture.tsx +172 -0
  13. package/src/components/ActionsPanel.tsx +332 -0
  14. package/src/components/AllVariantsPreview.tsx +78 -0
  15. package/src/components/App.tsx +604 -0
  16. package/src/components/BottomPanel.tsx +288 -0
  17. package/src/components/CodePanel.naming.test.tsx +59 -0
  18. package/src/components/CodePanel.tsx +118 -0
  19. package/src/components/CommandPalette.tsx +392 -0
  20. package/src/components/ComponentDocView.tsx +164 -0
  21. package/src/components/ComponentGraph.tsx +380 -0
  22. package/src/components/ComponentHeader.tsx +88 -0
  23. package/src/components/ContractPanel.tsx +241 -0
  24. package/src/components/DeviceMockup.tsx +156 -0
  25. package/src/components/EmptyVariantMessage.tsx +54 -0
  26. package/src/components/ErrorBoundary.tsx +97 -0
  27. package/src/components/FigmaEmbed.tsx +238 -0
  28. package/src/components/FragmentEditor.tsx +525 -0
  29. package/src/components/FragmentRenderer.tsx +61 -0
  30. package/src/components/HeaderSearch.tsx +24 -0
  31. package/src/components/HealthDashboard.tsx +441 -0
  32. package/src/components/HmrStatusIndicator.tsx +61 -0
  33. package/src/components/Icons.tsx +479 -0
  34. package/src/components/InteractionsPanel.tsx +757 -0
  35. package/src/components/IsolatedPreviewFrame.tsx +390 -0
  36. package/src/components/IsolatedRender.tsx +113 -0
  37. package/src/components/KeyboardShortcutsHelp.tsx +53 -0
  38. package/src/components/LandingPage.tsx +420 -0
  39. package/src/components/Layout.tsx +27 -0
  40. package/src/components/LeftSidebar.tsx +472 -0
  41. package/src/components/LoadErrorMessage.tsx +102 -0
  42. package/src/components/MultiViewportPreview.tsx +527 -0
  43. package/src/components/NoVariantsMessage.tsx +59 -0
  44. package/src/components/PanelShell.tsx +161 -0
  45. package/src/components/PerformancePanel.tsx +304 -0
  46. package/src/components/PreviewArea.tsx +254 -0
  47. package/src/components/PreviewAside.tsx +168 -0
  48. package/src/components/PreviewFrameHost.tsx +304 -0
  49. package/src/components/PreviewToolbar.tsx +80 -0
  50. package/src/components/PropsEditor.tsx +506 -0
  51. package/src/components/PropsTable.tsx +111 -0
  52. package/src/components/RelationsSection.tsx +88 -0
  53. package/src/components/ResizablePanel.tsx +271 -0
  54. package/src/components/RightSidebar.tsx +102 -0
  55. package/src/components/RuntimeToolsRegistrar.tsx +17 -0
  56. package/src/components/ScreenshotButton.tsx +90 -0
  57. package/src/components/ShadowPreview.tsx +204 -0
  58. package/src/components/Sidebar.tsx +169 -0
  59. package/src/components/SkeletonLoader.tsx +161 -0
  60. package/src/components/ThemeProvider.tsx +42 -0
  61. package/src/components/Toast.tsx +3 -0
  62. package/src/components/TokenStylePanel.tsx +699 -0
  63. package/src/components/TopToolbar.tsx +159 -0
  64. package/src/components/Untitled +1 -0
  65. package/src/components/UsageSection.tsx +95 -0
  66. package/src/components/VariantMatrix.tsx +391 -0
  67. package/src/components/VariantRenderer.tsx +131 -0
  68. package/src/components/VariantTabs.tsx +40 -0
  69. package/src/components/ViewerHeader.tsx +69 -0
  70. package/src/components/ViewerStateSync.tsx +52 -0
  71. package/src/components/ViewportSelector.tsx +172 -0
  72. package/src/components/WebMCPDevTools.tsx +503 -0
  73. package/src/components/WebMCPIntegration.tsx +47 -0
  74. package/src/components/WebMCPStatusIndicator.tsx +60 -0
  75. package/src/components/_future/CreatePage.tsx +835 -0
  76. package/src/components/viewer-utils.ts +16 -0
  77. package/src/composition-renderer.ts +381 -0
  78. package/src/constants/index.ts +1 -0
  79. package/src/constants/ui.ts +166 -0
  80. package/src/entry.tsx +335 -0
  81. package/src/hooks/index.ts +2 -0
  82. package/src/hooks/useA11yCache.ts +383 -0
  83. package/src/hooks/useA11yService.ts +364 -0
  84. package/src/hooks/useActions.ts +138 -0
  85. package/src/hooks/useAppState.ts +147 -0
  86. package/src/hooks/useCompiledFragments.ts +42 -0
  87. package/src/hooks/useFigmaIntegration.ts +132 -0
  88. package/src/hooks/useHmrStatus.ts +109 -0
  89. package/src/hooks/useKeyboardShortcuts.ts +270 -0
  90. package/src/hooks/usePreviewBridge.ts +347 -0
  91. package/src/hooks/useScrollSpy.ts +78 -0
  92. package/src/hooks/useShadowStyles.ts +221 -0
  93. package/src/hooks/useUrlState.ts +318 -0
  94. package/src/hooks/useViewSettings.ts +111 -0
  95. package/src/intelligence/healthReport.ts +505 -0
  96. package/src/intelligence/styleDrift.ts +340 -0
  97. package/src/intelligence/usageScanner.ts +309 -0
  98. package/src/jsx-parser.ts +486 -0
  99. package/src/preview-frame-entry.tsx +25 -0
  100. package/src/preview-frame.html +148 -0
  101. package/src/render-template.html +68 -0
  102. package/src/render-utils.ts +311 -0
  103. package/src/shared/ComponentDocContent.module.scss +10 -0
  104. package/src/shared/ComponentDocContent.module.scss.d.ts +2 -0
  105. package/src/shared/ComponentDocContent.tsx +274 -0
  106. package/src/shared/DocsHeaderBar.tsx +129 -0
  107. package/src/shared/DocsPageAsideHost.tsx +89 -0
  108. package/src/shared/DocsPageShell.tsx +124 -0
  109. package/src/shared/DocsSearchCommand.tsx +99 -0
  110. package/src/shared/DocsSidebarNav.tsx +66 -0
  111. package/src/shared/PropsTable.module.scss +68 -0
  112. package/src/shared/PropsTable.module.scss.d.ts +2 -0
  113. package/src/shared/PropsTable.tsx +76 -0
  114. package/src/shared/VariantPreviewCard.module.scss +114 -0
  115. package/src/shared/VariantPreviewCard.module.scss.d.ts +2 -0
  116. package/src/shared/VariantPreviewCard.tsx +137 -0
  117. package/src/shared/docs-data/index.ts +32 -0
  118. package/src/shared/docs-data/mcp-configs.ts +72 -0
  119. package/src/shared/docs-data/palettes.ts +75 -0
  120. package/src/shared/docs-data/setup-examples.ts +55 -0
  121. package/src/shared/docs-layout.scss +28 -0
  122. package/src/shared/docs-layout.scss.d.ts +2 -0
  123. package/src/shared/index.ts +34 -0
  124. package/src/shared/types.ts +53 -0
  125. package/src/style-utils.ts +414 -0
  126. package/src/styles/globals.css +278 -0
  127. package/src/types/a11y.ts +197 -0
  128. package/src/utils/a11y-fixes.ts +509 -0
  129. package/src/utils/actionExport.ts +372 -0
  130. package/src/utils/colorSchemes.ts +201 -0
  131. package/src/utils/contrast.ts +246 -0
  132. package/src/utils/detectRelationships.ts +256 -0
  133. package/src/webmcp/__tests__/analytics.test.ts +108 -0
  134. package/src/webmcp/analytics.ts +165 -0
  135. package/src/webmcp/index.ts +3 -0
  136. package/src/webmcp/posthog-bridge.ts +39 -0
  137. package/src/webmcp/runtime-tools.ts +152 -0
  138. package/src/webmcp/scan-utils.ts +135 -0
  139. package/src/webmcp/use-tool-analytics.ts +69 -0
  140. package/src/webmcp/viewer-state.ts +45 -0
  141. package/tsconfig.json +20 -0
@@ -0,0 +1,527 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Multi-Viewport Preview - Show component at multiple sizes simultaneously
4
+ *
5
+ * Displays the component at mobile, tablet, and desktop widths
6
+ * with proper device mockups and horizontal scrolling.
7
+ */
8
+
9
+ import { useState, type ReactNode } from "react";
10
+ import { Box, Stack, Text, Button, Menu } from "@fragments-sdk/ui";
11
+ import { ErrorBoundary } from "./ErrorBoundary.js";
12
+ import { IsolatedPreviewFrame } from "./IsolatedPreviewFrame.js";
13
+ import { ShadowPreview } from "./ShadowPreview.js";
14
+ import { ChevronDownIcon } from "./Icons.js";
15
+
16
+ interface ViewportConfig {
17
+ name: string;
18
+ width: number;
19
+ height: number;
20
+ type: "mobile" | "tablet" | "desktop";
21
+ }
22
+
23
+ interface MobilePreset {
24
+ name: string;
25
+ width: number;
26
+ height: number;
27
+ }
28
+
29
+ const MOBILE_PRESETS: MobilePreset[] = [
30
+ { name: "iPhone SE", width: 375, height: 667 },
31
+ { name: "iPhone 14", width: 390, height: 844 },
32
+ { name: "iPhone 14 Pro Max", width: 430, height: 932 },
33
+ { name: "Pixel 7", width: 412, height: 915 },
34
+ { name: "Galaxy S21", width: 360, height: 800 },
35
+ ];
36
+
37
+ const DEFAULT_VIEWPORTS: ViewportConfig[] = [
38
+ { name: "Mobile", width: 375, height: 667, type: "mobile" },
39
+ { name: "Tablet", width: 768, height: 1024, type: "tablet" },
40
+ { name: "Desktop", width: 1280, height: 800, type: "desktop" },
41
+ ];
42
+
43
+ interface MultiViewportPreviewProps {
44
+ /** Component name for error boundary */
45
+ componentName: string;
46
+ /** Fragment path for iframe rendering */
47
+ fragmentPath: string;
48
+ /** Variant name for iframe rendering */
49
+ variantName: string;
50
+ /** Render function that returns the component (fallback) */
51
+ renderContent: () => ReactNode;
52
+ /** Preview theme */
53
+ previewTheme: "light" | "dark";
54
+ /** Base zoom level (used for scaling if needed) */
55
+ zoom: number;
56
+ /** Whether to use iframe isolation */
57
+ useIframeIsolation?: boolean;
58
+ }
59
+
60
+ export function MultiViewportPreview({
61
+ componentName,
62
+ fragmentPath,
63
+ variantName,
64
+ renderContent,
65
+ previewTheme,
66
+ zoom,
67
+ useIframeIsolation = true,
68
+ }: MultiViewportPreviewProps) {
69
+ const [selectedMobile, setSelectedMobile] = useState<MobilePreset>(MOBILE_PRESETS[0]);
70
+
71
+ // Build viewports with selected mobile preset
72
+ const viewports: ViewportConfig[] = [
73
+ { name: "Mobile", width: selectedMobile.width, height: selectedMobile.height, type: "mobile" },
74
+ { name: "Tablet", width: 768, height: 1024, type: "tablet" },
75
+ { name: "Desktop", width: 1280, height: 800, type: "desktop" },
76
+ ];
77
+
78
+ return (
79
+ <Box height="100%" display="flex" style={{ flexDirection: 'column' }} background="primary">
80
+ {/* Header */}
81
+ <Box paddingX="md" paddingY="sm" borderBottom background="secondary" style={{ flexShrink: 0 }}>
82
+ <Stack direction="row" align="center" justify="center" gap="lg">
83
+ {/* Mobile with dropdown */}
84
+ <Menu>
85
+ <Menu.Trigger>
86
+ <Button variant="ghost" size="sm">
87
+ <span style={{ fontSize: 18 }}>📱</span>
88
+ <Text size="sm" weight="medium" color="secondary">Mobile</Text>
89
+ <Text size="xs" color="tertiary">({selectedMobile.width}px)</Text>
90
+ <ChevronDownIcon style={{ width: 12, height: 12 }} />
91
+ </Button>
92
+ </Menu.Trigger>
93
+ <Menu.Content>
94
+ {MOBILE_PRESETS.map((preset) => (
95
+ <Menu.Item
96
+ key={preset.name}
97
+ onClick={() => setSelectedMobile(preset)}
98
+ >
99
+ <Stack direction="row" justify="between" style={{ width: '100%' }}>
100
+ <Text size="xs">{preset.name}</Text>
101
+ <Text size="xs" color="tertiary">{preset.width}×{preset.height}</Text>
102
+ </Stack>
103
+ </Menu.Item>
104
+ ))}
105
+ </Menu.Content>
106
+ </Menu>
107
+
108
+ {/* Tablet */}
109
+ <Stack direction="row" align="center" gap="sm">
110
+ <span style={{ fontSize: 18 }}>📱</span>
111
+ <Text size="sm" weight="medium" color="secondary">Tablet</Text>
112
+ <Text size="xs" color="tertiary">(768px)</Text>
113
+ </Stack>
114
+
115
+ {/* Desktop */}
116
+ <Stack direction="row" align="center" gap="sm">
117
+ <span style={{ fontSize: 18 }}>🖥️</span>
118
+ <Text size="sm" weight="medium" color="secondary">Desktop</Text>
119
+ <Text size="xs" color="tertiary">(1280px)</Text>
120
+ </Stack>
121
+ </Stack>
122
+ </Box>
123
+
124
+ {/* Viewport panels with horizontal scroll */}
125
+ <Box overflow="auto" style={{ flex: 1 }}>
126
+ <Stack direction="row" gap="lg" style={{ padding: 32, minWidth: 'max-content' }}>
127
+ {viewports.map((vp) => (
128
+ <ViewportPanel
129
+ key={`${vp.name}-${vp.width}`}
130
+ viewport={vp}
131
+ componentName={componentName}
132
+ fragmentPath={fragmentPath}
133
+ variantName={variantName}
134
+ renderContent={renderContent}
135
+ previewTheme={previewTheme}
136
+ useIframeIsolation={useIframeIsolation}
137
+ />
138
+ ))}
139
+ </Stack>
140
+ </Box>
141
+ </Box>
142
+ );
143
+ }
144
+
145
+ interface ViewportPanelProps {
146
+ viewport: ViewportConfig;
147
+ componentName: string;
148
+ fragmentPath: string;
149
+ variantName: string;
150
+ renderContent: () => ReactNode;
151
+ previewTheme: "light" | "dark";
152
+ useIframeIsolation: boolean;
153
+ }
154
+
155
+ function ViewportPanel({
156
+ viewport,
157
+ componentName,
158
+ fragmentPath,
159
+ variantName,
160
+ renderContent,
161
+ previewTheme,
162
+ useIframeIsolation,
163
+ }: ViewportPanelProps) {
164
+ if (viewport.type === "desktop") {
165
+ return (
166
+ <DesktopMockup
167
+ width={viewport.width}
168
+ height={viewport.height}
169
+ label={viewport.name}
170
+ previewTheme={previewTheme}
171
+ componentName={componentName}
172
+ fragmentPath={fragmentPath}
173
+ variantName={variantName}
174
+ renderContent={renderContent}
175
+ useIframeIsolation={useIframeIsolation}
176
+ />
177
+ );
178
+ }
179
+
180
+ return (
181
+ <DeviceMockup
182
+ type={viewport.type}
183
+ width={viewport.width}
184
+ height={viewport.height}
185
+ label={viewport.name}
186
+ previewTheme={previewTheme}
187
+ componentName={componentName}
188
+ fragmentPath={fragmentPath}
189
+ variantName={variantName}
190
+ renderContent={renderContent}
191
+ useIframeIsolation={useIframeIsolation}
192
+ />
193
+ );
194
+ }
195
+
196
+ interface DeviceMockupProps {
197
+ type: "mobile" | "tablet";
198
+ width: number;
199
+ height: number;
200
+ label: string;
201
+ previewTheme: "light" | "dark";
202
+ componentName: string;
203
+ fragmentPath: string;
204
+ variantName: string;
205
+ renderContent: () => ReactNode;
206
+ useIframeIsolation: boolean;
207
+ }
208
+
209
+ function DeviceMockup({
210
+ type,
211
+ width,
212
+ height,
213
+ label,
214
+ previewTheme,
215
+ componentName,
216
+ fragmentPath,
217
+ variantName,
218
+ renderContent,
219
+ useIframeIsolation,
220
+ }: DeviceMockupProps) {
221
+ const isMobile = type === "mobile";
222
+ const frameWidth = width + 24; // Add bezel width
223
+ const screenHeight = height;
224
+
225
+ return (
226
+ <Stack align="center">
227
+ {/* Label */}
228
+ <Text size="sm" weight="medium" color="tertiary" style={{ marginBottom: 12 }}>
229
+ {label}
230
+ </Text>
231
+
232
+ {/* Device frame */}
233
+ <div
234
+ style={{
235
+ position: 'relative',
236
+ flexShrink: 0,
237
+ width: `${frameWidth}px`,
238
+ }}
239
+ >
240
+ <div
241
+ style={{
242
+ position: 'relative',
243
+ borderRadius: 40,
244
+ background: '#1a1a1a',
245
+ padding: 12,
246
+ boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.1)',
247
+ }}
248
+ >
249
+ {/* Side buttons (mobile only) */}
250
+ {isMobile && (
251
+ <>
252
+ <div style={{
253
+ position: 'absolute',
254
+ left: -3,
255
+ top: 96,
256
+ width: 3,
257
+ height: 32,
258
+ background: '#2a2a2a',
259
+ borderRadius: '4px 0 0 4px',
260
+ }} />
261
+ <div style={{
262
+ position: 'absolute',
263
+ left: -3,
264
+ top: 144,
265
+ width: 3,
266
+ height: 48,
267
+ background: '#2a2a2a',
268
+ borderRadius: '4px 0 0 4px',
269
+ }} />
270
+ <div style={{
271
+ position: 'absolute',
272
+ left: -3,
273
+ top: 208,
274
+ width: 3,
275
+ height: 48,
276
+ background: '#2a2a2a',
277
+ borderRadius: '4px 0 0 4px',
278
+ }} />
279
+ <div style={{
280
+ position: 'absolute',
281
+ right: -3,
282
+ top: 128,
283
+ width: 3,
284
+ height: 64,
285
+ background: '#2a2a2a',
286
+ borderRadius: '0 4px 4px 0',
287
+ }} />
288
+ </>
289
+ )}
290
+
291
+ {/* Screen container */}
292
+ <div
293
+ style={{
294
+ position: 'relative',
295
+ borderRadius: 32,
296
+ overflow: 'hidden',
297
+ background: '#ffffff',
298
+ height: `${screenHeight}px`,
299
+ width: `${width}px`,
300
+ }}
301
+ >
302
+ {/* Notch (mobile) or Camera (tablet) */}
303
+ {isMobile ? (
304
+ <div style={{
305
+ position: 'absolute',
306
+ top: 0,
307
+ left: '50%',
308
+ transform: 'translateX(-50%)',
309
+ width: 120,
310
+ height: 30,
311
+ background: '#1a1a1a',
312
+ borderRadius: '0 0 16px 16px',
313
+ zIndex: 10,
314
+ display: 'flex',
315
+ alignItems: 'center',
316
+ justifyContent: 'center',
317
+ gap: 8,
318
+ }}>
319
+ <div style={{ width: 8, height: 8, borderRadius: '50%', background: '#2a2a2a' }} />
320
+ <div style={{ width: 48, height: 6, borderRadius: 9999, background: '#2a2a2a' }} />
321
+ </div>
322
+ ) : (
323
+ <div style={{
324
+ position: 'absolute',
325
+ top: 8,
326
+ left: '50%',
327
+ transform: 'translateX(-50%)',
328
+ width: 12,
329
+ height: 12,
330
+ borderRadius: '50%',
331
+ background: '#2a2a2a',
332
+ zIndex: 10,
333
+ }} />
334
+ )}
335
+
336
+ {/* Screen content */}
337
+ <div
338
+ style={{ width: '100%', height: '100%', overflow: 'hidden' }}
339
+ data-theme={previewTheme}
340
+ >
341
+ {useIframeIsolation ? (
342
+ <IsolatedPreviewFrame
343
+ fragmentPath={fragmentPath}
344
+ variantName={variantName}
345
+ theme={previewTheme}
346
+ width="100%"
347
+ height="100%"
348
+ minHeight={screenHeight}
349
+ />
350
+ ) : (
351
+ <ShadowPreview theme={previewTheme} width="100%" height="100%" minHeight={screenHeight}>
352
+ <div style={{
353
+ paddingTop: isMobile ? 40 : 24,
354
+ paddingLeft: 16,
355
+ paddingRight: 16,
356
+ paddingBottom: 16,
357
+ }}>
358
+ <ErrorBoundary
359
+ componentName={componentName}
360
+ fallback={
361
+ <Text size="xs" color="tertiary" style={{ padding: 8 }}>
362
+ Error rendering at {width}px
363
+ </Text>
364
+ }
365
+ >
366
+ {renderContent()}
367
+ </ErrorBoundary>
368
+ </div>
369
+ </ShadowPreview>
370
+ )}
371
+ </div>
372
+
373
+ {/* Home indicator */}
374
+ <div style={{
375
+ position: 'absolute',
376
+ bottom: 8,
377
+ left: '50%',
378
+ transform: 'translateX(-50%)',
379
+ width: 100,
380
+ height: 4,
381
+ background: 'rgba(0,0,0,0.2)',
382
+ borderRadius: 9999,
383
+ zIndex: 10,
384
+ }} />
385
+ </div>
386
+ </div>
387
+ </div>
388
+ </Stack>
389
+ );
390
+ }
391
+
392
+ interface DesktopMockupProps {
393
+ width: number;
394
+ height: number;
395
+ label: string;
396
+ previewTheme: "light" | "dark";
397
+ componentName: string;
398
+ fragmentPath: string;
399
+ variantName: string;
400
+ renderContent: () => ReactNode;
401
+ useIframeIsolation: boolean;
402
+ }
403
+
404
+ function DesktopMockup({
405
+ width,
406
+ height,
407
+ label,
408
+ previewTheme,
409
+ componentName,
410
+ fragmentPath,
411
+ variantName,
412
+ renderContent,
413
+ useIframeIsolation,
414
+ }: DesktopMockupProps) {
415
+ return (
416
+ <Stack align="center">
417
+ {/* Label */}
418
+ <Text size="sm" weight="medium" color="tertiary" style={{ marginBottom: 12 }}>
419
+ {label}
420
+ </Text>
421
+
422
+ {/* Monitor frame */}
423
+ <Stack align="center">
424
+ {/* Screen */}
425
+ <div
426
+ style={{
427
+ position: 'relative',
428
+ background: '#1a1a1a',
429
+ borderRadius: 8,
430
+ padding: 8,
431
+ boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.1)',
432
+ }}
433
+ >
434
+ {/* Browser chrome */}
435
+ <div style={{
436
+ display: 'flex',
437
+ alignItems: 'center',
438
+ gap: 8,
439
+ padding: '8px 12px',
440
+ background: '#2a2a2a',
441
+ borderRadius: '6px 6px 0 0',
442
+ }}>
443
+ <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
444
+ <div style={{ width: 12, height: 12, borderRadius: '50%', background: '#ff5f57' }} />
445
+ <div style={{ width: 12, height: 12, borderRadius: '50%', background: '#ffbd2e' }} />
446
+ <div style={{ width: 12, height: 12, borderRadius: '50%', background: '#28ca41' }} />
447
+ </div>
448
+ <div style={{ flex: 1, margin: '0 16px' }}>
449
+ <div style={{
450
+ height: 24,
451
+ background: '#3a3a3a',
452
+ borderRadius: 6,
453
+ display: 'flex',
454
+ alignItems: 'center',
455
+ justifyContent: 'center',
456
+ padding: '0 12px',
457
+ }}>
458
+ <span style={{
459
+ fontSize: 12,
460
+ color: '#9ca3af',
461
+ overflow: 'hidden',
462
+ textOverflow: 'ellipsis',
463
+ whiteSpace: 'nowrap',
464
+ }}>
465
+ localhost:6006 — {width}px
466
+ </span>
467
+ </div>
468
+ </div>
469
+ </div>
470
+
471
+ {/* Screen content */}
472
+ <div
473
+ style={{
474
+ overflow: 'hidden',
475
+ width: `${width}px`,
476
+ height: `${height}px`,
477
+ }}
478
+ data-theme={previewTheme}
479
+ >
480
+ {useIframeIsolation ? (
481
+ <IsolatedPreviewFrame
482
+ fragmentPath={fragmentPath}
483
+ variantName={variantName}
484
+ theme={previewTheme}
485
+ width="100%"
486
+ height="100%"
487
+ minHeight={height}
488
+ />
489
+ ) : (
490
+ <ShadowPreview theme={previewTheme} width="100%" height="100%" minHeight={height}>
491
+ <div style={{ padding: 24 }}>
492
+ <ErrorBoundary
493
+ componentName={componentName}
494
+ fallback={
495
+ <Text size="xs" color="tertiary" style={{ padding: 8 }}>
496
+ Error rendering at {width}px
497
+ </Text>
498
+ }
499
+ >
500
+ {renderContent()}
501
+ </ErrorBoundary>
502
+ </div>
503
+ </ShadowPreview>
504
+ )}
505
+ </div>
506
+ </div>
507
+
508
+ {/* Monitor stand */}
509
+ <div style={{
510
+ width: 80,
511
+ height: 16,
512
+ background: 'linear-gradient(to bottom, #2a2a2a, #1a1a1a)',
513
+ borderRadius: '0 0 2px 2px',
514
+ }} />
515
+ <div style={{
516
+ width: 128,
517
+ height: 8,
518
+ background: '#1a1a1a',
519
+ borderRadius: 9999,
520
+ boxShadow: '0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1)',
521
+ }} />
522
+ </Stack>
523
+ </Stack>
524
+ );
525
+ }
526
+
527
+ export { DEFAULT_VIEWPORTS as VIEWPORTS, MOBILE_PRESETS };
@@ -0,0 +1,59 @@
1
+ import type { FragmentDefinition } from '@fragments-sdk/core';
2
+ import { Stack, Text, Alert, EmptyState } from "@fragments-sdk/ui";
3
+ import { LoadErrorMessage } from "./LoadErrorMessage.js";
4
+
5
+ interface NoVariantsMessageProps {
6
+ fragment?: FragmentDefinition;
7
+ }
8
+
9
+ export function NoVariantsMessage({ fragment }: NoVariantsMessageProps) {
10
+ // Check for load error (missing dependencies, schema errors, etc.)
11
+ const loadError = (fragment as any)?._loadError;
12
+ if (loadError) {
13
+ return <LoadErrorMessage error={loadError} componentName={fragment?.meta?.name} />;
14
+ }
15
+
16
+ const skippedVariants = (fragment?._generated as any)?.skippedVariants;
17
+
18
+ if (!skippedVariants || skippedVariants.length === 0) {
19
+ return (
20
+ <EmptyState style={{ height: "100%" }}>
21
+ <EmptyState.Description>No variants defined</EmptyState.Description>
22
+ </EmptyState>
23
+ );
24
+ }
25
+
26
+ return (
27
+ <Stack align="center" justify="center" style={{ height: "100%", padding: "24px" }}>
28
+ <Alert variant="info">
29
+ <Alert.Body>
30
+ <Alert.Title>
31
+ {skippedVariants.length} variant{skippedVariants.length === 1 ? "" : "s"} skipped
32
+ </Alert.Title>
33
+ <Alert.Content>
34
+ <Stack direction="column" gap="sm">
35
+ <Text size="xs" color="secondary">
36
+ These variants couldn't be rendered because they use syntax the parser doesn't
37
+ support yet:
38
+ </Text>
39
+ <ul style={{ marginTop: "4px", marginLeft: "16px", listStyleType: "disc" }}>
40
+ {skippedVariants.map((sv: any, i: number) => (
41
+ <li key={i}>
42
+ <Text size="xs" color="secondary">
43
+ <Text as="span" size="xs" weight="semibold">
44
+ {sv.name}:
45
+ </Text>{" "}
46
+ <Text as="span" size="xs" color="tertiary">
47
+ {sv.reason}
48
+ </Text>
49
+ </Text>
50
+ </li>
51
+ ))}
52
+ </ul>
53
+ </Stack>
54
+ </Alert.Content>
55
+ </Alert.Body>
56
+ </Alert>
57
+ </Stack>
58
+ );
59
+ }