euv-ui 0.49.4

Cross-platform UI component library and 17-scheme design system for the euv framework with pixel-consistent rendering across Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
Documentation
use super::*;

/// Pre-resolved syntax language used by the Eva code tokenizer without per-line string allocations.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub enum CodeLang {
    /// Generic programming language syntax.
    #[default]
    Generic,
    /// Rust source syntax (`"rust"`).
    Rust,
    /// Unified diff patch syntax (`"diff"`).
    Diff,
    /// JSON object/array syntax (`"json"`).
    Json,
    /// TOML key-value configuration syntax (`"toml"`).
    Toml,
    /// YAML key-value configuration syntax (`"yaml"`).
    Yaml,
}

/// Sizing policy controlling how `EuvCodeBlock` expands or constrains its inline width and height.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub enum EuvCodeBlockSizeMode {
    /// Automatically expands width and height to display the full code block without cramped fixed-height clipping while staying bounded inside constrained parent cards or viewports with smooth horizontal scrolling.
    #[default]
    AutoExpand,
    /// Expands height automatically to show all lines without vertical clipping while constraining width to the parent container with full-area horizontal scrolling.
    AutoExpandHeight,
    /// Expands width naturally to the longest code line while constraining height (`max_height`) with full-area vertical scrolling.
    AutoExpandWidth,
    /// Constrains both width and height (`max_height`) with full-area 2D horizontal and vertical scrolling.
    Fixed,
}

/// Syntax token classification mapped directly to VS Code `Eva Light Bold` / `Eva Dark Bold` TextMate scopes.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub enum CodeTokenKind {
    /// Default editor foreground text.
    #[default]
    Plain,
    /// Storage keyword or modifier (`fn`, `let`, `mut`, `pub`, `struct`; `#7C4DFF` / `#A78CFA` bold).
    Keyword,
    /// Control-flow or module keyword (`if`, `match`, `return`, `use`, `where`; `#C838C6` / `#CF68E1` bold).
    Control,
    /// Symbolic operator (`=`, `->`, `=>`, `&`, `+`, `-`; `#00BEC4` / `#56B7C3`).
    Operator,
    /// User type, struct, enum, or trait identifier (`#00BEC4` / `#56B7C3`).
    Type,
    /// Built-in primitive or numeric type (`u32`, `f32`, `bool`, `str`; `#EF8ED8` / `#FF6AB3`).
    PrimitiveType,
    /// Function or method name (`#437AED` / `#6495EE` bold).
    Function,
    /// Macro invocation, attribute, or lifetime (`#437AED` / `#6495EE` bold).
    Macro,
    /// Quoted string or character literal (`#53A053` / `#98C379`).
    String,
    /// Numeric literal (`#FF6D12` / `#FF9070`).
    Number,
    /// Language constant (`true`, `false`, `None`, `Some`; `#C838C6` / `#CF68E1` bold).
    Constant,
    /// Line or block comment (`#A9A9AA` / `#676E95` italic).
    Comment,
    /// Property key, field, or `Result`/`Option` type (`#CD6069` / `#E06C75`).
    Property,
    /// Punctuation or delimiter (`#A0A1A7` / `#79859D`).
    Punctuation,
    /// Diff insertion line (`+...`, `#44C145` / `#4EC150`).
    DiffAdd,
    /// Diff deletion line (`-...`, `#F14C4C`).
    DiffDel,
}

/// Semantic variant for `EuvMarkdownQuote` supporting plain blockquotes and GitHub-flavored Alerts.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub enum EuvMarkdownAlertKind {
    /// Standard Markdown blockquote (`> ...`).
    #[default]
    Quote,
    /// Informational note alert (`> [!NOTE]`).
    Note,
    /// Helpful tip alert (`> [!TIP]`).
    Tip,
    /// Essential requirement alert (`> [!IMPORTANT]`).
    Important,
    /// Warning alert (`> [!WARNING]`).
    Warning,
    /// Critical caution alert (`> [!CAUTION]`).
    Caution,
}

/// Column alignment parsed from GFM Markdown tables.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub enum EuvMarkdownAlign {
    /// Left-aligned column (`:---`).
    #[default]
    Left,
    /// Center-aligned column (`:---:`).
    Center,
    /// Right-aligned column (`---:`).
    Right,
}

/// Inline emphasis wrapper mode applied when recursively flattening nested Markdown inline spans.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum InlineWrapStyle {
    /// Wrap inner text spans as bold.
    Bold,
    /// Wrap inner text spans as italic.
    Italic,
    /// Wrap inner text spans as combined bold and italic.
    BoldItalic,
    /// Wrap inner text spans with strikethrough.
    Strike,
    /// Wrap inner text spans as highlighted text.
    Highlight,
}

/// Parsed inline Markdown segment rendered inside `EuvMarkdownParagraph` and list items.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum EuvMarkdownInline {
    /// Plain body text span.
    Text(String),
    /// Bold emphasis (`**text**` or `__text__`).
    Bold(String),
    /// Italic emphasis (`*text*` or `_text_`).
    Italic(String),
    /// Combined bold and italic emphasis (`***text***`).
    BoldItalic(String),
    /// Strikethrough (`~~text~~`).
    Strike(String),
    /// Highlighted text (`==text==` or `<mark>text</mark>`).
    Highlight(String),
    /// Superscript text (`^text^` or `<sup>text</sup>`).
    Superscript(String),
    /// Subscript text (`~text~` or `<sub>text</sub>`).
    Subscript(String),
    /// Inline monospace code chip (`` `code` ``).
    Code(String),
    /// Inline math expression (`$expr$`) formatted with Unicode math symbols.
    Math(String),
    /// Inline footnote reference badge (`[^id]`).
    FootnoteRef(String),
    /// Inline image (`![alt](url)` or `<img src="..." alt="...">`).
    Image {
        /// Accessible alt caption.
        alt: String,
        /// Image source URI.
        url: String,
    },
    /// Clickable linked image or badge (`[![alt](image_url)](link_url)`).
    LinkedImage {
        /// Accessible alt caption.
        alt: String,
        /// Image source URI.
        image_url: String,
        /// Destination hyperlink URL.
        link_url: String,
    },
    /// Clickable hyperlink (`[label](url)`, `[label][ref]`, or `<https://...>`).
    Link {
        /// Visible anchor text.
        label: String,
        /// Target URL or route.
        url: String,
    },
    /// Keyboard shortcut cap (`<kbd>Cmd+K</kbd>`).
    Kbd(String),
    /// Explicit inline hard line break (`  \n` or `\\\n`).
    HardBreak,
}

/// Parsed block-level Markdown AST node rendered natively by `EuvMarkdown`.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum EuvMarkdownBlock {
    /// ATX heading (`#` through `######`).
    Heading {
        /// Heading level (`1..=6`).
        level: u8,
        /// Heading text.
        text: String,
    },
    /// Rich inline paragraph.
    Paragraph(Vec<EuvMarkdownInline>),
    /// Fenced or indented syntax-highlighted code block.
    CodeBlock {
        /// Language identifier (e.g. `"rust"`, `"ts"`, `"json"`).
        language: String,
        /// Optional code fence header title or filename (`title="..."` / `filename="..."`).
        title: Option<String>,
        /// Optional 1-based highlighted line numbers parsed from `{1,3-5}` fence markers.
        highlight_lines: Vec<usize>,
        /// Raw code body.
        code: String,
    },
    /// Native vector Mermaid diagram block (` ```mermaid `).
    Mermaid {
        /// Raw Mermaid diagram source text.
        source: String,
    },
    /// Embedded native vector ECharts block (` ```echart ` or ` ```echarts `).
    EChart {
        /// Raw JSON or key-value ECharts specification text.
        source: String,
    },
    /// Display math block (`$$...$$`).
    MathBlock(String),
    /// Blockquote or GitHub-flavored Alert / container callout.
    Quote {
        /// Plain quote or alert kind.
        kind: EuvMarkdownAlertKind,
        /// Optional custom callout header title (for example from `::: warning Custom Title`).
        title: Option<String>,
        /// Nesting depth (`1` = top level).
        depth: usize,
        /// Raw content lines inside the callout.
        lines: Vec<String>,
        /// Recursively parsed nested Markdown child blocks inside the callout.
        children: Vec<EuvMarkdownBlock>,
    },
    /// Unordered, ordered, nested, or task-checklist list.
    List {
        /// Whether items render with ordinal numbers.
        ordered: bool,
        /// Starting ordinal number for ordered lists (`1` by default).
        start: usize,
        /// Ordered list items.
        items: Vec<EuvMarkdownListItem>,
    },
    /// GFM aligned data table.
    Table {
        /// Column header labels.
        headers: Vec<String>,
        /// Column alignments.
        alignments: Vec<EuvMarkdownAlign>,
        /// Body rows.
        rows: Vec<Vec<String>>,
    },
    /// Extended Markdown definition list (`Term` + `: Definition`).
    DefinitionList(Vec<EuvMarkdownDefItem>),
    /// Bottom footnote definitions section (`[^id]: text`).
    Footnotes(Vec<EuvMarkdownFootnote>),
    /// Thematic horizontal divider (`---`).
    Divider,
    /// Image figure (`![alt](url)`).
    Image {
        /// Accessible caption / alt text.
        alt: String,
        /// Image source URI or asset path.
        url: String,
    },
    /// Collapsible `<details><summary>` or `::: details` disclosure block.
    Details {
        /// Toggle summary header.
        summary: String,
        /// Whether the disclosure block starts expanded (`<details open>`).
        open: bool,
        /// Raw content lines revealed when expanded.
        body: Vec<String>,
        /// Recursively parsed nested Markdown child blocks revealed when expanded.
        children: Vec<EuvMarkdownBlock>,
    },
}