1#![allow(incomplete_features)]
9#![cfg_attr(
10 all(feature = "nightly", rustc_nightly),
11 feature(unsized_const_params)
12)]
13#![cfg_attr(all(feature = "nightly", rustc_nightly), feature(adt_const_params))]
16#![deny(missing_docs)]
17
18pub mod prelude {
20 pub use crate::{
21 html::{
22 attribute::{
23 any_attribute::IntoAnyAttribute,
24 aria::AriaAttributes,
25 custom::CustomAttribute,
26 global::{
27 ClassAttribute, GlobalAttributes, GlobalOnAttributes,
28 OnAttribute, OnTargetAttribute, PropAttribute,
29 StyleAttribute,
30 },
31 IntoAttributeValue,
32 },
33 directive::DirectiveAttribute,
34 element::{ElementChild, ElementExt, InnerHtmlAttribute},
35 node_ref::NodeRefAttribute,
36 },
37 renderer::{dom::Dom, Renderer},
38 view::{
39 add_attr::AddAnyAttr,
40 any_view::{AnyView, IntoAny, IntoMaybeErased},
41 IntoRender, Mountable, Render, RenderHtml,
42 },
43 };
44}
45
46use wasm_bindgen::JsValue;
47use web_sys::Node;
48
49pub mod dom;
51pub mod html;
53pub mod hydration;
55pub mod mathml;
57pub mod renderer;
59pub mod ssr;
61pub mod svg;
63pub mod view;
65
66pub use either_of as either;
67#[cfg(feature = "islands")]
68#[doc(hidden)]
69pub use wasm_bindgen;
70#[cfg(feature = "islands")]
71#[doc(hidden)]
72pub use web_sys;
73
74#[cfg(feature = "oco")]
76pub mod oco;
77#[cfg(feature = "reactive_graph")]
79pub mod reactive_graph;
80
81pub mod erased;
83
84pub(crate) trait UnwrapOrDebug {
85 type Output;
86
87 fn or_debug(self, el: &Node, label: &'static str);
88
89 fn ok_or_debug(
90 self,
91 el: &Node,
92 label: &'static str,
93 ) -> Option<Self::Output>;
94}
95
96impl<T> UnwrapOrDebug for Result<T, JsValue> {
97 type Output = T;
98
99 #[track_caller]
100 fn or_debug(self, el: &Node, name: &'static str) {
101 #[cfg(any(debug_assertions, leptos_debuginfo))]
102 {
103 if let Err(err) = self {
104 let location = std::panic::Location::caller();
105 web_sys::console::warn_3(
106 &JsValue::from_str(&format!(
107 "[WARNING] Non-fatal error at {location}, while \
108 calling {name} on "
109 )),
110 el,
111 &err,
112 );
113 }
114 }
115 #[cfg(not(any(debug_assertions, leptos_debuginfo)))]
116 {
117 _ = self;
118 }
119 }
120
121 #[track_caller]
122 fn ok_or_debug(
123 self,
124 el: &Node,
125 name: &'static str,
126 ) -> Option<Self::Output> {
127 #[cfg(any(debug_assertions, leptos_debuginfo))]
128 {
129 if let Err(err) = &self {
130 let location = std::panic::Location::caller();
131 web_sys::console::warn_3(
132 &JsValue::from_str(&format!(
133 "[WARNING] Non-fatal error at {location}, while \
134 calling {name} on "
135 )),
136 el,
137 err,
138 );
139 }
140 self.ok()
141 }
142 #[cfg(not(any(debug_assertions, leptos_debuginfo)))]
143 {
144 self.ok()
145 }
146 }
147}
148
149#[doc(hidden)]
150#[macro_export]
151macro_rules! or_debug {
152 ($action:expr, $el:expr, $label:literal) => {
153 if cfg!(any(debug_assertions, leptos_debuginfo)) {
154 $crate::UnwrapOrDebug::or_debug($action, $el, $label);
155 } else {
156 _ = $action;
157 }
158 };
159}
160
161#[doc(hidden)]
162#[macro_export]
163macro_rules! ok_or_debug {
164 ($action:expr, $el:expr, $label:literal) => {
165 if cfg!(any(debug_assertions, leptos_debuginfo)) {
166 $crate::UnwrapOrDebug::ok_or_debug($action, $el, $label)
167 } else {
168 $action.ok()
169 }
170 };
171}