*/
private array $cache = [];
public function render(string $slot, ?string $class = null, ?string $label = null): HtmlString
{
$world = $this->world();
$file = $world?->fileFor($slot);
if ($file === null) {
return new HtmlString(''); // a template asks for decoration and gets none
}
$svg = $this->cache[$file] ??= (string) file_get_contents($file);
if ($svg === '') {
return new HtmlString('');
}
$unique = 'm'.Str::lower(Str::random(6));
$svg = (string) preg_replace(['/\s(role|aria-label|aria-hidden)="[^"]*"/', '/
.*?<\/title>/s'], '', $svg);
$svg = (string) preg_replace(['/id="([^"]+)"/', '/url\(#([^)]+)\)/'], ['id="$1-'.$unique.'"', 'url(#$1-'.$unique.')'], $svg);
$attributes = 'class="'.e((string) $class).'" '.($label !== null
? 'role="img" aria-label="'.e($label).'"'
: 'aria-hidden="true" focusable="false"');
return new HtmlString((string) preg_replace('/