← All changes
|
modules/atomic-widgets/styles/atomic-styles-manager.php
+19
-12
4.1.3
→
4.3.1
View file →
| @@ -31,10 +31,10 @@ | ||
| 31 | 31 | |
| 32 | 32 | private array $fonts = []; |
| 33 | 33 | |
| 34 | 34 | public function __construct() { |
| 35 | - $this->css_files_manager = new CSS_Files_Manager(); | |
| 36 | 35 | $this->cache_validity = new Cache_Validity(); |
| 36 | + $this->css_files_manager = new CSS_Files_Manager( $this->cache_validity ); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public static function instance() { |
| 40 | 40 | if ( ! self::$instance ) { |
| @@ -124,17 +124,19 @@ | ||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $breakpoint_path = array_merge( $path, [ $breakpoint_key ] ); |
| 127 | 127 | |
| 128 | + // `CSS_Files_Manager::get()` owns the per-breakpoint decision: it consults the | |
| 129 | + // cache-validity leaf under `$breakpoint_path` (including the `should_exist` | |
| 130 | + // meta), regenerates when the cache is invalid or when a should-be-present file | |
| 131 | + // is missing on disk, and validates the leaf on success. See ED-24903. | |
| 128 | 132 | $style_file = $this->css_files_manager->get( |
| 129 | 133 | $this->convert_path_to_handle( $breakpoint_path ), |
| 130 | 134 | $breakpoint_media, |
| 131 | 135 | $render_css, |
| 132 | - $this->cache_validity->is_valid( $breakpoint_path ) | |
| 136 | + $breakpoint_path | |
| 133 | 137 | ); |
| 134 | 138 | |
| 135 | - $this->cache_validity->validate( $breakpoint_path ); | |
| 136 | - | |
| 137 | 139 | if ( ! $style_file ) { |
| 138 | 140 | continue; |
| 139 | 141 | } |
| 140 | 142 | |
| @@ -153,15 +155,10 @@ | ||
| 153 | 155 | $style_fonts = Style_Fonts::make( $style_key ); |
| 154 | 156 | |
| 155 | 157 | return Styles_Renderer::make( |
| 156 | 158 | Plugin::$instance->breakpoints->get_breakpoints_config() |
| 157 | - )->on_prop_transform( function( $key, $value ) use ( $style_fonts ) { | |
| 158 | - if ( 'font-family' !== $key ) { | |
| 159 | - return; | |
| 160 | - } | |
| 161 | - | |
| 162 | - $style_fonts->add( $value ); | |
| 163 | - } )->render( $styles ); | |
| 159 | + )->on_font_enqueue( fn( $font ) => $style_fonts->add( $font ) ) | |
| 160 | + ->render( $styles ); | |
| 164 | 161 | } |
| 165 | 162 | |
| 166 | 163 | private function get_breakpoint_media( string $breakpoint_key ): ?string { |
| 167 | 164 | $breakpoint_config = Plugin::$instance->breakpoints->get_breakpoints_config()[ $breakpoint_key ] ?? null; |
| @@ -181,14 +178,24 @@ | ||
| 181 | 178 | return Collection::make( $styles )->reduce( function( $group, $style ) { |
| 182 | 179 | Collection::make( $style['variants'] )->each( function( $variant ) use ( &$group, $style ) { |
| 183 | 180 | $breakpoint = $variant['meta']['breakpoint'] ?? self::DEFAULT_BREAKPOINT; |
| 184 | 181 | |
| 182 | + if ( empty( $breakpoint ) ) { | |
| 183 | + $breakpoint = self::DEFAULT_BREAKPOINT; | |
| 184 | + } | |
| 185 | + | |
| 185 | 186 | if ( ! isset( $group[ $breakpoint ][ $style['id'] ] ) ) { |
| 186 | - $group[ $breakpoint ][ $style['id'] ] = [ | |
| 187 | + $style_for_breakpoint = [ | |
| 187 | 188 | 'id' => $style['id'], |
| 188 | 189 | 'type' => $style['type'], |
| 189 | 190 | 'variants' => [], |
| 190 | 191 | ]; |
| 192 | + | |
| 193 | + if ( isset( $style['cssName'] ) ) { | |
| 194 | + $style_for_breakpoint['cssName'] = $style['cssName']; | |
| 195 | + } | |
| 196 | + | |
| 197 | + $group[ $breakpoint ][ $style['id'] ] = $style_for_breakpoint; | |
| 191 | 198 | } |
| 192 | 199 | |
| 193 | 200 | $group[ $breakpoint ][ $style['id'] ]['variants'][] = $variant; |
| 194 | 201 | } ); |