fix: apply theme logo scale reliably

This commit is contained in:
3252a8
2026-06-03 11:42:03 +03:00
parent e52c75538f
commit bcb7372500
4 changed files with 27 additions and 5 deletions
+9
View File
@@ -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}")
+1 -1
View File
@@ -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", {}, "Не удалось сохранить"));
}
@@ -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));
}
</script>
@@ -33,7 +44,7 @@
step={sliderStep}
{disabled}
onValueChange={handleValueChange}
{onValueCommit}
onValueCommit={handleValueCommit}
{...$$restProps}
>
<Slider.Range class="ui-range-input__range" />
+2
View File
@@ -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):