Skip to main content

axis_core/
lib.rs

1//! # AXIS-CORE SDK
2//!
3//! A Rust library for automated web accessibility checking.
4//!
5//! ## Quick Start
6//!
7//! ```rust
8//! use axis_core::AxisCore;
9//!
10//! #[tokio::main]
11//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
12//!     let checker = AxisCore::new();
13//!     let report = checker.check_url("https://example.com").await?;
14//!
15//!     println!("Accessibility Score: {}/100", report.accessibility_score);
16//!     println!("Issues Found: {}", report.total_issues);
17//!
18//!     Ok(())
19//! }
20//! ```
21
22pub mod models;
23pub mod checker;
24pub mod parser;
25
26use crate::models::Report;
27use crate::checker::AccessibilityChecker;
28use crate::parser::HtmlParser;
29
30/// Main AXIS-CORE SDK struct
31pub struct AxisCore {
32    checker: AccessibilityChecker,
33    parser: HtmlParser,
34}
35
36impl AxisCore {
37    /// Create a new AXIS-CORE checker instance
38    pub fn new() -> Self {
39        Self {
40            checker: AccessibilityChecker::new(),
41            parser: HtmlParser::new(),
42        }
43    }
44
45    /// Check accessibility of a web page by URL
46    ///
47    /// # Example
48    /// ```rust
49    /// # use axis_core::AxisCore;
50    /// # #[tokio::main]
51    /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
52    /// let checker = AxisCore::new();
53    /// let report = checker.check_url("https://example.com").await?;
54    /// # Ok(())
55    /// # }
56    /// ```
57    pub async fn check_url(&self, url: &str) -> Result<Report, Box<dyn std::error::Error>> {
58        let load_result = self.parser.load_from_url(url).await?;
59        let report = self.checker.check_accessibility(load_result);
60        Ok(report)
61    }
62
63    /// Check accessibility of HTML content
64    ///
65    /// # Example
66    /// ```rust
67    /// # use axis_core::AxisCore;
68    /// let checker = AxisCore::new();
69    /// let html = r#"<html><body><img src="test.jpg" /></body></html>"#;
70    /// let report = checker.check_html(html, None);
71    /// // Missing alt text will be flagged
72    /// ```
73    pub fn check_html(&self, html: &str, base_url: Option<&str>) -> Report {
74        let load_result = self.parser.parse_html(html, base_url);
75        self.checker.check_accessibility(load_result)
76    }
77
78    /// Export a report to text format
79    pub fn export_to_text(&self, report: &Report) -> String {
80        self.checker.export_to_text(report)
81    }
82
83    /// Get the SDK version
84    pub fn version() -> &'static str {
85        env!("CARGO_PKG_VERSION")
86    }
87}
88
89impl Default for AxisCore {
90    fn default() -> Self {
91        Self::new()
92    }
93}