diff --git a/src/main/scala/org/scalajs/dom/raw/OffscreenCanvas.scala b/src/main/scala/org/scalajs/dom/raw/OffscreenCanvas.scala new file mode 100644 index 000000000..187b85c8e --- /dev/null +++ b/src/main/scala/org/scalajs/dom/raw/OffscreenCanvas.scala @@ -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 +} diff --git a/src/main/scala/org/scalajs/dom/raw/WebWorkers.scala b/src/main/scala/org/scalajs/dom/raw/WebWorkers.scala index cd58e053d..5bebfc71d 100644 --- a/src/main/scala/org/scalajs/dom/raw/WebWorkers.scala +++ b/src/main/scala/org/scalajs/dom/raw/WebWorkers.scala @@ -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 @@ -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 diff --git a/src/main/scala/org/scalajs/dom/raw/WindowOrWorkerGlobalScope.scala b/src/main/scala/org/scalajs/dom/raw/WindowOrWorkerGlobalScope.scala new file mode 100644 index 000000000..f76d724e6 --- /dev/null +++ b/src/main/scala/org/scalajs/dom/raw/WindowOrWorkerGlobalScope.scala @@ -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 + * 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 +} diff --git a/src/main/scala/org/scalajs/dom/raw/lib.scala b/src/main/scala/org/scalajs/dom/raw/lib.scala index 77a6c1785..0a7b5c635 100644 --- a/src/main/scala/org/scalajs/dom/raw/lib.scala +++ b/src/main/scala/org/scalajs/dom/raw/lib.scala @@ -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 /** @@ -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 } /**