311, 'enabled' => true, 'position' => 'right'];
$content_width = $container_max === 0 ? '100%' : $container_max . 'px';
$content_no_sidebar_max = $container_max === 0 ? '100%' : max(860, $container_max - 220) . 'px';
$container_wide = $container_max === 0 ? '100%' : max(1280, $container_max + 160) . 'px';
$radius_sm = max(0, $border_radius - 2);
$radius_lg = $border_radius + 4;
$radius_xl = $border_radius + 10;
$rgb = $this->hex_to_rgb($primary_color);
$primary_hover = $this->adjust_hex_color($primary_color, -0.12);
$primary_active = $this->adjust_hex_color($primary_color, -0.22);
$font_stacks = $this->resolve_font_stacks($font_family);
$dark_rgb = $this->hex_to_rgb($dark_primary);
$dark_hover = $this->adjust_hex_color($dark_primary, -0.12);
$dark_active = $this->adjust_hex_color($dark_primary, -0.22);
$layout_vars = [
'--content-max' => $content_width,
'--content-no-sidebar-max' => $content_no_sidebar_max,
'--container' => $content_width,
'--container-wide' => $container_wide,
'--sidebar-width' => $sidebar_cfg['width'] . 'px',
'--color-primary' => $primary_color,
'--color-primary-hover' => $primary_hover,
'--color-primary-active' => $primary_active,
'--color-primary-soft' => sprintf('rgba(%d, %d, %d, 0.12)', $rgb[0], $rgb[1], $rgb[2]),
'--color-primary-softer' => sprintf('rgba(%d, %d, %d, 0.06)', $rgb[0], $rgb[1], $rgb[2]),
'--color-primary-rgb' => implode(', ', $rgb),
'--focus-color' => $primary_color,
'--radius-sm' => $radius_sm . 'px',
'--radius' => $border_radius . 'px',
'--radius-card' => $card_radius . 'px',
'--main-radius' => $card_radius . 'px',
'--radius-btn' => $border_radius . 'px',
'--radius-code' => $border_radius . 'px',
'--radius-lg' => $radius_lg . 'px',
'--radius-xl' => $radius_xl . 'px',
'--shadow-md' => '0 8px 24px rgba(20, 28, 48, 0.10)',
'--font-body' => $font_stacks['body'],
'--font-display' => $font_stacks['display'],
'--font-ui' => $font_stacks['ui'],
'--font-heading' => $font_stacks['ui'],
'--aksrt-logo-width' => $logo_width . 'px',
'--posts-list-scale' => (class_exists('AKSRT_Settings') ? AKSRT_Settings::get_post_list_style_settings()['list_scale'] ?? 70 : 70) . '%',
'--posts-card-scale' => (class_exists('AKSRT_Settings') ? AKSRT_Settings::get_post_list_style_settings()['card_scale'] ?? 70 : 70) . '%',
];
echo '' . "\n";
if (class_exists('AKSRT_Settings') && !empty(AKSRT_Settings::get_value('close_backdrop', false))) {
echo '' . "\n";
}
echo '' . "\n";
}
private function resolve_font_stacks(string $family): array {
switch ($family) {
case 'noto-sans-sc':
return [
'body' => '"Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif',
'display' => '"Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif',
'ui' => 'Inter, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif',
];
case 'noto-serif-sc':
return [
'body' => '"Noto Serif SC", Georgia, "Songti SC", serif',
'display' => '"Noto Serif SC", Georgia, "Songti SC", serif',
'ui' => 'Inter, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif',
];
default:
return [
'body' => '"Source Serif 4", "Noto Serif SC", Georgia, "Songti SC", "STSong", serif',
'display' => '"Source Serif 4", "Noto Serif SC", Georgia, "Songti SC", "STSong", serif',
'ui' => 'Inter, Manrope, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',
];
}
}
private function hex_to_rgb(string $hex): array {
$hex = ltrim($hex, '#');
if (strlen($hex) === 3) {
$hex = preg_replace('/(.)/', '$1$1', $hex);
}
if (!is_string($hex) || strlen($hex) !== 6) {
return [136, 171, 218];
}
return [
hexdec(substr($hex, 0, 2)),
hexdec(substr($hex, 2, 2)),
hexdec(substr($hex, 4, 2)),
];
}
private function adjust_hex_color(string $hex, float $amount): string {
$rgb = $this->hex_to_rgb($hex);
$adjusted = array_map(
static function (int $channel) use ($amount): int {
$base = $amount >= 0
? $channel + ((255 - $channel) * $amount)
: $channel * (1 + $amount);
return max(0, min(255, (int) round($base)));
},
$rgb
);
return sprintf('#%02X%02X%02X', $adjusted[0], $adjusted[1], $adjusted[2]);
}
}