2025-01-09 18:07:02 +02:00
|
|
|
import { Request, Response } from "express";
|
2024-07-18 21:35:17 +03:00
|
|
|
import optionService from "../../services/options.js";
|
2025-01-09 18:07:02 +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 = [
|
2025-01-03 21:08:30 +02:00
|
|
|
"system-ui",
|
2025-01-09 18:07:02 +02:00
|
|
|
"-apple-system",
|
|
|
|
|
"BlinkMacSystemFont",
|
2025-01-03 20:54:14 +02:00
|
|
|
"Segoe UI",
|
2025-01-03 20:59:13 +02:00
|
|
|
"Cantarell",
|
|
|
|
|
"Ubuntu",
|
2025-01-03 20:54:14 +02:00
|
|
|
"Noto Sans",
|
|
|
|
|
"Helvetica",
|
|
|
|
|
"Arial",
|
|
|
|
|
"sans-serif",
|
2025-01-09 18:07:02 +02:00
|
|
|
"Apple Color Emoji",
|
|
|
|
|
"Segoe UI Emoji"
|
2025-01-03 20:54:14 +02:00
|
|
|
].join(",");
|
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
const SYSTEM_MONOSPACE = ["ui-monospace", "SFMono-Regular", "SF Mono", "Consolas", "Source Code Pro", "Ubuntu Mono", "Menlo", "Liberation Mono", "monospace"].join(",");
|
2025-01-03 20:54:14 +02:00
|
|
|
|
2024-04-05 22:24:21 +03:00
|
|
|
function getFontCss(req: Request, res: Response) {
|
2025-01-09 18:07:02 +02:00
|
|
|
res.setHeader("Content-Type", "text/css");
|
2021-09-27 21:01:56 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
if (!optionService.getOptionBool("overrideThemeFonts")) {
|
|
|
|
|
res.send("");
|
2021-09-27 21:01:56 +02:00
|
|
|
|
|
|
|
|
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
|
2025-01-09 18:07:02 +02:00
|
|
|
let style = "body {";
|
2025-01-03 20:27:58 +02:00
|
|
|
style += getFontFamily(optionsMap);
|
|
|
|
|
style += getFontSize(optionsMap);
|
2025-01-09 18:07:02 +02:00
|
|
|
style += "}";
|
2025-01-03 20:27:58 +02:00
|
|
|
|
|
|
|
|
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.
|
2025-01-09 18:07:02 +02:00
|
|
|
if (mainFontFamily !== "theme") {
|
2025-01-03 20:54:14 +02:00
|
|
|
style += `--main-font-family: ${mainFontFamily};`;
|
2025-01-03 20:27:58 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
if (treeFontFamily !== "theme") {
|
2025-01-03 20:54:14 +02:00
|
|
|
style += `--tree-font-family: ${treeFontFamily};`;
|
2025-01-03 20:27:58 +02:00
|
|
|
}
|
2021-10-03 20:54:20 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
if (detailFontFamily !== "theme") {
|
2025-01-03 20:54:14 +02:00
|
|
|
style += `--detail-font-family: ${detailFontFamily};`;
|
2025-01-03 20:27:58 +02:00
|
|
|
}
|
2021-10-03 20:54:20 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
if (monospaceFontFamily !== "theme") {
|
2025-01-03 20:54:14 +02:00
|
|
|
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
|
|
|
|
|
};
|