#![allow(non_upper_case_globals)]
#[cfg(feature = "hot-reload-context")]
use crate::{map_global_attributes, map_svg_attributes};
use crate::{GlobalAttributes, SvgAttributes};
#[cfg(feature = "hot-reload-context")]
use dioxus_rsx::HotReloadingContext;
pub type AttributeDiscription = (&'static str, Option<&'static str>, bool);
macro_rules! impl_attribute {
(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident (DEFAULT),
) => {
pub const $fil: AttributeDiscription = (stringify!($fil), None, false);
};
(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident ($name:literal),
) => {
pub const $fil: AttributeDiscription = ($name, None, false);
};
(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident (volatile),
) => {
pub const $fil: AttributeDiscription = (stringify!($fil), None, true);
};
(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident (in $ns:literal),
) => {
pub const $fil: AttributeDiscription = (stringify!($fil), Some($ns), false)
};
(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident (in $ns:literal : volatile),
) => {
pub const $fil: AttributeDiscription = (stringify!($fil), Some($ns), true)
};
}
#[cfg(feature = "hot-reload-context")]
macro_rules! impl_attribute_match {
(
$attr:ident $fil:ident: $vil:ident (DEFAULT),
) => {
if $attr == stringify!($fil) {
return Some((stringify!($fil), None));
}
};
(
$attr:ident $fil:ident: $vil:ident (volatile),
) => {
if $attr == stringify!($fil) {
return Some((stringify!($fil), None));
}
};
(
$attr:ident $fil:ident: $vil:ident ($name:literal),
) => {
if $attr == stringify!($fil) {
return Some(($name, None));
}
};
(
$attr:ident $fil:ident: $vil:ident (in $ns:literal),
) => {
if $attr == stringify!($fil) {
return Some((stringify!(fil), Some(ns)));
}
};
}
macro_rules! impl_element {
(
$(#[$attr:meta])*
$name:ident None {
$(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
#[allow(non_camel_case_types)]
$(#[$attr])*
pub struct $name;
impl $name {
pub const TAG_NAME: &'static str = stringify!($name);
pub const NAME_SPACE: Option<&'static str> = None;
$(
impl_attribute!(
$(#[$attr_method])*
$fil: $vil ($extra),
);
)*
}
impl GlobalAttributes for $name {}
};
(
$(#[$attr:meta])*
$name:ident $namespace:literal {
$(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
#[allow(non_camel_case_types)]
$(#[$attr])*
pub struct $name;
impl SvgAttributes for $name {}
impl $name {
pub const TAG_NAME: &'static str = stringify!($name);
pub const NAME_SPACE: Option<&'static str> = Some($namespace);
$(
impl_attribute!(
$(#[$attr_method])*
$fil: $vil ($extra),
);
)*
}
};
(
$(#[$attr:meta])*
$element:ident [$name:literal, $namespace:tt] {
$(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
#[allow(non_camel_case_types)]
$(#[$attr])*
pub struct $element;
impl SvgAttributes for $element {}
impl $element {
pub const TAG_NAME: &'static str = $name;
pub const NAME_SPACE: Option<&'static str> = Some($namespace);
$(
impl_attribute!(
$(#[$attr_method])*
$fil: $vil ($extra),
);
)*
}
}
}
#[cfg(feature = "hot-reload-context")]
macro_rules! impl_element_match {
(
$el:ident $name:ident None {
$(
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
if $el == stringify!($name) {
return Some((stringify!($name), None));
}
};
(
$el:ident $name:ident $namespace:tt {
$(
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
if $el == stringify!($name) {
return Some((stringify!($name), Some(stringify!($namespace))));
}
};
}
#[cfg(feature = "hot-reload-context")]
macro_rules! impl_element_match_attributes {
(
$el:ident $attr:ident $name:ident None {
$(
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
if $el == stringify!($name) {
$(
impl_attribute_match!(
$attr $fil: $vil ($extra),
);
)*
}
};
(
$el:ident $attr:ident $name:ident $namespace:tt {
$(
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
if $el == stringify!($name) {
$(
impl_attribute_match!(
$attr $fil: $vil ($extra),
);
)*
}
}
}
macro_rules! builder_constructors {
(
$(
$(#[$attr:meta])*
$name:ident $namespace:tt {
$(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident $extra:tt,
)*
};
)*
) => {
#[cfg(feature = "hot-reload-context")]
pub struct HtmlCtx;
#[cfg(feature = "hot-reload-context")]
impl HotReloadingContext for HtmlCtx {
fn map_attribute(element: &str, attribute: &str) -> Option<(&'static str, Option<&'static str>)> {
$(
impl_element_match_attributes!(
element attribute $name $namespace {
$(
$fil: $vil $extra,
)*
}
);
)*
map_global_attributes(attribute).or_else(|| map_svg_attributes(attribute))
}
fn map_element(element: &str) -> Option<(&'static str, Option<&'static str>)> {
$(
impl_element_match!(
element $name $namespace {
$(
$fil: $vil $extra,
)*
}
);
)*
None
}
}
$(
impl_element!(
$(#[$attr])*
$name $namespace {
$(
$(#[$attr_method])*
$fil: $vil $extra,
)*
}
);
)*
};
}
// Organized in the same order as
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element
//
// Does not include obsolete elements.
//
// This namespace represents a collection of modern HTML-5 compatiable elements.
//
// This list does not include obsolete, deprecated, experimental, or poorly supported elements.
builder_constructors! {
// Document metadata
/// Build a
/// [`