= self::AA) { return $shade; } } return 950; } /** * Farbe für Links und Akzenttext auf dunklem Grund. */ public static function textShadeOnDark(string $hex): int { $palette = ColorPalette::fromHex($hex); foreach ([300, 200, 100, 50] as $shade) { if (ColorPalette::contrast($palette[$shade], self::DARK_BACKGROUND) >= self::AA) { return $shade; } } return 50; } /** * Hinweise für die Seite „Erscheinungsbild“. * * @return list */ public static function report(string $primary, ?string $secondary = null): array { $notes = []; $foreground = ColorPalette::foregroundFor($primary); $onButton = ColorPalette::contrast($primary, $foreground); $onWhite = ColorPalette::contrast($primary, self::LIGHT_BACKGROUND); $palette = ColorPalette::fromHex($primary); $notes[] = $onButton >= self::AA ? ['level' => 'ok', 'text' => sprintf('Schrift auf Schaltflächen (%s): Kontrast %s:1 – gut lesbar.', $foreground === '#FFFFFF' ? 'weiß' : 'schwarz', self::format($onButton))] : ['level' => 'warning', 'text' => sprintf('Schrift auf Schaltflächen erreicht nur %s:1 (empfohlen mindestens 4,5:1). Eine etwas dunklere oder hellere Markenfarbe wäre besser lesbar, z. B. %s.', self::format($onButton), $palette[700])]; if ($onWhite >= self::AA) { $notes[] = ['level' => 'ok', 'text' => sprintf('Links auf hellem Grund: Kontrast %s:1 – die Markenfarbe wird unverändert verwendet.', self::format($onWhite))]; } else { $shade = self::textShadeOnLight($primary); $notes[] = ['level' => 'info', 'text' => sprintf('Die Markenfarbe ist auf Weiß als Textfarbe zu hell (%s:1). Für Links und Akzenttexte wird automatisch die dunklere Abstufung %s verwendet. Schaltflächen und Flächen behalten die Markenfarbe.', self::format($onWhite), $palette[$shade])]; } if ($secondary !== null) { $onWhite2 = ColorPalette::contrast($secondary, self::LIGHT_BACKGROUND); if ($onWhite2 < 3) { $notes[] = ['level' => 'info', 'text' => sprintf('Die zweite Akzentfarbe ist auf Weiß sehr hell (%s:1). Für Beschriftungen wird automatisch eine dunklere Abstufung verwendet.', self::format($onWhite2))]; } } return $notes; } private static function format(float $ratio): string { return number_format($ratio, 1, ',', ''); } }