From ae0ce21fb930e8dcf53566e8adbc34ae9bdb4e97 Mon Sep 17 00:00:00 2001 From: Mark Lawlor Date: Thu, 7 Aug 2025 14:51:35 +1000 Subject: [PATCH] fix: parseLetterSpacing. Increase rounding precision --- src/compiler/declarations.ts | 22 ++++++++++++++------ src/runtime/native/conditions/media-query.ts | 2 +- src/runtime/native/styles/units.ts | 10 ++++++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/compiler/declarations.ts b/src/compiler/declarations.ts index 5ac9deb..aad7e94 100644 --- a/src/compiler/declarations.ts +++ b/src/compiler/declarations.ts @@ -757,7 +757,17 @@ function parseLetterSpacing( if (value.type === "normal") { return; } - return parseLength(value.value, builder); + const descriptor = parseLength(value.value, builder); + + if ( + Array.isArray(descriptor) && + descriptor[1] === "em" && + typeof descriptor[2] === "number" + ) { + return descriptor[2]; + } + + return descriptor; } function parseTextDecoration( @@ -1166,7 +1176,7 @@ export function parseLength( const { inlineRem = 14 } = builder.getOptions(); if (typeof length === "number") { - return length; + return round(length); } if ("unit" in length) { @@ -1177,19 +1187,19 @@ export function parseLength( } else if (length.value === -Infinity) { return -9999; } else { - return length.value; + return round(length.value); } } case "rem": if (typeof inlineRem === "number") { return length.value * inlineRem; } else { - return [{}, "rem", length.value]; + return [{}, "rem", round(length.value)]; } case "vw": case "vh": case "em": - return [{}, length.unit, length.value, 1]; + return [{}, length.unit, round(length.value), 1]; case "in": case "cm": case "mm": @@ -2288,7 +2298,7 @@ export function parseSVGPaint( } export function round(number: number) { - return Math.round((number + Number.EPSILON) * 100) / 100; + return Math.round((number + Number.EPSILON) * 10000) / 10000; } export function parseDimensionPercentageFor_LengthValue( diff --git a/src/runtime/native/conditions/media-query.ts b/src/runtime/native/conditions/media-query.ts index 7d4d0c7..c56e70f 100644 --- a/src/runtime/native/conditions/media-query.ts +++ b/src/runtime/native/conditions/media-query.ts @@ -39,7 +39,7 @@ function testComparison(mediaQuery: MediaCondition, get: Getter): Boolean { switch (mediaQuery[1]) { case "platform": - return right === Platform.OS; + return right === "native" || right === Platform.OS; case "prefers-color-scheme": { return right === get(colorScheme); } diff --git a/src/runtime/native/styles/units.ts b/src/runtime/native/styles/units.ts index 7e806b5..27457d2 100644 --- a/src/runtime/native/styles/units.ts +++ b/src/runtime/native/styles/units.ts @@ -2,17 +2,21 @@ import { rem as remObs, vh as vhObs, vw as vwObs } from "../reactivity"; import type { StyleFunctionResolver } from "./resolve"; -export const em: StyleFunctionResolver = (resolve, func) => { +export const em: StyleFunctionResolver = (resolve, func, get) => { let value = func[2]; if (!value) { return; } - const emValue = resolve([{}, "var", ["__rn-css-em"]]); + let emValue = resolve([{}, "var", ["__rn-css-em"]]); if (typeof emValue !== "number") { - return undefined; + emValue = get(remObs); + } + + if (typeof emValue !== "number") { + return; } return round(Number(value) * emValue);