PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.0-dev3
Elementor Website Builder – more than just a page builder v3.32.0-dev3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | modules/atomic-widgets/styles/styles-renderer.php +14 -47 4.2.23.32.0-dev3 View file →
@@ -3,14 +3,11 @@
3 3 namespace Elementor\Modules\AtomicWidgets\Styles;
4 4
5 5 use Elementor\Core\Utils\Collection;
6 6 use Elementor\Modules\AtomicWidgets\Module;
7 -use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Font_Enqueueable;
8 -use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type;
9 -use Elementor\Modules\AtomicWidgets\PropTypes\Union_Prop_Type;
10 -use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver;
11 7 use Elementor\Plugin;
12 8 use Elementor\Utils;
9 +use Elementor\Modules\AtomicWidgets\PropsResolver\Render_Props_Resolver;
13 10
14 11 class Styles_Renderer {
15 12 const DEFAULT_SELECTOR_PREFIX = '.elementor';
16 13
@@ -18,15 +15,15 @@
18 15 * @var array<string, array{direction: 'min' | 'max', value: int, is_enabled: boolean}>
19 16 */
20 17 private array $breakpoints;
21 18
22 - private $on_font_enqueue;
19 + private $on_prop_transform;
23 20
24 21 private string $selector_prefix;
25 22
26 23 /**
27 24 * @param array<string, array{direction: 'min' | 'max', value: int, is_enabled: boolean}> $breakpoints
28 - * @param string $selector_prefix
25 + * @param string $selector_prefix
29 26 */
30 27 private function __construct( array $breakpoints, string $selector_prefix = self::DEFAULT_SELECTOR_PREFIX ) {
31 28 $this->breakpoints = $breakpoints;
32 29 $this->selector_prefix = $selector_prefix;
@@ -64,10 +61,10 @@
64 61
65 62 return implode( '', $css_style );
66 63 }
67 64
68 - public function on_font_enqueue( callable $callback ): self {
69 - $this->on_font_enqueue = $callback;
65 + public function on_prop_transform( callable $callback ): self {
66 + $this->on_prop_transform = $callback;
70 67
71 68 return $this;
72 69 }
73 70
@@ -123,13 +120,10 @@
123 120 if ( ! $css && ! $custom_css ) {
124 121 return '';
125 122 }
126 123
127 - if ( isset( $variant['meta']['state'] ) ) {
128 - $selector = Style_States::get_selector_with_state( $base_selector, $variant['meta']['state'] );
129 - } else {
130 - $selector = $base_selector;
131 - }
124 + $state = isset( $variant['meta']['state'] ) ? ':' . $variant['meta']['state'] : '';
125 + $selector = $base_selector . $state;
132 126
133 127 $style_declaration = $selector . '{' . $css . $custom_css . '}';
134 128
135 129 if ( isset( $variant['meta']['breakpoint'] ) ) {
@@ -138,16 +132,17 @@
138 132
139 133 return $style_declaration;
140 134 }
141 135
142 -
143 136 private function props_to_css_string( array $props ): string {
144 137 $schema = Style_Schema::get();
145 138
146 139 return Collection::make( Render_Props_Resolver::for_styles()->resolve( $schema, $props ) )
147 140 ->filter()
148 - ->map( function ( $value, $prop ) use ( $props, $schema ) {
149 - $this->maybe_enqueue_font( $schema, $prop, $props[ $prop ] ?? null );
141 + ->map( function ( $value, $prop ) {
142 + if ( $this->on_prop_transform ) {
143 + call_user_func( $this->on_prop_transform, $prop, $value );
144 + }
150 145
151 146 return $prop . ':' . $value . ';';
152 147 } )
153 148 ->implode( '' );
@@ -152,40 +147,12 @@
152 147 } )
153 148 ->implode( '' );
154 149 }
155 150
156 - private function maybe_enqueue_font( array $schema, string $prop_key, $prop_value ): void {
157 - if ( ! $this->on_font_enqueue || ! is_array( $prop_value ) || empty( $prop_value['value'] ) ) {
158 - return;
159 - }
151 + private function custom_css_to_css_string( ?array $custom_css ): string {
152 + $is_feature_active = Plugin::$instance->experiments->is_feature_active( Module::EXPERIMENT_CUSTOM_CSS );
160 153
161 - $enqueueable = $this->resolve_font_enqueueable( $schema[ $prop_key ] ?? null, $prop_value );
162 -
163 - if ( ! $enqueueable ) {
164 - return;
165 - }
166 -
167 - $font = $enqueueable->get_enqueue_font_family( $prop_value['value'] );
168 -
169 - if ( $font ) {
170 - call_user_func( $this->on_font_enqueue, $font );
171 - }
172 - }
173 -
174 - private function resolve_font_enqueueable( ?Prop_Type $prop_type, array $prop_value ): ?Font_Enqueueable {
175 - if ( $prop_type instanceof Union_Prop_Type ) {
176 - $prop_type = $prop_type->get_prop_type( $prop_value['$$type'] ?? '' );
177 - }
178 -
179 - if ( $prop_type instanceof Font_Enqueueable ) {
180 - return $prop_type;
181 - }
182 -
183 - return null;
184 - }
185 -
186 - private function custom_css_to_css_string( ?array $custom_css ): string {
187 - return ! empty( $custom_css['raw'] )
154 + return $is_feature_active && ! empty( $custom_css['raw'] )
188 155 ? Utils::decode_string( $custom_css['raw'], '' ) . '\n'
189 156 : '';
190 157 }
191 158