Features -> Position -> Render block * */ if ( ! defined( 'ABSPATH' ) ) exit; function tbkkt_position_get_render_payload( string $block_name, array $attrs ): array { if ( ! tbkkt_supported_blocks_has_feature( $block_name, TBKKT_FEATURE_POSITION ) ) return array(); $classes = array(); $styles = array(); $allowed_position = array( 'absolute', 'fixed', 'relative', 'static', 'sticky', ); $allowed_overflow = array( 'auto', 'clip', 'hidden', 'scroll', 'visible', ); $overflow_mode = isset( $attrs['tbkktOverflowMode'] ) && (string) $attrs['tbkktOverflowMode'] === 'axes' ? 'axes' : 'general'; if ( $overflow_mode === 'axes' ) : $ox = tbkkt_block_markup_sanitize_class_slug( (string) ( $attrs['tbkktOverflowX'] ?? '' ) ); $oy = tbkkt_block_markup_sanitize_class_slug( (string) ( $attrs['tbkktOverflowY'] ?? '' ) ); if ( in_array( $ox, $allowed_overflow, true ) ) : $classes[] = 'tbkkt-overflow-x-' . $ox; endif; if ( in_array( $oy, $allowed_overflow, true ) ) : $classes[] = 'tbkkt-overflow-y-' . $oy; endif; else : $overflow = tbkkt_block_markup_sanitize_class_slug( (string) ( $attrs['tbkktOverflow'] ?? '' ) ); if ( in_array( $overflow, $allowed_overflow, true ) ) : $classes[] = 'tbkkt-overflow-' . $overflow; endif; endif; $offset_limit = 2000; $z_index_limit = 10000; $responsive_config = array( 'desktop' => array( 'position_key' => 'tbkktPosition', 'z_key' => 'tbkktZIndex', 'offset_keys' => array( 'top' => 'tbkktOffsetTop', 'right' => 'tbkktOffsetRight', 'bottom' => 'tbkktOffsetBottom', 'left' => 'tbkktOffsetLeft', ), 'unit_keys' => array( 'top' => 'tbkktOffsetTopUnit', 'right' => 'tbkktOffsetRightUnit', 'bottom' => 'tbkktOffsetBottomUnit', 'left' => 'tbkktOffsetLeftUnit', ), 'class_suffix' => '', 'var_suffix' => '', ), 'tablet' => array( 'position_key' => 'tbkktPositionTablet', 'z_key' => 'tbkktZIndexTablet', 'offset_keys' => array( 'top' => 'tbkktOffsetTopTablet', 'right' => 'tbkktOffsetRightTablet', 'bottom' => 'tbkktOffsetBottomTablet', 'left' => 'tbkktOffsetLeftTablet', ), 'unit_keys' => array( 'top' => 'tbkktOffsetTopUnitTablet', 'right' => 'tbkktOffsetRightUnitTablet', 'bottom' => 'tbkktOffsetBottomUnitTablet', 'left' => 'tbkktOffsetLeftUnitTablet', ), 'class_suffix' => '-tablet', 'var_suffix' => '--tablet', ), 'mobile' => array( 'position_key' => 'tbkktPositionMobile', 'z_key' => 'tbkktZIndexMobile', 'offset_keys' => array( 'top' => 'tbkktOffsetTopMobile', 'right' => 'tbkktOffsetRightMobile', 'bottom' => 'tbkktOffsetBottomMobile', 'left' => 'tbkktOffsetLeftMobile', ), 'unit_keys' => array( 'top' => 'tbkktOffsetTopUnitMobile', 'right' => 'tbkktOffsetRightUnitMobile', 'bottom' => 'tbkktOffsetBottomUnitMobile', 'left' => 'tbkktOffsetLeftUnitMobile', ), 'class_suffix' => '-mobile', 'var_suffix' => '--mobile', ), ); $has_any_z_index = false; $has_any_inset = false; foreach ( $responsive_config as $device_config ) : $class_suffix = (string) $device_config['class_suffix']; $var_suffix = (string) $device_config['var_suffix']; $position = tbkkt_block_markup_sanitize_class_slug( (string) ( $attrs[ $device_config['position_key'] ] ?? '' ) ); if ( in_array( $position, $allowed_position, true ) ) : $classes[] = 'tbkkt-position-' . $position . $class_suffix; endif; $z_index = tbkkt_style_value_clamp_int( $attrs[ $device_config['z_key'] ] ?? null, -$z_index_limit, $z_index_limit ); if ( $z_index !== null ) : $styles[] = '--tbkkt--position--z-index' . $var_suffix . ':' . $z_index . ';'; $classes[] = 'tbkkt-has-z-index' . $class_suffix; $has_any_z_index = true; endif; $has_inset = false; foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) : $offset = tbkkt_style_value_clamp_int( $attrs[ $device_config['offset_keys'][ $side ] ] ?? null, -$offset_limit, $offset_limit ); if ( $offset === null ) : continue; endif; $unit = tbkkt_style_value_sanitize_unit( (string) ( $attrs[ $device_config['unit_keys'][ $side ] ] ?? 'px' ) ); $token = tbkkt_style_value_format_length( (float) $offset, $unit ); if ( $token === '' ) : continue; endif; $styles[] = '--tbkkt--position--' . $side . $var_suffix . ':' . $token . ';'; $has_inset = true; endforeach; if ( $has_inset ) : $classes[] = 'tbkkt-has-inset' . $class_suffix; $has_any_inset = true; endif; endforeach; if ( $has_any_z_index && ! in_array( 'tbkkt-has-z-index', $classes, true ) ) : $classes[] = 'tbkkt-has-z-index'; endif; if ( $has_any_inset && ! in_array( 'tbkkt-has-inset', $classes, true ) ) : $classes[] = 'tbkkt-has-inset'; endif; $out_attrs = array(); if ( ! empty( $styles ) ) : $out_attrs['style'] = implode( '', $styles ); endif; return ( ! empty( $classes ) || ! empty( $out_attrs ) ) ? array( 'classes' => $classes, 'attrs' => $out_attrs, ) : array(); }