#![forbid(unsafe_code)]
#![deny(missing_docs)]
#![warn(clippy::pedantic)]
use core::hash::{Hash, Hasher};
use yew::html::{ChildrenRenderer, IntoPropValue};
use yew::virtual_dom::{VNode, VRaw};
use yew::{AttrValue, Html};
#[derive(Clone, Copy, Ord, PartialOrd, Eq)]
#[repr(transparent)]
pub struct BI(pub(crate) &'static str);
impl BI {
#[inline]
pub const fn html(self) -> Html {
VNode::VRaw(VRaw {
html: AttrValue::Static(self.0),
})
}
#[inline]
#[must_use]
pub const fn raw_html(self) -> &'static str {
self.0
}
}
impl PartialEq for BI {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.0.as_ptr() as usize == other.0.as_ptr() as usize && self.0.len() == other.0.len()
}
}
impl Hash for BI {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
(self.0.as_ptr() as usize + (self.0.len() >> 1)).hash(state);
}
}
impl From<BI> for Html {
#[inline]
fn from(value: BI) -> Self {
value.html()
}
}
impl From<&BI> for Html {
#[allow(clippy::inline_always)]
#[inline(always)]
fn from(value: &BI) -> Self {
Html::from(*value)
}
}
impl IntoPropValue<ChildrenRenderer<VNode>> for BI {
#[inline]
fn into_prop_value(self) -> ChildrenRenderer<VNode> {
self.html().into_prop_value()
}
}
impl IntoPropValue<ChildrenRenderer<VNode>> for &BI {
#[allow(clippy::inline_always)]
#[inline(always)]
fn into_prop_value(self) -> ChildrenRenderer<VNode> {
(*self).into_prop_value()
}
}
impl IntoPropValue<Html> for BI {
#[inline]
fn into_prop_value(self) -> Html {
self.html()
}
}
impl IntoPropValue<Html> for &BI {
#[allow(clippy::inline_always)]
#[inline(always)]
fn into_prop_value(self) -> Html {
(*self).into_prop_value()
}
}
pub struct BIFiles {
pub css: &'static str,
pub font_woff: &'static [u8],
pub font_woff2: &'static [u8],
pub license: &'static str,
}
macro_rules! version {
() => {
"v1.11.3"
};
}
macro_rules! path {
() => {
concat!("../../bootstrap-icons-", version!(), "/")
};
}
impl BIFiles {
pub const VERSION: &'static str = version!();
pub const NAME: &'static str = concat!("bootstrap-icons-", version!());
pub const FILES: Self = Self {
css: include_str!(concat!(path!(), "bootstrap-icons.css")),
font_woff: include_bytes!(concat!(path!(), "fonts/bootstrap-icons.woff")),
font_woff2: include_bytes!(concat!(path!(), "fonts/bootstrap-icons.woff2")),
license: include_str!(concat!(path!(), "fonts/LICENSE")),
};
pub const fn cdn() -> VNode {
VNode::VRaw(VRaw {
html: AttrValue::Static(concat!(
r#"<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@"#,
version!(),
r#"/font/bootstrap-icons.css">"#
)),
})
}
pub fn copy(to: &std::path::Path) -> Result<(), std::io::Error> {
let BIFiles {
css,
font_woff,
font_woff2,
license,
} = Self::FILES;
let fonts = to.join("fonts");
if !fonts.is_dir() {
std::fs::create_dir(&fonts)?;
}
std::fs::write(to.join("bootstrap-icons.css"), css)?;
std::fs::write(fonts.join("bootstrap-icons.woff"), font_woff)?;
std::fs::write(fonts.join("bootstrap-icons.woff2"), font_woff2)?;
std::fs::write(fonts.join("LICENSE"), license)?;
Ok(())
}
}
include!(concat!(env!("OUT_DIR"), "/bootstrap_icons_generated.rs"));