mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-13 22:39:06 +02:00
tailwind px helper
This commit is contained in:
19
apps/app/src/lib/tailwindSizeToPx.ts
Normal file
19
apps/app/src/lib/tailwindSizeToPx.ts
Normal 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user