Skip to content

Commit c497fef

Browse files
committed
Add facade for Intersection Observer API
1 parent 9d7e1b7 commit c497fef

File tree

6 files changed

+179
-0
lines changed

6 files changed

+179
-0
lines changed

api-reports/2_12.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15531,6 +15531,30 @@ InputType[SO] val insertReplacementText: InputType
1553115531
InputType[SO] val insertText: InputType
1553215532
InputType[SO] val insertTranspose: InputType
1553315533
InputType[SO] val insertUnorderedList: InputType
15534+
IntersectionObserver[JC] def disconnect(): Unit
15535+
IntersectionObserver[JC] def observe(target: Element): Unit
15536+
IntersectionObserver[JC] def root: Document | Element
15537+
IntersectionObserver[JC] def rootMargin: String
15538+
IntersectionObserver[JC] def takeRecords(): js.Array[IntersectionObserverEntry]
15539+
IntersectionObserver[JC] def thresholds: js.Array[Double]
15540+
IntersectionObserver[JC] def unobserve(target: Element): Unit
15541+
IntersectionObserverEntry[JC] def boundingClientRect: DOMRectReadOnly
15542+
IntersectionObserverEntry[JC] def intersectionRatio: Double
15543+
IntersectionObserverEntry[JC] def intersectionRect: DOMRectReadOnly
15544+
IntersectionObserverEntry[JC] def isIntersecting: Boolean
15545+
IntersectionObserverEntry[JC] def rootBounds: DOMRectReadOnly
15546+
IntersectionObserverEntry[JC] def target: Element
15547+
IntersectionObserverEntry[JC] def time: Double
15548+
IntersectionObserverEntryInit[JT] var boundingClientRect: DOMRect
15549+
IntersectionObserverEntryInit[JT] var intersectionRatio: Double
15550+
IntersectionObserverEntryInit[JT] var intersectionRect: DOMRect
15551+
IntersectionObserverEntryInit[JT] var isIntersecting: Boolean
15552+
IntersectionObserverEntryInit[JT] var rootBounds: DOMRect
15553+
IntersectionObserverEntryInit[JT] var target: Element
15554+
IntersectionObserverEntryInit[JT] var time: Double
15555+
IntersectionObserverInit[JT] var root: js.UndefOr[Document | Element]
15556+
IntersectionObserverInit[JT] var rootMargin: js.UndefOr[String]
15557+
IntersectionObserverInit[JT] var threshold: js.UndefOr[Double | js.Array[Double]]
1553415558
JsonWebKey[JT] var alg: js.Array[String]
1553515559
JsonWebKey[JT] var crv: String
1553615560
JsonWebKey[JT] var d: String

api-reports/2_13.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15531,6 +15531,30 @@ InputType[SO] val insertReplacementText: InputType
1553115531
InputType[SO] val insertText: InputType
1553215532
InputType[SO] val insertTranspose: InputType
1553315533
InputType[SO] val insertUnorderedList: InputType
15534+
IntersectionObserver[JC] def disconnect(): Unit
15535+
IntersectionObserver[JC] def observe(target: Element): Unit
15536+
IntersectionObserver[JC] def root: Document | Element
15537+
IntersectionObserver[JC] def rootMargin: String
15538+
IntersectionObserver[JC] def takeRecords(): js.Array[IntersectionObserverEntry]
15539+
IntersectionObserver[JC] def thresholds: js.Array[Double]
15540+
IntersectionObserver[JC] def unobserve(target: Element): Unit
15541+
IntersectionObserverEntry[JC] def boundingClientRect: DOMRectReadOnly
15542+
IntersectionObserverEntry[JC] def intersectionRatio: Double
15543+
IntersectionObserverEntry[JC] def intersectionRect: DOMRectReadOnly
15544+
IntersectionObserverEntry[JC] def isIntersecting: Boolean
15545+
IntersectionObserverEntry[JC] def rootBounds: DOMRectReadOnly
15546+
IntersectionObserverEntry[JC] def target: Element
15547+
IntersectionObserverEntry[JC] def time: Double
15548+
IntersectionObserverEntryInit[JT] var boundingClientRect: DOMRect
15549+
IntersectionObserverEntryInit[JT] var intersectionRatio: Double
15550+
IntersectionObserverEntryInit[JT] var intersectionRect: DOMRect
15551+
IntersectionObserverEntryInit[JT] var isIntersecting: Boolean
15552+
IntersectionObserverEntryInit[JT] var rootBounds: DOMRect
15553+
IntersectionObserverEntryInit[JT] var target: Element
15554+
IntersectionObserverEntryInit[JT] var time: Double
15555+
IntersectionObserverInit[JT] var root: js.UndefOr[Document | Element]
15556+
IntersectionObserverInit[JT] var rootMargin: js.UndefOr[String]
15557+
IntersectionObserverInit[JT] var threshold: js.UndefOr[Double | js.Array[Double]]
1553415558
JsonWebKey[JT] var alg: js.Array[String]
1553515559
JsonWebKey[JT] var crv: String
1553615560
JsonWebKey[JT] var d: String
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSGlobal
5+
import scala.scalajs.js.|
6+
7+
/** The IntersectionObserver interface of the Intersection Observer API provides a way to asynchronously observe changes
8+
* in the intersection of a target element with an ancestor element or with a top-level document's viewport.
9+
*/
10+
@js.native
11+
@JSGlobal
12+
class IntersectionObserver(
13+
callback: js.Function2[js.Array[IntersectionObserverEntry], IntersectionObserver, Unit],
14+
init: IntersectionObserverInit
15+
) extends js.Object {
16+
17+
/** The Element or Document whose bounds are used as the bounding box when testing for intersection. If no root value
18+
* was passed to the constructor or its value is null, the top-level document's viewport is used.
19+
*/
20+
def root: Document | Element = js.native
21+
22+
/** An offset rectangle applied to the root's bounding box when calculating intersections, effectively shrinking or
23+
* growing the root for calculation purposes. The value returned by this property may not be the same as the one
24+
* specified when calling the constructor as it may be changed to match internal requirements. Each offset can be
25+
* expressed in pixels (px) or as a percentage (%). The default is "0px 0px 0px 0px".
26+
*/
27+
def rootMargin: String = js.native
28+
29+
/** A list of thresholds, sorted in increasing numeric order, where each threshold is a ratio of intersection area to
30+
* bounding box area of an observed target. Notifications for a target are generated when any of the thresholds are
31+
* crossed for that target. If no value was passed to the constructor, 0 is used.
32+
*/
33+
def thresholds: js.Array[Double] = js.native
34+
35+
/** Stops the IntersectionObserver object from observing any target. */
36+
def disconnect(): Unit = js.native
37+
38+
/** Tells the IntersectionObserver a target element to observe. */
39+
def observe(target: Element): Unit = js.native
40+
41+
/** Returns an array of IntersectionObserverEntry objects for all observed targets. */
42+
def takeRecords(): js.Array[IntersectionObserverEntry] = js.native
43+
44+
/** Tells the IntersectionObserver to stop observing a particular target element. */
45+
def unobserve(target: Element): Unit = js.native
46+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSGlobal
5+
6+
/** The IntersectionObserverEntry interface of the Intersection Observer API describes the intersection between the
7+
* target element and its root container at a specific moment of transition.
8+
*/
9+
@js.native
10+
@JSGlobal
11+
class IntersectionObserverEntry(init: IntersectionObserverEntryInit) extends js.Object {
12+
13+
/** The bounds rectangle of the target element as a DOMRectReadOnly. */
14+
def boundingClientRect: DOMRectReadOnly = js.native
15+
16+
/** The ratio of the intersectionRect to the boundingClientRect. */
17+
def intersectionRatio: Double = js.native
18+
19+
/** A DOMRectReadOnly representing the target's visible area. */
20+
def intersectionRect: DOMRectReadOnly = js.native
21+
22+
/** A Boolean value which is true if the target element intersects with the intersection observer's root. If this is
23+
* true, then, the IntersectionObserverEntry describes a transition into a state of intersection; if it's false, then
24+
* you know the transition is from intersecting to not-intersecting.
25+
*/
26+
def isIntersecting: Boolean = js.native
27+
28+
/** A DOMRectReadOnly for the intersection observer's root. */
29+
def rootBounds: DOMRectReadOnly = js.native
30+
31+
/** The Element whose intersection with the root changed. */
32+
def target: Element = js.native
33+
34+
/** A DOMHighResTimeStamp indicating the time at which the intersection was recorded, relative to the
35+
* IntersectionObserver's time origin.
36+
*/
37+
def time: Double = js.native
38+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
trait IntersectionObserverEntryInit extends js.Object {
6+
7+
var boundingClientRect: DOMRect
8+
9+
var intersectionRatio: Double
10+
11+
var intersectionRect: DOMRect
12+
13+
var isIntersecting: Boolean
14+
15+
var rootBounds: DOMRect
16+
17+
var target: Element
18+
19+
var time: Double
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.|
5+
6+
/** An object which customizes the observer. */
7+
trait IntersectionObserverInit extends js.Object {
8+
9+
/** An Element or Document object which is an ancestor of the intended target, whose bounding rectangle will be
10+
* considered the viewport. Any part of the target not visible in the visible area of the root is not considered
11+
* visible.
12+
*/
13+
var root: js.UndefOr[Document | Element] = js.undefined
14+
15+
/** A string which specifies a set of offsets to add to the root's bounding_box when calculating intersections,
16+
* effectively shrinking or growing the root for calculation purposes. The syntax is approximately the same as that
17+
* for the CSS margin property; see The intersection root and root margin for more information on how the margin
18+
* works and the syntax. The default is "0px 0px 0px 0px".
19+
*/
20+
var rootMargin: js.UndefOr[String] = js.undefined
21+
22+
/** Either a single number or an array of numbers between 0.0 and 1.0, specifying a ratio of intersection area to
23+
* total bounding box area for the observed target. A value of 0.0 means that even a single visible pixel counts as
24+
* the target being visible. 1.0 means that the entire target element is visible. The default is a threshold of 0.0.
25+
*/
26+
var threshold: js.UndefOr[Double | js.Array[Double]] = js.undefined
27+
}

0 commit comments

Comments
 (0)