-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Hello again 😊 I've been using Capsize recently with REM units and ThreeJS which relies on World units and was wondering if you'd be interested in simplifying precomputeValues to numeric values to better serve these use cases? This would be a breaking change so totally understand if you'd rather not change the API this much, but I think something along the lines of this would help:
const values = precomputeValues({ fontMetrics, capHeight: 2, lineGap: 1 })
const textStyles = {
fontSize: `${values.fontSize}rem`,
lineHeight: `${values.lineHeight}rem`,
marginTop: `${values.capHeightTrim}rem`,
marginBottom: `${values.baselineTrim}rem`
}So you'd get numeric values back that are more flexible to work with and instead of using em units for the trim values, I propose multiplying the value by the font size so it can be used with libraries like ThreeJS where relative values don't exist.
Right now I simply parse and round the incoming values myself which is working well:
export const roundValue = (value) => {
return Math.round(parseFloat(value) * 10000) / 10000
}
export function createTextStyles({
capHeight,
lineGap,
}: {
capHeight: number
lineGap: number
}) {
const values = precomputeValues({ fontMetrics, capHeight, lineGap })
return {
fontSize: roundValue(values.fontSize),
lineHeight: roundValue(values.lineHeight),
leadingTrim: roundValue(lineGap / 2),
}
}Happy to work on a PR for this if it sounds like something you'd want to add 🙂