true, 'pricing' => true, 'faq' => true, 'table' => true, 'gallery' => true, 'split' => true, 'prose' => true ); const PADDING = array( 'stats' => 7, 'cta' => 8 ); const MOBILE_PADDING = array( 'cards', 'pricing', 'faq', 'table', 'gallery', 'prose', 'split', 'pattern', 'form' ); const DEFAULT_STYLE = array( 'cta' => 'contrast', 'stats' => 'subtle' ); const DEFERRABLE = array( 'cards', 'pricing', 'table', 'gallery', 'faq', 'stats' ); const FIRST_SCREEN = 3; const DEFER_HEIGHT = array( 'pricing' => '560px', 'stats' => '160px', 'faq' => '400px' ); const DISPLAY_H1 = AIEO_Content_Type::SCALE['display']; const DISPLAY_H2 = AIEO_Content_Type::SCALE['heading']; const DISPLAY_LEDE = AIEO_Content_Type::SCALE['lede-snug']; const HOME_GLOW = 'radial-gradient(60% 312px at 20% -12px,light-dark(rgb(238 106 18 / 12%),rgb(245 154 82 / 16%)),transparent 60%),radial-gradient(50% 260px at 85% 40px,light-dark(rgb(30 99 206 / 12%),rgb(106 168 255 / 14%)),transparent 60%),radial-gradient(40% 208px at 60% 352px,light-dark(rgb(63 143 26 / 10%),rgb(143 224 58 / 10%)),transparent 60%)'; private static $dark = false; const FAMILY_FIELDS = array( 'products', 'features', 'docs', 'motif', 'swatches' ); public static function render( array $s, array $media = array() ) { $kind = (string) ( $s['kind'] ?? '' ); $method = 'kind_' . $kind; if ( ! method_exists( __CLASS__, $method ) ) { return ''; } $was = self::$dark; self::$dark = self::is_dark( $s, $kind ); $markup = self::draw( $s, $media, $method ); self::$dark = $was; return $markup; } private static function draw( array $s, array $media, $method ) { if ( AIEO_Content_Layout::applies( $s ) ) { return self::finalise( AIEO_Content_Layout::render( $s + array( '_media' => $media ) ) ); } if ( AIEO_Content_Rooster_One::applies( $s ) ) { $r1 = AIEO_Content_Rooster_One::render( $s, $media ); if ( '' !== $r1 ) { return self::finalise( $r1 ); } } if ( AIEO_Content_Promo::applies( $s ) ) { $promo = AIEO_Content_Promo::render( $s, $media ); if ( '' !== $promo ) { return self::finalise( $promo ); } } return self::finalise( self::$method( $s, $media ) ); } public static function defer_default( $kind, $index ) { return (int) $index >= self::FIRST_SCREEN && in_array( (string) $kind, self::DEFERRABLE, true ); } public static function with_defer( array $s, $index ) { if ( ! array_key_exists( 'defer', $s ) ) { $s['defer'] = self::defer_default( (string) ( $s['kind'] ?? '' ), $index ); } return $s; } private static function deferred( array $s, $kind ) { return ! empty( $s['defer'] ) && in_array( $kind, self::DEFERRABLE, true ) ? (string) ( self::DEFER_HEIGHT[ $kind ] ?? '320px' ) : ''; } private static function muted( $on_dark = false ) { return self::$dark || $on_dark ? array() : array( 'textColor' => 'muted' ); } public static function finalise( $markup ) { if ( '' === $markup ) { return ''; } return (string) preg_replace( '/"hash":""/', '"hash":"' . AIEO_Content_Blocks::hash( $markup ) . '"', $markup, 1 ); } public static function metadata( array $s, $kind ) { $label = ucfirst( $kind ); $heading = AIEO_Content_Inline::heading_plain( (string) ( $s['heading'] ?? '' ) ); $meta = array( 'name' => '' !== $heading ? $label . ': ' . $heading : $label, 'rooster' => array( 'key' => (string) $s['key'], 'kind' => $kind, 'hash' => '' ), ); if ( AIEO_Content_Layout::head_only( $s ) ) { $meta['rooster']['blocks'] = array(); } return $meta; } public static function classes( array $s, $kind ) { $classes = array( 'rooster-section', 'rooster-section--' . $kind ); $style = (string) ( $s['style'] ?? self::DEFAULT_STYLE[ $kind ] ?? 'default' ); if ( 'card' === $style ) { if ( 'hero' === $kind ) { $classes[] = 'is-style-hero-card'; } } elseif ( 'default' !== $style && in_array( $style, self::STYLES, true ) ) { $classes[] = 'is-style-section-' . $style; } $tone = self::tone_class( $s ); if ( '' !== $tone ) { $classes[] = $tone; } return implode( ' ', $classes ); } public static function tone_class( array $s ) { $tone = sanitize_key( (string) ( $s['tone'] ?? '' ) ); if ( '' === $tone ) { return ''; } return in_array( $tone, AIEO_Content_Spec::TONES, true ) ? 'rooster-section--tone-' . $tone : 'is-style-accent-' . $tone; } public static function section( array $s, $kind, $layout ) { $head = empty( $s['headless'] ) ? self::head( $s, $kind ) : ''; return self::shell( $s, $kind, AIEO_Content_Layout::place( $s, $head, $layout ) . self::tail( $s, $kind, self::centred( $s, $kind ) ? 'center' : 'left' ) ); } const NOTICE_PILL = 'rooster-notice-pill'; const NOTICE_PLACES = array( 'below', 'lede' ); public static function notice_at_lede( array $s ) { return 'lede' === (string) ( $s['notice_place'] ?? '' ) && ! empty( $s['notice'] ) && ! empty( $s['lede'] ); } public static function lede_first( array $s ) { if ( ! self::notice_at_lede( $s ) ) { return array(); } $alias = self::alias( $s, 'notice' ); return array( 'prefix' => '' . AIEO_Content_Inline::html( (string) $s['notice'] ) . ' ', 'attrs' => '' !== $alias ? array( 'anchor' => $alias ) : array(), ); } const HERO_GAP = 'var:preset|spacing|8'; public static function hero_gap( array $s ) { $gap = isset( $s['gap'] ) ? self::padding_value( $s['gap'] ) : ''; return '' !== $gap ? $gap : self::HERO_GAP; } public static function is_pill( array $s ) { return 'pill' === (string) ( $s['heading_style'] ?? '' ); } public static function pill( array $s, $level, $html, $anchor = '', $center = false ) { $inner = ''; if ( ! empty( $s['icon'] ) ) { $inner .= AIEO_Content_Blocks::icon( (string) $s['icon'], '18px', 'rooster-section__icon' ); } $h_attrs = array( 'level' => (int) $level ); if ( '' !== (string) $anchor ) { $h_attrs['anchor'] = (string) $anchor; } if ( $center ) { $h_attrs['textAlign'] = 'center'; } $h_attrs['style'] = array( 'typography' => AIEO_Content_Type::step( 'pill' ) ); $inner .= AIEO_Content_Blocks::heading( $h_attrs, $html ); return AIEO_Content_Blocks::group( array( 'className' => 'rooster-section__pill', 'backgroundColor' => 'accent', 'style' => array( 'spacing' => array( 'blockGap' => '8px' ) ), 'layout' => array( 'type' => 'flex', 'flexWrap' => 'nowrap' ), ), $inner ); } public static function alias( array $s, $target ) { return (string) ( $s['_aliases'][ $target ] ?? '' ); } public static function anchor( array $s ) { return sanitize_title( (string) ( $s['anchor'] ?? $s['key'] ) ); } private static function shell( array $s, $kind, $inner, $extra_class = '' ) { $pad = (string) ( self::PADDING[ $kind ] ?? 9 ); $style = array( 'spacing' => array( 'padding' => array( 'top' => 'var:preset|spacing|' . $pad, 'bottom' => 'var:preset|spacing|' . $pad ), 'margin' => array( 'top' => '0', 'bottom' => '0' ) ) ); if ( in_array( $kind, self::MOBILE_PADDING, true ) ) { $style['@mobile'] = array( 'spacing' => array( 'padding' => array( 'top' => 'var:preset|spacing|8', 'bottom' => 'var:preset|spacing|8' ) ) ); } $style = self::padded( $s, $style ); $attrs = array( 'metadata' => self::metadata( $s, $kind ), 'align' => 'full', 'anchor' => self::anchor( $s ), 'className' => trim( self::classes( $s, $kind ) . ( '' !== $extra_class ? ' ' . $extra_class : '' ) ), 'style' => $style, 'layout' => array( 'type' => 'constrained' ), ); if ( ! empty( $s['_nested'] ) ) { unset( $attrs['align'] ); } return AIEO_Content_Blocks::group( $attrs, $inner ); } public static function padding_value( $value ) { if ( is_int( $value ) || ( is_string( $value ) && preg_match( '/^\d{1,2}$/', $value ) ) ) { $n = (int) $value; return $n >= 0 && $n <= 10 ? ( 0 === $n ? '0' : 'var:preset|spacing|' . $n ) : ''; } return is_string( $value ) && preg_match( '/^\d+(\.\d+)?(rem|px)$/', $value ) ? $value : ''; } public static function padded( array $s, array $style ) { foreach ( (array) ( $s['padding'] ?? array() ) as $side => $value ) { if ( 'mobile' === $side && is_array( $value ) ) { foreach ( $value as $edge => $length ) { $style['@mobile']['spacing']['padding'][ $edge ] = self::padding_value( $length ); } } elseif ( in_array( $side, array( 'top', 'bottom' ), true ) ) { $style['spacing']['padding'][ $side ] = self::padding_value( $value ); } } return $style; } private static function centred( array $s, $kind ) { return 'center' === (string) ( $s['align'] ?? ( 'cta' === $kind ? 'center' : 'left' ) ); } public static function is_strip( array $s ) { return 'stats' === (string) ( $s['kind'] ?? '' ) && ( ! empty( $s['headless'] ) || '' === trim( (string) ( $s['heading'] ?? '' ) ) ) && ! AIEO_Content_Layout::applies( $s ); } private static function head( array $s, $kind, array $opts = array() ) { $inner = ''; $center = empty( $opts['left'] ) && self::centred( $s, $kind ); $align = $center ? array( 'align' => 'center' ) : array(); $dark = self::is_dark( $s, $kind ); $pill = self::is_pill( $s ); $id = static fn ( $target ) => '' !== self::alias( $s, $target ) ? array( 'anchor' => self::alias( $s, $target ) ) : array(); if ( ! empty( $s['icon'] ) && ! $pill ) { $inner .= AIEO_Content_Blocks::icon( (string) $s['icon'], '40px', 'rooster-section__icon' ); } if ( ! empty( $s['eyebrow'] ) ) { $inner .= AIEO_Content_Blocks::paragraph( $id( 'eyebrow' ) + $align + array( 'className' => 'rooster-eyebrow', 'fontSize' => 'sm', 'style' => array( 'typography' => array( 'fontWeight' => '600', 'textTransform' => 'uppercase' ) ) ) + ( $dark ? array() : array( 'textColor' => 'accent-text' ) ), AIEO_Content_Inline::html( (string) $s['eyebrow'] ) ); } if ( ! empty( $s['badge'] ) && ( 'hero' !== $kind || AIEO_Content_Layout::applies( $s ) ) ) { $inner .= AIEO_Content_Blocks::paragraph( $id( 'badge' ) + $align + array( 'className' => 'rooster-badge', 'fontSize' => 'xs' ), AIEO_Content_Inline::html( (string) $s['badge'] ) ); } $heading = empty( $s['headless'] ) || ! empty( $opts['force_heading'] ) ? trim( (string) ( $s['heading'] ?? '' ) ) : ''; if ( '' !== $heading && empty( $opts['no_heading'] ) && $pill ) { $inner .= self::pill( $s, (int) ( $opts['level'] ?? $s['level'] ?? 2 ), AIEO_Content_Inline::heading( $heading ), self::alias( $s, 'heading' ), $center ); } elseif ( '' !== $heading && empty( $opts['no_heading'] ) ) { $level = (int) ( $opts['level'] ?? $s['level'] ?? 2 ); $h_attrs = array( 'level' => $level ) + $id( 'heading' ) + ( $center ? array( 'textAlign' => 'center' ) : array() ); $rule = array_key_exists( 'rule', $s ) ? (bool) $s['rule'] : 1 !== $level && ! empty( self::RULE[ $kind ] ); if ( $rule ) { $h_attrs['className'] = 'is-style-accent-rule'; } $role = AIEO_Content_Type::head_role( $level ); if ( self::is_home( $s ) ) { $h_attrs['style'] = array( 'typography' => 'h3' === $role ? AIEO_Content_Type::role( 'home', 'h3' ) : ( 'h1' === $role ? self::DISPLAY_H1 : self::DISPLAY_H2 ) ); if ( ! $dark ) { $h_attrs['textColor'] = 'contrast'; } } else { $h_attrs['fontSize'] = (string) ( $opts['fontSize'] ?? AIEO_Content_Type::THEME_HEADS[ $role ] ); } $inner .= AIEO_Content_Blocks::heading( $h_attrs, AIEO_Content_Inline::heading( $heading ) ); } if ( ! empty( $s['lede'] ) ) { $p_attrs = $align; if ( self::is_home( $s ) && ! $dark ) { $p_attrs['textColor'] = 'contrast-2'; $p_attrs['style'] = array( 'typography' => self::DISPLAY_LEDE ); } elseif ( empty( $opts['plain_lede'] ) && ! $dark ) { $p_attrs['textColor'] = 'muted'; } if ( ! empty( $opts['lede_size'] ) && ! self::is_home( $s ) ) { $p_attrs['fontSize'] = (string) $opts['lede_size']; } $inner .= AIEO_Content_Inline::blocks( $s['lede'], $p_attrs, self::lede_first( $s ) ); } if ( ! empty( $s['notice'] ) && ! self::notice_at_lede( $s ) ) { $inner .= AIEO_Content_Blocks::paragraph( $id( 'notice' ) + $align + array( 'className' => 'rooster-notice', 'fontSize' => 'sm' ), AIEO_Content_Inline::html( (string) $s['notice'] ) ); } if ( '' === $inner ) { return ''; } $g_attrs = array( 'metadata' => array( 'name' => __( 'Section head', 'ai-eshop-optimizer' ) ), 'templateLock' => 'contentOnly', 'lock' => array( 'move' => true, 'remove' => true ), ) + $id( 'head' ) + array( 'className' => 'rooster-section__head' . ( $center ? '' : ' rooster-align-start' ), 'style' => array( 'spacing' => array( 'blockGap' => 'var:preset|spacing|' . ( ! self::is_home( $s ) ? 3 : 4 ) ) ), 'layout' => $center ? array( 'type' => 'constrained' ) : array( 'type' => 'constrained', 'justifyContent' => 'left' ), ); if ( self::is_home( $s ) ) { $g_attrs['layout']['contentSize'] = '42rem'; } return AIEO_Content_Blocks::group( $g_attrs, $inner ); } const DISPLAYS = array( 'home', 'promo', 'rooster-one' ); private static function is_home( array $s ) { return 'home' === (string) ( $s['_display'] ?? '' ); } private static function is_dark( array $s, $kind ) { return in_array( (string) ( $s['style'] ?? self::DEFAULT_STYLE[ $kind ] ?? '' ), array( 'contrast', 'dark' ), true ); } private static function tail( array $s, $kind, $justify = 'center' ) { $dark = self::is_dark( $s, $kind ); $align = 'center' === $justify ? array( 'align' => 'center' ) : array(); $out = self::links( $s['links'] ?? null, $align ); $out .= self::buttons( $s, $kind, $justify, true ); if ( ! empty( $s['note'] ) ) { $out .= AIEO_Content_Inline::blocks( $s['note'], $align + array( 'className' => 'rooster-section__note', 'fontSize' => 'sm' ) + ( $dark ? array() : array( 'textColor' => 'muted' ) ) ); } return $out; } public static function links( $links, array $align ) { if ( empty( $links ) ) { return ''; } $heading = ''; $items = $links; if ( is_array( $links ) && ! array_is_list( $links ) ) { $heading = (string) ( $links['heading'] ?? '' ); $items = (array) ( $links['items'] ?? array() ); } $parts = array(); foreach ( (array) $items as $link ) { $text = trim( (string) ( $link['text'] ?? '' ) ); $href = trim( (string) ( $link['href'] ?? '' ) ); if ( '' !== $text && '' !== $href ) { $parts[] = '' . AIEO_Content_Inline::html( $text ) . ''; } } if ( ! $parts ) { return ''; } $html = ( '' !== $heading ? '' . AIEO_Content_Inline::html( $heading ) . ' ' : '' ) . implode( ' · ', $parts ); return AIEO_Content_Blocks::paragraph( $align + array( 'className' => 'rooster-section__links' ), $html ); } private static function buttons( array $s, $kind, $justify = 'center', $margin = true ) { $buttons = array(); $dark = self::is_dark( $s, $kind ); foreach ( array_values( (array) ( $s['buttons'] ?? array() ) ) as $i => $button ) { $style = (string) ( $button['style'] ?? ( 0 === $i ? 'primary' : 'outline' ) ); $style = 'secondary' === $style ? 'outline' : $style; $row = array( 'text' => AIEO_Content_Inline::plain( (string) ( $button['text'] ?? '' ) ), 'href' => (string) ( $button['href'] ?? '' ), 'style' => $style ); if ( 'outline' === $style && $dark && 'dark' !== (string) ( $s['style'] ?? '' ) ) { $row['textColor'] = 'bg'; } if ( 'primary' === $style && ( ( 'hero' === $kind && ! empty( $s['tiles'] ) ) || ( 'cta' === $kind && self::is_home( $s ) && ! $dark ) ) ) { $row['backgroundColor'] = 'contrast'; $row['textColor'] = 'bg'; } if ( self::is_home( $s ) ) { $row['size'] = 'large'; if ( 'outline' === $style && ! $dark ) { $row['textColor'] = 'contrast'; $row['wash'] = 'hero' === $kind; } } if ( ( ! empty( $button['external'] ) || AIEO_Content_Blocks::is_external( $row['href'] ) ) && false !== ( $button['new_tab'] ?? null ) ) { $row['external'] = true; } if ( ! empty( $button['icon'] ) ) { $row['icon'] = sanitize_key( (string) $button['icon'] ); } if ( ! empty( $button['action'] ) && isset( AIEO_Content_Spec::BUTTON_ACTIONS[ (string) $button['action'] ] ) ) { $row['class'] = AIEO_Content_Spec::BUTTON_ACTIONS[ (string) $button['action'] ]; $row['href'] = AIEO_Content_Spec::BUTTON_ACTION_LINKS[ (string) $button['action'] ] ?? '#'; } if ( ! empty( $button['solid'] ) ) { $light = self::family_light( (string) ( $s['tone'] ?? $s['_family'] ?? '' ) ); if ( '' !== $light ) { $row['solid'] = $light; unset( $row['backgroundColor'], $row['textColor'] ); } } if ( ! empty( $button['note'] ) ) { $row['note'] = AIEO_Content_Inline::plain( (string) $button['note'] ); } $buttons[] = $row; } if ( ! $buttons ) { return ''; } $attrs = array( 'layout' => array( 'type' => 'flex', 'justifyContent' => $justify ) ); if ( $margin ) { $attrs['style'] = array( 'spacing' => array( 'margin' => array( 'top' => 'var:preset|spacing|6' ) ) ); } if ( self::is_home( $s ) ) { $attrs['style']['spacing']['blockGap'] = 'var:preset|spacing|3'; $attrs['style']['@mobile'] = array( 'layout' => array( 'type' => 'flex', 'orientation' => 'vertical', 'justifyContent' => 'stretch' ) ); } return AIEO_Content_Blocks::buttons( $attrs, $buttons ); } private static function grid( $name, $inner, $min = '16rem', $gap = 5, $columns = 0, $defer = '' ) { $layout = $columns > 0 ? array( 'type' => 'grid', 'columnCount' => (int) $columns ) : array( 'type' => 'grid', 'minimumColumnWidth' => $min ); $attrs = array( 'metadata' => array( 'name' => $name ), 'lock' => array( 'move' => true, 'remove' => true ), 'align' => 'wide', 'style' => array( 'spacing' => array( 'blockGap' => 'var:preset|spacing|' . $gap, 'margin' => array( 'top' => 'var:preset|spacing|6' ) ) ), 'layout' => $layout, ); if ( '' !== (string) $defer ) { $attrs['roosterDefer'] = array( 'enabled' => true, 'height' => (string) $defer ); } return AIEO_Content_Blocks::group( $attrs, $inner ); } private static function feature_card( array $card, array $s, $number = 0 ) { if ( array_intersect( self::FAMILY_FIELDS, array_keys( $card ) ) ) { return self::family_card( $card, 'row' === (string) ( $s['layout'] ?? '' ) ? 'links' : 'card' ); } $attrs = array( 'variant' => 'feature', 'icon' => (string) ( $card['icon'] ?? 'award' ), 'title' => AIEO_Content_Inline::plain( (string) ( $card['title'] ?? '' ) ), 'text' => trim( (string) ( $card['text'] ?? '' ) ), 'href' => (string) ( $card['href'] ?? '' ), 'ctaText' => AIEO_Content_Inline::plain( (string) ( $card['ctaText'] ?? '' ) ), 'level' => (int) ( $card['level'] ?? ( isset( $s['level'] ) ? (int) $s['level'] + 1 : 3 ) ), 'layout' => (string) ( $card['layout'] ?? $s['layout'] ?? 'stack' ), ); $badge = (string) ( $card['badge'] ?? '' ); if ( '' === $badge && $number > 0 ) { $badge = (string) $number; } foreach ( array( 'badge' => $badge, 'kicker' => (string) ( $card['kicker'] ?? '' ), 'price' => (string) ( $card['price'] ?? '' ) ) as $key => $value ) { if ( '' !== $value ) { $attrs[ $key ] = AIEO_Content_Inline::plain( $value ); } } if ( ! empty( $card['highlighted'] ) ) { $attrs['highlighted'] = true; } if ( ! empty( $card['anchor'] ) ) { $attrs['anchor'] = sanitize_title( (string) $card['anchor'] ); } if ( empty( $card['items'] ) ) { return AIEO_Content_Blocks::block( 'card', $attrs ); } if ( '' === $badge ) { $badge = (string) count( (array) $card['items'] ); } $items = array(); foreach ( (array) $card['items'] as $item ) { $title = (string) ( is_array( $item ) ? ( $item['title'] ?? '' ) : $item ); $text = is_array( $item ) ? (string) ( $item['text'] ?? '' ) : ''; if ( '' !== $title ) { $items[] = '' . AIEO_Content_Inline::html( $title ) . '' . ( '' !== $text ? ': ' . AIEO_Content_Inline::html( $text ) : '' ); } } $text = implode( "\n", array_filter( preg_split( '/\r\n|\r|\n/', (string) ( $card['text'] ?? '' ) ) ?: array(), static fn ( $line ) => ! preg_match( '/^\s*[-*]\s+/u', $line ) ) ); $inner = ''; $title = AIEO_Content_Inline::html( (string) ( $card['title'] ?? '' ) ); if ( ! empty( $card['href'] ) && empty( $card['ctaText'] ) ) { $title = '' . $title . ''; } $head_row = AIEO_Content_Blocks::icon( (string) ( $card['icon'] ?? 'award' ), '24px', 'rooster-feature-card__icon' ) . AIEO_Content_Blocks::heading( array( 'level' => $attrs['level'], 'fontSize' => 'lg' ), $title ) . ( '' !== $badge ? AIEO_Content_Blocks::paragraph( array( 'className' => 'rooster-badge rooster-feature-card__badge', 'fontSize' => 'xs' ), AIEO_Content_Inline::html( $badge ) ) : '' ); $inner .= AIEO_Content_Blocks::group( array( 'className' => 'rooster-feature-card__head', 'style' => array( 'spacing' => array( 'blockGap' => 'var:preset|spacing|3' ) ), 'layout' => array( 'type' => 'flex', 'flexWrap' => 'nowrap', 'verticalAlignment' => 'center' ) ), $head_row ); if ( ! empty( $card['kicker'] ) ) { $inner .= AIEO_Content_Blocks::paragraph( array( 'fontSize' => 'sm', 'textColor' => 'accent-text' ), AIEO_Content_Inline::html( (string) $card['kicker'] ) ); } if ( trim( $text ) !== '' ) { $inner .= AIEO_Content_Inline::blocks( $text, array( 'fontSize' => 'sm' ) + self::muted( ! empty( $card['highlighted'] ) ) ); } if ( $items ) { $inner .= AIEO_Content_Blocks::list_block( array( 'className' => 'is-style-checkmark-list', 'fontSize' => 'sm' ), $items ); } if ( ! empty( $card['href'] ) && ! empty( $card['ctaText'] ) ) { $inner .= AIEO_Content_Blocks::buttons( array(), array( array( 'text' => AIEO_Content_Inline::plain( (string) $card['ctaText'] ), 'href' => (string) $card['href'], 'style' => 'outline' ) ) ); } $g_attrs = array( 'className' => 'rooster-feature-card rooster-feature-card--row has-list is-style-card' . ( ! empty( $card['highlighted'] ) ? ' is-highlighted' : '' ) ); if ( ! empty( $card['anchor'] ) ) { $g_attrs['anchor'] = sanitize_title( (string) $card['anchor'] ); } $g_attrs['layout'] = array( 'type' => 'flex', 'orientation' => 'vertical', 'flexWrap' => 'nowrap' ); return AIEO_Content_Blocks::group( $g_attrs, $inner ); } private static function family_card( array $card, $layout = 'card' ) { if ( ! empty( $card['swatches'] ) || ! WP_Block_Type_Registry::get_instance()->is_registered( 'rooster/card' ) ) { return self::family_blocks( $card ); } $row = static fn ( array $cells ) => rtrim( implode( ' | ', array_map( static fn ( $c ) => trim( str_replace( '|', '/', (string) $c ) ), $cells ) ), ' |' ); $lines = static function ( $items, array $fields ) use ( $row ) { $out = array(); foreach ( (array) $items as $item ) { $item = is_array( $item ) ? $item : array( 'title' => (string) $item ); $out[] = $row( array_map( static fn ( $f ) => in_array( $f, array( 'title', 'badge' ), true ) ? AIEO_Content_Inline::plain( (string) ( $item[ $f ] ?? '' ) ) : str_replace( array( "\r", "\n" ), ' ', (string) ( $item[ $f ] ?? '' ) ), $fields ) ); } return implode( "\n", array_filter( $out, 'strlen' ) ); }; $attrs = array( 'variant' => 'family', 'layout' => $layout, 'family' => sanitize_key( (string) ( $card['accent'] ?? $card['key'] ?? '' ) ), 'name' => AIEO_Content_Inline::plain( (string) ( $card['title'] ?? '' ) ), 'href' => (string) ( $card['href'] ?? '' ), 'heading' => AIEO_Content_Inline::plain( (string) ( $card['heading'] ?? '' ) ), 'text' => trim( (string) ( $card['text'] ?? '' ) ), 'products' => $lines( $card['products'] ?? array(), array( 'title', 'href', 'badge', 'text' ) ), 'features' => $lines( $card['features'] ?? array(), array( 'title', 'href' ) ), 'ctaText' => AIEO_Content_Inline::plain( (string) ( $card['ctaText'] ?? '' ) ), 'docsHref' => (string) ( $card['docs']['href'] ?? '' ), 'docsText' => AIEO_Content_Inline::plain( (string) ( $card['docs']['text'] ?? '' ) ), 'motif' => (string) ( $card['motif'] ?? '' ), 'level' => (int) ( $card['level'] ?? 3 ), ); if ( 'Documentation' === $attrs['docsText'] ) { $attrs['docsText'] = ''; } if ( ! empty( $card['anchor'] ) ) { $attrs['anchor'] = sanitize_title( (string) $card['anchor'] ); } if ( ! empty( $card['align'] ) ) { $attrs['align'] = (string) $card['align']; } return AIEO_Content_Blocks::block( 'card', array_filter( $attrs, static fn ( $v ) => '' !== $v ) ); } private static function family_blocks( array $card ) { $accent = sanitize_key( (string) ( $card['accent'] ?? '' ) ); $inner = ''; if ( ! empty( $card['motif'] ) && WP_Block_Patterns_Registry::get_instance()->is_registered( (string) $card['motif'] ) ) { $inner .= AIEO_Content_Blocks::comment( 'core/pattern', array( 'slug' => (string) $card['motif'] ) ); } $title = AIEO_Content_Inline::html( (string) ( $card['title'] ?? '' ) ); if ( ! empty( $card['href'] ) ) { $title = '' . $title . ''; } $inner .= AIEO_Content_Blocks::heading( array( 'level' => 3, 'fontSize' => 'xl' ), $title ); if ( ! empty( $card['text'] ) ) { $inner .= AIEO_Content_Inline::blocks( $card['text'], self::muted() ); } if ( ! empty( $card['products'] ) ) { $items = array(); foreach ( (array) $card['products'] as $product ) { $name = AIEO_Content_Inline::html( (string) ( $product['title'] ?? '' ) ); $href = (string) ( $product['href'] ?? '' ); $line = '' !== $href ? '' . $name . '' : $name; if ( ! empty( $product['text'] ) ) { $line .= ' — ' . AIEO_Content_Inline::html( (string) $product['text'] ); } $items[] = $line; } $inner .= AIEO_Content_Blocks::list_block( array( 'className' => 'rooster-family-card__products' ), $items ); } if ( ! empty( $card['features'] ) ) { $items = array(); foreach ( (array) $card['features'] as $feature ) { $name = AIEO_Content_Inline::html( (string) ( $feature['title'] ?? '' ) ); $href = (string) ( $feature['href'] ?? '' ); $items[] = '' !== $href ? '' . $name . '' : $name; } $inner .= AIEO_Content_Blocks::list_block( array( 'className' => 'is-style-chips' ), $items ); } if ( ! empty( $card['swatches'] ) ) { $chips = ''; foreach ( (array) $card['swatches'] as $colour ) { $colour = sanitize_hex_color( (string) $colour ); if ( ! $colour ) { continue; } $chips .= AIEO_Content_Blocks::comment( 'core/group', array( 'className' => 'rooster-swatch', 'style' => array( 'color' => array( 'background' => $colour ), 'dimensions' => array( 'minHeight' => '1.5rem' ) ), 'layout' => array( 'type' => 'constrained' ) ), '
' ); } if ( '' !== $chips ) { $inner .= AIEO_Content_Blocks::group( array( 'className' => 'rooster-swatches', 'style' => array( 'spacing' => array( 'blockGap' => 'var:preset|spacing|2' ) ), 'layout' => array( 'type' => 'flex', 'flexWrap' => 'nowrap' ) ), $chips ); } } $buttons = array(); if ( ! empty( $card['href'] ) && ! empty( $card['ctaText'] ) ) { $buttons[] = array( 'text' => AIEO_Content_Inline::plain( (string) $card['ctaText'] ), 'href' => (string) $card['href'], 'style' => 'primary' ); } if ( ! empty( $card['docs']['href'] ) ) { $buttons[] = array( 'text' => AIEO_Content_Inline::plain( (string) ( $card['docs']['text'] ?? __( 'Documentation', 'ai-eshop-optimizer' ) ) ), 'href' => (string) $card['docs']['href'], 'style' => 'outline' ); } if ( $buttons ) { $inner .= AIEO_Content_Blocks::buttons( array(), $buttons ); } return AIEO_Content_Blocks::group( array( 'className' => 'rooster-family-card is-style-card' . ( '' !== $accent ? ' is-style-accent-' . $accent : '' ), 'style' => array( 'spacing' => array( 'blockGap' => 'var:preset|spacing|4' ) ), 'layout' => array( 'type' => 'flex', 'orientation' => 'vertical', 'flexWrap' => 'nowrap' ), ), $inner ); } private static function price_card( array $tier, $layout ) { $attrs = self::price_attrs( $tier, $layout ); if ( empty( $tier['volume'] ) ) { return AIEO_Content_Blocks::block( 'plan', array( 'variant' => 'price' ) + $attrs ); } $volume = (array) $tier['volume']; $standin = AIEO_Content_Blocks::standin( 'price-card', $attrs ); $table = ''; if ( ! empty( $volume['caption'] ) ) { $table .= AIEO_Content_Blocks::paragraph( array( 'className' => 'rooster-price-card__volume-caption', 'fontSize' => 'sm', 'style' => array( 'typography' => array( 'fontWeight' => '600' ) ) ), AIEO_Content_Inline::html( (string) $volume['caption'] ) ); } $table .= AIEO_Content_Blocks::table( (array) ( $volume['columns'] ?? array() ), (array) ( $volume['rows'] ?? array() ), '', 'rooster-price-card__volume' ); if ( ! empty( $volume['note'] ) ) { $table .= AIEO_Content_Blocks::paragraph( array( 'fontSize' => 'xs' ) + self::muted( ! empty( $tier['highlighted'] ) ), AIEO_Content_Inline::html( (string) $volume['note'] ) ); } $pos = strrpos( $standin, '