Add the Material 3 Expressive foundation
tests / lint (push) Successful in 1m0s
tests / feature (8.4) (push) Successful in 1m0s
tests / feature (8.5) (push) Successful in 1m1s
tests / browser (safari, webkit) (push) Successful in 1m59s
tests / browser (chrome, chromium) (push) Successful in 1m49s
tests / browser (firefox, firefox) (push) Successful in 1m54s
tests / lint (push) Successful in 1m0s
tests / feature (8.4) (push) Successful in 1m0s
tests / feature (8.5) (push) Successful in 1m1s
tests / browser (safari, webkit) (push) Successful in 1m59s
tests / browser (chrome, chromium) (push) Successful in 1m49s
tests / browser (firefox, firefox) (push) Successful in 1m54s
Colour, shape, type, elevation and motion as tokens and Tailwind utilities; `php artisan material:scheme`, which generates an app's colour roles with Google's material-color-utilities (spec 2025); the theme head script with light, dark and system and its Alpine store; Google Sans Flex; every Material Symbol (4,135, outlined and filled) drawn by <x-icon> without blade-icons; all 35 M3 Expressive shapes, ported from androidx, as <x-shape>; the x-figure directive; the Toasts concern; DesignGuard for applications' tests; and a showcase with every token, both themes side by side and an icon search. Colour utilities are `@theme inline`, so a section with its own data-theme repaints; without it they resolve once on :root. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V9NnLxnPp8vaaurb3Z1MFy
This commit is contained in:
co-authored by
Claude Opus 5
parent
9b53891a8e
commit
b48e879254
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace NoNameWeb\LivewireMaterial\Support;
|
||||
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Inline SVGs from the package's own folders: Material Symbols and M3 Expressive shapes.
|
||||
*
|
||||
* Not blade-icons: its view-factory hook registers one Blade component per icon on every
|
||||
* request, which for the ~8,000 symbol files here would be ~8,000 registrations each time.
|
||||
* A file is read the first time it is drawn and kept for the life of the worker; the
|
||||
* contents never change while the application runs, so nothing request-specific is held.
|
||||
*/
|
||||
class SvgFile
|
||||
{
|
||||
/** @var array<string, string> */
|
||||
protected static array $contents = [];
|
||||
|
||||
public static function symbol(string $name, bool $filled, ComponentAttributeBag $attributes): HtmlString
|
||||
{
|
||||
if (preg_match('/^[a-z0-9_]+$/', $name) !== 1) {
|
||||
throw new InvalidArgumentException("[{$name}] is not a Material Symbol name. Symbols are named in lowercase with underscores, as on fonts.google.com/icons: `calendar_month`, `arrow_back`.");
|
||||
}
|
||||
|
||||
$path = static::directory('svg/symbols/'.($filled ? 'filled' : 'outlined'))."/{$name}.svg";
|
||||
|
||||
if (! is_file($path)) {
|
||||
throw new InvalidArgumentException("There is no Material Symbol named [{$name}].");
|
||||
}
|
||||
|
||||
return static::render($path, $attributes);
|
||||
}
|
||||
|
||||
public static function shape(string $name, ComponentAttributeBag $attributes): HtmlString
|
||||
{
|
||||
$path = static::directory('svg/shapes')."/{$name}.svg";
|
||||
|
||||
if (preg_match('/^[a-z0-9-]+$/', $name) !== 1 || ! is_file($path)) {
|
||||
throw new InvalidArgumentException("There is no M3 Expressive shape named [{$name}].");
|
||||
}
|
||||
|
||||
return static::render($path, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* The names of every Material Symbol the package ships.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function symbolNames(): array
|
||||
{
|
||||
return array_map(
|
||||
fn (string $file): string => basename($file, '.svg'),
|
||||
glob(static::directory('svg/symbols/outlined').'/*.svg') ?: [],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The names of every shape the package ships.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function shapeNames(): array
|
||||
{
|
||||
return array_map(
|
||||
fn (string $file): string => basename($file, '.svg'),
|
||||
glob(static::directory('svg/shapes').'/*.svg') ?: [],
|
||||
);
|
||||
}
|
||||
|
||||
protected static function render(string $path, ComponentAttributeBag $attributes): HtmlString
|
||||
{
|
||||
$svg = static::$contents[$path] ??= trim((string) file_get_contents($path));
|
||||
|
||||
return new HtmlString(preg_replace('/^<svg\b/', '<svg '.$attributes->toHtml(), $svg, 1));
|
||||
}
|
||||
|
||||
protected static function directory(string $path): string
|
||||
{
|
||||
return dirname(__DIR__, 2).'/resources/'.$path;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user