Verteile die redaktionellen Karten ausgewogen auf Zeilen mit Mindestbreite
Deploy Test / test (push) Successful in 5m48s
Deploy Test / deploy (push) Successful in 42s

Raster und hervorgehobene Variante umbrechen jetzt wie Text (Flex) statt im
Grid: Jede Karte ist mindestens 15 rem breit (mit Symbol neben dem Text
18 rem) und wandert bei Unterschreitung in die nächste Zeile. Die Zeilen
sind ausgewogen und unterscheiden sich um höchstens eine Karte (fünf Karten
3 + 2, zehn Karten 4 + 3 + 3) bei 1 bis 12 Karten.

Die Zahl je Zeile steht als erzeugte Tabelle in
lf-karten-verteilung.css (Generator scripts/cards-balance-css.py); das
Stylesheet liest die Zahl der Karten per :has(> .card:nth-child(n)), das
Markup bleibt unverändert. "Abstände gleichen aus" nutzt space-evenly,
mit Trennstrich bleiben die Spalten gleich breit.

Tests: Tabelle für 2 bis 12 Karten und alle Breiten, Mindestbreite, Flex.
Gemessen im Browser für 1 bis 12 Karten, vier Anordnungen, sechs Breiten.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-27 09:47:31 +01:00
1 parent 2393000468
commit a12818b752
26 files changed
+918 -53

No files matched your search

+87
View File
@@ -219,6 +219,93 @@ public function test_the_stylesheet_keeps_links_clickable_and_colors_readable_on
$this->assertStringContainsString('prefers-reduced-motion', substr($css, (int) strpos($css, '.cards--hover .card {')));
}
/**
* Wertet die erzeugte Tabelle (lf-karten-verteilung.css) wie der Browser aus: je Zahl der Karten, Breite des Platzes (rem)
* und Karte die Zahl der Karten in ihrer Zeile. Spätere Regeln gewinnen bei gleicher Spezifität; die Tabelle für Symbole
* neben dem Text hat die höhere.
*
* @return array<int, int> Karte (1-basiert, ohne die hervorgehobene erste) => Karten in ihrer Zeile
*/
private function rowSizes(string $css, int $cards, float $width, bool $side, bool $featured): array
{
$current = [];
$threshold = 0.0;
foreach (preg_split('/\R/', $css) as $line) {
if (preg_match('/^@container slot \(min-width: ([\d.]+)rem\)/', $line, $match)) {
$threshold = (float) $match[1];
continue;
}
if (str_starts_with($line, '}')) {
$threshold = 0.0;
continue;
}
if (! preg_match('/^\s*(\.cards[^{]*?) > \.card:nth-child\(n\+(\d+)\) \{ --cards-c: (\d+); \}$/', $line, $match) || $threshold > $width) {
continue;
}
[, $selector, $from, $value] = $match;
$isSide = str_contains($selector, 'cards--symbol-left');
$isFeatured = str_contains($selector, '.cards.cards-featured');
if ($isFeatured !== $featured || ($isSide && ! $side) || ! str_contains($selector, ':nth-child('.($cards + ($featured ? 1 : 0)).')):not(')) {
continue;
}
for ($child = (int) $from; $child <= $cards + ($featured ? 1 : 0); $child++) {
$card = $child - ($featured ? 1 : 0);
if ($card >= 1 && (($current[$card]['side'] ?? false) <= $isSide)) {
$current[$card] = ['side' => $isSide, 'value' => (int) $value];
}
}
}
return array_map(fn (array $entry): int => $entry['value'], $current);
}
public function test_the_balance_table_gives_even_rows_for_one_to_twelve_cards_at_every_width(): void
{
$css = (string) file_get_contents(resource_path('css/components/lf-karten-verteilung.css'));
foreach ([false, true] as $featured) {
foreach ([false, true] as $side) {
$minimum = $side ? 18.0 : 15.0;
foreach ([20.0, 31.75, 36.0, 40.0, 48.5, 57.5, 65.25, 70.0, 77.25, 82.0, 98.75, 120.0] as $width) {
$columns = max(1, min(6, (int) floor(($width + 1.75) / ($minimum + 1.75))));
foreach (range(2, 12) as $cards) {
$rows = (int) ceil($cards / $columns);
$base = intdiv($cards, $rows);
$extra = $cards % $rows;
$expected = array_merge(array_fill(0, $extra * ($base + 1), $base + 1), array_fill(0, $cards - $extra * ($base + 1), $base));
$sizes = $this->rowSizes($css, $cards, $width, $side, $featured);
// Fehlende Karten: keine Regel gilt, also eine Karte je Zeile (Vorgabe --cards-c: 1).
$actual = array_map(fn (int $card): int => $sizes[$card] ?? 1, range(1, $cards));
$this->assertSame(array_values($expected), $actual, sprintf('%d Karten, Platz %srem, Symbol neben dem Text: %s, hervorgehoben: %s', $cards, $width, $side ? 'ja' : 'nein', $featured ? 'ja' : 'nein'));
}
}
}
}
}
public function test_the_cards_wrap_at_the_minimum_width_and_stay_in_flex_rows(): void
{
$css = (string) file_get_contents(resource_path('css/widgets.css'));
$this->assertStringContainsString('min-inline-size: min(var(--card-min), 100%);', $css);
$this->assertStringContainsString('--card-min: 15rem;', $css);
$this->assertStringContainsString('--card-min: 18rem;', $css);
$this->assertMatchesRegularExpression('/\.cards-grid,\s*\.cards-featured \{[^}]*display: flex;[^}]*flex-wrap: wrap;/s', $css);
$this->assertStringContainsString("@import './components/lf-karten-verteilung.css';", (string) file_get_contents(resource_path('css/app.css')));
}
public function test_the_symbol_field_survives_duplicating_a_card(): void
{
// Beim Duplizieren wertet das Feld die Vorschau aus, bevor die Vorlage als Referenz bereitsteht (Skriptfehler