$values Custom properties. */ private static function declarations( array $values ): string { $css = ''; foreach ( $values as $property => $value ) { if ( is_string( $value ) && ! preg_match( '/[;{}<>\\\\\x00-\x1f]|url\s*\(|expression\s*\(|\/\*/i', $value ) ) { $css .= $property . ':' . self::preset( $value ) . ';'; } } return $css; } /** * Explicit block supports override theme defaults on this element only. * * @param array $attrs Block attributes. */ public static function block_style( array $attrs ): string { $style = is_array( $attrs['style'] ?? null ) ? $attrs['style'] : array(); $values = array(); $maps = array( 'color' => array( 'text' => '--showfm-text', 'background' => '--showfm-background', ), 'typography' => array( 'fontFamily' => '--showfm-font', 'fontSize' => '--showfm-font-size', 'lineHeight' => '--showfm-line-height', ), ); foreach ( $maps as $group => $properties ) { foreach ( $properties as $key => $variable ) { $values[ $variable ] = $style[ $group ][ $key ] ?? null; } } foreach ( array( 'textColor' => array( '--showfm-text', 'color' ), 'backgroundColor' => array( '--showfm-background', 'color' ), 'fontFamily' => array( '--showfm-font', 'font-family' ), 'fontSize' => array( '--showfm-font-size', 'font-size' ), ) as $key => $mapping ) { if ( isset( $attrs[ $key ] ) && is_string( $attrs[ $key ] ) && preg_match( '/^[a-zA-Z0-9-]+\z/', $attrs[ $key ] ) ) { $values[ $mapping[0] ] = 'var(--wp--preset--' . $mapping[1] . '--' . $attrs[ $key ] . ')'; } } if ( ! empty( $attrs['accent'] ) && is_string( $attrs['accent'] ) ) { $values['--showfm-accent'] = ( preg_match( '/\A#(?:[a-f0-9]{3}|[a-f0-9]{6})\z/i', $attrs['accent'] ) ? $attrs['accent'] : null ); } elseif ( isset( $values['--showfm-text'] ) ) { $values['--showfm-accent'] = $values['--showfm-text']; } foreach ( array( 'padding', 'margin' ) as $property ) { $spacing = $style['spacing'][ $property ] ?? null; if ( is_array( $spacing ) ) { foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) { $values[ '--showfm-' . $property . '-' . $side ] = $spacing[ $side ] ?? null; } } else { $values[ '--showfm-' . $property ] = $spacing; } } return self::declarations( $values ); } }