Skip to content
Merged
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
15 changes: 10 additions & 5 deletions src/CSSFontLoadingAPI/FontFace.res
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
open CSSFontLoadingTypes
module Types = CSSFontLoadingTypes

type t = Types.fontFace = {...Types.fontFace}
type fontDisplay = Types.fontDisplay
type fontFaceLoadStatus = Types.fontFaceLoadStatus
type fontFaceDescriptors = Types.fontFaceDescriptors = {...Types.fontFaceDescriptors}

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FontFace)
*/
@new
external make: (~family: string, ~source: string, ~descriptors: fontFaceDescriptors=?) => fontFace =
external make: (~family: string, ~source: string, ~descriptors: fontFaceDescriptors=?) => t =
"FontFace"

/**
Expand All @@ -15,7 +20,7 @@ external fromDataView: (
~family: string,
~source: DataView.t,
~descriptors: fontFaceDescriptors=?,
) => fontFace = "FontFace"
) => t = "FontFace"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FontFace)
Expand All @@ -25,10 +30,10 @@ external fromArrayBuffer: (
~family: string,
~source: ArrayBuffer.t,
~descriptors: fontFaceDescriptors=?,
) => fontFace = "FontFace"
) => t = "FontFace"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FontFace/load)
*/
@send
external load: fontFace => promise<fontFace> = "load"
external load: t => promise<t> = "load"
18 changes: 11 additions & 7 deletions src/CSSFontLoadingAPI/FontFaceSet.res
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
open CSSFontLoadingTypes
module Types = CSSFontLoadingTypes

include EventTarget.Impl({type t = fontFaceSet})
type t = Types.fontFaceSet = {...Types.fontFaceSet}
type fontFace = Types.fontFace = {...Types.fontFace}
type fontFaceSetLoadStatus = Types.fontFaceSetLoadStatus

include EventTarget.Impl({type t = t})

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FontFaceSet/add)
*/
@send
external add: (fontFaceSet, fontFace) => fontFaceSet = "add"
external add: (t, fontFace) => t = "add"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FontFaceSet/delete)
*/
@send
external delete: (fontFaceSet, fontFace) => bool = "delete"
external delete: (t, fontFace) => bool = "delete"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FontFaceSet/clear)
*/
@send
external clear: fontFaceSet => unit = "clear"
external clear: t => unit = "clear"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FontFaceSet/load)
*/
@send
external load: (fontFaceSet, ~font: string, ~text: string=?) => promise<array<fontFace>> = "load"
external load: (t, ~font: string, ~text: string=?) => promise<array<fontFace>> = "load"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FontFaceSet/check)
*/
@send
external check: (fontFaceSet, ~font: string, ~text: string=?) => bool = "check"
external check: (t, ~font: string, ~text: string=?) => bool = "check"
6 changes: 4 additions & 2 deletions src/CanvasAPI/CanvasGradient.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
open CanvasTypes
module Types = CanvasTypes

type t = Types.canvasGradient = {...Types.canvasGradient}

/**
Adds a color stop with the given color to the gradient at the given offset. 0.0 is the offset at one end of the gradient, 1.0 is the offset at the other end.
Expand All @@ -7,6 +9,6 @@ Throws an "IndexSizeError" DOMException if the offset is out of range. Throws a
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasGradient/addColorStop)
*/
@send
external addColorStop: (canvasGradient, ~offset: float, ~color: string) => unit = "addColorStop"
external addColorStop: (t, ~offset: float, ~color: string) => unit = "addColorStop"

let isInstanceOf = (_: 't): bool => %raw(`param instanceof CanvasGradient`)
7 changes: 4 additions & 3 deletions src/CanvasAPI/CanvasPattern.res
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
open DOMTypes
open CanvasTypes
module Types = CanvasTypes

type t = Types.canvasPattern = {...Types.canvasPattern}

/**
Sets the transformation matrix that will be used when rendering the pattern during a fill or stroke painting operation.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasPattern/setTransform)
*/
@send
external setTransform: (canvasPattern, ~transform: domMatrix2DInit=?) => unit = "setTransform"
external setTransform: (t, ~transform: DOMTypes.domMatrix2DInit=?) => unit = "setTransform"

let isInstanceOf = (_: 't): bool => %raw(`param instanceof CanvasPattern`)
25 changes: 15 additions & 10 deletions src/CanvasAPI/FillStyle.res
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
open Prelude
open CanvasTypes

external fromString: string => fillStyle = "%identity"
external fromCanvasGradient: canvasGradient => fillStyle = "%identity"
external fromCanvasPattern: canvasGradient => fillStyle = "%identity"
module Types = CanvasTypes

type t = Types.fillStyle
type canvasGradient = Types.canvasGradient = {...Types.canvasGradient}
type canvasPattern = Types.canvasPattern = {...Types.canvasPattern}

external fromString: string => t = "%identity"
external fromCanvasGradient: canvasGradient => t = "%identity"
external fromCanvasPattern: canvasPattern => t = "%identity"

/**
Represents a decoded version of the abstract `fillStyle` type, used in Context2D.
Expand All @@ -13,12 +18,12 @@ type decoded =
| CanvasGradient(canvasGradient)
| CanvasPattern(canvasPattern)

let decode = (t: fillStyle): decoded => {
if CanvasGradient.isInstanceOf(t) {
CanvasGradient(unsafeConversation(t))
} else if CanvasPattern.isInstanceOf(t) {
CanvasPattern(unsafeConversation(t))
let decode = (value: t): decoded => {
if CanvasGradient.isInstanceOf(value) {
CanvasGradient(unsafeConversation(value))
} else if CanvasPattern.isInstanceOf(value) {
CanvasPattern(unsafeConversation(value))
} else {
String(unsafeConversation(t))
String(unsafeConversation(value))
}
}
6 changes: 4 additions & 2 deletions src/CanvasAPI/ImageBitmap.res
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
open CanvasTypes
module Types = CanvasTypes

type t = Types.imageBitmap = {...Types.imageBitmap}

/**
Releases imageBitmap's underlying bitmap data.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/ImageBitmap/close)
*/
@send
external close: imageBitmap => unit = "close"
external close: t => unit = "close"
8 changes: 5 additions & 3 deletions src/CanvasAPI/ImageBitmapRenderingContext.res
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
open CanvasTypes
module Types = CanvasTypes

type t = Types.imageBitmapRenderingContext = {...Types.imageBitmapRenderingContext}
type imageBitmap = Types.imageBitmap = {...Types.imageBitmap}

/**
Transfers the underlying bitmap data from imageBitmap to context, and the bitmap becomes the contents of the canvas element to which context is bound.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/ImageBitmapRenderingContext/transferFromImageBitmap)
*/
@send
external transferFromImageBitmap: (imageBitmapRenderingContext, imageBitmap) => unit =
"transferFromImageBitmap"
external transferFromImageBitmap: (t, imageBitmap) => unit = "transferFromImageBitmap"
42 changes: 27 additions & 15 deletions src/CanvasAPI/OffscreenCanvas.res
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
open CanvasTypes
open FileTypes
module Types = CanvasTypes

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas)
*/
@new
external make: (~width: int, ~height: int) => offscreenCanvas = "OffscreenCanvas"

include EventTarget.Impl({type t = offscreenCanvas})
type t = Types.offscreenCanvas = {...Types.offscreenCanvas}
type imageBitmap = Types.imageBitmap = {...Types.imageBitmap}
type offscreenCanvasRenderingContext2D = Types.offscreenCanvasRenderingContext2D = {
...Types.offscreenCanvasRenderingContext2D,
}
type webGLRenderingContext = Types.webGLRenderingContext = {...Types.webGLRenderingContext}
type webGL2RenderingContext = Types.webGL2RenderingContext = {...Types.webGL2RenderingContext}
type webGLContextAttributes = Types.webGLContextAttributes = {...Types.webGLContextAttributes}
type imageBitmapRenderingContext = Types.imageBitmapRenderingContext = {
...Types.imageBitmapRenderingContext,
}
type imageBitmapRenderingContextSettings = Types.imageBitmapRenderingContextSettings = {
...Types.imageBitmapRenderingContextSettings,
}
type imageEncodeOptions = Types.imageEncodeOptions = {...Types.imageEncodeOptions}

external make: (~width: int, ~height: int) => t = "OffscreenCanvas"

include EventTarget.Impl({type t = t})

/**
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.
Expand All @@ -18,11 +33,8 @@ Returns null if the canvas has already been initialized with another context typ
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/getContext)
*/
@send
external getContext2D: (
offscreenCanvas,
@as("2d") _,
~options: JSON.t=?,
) => offscreenCanvasRenderingContext2D = "getContext"
external getContext2D: (t, @as("2d") _, ~options: JSON.t=?) => offscreenCanvasRenderingContext2D =
"getContext"

/**
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.
Expand All @@ -34,7 +46,7 @@ Returns null if the canvas has already been initialized with another context typ
*/
@send
external getContextWebGL: (
offscreenCanvas,
t,
@as("webgl") _,
~options: webGLContextAttributes=?,
) => webGLRenderingContext = "getContext"
Expand All @@ -49,7 +61,7 @@ Returns null if the canvas has already been initialized with another context typ
*/
@send
external getContextWebGL2: (
offscreenCanvas,
t,
@as("webgl2") _,
~options: webGLContextAttributes=?,
) => webGL2RenderingContext = "getContext"
Expand All @@ -64,7 +76,7 @@ Returns null if the canvas has already been initialized with another context typ
*/
@send
external getContextBitmapRenderer: (
offscreenCanvas,
t,
@as("bitmaprenderer") _,
~options: imageBitmapRenderingContextSettings=?,
) => imageBitmapRenderingContext = "getContext"
Expand All @@ -74,7 +86,7 @@ Returns a newly created ImageBitmap object with the image in the OffscreenCanvas
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/transferToImageBitmap)
*/
@send
external transferToImageBitmap: offscreenCanvas => imageBitmap = "transferToImageBitmap"
external transferToImageBitmap: t => imageBitmap = "transferToImageBitmap"

/**
Returns a promise that will fulfill with a new Blob object representing a file containing the image in the OffscreenCanvas object.
Expand All @@ -83,5 +95,5 @@ The argument, if provided, is a dictionary that controls the encoding options of
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/convertToBlob)
*/
@send
external convertToBlob: (offscreenCanvas, ~options: imageEncodeOptions=?) => promise<blob> =
external convertToBlob: (t, ~options: imageEncodeOptions=?) => promise<FileTypes.blob> =
"convertToBlob"
31 changes: 16 additions & 15 deletions src/CanvasAPI/Path2D.res
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
open CanvasTypes
open DOMTypes
module Types = CanvasTypes

type t = Types.path2D = {...Types.path2D}

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Path2D)
*/
@new
external make: (~path: path2D=?) => path2D = "Path2D"
external make: (~path: t=?) => t = "Path2D"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Path2D)
*/
@new
external fromString: (~path: string=?) => path2D = "Path2D"
external fromString: (~path: string=?) => t = "Path2D"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/closePath)
*/
@send
external closePath: path2D => unit = "closePath"
external closePath: t => unit = "closePath"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/moveTo)
*/
@send
external moveTo: (path2D, ~x: float, ~y: float) => unit = "moveTo"
external moveTo: (t, ~x: float, ~y: float) => unit = "moveTo"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/lineTo)
*/
@send
external lineTo: (path2D, ~x: float, ~y: float) => unit = "lineTo"
external lineTo: (t, ~x: float, ~y: float) => unit = "lineTo"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/quadraticCurveTo)
*/
@send
external quadraticCurveTo: (path2D, ~cpx: float, ~cpy: float, ~x: float, ~y: float) => unit =
external quadraticCurveTo: (t, ~cpx: float, ~cpy: float, ~x: float, ~y: float) => unit =
"quadraticCurveTo"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/bezierCurveTo)
*/
@send
external bezierCurveTo: (
path2D,
t,
~cp1x: float,
~cp1y: float,
~cp2x: float,
Expand All @@ -56,21 +57,21 @@ external bezierCurveTo: (
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/arcTo)
*/
@send
external arcTo: (path2D, ~x1: float, ~y1: float, ~x2: float, ~y2: float, ~radius: float) => unit =
external arcTo: (t, ~x1: float, ~y1: float, ~x2: float, ~y2: float, ~radius: float) => unit =
"arcTo"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/rect)
*/
@send
external rect: (path2D, ~x: float, ~y: float, ~w: float, ~h: float) => unit = "rect"
external rect: (t, ~x: float, ~y: float, ~w: float, ~h: float) => unit = "rect"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/roundRect)
*/
@send
external roundRect: (
path2D,
t,
~x: float,
~y: float,
~w: float,
Expand All @@ -83,7 +84,7 @@ external roundRect: (
*/
@send
external arc: (
path2D,
t,
~x: float,
~y: float,
~radius: float,
Expand All @@ -97,7 +98,7 @@ external arc: (
*/
@send
external ellipse: (
path2D,
t,
~x: float,
~y: float,
~radiusX: float,
Expand All @@ -113,4 +114,4 @@ Adds to the path the path given by the argument.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Path2D/addPath)
*/
@send
external addPath: (path2D, ~path: path2D, ~transform: domMatrix2DInit=?) => unit = "addPath"
external addPath: (t, ~path: t, ~transform: DOMTypes.domMatrix2DInit=?) => unit = "addPath"
Loading