-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add favicon generation functionalities (#189)
Introduce favicon generation capabilities using the GDImage library and workbox integration for service worker builds. This includes browser config for Windows 8+ tile architecture, supporting different image sizes and output formats. New validations in the configuration test ensure that these additions function as expected. Modifications in the service worker compiler class aim at better usage of interfaces and performance improvements.
- Loading branch information
Showing
18 changed files
with
761 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SpomkyLabs\PwaBundle\Dto; | ||
|
||
use Symfony\Component\Serializer\Attribute\SerializedName; | ||
|
||
final class Favicons | ||
{ | ||
public bool $enabled = false; | ||
|
||
public Asset $src; | ||
|
||
#[SerializedName('background_color')] | ||
public null|string $backgroundColor = null; | ||
|
||
#[SerializedName('safari_pinned_tab_color')] | ||
public null|string $safariPinnedTabColor = null; | ||
|
||
#[SerializedName('tile_color')] | ||
public null|string $tileColor = null; | ||
|
||
/** | ||
* @var int<1, 50>|null | ||
*/ | ||
#[SerializedName('border_radius')] | ||
public null|int $borderRadius = null; | ||
|
||
/** | ||
* @var int<1, 100>|null | ||
*/ | ||
#[SerializedName('image_scale')] | ||
public null|int $imageScale = null; | ||
|
||
#[SerializedName('only_high_resolution')] | ||
public null|bool $onlyHighResolution = null; | ||
|
||
#[SerializedName('only_tile_silhouette')] | ||
public null|bool $onlyTileSilhouette = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator; | ||
|
||
return static function (DefinitionConfigurator $definition): void { | ||
$definition->rootNode() | ||
->beforeNormalization() | ||
->ifTrue( | ||
static fn (null|array $v): bool => $v !== null && isset($v['manifest']) && $v['manifest']['enabled'] === true && isset($v['favicons']) && $v['favicons']['enabled'] === true && isset($v['manifest']['theme_color']) | ||
) | ||
->then(static function (array $v): array { | ||
$v['favicons']['background_color'] = $v['manifest']['theme_color']; | ||
return $v; | ||
}) | ||
->end() | ||
->children() | ||
->arrayNode('favicons') | ||
->canBeEnabled() | ||
->children() | ||
->scalarNode('src') | ||
->isRequired() | ||
->info('The source of the favicon. Shall be a SVG or large PNG.') | ||
->end() | ||
->scalarNode('background_color') | ||
->defaultNull() | ||
->info( | ||
'The background color of the application. If this value is not defined and that of the Manifest section is, the value of the latter will be used.' | ||
) | ||
->example(['red', '#f5ef06']) | ||
->end() | ||
->scalarNode('safari_pinned_tab_color') | ||
->defaultNull() | ||
->info('The color of the Safari pinned tab.') | ||
->example(['red', '#f5ef06']) | ||
->end() | ||
->scalarNode('tile_color') | ||
->defaultNull() | ||
->info('The color of the tile for Windows 8+.') | ||
->example(['red', '#f5ef06']) | ||
->end() | ||
->integerNode('border_radius') | ||
->defaultNull() | ||
->min(1) | ||
->max(50) | ||
->info('The border radius of the icon.') | ||
->end() | ||
->integerNode('image_scale') | ||
->defaultNull() | ||
->min(1) | ||
->max(100) | ||
->info('The scale of the icon.') | ||
->end() | ||
->booleanNode('generate_precomposed') | ||
->defaultFalse() | ||
->info('Generate precomposed icons. Useful for old iOS devices.') | ||
->end() | ||
->booleanNode('only_high_resolution') | ||
->defaultTrue() | ||
->info('Only high resolution icons.') | ||
->end() | ||
->booleanNode('only_tile_silhouette') | ||
->defaultTrue() | ||
->info('Only tile silhouette for Windows 8+.') | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SpomkyLabs\PwaBundle\Service; | ||
|
||
use SpomkyLabs\PwaBundle\Dto\Favicons; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
use function assert; | ||
|
||
final class FaviconsBuilder | ||
{ | ||
private null|Favicons $favicons = null; | ||
|
||
/** | ||
* @param array<string, mixed> $config | ||
*/ | ||
public function __construct( | ||
private readonly DenormalizerInterface $denormalizer, | ||
private readonly array $config, | ||
) { | ||
} | ||
|
||
public function create(): Favicons | ||
{ | ||
if ($this->favicons === null) { | ||
$result = $this->denormalizer->denormalize($this->config, Favicons::class); | ||
assert($result instanceof Favicons); | ||
$this->favicons = $result; | ||
} | ||
|
||
return $this->favicons; | ||
} | ||
} |
Oops, something went wrong.