Components -> Appearance * */ if ( ! defined( 'ABSPATH' ) ) exit; if ( ! function_exists( 'tbkkt_appearance_clamp_rotation_deg' ) ) : function tbkkt_appearance_clamp_rotation_deg( $deg ): int { if ( ! is_numeric( $deg ) ) return 0; $n = (int) round( (float) $deg ); $n = $n % 360; if ( $n < 0 ) $n += 360; return $n; } endif; if ( ! function_exists( 'tbkkt_appearance_build_style_fragment' ) ) : function tbkkt_appearance_build_style_fragment( array $opts = array() ): string { $parts = array(); if ( array_key_exists( 'size', $opts ) ) : $size_raw = trim( (string) $opts['size'] ); $size = tbkkt_style_value_sanitize_length( $size_raw ); if ( $size !== '' ) : $parts[] = '--tbkkt--appearance--size:' . $size . ';'; endif; endif; $omit_rotation = ! empty( $opts['omit_rotation'] ); if ( ! $omit_rotation && array_key_exists( 'rotation_deg', $opts ) ) : $rot = tbkkt_appearance_clamp_rotation_deg( $opts['rotation_deg'] ?? 0 ); if ( $rot !== 0 ) : $parts[] = '--tbkkt--appearance--transform:rotate(' . (int) $rot . 'deg);'; endif; endif; return implode( '', $parts ); } endif; if ( ! function_exists( 'tbkkt_appearance_merge_transform_into_graphic_markup' ) ) : function tbkkt_appearance_merge_transform_into_graphic_markup( string $html, $rotation_deg ): string { $html = trim( (string) $html ); if ( $html === '' ) return $html; $rot = tbkkt_appearance_clamp_rotation_deg( $rotation_deg ?? 0 ); if ( $rot === 0 ) return $html; $style = '--tbkkt--appearance--transform:rotate(' . (int) $rot . 'deg);'; $class = 'tbkkt-has-transform'; $merge_opening_tag = static function ( string $tag, string $rest, string $style, string $class ): string { if ( preg_match( '/\bclass\s*=\s*(["\'])(.*?)\1/s', $rest, $cm ) ) : $q = $cm[1]; $merged = trim( $cm[2] . ' ' . $class ); $rest = preg_replace( '/\bclass\s*=\s*(["\'])(.*?)\1/s', 'class=' . $q . esc_attr( $merged ) . $q, $rest, 1 ); else : $rest = ' class="' . esc_attr( $class ) . '"' . $rest; endif; if ( preg_match( '/\bstyle\s*=\s*(["\'])(.*?)\1/s', $rest, $sm ) ) : $q = $sm[1]; $merged = trim( rtrim( (string) $sm[2], ';' ) . ';' . $style ); $rest = preg_replace( '/\bstyle\s*=\s*(["\'])(.*?)\1/s', 'style=' . $q . esc_attr( $merged ) . $q, $rest, 1 ); else : $rest = $rest . ' style="' . esc_attr( $style ) . '"'; endif; return '<' . $tag . $rest . '>'; }; if ( preg_match( '/]*)?>/i', static function ( array $m ) use ( $style, $class, $merge_opening_tag, &$done ): string { if ( $done ) : return $m[0]; endif; $done = true; $rest = isset( $m[1] ) ? $m[1] : ''; return $merge_opening_tag( 'svg', $rest, $style, $class ); }, $html, 1 ); return is_string( $out ) ? $out : $html; endif; $done = false; $out = preg_replace_callback( '/]*)?>/i', static function ( array $m ) use ( $style, $class, $merge_opening_tag, &$done ): string { if ( $done ) : return $m[0]; endif; $done = true; $rest = isset( $m[1] ) ? $m[1] : ''; return $merge_opening_tag( 'img', $rest, $style, $class ); }, $html, 1 ); return is_string( $out ) ? $out : $html; } endif;