Add @fonts Blade directive and Vite font optimization runtime (#59584)
* Add @fonts Blade directive and Vite::fonts() runtime Consume the font manifest written by the Vite plugin to render preload links and inline font CSS. The directive and facade method support optional family filtering, CSP nonces, preload attribute customization, and both build and hot mode. ViteFonts handles manifest reading and validation while Vite owns rendering and preload recording, keeping the public API surface narrow. * Fix font optimization contract and API consistency - Filter preloads by requested families before validation so a malformed entry for an unrequested family does not throw - Filter CSS variables block alongside familyStyles so filtered output only emits variables for the requested families - Pass 'fonts' instead of null to preload attribute resolvers for consistent callback shape with existing Vite preloads - Remove unused public buildDirectory() getter and facade annotation to keep the API surface minimal * Add stricter PHPStan array types to font optimization docblocks * Add tests for font utility class rendering through ViteFonts pipeline Verifies that .font-* CSS utility classes generated by the Vite plugin flow through the framework's familyStyles rendering in build mode, hot mode, filtered-by-family, and with custom variable names. * Update font runtime to use alias-based manifest keys Align Vite::fonts() and ViteFonts with the vite-plugin's new alias-keyed manifest structure. Preloads and family entries are now filtered by alias instead of family name, and validation messages reference aliases accordingly. * Apply fixes from StyleCI * Parse font CSS variables structurally instead of line-by-line The previous filterVariables() implementation split on newlines and matched variables by string containment, coupling it to the plugin's multiline formatting. If the :root block were emitted on a single line or minified, filtering would leak unrelated variables. Now parses the :root block with regex to extract declarations regardless of whitespace, making it resilient to formatting changes. * Apply fixes from StyleCI * Address code review follow-ups on font optimization runtime * Simplify fonts() alias gate and type ViteFonts parameters * fix facade param name * remove dead null check * use null coalesce * Render readable font HTML and harden manifest style contract - Render each preload link on its own line, wrap the inline style tag on newlines, and separate the preload block from the style block so the rendered font HTML stays readable. - Throw a descriptive ViteException when style.familyStyles or style.variables is not an alias-keyed array, replacing the cryptic TypeError users hit when a newer framework reads an older plugin's manifest. - Update existing rendering assertions to the new format and add regression tests for the readable layout and the contract error. * formatting * fix method --------- Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Joe Tannenbaum <joe.tannenbaum@laravel.com> Co-authored-by: Taylor Otwell <taylor@laravel.com>
W
Wendell Adriel committed
ca0263c7c5c753b4468628ecb656ceb5f6c610af
Parent: 92cf2de
Committed by GitHub <noreply@github.com>
on 4/28/2026, 11:51:23 AM