@once
@php
// One lifecycle, with a different visual design for each supplied theme.
// Public pages already supply runtime data; portal layouts pass their own context.
$loaderThemeManager = app(\App\Services\ThemeManager::class);
$loaderTheme = (array) ($pageLoaderTheme ?? $runtimeTheme ?? $activeTheme ?? $loaderThemeManager->active());
$loaderCms = (array) ($pageLoaderCms ?? $runtimeCms ?? $cms ?? app(\App\Services\CmsSettingsService::class)->get());
$loaderBranding = (array) data_get($loaderCms, 'branding', $runtimeBranding ?? []);
$loaderThemeSlug = (string) ($loaderTheme['slug'] ?? $runtimeThemeSlug ?? $loaderThemeManager->activeSlug());
$loaderDesignSlug = (string) ($pageLoaderDesign ?? $loaderThemeSlug);
if (!\App\Support\ClientThemeDesign::supports($loaderDesignSlug)) {
$loaderTemplate = $loaderThemeManager->record($loaderThemeSlug);
$loaderDesignSlug = $loaderTemplate ? \App\Support\ClientThemeDesign::layoutFor($loaderTemplate) : 'fina';
}
$loaderContext = in_array($pageLoaderContext ?? 'website', ['website', 'client', 'auth'], true)
? ($pageLoaderContext ?? 'website') : 'website';
$loaderMode = $loaderContext === 'website' ? \App\Support\BrandLogo::themeSurface($loaderDesignSlug) : 'dark';
$loaderBrandName = trim((string) data_get($loaderBranding, 'brand_name', ''))
?: trim((string) data_get($loaderBranding, 'site_name', ''))
?: trim((string) ($runtimeSiteName ?? config('app.name', 'Trading Platform')))
?: 'Trading Platform';
$loaderEnabled = data_get($loaderBranding, 'loader_enabled', 'yes') !== 'no';
$loaderShowLogo = data_get($loaderBranding, 'loader_show_logo', 'yes') !== 'no';
$loaderFrequency = in_array(data_get($loaderBranding, 'loader_frequency', 'session'), ['page', 'session'], true)
? (string) data_get($loaderBranding, 'loader_frequency', 'session') : 'session';
$loaderMessage = trim((string) data_get($loaderBranding, 'loader_message', 'Preparing your trading workspace'))
?: 'Preparing your trading workspace';
$loaderMinimumMs = max(0, min(3000, (int) data_get($loaderBranding, 'loader_min_duration', 550)));
$loaderMaximumMs = max(2000, min(15000, (int) data_get($loaderBranding, 'loader_max_duration', 7000)));
$loaderMaximumMs = max($loaderMaximumMs, $loaderMinimumMs + 500);
$loaderUseTextLogo = data_get($loaderBranding, 'use_text_logo', 'no') === 'yes';
$loaderLogoLocation = match ($loaderContext) {
'client' => 'client_header',
'auth' => 'auth',
default => 'main_menu',
};
$loaderLogoLight = $loaderUseTextLogo ? null : \App\Support\BrandLogo::url($loaderLogoLocation, $loaderCms, 'light');
$loaderLogoDark = $loaderUseTextLogo ? null : \App\Support\BrandLogo::url($loaderLogoLocation, $loaderCms, 'dark');
$loaderLightSource = \App\Support\BrandLogo::source('light', $loaderCms);
$loaderDarkSource = \App\Support\BrandLogo::source('dark', $loaderCms);
// A forced/fallback logo keeps a suitable plate even on the opposite color mode.
$loaderLogoSurfaceLight = $loaderLogoLight && $loaderLogoLight === $loaderDarkSource
&& (!$loaderLightSource || \App\Support\BrandLogo::mode($loaderLogoLocation, $loaderCms, 'light') === 'dark') ? 'dark' : 'light';
$loaderLogoSurfaceDark = $loaderLogoDark && $loaderLogoDark === $loaderLightSource
&& (!$loaderDarkSource || \App\Support\BrandLogo::mode($loaderLogoLocation, $loaderCms, 'dark') === 'light') ? 'light' : 'dark';
$loaderInitials = $loaderUseTextLogo ? trim((string) data_get($loaderBranding, 'text_logo_letters', '')) : '';
if ($loaderInitials === '') {
$loaderWords = preg_split('/[^\pL\pN]+/u', $loaderBrandName, -1, PREG_SPLIT_NO_EMPTY) ?: [];
$loaderInitials = collect($loaderWords)->take(3)
->map(static fn (string $word): string => mb_strtoupper(mb_substr($word, 0, 1)))->implode('');
}
$loaderInitials = mb_strtoupper(mb_substr($loaderInitials ?: $loaderBrandName, 0, 4));
$normalizeLoaderHex = static function (mixed $value, string $fallback): string {
$value = trim((string) $value);
if (preg_match('/^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$/D', $value) !== 1) return $fallback;
if (strlen($value) === 4) $value = '#'.$value[1].$value[1].$value[2].$value[2].$value[3].$value[3];
return strtoupper($value);
};
$loaderHexToRgb = static fn (string $hex): string => implode(', ', [
hexdec(substr($hex, 1, 2)), hexdec(substr($hex, 3, 2)), hexdec(substr($hex, 5, 2)),
]);
$loaderContrastText = static function (string $hex): string {
$rgb = [hexdec(substr($hex, 1, 2)), hexdec(substr($hex, 3, 2)), hexdec(substr($hex, 5, 2))];
[$r, $g, $b] = array_map(static function (int $channel): float {
$c = $channel / 255;
return $c <= 0.04045 ? $c / 12.92 : (($c + 0.055) / 1.055) ** 2.4;
}, $rgb);
$luminance = 0.2126 * $r + 0.7152 * $g + 0.0722 * $b;
return ($luminance + 0.05) / 0.05 >= 1.05 / ($luminance + 0.05) ? '#000000' : '#FFFFFF';
};
$loaderCustomColors = data_get($loaderCms, 'colors.customized', 'no') === 'yes';
$loaderPrimary = $normalizeLoaderHex($loaderCustomColors
? data_get($loaderCms, 'colors.primary', $loaderTheme['primary'] ?? null)
: ($loaderTheme['primary'] ?? $runtimePrimary ?? null), '#2F6BFF');
$loaderSecondary = $normalizeLoaderHex($loaderCustomColors
? data_get($loaderCms, 'colors.secondary', $loaderTheme['secondary'] ?? null)
: ($loaderTheme['secondary'] ?? $runtimeSecondary ?? null), '#10131A');
$loaderAccent = $normalizeLoaderHex($loaderCustomColors
? data_get($loaderCms, 'colors.accent', $loaderTheme['accent'] ?? null)
: ($loaderTheme['accent'] ?? $runtimeAccent ?? null), '#F6C80F');
// Once per session is shared by the public/auth/client pages of this brand
// and theme; switching to another theme reveals its own loading design.
$loaderStorageKey = 'platform-site-loader:v3:'.sha1(mb_strtolower($loaderBrandName).'|'.$loaderThemeSlug);
$loaderConfig = [
'enabled' => $loaderEnabled, 'showLogo' => $loaderShowLogo, 'frequency' => $loaderFrequency,
'theme' => $loaderDesignSlug, 'context' => $loaderContext, 'mode' => $loaderMode,
'brand' => $loaderBrandName, 'initials' => $loaderInitials, 'message' => $loaderMessage,
'logoLight' => $loaderLogoLight, 'logoDark' => $loaderLogoDark,
'logoSurfaceLight' => $loaderLogoSurfaceLight, 'logoSurfaceDark' => $loaderLogoSurfaceDark,
'primary' => $loaderPrimary, 'secondary' => $loaderSecondary, 'accent' => $loaderAccent,
'primaryRgb' => $loaderHexToRgb($loaderPrimary), 'secondaryRgb' => $loaderHexToRgb($loaderSecondary),
'accentRgb' => $loaderHexToRgb($loaderAccent), 'onPrimary' => $loaderContrastText($loaderPrimary),
'minimumMs' => $loaderMinimumMs, 'maximumWaitMs' => $loaderMaximumMs, 'storageKey' => $loaderStorageKey,
];
$loaderCssVersion = filemtime(public_path('themes/runtime/site-loader.css'));
$loaderJsVersion = filemtime(public_path('themes/runtime/site-loader.js'));
@endphp
@endonce