declarations. * @return string CSS, or ''. */ public static function rules( $styles, $base, $emit ) { if ( ! is_array( $styles ) || ! StyleBuckets::has_schema_version( $styles ) ) { return ''; } $css = ''; foreach ( array_values( Helper::get_responsive_devices() ) as $device ) { $media = Helper::breakpoint_media_query( $device ); $bucket_key = StyleBuckets::device_bucket_key( $device ); foreach ( StyleBuckets::state_keys() as $state ) { $props = StyleBuckets::read_bucket( $styles, $bucket_key, $state ); if ( empty( $props ) ) { continue; } $body = ''; foreach ( (array) call_user_func( $emit, $props, $state ) as $suffix => $declarations ) { if ( '' !== $declarations ) { $body .= $base . $state . $suffix . '{' . $declarations . '}'; } } if ( '' !== $body ) { $css .= ( '' !== $media ) ? $media . '{' . $body . '}' : $body; } } } return $css; } /** * A Range value ({ value, valueUnit }) as an escaped CSS length, or ''. * * @param mixed $value The stored value. * @param string $unit Fallback unit. * @return string */ public static function range( $value, $unit = 'px' ) { if ( is_array( $value ) ) { if ( ! isset( $value['value'] ) || '' === $value['value'] || null === $value['value'] ) { return ''; } $unit = ! empty( $value['valueUnit'] ) ? $value['valueUnit'] : $unit; return Helper::esc_css_value( $value['value'] . $unit ); } return is_scalar( $value ) && '' !== (string) $value ? Helper::esc_css_value( (string) $value ) : ''; } /** * A scalar prop, escaped, or ''. * * @param array $props Bucket props. * @param string $key Prop key. * @return string */ public static function scalar( $props, $key ) { if ( ! isset( $props[ $key ] ) || ! is_scalar( $props[ $key ] ) || '' === (string) $props[ $key ] ) { return ''; } return Helper::esc_css_value( (string) $props[ $key ] ); } /** * Horizontal placement of a block-level box narrower than its parent. * Mirrors alignCss() in block-props.js. * * @param string $align left | center | right | justify. * @return string */ public static function align_css( $align ) { switch ( $align ) { case 'left': return 'margin-left:0;margin-right:auto;'; case 'center': return 'margin-left:auto;margin-right:auto;'; case 'right': return 'margin-left:auto;margin-right:0;'; case 'justify': return 'width:100%;max-width:100%;'; default: return ''; } } }