refactor: flatten src/AKSRT → src (drop theme-identifier dir)

Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
This commit is contained in:
kate522 committed 2026-08-02 22:06:06 +08:00
1 parent 56f1a8175f
commit 8c5b1555c9
285 files changed
+26 -3600

No files matched your search

+192
View File
@@ -0,0 +1,192 @@
<?php
/**
* @package AKSRT
*/
namespace AKSRT\Frontend;
defined('ABSPATH') || exit;
class InlineStyleBuilder {
public function output(): void {
$logo_url = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::logo_url() : (string) aksrt_get_setting('logo_url', '');
$dark_logo_url = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::logo_dark_url() : (string) aksrt_get_setting('site_logo_dark', '');
$favicon = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::favicon_url() : (string) aksrt_get_setting('favicon_url', '');
$primary_color = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::resolved_primary_color() : '#f04494';
$dark_primary = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::dark_primary_color() : '#f04494';
$border_radius = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::border_radius() : 8;
$card_radius = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::card_radius() : ($border_radius + 4);
$container_max = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::container_max_width() : 1200;
$font_family = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::font_family() : 'system';
$logo_width = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::logo_width() : 150;
$sidebar_cfg = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_sidebar_config() : ['width' => 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);
// Zibll hard-codes 311px dual-column math; keep runtime width aligned to that
// baseline when settings still hold the old 300 default (or empty).
$sidebar_width = (int) ($sidebar_cfg['width'] ?? 311);
if ($sidebar_width <= 0 || $sidebar_width === 300) {
$sidebar_width = 311;
}
$sidebar_width = max(200, min(400, $sidebar_width));
$layout_vars = [
'--content-max' => $content_width,
'--content-no-sidebar-max' => $content_no_sidebar_max,
'--container' => $content_width,
'--container-wide' => $container_wide,
'--mian-max-width' => $content_width, // zibll typo token
'--sidebar-width' => $sidebar_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',
// Zibll --main-radius tracks the base radius (8), not the larger card radius.
'--main-radius' => $border_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)',
'--main-shadow' => 'rgba(116, 116, 116, 0.08)',
'--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',
'--nav-height' => '60px',
'--single-cover-scale' => '35%',
'--posts-list-scale' => (class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['list_scale'] ?? 70 : 70) . '%',
'--posts-card-scale' => (class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['card_scale'] ?? 70 : 70) . '%',
];
echo '<style id="aksrt-runtime-vars">:root{';
foreach ($layout_vars as $name => $value) {
echo esc_html($name) . ':' . esc_attr($value) . ';';
}
if ($logo_url) {
echo '--aksrt-logo-url:"' . esc_url($logo_url) . '";';
}
if ($dark_logo_url) {
echo '--aksrt-logo-dark-url:"' . esc_url($dark_logo_url) . '";';
}
if ($favicon) {
echo '--aksrt-favicon:"' . esc_url($favicon) . '";';
}
if ($dark_primary !== $primary_color) {
echo '}html.dark{';
echo '--color-primary:' . esc_attr($dark_primary) . ';';
echo '--color-primary-hover:' . esc_attr($dark_hover) . ';';
echo '--color-primary-active:' . esc_attr($dark_active) . ';';
echo '--color-primary-soft:' . sprintf('rgba(%d,%d,%d,0.12)', $dark_rgb[0], $dark_rgb[1], $dark_rgb[2]) . ';';
echo '--color-primary-softer:' . sprintf('rgba(%d,%d,%d,0.06)', $dark_rgb[0], $dark_rgb[1], $dark_rgb[2]) . ';';
echo '--color-primary-rgb:' . esc_attr(implode(', ', $dark_rgb)) . ';';
echo '--focus-color:' . esc_attr($dark_primary) . ';';
}
echo '}</style>' . "\n";
// Zibll header_theme_custom → --header-bg / --header-color on .header.
if (class_exists('\AKSRT\Settings\Settings')) {
$ht = \AKSRT\Settings\Settings::get_header_theme_config();
if (!empty($ht['custom'])) {
$h_bg = $ht['bg_custom'] !== '' ? $ht['bg_custom'] : ($ht['bg'] ?? '');
$h_fg = $ht['color_custom'] ?? '';
if ($h_bg !== '' || $h_fg !== '') {
echo '<style id="aksrt-header-theme">.header{';
if ($h_bg !== '') {
echo '--header-bg:' . esc_attr($h_bg) . ';background:' . esc_attr($h_bg) . ';';
}
if ($h_fg !== '') {
echo '--header-color:' . esc_attr($h_fg) . ';color:' . esc_attr($h_fg) . ';';
}
echo '}</style>' . "\n";
}
}
}
if (class_exists('\AKSRT\Settings\Settings') && !empty(\AKSRT\Settings\Settings::get_value('close_backdrop', false))) {
echo '<style id="aksrt-no-backdrop">.aksrt-header,.header-inner,.site-header,.header,.mobile-nav-overlay,.modal-backdrop,.aksrt-drawer-overlay,.aksrt-float-btn,.sidebar-inner{backdrop-filter:none!important;-webkit-backdrop-filter:none!important;background-color:var(--bg-card,#fff)!important}</style>' . "\n";
}
echo '<style id="aksrt-runtime-components">'
. '.aksrt-search-hot-keywords{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:12px;font-family:var(--font-ui);}'
. '.aksrt-search-hot-keywords__label{font-size:12px;color:var(--color-ink-3);}'
. '.aksrt-search-hot-keywords__list{display:flex;gap:8px;flex-wrap:wrap;}'
. '.aksrt-search-hot-keywords__item{display:inline-flex;align-items:center;padding:4px 10px;border-radius:999px;background:var(--surface-2,#f3f4f6);color:var(--color-ink-2,#374151);font-size:12px;line-height:1.4;text-decoration:none;}'
. '.aksrt-search-hot-keywords__item:hover{background:var(--color-primary,#2563eb);color:#fff;}'
. '.site-footer__copyright--extra{margin-top:8px;opacity:.78;}'
. '</style>' . "\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]);
}
}