Skip to content

Add Façade Types to Support ResizeObserver #694

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 11 commits into from
Apr 21, 2022
41 changes: 35 additions & 6 deletions api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1237,14 +1237,28 @@ DOMList[SO] def iterator: Iterator[T]
DOMList[SO] def length: Int
DOMList[SO] def next(): T
DOMParser[JC] def parseFromString(string: String, mimeType: MIMEType): Document
DOMRect[JC] var bottom: Double
DOMRect[JC] var height: Double
DOMRect[JC] var left: Double
DOMRect[JC] var right: Double
DOMRect[JC] var top: Double
DOMRect[JC] var width: Double
DOMRect[JC] def bottom: Double
DOMRect[JC] def height: Double
DOMRect[JC] def height_ = (height: Double): Unit
DOMRect[JC] def left: Double
DOMRect[JC] def right: Double
DOMRect[JC] def top: Double
DOMRect[JC] def width: Double
DOMRect[JC] def width_ = (width: Double): Unit
DOMRect[JC] def x: Double
DOMRect[JC] def x_ = (x: Double): Unit
DOMRect[JC] def y: Double
DOMRect[JC] def y_ = (y: Double): Unit
DOMRectList[JC] @JSBracketAccess def apply(index: Int): T
DOMRectList[JC] def length: Int
DOMRectReadOnly[JT] def bottom: Double
DOMRectReadOnly[JT] def height: Double
DOMRectReadOnly[JT] def left: Double
DOMRectReadOnly[JT] def right: Double
DOMRectReadOnly[JT] def top: Double
DOMRectReadOnly[JT] def width: Double
DOMRectReadOnly[JT] def x: Double
DOMRectReadOnly[JT] def y: Double
DOMSettableTokenList[JT] def add(token: String): Unit
DOMSettableTokenList[JT] @JSBracketAccess def apply(index: Int): T
DOMSettableTokenList[JT] def contains(token: String): Boolean
Expand Down Expand Up @@ -15948,6 +15962,21 @@ RequestType[SO] val script: RequestType
RequestType[SO] val style: RequestType
RequestType[SO] val track: RequestType
RequestType[SO] val video: RequestType
ResizeObserver[JC] def disconnect(): Unit
ResizeObserver[JC] def observe(target: Element): Unit
ResizeObserver[JC] def observe(target: Element, options: ResizeObserverOptions): Unit
ResizeObserver[JC] def unobserve(target: Element): Unit
ResizeObserverBoxOption[JT]
ResizeObserverBoxOption[SO] val `border-box`: ResizeObserverBoxOption
ResizeObserverBoxOption[SO] val `content-box`: ResizeObserverBoxOption
ResizeObserverBoxOption[SO] val `device-pixel-content-box`: ResizeObserverBoxOption
ResizeObserverEntry[JT] def borderBoxSize: js.Array[ResizeObserverSize]
ResizeObserverEntry[JT] def contentBoxSize: js.Array[ResizeObserverSize]
ResizeObserverEntry[JT] def contentRect: DOMRectReadOnly
ResizeObserverEntry[JT] def target: Element
ResizeObserverOptions[JT] var box: js.UndefOr[ResizeObserverBoxOption]
ResizeObserverSize[JT] def blockSize: Double
ResizeObserverSize[JT] def inlineSize: Double
Response[JC] def arrayBuffer(): js.Promise[ArrayBuffer]
Response[JC] def blob(): js.Promise[Blob]
Response[JC] val body: ReadableStream[Uint8Array]
Expand Down
41 changes: 35 additions & 6 deletions api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1237,14 +1237,28 @@ DOMList[SO] def iterator: Iterator[T]
DOMList[SO] def length: Int
DOMList[SO] def next(): T
DOMParser[JC] def parseFromString(string: String, mimeType: MIMEType): Document
DOMRect[JC] var bottom: Double
DOMRect[JC] var height: Double
DOMRect[JC] var left: Double
DOMRect[JC] var right: Double
DOMRect[JC] var top: Double
DOMRect[JC] var width: Double
DOMRect[JC] def bottom: Double
DOMRect[JC] def height: Double
DOMRect[JC] def height_ = (height: Double): Unit
DOMRect[JC] def left: Double
DOMRect[JC] def right: Double
DOMRect[JC] def top: Double
DOMRect[JC] def width: Double
DOMRect[JC] def width_ = (width: Double): Unit
DOMRect[JC] def x: Double
DOMRect[JC] def x_ = (x: Double): Unit
DOMRect[JC] def y: Double
DOMRect[JC] def y_ = (y: Double): Unit
DOMRectList[JC] @JSBracketAccess def apply(index: Int): T
DOMRectList[JC] def length: Int
DOMRectReadOnly[JT] def bottom: Double
DOMRectReadOnly[JT] def height: Double
DOMRectReadOnly[JT] def left: Double
DOMRectReadOnly[JT] def right: Double
DOMRectReadOnly[JT] def top: Double
DOMRectReadOnly[JT] def width: Double
DOMRectReadOnly[JT] def x: Double
DOMRectReadOnly[JT] def y: Double
DOMSettableTokenList[JT] def add(token: String): Unit
DOMSettableTokenList[JT] @JSBracketAccess def apply(index: Int): T
DOMSettableTokenList[JT] def contains(token: String): Boolean
Expand Down Expand Up @@ -15948,6 +15962,21 @@ RequestType[SO] val script: RequestType
RequestType[SO] val style: RequestType
RequestType[SO] val track: RequestType
RequestType[SO] val video: RequestType
ResizeObserver[JC] def disconnect(): Unit
ResizeObserver[JC] def observe(target: Element): Unit
ResizeObserver[JC] def observe(target: Element, options: ResizeObserverOptions): Unit
ResizeObserver[JC] def unobserve(target: Element): Unit
ResizeObserverBoxOption[JT]
ResizeObserverBoxOption[SO] val `border-box`: ResizeObserverBoxOption
ResizeObserverBoxOption[SO] val `content-box`: ResizeObserverBoxOption
ResizeObserverBoxOption[SO] val `device-pixel-content-box`: ResizeObserverBoxOption
ResizeObserverEntry[JT] def borderBoxSize: js.Array[ResizeObserverSize]
ResizeObserverEntry[JT] def contentBoxSize: js.Array[ResizeObserverSize]
ResizeObserverEntry[JT] def contentRect: DOMRectReadOnly
ResizeObserverEntry[JT] def target: Element
ResizeObserverOptions[JT] var box: js.UndefOr[ResizeObserverBoxOption]
ResizeObserverSize[JT] def blockSize: Double
ResizeObserverSize[JT] def inlineSize: Double
Response[JC] def arrayBuffer(): js.Promise[ArrayBuffer]
Response[JC] def blob(): js.Promise[Blob]
Response[JC] val body: ReadableStream[Uint8Array]
Expand Down
13 changes: 13 additions & 0 deletions dom/src/main/scala-2/org/scalajs/dom/ResizeObserverBoxOption.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.scalajs.dom

import scala.scalajs.js

/** ResizeObserverOptions [[https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe]] */
@js.native
sealed trait ResizeObserverBoxOption extends js.Any

object ResizeObserverBoxOption {
val `content-box`: ResizeObserverBoxOption = "content-box".asInstanceOf[ResizeObserverBoxOption]
val `border-box`: ResizeObserverBoxOption = "border-box".asInstanceOf[ResizeObserverBoxOption]
val `device-pixel-content-box`: ResizeObserverBoxOption = "device-pixel-content-box".asInstanceOf[ResizeObserverBoxOption]
}
12 changes: 12 additions & 0 deletions dom/src/main/scala-3/org/scalajs/dom/ResizeObserverBoxOption.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.scalajs.dom

import scala.scalajs.js

/** ResizeObserverOptions [[https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe]] */
opaque type ResizeObserverBoxOption <: String = String

object ResizeObserverBoxOption {
val `content-box`: ResizeObserverBoxOption = "content-box"
val `border-box`: ResizeObserverBoxOption = "border-box"
val `device-pixel-content-box`: ResizeObserverBoxOption = "device-pixel-content-box"
}
13 changes: 6 additions & 7 deletions dom/src/main/scala/org/scalajs/dom/DOMRect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ package org.scalajs.dom
import scala.scalajs.js
import scala.scalajs.js.annotation._

/** A DOMRect describes the size and position of a rectangle. */
@js.native
@JSGlobal
class DOMRect extends js.Object {
var left: Double = js.native
var width: Double = js.native
var right: Double = js.native
var top: Double = js.native
var bottom: Double = js.native
var height: Double = js.native
class DOMRect extends DOMRectReadOnly {
def width_=(width: Double): Unit = js.native
def height_=(height: Double): Unit = js.native
def x_=(x: Double): Unit = js.native
def y_=(y: Double): Unit = js.native
}
31 changes: 31 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/DOMRectReadOnly.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.scalajs.dom

import scala.scalajs.js

@js.native
trait DOMRectReadOnly extends js.Object {

/** The x coordinate of the DOMRect's origin. */
def x: Double = js.native

/** The y coordinate of the DOMRect's origin. */
def y: Double = js.native

/** The width of the DOMRect. */
def width: Double = js.native

/** The height of the DOMRect. */
def height: Double = js.native

/** Returns the top coordinate value of the DOMRect (usually the same as y.) */
def top: Double = js.native

/** Returns the right coordinate value of the DOMRect (usually the same as x + width). */
def right: Double = js.native

/** Returns the bottom coordinate value of the DOMRect (usually the same as y + height) */
def bottom: Double = js.native

/** Returns the left coordinate value of the DOMRect (usually the same as x) */
def left: Double = js.native
}
25 changes: 25 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/ResizeObserver.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

/** The ResizeObserver constructor creates a new ResizeObserver object, which can be used to report changes to the
* content or border box of an Element or the bounding box of an SVGElement
*
* @param callback
* The function called whenever an observed resize occurs.
*/
@js.native
@JSGlobal
class ResizeObserver(callback: js.Function2[js.Array[ResizeObserverEntry], ResizeObserver, _]) extends js.Object {

/** Starts observing the specified Element or SVGElement. */
def observe(target: Element): Unit = js.native
def observe(target: Element, options: ResizeObserverOptions): Unit = js.native

/** Unobserves all observed Element or SVGElement targets. */
def disconnect(): Unit = js.native

/** Ends the observing of a specified Element or SVGElement. */
def unobserve(target: Element): Unit = js.native
}
30 changes: 30 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/ResizeObserverEntry.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.scalajs.dom

import scala.scalajs.js

/** The ResizeObserverEntry interface represents the object passedto the ResizeObserver() constructor's callback
* function, which allows you to access the new dimensions of the Element or SVGElement being observed.
*/
@js.native
trait ResizeObserverEntry extends js.Object {

/** A reference to the Element or SVGElement being observed */
def target: Element = js.native

/** An array containing objects with the new border box size of the observed element. The array is necessary to
* support elements that have multiple fragments, which occur in multi-column scenarios.
*/
def borderBoxSize: js.Array[ResizeObserverSize] = js.native

/** An array containing objects with the new content box size of the observed element. The array is necessary to
* support elements that have multiple fragments, which occur in multi-column scenarios.
*/
def contentBoxSize: js.Array[ResizeObserverSize] = js.native

/** A [[DOMRectReadOnly]] object containing the new size of the observed element when the callback is run. Note that
* this is better supported than the above two properties, but it is left over from an earlier implementation of the
* Resize Observer API, is still included in the spec for web compat reasons, and may be deprecated in future
* versions.
*/
def contentRect: DOMRectReadOnly = js.native
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.scalajs.dom

import scala.scalajs.js

trait ResizeObserverOptions extends js.Object {
var box: js.UndefOr[ResizeObserverBoxOption] = js.undefined
}
19 changes: 19 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/ResizeObserverSize.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.scalajs.dom

import scala.scalajs.js

@js.native
trait ResizeObserverSize extends js.Object {

/** The length of the observed element's border box in the block dimension. For boxes with a horizontal writing-mode,
* this is the vertical dimension, or height; if the writing-mode is vertical, this is the horizontal dimension, or
* width.
*/
def blockSize: Double = js.native

/** The length of the observed element's border box in the inline dimension. For boxes with a horizontal writing-mode,
* this is the horizontal dimension, or width; if the writing-mode is vertical, this is the vertical dimension, or
* height.
*/
def inlineSize: Double = js.native
}