From bcb737250089241d9c23227ace713d4b08c6b1d5 Mon Sep 17 00:00:00 2001 From: 3252a8 <3252a8@proton.me> Date: Wed, 3 Jun 2026 11:42:03 +0300 Subject: [PATCH] fix: apply theme logo scale reliably --- backend/bot/app/web/webapp/assets.py | 9 +++++++++ frontend/src/lib/admin/stores/themesStore.js | 2 +- .../src/lib/components/ui/range-input.svelte | 19 +++++++++++++++---- tests/test_webapp_assets.py | 2 ++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/backend/bot/app/web/webapp/assets.py b/backend/bot/app/web/webapp/assets.py index 7b2aba8..3206b03 100644 --- a/backend/bot/app/web/webapp/assets.py +++ b/backend/bot/app/web/webapp/assets.py @@ -1516,6 +1516,7 @@ _INITIAL_THEME_TOKEN_CSS_MAP = { "font_sans": "--font-sans", "font_logo": "--font-logo", "font_mono": "--font-mono", + "home_logo_scale": "--home-logo-scale", "admin_bg": "--admin-bg", "admin_surface": "--admin-surface", "admin_surface_2": "--admin-surface-2", @@ -1570,6 +1571,14 @@ def _initial_theme_head_markup(request: web.Request, theme: Any, primary_color: tokens = tokens if isinstance(tokens, dict) else {} declarations = [] for token_key, css_name in _INITIAL_THEME_TOKEN_CSS_MAP.items(): + if token_key == "home_logo_scale": + try: + scale = float(tokens.get(token_key) or 0) + except (TypeError, ValueError): + continue + if scale > 0: + declarations.append(f"{css_name}:{scale / 100:g}") + continue value = str(tokens.get(token_key) or "").strip() if value: declarations.append(f"{css_name}:{value}") diff --git a/frontend/src/lib/admin/stores/themesStore.js b/frontend/src/lib/admin/stores/themesStore.js index 6e8acfc..7d20d45 100644 --- a/frontend/src/lib/admin/stores/themesStore.js +++ b/frontend/src/lib/admin/stores/themesStore.js @@ -49,7 +49,7 @@ export function createThemesStore({ api, onThemesSaved, flash, at }) { themesDir: data.themes_dir || s.themesDir, })); if (!silent) flash(at("themes_saved", {}, "Темы сохранены")); - if (typeof onThemesSaved === "function") onThemesSaved(); + if (typeof onThemesSaved === "function") await onThemesSaved(); } else { flash(data?.message || data?.error || at("themes_save_failed", {}, "Не удалось сохранить")); } diff --git a/frontend/src/lib/components/ui/range-input.svelte b/frontend/src/lib/components/ui/range-input.svelte index c420c56..3c0ea7f 100644 --- a/frontend/src/lib/components/ui/range-input.svelte +++ b/frontend/src/lib/components/ui/range-input.svelte @@ -13,14 +13,25 @@ let className = ""; export { className as class }; - $: sliderValue = Number(value ?? min ?? 0); $: sliderMin = min === undefined ? undefined : Number(min); $: sliderMax = max === undefined ? undefined : Number(max); $: sliderStep = step === undefined ? undefined : Number(step); + $: sliderValue = normalizeSliderValue(value, sliderMin ?? 0); + + function normalizeSliderValue(next, fallback = 0) { + const raw = Array.isArray(next) ? next[0] : next; + const numeric = Number(raw); + return Number.isFinite(numeric) ? numeric : fallback; + } function handleValueChange(next) { - value = next; - onValueChange(next); + const normalized = normalizeSliderValue(next, sliderMin ?? 0); + value = normalized; + onValueChange(normalized); + } + + function handleValueCommit(next) { + onValueCommit(normalizeSliderValue(next, sliderMin ?? 0)); } @@ -33,7 +44,7 @@ step={sliderStep} {disabled} onValueChange={handleValueChange} - {onValueCommit} + onValueCommit={handleValueCommit} {...$$restProps} > diff --git a/tests/test_webapp_assets.py b/tests/test_webapp_assets.py index 3dc6777..795c6a6 100644 --- a/tests/test_webapp_assets.py +++ b/tests/test_webapp_assets.py @@ -646,6 +646,7 @@ class WebAppAssetTests(unittest.IsolatedAsyncioTestCase): def test_initial_theme_head_markup_includes_css_and_tokens(self): cfg = builtin_webapp_themes_config("#123456") theme = cfg.theme_by_key("light") + theme.tokens.home_logo_scale = 135 request = SimpleNamespace(get=lambda key, default="": "nonce-value") markup = subscription_webapp._initial_theme_head_markup(request, theme, "#123456") @@ -653,6 +654,7 @@ class WebAppAssetTests(unittest.IsolatedAsyncioTestCase): self.assertIn("/webapp-theme-css/light/style.css?v=", markup) self.assertIn('nonce="nonce-value"', markup) self.assertIn("--accent:#123456", markup) + self.assertIn("--home-logo-scale:1.35", markup) self.assertIn("color-scheme:light", markup) def test_theme_asset_version_bumps_for_saved_default_css_theme(self):