mod style_provider;
pub use style_provider::{StyleProvider, StyleSurface};
fn viewer_bundle() -> &'static str {
include_str!(concat!(env!("OUT_DIR"), "/css/_viewer_bundle.css"))
}
fn column_dropdown_bundle() -> &'static str {
include_str!(concat!(env!("OUT_DIR"), "/css/_column_dropdown.css"))
}
fn filter_dropdown_bundle() -> &'static str {
include_str!(concat!(env!("OUT_DIR"), "/css/_filter_dropdown.css"))
}
fn function_dropdown_bundle() -> &'static str {
include_str!(concat!(env!("OUT_DIR"), "/css/_function_dropdown.css"))
}
fn dropdown_menu_bundle() -> &'static str {
include_str!(concat!(env!("OUT_DIR"), "/css/_dropdown_menu.css"))
}
thread_local! {
static VIEWER_SHEET: web_sys::CssStyleSheet = make_sheet(viewer_bundle());
static COLUMN_DROPDOWN_SHEET: web_sys::CssStyleSheet = make_sheet(column_dropdown_bundle());
static FILTER_DROPDOWN_SHEET: web_sys::CssStyleSheet = make_sheet(filter_dropdown_bundle());
static FUNCTION_DROPDOWN_SHEET: web_sys::CssStyleSheet = make_sheet(function_dropdown_bundle());
static DROPDOWN_MENU_SHEET: web_sys::CssStyleSheet = make_sheet(dropdown_menu_bundle());
}
fn make_sheet(css: &str) -> web_sys::CssStyleSheet {
let sheet = web_sys::CssStyleSheet::new().unwrap();
sheet.replace_sync(css).unwrap();
sheet
}
pub(crate) fn surface_sheet(surface: StyleSurface) -> web_sys::CssStyleSheet {
match surface {
StyleSurface::Viewer => VIEWER_SHEET.with(|x| x.clone()),
StyleSurface::ColumnDropdown => COLUMN_DROPDOWN_SHEET.with(|x| x.clone()),
StyleSurface::FilterDropdown => FILTER_DROPDOWN_SHEET.with(|x| x.clone()),
StyleSurface::FunctionDropdown => FUNCTION_DROPDOWN_SHEET.with(|x| x.clone()),
StyleSurface::DropdownMenu => DROPDOWN_MENU_SHEET.with(|x| x.clone()),
}
}