@php use App\Support\Services\OrganizationBrandingResolver; $branding = app(OrganizationBrandingResolver::class)->resolve(); $primary = $branding->palette['primary'] ?? '#1e66c8'; $secondary = $branding->palette['secondary'] ?? '#94a3b8'; $accent = $branding->palette['accent'] ?? '#22c55e'; $font = $branding->theme['font'] ?? null; $hexToRgb = static function (string $hex): array { $hex = ltrim($hex, '#'); if (strlen($hex) === 3) { $hex = sprintf('%s%s%s', $hex[0].$hex[0], $hex[1].$hex[1], $hex[2].$hex[2]); } return [ hexdec(substr($hex, 0, 2)), hexdec(substr($hex, 2, 2)), hexdec(substr($hex, 4, 2)), ]; }; $mix = static function (array $base, array $target, float $ratio): array { return [ (int) round($base[0] * (1 - $ratio) + $target[0] * $ratio), (int) round($base[1] * (1 - $ratio) + $target[1] * $ratio), (int) round($base[2] * (1 - $ratio) + $target[2] * $ratio), ]; }; $base = $hexToRgb($primary); $secondaryBase = $hexToRgb($secondary); $accentBase = $hexToRgb($accent); $white = [255, 255, 255]; $black = [0, 0, 0]; $shadeMap = [ 50 => 0.9, 100 => 0.75, 200 => 0.6, 300 => 0.45, 400 => 0.25, 500 => 0.0, 600 => -0.1, 700 => -0.25, 800 => -0.4, 900 => -0.55, 950 => -0.7, ]; $shades = []; $secondaryShades = []; $accentShades = []; foreach ($shadeMap as $shade => $ratio) { if ($ratio >= 0) { $shades[$shade] = $mix($base, $white, $ratio); $secondaryShades[$shade] = $mix($secondaryBase, $white, $ratio); $accentShades[$shade] = $mix($accentBase, $white, $ratio); } else { $shades[$shade] = $mix($base, $black, abs($ratio)); $secondaryShades[$shade] = $mix($secondaryBase, $black, abs($ratio)); $accentShades[$shade] = $mix($accentBase, $black, abs($ratio)); } } @endphp