-
Notifications
You must be signed in to change notification settings - Fork 161
Add facade for Intersection Observer API #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c497fef
Add facade for Intersection Observer API
lindholc c7f1c14
Use FrozenArray
lindholc cecd5af
Make options an optional argument
lindholc 8483fee
Add DOMRectInit
lindholc 2dc2bcb
Use DOMRectInit
lindholc 70f1ee5
Update api-reports
lindholc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
dom/src/main/scala/org/scalajs/dom/IntersectionObserver.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSGlobal | ||
import scala.scalajs.js.| | ||
|
||
/** The IntersectionObserver interface of the Intersection Observer API provides a way to asynchronously observe changes | ||
* in the intersection of a target element with an ancestor element or with a top-level document's viewport. | ||
*/ | ||
@js.native | ||
@JSGlobal | ||
class IntersectionObserver( | ||
callback: js.Function2[js.Array[IntersectionObserverEntry], IntersectionObserver, Unit], | ||
init: IntersectionObserverInit | ||
) extends js.Object { | ||
|
||
/** The Element or Document whose bounds are used as the bounding box when testing for intersection. If no root value | ||
* was passed to the constructor or its value is null, the top-level document's viewport is used. | ||
*/ | ||
def root: Document | Element = js.native | ||
|
||
/** An offset rectangle applied to the root's bounding box when calculating intersections, effectively shrinking or | ||
* growing the root for calculation purposes. The value returned by this property may not be the same as the one | ||
* specified when calling the constructor as it may be changed to match internal requirements. Each offset can be | ||
* expressed in pixels (px) or as a percentage (%). The default is "0px 0px 0px 0px". | ||
*/ | ||
def rootMargin: String = js.native | ||
|
||
/** A list of thresholds, sorted in increasing numeric order, where each threshold is a ratio of intersection area to | ||
* bounding box area of an observed target. Notifications for a target are generated when any of the thresholds are | ||
* crossed for that target. If no value was passed to the constructor, 0 is used. | ||
*/ | ||
def thresholds: js.Array[Double] = js.native | ||
lindholc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Stops the IntersectionObserver object from observing any target. */ | ||
def disconnect(): Unit = js.native | ||
|
||
/** Tells the IntersectionObserver a target element to observe. */ | ||
def observe(target: Element): Unit = js.native | ||
|
||
/** Returns an array of IntersectionObserverEntry objects for all observed targets. */ | ||
def takeRecords(): js.Array[IntersectionObserverEntry] = js.native | ||
|
||
/** Tells the IntersectionObserver to stop observing a particular target element. */ | ||
def unobserve(target: Element): Unit = js.native | ||
} |
38 changes: 38 additions & 0 deletions
38
dom/src/main/scala/org/scalajs/dom/IntersectionObserverEntry.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSGlobal | ||
|
||
/** The IntersectionObserverEntry interface of the Intersection Observer API describes the intersection between the | ||
* target element and its root container at a specific moment of transition. | ||
*/ | ||
@js.native | ||
@JSGlobal | ||
class IntersectionObserverEntry(init: IntersectionObserverEntryInit) extends js.Object { | ||
|
||
/** The bounds rectangle of the target element as a DOMRectReadOnly. */ | ||
def boundingClientRect: DOMRectReadOnly = js.native | ||
|
||
/** The ratio of the intersectionRect to the boundingClientRect. */ | ||
def intersectionRatio: Double = js.native | ||
|
||
/** A DOMRectReadOnly representing the target's visible area. */ | ||
def intersectionRect: DOMRectReadOnly = js.native | ||
|
||
/** A Boolean value which is true if the target element intersects with the intersection observer's root. If this is | ||
* true, then, the IntersectionObserverEntry describes a transition into a state of intersection; if it's false, then | ||
* you know the transition is from intersecting to not-intersecting. | ||
*/ | ||
def isIntersecting: Boolean = js.native | ||
|
||
/** A DOMRectReadOnly for the intersection observer's root. */ | ||
def rootBounds: DOMRectReadOnly = js.native | ||
|
||
/** The Element whose intersection with the root changed. */ | ||
def target: Element = js.native | ||
|
||
/** A DOMHighResTimeStamp indicating the time at which the intersection was recorded, relative to the | ||
* IntersectionObserver's time origin. | ||
*/ | ||
def time: Double = js.native | ||
} |
20 changes: 20 additions & 0 deletions
20
dom/src/main/scala/org/scalajs/dom/IntersectionObserverEntryInit.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
|
||
trait IntersectionObserverEntryInit extends js.Object { | ||
|
||
var boundingClientRect: DOMRect | ||
lindholc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var intersectionRatio: Double | ||
|
||
var intersectionRect: DOMRect | ||
lindholc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var isIntersecting: Boolean | ||
|
||
var rootBounds: DOMRect | ||
lindholc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var target: Element | ||
|
||
var time: Double | ||
} |
27 changes: 27 additions & 0 deletions
27
dom/src/main/scala/org/scalajs/dom/IntersectionObserverInit.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.scalajs.dom | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.| | ||
|
||
/** An object which customizes the observer. */ | ||
trait IntersectionObserverInit extends js.Object { | ||
|
||
/** An Element or Document object which is an ancestor of the intended target, whose bounding rectangle will be | ||
* considered the viewport. Any part of the target not visible in the visible area of the root is not considered | ||
* visible. | ||
*/ | ||
var root: js.UndefOr[Document | Element] = js.undefined | ||
|
||
/** A string which specifies a set of offsets to add to the root's bounding_box when calculating intersections, | ||
* effectively shrinking or growing the root for calculation purposes. The syntax is approximately the same as that | ||
* for the CSS margin property; see The intersection root and root margin for more information on how the margin | ||
* works and the syntax. The default is "0px 0px 0px 0px". | ||
*/ | ||
var rootMargin: js.UndefOr[String] = js.undefined | ||
|
||
/** Either a single number or an array of numbers between 0.0 and 1.0, specifying a ratio of intersection area to | ||
* total bounding box area for the observed target. A value of 0.0 means that even a single visible pixel counts as | ||
* the target being visible. 1.0 means that the entire target element is visible. The default is a threshold of 0.0. | ||
*/ | ||
var threshold: js.UndefOr[Double | js.Array[Double]] = js.undefined | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.