@@ -44,15 +44,17 @@ export const exactValue = (
4444/**
4545 * convert pixel values to Tailwind attributes.
4646 * by default, Tailwind uses rem, while Figma uses px.
47- * Therefore, a conversion is necessary. Rem = Pixel / 16.abs
47+ * Therefore, a conversion is necessary. Rem = Pixel / baseFontSize
4848 * Then, find in the corresponding table the closest value.
4949 */
5050const pxToRemToTailwind = (
5151 value : number ,
5252 conversionMap : Record < number , string > ,
5353) : string => {
5454 const keys = Object . keys ( conversionMap ) . map ( ( d ) => + d ) ;
55- const remValue = value / 16 ;
55+ // Use the configured base font size or fall back to default 16px
56+ const baseFontSize = localTailwindSettings . baseFontSize || 16 ;
57+ const remValue = value / baseFontSize ;
5658 const convertedValue = exactValue ( remValue , keys ) ;
5759
5860 if ( convertedValue ) {
@@ -76,6 +78,8 @@ const pxToTailwind = (
7678 const keys = Object . keys ( conversionMap ) . map ( ( d ) => + d ) ;
7779 const convertedValue = exactValue ( value , keys ) ;
7880
81+ console . log ( "convertedValue" , convertedValue ) ;
82+
7983 if ( convertedValue ) {
8084 return conversionMap [ convertedValue ] ;
8185 } else if ( localTailwindSettings . roundTailwindValues ) {
@@ -111,30 +115,16 @@ export const pxToBlur = (value: number): string | null => {
111115} ;
112116
113117export const pxToLayoutSize = ( value : number ) : string => {
114- // First check if it's a direct match to avoid rounding errors
115- const exactValue = Object . keys ( config . layoutSize )
116- . map ( Number )
117- . find ( ( size ) => Math . abs ( value - size ) < 0.05 ) ;
118-
119- if ( exactValue !== undefined ) {
120- return ( config . layoutSize as any ) [ exactValue ] ;
121- }
122-
123- // If not an exact match but rounding is enabled, check for a close match
124- if ( localTailwindSettings . roundTailwindValues ) {
125- const thresholdValue = nearestValueWithThreshold (
126- value ,
127- Object . keys ( config . layoutSize ) . map ( Number ) ,
128- 15 , // 15% threshold for layout sizes
129- ) ;
130-
131- if ( thresholdValue !== null ) {
132- return ( config . layoutSize as any ) [ thresholdValue ] ;
133- }
134- }
135-
136- // No match found, return arbitrary value
137- return `[${ numberToFixedString ( value ) } px]` ;
118+ // Scale the input value according to the base font size ratio
119+ const baseFontSize = localTailwindSettings . baseFontSize || 16 ;
120+ // If baseFontSize is different than 16, we need to adjust the pixel value
121+ // For example, with baseFontSize=14, 7px should match with the key for 8px (w-2)
122+ const scaledValue = ( value * 16 ) / baseFontSize ;
123+
124+ // Use pxToTailwind directly with the scaled value, since the keys in config.layoutSize
125+ // are likely in pixels based on a 16px base font size
126+ const result = pxToTailwind ( scaledValue , config . layoutSize ) ;
127+ return result !== null ? result : `[${ numberToFixedString ( value ) } px]` ;
138128} ;
139129
140130export const nearestOpacity = ( nodeOpacity : number ) : number => {
0 commit comments