Skip to content

Commit 53832c8

Browse files
committed
Adding facade for ResizeObserver and required types
1 parent 59b5b89 commit 53832c8

File tree

5 files changed

+173
-0
lines changed

5 files changed

+173
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
trait DOMRectReadOnly extends js.Object {
7+
8+
/** The x coordinate of the DOMRect's origin.
9+
*
10+
* MDN
11+
*/
12+
def x: Double = js.native
13+
14+
/** The y coordinate of the DOMRect's origin.
15+
*
16+
* MDN
17+
*/
18+
def y: Double = js.native
19+
20+
/** The width of the DOMRect.
21+
*
22+
* MDN
23+
*/
24+
def width: Double = js.native
25+
26+
/** The height of the DOMRect.
27+
*
28+
* MDN
29+
*/
30+
def height: Double = js.native
31+
32+
/** Returns the top coordinate value of the DOMRect (usually the same as y.)
33+
*
34+
* MDN
35+
*/
36+
def top: Double = js.native
37+
38+
/** Returns the right coordinate value of the DOMRect (usually the same as x + width).
39+
*
40+
* MDN
41+
*/
42+
def right: Double = js.native
43+
44+
/** Returns the bottom coordinate value of the DOMRect (usually the same as y + height)
45+
*
46+
* MDN
47+
*/
48+
def bottom: Double = js.native
49+
50+
/** Returns the left coordinate value of the DOMRect (usually the same as x)
51+
*
52+
* MDN
53+
*/
54+
def left: Double = js.native
55+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSGlobal
5+
6+
/** The ResizeObserver constructor creates a new ResizeObserver object, which can be used to report changes to the
7+
* content or border box of an Element or the bounding box of an SVGElement - MDN
8+
*
9+
* @param callback
10+
* The function called whenever an observed resize occurs. - MDN
11+
*/
12+
@js.native
13+
@JSGlobal
14+
class ResizeObserver(callback: js.Function2[js.Array[ResizeObserverEntry], ResizeObserver, _]) extends js.Object {
15+
16+
/** Starts observing the specified Element or SVGElement.
17+
*
18+
* MDN
19+
*/
20+
def observe(target: Node, options: js.UndefOr[ResizeObserverOptions] = js.native): Unit = js.native
21+
22+
/** Unobserves all observed Element or SVGElement targets.
23+
*
24+
* MDN
25+
*/
26+
def disconnect(): Unit = js.native
27+
28+
/** Ends the observing of a specified Element or SVGElement.
29+
*
30+
* MDN
31+
*/
32+
def unobserve(target: Node): Unit = js.native
33+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** The ResizeObserverEntry interface represents the object passedto the ResizeObserver() constructor's callback
6+
* function, which allows you to access the new dimensions of the Element or SVGElement being observed.
7+
*
8+
* MDN
9+
*/
10+
@js.native
11+
trait ResizeObserverEntry extends js.Object {
12+
13+
/** A reference to the Element or SVGElement being observed
14+
*
15+
* MDN
16+
*/
17+
def target: Node = js.native
18+
19+
/** An array containing objects with the new border box size of the observed element. The array is necessary to
20+
* support elements that have multiple fragments, which occur in multi-column scenarios.
21+
*
22+
* MDN
23+
*/
24+
def borderBoxSize: js.Array[ResizeObserverSize] = js.native
25+
26+
/** An array containing objects with the new content box size of the observed element. The array is necessary to
27+
* support elements that have multiple fragments, which occur in multi-column scenarios.
28+
*
29+
* MDN
30+
*/
31+
def contentBoxSize: js.Array[ResizeObserverSize] = js.native
32+
33+
/** A [[DOMRectReadOnly]] object containing the new size of the observed element when the callback is run. Note that
34+
* this is better supported than the above two properties, but it is left over from an earlier implementation of the
35+
* Resize Observer API, is still included in the spec for web compat reasons, and may be deprecated in future
36+
* versions.
37+
*
38+
* MDN
39+
*/
40+
def contentRect: DOMRectReadOnly = js.native
41+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
trait ResizeObserverOptions extends js.Object {
7+
var box: js.UndefOr[String] = js.native
8+
}
9+
10+
/** Factory for [[ResizeObserverOptions]] objects. */
11+
object ResizeObserverOptions {
12+
13+
/** Creates a new [[ResizeObserverOptions]] object with the given values. */
14+
def apply(
15+
box: Option[String] = None
16+
): ResizeObserverOptions = {
17+
val res = js.Dynamic.asInstanceOf[ResizeObserverOptions]
18+
box.foreach(res.box = _)
19+
res
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
trait ResizeObserverSize extends js.Object {
7+
8+
/** The length of the observed element's border box in the block dimension. For boxes with a horizontal writing-mode,
9+
* this is the vertical dimension, or height; if the writing-mode is vertical, this is the horizontal dimension, or
10+
* width.
11+
*
12+
* MDN
13+
*/
14+
def blockSize: Double = js.native
15+
16+
/** The length of the observed element's border box in the inline dimension. For boxes with a horizontal writing-mode,
17+
* this is the horizontal dimension, or width; if the writing-mode is vertical, this is the vertical dimension, or
18+
* height.
19+
*
20+
* MDN
21+
*/
22+
def inlineSize: Double = js.native
23+
}

0 commit comments

Comments
 (0)