diff --git a/app/Domain/Cms/Widgets/Types/HeroWidget.php b/app/Domain/Cms/Widgets/Types/HeroWidget.php index 5f0427d..87cecb7 100644 --- a/app/Domain/Cms/Widgets/Types/HeroWidget.php +++ b/app/Domain/Cms/Widgets/Types/HeroWidget.php @@ -70,9 +70,9 @@ public function narrowBehavior(): string public function heights(): array { return [ - 'compact' => 'Kompakt (mind. 400 px)', - 'normal' => 'Normal (mind. 512 px)', - 'large' => 'Groß (mind. 640 px)', + 'compact' => 'Kompakt (niedriger, 75 % der Standardhöhe)', + 'normal' => 'Standard', + 'large' => 'Großzügig (höher, 130 % der Standardhöhe)', ]; } diff --git a/app/Domain/Cms/Widgets/Types/ImageTextWidget.php b/app/Domain/Cms/Widgets/Types/ImageTextWidget.php index f26ef3f..259894c 100644 --- a/app/Domain/Cms/Widgets/Types/ImageTextWidget.php +++ b/app/Domain/Cms/Widgets/Types/ImageTextWidget.php @@ -73,7 +73,7 @@ public function heights(): array { return [ 'compact' => 'Kompakt (flacheres Bild, engere Abstände)', - 'normal' => 'Normal', + 'normal' => 'Standard', 'spacious' => 'Großzügig (höheres Bild, mehr Abstand)', ]; } diff --git a/app/Domain/Cms/Widgets/WidgetType.php b/app/Domain/Cms/Widgets/WidgetType.php index 20bded9..1ada0d3 100644 --- a/app/Domain/Cms/Widgets/WidgetType.php +++ b/app/Domain/Cms/Widgets/WidgetType.php @@ -41,7 +41,7 @@ public function version(): int public const HEIGHTS = [ 'auto' => 'Automatisch', 'compact' => 'Kompakt', - 'normal' => 'Normal', + 'normal' => 'Standard', 'large' => 'Groß', 'spacious' => 'Großzügig', 'fill' => 'Abschnittshöhe füllen', diff --git a/app/Domain/Design/DesignScale.php b/app/Domain/Design/DesignScale.php new file mode 100644 index 0000000..c7d1464 --- /dev/null +++ b/app/Domain/Design/DesignScale.php @@ -0,0 +1,164 @@ + + */ + public const PARAMETERS = [ + 'body' => ['label' => 'Fließtext', 'default' => 17, 'min' => 16, 'max' => 20, 'unit' => 'px', 'group' => 'Schrift', + 'hint' => 'Schriftgröße auf Desktop; auf kleinen Bildschirmen etwa 1 px weniger, nie unter 16 px.', + 'effect' => 'Auch Einleitung, Überschrift 3, kleine Schrift und Schaltflächen folgen daraus.'], + 'h1' => ['label' => 'Überschrift 1', 'default' => 40, 'min' => 30, 'max' => 56, 'unit' => 'px', 'group' => 'Schrift', + 'hint' => 'Seitentitel auf Desktop; schrumpft auf Smartphones auf etwa 70 %.', + 'effect' => 'Muss mindestens 4 px größer sein als Überschrift 2.'], + 'h2' => ['label' => 'Überschrift 2', 'default' => 28, 'min' => 22, 'max' => 40, 'unit' => 'px', 'group' => 'Schrift', + 'hint' => 'Abschnittstitel auf Desktop; auch Titel in Bild und Text, Handlungsaufruf und breiten Karten.', + 'effect' => 'Muss mindestens 6 px größer sein als der Fließtext. Überschrift 3 bleibt darunter.'], + 'display' => ['label' => 'Display-Überschrift (Höchstwert)', 'default' => 52, 'min' => 36, 'max' => 80, 'unit' => 'px', 'group' => 'Schrift', + 'hint' => 'Größter Titel (Einstieg). Wächst mit der Breite des Platzes bis zu diesem Wert.', + 'effect' => 'Mindestens so groß wie Überschrift 1.'], + 'space' => ['label' => 'Basisabstand', 'default' => 8, 'min' => 6, 'max' => 12, 'unit' => 'px', 'group' => 'Abstände', + 'hint' => 'Grundmaß des Abstandsrasters (halber, einfacher, anderthalbfacher bis zwölffacher Wert).', + 'effect' => 'Alle Abstandsstufen der Komponenten und die Abstände zwischen Plätzen im Raster.'], + 'section' => ['label' => 'Abschnittsabstand (Desktop)', 'default' => 48, 'min' => 24, 'max' => 96, 'unit' => 'px', 'group' => 'Abstände', + 'hint' => 'Stufe „Normal“ auf Desktop. „Kompakt“ ist zwei Drittel davon, „Großzügig“ das Anderthalbfache.', + 'effect' => 'Auf Smartphones werden alle Stufen kleiner.'], + 'card_pad' => ['label' => 'Karten-Innenabstand', 'default' => 20, 'min' => 12, 'max' => 32, 'unit' => 'px', 'group' => 'Abstände', + 'hint' => 'Innenabstand von Karten auf Desktop.', + 'effect' => 'Große Flächen (Einstieg, Bild und Text, Handlungsaufruf) verwenden das Ein- bis Zweifache.'], + 'header' => ['label' => 'Höhe der Kopfzeile', 'default' => 80, 'min' => 56, 'max' => 112, 'unit' => 'px', 'group' => 'Rahmen', + 'hint' => 'Kopfzeile im Ausgangszustand auf Desktop. Beim Scrollen und auf Smartphones gilt 80 % davon.', + 'effect' => 'Die Anzeigegröße der Wortmarke folgt daraus; die Wortmarke selbst bleibt unverändert.'], + 'width' => ['label' => 'Maximale Inhaltsbreite', 'default' => 1312, 'min' => 960, 'max' => 1600, 'unit' => 'px', 'group' => 'Rahmen', + 'hint' => 'Breite des Standardrasters; Kopfzeile, Inhalt und Fußbereich fluchten hier. „Breit“ ist etwa 17 % mehr.', + 'effect' => 'Der Lesebereich (44 rem) ist davon unabhängig.'], + 'media' => ['label' => 'Bildhöhe in Bild und Text (Desktop)', 'default' => 320, 'min' => 200, 'max' => 480, 'unit' => 'px', 'group' => 'Medien', + 'hint' => 'Höhe des Bildes neben dem Text in der Variante „Standard“. Kompakt: 75 %, Großzügig: 130 %.', + 'effect' => 'Bestimmt zugleich die Mindesthöhe des Einstiegs (das 1,2-Fache; kompakt und großzügig wie bei Bild und Text).'], + ]; + + /** Gruppen in fester Reihenfolge. */ + public const GROUPS = ['Schrift', 'Abstände', 'Rahmen', 'Medien']; + + /** + * @return array + */ + public static function defaults(): array + { + return array_map(static fn (array $p): int => $p['default'], self::PARAMETERS); + } + + /** Name der CSS-Variable, zum Beispiel card_pad → --ds-card-pad. */ + public static function variable(string $key): string + { + return '--ds-'.str_replace('_', '-', $key); + } + + /** + * Prüft vollständige Eingaben (Zeichenketten aus dem Formular oder Zahlen). Gibt Fehlermeldungen je Schlüssel zurück; + * leer, wenn alles zulässig ist. + * + * @param array $input + * @return array + */ + public static function errors(array $input): array + { + $rules = []; + $messages = []; + $names = []; + + foreach (self::PARAMETERS as $key => $p) { + $rules[$key] = ['required', 'integer', 'min:'.$p['min'], 'max:'.$p['max']]; + $names[$key] = $p['label']; + $messages["$key.required"] = $p['label'].': Bitte einen Wert eintragen.'; + $messages["$key.integer"] = $p['label'].': Bitte eine ganze Zahl in Pixeln eintragen.'; + $messages["$key.min"] = $p['label'].': Der Wert muss mindestens '.$p['min'].' px betragen.'; + $messages["$key.max"] = $p['label'].': Der Wert darf höchstens '.$p['max'].' px betragen.'; + } + + $validator = Validator::make(array_intersect_key($input, self::PARAMETERS), $rules, $messages, $names); + $errors = []; + + foreach ($validator->errors()->messages() as $key => $list) { + $errors[$key] = $list[0]; + } + + if ($errors !== []) { + return $errors; + } + + $v = array_map('intval', array_intersect_key($input, self::PARAMETERS)); + + if ($v['h2'] < $v['body'] + 6) { + $errors['h2'] = 'Überschrift 2 muss mindestens 6 px größer sein als der Fließtext ('.($v['body'] + 6).' px).'; + } + + if ($v['h1'] < $v['h2'] + 4) { + $errors['h1'] = 'Überschrift 1 muss mindestens 4 px größer sein als Überschrift 2 ('.($v['h2'] + 4).' px).'; + } + + if ($v['display'] < $v['h1']) { + $errors['display'] = 'Die Display-Überschrift darf nicht kleiner sein als Überschrift 1 ('.$v['h1'].' px).'; + } + + return $errors; + } + + /** + * Gespeicherte Werte lesen: nur bekannte Schlüssel, ganze Zahlen im zulässigen Bereich und stimmige Reihenfolge. + * Alles andere (fehlende Schlüssel, Fremdes, beschädigte Daten) ergibt die Standardwerte, nie einen Fehler. + * + * @return array + */ + public static function read(mixed $stored): array + { + if (! is_array($stored)) { + return self::defaults(); + } + + $merged = self::defaults(); + + foreach (array_keys(self::PARAMETERS) as $key) { + if (array_key_exists($key, $stored) && (is_int($stored[$key]) || (is_string($stored[$key]) && ctype_digit($stored[$key])))) { + $merged[$key] = (int) $stored[$key]; + } + } + + return self::errors($merged) === [] ? $merged : self::defaults(); + } + + /** + * Inline-Stylesheet mit den abweichenden Basiswerten. Ausgegeben werden ausschließlich geprüfte ganze Zahlen zu + * bekannten Schlüsseln. Ohne Abweichung leer: dann gelten die Standardwerte aus tokens.css. + * + * @param array $values + */ + public static function css(array $values): string + { + $declarations = ''; + + foreach (self::PARAMETERS as $key => $p) { + $value = $values[$key] ?? $p['default']; + + if ($value !== $p['default'] && $value >= $p['min'] && $value <= $p['max']) { + $declarations .= sprintf('%s:%d;', self::variable($key), $value); + } + } + + return $declarations === '' ? '' : ':root{'.$declarations.'}'; + } +} diff --git a/app/Domain/Design/DesignSettings.php b/app/Domain/Design/DesignSettings.php new file mode 100644 index 0000000..72b55b9 --- /dev/null +++ b/app/Domain/Design/DesignSettings.php @@ -0,0 +1,121 @@ +|null */ + private static ?array $memo = null; + + /** + * Wirksame Werte (gespeichert oder Standard). + * + * @return array + */ + public static function values(): array + { + if (self::$memo !== null) { + return self::$memo; + } + + try { + $stored = Cache::rememberForever(self::CACHE_KEY, static function (): array { + $row = SiteSetting::query()->find(self::KEY); + + return $row === null ? [] : (array) $row->value; + }); + + return self::$memo = $stored === [] ? DesignScale::defaults() : DesignScale::read($stored); + } catch (Throwable) { + return self::$memo = DesignScale::defaults(); + } + } + + /** Ob abweichende Werte wirksam sind. */ + public static function isCustomised(): bool + { + return self::values() !== DesignScale::defaults(); + } + + /** + * Speichert vollständige, geprüfte Werte. + * + * @param array $input + * @return array Fehlermeldungen je Schlüssel; leer bei Erfolg + */ + public static function save(array $input, ?User $by = null): array + { + $errors = DesignScale::errors($input); + + if ($errors !== []) { + return $errors; + } + + $ordered = []; + + foreach (array_keys(DesignScale::PARAMETERS) as $key) { + $ordered[$key] = (int) $input[$key]; + } + + SiteSetting::query()->updateOrCreate(['key' => self::KEY], ['value' => $ordered, 'updated_by' => $by?->getKey()]); + self::flush(); + + return []; + } + + /** Standardwerte wiederherstellen: die Zeile entfällt, es gelten wieder die Werte aus tokens.css. */ + public static function reset(): void + { + SiteSetting::query()->whereKey(self::KEY)->delete(); + self::flush(); + } + + /** Zeitpunkt der letzten Speicherung, falls vorhanden. */ + public static function updatedAt(): ?Carbon + { + try { + return SiteSetting::query()->find(self::KEY)?->updated_at; + } catch (Throwable) { + return null; + } + } + + public static function flush(): void + { + self::$memo = null; + + try { + Cache::forget(self::CACHE_KEY); + } catch (Throwable) { + // Der Zwischenspeicher ist nur Beschleunigung. + } + } + + /** + * Stylesheet-Block für Layouts und Vorschauen; nach dem Stylesheet der Website einzufügen, damit er gewinnt. + * Leer, solange keine abweichenden Werte gespeichert sind. + */ + public static function styleTag(): HtmlString + { + $css = DesignScale::css(self::values()); + + return new HtmlString($css === '' ? '' : ''); + } +} diff --git a/app/Domain/Design/SiteSetting.php b/app/Domain/Design/SiteSetting.php new file mode 100644 index 0000000..f63a2bf --- /dev/null +++ b/app/Domain/Design/SiteSetting.php @@ -0,0 +1,31 @@ + $value + * @property int|null $updated_by + */ +class SiteSetting extends Model +{ + protected $table = 'site_settings'; + + protected $primaryKey = 'key'; + + public $incrementing = false; + + protected $keyType = 'string'; + + protected $guarded = []; + + protected function casts(): array + { + return ['value' => 'array']; + } +} diff --git a/app/Filament/Pages/DesignGroessen.php b/app/Filament/Pages/DesignGroessen.php new file mode 100644 index 0000000..dfcfc21 --- /dev/null +++ b/app/Filament/Pages/DesignGroessen.php @@ -0,0 +1,133 @@ + */ + public array $werte = []; + + /** Fehlermeldungen je Basiswert nach dem letzten Speichern. @var array */ + public array $fehler = []; + + /** @var array{aktion: string, argument: int|string|null, titel: string, text: string, label: string, gefahr: bool}|null */ + public ?array $bestaetigung = null; + + public static function canAccess(): bool + { + return auth()->user()?->hasStaffRole(StaffRole::Systemverwalter) === true; + } + + public function mount(): void + { + $this->ladeGespeicherte(); + } + + public function getHeading(): string|Htmlable|null + { + return 'Größen'; + } + + public function getMaxContentWidth(): Width|string|null + { + return Width::SevenExtraLarge; + } + + /** Wirksame Werte der Website (gespeichert oder Standard). @return array */ + public function gespeichert(): array + { + return DesignSettings::values(); + } + + /** Ob die Eingaben vom wirksamen Stand abweichen. */ + public function geaendert(): bool + { + $aktuell = []; + + foreach (array_keys(DesignScale::PARAMETERS) as $key) { + $wert = $this->werte[$key] ?? ''; + $aktuell[$key] = is_string($wert) && ctype_digit($wert) ? (int) $wert : $wert; + } + + return $aktuell !== $this->gespeichert(); + } + + public function speichern(): void + { + $this->fehler = DesignSettings::save($this->werte, auth()->user()); + + if ($this->fehler !== []) { + Notification::make()->danger()->title('Nicht gespeichert')->body('Bitte die markierten Werte korrigieren.')->send(); + + return; + } + + $this->ladeGespeicherte(); + Notification::make()->success()->title('Größen gespeichert')->body('Die Werte gelten jetzt auf der Website und in den CMS-Vorschauen.')->send(); + } + + public function askConfirmation(string $aktion, int|string|null $argument = null): void + { + $this->bestaetigung = match ($aktion) { + 'standard' => ['aktion' => 'standard', 'argument' => null, 'titel' => 'Standardwerte wiederherstellen?', 'text' => 'Die gespeicherten Größen werden entfernt. Website und Vorschauen verwenden sofort wieder die Standardwerte aus dem Designsystem. Offene Eingaben gehen dabei verloren.', 'label' => 'Standardwerte wiederherstellen', 'gefahr' => true], + 'verwerfen' => ['aktion' => 'verwerfen', 'argument' => null, 'titel' => 'Änderungen verwerfen?', 'text' => 'Die Eingaben kehren zum wirksamen Stand zurück. Gespeichert wird dabei nichts.', 'label' => 'Verwerfen', 'gefahr' => true], + default => null, + }; + } + + public function confirmConfirmation(): void + { + $frage = $this->bestaetigung; + $this->bestaetigung = null; + + match ($frage['aktion'] ?? null) { + 'standard' => $this->standardWiederherstellen(), + 'verwerfen' => $this->ladeGespeicherte(), + default => null, + }; + } + + public function cancelConfirmation(): void + { + $this->bestaetigung = null; + } + + private function standardWiederherstellen(): void + { + DesignSettings::reset(); + $this->ladeGespeicherte(); + Notification::make()->success()->title('Standardwerte wiederhergestellt')->body('Website und Vorschauen verwenden wieder die Standardwerte.')->send(); + } + + private function ladeGespeicherte(): void + { + $this->werte = $this->gespeichert(); + $this->fehler = []; + } +} diff --git a/app/Filament/Support/WidgetEditor.php b/app/Filament/Support/WidgetEditor.php index 7254bf4..9d64d11 100644 --- a/app/Filament/Support/WidgetEditor.php +++ b/app/Filament/Support/WidgetEditor.php @@ -7,6 +7,7 @@ use App\Domain\Cms\Widgets\WidgetRegistry; use App\Domain\Cms\Widgets\WidgetRenderer; use App\Domain\Cms\Widgets\WidgetType; +use App\Domain\Design\DesignSettings; use Filament\Actions\Action; use Filament\Forms\Components\Builder; use Filament\Forms\Components\Builder\Block; @@ -426,7 +427,7 @@ public static function renderPreview(string $type, array $state): string public static function previewStylesheets(): string { try { - return app(Vite::class)(['resources/css/app.css'])->toHtml(); + return app(Vite::class)(['resources/css/app.css'])->toHtml().DesignSettings::styleTag()->toHtml(); } catch (Throwable) { return ''; } diff --git a/database/migrations/2026_11_22_100000_create_site_settings.php b/database/migrations/2026_11_22_100000_create_site_settings.php new file mode 100644 index 0000000..840ddc0 --- /dev/null +++ b/database/migrations/2026_11_22_100000_create_site_settings.php @@ -0,0 +1,28 @@ +string('key', 100)->primary(); + $table->json('value'); + $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('site_settings'); + } +}; diff --git a/resources/css/components.css b/resources/css/components.css index e380afd..11a4cee 100644 --- a/resources/css/components.css +++ b/resources/css/components.css @@ -27,6 +27,7 @@ .ui-button { background: var(--color-action); color: var(--color-action-text); font: inherit; + font-size: var(--text-button); font-weight: 700; line-height: 1.2; max-width: 100%; @@ -140,6 +141,7 @@ .form button:not(.button-quiet):not(.button-secondary) { background: var(--color-action); color: var(--color-action-text); font: inherit; + font-size: var(--text-button); font-weight: 700; cursor: pointer; } @@ -214,7 +216,7 @@ .empty { background: var(--color-surface-raised); border: 1px solid var(--color-border); border-radius: var(--radius-card); - padding: var(--space-5); + padding: var(--pad-card); } .empty { diff --git a/resources/css/components/lf-bild-text.css b/resources/css/components/lf-bild-text.css index ce3ead0..f7cbd3f 100644 --- a/resources/css/components/lf-bild-text.css +++ b/resources/css/components/lf-bild-text.css @@ -7,6 +7,9 @@ * - Oberfläche „clear“ übernimmt die Bedeutungswerte des Abschnitts (auch auf dunklen Abschnitten lesbar). * - Überschrift erbt Farbe und Schrift (globale h1–h3-Regeln setzen sonst Navy). * - Fokusfarbe aus den Tokens; Schriften über --lf-font-display und --lf-font-ui. + * - Größen aus der gemeinsamen Skala (ADR-44, tokens.css): Titel bis --text-h2, Text --text-body, Schaltflächen + * --text-button, Innenabstand --pad-card/--pad-surface, Bildhöhe --ds-media. Die Dichtestufe (--dens) bestimmt Bildhöhe, + * Abstand und Innenabstand der Varianten kompakt, normal und großzügig. */ .lf-bt-host { container: lf-bt / inline-size; inline-size: 100%; min-inline-size: 0; max-inline-size: 100%; } .lf-bt-host, .lf-bt-host * { box-sizing: border-box; } @@ -20,12 +23,13 @@ .lf-bt { --bt-eyebrow: #295b08; --bt-focus-x: 64%; --bt-focus-y: 43%; + --bt-img-h: calc(var(--ds-media) * var(--dens) / 16 * 1rem); --color-focus: var(--lf-focus); display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; - gap: clamp(0.9rem, 2.65cqi, 2rem); - padding: clamp(1rem, 2.8cqi, 3.25rem); + gap: calc(clamp(var(--space-3), 2.4cqi, var(--space-6)) * var(--dens)); + padding: calc(clamp(var(--pad-card), 3cqi, var(--pad-surface)) * var(--dens)); border-radius: clamp(1rem, 1.8cqi, 1.65rem); min-inline-size: 0; max-inline-size: 100%; @@ -82,7 +86,7 @@ .lf-bt__headline { margin: 0; color: inherit; font-family: var(--lf-font-display); - font-size: clamp(1.55rem, 4.5cqi, 3.35rem); + font-size: clamp(1.4rem, 3.6cqi, var(--text-h2)); line-height: 1.14; letter-spacing: -0.03em; font-weight: 850; @@ -101,7 +105,7 @@ .lf-bt__accent { transform: rotate(-1deg); } -.lf-bt__body { color: var(--bt-muted); font-size: clamp(0.97rem, 1.45cqi, 1.12rem); line-height: 1.62; overflow-wrap: anywhere; } +.lf-bt__body { color: var(--bt-muted); font-size: var(--text-body); line-height: 1.6; overflow-wrap: anywhere; } .lf-bt__body > :first-child { margin-block-start: 0; } .lf-bt__body > :last-child { margin-block-end: 0; } .lf-bt__body p { margin: 0 0 0.9em; } @@ -118,15 +122,15 @@ .lf-bt__button { gap: 0.5rem; max-inline-size: 100%; min-inline-size: 0; - min-block-size: 2.95rem; - padding: 0.7rem 1rem; + min-block-size: var(--touch-target); + padding: 0.6rem 1rem; background: var(--bt-green); border: 2px solid var(--bt-green); color: #fff; border-radius: 999px; text-decoration: none; text-align: center; - font-size: 0.89rem; + font-size: var(--text-button); font-weight: 800; line-height: 1.33; overflow-wrap: anywhere; @@ -166,6 +170,8 @@ .lf-bt__image { max-inline-size: none; block-size: auto; aspect-ratio: 16 / 10; + /* Nie höher als die Zielhöhe auf Desktop (Mediengröße × Dichtestufe); der Bildausschnitt folgt dem Fokuspunkt. */ + max-block-size: var(--bt-img-h); object-fit: cover; object-position: var(--bt-focus-x) var(--bt-focus-y); border-radius: clamp(0.78rem, 1.8cqi, 1.3rem); @@ -174,28 +180,23 @@ .lf-bt__image { .lf-bt--height-compact .lf-bt__image { aspect-ratio: 16 / 9; } .lf-bt--height-spacious .lf-bt__image { aspect-ratio: 4 / 3; } -.lf-bt--height-compact { gap: clamp(0.75rem, 2cqi, 1.45rem); } -.lf-bt--height-spacious { gap: clamp(1.15rem, 3.4cqi, 2.7rem); } .lf-bt--without-image { grid-template-columns: minmax(0, 1fr); } /* Schmale Plätze: vollständiger Text und Links, keine erzwungene Höhe. */ @container lf-bt (max-width: 539.99px) { .lf-bt__actions { display: grid; grid-template-columns: minmax(0, 1fr); } .lf-bt__button { inline-size: 100%; } - .lf-bt__headline { font-size: clamp(1.42rem, 6.8cqi, 2.2rem); } + .lf-bt__headline { font-size: clamp(1.375rem, 6.8cqi, var(--text-h2)); } .lf-bt__eyebrow { letter-spacing: 0.03em; } } /* Mittlere Containerbreite (meist zwei Einheiten): flacher Bildstreifen statt gequetschter Zweispaltigkeit. */ @container lf-bt (min-width: 540px) and (max-width: 899.99px) { - .lf-bt { gap: clamp(0.8rem, 1.6cqi, 1.2rem); padding: clamp(1.1rem, 2.4cqi, 1.65rem); } .lf-bt--clear { padding-inline: 0; } .lf-bt__media { inline-size: 100%; } .lf-bt__image { aspect-ratio: 2.15 / 1; } .lf-bt--height-compact .lf-bt__image { aspect-ratio: 2.5 / 1; } .lf-bt--height-spacious .lf-bt__image { aspect-ratio: 1.8 / 1; } - .lf-bt__headline { font-size: clamp(1.65rem, 3.6cqi, 2.28rem); } - .lf-bt__body { font-size: 1.01rem; line-height: 1.59; } .lf-bt__actions { margin-block-start: 0.95rem; } .lf-bt__button { flex: 1 1 13rem; } } @@ -203,20 +204,19 @@ @container lf-bt (min-width: 540px) and (max-width: 899.99px) { /* Breiter Container: zweispaltige Komposition, Bild links oder rechts. */ @container lf-bt (min-width: 900px) { .lf-bt { - grid-template-columns: minmax(0, 1.02fr) minmax(0, 0.98fr); + grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr); align-items: center; - gap: clamp(1.8rem, 4cqi, 4.5rem); - padding: clamp(1.8rem, 4cqi, 4.5rem); + gap: calc(clamp(var(--space-5), 3cqi, var(--space-7)) * var(--dens)); } .lf-bt--clear { padding-inline: 0; } - .lf-bt__media { order: 0; align-self: stretch; } + /* + * Bildhöhe = Zielhöhe (Mediengröße × Dichtestufe); sie wächst nur, wenn der Text höher ist. Das Bild füllt die + * Fläche und gibt keine eigene Höhe vor (unabhängig vom Seitenverhältnis der Datei); der Ausschnitt folgt dem Fokuspunkt. + */ + .lf-bt__media { order: 0; align-self: stretch; min-block-size: var(--bt-img-h); } .lf-bt--image-left .lf-bt__media { order: -1; } - .lf-bt__image { block-size: 100%; min-block-size: 18rem; aspect-ratio: 4 / 3; } - .lf-bt--height-compact .lf-bt__image { min-block-size: 14rem; aspect-ratio: 3 / 2; } - .lf-bt--height-spacious .lf-bt__image { min-block-size: 24rem; aspect-ratio: 1 / 1; } - .lf-bt--height-compact { padding-block: clamp(1.25rem, 2.8cqi, 2.6rem); } - .lf-bt--height-spacious { padding-block: clamp(2.15rem, 4.5cqi, 4.75rem); } + .lf-bt__image { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; max-block-size: none; aspect-ratio: auto; } .lf-bt--without-image { grid-template-columns: minmax(0, 1fr); } } diff --git a/resources/css/components/lf-hero.css b/resources/css/components/lf-hero.css index babd297..7170665 100644 --- a/resources/css/components/lf-hero.css +++ b/resources/css/components/lf-hero.css @@ -24,7 +24,7 @@ .lf-hero { display: grid; align-items: center; min-inline-size: 0; - min-block-size: 32rem; + min-block-size: calc(var(--ds-media) * 1.2 * var(--dens) / 16 * 1rem); max-inline-size: 100%; border-radius: clamp(1rem, 1.9cqi, 1.75rem); background: var(--lf-hero-cream); @@ -32,9 +32,10 @@ .lf-hero { font-family: var(--lf-font-display); } -.lf-hero--height-compact { min-block-size: 25rem; } -.lf-hero--height-normal { min-block-size: 32rem; } -.lf-hero--height-large { min-block-size: 40rem; } +/* Mindesthöhen kommen aus der Mediengröße und der Dichtestufe (--dens, tokens.css): kompakt 0,9 ×, normal 1,2 ×, groß 1,56 × --ds-media. */ +.lf-hero--height-compact, +.lf-hero--height-normal, +.lf-hero--height-large { min-block-size: calc(var(--ds-media) * 1.2 * var(--dens) / 16 * 1rem); } .lf-hero__photo { position: absolute; @@ -128,8 +129,8 @@ .lf-hero__inner { max-inline-size: 1440px; min-inline-size: 0; margin-inline: auto; - padding: clamp(1.8rem, 4.3cqi, 5rem); - padding-block: clamp(2.1rem, 5cqi, 5rem); + padding: clamp(var(--pad-card), 3.4cqi, var(--pad-surface)); + padding-block: clamp(var(--pad-card), 3.4cqi, var(--pad-surface)); } .lf-hero__copy { position: relative; max-inline-size: min(660px, 58%); min-inline-size: 0; } @@ -151,7 +152,7 @@ .lf-hero__title { margin: 0.25em 0; color: inherit; font-family: inherit; - font-size: clamp(2.1rem, 5.4cqi, 4.9rem); + font-size: clamp(1.75rem, 4cqi, var(--text-display)); line-height: 1.06; letter-spacing: -0.035em; font-weight: 900; @@ -184,7 +185,7 @@ .lf-hero__description { max-inline-size: 56ch; margin: 0 0 clamp(1.25rem, 2.1cqi, 2rem); font-family: var(--lf-font-ui); - font-size: clamp(1.05rem, 1.7cqi, 1.3rem); + font-size: clamp(1rem, 1.5cqi, var(--text-lede)); line-height: 1.5; overflow-wrap: anywhere; } @@ -197,11 +198,11 @@ .lf-hero__button { justify-content: center; min-inline-size: 0; max-inline-size: 100%; - min-block-size: 3rem; - padding: 0.77rem 1.2rem; + min-block-size: var(--touch-target); + padding: 0.6rem 1.1rem; border: 2px solid transparent; border-radius: 999px; - font: 800 0.96rem/1.28 var(--lf-font-ui); + font: 800 var(--text-button)/1.28 var(--lf-font-ui); text-decoration: none; text-align: center; white-space: normal; @@ -237,10 +238,10 @@ @container lf-hero (max-width: 859.99px) { .lf-hero__photo { position: relative; display: block; block-size: auto; aspect-ratio: 16 / 9; } .lf-hero__video { inset: 0 0 auto 0; block-size: auto; aspect-ratio: 16 / 9; border-radius: inherit; } .lf-hero--photo-split::before { display: none; } - .lf-hero__inner { padding: clamp(1.2rem, 3.5cqi, 2rem); padding-block-end: 2.4rem; } + .lf-hero__inner { padding: clamp(var(--pad-card), 3.5cqi, calc(var(--pad-card) * 1.6)); padding-block-end: calc(var(--pad-card) * 1.6); } .lf-hero__copy { max-inline-size: 100%; } - .lf-hero__title { font-size: clamp(2rem, 5.5cqi, 3.1rem); } - .lf-hero__description { font-size: 1.07rem; } + .lf-hero__title { font-size: clamp(1.75rem, 5.5cqi, var(--text-display)); } + .lf-hero__description { font-size: var(--text-lede); } .lf-hero--editorial-solid .lf-hero__copy { max-inline-size: 100%; } .lf-hero__rays { inset-block-start: -1.6rem; inset-inline-start: auto; inset-inline-end: 0; transform: rotate(10deg); } } diff --git a/resources/css/components/lf-premium-card.css b/resources/css/components/lf-premium-card.css index 8455756..853a853 100644 --- a/resources/css/components/lf-premium-card.css +++ b/resources/css/components/lf-premium-card.css @@ -10,6 +10,8 @@ * - Schriften und Farben ausschließlich über vorhandene Tokens (tokens.css); keine neuen Schriften. * - Die Karte hat ihre eigene helle Fläche und setzt dafür die hellen Bedeutungswerte, auch in dunklen Abschnitten. * - Kein line-clamp, keine feste Höhe: lange Titel und Texte brechen um. + * - Größen aus der gemeinsamen Skala (ADR-44, tokens.css): Titel bis --text-h3 (breit --text-h2), Text --text-body, + * Schaltfläche --text-button, Innenabstand --pad-card, Tafelhöhe aus dem Basisabstand. */ .lf-pc, .lf-pc * { @@ -40,7 +42,7 @@ .lf-pc { border: 1px solid var(--color-border); border-radius: var(--radius-panel); box-shadow: var(--shadow-raised); - font: 400 1rem/1.55 var(--font-reading); + font: 400 var(--text-body)/1.55 var(--font-reading); overflow-wrap: anywhere; } @@ -104,7 +106,7 @@ .lf-pc__body { flex-direction: column; align-items: start; min-inline-size: 0; - padding: clamp(20px, 4.5cqi, 32px); + padding: clamp(var(--pad-card), 3.4cqi, calc(var(--pad-card) * 1.4)); gap: 12px; } @@ -120,7 +122,7 @@ .lf-pc__kind { .lf-pc .lf-pc__title { margin: 0; color: var(--color-heading); - font: 800 clamp(1.35rem, 4.6cqi, 1.75rem) / 1.18 var(--font-display); + font: 800 clamp(1.2rem, 4cqi, var(--text-h3)) / 1.18 var(--font-display); letter-spacing: -0.025em; text-wrap: balance; } @@ -175,7 +177,7 @@ .lf-pc__cta { background: var(--pc-action); color: var(--pc-action-text); font-weight: 600; - font-size: 0.9375rem; + font-size: var(--text-button); line-height: 1.4; text-decoration: none; text-align: center; @@ -216,16 +218,16 @@ .lf-pc__panel { flex-direction: column; justify-content: space-between; gap: 20px; - min-block-size: 140px; + min-block-size: calc(var(--ds-space) * 14 / 16 * 1rem); margin: 10px 10px 0; - padding: 24px; + padding: calc(var(--pad-card) * 1.2); border-radius: var(--radius-card); background: var(--lf-navy); color: var(--lf-white); } .lf-pc__panel-label { - font: 800 1.6rem / 1.15 var(--font-display); + font: 800 calc(var(--text-h3) * 1.1) / 1.15 var(--font-display); } .lf-pc__panel-accent { @@ -329,7 +331,7 @@ @container slot (min-width: 520px) { /* Neben dem Text wie ein Bild mittig, auch wenn die Karte auf Zeilenhöhe gestreckt ist. */ .lf-pc:not(.lf-pc--stacked) .lf-pc__panel { margin: 10px 0 10px 10px; - min-block-size: 220px; + min-block-size: calc(var(--ds-space) * 20 / 16 * 1rem); align-self: center; } @@ -339,8 +341,8 @@ @container slot (min-width: 520px) { border-radius: var(--radius-card); } - .lf-pc__body { padding: clamp(22px, 4cqi, 36px); } - .lf-pc .lf-pc__title { font-size: clamp(1.45rem, 3.4cqi, 2rem); } + .lf-pc__body { padding: clamp(var(--pad-card), 3cqi, calc(var(--pad-card) * 1.4)); } + .lf-pc .lf-pc__title { font-size: clamp(1.2rem, 3cqi, var(--text-h2)); } } @media (prefers-reduced-motion: reduce) { diff --git a/resources/css/site.css b/resources/css/site.css index 0dec335..249300a 100644 --- a/resources/css/site.css +++ b/resources/css/site.css @@ -37,7 +37,8 @@ .brand-claim { */ .brand-logo { flex: none; - --brand-logo-height: 3rem; + /* Anzeigegröße folgt der Kopfzeilenhöhe (--ds-header); die Wortmarke selbst bleibt unverändert. */ + --brand-logo-height: calc(var(--ds-header) * 0.6 / 16 * 1rem); } .brand-logo-image { @@ -48,7 +49,7 @@ .brand-logo-image { @media (min-width: 75rem) { .site-header .brand-logo { - --brand-logo-height: 3.75rem; + --brand-logo-height: calc(var(--ds-header) * 0.55 / 16 * 1rem); } } @@ -99,7 +100,7 @@ .site-header-inner { @media (min-width: 75rem) { .site-header .brand-logo { transform-origin: left center; - transform: scale(1.32); + transform: scale(1.25); transition: transform 0.22s ease; } @@ -405,7 +406,7 @@ .site-main { .sheet { width: min(var(--container-standard), 100% - 2 * var(--gutter)); margin-inline: auto; - padding: clamp(1.5rem, 4vw, 3.5rem) 0 clamp(3rem, 6vw, 5rem); + padding: var(--section-space-compact) 0 var(--section-space-normal); } .sheet > .block + .block { @@ -477,7 +478,7 @@ .site-footer { isolation: isolate; background: var(--color-surface); color: var(--color-text); - padding: clamp(3rem, 2rem + 4vw, 5rem) 0 0; + padding: var(--section-space-normal) 0 0; margin-top: 0; } @@ -489,7 +490,7 @@ main:has(> .page-section.scope-dark:last-child) + .site-footer { .site-footer-inner { display: grid; gap: var(--space-6) var(--space-7); - padding-bottom: clamp(2.5rem, 2rem + 2vw, 3.5rem); + padding-bottom: var(--section-space-compact); } @media (min-width: 48rem) { @@ -503,7 +504,7 @@ .site-footer .brand { } .site-footer .brand-logo { - --brand-logo-height: 4.5rem; + --brand-logo-height: calc(var(--ds-header) * 0.65 / 16 * 1rem); } .site-footer h2 { @@ -540,7 +541,7 @@ .site-footer-base { position: relative; z-index: 1; border-top: 1px solid var(--color-border); - padding: var(--space-3) 0 clamp(3rem, 2rem + 4vw, 4.5rem); + padding: var(--space-3) 0 var(--section-space-normal); } .site-footer-base ul { @@ -567,7 +568,7 @@ .site-footer-arc { } .site-footer:not(:has(.site-footer-base)) .site-footer-inner { - padding-bottom: clamp(4rem, 3rem + 4vw, 6rem); + padding-bottom: var(--section-space-large); } /* Markenakzente (Brand-Kit 03_svg_entwuerfe, Entwürfe). Nur dekorativ, Farbe über Tokens. */ diff --git a/resources/css/tokens.css b/resources/css/tokens.css index 72d02e5..4b6de50 100644 --- a/resources/css/tokens.css +++ b/resources/css/tokens.css @@ -76,28 +76,68 @@ :root { --lf-font-ui: var(--font-reading); --lf-muted: #46556b; - /* Typografie (Website-Zielkonzept 7.2: Fließtext 17 → 18 px, H1 34 → 52 px) */ + /* + * Größenskala (ADR-44). Zehn Basiswerte in Pixel als Zahl; alles Weitere leitet dieses Stylesheet daraus ab. + * Die Verwaltung („Website → Design → Größen“) überschreibt abweichende Werte mit einem Inline-Stylesheet + * (App\Domain\Design\DesignSettings::styleTag) nach diesem Stylesheet. Die Standardwerte hier und in + * App\Domain\Design\DesignScale müssen gleich sein (Test DesignScaleTest). Ableitungsregeln stehen nur hier. + * Umgerechnet wird in rem, damit die Textgröße des Browsers wirkt. Trefferflächen (--touch-target) und die + * Untergrenze 16 px für Fließtext sind nicht einstellbar. + */ + --ds-body: 17; + --ds-h1: 40; + --ds-h2: 28; + --ds-display: 52; + --ds-space: 8; + --ds-section: 48; + --ds-card-pad: 20; + --ds-header: 80; + --ds-width: 1312; + --ds-media: 320; + + /* + * Fließende Interpolation: --fl ist 0 bei 22,5 rem (360 px) Fensterbreite und 1 rem bei 75 rem (1200 px). Ein Wert + * zwischen Minimum und Maximum (Zahlen in px) lautet clamp(min, min + (max − min) / 16 × --fl, max). + */ + --fl: calc((100vw - 22.5rem) / 52.5); + + /* Typografie. Minimum auf kleinen Bildschirmen, Maximum ab 75 rem. Überschriften bleiben stets größer als der Text. */ --font-reading: var(--font-sans); - --text-small: 0.9375rem; - --text-body: clamp(1.0625rem, 1.03rem + 0.15vw, 1.125rem); - --text-lede: clamp(1.125rem, 1.05rem + 0.4vw, 1.3125rem); - --text-h3: clamp(1.25rem, 1.16rem + 0.4vw, 1.375rem); - --text-h2: clamp(1.625rem, 1.35rem + 1.2vw, 2.125rem); - --text-h1: clamp(2.125rem, 1.6rem + 2.4vw, 3.25rem); - --leading-body: 1.6; + --n-body-min: max(16, calc(var(--ds-body) - 1)); + --n-h3-max: min(calc(var(--ds-body) * 1.18), calc(var(--ds-h2) * 0.8)); + --n-h3-min: min(calc(var(--ds-body) * 1.06), var(--n-h3-max)); + --n-h2-min: max(calc(var(--n-body-min) * 1.15), calc(var(--ds-h2) * 0.79)); + --n-h1-min: max(calc(var(--n-h2-min) * 1.15), calc(var(--ds-h1) * 0.7)); + --n-display-min: max(calc(var(--n-h1-min) * 1.1), calc(var(--ds-display) * 0.62)); + --text-body: clamp(calc(var(--n-body-min) / 16 * 1rem), calc(var(--n-body-min) / 16 * 1rem + (var(--ds-body) - var(--n-body-min)) / 16 * var(--fl)), calc(var(--ds-body) / 16 * 1rem)); + --text-small: max(0.875rem, calc(var(--ds-body) * 0.85 / 16 * 1rem)); + --text-button: max(0.9375rem, calc(var(--ds-body) * 0.88 / 16 * 1rem)); + --text-lede: clamp(calc(var(--n-body-min) * 1.06 / 16 * 1rem), calc(var(--n-body-min) * 1.06 / 16 * 1rem + (var(--ds-body) * 1.12 - var(--n-body-min) * 1.06) / 16 * var(--fl)), calc(var(--ds-body) * 1.12 / 16 * 1rem)); + --text-h3: clamp(calc(var(--n-h3-min) / 16 * 1rem), calc(var(--n-h3-min) / 16 * 1rem + (var(--n-h3-max) - var(--n-h3-min)) / 16 * var(--fl)), calc(var(--n-h3-max) / 16 * 1rem)); + --text-h2: clamp(calc(var(--n-h2-min) / 16 * 1rem), calc(var(--n-h2-min) / 16 * 1rem + (var(--ds-h2) - var(--n-h2-min)) / 16 * var(--fl)), calc(var(--ds-h2) / 16 * 1rem)); + --text-h1: clamp(calc(var(--n-h1-min) / 16 * 1rem), calc(var(--n-h1-min) / 16 * 1rem + (var(--ds-h1) - var(--n-h1-min)) / 16 * var(--fl)), calc(var(--ds-h1) / 16 * 1rem)); + --text-display: clamp(calc(var(--n-display-min) / 16 * 1rem), calc(var(--n-display-min) / 16 * 1rem + (var(--ds-display) - var(--n-display-min)) / 16 * var(--fl)), calc(var(--ds-display) / 16 * 1rem)); + --leading-body: 1.55; --leading-heading: 1.15; --measure: 70ch; - /* Abstände (Grundmaß 4 px) */ - --space-1: 0.25rem; - --space-2: 0.5rem; - --space-3: 0.75rem; - --space-4: 1rem; - --space-5: 1.5rem; - --space-6: 2rem; - --space-7: 3rem; - --space-8: 4rem; - --space-9: 6rem; + /* Abstände: Vielfache des Basisabstands (bei 8 px: 4, 8, 12, 16, 24, 32, 48, 64, 96 px) */ + --space-1: calc(var(--ds-space) * 0.5 / 16 * 1rem); + --space-2: calc(var(--ds-space) / 16 * 1rem); + --space-3: calc(var(--ds-space) * 1.5 / 16 * 1rem); + --space-4: calc(var(--ds-space) * 2 / 16 * 1rem); + --space-5: calc(var(--ds-space) * 3 / 16 * 1rem); + --space-6: calc(var(--ds-space) * 4 / 16 * 1rem); + --space-7: calc(var(--ds-space) * 6 / 16 * 1rem); + --space-8: calc(var(--ds-space) * 8 / 16 * 1rem); + --space-9: calc(var(--ds-space) * 12 / 16 * 1rem); + + /* + * Innenabstände von Flächen. --pad-card: Karten (kleine Bildschirme 80 %). --pad-surface: Obergrenze für große + * Flächen (Einstieg, Bild und Text, Handlungsaufruf); diese wachsen mit dem Platz (cqi) zwischen beiden Werten. + */ + --pad-card: clamp(calc(var(--ds-card-pad) * 0.8 / 16 * 1rem), calc(var(--ds-card-pad) * 0.8 / 16 * 1rem + var(--ds-card-pad) * 0.2 / 16 * var(--fl)), calc(var(--ds-card-pad) / 16 * 1rem)); + --pad-surface: calc(var(--ds-card-pad) * 2.4 / 16 * 1rem); /* Rundungen und Schatten */ --radius-small: 8px; @@ -116,20 +156,31 @@ :root { * - Vollbreite: Inhalt bis an den Seitenrand (mit Randabstand) */ --gutter: clamp(1rem, 4vw, 2.5rem); - --grid-gap: clamp(1.25rem, 2.5vw, 2.25rem); - /* Stufen der Abschnittsabstände (oben, unten) und des Widget-Abstands im Abschnittsraster (SectionStyle::SPACINGS). */ + /* + * Stufen der Abschnittsabstände (oben, unten) und des Widget-Abstands im Abschnittsraster (SectionStyle::SPACINGS), + * abgeleitet aus --ds-section (Normal auf Desktop; Kompakt zwei Drittel, Großzügig das Anderthalbfache) und + * --ds-space. Auf kleinen Bildschirmen jeweils kleiner. + */ --section-space-none: 0px; - --section-space-compact: clamp(1.5rem, 1rem + 2vw, 3rem); - --section-space-normal: clamp(3rem, 2rem + 4vw, 6rem); - --section-space-large: clamp(4.5rem, 3rem + 5vw, 8rem); + --section-space-compact: clamp(calc(var(--ds-section) * 0.5 / 16 * 1rem), calc(var(--ds-section) * 0.5 / 16 * 1rem + var(--ds-section) * 0.1667 / 16 * var(--fl)), calc(var(--ds-section) * 0.6667 / 16 * 1rem)); + --section-space-normal: clamp(calc(var(--ds-section) * 0.75 / 16 * 1rem), calc(var(--ds-section) * 0.75 / 16 * 1rem + var(--ds-section) * 0.25 / 16 * var(--fl)), calc(var(--ds-section) / 16 * 1rem)); + --section-space-large: clamp(calc(var(--ds-section) / 16 * 1rem), calc(var(--ds-section) / 16 * 1rem + var(--ds-section) * 0.5 / 16 * var(--fl)), calc(var(--ds-section) * 1.5 / 16 * 1rem)); --section-gap-none: 0px; - --section-gap-compact: clamp(0.75rem, 1.25vw, 1.25rem); - --section-gap-normal: clamp(1.25rem, 2.5vw, 2.25rem); - --section-gap-large: clamp(2rem, 4vw, 3.5rem); + --section-gap-compact: clamp(calc(var(--ds-space) * 1.5 / 16 * 1rem), calc(var(--ds-space) * 1.5 / 16 * 1rem + var(--ds-space) * 0.5 / 16 * var(--fl)), calc(var(--ds-space) * 2 / 16 * 1rem)); + --section-gap-normal: clamp(calc(var(--ds-space) * 2 / 16 * 1rem), calc(var(--ds-space) * 2 / 16 * 1rem + var(--ds-space) * 1.5 / 16 * var(--fl)), calc(var(--ds-space) * 3.5 / 16 * 1rem)); + --section-gap-large: clamp(calc(var(--ds-space) * 3 / 16 * 1rem), calc(var(--ds-space) * 3 / 16 * 1rem + var(--ds-space) * 2 / 16 * var(--fl)), calc(var(--ds-space) * 5 / 16 * 1rem)); + --grid-gap: var(--section-gap-normal); --width-reading: 44rem; - --width-standard: 82rem; - --width-wide: 96rem; + --width-standard: calc(var(--ds-width) / 16 * 1rem); + --width-wide: calc(var(--ds-width) * 1.17 / 16 * 1rem); + + /* + * Mediengröße. --media-h: Höhe des Bildes neben dem Text (Bild und Text, Variante Standard). Die Dichtestufen der + * Größenvarianten (Einstieg: kompakt, normal, groß; Bild und Text: kompakt, normal, großzügig) skalieren über + * --dens (Kompakt 0,75, Standard 1, Großzügig 1,3) Bildhöhe, Mindesthöhe und Innenabstände. + */ + --media-h: calc(var(--ds-media) / 16 * 1rem); --container-narrow: var(--width-reading); --container-standard: var(--width-standard); --container-wide: var(--width-wide); @@ -141,18 +192,33 @@ :root { * --header-height-initial hoch und klebt mit negativem Abstand, sodass beim Scrollen nur die * kompakte Leiste (--header-height) sichtbar bleibt. Auf Smartphones sind beide Werte gleich. */ - --header-height: 4rem; - --header-height-initial: 4rem; + --header-height: calc(var(--ds-header) * 0.8 / 16 * 1rem); + --header-height-initial: calc(var(--ds-header) * 0.8 / 16 * 1rem); --touch-target: 2.75rem; } @media (min-width: 75rem) { :root { - --header-height: 4.5rem; - --header-height-initial: 6.5rem; + --header-height-initial: calc(var(--ds-header) / 16 * 1rem); } } +/* Dichtestufen der Größenvarianten (gespeicherte Schlüssel bleiben compact, normal, large bzw. spacious). */ +.lf-hero, +.lf-bt { + --dens: 1; +} + +.lf-hero--height-compact, +.lf-bt--height-compact { + --dens: 0.75; +} + +.lf-hero--height-large, +.lf-bt--height-spacious { + --dens: 1.3; +} + /* Dunkle Fläche: helle Schrift, gelber Fokus (Navy/Weiß 15:1). */ .scope-dark { --color-text: #f4f6f8; diff --git a/resources/css/widgets.css b/resources/css/widgets.css index 3014288..b55d7c3 100644 --- a/resources/css/widgets.css +++ b/resources/css/widgets.css @@ -102,11 +102,11 @@ .card-image { .card-body { display: grid; gap: var(--space-2); - padding: var(--space-5); + padding: var(--pad-card); } .card-title { - font-size: clamp(1.1875rem, 1.1rem + 0.4cqi, 1.375rem); + font-size: var(--text-h3); line-height: 1.2; margin: 0; } @@ -156,11 +156,11 @@ .cards-featured .card-lead { } .cards-featured .card-lead .card-title { - font-size: clamp(1.5rem, 1.1rem + 1.8cqi, 2.25rem); + font-size: clamp(1.375rem, 3cqi, var(--text-h2)); } .cards-featured .card-lead .card-body { - padding: clamp(1.5rem, 4cqi, 3rem); + padding: clamp(var(--pad-card), 3.4cqi, var(--pad-surface)); align-content: center; } @@ -172,7 +172,7 @@ @container slot (min-width: 44rem) { .cards-featured .card-lead .card-media { aspect-ratio: auto; - min-height: 20rem; + min-height: var(--media-h); } } @@ -260,8 +260,8 @@ .catalog-card-visual { position: relative; display: flex; align-items: flex-end; - min-height: 7rem; - padding: var(--space-4) var(--space-5); + min-height: calc(var(--ds-space) * 11 / 16 * 1rem); + padding: var(--space-3) var(--pad-card); background: var(--lf-navy); border-bottom: 5px solid var(--lf-yellow); } @@ -274,14 +274,14 @@ .scope-dark .catalog-card-visual { .catalog-card-visual span { font-family: var(--font-display); font-weight: 800; - font-size: 1.25rem; + font-size: var(--text-h3); color: var(--lf-white); } .catalog-card-rays { position: absolute; - top: var(--space-4); - right: var(--space-5); + top: var(--space-3); + right: var(--pad-card); width: 2.75rem; } @@ -289,11 +289,11 @@ .catalog-card-body { display: grid; gap: var(--space-2); align-content: start; - padding: var(--space-5); + padding: var(--pad-card); } .catalog-card-body h3 { - font-size: clamp(1.25rem, 1.15rem + 0.5cqi, 1.5rem); + font-size: var(--text-h3); line-height: 1.2; margin: 0; } @@ -359,12 +359,12 @@ @container slot (min-width: 40rem) { .catalog-cards-standard[data-count='1'] .catalog-card-visual { border-bottom: 0; border-right: 5px solid var(--lf-yellow); - min-height: 11rem; + min-height: calc(var(--ds-space) * 16 / 16 * 1rem); } .catalog-cards-standard[data-count='1'] .catalog-card-body { align-content: center; - padding: var(--space-6); + padding: calc(var(--pad-card) * 1.5); } } @@ -409,7 +409,7 @@ .cta { position: relative; background: var(--color-surface-subtle); border-radius: var(--radius-panel); - padding: clamp(1.5rem, 5cqi, 3rem); + padding: clamp(var(--pad-card), 3.4cqi, var(--pad-surface)); color: var(--lf-ink); --color-heading: var(--lf-navy); --color-text: var(--lf-ink); @@ -425,7 +425,7 @@ .section-bg-light .cta { } .cta h2 { - font-size: clamp(1.5rem, 1.1rem + 2cqi, 2.25rem); + font-size: clamp(1.375rem, 3.6cqi, var(--text-h2)); } .cta p { @@ -450,7 +450,7 @@ .faq { .faq dt { font-family: var(--font-display); font-weight: 700; - font-size: 1.125rem; + font-size: var(--text-h3); color: var(--color-heading); padding-top: var(--space-4); border-top: 1px solid var(--color-border); diff --git a/resources/views/filament/design/groessen.blade.php b/resources/views/filament/design/groessen.blade.php new file mode 100644 index 0000000..abb8648 --- /dev/null +++ b/resources/views/filament/design/groessen.blade.php @@ -0,0 +1,94 @@ +{{-- Website → Design → Größen (ADR-44): zehn Basiswerte der Größenskala, Arbeitsstand mit einer Speicherhandlung. --}} +@php + $geaendert = $this->geaendert(); + $eigene = \App\Domain\Design\DesignSettings::isCustomised(); + $gespeichert = \App\Domain\Design\DesignSettings::updatedAt(); + $status = match (true) { + $this->fehler !== [] => [['text' => 'Nicht gespeichert: Bitte die markierten Werte korrigieren.', 'ton' => 'offen']], + $geaendert => [ + ['text' => 'Änderungen nicht gespeichert', 'ton' => 'offen'], + ['text' => 'Wirkt nach dem Speichern sofort auf die öffentliche Website und alle CMS-Vorschauen, ohne Deployment.', 'ton' => 'neutral'], + ], + default => [[ + 'text' => ($eigene ? 'Eigene Werte gespeichert' : 'Standardwerte aktiv').' · gelten auf der Website und in den CMS-Vorschauen'.($eigene && $gespeichert ? ' · zuletzt '.$gespeichert->timezone(config('app.timezone'))->format('d.m.Y H:i') : ''), + 'ton' => 'gut', + ]], + }; + $aktionen = [ + ['label' => 'Website ansehen (gespeicherter Stand)', 'href' => url('/'), 'neu' => true, 'icon' => 'extern', 'art' => 'line'], + ['label' => 'Größen speichern', 'wire' => 'speichern', 'art' => 'primary', 'disabled' => ! $geaendert], + ]; + $mehr = []; + if ($geaendert) { + $mehr[] = ['label' => 'Änderungen verwerfen …', 'wire' => "askConfirmation('verwerfen')", 'hinweis' => 'Die Eingaben kehren zum wirksamen Stand zurück.', 'gefahr' => true]; + } + $mehr[] = ['label' => 'Standardwerte wiederherstellen …', 'wire' => "askConfirmation('standard')", 'hinweis' => 'Entfernt die gespeicherten Größen; es gelten wieder die Standardwerte.', 'gefahr' => true]; + $standard = \App\Domain\Design\DesignScale::defaults(); +@endphp + +
+ @include('filament.verwaltung.kopf', [ + 'brot' => ['Website', 'Design', 'Größen'], + 'titel' => 'Größen', + 'typ' => 'Basiswerte der Größenskala für Website und CMS-Vorschau', + 'status' => $status, + 'aktionen' => $aktionen, + 'mehr' => $mehr, + ]) + +

+ Zehn Basiswerte in Pixel steuern die gesamte Größenskala. Alles Weitere (Überschrift 3, Einleitung, kleine Schrift, Abschnittsabstände, + Abstände im Raster, Kopfzeile beim Scrollen, Mindesthöhen der Varianten kompakt, standard und großzügig) wird daraus abgeleitet. + Auf Smartphones und Tablets werden die Werte automatisch kleiner; der Fließtext bleibt dort mindestens 16 px groß, Bedienflächen mindestens 44 px. +

+ + @foreach (\App\Domain\Design\DesignScale::GROUPS as $gruppe) +
+

{{ $gruppe }}

+
+ @foreach (\App\Domain\Design\DesignScale::PARAMETERS as $key => $p) + @continue($p['group'] !== $gruppe) + @php + $fehler = $this->fehler[$key] ?? null; + $wert = $this->werte[$key] ?? ''; + $istStandard = (string) $wert === (string) $standard[$key]; + @endphp +
$fehler !== null]) wire:key="groesse-{{ $key }}"> + + @if ($fehler) +

{{ $fehler }}

+ @endif +

{{ $p['hint'] }} {{ $p['effect'] }}

+
+ Zulässig {{ $p['min'] }} bis {{ $p['max'] }} px · Standard {{ $standard[$key] }} px + @unless ($istStandard) + + @endunless +
+
+ @endforeach +
+
+ @endforeach + +
+ @include('filament.verwaltung.icon', ['name' => 'info'])Hilfe +
+

Der Arbeitsstand bleibt offen, bis „Größen speichern“ ihn schreibt. Danach gelten die Werte sofort auf der Website und in jeder CMS-Vorschau; ein Deployment ist nicht nötig. „Website ansehen“ zeigt den gespeicherten Stand, nicht die offenen Eingaben.

+

„Standardwerte wiederherstellen“ entfernt die gespeicherten Größen. Inhalte, Seiten und Widget-Einstellungen bleiben dabei unverändert.

+

Die Größenvarianten kompakt, standard und großzügig der Widgets (Einstieg, Bild und Text) bauen auf denselben Werten auf: Kompakt ist 75 %, großzügig 130 % der Standardhöhe und -abstände.

+

Die Skala gilt auch im Mitgliederbereich, soweit er die gemeinsamen Schrift- und Abstandswerte verwendet. Kopfzeile, Abschnittsabstände, Inhaltsbreite und Bildhöhen betreffen nur die öffentliche Website.

+
+
+
+@include('filament.verwaltung.bestaetigung') +
diff --git a/resources/views/filament/verwaltung/styles.blade.php b/resources/views/filament/verwaltung/styles.blade.php index b8a7986..72011d8 100644 --- a/resources/views/filament/verwaltung/styles.blade.php +++ b/resources/views/filament/verwaltung/styles.blade.php @@ -183,6 +183,15 @@ .vw-karte-box { display: grid; gap: 0.75rem; padding: 1rem 1.1rem; border: 1px solid var(--vw-line); border-radius: var(--vw-radius); background: var(--vw-surface); } .vw-karte-box h2 { font-size: 1.05rem; } .vw-karte-box.is-flach { background: var(--vw-paper); } + + /* Website → Design → Größen */ + .vw-groessen { display: grid; gap: 1rem; } + .vw-groessen-raster { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr)); gap: 0 1.5rem; } + .vw-groessen-feld { border-bottom: 0; border-top: 1px solid var(--vw-line); align-content: start; } + .vw-groessen-eingabe { display: flex; align-items: center; gap: 0.5rem; max-width: 12rem; } + .vw-groessen-eingabe input { width: 100%; min-height: var(--vw-target); padding: 0.45rem 0.7rem; border: 1px solid var(--vw-line-strong); border-radius: var(--vw-radius); background: var(--vw-surface); color: var(--vw-ink); font: inherit; font-weight: 400; } + .vw-groessen-eingabe span { color: var(--vw-quiet); font-weight: 400; } + .vw-groessen-feld.is-fehler input { border-color: var(--vw-error); } .vw-quelle { display: grid; gap: 0.4rem; } .vw-varianten { display: grid; gap: 0.5rem; margin: 0; padding: 0; list-style: none; } .vw-varianten li { display: grid; gap: 0.15rem; padding: 0.6rem 0.7rem; border: 1px solid var(--vw-line); border-radius: var(--vw-radius-small); background: var(--vw-surface); } diff --git a/resources/views/layouts/member.blade.php b/resources/views/layouts/member.blade.php index f88fa17..1fc3003 100644 --- a/resources/views/layouts/member.blade.php +++ b/resources/views/layouts/member.blade.php @@ -7,6 +7,8 @@ @fonts @vite(['resources/css/app.css', 'resources/js/app.js']) + {{-- Abweichende Basiswerte der Größenskala (Website → Design → Größen); nach dem Stylesheet, damit sie gelten. --}} + {{ \App\Domain\Design\DesignSettings::styleTag() }} diff --git a/resources/views/layouts/site.blade.php b/resources/views/layouts/site.blade.php index 8591b48..70ca12f 100644 --- a/resources/views/layouts/site.blade.php +++ b/resources/views/layouts/site.blade.php @@ -14,6 +14,8 @@ @fonts @vite(['resources/css/app.css', 'resources/js/app.js']) + {{-- Abweichende Basiswerte der Größenskala (Website → Design → Größen); nach dem Stylesheet, damit sie gelten. --}} + {{ \App\Domain\Design\DesignSettings::styleTag() }} diff --git a/tests/Feature/DesignScaleSettingsTest.php b/tests/Feature/DesignScaleSettingsTest.php new file mode 100644 index 0000000..b4cb292 --- /dev/null +++ b/tests/Feature/DesignScaleSettingsTest.php @@ -0,0 +1,245 @@ +systemverwalter()->create(); + $admin->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + return $admin; + } + + private function publishPage(string $path = '/groessen'): void + { + $page = Page::query()->create(['path' => $path]); + $service = app(PageService::class); + $service->publish($page, $service->saveRevision($page, [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Größen']]], null, null, null)); + } + + // --------------------------------------------------------------------------------------------------------------- + // Speicherung + // --------------------------------------------------------------------------------------------------------------- + + public function test_without_a_stored_row_the_defaults_apply_and_nothing_is_written(): void + { + $this->assertSame(DesignScale::defaults(), DesignSettings::values()); + $this->assertFalse(DesignSettings::isCustomised()); + $this->assertSame('', (string) DesignSettings::styleTag()); + $this->assertSame(0, SiteSetting::query()->count(), 'Die Migration legt keine Zeile an.'); + } + + public function test_saving_validates_stores_and_takes_effect_immediately(): void + { + $admin = $this->admin(); + $this->assertSame(DesignScale::defaults(), DesignSettings::values()); + + $errors = DesignSettings::save([...DesignScale::defaults(), 'body' => 18, 'card_pad' => 24], $admin); + + $this->assertSame([], $errors); + $this->assertSame(18, DesignSettings::values()['body']); + $this->assertTrue(DesignSettings::isCustomised()); + $this->assertSame($admin->getKey(), SiteSetting::query()->find(DesignSettings::KEY)->updated_by); + $this->assertSame('', (string) DesignSettings::styleTag()); + } + + public function test_invalid_input_is_not_stored(): void + { + $errors = DesignSettings::save([...DesignScale::defaults(), 'body' => 40]); + + $this->assertArrayHasKey('body', $errors); + $this->assertSame(0, SiteSetting::query()->count()); + $this->assertSame(DesignScale::defaults(), DesignSettings::values()); + } + + public function test_reset_removes_the_row_and_restores_the_defaults(): void + { + DesignSettings::save([...DesignScale::defaults(), 'h1' => 44]); + $this->assertSame(44, DesignSettings::values()['h1']); + + DesignSettings::reset(); + + $this->assertSame(DesignScale::defaults(), DesignSettings::values()); + $this->assertSame(0, SiteSetting::query()->count()); + $this->assertSame('', (string) DesignSettings::styleTag()); + } + + public function test_damaged_stored_data_falls_back_to_the_defaults(): void + { + SiteSetting::query()->create(['key' => DesignSettings::KEY, 'value' => ['body' => 999, 'h1' => 'x']]); + DesignSettings::flush(); + + $this->assertSame(DesignScale::defaults(), DesignSettings::values()); + $this->assertSame('', (string) DesignSettings::styleTag()); + } + + public function test_a_missing_table_does_not_break_the_public_site(): void + { + $this->publishPage(); + Schema::drop('site_settings'); + DesignSettings::flush(); + + $this->get('/groessen')->assertOk()->assertSee('Größen')->assertDontSee('lf-design-scale', false); + $this->assertSame(DesignScale::defaults(), DesignSettings::values()); + } + + // --------------------------------------------------------------------------------------------------------------- + // Wirkung auf Website, Anmeldung, Mitgliederbereich und Vorschau + // --------------------------------------------------------------------------------------------------------------- + + public function test_the_public_site_the_login_and_the_member_area_use_the_stored_values_after_the_stylesheet(): void + { + $this->publishPage(); + DesignSettings::save([...DesignScale::defaults(), 'body' => 19, 'header' => 96]); + + foreach (['/groessen', '/anmelden'] as $path) { + $html = $this->get($path)->assertOk()->getContent(); + $this->assertStringContainsString('', $html, $path); + } + + $member = User::factory()->create(); + $html = $this->actingAs($member)->get(route('member.dashboard'))->getContent(); + $this->assertStringContainsString('--ds-body:19;', $html, 'Der Mitgliederbereich nutzt dieselbe Skala.'); + } + + public function test_defaults_add_no_inline_block_to_the_page(): void + { + $this->publishPage(); + + $this->get('/groessen')->assertOk()->assertDontSee('lf-design-scale', false); + } + + public function test_the_cms_previews_use_the_same_active_values(): void + { + $this->assertStringNotContainsString('lf-design-scale', WidgetEditor::previewStylesheets()); + + DesignSettings::save([...DesignScale::defaults(), 'h2' => 30, 'media' => 360]); + + $this->assertStringContainsString(':root{--ds-h2:30;--ds-media:360;}', WidgetEditor::previewStylesheets()); + } + + // --------------------------------------------------------------------------------------------------------------- + // Verwaltungsseite + // --------------------------------------------------------------------------------------------------------------- + + public function test_only_the_system_administrator_may_open_the_page(): void + { + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + $this->get('/verwaltung/design/groessen')->assertRedirect(); + $this->actingAs($editor, 'staff')->get('/verwaltung/design/groessen')->assertForbidden(); + $this->actingAs($this->admin(), 'staff')->get('/verwaltung/design/groessen')->assertOk()->assertSee('Größen')->assertSee('Fließtext'); + } + + public function test_the_page_is_listed_in_the_navigation_for_the_administrator(): void + { + $this->actingAs($this->admin(), 'staff')->get('/verwaltung/design/groessen')->assertOk() + ->assertSee('Design') + ->assertSee(DesignGroessen::getUrl()); + } + + public function test_the_form_shows_the_active_values_and_saves_changes_with_one_action(): void + { + $component = Livewire::actingAs($this->admin(), 'staff')->test(DesignGroessen::class); + + $component->assertSet('werte.body', 17)->assertSet('werte.width', 1312); + $this->assertFalse($component->instance()->geaendert()); + + $component->set('werte.body', '18')->set('werte.media', '300'); + $this->assertTrue($component->instance()->geaendert()); + $this->assertSame(DesignScale::defaults(), DesignSettings::values(), 'Offene Eingaben speichern nichts.'); + + $component->call('speichern')->assertHasNoErrors(); + + $this->assertSame(18, DesignSettings::values()['body']); + $this->assertSame(300, DesignSettings::values()['media']); + $this->assertFalse($component->instance()->geaendert()); + } + + public function test_invalid_values_show_messages_and_are_not_saved(): void + { + $component = Livewire::actingAs($this->admin(), 'staff')->test(DesignGroessen::class) + ->set('werte.body', '99') + ->set('werte.h2', '') + ->call('speichern'); + + $this->assertArrayHasKey('body', $component->get('fehler')); + $this->assertArrayHasKey('h2', $component->get('fehler')); + $this->assertSame(0, SiteSetting::query()->count()); + $component->assertSee('mindestens 16 px', false)->assertSee('höchstens 20 px', false); + } + + public function test_restoring_the_defaults_needs_a_confirmation_and_clears_the_stored_values(): void + { + DesignSettings::save([...DesignScale::defaults(), 'body' => 18, 'section' => 64]); + + $component = Livewire::actingAs($this->admin(), 'staff')->test(DesignGroessen::class) + ->assertSet('werte.section', 64) + ->call('askConfirmation', 'standard'); + + $this->assertSame(64, DesignSettings::values()['section'], 'Erst die Bestätigung wirkt.'); + $component->assertSee('Standardwerte wiederherstellen?', false)->call('confirmConfirmation'); + + $this->assertSame(DesignScale::defaults(), DesignSettings::values()); + $component->assertSet('werte.section', 48)->assertSet('bestaetigung', null); + } + + public function test_cancelling_the_confirmation_keeps_everything(): void + { + DesignSettings::save([...DesignScale::defaults(), 'body' => 18]); + + Livewire::actingAs($this->admin(), 'staff')->test(DesignGroessen::class) + ->call('askConfirmation', 'standard') + ->call('cancelConfirmation') + ->assertSet('bestaetigung', null); + + $this->assertSame(18, DesignSettings::values()['body']); + } + + public function test_discarding_returns_the_inputs_to_the_active_state_without_saving(): void + { + $component = Livewire::actingAs($this->admin(), 'staff')->test(DesignGroessen::class) + ->set('werte.h1', '44') + ->call('askConfirmation', 'verwerfen') + ->call('confirmConfirmation') + ->assertSet('werte.h1', 40); + + $this->assertSame(0, SiteSetting::query()->count()); + $this->assertFalse($component->instance()->geaendert()); + } + + public function test_a_redakteur_cannot_call_the_page_component(): void + { + $editor = User::factory()->redakteur()->create(); + + Livewire::actingAs($editor, 'staff')->test(DesignGroessen::class)->assertForbidden(); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 388f6b5..0e09dcc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,7 @@ namespace Tests; +use App\Domain\Design\DesignSettings; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase @@ -11,5 +12,6 @@ protected function setUp(): void parent::setUp(); $this->withoutVite(); + DesignSettings::flush(); } } diff --git a/tests/Unit/DesignScaleTest.php b/tests/Unit/DesignScaleTest.php new file mode 100644 index 0000000..2289d57 --- /dev/null +++ b/tests/Unit/DesignScaleTest.php @@ -0,0 +1,95 @@ +assertSame([ + 'body' => 17, 'h1' => 40, 'h2' => 28, 'display' => 52, 'space' => 8, + 'section' => 48, 'card_pad' => 20, 'header' => 80, 'width' => 1312, 'media' => 320, + ], DesignScale::defaults()); + $this->assertSame([], DesignScale::errors(DesignScale::defaults())); + } + + public function test_every_default_lies_within_its_range(): void + { + foreach (DesignScale::PARAMETERS as $key => $p) { + $this->assertGreaterThanOrEqual($p['min'], $p['default'], $key); + $this->assertLessThanOrEqual($p['max'], $p['default'], $key); + $this->assertContains($p['group'], DesignScale::GROUPS, $key); + } + } + + public function test_the_defaults_equal_the_values_in_the_stylesheet(): void + { + $css = file_get_contents(dirname(__DIR__, 2).'/resources/css/tokens.css'); + $this->assertNotFalse($css); + preg_match_all('/--ds-([a-z0-9-]+):\s*(\d+);/', $css, $found, PREG_SET_ORDER); + $declared = []; + + foreach ($found as [, $name, $value]) { + $declared[str_replace('-', '_', $name)] = (int) $value; + } + + $this->assertSame(DesignScale::defaults(), $declared, 'tokens.css (Block Größenskala) und DesignScale::PARAMETERS müssen dieselben Standardwerte haben.'); + } + + public function test_values_outside_the_ranges_are_rejected_with_a_message_per_field(): void + { + $errors = DesignScale::errors([...DesignScale::defaults(), 'body' => 12, 'width' => 3000, 'media' => 'abc', 'space' => '']); + + $this->assertEqualsCanonicalizing(['body', 'width', 'media', 'space'], array_keys($errors)); + $this->assertStringContainsString('mindestens 16 px', $errors['body']); + $this->assertStringContainsString('höchstens 1600 px', $errors['width']); + $this->assertStringContainsString('ganze Zahl', $errors['media']); + $this->assertStringContainsString('Bitte einen Wert', $errors['space']); + } + + public function test_the_order_of_the_type_sizes_is_enforced(): void + { + $this->assertArrayHasKey('h2', DesignScale::errors([...DesignScale::defaults(), 'body' => 20, 'h2' => 24])); + $this->assertArrayHasKey('h1', DesignScale::errors([...DesignScale::defaults(), 'h2' => 36, 'h1' => 38])); + $this->assertArrayHasKey('display', DesignScale::errors([...DesignScale::defaults(), 'h1' => 50, 'display' => 44])); + $this->assertSame([], DesignScale::errors([...DesignScale::defaults(), 'body' => 18, 'h2' => 24, 'h1' => 30, 'display' => 36])); + } + + public function test_form_strings_are_accepted_as_numbers(): void + { + $input = array_map('strval', DesignScale::defaults()); + + $this->assertSame([], DesignScale::errors($input)); + $this->assertSame([], DesignScale::errors([...$input, 'body' => '18'])); + $this->assertNotSame([], DesignScale::errors([...$input, 'body' => '17.5']), 'Nur ganze Pixel.'); + } + + public function test_only_deviating_values_become_variables(): void + { + $this->assertSame('', DesignScale::css(DesignScale::defaults())); + $this->assertSame(':root{--ds-body:18;--ds-card-pad:24;}', DesignScale::css([...DesignScale::defaults(), 'body' => 18, 'card_pad' => 24])); + } + + public function test_the_stylesheet_block_contains_only_validated_numbers_of_known_keys(): void + { + $css = DesignScale::css([...DesignScale::defaults(), 'body' => 18, 'evil' => '};body{display:none}', 'h1' => 99999]); + + $this->assertSame(':root{--ds-body:18;}', $css, 'Unbekannte Schlüssel und Werte außerhalb des Bereichs werden nie ausgegeben.'); + } + + public function test_reading_stored_values_never_fails_and_falls_back_to_the_defaults(): void + { + $this->assertSame(DesignScale::defaults(), DesignScale::read(null)); + $this->assertSame(DesignScale::defaults(), DesignScale::read('kaputt')); + $this->assertSame(DesignScale::defaults(), DesignScale::read(['body' => 99]), 'Außerhalb des Bereichs: Standard.'); + $this->assertSame(DesignScale::defaults(), DesignScale::read(['h1' => 30, 'h2' => 29]), 'Falsche Reihenfolge: Standard.'); + $this->assertSame([...DesignScale::defaults(), 'body' => 18], DesignScale::read(['body' => 18, 'unbekannt' => 5, 'h1' => 'x']), 'Fehlendes und Fremdes wird ignoriert.'); + $this->assertSame([...DesignScale::defaults(), 'body' => 18], DesignScale::read(['body' => '18'])); + } +}