termcinema-engine 0.1.0

🧠 Core typewriter-style terminal animation engine (SVG renderer) for termcinema
Documentation
use crate::constants::*;

/// Visual style configuration for font and color settings.
///
/// Defines the appearance of rendered content, including font size,
/// font family, and optional text/background colors. Used across themes,
/// CLI overrides, and fallback rendering.
#[derive(Clone)]
pub struct StyleSpec {
    /// Font size in **pixels**.
    pub font_size: u32,

    /// CSS font-family name (e.g. `"JetBrains Mono"`).
    /// Can refer to an embedded font or system fallback.
    pub font_family: String,

    /// Text color in hexadecimal (e.g. `"#00FF00"`), or `None` for transparent.
    pub text_color: Option<String>,

    /// Background color in hexadecimal (e.g. `"#000000"`), or `None` for transparent.
    pub background_color: Option<String>,
}

/// Default style configuration using built-in constants.
///
/// This is used when no explicit style is provided by the user or theme.
impl Default for StyleSpec {
    fn default() -> Self {
        StyleSpec {
            font_size: DEFAULT_STYLE_FONT_SIZE,
            font_family: DEFAULT_STYLE_FONT_FAMILY.into(),
            text_color: Some(DEFAULT_STYLE_TEXT_COLOR.into()),
            background_color: Some(DEFAULT_STYLE_BACKGROUND_COLOR.into()),
        }
    }
}

/// Extracts raw style values for rendering engines.
///
/// Returns a tuple of resolved visual parameters:
/// `(font_size, font_family, text_color, background_color)`
///
/// - If any color is `None`, falls back to default constants;
/// - Used by SVG renderers and preview tools for layout calculation.
pub(crate) fn extract_style_primitives(style: &StyleSpec) -> (u32, &str, &str, &str) {
    (
        style.font_size,
        &style.font_family,
        style
            .text_color
            .as_deref()
            .unwrap_or(DEFAULT_STYLE_TEXT_COLOR),
        style
            .background_color
            .as_deref()
            .unwrap_or(DEFAULT_STYLE_BACKGROUND_COLOR),
    )
}