'', 'tablet' => '', 'mobile' => '', ); foreach ( $variables as $device => $data ) { $css = implode( ';', $data ); if ( ! empty( $css ) ) { $device_css[ $device ] .= $selector . '{' . $css . '}'; } } $result = ''; foreach ( $device_css as $device => $css ) { if ( ! in_array( $device, brandy_get_devices(), true ) ) { continue; } if ( 'tablet' === $device ) { $css = DynamicCss::wrap_tablet_responsive( $css ); } if ( 'mobile' === $device ) { $css = DynamicCss::wrap_mobile_responsive( $css ); } $result .= $css; } return $result; } /** * Generates CSS properties for different directions based on the given name and spacing values. * * @param string $name The name to be used as a prefix for the CSS properties. * @param array $spacing An associative array containing spacing values for each direction (top, right, bottom, left). * @return array An associative array containing CSS properties for each direction. */ public static function get_directions_spacing_css_variables( $name, $spacing ) { if ( ! self::is_spacing_data( $spacing ) ) { return array(); } $directions = array( 'top', 'right', 'bottom', 'left' ); $result = array(); foreach ( $directions as $direction ) { if ( 'wp' === $spacing['unit'] ) { $result[] = "$name-$direction:" . $spacing[ $direction ]; } else { $result[] = "$name-$direction:" . $spacing[ $direction ] . $spacing['unit']; } } return $result; } /** * Generates CSS properties for different directions based on the given name and spacing values. * * @param string $name The name to be used as a prefix for the CSS properties. * @param array $spacing An associative array containing spacing values for each direction (top, right, bottom, left). * @return array An associative array containing CSS properties for each direction. */ public static function get_directions_css_variables( $name, $css_value ) { $directions = array( 'top', 'right', 'bottom', 'left' ); $result = array(); foreach ( $directions as $direction ) { $result[] = "$name-$direction:$css_value"; } return $result; } public static function get_css_variable( $name, $value ) { if ( empty( $value ) ) { return ''; } // if ( is_rtl() ) { // if ( 'right' === $value ) { // $value = 'left'; // } // if ( 'left' === $value ) { // $value = 'right'; // } // } if ( is_array( $value ) ) { return ''; } if ( is_array( $name ) ) { return ''; } return "$name:$value"; } public static function get_spacing_css_variable( $name, $data ) { return self::get_css_variable( $name, self::get_spacing_css( $data ) ); } public static function get_dimension_css_variable( $name, $data ) { return self::get_css_variable( $name, self::get_dimension_css( $data ) ); } public static function get_box_shadow_css_variable( $name, $data ) { return self::get_css_variable( $name, self::get_box_shadow_css( $data ) ); } public static function get_typography_css_variables( $data, $selector = '' ) { $result = array( 'desktop' => array(), 'tablet' => array(), 'mobile' => array(), ); if ( empty( $data ) ) { $data = array(); } foreach ( $data as $typo_type => $typo_value ) { if ( is_null( $typo_value ) ) { continue; } foreach ( $typo_value as $device => $variable_value ) { if ( ! in_array( $device, brandy_get_devices(), true ) ) { continue; } $variable_value = Helpers::get_device_value( $typo_value, $device ); if ( is_null( $variable_value ) ) { continue; } if ( 'font_style' === $typo_type ) { if ( ! empty( $selector ) ) { if ( ! isset( $result[ $device ][ $selector ] ) ) { $result[ $device ][ $selector ] = array(); } $result[ $device ][ $selector ][] = self::get_css_variable( 'font-weight', $variable_value['weight'] ); $result[ $device ][ $selector ][] = self::get_css_variable( 'font-style', $variable_value['italic'] ? 'italic' : 'normal' ); } else { $result[ $device ][] = self::get_css_variable( 'font-weight', $variable_value['weight'] ); $result[ $device ][] = self::get_css_variable( 'font-style', $variable_value['italic'] ? 'italic' : 'normal' ); } continue; } if ( in_array( $typo_type, array( 'font_size', 'line_height', 'letter_spacing' ), true ) ) { $dimension_css = self::get_dimension_css( $variable_value ); if ( empty( $variable_value['value'] ) ) { $dimension_css = 'inherit'; } if ( empty( $dimension_css ) ) { $dimension_css = 'inherit'; } if ( ! empty( $selector ) ) { if ( ! isset( $result[ $device ][ $selector ] ) ) { $result[ $device ][ $selector ] = array(); } $result[ $device ][ $selector ][] = self::get_css_variable( str_replace( '_', '-', $typo_type ), $dimension_css ); } else { $result[ $device ][] = self::get_css_variable( str_replace( '_', '-', $typo_type ), $dimension_css ); } continue; } if ( 'transform' === $typo_type ) { $typo_type = 'text-transform'; } if ( 'decoration' === $typo_type ) { $typo_type = 'text-decoration'; } if ( ! empty( $selector ) ) { if ( ! isset( $result[ $device ][ $selector ] ) ) { $result[ $device ][ $selector ] = array(); } $result[ $device ][ $selector ][] = self::get_css_variable( str_replace( '_', '-', $typo_type ), $variable_value ); } else { $result[ $device ][] = self::get_css_variable( str_replace( '_', '-', $typo_type ), $variable_value ); } } } return $result; } }