From 625c1264fedd9e52023cd85d51a1bf8daa63c63c Mon Sep 17 00:00:00 2001 From: nfebe Date: Mon, 7 Jul 2025 20:37:18 +0100 Subject: [PATCH] fix(theming): Correctly generate CSS for font themes Fixes a regression from dropping the SCSS compiler that broke font themes like OpenDyslexic. The old code relied on the SCSS compiler to automatically correct the order of the CSS rules, ensuring the @font-face declaration was always valid. The server now correctly generates the `@font-face` rule at the top level of the stylesheet, fixing the previously invalid nested CSS. Introduced in : f1448fcf0777db7d4254cb0a3ef94d63be9f7a24 Signed-off-by: nfebe --- apps/theming/lib/Controller/ThemingController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 4763e384156..e5cee254fe8 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -402,7 +402,17 @@ class ThemingController extends Controller { $css = ":root { $variables } " . $customCss; } else { // If not set, we'll rely on the body class - $css = "[data-theme-$themeId] { $variables $customCss }"; + // We need to separate @-rules from normal selectors, as they can't be nested + // This is a replacement for the SCSS compiler that did this automatically before f1448fcf0777db7d4254cb0a3ef94d63be9f7a24 + // We need a better way to handle this, but for now we just remove comments and split the at-rules + // from the rest of the CSS. + $customCssWithoutComments = preg_replace('!/\*.*?\*/!s', '', $customCss); + $customCssWithoutComments = preg_replace('!//.*!', '', $customCssWithoutComments); + preg_match_all('/(@[^{]+{(?:[^{}]*|(?R))*})/', $customCssWithoutComments, $atRules); + $atRulesCss = implode('', $atRules[0]); + $scopedCss = preg_replace('/(@[^{]+{(?:[^{}]*|(?R))*})/', '', $customCssWithoutComments); + + $css = "$atRulesCss [data-theme-$themeId] { $variables $scopedCss }"; } try {