arks-server 1.3.2

Git server: upload-pack / receive-pack + smart/dumb HTTP + daemon (M11/M25)
Documentation
//! Typed Lucide SVG sprite icon primitives (`web::ui::icon`, `Icon`, `IconSize`)
//! governed by `web-platform-baseline.sot.md` WP-ICON-1..3.
//!
//! All icons come from the single vendored `/assets/icons.svg` sprite (Lucide v1.84.0, ISC,
//! plus the existing A2-R2 arks mark `i-arks`). Emoji and Unicode symbol glyphs are banned
//! as UI icons.

use crate::web::core::assets::core_asset_url;
use crate::web::core::html::{Attr, HtmlBuf, Render};

/// Standard icon sizing classes matching `web_ui.css`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IconSize {
    /// 12px (inside pills/badges).
    Xs,
    /// 14px (dense rows, secondary controls).
    Sm,
    /// 16px (default navigation & buttons).
    Md,
    /// 18px (section headers).
    Lg,
    /// 28px (A2-R2 brand mark in topbar).
    Brand,
}

impl IconSize {
    pub const fn class(self) -> &'static str {
        match self {
            Self::Xs => "ico ico-xs",
            Self::Sm => "ico ico-sm",
            Self::Md => "ico",
            Self::Lg => "ico ico-lg",
            Self::Brand => "ico ico-brand",
        }
    }
}

/// Complete typed catalog of symbols embedded in `/assets/icons.svg`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Icon {
    Activity,
    Archive,
    Arks,
    ArrowLeft,
    ArrowRight,
    BadgeCheck,
    Bell,
    BookOpen,
    Bot,
    Box,
    ChartColumn,
    Check,
    ChevronDown,
    ChevronRight,
    CircleAlert,
    CircleCheck,
    CircleDot,
    CirclePlay,
    CircleX,
    Clock,
    Cloud,
    Code,
    Copy,
    Cpu,
    Download,
    Ellipsis,
    ExternalLink,
    Eye,
    File,
    FileText,
    Folder,
    GitBranch,
    GitCommitHorizontal,
    GitCompare,
    GitFork,
    GitGraph,
    GitMerge,
    GitPullRequest,
    GitPullRequestArrow,
    History,
    KeyRound,
    Layers,
    Link,
    ListFilter,
    Lock,
    LogOut,
    Menu,
    MessageSquare,
    Moon,
    Network,
    Pencil,
    Plus,
    Radio,
    RefreshCw,
    Search,
    Settings,
    Shield,
    ShieldCheck,
    Sparkles,
    SquareKanban,
    Star,
    Sun,
    Tag,
    Terminal,
    Trash2,
    TriangleAlert,
    Undo2,
    User,
    Users,
    Webhook,
    Workflow,
    X,
}

impl Icon {
    /// Every variant in `Icon`, verified against `/assets/icons.svg` by unit tests.
    pub const ALL: &'static [Icon] = &[
        Self::Activity,
        Self::Archive,
        Self::Arks,
        Self::ArrowLeft,
        Self::ArrowRight,
        Self::BadgeCheck,
        Self::Bell,
        Self::BookOpen,
        Self::Bot,
        Self::Box,
        Self::ChartColumn,
        Self::Check,
        Self::ChevronDown,
        Self::ChevronRight,
        Self::CircleAlert,
        Self::CircleCheck,
        Self::CircleDot,
        Self::CirclePlay,
        Self::CircleX,
        Self::Clock,
        Self::Cloud,
        Self::Code,
        Self::Copy,
        Self::Cpu,
        Self::Download,
        Self::Ellipsis,
        Self::ExternalLink,
        Self::Eye,
        Self::File,
        Self::FileText,
        Self::Folder,
        Self::GitBranch,
        Self::GitCommitHorizontal,
        Self::GitCompare,
        Self::GitFork,
        Self::GitGraph,
        Self::GitMerge,
        Self::GitPullRequest,
        Self::GitPullRequestArrow,
        Self::History,
        Self::KeyRound,
        Self::Layers,
        Self::Link,
        Self::ListFilter,
        Self::Lock,
        Self::LogOut,
        Self::Menu,
        Self::MessageSquare,
        Self::Moon,
        Self::Network,
        Self::Pencil,
        Self::Plus,
        Self::Radio,
        Self::RefreshCw,
        Self::Search,
        Self::Settings,
        Self::Shield,
        Self::ShieldCheck,
        Self::Sparkles,
        Self::SquareKanban,
        Self::Star,
        Self::Sun,
        Self::Tag,
        Self::Terminal,
        Self::Trash2,
        Self::TriangleAlert,
        Self::Undo2,
        Self::User,
        Self::Users,
        Self::Webhook,
        Self::Workflow,
        Self::X,
    ];

    /// Symbol ID suffix (`i-<slug>`) inside `/assets/icons.svg`.
    pub const fn symbol_id(self) -> &'static str {
        match self {
            Self::Activity => "i-activity",
            Self::Archive => "i-archive",
            Self::Arks => "i-arks",
            Self::ArrowLeft => "i-arrow-left",
            Self::ArrowRight => "i-arrow-right",
            Self::BadgeCheck => "i-badge-check",
            Self::Bell => "i-bell",
            Self::BookOpen => "i-book-open",
            Self::Bot => "i-bot",
            Self::Box => "i-box",
            Self::ChartColumn => "i-chart-column",
            Self::Check => "i-check",
            Self::ChevronDown => "i-chevron-down",
            Self::ChevronRight => "i-chevron-right",
            Self::CircleAlert => "i-circle-alert",
            Self::CircleCheck => "i-circle-check",
            Self::CircleDot => "i-circle-dot",
            Self::CirclePlay => "i-circle-play",
            Self::CircleX => "i-circle-x",
            Self::Clock => "i-clock",
            Self::Cloud => "i-cloud",
            Self::Code => "i-code",
            Self::Copy => "i-copy",
            Self::Cpu => "i-cpu",
            Self::Download => "i-download",
            Self::Ellipsis => "i-ellipsis",
            Self::ExternalLink => "i-external-link",
            Self::Eye => "i-eye",
            Self::File => "i-file",
            Self::FileText => "i-file-text",
            Self::Folder => "i-folder",
            Self::GitBranch => "i-git-branch",
            Self::GitCommitHorizontal => "i-git-commit-horizontal",
            Self::GitCompare => "i-git-compare",
            Self::GitFork => "i-git-fork",
            Self::GitGraph => "i-git-graph",
            Self::GitMerge => "i-git-merge",
            Self::GitPullRequest => "i-git-pull-request",
            Self::GitPullRequestArrow => "i-git-pull-request-arrow",
            Self::History => "i-history",
            Self::KeyRound => "i-key-round",
            Self::Layers => "i-layers",
            Self::Link => "i-link",
            Self::ListFilter => "i-list-filter",
            Self::Lock => "i-lock",
            Self::LogOut => "i-log-out",
            Self::Menu => "i-menu",
            Self::MessageSquare => "i-message-square",
            Self::Moon => "i-moon",
            Self::Network => "i-network",
            Self::Pencil => "i-pencil",
            Self::Plus => "i-plus",
            Self::Radio => "i-radio",
            Self::RefreshCw => "i-refresh-cw",
            Self::Search => "i-search",
            Self::Settings => "i-settings",
            Self::Shield => "i-shield",
            Self::ShieldCheck => "i-shield-check",
            Self::Sparkles => "i-sparkles",
            Self::SquareKanban => "i-square-kanban",
            Self::Star => "i-star",
            Self::Sun => "i-sun",
            Self::Tag => "i-tag",
            Self::Terminal => "i-terminal",
            Self::Trash2 => "i-trash-2",
            Self::TriangleAlert => "i-triangle-alert",
            Self::Undo2 => "i-undo-2",
            Self::User => "i-user",
            Self::Users => "i-users",
            Self::Webhook => "i-webhook",
            Self::Workflow => "i-workflow",
            Self::X => "i-x",
        }
    }
}

/// Renderable strict-CSP SVG `<use>` icon primitive.
#[derive(Debug, Clone, Copy)]
pub struct IconEl {
    pub icon: Icon,
    pub size: IconSize,
}

/// Render a default 16px Lucide sprite icon (`aria-hidden="true"`).
pub const fn icon(icon: Icon) -> IconEl {
    IconEl {
        icon,
        size: IconSize::Md,
    }
}

/// Render a sized Lucide sprite icon (`aria-hidden="true"`).
pub const fn icon_sized(icon: Icon, size: IconSize) -> IconEl {
    IconEl { icon, size }
}

impl Render for IconEl {
    fn render_to(&self, out: &mut HtmlBuf) {
        let href = format!(
            "{}#{}",
            core_asset_url("/assets/icons.svg"),
            self.icon.symbol_id()
        );
        let cls = if self.icon == Icon::Arks {
            match self.size {
                IconSize::Brand => "ico ico-brand ico-fill",
                _ => "ico ico-fill",
            }
        } else {
            self.size.class()
        };
        out.el(
            "svg",
            &[Attr::Class(cls), Attr::Aria("hidden", "true")],
            |svg: &mut HtmlBuf| {
                svg.el("use", &[Attr::Href(&href)], ());
            },
        );
    }
}

/// Forbidden emoji/Unicode symbol glyphs banned as UI icons (WP-ICON-1).
pub const FORBIDDEN_GLYPH_ICONS: &[char] = &[
    '⚙', '👥', '⚿', '◇', '⑂', '☆', '▸', '≡', '⌕', '🔔', '◐', '⟲', '✎', '✓', '✕', '▾',
];

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

    const SPRITE: &str = include_str!("../../assets/icons.svg");

    #[test]
    fn every_icon_variant_exists_in_lucide_sprite() {
        for &ic in Icon::ALL {
            let needle = format!("id=\"{}\"", ic.symbol_id());
            assert!(
                SPRITE.contains(&needle),
                "Icon::{ic:?} missing symbol {needle} in assets/icons.svg"
            );
        }
        assert_eq!(Icon::ALL.len(), 72);
    }

    #[test]
    fn icon_renders_fingerprinted_svg_use_without_inline_style() {
        let mut buf = HtmlBuf::new();
        icon(Icon::GitBranch).render_to(&mut buf);
        let html = buf.finish();
        assert!(html.contains("class=\"ico\""));
        assert!(html.contains("aria-hidden=\"true\""));
        assert!(html.contains("/assets/icons."));
        assert!(html.contains("#i-git-branch"));
        assert!(!html.contains("style="));
    }
}