icons 0.7.2

Icons for Rust fullstack applications — Leptos and Dioxus.
Documentation
//! Static animated icon registry for zero-allocation icon lookup
//!
//! This module provides pre-compiled static data for all animated icons,
//! implementing the same registry pattern as regular leptos icons.
//!
//! 🤖 AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
//! Generated by: generate_animated_icon_registry.py

use super::animated_icon_type::AnimatedIconType;
use crate::common::static_svg_element::StaticSvgElement;

/// Static elements for Heart icon
static HEART_ELEMENTS: &[StaticSvgElement] = &[StaticSvgElement::Path {
    d: "M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",
}];

/// Static elements for Plus icon
static PLUS_ELEMENTS: &[StaticSvgElement] =
    &[StaticSvgElement::Path { d: "M5 12h14" }, StaticSvgElement::Path { d: "M12 5v14" }];

/// Get static SVG elements for a specific animated icon
///
/// Returns None if the icon is not found in the registry.
/// This is a zero-allocation O(1) lookup.
pub fn get_animated_icon_elements(icon_type: AnimatedIconType) -> Option<&'static [StaticSvgElement]> {
    match icon_type {
        AnimatedIconType::Heart => Some(HEART_ELEMENTS),
        AnimatedIconType::Plus => Some(PLUS_ELEMENTS),
    }
}

/// Check if an animated icon exists in the registry
pub fn has_animated_icon(icon_type: AnimatedIconType) -> bool {
    get_animated_icon_elements(icon_type).is_some()
}

/// Get the total number of animated icons in the registry
pub fn animated_icon_count() -> usize {
    AnimatedIconType::all().len()
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/*                        🧪 TESTS 🧪                         */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_animated_icon_registry_heart() {
        let elements = get_animated_icon_elements(AnimatedIconType::Heart).unwrap();
        assert_eq!(elements.len(), 1);

        match &elements[0] {
            StaticSvgElement::Path { d } => {
                assert!(d.contains("M19 14c1.49-1.46"));
                assert!(d.contains("l7 7Z"));
            }
            _ => panic!("Expected Path element for Heart"),
        }
    }

    #[test]
    fn test_animated_icon_registry_plus() {
        let elements = get_animated_icon_elements(AnimatedIconType::Plus).unwrap();
        assert_eq!(elements.len(), 2);

        match &elements[0] {
            StaticSvgElement::Path { d } => assert_eq!(*d, "M5 12h14"),
            _ => panic!("Expected Path element for Plus[0]"),
        }

        match &elements[1] {
            StaticSvgElement::Path { d } => assert_eq!(*d, "M12 5v14"),
            _ => panic!("Expected Path element for Plus[1]"),
        }
    }

    #[test]
    fn test_animated_icon_registry_zero_allocation() {
        // Test that registry returns static references
        let elements1 = get_animated_icon_elements(AnimatedIconType::Heart).unwrap();
        let elements2 = get_animated_icon_elements(AnimatedIconType::Heart).unwrap();

        // Should be the same static reference
        assert_eq!(elements1.as_ptr(), elements2.as_ptr());

        // Test that strings are static references
        match &elements1[0] {
            StaticSvgElement::Path { d } => {
                let ptr1 = d.as_ptr();
                match &elements2[0] {
                    StaticSvgElement::Path { d: d2 } => {
                        let ptr2 = d2.as_ptr();
                        assert_eq!(ptr1, ptr2, "Path data should be static reference");
                    }
                    _ => panic!("Expected Path"),
                }
            }
            _ => panic!("Expected Path"),
        }
    }

    #[test]
    fn test_has_animated_icon() {
        assert!(has_animated_icon(AnimatedIconType::Heart));
        assert!(has_animated_icon(AnimatedIconType::Plus));
    }

    #[test]
    fn test_animated_icon_count() {
        assert_eq!(animated_icon_count(), 2);
    }

    #[test]
    fn test_animated_registry_completeness() {
        // Test that all icon types have registry entries
        for icon_type in AnimatedIconType::all() {
            let elements = get_animated_icon_elements(*icon_type);
            assert!(elements.is_some(), "Missing registry entry for {:?}", icon_type);
            assert!(!elements.unwrap().is_empty(), "Empty registry entry for {:?}", icon_type);
        }
    }
}