typstify_search_wasm/
lib.rs

1//! Typstify Search WASM Runtime
2//!
3//! Browser-side search using WebAssembly.
4//!
5//! # Features
6//!
7//! - **SimpleSearchEngine**: Lightweight JSON-based search for small sites (<500KB)
8//! - **SearchEngine**: Full chunked index support for larger sites (coming soon)
9//! - **Chunk caching**: Efficient network usage with `scc::HashMap`
10//!
11//! # Example (JavaScript)
12//!
13//! ```javascript
14//! import { SimpleSearchEngine } from 'typstify-search-wasm';
15//!
16//! // Load index
17//! const engine = await new SimpleSearchEngine('/search.json');
18//!
19//! // Search
20//! const results = engine.search('rust programming', 10);
21//! console.log(results);
22//! ```
23
24pub mod directory;
25pub mod query;
26pub mod simple;
27
28pub use directory::{DirectoryError, FileManifest, HttpDirectory, IndexManifest};
29pub use query::{SearchQuery, SearchResult, SearchResults};
30pub use simple::{SimpleDocument, SimpleSearchEngine, SimpleSearchIndex};
31use wasm_bindgen::prelude::*;
32
33/// Initialize the WASM module.
34///
35/// Sets up panic hook for better error messages in the console.
36#[wasm_bindgen(start)]
37pub fn init() {
38    console_error_panic_hook::set_once();
39}
40
41/// Get the version of the search library.
42#[wasm_bindgen(js_name = getVersion)]
43pub fn get_version() -> String {
44    env!("CARGO_PKG_VERSION").to_string()
45}
46
47/// Check if the library is ready.
48#[wasm_bindgen(js_name = isReady)]
49pub fn is_ready() -> bool {
50    true
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_get_version() {
59        let version = get_version();
60        assert!(!version.is_empty());
61        assert!(version.starts_with("0."));
62    }
63
64    #[test]
65    fn test_is_ready() {
66        assert!(is_ready());
67    }
68}