多🌹444收拾收拾计算机视觉手机手机手机手机4大尺寸惆怅长岑长
??????????????????????????С??????????????P??????????????????????????????????????????????????????^??????????
????j??????????
? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!blade-icons/pint.json 0000644 00000000165 15266554047 0010611 0 ustar 00 {
"notPath": [
"tests/fixtures/blade-icons.php",
"tests/fixtures/generated-manifest.php"
]
}
blade-icons/src/Generation/IconGenerator.php 0000644 00000004776 15266554047 0015112 0 ustar 00 filesystem = new Filesystem;
$this->sets = $sets;
}
public static function create(array $config): self
{
return new self($config);
}
public function generate(): void
{
foreach ($this->sets as $set) {
$destination = $this->getDestinationDirectory($set);
$files = array_filter(
$this->filesystem->files($set['source']),
fn (SplFileInfo $value) => str_ends_with($value->getFilename(), '.svg')
);
foreach ($files as $file) {
$filename = Str::of($file->getFilename());
$filename = $this->applyPrefixes($set, $filename);
$filename = $this->applySuffixes($set, $filename);
$pathname = $destination.$filename;
$this->filesystem->copy($file->getRealPath(), $pathname);
if (is_callable($set['after'] ?? null)) {
$set['after']($pathname, $set, $file);
}
}
}
}
private function getDestinationDirectory(array $set): string
{
$destination = Str::finish($set['destination'], DIRECTORY_SEPARATOR);
if (! Arr::get($set, 'safe', false)) {
$this->filesystem->deleteDirectory($destination);
}
$this->filesystem->ensureDirectoryExists($destination);
return $destination;
}
private function applyPrefixes($set, Stringable $filename): Stringable
{
if ($set['input-prefix'] ?? false) {
$filename = $filename->after($set['input-prefix']);
}
if ($set['output-prefix'] ?? false) {
$filename = $filename->prepend($set['output-prefix']);
}
return $filename;
}
private function applySuffixes($set, Stringable $filename): Stringable
{
if ($set['input-suffix'] ?? false) {
$filename = $filename->replace($set['input-suffix'].'.svg', '.svg');
}
if ($set['output-suffix'] ?? false) {
$filename = $filename->replace('.svg', $set['output-suffix'].'.svg');
}
return $filename;
}
}
blade-icons/src/Factory.php 0000644 00000016411 15266554047 0011654 0 ustar 00 filesystem = $filesystem;
$this->manifest = $manifest;
$this->disks = $disks;
$this->config = $config;
$this->config['class'] = $config['class'] ?? '';
$this->config['attributes'] = (array) ($config['attributes'] ?? []);
$this->config['fallback'] = $config['fallback'] ?? '';
$this->config['components'] = [
'disabled' => $config['components']['disabled'] ?? false,
'default' => $config['components']['default'] ?? 'icon',
];
}
/**
* @internal This method is only meant for internal purposes and does not fall under the package's BC promise.
*/
public function all(): array
{
return $this->sets;
}
/**
* @throws CannotRegisterIconSet
*/
public function add(string $set, array $options): self
{
if (! isset($options['prefix'])) {
throw CannotRegisterIconSet::prefixNotDefined($set);
}
if ($collidingSet = $this->getSetByPrefix($options['prefix'])) {
throw CannotRegisterIconSet::prefixNotUnique($set, $collidingSet);
}
$paths = (array) ($options['paths'] ?? $options['path'] ?? []);
$options['paths'] = array_filter(array_map(
fn ($path) => $path !== '/' ? rtrim($path, '/') : $path,
$paths,
));
if (empty($options['paths'])) {
throw CannotRegisterIconSet::pathsNotDefined($set);
}
unset($options['path']);
$filesystem = $this->filesystem($options['disk'] ?? null);
foreach ($options['paths'] as $path) {
if ($path !== '/' && $filesystem->missing($path)) {
throw CannotRegisterIconSet::nonExistingPath($set, $path);
}
}
$this->sets[$set] = $options;
$this->cache = [];
return $this;
}
public function registerComponents(): void
{
if ($this->config['components']['disabled']) {
return;
}
foreach ($this->manifest->getManifest($this->sets) as $set => $paths) {
foreach ($paths as $icons) {
foreach ($icons as $icon) {
Blade::component(
SvgComponent::class,
$icon,
$this->sets[$set]['prefix'] ?? '',
);
}
}
}
}
/**
* @throws SvgNotFound
*/
public function svg(string $name, $class = '', array $attributes = []): Svg
{
[$set, $name] = $this->splitSetAndName($name);
try {
return new Svg(
$name,
$this->contents($set, $name),
$this->formatAttributes($set, $class, $attributes),
);
} catch (SvgNotFound $exception) {
if (isset($this->sets[$set]['fallback']) && $this->sets[$set]['fallback'] !== '') {
$name = $this->sets[$set]['fallback'];
try {
return new Svg(
$name,
$this->contents($set, $name),
$this->formatAttributes($set, $class, $attributes),
);
} catch (SvgNotFound $exception) {
//
}
}
if ($this->config['fallback']) {
return $this->svg($this->config['fallback'], $class, $attributes);
}
throw $exception;
}
}
/**
* @throws SvgNotFound
*/
private function contents(string $set, string $name): string
{
if (isset($this->cache[$set][$name])) {
return $this->cache[$set][$name];
}
if (isset($this->sets[$set])) {
foreach ($this->sets[$set]['paths'] as $path) {
try {
return $this->cache[$set][$name] = $this->getSvgFromPath(
$name,
$path,
$this->sets[$set]['disk'] ?? null,
);
} catch (FileNotFoundException $exception) {
//
}
}
}
throw SvgNotFound::missing($set, $name);
}
private function getSvgFromPath(string $name, string $path, ?string $disk = null): string
{
$contents = trim($this->filesystem($disk)->get(sprintf(
'%s/%s.svg',
rtrim($path),
str_replace('.', '/', $name),
)));
return $this->cleanSvgContents($contents);
}
private function cleanSvgContents(string $contents): string
{
return trim(preg_replace('/^(<\?xml.+?\?>)/', '', $contents));
}
private function splitSetAndName(string $name): array
{
$prefix = Str::before($name, '-');
$set = $this->getSetByPrefix($prefix);
$name = $set ? Str::after($name, '-') : $name;
return [$set ?? 'default', $name];
}
private function getSetByPrefix(string $prefix): ?string
{
return collect($this->sets)->where('prefix', $prefix)->keys()->first();
}
private function formatAttributes(string $set, $class = '', array $attributes = []): array
{
if (is_string($class)) {
if ($class = $this->buildClass($set, $class)) {
$attributes['class'] = $attributes['class'] ?? $class;
}
} elseif (is_array($class)) {
$attributes = $class;
if (! isset($attributes['class']) && $class = $this->buildClass($set, '')) {
$attributes['class'] = $class;
}
}
$attributes = array_merge(
$this->config['attributes'],
(array) ($this->sets[$set]['attributes'] ?? []),
$attributes,
);
foreach ($attributes as $key => $value) {
if (is_string($value)) {
$attributes[$key] = str_replace('"', '"', $value);
}
}
return $attributes;
}
private function buildClass(string $set, string $class): string
{
return trim(sprintf(
'%s %s',
trim(sprintf('%s %s', $this->config['class'], $this->sets[$set]['class'] ?? '')),
$class,
));
}
/**
* @return \Illuminate\Contracts\Filesystem\Filesystem|Filesystem
*/
private function filesystem(?string $disk = null)
{
return $this->disks && $disk ? $this->disks->disk($disk) : $this->filesystem;
}
}
blade-icons/src/Exceptions/SvgNotFound.php 0000644 00000000443 15266554047 0014600 0 ustar 00 filesystem = $filesystem;
$this->manifestPath = $manifestPath;
$this->disks = $disks;
}
private function build(array $sets): array
{
$compiled = [];
foreach ($sets as $name => $set) {
$icons = [];
foreach ($set['paths'] as $path) {
$icons[$path] = [];
foreach ($this->filesystem($set['disk'] ?? null)->allFiles($path) as $file) {
if ($file instanceof SplFileInfo) {
if ($file->getExtension() !== 'svg') {
continue;
}
$icons[$path][] = $this->format($file->getPathName(), $path);
} else {
if (! Str::endsWith($file, '.svg')) {
continue;
}
$icons[$path][] = $this->format($file, $path);
}
}
$icons[$path] = array_unique($icons[$path]);
}
$compiled[$name] = array_filter($icons);
}
return $compiled;
}
/**
* @return \Illuminate\Contracts\Filesystem\Filesystem|Filesystem
*/
private function filesystem(?string $disk = null)
{
return $this->disks && $disk ? $this->disks->disk($disk) : $this->filesystem;
}
public function delete(): bool
{
return $this->filesystem->delete($this->manifestPath);
}
private function format(string $pathname, string $path): string
{
return (string) Str::of($pathname)
->after($path.DIRECTORY_SEPARATOR)
->replace(DIRECTORY_SEPARATOR, '.')
->basename('.svg');
}
public function getManifest(array $sets): array
{
if (! is_null($this->manifest)) {
return $this->manifest;
}
if (! $this->filesystem->exists($this->manifestPath)) {
return $this->manifest = $this->build($sets);
}
return $this->manifest = $this->filesystem->getRequire($this->manifestPath);
}
/**
* @throws Exception
*/
public function write(array $sets): void
{
if (! is_writable($dirname = dirname($this->manifestPath))) {
throw new Exception("The {$dirname} directory must be present and writable.");
}
$this->filesystem->replace(
$this->manifestPath,
'build($sets), true).';',
);
}
}
blade-icons/src/Components/Svg.php 0000644 00000000766 15266554047 0013137 0 ustar 00 getIterator()->getArrayCopy();
$class = $attributes['class'] ?? '';
unset($attributes['class']);
return svg($this->componentName, $class, $attributes)->toHtml();
};
}
}
blade-icons/src/Components/Icon.php 0000644 00000001140 15266554047 0013253 0 ustar 00 name = $name;
}
public function render(): Closure
{
return function (array $data) {
$attributes = $data['attributes']->getIterator()->getArrayCopy();
$class = $attributes['class'] ?? '';
unset($attributes['class']);
return svg($this->name, $class, $attributes)->toHtml();
};
}
}
blade-icons/src/Svg.php 0000644 00000005413 15266554047 0011004 0 ustar 00 name = $name;
$this->contents = $this->deferContent($contents, $attributes['defer'] ?? false);
unset($attributes['defer']);
$this->attributes = $attributes;
}
public function name(): string
{
return $this->name;
}
public function contents(): string
{
return $this->contents;
}
/**
* This method adds a title element and an aria-labelledby attribute to the SVG.
* To comply with accessibility standards, SVGs should have a title element.
* Check accessibility patterns for icons: https://www.deque.com/blog/creating-accessible-svgs/
*/
public function addTitle(string $title): string
{
// create title element
$titleElement = '
'.$title.'';
// add role attribute to svg element
$this->attributes['role'] = 'img';
// add title element to svg
return preg_replace('/