Skip to content

Add WindowOrWorkerGlobalScope #416

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/main/scala/org/scalajs/dom/raw/OffscreenCanvas.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.scalajs.dom.raw

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

/**
* The OffscreenCanvas interface provides a canvas that can be rendered off
* screen.
* It is available in both the window and worker contexts.
*
* MDN
*/
@js.native
@JSGlobal
class OffscreenCanvas(var width: Double, var height: Double)
extends js.Object {

/**
* Returns a rendering context for the offscreen canvas.
*
* MDN
*/
def getContext(contextType: String): js.Dynamic = js.native
def getContext(contextType: String,
contextAttributes: WebGLContextAttributes): js.Dynamic = js.native
def getContext(contextType: String,
contextAttributes: TwoDContextAttributes): js.Dynamic = js.native

/**
* Creates a Blob object representing the image contained in the canvas.
*
* MDN
*/
def convertToBlob(
options: ConvertToBlobOptions = ???): js.Promise[Blob] = js.native

/**
* Creates an ImageBitmap object from the most recently rendered image of
* the OffscreenCanvas.
*
* MDN
*/
def transferToImageBitmap(): ImageBitmap = js.native
}

trait TwoDContextAttributes extends js.Object {
var alpha: js.UndefOr[Boolean] = js.undefined

var willReadFrequently: js.UndefOr[Boolean] = js.undefined

var storage: js.UndefOr[String] = js.undefined
}

trait ConvertToBlobOptions extends js.Object {
var `type`: js.UndefOr[String] = js.undefined

var quality: js.UndefOr[Double] = js.undefined
}
4 changes: 2 additions & 2 deletions src/main/scala/org/scalajs/dom/raw/WebWorkers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Worker(stringUrl: String) extends AbstractWorker {
* MDN
*/
@js.native
trait WorkerGlobalScope extends EventTarget {
trait WorkerGlobalScope extends EventTarget with WindowOrWorkerGlobalScope {

/**
* The caches read-only property of the WorkerGlobalScope interface returns
Expand All @@ -117,7 +117,7 @@ trait WorkerGlobalScope extends EventTarget {
*
* MDN
*/
def caches: js.Any = js.native
override def caches: js.Any = js.native

/**
* The self read-only property of the WorkerGlobalScope interface returns a
Expand Down
137 changes: 137 additions & 0 deletions src/main/scala/org/scalajs/dom/raw/WindowOrWorkerGlobalScope.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package org.scalajs.dom.raw

import org.scalajs.dom.experimental.{RequestInfo, RequestInit, Response}

import scala.scalajs.js
import scala.scalajs.js.|

@js.native
trait WindowOrWorkerGlobalScope extends js.Object {

def caches: js.Any = js.native
def crossOriginIsolated: Boolean = js.native
def isSecureContext: Boolean = js.native
def origin: String = js.native

type indexedDB = org.scalajs.dom.raw.IDBFactory

/**
* Starts the process of fetching a resource from the network.
*
* MDN
*/
def fetch(info: RequestInfo,
init: RequestInit = null): js.Promise[Response] = js.native

/**
* Enqueues a microtask—a short function to be executed after execution of
* the JavaScript code completes and control isn't being returned to a
* JavaScript caller, but before handling callbacks and other tasks.
*
* This lets your code run without interfering with other, possibly higher
* priority, code, but before the browser runtime regains control,
* potentially depending upon the work you need to complete.
*
* MDN
*/
def queueMicrotask(function: js.Function): Unit = js.native

/**
* Creates a base-64 encoded ASCII string from a "string" of binary data.
*/
def btoa(rawString: String): String = js.native

/**
* Decodes a string of data which has been encoded using base-64 encoding.
*/
def atob(encodedString: String): String = js.native

/**
* Clears the delay set by window.setTimeout().
*
* MDN
*/
def clearTimeout(handle: Int): Unit = js.native

/**
* Calls a function or executes a code snippet after a specified delay.
*
* MDN
*/
def setTimeout(handler: js.Function0[Any], timeout: Double): Int = js.native

/**
* Cancels repeated action which was set up using setInterval.
*
* MDN
*/
def clearInterval(handle: Int): Unit = js.native

/**
* Calls a function or executes a code snippet repeatedly, with a fixed time
* delay between each call to that function.
*
* MDN
*/
def setInterval(handler: js.Function0[Any], timeout: Double): Int = js.native

/**
* Accepts a variety of different image sources, and returns a Promise which
* resolves to an ImageBitmap.
* Optionally the source is cropped to the rectangle of pixels originating at
* (sx, sy) with width sw, and height sh.
*
* MDN
*/
def createImageBitmap(
image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas): js.Promise[ImageBitmap] = js.native
def createImageBitmap(
image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas,
options: CreateImageBitmapOption): js.Promise[ImageBitmap] = js.native
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
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
}

trait CreateImageBitmapOption extends js.Object {
var imageOrientation: js.UndefOr[String] = js.undefined

var premultiplyAlpha: js.UndefOr[String] = js.undefined

var colorSpaceConversion: js.UndefOr[String] = js.undefined

var resizeWidth: js.UndefOr[Double] = js.undefined

var resizeHeight: js.UndefOr[Double] = js.undefined

var resizeQuality: js.UndefOr[String] = js.undefined
}

/**
* The ImageBitmap interface represents a bitmap image which can be drawn to a
* <canvas> without undue latency.
* It can be created from a variety of source objects using the
* createImageBitmap() factory method.
* ImageBitmap provides an asynchronous and resource efficient pathway to
* prepare textures for rendering in WebGL.
*
* MDN
*/
@js.native
trait ImageBitmap extends js.Object {

/**
* An unsigned long representing the height, in CSS pixels, of the ImageData.
*/
def height: Double = js.native

/**
* An unsigned long representing the width, in CSS pixels, of the ImageData.
*/
def width: Double = js.native
}
13 changes: 11 additions & 2 deletions src/main/scala/org/scalajs/dom/raw/lib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2057,8 +2057,8 @@ trait WindowSessionStorage extends js.Object {
@JSGlobal
class Window
extends EventTarget with WindowLocalStorage with WindowSessionStorage
with WindowTimers with WindowBase64 with IDBEnvironment
with WindowConsole {
with WindowTimers with WindowBase64 with IDBEnvironment with WindowConsole
with WindowOrWorkerGlobalScope {
var ondragend: js.Function1[DragEvent, _] = js.native

/**
Expand Down Expand Up @@ -2762,6 +2762,15 @@ class Window
* MDN
*/
var lostpointercapture: js.Function1[PointerEvent, _] = js.native

override def btoa(rawString: String): String = js.native
override def atob(encodedString: String): String = js.native
override def clearTimeout(handle: Int): Unit = js.native
override def setTimeout(handler: js.Function0[Any],
timeout: Double): Int = js.native
override def clearInterval(handle: Int): Unit = js.native
override def setInterval(handler: js.Function0[Any],
timeout: Double): Int = js.native
}

/**
Expand Down