@@ -74,7 +74,7 @@ export function registerDialtoneTransforms (styleDictionary) {
7474 transform : ( token ) => {
7575 // replace unmathable characters with empty string
7676 const mathString = token . value . replace ( / d p | s p | e m | p x | % / g, '' ) ;
77- // eslint-disable-next-line no-eval
77+
7878 const result = eval ( mathString ) . toFixed ( 2 ) ;
7979 return `${ result } dp` ;
8080 } ,
@@ -167,6 +167,8 @@ export function registerDialtoneTransforms (styleDictionary) {
167167 type : 'value' ,
168168 transitive : true ,
169169 filter : function ( token ) {
170+ // Exclude lineHeight dimension tokens - they're handled by lineHeight transform
171+ if ( token . type === 'dimension' && token . path ?. includes ( 'lineHeight' ) ) return false ;
170172 return [ ...SPACING_IDENTIFIERS , ...SIZE_IDENTIFIERS ] . includes ( token . type ) &&
171173 // The fontSize token in typography tokens is a 'dimension' type for some reason,
172174 // so have this special case to exclude it from this transform.
@@ -219,7 +221,7 @@ export function registerDialtoneTransforms (styleDictionary) {
219221 if ( token . value . includes ( '.sp' ) ) unit = 'sp' ;
220222 if ( token . value . includes ( '.em' ) ) unit = 'em' ;
221223 const mathString = token . value . replace ( / \. d p | \. s p | \. e m | p x | % / g, '' ) ;
222- // eslint-disable-next-line no-eval
224+
223225 const result = eval ( mathString ) ;
224226 return `${ result } .${ unit } ` ;
225227 } ,
@@ -229,7 +231,9 @@ export function registerDialtoneTransforms (styleDictionary) {
229231 name : 'dt/android/compose/lineHeight/percentToDecimal' ,
230232 type : 'value' ,
231233 filter : function ( token ) {
232- return LINE_HEIGHT_IDENTIFIERS . includes ( token . type ) ;
234+ // Match by type (legacy tokens) or path (DTCG-compliant tokens with type: dimension)
235+ return LINE_HEIGHT_IDENTIFIERS . includes ( token . type ) ||
236+ ( token . type === 'dimension' && token . path ?. includes ( 'lineHeight' ) ) ;
233237 } ,
234238 transform : ( token ) => {
235239 const floatVal = parseFloat ( token . value ) ;
@@ -313,6 +317,8 @@ export function registerDialtoneTransforms (styleDictionary) {
313317 name : 'dt/ios/size/pxToCGFloat' ,
314318 type : 'value' ,
315319 filter : function ( token ) {
320+ // Exclude lineHeight dimension tokens - they're handled by dt/ios/lineHeight/percentToDecimal
321+ if ( token . type === 'dimension' && token . path ?. includes ( 'lineHeight' ) ) return false ;
316322 return [ ...SPACING_IDENTIFIERS , ...SIZE_IDENTIFIERS ] . includes ( token . type ) ;
317323 } ,
318324 transform : ( token ) => {
@@ -330,7 +336,11 @@ export function registerDialtoneTransforms (styleDictionary) {
330336 name : 'dt/ios/lineHeight/percentToDecimal' ,
331337 type : 'value' ,
332338 filter : function ( token ) {
333- return [ 'opacity' , ...LINE_HEIGHT_IDENTIFIERS ] . includes ( token . type ) ;
339+ // Skip if already transformed to CGFloat
340+ if ( typeof token . value === 'string' && token . value . includes ( 'CGFloat' ) ) return false ;
341+ // Match by type (legacy tokens) or path (DTCG-compliant tokens with type: dimension)
342+ return [ 'opacity' , ...LINE_HEIGHT_IDENTIFIERS ] . includes ( token . type ) ||
343+ ( token . type === 'dimension' && token . path ?. includes ( 'lineHeight' ) ) ;
334344 } ,
335345 transform : ( token ) => {
336346 const floatVal = parseFloat ( token . value ) ;
@@ -347,7 +357,9 @@ export function registerDialtoneTransforms (styleDictionary) {
347357 name : 'dt/lineHeight/percentToDecimal' ,
348358 type : 'value' ,
349359 filter : function ( token ) {
350- return LINE_HEIGHT_IDENTIFIERS . includes ( token . type ) ;
360+ // Match by type (legacy tokens) or path (DTCG-compliant tokens with type: dimension)
361+ return LINE_HEIGHT_IDENTIFIERS . includes ( token . type ) ||
362+ ( token . type === 'dimension' && token . path ?. includes ( 'lineHeight' ) ) ;
351363 } ,
352364 transform : ( token ) => {
353365 const floatVal = parseFloat ( token . value ) ;
@@ -380,24 +392,4 @@ export function registerDialtoneTransforms (styleDictionary) {
380392 } ,
381393 } ) ;
382394
383- styleDictionary . registerTransform ( {
384- name : 'dt/lineHeight/percentToDecimal' ,
385- type : 'value' ,
386- filter : function ( token ) {
387- return LINE_HEIGHT_IDENTIFIERS . includes ( token . type ) ;
388- } ,
389- transform : ( token ) => {
390- const floatVal = parseFloat ( token . value ) ;
391-
392- if ( isNaN ( floatVal ) ) {
393- throwSizeError ( token . path , token . value , '%' ) ;
394- }
395-
396- if ( floatVal === 0 ) {
397- return '0' ;
398- }
399-
400- return `${ floatVal / 100 } ` ;
401- } ,
402- } ) ;
403395}
0 commit comments