#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]
#[macro_use]
extern crate alloc;
#[macro_use]
extern crate log;
#[allow(unused_imports)]
use alloc::{boxed::Box, vec::Vec};
pub use fixed;
pub use num_traits;
#[cfg(feature = "wasm-entrance")]
use wasm_bindgen::prelude::*;
#[cfg(debug_assertions)]
mod check_trait;
mod group;
mod path;
pub use group::{StyleSheetGroup, StyleSheetImportIndex, StyleSheetResource, TEMP_SHEET_INDEX};
pub mod sheet;
pub use sheet::{LinkedStyleSheet, StyleSheet};
pub mod property;
pub mod query;
mod resolve_font_size;
pub mod typing;
mod typing_stringify;
pub use query::{EnvValues, MediaQueryStatus, StyleQuery};
pub mod ffi;
pub mod length_num;
pub mod parser;
#[cfg(debug_assertions)]
use check_trait::CompatibilityCheck;
#[cfg(all(target_arch = "wasm32", feature = "wasm-entrance"))]
fn init_logger() {
use std::sync::Once;
static INIT: Once = Once::new();
INIT.call_once(|| {
console_log::init_with_level(log::Level::Debug).unwrap();
});
}
#[cfg(all(target_arch = "wasm32", feature = "wasm-entrance"))]
#[wasm_bindgen(start)]
pub fn wasm_main() {
init_logger();
console_error_panic_hook::set_once();
}
#[doc(hidden)]
#[cfg(all(feature = "serialize", feature = "serialize_json"))]
#[cfg_attr(
feature = "wasm-entrance",
wasm_bindgen(js_name = "compileStyleSheetToJson")
)]
pub fn compile_style_sheet_to_json(filename: &str, style_text: &str) -> String {
let (style_sheet, warnings) = parser::parse_style_sheet(filename, style_text);
for w in warnings {
warn!(
"{} (at {:?}, from line {:?} column {:?} to line {:?} column {:?})",
w.message.as_str(),
filename,
w.start_line,
w.start_col,
w.end_line,
w.end_col,
);
}
style_sheet.serialize_json()
}
#[cfg(feature = "serialize")]
#[cfg_attr(
feature = "wasm-entrance",
wasm_bindgen(js_name = "compileStyleSheetToBincode")
)]
pub fn compile_style_sheet_to_bincode(filename: &str, style_text: &str) -> Vec<u8> {
let (style_sheet, warnings) = parser::parse_style_sheet(filename, style_text);
for w in warnings {
warn!(
"{} (at {:?}, from line {:?} column {:?} to line {:?} column {:?})",
w.message.as_str(),
filename,
w.start_line,
w.start_col,
w.end_line,
w.end_col,
);
}
style_sheet.serialize_bincode()
}
#[cfg(feature = "deserialize")]
#[cfg_attr(
feature = "wasm-entrance",
wasm_bindgen(js_name = "styleSheetFromBincode")
)]
pub fn style_sheet_from_bincode(bincode: Vec<u8>) -> StyleSheetGroup {
let ptr = Box::into_raw(bincode.into_boxed_slice());
let mut ssg = StyleSheetGroup::new();
let mut resource = StyleSheetResource::new();
unsafe {
resource.add_bincode_zero_copy("", ptr, move || drop(Box::from_raw(ptr)));
}
ssg.append_from_resource(&resource, "", None);
ssg
}