Skip to content

Commit e6b3a4b

Browse files
committed
Add WindowOrWorkerGlobalScope
1 parent 1496242 commit e6b3a4b

File tree

4 files changed

+193
-3
lines changed

4 files changed

+193
-3
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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) extends js.Object {
16+
/**
17+
* Returns a rendering context for the offscreen canvas.
18+
*
19+
* MDN
20+
*/
21+
def getContext(contextType: String): js.Dynamic = js.native
22+
def getContext(contextType: String, contextAttributes: WebGLContextAttributes): js.Dynamic = js.native
23+
def getContext(contextType: String, contextAttributes: TwoDContextAttributes): js.Dynamic = js.native
24+
25+
/**
26+
* Creates a Blob object representing the image contained in the canvas.
27+
*
28+
* MDN
29+
*/
30+
def convertToBlob(options: ConvertToBlobOptions = ???): js.Promise[Blob] = js.native
31+
32+
/**
33+
* Creates an ImageBitmap object from the most recently rendered image of
34+
* the OffscreenCanvas.
35+
*
36+
* MDN
37+
*/
38+
def transferToImageBitmap(): ImageBitmap = js.native
39+
}
40+
41+
trait TwoDContextAttributes extends js.Object {
42+
var alpha: js.UndefOr[Boolean] = js.undefined
43+
44+
var willReadFrequently: js.UndefOr[Boolean] = js.undefined
45+
46+
var storage: js.UndefOr[String] = js.undefined
47+
}
48+
49+
trait ConvertToBlobOptions extends js.Object {
50+
var `type`: js.UndefOr[String] = js.undefined
51+
52+
var quality: js.UndefOr[Double] = js.undefined
53+
}

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

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

112113
/**
113114
* The caches read-only property of the WorkerGlobalScope interface returns
@@ -117,7 +118,7 @@ trait WorkerGlobalScope extends EventTarget {
117118
*
118119
* MDN
119120
*/
120-
def caches: js.Any = js.native
121+
override def caches: js.Any = js.native
121122

122123
/**
123124
* The self read-only property of the WorkerGlobalScope interface returns a
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
/**
51+
* Clears the delay set by window.setTimeout().
52+
*
53+
* MDN
54+
*/
55+
def clearTimeout(handle: Int): Unit = js.native
56+
57+
/**
58+
* Calls a function or executes a code snippet after a specified delay.
59+
*
60+
* MDN
61+
*/
62+
def setTimeout(handler: js.Function0[Any], timeout: Double): Int = js.native
63+
64+
/**
65+
* Cancels repeated action which was set up using setInterval.
66+
*
67+
* MDN
68+
*/
69+
def clearInterval(handle: Int): Unit = js.native
70+
71+
/**
72+
* Calls a function or executes a code snippet repeatedly, with a fixed time
73+
* delay between each call to that function.
74+
*
75+
* MDN
76+
*/
77+
def setInterval(handler: js.Function0[Any], timeout: Double): Int = js.native
78+
79+
/**
80+
* Accepts a variety of different image sources, and returns a Promise which
81+
* resolves to an ImageBitmap.
82+
* Optionally the source is cropped to the rectangle of pixels originating at
83+
* (sx, sy) with width sw, and height sh.
84+
*
85+
* MDN
86+
*/
87+
def createImageBitmap(image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas): js.Promise[ImageBitmap] = js.native
88+
def createImageBitmap(image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas, options: CreateImageBitmapOption): js.Promise[ImageBitmap] = js.native
89+
def createImageBitmap(image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas, sx: Double, sy: Double, sw: Double, sh: Double): js.Promise[ImageBitmap] = js.native
90+
def createImageBitmap(image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas, sx: Double, sy: Double, sw: Double, sh: Double, options: CreateImageBitmapOption): js.Promise[ImageBitmap] = js.native
91+
}
92+
93+
94+
trait CreateImageBitmapOption extends js.Object {
95+
var imageOrientation: js.UndefOr[String] = js.undefined
96+
97+
var premultiplyAlpha: js.UndefOr[String] = js.undefined
98+
99+
var colorSpaceConversion: js.UndefOr[String] = js.undefined
100+
101+
var resizeWidth: js.UndefOr[Double] = js.undefined
102+
103+
var resizeHeight: js.UndefOr[Double] = js.undefined
104+
105+
var resizeQuality: js.UndefOr[String] = js.undefined
106+
}
107+
108+
/**
109+
* The ImageBitmap interface represents a bitmap image which can be drawn to a
110+
* <canvas> without undue latency.
111+
* It can be created from a variety of source objects using the
112+
* createImageBitmap() factory method.
113+
* ImageBitmap provides an asynchronous and resource efficient pathway to
114+
* prepare textures for rendering in WebGL.
115+
*
116+
* MDN
117+
*/
118+
@js.native
119+
trait ImageBitmap extends js.Object {
120+
/**
121+
* An unsigned long representing the height, in CSS pixels, of the ImageData.
122+
*/
123+
def height: Double = js.native
124+
125+
/**
126+
* An unsigned long representing the width, in CSS pixels, of the ImageData.
127+
*/
128+
def width: Double = js.native
129+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ trait WindowSessionStorage extends js.Object {
20582058
class Window
20592059
extends EventTarget with WindowLocalStorage with WindowSessionStorage
20602060
with WindowTimers with WindowBase64 with IDBEnvironment
2061-
with WindowConsole {
2061+
with WindowConsole with WindowOrWorkerGlobalScope {
20622062
var ondragend: js.Function1[DragEvent, _] = js.native
20632063

20642064
/**
@@ -2762,6 +2762,13 @@ 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], timeout: Double): Int = js.native
2770+
override def clearInterval(handle: Int): Unit = js.native
2771+
override def setInterval(handler: js.Function0[Any], timeout: Double): Int = js.native
27652772
}
27662773

27672774
/**

0 commit comments

Comments
 (0)