> */ public const UNITS = [ 'u4' => [4], 'u2_2' => [2, 2], 'u1_3' => [1, 3], 'u3_1' => [3, 1], 'u1_2_1' => [1, 2, 1], 'u1_1_1_1' => [1, 1, 1, 1], 'u1_1_2' => [1, 1, 2], 'u2_1_1' => [2, 1, 1], ]; /** @var array */ public const LABELS = [ 'u4' => 'Volle Breite', 'u2_2' => 'Zwei gleich breit', 'u1_3' => 'Schmal und breit', 'u3_1' => 'Breit und schmal', 'u1_2_1' => 'Mitte betont', 'u1_1_1_1' => 'Vier gleich breit', 'u1_1_2' => 'Zwei schmal, eins breit', 'u2_1_1' => 'Eins breit, zwei schmal', ]; public static function has(mixed $key): bool { return is_string($key) && isset(self::UNITS[$key]); } /** * @return list */ public static function units(string $key): array { return self::UNITS[$key] ?? self::UNITS[self::DEFAULT]; } public static function slotCount(string $key): int { return count(self::units($key)); } /** Kurzform wie „1 + 3“. */ public static function short(string $key): string { return implode(' + ', self::units($key)); } public static function label(string $key): string { return (self::LABELS[$key] ?? self::LABELS[self::DEFAULT]).' ('.self::short($key).')'; } /** * @return array */ public static function options(): array { $options = []; foreach (array_keys(self::UNITS) as $key) { $options[$key] = self::label($key); } return $options; } /** * Spaltenvorlagen für die Slots, die tatsächlich etwas darstellen. * * - Desktop (Abschnitt ab 60rem): Verhältnis der Einheiten. * - Tablet (ab 40rem): gleich breite Slots bleiben nebeneinander (zwei oder drei Spalten, vier Slots als 2 × 2); * ungleiche Raster stapeln, damit kein Slot unter etwa 13rem fällt. * - Smartphone: immer eine Spalte. Die Lese- und Fokusreihenfolge bleibt die Reihenfolge der Slots. * * @param list $units * @return array{lg: string, md: string} */ public static function columns(array $units): array { $units = array_values(array_filter($units, fn ($unit): bool => is_int($unit) && $unit > 0)); $count = count($units); if ($count <= 1) { return ['lg' => 'minmax(0, 1fr)', 'md' => 'minmax(0, 1fr)']; } $lg = implode(' ', array_map(fn (int $unit): string => "minmax(0, {$unit}fr)", $units)); $equal = count(array_unique($units)) === 1; $md = match (true) { ! $equal => 'minmax(0, 1fr)', $count === 3 => 'repeat(3, minmax(0, 1fr))', default => 'repeat(2, minmax(0, 1fr))', }; return ['lg' => $lg, 'md' => $md]; } /** * Symbolbild des Rasters für die grafische Auswahl im Editor (rein dekorativ). */ public static function schematicSvg(string $key): string { $units = self::units($key); $gap = 2; $width = 56 - $gap * (count($units) - 1); $x = 2; $rects = ''; foreach ($units as $unit) { $w = (int) round($width * $unit / 4); $rects .= sprintf('', $x, $w); $x += $w + $gap; } return ''; } }