Skip to content

Commit 61b162a

Browse files
authored
Lib: adds the intersection observer API (#1063)
1 parent 90be416 commit 61b162a

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
class type intersectionObserverEntry =
2+
object
3+
method target : Dom.node Js.t Js.readonly_prop
4+
5+
method boundingClientRect : Dom_html.clientRect Js.t Js.readonly_prop
6+
7+
method rootBounds : Dom_html.clientRect Js.t Js.readonly_prop
8+
9+
method intersectionRect : Dom_html.clientRect Js.t Js.readonly_prop
10+
11+
method intersectionRatio : float Js.t Js.readonly_prop
12+
13+
method isIntersecting : bool Js.t Js.readonly_prop
14+
(* Missing Dom.highResTimeStamp
15+
method time : Dom.highResTimeStamp Js.t Js.readonly_prop *)
16+
end
17+
18+
class type intersectionObserverOptions =
19+
object
20+
method root : Dom.node Js.t Js.writeonly_prop
21+
22+
method rootMargin : Js.js_string Js.t Js.writeonly_prop
23+
24+
method threshold : float Js.js_array Js.t Js.writeonly_prop
25+
end
26+
27+
class type intersectionObserver =
28+
object
29+
method root : Dom.node Js.t Js.readonly_prop
30+
31+
method rootMargin : Js.js_string Js.t Js.readonly_prop
32+
33+
method threshold : float Js.t Js.readonly_prop
34+
35+
method observe : #Dom.node Js.t -> unit Js.meth
36+
37+
method unobserve : #Dom.node Js.t -> unit Js.meth
38+
39+
method disconnect : unit Js.meth
40+
41+
method takeRecords : intersectionObserverEntry Js.t Js.js_array Js.meth
42+
end
43+
44+
let empty_intersection_observer_options () : intersectionObserverOptions Js.t =
45+
Js.Unsafe.obj [||]
46+
47+
let intersectionObserver_unsafe = Js.Unsafe.global##._IntersectionObserver
48+
49+
let is_supported () = Js.Optdef.test intersectionObserver_unsafe
50+
51+
let intersectionObserver :
52+
( ( intersectionObserverEntry Js.t Js.js_array Js.t
53+
-> intersectionObserver Js.t
54+
-> unit)
55+
Js.callback
56+
-> intersectionObserverOptions Js.t
57+
-> intersectionObserver Js.t)
58+
Js.constr =
59+
intersectionObserver_unsafe
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
(** The Intersection Observer API provides a way to asynchronously observe
2+
changes in the intersection of a target element with an ancestor element or
3+
with a top-level document's viewport.
4+
5+
https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API *)
6+
7+
class type intersectionObserverEntry =
8+
object
9+
method target : Dom.node Js.t Js.readonly_prop
10+
11+
method boundingClientRect : Dom_html.clientRect Js.t Js.readonly_prop
12+
13+
method rootBounds : Dom_html.clientRect Js.t Js.readonly_prop
14+
15+
method intersectionRect : Dom_html.clientRect Js.t Js.readonly_prop
16+
17+
method intersectionRatio : float Js.t Js.readonly_prop
18+
19+
method isIntersecting : bool Js.t Js.readonly_prop
20+
(* Missing Dom.highResTimeStamp
21+
method time : Dom.highResTimeStamp Js.t Js.readonly_prop *)
22+
end
23+
24+
class type intersectionObserverOptions =
25+
object
26+
method root : Dom.node Js.t Js.writeonly_prop
27+
28+
method rootMargin : Js.js_string Js.t Js.writeonly_prop
29+
30+
method threshold : float Js.js_array Js.t Js.writeonly_prop
31+
end
32+
33+
class type intersectionObserver =
34+
object
35+
method root : Dom.node Js.t Js.readonly_prop
36+
37+
method rootMargin : Js.js_string Js.t Js.readonly_prop
38+
39+
method threshold : float Js.t Js.readonly_prop
40+
41+
method observe : #Dom.node Js.t -> unit Js.meth
42+
43+
method unobserve : #Dom.node Js.t -> unit Js.meth
44+
45+
method disconnect : unit Js.meth
46+
47+
method takeRecords : intersectionObserverEntry Js.t Js.js_array Js.meth
48+
end
49+
50+
val empty_intersection_observer_options : unit -> intersectionObserverOptions Js.t
51+
52+
val is_supported : unit -> bool
53+
54+
val intersectionObserver :
55+
( ( intersectionObserverEntry Js.t Js.js_array Js.t
56+
-> intersectionObserver Js.t
57+
-> unit)
58+
Js.callback
59+
-> intersectionObserverOptions Js.t
60+
-> intersectionObserver Js.t)
61+
Js.constr

0 commit comments

Comments
 (0)