diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index fc20a3f5d..05f683b6c 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -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 @@ -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] diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index fc20a3f5d..05f683b6c 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -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 @@ -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] diff --git a/dom/src/main/scala-2/org/scalajs/dom/ResizeObserverBoxOption.scala b/dom/src/main/scala-2/org/scalajs/dom/ResizeObserverBoxOption.scala new file mode 100644 index 000000000..9e4e40894 --- /dev/null +++ b/dom/src/main/scala-2/org/scalajs/dom/ResizeObserverBoxOption.scala @@ -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] +} diff --git a/dom/src/main/scala-3/org/scalajs/dom/ResizeObserverBoxOption.scala b/dom/src/main/scala-3/org/scalajs/dom/ResizeObserverBoxOption.scala new file mode 100644 index 000000000..fd6cbcf2e --- /dev/null +++ b/dom/src/main/scala-3/org/scalajs/dom/ResizeObserverBoxOption.scala @@ -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" +} diff --git a/dom/src/main/scala/org/scalajs/dom/DOMRect.scala b/dom/src/main/scala/org/scalajs/dom/DOMRect.scala index 3ad89901d..5d36618f2 100644 --- a/dom/src/main/scala/org/scalajs/dom/DOMRect.scala +++ b/dom/src/main/scala/org/scalajs/dom/DOMRect.scala @@ -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 } diff --git a/dom/src/main/scala/org/scalajs/dom/DOMRectReadOnly.scala b/dom/src/main/scala/org/scalajs/dom/DOMRectReadOnly.scala new file mode 100644 index 000000000..7b099aef7 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/DOMRectReadOnly.scala @@ -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 +} diff --git a/dom/src/main/scala/org/scalajs/dom/ResizeObserver.scala b/dom/src/main/scala/org/scalajs/dom/ResizeObserver.scala new file mode 100644 index 000000000..b220a17c0 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/ResizeObserver.scala @@ -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 +} diff --git a/dom/src/main/scala/org/scalajs/dom/ResizeObserverEntry.scala b/dom/src/main/scala/org/scalajs/dom/ResizeObserverEntry.scala new file mode 100644 index 000000000..da4ededdb --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/ResizeObserverEntry.scala @@ -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 +} diff --git a/dom/src/main/scala/org/scalajs/dom/ResizeObserverOptions.scala b/dom/src/main/scala/org/scalajs/dom/ResizeObserverOptions.scala new file mode 100644 index 000000000..0f0f37ed8 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/ResizeObserverOptions.scala @@ -0,0 +1,7 @@ +package org.scalajs.dom + +import scala.scalajs.js + +trait ResizeObserverOptions extends js.Object { + var box: js.UndefOr[ResizeObserverBoxOption] = js.undefined +} diff --git a/dom/src/main/scala/org/scalajs/dom/ResizeObserverSize.scala b/dom/src/main/scala/org/scalajs/dom/ResizeObserverSize.scala new file mode 100644 index 000000000..14eedb79c --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/ResizeObserverSize.scala @@ -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 +}