@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.
- package/dist/bin.js +26 -8
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-ZDA3PLQ6.js → chunk-5G3VZH43.js} +2 -2
- package/dist/{chunk-566BNPQZ.js → chunk-HRFUSSZI.js} +25 -6
- package/dist/chunk-HRFUSSZI.js.map +1 -0
- package/dist/{chunk-CAMXG5HJ.js → chunk-ZM4ZQZWZ.js} +2 -2
- package/dist/{generate-BGKTKO6E.js → generate-FBHSXR3D.js} +2 -2
- package/dist/index.js +2 -2
- package/dist/{init-Q53R5Q2T.js → init-UFGK5TCN.js} +77 -6
- package/dist/init-UFGK5TCN.js.map +1 -0
- package/dist/{scan-OQU7M4GH.js → scan-CJF2DOQW.js} +3 -3
- package/dist/{scan-generate-T5QNUG7N.js → scan-generate-SJAN5MVI.js} +2 -2
- package/dist/snapshot-SV2JOFZH.js +139 -0
- package/dist/snapshot-SV2JOFZH.js.map +1 -0
- package/dist/{test-2CSOSS3B.js → test-Z5LVO724.js} +2 -2
- package/dist/{tokens-DXEGYTOJ.js → tokens-CE46OTMD.js} +2 -2
- package/dist/{viewer-DBEPYM3G.js → viewer-DLLJIMCK.js} +69 -47
- package/dist/viewer-DLLJIMCK.js.map +1 -0
- package/package.json +6 -14
- package/src/bin.ts +30 -0
- package/src/commands/init.ts +76 -1
- package/src/commands/snapshot.ts +197 -0
- package/src/core/loader.ts +38 -8
- package/src/viewer/__tests__/viewer-integration.test.ts +85 -74
- package/src/viewer/server.ts +37 -22
- package/src/viewer/vite-plugin.ts +25 -9
- package/dist/chunk-566BNPQZ.js.map +0 -1
- package/dist/init-Q53R5Q2T.js.map +0 -1
- package/dist/viewer-DBEPYM3G.js.map +0 -1
- package/src/viewer/__tests__/a11y-fixes.test.ts +0 -358
- package/src/viewer/__tests__/jsx-parser.test.ts +0 -502
- package/src/viewer/__tests__/render-utils.test.ts +0 -232
- package/src/viewer/__tests__/style-utils.test.ts +0 -404
- package/src/viewer/assets/fragments-logo.ts +0 -4
- package/src/viewer/components/AccessibilityPanel.tsx +0 -1457
- package/src/viewer/components/ActionCapture.tsx +0 -172
- package/src/viewer/components/ActionsPanel.tsx +0 -332
- package/src/viewer/components/AllVariantsPreview.tsx +0 -78
- package/src/viewer/components/App.tsx +0 -582
- package/src/viewer/components/BottomPanel.tsx +0 -288
- package/src/viewer/components/CodePanel.naming.test.tsx +0 -59
- package/src/viewer/components/CodePanel.tsx +0 -118
- package/src/viewer/components/CommandPalette.tsx +0 -392
- package/src/viewer/components/ComponentDocView.tsx +0 -164
- package/src/viewer/components/ComponentGraph.tsx +0 -380
- package/src/viewer/components/ComponentHeader.tsx +0 -88
- package/src/viewer/components/ContractPanel.tsx +0 -241
- package/src/viewer/components/EmptyVariantMessage.tsx +0 -54
- package/src/viewer/components/ErrorBoundary.tsx +0 -97
- package/src/viewer/components/FigmaEmbed.tsx +0 -238
- package/src/viewer/components/FragmentEditor.tsx +0 -525
- package/src/viewer/components/FragmentRenderer.tsx +0 -61
- package/src/viewer/components/HeaderSearch.tsx +0 -24
- package/src/viewer/components/HealthDashboard.tsx +0 -441
- package/src/viewer/components/HmrStatusIndicator.tsx +0 -61
- package/src/viewer/components/Icons.tsx +0 -479
- package/src/viewer/components/InteractionsPanel.tsx +0 -757
- package/src/viewer/components/IsolatedPreviewFrame.tsx +0 -346
- package/src/viewer/components/IsolatedRender.tsx +0 -113
- package/src/viewer/components/KeyboardShortcutsHelp.tsx +0 -53
- package/src/viewer/components/LandingPage.tsx +0 -421
- package/src/viewer/components/Layout.tsx +0 -27
- package/src/viewer/components/LeftSidebar.tsx +0 -472
- package/src/viewer/components/LoadErrorMessage.tsx +0 -102
- package/src/viewer/components/MultiViewportPreview.tsx +0 -522
- package/src/viewer/components/NoVariantsMessage.tsx +0 -59
- package/src/viewer/components/PanelShell.tsx +0 -161
- package/src/viewer/components/PerformancePanel.tsx +0 -304
- package/src/viewer/components/PreviewArea.tsx +0 -472
- package/src/viewer/components/PreviewAside.tsx +0 -168
- package/src/viewer/components/PreviewFrameHost.tsx +0 -303
- package/src/viewer/components/PreviewPane.tsx +0 -149
- package/src/viewer/components/PreviewToolbar.tsx +0 -80
- package/src/viewer/components/PropsEditor.tsx +0 -506
- package/src/viewer/components/PropsTable.tsx +0 -111
- package/src/viewer/components/RelationsSection.tsx +0 -88
- package/src/viewer/components/ResizablePanel.tsx +0 -271
- package/src/viewer/components/RightSidebar.tsx +0 -102
- package/src/viewer/components/RuntimeToolsRegistrar.tsx +0 -17
- package/src/viewer/components/ScreenshotButton.tsx +0 -90
- package/src/viewer/components/Sidebar.tsx +0 -169
- package/src/viewer/components/SkeletonLoader.tsx +0 -161
- package/src/viewer/components/ThemeProvider.tsx +0 -42
- package/src/viewer/components/Toast.tsx +0 -3
- package/src/viewer/components/TokenStylePanel.tsx +0 -699
- package/src/viewer/components/TopToolbar.tsx +0 -159
- package/src/viewer/components/UsageSection.tsx +0 -95
- package/src/viewer/components/VariantMatrix.tsx +0 -388
- package/src/viewer/components/VariantRenderer.tsx +0 -131
- package/src/viewer/components/VariantTabs.tsx +0 -40
- package/src/viewer/components/ViewerHeader.tsx +0 -69
- package/src/viewer/components/ViewerStateSync.tsx +0 -52
- package/src/viewer/components/ViewportSelector.tsx +0 -172
- package/src/viewer/components/WebMCPDevTools.tsx +0 -503
- package/src/viewer/components/WebMCPIntegration.tsx +0 -47
- package/src/viewer/components/WebMCPStatusIndicator.tsx +0 -60
- package/src/viewer/components/_future/CreatePage.tsx +0 -836
- package/src/viewer/components/viewer-utils.ts +0 -16
- package/src/viewer/composition-renderer.ts +0 -381
- package/src/viewer/constants/index.ts +0 -1
- package/src/viewer/constants/ui.ts +0 -166
- package/src/viewer/entry.tsx +0 -335
- package/src/viewer/hooks/index.ts +0 -2
- package/src/viewer/hooks/useA11yCache.ts +0 -383
- package/src/viewer/hooks/useA11yService.ts +0 -364
- package/src/viewer/hooks/useActions.ts +0 -138
- package/src/viewer/hooks/useAppState.ts +0 -147
- package/src/viewer/hooks/useCompiledFragments.ts +0 -42
- package/src/viewer/hooks/useFigmaIntegration.ts +0 -132
- package/src/viewer/hooks/useHmrStatus.ts +0 -109
- package/src/viewer/hooks/useKeyboardShortcuts.ts +0 -270
- package/src/viewer/hooks/usePreviewBridge.ts +0 -347
- package/src/viewer/hooks/useScrollSpy.ts +0 -78
- package/src/viewer/hooks/useUrlState.ts +0 -318
- package/src/viewer/hooks/useViewSettings.ts +0 -111
- package/src/viewer/index.html +0 -28
- package/src/viewer/intelligence/healthReport.ts +0 -505
- package/src/viewer/intelligence/styleDrift.ts +0 -340
- package/src/viewer/intelligence/usageScanner.ts +0 -309
- package/src/viewer/jsx-parser.ts +0 -486
- package/src/viewer/preview-frame-entry.tsx +0 -25
- package/src/viewer/preview-frame.html +0 -125
- package/src/viewer/public/favicon.ico +0 -0
- package/src/viewer/render-template.html +0 -68
- package/src/viewer/styles/globals.css +0 -278
- package/src/viewer/types/a11y.ts +0 -197
- package/src/viewer/utils/a11y-fixes.ts +0 -509
- package/src/viewer/utils/actionExport.ts +0 -372
- package/src/viewer/utils/colorSchemes.ts +0 -201
- package/src/viewer/utils/detectRelationships.ts +0 -256
- package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss +0 -10
- package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss.d.ts +0 -2
- package/src/viewer/vendor/shared/src/ComponentDocContent.tsx +0 -274
- package/src/viewer/vendor/shared/src/DocsHeaderBar.tsx +0 -129
- package/src/viewer/vendor/shared/src/DocsPageAsideHost.tsx +0 -89
- package/src/viewer/vendor/shared/src/DocsPageShell.tsx +0 -124
- package/src/viewer/vendor/shared/src/DocsSearchCommand.tsx +0 -99
- package/src/viewer/vendor/shared/src/DocsSidebarNav.tsx +0 -66
- package/src/viewer/vendor/shared/src/PropsTable.module.scss +0 -68
- package/src/viewer/vendor/shared/src/PropsTable.module.scss.d.ts +0 -2
- package/src/viewer/vendor/shared/src/PropsTable.tsx +0 -76
- package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss +0 -114
- package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss.d.ts +0 -2
- package/src/viewer/vendor/shared/src/VariantPreviewCard.tsx +0 -134
- package/src/viewer/vendor/shared/src/docs-data/index.ts +0 -32
- package/src/viewer/vendor/shared/src/docs-data/mcp-configs.ts +0 -72
- package/src/viewer/vendor/shared/src/docs-data/palettes.ts +0 -75
- package/src/viewer/vendor/shared/src/docs-data/setup-examples.ts +0 -55
- package/src/viewer/vendor/shared/src/docs-layout.scss +0 -28
- package/src/viewer/vendor/shared/src/docs-layout.scss.d.ts +0 -2
- package/src/viewer/vendor/shared/src/index.ts +0 -34
- package/src/viewer/vendor/shared/src/types.ts +0 -53
- package/src/viewer/webmcp/__tests__/analytics.test.ts +0 -108
- package/src/viewer/webmcp/analytics.ts +0 -165
- package/src/viewer/webmcp/index.ts +0 -3
- package/src/viewer/webmcp/posthog-bridge.ts +0 -39
- package/src/viewer/webmcp/runtime-tools.ts +0 -152
- package/src/viewer/webmcp/scan-utils.ts +0 -135
- package/src/viewer/webmcp/use-tool-analytics.ts +0 -69
- package/src/viewer/webmcp/viewer-state.ts +0 -45
- /package/dist/{chunk-ZDA3PLQ6.js.map → chunk-5G3VZH43.js.map} +0 -0
- /package/dist/{chunk-CAMXG5HJ.js.map → chunk-ZM4ZQZWZ.js.map} +0 -0
- /package/dist/{generate-BGKTKO6E.js.map → generate-FBHSXR3D.js.map} +0 -0
- /package/dist/{scan-OQU7M4GH.js.map → scan-CJF2DOQW.js.map} +0 -0
- /package/dist/{scan-generate-T5QNUG7N.js.map → scan-generate-SJAN5MVI.js.map} +0 -0
- /package/dist/{test-2CSOSS3B.js.map → test-Z5LVO724.js.map} +0 -0
- /package/dist/{tokens-DXEGYTOJ.js.map → tokens-CE46OTMD.js.map} +0 -0
|
@@ -1,699 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token-Aware Style Comparison Panel
|
|
3
|
-
*
|
|
4
|
-
* Enhanced style comparison that shows:
|
|
5
|
-
* - Property, Figma value, Rendered value, Match status
|
|
6
|
-
* - Token names when values match design tokens
|
|
7
|
-
* - Hardcoded value warnings
|
|
8
|
-
* - Fix suggestions that can be copied
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { useState, useEffect, useCallback } from "react";
|
|
12
|
-
import { Badge, Stack, Text, Button, Box } from "@fragments-sdk/ui";
|
|
13
|
-
import type { DesignToken, EnhancedStyleDiffItem, TokenUsageSummary } from "../../core/index.js";
|
|
14
|
-
import { Palette } from "@phosphor-icons/react";
|
|
15
|
-
import { CheckIcon, XIcon, LoadingIcon, FigmaIcon, WandIcon } from "./Icons.js";
|
|
16
|
-
import { PanelShell } from "./PanelShell.js";
|
|
17
|
-
|
|
18
|
-
// Alias for semantic clarity
|
|
19
|
-
const SyncingIcon = LoadingIcon;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Maps CSS properties to expected token categories
|
|
23
|
-
* This prevents false positives like "height: 49px" matching "--top-bar-height"
|
|
24
|
-
*/
|
|
25
|
-
const PROPERTY_CATEGORY_MAP: Record<string, string[]> = {
|
|
26
|
-
// Color properties
|
|
27
|
-
color: ["color"],
|
|
28
|
-
backgroundColor: ["color"],
|
|
29
|
-
borderColor: ["color", "border"],
|
|
30
|
-
borderTopColor: ["color", "border"],
|
|
31
|
-
borderRightColor: ["color", "border"],
|
|
32
|
-
borderBottomColor: ["color", "border"],
|
|
33
|
-
borderLeftColor: ["color", "border"],
|
|
34
|
-
outlineColor: ["color"],
|
|
35
|
-
fill: ["color"],
|
|
36
|
-
stroke: ["color"],
|
|
37
|
-
caretColor: ["color"],
|
|
38
|
-
textDecorationColor: ["color"],
|
|
39
|
-
boxShadow: ["shadow", "color"],
|
|
40
|
-
|
|
41
|
-
// Spacing properties
|
|
42
|
-
margin: ["spacing"],
|
|
43
|
-
marginTop: ["spacing"],
|
|
44
|
-
marginRight: ["spacing"],
|
|
45
|
-
marginBottom: ["spacing"],
|
|
46
|
-
marginLeft: ["spacing"],
|
|
47
|
-
padding: ["spacing"],
|
|
48
|
-
paddingTop: ["spacing"],
|
|
49
|
-
paddingRight: ["spacing"],
|
|
50
|
-
paddingBottom: ["spacing"],
|
|
51
|
-
paddingLeft: ["spacing"],
|
|
52
|
-
gap: ["spacing"],
|
|
53
|
-
rowGap: ["spacing"],
|
|
54
|
-
columnGap: ["spacing"],
|
|
55
|
-
|
|
56
|
-
// Sizing properties (NOT spacing - heights shouldn't match spacing tokens)
|
|
57
|
-
width: ["sizing"],
|
|
58
|
-
height: ["sizing"],
|
|
59
|
-
minWidth: ["sizing"],
|
|
60
|
-
minHeight: ["sizing"],
|
|
61
|
-
maxWidth: ["sizing"],
|
|
62
|
-
maxHeight: ["sizing"],
|
|
63
|
-
|
|
64
|
-
// Border radius
|
|
65
|
-
borderRadius: ["radius"],
|
|
66
|
-
borderTopLeftRadius: ["radius"],
|
|
67
|
-
borderTopRightRadius: ["radius"],
|
|
68
|
-
borderBottomLeftRadius: ["radius"],
|
|
69
|
-
borderBottomRightRadius: ["radius"],
|
|
70
|
-
|
|
71
|
-
// Typography
|
|
72
|
-
fontSize: ["typography"],
|
|
73
|
-
fontWeight: ["typography"],
|
|
74
|
-
lineHeight: ["typography"],
|
|
75
|
-
letterSpacing: ["typography"],
|
|
76
|
-
fontFamily: ["typography"],
|
|
77
|
-
|
|
78
|
-
// Border
|
|
79
|
-
borderWidth: ["border"],
|
|
80
|
-
borderTopWidth: ["border"],
|
|
81
|
-
borderRightWidth: ["border"],
|
|
82
|
-
borderBottomWidth: ["border"],
|
|
83
|
-
borderLeftWidth: ["border"],
|
|
84
|
-
|
|
85
|
-
// Z-index
|
|
86
|
-
zIndex: ["z-index"],
|
|
87
|
-
|
|
88
|
-
// Animation
|
|
89
|
-
transitionDuration: ["animation"],
|
|
90
|
-
animationDuration: ["animation"],
|
|
91
|
-
transitionDelay: ["animation"],
|
|
92
|
-
animationDelay: ["animation"],
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Get expected token categories for a CSS property
|
|
97
|
-
*/
|
|
98
|
-
function getExpectedCategories(property: string): string[] | null {
|
|
99
|
-
return PROPERTY_CATEGORY_MAP[property] || null;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
interface TokenStylePanelProps {
|
|
103
|
-
figmaUrl: string;
|
|
104
|
-
figmaStyles: Record<string, string> | null;
|
|
105
|
-
renderedStyles: Record<string, string> | null;
|
|
106
|
-
figmaLoading: boolean;
|
|
107
|
-
figmaError?: string;
|
|
108
|
-
onFetchFigma: () => void;
|
|
109
|
-
onRefreshRendered: () => void;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
interface TokenData {
|
|
113
|
-
tokens: DesignToken[];
|
|
114
|
-
meta?: {
|
|
115
|
-
totalTokens: number;
|
|
116
|
-
parseTimeMs: number;
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Module-level cache for tokens to avoid refetching on tab switches
|
|
121
|
-
let cachedTokenData: TokenData | null = null;
|
|
122
|
-
let cachedTokenError: string | null = null;
|
|
123
|
-
let tokenFetchPromise: Promise<void> | null = null;
|
|
124
|
-
|
|
125
|
-
export function TokenStylePanel({
|
|
126
|
-
figmaUrl,
|
|
127
|
-
figmaStyles,
|
|
128
|
-
renderedStyles,
|
|
129
|
-
figmaLoading,
|
|
130
|
-
figmaError,
|
|
131
|
-
onFetchFigma,
|
|
132
|
-
onRefreshRendered,
|
|
133
|
-
}: TokenStylePanelProps) {
|
|
134
|
-
const [tokenData, setTokenData] = useState<TokenData | null>(null);
|
|
135
|
-
const [tokenError, setTokenError] = useState<string | null>(null);
|
|
136
|
-
const [tokenLoading, setTokenLoading] = useState(false);
|
|
137
|
-
const [copiedFix, setCopiedFix] = useState<string | null>(null);
|
|
138
|
-
|
|
139
|
-
// Fetch tokens on mount (with module-level caching)
|
|
140
|
-
useEffect(() => {
|
|
141
|
-
// Use cached data if available
|
|
142
|
-
if (cachedTokenData) {
|
|
143
|
-
setTokenData(cachedTokenData);
|
|
144
|
-
setTokenLoading(false);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (cachedTokenError) {
|
|
148
|
-
setTokenError(cachedTokenError);
|
|
149
|
-
setTokenLoading(false);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// If a fetch is already in progress, wait for it
|
|
154
|
-
if (tokenFetchPromise) {
|
|
155
|
-
setTokenLoading(true);
|
|
156
|
-
tokenFetchPromise.then(() => {
|
|
157
|
-
setTokenData(cachedTokenData);
|
|
158
|
-
setTokenError(cachedTokenError);
|
|
159
|
-
setTokenLoading(false);
|
|
160
|
-
});
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const fetchTokens = async () => {
|
|
165
|
-
setTokenLoading(true);
|
|
166
|
-
setTokenError(null);
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
const response = await fetch("/fragments/tokens");
|
|
170
|
-
|
|
171
|
-
if (!response.ok) {
|
|
172
|
-
const data = await response.json();
|
|
173
|
-
if (data.error) {
|
|
174
|
-
cachedTokenError = data.suggestion || data.error;
|
|
175
|
-
setTokenError(cachedTokenError);
|
|
176
|
-
}
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const data = await response.json();
|
|
181
|
-
cachedTokenData = data;
|
|
182
|
-
setTokenData(data);
|
|
183
|
-
} catch (err) {
|
|
184
|
-
cachedTokenError = "Failed to fetch tokens";
|
|
185
|
-
setTokenError(cachedTokenError);
|
|
186
|
-
} finally {
|
|
187
|
-
setTokenLoading(false);
|
|
188
|
-
tokenFetchPromise = null;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
tokenFetchPromise = fetchTokens();
|
|
193
|
-
}, []);
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Find a token by value, filtered by property category to avoid false positives.
|
|
197
|
-
* Returns null if no appropriate token is found.
|
|
198
|
-
*/
|
|
199
|
-
const tokenByValue = useCallback(
|
|
200
|
-
(value: string, property?: string): { token: DesignToken; confidence: "exact" | "value-only" } | null => {
|
|
201
|
-
if (!tokenData?.tokens) return null;
|
|
202
|
-
|
|
203
|
-
const normalized = normalizeValue(value);
|
|
204
|
-
const expectedCategories = property ? getExpectedCategories(property) : null;
|
|
205
|
-
|
|
206
|
-
// First pass: look for exact category match
|
|
207
|
-
for (const token of tokenData.tokens) {
|
|
208
|
-
const tokenNormalized = normalizeValue(token.resolvedValue);
|
|
209
|
-
if (tokenNormalized === normalized) {
|
|
210
|
-
// Check if this token's category matches what we expect for this property
|
|
211
|
-
if (expectedCategories && expectedCategories.includes(token.category)) {
|
|
212
|
-
return { token, confidence: "exact" };
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Second pass: if we have expectedCategories but found no match, don't return anything
|
|
218
|
-
// This prevents "height: 49px" from matching "--top-bar-height" (a sizing token when we want sizing)
|
|
219
|
-
if (expectedCategories) {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Fallback: if we don't know the property type, return any matching token
|
|
224
|
-
// but mark it as "value-only" confidence
|
|
225
|
-
for (const token of tokenData.tokens) {
|
|
226
|
-
const tokenNormalized = normalizeValue(token.resolvedValue);
|
|
227
|
-
if (tokenNormalized === normalized) {
|
|
228
|
-
return { token, confidence: "value-only" };
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return null;
|
|
233
|
-
},
|
|
234
|
-
[tokenData]
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
// Copy fix to clipboard
|
|
238
|
-
const copyFix = useCallback((property: string, tokenName: string) => {
|
|
239
|
-
const cssProperty = property.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
240
|
-
const code = `${cssProperty}: var(${tokenName});`;
|
|
241
|
-
navigator.clipboard.writeText(code);
|
|
242
|
-
setCopiedFix(property);
|
|
243
|
-
setTimeout(() => setCopiedFix(null), 2000);
|
|
244
|
-
}, []);
|
|
245
|
-
|
|
246
|
-
// Determine empty config for error / idle states
|
|
247
|
-
const emptyConfig = (() => {
|
|
248
|
-
if (!figmaLoading && figmaError) {
|
|
249
|
-
return {
|
|
250
|
-
icon: <Palette size={24} weight="regular" style={{ color: 'var(--text-tertiary)' }} />,
|
|
251
|
-
title: "Style comparison failed",
|
|
252
|
-
description: figmaError,
|
|
253
|
-
action: <Button variant="secondary" size="sm" onClick={onFetchFigma}>Retry</Button>,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
if (!figmaLoading && !figmaStyles) {
|
|
257
|
-
return {
|
|
258
|
-
icon: <Palette size={24} weight="regular" style={{ color: 'var(--text-tertiary)' }} />,
|
|
259
|
-
title: "No style data",
|
|
260
|
-
description: "Load Figma styles to compare design tokens with rendered output.",
|
|
261
|
-
action: <Button size="sm" onClick={onFetchFigma}>Load Styles</Button>,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
return undefined;
|
|
265
|
-
})();
|
|
266
|
-
|
|
267
|
-
// Build comparison data (safe — only used when figmaStyles exist, i.e. PanelShell renders children)
|
|
268
|
-
const figma = figmaStyles || {};
|
|
269
|
-
const rendered = renderedStyles || {};
|
|
270
|
-
const allProps = [...new Set([...Object.keys(figma), ...Object.keys(rendered)])];
|
|
271
|
-
|
|
272
|
-
const properties = allProps.map((prop) => {
|
|
273
|
-
const figmaValue = figma[prop] || "(not set)";
|
|
274
|
-
const renderedValue = rendered[prop] || "(not set)";
|
|
275
|
-
const match = compareValue(prop, figma[prop] || "", rendered[prop] || "");
|
|
276
|
-
|
|
277
|
-
const figmaMatch = figma[prop] ? tokenByValue(figma[prop], prop) : null;
|
|
278
|
-
const renderedMatch = rendered[prop] ? tokenByValue(rendered[prop], prop) : null;
|
|
279
|
-
|
|
280
|
-
const figmaToken = figmaMatch?.token || null;
|
|
281
|
-
const renderedToken = renderedMatch?.token || null;
|
|
282
|
-
const figmaConfidence = figmaMatch?.confidence;
|
|
283
|
-
const renderedConfidence = renderedMatch?.confidence;
|
|
284
|
-
|
|
285
|
-
const isHardcoded = !!figmaToken && !renderedToken && figma[prop] !== rendered[prop];
|
|
286
|
-
|
|
287
|
-
return {
|
|
288
|
-
property: prop,
|
|
289
|
-
figma: figmaValue,
|
|
290
|
-
rendered: renderedValue,
|
|
291
|
-
match,
|
|
292
|
-
figmaToken,
|
|
293
|
-
renderedToken,
|
|
294
|
-
figmaConfidence,
|
|
295
|
-
renderedConfidence,
|
|
296
|
-
isHardcoded,
|
|
297
|
-
};
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
const differences = properties.filter((p) => !p.match).length;
|
|
301
|
-
const hardcodedCount = properties.filter((p) => p.isHardcoded).length;
|
|
302
|
-
const fixableCount = properties.filter((p) => p.isHardcoded && p.figmaToken).length;
|
|
303
|
-
const tokenUsageCount = properties.filter((p) => p.renderedToken).length;
|
|
304
|
-
|
|
305
|
-
const compliancePercent =
|
|
306
|
-
properties.length > 0
|
|
307
|
-
? Math.round(((tokenUsageCount + properties.filter((p) => p.match && !p.figmaToken).length) / properties.length) * 100)
|
|
308
|
-
: 100;
|
|
309
|
-
|
|
310
|
-
// Toolbar with token status + summary badges (only when data is loaded)
|
|
311
|
-
const toolbar = figmaStyles ? (
|
|
312
|
-
<Stack direction="row" align="center" justify="between" style={{ width: '100%' }}>
|
|
313
|
-
<Stack direction="row" align="center" gap="md">
|
|
314
|
-
{tokenData && (
|
|
315
|
-
<Text size="xs" color="tertiary">
|
|
316
|
-
{tokenData.meta?.totalTokens || tokenData.tokens.length} tokens loaded
|
|
317
|
-
</Text>
|
|
318
|
-
)}
|
|
319
|
-
{tokenLoading && (
|
|
320
|
-
<Stack direction="row" align="center" gap="xs" style={{ color: 'var(--text-tertiary)' }}>
|
|
321
|
-
<SyncingIcon style={{ width: 12, height: 12, animation: 'spin 1s linear infinite' }} />
|
|
322
|
-
<Text size="xs">Loading tokens...</Text>
|
|
323
|
-
</Stack>
|
|
324
|
-
)}
|
|
325
|
-
{tokenError && !tokenLoading && (
|
|
326
|
-
<Text size="xs" style={{ color: '#d97706' }} title={tokenError}>
|
|
327
|
-
Tokens not configured
|
|
328
|
-
</Text>
|
|
329
|
-
)}
|
|
330
|
-
</Stack>
|
|
331
|
-
|
|
332
|
-
<Stack direction="row" align="center" gap="sm">
|
|
333
|
-
{tokenData && (
|
|
334
|
-
<Badge
|
|
335
|
-
variant={compliancePercent >= 80 ? 'success' : compliancePercent >= 50 ? 'warning' : 'danger'}
|
|
336
|
-
>
|
|
337
|
-
{compliancePercent}% token compliance
|
|
338
|
-
</Badge>
|
|
339
|
-
)}
|
|
340
|
-
|
|
341
|
-
<Badge variant={differences === 0 ? 'success' : 'warning'}>
|
|
342
|
-
{differences === 0 ? "All styles match" : `${differences} difference${differences !== 1 ? "s" : ""}`}
|
|
343
|
-
</Badge>
|
|
344
|
-
|
|
345
|
-
{hardcodedCount > 0 && (
|
|
346
|
-
<Badge variant="danger">
|
|
347
|
-
{hardcodedCount} hardcoded
|
|
348
|
-
</Badge>
|
|
349
|
-
)}
|
|
350
|
-
</Stack>
|
|
351
|
-
</Stack>
|
|
352
|
-
) : undefined;
|
|
353
|
-
|
|
354
|
-
return (
|
|
355
|
-
<PanelShell loading={figmaLoading} toolbar={toolbar} empty={emptyConfig}>
|
|
356
|
-
<div style={{ overflowX: 'auto' }}>
|
|
357
|
-
{/* Comparison Table */}
|
|
358
|
-
<table style={{ width: '100%', fontSize: '12px' }}>
|
|
359
|
-
<thead>
|
|
360
|
-
<tr style={{ borderBottom: '1px solid var(--border)' }}>
|
|
361
|
-
<th style={{ padding: '8px 12px', textAlign: 'left', color: 'var(--text-tertiary)', fontWeight: 500 }}>Property</th>
|
|
362
|
-
<th style={{ padding: '8px 12px', textAlign: 'left', color: 'var(--text-tertiary)', fontWeight: 500 }}>Figma</th>
|
|
363
|
-
{tokenData && (
|
|
364
|
-
<th style={{ padding: '8px 12px', textAlign: 'left', color: 'var(--text-tertiary)', fontWeight: 500 }}>Token</th>
|
|
365
|
-
)}
|
|
366
|
-
<th style={{ padding: '8px 12px', textAlign: 'left', color: 'var(--text-tertiary)', fontWeight: 500 }}>Rendered</th>
|
|
367
|
-
<th style={{ padding: '8px 12px', textAlign: 'center', color: 'var(--text-tertiary)', fontWeight: 500, width: '48px' }}>Match</th>
|
|
368
|
-
{tokenData && fixableCount > 0 && (
|
|
369
|
-
<th style={{ padding: '8px 12px', textAlign: 'center', color: 'var(--text-tertiary)', fontWeight: 500, width: '64px' }}>Fix</th>
|
|
370
|
-
)}
|
|
371
|
-
</tr>
|
|
372
|
-
</thead>
|
|
373
|
-
<tbody>
|
|
374
|
-
{properties.map((prop, index) => (
|
|
375
|
-
<tr
|
|
376
|
-
key={prop.property}
|
|
377
|
-
style={{
|
|
378
|
-
borderBottom: index < properties.length - 1 ? '1px solid var(--border)' : undefined,
|
|
379
|
-
background: prop.isHardcoded
|
|
380
|
-
? 'color-mix(in srgb, #ef4444 5%, transparent)'
|
|
381
|
-
: !prop.match
|
|
382
|
-
? 'color-mix(in srgb, #f59e0b 5%, transparent)'
|
|
383
|
-
: undefined,
|
|
384
|
-
}}
|
|
385
|
-
>
|
|
386
|
-
<td style={{ padding: '8px 12px', fontFamily: 'monospace', color: 'var(--text-primary)' }}>{prop.property}</td>
|
|
387
|
-
<td style={{ padding: '8px 12px' }}>
|
|
388
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
|
389
|
-
{isColorProperty(prop.property) && prop.figma !== "(not set)" && (
|
|
390
|
-
<ColorSwatch color={prop.figma} />
|
|
391
|
-
)}
|
|
392
|
-
<span style={{ fontFamily: 'monospace', color: 'var(--text-secondary)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: '120px' }} title={prop.figma}>
|
|
393
|
-
{prop.figma}
|
|
394
|
-
</span>
|
|
395
|
-
</div>
|
|
396
|
-
</td>
|
|
397
|
-
{tokenData && (
|
|
398
|
-
<td style={{ padding: '8px 12px' }}>
|
|
399
|
-
{prop.figmaToken ? (
|
|
400
|
-
<TokenBadge token={prop.figmaToken} confidence={prop.figmaConfidence} />
|
|
401
|
-
) : prop.renderedToken ? (
|
|
402
|
-
<TokenBadge token={prop.renderedToken} confidence={prop.renderedConfidence} />
|
|
403
|
-
) : (
|
|
404
|
-
<span style={{ color: 'var(--text-tertiary)' }}>-</span>
|
|
405
|
-
)}
|
|
406
|
-
</td>
|
|
407
|
-
)}
|
|
408
|
-
<td style={{ padding: '8px 12px' }}>
|
|
409
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
|
410
|
-
{isColorProperty(prop.property) && prop.rendered !== "(not set)" && (
|
|
411
|
-
<ColorSwatch color={prop.rendered} />
|
|
412
|
-
)}
|
|
413
|
-
<span style={{ fontFamily: 'monospace', color: 'var(--text-secondary)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: '120px' }} title={prop.rendered}>
|
|
414
|
-
{prop.rendered}
|
|
415
|
-
</span>
|
|
416
|
-
{prop.isHardcoded && (
|
|
417
|
-
<Badge variant="danger">HC</Badge>
|
|
418
|
-
)}
|
|
419
|
-
</div>
|
|
420
|
-
</td>
|
|
421
|
-
<td style={{ padding: '8px 12px', textAlign: 'center' }}>
|
|
422
|
-
{prop.match ? (
|
|
423
|
-
<CheckIcon style={{ width: 16, height: 16, color: '#16a34a', margin: '0 auto' }} />
|
|
424
|
-
) : (
|
|
425
|
-
<XIcon style={{ width: 16, height: 16, color: '#d97706', margin: '0 auto' }} />
|
|
426
|
-
)}
|
|
427
|
-
</td>
|
|
428
|
-
{tokenData && fixableCount > 0 && (
|
|
429
|
-
<td style={{ padding: '8px 12px', textAlign: 'center' }}>
|
|
430
|
-
{prop.isHardcoded && prop.figmaToken && (
|
|
431
|
-
<button
|
|
432
|
-
onClick={() => copyFix(prop.property, prop.figmaToken!.name)}
|
|
433
|
-
style={{
|
|
434
|
-
padding: '4px',
|
|
435
|
-
borderRadius: '4px',
|
|
436
|
-
transition: 'color 0.15s, background 0.15s',
|
|
437
|
-
background: copiedFix === prop.property ? 'color-mix(in srgb, #22c55e 15%, transparent)' : 'transparent',
|
|
438
|
-
color: copiedFix === prop.property ? '#16a34a' : 'var(--text-tertiary)',
|
|
439
|
-
border: 'none',
|
|
440
|
-
cursor: 'pointer',
|
|
441
|
-
}}
|
|
442
|
-
title={`Copy: ${prop.property.replace(/([A-Z])/g, "-$1").toLowerCase()}: var(${prop.figmaToken.name});`}
|
|
443
|
-
>
|
|
444
|
-
{copiedFix === prop.property ? (
|
|
445
|
-
<CheckIcon style={{ width: 12, height: 12 }} />
|
|
446
|
-
) : (
|
|
447
|
-
<WandIcon style={{ width: 12, height: 12 }} />
|
|
448
|
-
)}
|
|
449
|
-
</button>
|
|
450
|
-
)}
|
|
451
|
-
</td>
|
|
452
|
-
)}
|
|
453
|
-
</tr>
|
|
454
|
-
))}
|
|
455
|
-
</tbody>
|
|
456
|
-
</table>
|
|
457
|
-
|
|
458
|
-
{/* Hardcoded fixes summary */}
|
|
459
|
-
{hardcodedCount > 0 && tokenData && (
|
|
460
|
-
<Box padding="sm" rounded="md" style={{ marginTop: '16px', background: 'color-mix(in srgb, #f59e0b 8%, transparent)', border: '1px solid color-mix(in srgb, #f59e0b 20%, transparent)' }}>
|
|
461
|
-
<Stack direction="row" align="start" gap="sm">
|
|
462
|
-
<WandIcon style={{ width: 16, height: 16, color: '#d97706', marginTop: '2px' }} />
|
|
463
|
-
<div>
|
|
464
|
-
<Text size="xs" weight="medium" style={{ color: '#92400e' }}>
|
|
465
|
-
{hardcodedCount} hardcoded value{hardcodedCount !== 1 ? "s" : ""} detected
|
|
466
|
-
</Text>
|
|
467
|
-
<Text size="xs" style={{ color: '#a16207', marginTop: '4px' }}>
|
|
468
|
-
These values should use design tokens for consistency and theming support.
|
|
469
|
-
Click the fix button to copy the token-based CSS.
|
|
470
|
-
</Text>
|
|
471
|
-
</div>
|
|
472
|
-
</Stack>
|
|
473
|
-
</Box>
|
|
474
|
-
)}
|
|
475
|
-
</div>
|
|
476
|
-
</PanelShell>
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// ----- Helper Components -----
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* Enhanced tooltip showing full token details on hover
|
|
484
|
-
*/
|
|
485
|
-
function TokenBadge({
|
|
486
|
-
token,
|
|
487
|
-
confidence,
|
|
488
|
-
}: {
|
|
489
|
-
token: DesignToken;
|
|
490
|
-
confidence?: "exact" | "value-only";
|
|
491
|
-
}) {
|
|
492
|
-
const [showTooltip, setShowTooltip] = useState(false);
|
|
493
|
-
|
|
494
|
-
const isValueOnly = confidence === "value-only";
|
|
495
|
-
|
|
496
|
-
return (
|
|
497
|
-
<div style={{ position: 'relative', display: 'inline-block' }}>
|
|
498
|
-
<span
|
|
499
|
-
style={{
|
|
500
|
-
fontFamily: 'monospace',
|
|
501
|
-
fontSize: '12px',
|
|
502
|
-
cursor: 'help',
|
|
503
|
-
padding: '2px 6px',
|
|
504
|
-
borderRadius: '4px',
|
|
505
|
-
color: isValueOnly ? '#d97706' : 'var(--color-accent)',
|
|
506
|
-
background: isValueOnly
|
|
507
|
-
? 'color-mix(in srgb, #f59e0b 8%, transparent)'
|
|
508
|
-
: 'color-mix(in srgb, var(--color-accent) 8%, transparent)',
|
|
509
|
-
}}
|
|
510
|
-
onMouseEnter={() => setShowTooltip(true)}
|
|
511
|
-
onMouseLeave={() => setShowTooltip(false)}
|
|
512
|
-
>
|
|
513
|
-
{token.name}
|
|
514
|
-
</span>
|
|
515
|
-
|
|
516
|
-
{/* Enhanced tooltip */}
|
|
517
|
-
{showTooltip && (
|
|
518
|
-
<div
|
|
519
|
-
style={{
|
|
520
|
-
position: 'absolute',
|
|
521
|
-
zIndex: 50,
|
|
522
|
-
left: 0,
|
|
523
|
-
top: '100%',
|
|
524
|
-
marginTop: '4px',
|
|
525
|
-
padding: '12px',
|
|
526
|
-
background: 'var(--bg-primary)',
|
|
527
|
-
border: '1px solid var(--border)',
|
|
528
|
-
borderRadius: '8px',
|
|
529
|
-
boxShadow: '0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1)',
|
|
530
|
-
minWidth: '280px',
|
|
531
|
-
maxWidth: '320px',
|
|
532
|
-
}}
|
|
533
|
-
>
|
|
534
|
-
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px', fontSize: '12px' }}>
|
|
535
|
-
{/* Token name */}
|
|
536
|
-
<div>
|
|
537
|
-
<span style={{ color: 'var(--text-tertiary)' }}>Token:</span>
|
|
538
|
-
<span style={{ marginLeft: '8px', fontFamily: 'monospace', color: 'var(--text-primary)', fontWeight: 500 }}>{token.name}</span>
|
|
539
|
-
</div>
|
|
540
|
-
|
|
541
|
-
{/* Resolved value */}
|
|
542
|
-
<div style={{ display: 'flex', alignItems: 'center' }}>
|
|
543
|
-
<span style={{ color: 'var(--text-tertiary)' }}>Value:</span>
|
|
544
|
-
<span style={{ marginLeft: '8px', fontFamily: 'monospace', color: 'var(--text-secondary)' }}>{token.resolvedValue}</span>
|
|
545
|
-
{token.category === "color" && (
|
|
546
|
-
<ColorSwatch color={token.resolvedValue} />
|
|
547
|
-
)}
|
|
548
|
-
</div>
|
|
549
|
-
|
|
550
|
-
{/* Raw value (if different from resolved) */}
|
|
551
|
-
{token.rawValue !== token.resolvedValue && (
|
|
552
|
-
<div>
|
|
553
|
-
<span style={{ color: 'var(--text-tertiary)' }}>Raw:</span>
|
|
554
|
-
<span style={{ marginLeft: '8px', fontFamily: 'monospace', color: 'var(--text-secondary)' }}>{token.rawValue}</span>
|
|
555
|
-
</div>
|
|
556
|
-
)}
|
|
557
|
-
|
|
558
|
-
{/* Category & Level */}
|
|
559
|
-
<div style={{ display: 'flex', gap: '16px' }}>
|
|
560
|
-
<div>
|
|
561
|
-
<span style={{ color: 'var(--text-tertiary)' }}>Category:</span>
|
|
562
|
-
<span style={{ marginLeft: '8px', color: 'var(--text-secondary)', textTransform: 'capitalize' }}>{token.category}</span>
|
|
563
|
-
</div>
|
|
564
|
-
<div>
|
|
565
|
-
<span style={{ color: 'var(--text-tertiary)' }}>Level:</span>
|
|
566
|
-
<span style={{ marginLeft: '8px', color: 'var(--text-secondary)' }}>
|
|
567
|
-
{token.level === 1 ? "Base" : token.level === 2 ? "Semantic" : "Component"}
|
|
568
|
-
</span>
|
|
569
|
-
</div>
|
|
570
|
-
</div>
|
|
571
|
-
|
|
572
|
-
{/* Theme */}
|
|
573
|
-
<div>
|
|
574
|
-
<span style={{ color: 'var(--text-tertiary)' }}>Theme:</span>
|
|
575
|
-
<span style={{ marginLeft: '8px', color: 'var(--text-secondary)' }}>{token.theme}</span>
|
|
576
|
-
</div>
|
|
577
|
-
|
|
578
|
-
{/* Reference chain (if has references) */}
|
|
579
|
-
{token.referenceChain.length > 1 && (
|
|
580
|
-
<div>
|
|
581
|
-
<span style={{ color: 'var(--text-tertiary)' }}>References:</span>
|
|
582
|
-
<div style={{ marginTop: '4px', fontFamily: 'monospace', color: 'var(--text-secondary)', fontSize: '10px', display: 'flex', flexDirection: 'column', gap: '2px' }}>
|
|
583
|
-
{token.referenceChain.map((ref, i) => (
|
|
584
|
-
<div key={ref} style={{ display: 'flex', alignItems: 'center' }}>
|
|
585
|
-
{i > 0 && <span style={{ marginRight: '4px', color: 'var(--text-tertiary)' }}>→</span>}
|
|
586
|
-
<span>{ref}</span>
|
|
587
|
-
</div>
|
|
588
|
-
))}
|
|
589
|
-
</div>
|
|
590
|
-
</div>
|
|
591
|
-
)}
|
|
592
|
-
|
|
593
|
-
{/* Source file */}
|
|
594
|
-
<div style={{ paddingTop: '4px', borderTop: '1px solid var(--border)' }}>
|
|
595
|
-
<span style={{ color: 'var(--text-tertiary)' }}>Source:</span>
|
|
596
|
-
<span style={{ marginLeft: '8px', fontFamily: 'monospace', fontSize: '10px', color: 'var(--text-tertiary)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
|
597
|
-
{token.sourceFile.split("/").slice(-2).join("/")}
|
|
598
|
-
{token.lineNumber && `:${token.lineNumber}`}
|
|
599
|
-
</span>
|
|
600
|
-
</div>
|
|
601
|
-
|
|
602
|
-
{/* Confidence indicator */}
|
|
603
|
-
{confidence === "value-only" && (
|
|
604
|
-
<div style={{ paddingTop: '4px', color: '#d97706' }}>
|
|
605
|
-
Warning: Value match only - verify this is the correct token
|
|
606
|
-
</div>
|
|
607
|
-
)}
|
|
608
|
-
</div>
|
|
609
|
-
</div>
|
|
610
|
-
)}
|
|
611
|
-
</div>
|
|
612
|
-
);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
function ColorSwatch({ color }: { color: string }) {
|
|
616
|
-
return (
|
|
617
|
-
<div
|
|
618
|
-
style={{
|
|
619
|
-
width: '16px',
|
|
620
|
-
height: '16px',
|
|
621
|
-
borderRadius: '4px',
|
|
622
|
-
border: '1px solid var(--border)',
|
|
623
|
-
flexShrink: 0,
|
|
624
|
-
marginLeft: '4px',
|
|
625
|
-
backgroundColor: color,
|
|
626
|
-
}}
|
|
627
|
-
title={color}
|
|
628
|
-
/>
|
|
629
|
-
);
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// ----- Helper Functions -----
|
|
633
|
-
|
|
634
|
-
function isColorProperty(prop: string): boolean {
|
|
635
|
-
const colorProps = ["backgroundColor", "borderColor", "color", "fill", "stroke"];
|
|
636
|
-
return colorProps.includes(prop) || prop.toLowerCase().includes("color");
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
/**
|
|
640
|
-
* Normalize a CSS value for comparison.
|
|
641
|
-
* Handles colors (hex, rgb, rgba) and general values.
|
|
642
|
-
*/
|
|
643
|
-
function normalizeValue(value: string): string {
|
|
644
|
-
if (!value) return "";
|
|
645
|
-
|
|
646
|
-
const trimmed = value.toLowerCase().trim();
|
|
647
|
-
|
|
648
|
-
// Already normalized hex
|
|
649
|
-
if (trimmed.match(/^#[0-9a-f]{6}$/i)) {
|
|
650
|
-
return trimmed;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
// Short hex -> long hex
|
|
654
|
-
const shortHex = trimmed.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i);
|
|
655
|
-
if (shortHex) {
|
|
656
|
-
return `#${shortHex[1]}${shortHex[1]}${shortHex[2]}${shortHex[2]}${shortHex[3]}${shortHex[3]}`;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
// Parse hex
|
|
660
|
-
const hexMatch = trimmed.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
|
|
661
|
-
if (hexMatch) {
|
|
662
|
-
return trimmed;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
// Parse rgb/rgba
|
|
666
|
-
const rgbMatch = value.match(
|
|
667
|
-
/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+)?\s*\)/
|
|
668
|
-
);
|
|
669
|
-
if (rgbMatch) {
|
|
670
|
-
const r = parseInt(rgbMatch[1], 10).toString(16).padStart(2, "0");
|
|
671
|
-
const g = parseInt(rgbMatch[2], 10).toString(16).padStart(2, "0");
|
|
672
|
-
const b = parseInt(rgbMatch[3], 10).toString(16).padStart(2, "0");
|
|
673
|
-
return `#${r}${g}${b}`;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
return trimmed;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
function compareValue(prop: string, figma: string, rendered: string): boolean {
|
|
680
|
-
if (figma === rendered) return true;
|
|
681
|
-
if (!figma || !rendered) return false;
|
|
682
|
-
|
|
683
|
-
// Color comparison
|
|
684
|
-
if (isColorProperty(prop)) {
|
|
685
|
-
return normalizeValue(figma) === normalizeValue(rendered);
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
// Numeric comparison with near-zero tolerance for floating point rounding only
|
|
689
|
-
// Using < 0.1 ensures 1px vs 2px shows as mismatch, while 1.0001px vs 1px matches
|
|
690
|
-
const figmaNum = parseFloat(figma);
|
|
691
|
-
const renderedNum = parseFloat(rendered);
|
|
692
|
-
if (!isNaN(figmaNum) && !isNaN(renderedNum)) {
|
|
693
|
-
return Math.abs(figmaNum - renderedNum) < 0.1;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
return false;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
export default TokenStylePanel;
|