diff --git a/apps/app/src/lib/tailwindSizeToPx.ts b/apps/app/src/lib/tailwindSizeToPx.ts new file mode 100644 index 0000000..1f0b407 --- /dev/null +++ b/apps/app/src/lib/tailwindSizeToPx.ts @@ -0,0 +1,19 @@ +export function tailwindClassToPixels(className: string): number | null { + const remSize = getRemInPixels(); // <-- real rem size at runtime + + const regex = /^(w|h)-(\d+)$/; + const match = className.match(regex); + if (!match) return null; + + const value = parseInt(match[2], 10); + return (value / 4) * remSize; +} + +export function getRemInPixels(): number { + try { + const fontSize = getComputedStyle(document.documentElement).fontSize; + return parseFloat(fontSize); + } catch (e) { + return 16; // Default to 16px if unable to get computed style + } +}