2024-04-05 22:24:21 +03:00
|
|
|
import { Request, Response } from 'express';
|
2024-07-18 21:35:17 +03:00
|
|
|
import optionService from "../../services/options.js";
|
2025-01-03 20:27:58 +02:00
|
|
|
import { OptionMap } from '../../services/options_interface.js';
|
2021-09-27 21:01:56 +02:00
|
|
|
|
2025-01-03 20:54:14 +02:00
|
|
|
const SYSTEM_SANS_SERIF = [
|
|
|
|
|
"-apple-system",
|
|
|
|
|
"BlinkMacSystemFont",
|
|
|
|
|
"Segoe UI",
|
|
|
|
|
"Noto Sans",
|
|
|
|
|
"Helvetica",
|
|
|
|
|
"Arial",
|
|
|
|
|
"sans-serif",
|
|
|
|
|
"Apple Color Emoji","Segoe UI Emoji"
|
|
|
|
|
].join(",");
|
|
|
|
|
|
|
|
|
|
const SYSTEM_MONOSPACE = [
|
|
|
|
|
"monospace"
|
|
|
|
|
].join(",");
|
|
|
|
|
|
2024-04-05 22:24:21 +03:00
|
|
|
function getFontCss(req: Request, res: Response) {
|
2021-09-27 21:01:56 +02:00
|
|
|
res.setHeader('Content-Type', 'text/css');
|
|
|
|
|
|
|
|
|
|
if (!optionService.getOptionBool('overrideThemeFonts')) {
|
|
|
|
|
res.send('');
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-29 22:10:13 +02:00
|
|
|
const optionsMap = optionService.getOptionMap();
|
2021-09-27 21:01:56 +02:00
|
|
|
|
|
|
|
|
// using body to be more specific than themes' :root
|
2021-10-03 20:54:20 +02:00
|
|
|
let style = 'body {';
|
2025-01-03 20:27:58 +02:00
|
|
|
style += getFontFamily(optionsMap);
|
|
|
|
|
style += getFontSize(optionsMap);
|
|
|
|
|
style += '}';
|
|
|
|
|
|
|
|
|
|
res.send(style);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-03 20:54:14 +02:00
|
|
|
function getFontFamily({ mainFontFamily, treeFontFamily, detailFontFamily, monospaceFontFamily }: OptionMap) {
|
2025-01-03 20:27:58 +02:00
|
|
|
let style = "";
|
|
|
|
|
|
2025-01-03 20:54:14 +02:00
|
|
|
// System override
|
|
|
|
|
if (mainFontFamily === "system") {
|
|
|
|
|
mainFontFamily = SYSTEM_SANS_SERIF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (treeFontFamily === "system") {
|
|
|
|
|
treeFontFamily = SYSTEM_SANS_SERIF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (detailFontFamily === "system") {
|
|
|
|
|
detailFontFamily = SYSTEM_SANS_SERIF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (monospaceFontFamily === "system") {
|
|
|
|
|
monospaceFontFamily = SYSTEM_MONOSPACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply the font override if not using theme fonts.
|
|
|
|
|
if (mainFontFamily !== 'theme') {
|
|
|
|
|
style += `--main-font-family: ${mainFontFamily};`;
|
2025-01-03 20:27:58 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-03 20:54:14 +02:00
|
|
|
if (treeFontFamily !== 'theme') {
|
|
|
|
|
style += `--tree-font-family: ${treeFontFamily};`;
|
2025-01-03 20:27:58 +02:00
|
|
|
}
|
2021-10-03 20:54:20 +02:00
|
|
|
|
2025-01-03 20:54:14 +02:00
|
|
|
if (detailFontFamily !== 'theme') {
|
|
|
|
|
style += `--detail-font-family: ${detailFontFamily};`;
|
2025-01-03 20:27:58 +02:00
|
|
|
}
|
2021-10-03 20:54:20 +02:00
|
|
|
|
2025-01-03 20:54:14 +02:00
|
|
|
if (monospaceFontFamily !== 'theme') {
|
|
|
|
|
style += `--monospace-font-family: ${monospaceFontFamily};`;
|
2025-01-03 20:27:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return style;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getFontSize(optionsMap: OptionMap) {
|
|
|
|
|
let style = "";
|
2021-10-03 20:54:20 +02:00
|
|
|
style += `--main-font-size: ${optionsMap.mainFontSize}%;`;
|
|
|
|
|
style += `--tree-font-size: ${optionsMap.treeFontSize}%;`;
|
|
|
|
|
style += `--detail-font-size: ${optionsMap.detailFontSize}%;`;
|
2021-10-31 16:48:21 +01:00
|
|
|
style += `--monospace-font-size: ${optionsMap.monospaceFontSize}%;`;
|
2021-10-03 20:54:20 +02:00
|
|
|
|
2025-01-03 20:27:58 +02:00
|
|
|
return style;
|
2021-09-27 21:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-18 21:42:44 +03:00
|
|
|
export default {
|
2021-09-27 21:01:56 +02:00
|
|
|
getFontCss
|
|
|
|
|
};
|