*/ public static function all(): array { static $animations = null; if ( null === $animations ) { $animations = array( self::NONE => array( 'label' => __( 'None', 'animora' ), 'site_default' => true, 'category' => null, ), self::DEFAULT_SENTINEL => array( 'label' => __( 'Default', 'animora' ), 'site_default' => false, 'category' => null, ), 'fade-in' => array( 'label' => __( 'Fade In', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_SCROLL, ), 'fade-in-up' => array( 'label' => __( 'Fade In Up', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_SCROLL, ), 'fade-in-right' => array( 'label' => __( 'Fade In Right', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_SCROLL, ), 'fade-in-left' => array( 'label' => __( 'Fade In Left', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_SCROLL, ), 'zoom-in' => array( 'label' => __( 'Zoom In', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_SCROLL, ), 'zoom-and-fade' => array( 'label' => __( 'Zoom and Fade', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_SCROLL, ), 'zoom-and-spin' => array( 'label' => __( 'Zoom and Spin', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_SCROLL, ), 'shake' => array( 'label' => __( 'Shake', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_ATTENTION, ), 'pulse' => array( 'label' => __( 'Pulse', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_ATTENTION, ), 'heartbeat' => array( 'label' => __( 'Heartbeat', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_ATTENTION, ), 'blink' => array( 'label' => __( 'Blink', 'animora' ), 'site_default' => true, 'category' => self::CATEGORY_ATTENTION, ), ); } return $animations; } /** * Whether an entry belongs to a category, or is a universal sentinel * ("none"/"default") that belongs to every category. * * @since 0.1.0 * @param array $entry Registry entry. * @param string $category Category to check against. * @return bool */ private static function entry_matches_category( array $entry, string $category ): bool { return null === $entry['category'] || $category === $entry['category']; } /** * Slug => label for every choice in a category, including "None" and * "Default" — used by the per-block Inspector panel. * * @since 0.1.0 * @param string $category self::CATEGORY_SCROLL or self::CATEGORY_ATTENTION. * @return array */ public static function choices_for_block( string $category ): array { $entries = array_filter( self::all(), static function ( array $entry ) use ( $category ): bool { return self::entry_matches_category( $entry, $category ); } ); return wp_list_pluck( $entries, 'label' ); } /** * Slug => label for choices valid as the site-wide default within a * category — excludes the "Default" sentinel, which would be * self-referential. * * @since 0.1.0 * @param string $category self::CATEGORY_SCROLL or self::CATEGORY_ATTENTION. * @return array */ public static function choices_for_site_default( string $category ): array { $eligible = array_filter( self::all(), static function ( array $entry ) use ( $category ): bool { return $entry['site_default'] && self::entry_matches_category( $entry, $category ); } ); return wp_list_pluck( $eligible, 'label' ); } /** * Whether a slug is a recognised animation within a category * (including the universal "none"/"default" sentinels). * * @since 0.1.0 * @param string $slug Slug to check. * @param string $category self::CATEGORY_SCROLL or self::CATEGORY_ATTENTION. * @return bool */ public static function is_valid( string $slug, string $category ): bool { $all = self::all(); return isset( $all[ $slug ] ) && self::entry_matches_category( $all[ $slug ], $category ); } }