Skip to content

Commit c794a67

Browse files
committed
Add WindowOrWorkerGlobalScope
1 parent 1496242 commit c794a67

File tree

4 files changed

+208
-4
lines changed

4 files changed

+208
-4
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.scalajs.dom.raw
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSGlobal
5+
6+
/**
7+
* The OffscreenCanvas interface provides a canvas that can be rendered off
8+
* screen.
9+
* It is available in both the window and worker contexts.
10+
*
11+
* MDN
12+
*/
13+
@js.native
14+
@JSGlobal
15+
class OffscreenCanvas(var width: Double, var height: Double)
16+
extends js.Object {
17+
18+
/**
19+
* Returns a rendering context for the offscreen canvas.
20+
*
21+
* MDN
22+
*/
23+
def getContext(contextType: String): js.Dynamic = js.native
24+
def getContext(contextType: String,
25+
contextAttributes: WebGLContextAttributes): js.Dynamic = js.native
26+
def getContext(contextType: String,
27+
contextAttributes: TwoDContextAttributes): js.Dynamic = js.native
28+
29+
/**
30+
* Creates a Blob object representing the image contained in the canvas.
31+
*
32+
* MDN
33+
*/
34+
def convertToBlob(
35+
options: ConvertToBlobOptions = ???): js.Promise[Blob] = js.native
36+
37+
/**
38+
* Creates an ImageBitmap object from the most recently rendered image of
39+
* the OffscreenCanvas.
40+
*
41+
* MDN
42+
*/
43+
def transferToImageBitmap(): ImageBitmap = js.native
44+
}
45+
46+
trait TwoDContextAttributes extends js.Object {
47+
var alpha: js.UndefOr[Boolean] = js.undefined
48+
49+
var willReadFrequently: js.UndefOr[Boolean] = js.undefined
50+
51+
var storage: js.UndefOr[String] = js.undefined
52+
}
53+
54+
trait ConvertToBlobOptions extends js.Object {
55+
var `type`: js.UndefOr[String] = js.undefined
56+
57+
var quality: js.UndefOr[Double] = js.undefined
58+
}

src/main/scala/org/scalajs/dom/raw/WebWorkers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Worker(stringUrl: String) extends AbstractWorker {
107107
* MDN
108108
*/
109109
@js.native
110-
trait WorkerGlobalScope extends EventTarget {
110+
trait WorkerGlobalScope extends EventTarget with WindowOrWorkerGlobalScope {
111111

112112
/**
113113
* The caches read-only property of the WorkerGlobalScope interface returns
@@ -117,7 +117,7 @@ trait WorkerGlobalScope extends EventTarget {
117117
*
118118
* MDN
119119
*/
120-
def caches: js.Any = js.native
120+
override def caches: js.Any = js.native
121121

122122
/**
123123
* The self read-only property of the WorkerGlobalScope interface returns a
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package org.scalajs.dom.raw
2+
3+
import org.scalajs.dom.experimental.{RequestInfo, RequestInit, Response}
4+
5+
import scala.scalajs.js
6+
import scala.scalajs.js.|
7+
8+
@js.native
9+
trait WindowOrWorkerGlobalScope extends js.Object {
10+
11+
def caches: js.Any = js.native
12+
def crossOriginIsolated: Boolean = js.native
13+
def isSecureContext: Boolean = js.native
14+
def origin: String = js.native
15+
16+
type indexedDB = org.scalajs.dom.raw.IDBFactory
17+
18+
/**
19+
* Starts the process of fetching a resource from the network.
20+
*
21+
* MDN
22+
*/
23+
def fetch(info: RequestInfo,
24+
init: RequestInit = null): js.Promise[Response] = js.native
25+
26+
/**
27+
* Enqueues a microtask—a short function to be executed after execution of
28+
* the JavaScript code completes and control isn't being returned to a
29+
* JavaScript caller, but before handling callbacks and other tasks.
30+
*
31+
* This lets your code run without interfering with other, possibly higher
32+
* priority, code, but before the browser runtime regains control,
33+
* potentially depending upon the work you need to complete.
34+
*
35+
* MDN
36+
*/
37+
def queueMicrotask(function: js.Function): Unit = js.native
38+
39+
/**
40+
* Creates a base-64 encoded ASCII string from a "string" of binary data.
41+
*/
42+
def btoa(rawString: String): String = js.native
43+
44+
/**
45+
* Decodes a string of data which has been encoded using base-64 encoding.
46+
*/
47+
def atob(encodedString: String): String = js.native
48+
49+
/**
50+
* Clears the delay set by window.setTimeout().
51+
*
52+
* MDN
53+
*/
54+
def clearTimeout(handle: Int): Unit = js.native
55+
56+
/**
57+
* Calls a function or executes a code snippet after a specified delay.
58+
*
59+
* MDN
60+
*/
61+
def setTimeout(handler: js.Function0[Any], timeout: Double): Int = js.native
62+
63+
/**
64+
* Cancels repeated action which was set up using setInterval.
65+
*
66+
* MDN
67+
*/
68+
def clearInterval(handle: Int): Unit = js.native
69+
70+
/**
71+
* Calls a function or executes a code snippet repeatedly, with a fixed time
72+
* delay between each call to that function.
73+
*
74+
* MDN
75+
*/
76+
def setInterval(handler: js.Function0[Any], timeout: Double): Int = js.native
77+
78+
/**
79+
* Accepts a variety of different image sources, and returns a Promise which
80+
* resolves to an ImageBitmap.
81+
* Optionally the source is cropped to the rectangle of pixels originating at
82+
* (sx, sy) with width sw, and height sh.
83+
*
84+
* MDN
85+
*/
86+
def createImageBitmap(
87+
image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas): js.Promise[ImageBitmap] = js.native
88+
def createImageBitmap(
89+
image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas,
90+
options: CreateImageBitmapOption): js.Promise[ImageBitmap] = js.native
91+
def createImageBitmap(
92+
image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas,
93+
sx: Double, sy: Double, sw: Double,
94+
sh: Double): js.Promise[ImageBitmap] = js.native
95+
def createImageBitmap(
96+
image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas,
97+
sx: Double, sy: Double, sw: Double, sh: Double,
98+
options: CreateImageBitmapOption): js.Promise[ImageBitmap] = js.native
99+
}
100+
101+
trait CreateImageBitmapOption extends js.Object {
102+
var imageOrientation: js.UndefOr[String] = js.undefined
103+
104+
var premultiplyAlpha: js.UndefOr[String] = js.undefined
105+
106+
var colorSpaceConversion: js.UndefOr[String] = js.undefined
107+
108+
var resizeWidth: js.UndefOr[Double] = js.undefined
109+
110+
var resizeHeight: js.UndefOr[Double] = js.undefined
111+
112+
var resizeQuality: js.UndefOr[String] = js.undefined
113+
}
114+
115+
/**
116+
* The ImageBitmap interface represents a bitmap image which can be drawn to a
117+
* <canvas> without undue latency.
118+
* It can be created from a variety of source objects using the
119+
* createImageBitmap() factory method.
120+
* ImageBitmap provides an asynchronous and resource efficient pathway to
121+
* prepare textures for rendering in WebGL.
122+
*
123+
* MDN
124+
*/
125+
@js.native
126+
trait ImageBitmap extends js.Object {
127+
128+
/**
129+
* An unsigned long representing the height, in CSS pixels, of the ImageData.
130+
*/
131+
def height: Double = js.native
132+
133+
/**
134+
* An unsigned long representing the width, in CSS pixels, of the ImageData.
135+
*/
136+
def width: Double = js.native
137+
}

src/main/scala/org/scalajs/dom/raw/lib.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,8 +2057,8 @@ trait WindowSessionStorage extends js.Object {
20572057
@JSGlobal
20582058
class Window
20592059
extends EventTarget with WindowLocalStorage with WindowSessionStorage
2060-
with WindowTimers with WindowBase64 with IDBEnvironment
2061-
with WindowConsole {
2060+
with WindowTimers with WindowBase64 with IDBEnvironment with WindowConsole
2061+
with WindowOrWorkerGlobalScope {
20622062
var ondragend: js.Function1[DragEvent, _] = js.native
20632063

20642064
/**
@@ -2762,6 +2762,15 @@ class Window
27622762
* MDN
27632763
*/
27642764
var lostpointercapture: js.Function1[PointerEvent, _] = js.native
2765+
2766+
override def btoa(rawString: String): String = js.native
2767+
override def atob(encodedString: String): String = js.native
2768+
override def clearTimeout(handle: Int): Unit = js.native
2769+
override def setTimeout(handler: js.Function0[Any],
2770+
timeout: Double): Int = js.native
2771+
override def clearInterval(handle: Int): Unit = js.native
2772+
override def setInterval(handler: js.Function0[Any],
2773+
timeout: Double): Int = js.native
27652774
}
27662775

27672776
/**

0 commit comments

Comments
 (0)