webbind/
lib.rs

1#![allow(unused_imports)]
2#![allow(non_camel_case_types)]
3#![allow(clippy::new_without_default)]
4#![allow(clippy::useless_conversion)]
5#![allow(clippy::too_many_arguments)]
6#![no_std]
7
8extern crate alloc;
9
10use alloc::string::String;
11use jsbind::prelude::*;
12
13#[allow(unused_macros)]
14macro_rules! web_feature {
15    ($feature:literal, $mod_ident:ident, $path:literal, $type_ident:ident) => {
16        #[cfg(feature = $feature)]
17        #[path = $path]
18        pub mod $mod_ident;
19        #[cfg(feature = $feature)]
20        pub use $mod_ident::*;
21
22        #[cfg(not(feature = $feature))]
23        pub type $type_ident = Any;
24    };
25}
26
27include!(concat!(env!("OUT_DIR"), "/generated_mods.rs"));
28
29pub fn window() -> Window {
30    Any::global("window").as_::<Window>()
31}
32
33pub use jsbind::prelude::atob;
34pub use jsbind::prelude::btoa;
35pub use jsbind::prelude::is_nan;
36pub use jsbind::prelude::parse_float;
37pub use jsbind::prelude::parse_int;
38pub use jsbind::prelude::queue_microtask;
39pub use jsbind::prelude::{JsStructuredSerializeOptions, structured_clone};
40
41pub fn report_error(error: &jsbind::prelude::JsError) {
42    Any::global("reportError").invoke(&[error.into()]);
43}
44
45pub fn caches() -> CacheStorage {
46    Any::global("caches").as_()
47}
48
49pub fn cross_origin_isolated() -> bool {
50    Any::global("crossOriginIsolated").as_::<bool>()
51}
52
53pub fn crypto() -> Crypto {
54    Any::global("crypto").as_()
55}
56
57pub fn indexed_db() -> IDBFactory {
58    Any::global("indexedDB").as_()
59}
60
61pub fn is_secure_context() -> bool {
62    Any::global("isSecureContext").as_()
63}
64
65pub fn origin() -> jsbind::prelude::JsString {
66    Any::global("origin").as_()
67}
68
69// #[cfg(feature = "Performance")]
70pub fn performance() -> self::performance::Performance {
71    Any::global("performance").as_()
72}
73
74pub fn create_image_bitmap0(
75    image: &jsbind::prelude::Any,
76) -> jsbind::prelude::Promise<Result<ImageBitmap, JsError>> {
77    Any::global("createImageBitmap")
78        .invoke(&[image.clone()])
79        .as_()
80}
81
82pub fn create_image_bitmap1(
83    image: &jsbind::prelude::Any,
84    options: &jsbind::prelude::Object,
85) -> jsbind::prelude::Promise<Result<ImageBitmap, JsError>> {
86    Any::global("createImageBitmap")
87        .invoke(&[image.clone(), options.into()])
88        .as_()
89}
90
91pub fn create_image_bitmap2(
92    image: &jsbind::prelude::Any,
93    sx: f64,
94    sy: f64,
95    sw: f64,
96    sh: f64,
97) -> jsbind::prelude::Promise<Result<ImageBitmap, JsError>> {
98    Any::global("createImageBitmap")
99        .invoke(&[image.clone(), sx.into(), sy.into(), sw.into(), sh.into()])
100        .as_()
101}
102
103pub fn create_image_bitmap3(
104    image: &jsbind::prelude::Any,
105    sx: f64,
106    sy: f64,
107    sw: f64,
108    sh: f64,
109    options: &jsbind::prelude::Object,
110) -> jsbind::prelude::Promise<Result<ImageBitmap, JsError>> {
111    Any::global("createImageBitmap")
112        .invoke(&[
113            image.clone(),
114            sx.into(),
115            sy.into(),
116            sw.into(),
117            sh.into(),
118            options.into(),
119        ])
120        .as_()
121}