{{-- @intent Renderização única de imagem do serviço Media (ADR-026 §5): `` com AVIF/WebP, `width`/`height` (CLS zero) e a mesma origem (`media.stream`) — **nunca** `` cru. @description Recebe as **chaves de objeto** (não URLs): a URL é derivada aqui, então trocar RustFS por AWS S3/CDN é `.env` (ADR-030). O tamanho/alinhamento/layout vêm do chamador (`figure-class`/`img-class`); o componente só garante a semântica, o formato e o CLS. --}} @props([ 'path' => null, 'sources' => [], 'alt' => '', 'caption' => null, 'width' => 0, 'height' => 0, 'sizes' => null, 'loading' => 'lazy', 'fetchpriority' => null, 'figureClass' => 'media-picture', 'imgClass' => null, ]) @php $routeName = config('services.media.stream_route'); $routeName = is_string($routeName) && $routeName !== '' ? $routeName : 'media.stream'; $resolve = static function (mixed $key) use ($routeName): ?string { $key = is_string($key) ? ltrim(trim($key), '/') : ''; return $key === '' ? null : route($routeName, ['path' => $key]); }; $src = $resolve($path); // Agrupa as variantes por formato, em ordem crescente de largura (srcset determinístico). $groups = []; foreach (is_array($sources) ? $sources : [] as $source) { if (! is_array($source)) { continue; } $url = $resolve($source['path'] ?? null); $variantWidth = is_numeric($source['width'] ?? null) ? (int) $source['width'] : 0; $type = is_string($source['type'] ?? null) && $source['type'] !== '' ? $source['type'] : 'image/webp'; if ($url === null || $variantWidth <= 0) { continue; } $groups[$type][] = ['url' => $url, 'width' => $variantWidth]; } foreach ($groups as $type => $variants) { usort($variants, static fn (array $a, array $b): int => $a['width'] <=> $b['width']); $groups[$type] = $variants; } ksort($groups); @endphp @if ($src !== null)
@foreach ($groups as $type => $variants) @endforeach {{ $alt }} 0 && (int) $height > 0) width="{{ (int) $width }}" height="{{ (int) $height }}" @endif @if (filled($sizes)) sizes="{{ $sizes }}" @endif @if (filled($imgClass)) class="{{ $imgClass }}" @endif loading="{{ $loading }}" decoding="async" @if (filled($fetchpriority)) fetchpriority="{{ $fetchpriority }}" @endif > @if (filled($caption) || filled($alt))
blank($caption)])>{{ $caption ?: $alt }}
@endif
@endif