1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use super::*;
/// The IntersectionObserver class.
/// [`IntersectionObserver`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct IntersectionObserver {
inner: Any,
}
impl FromVal for IntersectionObserver {
fn from_val(v: &Any) -> Self {
IntersectionObserver {
inner: Any::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for IntersectionObserver {
type Target = Any;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for IntersectionObserver {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for IntersectionObserver {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for IntersectionObserver {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<IntersectionObserver> for Any {
fn from(s: IntersectionObserver) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&IntersectionObserver> for Any {
fn from(s: &IntersectionObserver) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(IntersectionObserver);
impl IntersectionObserver {
/// Getter of the `root` attribute.
/// [`IntersectionObserver.root`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/root)
pub fn root(&self) -> Any {
self.inner.get("root").as_::<Any>()
}
}
impl IntersectionObserver {
/// Getter of the `rootMargin` attribute.
/// [`IntersectionObserver.rootMargin`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin)
pub fn root_margin(&self) -> JsString {
self.inner.get("rootMargin").as_::<JsString>()
}
}
impl IntersectionObserver {
/// Getter of the `scrollMargin` attribute.
/// [`IntersectionObserver.scrollMargin`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/scrollMargin)
pub fn scroll_margin(&self) -> JsString {
self.inner.get("scrollMargin").as_::<JsString>()
}
}
impl IntersectionObserver {
/// Getter of the `thresholds` attribute.
/// [`IntersectionObserver.thresholds`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/thresholds)
pub fn thresholds(&self) -> TypedArray<f64> {
self.inner.get("thresholds").as_::<TypedArray<f64>>()
}
}
impl IntersectionObserver {
/// Getter of the `delay` attribute.
/// [`IntersectionObserver.delay`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/delay)
pub fn delay(&self) -> i32 {
self.inner.get("delay").as_::<i32>()
}
}
impl IntersectionObserver {
/// Getter of the `trackVisibility` attribute.
/// [`IntersectionObserver.trackVisibility`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/trackVisibility)
pub fn track_visibility(&self) -> bool {
self.inner.get("trackVisibility").as_::<bool>()
}
}
impl IntersectionObserver {
/// The `new IntersectionObserver(..)` constructor, creating a new IntersectionObserver instance
pub fn new(callback: &Function) -> IntersectionObserver {
Self {
inner: Any::global("IntersectionObserver")
.new(&[callback.into()])
.as_::<Any>(),
}
}
}
impl IntersectionObserver {
/// The `new IntersectionObserver(..)` constructor, creating a new IntersectionObserver instance
pub fn new_with_options(
callback: &Function,
options: &IntersectionObserverInit,
) -> IntersectionObserver {
Self {
inner: Any::global("IntersectionObserver")
.new(&[callback.into(), options.into()])
.as_::<Any>(),
}
}
}
impl IntersectionObserver {
/// The observe method.
/// [`IntersectionObserver.observe`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/observe)
pub fn observe(&self, target: &Element) -> Undefined {
self.inner
.call("observe", &[target.into()])
.as_::<Undefined>()
}
}
impl IntersectionObserver {
/// The unobserve method.
/// [`IntersectionObserver.unobserve`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/unobserve)
pub fn unobserve(&self, target: &Element) -> Undefined {
self.inner
.call("unobserve", &[target.into()])
.as_::<Undefined>()
}
}
impl IntersectionObserver {
/// The disconnect method.
/// [`IntersectionObserver.disconnect`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/disconnect)
pub fn disconnect(&self) -> Undefined {
self.inner.call("disconnect", &[]).as_::<Undefined>()
}
}
impl IntersectionObserver {
/// The takeRecords method.
/// [`IntersectionObserver.takeRecords`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/takeRecords)
pub fn take_records(&self) -> TypedArray<IntersectionObserverEntry> {
self.inner
.call("takeRecords", &[])
.as_::<TypedArray<IntersectionObserverEntry>>()
}
}