use viewpoint_js::js;
fn main() {
println!("=== Simple Expressions ===");
let simple = js! { 1 + 2 };
println!("1 + 2: {simple}");
let arrow = js! { () => window.innerWidth };
println!("Arrow function: {arrow}");
let selector = "li";
let multiline = js! {
(() => {
const items = document.querySelectorAll(#{selector});
return items.length;
})()
};
println!("IIFE: {multiline}");
println!("\n=== Interpolation ===");
let selector = ".my-class";
let with_string = js! { document.querySelector(#{selector}) };
println!("With string interpolation: {with_string}");
let count = 42;
let with_number = js! { Array(#{count}).fill(0) };
println!("With number interpolation: {with_number}");
let is_visible = true;
let with_bool = js! { element.hidden = !#{is_visible} };
println!("With bool interpolation: {with_bool}");
println!("\n=== Option Handling ===");
let some_value: Option<i32> = Some(100);
let with_some = js! { console.log(#{some_value}) };
println!("With Some value: {with_some}");
let none_value: Option<i32> = None;
let with_none = js! { console.log(#{none_value}) };
println!("With None value: {with_none}");
println!("\n=== Multiple Interpolations ===");
let x = 10;
let y = 20;
let multiple = js! { ({ x: #{x}, y: #{y} }) };
println!("Multiple values: {multiple}");
println!("\n=== String Escaping ===");
let message = "Hello \"World\"!\nNew line here.";
let escaped = js! { alert(#{message}) };
println!("Escaped string: {escaped}");
println!("\n=== Complex Expressions ===");
let len = 5;
let complex = js! {
(() => {
const result = [];
for (let i = 0; i < #{len}; i++) {
result.push(i);
}
return result;
})()
};
println!("Complex expression: {complex}");
println!("\n=== Output Types ===");
let static_str: &'static str = js! { window.location.href };
println!("Static str type: {static_str}");
let val = 1;
let dynamic_string: String = js! { console.log(#{val}) };
println!("Dynamic String type: {dynamic_string}");
println!("\n=== All examples completed! ===");
}