pub mod element {
#[doc(alias = "script")]
#[non_exhaustive]
#[derive(PartialEq, Clone, Default)]
pub struct Script {
sys: html_sys::scripting::Script,
children: Vec<super::child::ScriptChild>,
}
impl Script {
pub fn builder() -> super::builder::ScriptBuilder {
super::builder::ScriptBuilder::new(Default::default())
}
}
impl Script {
pub fn data_map(&self) -> &html_sys::DataMap {
&self.sys.data_map
}
pub fn data_map_mut(&mut self) -> &mut html_sys::DataMap {
&mut self.sys.data_map
}
}
impl Script {
pub fn src(&self) -> std::option::Option<&str> {
self.sys.src.as_deref()
}
pub fn set_src(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.src = value.map(|v| v.into());
}
pub fn type_(&self) -> std::option::Option<&str> {
self.sys.type_.as_deref()
}
pub fn set_type_(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.type_ = value.map(|v| v.into());
}
pub fn nomodule(&self) -> std::option::Option<&str> {
self.sys.nomodule.as_deref()
}
pub fn set_nomodule(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.nomodule = value.map(|v| v.into());
}
pub fn async_(&self) -> std::option::Option<&str> {
self.sys.async_.as_deref()
}
pub fn set_async_(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.async_ = value.map(|v| v.into());
}
pub fn defer(&self) -> std::option::Option<&str> {
self.sys.defer.as_deref()
}
pub fn set_defer(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.defer = value.map(|v| v.into());
}
pub fn crossorigin(&self) -> std::option::Option<&str> {
self.sys.crossorigin.as_deref()
}
pub fn set_crossorigin(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.crossorigin = value.map(|v| v.into());
}
pub fn integrity(&self) -> std::option::Option<&str> {
self.sys.integrity.as_deref()
}
pub fn set_integrity(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.integrity = value.map(|v| v.into());
}
pub fn referrerpolicy(&self) -> std::option::Option<&str> {
self.sys.referrerpolicy.as_deref()
}
pub fn set_referrerpolicy(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.referrerpolicy = value.map(|v| v.into());
}
pub fn blocking(&self) -> std::option::Option<&str> {
self.sys.blocking.as_deref()
}
pub fn set_blocking(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.blocking = value.map(|v| v.into());
}
pub fn fetchpriority(&self) -> std::option::Option<&str> {
self.sys.fetchpriority.as_deref()
}
pub fn set_fetchpriority(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.fetchpriority = value.map(|v| v.into());
}
pub fn access_key(&self) -> std::option::Option<&str> {
self.sys.access_key.as_deref()
}
pub fn set_access_key(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.access_key = value.map(|v| v.into());
}
pub fn auto_capitalize(&self) -> std::option::Option<&str> {
self.sys.auto_capitalize.as_deref()
}
pub fn set_auto_capitalize(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.auto_capitalize = value.map(|v| v.into());
}
pub fn autofocus(&self) -> bool {
self.sys.autofocus
}
pub fn set_autofocus(&mut self, value: bool) {
self.sys.autofocus = value;
}
pub fn class(&self) -> std::option::Option<&str> {
self.sys.class.as_deref()
}
pub fn set_class(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.class = value.map(|v| v.into());
}
pub fn content_editable(&self) -> std::option::Option<&str> {
self.sys.content_editable.as_deref()
}
pub fn set_content_editable(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.content_editable = value.map(|v| v.into());
}
pub fn direction(&self) -> std::option::Option<&str> {
self.sys.direction.as_deref()
}
pub fn set_direction(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.direction = value.map(|v| v.into());
}
pub fn draggable(&self) -> bool {
self.sys.draggable
}
pub fn set_draggable(&mut self, value: bool) {
self.sys.draggable = value;
}
pub fn enter_key_hint(&self) -> std::option::Option<&str> {
self.sys.enter_key_hint.as_deref()
}
pub fn set_enter_key_hint(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.enter_key_hint = value.map(|v| v.into());
}
pub fn export_parts(&self) -> std::option::Option<&str> {
self.sys.export_parts.as_deref()
}
pub fn set_export_parts(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.export_parts = value.map(|v| v.into());
}
pub fn hidden(&self) -> std::option::Option<&str> {
self.sys.hidden.as_deref()
}
pub fn set_hidden(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.hidden = value.map(|v| v.into());
}
pub fn id(&self) -> std::option::Option<&str> {
self.sys.id.as_deref()
}
pub fn set_id(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.id = value.map(|v| v.into());
}
pub fn inert(&self) -> bool {
self.sys.inert
}
pub fn set_inert(&mut self, value: bool) {
self.sys.inert = value;
}
pub fn input_mode(&self) -> std::option::Option<&str> {
self.sys.input_mode.as_deref()
}
pub fn set_input_mode(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.input_mode = value.map(|v| v.into());
}
pub fn is_(&self) -> std::option::Option<&str> {
self.sys.is_.as_deref()
}
pub fn set_is_(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.is_ = value.map(|v| v.into());
}
pub fn item_id(&self) -> std::option::Option<&str> {
self.sys.item_id.as_deref()
}
pub fn set_item_id(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.item_id = value.map(|v| v.into());
}
pub fn item_prop(&self) -> std::option::Option<&str> {
self.sys.item_prop.as_deref()
}
pub fn set_item_prop(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.item_prop = value.map(|v| v.into());
}
pub fn item_ref(&self) -> std::option::Option<&str> {
self.sys.item_ref.as_deref()
}
pub fn set_item_ref(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.item_ref = value.map(|v| v.into());
}
pub fn item_scope(&self) -> std::option::Option<&str> {
self.sys.item_scope.as_deref()
}
pub fn set_item_scope(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.item_scope = value.map(|v| v.into());
}
pub fn item_type(&self) -> std::option::Option<&str> {
self.sys.item_type.as_deref()
}
pub fn set_item_type(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.item_type = value.map(|v| v.into());
}
pub fn lang(&self) -> std::option::Option<&str> {
self.sys.lang.as_deref()
}
pub fn set_lang(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.lang = value.map(|v| v.into());
}
pub fn nonce(&self) -> std::option::Option<&str> {
self.sys.nonce.as_deref()
}
pub fn set_nonce(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.nonce = value.map(|v| v.into());
}
pub fn part(&self) -> std::option::Option<&str> {
self.sys.part.as_deref()
}
pub fn set_part(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.part = value.map(|v| v.into());
}
pub fn slot(&self) -> std::option::Option<&str> {
self.sys.slot.as_deref()
}
pub fn set_slot(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.slot = value.map(|v| v.into());
}
pub fn spellcheck(&self) -> std::option::Option<&str> {
self.sys.spellcheck.as_deref()
}
pub fn set_spellcheck(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.spellcheck = value.map(|v| v.into());
}
pub fn style(&self) -> std::option::Option<&str> {
self.sys.style.as_deref()
}
pub fn set_style(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.style = value.map(|v| v.into());
}
pub fn tab_index(&self) -> std::option::Option<i64> {
self.sys.tab_index
}
pub fn set_tab_index(&mut self, value: std::option::Option<i64>) {
self.sys.tab_index = value;
}
pub fn title(&self) -> std::option::Option<&str> {
self.sys.title.as_deref()
}
pub fn set_title(
&mut self,
value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
) {
self.sys.title = value.map(|v| v.into());
}
pub fn translate(&self) -> bool {
self.sys.translate
}
pub fn set_translate(&mut self, value: bool) {
self.sys.translate = value;
}
}
impl Script {
pub fn children(&self) -> &[super::child::ScriptChild] {
self.children.as_ref()
}
pub fn children_mut(&mut self) -> &mut Vec<super::child::ScriptChild> {
&mut self.children
}
}
impl crate::Render for Script {
fn render(
&self,
f: &mut std::fmt::Formatter<'_>,
depth: usize,
) -> std::fmt::Result {
write!(f, "{:level$}", "", level = depth * 4)?;
html_sys::RenderElement::write_opening_tag(&self.sys, f)?;
if !self.children.is_empty() {
write!(f, "\n")?;
}
for el in &self.children {
crate::Render::render(&el, f, depth)?;
write!(f, "\n")?;
}
write!(f, "{:level$}", "", level = depth * 4)?;
html_sys::RenderElement::write_closing_tag(&self.sys, f)?;
Ok(())
}
}
impl std::fmt::Debug for Script {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
crate::Render::render(self, f, 0)?;
Ok(())
}
}
impl std::fmt::Display for Script {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
html_sys::RenderElement::write_opening_tag(&self.sys, f)?;
for el in &self.children {
write!(f, "{el}")?;
}
html_sys::RenderElement::write_closing_tag(&self.sys, f)?;
Ok(())
}
}
impl crate::HtmlElement for Script {}
impl crate::MetadataContent for Script {}
impl crate::FlowContent for Script {}
impl crate::PhrasingContent for Script {}
impl crate::ScriptSupportingContent for Script {}
impl std::convert::Into<html_sys::scripting::Script> for Script {
fn into(self) -> html_sys::scripting::Script {
self.sys
}
}
impl From<html_sys::scripting::Script> for Script {
fn from(sys: html_sys::scripting::Script) -> Self {
Self { sys, children: vec![] }
}
}
}
pub mod child {
#[derive(PartialEq, Clone)]
pub enum ScriptChild {
Text(std::borrow::Cow<'static, str>),
}
impl std::convert::From<std::borrow::Cow<'static, str>> for ScriptChild {
fn from(value: std::borrow::Cow<'static, str>) -> Self {
Self::Text(value)
}
}
impl std::convert::From<&'static str> for ScriptChild {
fn from(value: &'static str) -> Self {
Self::Text(value.into())
}
}
impl std::convert::From<String> for ScriptChild {
fn from(value: String) -> Self {
Self::Text(value.into())
}
}
impl crate::Render for ScriptChild {
fn render(
&self,
f: &mut std::fmt::Formatter<'_>,
depth: usize,
) -> std::fmt::Result {
match self {
Self::Text(el) => crate::Render::render(el, f, depth + 1),
}
}
}
impl std::fmt::Debug for ScriptChild {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
crate::Render::render(self, f, 0)?;
Ok(())
}
}
impl std::fmt::Display for ScriptChild {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Text(el) => write!(f, "{el}"),
}
}
}
}
pub mod builder {
pub struct ScriptBuilder {
element: super::element::Script,
}
impl ScriptBuilder {
pub(crate) fn new(element: super::element::Script) -> Self {
Self { element }
}
pub fn build(&mut self) -> super::element::Script {
self.element.clone()
}
pub fn data(
&mut self,
data_key: impl Into<std::borrow::Cow<'static, str>>,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut ScriptBuilder {
self.element.data_map_mut().insert(data_key.into(), value.into());
self
}
pub fn text(
&mut self,
s: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
let cow = s.into();
self.element.children_mut().push(cow.into());
self
}
pub fn src(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_src(Some(value.into()));
self
}
pub fn type_(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_type_(Some(value.into()));
self
}
pub fn nomodule(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_nomodule(Some(value.into()));
self
}
pub fn async_(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_async_(Some(value.into()));
self
}
pub fn defer(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_defer(Some(value.into()));
self
}
pub fn crossorigin(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_crossorigin(Some(value.into()));
self
}
pub fn integrity(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_integrity(Some(value.into()));
self
}
pub fn referrerpolicy(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_referrerpolicy(Some(value.into()));
self
}
pub fn blocking(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_blocking(Some(value.into()));
self
}
pub fn fetchpriority(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_fetchpriority(Some(value.into()));
self
}
pub fn access_key(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_access_key(Some(value.into()));
self
}
pub fn auto_capitalize(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_auto_capitalize(Some(value.into()));
self
}
pub fn autofocus(&mut self, value: bool) -> &mut Self {
self.element.set_autofocus(value);
self
}
pub fn class(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_class(Some(value.into()));
self
}
pub fn content_editable(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_content_editable(Some(value.into()));
self
}
pub fn direction(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_direction(Some(value.into()));
self
}
pub fn draggable(&mut self, value: bool) -> &mut Self {
self.element.set_draggable(value);
self
}
pub fn enter_key_hint(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_enter_key_hint(Some(value.into()));
self
}
pub fn export_parts(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_export_parts(Some(value.into()));
self
}
pub fn hidden(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_hidden(Some(value.into()));
self
}
pub fn id(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_id(Some(value.into()));
self
}
pub fn inert(&mut self, value: bool) -> &mut Self {
self.element.set_inert(value);
self
}
pub fn input_mode(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_input_mode(Some(value.into()));
self
}
pub fn is_(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_is_(Some(value.into()));
self
}
pub fn item_id(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_item_id(Some(value.into()));
self
}
pub fn item_prop(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_item_prop(Some(value.into()));
self
}
pub fn item_ref(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_item_ref(Some(value.into()));
self
}
pub fn item_scope(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_item_scope(Some(value.into()));
self
}
pub fn item_type(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_item_type(Some(value.into()));
self
}
pub fn lang(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_lang(Some(value.into()));
self
}
pub fn nonce(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_nonce(Some(value.into()));
self
}
pub fn part(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_part(Some(value.into()));
self
}
pub fn slot(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_slot(Some(value.into()));
self
}
pub fn spellcheck(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_spellcheck(Some(value.into()));
self
}
pub fn style(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_style(Some(value.into()));
self
}
pub fn tab_index(&mut self, value: i64) -> &mut Self {
self.element.set_tab_index(Some(value));
self
}
pub fn title(
&mut self,
value: impl Into<std::borrow::Cow<'static, str>>,
) -> &mut Self {
self.element.set_title(Some(value.into()));
self
}
pub fn translate(&mut self, value: bool) -> &mut Self {
self.element.set_translate(value);
self
}
pub fn push<T>(&mut self, child_el: T) -> &mut Self
where
T: Into<crate::generated::all::children::ScriptChild>,
{
let child_el = child_el.into();
self.element.children_mut().push(child_el);
self
}
pub fn extend<I, T>(&mut self, iter: I) -> &mut Self
where
I: IntoIterator<Item = T>,
T: Into<crate::generated::all::children::ScriptChild>,
{
let iter = iter.into_iter().map(|child_el| child_el.into());
self.element.children_mut().extend(iter);
self
}
}
}