|
| 1 | +@@warning("-30") |
| 2 | + |
| 3 | +open Prelude |
| 4 | +open Event |
| 5 | +open File |
| 6 | + |
| 7 | +type offscreenRenderingContextId = |
| 8 | + | @as("2d") V2d |
| 9 | + | @as("bitmaprenderer") Bitmaprenderer |
| 10 | + | @as("webgl") Webgl |
| 11 | + | @as("webgl2") Webgl2 |
| 12 | + | @as("webgpu") Webgpu |
| 13 | + |
| 14 | +/** |
| 15 | +[See OffscreenCanvas on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas) |
| 16 | +*/ |
| 17 | +type offscreenCanvas = { |
| 18 | + ...eventTarget, |
| 19 | + /** |
| 20 | + These attributes return the dimensions of the OffscreenCanvas object's bitmap. |
| 21 | +
|
| 22 | +They can be set, to replace the bitmap with a new, transparent black bitmap of the specified dimensions (effectively resizing it). |
| 23 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/width) |
| 24 | + */ |
| 25 | + mutable width: int, |
| 26 | + /** |
| 27 | + These attributes return the dimensions of the OffscreenCanvas object's bitmap. |
| 28 | +
|
| 29 | +They can be set, to replace the bitmap with a new, transparent black bitmap of the specified dimensions (effectively resizing it). |
| 30 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/height) |
| 31 | + */ |
| 32 | + mutable height: int, |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | +[See ImageBitmap on MDN](https://developer.mozilla.org/docs/Web/API/ImageBitmap) |
| 37 | +*/ |
| 38 | +type imageBitmap = { |
| 39 | + /** |
| 40 | + Returns the intrinsic width of the image, in CSS pixels. |
| 41 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/ImageBitmap/width) |
| 42 | + */ |
| 43 | + width: int, |
| 44 | + /** |
| 45 | + Returns the intrinsic height of the image, in CSS pixels. |
| 46 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/ImageBitmap/height) |
| 47 | + */ |
| 48 | + height: int, |
| 49 | +} |
| 50 | + |
| 51 | +type offscreenRenderingContext = any |
| 52 | + |
| 53 | +type imageEncodeOptions = { |
| 54 | + @as("type") mutable type_: string, |
| 55 | + mutable quality: any, |
| 56 | +} |
| 57 | + |
| 58 | +module OffscreenCanvas = { |
| 59 | + /** |
| 60 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas) |
| 61 | + */ |
| 62 | + @new |
| 63 | + external make: (int, int) => offscreenCanvas = "OffscreenCanvas" |
| 64 | + /** |
| 65 | + Returns an object that exposes an API for drawing on the OffscreenCanvas object. contextId specifies the desired API: "2d", "bitmaprenderer", "webgl", or "webgl2". options is handled by that API. |
| 66 | +
|
| 67 | +This specification defines the "2d" context below, which is similar but distinct from the "2d" context that is created from a canvas element. The WebGL specifications define the "webgl" and "webgl2" contexts. [WEBGL] |
| 68 | +
|
| 69 | +Returns null if the canvas has already been initialized with another context type (e.g., trying to get a "2d" context after getting a "webgl" context). |
| 70 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/getContext) |
| 71 | + */ |
| 72 | + @send |
| 73 | + external getContext: ( |
| 74 | + offscreenCanvas, |
| 75 | + offscreenRenderingContextId, |
| 76 | + any, |
| 77 | + ) => offscreenRenderingContext = "getContext" |
| 78 | + |
| 79 | + /** |
| 80 | + Returns a newly created ImageBitmap object with the image in the OffscreenCanvas object. The image in the OffscreenCanvas object is replaced with a new blank image. |
| 81 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/transferToImageBitmap) |
| 82 | + */ |
| 83 | + @send |
| 84 | + external transferToImageBitmap: offscreenCanvas => imageBitmap = "transferToImageBitmap" |
| 85 | + |
| 86 | + /** |
| 87 | + Returns a promise that will fulfill with a new Blob object representing a file containing the image in the OffscreenCanvas object. |
| 88 | +
|
| 89 | +The argument, if provided, is a dictionary that controls the encoding options of the image file to be created. The type field specifies the file format and has a default value of "image/png"; that type is also used if the requested type isn't supported. If the image format supports variable quality (such as "image/jpeg"), then the quality field is a number in the range 0.0 to 1.0 inclusive indicating the desired quality level for the resulting image. |
| 90 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/convertToBlob) |
| 91 | + */ |
| 92 | + @send |
| 93 | + external convertToBlob: (offscreenCanvas, imageEncodeOptions) => Promise.t<blob> = "convertToBlob" |
| 94 | +} |
| 95 | + |
| 96 | +module ImageBitmap = { |
| 97 | + /** |
| 98 | + Releases imageBitmap's underlying bitmap data. |
| 99 | + [Read more on MDN](https://developer.mozilla.org/docs/Web/API/ImageBitmap/close) |
| 100 | + */ |
| 101 | + @send |
| 102 | + external close: imageBitmap => unit = "close" |
| 103 | +} |
0 commit comments