$style Gestaltung des Abschnitts (roh oder gespeichert) * @return array{kind: string, label: string, bg: ?string, fg: ?string, image: ?string, dark: bool} */ public static function of(array $style): array { $style = SectionStyle::fromStored($style); $background = $style['background']; if ($background === 'palette') { $slot = DesignPalette::find($style['palette_slot']); if ($slot !== null) { return ['kind' => 'palette', 'label' => $slot['name'], 'bg' => $slot['bg'], 'fg' => $slot['fg'], 'image' => null, 'dark' => ColorContrast::isDarkSurface($slot['fg'], $slot['bg'])]; } } if ($background === 'image') { // Vorschaubreite aus dem Medienmanager (auch ohne Website-Freigabe, wie die Seitenvorschau). $url = $style['image'] === null ? null : app(WebsiteImage::class)->url($style['image'], true, 640); return ['kind' => 'image', 'label' => SectionStyle::BACKGROUNDS['image'], 'bg' => null, 'fg' => null, 'image' => $url, 'dark' => $style['overlay'] === 'dark']; } foreach (DesignPalette::builtIns() as $built) { if ($built['key'] === $background) { return ['kind' => $background === 'default' ? 'default' : 'brand', 'label' => $built['label'], 'bg' => $built['bg'], 'fg' => $built['fg'], 'image' => null, 'dark' => ColorContrast::isDarkSurface($built['fg'], $built['bg'])]; } } return ['kind' => 'default', 'label' => SectionStyle::BACKGROUNDS['default'], 'bg' => '#ffffff', 'fg' => '#15243a', 'image' => null, 'dark' => false]; } /** * Eigenschaften für den Platzbereich des Abschnitts. Leer bei „Standard“, damit sich dort nichts ändert. * * @param array $style */ public static function css(array $style): string { $surface = self::of($style); if ($surface['kind'] === 'default') { return ''; } if ($surface['kind'] === 'image') { return $surface['image'] === null ? '--luf-fl-bg: #d9dee5' : "--luf-fl-bg: #d9dee5; --luf-fl-img: url('".self::plain($surface['image'])."')"; } return '--luf-fl-bg: '.$surface['bg']; } /** * Farbfeld im Abschnittskopf. Nur bei eigener Fläche; der Name der Fläche steht in der Kurzangabe daneben, das Feld * ist daher nur Schmuck für Screenreader (aria-hidden) und im Titel benannt. * * @param array $style */ public static function swatch(array $style): string { $surface = self::of($style); if ($surface['kind'] === 'default') { return ''; } $css = $surface['kind'] === 'image' ? 'background: #d9dee5'.($surface['image'] === null ? '' : " url('".self::plain($surface['image'])."') center / cover") : 'background: '.$surface['bg'].'; color: '.$surface['fg']; return ''; } /** Adresse ohne Zeichen, die einen CSS-Wert verlassen könnten. */ private static function plain(string $url): string { return preg_replace('/[\s"\'()\\\\]/', '', $url) ?? ''; } }