# elementor/4.3.3/modules/mcp/abilities/appliers/v3/serializer/block-renderer.php

Elementor Website Builder – more than just a page builder, version 4.3.3. 77 lines.

- Page: https://pluginprobe.com/plugins/elementor/4.3.3/code/modules/mcp/abilities/appliers/v3/serializer/block-renderer.php
- Raw: https://pluginprobe.com/plugins/elementor/4.3.3/raw/modules/mcp/abilities/appliers/v3/serializer/block-renderer.php
- Modified: 2026-09-01T11:47:36+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/elementor/4.3.3/code/modules/mcp/abilities/appliers/v3/serializer/block-renderer.php#L10-L20`.

```php
<?php

namespace Elementor\Modules\Mcp\Abilities\Appliers\V3\Serializer;

use Elementor\Modules\Mcp\Abilities\Appliers\V3\Mapper\Responsive_Key_Resolver;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Renders a {@see V3_Block_Accumulator} back into a CSS string that
 * {@see \Elementor\Modules\Mcp\Abilities\Appliers\V3\V3_Style_Mapper} can consume.
 *
 * Layout: base declarations, then `&:hover|focus|active { ... }`, then
 * `@media(--breakpoint) { ... }` blocks with the same nesting inside.
 */
class Block_Renderer {

	public function render( V3_Block_Accumulator $blocks ): string {
		$grouped = $blocks->all();
		$parts = [];

		$default = $grouped[ Responsive_Key_Resolver::BASE_BREAKPOINT ] ?? [];
		unset( $grouped[ Responsive_Key_Resolver::BASE_BREAKPOINT ] );

		$rendered_default = $this->render_state_group( $default );
		if ( '' !== $rendered_default ) {
			$parts[] = $rendered_default;
		}

		foreach ( $grouped as $breakpoint => $state_group ) {
			$rendered = $this->render_state_group( $state_group );
			if ( '' === $rendered ) {
				continue;
			}
			$parts[] = sprintf( '@media(--%s) { %s }', $breakpoint, $rendered );
		}

		return implode( ' ', $parts );
	}

	/**
	 * @param array<string, array<string, string>> $state_group
	 */
	private function render_state_group( array $state_group ): string {
		$parts = [];

		$base = $state_group[''] ?? [];
		unset( $state_group[''] );
		if ( ! empty( $base ) ) {
			$parts[] = $this->render_declarations( $base );
		}

		foreach ( $state_group as $state => $declarations ) {
			if ( empty( $declarations ) ) {
				continue;
			}
			$parts[] = sprintf( '&:%s { %s }', $state, $this->render_declarations( $declarations ) );
		}

		return implode( ' ', $parts );
	}

	/**
	 * @param array<string, string> $declarations
	 */
	private function render_declarations( array $declarations ): string {
		$parts = [];
		foreach ( $declarations as $property => $value ) {
			$parts[] = sprintf( '%s: %s;', $property, $value );
		}

		return implode( ' ', $parts );
	}
}

```
