Skip to content

Commit 7d0508c

Browse files
authored
Merge pull request #805 from lindholc/intersection-observer
Add facade for Intersection Observer API
2 parents 9d7e1b7 + 70f1ee5 commit 7d0508c

7 files changed

+200
-0
lines changed

api-reports/2_12.txt

+28
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,10 @@ DOMRect[JC] def x: Double
15021502
DOMRect[JC] def x_ = (x: Double): Unit
15031503
DOMRect[JC] def y: Double
15041504
DOMRect[JC] def y_ = (y: Double): Unit
1505+
DOMRectInit[JT] var height: js.UndefOr[Double]
1506+
DOMRectInit[JT] var width: js.UndefOr[Double]
1507+
DOMRectInit[JT] var x: js.UndefOr[Double]
1508+
DOMRectInit[JT] var y: js.UndefOr[Double]
15051509
DOMRectList[JC] @JSBracketAccess def apply(index: Int): T
15061510
DOMRectList[JC] def length: Int
15071511
DOMRectReadOnly[JT] def bottom: Double
@@ -15531,6 +15535,30 @@ InputType[SO] val insertReplacementText: InputType
1553115535
InputType[SO] val insertText: InputType
1553215536
InputType[SO] val insertTranspose: InputType
1553315537
InputType[SO] val insertUnorderedList: InputType
15538+
IntersectionObserver[JC] def disconnect(): Unit
15539+
IntersectionObserver[JC] def observe(target: Element): Unit
15540+
IntersectionObserver[JC] def root: Document | Element
15541+
IntersectionObserver[JC] def rootMargin: String
15542+
IntersectionObserver[JC] def takeRecords(): js.Array[IntersectionObserverEntry]
15543+
IntersectionObserver[JC] def thresholds: FrozenArray[Double]
15544+
IntersectionObserver[JC] def unobserve(target: Element): Unit
15545+
IntersectionObserverEntry[JC] def boundingClientRect: DOMRectReadOnly
15546+
IntersectionObserverEntry[JC] def intersectionRatio: Double
15547+
IntersectionObserverEntry[JC] def intersectionRect: DOMRectReadOnly
15548+
IntersectionObserverEntry[JC] def isIntersecting: Boolean
15549+
IntersectionObserverEntry[JC] def rootBounds: DOMRectReadOnly
15550+
IntersectionObserverEntry[JC] def target: Element
15551+
IntersectionObserverEntry[JC] def time: Double
15552+
IntersectionObserverEntryInit[JT] var boundingClientRect: DOMRectInit
15553+
IntersectionObserverEntryInit[JT] var intersectionRatio: Double
15554+
IntersectionObserverEntryInit[JT] var intersectionRect: DOMRectInit
15555+
IntersectionObserverEntryInit[JT] var isIntersecting: Boolean
15556+
IntersectionObserverEntryInit[JT] var rootBounds: DOMRectInit
15557+
IntersectionObserverEntryInit[JT] var target: Element
15558+
IntersectionObserverEntryInit[JT] var time: Double
15559+
IntersectionObserverInit[JT] var root: js.UndefOr[Document | Element]
15560+
IntersectionObserverInit[JT] var rootMargin: js.UndefOr[String]
15561+
IntersectionObserverInit[JT] var threshold: js.UndefOr[Double | js.Array[Double]]
1553415562
JsonWebKey[JT] var alg: js.Array[String]
1553515563
JsonWebKey[JT] var crv: String
1553615564
JsonWebKey[JT] var d: String

api-reports/2_13.txt

+28
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,10 @@ DOMRect[JC] def x: Double
15021502
DOMRect[JC] def x_ = (x: Double): Unit
15031503
DOMRect[JC] def y: Double
15041504
DOMRect[JC] def y_ = (y: Double): Unit
1505+
DOMRectInit[JT] var height: js.UndefOr[Double]
1506+
DOMRectInit[JT] var width: js.UndefOr[Double]
1507+
DOMRectInit[JT] var x: js.UndefOr[Double]
1508+
DOMRectInit[JT] var y: js.UndefOr[Double]
15051509
DOMRectList[JC] @JSBracketAccess def apply(index: Int): T
15061510
DOMRectList[JC] def length: Int
15071511
DOMRectReadOnly[JT] def bottom: Double
@@ -15531,6 +15535,30 @@ InputType[SO] val insertReplacementText: InputType
1553115535
InputType[SO] val insertText: InputType
1553215536
InputType[SO] val insertTranspose: InputType
1553315537
InputType[SO] val insertUnorderedList: InputType
15538+
IntersectionObserver[JC] def disconnect(): Unit
15539+
IntersectionObserver[JC] def observe(target: Element): Unit
15540+
IntersectionObserver[JC] def root: Document | Element
15541+
IntersectionObserver[JC] def rootMargin: String
15542+
IntersectionObserver[JC] def takeRecords(): js.Array[IntersectionObserverEntry]
15543+
IntersectionObserver[JC] def thresholds: FrozenArray[Double]
15544+
IntersectionObserver[JC] def unobserve(target: Element): Unit
15545+
IntersectionObserverEntry[JC] def boundingClientRect: DOMRectReadOnly
15546+
IntersectionObserverEntry[JC] def intersectionRatio: Double
15547+
IntersectionObserverEntry[JC] def intersectionRect: DOMRectReadOnly
15548+
IntersectionObserverEntry[JC] def isIntersecting: Boolean
15549+
IntersectionObserverEntry[JC] def rootBounds: DOMRectReadOnly
15550+
IntersectionObserverEntry[JC] def target: Element
15551+
IntersectionObserverEntry[JC] def time: Double
15552+
IntersectionObserverEntryInit[JT] var boundingClientRect: DOMRectInit
15553+
IntersectionObserverEntryInit[JT] var intersectionRatio: Double
15554+
IntersectionObserverEntryInit[JT] var intersectionRect: DOMRectInit
15555+
IntersectionObserverEntryInit[JT] var isIntersecting: Boolean
15556+
IntersectionObserverEntryInit[JT] var rootBounds: DOMRectInit
15557+
IntersectionObserverEntryInit[JT] var target: Element
15558+
IntersectionObserverEntryInit[JT] var time: Double
15559+
IntersectionObserverInit[JT] var root: js.UndefOr[Document | Element]
15560+
IntersectionObserverInit[JT] var rootMargin: js.UndefOr[String]
15561+
IntersectionObserverInit[JT] var threshold: js.UndefOr[Double | js.Array[Double]]
1553415562
JsonWebKey[JT] var alg: js.Array[String]
1553515563
JsonWebKey[JT] var crv: String
1553615564
JsonWebKey[JT] var d: String
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
trait DOMRectInit extends js.Object {
6+
var x: js.UndefOr[Double] = js.undefined
7+
8+
var y: js.UndefOr[Double] = js.undefined
9+
10+
var width: js.UndefOr[Double] = js.undefined
11+
12+
var height: js.UndefOr[Double] = js.undefined
13+
}
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+
options: IntersectionObserverInit = js.native
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: FrozenArray[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+
}
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+
}
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: DOMRectInit
8+
9+
var intersectionRatio: Double
10+
11+
var intersectionRect: DOMRectInit
12+
13+
var isIntersecting: Boolean
14+
15+
var rootBounds: DOMRectInit
16+
17+
var target: Element
18+
19+
var time: Double
20+
}
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)