|
| 1 | +/** |
| 2 | + * Spec: https://www.w3.org/TR/intersection-observer/ |
| 3 | + */ |
| 4 | + |
| 5 | +module IntersectionObserverEntry = { |
| 6 | + /** |
| 7 | + * Spec: https://www.w3.org/TR/intersection-observer/#intersection-observer-entry |
| 8 | + */ |
| 9 | + |
| 10 | + type t = Dom.intersectionObserverEntry |
| 11 | + |
| 12 | + /* Properties */ |
| 13 | + |
| 14 | + @get external time: t => float = "time" |
| 15 | + @get external rootBounds: t => Dom.domRect = "rootBounds" |
| 16 | + @get external boundingClientRect: t => Dom.domRect = "boundingClientRect" |
| 17 | + @get external intersectionRect: t => Dom.domRect = "intersectionRect" |
| 18 | + @get external isIntersecting: t => bool = "isIntersecting" |
| 19 | + @get external intersectionRatio: t => float = "intersectionRatio" |
| 20 | + @get external target: t => Dom.element = "target" |
| 21 | +} |
| 22 | + |
| 23 | +type t = Dom.intersectionObserver |
| 24 | + |
| 25 | +type intersectionObserverInit = { |
| 26 | + root: option<Dom.element>, |
| 27 | + rootMargin: option<string>, |
| 28 | + threshold: option<array<float>>, // between 0 and 1. |
| 29 | +} |
| 30 | + |
| 31 | +@obj |
| 32 | +external makeInit: ( |
| 33 | + ~root: Dom.element=?, |
| 34 | + ~rootMargin: string=?, |
| 35 | + ~threshold: array<float>=?, |
| 36 | + unit, |
| 37 | +) => intersectionObserverInit = "" |
| 38 | + |
| 39 | +@new |
| 40 | +external make: (@uncurry (array<IntersectionObserverEntry.t>, t) => unit) => t = |
| 41 | + "IntersectionObserver" |
| 42 | + |
| 43 | +@new |
| 44 | +external makeWithInit: ( |
| 45 | + @uncurry (array<IntersectionObserverEntry.t>, t) => unit, |
| 46 | + intersectionObserverInit, |
| 47 | +) => t = "IntersectionObserver" |
| 48 | + |
| 49 | +/* Properties */ |
| 50 | + |
| 51 | +@get @return(nullable) |
| 52 | +external root: t => option<Dom.element> = "root" |
| 53 | +@get external rootMargin: t => string = "rootMargin" |
| 54 | +@get external thresholds: t => array<float> = "thresholds" |
| 55 | + |
| 56 | +/* Methods */ |
| 57 | + |
| 58 | +@send external disconnect: t => unit = "disconnect" |
| 59 | +@send external observe: (t, Dom.element) => unit = "observe" |
| 60 | +@send external unobserve: (t, Dom.element) => unit = "unobserve" |
| 61 | +@send external takeRecords: t => array<IntersectionObserverEntry.t> = "takeRecords" |
0 commit comments