tailwind px helper

This commit is contained in:
2025-04-28 20:28:38 +02:00
parent d88138ecce
commit 3695eb084d

View File

@@ -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
}
}