From 990937064476d89b04855ecd4f0d5b6a44247e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Wed, 31 Jul 2024 08:59:49 +0200 Subject: [PATCH 1/2] Android: force `em` values to use the `X.em` format by always dding a decimal place --- assets/android/src/TypographyTokens.kt | 32 ++++++++++++------------- src/transforms/kotlin/percentageToEm.ts | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/assets/android/src/TypographyTokens.kt b/assets/android/src/TypographyTokens.kt index 47f5894d..b00672a8 100644 --- a/assets/android/src/TypographyTokens.kt +++ b/assets/android/src/TypographyTokens.kt @@ -40,7 +40,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 22.sp, fontSize = 16.sp, - letterSpacing = 0.015625.em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -49,7 +49,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 22.sp, fontSize = 16.sp, - letterSpacing = 0.015625.em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -58,7 +58,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 20.sp, fontSize = 14.sp, - letterSpacing = 0.017857.em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -67,7 +67,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 20.sp, fontSize = 14.sp, - letterSpacing = 0.017857.em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -76,7 +76,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 17.sp, fontSize = 12.sp, - letterSpacing = 0.033333.em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -85,7 +85,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 17.sp, fontSize = 12.sp, - letterSpacing = 0.033333.em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -94,7 +94,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 15.sp, fontSize = 11.sp, - letterSpacing = 0.045454.em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -103,7 +103,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 15.sp, fontSize = 11.sp, - letterSpacing = 0.045454.em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -112,7 +112,7 @@ object TypographyTokens { fontWeight = FontWeight.W700, lineHeight = 34.sp, fontSize = 28.sp, - letterSpacing = 0em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -121,7 +121,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 34.sp, fontSize = 28.sp, - letterSpacing = 0em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -130,7 +130,7 @@ object TypographyTokens { fontWeight = FontWeight.W700, lineHeight = 27.sp, fontSize = 22.sp, - letterSpacing = 0em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -139,7 +139,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 27.sp, fontSize = 22.sp, - letterSpacing = 0em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -148,7 +148,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 25.sp, fontSize = 20.sp, - letterSpacing = 0em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -157,7 +157,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 25.sp, fontSize = 20.sp, - letterSpacing = 0em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -166,7 +166,7 @@ object TypographyTokens { fontWeight = FontWeight.W700, lineHeight = 41.sp, fontSize = 34.sp, - letterSpacing = 0em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -175,7 +175,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 41.sp, fontSize = 34.sp, - letterSpacing = 0em, + letterSpacing = 0.0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) diff --git a/src/transforms/kotlin/percentageToEm.ts b/src/transforms/kotlin/percentageToEm.ts index 85f7204f..a6b38125 100644 --- a/src/transforms/kotlin/percentageToEm.ts +++ b/src/transforms/kotlin/percentageToEm.ts @@ -28,6 +28,6 @@ export default { }, transform: (token: TransformedToken): string => { const val = Number.parseFloat(token.value.replace("%", "")); - return `${val / 100}.em`; + return `${(val / 100).toFixed(1)}.em`; }, } satisfies Transform; From d1299767005635ed28270a417b7ab0e3d6638b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Wed, 31 Jul 2024 16:03:15 +0200 Subject: [PATCH 2/2] Use @robintown's suggestion instead --- assets/android/src/TypographyTokens.kt | 32 ++++++++++++------------- src/configs/getAndroidConfig.ts | 1 - src/transforms/kotlin/percentageToEm.ts | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/assets/android/src/TypographyTokens.kt b/assets/android/src/TypographyTokens.kt index b00672a8..b6ce1d4b 100644 --- a/assets/android/src/TypographyTokens.kt +++ b/assets/android/src/TypographyTokens.kt @@ -40,7 +40,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 22.sp, fontSize = 16.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.015625.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -49,7 +49,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 22.sp, fontSize = 16.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.015625.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -58,7 +58,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 20.sp, fontSize = 14.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.017857.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -67,7 +67,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 20.sp, fontSize = 14.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.017857.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -76,7 +76,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 17.sp, fontSize = 12.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.033333.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -85,7 +85,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 17.sp, fontSize = 12.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.033333.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -94,7 +94,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 15.sp, fontSize = 11.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.045454.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -103,7 +103,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 15.sp, fontSize = 11.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.045454.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -112,7 +112,7 @@ object TypographyTokens { fontWeight = FontWeight.W700, lineHeight = 34.sp, fontSize = 28.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -121,7 +121,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 34.sp, fontSize = 28.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -130,7 +130,7 @@ object TypographyTokens { fontWeight = FontWeight.W700, lineHeight = 27.sp, fontSize = 22.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -139,7 +139,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 27.sp, fontSize = 22.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -148,7 +148,7 @@ object TypographyTokens { fontWeight = FontWeight.W500, lineHeight = 25.sp, fontSize = 20.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -157,7 +157,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 25.sp, fontSize = 20.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -166,7 +166,7 @@ object TypographyTokens { fontWeight = FontWeight.W700, lineHeight = 41.sp, fontSize = 34.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) @@ -175,7 +175,7 @@ object TypographyTokens { fontWeight = FontWeight.W400, lineHeight = 41.sp, fontSize = 34.sp, - letterSpacing = 0.0.em, + letterSpacing = 0.em, platformStyle = PlatformTextStyle(includeFontPadding = false), lineHeightStyle = LineHeightStyle(LineHeightStyle.Alignment.Center, LineHeightStyle.Trim.None) ) diff --git a/src/configs/getAndroidConfig.ts b/src/configs/getAndroidConfig.ts index 25e57d0d..bfd1db75 100644 --- a/src/configs/getAndroidConfig.ts +++ b/src/configs/getAndroidConfig.ts @@ -240,7 +240,6 @@ export function getCommonAndroidConfig(): PlatformConfig { return { transforms: [ "camelCaseDecimal", - "ts/resolveMath", "attribute/cti", "kotlin/fontWeight", "kotlin/literal", diff --git a/src/transforms/kotlin/percentageToEm.ts b/src/transforms/kotlin/percentageToEm.ts index a6b38125..85f7204f 100644 --- a/src/transforms/kotlin/percentageToEm.ts +++ b/src/transforms/kotlin/percentageToEm.ts @@ -28,6 +28,6 @@ export default { }, transform: (token: TransformedToken): string => { const val = Number.parseFloat(token.value.replace("%", "")); - return `${(val / 100).toFixed(1)}.em`; + return `${val / 100}.em`; }, } satisfies Transform;