#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum StyleSurface {
#[default]
Viewer,
ColumnDropdown,
FilterDropdown,
FunctionDropdown,
DropdownMenu,
ContextMenu,
}
impl StyleSurface {
pub fn sheet(self) -> web_sys::CssStyleSheet {
match self {
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()),
StyleSurface::ContextMenu => CONTEXT_MENU_SHEET.with(|x| x.clone()),
}
}
}
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"))
}
fn context_menu_bundle() -> &'static str {
include_str!(concat!(env!("OUT_DIR"), "/css/_context_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());
static CONTEXT_MENU_SHEET: web_sys::CssStyleSheet = make_sheet(context_menu_bundle());
}
fn make_sheet(css: &str) -> web_sys::CssStyleSheet {
let sheet = web_sys::CssStyleSheet::new().unwrap();
sheet.replace_sync(css).unwrap();
sheet
}