open-webui/src/lib/utils/text-scale.ts
Timothy Jaeryang Baek b9765fe979 refac
2026-08-30 12:36:16 -04:00

27 lines
770 B
TypeScript

export const setTextScale = (scale: number) => {
if (typeof document === 'undefined') {
return;
}
document.documentElement.style.setProperty('--app-text-scale', `${scale}`);
};
export const normalizeAppFontFamily = (fontFamily?: string | null) =>
typeof fontFamily === 'string' ? fontFamily.trim().replace(/[\u0000-\u001f\u007f]/g, '') : '';
export const setAppFontFamily = (fontFamily?: string | null) => {
if (typeof document === 'undefined') {
return;
}
const normalized = normalizeAppFontFamily(fontFamily);
if (!normalized) {
document.documentElement.style.removeProperty('--app-font-family');
return;
}
document.documentElement.style.setProperty(
'--app-font-family',
`"${normalized.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`
);
};