2025-12-07 19:32:53 +02:00
|
|
|
import { SEMANTIC_TYPOGRAPHY } from '@/lib/typography';
|
|
|
|
|
|
|
|
|
|
let started = false;
|
|
|
|
|
|
2025-12-13 16:34:17 +02:00
|
|
|
const TYPOGRAPHY_STYLE_ID = 'openchamber-typography-base';
|
|
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
const applySemanticTypography = (): void => {
|
|
|
|
|
if (typeof document === 'undefined') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-12-13 16:34:17 +02:00
|
|
|
|
|
|
|
|
const cssVars = Object.entries(SEMANTIC_TYPOGRAPHY)
|
|
|
|
|
.map(([key, value]) => ` --text-${key.replace(/([A-Z])/g, '-$1').toLowerCase()}: ${value};`)
|
|
|
|
|
.join('\n');
|
|
|
|
|
|
|
|
|
|
const styleContent = `:root {\n${cssVars}\n}\n`;
|
|
|
|
|
|
|
|
|
|
const existing = document.getElementById(TYPOGRAPHY_STYLE_ID);
|
|
|
|
|
if (existing) {
|
|
|
|
|
existing.textContent = styleContent;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const style = document.createElement('style');
|
|
|
|
|
style.id = TYPOGRAPHY_STYLE_ID;
|
|
|
|
|
style.textContent = styleContent;
|
|
|
|
|
document.head.appendChild(style);
|
2025-12-07 19:32:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const startTypographyWatcher = (): void => {
|
|
|
|
|
if (started || typeof window === 'undefined') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
started = true;
|
|
|
|
|
|
|
|
|
|
applySemanticTypography();
|
|
|
|
|
};
|