Zeige den Abschnittshintergrund im Seitenaufbau des Editors
Farbfeld im Abschnittskopf und die eingestellte Fläche (Markenfläche, Palettenfarbe, Hintergrundbild) als Rahmen hinter den Plätzen. Reine Anzeige im Editor; Speicherformat und Ausgabe bleiben unverändert. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
63ad125859
commit
aca713c6ba
8 files changed
+233
-4
No files matched your search
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Cms\Sections\SectionStyle;
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use App\Domain\Design\ColorContrast;
|
||||
use App\Domain\Design\DesignPalette;
|
||||
|
||||
/**
|
||||
* Fläche eines Abschnitts für den Seitenaufbau im Editor: die eingestellte Hintergrundfarbe (feste Markenfläche, Farbe
|
||||
* aus der Palette oder Hintergrundbild), damit sie schon in der Seitenübersicht sichtbar ist und nicht erst in der
|
||||
* Vorschau. Reine Anzeige; die Ausgabe auf der Website steht im SectionRenderer.
|
||||
*/
|
||||
final class SectionSurface
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $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<string, mixed> $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<string, mixed> $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 '<span class="luf-abschnitt-flaeche" aria-hidden="true" title="Hintergrund: '.e($surface['label']).'" style="'.e($css).'">Aa</span>';
|
||||
}
|
||||
|
||||
/** Adresse ohne Zeichen, die einen CSS-Wert verlassen könnten. */
|
||||
private static function plain(string $url): string
|
||||
{
|
||||
return preg_replace('/[\s"\'()\\\\]/', '', $url) ?? '';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user